$darkmode
DENOPTIM
ConformerExtractorTaskTest.java
Go to the documentation of this file.
1package denoptim.fragmenter;
2
3import static org.junit.jupiter.api.Assertions.assertEquals;
4
5import java.util.ArrayList;
6import java.util.List;
7import java.util.logging.Logger;
8
9import javax.vecmath.Point3d;
10
11import org.junit.jupiter.api.Test;
12import org.openscience.cdk.Atom;
13import org.openscience.cdk.interfaces.IAtom;
14import org.openscience.cdk.interfaces.IAtomContainer;
15import org.openscience.cdk.interfaces.IChemObjectBuilder;
16import org.openscience.cdk.silent.SilentChemObjectBuilder;
17
18import denoptim.constants.DENOPTIMConstants;
19import denoptim.graph.APClass;
20import denoptim.graph.AttachmentPoint;
21import denoptim.graph.Fragment;
22import denoptim.graph.Vertex.BBType;
23
28{
29
33 private IChemObjectBuilder builder = SilentChemObjectBuilder.getInstance();
34
35//-----------------------------------------------------------------------------
36
37 @Test
38 public void testExtractClusterableFragments() throws Exception
39 {
40 String isoFamId = "IdOfThisFamily";
41
42 IAtomContainer mol1 = builder.newAtomContainer();
43 mol1.addAtom(new Atom("C", new Point3d(0,0,0)));
44 mol1.addAtom(new Atom("H", new Point3d(1,1,1)));
45 mol1.addAtom(new Atom("O", new Point3d(3,1,1)));
46 Fragment frag1 = new Fragment(mol1, BBType.UNDEFINED);
47 frag1.addAP(0, APClass.make("A:0"), new Point3d(3,0,0));
48 frag1.addAP(1, APClass.make("B:0"), new Point3d(3,2,0));
50
51 Fragment frag1clone = frag1.clone();
53
54 IAtomContainer mol2 = builder.newAtomContainer();
55 mol2.addAtom(new Atom("O", new Point3d(3,1,1)));
56 mol2.addAtom(new Atom("H", new Point3d(1,1,1)));
57 mol2.addAtom(new Atom("C", new Point3d(0,0,0)));
58 Fragment frag2 = new Fragment(mol2, BBType.UNDEFINED);
59 frag2.addAP(1, APClass.make("B:0"), new Point3d(3,2,0));
60 frag2.addAP(2, APClass.make("A:0"), new Point3d(3,0,0));
62
63 IAtomContainer mol3 = builder.newAtomContainer();
64 mol3.addAtom(new Atom("O", new Point3d(1,3,1)));
65 mol3.addAtom(new Atom("H", new Point3d(1,1,1)));
66 mol3.addAtom(new Atom("C", new Point3d(0,0,0)));
67 Fragment frag3 = new Fragment(mol3, BBType.UNDEFINED);
68 frag3.addAP(1, APClass.make("B:0"), new Point3d(0,3,2));
69 frag3.addAP(2, APClass.make("A:0"), new Point3d(0,3,0));
71
72 IAtomContainer mol4 = builder.newAtomContainer();
73 mol4.addAtom(new Atom("C", new Point3d(0,0,0)));
74 Fragment frag4 = new Fragment(mol3, BBType.UNDEFINED);
75 frag4.addAP(0, APClass.make("dummy:0"), new Point3d(0,3,2));
77
78 IAtomContainer mol5 = builder.newAtomContainer();
79 mol5.addAtom(new Atom("O", new Point3d(1,3,1)));
80 mol5.addAtom(new Atom("H", new Point3d(1,1,1)));
81 mol5.addAtom(new Atom("C", new Point3d(0,0,0)));
82 Fragment frag5 = new Fragment(mol3, BBType.UNDEFINED);
83 frag5.addAP(1, APClass.make("B:0"), new Point3d(0,3,2));
84 frag5.addAP(2, APClass.make("A:0"), new Point3d(0,3,0));
86
87 List<IAtomContainer> lst = new ArrayList<IAtomContainer>();
88 lst.add(frag1.getIAtomContainer());
89 lst.add(frag1clone.getIAtomContainer());
90 lst.add(frag4.getIAtomContainer());
91 lst.add(frag2.getIAtomContainer());
92 lst.add(frag3.getIAtomContainer());
93 lst.add(frag5.getIAtomContainer());
94
95 List<ClusterableFragment> sample =
97 lst.iterator(), isoFamId, Logger.getLogger("DummyLog"));
98
99 // Not all are extracted: two have different isomorphic family ID.
100 assertEquals(4,sample.size());
101
102 // Order is given by the first fragment
103 int j=0;
104 for (IAtom atm : frag1.atoms())
105 {
106 assertEquals(atm.getSymbol(),
107 sample.get(0).getOrderedNodes().get(j).getLabel());
108 j++;
109 }
110 for (AttachmentPoint ap : frag1.getAttachmentPoints())
111 {
112 assertEquals(ap.getAPClass().toString(),
113 sample.get(0).getOrderedNodes().get(j).getLabel());
114 j++;
115 }
116
117 // All the others should have the same order of atoms/APs
118 for (ClusterableFragment cf : sample)
119 {
120 for (int i=0; i<cf.getOrderedNodes().size(); i++)
121 {
122 assertEquals(sample.get(0).getOrderedNodes().get(i).getLabel(),
123 cf.getOrderedNodes().get(i).getLabel());
124 }
125 }
126 }
127
128//-----------------------------------------------------------------------------
129
130}
General set of constants used in DENOPTIM.
static final Object ISOMORPHICFAMILYID
Property used to store the identifier of the family of isomorphic fragments that owns a fragment.
Represents a fragment that can be clustered based on the 3*N coordinate of atoms and attachment point...
Task that analyzes an isomorphic family of fragments to identify the most representative fragment (i....
static List< ClusterableFragment > extractClusterableFragments(Iterator< IAtomContainer > reader, String isomorphicFamilyId, Logger logger)
Analyzes all the entries provided by the iterator and extracts those that pertain the specified isomo...
IChemObjectBuilder builder
Private builder of atom containers.
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....
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
Fragment clone()
Returns a deep copy of this fragments.
Definition: Fragment.java:733
Iterable< IAtom > atoms()
Definition: Fragment.java:822
IAtomContainer getIAtomContainer()
Definition: Fragment.java:788
void setProperty(Object key, Object property)
Definition: Vertex.java:1148
The type of building block.
Definition: Vertex.java:86