$darkmode
DENOPTIM
ThreeDimTreeBuilderTest.java
Go to the documentation of this file.
1package denoptim.molecularmodeling;
2
3/*
4 * DENOPTIM
5 * Copyright (C) 2019 Vishwesh Venkatraman <vishwesh.venkatraman@ntnu.no>
6 * and Marco Foscato <marco.foscato@uib.no>
7 *
8 * This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU Affero General Public License as published
10 * by the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Affero General Public License for more details.
17 *
18 * You should have received a copy of the GNU Affero General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22import static org.junit.jupiter.api.Assertions.assertEquals;
23
24import java.util.ArrayList;
25import java.util.Arrays;
26import java.util.HashMap;
27import java.util.HashSet;
28import java.util.logging.Logger;
29
30import javax.vecmath.Point3d;
31
32import org.junit.jupiter.api.Test;
33import org.openscience.cdk.Atom;
34import org.openscience.cdk.PseudoAtom;
35import org.openscience.cdk.interfaces.IAtom;
36import org.openscience.cdk.interfaces.IAtomContainer;
37import org.openscience.cdk.silent.Bond;
38
39import denoptim.fragspace.FragmentSpace;
40import denoptim.fragspace.FragmentSpaceParameters;
41import denoptim.graph.APClass;
42import denoptim.graph.DGraph;
43import denoptim.graph.Edge;
44import denoptim.graph.Edge.BondType;
45import denoptim.graph.EmptyVertex;
46import denoptim.graph.Fragment;
47import denoptim.graph.Vertex;
48import denoptim.graph.Vertex.BBType;
49import denoptim.utils.Randomizer;
50
58{
59
60//------------------------------------------------------------------------------
61
62 @Test
63 public void testConversionTo3dTree() throws Exception
64 {
70
71 HashMap<APClass,ArrayList<APClass>> cpMap =
72 new HashMap<APClass,ArrayList<APClass>>();
73 cpMap.put(a0, new ArrayList<APClass>(Arrays.asList(a0, b0)));
74 HashMap<APClass,APClass> capMap = new HashMap<APClass,APClass>();
75 capMap.put(a0, h0);
76 HashSet<APClass> forbEnds = new HashSet<APClass>();
77 forbEnds.add(b0);
78
79
80 Fragment frg1 = new Fragment();
81 IAtom a1 = new Atom("C", new Point3d(new double[]{0.0, 0.0, 0.0}));
82 IAtom a2 = new Atom("C", new Point3d(new double[]{1.0, 0.0, 0.0}));
83 frg1.addAtom(a1);
84 frg1.addAtom(a2);
85 frg1.addBond(new Bond(a1, a2));
86 frg1.addAP(0, a0, new Point3d(new double[]{0.0, 0.0, 1.0}));
87 frg1.addAP(1, a0, new Point3d(new double[]{1.0, 1.0, 1.0}));
89
90 Fragment frg2 = new Fragment();
91 IAtom a3 = new Atom("C", new Point3d(new double[]{0.0, 0.0, 0.0}));
92 frg2.addAtom(a3);
93 frg2.addAP(0, a0, new Point3d(new double[]{0.0, 1.0, 1.0}));
94 frg2.addAP(0, b0, new Point3d(new double[]{0.0, 1.0, -1.0}));
96
97 Fragment frg3 = new Fragment();
98 IAtom a7 = new Atom("C", new Point3d(new double[]{2.0, 0.0, 0.0}));
99 IAtom a8 = new Atom("O", new Point3d(new double[]{3.0, 0.0, 0.0}));
100 frg3.addAtom(a7);
101 frg3.addAtom(a8);
102 frg3.addBond(new Bond(a7, a8));
103 frg3.addAP(0, a0, new Point3d(new double[]{2.0, 1.0, 1.0}));
104 frg3.addAP(0, a0, new Point3d(new double[]{2.0, 1.0, -1.0}));
105 frg3.addAP(0, b0, new Point3d(new double[]{3.0, 1.0, -1.0}));
107
108 Fragment rca1 = new Fragment();
109 IAtom a4 = new PseudoAtom("ATP", new Point3d(
110 new double[]{0.0, 0.0, 0.0}));
111 rca1.addAtom(a4);
112 rca1.addAP(0, ap0, new Point3d(new double[]{0.0, 1.0, 1.0}));
114
115 Fragment rca2 = new Fragment();
116 IAtom a5 = new PseudoAtom("ATM", new Point3d(
117 new double[]{1.0, 0.0, 0.0}));
118 rca2.addAtom(a5);
119 rca2.addAP(0, am0, new Point3d(new double[]{0.0, 1.0, 1.0}));
121
122 Fragment cap = new Fragment();
123 IAtom a6 = new Atom("H", new Point3d(new double[]{0.0, 0.0, 0.0}));
124 cap.addAtom(a6);
125 cap.addAP(0, h0, new Point3d(new double[]{0.0, 1.0, 1.0}));
127
128 ArrayList<Vertex> scaff = new ArrayList<Vertex>();
129 scaff.add(frg1);
130 ArrayList<Vertex> frags = new ArrayList<Vertex>();
131 frags.add(frg2);
132 frags.add(rca1);
133 frags.add(rca2);
134 frags.add(frg3);
135 ArrayList<Vertex> caps = new ArrayList<Vertex>();
136 caps.add(cap);
137
139 FragmentSpace fs = new FragmentSpace(fsp, scaff, frags, caps,
140 cpMap, capMap, forbEnds, cpMap);
142
143 DGraph g1 = new DGraph();
145 BBType.SCAFFOLD, fs);
147 BBType.FRAGMENT, fs);
149 BBType.FRAGMENT, fs);
151 BBType.FRAGMENT, fs);
152 g1.addVertex(v1);
153 g1.addVertex(v2);
154 g1.addVertex(v3);
155 g1.addVertex(v4);
156
157 Edge e1 = new Edge(v1.getAP(1), v2.getAP(0),
159 Edge e2 = new Edge(v2.getAP(1), v3.getAP(0),
161 Edge e3 = new Edge(v1.getAP(0), v4.getAP(0),
163 g1.addEdge(e1);
164 g1.addEdge(e2);
165 g1.addEdge(e3);
166
167 g1.addRing(v3, v4);
168
169 Logger logger = Logger.getLogger("DummyLogger");
170 Randomizer rng = new Randomizer();
171 ThreeDimTreeBuilder t3d = new ThreeDimTreeBuilder(logger, rng);
172
173 IAtomContainer mol = t3d.convertGraphTo3DAtomContainer(g1,false);
174 assertEquals(4, mol.getBondCount(), "Number of bonds without the "
175 + "cyclic one");
176 assertEquals(5, mol.getAtomCount(), "Number of atoms in cyclic molecule"
177 + " before forming ring");
178
179 mol = t3d.convertGraphTo3DAtomContainer(g1,true);
180 // NB: no RCAs anymore, so two atoms less than before (the RCAs),
181 // and two bonds less than the moment when we have made
182 // the ring-closing bond but we have not yet removed the RCAs.
183 // Basically we add 1 bond and remove 2.
184 assertEquals(3, mol.getBondCount(), "Number of bonds, including the "
185 + "cyclic one");
186 assertEquals(3, mol.getAtomCount(), "Number of atoms in cyclic "
187 + "molecule after removal of RCAs");
188
189
190 DGraph g2 = new DGraph();
192 BBType.SCAFFOLD, fs);
194 BBType.FRAGMENT, fs);
196 BBType.FRAGMENT, fs);
198 BBType.FRAGMENT, fs);
199 g2.addVertex(v1b);
200 g2.addVertex(v2b);
201 g2.addVertex(v3b);
202 g2.addVertex(v4b);
203
204 Edge e1b = new Edge(v1b.getAP(1), v2b.getAP(0),
206 Edge e2b = new Edge(v2b.getAP(1), v3b.getAP(0),
208 Edge e3b = new Edge(v1b.getAP(0), v4b.getAP(0),
210 g2.addEdge(e1b);
211 g2.addEdge(e2b);
212 g2.addEdge(e3b);
213
214 IAtomContainer acyclicMol = t3d.convertGraphTo3DAtomContainer(
215 g2,true);
216 assertEquals(4, acyclicMol.getBondCount(), "Number of bonds in acyclic "
217 + "graph with RCAs");
218 assertEquals(5, acyclicMol.getAtomCount(), "Number of atoms in acyclic "
219 + "molecule before forming ring");
220
221
222 DGraph g3 = new DGraph();
223 EmptyVertex v1c = new EmptyVertex(1);
224 v1c.addAP(a0);
225 v1c.addAP(a0);
227 BBType.FRAGMENT, fs);
229 BBType.FRAGMENT, fs);
231 BBType.FRAGMENT, fs);
232 g3.addVertex(v1c);
233 g3.addVertex(v2c);
234 g3.addVertex(v3c);
235 g3.addVertex(v4c);
236
237 Edge e1c = new Edge(v1c.getAP(1), v2c.getAP(0),
239 Edge e2c = new Edge(v2c.getAP(1), v3c.getAP(0),
241 Edge e3c = new Edge(v1c.getAP(0), v4c.getAP(0),
243 g3.addEdge(e1c);
244 g3.addEdge(e2c);
245 g3.addEdge(e3c);
246
247 IAtomContainer molFromEmptyScaff = t3d.convertGraphTo3DAtomContainer(
248 g3,true);
249 assertEquals(1, molFromEmptyScaff.getBondCount(), "Number of bonds in "
250 + "mol with empty scaffold");
251 assertEquals(3, molFromEmptyScaff.getAtomCount(), "Number of atoms in "
252 + "mol with empty scaffold");
253
254
255 DGraph g4 = new DGraph();
256 EmptyVertex v1d = new EmptyVertex(1);
257 v1d.addAP(a0);
258 v1d.addAP(a0);
259 EmptyVertex v2d = new EmptyVertex(2);
260 v2d.addAP(a0);
261 v2d.addAP(b0);
263 BBType.FRAGMENT, fs);
265 BBType.FRAGMENT, fs);
266 EmptyVertex v5d = new EmptyVertex(5);
267 v5d.addAP(b0);
268 v5d.addAP(b0);
270 BBType.FRAGMENT, fs);
272 BBType.FRAGMENT, fs);
273 g4.addVertex(v1d);
274 g4.addVertex(v2d);
275 g4.addVertex(v3d);
276 g4.addVertex(v4d);
277 g4.addVertex(v5d);
278 g4.addVertex(v6d);
279 g4.addVertex(v7d);
280
281 Edge e1d = new Edge(v1d.getAP(1), v2d.getAP(0),
283 Edge e2d = new Edge(v2d.getAP(1), v7d.getAP(1),
285 Edge e3d = new Edge(v1d.getAP(0), v3d.getAP(0),
287 Edge e4d = new Edge(v3d.getAP(1), v4d.getAP(0),
289 Edge e5d = new Edge(v3d.getAP(2), v5d.getAP(1),
291 Edge e6d = new Edge(v5d.getAP(0), v6d.getAP(1),
293 g4.addEdge(e1d);
294 g4.addEdge(e2d);
295 g4.addEdge(e3d);
296 g4.addEdge(e4d);
297 g4.addEdge(e5d);
298 g4.addEdge(e6d);
299
300 IAtomContainer molWithEmptyNodes = t3d.convertGraphTo3DAtomContainer(
301 g4,true);
302 assertEquals(2, molWithEmptyNodes.getBondCount(), "Number of bonds in "
303 + "mol with empty scaffold and other nodes");
304 assertEquals(5, molWithEmptyNodes.getAtomCount(), "Number of atoms in "
305 + "mol with empty scaffold and other nodes");
306 }
307
308//------------------------------------------------------------------------------
309
310}
Class defining a space of building blocks.
void setAPclassBasedApproach(boolean useAPC)
Set the fragment space to behave according to APClass-based approach.
Parameters defining the fragment space.
static final APClass RCACLASSPLUS
Conventional class of attachment points on ring-closing vertexes.
Definition: APClass.java:84
static final APClass RCACLASSMINUS
Conventional class of attachment points on ring-closing vertexes.
Definition: APClass.java:91
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
Container for the list of vertices and the edges that connect them.
Definition: DGraph.java:102
void addVertex(Vertex vertex)
Appends a vertex to this graph without creating any edge.
Definition: DGraph.java:1097
void addRing(Ring ring)
Definition: DGraph.java:1030
void addEdge(Edge edge)
Adds the edge to the list of edges belonging to this graph.
Definition: DGraph.java:1021
This class represents the edge between two vertices.
Definition: Edge.java:38
An empty vertex has the behaviors of a vertex, but has no molecular structure.
void addAP()
Adds an attachment point with no APClass or other attribute.
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
void addBond(IBond bond)
Definition: Fragment.java:871
void addAtom(IAtom atom)
Definition: Fragment.java:836
void projectAPsToProperties()
Finds the DENOPTIMAttachmentPoint objects defined as properties of the atoms in this container,...
Definition: Fragment.java:693
A vertex is a data structure that has an identity and holds a list of AttachmentPoints.
Definition: Vertex.java:61
AttachmentPoint getAP(int i)
Get attachment point i on this vertex.
Definition: Vertex.java:920
static Vertex newVertexFromLibrary(int bbId, Vertex.BBType bbt, FragmentSpace fragSpace)
Builds a new molecular fragment kind of vertex.
Definition: Vertex.java:214
Tool to build build three-dimensional (3D) tree-like molecular structures from DGraph.
IAtomContainer convertGraphTo3DAtomContainer(DGraph graph)
Created a three-dimensional molecular representation from a given DGraph.
Tool to generate random numbers and random decisions.
Definition: Randomizer.java:35
Possible chemical bond types an edge can represent.
Definition: Edge.java:303
The type of building block.
Definition: Vertex.java:86