19package denoptim.utils;
21import java.io.BufferedReader;
23import java.io.FileReader;
24import java.io.IOException;
25import java.util.ArrayList;
26import java.util.HashMap;
28import java.util.logging.Level;
29import java.util.logging.Logger;
30import java.util.TreeMap;
32import org.openscience.cdk.graph.SpanningTree;
33import org.openscience.cdk.interfaces.IAtom;
34import org.openscience.cdk.interfaces.IAtomContainer;
35import org.openscience.cdk.interfaces.IBond;
36import org.openscience.cdk.interfaces.IChemObjectBuilder;
37import org.openscience.cdk.interfaces.IRingSet;
38import org.openscience.cdk.isomorphism.Mappings;
39import org.openscience.cdk.silent.RingSet;
40import org.openscience.cdk.silent.SilentChemObjectBuilder;
42import denoptim.constants.DENOPTIMConstants;
43import denoptim.exception.DENOPTIMException;
55 private static final IChemObjectBuilder
builder =
56 SilentChemObjectBuilder.getInstance();
86 String defRotBndsFile,
boolean addIterfragBonds,
boolean excludeRings,
89 ArrayList<ObjectPair> rotatableBonds =
new ArrayList<ObjectPair>();
92 for (IBond b : mol.bonds())
105 IAtomContainer locMol =
builder.newAtomContainer();
107 locMol = mol.clone();
108 for (
int iAtm=0; iAtm<locMol.getAtomCount(); iAtm++)
112 }
catch (Throwable t) {
117 if (!defRotBndsFile.equals(
""))
127 String msg =
"WARNING! Attempt to match rotatable bonds returned "
128 +
"an error! Selecting only fragment-fragment "
130 logger.log(Level.WARNING, msg);
133 for (String name : listQueries.keySet())
143 for (
int[] singleMatch : matches)
146 if (singleMatch.length != 2)
148 throw new Error(
"DENOPTIM can only deal with bonds "
149 +
"involving 2 atoms. Check bond "
161 boolean alreadyThere =
false;
164 int a1 = ((Integer)op.getFirst()).intValue();
165 int a2 = ((Integer)op.getSecond()).intValue();
166 if (((a1 == idAtmA) && (a2 == idAtmB)) ||
167 ((a2 == idAtmA) && (a1 == idAtmB)))
176 Integer.valueOf(idAtmA),
177 Integer.valueOf(idAtmB));
178 rotatableBonds.add(newRotBnd);
186 SpanningTree st =
new SpanningTree(mol);
187 IRingSet allRings =
new RingSet();
191 allRings = st.getAllRings();
192 }
catch (Exception ex) {
198 ArrayList<ObjectPair> toRemove =
new ArrayList<ObjectPair>();
201 int a1 = ((Integer)op.getFirst()).intValue();
202 int a2 = ((Integer)op.getSecond()).intValue();
204 IBond bnd = mol.getBond(mol.getAtom(a1),mol.getAtom(a2));
208 IRingSet rs = allRings.getRings(bnd);
211 logger.log(Level.FINE,
"Ignoring cyclic bond: "+bnd);
223 rotatableBonds.remove(op);
227 return rotatableBonds;
243 ArrayList<ObjectPair> interfragBonds =
new ArrayList<ObjectPair>();
246 for (IBond bnd : mol.bonds())
248 if (bnd.getAtomCount() == 2)
250 IAtom atmA = bnd.getAtom(0);
251 IAtom atmB = bnd.getAtom(1);
252 String fragIdA = atmA.getProperty(p).toString();
253 String fragIdB = atmB.getProperty(p).toString();
255 if (!fragIdA.equals(fragIdB) &&
256 (mol.getConnectedBondsCount(atmA) != 1) &&
257 (mol.getConnectedBondsCount(atmB) != 1))
260 int idAtmA = mol.indexOf(atmA);
261 int idAtmB = mol.indexOf(atmB);
264 newRotBnd =
new ObjectPair(Integer.valueOf(idAtmA),
265 Integer.valueOf(idAtmB));
267 newRotBnd =
new ObjectPair(Integer.valueOf(idAtmB),
268 Integer.valueOf(idAtmA));
270 interfragBonds.add(newRotBnd);
275 String str =
"ERROR! Unable to handle bonds involving other "
280 return interfragBonds;
295 Map<String,String> mapOfSMARTS =
new HashMap<String,String>();
298 if (filename.equals(
null))
301 +
" null! Cannot read definition of rotational space.");
304 File f =
new File(filename);
308 +
"' does not exist! Cannot find definition of rotational "
312 BufferedReader br =
null;
316 br =
new BufferedReader(
new FileReader(filename));
317 while ((line = br.readLine()) !=
null)
319 if (line.trim().length() == 0)
322 if (line.trim().startsWith(
"#"))
325 String[] parts = line.split(
"\\s+");
326 if (parts.length != 2)
329 +
"rotational Space definition. "
330 +
"Check line '"+ line +
"' in file "
333 String key = parts[0];
334 String smarts = parts[1];
335 if (mapOfSMARTS.keySet().contains(key))
338 +
"rotatabe bond named '" + key +
"'. "
339 +
"Check line '"+ line +
"' in file "
344 mapOfSMARTS.put(key,smarts);
348 catch (IOException nfe)
361 catch (IOException ioe)
387 IAtomContainer mol, ArrayList<ObjectPair> rotatableBonds,
392 IAtomContainer locMol =
builder.newAtomContainer();
394 locMol = mol.clone();
395 for (
int iAtm=0; iAtm<locMol.getAtomCount(); iAtm++)
399 }
catch (Throwable t) {
404 if (defRotBndContrFile.equals(
""))
414 TreeMap<String,String> listQueries =
new TreeMap<String,String>();
417 listQueries.put(e.getKey(),e.getValue().getSmarts());
424 String msg =
"ERROR! Attempt to match constrained rotatable bonds returned "
426 throw new Error(msg);
429 for (Map.Entry<String,String> e : listQueries.entrySet())
431 String name = e.getKey();
441 for (
int[] singleMatch : matches)
444 if (singleMatch.length != 4)
446 throw new Error(
"Expecting a constrain to be defined by 4 atoms. "
447 +
"Check this match of constraint '" + name +
"': "
466 int a1 = ((Integer)op.getFirst()).intValue();
467 int a2 = ((Integer)op.getSecond()).intValue();
468 if (((a1 == idAtmB) && (a2 == idAtmC)) ||
469 ((a2 == idAtmB) && (a1 == idAtmC)))
475 if (opToRemove!=
null)
477 rotatableBonds.remove(opToRemove);
478 IBond bnd = mol.getBond(mol.getAtom(idAtmB), mol.getAtom(idAtmC));
480 mol.getAtom(idAtmA), mol.getAtom(idAtmB),
481 mol.getAtom(idAtmC), mol.getAtom(idAtmD)});
483 mapOfConstraints.get(name).getValue());
485 logger.log(Level.INFO,
"Constraining dihedral along bond "
489 +
" (rotatable bond constrain: '" + name +
"')");
507 TreeMap<String,RotBndConstraint> mapOfConstraints =
new TreeMap<String,RotBndConstraint>();
510 if (filename.equals(
null))
513 +
" null! Cannot read definition of rotational constraints.");
516 File f =
new File(filename);
520 +
"' does not exist! Cannot find definition of rotational "
524 BufferedReader br =
null;
528 br =
new BufferedReader(
new FileReader(filename));
529 while ((line = br.readLine()) !=
null)
531 if (line.trim().length() == 0)
534 if (line.trim().startsWith(
"#"))
537 String[] parts = line.split(
"\\s+");
539 if (parts.length != 3)
542 +
"rotational constraints definition. "
543 +
"Check line '"+ line +
"' in file "
546 String key = parts[0];
547 String smarts = parts[1];
548 double value = Double.parseDouble(parts[2]);
549 if (mapOfConstraints.keySet().contains(key))
552 +
"rotational contraint named '" + key +
"'. "
553 +
"Check line '"+ line +
"' in file "
562 catch (IOException nfe)
575 catch (IOException ioe)
580 return mapOfConstraints;
General set of constants used in DENOPTIM.
static final String ATMPROPVERTEXPATH
Name of Atom property used to store the unique ID of the Vertex that owns the atom and the IDs of any...
static final String BONDPROPROTATABLE
String tag of Bond's property used to store the property of being rotatable.
Container of lists of atoms matching a list of SMARTS.
Mappings getMatchesOfSMARTS(String ref)
int getNumMatchesOfQuery(String query)
Utilities for molecule conversion.
static void removeRCA(IAtomContainer mol)
Replace any PseudoAtoms representing ring closing attractors with H.
static String getAtomRef(IAtom atm, IAtomContainer mol)
This class is the equivalent of the Pair data structure used in C++ Although AbstractMap....
The definition of a constraint applying to rotatable bonds.
Tool box for definition and management of the rotational space, which is given by the list of rotatab...
static final IChemObjectBuilder builder
static TreeMap< String, RotBndConstraint > getRotationalConstraintsDefinition(String filename)
Reads the definition of constraints on the rotatable bonds.
static ArrayList< ObjectPair > getInterVertexBonds(IAtomContainer mol)
Search for all bonds connecting atoms corresponding to two different vertices in the DENOPTIMGraph.
static final String PROPERTY_ROTDBDCSTR_DEF
static final String PROPERTY_RSU_ATMID
static void processConstrainedRotatableBonds(IAtomContainer mol, ArrayList< ObjectPair > rotatableBonds, String defRotBndContrFile, Logger logger)
Process the constrained rotatable bonds.
static final String PROPERTY_ROTDBDCSTR_VALUE
static Map< String, String > getRotationalSpaceDefinition(String filename)
Read a formatted file and return a map with all the SMARTS queries identifying rotatable bonds.
static ArrayList< ObjectPair > defineRotatableBonds(IAtomContainer mol, String defRotBndsFile, boolean addIterfragBonds, boolean excludeRings, Logger logger)
Define the rotational space (a.k.a.