$darkmode
DENOPTIM
DynamicCentroidClusterTest.java
Go to the documentation of this file.
1package denoptim.fragmenter;
2
3import static org.junit.jupiter.api.Assertions.assertTrue;
4
5import java.util.ArrayList;
6import java.util.List;
7
8import javax.vecmath.Point3d;
9
10import org.junit.jupiter.api.Test;
11import org.openscience.cdk.Atom;
12import org.openscience.cdk.interfaces.IAtomContainer;
13import org.openscience.cdk.interfaces.IBond;
14import org.openscience.cdk.interfaces.IChemObjectBuilder;
15import org.openscience.cdk.silent.SilentChemObjectBuilder;
16
17import denoptim.fragmenter.FragmentClusterer.DistanceAsRMSD;
18import denoptim.graph.APClass;
19import denoptim.graph.Fragment;
20import denoptim.graph.Vertex.BBType;
21
26{
27
31 private IChemObjectBuilder builder = SilentChemObjectBuilder.getInstance();
32
33//------------------------------------------------------------------------------
34
35 @Test
36 public void testGetCentroid() throws Exception
37 {
38 List<ClusterableFragment> sample = new ArrayList<ClusterableFragment>();
39
40 IAtomContainer mol0 = builder.newAtomContainer();
41 mol0.addAtom(new Atom("C", new Point3d(0,0,0)));
42 mol0.addAtom(new Atom("H", new Point3d(2,0,0)));
43 mol0.addBond(0,1,IBond.Order.SINGLE);
44 Fragment frag0 = new Fragment(mol0, BBType.UNDEFINED);
45 frag0.addAP(0, APClass.make("A:0"), new Point3d(-2,0,0));
48 sample.add(cf0);
49
50 IAtomContainer mol1 = builder.newAtomContainer();
51 mol1.addAtom(new Atom("C", new Point3d(0,0,0)));
52 mol1.addAtom(new Atom("H", new Point3d(1,0,0)));
53 mol1.addBond(0,1,IBond.Order.SINGLE);
54 Fragment frag1 = new Fragment(mol1, BBType.UNDEFINED);
55 frag1.addAP(0, APClass.make("A:0"), new Point3d(-1,0,0));
58 sample.add(cf1);
59
60 IAtomContainer mol2 = builder.newAtomContainer();
61 mol2.addAtom(new Atom("C", new Point3d(0,0,0)));
62 mol2.addAtom(new Atom("H", new Point3d(1.5,0,0)));
63 mol2.addBond(0,1,IBond.Order.SINGLE);
64 Fragment frag2 = new Fragment(mol2, BBType.UNDEFINED);
65 frag2.addAP(0, APClass.make("A:0"), new Point3d(-1.5,0,0));
68 sample.add(cf2);
69
71 cluster.addPoint(cf0);
72 cluster.addPoint(cf1);
73 cluster.addPoint(cf2);
74
75 ClusterableFragment centroid = cluster.getCentroid();
76
77 DistanceAsRMSD measure = new DistanceAsRMSD();
78 assertTrue(measure.compute(centroid.getPoint(), cf2.getPoint())<0.0001);
79 assertTrue(centroid != cf2);
80 }
81
82//------------------------------------------------------------------------------
83
84 @Test
85 public void testGetNearestToCentroid() throws Exception
86 {
87 List<ClusterableFragment> sample = new ArrayList<ClusterableFragment>();
88
89 IAtomContainer mol0 = builder.newAtomContainer();
90 mol0.addAtom(new Atom("C", new Point3d(0,0,0)));
91 mol0.addAtom(new Atom("H", new Point3d(2,0,0)));
92 mol0.addBond(0,1,IBond.Order.SINGLE);
93 Fragment frag0 = new Fragment(mol0, BBType.UNDEFINED);
94 frag0.addAP(0, APClass.make("A:0"), new Point3d(-2,0,0));
97 sample.add(cf0);
98
99 IAtomContainer mol1 = builder.newAtomContainer();
100 mol1.addAtom(new Atom("C", new Point3d(0,0,0)));
101 mol1.addAtom(new Atom("H", new Point3d(1,0,0)));
102 mol1.addBond(0,1,IBond.Order.SINGLE);
103 Fragment frag1 = new Fragment(mol1, BBType.UNDEFINED);
104 frag1.addAP(0, APClass.make("A:0"), new Point3d(-1,0,0));
107 sample.add(cf1);
108
109 IAtomContainer mol2 = builder.newAtomContainer();
110 mol2.addAtom(new Atom("C", new Point3d(0,0,0)));
111 mol2.addAtom(new Atom("H", new Point3d(1.5,0,0)));
112 mol2.addBond(0,1,IBond.Order.SINGLE);
113 Fragment frag2 = new Fragment(mol2, BBType.UNDEFINED);
114 frag2.addAP(0, APClass.make("A:0"), new Point3d(-1.5,0,0));
117 sample.add(cf2);
118
120 cluster.addPoint(cf0);
121 cluster.addPoint(cf1);
122 cluster.addPoint(cf2);
123
124
125 DistanceAsRMSD measure = new DistanceAsRMSD();
126 ClusterableFragment nearest = cluster.getNearestToCentroid(measure);
127 assertTrue(measure.compute(nearest.getPoint(), cf2.getPoint())<0.0001);
128 assertTrue(nearest == cf2);
129 }
130
131//------------------------------------------------------------------------------
132
133}
Represents a fragment that can be clustered based on the 3*N coordinate of atoms and attachment point...
void setNaturalNodeOrder()
Define the node order from the list of atoms and attachment points.
A cluster with a centroid that can be updated after definition of the cluster.
ClusterableFragment getCentroid()
Get the point chosen to be the centroid of this cluster.
ClusterableFragment getNearestToCentroid(DistanceMeasure measure)
Gets the original data that upon clustering is closest to the cluster centroid according to the given...
void addPoint(ClusterableFragment point)
Add a new member of this cluster.
IChemObjectBuilder builder
Private builder of atom containers.
Distance in terms of RMSD between sets of 3D points expressed as a single vector of coordinates [x1,...
double compute(double[] coordsA, double[] coordsB)
static APClass make(String ruleAndSubclass)
Creates an APClass if it does not exist already, or returns the reference to the existing instance.
Definition: APClass.java:136
Class representing a continuously connected portion of chemical object holding attachment points.
Definition: Fragment.java:61
void addAP(int atomPositionNumber)
Adds an attachment point with a dummy APClass.
Definition: Fragment.java:343
The type of building block.
Definition: Vertex.java:86