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;
31import org.openscience.cdk.graph.SpanningTree;
32import org.openscience.cdk.interfaces.IAtom;
33import org.openscience.cdk.interfaces.IAtomContainer;
34import org.openscience.cdk.interfaces.IBond;
35import org.openscience.cdk.interfaces.IChemObjectBuilder;
36import org.openscience.cdk.interfaces.IRingSet;
37import org.openscience.cdk.isomorphism.Mappings;
38import org.openscience.cdk.silent.RingSet;
39import org.openscience.cdk.silent.SilentChemObjectBuilder;
41import denoptim.constants.DENOPTIMConstants;
42import denoptim.exception.DENOPTIMException;
54 private static final IChemObjectBuilder
builder =
55 SilentChemObjectBuilder.getInstance();
79 String defRotBndsFile,
boolean addIterfragBonds,
boolean excludeRings,
82 ArrayList<ObjectPair> rotatableBonds =
new ArrayList<ObjectPair>();
85 for (IBond b : mol.bonds())
98 IAtomContainer locMol =
builder.newAtomContainer();
100 locMol = mol.clone();
101 }
catch (Throwable t) {
107 if (!defRotBndsFile.equals(
""))
117 String msg =
"WARNING! Attempt to match rotatable bonds returned "
118 +
"an error! Selecting only fragment-fragment "
120 logger.log(Level.WARNING, msg);
123 for (String name : listQueries.keySet())
133 for (
int[] singleMatch : matches)
136 if (singleMatch.length != 2)
138 throw new Error(
"DENOPTIM can only deal with bonds "
139 +
"involving 2 atoms. Check bond "
147 int idAtmA = singleMatch[0];
148 int idAtmB = singleMatch[1];
151 boolean alreadyThere =
false;
154 int a1 = ((Integer)op.getFirst()).intValue();
155 int a2 = ((Integer)op.getSecond()).intValue();
156 if (((a1 == idAtmA) && (a2 == idAtmB)) ||
157 ((a2 == idAtmA) && (a1 == idAtmB)))
166 Integer.valueOf(idAtmA),
167 Integer.valueOf(idAtmB));
168 rotatableBonds.add(newRotBnd);
176 SpanningTree st =
new SpanningTree(mol);
177 IRingSet allRings =
new RingSet();
181 allRings = st.getAllRings();
182 }
catch (Exception ex) {
188 ArrayList<ObjectPair> toRemove =
new ArrayList<ObjectPair>();
191 int a1 = ((Integer)op.getFirst()).intValue();
192 int a2 = ((Integer)op.getSecond()).intValue();
194 IBond bnd = mol.getBond(mol.getAtom(a1),mol.getAtom(a2));
198 IRingSet rs = allRings.getRings(bnd);
201 logger.log(Level.FINE,
"Ignoring cyclic bond: "+bnd);
213 rotatableBonds.remove(op);
217 return rotatableBonds;
233 ArrayList<ObjectPair> interfragBonds =
new ArrayList<ObjectPair>();
236 for (IBond bnd : mol.bonds())
238 if (bnd.getAtomCount() == 2)
240 IAtom atmA = bnd.getAtom(0);
241 IAtom atmB = bnd.getAtom(1);
242 String fragIdA = atmA.getProperty(p).toString();
243 String fragIdB = atmB.getProperty(p).toString();
245 if (!fragIdA.equals(fragIdB) &&
246 (mol.getConnectedBondsCount(atmA) != 1) &&
247 (mol.getConnectedBondsCount(atmB) != 1))
250 int idAtmA = mol.indexOf(atmA);
251 int idAtmB = mol.indexOf(atmB);
254 newRotBnd =
new ObjectPair(Integer.valueOf(idAtmA),
255 Integer.valueOf(idAtmB));
257 newRotBnd =
new ObjectPair(Integer.valueOf(idAtmB),
258 Integer.valueOf(idAtmA));
260 interfragBonds.add(newRotBnd);
265 String str =
"ERROR! Unable to handle bonds involving other "
270 return interfragBonds;
285 Map<String,String> mapOfSMARTS =
new HashMap<String,String>();
288 if (filename.equals(
null))
291 +
" null! annot read definition of rotational space.");
294 File f =
new File(filename);
298 +
"' does not exist! Cannot find definition of rotational "
302 BufferedReader br =
null;
306 br =
new BufferedReader(
new FileReader(filename));
307 while ((line = br.readLine()) !=
null)
309 if (line.trim().length() == 0)
312 if (line.trim().startsWith(
"#"))
315 String[] parts = line.split(
"\\s+");
316 if (parts.length != 2)
319 +
"rotational Space definition. "
320 +
"Check line '"+ line +
"' in file "
323 String key = parts[0];
324 String smarts = parts[1];
325 if (mapOfSMARTS.keySet().contains(key))
328 +
"rotatabe bond named '" + key +
"'. "
329 +
"Check line '"+ line +
"' in file "
334 mapOfSMARTS.put(key,smarts);
338 catch (IOException nfe)
351 catch (IOException ioe)
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.
This class is the equivalent of the Pair data structure used in C++ Although AbstractMap....
Tool box for definition and management of the rotational space, which is given by the list of rotatab...
static final IChemObjectBuilder builder
static ArrayList< ObjectPair > getInterVertexBonds(IAtomContainer mol)
Search for all bonds connecting atoms corresponding to two different vertices in the DENOPTIMGraph.
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 (also torsional space) for a given molecule.