21import static org.junit.jupiter.api.Assertions.assertEquals;
22import static org.junit.jupiter.api.Assertions.assertNotEquals;
23import static org.junit.jupiter.api.Assertions.assertTrue;
25import javax.vecmath.Point3d;
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;
37import com.google.gson.Gson;
39import denoptim.graph.Fragment;
40import denoptim.graph.FragmentTest;
41import denoptim.graph.Template;
42import denoptim.graph.TemplateTest;
43import denoptim.graph.Vertex;
44import denoptim.graph.Vertex.BBType;
45import denoptim.utils.MoleculeUtils;
46import denoptim.utils.MutationType;
56 private IChemObjectBuilder
builder = SilentChemObjectBuilder.getInstance();
63 IAtomContainer iac =
builder.newAtomContainer();
64 IAtom a1 =
new Atom(
"H");
65 a1.setPoint3d(
new Point3d(2.624, -4.243, 6.465));
66 IAtom a2 =
new Atom(
"Ru");
67 a2.setPoint3d(
new Point3d(-0.001, 23.943, -0.115));
68 IAtom a3 =
new PseudoAtom(
"RCA");
69 a3.setPoint3d(
new Point3d(0.0, 0.0, 0.0));
73 iac.addBond(
new Bond(a1, a2, IBond.Order.SINGLE));
74 iac.addBond(
new Bond(a1, a3, IBond.Order.TRIPLE));
75 iac.addBond(
new Bond(a2, a3, IBond.Order.UNSET));
78 String jsonString = jsonWriter.toJson(iac);
83 IAtomContainer iacFromJSON = jsonReader.fromJson(jsonString,
84 IAtomContainer.class);
86 assertEquals(iac.getAtomCount(),iacFromJSON.getAtomCount(),
"#Atoms");
87 assertEquals(iac.getBondCount(),iacFromJSON.getBondCount(),
"#Bonds");
88 for (
int i=0; i<iac.getAtomCount(); i++)
90 IAtom atmOri = iac.getAtom(i);
91 IAtom atmJsn = iacFromJSON.getAtom(i);
99 for (
int i=0; i<iac.getBondCount(); i++)
101 IBond bndOri = iac.getBond(i);
102 IBond bndJsn = iacFromJSON.getBond(i);
103 assertEquals(iac.indexOf(bndOri.getAtom(0)),
104 iacFromJSON.indexOf(bndJsn.getAtom(0)),
105 "1st atom in bond "+i);
106 assertEquals(iac.indexOf(bndOri.getAtom(1)),
107 iacFromJSON.indexOf(bndJsn.getAtom(1)),
108 "2nd atom in bond "+i);
109 assertEquals(bndOri.getOrder(),bndJsn.getOrder(),
126 String jsonString = jsonWriter.toJson(tmpl);
138 "Number of APs (B)");
141 "Number of symmetric sets");
144 assertEquals(tmpl.
isRCV(), tmplFromJSON.
isRCV(),
146 assertNotEquals(tmpl.hashCode(), tmplFromJSON.hashCode(),
150 "Building block ID");
153 "Building block type");
158 IAtom atmOri = iac.getAtom(i);
159 IAtom atmJsn = iacFromJSON.getAtom(i);
167 for (
int i=0; i<iac.getBondCount(); i++)
169 IBond bndOri = iac.getBond(i);
170 IBond bndJsn = iacFromJSON.getBond(i);
171 assertEquals(iac.indexOf(bndOri.getAtom(0)),
172 iacFromJSON.indexOf(bndJsn.getAtom(0)),
173 "1st atom in bond "+i);
174 assertEquals(iac.indexOf(bndOri.getAtom(1)),
175 iacFromJSON.indexOf(bndJsn.getAtom(1)),
176 "2nd atom in bond "+i);
177 assertEquals(bndOri.getOrder(),bndJsn.getOrder(),
194 String jsonString = jsonWriter.toJson(frag);
205 ((
Fragment) fragFromJSON).getAPCountOnAtom(0),
208 ((
Fragment) fragFromJSON).getAPCountOnAtom(2),
212 "Number of APs (B)");
215 "Number of symmetric sets");
218 "Number of symmetric APs in set");
221 assertEquals(frag.
isRCV(), fragFromJSON.
isRCV(),
223 assertNotEquals(frag.hashCode(), fragFromJSON.hashCode(),
227 "Building block ID");
230 "Building block type");
235 IAtom atmOri = iac.getAtom(i);
236 IAtom atmJsn = iacFromJSON.getAtom(i);
244 for (
int i=0; i<iac.getBondCount(); i++)
246 IBond bndOri = iac.getBond(i);
247 IBond bndJsn = iacFromJSON.getBond(i);
248 assertEquals(iac.indexOf(bndOri.getAtom(0)),
249 iacFromJSON.indexOf(bndJsn.getAtom(0)),
250 "1st atom in bond "+i);
251 assertEquals(iac.indexOf(bndOri.getAtom(1)),
252 iacFromJSON.indexOf(bndJsn.getAtom(1)),
253 "2nd atom in bond "+i);
254 assertEquals(bndOri.getOrder(),bndJsn.getOrder(),
263 double delta = 0.0000001;
264 return Math.abs(a-b) <= delta;
Class representing a continuously connected portion of chemical object holding attachment points.
int getAPCountOnAtom(int srcAtmId)
Returns the number of APs currently defined on a specific atom source.
List< AttachmentPoint > getAttachmentPoints()
IAtomContainer getIAtomContainer()
List< SymmetricAPs > getSymmetricAPSets()
Unit test for DENOPTIMFragment.
static Fragment makeFragment()
ArrayList< AttachmentPoint > getAttachmentPoints()
Return the list of attachment points visible from outside the template, i.e., the so-called outer APs...
List< SymmetricAPs > getSymmetricAPSets()
The SymmetricSet produced from this method contain indexes of the AttachmentPoints in the list return...
IAtomContainer getIAtomContainer()
The molecular representation, if any, is generated by this method and stored until further changes in...
Unit test for DENOPTIMTemplate.
static Template getTestAmideTemplate()
Builds a template object meant for tests.
A vertex is a data structure that has an identity and holds a list of AttachmentPoints.
int getBuildingBlockId()
Returns the index of the building block that should correspond to the position of the building block ...
Vertex.BBType getBuildingBlockType()
abstract List< AttachmentPoint > getAttachmentPoints()
void setBuildingBlockId(int buildingBlockId)
abstract List< SymmetricAPs > getSymmetricAPSets()
static Vertex fromJson(String json)
boolean removeMutationType(MutationType mt)
Removes the specified mutation type.
void setBuildingBlockType(Vertex.BBType buildingBlockType)
abstract IAtomContainer getIAtomContainer()
Class for de/serializing DENOPTIM graphs from/to JSON format.
Unit test for DENOPTIMgson.
IChemObjectBuilder builder
boolean areCloseEnough(double a, double b)
void testTemplateSerialization()
void testIAtomContainerToJSONAndBack()
void testMolecularFragmentSerialization()
Utilities for molecule conversion.
static String getSymbolOrLabel(IAtom atm)
Gets either the elemental symbol (for standard atoms) of the label (for pseudo-atoms).
static Point3d getPoint3d(IAtom atm)
Return the 3D coordinates, if present.
The type of building block.
Types of mutation defined in relation to what happens to the target vertex (i.e., the actual mutation...
CHANGELINK
Replace the target vertex keeping all the child structure.
CHANGEBRANCH
Replace the target vertex and any of the child vertices.