$darkmode
DENOPTIM
PathSubGraphTest.java
Go to the documentation of this file.
1/*
2 * DENOPTIM
3 * Copyright (C) 2022 Marco Foscato <marco.foscato@uib.no>
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU Affero General Public License as published
7 * by the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Affero General Public License for more details.
14 *
15 * You should have received a copy of the GNU Affero General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19package denoptim.graph.rings;
20
21import static org.junit.jupiter.api.Assertions.assertEquals;
22
23import java.util.logging.Logger;
24
25import javax.vecmath.Point3d;
26
27import org.junit.jupiter.api.Test;
28import org.openscience.cdk.Atom;
29import org.openscience.cdk.Bond;
30import org.openscience.cdk.PseudoAtom;
31import org.openscience.cdk.interfaces.IAtom;
32import org.openscience.cdk.interfaces.IAtomContainer;
33import org.openscience.cdk.interfaces.IBond;
34import org.openscience.cdk.interfaces.IChemObjectBuilder;
35import org.openscience.cdk.silent.SilentChemObjectBuilder;
36
37import denoptim.exception.DENOPTIMException;
38import denoptim.graph.APClass;
39import denoptim.graph.DGraph;
40import denoptim.graph.Edge;
41import denoptim.graph.Edge.BondType;
42import denoptim.graph.Fragment;
43import denoptim.graph.Vertex.BBType;
44import denoptim.molecularmodeling.ThreeDimTreeBuilder;
45import denoptim.utils.Randomizer;
46
53public class PathSubGraphTest {
54
55 //------------------------------------------------------------------------------
69 public static DGraph makeTestGraphA() throws DENOPTIMException
70 {
71 APClass apc = APClass.make("A",0);
72
73 DGraph graph = new DGraph();
74
75 IChemObjectBuilder builder = SilentChemObjectBuilder.getInstance();
76
77 IAtomContainer iacA = builder.newAtomContainer();
78 IAtom iaA1 = new Atom("O",new Point3d(0,0,0));
79 IAtom iaA2 = new Atom("O",new Point3d(1,0,0));
80 iacA.addAtom(iaA1);
81 iacA.addAtom(iaA2);
82 iacA.addBond(new Bond(iaA1, iaA2, IBond.Order.SINGLE));
83 Fragment vA = new Fragment(0,iacA,BBType.FRAGMENT);
84 vA.addAP(0,new Point3d(0,-1,0),apc);
85 vA.addAP(1,new Point3d(2,0,0),apc);
86
87 IAtomContainer iacB = builder.newAtomContainer();
88 IAtom iaB1 = new Atom("C",new Point3d(0,0,0));
89 IAtom iaB2 = new Atom("C",new Point3d(1,0,0));
90 IAtom iaB3 = new Atom("C",new Point3d(1,-0.33,0));
91 IAtom iaB4 = new Atom("C",new Point3d(1,-0.66,0));
92 IAtom iaB5 = new Atom("C",new Point3d(1,-1,0));
93 IAtom iaB6 = new Atom("C",new Point3d(0,-1,0));
94 IAtom iaB7 = new Atom("C",new Point3d(0,-0.5,0));
95 iacB.addAtom(iaB1);
96 iacB.addAtom(iaB2);
97 iacB.addAtom(iaB3);
98 iacB.addAtom(iaB4);
99 iacB.addAtom(iaB5);
100 iacB.addAtom(iaB6);
101 iacB.addAtom(iaB7);
102 iacB.addBond(new Bond(iaB1, iaB2, IBond.Order.SINGLE));
103 iacB.addBond(new Bond(iaB2, iaB3, IBond.Order.SINGLE));
104 iacB.addBond(new Bond(iaB3, iaB4, IBond.Order.SINGLE));
105 iacB.addBond(new Bond(iaB4, iaB5, IBond.Order.SINGLE));
106 iacB.addBond(new Bond(iaB5, iaB6, IBond.Order.SINGLE));
107 iacB.addBond(new Bond(iaB6, iaB7, IBond.Order.SINGLE));
108 iacB.addBond(new Bond(iaB1, iaB7, IBond.Order.SINGLE));
109 Fragment vB = new Fragment(1,iacB,BBType.FRAGMENT);
110 vB.addAP(0,new Point3d(-1,0,0),apc);
111 vB.addAP(5,new Point3d(-1,-1,0),apc);
112 vB.addAP(6,new Point3d(1,1,0),apc);
113
114 IAtomContainer iacC = builder.newAtomContainer();
115 IAtom iaC1 = new Atom("N",new Point3d(0,0,0));
116 IAtom iaC2 = new Atom("N",new Point3d(-1,0,0));
117 IAtom iaC3 = new Atom("N",new Point3d(0,-1,0));
118 iacC.addAtom(iaC1);
119 iacC.addAtom(iaC2);
120 iacC.addAtom(iaC3);
121 iacC.addBond(new Bond(iaC1, iaC2, IBond.Order.SINGLE));
122 iacC.addBond(new Bond(iaC2, iaC3, IBond.Order.SINGLE));
123 iacC.addBond(new Bond(iaC1, iaC3, IBond.Order.SINGLE));
124 Fragment vC = new Fragment(2,iacC,BBType.FRAGMENT);
125 vC.addAP(0,new Point3d(1,0,0),apc);
126 vC.addAP(1,new Point3d(-1,1,0),apc);
127 vC.addAP(2,new Point3d(-1,-1,0),apc);
128
129 IAtomContainer iacG = builder.newAtomContainer();
130 IAtom iaG1 = new Atom("P",new Point3d(0,0,0));
131 IAtom iaG2 = new Atom("P",new Point3d(0,0,1));
132 IAtom iaG3 = new Atom("P",new Point3d(0,0,2));
133 iacG.addAtom(iaG1);
134 iacG.addAtom(iaG2);
135 iacG.addAtom(iaG3);
136 iacG.addBond(new Bond(iaG1, iaG2, IBond.Order.SINGLE));
137 iacG.addBond(new Bond(iaG2, iaG3, IBond.Order.SINGLE));
138 Fragment vG = new Fragment(5,iacG,BBType.FRAGMENT);
139 vG.addAP(0,new Point3d(1,0,0),apc);
140
141 IAtomContainer iacD = builder.newAtomContainer();
142 iacD.addAtom(new PseudoAtom("ATN",new Point3d(0,0,0)));
143 Fragment vD = new Fragment(3,iacD,BBType.FRAGMENT);
144 vD.addAP(0,new Point3d(-1,0,0),APClass.make("ATneutral",0));
145 vD.setAsRCV(true);
146
147 IAtomContainer iacE = builder.newAtomContainer();
148 iacE.addAtom(new PseudoAtom("ATN",new Point3d(0,0,0)));
149 Fragment vE = new Fragment(4,iacE,BBType.FRAGMENT);
150 vE.addAP(0, new Point3d(-1,0,0),APClass.make("ATneutral",0));
151 vE.setAsRCV(true);
152
153 graph.addVertex(vA);
154 graph.addVertex(vD);
155 graph.addVertex(vB);
156 graph.addVertex(vC);
157 graph.addVertex(vG);
158 graph.addVertex(vE);
159 graph.addEdge(new Edge(vA.getAP(0), vD.getAP(0), BondType.SINGLE));
160 graph.addEdge(new Edge(vA.getAP(1), vB.getAP(0), BondType.SINGLE));
161 graph.addEdge(new Edge(vB.getAP(1), vC.getAP(0), BondType.SINGLE));
162 graph.addEdge(new Edge(vC.getAP(2), vG.getAP(0), BondType.SINGLE));
163 graph.addEdge(new Edge(vC.getAP(1), vE.getAP(0), BondType.SINGLE));
164
165 return graph;
166 }
167
168//------------------------------------------------------------------------------
181 {
182 APClass apc = APClass.make("A",0,BondType.SINGLE);
183
184 DGraph graph = new DGraph();
185
186 IChemObjectBuilder builder = SilentChemObjectBuilder.getInstance();
187
188 IAtomContainer iacA = builder.newAtomContainer();
189 IAtom iaA1 = new Atom("O",new Point3d(0,0,0));
190 iacA.addAtom(iaA1);
191 Fragment vA = new Fragment(0,iacA,BBType.FRAGMENT);
192 vA.addAP(0,new Point3d(0,-1,0),apc);
193 vA.addAP(0,new Point3d(1,-1,0),apc);
194
195 IAtomContainer iacB = builder.newAtomContainer();
196 IAtom iaB1 = new Atom("C",new Point3d(0,0,0));
197 iacB.addAtom(iaB1);
198 Fragment vB = new Fragment(1,iacB,BBType.FRAGMENT);
199 vB.addAP(0,new Point3d(-1,0,0),apc);
200 vB.addAP(0,new Point3d(-1,-1,0),apc);
201
202 IAtomContainer iacC = builder.newAtomContainer();
203 IAtom iaC1 = new Atom("N",new Point3d(0,0,0));
204 iacC.addAtom(iaC1);
205 Fragment vC = new Fragment(2,iacC,BBType.FRAGMENT);
206 vC.addAP(0,new Point3d(1,0,0),apc);
207 vC.addAP(0,new Point3d(1,1,0),apc);
208
209 IAtomContainer iacG = builder.newAtomContainer();
210 IAtom iaG1 = new Atom("P",new Point3d(0,0,0));
211 iacG.addAtom(iaG1);
212 Fragment vG = new Fragment(5,iacG,BBType.FRAGMENT);
213 vG.addAP(0,new Point3d(1,0,0),apc);
214 vG.addAP(0,new Point3d(-1,1,0),apc);
215
216 IAtomContainer iacD = builder.newAtomContainer();
217 iacD.addAtom(new PseudoAtom("ATN",new Point3d(0,0,0)));
218 Fragment vD = new Fragment(3,iacD,BBType.FRAGMENT);
219 vD.addAP(0,new Point3d(-1,0,0),APClass.make("ATneutral",0));
220 vD.setAsRCV(true);
221
222 IAtomContainer iacE = builder.newAtomContainer();
223 iacE.addAtom(new PseudoAtom("ATN",new Point3d(0,0,0)));
224 Fragment vE = new Fragment(4,iacE,BBType.FRAGMENT);
225 vE.addAP(0, new Point3d(-1,0,0),APClass.make("ATneutral",0));
226 vE.setAsRCV(true);
227
228 graph.addVertex(vA);
229 graph.addVertex(vD);
230 graph.addVertex(vB);
231 graph.addVertex(vC);
232 graph.addVertex(vG);
233 graph.addVertex(vE);
234 graph.addEdge(new Edge(vA.getAP(0), vD.getAP(0), BondType.SINGLE));
235 graph.addEdge(new Edge(vA.getAP(1), vB.getAP(0), BondType.SINGLE));
236 graph.addEdge(new Edge(vB.getAP(1), vC.getAP(0), BondType.SINGLE));
237 graph.addEdge(new Edge(vC.getAP(1), vG.getAP(0), BondType.SINGLE));
238 graph.addEdge(new Edge(vG.getAP(1), vE.getAP(0), BondType.SINGLE));
239
240 // Use this just to verify identify of the graph
241 /*
242 ArrayList<DENOPTIMFragment> frags = new ArrayList<>();
243 frags.add(vA);
244 frags.add(vB);
245 frags.add(vC);
246 frags.add(vD);
247 frags.add(vE);
248 DenoptimIO.writeFragmentSet("/tmp/frags.sdf", frags);
249 System.out.println("WRITING TEST GRAPH B");
250 DenoptimIO.writeGraphsToFile(new File("/tmp/test_graph_B"),
251 FileFormat.GRAPHSDF,
252 new ArrayList<DENOPTIMGraph>(Arrays.asList(graph)));
253*/
254 return graph;
255 }
256
257//------------------------------------------------------------------------------
258
259 @Test
260 public void testMakePathSubGraph() throws Exception
261 {
262 DGraph gA = makeTestGraphA();
263 DGraph gB = makeTestGraphB();
264
265 Logger logger = Logger.getLogger("DummyLogger");
266 Randomizer rng = new Randomizer();
267
268 ThreeDimTreeBuilder t3d = new ThreeDimTreeBuilder(logger,rng);
269 t3d.setAlignBBsIn3D(false); //3D not needed
270 IAtomContainer molA = t3d.convertGraphTo3DAtomContainer(gA,true);
271 IAtomContainer molB = t3d.convertGraphTo3DAtomContainer(gB,true);
272
274 gA.getVertexAtPosition(5),gA);
275 pA.makeMolecularRepresentation(molA, false, logger, rng);
277 gB.getVertexAtPosition(5),gB);
278 pB.makeMolecularRepresentation(molB, false, logger, rng);
279
280 IAtomContainer iacA = pA.getMolecularRepresentation();
281 assertEquals(14,iacA.getAtomCount(), "Atom count in the path");
282
283 IAtomContainer iacB = pB.getMolecularRepresentation();
284 assertEquals(6,iacB.getAtomCount(), "Atom count in the path");
285 }
286
287//------------------------------------------------------------------------------
288
289}
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
Vertex getVertexAtPosition(int pos)
Returns the vertex that is in the given position of the list of vertices belonging to this graph.
Definition: DGraph.java:2514
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
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 setAsRCV(boolean isRCV)
Definition: Vertex.java:254
AttachmentPoint getAP(int i)
Get attachment point i on this vertex.
Definition: Vertex.java:920
This object represents a path in a DGraph.
void makeMolecularRepresentation(IAtomContainer mol, boolean make3D, Logger logger, Randomizer randomizer)
Creates the molecular representation, list of atoms and bonds involved in the path between the head a...
IAtomContainer getMolecularRepresentation()
Returns the molecular representation.
static DGraph makeTestGraphB()
Build a graph meant to be used in unit tests.
static DGraph makeTestGraphA()
Build a graph meant to be used in unit tests.
Tool to build build three-dimensional (3D) tree-like molecular structures from DGraph.
void setAlignBBsIn3D(boolean align)
Sets the flag that controls whether building blocks have to be aligned according to the AP vectors or...
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