3import static org.junit.jupiter.api.Assertions.assertEquals;
4import static org.junit.jupiter.api.Assertions.assertFalse;
5import static org.junit.jupiter.api.Assertions.assertNotEquals;
6import static org.junit.jupiter.api.Assertions.assertNull;
7import static org.junit.jupiter.api.Assertions.assertTrue;
28import java.util.ArrayList;
31import javax.vecmath.Point3d;
33import org.junit.jupiter.api.Test;
34import org.openscience.cdk.Atom;
35import org.openscience.cdk.silent.Bond;
37import denoptim.constants.DENOPTIMConstants;
38import denoptim.graph.Edge.BondType;
39import denoptim.graph.Vertex.BBType;
49 private final String
APRULE =
"MyRule";
52 + DENOPTIMConstants.SEPARATORAPPROPSCL +
APSUBRULE;
53 private final Point3d
DIRVEC =
new Point3d(1.1, 2.2, 3.3);
60 String[] altStrings = {
61 "123#myrule:0:DOUBLE:1.0%2.0%-3.0",
62 "123#myrule:0:1.0%2.0%-3.0",
63 "123#myrule:0:UNDEFINED",
72 boolean[] check3d = {
true,
true,
false,
false};
74 for (
int i=0; i< altStrings.length; i++)
78 assertTrue(Integer.class.isInstance(o[0]));
79 int atmId = (int) o[0];
80 assertEquals(122, atmId);
82 assertTrue(o[1] instanceof
APClass);
89 assertTrue(o[2] instanceof Point3d);
90 Point3d p3d = (Point3d)o[2];
92 assertTrue(Math.abs(p3d.x - 1.0) < thrl);
93 assertTrue(Math.abs(p3d.y - 2.0) < thrl);
94 assertTrue(Math.abs(p3d.z + 3.0) < thrl);
96 assertEquals(
null,o[2]);
127 int[] expected1 = {6,5,4,3,2,1};
132 assertTrue(deepAPs1.contains(srcAP1),
"srcAP is deep");
133 assertTrue(trgAP1==vB1.
getAP(0),
"trgAP is on surface");
136 List<Vertex> addedVertexes1 =
new ArrayList<Vertex>();
137 addedVertexes1.add(vB1);
138 for (
int i=1; i<6; i++)
145 addedVertexes1.add(vNew);
150 assertTrue(deepAPs1.contains(srcAP1),
"srcAP is deep");
151 assertTrue(trgAP1==vNew.
getAP(0),
"trgAP is on surface");
154 template.setInnerGraph(gNew);
160 int nTotAvailAPs1 = 0;
161 int correntLinks1 = 0;
164 if (deepAP.isAvailableThroughout())
168 Vertex linkedOwner = deepAP.getLinkedAPThroughout().getOwner();
169 if (addedVertexes1.contains(linkedOwner))
173 assertEquals(1,nTotAvailAPs1,
"total number deep available");
174 assertEquals(addedVertexes1.size(),correntLinks1,
"number links to layers");
205 int[] expected2 = {6,5,4,3,2,1};
210 assertTrue(deepAPs2.contains(trgAP2),
"trgAP is deep");
211 assertTrue(srcAP2==vB2.
getAP(0),
"srcAP is on surface");
214 List<Vertex> addedVertexes2 =
new ArrayList<Vertex>();
215 addedVertexes2.add(vB2);
216 for (
int i=1; i<6; i++)
227 addedVertexes2.add(vNew);
232 assertTrue(deepAPs2.contains(trgAP2),
"trgAP is deep");
233 assertTrue(srcAP2==vNew.
getAP(0),
"srcAP is on surface");
236 template.setInnerGraph(gNew);
242 int nTotAvailAPs = 0;
243 int correntLinks = 0;
246 if (deepAP.isAvailableThroughout())
250 Vertex linkedOwner = deepAP.getLinkedAPThroughout().getOwner();
251 if (addedVertexes2.contains(linkedOwner))
255 assertEquals(1,nTotAvailAPs,
"total number deep available");
256 assertEquals(addedVertexes2.size(),correntLinks,
"number links to layers");
262 List<AttachmentPoint> deepAPs,
Vertex v)
268 if (deepAPs.contains(ap))
274 assertEquals(expectedMAtches,nfound,
"number of deep-traced APs");
301 int[] expectedN = {6,6,6,6};
302 int[] expectedNThroughout = {6,5,4,3};
304 checkAvailNT(expectedN[0], expectedNThroughout[0], 0, vA);
307 for (
int i=1; i<4; i++)
315 template.setInnerGraph(gNew);
316 checkAvailNT(expectedN[i], expectedNThroughout[i], i, vA);
329 if (apA.isAvailable())
331 if (apA.isAvailableThroughout())
334 assertEquals(expN,n,
"Number of level-available ("+level+
"");
335 assertEquals(expNTm,nThroughout,
"Number of throughout-available ("+level+
")");
355 List<Vertex> newVrtxs =
new ArrayList<Vertex>();
358 for (
int i=0; i<5; i++)
367 template.setInnerGraph(gNew);
382 assertTrue(apA.isAvailable(),
"APs of vA are all free within the "
383 +
"graph owning vA.");
384 Edge e = apA.getEdgeUserThroughout();
393 inAP = ((
Template) src).getInnerAPFromOuterAP(
399 assertEquals(apA,inAP,
"Src AP identity");
400 assertEquals(onion.get(i).getAP(0),e.
getTrgAP(),
"Trg AP identity");
424 assertTrue(ap1A.
isSrcInUser(),
"Check AP used as src.");
425 assertFalse(ap2B.
isSrcInUser(),
"Check AP used as trg.");
426 assertFalse(ap1B.
isSrcInUser(),
"Check AP free on src side.");
427 assertFalse(ap2A.
isSrcInUser(),
"Check AP free on trg side.");
449 assertTrue(ap1A.
getLinkedAP() == ap2B,
"Get AP on other side of ap1A");
450 assertTrue(ap2B.
getLinkedAP() == ap1A,
"Get AP on other dice of ap2");
451 assertNull(ap1B.
getLinkedAP(),
"Free AP 1B should return null");
452 assertNull(ap2A.
getLinkedAP(),
"Free AP 2A should return null");
461 dummyVertex.
addAtom(
new Atom(
"C"));
479 dummyVertex.
addAtom(
new Atom(
"C"));
503 dummyVertex.
addAtom(
new Atom(
"C"));
504 dummyVertex.
addAtom(
new Atom(
"C"));
505 dummyVertex.
addAtom(
new Atom(
"C"));
506 dummyVertex.
addAtom(
new Atom(
"C"));
507 dummyVertex.
addAtom(
new Atom(
"C"));
508 dummyVertex.
addAtom(
new Atom(
"C"));
509 dummyVertex.
addAtom(
new Atom(
"C"));
510 dummyVertex.
addAP(0);
511 dummyVertex.
addAP(0);
521 dummyVertex.
addAP(5,
new Point3d(1.1, 2.2, 3.3),
525 dummyVertex.
addAP(5,
new Point3d(2.2, 2.2, 3.3),
533 assertEquals(list.get(0),ap1);
534 assertEquals(list.get(1),ap2);
535 assertEquals(list.get(2),ap3);
536 assertEquals(list.get(3),ap4);
537 assertEquals(list.get(4),ap5);
538 assertEquals(list.get(5),ap6);
556 assertEquals(-1,apA.
compareTo(apB),
"Comparison driven by ID.");
557 assertTrue(apA.
sameAs(apAc),
"SameAs ignores ID.");
558 assertTrue(apB.
sameAs(apBc),
"SameAs ignores ID (2).");
572 assertFalse(apA.
sameAs(apB));
588 assertFalse(apA.
sameAs(apAc));
605 Point3d p3d =
new Point3d(0.1, 0.2, -0.3);
617 assertNotEquals(orig.
getID(),clone.
getID(),
"ID");
620 assertEquals(e,orig.
getEdgeUser(),
"Edge user in original");
621 assertEquals(
null,clone.
getEdgeUser(),
"Edge user in clone");
631 Atom a1 =
new Atom(
"C");
632 Atom a2 =
new Atom(
"C");
633 Atom a3 =
new Atom(
"C");
683 Atom a1 =
new Atom(
"C");
684 Atom a2 =
new Atom(
"C");
685 Atom a3 =
new Atom(
"C");
762 "Through edge intra-template (A)");
764 "Through edge intra-template (B)");
766 "Through edge intra-template (C)");
768 "Through edge intra-template (D)");
796 "Through deep edge (A)");
798 "Through deep edge (B)");
General set of constants used in DENOPTIM.
static final String SEPARATORAPPROPAAP
Separator between atom index and APClass in molecular property.
static final BondType DEFAULTBT
Default bond type for all but APClasses of RCVs.
static APClass make(String ruleAndSubclass)
Creates an APClass if it does not exist already, or returns the reference to the existing instance.
Comparator for DENOPTIMAttachmentPoints.
An attachment point (AP) is a possibility to attach a Vertex onto the vertex holding the AP (i....
AttachmentPoint getLinkedAP()
Gets the attachment point (AP) that is connected to this AP via the edge user.
AttachmentPoint getEmbeddedAP()
For vertices that are templates this method returns the attachment point that is embedded in the temp...
void setAPClass(String apClass)
Set the Attachment Point class.
APClass getAPClass()
Returns the Attachment Point class.
void setDirectionVector(Point3d dirVec)
Sets the end of the 3D vector defining the direction of the AP in 3D.
int getID()
Returns a unique integer that is used to sort list of attachment points.
int getAtomPositionNumber()
The index of the source atom in the atom list of the fragment.
static Object[] processSdfString(String str)
Parses the string format used to record one attachment point in SDF files.
AttachmentPoint clone()
Returns a deep clone of this attachment point.
Point3d getDirectionVector()
Returns the end of the direction vector.
boolean hasConnectedSrcAtom(AttachmentPoint other)
Checks if this and another APs are rooted on atoms that are bonded in any way other than a possible c...
boolean isSrcInUser()
Checks the role of this AP in the user.
boolean sameAs(AttachmentPoint other)
Compares the features of this and another attachment point and decides if the two are same.
boolean hasSameSrcAtom(AttachmentPoint other)
String getSingleAPStringSDF(boolean isFirst, int srcAtmID)
Prepare a string for writing this AP in a fragment SDF file.
int compareTo(AttachmentPoint other)
Compares this and another attachment points based on their unique identifier.
Edge getEdgeUser()
Gets the edge that is using this AP, or null if no edge is using this AP.
String toStringNoId()
Produces a string with the information included in this object.
Unit test for DENOPTIMAttachmentPoint.
void checkGetEdgeUserThroughput(Vertex v, List< Vertex > onion)
void checkIdentityOfEmbeddedAP(int expectedMAtches, List< AttachmentPoint > deepAPs, Vertex v)
void testHasSameSrcAtom()
void testParsingofSdfAPString()
void checkAvailNT(int expN, int expNTm, int level, Vertex v)
void testConstructorsAndSDFStringNoDirVec()
void testGetEdbeUserThrougout()
void testAvailableThrougout()
void testSameAs_DiffSrcAtm()
void testSameAs_DiffAPClass()
void testHasConnectedSrcAtom()
void testConstructorsAndSDFString()
Container for the list of vertices and the edges that connect them.
Edge getEdgeAtPosition(int pos)
void addVertex(Vertex vertex)
Appends a vertex to this graph without creating any edge.
void appendVertexOnAP(AttachmentPoint srcAP, AttachmentPoint trgAP)
Append a vertex to this graph: adds the new vertex to the list of vertices belonging to the graph,...
void addEdge(Edge edge)
Adds the edge to the list of edges belonging to this graph.
This class represents the edge between two vertices.
AttachmentPoint getSrcAPThroughout()
AttachmentPoint getTrgAP()
AttachmentPoint getSrcAP()
AttachmentPoint getTrgAPThroughout()
An empty vertex has the behaviors of a vertex, but has no molecular structure.
EmptyVertex clone()
Returns a deep-copy of this vertex.
List< AttachmentPoint > getAttachmentPoints()
void addAP()
Adds an attachment point with no APClass or other attribute.
Class representing a continuously connected portion of chemical object holding attachment points.
void addAP(int atomPositionNumber)
Adds an attachment point with a dummy APClass.
AttachmentPoint addAPOnAtom(IAtom srcAtm, APClass apc, Point3d vector)
Add an attachment point to the specifies atom.
List< AttachmentPoint > getAttachmentPoints()
Fragment clone()
Returns a deep copy of this fragments.
void setInnerGraph(DGraph innerGraph)
Template clone()
Returns a deep copy of this template.
A vertex is a data structure that has an identity and holds a list of AttachmentPoints.
void setVertexId(long vertexId2)
abstract List< AttachmentPoint > getAttachmentPoints()
AttachmentPoint getAP(int i)
Get attachment point i on this vertex.
Possible chemical bond types an edge can represent.
The type of building block.