1package denoptim.fragmenter;
3import java.util.ArrayList;
4import java.util.HashMap;
5import java.util.HashSet;
9import java.util.logging.Logger;
11import org.openscience.cdk.interfaces.IAtom;
12import org.openscience.cdk.interfaces.IAtomContainer;
13import org.openscience.cdk.interfaces.IBond;
14import org.openscience.cdk.silent.SilentChemObjectBuilder;
16import denoptim.constants.DENOPTIMConstants;
17import denoptim.utils.DummyAtomHandler;
18import denoptim.utils.MoleculeUtils;
56 Set<IAtom> boundaryAtoms =
new HashSet<>();
57 Map<IAtom, Long> atomToVertexId =
new HashMap<>();
58 Set<Long> visitedVertexIds =
new HashSet<>();
59 Set<Long> visitedVertexIdsBoundaries =
new HashSet<>();
60 Set<IAtom> atomsWithAPs =
new HashSet<>();
72 Long vid = Long.parseLong(vidProp.toString());
73 visitedVertexIds.add(vid);
74 atomToVertexId.put(atom, vid);
79 atomsWithAPs.add(atom);
83 List<IAtom> neighbors =
originalIAC.getConnectedAtomsList(atom);
84 for (IAtom neighbor : neighbors)
87 if (nbrVidProp !=
null)
89 Long nbrVid = Long.parseLong(nbrVidProp.toString());
90 if (!vid.equals(nbrVid))
92 boundaryAtoms.add(atom);
93 boundaryAtoms.add(neighbor);
94 visitedVertexIdsBoundaries.add(vid);
95 visitedVertexIdsBoundaries.add(nbrVid);
106 visitedVertexIds.removeAll(visitedVertexIdsBoundaries);
107 if (!visitedVertexIds.isEmpty())
114 if (boundaryAtoms.isEmpty())
129 if (atomsWithAPs.contains(atom))
136 if (atom.getSymbol().equals(
"H"))
138 if (atomsWithAPs.contains(atom))
150 List<IAtom> boundaryList =
new ArrayList<>(boundaryAtoms);
151 for (
int i = 0; i < boundaryList.size(); i++)
153 for (
int j = i + 1; j < boundaryList.size(); j++)
155 IAtom start = boundaryList.get(i);
156 IAtom end = boundaryList.get(j);
163 start, end, atomToVertexId);
187 IAtomContainer reduced = SilentChemObjectBuilder.getInstance().newAtomContainer();
192 for (
int i = 0; i < bufferShellSize; i++)
194 if (atomsToKeep.size() ==
originalIAC.getAtomCount())
199 Set<IAtom> nextLevelAtoms =
new HashSet<>();
200 for (IAtom atm : thisLevelAtoms)
202 List<IAtom> neighbors =
originalIAC.getConnectedAtomsList(atm);
203 for (IAtom neighbor : neighbors)
205 if (!atomsToKeep.contains(neighbor))
212 atomsToKeep.add(neighbor);
213 nextLevelAtoms.add(neighbor);
217 thisLevelAtoms = nextLevelAtoms;
221 Map<IAtom, IAtom> originalToReduced =
new HashMap<>();
222 for (IAtom originalAtom : atomsToKeep)
224 IAtom reducedAtom = originalAtom.getBuilder().newInstance(
225 IAtom.class, originalAtom);
226 reduced.addAtom(reducedAtom);
227 originalToReduced.put(originalAtom, reducedAtom);
230 int originalIndex =
originalIAC.indexOf(originalAtom);
231 reducedAtom.setProperty(
"DENOPTIM_ORIGINAL_ATOM_INDEX", originalIndex);
234 for (Object key : originalAtom.getProperties().keySet())
236 if (!key.equals(
"DENOPTIM_ORIGINAL_ATOM_INDEX"))
238 reducedAtom.setProperty(key, originalAtom.getProperty(key));
246 IAtom atom1 = bond.getAtom(0);
247 IAtom atom2 = bond.getAtom(1);
249 if (atomsToKeep.contains(atom1) && atomsToKeep.contains(atom2))
251 IBond newBond = bond.getBuilder().newInstance(IBond.class,
252 originalToReduced.get(atom1), originalToReduced.get(atom2), bond.getOrder());
253 reduced.addBond(newBond);
General set of constants used in DENOPTIM.
static final String ATMPROPAPS
String tag of Atom property used to store attachment points.
static final String ATMPROPVERTEXID
String tag of Atom property used to store the unique ID of the Vertex corresponding to the molecular ...
static final String DUMMYATMSYMBOL
Symbol of dummy atom.
TopoTemplateProducer(IAtomContainer originalIAC)
Constructor.
IAtomContainer originalIAC
The original IAtomContainer to produce a topology-critical template for.
boolean produceHDepleted
Flag recording whether we could only produce a H-depleted template.
Set< IAtom > topoCriticalAtoms
topology-critical atoms
IAtomContainer getTemplateWithBufferShell(int bufferShellSize)
Produced a new IAtomContainer containing all the atoms needed to define the topology of the original ...
Utilities for molecule conversion.
static String getSymbolOrLabel(IAtom atm)
Gets either the elemental symbol (for standard atoms) of the label (for pseudo-atoms).
static List< IAtom > findShortestPath(IAtomContainer mol, IAtom start, IAtom end, Map< IAtom, Long > atomToVertexId)
Finds the shortest path between two atoms in a molecule using BFS.
static boolean isElement(IAtom atom)
Check element symbol corresponds to real element of Periodic Table.