$darkmode
DENOPTIM
ClosableChain.java
Go to the documentation of this file.
1/*
2 * DENOPTIM
3 * Copyright (C) 2019 Marco Foscato <marco.foscato@uib.no>
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU Affero General Public License as published
7 * by the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Affero General Public License for more details.
14 *
15 * You should have received a copy of the GNU Affero General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19package denoptim.graph.rings;
20
21import java.util.ArrayList;
22
23import denoptim.graph.Fragment;
24import denoptim.graph.Vertex;
25import denoptim.graph.Vertex.BBType;
26
34public class ClosableChain implements Cloneable
35{
39 private ArrayList<ChainLink> links;
40
45 private int tuningPoint;
46
47//-----------------------------------------------------------------------------
48
54 {
55 this.links = new ArrayList<ChainLink>();
56 }
57
58//-----------------------------------------------------------------------------
59
64 public ClosableChain(String str)
65 {
66 links = new ArrayList<ChainLink>();
67
68 String words[] = str.trim().split("%");
69
70 String[] parts = words[0].split("_");
71 for (int i=0; i<parts.length; i++)
72 {
73 String clStr = parts[i];
74 String[] clParts = clStr.trim().split("/");
75 int molID = Integer.parseInt(clParts[0]);
76 BBType bbt = BBType.valueOf(clParts[1]);
77 String[] partsAps = clParts[2].split("ap");
78 int apLeft = Integer.parseInt(partsAps[1]);
79 int apRight = Integer.parseInt(partsAps[2]);
80 ChainLink cl = new ChainLink(molID, bbt, apLeft, apRight);
81 links.add(cl);
82 }
83 tuningPoint = Integer.parseInt(words[1]);
84 }
85
86//----------------------------------------------------------------------------
87
92 public void appendLink(ChainLink l)
93 {
94 links.add(l);
95 }
96
97//----------------------------------------------------------------------------
98
103 public void setTurningPoint(int tp)
104 {
105 this.tuningPoint = tp;
106 }
107
108//----------------------------------------------------------------------------
109
114 public ArrayList<ChainLink> getLinks()
115 {
116 return links;
117 }
118
119//-----------------------------------------------------------------------------
120
127 public ChainLink getLink(int i)
128 {
129 return links.get(i);
130 }
131
132//-----------------------------------------------------------------------------
133
139 public int getSize()
140 {
141 return links.size();
142 }
143
144//-----------------------------------------------------------------------------
145
155 {
156 return getLink(tuningPoint).getIdx();
157 }
158
159//-----------------------------------------------------------------------------
160
168 public int involvesVertex(Vertex vert)
169 {
170 int result = -1;
171 if (vert instanceof Fragment)
172 {
173 int vertIdx = ((Fragment)vert).getBuildingBlockId();
174 Vertex.BBType vertFrgTyp = ((Fragment)vert).getBuildingBlockType();
175 for (int i=0; i<links.size(); i++)
176 {
177 ChainLink cl = links.get(i);
178 if (cl.getIdx() == vertIdx &&
179 cl.getFragType() == vertFrgTyp)
180 {
181 result = i;
182 break;
183 }
184 }
185 }
186 return result;
187 }
188
189//-----------------------------------------------------------------------------
190
203 public int involvesVertexAndAP(Vertex vert, int apIDA, int apIDB)
204 {
205 int result = -1;
206 if (vert instanceof Fragment)
207 {
208 int vertMolID = ((Fragment)vert).getBuildingBlockId();
209 Vertex.BBType vertFrgTyp = ((Fragment)vert).getBuildingBlockType();
210 for (int i=0; i<links.size(); i++)
211 {
212 ChainLink cl = links.get(i);
213 if (cl.getIdx() == vertMolID &&
214 cl.getFragType() == vertFrgTyp &&
215 ((cl.getApIdToLeft()==apIDA && cl.getApIdToRight()==apIDB) ||
216 (cl.getApIdToLeft()==apIDB && cl.getApIdToRight()==apIDA)))
217 {
218 result = i;
219 break;
220 }
221 }
222 }
223 return result;
224 }
225
226//-----------------------------------------------------------------------------
227
233 {
235 for (ChainLink l : links)
236 {
237 c.appendLink(l.clone());
238 }
240 return c;
241 }
242
243//-----------------------------------------------------------------------------
244
249 public String toString()
250 {
251 String str = " ClosableChain[";
252 for (ChainLink cc : links)
253 {
254 str = str + cc;
255 }
256 str = str + "]";
257 return str;
258 }
259
260//-----------------------------------------------------------------------------
261}
262
Class representing a continuously connected portion of chemical object holding attachment points.
Definition: Fragment.java:61
A vertex is a data structure that has an identity and holds a list of AttachmentPoints.
Definition: Vertex.java:61
ClosableChain represents a chain of fragments (chain links) that is closable (or candidate closable).
ArrayList< ChainLink > links
List of ChainLinks in this chain.
ChainLink getLink(int i)
Get a specific ChainLink
ClosableChain clone()
Returns a deep-copy.
int involvesVertexAndAP(Vertex vert, int apIDA, int apIDB)
Check whether a combination of vertex and attachment points ID is involved in this chain.
int getTurningPointIdx()
Get the vertex ID of the turning point.Note that since the chain is a path in a graph the relative di...
void appendLink(ChainLink l)
Append a link to this chain.
void setTurningPoint(int tp)
Defined the turning point in the list of links.
ClosableChain(String str)
Constructs a ClosableChain from the string representation.
int involvesVertex(Vertex vert)
Check whether a given vertex is involved in this chain.
ClosableChain()
Constructs an empty ClosableChain.
ArrayList< ChainLink > getLinks()
Get the list of ChainLinks.
int getSize()
Get length of chain.
int tuningPoint
The position of the scaffold vertex: turning point for the direction of the chain.
The type of building block.
Definition: Vertex.java:86
static BBType parseInt(int i)
Translates the integer into the enum.
Definition: Vertex.java:103