$darkmode
DENOPTIM
RingClosure.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;
22import java.util.logging.Level;
23import java.util.logging.Logger;
24
25import javax.vecmath.Point3d;
26import javax.vecmath.Vector3d;
27
28import denoptim.constants.DENOPTIMConstants;
29
42public class RingClosure
43{
47 private Point3d h1;
48
52 private Point3d h2;
53
57 private Point3d t1;
58
62 private Point3d t2;
63
67 private Vector3d h;
68
72 private Vector3d t;
73
77 private double distH1T2;
78
82 private double distH2T1;
83
87 private double distH2T2;
88
92 private double qscore = Double.NaN;
93
98
99//-----------------------------------------------------------------------------
100
106 {
107 this.settings = settings;
108 }
109
110//-----------------------------------------------------------------------------
111
116 public RingClosure(Point3d h1, Point3d h2, Point3d t1, Point3d t2)
117 {
118 this.h1 = h1;
119 this.h2 = h2;
120 this.t1 = t1;
121 this.t2 = t2;
122 }
123
124//-----------------------------------------------------------------------------
125
133 {
134 this.distH1T2 = h1.distance(t2);
135 this.distH2T1 = h2.distance(t1);
136 this.distH2T2 = h2.distance(t2);
137 this.h = new Vector3d(h2.x-h1.x, h2.y-h1.y, h2.z-h1.z);
138 this.t = new Vector3d(t2.x-t1.x, t2.y-t1.y, t2.z-t1.z);
139 this.h.normalize();
140 this.t.normalize();
141 }
142
143//-----------------------------------------------------------------------------
144
154 public boolean isClosable(ArrayList<Double> clsablConds,Logger logger)
155 {
156 return isClosable(clsablConds.get(0),
157 clsablConds.get(1),
158 clsablConds.get(2),
159 clsablConds.get(3),
160 clsablConds.get(4),
161 clsablConds.get(5),
162 clsablConds.get(6),
163 logger);
164 }
165
166//-----------------------------------------------------------------------------
167
184 public boolean isClosable (double minDH1T2, double maxDH1T2,
185 double minDH2T1, double maxDH2T1,
186 double minDH2T2, double maxDH2T2,
187 double maxDotHT, Logger logger)
188 {
189 boolean res = false;
190 this.distH1T2 = h1.distance(t2);
191 this.distH2T1 = h2.distance(t1);
192 this.distH2T2 = h2.distance(t2);
193 if (logger.isLoggable(Level.FINEST))
194 {
195 StringBuilder sb = new StringBuilder();
196 String NL = DENOPTIMConstants.EOL;
197 sb.append("Values for evaluation of closability:");
198 sb.append(" distH1T2: " + String.format("%8.4f",distH1T2));
199 sb.append(" min: " + String.format("%8.4f",minDH1T2));
200 sb.append(" max: " + String.format("%8.4f",maxDH1T2) + NL);
201 sb.append(" distH2T1: " + String.format("%8.4f",distH2T1));
202 sb.append(" min: " + String.format("%8.4f",minDH2T1));
203 sb.append(" max: " + String.format("%8.4f",maxDH2T1) + NL);
204 sb.append(" distH2T2: " + String.format("%8.4f",distH2T2));
205 sb.append(" min: " + String.format("%8.4f",minDH2T2));
206 sb.append(" max: " + String.format("%8.4f",maxDH2T2) + NL);
207 h = new Vector3d(h2.x-h1.x, h2.y-h1.y, h2.z-h1.z);
208 t = new Vector3d(t2.x-t1.x, t2.y-t1.y, t2.z-t1.z);
209 h.normalize();
210 t.normalize();
211 sb.append(" dot: " + String.format("%8.4f", h.dot(t)));
212 sb.append(" max: " + String.format("%8.4f%n", maxDotHT));
213 logger.log(Level.FINEST,sb.toString());
214 }
215
216 if (distH1T2 < maxDH1T2 && distH1T2 > minDH1T2 &&
217 distH2T1 < maxDH2T1 && distH2T1 > minDH2T1 &&
218 distH2T2 < maxDH2T2 && distH2T2 > minDH2T2)
219 {
220 h = new Vector3d(h2.x-h1.x, h2.y-h1.y, h2.z-h1.z);
221 t = new Vector3d(t2.x-t1.x, t2.y-t1.y, t2.z-t1.z);
222 h.normalize();
223 t.normalize();
224
225 if (h.dot(t) <= maxDotHT)
226 {
227 logger.log(Level.FINEST," CLOSABLE!");
228 res = true;
229 }
230 }
231 return res;
232 }
233
234//-----------------------------------------------------------------------------
235
241 public double getRingClosureQuality()
242 {
243 if (Double.isNaN(qscore))
244 {
245 double lenH = h1.distance(h2);
246 double lenT = t1.distance(t2);
247 double optDistH1T2 = 0.0;
248 double optDistH2T1 = 0.0;
249 double optDistH1T1 = 0.0;
250 double optDistH2T2 = 0.0;
251 optDistH1T1 = (lenH + lenT) / 2.0;
252 optDistH2T2 = optDistH1T1;
253
254 qscore = Math.abs(h1.distance(t1) - optDistH1T1) +
255 Math.abs(h2.distance(t2) - optDistH2T2) +
256 Math.abs(h1.distance(t2) - optDistH1T2) +
257 Math.abs(h2.distance(t1) - optDistH2T1);
258 }
259 return qscore;
260 }
261
262//-----------------------------------------------------------------------------
263
269 public Point3d getPoint(int i)
270 {
271 if (i == 0)
272 return h1;
273 else if (i == 1)
274 return h2;
275 else if (i == 2)
276 return t1;
277 else if (i == 3)
278 return t2;
279 return null;
280 }
281
282//-----------------------------------------------------------------------------
283
316 public ArrayList<Double> getClosabilityConditions(double etrxTol)
317 {
318 ArrayList<Double> clsablConds = new ArrayList<Double>();
319
320 //Define conditions based on SrcAtom-to-RCA bonds and RC-strategy
321 double lenH = h1.distance(h2);
322 double lenT = t1.distance(t2);
323 double distTolerance = (lenH + lenT) / 2.0;
324 distTolerance = distTolerance * etrxTol * settings.getRCDistTolerance();
325 double minDistH1T2 = -1.0;
326 double minDistH2T1 = -1.0;
327 double minDistH2T2 = -1.0;
328 double maxDistH1T2 = 0.0;
329 double maxDistH2T1 = 0.0;
330 double maxDistH2T2 = 0.0;
331 double maxDotProdHT = settings.getRCDotPrTolerance();
332 maxDistH1T2 = distTolerance;
333 maxDistH2T1 = distTolerance;
334 maxDistH2T2 = lenH + lenT;
335
336 //Collect conditions as a vector
337 clsablConds.add(minDistH1T2);
338 clsablConds.add(maxDistH1T2);
339 clsablConds.add(minDistH2T1);
340 clsablConds.add(maxDistH2T1);
341 clsablConds.add(minDistH2T2);
342 clsablConds.add(maxDistH2T2);
343 clsablConds.add(maxDotProdHT);
344
345 return clsablConds;
346 }
347
348//-----------------------------------------------------------------------------
349
355 {
356 Point3d nH1 = new Point3d(h1.x, h1.y, h1.z);
357 Point3d nH2 = new Point3d(h2.x, h2.y, h2.z);
358 Point3d nT1 = new Point3d(t1.x, t1.y, t1.z);
359 Point3d nT2 = new Point3d(t2.x, t2.y, t2.z);
360 RingClosure nRc = new RingClosure(nH1, nH2, nT1, nT2);
361 return nRc;
362 }
363
364//-----------------------------------------------------------------------------
365
370 public String toString()
371 {
372 String s = "RingClosure [" + h1 + " " + h2 + " " + t1 + " " + t2 + "]";
373 return s;
374 }
375
376//-----------------------------------------------------------------------------
377}
378
General set of constants used in DENOPTIM.
static final String EOL
new line character
RingClosure represents the arrangement of atoms and PseudoAtoms identifying the head and tail of a ch...
Vector3d h
vector head of chain
double distH2T2
Distance H2 T2.
boolean isClosable(ArrayList< Double > clsablConds, Logger logger)
Evaluate closability by comparing the distances and the dot product with the given critera.
Point3d getPoint(int i)
Returns the point requested.
ArrayList< Double > getClosabilityConditions(double etrxTol)
Returns the list of min/max values defining the closability conditions.
double qscore
Quality score of the head and tail vectors alignement.
RingClosure deepCopy()
Returns a deep copy of this RingClosure object.
boolean isClosable(double minDH1T2, double maxDH1T2, double minDH2T1, double maxDH2T1, double minDH2T2, double maxDH2T2, double maxDotHT, Logger logger)
Evaluate closability by comparing the distances and the dot product with the given critera (i....
double distH1T2
Distance H1 T2.
void calculateDescriptors()
Calculate desctiprots (distances and dot product).
Point3d t2
The second point defining the tail vector.
Vector3d t
vector tail of chain
Point3d t1
The firs point defining the tail vector.
double distH2T1
Distance H2 T1.
RingClosure(Point3d h1, Point3d h2, Point3d t1, Point3d t2)
Constructs a RingClosure from the involved points.
Point3d h2
The second point defining the head vector.
RingClosureParameters settings
Parameters.
RingClosure(RingClosureParameters settings)
Constructs an empty RingClosure.
double getRingClosureQuality()
Returns the score evaluating the overal closure quality of this ring closure.
Point3d h1
The firs point defining the head vector.
Parameters and setting related to handling ring closures.