$darkmode
DENOPTIM
FragmentClustererTest.java
Go to the documentation of this file.
1package denoptim.fragmenter;
2
3import static org.junit.jupiter.api.Assertions.assertEquals;
4import static org.junit.jupiter.api.Assertions.assertTrue;
5
6import java.io.File;
7import java.util.ArrayList;
8import java.util.List;
9
10import javax.vecmath.Matrix4d;
11import javax.vecmath.Point3d;
12import javax.vecmath.Vector3d;
13
14import org.apache.commons.math3.stat.descriptive.SummaryStatistics;
15import org.junit.jupiter.api.Test;
16import org.openscience.cdk.Atom;
17import org.openscience.cdk.PseudoAtom;
18import org.openscience.cdk.interfaces.IAtom;
19import org.openscience.cdk.interfaces.IAtomContainer;
20import org.openscience.cdk.interfaces.IBond;
21import org.openscience.cdk.interfaces.IChemObjectBuilder;
22import org.openscience.cdk.silent.SilentChemObjectBuilder;
23
24import denoptim.files.FileFormat;
25import denoptim.fragmenter.FragmentClusterer.DistanceAsRMSD;
26import denoptim.graph.APClass;
27import denoptim.graph.AttachmentPoint;
28import denoptim.graph.Fragment;
29import denoptim.graph.Vertex;
30import denoptim.graph.Vertex.BBType;
31import denoptim.io.DenoptimIO;
32import denoptim.programs.fragmenter.FragmenterParameters;
33import denoptim.utils.Randomizer;
34
39{
40
44 private IChemObjectBuilder builder = SilentChemObjectBuilder.getInstance();
45
49 private Randomizer rng = new Randomizer(1L);
50
51//------------------------------------------------------------------------------
52
53 @Test
54 public void testDistanceAsRMSD()
55 {
56 DistanceAsRMSD measure = new DistanceAsRMSD();
57
58 double[] pA = new double[] {0,0,0, 0,0,0};
59 double[] pB = new double[] {0,0,0, 1,0,0};
60 double[] pC = new double[] {0,0,0, 2,0,0};
61
62 // NB: this RMSD upon alignement not distance!
63 double val = measure.compute(pA, pB);
64 assertTrue(Math.abs(val - 0.5) < 0.0001);
65 assertTrue(Math.abs(measure.compute(pB, pA) - 0.5) < 0.0001);
66 assertTrue(Math.abs(measure.compute(pA, pA) - 0) < 0.0001);
67 assertTrue(Math.abs(measure.compute(pB, pB) - 0) < 0.0001);
68
69 assertTrue(Math.abs(measure.compute(pA, pC) - 1.0) < 0.0001);
70 assertTrue(Math.abs(measure.compute(pC, pA) - 1.0) < 0.0001);
71
72 assertTrue(Math.abs(measure.compute(pB, pC) - 0.5) < 0.0001);
73 assertTrue(Math.abs(measure.compute(pC, pB) - 0.5) < 0.0001);
74
75 pA = new double[] {0,0,0, 0,0,0};
76 pB = new double[] {0,0,0, 0,1,0};
77 pC = new double[] {0,0,0, 0,2,0};
78 assertTrue(Math.abs(measure.compute(pA, pB) - 0.5) < 0.0001);
79 assertTrue(Math.abs(measure.compute(pB, pA) - 0.5) < 0.0001);
80 assertTrue(Math.abs(measure.compute(pA, pA) - 0) < 0.0001);
81 assertTrue(Math.abs(measure.compute(pB, pB) - 0) < 0.0001);
82 assertTrue(Math.abs(measure.compute(pA, pC) - 1.0) < 0.0001);
83 assertTrue(Math.abs(measure.compute(pC, pA) - 1.0) < 0.0001);
84 assertTrue(Math.abs(measure.compute(pB, pC) - 0.5) < 0.0001);
85 assertTrue(Math.abs(measure.compute(pC, pB) - 0.5) < 0.0001);
86
87 pA = new double[] {0,0,0, 0,0,0};
88 pB = new double[] {0,0,0, 0,0,1};
89 pC = new double[] {0,0,0, 0,0,2};
90 assertTrue(Math.abs(measure.compute(pA, pB) - 0.5) < 0.0001);
91 assertTrue(Math.abs(measure.compute(pB, pA) - 0.5) < 0.0001);
92 assertTrue(Math.abs(measure.compute(pA, pA) - 0) < 0.0001);
93 assertTrue(Math.abs(measure.compute(pB, pB) - 0) < 0.0001);
94 assertTrue(Math.abs(measure.compute(pA, pC) - 1.0) < 0.0001);
95 assertTrue(Math.abs(measure.compute(pC, pA) - 1.0) < 0.0001);
96 assertTrue(Math.abs(measure.compute(pB, pC) - 0.5) < 0.0001);
97 assertTrue(Math.abs(measure.compute(pC, pB) - 0.5) < 0.0001);
98
99 pA = new double[] {0,0,0, 0,0,0};
100 pB = new double[] {0,0,1, 0,0,0};
101 pC = new double[] {0,0,2, 0,0,0};
102 assertTrue(Math.abs(measure.compute(pA, pB) - 0.5) < 0.0001);
103 assertTrue(Math.abs(measure.compute(pB, pA) - 0.5) < 0.0001);
104 assertTrue(Math.abs(measure.compute(pA, pA) - 0) < 0.0001);
105 assertTrue(Math.abs(measure.compute(pB, pB) - 0) < 0.0001);
106 assertTrue(Math.abs(measure.compute(pA, pC) - 1.0) < 0.0001);
107 assertTrue(Math.abs(measure.compute(pC, pA) - 1.0) < 0.0001);
108 assertTrue(Math.abs(measure.compute(pB, pC) - 0.5) < 0.0001);
109 assertTrue(Math.abs(measure.compute(pC, pB) - 0.5) < 0.0001);
110
111 pA = new double[] {0,0,0, 1,0,0};
112 pB = new double[] {0,0,0, 6,0,0};
113 assertTrue(Math.abs(measure.compute(pA, pB) - 2.5) < 0.0001);
114 assertTrue(Math.abs(measure.compute(pB, pA) - 2.5) < 0.0001);
115 }
116
117//------------------------------------------------------------------------------
118
119 @Test
121 {
122 double[] center = new double[] {
123 0,0,0,
124 1,0,0,
125 0,1,0,
126 0,0,1};
128 center, 100, 0.1);
129 double[] center2 = new double[] {
130 0,0,0,
131 0,0,10,
132 0,20,0,
133 0,0,20};
135 center2, 100, 0.1);
136 assertTrue(Math.abs(s1.getMean()-s2.getMean()) < 0.05);
137
138 center = new double[] {
139 0,0,0,
140 1,0,0,
141 0,1,0,
142 0,0,1,
143 -1,0,0,
144 0,-1,0,
145 0,0,-1,
146 1,0,0,
147 0,1,0,
148 0,0,1,
149 -1,0,0,
150 0,-1,0,
151 0,0,-1,
152 1,0,0,
153 0,1,0,
154 0,0,1,
155 -1,0,0,
156 0,-1,0,
157 0,0,-1};
159 center, 100, 0.1);
160 center2 = new double[] {
161 0,0,0,
162 20,0,0,
163 0,20,0,
164 0,0,20,
165 -20,0,0,
166 0,-20,0,
167 0,0,-20,
168 60,0,0,
169 0,60,0,
170 0,0,60,
171 -60,0,0,
172 0,-60,0,
173 0,0,-60,
174 80,0,0,
175 0,80,0,
176 0,0,80,
177 -80,0,0,
178 0,-80,0,
179 0,0,-80};
181 center2, 100, 0.1);
182 assertTrue(Math.abs(s3.getMean()-s4.getMean()) < 0.05);
183 }
184
185//------------------------------------------------------------------------------
186
187 @Test
188 public void testCluster() throws Exception
189 {
190 // Use this to create informative logs and files that allow to
191 // see what geometries are put in each cluster
192 boolean manualDebug = false;
193
194 double noise = 0.25;
195 // NB: the distortions are [-noise,noise] and is uniformely distributed
196 // So, the extreme cases have same probability of no distortion
197
198 // Build first set of fragment (should all be in one cluster)
199 List<ClusterableFragment> sample = new ArrayList<ClusterableFragment>();
200 Point3d[] pointsA = new Point3d[] {
201 new Point3d(-0.4574,-0.0273,0.3953),
202 new Point3d(1.2914,-0.0103,-0.0437),
203 new Point3d(-1.0737,-1.1960,-0.1490),
204 new Point3d(-0.5595,-0.0346,1.4805),
205 new Point3d(-1.0796,1.1129,-0.1241)};
206 for (int i=0; i<10; i++)
207 {
208 IAtomContainer mol = builder.newAtomContainer();
209 Point3d pA = getNoisyPoint(pointsA[0],noise);
210 Point3d pB = getNoisyPoint(pointsA[1],noise);
211 Point3d pC = getNoisyPoint(pointsA[2],noise);
212 Point3d pD = getNoisyPoint(pointsA[3],noise);
213 Point3d pE = getNoisyPoint(pointsA[4],noise);
214 Matrix4d tM = new Matrix4d();
215 tM.rotX(i*17.0);
216 tM.rotY(i*17.0);
217 tM.rotZ(-i*17.0);
218 tM.setTranslation(new Vector3d(i,i,i));
219 tM.transform(pA);
220 tM.transform(pB);
221 tM.transform(pC);
222 tM.transform(pD);
223 tM.transform(pE);
224 mol.addAtom(new Atom("C", pA));
225 mol.addAtom(new Atom("H", pB));
226 mol.addAtom(new Atom("O", pC));
227 mol.addBond(0,1,IBond.Order.SINGLE);
228 mol.addBond(0,2,IBond.Order.SINGLE);
229 Fragment frag = new Fragment(mol, BBType.UNDEFINED);
230 frag.addAP(0, APClass.make("A:0"), pD);
231 frag.addAP(0, APClass.make("B:0"), pE);
234 sample.add(cf);
235 }
236
237 if (manualDebug)
238 {
239 ArrayList<IAtomContainer> mols = new ArrayList<IAtomContainer>();
240 for (int i=0; i<sample.size(); i++)
241 {
242 mols.add(getMol(sample.get(i).getOriginalFragment()));
243 }
244 DenoptimIO.writeSDFFile("/tmp/original_sample.sdf", mols);
245 }
246
248
249 if (manualDebug)
250 {
251 settings.startConsoleLogger("ClustererTest");
252 settings.setVerbosity(2);
253 }
254
255 FragmentClusterer fc = new FragmentClusterer(sample,settings);
256 fc.cluster();
257 assertEquals(1,fc.getClusters().size());
258
259 if (manualDebug)
260 {
261 ArrayList<IAtomContainer> mols = new ArrayList<IAtomContainer>();
262 for (int i=0; i<fc.getTransformedClusters().get(0).size(); i++)
263 {
264 mols.add(getMol(fc.getTransformedClusters().get(0).get(i)));
265 }
266 DenoptimIO.writeSDFFile("/tmp/transformed.sdf", mols);
267
268 ArrayList<IAtomContainer> mols2 = new ArrayList<IAtomContainer>();
269 for (int i=0; i<sample.size(); i++)
270 {
271 mols2.add(getMol(sample.get(i).getOriginalFragment()));
272 }
273 DenoptimIO.writeSDFFile("/tmp/original_sample_after.sdf", mols2);
274 }
275
276 Point3d[] pointsB = new Point3d[] {
277 new Point3d(0.4574,-0.0273,0.3953),
278 new Point3d(-1.2914,-0.0103,-0.0437),
279 new Point3d(1.0737,-1.1960,-0.1490),
280 new Point3d(0.5595,-0.0346,1.4805),
281 new Point3d(1.0796,1.1129,-0.1241)};
282 for (int i=0; i<5; i++)
283 {
284 IAtomContainer mol = builder.newAtomContainer();
285 mol.addAtom(new Atom("C", getNoisyPoint(pointsB[0],noise)));
286 mol.addAtom(new Atom("H", getNoisyPoint(pointsB[1],noise)));
287 mol.addAtom(new Atom("O", getNoisyPoint(pointsB[2],noise)));
288 mol.addBond(0,1,IBond.Order.SINGLE);
289 mol.addBond(0,2,IBond.Order.SINGLE);
290 Fragment frag = new Fragment(mol, BBType.UNDEFINED);
291 frag.addAP(0, APClass.make("A:0"), getNoisyPoint(pointsB[3],noise));
292 frag.addAP(0, APClass.make("B:0"), getNoisyPoint(pointsB[4],noise));
295 sample.add(cf);
296 }
297
298 fc = new FragmentClusterer(sample,settings);
299 fc.cluster();
300 assertEquals(2,fc.getClusters().size());
301
302 Point3d[] pointsC = new Point3d[] {
303 new Point3d(0,0,0),
304 new Point3d(2,0,0),
305 new Point3d(0,2,0),
306 new Point3d(-2,0,0),
307 new Point3d(0,-2,0)};
308 for (int i=0; i<5; i++)
309 {
310 IAtomContainer mol = builder.newAtomContainer();
311 mol.addAtom(new Atom("C", getNoisyPoint(pointsC[0],noise)));
312 mol.addAtom(new Atom("H", getNoisyPoint(pointsC[1],noise)));
313 mol.addAtom(new Atom("O", getNoisyPoint(pointsC[2],noise)));
314 mol.addBond(0,1,IBond.Order.SINGLE);
315 mol.addBond(0,2,IBond.Order.SINGLE);
316 Fragment frag = new Fragment(mol, BBType.UNDEFINED);
317 frag.addAP(0, APClass.make("A:0"), getNoisyPoint(pointsC[3],noise));
318 frag.addAP(0, APClass.make("B:0"), getNoisyPoint(pointsC[4],noise));
321 sample.add(cf);
322 }
323
324 fc = new FragmentClusterer(sample,settings);
325 fc.cluster();
326 assertEquals(3,fc.getClusters().size());
327
328 Point3d[] pointsD = new Point3d[] {
329 new Point3d(5,0,0),
330 new Point3d(6.5,0,0),
331 new Point3d(8,0,0),
332 new Point3d(5,1,0),
333 new Point3d(0,0,0)};
334 for (int i=0; i<5; i++)
335 {
336 IAtomContainer mol = builder.newAtomContainer();
337 mol.addAtom(new Atom("C", getNoisyPoint(pointsD[0],noise)));
338 mol.addAtom(new Atom("H", getNoisyPoint(pointsD[1],noise)));
339 mol.addAtom(new Atom("O", getNoisyPoint(pointsD[2],noise)));
340 mol.addBond(0,1,IBond.Order.SINGLE);
341 mol.addBond(0,2,IBond.Order.SINGLE);
342 Fragment frag = new Fragment(mol, BBType.UNDEFINED);
343 frag.addAP(0, APClass.make("A:0"), getNoisyPoint(pointsD[3],noise));
344 frag.addAP(0, APClass.make("B:0"), getNoisyPoint(pointsD[4],noise));
347 sample.add(cf);
348 }
349
350 fc = new FragmentClusterer(sample,settings);
351 fc.cluster();
352 assertEquals(4,fc.getClusters().size());
353
354 Point3d[] pointsE = new Point3d[] {
355 new Point3d(5,0,0),
356 new Point3d(6.5,0,0),
357 new Point3d(8,0,0),
358 new Point3d(5,1,0),
359 new Point3d(7,0,0)};
360 for (int i=0; i<5; i++)
361 {
362 IAtomContainer mol = builder.newAtomContainer();
363 mol.addAtom(new Atom("C", getNoisyPoint(pointsE[0],noise)));
364 mol.addAtom(new Atom("H", getNoisyPoint(pointsE[1],noise)));
365 mol.addAtom(new Atom("O", getNoisyPoint(pointsE[2],noise)));
366 mol.addBond(0,1,IBond.Order.SINGLE);
367 mol.addBond(0,2,IBond.Order.SINGLE);
368 Fragment frag = new Fragment(mol, BBType.UNDEFINED);
369 frag.addAP(0, APClass.make("A:0"), getNoisyPoint(pointsE[3],noise));
370 frag.addAP(0, APClass.make("B:0"), getNoisyPoint(pointsE[4],noise));
373 sample.add(cf);
374 }
375
376 fc = new FragmentClusterer(sample,settings);
377 fc.cluster();
378 assertEquals(5,fc.getClusters().size());
379
380 Point3d[] pointsF = new Point3d[] {
381 new Point3d(4,0,0),
382 new Point3d(6.5,0,0),
383 new Point3d(8,0,0),
384 new Point3d(3,0,0),
385 new Point3d(7,0,0)};
386 for (int i=0; i<5; i++)
387 {
388 IAtomContainer mol = builder.newAtomContainer();
389 mol.addAtom(new Atom("C", getNoisyPoint(pointsF[0],noise)));
390 mol.addAtom(new Atom("H", getNoisyPoint(pointsF[1],noise)));
391 mol.addAtom(new Atom("O", getNoisyPoint(pointsF[2],noise)));
392 mol.addBond(0,1,IBond.Order.SINGLE);
393 mol.addBond(0,2,IBond.Order.SINGLE);
394 Fragment frag = new Fragment(mol, BBType.UNDEFINED);
395 frag.addAP(0, APClass.make("A:0"), getNoisyPoint(pointsF[3],noise));
396 frag.addAP(0, APClass.make("B:0"), getNoisyPoint(pointsF[4],noise));
399 sample.add(cf);
400 }
401
402 fc = new FragmentClusterer(sample,settings);
403 fc.cluster();
404 assertEquals(6,fc.getClusters().size());
405
406 List<Fragment> centroids = fc.getClusterCentroids();
407 List<DynamicCentroidCluster> clusters = fc.getClusters();
408 List<List<Fragment>> trnsClusters = fc.getTransformedClusters();
409 for (int iCluster=0; iCluster<centroids.size(); iCluster++)
410 {
411 assertEquals(trnsClusters.get(iCluster).size(),
412 clusters.get(iCluster).getPoints().size(),
413 "Number of members in the cluster and transformed cluster");
414 int numMembers = trnsClusters.get(iCluster).size();
415 for (int iMember=0; iMember<numMembers; iMember++)
416 {
417 Fragment centroid = centroids.get(iCluster);
418 ClusterableFragment clustFrag = clusters.get(
419 iCluster).getPoints().get(iMember);
420 Fragment trnsClustFrag = clusters.get(
421 iCluster).getPoints().get(iMember).getTransformedCopy();
422 Fragment trnsFrag = trnsClusters.get(iCluster).get(iMember);
423
424 int iPoint = 0;
425 for (IAtom atm : centroid.atoms())
426 {
427 // Check that the three points are effectively the same
428 Point3d trnsFragPt = trnsFrag.getAtom(iPoint).getPoint3d();
429 Point3d trnsCopyPt = trnsClustFrag.getAtom(iPoint).getPoint3d();
430 Point3d clustFragPt = ClusterableFragment.convertToPointArray(
431 clustFrag.allCoords)[iPoint];
432 assertTrue(trnsFragPt.distance(trnsCopyPt) < 0.001);
433 assertTrue(trnsFragPt.distance(clustFragPt) < 0.001);
434
435 // Check that the centroid is not too far.
436 // We expect the centroid to be somewhat close to the norm
437 // of the distortion distribution, but it is not spot-on
438 // because the number of samples in the uniform distribution
439 // is very limited.
440 // Therefore, we allow for an additional 50%
441 Point3d centroidPt = atm.getPoint3d();
442 assertTrue(centroidPt.distance(trnsFragPt) < noise*1.5);
443 // NB: no need to check trnsCopyPt and clustFragPt as we
444 // already know they are sufficiently close to each other.
445
446 iPoint++;
447 }
448 int iAP = 0;
449 for (AttachmentPoint ap : centroid.getAttachmentPoints())
450 {
451 // Check that the three points are effectively the same
452 Point3d trnsFragPt = trnsFrag.getAP(iAP).getDirectionVector();
453 Point3d trnsCopyPt = trnsClustFrag.getAP(iAP).getDirectionVector();
454 Point3d clustFragPt = ClusterableFragment.convertToPointArray(
455 clustFrag.allCoords)[iPoint];
456 assertTrue(trnsFragPt.distance(trnsCopyPt) < 0.001);
457 assertTrue(trnsFragPt.distance(clustFragPt) < 0.001);
458
459 Point3d centroidPt = ap.getDirectionVector();
460 assertTrue(centroidPt.distance(trnsFragPt) < noise*1.5);
461 // NB: no need to check trnsCopyPt and clustFragPt as we
462 // already know they are sufficiently close to each other.
463
464 iPoint++;
465 iAP++;
466 }
467 }
468 }
469
470 if (manualDebug)
471 {
472 ArrayList<Vertex> lstVrtx = new ArrayList<Vertex>();
473 for (ClusterableFragment cf : sample)
474 lstVrtx.add(cf.getOriginalFragment());
475 DenoptimIO.writeVertexesToFile(new File("/tmp/vertexes.sdf"),
476 FileFormat.VRTXSDF, lstVrtx, false);
477
478 for (int i=0; i<fc.getClusters().size(); i++)
479 {
480 ArrayList<IAtomContainer> mols = new ArrayList<IAtomContainer>();
481 for (ClusterableFragment cf : fc.getClusters().get(i).getPoints())
482 {
483 mols.add(getMol(cf.getTransformedCopy()));
484 }
485 DenoptimIO.writeSDFFile("/tmp/cluster_"+i+".sdf", mols);
486
487
488 ArrayList<IAtomContainer> molsTrs = new ArrayList<IAtomContainer>();
489 for (Fragment f : fc.getTransformedClusters().get(i))
490 {
491 molsTrs.add(getMol(f));
492 }
493 DenoptimIO.writeSDFFile("/tmp/cluster_"+i+"_trns.sdf", molsTrs);
494
495 IAtomContainer center = getMol(centroids.get(i));
496 DenoptimIO.writeSDFFile("/tmp/cluster_"+i+"_centroid.sdf", center);
497 }
498 }
499 }
500
501//------------------------------------------------------------------------------
502
507 private IAtomContainer getMol(Fragment frag)
508 {
509 IAtomContainer mol = builder.newAtomContainer();
510 for (IAtom a : frag.atoms())
511 mol.addAtom(new Atom(a.getSymbol(),a.getPoint3d()));
512 for (AttachmentPoint ap : frag.getAttachmentPoints())
513 mol.addAtom(new PseudoAtom("W",ap.getDirectionVector()));
514 return mol;
515 }
516
517//-----------------------------------------------------------------------------
518
519 @Test
520 public void testCluster2() throws Exception
521 {
522 double noise = 0.25;
523 // NB: the distortions are [-noise,noise] and is uniformely distributed
524 // So, the extreme cases have same probability of no distortion
525
526 List<ClusterableFragment> sample = new ArrayList<ClusterableFragment>();
527
528 Point3d[] points = new Point3d[] {
529 new Point3d(0,0,0),
530 new Point3d(1,0,0)};
531 for (int i=0; i<5; i++)
532 {
533 IAtomContainer mol = builder.newAtomContainer();
534 mol.addAtom(new Atom("C", getNoisyPoint(points[0],noise)));
535 Fragment frag = new Fragment(mol, BBType.UNDEFINED);
536 frag.addAP(0, APClass.make("A:0"), getNoisyPoint(points[1],noise));
539 sample.add(cf);
540 }
541
543 //settings.startConsoleLogger("ClustererTest");
544 //settings.setVerbosity(2);
545
546 FragmentClusterer fc = new FragmentClusterer(sample,settings);
547 fc.cluster();
548 assertEquals(1,fc.getClusters().size());
549
550
551 // Adding same points that are just placed elsewhere in space
552 points = new Point3d[] {
553 new Point3d(0,0,-1),
554 new Point3d(0,0,-2)};
555 for (int i=0; i<5; i++)
556 {
557 IAtomContainer mol = builder.newAtomContainer();
558 mol.addAtom(new Atom("C", getNoisyPoint(points[0],noise)));
559 Fragment frag = new Fragment(mol, BBType.UNDEFINED);
560 frag.addAP(0, APClass.make("A:0"), getNoisyPoint(points[1],noise));
563 sample.add(cf);
564 }
565 fc = new FragmentClusterer(sample,settings);
566 fc.cluster();
567 assertEquals(1,fc.getClusters().size());
568
569 // Add more clusters (each different from each other and the old ones)
570 for (int k=2; k<10; k++)
571 {
572 points = new Point3d[] {
573 new Point3d(k,0,0),
574 new Point3d(0,0,0)};
575 for (int i=0; i<5; i++)
576 {
577 IAtomContainer mol = builder.newAtomContainer();
578 mol.addAtom(new Atom("C", getNoisyPoint(points[0],noise)));
579 Fragment frag = new Fragment(mol, BBType.UNDEFINED);
580 frag.addAP(0, APClass.make("A:0"), getNoisyPoint(points[1],noise));
583 sample.add(cf);
584 }
585 fc = new FragmentClusterer(sample,settings);
586 fc.cluster();
587 assertEquals(k,fc.getClusters().size());
588 }
589
590 // Keep this code: it might be useful to look at the geometries.
591 /*
592 ArrayList<Vertex> lstVrtx = new ArrayList<Vertex>();
593 for (ClusterableFragment cf : sample)
594 lstVrtx.add(cf.getOriginalFragment());
595 DenoptimIO.writeVertexesToFile(new File("/tmp/cf.sdf"),
596 FileFormat.VRTXSDF, lstVrtx, false);
597 */
598 }
599
600//------------------------------------------------------------------------------
601
607 private Point3d getNoisyPoint(Point3d p, double noiseMagnitude)
608 {
609 Point3d noise = rng.getNoisyPoint(noiseMagnitude);
610 return new Point3d(p.x+noise.x, p.y+noise.y, p.z+noise.z);
611 }
612
613//------------------------------------------------------------------------------
614
615}
Represents a fragment that can be clustered based on the 3*N coordinate of atoms and attachment point...
double[] allCoords
Ordered list of coordinated reflecting the ordered list of atoms/APs.
void setNaturalNodeOrder()
Define the node order from the list of atoms and attachment points.
static Point3d[] convertToPointArray(double[] coords)
Converts an array of 3*N-dimensional coordinates into an array of 3-dimensional points assuming coord...
Distance in terms of RMSD between sets of 3D points expressed as a single vector of coordinates [x1,...
double compute(double[] coordsA, double[] coordsB)
List< Fragment > getClusterCentroids()
Once the clustering is done, this method return the list of cluster centroids.
static SummaryStatistics getRMSDStatsOfNoisyDistorsions(double[] center, int sampleSize, double maxNoise)
Computes statistics for a unimodal, normally noise-distorted population of points generated by distor...
void cluster()
Runs the clustering algorithm:
List< DynamicCentroidCluster > getClusters()
Once the clustering is done, this method return the list of resulting clusters.
List< List< Fragment > > getTransformedClusters()
Once the clustering is done, this method return the list of clusters.
Point3d getNoisyPoint(Point3d p, double noiseMagnitude)
The noise magnitude is to be interpreted as half of the overall magnitude.
IAtomContainer getMol(Fragment frag)
Converts the fragment into a collection of atoms where attachment points are converted into atoms tha...
IChemObjectBuilder builder
Private builder of atom containers.
Randomizer rng
Random number generator.
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
An attachment point (AP) is a possibility to attach a Vertex onto the vertex holding the AP (i....
Point3d getDirectionVector()
Returns the end of the direction vector.
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
List< AttachmentPoint > getAttachmentPoints()
Definition: Fragment.java:1120
Iterable< IAtom > atoms()
Definition: Fragment.java:822
IAtom getAtom(int number)
Definition: Fragment.java:843
AttachmentPoint getAP(int i)
Get attachment point i on this vertex.
Definition: Vertex.java:920
Utility methods for input/output.
static File writeVertexesToFile(File file, FileFormat format, List< Vertex > vertexes)
Writes vertexes to file.
static void writeSDFFile(String fileName, IAtomContainer mol)
Writes IAtomContainer to SDF file.
Logger startConsoleLogger(String loggerIdentifier)
Starts a program-specific logger that prints to System.err stream.
void setVerbosity(int l)
Set the level of verbosity.
Parameters controlling execution of the fragmenter.
Tool to generate random numbers and random decisions.
Definition: Randomizer.java:35
Point3d getNoisyPoint(double maxAbsValue)
Returns a point in three-dimensional space with a random set of coordinates, the absolute value of wh...
File formats identified by DENOPTIM.
Definition: FileFormat.java:32
The type of building block.
Definition: Vertex.java:86