$darkmode
DENOPTIM
EmptyVertex.java
Go to the documentation of this file.
1package denoptim.graph;
2
3/*
4 * DENOPTIM
5 * Copyright (C) 2019 Marco Foscato <marco.foscato@uib.no>
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as published
9 * by the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
16 *
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21import java.util.ArrayList;
22import java.util.List;
23import java.util.logging.Logger;
24
25import org.openscience.cdk.AtomContainer;
26import org.openscience.cdk.interfaces.IAtomContainer;
27
28import com.google.gson.Gson;
29
30import denoptim.constants.DENOPTIMConstants;
31import denoptim.json.DENOPTIMgson;
32import denoptim.utils.GraphUtils;
33import denoptim.utils.MutationType;
34import denoptim.utils.Randomizer;
35
36
44public class EmptyVertex extends Vertex
45{
49 private List<AttachmentPoint> lstAPs;
50
55 private List<SymmetricAPs> lstSymAPs;
56
57//------------------------------------------------------------------------------
58
62 public EmptyVertex()
63 {
65 lstAPs = new ArrayList<AttachmentPoint>();
66 lstSymAPs = new ArrayList<SymmetricAPs>();
67 }
68
69//------------------------------------------------------------------------------
70
78 public EmptyVertex(BBType type)
79 {
81 lstAPs = new ArrayList<AttachmentPoint>();
82 lstSymAPs = new ArrayList<SymmetricAPs>();
83 buildingBlockType = type;
84 }
85
86//------------------------------------------------------------------------------
87
95 public EmptyVertex(long id)
96 {
97 super(VertexType.EmptyVertex, id);
98 lstAPs = new ArrayList<AttachmentPoint>();
99 lstSymAPs = new ArrayList<SymmetricAPs>();
100 }
101
102//------------------------------------------------------------------------------
103
113 public EmptyVertex(long id, ArrayList<AttachmentPoint> lstAPs,
114 ArrayList<SymmetricAPs> lstSymAPs, boolean isRCV)
115 {
116 super(VertexType.EmptyVertex, id);
117 this.lstAPs = lstAPs;
118 this.lstSymAPs = lstSymAPs;
120 }
121
122//------------------------------------------------------------------------------
123
124 public List<AttachmentPoint> getAttachmentPoints()
125 {
126 return lstAPs;
127 }
128
129//------------------------------------------------------------------------------
130
131 public void setSymmetricAP(List<SymmetricAPs> sAPs)
132 {
133 lstSymAPs = sAPs;
134 }
135
136//------------------------------------------------------------------------------
137
138 public List<SymmetricAPs> getSymmetricAP()
139 {
140 return lstSymAPs;
141 }
142
143//------------------------------------------------------------------------------
144
154 @Override
156 {
157 for (SymmetricAPs symmetricSet : lstSymAPs)
158 {
159 if (symmetricSet.contains(ap))
160 {
161 return symmetricSet;
162 }
163 }
164 return null;
165 }
166
167//------------------------------------------------------------------------------
168
169 public int getNumberOfAPs()
170 {
171 return lstAPs.size();
172 }
173
174//------------------------------------------------------------------------------
175
181 public ArrayList<Integer> getFreeAPList()
182 {
183 ArrayList<Integer> lstAvailableAP = new ArrayList<>();
184 for (int i=0; i<lstAPs.size(); i++)
185 {
186 if (lstAPs.get(i).isAvailable())
187 lstAvailableAP.add(i);
188 }
189 return lstAvailableAP;
190 }
191
192//------------------------------------------------------------------------------
193
194 public int getFreeAPCount()
195 {
196 int n = 0;
197 for (AttachmentPoint denoptimAttachmentPoint : lstAPs) {
198 if (denoptimAttachmentPoint.isAvailable())
199 n++;
200 }
201 return n;
202 }
203
204//------------------------------------------------------------------------------
205
206 public boolean hasFreeAP()
207 {
208 for (AttachmentPoint denoptimAttachmentPoint : lstAPs) {
209 if (denoptimAttachmentPoint.isAvailable())
210 return true;
211 }
212 return false;
213 }
214
215//------------------------------------------------------------------------------
216
222 public boolean hasSymmetricAP()
223 {
224 return !lstSymAPs.isEmpty();
225 }
226
227//------------------------------------------------------------------------------
228
229 @Override
230 public String toString()
231 {
232 return getVertexId() + "_EmptyVertex";
233 }
234
235//------------------------------------------------------------------------------
236
237 public void cleanup()
238 {
239 if (lstSymAPs != null)
240 {
241 lstSymAPs.clear();
242 }
243 if (lstAPs != null)
244 {
245 lstAPs.clear();
246 }
247 }
248
249//------------------------------------------------------------------------------
250
255 @Override
257 {
259 c.setAsRCV(this.isRCV());
262
264
265 for (AttachmentPoint ap : lstAPs)
266 {
267 AttachmentPoint cAp = new AttachmentPoint(c, -1, null,
268 ap.getAPClass());
269 cAp.setCutId(ap.getCutId());
270 cAp.setID(ap.getID());
271 c.lstAPs.add(cAp);
272 }
273
274 List<SymmetricAPs> cLstSymAPs = new ArrayList<SymmetricAPs>();
275 for (SymmetricAPs symAPs : lstSymAPs)
276 {
277 SymmetricAPs cSymAPs = new SymmetricAPs();
278 for (AttachmentPoint ap : symAPs)
279 {
280 cSymAPs.add(c.getAP(ap.getIndexInOwner()));
281 }
282 cLstSymAPs.add(cSymAPs);
283 }
284
285 c.setSymmetricAPSets(cLstSymAPs);
287 if (uniquefyingPropertyKeys!=null)
289 return c;
290 }
291
292//------------------------------------------------------------------------------
293
298 public void addAP() {
299 AttachmentPoint ap = new AttachmentPoint(this);
300 getAttachmentPoints().add(ap);
301 }
302
303//------------------------------------------------------------------------------
304
309 public void addAP(APClass apClass) {
310 AttachmentPoint ap = new AttachmentPoint(this,
311 -1, null, apClass);
312 getAttachmentPoints().add(ap);
313 }
314
315//------------------------------------------------------------------------------
316
328 public boolean sameAs(EmptyVertex other, StringBuilder reason)
329 {
330 if (this.uniquefyingPropertyKeys.size()!=0
331 || other.uniquefyingPropertyKeys.size()!=0)
332 {
333 if (!this.uniquefyingPropertyKeys.equals(other.uniquefyingPropertyKeys))
334 return false;
335
336 for (String k : this.uniquefyingPropertyKeys)
337 {
338 if (!this.properties.get(k).equals(other.properties.get(k)))
339 return false;
340 }
341 }
342 return sameVertexFeatures(other, reason);
343 }
344
345//------------------------------------------------------------------------------
346
348 {
349 return 0;
350 }
351
352//------------------------------------------------------------------------------
353
354 public boolean containsAtoms()
355 {
356 return false;
357 }
358
359//-----------------------------------------------------------------------------
360
368 @Override
369 public IAtomContainer getIAtomContainer()
370 {
371 IAtomContainer iac = new AtomContainer();
372 iac.setProperty(DENOPTIMConstants.APSTAG, "");
373 iac.setProperty(DENOPTIMConstants.VERTEXJSONTAG,this.toJson());
374
375 return iac;
376 }
377
378//------------------------------------------------------------------------------
379
386 @Override
387 public IAtomContainer getIAtomContainer(Logger logger,
388 Randomizer rng, boolean removeUsedRCAs, boolean rebuild)
389 {
390 return getIAtomContainer();
391 }
392
393//------------------------------------------------------------------------------
394
401 public String toJson()
402 {
403 Gson gson = DENOPTIMgson.getWriter();
404 String jsonOutput = gson.toJson(this);
405 return jsonOutput;
406 }
407
408//------------------------------------------------------------------------------
409
416 public static EmptyVertex fromJson(String json)
417 {
418 Gson gson = DENOPTIMgson.getReader();
419 EmptyVertex ev = gson.fromJson(json, EmptyVertex.class);
421 {
422 ap.setOwner(ev);
423 }
424 return ev;
425 }
426
427//-----------------------------------------------------------------------------
428
434 public ArrayList<APClass> getAllAPClasses()
435 {
436 ArrayList<APClass> lst = new ArrayList<APClass>();
437 for (AttachmentPoint ap : lstAPs)
438 {
439 APClass apCls = ap.getAPClass();
440 if (!lst.contains(apCls))
441 {
442 lst.add(apCls);
443 }
444 }
445 return lst;
446 }
447
448//-----------------------------------------------------------------------------
449
450 @Override
451 protected void setSymmetricAPSets(List<SymmetricAPs> sAPs)
452 {
453 this.lstSymAPs = sAPs;
454 }
455
456//-----------------------------------------------------------------------------
457
458 @Override
459 protected void addSymmetricAPSet(SymmetricAPs symAPs)
460 {
461 if (this.lstSymAPs==null)
462 {
463 this.lstSymAPs = new ArrayList<SymmetricAPs>();
464 }
465 this.lstSymAPs.add(symAPs);
466 }
467
468//-----------------------------------------------------------------------------
469
470 @Override
471 public List<SymmetricAPs> getSymmetricAPSets()
472 {
473 return lstSymAPs;
474 }
475
476//------------------------------------------------------------------------------
477
486 @Override
487 public List<Vertex> getMutationSites(List<MutationType> ignoredTypes)
488 {
489 List<Vertex> lst = new ArrayList<Vertex>();
490 switch (getBuildingBlockType())
491 {
492 case CAP:
493 break;
494
495 case SCAFFOLD:
496 break;
497
498 default:
499 if (getMutationTypes(ignoredTypes).size()>0)
500 lst.add(this);
501 break;
502 }
503 return lst;
504 }
505
506//------------------------------------------------------------------------------
507
508}
General set of constants used in DENOPTIM.
static final String VERTEXJSONTAG
SDF tag containing vertex encoding in JSON format.
static final String APSTAG
SDF tag defining attachment points.
An attachment point (AP) is a possibility to attach a Vertex onto the vertex holding the AP (i....
void setID(int id)
Sets the unique integer that is used to sort list of attachment points.
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.
List< AttachmentPoint > lstAPs
Attachment points on this vertex.
List< SymmetricAPs > getSymmetricAP()
SymmetricAPs getSymmetricAPs(AttachmentPoint ap)
For the given attachment point index locate the symmetric partners i.e.
void addSymmetricAPSet(SymmetricAPs symAPs)
IAtomContainer getIAtomContainer()
Although empty vertex do not contain atoms, by definitions, we allow the generation of an SDF represe...
ArrayList< Integer > getFreeAPList()
IAtomContainer getIAtomContainer(Logger logger, Randomizer rng, boolean removeUsedRCAs, boolean rebuild)
Although empty vertex do not contain atoms, by definitions, we allow the generation of an SDF represe...
List< SymmetricAPs > lstSymAPs
List of AP sets that are related to each other, so that we call them "symmetric" (though symmetry is ...
EmptyVertex(BBType type)
Constructor for an identified vertex without attachment points.
boolean sameAs(EmptyVertex other, StringBuilder reason)
Compares this and another vertex ignoring vertex IDs.
EmptyVertex clone()
Returns a deep-copy of this vertex.
void addAP(APClass apClass)
Adds an attachment point with the specified APClass.
EmptyVertex(long id)
Constructor for an identified vertex without attachment points.
EmptyVertex()
Constructor for an empty vertex.
ArrayList< APClass > getAllAPClasses()
Returns the list of all APClasses on present on this fragment.
void setSymmetricAP(List< SymmetricAPs > sAPs)
void setSymmetricAPSets(List< SymmetricAPs > sAPs)
String toJson()
Produces a string that represents this vertex and that adheres to the JSON format.
List< SymmetricAPs > getSymmetricAPSets()
String toString()
Produces a human readable, short string to represent the vertex by its vertex ID, building block ID (...
List< Vertex > getMutationSites(List< MutationType > ignoredTypes)
A list of mutation sites from within this vertex.
List< AttachmentPoint > getAttachmentPoints()
EmptyVertex(long id, ArrayList< AttachmentPoint > lstAPs, ArrayList< SymmetricAPs > lstSymAPs, boolean isRCV)
Constructor for an identified vertex.
void addAP()
Adds an attachment point with no APClass or other attribute.
A collection of AttachmentPoints that are related by a relation that we call "symmetry",...
boolean add(T item)
Adds an item to this list, if not already present.
A vertex is a data structure that has an identity and holds a list of AttachmentPoints.
Definition: Vertex.java:61
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
List< MutationType > getMutationTypes()
Returns the list of mutation types.
Definition: Vertex.java:846
void setProperties(Map< Object, Object > properties)
Definition: Vertex.java:1195
int getBuildingBlockId()
Returns the index of the building block that should correspond to the position of the building block ...
Definition: Vertex.java:284
Vertex.BBType getBuildingBlockType()
Definition: Vertex.java:298
List< MutationType > getUnfilteredMutationTypes()
Returns the mutation types that are constitutionally configures for this vertex irrespectively on the...
Definition: Vertex.java:823
void setAsRCV(boolean isRCV)
Definition: Vertex.java:254
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
void setBuildingBlockId(int buildingBlockId)
Definition: Vertex.java:291
void setBuildingBlockType(Vertex.BBType buildingBlockType)
Definition: Vertex.java:305
AttachmentPoint getAP(int i)
Get attachment point i on this vertex.
Definition: Vertex.java:920
Class for de/serializing DENOPTIM graphs from/to JSON format.
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
Flag declaring the type of Vertex implementation.
Definition: Vertex.java:172