20package denoptim.utils;
22import java.util.ArrayList;
23import java.util.HashMap;
27import org.jgrapht.graph.DefaultUndirectedGraph;
29import denoptim.exception.DENOPTIMException;
30import denoptim.fragspace.FragmentSpace;
31import denoptim.graph.AttachmentPoint;
32import denoptim.graph.DGraph;
33import denoptim.graph.Edge;
34import denoptim.graph.Edge.BondType;
35import denoptim.graph.EmptyVertex;
36import denoptim.graph.Fragment;
37import denoptim.graph.Ring;
38import denoptim.graph.SymmetricVertexes;
39import denoptim.graph.Template;
40import denoptim.graph.Vertex;
41import denoptim.graph.simplified.Node;
42import denoptim.graph.simplified.NodeConnection;
43import denoptim.graph.simplified.UndirectedEdge;
104 String[] s1 = strGraph.split(
"\\s+");
105 int gcode = Integer.parseInt(s1[0]);
113 for (
int i=3; i<s1.length; i++)
115 oStr = oStr +
" " + s1[i];
119 int beginningOfSymSets = oStr.indexOf(
"SymmetricSet");
120 if (beginningOfSymSets == -1)
126 rStr = oStr.substring(0,beginningOfSymSets);
127 sStr = oStr.substring(beginningOfSymSets);
131 String[] s2 = vStr.split(
",");
133 ArrayList<Vertex> vertices =
new ArrayList<>();
136 for (
int i=0; i<s2.length; i++)
138 String[] s3 = s2[i].split(
"_");
141 int vid = Integer.parseInt(s3[0]);
143 int molid = Integer.parseInt(s3[1]) - 1;
146 Integer.parseInt(s3[2]));
149 if (fragSpace.isDefined())
162 ArrayList<Edge> edges =
new ArrayList<>();
165 if (eStr.contains(
","))
167 s2 = eStr.split(
",");
168 for (
int i=0; i<s2.length; i++)
170 String[] s4 = s2[i].split(
"_");
171 int srcVrtxID = Integer.parseInt(s4[0]);
173 int srcAPID = Integer.parseInt(s4[1]);
175 int trgVrtxID = Integer.parseInt(s4[2]);
177 int trgAPID = Integer.parseInt(s4[3]);
189 for (
int j = 0, apsFound = 0; apsFound < 2; j++) {
190 Vertex vertex = vertices.get(j);
208 srcAP = vertex.
getAP(srcAPID);
230 trgAP = vertex.
getAP(trgAPID);
237 }
catch (IndexOutOfBoundsException e) {
238 throw new IllegalStateException(
"Searching for srcVrtxID:"
239 + srcVrtxID +
", srcAPID:"
240 + srcAPID +
", trgVrtxID:"
241 + trgVrtxID +
", trgAPID:"
242 + trgAPID +
", but source or target " +
243 "attachment point not present on source or target" +
244 " vertex. "+strGraph, e);
247 Edge ne =
new Edge(srcAP, trgAP, btype);
253 ArrayList<Ring> rings =
new ArrayList<>();
254 String[] sr2 = rStr.split(
"DENOPTIMRing ");
255 for (
int i=1; i<sr2.length; i++)
258 String sr5 = sr4.substring(sr4.indexOf(
"=") + 1).trim();
259 sr5 = sr5.substring(1,sr5.length()-2);
260 String[] sr6 = sr5.split(
",\\s");
261 ArrayList<Vertex> lstVerteces =
262 new ArrayList<Vertex>();
263 for (
int j=0; j<sr6.length; j++)
265 String sr7[] = sr6[j].split(
"_");
268 int vid = Integer.parseInt(sr7[0]);
272 if (v.getVertexId() == vid)
285 List<SymmetricVertexes> symSets =
new ArrayList<SymmetricVertexes>();
286 String[] ss8 = sStr.split(
"SymmetricSet ");
287 for (
int i=1; i<ss8.length; i++)
290 String ss5 = ss4.substring(ss4.indexOf(
"=") + 1).trim();
291 ss5 = ss5.substring(1,ss5.length()-2);
292 String[] ss6 = ss5.split(
",\\s");
293 ArrayList<Integer> symVrtxIds =
new ArrayList<Integer>();
294 for (
int j=0; j<ss6.length; j++)
296 symVrtxIds.add(Integer.parseInt(ss6[j]));
300 for (Integer vid : symVrtxIds)
303 .filter(v -> v.getVertexId()==vid)
304 .forEach(v -> ss.
add(v));
314 long vid = r.getHeadVertex().getVertexId();
317 if (e.getTrgVertex() == vid || e.getSrcVertex() == vid)
319 r.setBondType(e.getBondType());
346 public static DefaultUndirectedGraph<Vertex, UndirectedEdge>
349 DefaultUndirectedGraph<Vertex, UndirectedEdge> g =
351 Map<Vertex,Integer> vis =
new HashMap<Vertex,Integer>();
370 Vertex vA = e.getSrcAP().getOwner();
371 Vertex vB = e.getTrgAP().getOwner();
375 e.getTrgAP(), e.getBondType()));
381 Vertex vA = r.getHeadVertex();
382 Vertex vB = r.getTailVertex();
408 public static DefaultUndirectedGraph<Node, NodeConnection>
411 DefaultUndirectedGraph<Node, NodeConnection> g =
419 g.addVertex(
new Node(v));
422 g.addVertex(
new Node(v));
428 Vertex vA = e.getSrcAP().getOwner();
429 Vertex vB = e.getTrgAP().getOwner();
442 Vertex vA = r.getHeadVertex();
443 Vertex vB = r.getTailVertex();
456 Vertex srcVrtx = ap.getOwner();
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....
void setAPClass(String apClass)
Set the Attachment Point class.
BondType getBondType()
Returns the bond type preferred by this attachment point as defined by the APClass,...
Container for the list of vertices and the edges that connect them.
ArrayList< AttachmentPoint > getAvailableAPs()
Returns the list of available attachment points contained in this graph.
List< Vertex > getVertexList()
List< Edge > getEdgeList()
boolean isVertexInRing(Vertex v)
This class represents the edge between two vertices.
AttachmentPoint getSrcAP()
An empty vertex has the behaviors of a vertex, but has no molecular structure.
void addAP()
Adds an attachment point with no APClass or other attribute.
Class representing a continuously connected portion of chemical object holding attachment points.
This class represents the closure of a ring in a spanning tree.
boolean add(T item)
Adds an item to this list, if not already present.
A collection of Vertexs that are related by a relation that we call "symmetry", even though this clas...
A vertex is a data structure that has an identity and holds a list of AttachmentPoints.
Edge getEdgeToParent()
Looks into the edges that use any of the APs that belong to this vertex and returns the edge that has...
Vertex getParent()
Looks into the edges that use any of the APs that belong to this vertex and returns the vertex which ...
Object getProperty(Object property)
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.
This class represents an edge that is undirected and ignores attachment points.
This class represents a subgraph feature that defined the structure of a graph.
static final String REFTOVERTEXKERNEL
Property if Vertex used to store the reference to the corresponding Node.
This class represents an undirected version of the edge between two vertices.
Possible chemical bond types an edge can represent.
static BondType parseStr(String string)
The type of building block.
static BBType parseInt(int i)
Translates the integer into the enum.