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 this.vertexId = vertexId2;
337 if (symmetricSet.contains(ap))
359 if (ap.isAvailable())
384 ArrayList<AttachmentPoint> lst =
385 new ArrayList<AttachmentPoint>();
388 if (ap.isAvailableThroughout())
430 ArrayList<AttachmentPoint> lst =
431 new ArrayList<AttachmentPoint>();
434 if (!ap.isAvailable())
464 ArrayList<AttachmentPoint> lst =
465 new ArrayList<AttachmentPoint>();
468 if (!ap.isAvailableThroughout())
504 if (ap.isAvailableThroughout())
599 return sameAs(other,
new StringBuilder());
614 if (this.getClass() == other.getClass())
623 }
else if (
this instanceof
Template) {
627 System.err.println(
"WARNING: Unimplemented sameAs method for "
628 +
"vertex subtype '" + this.getClass().getName() +
"'");
648 reason.append(
"Different building block type ("
663 reason.append(
"Different number of APs ("
676 reason.append(
"Difference in AP "+i+
": "+apT+
" vs "+apO);
711 Randomizer rng,
boolean removeUsedRCAs,
boolean rebuild);
722 ArrayList<APClass> lst =
new ArrayList<APClass>();
725 APClass apCls = ap.getAPClass();
726 if (!lst.contains(apCls))
744 ArrayList<APClass> lst =
new ArrayList<APClass>();
747 if (!ap.isAvailable())
750 APClass apCls = ap.getAPClass();
751 if (!lst.contains(apCls))
805 List<MutationType> ignoredTypes);
861 List<MutationType> filteredTypes =
new ArrayList<MutationType>(
908 filteredTypes.removeAll(excludedTypes);
910 return filteredTypes;
975 Edge user = ap.getEdgeUser();
1000 Edge user = ap.getEdgeUser();
1028 ArrayList<AttachmentPoint> apsOnChildren =
1029 new ArrayList<AttachmentPoint>();
1032 Edge user = ap.getEdgeUserThroughout();
1041 return apsOnChildren;
1059 ArrayList<Vertex> children =
new ArrayList<Vertex>();
1062 Edge user = ap.getEdgeUserThroughout();
1066 if (ap.isSrcInUserThroughout())
1087 ArrayList<Vertex> children =
new ArrayList<Vertex>();
1092 Edge user = ap.getEdgeUser();
1179 Map<Object, Object> copy =
new HashMap<Object, Object>();
1183 if ((k instanceof String && v instanceof String)
1205 return gson.fromJson(json,
Vertex.class);
1224 implements JsonDeserializer<Vertex>
1228 JsonDeserializationContext context)
throws JsonParseException
1230 JsonObject jsonObject = json.getAsJsonObject();
1232 if (!jsonObject.has(
"vertexType"))
1234 String msg =
"Missing 'vertexType': found a "
1235 +
"JSON string generated by a previous version and "
1236 +
"that is no longer compatible. "
1237 +
"Upgrade the JSON string by adding "
1238 +
"the member 'vertexType', which can be any of these:";
1240 msg = msg +
" " + v;
1242 throw new JsonParseException(msg);
1246 VertexType vt = context.deserialize(jsonObject.get(
"vertexType"),
1257 case MolecularFragment:
1275 if (jsonObject.has(
"lstSymAPs"))
1277 for (JsonElement elSet : jsonObject.get(
"lstSymAPs").getAsJsonArray())
1279 List<AttachmentPoint> aps =
new ArrayList<AttachmentPoint>();
1280 for (JsonElement elId : elSet.getAsJsonArray())
1282 int id = context.deserialize(elId, Integer.class);
1286 String msg =
"Failed to parse 'lstSymAPs'. It is "
1287 +
"possible that the JSON input has been "
1288 +
"writted by a previosu version of "
1289 +
"DENOPTIM. If so, its syntax needs to be "
1291 throw new JsonParseException(msg);
1324 String[] pair = {a2b,b2a};
1380 +
"read a vertex from "
1381 +
"a SDF file that contains a JSON definition of a "
1382 +
"graph. This should not be intentional, so we'll "
1383 +
"read the atom container ignoring the JSON "
1384 +
"definition of a graph.");
1391 +
"create vertex. ",e);
1421 if (this.owner !=
null && other.
owner !=
null
1422 &&
this.owner == other.
owner)
1427 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.
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.
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.
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.
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.
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.
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 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...
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...