1package denoptim.graph.rings;
3import java.util.ArrayList;
4import java.util.Collections;
7import java.util.logging.Level;
8import java.util.logging.Logger;
10import org.openscience.cdk.Bond;
11import org.openscience.cdk.graph.matrix.TopologicalMatrix;
12import org.openscience.cdk.interfaces.IAtom;
13import org.openscience.cdk.interfaces.IAtomContainer;
14import org.openscience.cdk.interfaces.IBond;
16import denoptim.constants.DENOPTIMConstants;
17import denoptim.exception.DENOPTIMException;
18import denoptim.fragspace.FragmentSpace;
19import denoptim.graph.APClass;
20import denoptim.graph.AttachmentPoint;
21import denoptim.graph.DGraph;
22import denoptim.graph.Edge;
23import denoptim.graph.EmptyVertex;
24import denoptim.graph.Fragment;
25import denoptim.graph.Ring;
26import denoptim.graph.Vertex;
27import denoptim.graph.Edge.BondType;
28import denoptim.utils.MoleculeUtils;
40 private IAtomContainer
mol;
75 private List<Boolean>
done;
119 this.settings = rcParams;
137 mol = (IAtomContainer) origMol.clone();
138 }
catch (Throwable t) {
139 throw new IllegalArgumentException(t);
156 done =
new ArrayList<Boolean>(Collections.nCopies(
sz,
false));
169 long startTime = System.nanoTime();
171 long endTime = System.nanoTime();
172 long duration = (- startTime + endTime) / (
long) 1000.0;
174 if (
logger.isLoggable(Level.FINE))
176 StringBuilder sb =
new StringBuilder();
177 sb.append(
"TopoMat N: " +
mol.getAtomCount() +
" " + duration
178 +
" microsec." +
NL);
179 int n =
mol.getAtomCount();
180 sb.append(
"Topological matrix (n=" + n +
")"+
NL);
181 for (
int i=0; i<n; i++)
184 for (
int j=0; j<n; j++)
190 logger.log(Level.FINE, sb.toString());
201 weigths =
new ArrayList<Double>(Collections.nCopies(
sz, 0.0));
203 for (
int i=0; i<
sz; i++)
208 boolean isAtmI = vI instanceof
Fragment;
214 if (
mol.getConnectedAtomsList(atmI).size()==0)
220 String s =
"Attempt to evaluate RCA pair compatibility "
221 +
"with a non-RCA end (" + atmI +
").";
222 throw new IllegalStateException(s);
226 for (
int j=i+1; j<
sz; j++)
231 boolean isAtmJ = vJ instanceof
Fragment;
239 String s =
"Attempt to evaluate RCA pair compatibility "
240 +
"with a non-RCA end (" + atmJ +
").";
241 throw new IllegalStateException(s);
245 if ((isAtmI && !isAtmJ) || (!isAtmI && isAtmJ))
249 if (!isAtmI && !isAtmJ)
278 logger.log(Level.FINE,
" i:" + i +
" j:" + j +
" size:"
279 + ringSize +
" factors:" +
weigths);
284 if (
logger.isLoggable(Level.FINE))
286 StringBuilder sb =
new StringBuilder();
287 sb.append(
"RCV pairs compatibility (ring size-biased):"+
NL);
288 for (
int i=0; i<
sz;i++)
291 for (
int j=0; j<
sz; j++)
300 logger.log(Level.FINE, sb.toString());
319 String s =
"Evaluation of RCV pair " + vI +
" " + vJ +
": ";
340 logger.log(Level.FINE, s +
"RC-CPMap does not contain class (I) "
341 + parentAPClsI +
" " + parentAPClsI.hashCode());
350 logger.log(Level.FINE, s +
"RC-CPMap does not contain class (J) "
351 + parentAPClsJ +
" " + parentAPClsJ.hashCode());
360 logger.log(Level.FINE, s +
"vI same as vJ: loop not allowed!");
365 if (pvI == pvJ && srcAtmIdI == srcAtmIdJ)
367 logger.log(Level.FINE, s +
"Same src: " + pvI +
" " + pvJ
368 +
" " + srcAtmIdI +
" " + srcAtmIdJ);
376 if (!(compatClassesI.contains(parentAPClsJ) ||
377 compatClassesJ.contains(parentAPClsI)))
379 logger.log(Level.FINE,s +
"APClass not compatible "
384 logger.log(Level.FINE, s +
"all criteria satisfied.");
393 List<Vertex> wLst =
new ArrayList<Vertex>();
394 for (
int i=0; i<
sz; i++)
401 for (
int j=0; j<
weigths.get(i); j++)
407 logger.log(Level.FINE,
"Ring size-biased list of RCVs:" + wLst);
417 List<Vertex> wLst =
new ArrayList<Vertex>();
418 for (
int j=0; j<
sz; j++)
452 for (
int z=0; z<szFct; z++)
458 logger.log(Level.FINE,
"Ring size-biased list of RCVs for " + vI
471 String s =
"Attempt to make ring closing bond between "
472 +
"multi-atom Ring Closing Vertices (RCV). "
473 +
"For now, only single-atom RCVs are expected in "
474 +
"this implementation.";
475 throw new IllegalStateException(s);
479 IAtom srcI =
mol.getConnectedAtomsList(
481 IAtom srcJ =
mol.getConnectedAtomsList(
490 IBond bnd =
new Bond(srcI,srcJ);
494 logger.log(Level.FINE,
"WARNING! Attempt to add ring closing bond "
495 +
"did not add any actual chemical bond because the "
496 +
"bond type of the chord is '" + bndTyp +
"'.");
499 logger.log(Level.FINEST,
" ==> UPDATING "
500 +
this.getClass().getSimpleName() +
" <==");
General set of constants used in DENOPTIM.
static final String EOL
new line character
Class defining a space of building blocks.
HashMap< APClass, ArrayList< APClass > > getRCCompatibilityMatrix()
Returns the compatibility matrix for ring closing fragment-fragment connections or null if not provid...
An attachment point (AP) is a possibility to attach a Vertex onto the vertex holding the AP (i....
int getAtomPositionNumber()
The index of the source atom in the atom list of the fragment.
Container for the list of vertices and the edges that connect them.
ArrayList< Vertex > getFreeRCVertices()
Search for unused ring closing vertices: vertices that contain only a RingClosingAttractor and are no...
This class represents the edge between two vertices.
An empty vertex has the behaviors of a vertex, but has no molecular structure.
Class representing a continuously connected portion of chemical object holding attachment points.
A vertex is a data structure that has an identity and holds a list of AttachmentPoints.
Edge getEdgeToParent()
Looks into the edges that use any of the APs that belong to this vertex and returns the edge that has...
Vertex getParent()
Looks into the edges that use any of the APs that belong to this vertex and returns the vertex which ...
abstract List< AttachmentPoint > getAttachmentPoints()
The RingClosingAttractor represent the available valence/connection that allows to close a ring.
boolean isAttractor()
Checks whether the constructed RingClosingAttractor does corresponds to a RingClosingAttractor in the...
boolean isCompatible(RingClosingAttractor other)
Evaluate compatibility between this RingClosingAttractor and another one.
Parameters and setting related to handling ring closures.
List< Integer > getRingSizeBias()
Utility class to calculate and manage the alternative ring sizes achievable by formation of Rings.
RingClosureParameters settings
Parameters related to rings.
List< Vertex > getRSBiasedListOfCandidates()
boolean getCompatibilityOfPair(Vertex vI, Vertex vJ)
boolean[][] compatibilityOfPairs
Compatibility matrix between pairs of RCAs in the current system.
boolean evaluateRCVPair(Vertex vI, Vertex vJ, FragmentSpace fragSpace)
Method to analyze a pair of vertices and evaluate whether they respect the criteria for being the two...
Logger logger
tool managing the logs
void fillTopologicalMatrix()
void addRingClosingBond(Vertex vI, Vertex vJ)
int[][] topoMat
Topological matrix: contains the number of bonds (shortest path) separating the two atoms having inde...
RingSizeManager(FragmentSpace fragSpace, RingClosureParameters rcParams)
Creates a tool that will work according to the given system-aspecific settings.
IAtomContainer mol
Molecular representation of the current system.
void initialize(IAtomContainer origMol, DGraph graph)
Makes this ring size manager work on a specific system that has a molecular representation and a DENO...
List< Integer > ringSizeBias
Parameters setting the bias for selecting rings of given size.
ArrayList< Vertex > lstVert
List of Ring Closing Vertices (RCV as DENOPTIMVerex) each containing an available Ring Closing Attrac...
List< Double > weigths
List of weight factors used to control the likeliness of choosing rings of a given size for the curre...
List< Boolean > done
List of flags defining if an RCA has been "used", i.e., not used to make an actual chord,...
static final String NL
New line character.
void setVertexAsDone(Vertex v)
Map< Vertex, ArrayList< Integer > > vIdToAtmId
Map linking the list of vertices and atoms.
int sz
Size of the list of available RCAs.
FragmentSpace fragSpace
Definition of the fragment space.
void calculateCompatibilityOfAllRCAPairs()
List< Vertex > getRSBiasedListOfCandidates(Vertex vI)
Logger getLogger()
Get the name of the program specific logger.
Utilities for molecule conversion.
static Map< Vertex, ArrayList< Integer > > getVertexToAtomIdMap(ArrayList< Vertex > vertLst, IAtomContainer mol)
Method to generate the map making in relation DENOPTIMVertex ID and atom index in the IAtomContainer ...
Possible chemical bond types an edge can represent.
boolean hasCDKAnalogue()
Checks if it is possible to convert this edge type into a CDK bond.