$darkmode
DENOPTIM
Vertex.java
Go to the documentation of this file.
1/*
2 * DENOPTIM
3 * Copyright (C) 2019 Vishwesh Venkatraman <vishwesh.venkatraman@ntnu.no> and
4 * Marco Foscato <marco.foscato@uib.no>
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Affero General Public License as published
8 * by the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Affero General Public License for more details.
15 *
16 * You should have received a copy of the GNU Affero General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20package denoptim.graph;
21
22import java.lang.reflect.Type;
23import java.util.ArrayList;
24import java.util.Arrays;
25import java.util.HashMap;
26import java.util.HashSet;
27import java.util.List;
28import java.util.Map;
29import java.util.Set;
30import java.util.logging.Level;
31import java.util.logging.Logger;
32
33import org.openscience.cdk.interfaces.IAtomContainer;
34
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;
42
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;
52
60public abstract class Vertex implements Cloneable
61{
65 private DGraph owner;
66
70 private long vertexId;
71
76 protected int buildingBlockId = -99;
77
86 public enum BBType {
87 UNDEFINED, SCAFFOLD, FRAGMENT, CAP, NONE;
88
89 private int i = -99;
90
91 static {
92 NONE.i = -1;
93 SCAFFOLD.i = 0;
94 FRAGMENT.i = 1;
95 CAP.i = 2;
96 }
97
103 public static BBType parseInt(int i) {
104 BBType bbt;
105 switch (i)
106 {
107 case 0:
108 bbt = SCAFFOLD;
109 break;
110 case 1:
111 bbt = FRAGMENT;
112 break;
113 case 2:
114 bbt = CAP;
115 break;
116 default:
117 bbt = UNDEFINED;
118 break;
119 }
120 return bbt;
121 }
122
126 public int toOldInt()
127 {
128 return i;
129 }
130 }
131
132 /*
133 * Building block type distinguished among types of building blocks:
134 * scaffolds, fragments, and capping.
135 * Can be undefined, which is the default.
136 */
138
139 /*
140 * Flag indicating that this as a ring closing vertex
141 */
142 private boolean isRCV;
143
147 protected Map<Object, Object> properties;
148
154 protected Set<String> uniquefyingPropertyKeys = new HashSet<String>();
155
159 private List<MutationType> allowedMutationTypes =
160 new ArrayList<MutationType>(Arrays.asList(MutationType.values()));
161
166 protected final VertexType vertexType;
167
172 public enum VertexType {
176 }
177
178//------------------------------------------------------------------------------
179
184 {
185 this.vertexType = vertexType;
187 isRCV = false;
188 }
189
190//------------------------------------------------------------------------------
191
199 public Vertex(VertexType vertexType, long id)
200 {
201 this(vertexType);
202 vertexId = id;
203 }
204
205//------------------------------------------------------------------------------
206
214 public static Vertex newVertexFromLibrary(int bbId,
215 Vertex.BBType bbt, FragmentSpace fragSpace)
216 throws DENOPTIMException
217 {
219 fragSpace);
220 }
221
222//------------------------------------------------------------------------------
223
231 public static Vertex newVertexFromLibrary(long vertexId, int bbId,
232 Vertex.BBType bbt, FragmentSpace fragSpace)
233 throws DENOPTIMException
234 {
235 // The actual type of vertex
236 // returned by this method depends on the what we get from the
237 // FragmentSpace.getVertexFromLibrary call
238 Vertex v = fragSpace.getVertexFromLibrary(bbt,bbId);
240
241 v.setAsRCV(v.getNumberOfAPs() == 1
243 v.getAttachmentPoints().get(0).getAPClass()));
244
245 return v;
246 }
247
248//------------------------------------------------------------------------------
249
250 public abstract List<AttachmentPoint> getAttachmentPoints();
251
252//------------------------------------------------------------------------------
253
254 public void setAsRCV(boolean isRCV)
255 {
256 this.isRCV = isRCV;
257 }
258
259//------------------------------------------------------------------------------
260
261 public void setVertexId(long vertexId2)
262 {
263 this.vertexId = vertexId2;
264 }
265
266//------------------------------------------------------------------------------
267
268 public long getVertexId()
269 {
270 return vertexId;
271 }
272
273//------------------------------------------------------------------------------
274
285 {
286 return buildingBlockId;
287 }
288
289//------------------------------------------------------------------------------
290
292 {
293 this.buildingBlockId = buildingBlockId;
294 }
295
296//------------------------------------------------------------------------------
297
298 public Vertex.BBType getBuildingBlockType()
299 {
300 return buildingBlockType;
301 }
302
303//------------------------------------------------------------------------------
304
306 {
307 this.buildingBlockType = buildingBlockType;
308 }
309
310//------------------------------------------------------------------------------
311
312 protected abstract void setSymmetricAPSets(List<SymmetricAPs> sAPs);
313
314//------------------------------------------------------------------------------
315
316 protected abstract void addSymmetricAPSet(SymmetricAPs symAPs);
317
318//------------------------------------------------------------------------------
319
320 public abstract List<SymmetricAPs> getSymmetricAPSets();
321
322//------------------------------------------------------------------------------
323
334 {
335 for (SymmetricAPs symmetricSet : getSymmetricAPSets())
336 {
337 if (symmetricSet.contains(ap))
338 {
339 return symmetricSet;
340 }
341 }
342 return new SymmetricAPs();
343 }
344
345//------------------------------------------------------------------------------
346
347 public int getNumberOfAPs()
348 {
349 return getAttachmentPoints().size();
350 }
351
352//------------------------------------------------------------------------------
353
354 public int getFreeAPCount()
355 {
356 int n = 0;
358 {
359 if (ap.isAvailable())
360 n++;
361 }
362 return n;
363 }
364
365//------------------------------------------------------------------------------
366
382 public ArrayList<AttachmentPoint> getFreeAPThroughout()
383 {
384 ArrayList<AttachmentPoint> lst =
385 new ArrayList<AttachmentPoint>();
387 {
388 if (ap.isAvailableThroughout())
389 lst.add(ap);
390 }
391 return lst;
392 }
393
394//------------------------------------------------------------------------------
395
411 {
412 return getFreeAPThroughout().size();
413 }
414
415//------------------------------------------------------------------------------
416
428 public ArrayList<AttachmentPoint> getCappedAPs()
429 {
430 ArrayList<AttachmentPoint> lst =
431 new ArrayList<AttachmentPoint>();
433 {
434 if (!ap.isAvailable())
435 {
436 AttachmentPoint linkedAP = ap.getLinkedAP();
437 if (linkedAP.getOwner().getBuildingBlockType() == BBType.CAP)
438 lst.add(ap);
439 }
440 }
441 return lst;
442 }
443
444//------------------------------------------------------------------------------
445
462 public ArrayList<AttachmentPoint> getCappedAPsThroughout()
463 {
464 ArrayList<AttachmentPoint> lst =
465 new ArrayList<AttachmentPoint>();
467 {
468 if (!ap.isAvailableThroughout())
469 {
471 if (linkedAP.getOwner().getBuildingBlockType() == BBType.CAP)
472 lst.add(ap);
473 }
474 }
475 return lst;
476 }
477
478//------------------------------------------------------------------------------
479
494 {
495 return getCappedAPsThroughout().size();
496 }
497
498//------------------------------------------------------------------------------
499
500 public boolean hasFreeAP()
501 {
503 {
504 if (ap.isAvailableThroughout())
505 return true;
506 }
507 return false;
508 }
509
510//------------------------------------------------------------------------------
511
512 protected int getUniqueAPIndex()
513 {
514 if (owner == null)
515 {
516 return getNumberOfAPs();
517 } else {
518 return owner.getUniqueAPIndex();
519 }
520 }
521
522//------------------------------------------------------------------------------
523
529 public boolean isRCV()
530 {
531 return isRCV;
532 }
533
534//------------------------------------------------------------------------------
535
541 public boolean hasSymmetricAP()
542 {
543 return !getSymmetricAPSets().isEmpty();
544 }
545
546//------------------------------------------------------------------------------
547
558 @Override
559 public String toString()
560 {
561 return vertexId + "_" + (buildingBlockId + 1) + "_"
563 }
564
565//------------------------------------------------------------------------------
566
567 public void cleanup()
568 {
569 if (getSymmetricAPSets() != null)
570 {
571 getSymmetricAPSets().clear();
572 }
573 if (getAttachmentPoints() != null)
574 {
575 getAttachmentPoints().clear();
576 }
577 }
578
579//------------------------------------------------------------------------------
580
586 @Override
587 public abstract Vertex clone();
588
589//------------------------------------------------------------------------------
590
597 public boolean sameAs(Vertex other)
598 {
599 return sameAs(other, new StringBuilder());
600 }
601
602//------------------------------------------------------------------------------
603
612 public boolean sameAs(Vertex other, StringBuilder reason)
613 {
614 if (this.getClass() == other.getClass())
615 {
616 if (this instanceof Fragment)
617 {
618 return ((Fragment) this).sameAs(
619 (Fragment) other, reason);
620 } else if (this instanceof EmptyVertex) {
621 return ((EmptyVertex) this).sameAs(
622 (EmptyVertex) other, reason);
623 } else if (this instanceof Template) {
624 return ((Template) this).sameAs(
625 (Template) other, reason);
626 } else {
627 System.err.println("WARNING: Unimplemented sameAs method for "
628 + "vertex subtype '" + this.getClass().getName() + "'");
629 }
630 }
631 return sameVertexFeatures(other, reason);
632 }
633
634//------------------------------------------------------------------------------
635
644 public boolean sameVertexFeatures(Vertex other, StringBuilder reason)
645 {
646 if (this.getBuildingBlockType() != other.getBuildingBlockType())
647 {
648 reason.append("Different building block type ("
649 + this.getBuildingBlockType()+":"
650 + other.getBuildingBlockType()+"); ");
651 return false;
652 }
653
654 if (this.getBuildingBlockId() != other.getBuildingBlockId())
655 {
656 reason.append("Different molID ("+this.getBuildingBlockId()+":"
657 + other.getBuildingBlockId()+"); ");
658 return false;
659 }
660
661 if (this.getNumberOfAPs() != other.getNumberOfAPs())
662 {
663 reason.append("Different number of APs ("
664 +this.getNumberOfAPs()+":"
665 +other.getNumberOfAPs()+"); ");
666 return false;
667 }
668
669 // Order of APs must be the same
670 for (int i=0; i<this.getNumberOfAPs(); i++)
671 {
672 AttachmentPoint apT = this.getAP(i);
673 AttachmentPoint apO = other.getAP(i);
674 if (!apT.sameAs(apO))
675 {
676 reason.append("Difference in AP "+i+": "+apT+" vs "+apO);
677 return false;
678 }
679 }
680
681 return true;
682 }
683
684//------------------------------------------------------------------------------
685
686 public abstract int getHeavyAtomsCount();
687
688//------------------------------------------------------------------------------
689
690 public abstract boolean containsAtoms();
691
692//------------------------------------------------------------------------------
693
694 public abstract IAtomContainer getIAtomContainer();
695
696//------------------------------------------------------------------------------
697
710 public abstract IAtomContainer getIAtomContainer(Logger logger,
711 Randomizer rng, boolean removeUsedRCAs, boolean rebuild);
712
713//-----------------------------------------------------------------------------
714
720 public ArrayList<APClass> getAllAPClasses()
721 {
722 ArrayList<APClass> lst = new ArrayList<APClass>();
724 {
725 APClass apCls = ap.getAPClass();
726 if (!lst.contains(apCls))
727 {
728 lst.add(apCls);
729 }
730 }
731 return lst;
732 }
733
734//-----------------------------------------------------------------------------
735
742 public ArrayList<APClass> getAllAvailableAPClasses()
743 {
744 ArrayList<APClass> lst = new ArrayList<APClass>();
746 {
747 if (!ap.isAvailable())
748 continue;
749
750 APClass apCls = ap.getAPClass();
751 if (!lst.contains(apCls))
752 {
753 lst.add(apCls);
754 }
755 }
756 return lst;
757 }
758
759//------------------------------------------------------------------------------
760
761 public void resetGraphOwner()
762 {
763 this.owner = null;
764 }
765
766//------------------------------------------------------------------------------
767
769 {
770 this.owner = owner;
771 }
772
773//------------------------------------------------------------------------------
774
780 {
781 return owner;
782 }
783
784//------------------------------------------------------------------------------
785
790 public List<Vertex> getMutationSites()
791 {
792 return getMutationSites(new ArrayList<MutationType>());
793 }
794
795//------------------------------------------------------------------------------
796
804 public abstract List<Vertex> getMutationSites(
805 List<MutationType> ignoredTypes);
806
807//------------------------------------------------------------------------------
808
809 public void setMutationTypes(List<MutationType> lst)
810 {
812 }
813
814//------------------------------------------------------------------------------
815
823 protected List<MutationType> getUnfilteredMutationTypes()
824 {
826 }
827
828//------------------------------------------------------------------------------
829
836 {
837 return allowedMutationTypes.remove(mt);
838 }
839
840//------------------------------------------------------------------------------
841
846 public List<MutationType> getMutationTypes()
847 {
848 return getMutationTypes(new ArrayList<MutationType>());
849 }
850
851//------------------------------------------------------------------------------
852
859 public List<MutationType> getMutationTypes(List<MutationType> excludedTypes)
860 {
861 List<MutationType> filteredTypes = new ArrayList<MutationType>(
863 if (owner != null)
864 {
865 // this vertex is part of a graph
866
867 // Cannot add/change link on vertex that is not linked
868 if (getChilddren().isEmpty())
869 {
870 filteredTypes.remove(MutationType.ADDLINK);
871 filteredTypes.remove(MutationType.CHANGELINK);
872 }
873
874 // Cannot extend vertex that has no truly free AP, but can do it
875 // on APs that are used by capping groups.
876 if ((getFreeAPCountThroughout() + getCappedAPs().size()) == 0)
877 {
878 filteredTypes.remove(MutationType.EXTEND);
879 filteredTypes.remove(MutationType.ADDRING);
880 }
881
882 // Cannot remove the only vertex of a graph
883 if (owner.getVertexCount()==0)
884 filteredTypes.remove(MutationType.DELETE);
885
886 // Cannot start removal of chain from a branching vertex.
887 long nonCap = getAttachmentPoints().size()
890 if (nonCap > 2)
891 filteredTypes.remove(MutationType.DELETECHAIN);
892 }
893
895 {
896 filteredTypes.remove(MutationType.DELETELINK);
897 }
898
900 {
901 filteredTypes.remove(MutationType.DELETECHAIN);
902 filteredTypes.remove(MutationType.DELETELINK);
903 filteredTypes.remove(MutationType.CHANGELINK);
904 filteredTypes.remove(MutationType.CHANGEBRANCH);
905 filteredTypes.remove(MutationType.DELETE);
906 }
907
908 filteredTypes.removeAll(excludedTypes);
909
910 return filteredTypes;
911 }
912
913//------------------------------------------------------------------------------
914
920 public AttachmentPoint getAP(int i) {
921 return getAttachmentPoints().get(i);
922 }
923
924//------------------------------------------------------------------------------
925
932 {
934 {
935 if (ap.getID()==i)
936 return ap;
937 }
938 return null;
939 }
940
941//------------------------------------------------------------------------------
942
950 {
951 for (int i=0; i<getAttachmentPoints().size(); i++)
952 {
953 AttachmentPoint candAp = getAttachmentPoints().get(i);
954 if (candAp == ap)
955 {
956 return i;
957 }
958 }
959 return -1;
960 }
961
962//------------------------------------------------------------------------------
963
974 {
975 Edge user = ap.getEdgeUser();
976 if (user == null)
977 continue;
978
979 if (ap == user.getTrgAP())
980 {
981 return user;
982 }
983 }
984 return null;
985 }
986
987//------------------------------------------------------------------------------
988
997 {
999 {
1000 Edge user = ap.getEdgeUser();
1001 if (user == null)
1002 continue;
1003
1004 if (ap == user.getTrgAP())
1005 {
1006 return user.getSrcAP().getOwner();
1007 }
1008 }
1009 return null;
1010 }
1011
1012//------------------------------------------------------------------------------
1013
1026 public ArrayList<AttachmentPoint> getAPsFromChildren()
1027 {
1028 ArrayList<AttachmentPoint> apsOnChildren =
1029 new ArrayList<AttachmentPoint>();
1031 {
1032 Edge user = ap.getEdgeUserThroughout();
1033 if (user == null)
1034 continue;
1035
1036 if (ap == user.getSrcAPThroughout())
1037 {
1038 apsOnChildren.add(user.getTrgAPThroughout());
1039 }
1040 }
1041 return apsOnChildren;
1042 }
1043
1044//------------------------------------------------------------------------------
1045
1057 public ArrayList<Vertex> getChildrenThroughout()
1058 {
1059 ArrayList<Vertex> children = new ArrayList<Vertex>();
1061 {
1062 Edge user = ap.getEdgeUserThroughout();
1063 if (user == null)
1064 continue;
1065
1066 if (ap.isSrcInUserThroughout())
1067 {
1068 children.add(user.getTrgAP().getOwner());
1069 }
1070 }
1071 return children;
1072 }
1073
1074//------------------------------------------------------------------------------
1075
1085 public ArrayList<Vertex> getChilddren()
1086 {
1087 ArrayList<Vertex> children = new ArrayList<Vertex>();
1089 {
1090 // NB: this is meant to NOT cross template boundaries, so that all
1091 // children do belong to the same graph.
1092 Edge user = ap.getEdgeUser();
1093 if (user == null)
1094 continue;
1095
1096 if (ap == user.getSrcAP())
1097 {
1098 children.add(user.getTrgAP().getOwner());
1099 }
1100 }
1101 return children;
1102 }
1103
1104//------------------------------------------------------------------------------
1105
1112 public void setUniquefyingProperty(String key)
1113 {
1114 uniquefyingPropertyKeys.add(key);
1115 }
1116
1117//------------------------------------------------------------------------------
1118
1119 public Map<Object, Object> getProperties()
1120 {
1121 return properties;
1122 }
1123
1124//------------------------------------------------------------------------------
1125
1126 public boolean hasProperty(Object property)
1127 {
1128 if (properties==null)
1129 return false;
1130
1131 return properties.containsKey(property);
1132 }
1133
1134//------------------------------------------------------------------------------
1135
1136 public Object getProperty(Object property)
1137 {
1138 if (properties == null)
1139 {
1140 return null;
1141 } else {
1142 return properties.get(property);
1143 }
1144 }
1145
1146//-----------------------------------------------------------------------------
1147
1148 public void setProperty(Object key, Object property)
1149 {
1150 if (properties == null)
1151 {
1152 properties = new HashMap<Object, Object>();
1153 }
1154 properties.put(key, property);
1155 }
1156
1157//-----------------------------------------------------------------------------
1158
1159 public void removeProperty(Object key)
1160 {
1161 if (properties == null)
1162 return;
1163
1164 properties.remove(key);
1165 }
1166
1167//------------------------------------------------------------------------------
1168
1174 protected Map<Object, Object> copyStringBasedProperties()
1175 {
1176 if (properties==null)
1177 return null;
1178
1179 Map<Object, Object> copy = new HashMap<Object, Object>();
1180 for (Object k : properties.keySet())
1181 {
1182 Object v = properties.get(k);
1183 if ((k instanceof String && v instanceof String)
1184 || (uniquefyingPropertyKeys!=null
1185 && uniquefyingPropertyKeys.contains(k)))
1186 {
1187 copy.put(k,v);
1188 }
1189 }
1190 return copy;
1191 }
1192
1193//-----------------------------------------------------------------------------
1194
1195 public void setProperties(Map<Object, Object> properties)
1196 {
1197 this.properties = properties;
1198 }
1199
1200//------------------------------------------------------------------------------
1201
1202 public static Vertex fromJson(String json)
1203 {
1204 Gson gson = DENOPTIMgson.getReader();
1205 return gson.fromJson(json, Vertex.class);
1206 }
1207
1208//------------------------------------------------------------------------------
1209
1217 {
1218 return VertexType.valueOf(vertexType.name());
1219 }
1220
1221//------------------------------------------------------------------------------
1222
1223 public static class DENOPTIMVertexDeserializer
1224 implements JsonDeserializer<Vertex>
1225 {
1226 @Override
1227 public Vertex deserialize(JsonElement json, Type typeOfT,
1228 JsonDeserializationContext context) throws JsonParseException
1229 {
1230 JsonObject jsonObject = json.getAsJsonObject();
1231
1232 if (!jsonObject.has("vertexType"))
1233 {
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:";
1239 for (VertexType v : VertexType.values())
1240 msg = msg + " " + v;
1241 msg = msg + ". ";
1242 throw new JsonParseException(msg);
1243 }
1244
1245 // Deseralization differs for the types of vertices
1246 VertexType vt = context.deserialize(jsonObject.get("vertexType"),
1247 VertexType.class);
1248 Vertex v = null;
1249 switch (vt)
1250 {
1251 case Template:
1252 {
1253 v = Template.fromJson(jsonObject.toString());
1254 break;
1255 }
1256
1257 case MolecularFragment:
1258 {
1259 v = Fragment.fromJson(jsonObject.toString());
1260 break;
1261 }
1262
1263 case EmptyVertex:
1264 {
1265 v = EmptyVertex.fromJson(jsonObject.toString());
1266 break;
1267 }
1268
1269 default:
1270 {
1271 return null;
1272 }
1273 }
1274
1275 if (jsonObject.has("lstSymAPs"))
1276 {
1277 for (JsonElement elSet : jsonObject.get("lstSymAPs").getAsJsonArray())
1278 {
1279 List<AttachmentPoint> aps = new ArrayList<AttachmentPoint>();
1280 for (JsonElement elId : elSet.getAsJsonArray())
1281 {
1282 int id = context.deserialize(elId, Integer.class);
1283 AttachmentPoint ap = v.getAPWithId(id);
1284 if (ap==null)
1285 {
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 "
1290 + "upgraded.";
1291 throw new JsonParseException(msg);
1292 }
1293 aps.add(ap);
1294 }
1295 v.addSymmetricAPSet(new SymmetricAPs(aps));
1296 }
1297 }
1298
1299 return v;
1300 }
1301 }
1302
1303//------------------------------------------------------------------------------
1304
1315 public String[] getPathIDs(AttachmentPoint apA,
1316 AttachmentPoint apB)
1317 {
1318 String a2b = this.getBuildingBlockId() + "/"
1319 + this.getBuildingBlockType() + "/ap"
1320 + getIndexOfAP(apA) + "ap" + getIndexOfAP(apB) + "_";
1321 String b2a = this.getBuildingBlockId() + "/"
1322 + this.getBuildingBlockType() + "/ap"
1323 + getIndexOfAP(apB) + "ap" + getIndexOfAP(apA) + "_";
1324 String[] pair = {a2b,b2a};
1325 return pair;
1326 }
1327
1328//------------------------------------------------------------------------------
1329
1345 public static Vertex convertIACToVertex(IAtomContainer iac,
1346 Vertex.BBType bbt) throws DENOPTIMException
1347 {
1348 Vertex v = new Fragment(iac, bbt);
1349 v.setAsRCV(v.getNumberOfAPs() == 1
1351 v.getAttachmentPoints().get(0).getAPClass()));
1352 return v;
1353 }
1354
1355//------------------------------------------------------------------------------
1356
1366 public static Vertex parseVertexFromSDFFormat(IAtomContainer mol,
1367 Gson reader, BBType bbt) throws DENOPTIMException
1368 {
1369 Vertex v = null;
1370 try
1371 {
1372 Object json = mol.getProperty(DENOPTIMConstants.VERTEXJSONTAG);
1373 if (json != null) {
1374 v = reader.fromJson(json.toString(), Vertex.class);
1375 } else {
1377 if (json != null)
1378 {
1379 StaticLogger.appLogger.log(Level.WARNING, "Attempt to "
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.");
1385 }
1386 v = Vertex.convertIACToVertex(mol, bbt);
1387 }
1388 } catch (JsonSyntaxException | DENOPTIMException e)
1389 {
1390 throw new DENOPTIMException("Unable to parse IAtomContainer to "
1391 + "create vertex. ",e);
1392 }
1393 v.setBuildingBlockType(bbt);
1394 return v;
1395 }
1396
1397
1398//------------------------------------------------------------------------------
1399
1407 public boolean connectedTo(Vertex other)
1408 {
1409 return this.getParent() == other || this == other.getParent();
1410 }
1411
1412//------------------------------------------------------------------------------
1413
1420 {
1421 if (this.owner != null && other.owner !=null
1422 && this.owner == other.owner)
1423 {
1425 {
1426 AttachmentPoint linkedAp = ap.getLinkedAP();
1427 if (linkedAp == null)
1428 continue;
1429 if (linkedAp.getOwner()==other)
1430 return ap.getEdgeUser();
1431 }
1432 }
1433 return null;
1434 }
1435
1436//------------------------------------------------------------------------------
1437
1438}
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.
Definition: DGraph.java:102
This class represents the edge between two vertices.
Definition: Edge.java:38
AttachmentPoint getSrcAPThroughout()
Definition: Edge.java:101
AttachmentPoint getTrgAP()
Definition: Edge.java:115
AttachmentPoint getSrcAP()
Definition: Edge.java:94
AttachmentPoint getTrgAPThroughout()
Definition: Edge.java:108
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.
Definition: Fragment.java:61
static Fragment fromJson(String json)
Reads a JSON string and returns an instance of this class.
Definition: Fragment.java:1207
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.
Definition: Template.java:1028
Vertex deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
Definition: Vertex.java:1227
A vertex is a data structure that has an identity and holds a list of AttachmentPoints.
Definition: Vertex.java:61
ArrayList< Vertex > getChildrenThroughout()
Looks into the edges that use any of the APs that belong to this vertex and returns the list of verti...
Definition: Vertex.java:1057
boolean connectedTo(Vertex other)
Checks if this and another vertex are directly connected by an edge within the same graph recursion l...
Definition: Vertex.java:1407
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.
Definition: Vertex.java:1366
Set< String > uniquefyingPropertyKeys
List of properties required to make Vertex#sameAs(Vertex, StringBuilder) method return false when pro...
Definition: Vertex.java:154
Map< Object, Object > properties
Map of customizable properties.
Definition: Vertex.java:147
void setMutationTypes(List< MutationType > lst)
Definition: Vertex.java:809
Map< Object, Object > getProperties()
Definition: Vertex.java:1119
List< MutationType > getMutationTypes()
Returns the list of mutation types.
Definition: Vertex.java:846
void setProperties(Map< Object, Object > properties)
Definition: Vertex.java:1195
ArrayList< AttachmentPoint > getCappedAPs()
Gets attachment points that are used by capping groups.
Definition: Vertex.java:428
int getBuildingBlockId()
Returns the index of the building block that should correspond to the position of the building block ...
Definition: Vertex.java:284
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.
Definition: Vertex.java:231
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.
Definition: Vertex.java:720
Edge getEdgeToParent()
Looks into the edges that use any of the APs that belong to this vertex and returns the edge that has...
Definition: Vertex.java:972
void setVertexId(long vertexId2)
Definition: Vertex.java:261
ArrayList< AttachmentPoint > getCappedAPsThroughout()
Gets attachment points that are used by capping groups throughout the graph levels,...
Definition: Vertex.java:462
String[] getPathIDs(AttachmentPoint apA, AttachmentPoint apB)
Produces a pair of strings that identify the "path" between two given attachment points.
Definition: Vertex.java:1315
int getFreeAPCountThroughout()
Counts the number of attachment points that are availability throughout the graph level,...
Definition: Vertex.java:410
abstract boolean containsAtoms()
int getIndexOfAP(AttachmentPoint ap)
Returns the position of the given AP in the list of APs of this vertex.
Definition: Vertex.java:949
void removeProperty(Object key)
Definition: Vertex.java:1159
String toString()
Produces a human readable, short string to represent the vertex by its vertex ID, building block ID (...
Definition: Vertex.java:559
Vertex(VertexType vertexType)
Constructor for an empty vertex.
Definition: Vertex.java:183
boolean hasSymmetricAP()
Definition: Vertex.java:541
Vertex getParent()
Looks into the edges that use any of the APs that belong to this vertex and returns the vertex which ...
Definition: Vertex.java:996
Vertex.BBType getBuildingBlockType()
Definition: Vertex.java:298
VertexType getVertexType()
Returns the value of the vertex type.
Definition: Vertex.java:1216
DGraph owner
Graph that includes this vertex.
Definition: Vertex.java:65
List< MutationType > getUnfilteredMutationTypes()
Returns the mutation types that are constitutionally configures for this vertex irrespectively on the...
Definition: Vertex.java:823
List< Vertex > getMutationSites()
A list of mutation sites from within this vertex.
Definition: Vertex.java:790
List< MutationType > getMutationTypes(List< MutationType > excludedTypes)
Returns the list of mutation types.
Definition: Vertex.java:859
AttachmentPoint getAPWithId(int i)
Get attachment point that has the given identifier, or null.
Definition: Vertex.java:931
void setAsRCV(boolean isRCV)
Definition: Vertex.java:254
void setGraphOwner(DGraph owner)
Definition: Vertex.java:768
DGraph getGraphOwner()
Returns the graph this vertex belongs to or null.
Definition: Vertex.java:779
int buildingBlockId
Index of this building block in the library of building blocks, or negative if this vertex is not par...
Definition: Vertex.java:76
BBType buildingBlockType
Definition: Vertex.java:137
Map< Object, Object > copyStringBasedProperties()
Copies all the string-based properties and properties defined in the Vertex#uniquefyingPropertyKeys s...
Definition: Vertex.java:1174
boolean sameVertexFeatures(Vertex other, StringBuilder reason)
Compares this and another vertex ignoring vertex IDs.
Definition: Vertex.java:644
boolean sameAs(Vertex other, StringBuilder reason)
Compares this and another vertex ignoring vertex IDs.
Definition: Vertex.java:612
ArrayList< Vertex > getChilddren()
Looks into the edges that use any of the APs that belong to this vertex and returns the list of verti...
Definition: Vertex.java:1085
ArrayList< APClass > getAllAvailableAPClasses()
Returns the list of all APClasses present on free attachment point on this vertex.
Definition: Vertex.java:742
abstract List< AttachmentPoint > getAttachmentPoints()
void setBuildingBlockId(int buildingBlockId)
Definition: Vertex.java:291
ArrayList< AttachmentPoint > getAPsFromChildren()
Looks into the edges that use any of the APs that belong to this vertex and returns the list of attac...
Definition: Vertex.java:1026
abstract List< SymmetricAPs > getSymmetricAPSets()
SymmetricAPs getSymmetricAPs(AttachmentPoint ap)
For the given attachment point index locate the symmetric partners i.e.
Definition: Vertex.java:333
Object getProperty(Object property)
Definition: Vertex.java:1136
abstract int getHeavyAtomsCount()
static Vertex convertIACToVertex(IAtomContainer iac, Vertex.BBType bbt)
Processes an IAtomContainer and builds a Vertex that is an instance of Fragment.
Definition: Vertex.java:1345
boolean hasProperty(Object property)
Definition: Vertex.java:1126
List< MutationType > allowedMutationTypes
List of mutations that we can perform on this vertex.
Definition: Vertex.java:159
static Vertex fromJson(String json)
Definition: Vertex.java:1202
void setUniquefyingProperty(String key)
Add the given key among the properties that are checked for equality when comparing vertices with the...
Definition: Vertex.java:1112
boolean removeMutationType(MutationType mt)
Removes the specified mutation type.
Definition: Vertex.java:835
boolean sameAs(Vertex other)
Compares this and another vertex ignoring vertex IDs.
Definition: Vertex.java:597
void setBuildingBlockType(Vertex.BBType buildingBlockType)
Definition: Vertex.java:305
int getCappedAPCountThroughout()
Counts the number of attachment points that are used by BBType#CAP vertex.
Definition: Vertex.java:493
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.
Definition: Vertex.java:166
Vertex(VertexType vertexType, long id)
Constructor for an identified vertex without attachment points.
Definition: Vertex.java:199
abstract IAtomContainer getIAtomContainer()
boolean hasFreeAP()
Definition: Vertex.java:500
void setProperty(Object key, Object property)
Definition: Vertex.java:1148
long vertexId
Unique identifier associated with the vertex instance.
Definition: Vertex.java:70
ArrayList< AttachmentPoint > getFreeAPThroughout()
Gets attachment points that are availability throughout the graph level, i.e., checks also across the...
Definition: Vertex.java:382
AttachmentPoint getAP(int i)
Get attachment point i on this vertex.
Definition: Vertex.java:920
static Vertex newVertexFromLibrary(int bbId, Vertex.BBType bbt, FragmentSpace fragSpace)
Builds a new molecular fragment kind of vertex.
Definition: Vertex.java:214
abstract void addSymmetricAPSet(SymmetricAPs symAPs)
Edge getEdgeWith(Vertex other)
Finds the edge between this and the other vertex, if it exists.
Definition: Vertex.java:1419
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
Utilities for graphs.
Definition: GraphUtils.java:40
static synchronized long getUniqueVertexIndex()
Unique counter for the number of graph vertices generated.
Definition: GraphUtils.java:97
Tool to generate random numbers and random decisions.
Definition: Randomizer.java:35
The type of building block.
Definition: Vertex.java:86
static BBType parseInt(int i)
Translates the integer into the enum.
Definition: Vertex.java:103
Flag declaring the type of Vertex implementation.
Definition: Vertex.java:172
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...