19package denoptim.graph;
21import java.lang.reflect.Type;
22import java.util.ArrayList;
23import java.util.Arrays;
24import java.util.Collections;
25import java.util.HashSet;
29import com.google.gson.JsonDeserializationContext;
30import com.google.gson.JsonDeserializer;
31import com.google.gson.JsonElement;
32import com.google.gson.JsonObject;
33import com.google.gson.JsonParseException;
35import denoptim.constants.DENOPTIMConstants;
36import denoptim.exception.DENOPTIMException;
37import denoptim.fragspace.FragmentSpace;
38import denoptim.graph.Edge.BondType;
39import denoptim.graph.rings.RingClosingAttractor;
41public class APClass implements Cloneable,Comparable<APClass>
69 public static final String
ATPLUS =
"ATplus";
74 public static final String
ATMINUS =
"ATminus";
170 +
"' that does not respect syntax <rule>"
173 String[] parts = ruleAndSubclass.split(
175 return make(parts[0], Integer.parseInt(parts[1]));
226 +
"' that does not respect syntax <rule>"
229 String[] parts = ruleAndSubclass.split(
231 return make(parts[0], Integer.parseInt(parts[1]), bt);
275 boolean found =
false;
278 if (existingApc.getRule().equals(
rule)
279 && existingApc.getSubClass()==
subClass)
281 newApc = existingApc;
296 System.err.println(
"WARNING! Changing bond order of "
297 +
"APClass " + newApc +
": " + newApc.
bndTyp
322 this.subClass = sumClass;
333 List<String> names =
new ArrayList<String>();
336 names.add(apc.toString());
338 Collections.sort(names);
381 return rule + DENOPTIMConstants.SEPARATORAPPROPSCL
393 return rule + DENOPTIMConstants.SEPARATORAPPROPSCL
395 + DENOPTIMConstants.SEPARATORAPPROPSCL
411 return s.matches(
"^[0-9]*$");
428 return s.matches(
"^[a-zA-Z0-9_-]+$");
442 if (!s.matches(
"^[a-z,A-Z,0-9].*"))
445 if (!s.matches(
".*[0-9]$"))
455 for (
int i=0; i<s.length(); i++)
493 int ruleComparison = this.rule.compareTo(o.
rule);
494 if (ruleComparison == 0) {
495 return Integer.compare(this.subClass, o.
subClass);
497 return ruleComparison;
520 return this.hashCode() == o.hashCode();
526 implements JsonDeserializer<APClass>
530 JsonDeserializationContext context)
throws JsonParseException
532 JsonObject jo = json.getAsJsonObject();
534 if (jo.has(
"bndTyp"))
536 apc =
getUnique(jo.get(
"rule").getAsString(),
537 jo.get(
"subClass").getAsInt(),
538 context.deserialize(jo.get(
"bndTyp"),
BondType.class));
541 String
rule = jo.get(
"rule").getAsString();
542 int subClass = jo.get(
"subClass").getAsInt();
543 boolean found =
false;
546 if (existingApc.getRule().equals(
rule)
547 && existingApc.getSubClass()==
subClass)
556 System.out.println(
"WARNING! Setting " +
DEFAULTBT
558 apc =
getUnique(jo.get(
"rule").getAsString(),
559 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 final APClass APCAROMBRIDGE4EL
Conventional class of attachment points on aromatic-bridge vertexes bringing 4 electrons to the aroma...
static Set< APClass > uniqueAPClasses
Set unique APClasses.
static final APClass APCAROMBRIDGE2EL
Conventional class of attachment points on aromatic-bridge vertexes bringing 2 electrons to the aroma...
static final APClass APCAROMBRIDGE3EL
Conventional class of attachment points on aromatic-bridge vertexes bringing 3 electrons to the aroma...
static final Set< APClass > APCAROMBRIDGES
Conventional classes for of attachment points on aromatic-bridge vertexes.
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.