19package denoptim.utils;
21import java.util.ArrayList;
22import java.util.HashMap;
23import java.util.HashSet;
28import org.openscience.cdk.Bond;
29import org.openscience.cdk.interfaces.IAtom;
30import org.openscience.cdk.interfaces.IAtomContainer;
31import org.openscience.cdk.interfaces.IBond;
32import org.openscience.cdk.interfaces.IChemObjectBuilder;
33import org.openscience.cdk.silent.SilentChemObjectBuilder;
35import denoptim.constants.DENOPTIMConstants;
36import denoptim.exception.DENOPTIMException;
37import denoptim.graph.APClass;
38import denoptim.graph.Edge.BondType;
39import denoptim.graph.Ring;
54 private ArrayList<ArrayList<Boolean>>
flags;
59 private Map<Integer, Map<Integer, Set<Integer>>>
layers;
71 flags =
new ArrayList<>();
99 ArrayList<Integer> lst =
new ArrayList<Integer>();
102 lst.add(i.intValue());
121 ArrayList<Integer> lst =
new ArrayList<Integer>();
124 lst.add(i.intValue());
147 ArrayList<Integer> reorderedAtms =
new ArrayList<>(mol.getAtomCount());
149 ArrayList<Integer> pointer =
new ArrayList<>(mol.getAtomCount());
151 for (
int i = 0; i < mol.getAtomCount(); i++) {
164 String str =
"ERROR! Atom ordering: scheme not recognized";
212 IChemObjectBuilder builder = SilentChemObjectBuilder.getInstance();
213 IAtomContainer iac = builder.newAtomContainer();
215 StringBuilder sbMolProp =
new StringBuilder();
216 for (
int i = 0; i < original.getAtomCount(); i++)
218 IAtom originalAtom = original.getAtom(newToOldOrder.get(i));
220 String atmPropVID =
" none";
224 atmPropVID =
" " + ((Long) p).longValue();
226 ((Long) p).longValue());
228 sbMolProp.append(atmPropVID);
230 Object pVPath = originalAtom.getProperty(
238 Object pAPCls = originalAtom.getProperty(
246 Object pBndTyp = originalAtom.getProperty(
254 Object pRing = originalAtom.getProperty(
267 sbMolProp.toString().trim());
273 e.toString().trim());
277 for (
int i = 0; i < original.getBondCount(); i++) {
279 IBond oldBnd = original.getBond(i);
280 if (oldBnd.getAtomCount() != 2) {
281 String msg =
"Multicenter bond not supported.";
284 int atm1 = original.indexOf(oldBnd.getAtom(0));
285 int atm2 = original.indexOf(oldBnd.getAtom(1));
288 IBond.Order order = oldBnd.getOrder();
289 IBond.Stereo stereo = oldBnd.getStereo();
290 IBond bnd =
new Bond(iac.getAtom(newatm1),
291 iac.getAtom(newatm2), order, stereo);
293 }
catch (Throwable t) {
294 String msg =
"ERROR in making new bond";
332 List<IAtom> neighbourAtoms = mol.getConnectedAtomsList(mol.getAtom(seed));
335 List<IAtom> purgedList =
new ArrayList<>();
336 for (IAtom connectedAtom : neighbourAtoms)
338 int atmidx = mol.indexOf(connectedAtom);
339 if (!
flags.get(flag).get(atmidx))
341 purgedList.add(connectedAtom);
346 if (purgedList.isEmpty())
352 if (purgedList.size() > 1)
358 for (IAtom connectedAtom : purgedList) {
360 int atmidx = mol.indexOf(connectedAtom);
363 if (
flags.get(flag).get(atmidx)) {
372 for (IAtom connectedAtom : purgedList) {
375 int atmidx = mol.indexOf(connectedAtom);
378 if (mol.getConnectedBondsCount(connectedAtom) > 1) {
410 Map<Integer, Set<Integer>> layersOfAP =
layers.get(ap);
414 Set<Integer> atmInLyr = layersOfAP.get(
lidx);
417 for (
int atmIdx : atmInLyr)
419 List<IAtom> neighbourAtoms = mol.getConnectedAtomsList(mol.getAtom(atmIdx));
421 for (IAtom ngbAtm : neighbourAtoms)
423 int ngbAtmIdx = mol.indexOf(ngbAtm);
424 if (!
flags.get(lyflg).get(ngbAtmIdx))
426 int layerOfNgbAtm =
lidx + 1;
433 goon = layersOfAP.containsKey(
lidx + 1);
440 int numberOfLayers = layersOfAP.keySet().size();
441 for (
int i = 0; i < numberOfLayers; i++)
444 Set<Integer> idxInLyr = layersOfAP.get(i);
445 List<IAtom> atmInLyr =
new ArrayList<>();
446 for (Integer idx : idxInLyr)
448 atmInLyr.add(mol.getAtom(idx));
455 for (IAtom orderedAtm : atmInLyr) {
457 int atmidx = mol.indexOf(orderedAtm);
482 if (!
layers.containsKey(ap))
484 Map<Integer, Set<Integer>> layersForAP =
new HashMap<>();
485 layers.put(ap, layersForAP);
489 if (!
layers.get(ap).containsKey(layer))
491 Set<Integer> atmInLayer =
new HashSet<>();
492 layers.get(ap).put(layer, atmInLayer);
496 layers.get(ap).get(layer).add(atmidx);
499 flags.get(doneFlag).set(atmidx,
true);
514 flags.get(doneFlag).set(atmidx,
true);
538 List<IAtom> outList =
new ArrayList<>();
541 List<ConnectedLigand> ligList =
new ArrayList<>();
542 for (IAtom seed : inList)
545 mol.getConnectedBondsCount(seed));
552 IAtom a = connectedLigand.getAtom();
572 int atoms = mol.getAtomCount();
573 ArrayList<Boolean> flg =
new ArrayList<>();
574 for (
int i = 0; i < atoms; i++)
581 freeFlag =
flags.indexOf(flg);
594 flags.remove(flagID);
General set of constants used in DENOPTIM.
static final String ATMPROPVERTEXID
String tag of Atom property used to store the unique ID of the Vertex corresponding to the molecular ...
static final Object RCAPROPRINGUSER
Property of a IAtom representing a RingClosingAttractor.
static final Object RCAPROPCHORDBNDTYP
Property of a IAtom representing a RingClosingAttractor.
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 MOLERRORTAG
SDF tag containing errors during execution of molecule specific tasks.
static final Object RCAPROPAPCTORCA
Property of a IAtom representing a RingClosingAttractor.
This class represents the closure of a ring in a spanning tree.
Tool for re-organizing the list of atoms of an IAtomContainer
void deleteAtomsFlag(int flagID)
Destroy a vector of flags.
void processAtom(int atmidx, int ap, int doneFlag)
Perform all the operation to report an atom in the new order.
void branchOrienterReordering(int seed, int flag, IAtomContainer mol)
Reorders atoms according to the branch-oriented scheme.
List< IAtom > prioritizeAtomList(List< IAtom > inList, IAtomContainer mol)
Change the order of atoms in a list according to the priority rules defined in the comparator Connect...
Map< Integer, ArrayList< Integer > > oldToNewOrder
void setScheme(int scheme)
void addAtomToLayer(int atmidx, int ap, int layer, int doneFlag)
Set the layer membership of an antom.
ArrayList< Integer > getNewToOldOrder(int seed)
Returns the list of indexes that allow to map the new atom position with the old one.
Map< Integer, Map< Integer, Set< Integer > > > layers
Map< Integer, ArrayList< Integer > > atomOrders
int getFreeAtomsFlag(IAtomContainer mol)
Generates a vector of boolean flags.
static IAtomContainer makeReorderedCopy(IAtomContainer original, List< Integer > newToOldOrder, List< Integer > oldToNewOrder)
Produces a new container that looks very similar to the original one, but has a different atom order.
IAtomContainer reorderStartingFrom(int seed, IAtomContainer mol)
Reorder the atoms in mol starting with atom seed
ArrayList< Integer > getOldToNewOrder(int seed)
Returns the list of indexes that allow to map the old atom position with the new one.
void layerOrientedReordering(int seed, int flag, IAtomContainer mol)
Reorders atoms according to the layer-oriented scheme.
ArrayList< ArrayList< Boolean > > flags
void exploreMolecule(int seed, int flag, IAtomContainer mol, int ap)
Method meant for recursion on all atoms connected to a starting point.
Compare two ConnectedLigand according to the number of connected atoms and the mass number.
A ConnectedLigand is just an atom with an explicit field reporting the number of connected atoms.
Utilities for molecule conversion.
static IAtom makeSameAtomAs(IAtom oAtm)
Method that constructs an atom that reflect the same atom given as parameter in terms of element symb...
Possible chemical bond types an edge can represent.