19package denoptim.graph.rings;
 
   21import java.util.ArrayList;
 
   22import java.util.Arrays;
 
   23import java.util.Collections;
 
   24import java.util.HashSet;
 
   25import java.util.Iterator;
 
   29import java.util.logging.Logger;
 
   31import javax.vecmath.Point3d;
 
   33import org.openscience.cdk.graph.ShortestPaths;
 
   34import org.openscience.cdk.interfaces.IAtom;
 
   35import org.openscience.cdk.interfaces.IAtomContainer;
 
   36import org.openscience.cdk.interfaces.IBond;
 
   38import denoptim.constants.DENOPTIMConstants;
 
   39import denoptim.exception.DENOPTIMException;
 
   40import denoptim.graph.AttachmentPoint;
 
   41import denoptim.graph.DGraph;
 
   42import denoptim.graph.Edge;
 
   43import denoptim.graph.Vertex;
 
   44import denoptim.io.DenoptimIO;
 
   45import denoptim.molecularmodeling.ThreeDimTreeBuilder;
 
   46import denoptim.utils.Randomizer;
 
  151        List<Vertex> vAToSeed = 
new ArrayList<Vertex>();
 
  154        List<Vertex> vBToSeed = 
new ArrayList<Vertex>();
 
  158        if (Collections.disjoint(vAToSeed, vBToSeed))
 
  169        for (
int i=0; i<vAToSeed.size(); i++)
 
  172            if (vBToSeed.contains(vAToSeed.get(i)))
 
  179                int idStart = vBToSeed.indexOf(vAToSeed.get(i))-1;
 
  181                for (
int j=idStart; j>-1; j--)
 
  204        boolean insideOut = 
false;
 
  205        ArrayList<Vertex> gVertices = 
new ArrayList<Vertex>();
 
  206        ArrayList<Edge> gEdges = 
new ArrayList<Edge>();
 
  219            int apIdBack2Here = -1;
 
  220            int apIdHere2Back = -1;
 
  221            int apIdHere2Frnt = -1;
 
  222            int apIdFrnt2Here = -1;
 
  252                    vertHere.
getAP(apIdHere2Frnt));
 
  263                gVertices.add(cloneVertBack);
 
  268                cloneVertBack = gVertices.get(gVertices.size()-1);
 
  270            gVertices.add(cloneVertHere);
 
  271            gEdges.add(
new Edge(cloneVertBack.
getAP(apIdBack2Here),
 
  272                    cloneVertHere.
getAP(apIdHere2Back),
 
  276                gVertices.add(cloneVertFrnt);
 
  277                gEdges.add(
new Edge(cloneVertHere.
getAP(apIdHere2Frnt),
 
  278                        cloneVertFrnt.
getAP(apIdFrnt2Here),
 
  284        this.graph = 
new DGraph(gVertices,gEdges);
 
  287        String[] pA = 
chainID.split(
"_");
 
  291        for (
int i=1; i<pA.length; i++)
 
  295            for (
int j=0; j<pA.length; j++)
 
  297                if ((i+j) < pA.length)
 
  299                    altrnA = altrnA + pA[i+j] + 
"_";
 
  300                    altrnB = altrnB + pB[i+j] + 
"_";
 
  302                    altrnA = altrnA + pA[i+j-pA.length] + 
"_";
 
  303                    altrnB = altrnB + pB[i+j-pA.length] + 
"_";
 
  335            Iterator<AttachmentPoint> path = 
findPath(from, to,
 
  336                    new HashSet<>()).iterator();
 
  338            if (!path.hasNext()) {
 
  354            while (path.hasNext()) {
 
  355                srcAP = path.next().
clone();
 
  359                trgAP = path.next().
clone();
 
  386        if (visited.contains(fromId)) {
 
  387            return new ArrayList<>();
 
  392            Edge e = fromAP.getEdgeUser();
 
  398                return Arrays.asList(fromAP, adjAP);
 
  401            Iterable<AttachmentPoint> path = 
findPath(adj, to, visited);
 
  403            if (path.iterator().hasNext()) {
 
  404                List<AttachmentPoint> extendedPath =
 
  405                        new ArrayList<AttachmentPoint>(Arrays.asList(
 
  407                path.iterator().forEachRemaining(extendedPath::add);
 
  412        return Collections.emptyList();
 
  433        Map<IAtom,ArrayList<AttachmentPoint>> apsPerAtom = 
 
  435        Map<IBond,ArrayList<AttachmentPoint>> apsPerBond =
 
  440            String f = 
"/tmp/pathSubGraph.sdf";
 
  441            System.out.println(
"Find SDF representation of path in: " + f);
 
  445            } 
catch (Throwable t) {
 
  446                throw new Error(
"Could not save debug file '" + f + 
"'.");
 
  459        for (IAtom atm : mol.atoms())
 
  461            long vrtId = (Long) atm.getProperty(
 
  469            if (e0 != 
null && e1 != 
null)
 
  472        List<IAtom> ends = 
new ArrayList<IAtom>();
 
  484        List<IAtom> pathInFullMol = 
new ArrayList<IAtom>();
 
  486        IAtom currentAtm = 
null;
 
  487        long prevAtmInPathVID = -1;
 
  488        long currAtmInPathVID = -1;
 
  489        long nextAtmInPathVID = -1;
 
  490        List<IAtom> candidates = 
new ArrayList<IAtom>();
 
  496                currentAtm = ends.get(0);
 
  497                pathInFullMol.add(currentAtm);
 
  498                candidates.addAll(mol.getConnectedAtomsList(currentAtm));
 
  501                pathInFullMol.add(ends.get(1));
 
  510            if (prevAtmInPathVID != currAtmInPathVID)
 
  512                for (IAtom c : candidates)
 
  517                        pathInFullMol.add(currentAtm);
 
  520                        for (IAtom c2 : mol.getConnectedAtomsList(c))
 
  522                            if (!pathInFullMol.contains(c2))
 
  531                List<IAtom> newCandidates = 
new ArrayList<IAtom>(); 
 
  532                for (IAtom nbr : candidates)
 
  534                    boolean foundNextLevel = 
false;
 
  535                    for (IAtom nbrNbr : mol.getConnectedAtomsList(nbr))
 
  537                        if (pathInFullMol.contains(nbrNbr)
 
  538                                || candidates.contains(nbrNbr))
 
  542                        if (vid == nextAtmInPathVID 
 
  543                                && currAtmInPathVID!=nextAtmInPathVID)
 
  545                            ShortestPaths sp = 
new ShortestPaths(mol, 
 
  547                            List<IAtom> itnraVertPath = 
new ArrayList<IAtom>(
 
  548                                    Arrays.asList(sp.atomsTo(nbr)));
 
  551                            for (
int j=1; j<itnraVertPath.size(); j++)
 
  552                                pathInFullMol.add(itnraVertPath.get(j));
 
  555                            newCandidates.clear();
 
  556                            newCandidates.add(nbrNbr);
 
  557                            foundNextLevel = 
true;
 
  560                            if (vid == currAtmInPathVID)
 
  562                                newCandidates.add(nbrNbr);
 
  570                candidates.addAll(newCandidates);
 
  576            throw new IllegalStateException(
"Paths have different size! " 
  578                    + 
"proceed in the evaluation of ring closability. " 
  579                    + 
"Please report this to the author.");
 
  587        for (
int i=0; i < pathInFullMol.size()-1; i++)
 
  589            IBond bnd = mol.getBond(pathInFullMol.get(i), 
 
  590                                    pathInFullMol.get(i+1));
 
  600            ArrayList<Point3d> fourPoints = 
new ArrayList<Point3d>();
 
  609            long vIdA0 = a0.getProperty(keyPropVrtID);
 
  610            long vIdA1 = a1.getProperty(keyPropVrtID);
 
  611            long vIdA2 = a2.getProperty(keyPropVrtID);
 
  612            long vIdA3 = a3.getProperty(keyPropVrtID);
 
  616            p0 = a0.getPoint3d(); 
 
  617            p1 = a1.getPoint3d();
 
  618            p2 = a2.getPoint3d();
 
  619            p3 = a3.getPoint3d(); 
 
  629                    if (apsPerBond.keySet().contains(bndA1A2))
 
  631                        if (apsPerBond.get(bndA1A2).contains(ap))
 
  636                    p0 = 
new Point3d(ap.getDirectionVector());
 
  644                List<IAtom> nbrsOfA1 = 
iacPathVAVB.getConnectedAtomsList(a1);
 
  645                int lowIDs = 10000000;
 
  646                for (IAtom nbrOfA1 : nbrsOfA1)
 
  658                p0 = 
new Point3d(
iacPathVAVB.getAtom(lowIDs).getPoint3d());
 
  669                    if (apsPerBond.keySet().contains(bndA1A2))
 
  671                        if (apsPerBond.get(bndA1A2).contains(ap))
 
  676                    p3 = 
new Point3d(ap.getDirectionVector());
 
  684                List<IAtom> nbrsOfA2 = 
iacPathVAVB.getConnectedAtomsList(a2);
 
  685                int lowIDs = 10000000;
 
  686                for (IAtom nbrOfA2 : nbrsOfA2)
 
  698                p3 = 
new Point3d(
iacPathVAVB.getAtom(lowIDs).getPoint3d());
 
  711            System.out.println(
"Points for dihedral angle definition: ");
 
  716                    System.out.println(
"  "+p);
 
  718            System.out.println(
"  ");
 
  737        IAtom head = iac.getAtom(0);
 
  738        IAtom tail = iac.getAtom(iac.getAtomCount()-1);
 
  739        ShortestPaths sp = 
new ShortestPaths(iac, head);
 
  740        List<IAtom> path = 
new ArrayList<IAtom>(Arrays.asList(
 
  931       StringBuilder sb = 
new StringBuilder();
 
  932       boolean first = 
true;
 
  939           sb.append(v.getVertexId());
 
  942       return sb.toString();
 
General set of constants used in DENOPTIM.
static final Object MOLPROPAPxBOND
Key for IAtomContainer property containing the map of AttachmentPoints per atom.
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 MOLPROPAPxATOM
Key for IAtomContainer property containing the map of AttachmentPoints per vertex ID.
An attachment point (AP) is a possibility to attach a Vertex onto the vertex holding the AP (i....
void setOwner(Vertex owner)
Sets the reference to the vertex that owns this attachment point.
AttachmentPoint clone()
Returns a deep clone of this attachment point.
Container for the list of vertices and the edges that connect them.
void addVertex(Vertex vertex)
Appends a vertex to this graph without creating any edge.
void appendVertexOnAP(AttachmentPoint srcAP, AttachmentPoint trgAP)
Append a vertex to this graph: adds the new vertex to the list of vertices belonging to the graph,...
void getParentTree(Vertex vertex, List< Vertex > parentTree)
Traverse the graph until it identifies the source of the directed path reachable from the given verte...
This class represents the edge between two vertices.
AttachmentPoint getTrgAP()
AttachmentPoint getSrcAP()
A vertex is a data structure that has an identity and holds a list of AttachmentPoints.
abstract Vertex clone()
Returns a deep-copy of this vertex.
String[] getPathIDs(AttachmentPoint apA, AttachmentPoint apB)
Produces a pair of strings that identify the "path" between two given attachment points.
abstract List< AttachmentPoint > getAttachmentPoints()
AttachmentPoint getAP(int i)
Get attachment point i on this vertex.
This object represents a path in a DGraph.
RingClosingConformations rcc
The list of closable conformations, if any is found.
boolean hasMolRepr
The flag defining whether this object has already a molecular representation or not.
String getAtomRefStr()
Returns the string with atom symbols and number for an easy identification of the path in a molecular...
static Iterable< AttachmentPoint > findPath(Vertex from, Vertex to, Set< Long > visited)
Returns a sequence of APs that is the path from vertex from to vertex to.
List< IBond > getBondPath()
Returns the list of bonds in the path between the head and the tail.
RingClosingConformations getRCC()
Returns the ring closing conformations.
String atmNumStr
The string of atoms involved (atom numbers from full molecule list)
int getPathLength()
Returns the length of the list of edges involved in this path.
void makeMolecularRepresentation(IAtomContainer mol, boolean make3D, Logger logger, Randomizer randomizer)
Creates the molecular representation, list of atoms and bonds involved in the path between the head a...
List< Vertex > getVertecesPath()
Returns the list of verteces involved.
Vertex vA
The vertex representing the first RCA: head of the path.
IAtomContainer getMolecularRepresentation()
Returns the molecular representation.
String chainID
The string identifier of this path.
String getChainID()
Returns the string representation of the path.
Vertex vB
The vertex representing the second RCA: the tail of the path.
PathSubGraph(Vertex vA, Vertex vB, DGraph molGraph)
Constructs a new PathSubGraph specifying the first and last vertex of the path.
List< IBond > bondsPathVAVB
The list of bonds in the shortest path.
IAtomContainer iacPathVAVB
The molecular representation of the fragment in the path.
List< IAtom > getAtomPath()
Returns the list of atoms in the path between the head and the tail.
boolean hasMolecularRepresentation()
Returns true if the molecular representation has been set.
List< Edge > edgesPathVAVB
The list of edges of the original graph and involved in the path.
Vertex getHeadVertex()
Returns the vertex representing the head of the chain.
List< IAtom > atomsPathVAVB
The list of atoms in the shortest path.
ArrayList< ArrayList< Point3d > > dihedralRefPts
Per each bond the pair of point used to define the torsion.
static List< IAtom > findAtomPath(IAtomContainer iac)
Finds the shortest path of atoms between the first and last atom in the given atom container.
ArrayList< ArrayList< Point3d > > getDihedralRefPoints()
Returns the list of point to be used to define the torsion of a bond uniquely (independently on the s...
Vertex getTailVertex()
Returns the vertex representing the tail of the chain.
List< Vertex > vertPathVAVB
The list of vertices of the original graph and involved in the path.
static DGraph findPath(Vertex from, Vertex to)
Returns a path as a DENOPTIMGraph from the first argument to the second one.
List< Edge > getEdgesPath()
Returns the list of edges involved.
ArrayList< String > allPossibleChainIDs
void setRCC(RingClosingConformations rcc)
Set the ring closing conformations to this object.
long getVertexIdInPath(IAtom a)
DGraph graph
The graph representation of this path.
Vertex turningPointVert
The turning point in the graph: after this point the direction of edges becomes opposite than before.
List< String > getAllAlternativeChainIDs()
Returns all the possible IDs for this chain.
Utility methods for input/output.
static void writeSDFFile(String fileName, IAtomContainer mol)
Writes IAtomContainer to SDF file.
Tool to build build three-dimensional (3D) tree-like molecular structures from DGraph.
IAtomContainer convertGraphTo3DAtomContainer(DGraph graph)
Created a three-dimensional molecular representation from a given DGraph.
Tool to generate random numbers and random decisions.