20package denoptim.graph;
22import java.lang.reflect.Type;
23import java.util.ArrayList;
24import java.util.Arrays;
25import java.util.HashMap;
26import java.util.HashSet;
30import java.util.logging.Level;
31import java.util.logging.Logger;
33import org.openscience.cdk.interfaces.IAtomContainer;
35import com.google.gson.Gson;
36import com.google.gson.JsonDeserializationContext;
37import com.google.gson.JsonDeserializer;
38import com.google.gson.JsonElement;
39import com.google.gson.JsonObject;
40import com.google.gson.JsonParseException;
41import com.google.gson.JsonSyntaxException;
43import denoptim.constants.DENOPTIMConstants;
44import denoptim.exception.DENOPTIMException;
45import denoptim.fragspace.FragmentSpace;
46import denoptim.graph.rings.RingClosingAttractor;
47import denoptim.json.DENOPTIMgson;
48import denoptim.logging.StaticLogger;
49import denoptim.utils.GraphUtils;
50import denoptim.utils.MutationType;
51import denoptim.utils.Randomizer;
60public abstract class Vertex implements Cloneable
87 UNDEFINED, SCAFFOLD, FRAGMENT,
CAP, NONE;
160 new ArrayList<MutationType>(Arrays.asList(
MutationType.values()));
238 Vertex v = fragSpace.getVertexFromLibrary(bbt,bbId);
263 List<AttachmentPoint> list =
new ArrayList<AttachmentPoint>();
266 if (ap.getAPClass().toString().startsWith(root))
283 this.vertexId = vertexId2;
357 if (symmetricSet.contains(ap))
379 if (ap.isAvailable())
404 ArrayList<AttachmentPoint> lst =
405 new ArrayList<AttachmentPoint>();
408 if (ap.isAvailableThroughout())
450 ArrayList<AttachmentPoint> lst =
451 new ArrayList<AttachmentPoint>();
454 if (!ap.isAvailable())
484 ArrayList<AttachmentPoint> lst =
485 new ArrayList<AttachmentPoint>();
488 if (!ap.isAvailableThroughout())
524 if (ap.isAvailableThroughout())
586 if (ap.isAvailableThroughout())
671 return sameAs(other,
new StringBuilder());
686 if (this.getClass() == other.getClass())
695 }
else if (
this instanceof
Template) {
699 System.err.println(
"WARNING: Unimplemented sameAs method for "
700 +
"vertex subtype '" + this.getClass().getName() +
"'");
720 reason.append(
"Different building block type ("
735 reason.append(
"Different number of APs ("
748 reason.append(
"Difference in AP "+i+
": "+apT+
" vs "+apO);
783 Randomizer rng,
boolean removeUsedRCAs,
boolean rebuild);
794 ArrayList<APClass> lst =
new ArrayList<APClass>();
797 APClass apCls = ap.getAPClass();
798 if (!lst.contains(apCls))
816 ArrayList<APClass> lst =
new ArrayList<APClass>();
819 if (!ap.isAvailable())
822 APClass apCls = ap.getAPClass();
823 if (!lst.contains(apCls))
877 List<MutationType> ignoredTypes);
933 List<MutationType> filteredTypes =
new ArrayList<MutationType>(
995 filteredTypes.removeAll(excludedTypes);
997 return filteredTypes;
1062 Edge user = ap.getEdgeUser();
1087 Edge user = ap.getEdgeUser();
1115 ArrayList<AttachmentPoint> apsOnChildren =
1116 new ArrayList<AttachmentPoint>();
1119 Edge user = ap.getEdgeUserThroughout();
1128 return apsOnChildren;
1146 ArrayList<Vertex> children =
new ArrayList<Vertex>();
1149 Edge user = ap.getEdgeUserThroughout();
1153 if (ap.isSrcInUserThroughout())
1174 ArrayList<Vertex> children =
new ArrayList<Vertex>();
1179 Edge user = ap.getEdgeUser();
1266 Map<Object, Object> copy =
new HashMap<Object, Object>();
1270 if ((k instanceof String && v instanceof String)
1292 return gson.fromJson(json,
Vertex.class);
1311 implements JsonDeserializer<Vertex>
1315 JsonDeserializationContext context)
throws JsonParseException
1317 JsonObject jsonObject = json.getAsJsonObject();
1319 if (!jsonObject.has(
"vertexType"))
1321 String msg =
"Missing 'vertexType': found a "
1322 +
"JSON string generated by a previous version and "
1323 +
"that is no longer compatible. "
1324 +
"Upgrade the JSON string by adding "
1325 +
"the member 'vertexType', which can be any of these:";
1327 msg = msg +
" " + v;
1329 throw new JsonParseException(msg);
1333 VertexType vt = context.deserialize(jsonObject.get(
"vertexType"),
1344 case MolecularFragment:
1362 if (jsonObject.has(
"lstSymAPs"))
1364 for (JsonElement elSet : jsonObject.get(
"lstSymAPs").getAsJsonArray())
1366 List<AttachmentPoint> aps =
new ArrayList<AttachmentPoint>();
1367 for (JsonElement elId : elSet.getAsJsonArray())
1369 int id = context.deserialize(elId, Integer.class);
1373 String msg =
"Failed to parse 'lstSymAPs'. It is "
1374 +
"possible that the JSON input has been "
1375 +
"writted by a previosu version of "
1376 +
"DENOPTIM. If so, its syntax needs to be "
1378 throw new JsonParseException(msg);
1411 String[] pair = {a2b,b2a};
1467 +
"read a vertex from "
1468 +
"a SDF file that contains a JSON definition of a "
1469 +
"graph. This should not be intentional, so we'll "
1470 +
"read the atom container ignoring the JSON "
1471 +
"definition of a graph.");
1478 +
"create vertex. ",e);
1508 if (this.owner !=
null && other.
owner !=
null
1509 &&
this.owner == other.
owner)
1514 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...