20package denoptim.graph;
22import java.lang.reflect.Type;
23import java.util.ArrayList;
24import java.util.Arrays;
25import java.util.Collection;
26import java.util.HashMap;
27import java.util.HashSet;
31import java.util.logging.Level;
32import java.util.logging.Logger;
34import org.openscience.cdk.interfaces.IAtomContainer;
36import com.google.gson.Gson;
37import com.google.gson.JsonDeserializationContext;
38import com.google.gson.JsonDeserializer;
39import com.google.gson.JsonElement;
40import com.google.gson.JsonObject;
41import com.google.gson.JsonParseException;
42import com.google.gson.JsonSyntaxException;
44import denoptim.constants.DENOPTIMConstants;
45import denoptim.exception.DENOPTIMException;
46import denoptim.fragspace.FragmentSpace;
47import denoptim.graph.rings.RingClosingAttractor;
48import denoptim.json.DENOPTIMgson;
49import denoptim.logging.StaticLogger;
50import denoptim.utils.GraphUtils;
51import denoptim.utils.MutationType;
52import denoptim.utils.Randomizer;
61public abstract class Vertex implements Cloneable
88 UNDEFINED, SCAFFOLD, FRAGMENT,
CAP, NONE;
161 new ArrayList<MutationType>(Arrays.asList(
MutationType.values()));
239 Vertex v = fragSpace.getVertexFromLibrary(bbt,bbId);
264 List<AttachmentPoint> list =
new ArrayList<AttachmentPoint>();
267 if (ap.getAPClass().toString().startsWith(root))
284 this.vertexId = vertexId2;
358 if (symmetricSet.contains(ap))
380 if (ap.isAvailable())
405 ArrayList<AttachmentPoint> lst =
406 new ArrayList<AttachmentPoint>();
409 if (ap.isAvailableThroughout())
451 ArrayList<AttachmentPoint> lst =
452 new ArrayList<AttachmentPoint>();
455 if (!ap.isAvailable())
485 ArrayList<AttachmentPoint> lst =
486 new ArrayList<AttachmentPoint>();
489 if (!ap.isAvailableThroughout())
525 if (ap.isAvailableThroughout())
587 if (ap.isAvailableThroughout())
672 return sameAs(other,
new StringBuilder());
687 if (this.getClass() == other.getClass())
696 }
else if (
this instanceof
Template) {
700 System.err.println(
"WARNING: Unimplemented sameAs method for "
701 +
"vertex subtype '" + this.getClass().getName() +
"'");
721 reason.append(
"Different building block type ("
736 reason.append(
"Different number of APs ("
749 reason.append(
"Difference in AP "+i+
": "+apT+
" vs "+apO);
784 Randomizer rng,
boolean removeUsedRCAs,
boolean rebuild);
795 ArrayList<APClass> lst =
new ArrayList<APClass>();
798 APClass apCls = ap.getAPClass();
799 if (!lst.contains(apCls))
817 ArrayList<APClass> lst =
new ArrayList<APClass>();
820 if (!ap.isAvailable())
823 APClass apCls = ap.getAPClass();
824 if (!lst.contains(apCls))
878 List<MutationType> ignoredTypes);
934 List<MutationType> filteredTypes =
new ArrayList<MutationType>(
996 filteredTypes.removeAll(excludedTypes);
998 return filteredTypes;
1063 Edge user = ap.getEdgeUser();
1088 Edge user = ap.getEdgeUser();
1116 ArrayList<AttachmentPoint> apsOnChildren =
1117 new ArrayList<AttachmentPoint>();
1120 Edge user = ap.getEdgeUserThroughout();
1129 return apsOnChildren;
1147 ArrayList<Vertex> children =
new ArrayList<Vertex>();
1150 Edge user = ap.getEdgeUserThroughout();
1154 if (ap.isSrcInUserThroughout())
1175 ArrayList<Vertex> children =
new ArrayList<Vertex>();
1180 Edge user = ap.getEdgeUser();
1267 Map<Object, Object> copy =
new HashMap<Object, Object>();
1271 if ((k instanceof String && v instanceof String)
1293 return gson.fromJson(json,
Vertex.class);
1312 implements JsonDeserializer<Vertex>
1316 JsonDeserializationContext context)
throws JsonParseException
1318 JsonObject jsonObject = json.getAsJsonObject();
1320 if (!jsonObject.has(
"vertexType"))
1322 String msg =
"Missing 'vertexType': found a "
1323 +
"JSON string generated by a previous version and "
1324 +
"that is no longer compatible. "
1325 +
"Upgrade the JSON string by adding "
1326 +
"the member 'vertexType', which can be any of these:";
1328 msg = msg +
" " + v;
1330 throw new JsonParseException(msg);
1334 VertexType vt = context.deserialize(jsonObject.get(
"vertexType"),
1345 case MolecularFragment:
1363 if (jsonObject.has(
"lstSymAPs"))
1365 for (JsonElement elSet : jsonObject.get(
"lstSymAPs").getAsJsonArray())
1367 List<AttachmentPoint> aps =
new ArrayList<AttachmentPoint>();
1368 for (JsonElement elId : elSet.getAsJsonArray())
1370 int id = context.deserialize(elId, Integer.class);
1374 String msg =
"Failed to parse 'lstSymAPs'. It is "
1375 +
"possible that the JSON input has been "
1376 +
"writted by a previosu version of "
1377 +
"DENOPTIM. If so, its syntax needs to be "
1379 throw new JsonParseException(msg);
1412 String[] pair = {a2b,b2a};
1468 +
"read a vertex from "
1469 +
"a SDF file that contains a JSON definition of a "
1470 +
"graph. This should not be intentional, so we'll "
1471 +
"read the atom container ignoring the JSON "
1472 +
"definition of a graph.");
1479 +
"create vertex. ",e);
1509 if (this.owner !=
null && other.
owner !=
null
1510 &&
this.owner == other.
owner)
1515 if (linkedAp ==
null)
General set of constants used in DENOPTIM.
static final String VERTEXJSONTAG
SDF tag containing vertex encoding in JSON format.
static final String GRAPHJSONTAG
SDF tag containing graph encoding in JSON format.
Class defining a space of building blocks.
static final Set< APClass > APCAROMBRIDGES
Conventional classes for of attachment points on aromatic-bridge vertexes.
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.
APClass getAPClass()
Returns the Attachment Point class.
boolean sameAs(AttachmentPoint other)
Compares the features of this and another attachment point and decides if the two are same.
AttachmentPoint getLinkedAPThroughout()
Gets the attachment point (AP) that is connected to this AP via the edge user or in any edge user tha...
Edge getEdgeUser()
Gets the edge that is using this AP, or null if no edge is using this AP.
Container for the list of vertices and the edges that connect them.
ArrayList< Ring > getRingsInvolvingVertex(Vertex v)
Returns the list of rings that include the given vertex in their fundamental cycle.
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.
static EmptyVertex fromJson(String json)
Reads a JSON string and returns an instance of this class.
Class representing a continuously connected portion of chemical object holding attachment points.
static Fragment fromJson(String json)
Reads a JSON string and returns an instance of this class.
This class represents the closure of a ring in a spanning tree.
Vertex getVertexAtPosition(int i)
A collection of AttachmentPoints that are related by a relation that we call "symmetry",...
static Template fromJson(String json)
Reads a JSON string and returns an instance of this class.
Vertex deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
A vertex is a data structure that has an identity and holds a list of AttachmentPoints.
ArrayList< Vertex > getChildrenThroughout()
Looks into the edges that use any of the APs that belong to this vertex and returns the list of verti...
boolean connectedTo(Vertex other)
Checks if this and another vertex are directly connected by an edge within the same graph recursion l...
abstract Vertex clone()
Returns a deep-copy of this vertex.
static Vertex parseVertexFromSDFFormat(IAtomContainer mol, Gson reader, BBType bbt)
Created a Vertex from the SDF representation, i.e., from an IAtomContainer.
Set< String > uniquefyingPropertyKeys
List of properties required to make Vertex#sameAs(Vertex, StringBuilder) method return false when pro...
Map< Object, Object > properties
Map of customizable properties.
void setMutationTypes(List< MutationType > lst)
Map< Object, Object > getProperties()
List< MutationType > getMutationTypes()
Returns the list of mutation types.
List< AttachmentPoint > getAPsWithAPClassStartingWith(String root)
Finds only APs that have APClass starting with the given string.
void setProperties(Map< Object, Object > properties)
ArrayList< AttachmentPoint > getCappedAPs()
Gets attachment points that are used by capping groups.
int getBuildingBlockId()
Returns the index of the building block that should correspond to the position of the building block ...
static Vertex newVertexFromLibrary(long vertexId, int bbId, Vertex.BBType bbt, FragmentSpace fragSpace)
Make a new vertex that is a copy of a vertex in the fragment space.
abstract void setSymmetricAPSets(List< SymmetricAPs > sAPs)
abstract List< Vertex > getMutationSites(List< MutationType > ignoredTypes)
A list of mutation sites from within this vertex.
ArrayList< APClass > getAllAPClasses()
Returns the list of all APClasses present on this vertex.
Edge getEdgeToParent()
Looks into the edges that use any of the APs that belong to this vertex and returns the edge that has...
void setVertexId(long vertexId2)
ArrayList< AttachmentPoint > getCappedAPsThroughout()
Gets attachment points that are used by capping groups throughout the graph levels,...
String[] getPathIDs(AttachmentPoint apA, AttachmentPoint apB)
Produces a pair of strings that identify the "path" between two given attachment points.
int getFreeAPCountThroughout()
Counts the number of attachment points that are availability throughout the graph level,...
abstract boolean containsAtoms()
int getIndexOfAP(AttachmentPoint ap)
Returns the position of the given AP in the list of APs of this vertex.
void removeProperty(Object key)
String toString()
Produces a human readable, short string to represent the vertex by its vertex ID, building block ID (...
Vertex(VertexType vertexType)
Constructor for an empty vertex.
Vertex getParent()
Looks into the edges that use any of the APs that belong to this vertex and returns the vertex which ...
Vertex.BBType getBuildingBlockType()
VertexType getVertexType()
Returns the value of the vertex type.
DGraph owner
Graph that includes this vertex.
boolean isConnectedToAromaticBridge()
Checks if this vertex is connected to any vertex meant to be a piece of an aromatic system.
List< MutationType > getUnfilteredMutationTypes()
Returns the mutation types that are constitutionally configures for this vertex irrespectively on the...
List< Vertex > getMutationSites()
A list of mutation sites from within this vertex.
List< MutationType > getMutationTypes(List< MutationType > excludedTypes)
Returns the list of mutation types.
AttachmentPoint getAPWithId(int i)
Get attachment point that has the given identifier, or null.
void setAsRCV(boolean isRCV)
void setGraphOwner(DGraph owner)
DGraph getGraphOwner()
Returns the graph this vertex belongs to or null.
int buildingBlockId
Index of this building block in the library of building blocks, or negative if this vertex is not par...
Map< Object, Object > copyStringBasedProperties()
Copies all the string-based properties and properties defined in the Vertex#uniquefyingPropertyKeys s...
boolean isAromaticBridge()
Checks if this vertex is meant to be a piece of an aromatic system.
boolean sameVertexFeatures(Vertex other, StringBuilder reason)
Compares this and another vertex ignoring vertex IDs.
boolean sameAs(Vertex other, StringBuilder reason)
Compares this and another vertex ignoring vertex IDs.
ArrayList< Vertex > getChilddren()
Looks into the edges that use any of the APs that belong to this vertex and returns the list of verti...
ArrayList< APClass > getAllAvailableAPClasses()
Returns the list of all APClasses present on free attachment point on this vertex.
abstract List< AttachmentPoint > getAttachmentPoints()
void setBuildingBlockId(int buildingBlockId)
ArrayList< AttachmentPoint > getAPsFromChildren()
Looks into the edges that use any of the APs that belong to this vertex and returns the list of attac...
abstract List< SymmetricAPs > getSymmetricAPSets()
SymmetricAPs getSymmetricAPs(AttachmentPoint ap)
For the given attachment point index locate the symmetric partners i.e.
Object getProperty(Object property)
abstract int getHeavyAtomsCount()
static Vertex convertIACToVertex(IAtomContainer iac, Vertex.BBType bbt)
Processes an IAtomContainer and builds a Vertex that is an instance of Fragment.
boolean hasProperty(Object property)
List< MutationType > allowedMutationTypes
List of mutations that we can perform on this vertex.
static Vertex fromJson(String json)
void setUniquefyingProperty(String key)
Add the given key among the properties that are checked for equality when comparing vertices with the...
boolean removeMutationType(MutationType mt)
Removes the specified mutation type.
boolean sameAs(Vertex other)
Compares this and another vertex ignoring vertex IDs.
void setBuildingBlockType(Vertex.BBType buildingBlockType)
int getCappedAPCountThroughout()
Counts the number of attachment points that are used by BBType#CAP vertex.
abstract IAtomContainer getIAtomContainer(Logger logger, Randomizer rng, boolean removeUsedRCAs, boolean rebuild)
Method meant to trigger regeneration of the chemical representation, typically needed to drop a low q...
final VertexType vertexType
Field distinguishing implementations of Vertex when deserializing JSON representations.
Vertex(VertexType vertexType, long id)
Constructor for an identified vertex without attachment points.
abstract IAtomContainer getIAtomContainer()
void setProperty(Object key, Object property)
long vertexId
Unique identifier associated with the vertex instance.
ArrayList< AttachmentPoint > getFreeAPThroughout()
Gets attachment points that are availability throughout the graph level, i.e., checks also across the...
AttachmentPoint getAP(int i)
Get attachment point i on this vertex.
static Vertex newVertexFromLibrary(int bbId, Vertex.BBType bbt, FragmentSpace fragSpace)
Builds a new molecular fragment kind of vertex.
abstract void addSymmetricAPSet(SymmetricAPs symAPs)
Edge getEdgeWith(Vertex other)
Finds the edge between this and the other vertex, if it exists.
The RingClosingAttractor represent the available valence/connection that allows to close a ring.
static final Set< APClass > RCAAPCLASSSET
Recognized APClass for RingClosingAttractor.
Class for de/serializing DENOPTIM graphs from/to JSON format.
Logger class for DENOPTIM.
static final Logger appLogger
static synchronized long getUniqueVertexIndex()
Unique counter for the number of graph vertices generated.
Tool to generate random numbers and random decisions.
The type of building block.
static BBType parseInt(int i)
Translates the integer into the enum.
Flag declaring the type of Vertex implementation.
Types of mutation defined in relation to what happens to the target vertex (i.e., the actual mutation...
ADDFUSEDRING
Adds a subgraph that introduced a fused ring.
DELETE
Removes the target vertex and all child vertices.
DELETELINK
Removes a vertex from a tree and merges remaining branches into the remaining trunk.
CHANGELINK
Replace the target vertex keeping all the child structure.
EXTEND
append vertices on the target vertex according to substitution probability.
CHANGEBRANCH
Replace the target vertex and any of the child vertices.
ADDLINK
Adds a vertex between two previously connected vertexes.
ADDRING
Creates a ring-closure to add a ring.
DELETECHAIN
Removes a vertex and all its neighbors recursively until a branching point, i.e., until a vertex that...