20package denoptim.utils;
23import java.util.ArrayList;
24import java.util.Collections;
25import java.util.HashSet;
28import java.util.logging.Level;
29import java.util.logging.Logger;
31import javax.vecmath.Point2d;
32import javax.vecmath.Point3d;
33import javax.vecmath.Vector3d;
35import org.openscience.cdk.Bond;
36import org.openscience.cdk.PseudoAtom;
37import org.openscience.cdk.interfaces.IAtom;
38import org.openscience.cdk.interfaces.IAtomContainer;
39import org.openscience.cdk.interfaces.IBond;
41import denoptim.constants.DENOPTIMConstants;
42import denoptim.exception.DENOPTIMException;
43import denoptim.graph.AttachmentPoint;
44import denoptim.graph.Fragment;
45import denoptim.io.DenoptimIO;
58 private String
elm =
"";
92 List<IAtom> dummiesList =
new ArrayList<>();
95 for (IAtom atm : mol.atoms())
102 dummiesList.add(atm);
107 if (symbol.equals(
elm))
109 dummiesList.add(atm);
114 if (
logger.isLoggable(Level.FINEST))
116 StringBuilder sb =
new StringBuilder();
117 sb.append(
"Found "+dummiesList.size()+
" dummy atoms:");
118 for (IAtom du : dummiesList)
123 logger.log(Level.FINEST,sb.toString());
127 for (IAtom du : dummiesList)
130 List<IAtom> nbrOfDu = mol.getConnectedAtomsList(du);
131 for (IAtom nbr : nbrOfDu)
132 mol.removeBond(du,nbr);
136 logger.log(Level.FINEST,
"NOTE! Atom Numbers change: "
137 +
"dummy atom deleted");
147 List<IAtom> dummiesList =
new ArrayList<>();
150 for (IAtom atm : mol.atoms())
157 dummiesList.add(atm);
160 if (symbol.equals(
elm))
162 dummiesList.add(atm);
167 if (
logger.isLoggable(Level.FINEST))
169 StringBuilder sb =
new StringBuilder();
170 sb.append(
"Found "+dummiesList.size()+
" dummy atoms:");
171 for (IAtom du : dummiesList)
176 logger.log(Level.FINEST,sb.toString());
180 for (IAtom du : dummiesList)
183 List<IAtom> nbrOfDu = mol.getConnectedAtomsList(du);
184 int numOfTerms = nbrOfDu.size();
185 for (IAtom nbr : nbrOfDu)
186 mol.removeBond(du,nbr);
189 List<Set<IAtom>> goupsOfTerms =
new ArrayList<>();
190 List<Integer> hapticity =
new ArrayList<>();
191 for (
int i=0; i<numOfTerms; i++)
198 IAtom nbrI = nbrOfDu.get(i);
199 Set<IAtom> ligOfNbrI =
201 if (!ligOfNbrI.isEmpty())
203 goupsOfTerms.add(ligOfNbrI);
204 hapticity.add(ligOfNbrI.size());
209 if (
logger.isLoggable(Level.FINEST))
211 StringBuilder sb =
new StringBuilder();
212 sb.append(
"There are "+goupsOfTerms.size()+
" groups of terms");
213 for (
int i=0; i<goupsOfTerms.size(); i++)
215 Set<IAtom> s = goupsOfTerms.get(i);
216 sb.append(
" Group "+i+
" - Hapticity: "+hapticity.get(i)
220 sb.append((mol.indexOf(sa)+1)+
225 logger.log(Level.FINEST, sb.toString());
229 if (goupsOfTerms.size() > 1)
233 boolean ligandFound =
false;
234 List<Point3d> allCandidates =
new ArrayList<Point3d>();
235 for (
int i=0; i<goupsOfTerms.size(); i++)
237 Set<IAtom> grp = goupsOfTerms.get(i);
240 Point3d candidateDuP3d =
new Point3d();
241 for (IAtom atm : grp)
245 Point3d ligP3d = atm.getPoint3d();
246 candidateDuP3d.x = candidateDuP3d.x + ligP3d.x;
247 candidateDuP3d.y = candidateDuP3d.y + ligP3d.y;
248 candidateDuP3d.z = candidateDuP3d.z + ligP3d.z;
252 Point2d ligP2d = atm.getPoint2d();
253 candidateDuP3d.x = candidateDuP3d.x + ligP2d.x;
254 candidateDuP3d.y = candidateDuP3d.y + ligP2d.y;
255 candidateDuP3d.z = 0.0000;
258 allCandidates.add(candidateDuP3d);
259 candidateDuP3d.x = candidateDuP3d.x / (double) hapticity.get(i);
260 candidateDuP3d.y = candidateDuP3d.y / (double) hapticity.get(i);
261 candidateDuP3d.z = candidateDuP3d.z / (double) hapticity.get(i);
264 Point3d dummyP3d =
new Point3d();
267 Point3d du3d = du.getPoint3d();
274 Point2d du2d = du.getPoint2d();
282 double dist = candidateDuP3d.distance(dummyP3d);
287 String msg =
"More then one group of atoms may "
288 +
"correspond to the ligand. Not able "
289 +
"to identify the ligand!";
300 String msg =
"Dummy atom does not seem to be placed at the "
301 +
"centroid of a multihapto ligand. "
303 +
"Candidates: " + allCandidates
304 +
"See current molecule in 'error.sdf'";
311 Set<IAtom> ligand = goupsOfTerms.get(ligandID);
312 for (
int i=0; i<goupsOfTerms.size(); i++)
317 Set<IAtom> grp = goupsOfTerms.get(i);
319 for (IAtom centralAtm : grp)
321 for (IAtom ligandAtm : ligand)
323 logger.log(Level.FINEST,
"Making a bond between: "
324 + mol.indexOf(ligandAtm)
327 + mol.indexOf(centralAtm)
330 IBond bnd =
new Bond(ligandAtm,centralAtm);
339 logger.log(Level.FINEST,
"NOTE! Atom Numbers change: "
340 +
"dummy atom deleted");
359 IAtomContainer mol, List<Boolean> doneFlag)
361 Set<IAtom> outSet =
new HashSet<>();
364 int idx = inList.indexOf(seed);
365 doneFlag.set(idx,
true);
369 List<IAtom> connToSeed = mol.getConnectedAtomsList(seed);
370 connToSeed.retainAll(inList);
371 for (IAtom nbr : connToSeed)
373 int idx2 = inList.indexOf(nbr);
374 if (!doneFlag.get(idx2))
377 Set<IAtom> recursiveOut =
380 outSet.addAll(recursiveOut);
398 List<Boolean> flg =
new ArrayList<>();
399 for (
int i = 0; i<size; i++) {
409 return mol.indexOf(atm) + 1;
430 for (IAtom atm : frag.
atoms())
437 for (IAtom nbr : nbrs)
445 continue loopOverAtoms;
451 loopOverNeigborsOfOneAtom:
452 for(
int i=0; i<(nbrs.size()+nbrAP.size()); i++)
458 pL = nbrAP.get(i-nbrs.size()).getDirectionVector();
462 for (
int j=i+1; j<(nbrs.size()+nbrAP.size()); j++)
468 pR = nbrAP.get(j-nbrs.size()).getDirectionVector();
476 List<Point3d> placesToAvoid =
new ArrayList<Point3d>();
478 placesToAvoid.add(ap.getDirectionVector());
486 IBond dummyBnd =
new Bond(dummyAtm,atm);
488 break loopOverNeigborsOfOneAtom;
515 IAtomContainer mol, List<Point3d> placesToAvoid)
521 List<Vector3d> allBusyDirections =
new ArrayList<Vector3d>();
522 List<IAtom> nbrs = mol.getConnectedAtomsList(atmA);
523 for (IAtom nbr : nbrs)
528 allBusyDirections.add(vLoc);
530 Vector3d vLocOpposite =
new Vector3d(vLoc.x * -1.0, vLoc.y * -1.0,
532 vLocOpposite.normalize();
533 allBusyDirections.add(vLocOpposite);
535 for (Point3d pOther : placesToAvoid)
539 allBusyDirections.add(vLoc);
541 Vector3d vLocOpposite =
new Vector3d(vLoc.x * -1.0, vLoc.y * -1.0,
543 vLocOpposite.normalize();
544 allBusyDirections.add(vLocOpposite);
554 ArrayList<Vector3d> allAttempts =
new ArrayList<Vector3d>();
555 ArrayList<Double> allAttemptsMinVal =
new ArrayList<Double>();
556 double angStep = 22.0;
557 double maxStepD = 360.0 / angStep;
558 int maxStep = (int) maxStepD;
559 double forbiddenRadius = 0.2;
560 for(
int j=1; j<3; j++)
562 for(
int step = 0; step<maxStep; step++)
564 Vector3d vADuTry =
new Vector3d();
567 vADuTry =
new Vector3d(vNorm.x,vNorm.y,vNorm.z);
570 new Vector3d(vNorm.x*(Math.sqrt(2.0)),
571 vNorm.y*(Math.sqrt(2.0)),
572 vNorm.z*(Math.sqrt(2.0))));
577 double ang = angStep * step;
583 boolean skip =
false;
585 for (
int i=0; i<allBusyDirections.size(); i++)
587 Vector3d busyDir = allBusyDirections.get(i);
590 double l = diffVec.length();
591 if (l < forbiddenRadius)
605 allAttempts.add(vADuTry);
606 allAttemptsMinVal.add(min);
611 double max = Collections.max(allAttemptsMinVal);
612 int best = allAttemptsMinVal.indexOf(max);
613 Vector3d vADu =
new Vector3d();
614 vADu = allAttempts.get(best);
618 Point3d duP3dB =
new Point3d(vADu.x, vADu.y, vADu.z);
General set of constants used in DENOPTIM.
static final String DUMMYATMSYMBOL
Symbol of dummy atom.
An attachment point (AP) is a possibility to attach a Vertex onto the vertex holding the AP (i....
Class representing a continuously connected portion of chemical object holding attachment points.
List< IAtom > getConnectedAtomsList(IAtom atom)
int getAPCountOnAtom(int srcAtmId)
Returns the number of APs currently defined on a specific atom source.
Iterable< IAtom > atoms()
ArrayList< AttachmentPoint > getAPsFromAtom(IAtom srcAtm)
IAtomContainer getIAtomContainer()
int getConnectedAtomsCount(IAtom atom)
Utility methods for input/output.
static void writeSDFFile(String fileName, IAtomContainer mol)
Writes IAtomContainer to SDF file.
static final String NL
Newline character from system.
Utilities for working in the Cartesian space.
static Vector3d getSumOfVector(Vector3d A, Vector3d B)
Get sum of vector A and B.
static Vector3d getDiffOfVector(Vector3d A, Vector3d B)
Calculates the vector difference of vectors A and B.
static void translateOrigin(Vector3d v, Point3d newOrigin)
Changes the origin of a vector.
static Vector3d getNormalDirection(Vector3d dir)
Generate a vector that is perpendicular to the given one.
static Vector3d getVectorFromTo(Point3d a, Point3d b)
Creates an object Vector3d that originates from point a and goes to point b.
static void rotatedVectorWAxisAngle(Vector3d v, Vector3d axis, double ang)
Rotate a vector according to a given rotation axis and angle.
Toll to add/remove dummy atoms from linearities or multi-hapto sites.
static void addDummiesOnLinearities(Fragment frag, double angLim)
Append dummy atoms on otherwise linear arrangements of atoms.
List< Boolean > getFlagsVector(int size)
Generates a vector of boolean flags.
static int getSDFAtomNumber(IAtomContainer mol, IAtom atm)
Set< IAtom > exploreConnectedToAtom(IAtom seed, List< IAtom > inList, IAtomContainer mol, List< Boolean > doneFlag)
Explore connected systems in a list of atoms and returns all the atoms that can be reached starting f...
static IAtom getDummyInSafeDirection(IAtom atmA, Point3d pB, IAtomContainer mol, List< Point3d > placesToAvoid)
Generates a dummy atom 0.1 nm from atom A in a place that is safe for a dummy atom.
DummyAtomHandler(String elm, Logger logger)
Constructor defining a specific elemental symbol to consider the symbol of dummy atoms.
String elm
The elemental symbol that we consider to be the symbol of a dummy atom.
Logger logger
Program-specific logger.
IAtomContainer removeDummy(IAtomContainer mol)
Removes all dummy atoms and the bonds connecting them to other atoms.
IAtomContainer removeDummyInHapto(IAtomContainer mol)
Some useful math operations.
static double angle(Point3d a, Point3d b, Point3d c)
Calculate the angle between the 3 points.
Utilities for molecule conversion.
static String getSymbolOrLabel(IAtom atm)
Gets either the elemental symbol (for standard atoms) of the label (for pseudo-atoms).
static boolean isDummy(IAtom atm)
Checks if the given atom is a dummy atom based on the elemental symbol and the string used for dummy ...
static Point3d getPoint3d(IAtom atm)
Return the 3D coordinates, if present.