19package denoptim.graph;
21import java.lang.reflect.Type;
22import java.util.ArrayList;
23import java.util.Collections;
24import java.util.HashSet;
28import com.google.gson.JsonDeserializationContext;
29import com.google.gson.JsonDeserializer;
30import com.google.gson.JsonElement;
31import com.google.gson.JsonObject;
32import com.google.gson.JsonParseException;
34import denoptim.constants.DENOPTIMConstants;
35import denoptim.exception.DENOPTIMException;
36import denoptim.fragspace.FragmentSpace;
37import denoptim.graph.Edge.BondType;
38import denoptim.graph.rings.RingClosingAttractor;
40public class APClass implements Cloneable,Comparable<APClass>
68 public static final String
ATPLUS =
"ATplus";
73 public static final String
ATMINUS =
"ATminus";
142 +
"' that does not respect syntax <rule>"
145 String[] parts = ruleAndSubclass.split(
147 return make(parts[0], Integer.parseInt(parts[1]));
198 +
"' that does not respect syntax <rule>"
201 String[] parts = ruleAndSubclass.split(
203 return make(parts[0], Integer.parseInt(parts[1]), bt);
247 boolean found =
false;
250 if (existingApc.getRule().equals(
rule)
251 && existingApc.getSubClass()==
subClass)
253 newApc = existingApc;
268 System.err.println(
"WARNING! Changing bond order of "
269 +
"APClass " + newApc +
": " + newApc.
bndTyp
294 this.subClass = sumClass;
305 List<String> names =
new ArrayList<String>();
308 names.add(apc.toString());
310 Collections.sort(names);
353 return rule + DENOPTIMConstants.SEPARATORAPPROPSCL
365 return rule + DENOPTIMConstants.SEPARATORAPPROPSCL
367 + DENOPTIMConstants.SEPARATORAPPROPSCL
383 return s.matches(
"^[0-9]*$");
400 return s.matches(
"^[a-zA-Z0-9_-]+$");
414 if (!s.matches(
"^[a-z,A-Z,0-9].*"))
417 if (!s.matches(
".*[0-9]$"))
427 for (
int i=0; i<s.length(); i++)
465 int ruleComparison = this.rule.compareTo(o.
rule);
466 if (ruleComparison == 0) {
467 return Integer.compare(this.subClass, o.
subClass);
469 return ruleComparison;
492 return this.hashCode() == o.hashCode();
498 implements JsonDeserializer<APClass>
502 JsonDeserializationContext context)
throws JsonParseException
504 JsonObject jo = json.getAsJsonObject();
506 if (jo.has(
"bndTyp"))
508 apc =
getUnique(jo.get(
"rule").getAsString(),
509 jo.get(
"subClass").getAsInt(),
510 context.deserialize(jo.get(
"bndTyp"),
BondType.class));
513 String
rule = jo.get(
"rule").getAsString();
514 int subClass = jo.get(
"subClass").getAsInt();
515 boolean found =
false;
518 if (existingApc.getRule().equals(
rule)
519 && existingApc.getSubClass()==
subClass)
528 System.out.println(
"WARNING! Setting " +
DEFAULTBT
530 apc =
getUnique(jo.get(
"rule").getAsString(),
531 jo.get(
"subClass").getAsInt(),
DEFAULTBT);
General set of constants used in DENOPTIM.
static final String SEPARATORAPPROPSCL
Separator between APClass and APSubClass and coordinates.
Class defining a space of building blocks.
ArrayList< APClass > getCompatibleAPClasses(APClass apc)
Returns a list of APClasses compatible with the given APClass.
APClass deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
static List< String > getAllAPClassesAsString()
Returns the list of the names of all APClasses.
boolean isCPMapCompatibleWith(APClass other, FragmentSpace fragSpace)
Check compatibility as defined in the compatibility matrix considering this AP as source and the othe...
APClass clone()
WARNING: this method does NOT clone! It just returns the reference to this.
static final APClass RCACLASSPLUS
Conventional class of attachment points on ring-closing vertexes.
static APClass make(String rule, int subClass)
Constructor for an APClass with default bond type (i.e., BondType#DEFAULTBT).
static final String ATNEUTRAL
String defining a conventional APClass.
static APClass make(String ruleAndSubclass, BondType bt)
Constructor for a fully defined APClass.
static APClass make(String rule, int subClass, BondType bt)
Constructor for a fully defined APClass.
static final Object uniqueAPClassesLock
Synchronization lock.
BondType bndTyp
Bond type to use when converting edge users into formal bonds.
static final APClass RCACLASSMINUS
Conventional class of attachment points on ring-closing vertexes.
static boolean isValidAPClassString(String s)
Evaluate is a candidate string can be used as APClass.
static boolean isValidAPRuleString(String s)
Evaluates the given string as a candidate attachment point rule, i.e., as name of a fragmentation rul...
static final String ATMINUS
String defining a conventional APClass.
String rule
The main feature of the APClass.
static final BondType DEFAULTBT
Default bond type for all but APClasses of RCVs.
void setBondType(BondType bt)
static final String ATPLUS
String defining a conventional APClass.
APClass()
Constructor for an empty APClass.
void setSubClass(int sumClass)
static boolean isValidAPSubCLassString(String s)
Evaluate the given string as a candidate for attachment point subclass, i.e., the attachment point cl...
int subClass
The secondary feature of the APClass.
String toString()
Do not use this to make SDF representations.
static APClass make(String ruleAndSubclass)
Creates an APClass if it does not exist already, or returns the reference to the existing instance.
static final APClass RCACLASSNEUTRAL
Conventional class of attachment points on ring-closing vertexes.
void setRule(String rule)
static Set< APClass > uniqueAPClasses
Set unique APClasses.
static APClass getUnique(String rule, int subClass, BondType bt)
Checks if there is already a instance with the given members, if not it created one.
The RingClosingAttractor represent the available valence/connection that allows to close a ring.
static final Set< APClass > RCAAPCLASSSET
Recognized APClass for RingClosingAttractor.
Possible chemical bond types an edge can represent.