Search in sources :

Example 1 with RNode

use of org.openscience.cdk.isomorphism.mcss.RNode in project cdk by cdk.

the class UniversalIsomorphismTester method arcConstructor.

/**
 *  Build edges of the {@link RGraph}s.
 *  This method create the edge of the RGraph and
 *  calculates the incompatibility and neighborhood
 *  relationships between RGraph nodes.
 *
 * @param  gr   the rGraph
 * @param  ac1   first molecule. Must not be an {@link IQueryAtomContainer}.
 * @param  ac2   second molecule. May be an {@link IQueryAtomContainer}.
 * @throws CDKException if it takes too long to get the overlaps
 */
private static void arcConstructor(RGraph gr, IAtomContainer ac1, IAtomContainer ac2) throws CDKException {
    // each node is incompatible with himself
    for (int i = 0; i < gr.getGraph().size(); i++) {
        RNode x = gr.getGraph().get(i);
        x.getForbidden().set(i);
    }
    IBond a1;
    IBond a2;
    IBond b1;
    IBond b2;
    gr.setFirstGraphSize(ac1.getBondCount());
    gr.setSecondGraphSize(ac2.getBondCount());
    for (int i = 0; i < gr.getGraph().size(); i++) {
        RNode x = gr.getGraph().get(i);
        // else they are incompatible.
        for (int j = i + 1; j < gr.getGraph().size(); j++) {
            RNode y = gr.getGraph().get(j);
            a1 = ac1.getBond(x.getRMap().getId1());
            a2 = ac2.getBond(x.getRMap().getId2());
            b1 = ac1.getBond(y.getRMap().getId1());
            b2 = ac2.getBond(y.getRMap().getId2());
            if (a2 instanceof IQueryBond) {
                if (a1.equals(b1) || a2.equals(b2) || !queryAdjacencyAndOrder(a1, b1, a2, b2)) {
                    x.getForbidden().set(j);
                    y.getForbidden().set(i);
                } else if (hasCommonAtom(a1, b1)) {
                    x.getExtension().set(j);
                    y.getExtension().set(i);
                }
            } else {
                if (a1.equals(b1) || a2.equals(b2) || (!getCommonSymbol(a1, b1).equals(getCommonSymbol(a2, b2)))) {
                    x.getForbidden().set(j);
                    y.getForbidden().set(i);
                } else if (hasCommonAtom(a1, b1)) {
                    x.getExtension().set(j);
                    y.getExtension().set(i);
                }
            }
        }
    }
}
Also used : IBond(org.openscience.cdk.interfaces.IBond) IQueryBond(org.openscience.cdk.isomorphism.matchers.IQueryBond) RNode(org.openscience.cdk.isomorphism.mcss.RNode)

Example 2 with RNode

use of org.openscience.cdk.isomorphism.mcss.RNode in project cdk by cdk.

the class UniversalIsomorphismTester method nodeConstructor.

/**
 *  Builds  the nodes of the {@link RGraph} ( resolution graph ), from
 *  two atom containers (description of the two molecules to compare)
 *
 * @param  gr   the target RGraph
 * @param  ac1   first molecule. Must not be an {@link IQueryAtomContainer}.
 * @param  ac2   second molecule. May be an {@link IQueryAtomContainer}.
 * @throws CDKException if it takes too long to identify overlaps
 */
private static void nodeConstructor(RGraph gr, IAtomContainer ac1, IAtomContainer ac2) throws CDKException {
    if (ac1 instanceof IQueryAtomContainer)
        throw new CDKException("The first IAtomContainer must not be an IQueryAtomContainer");
    // resets the target graph.
    gr.clear();
    // compares each bond of G1 to each bond of G2
    for (int i = 0; i < ac1.getBondCount(); i++) {
        for (int j = 0; j < ac2.getBondCount(); j++) {
            IBond bondA2 = ac2.getBond(j);
            if (bondA2 instanceof IQueryBond) {
                IQueryBond queryBond = (IQueryBond) bondA2;
                IQueryAtom atom1 = (IQueryAtom) (bondA2.getBegin());
                IQueryAtom atom2 = (IQueryAtom) (bondA2.getEnd());
                IBond bond = ac1.getBond(i);
                if (queryBond.matches(bond)) {
                    // ok, bonds match
                    if (atom1.matches(bond.getBegin()) && atom2.matches(bond.getEnd()) || atom1.matches(bond.getEnd()) && atom2.matches(bond.getBegin())) {
                        // ok, atoms match in either order
                        gr.addNode(new RNode(i, j));
                    }
                }
            } else {
                // in the resolution graph
                if ((// bond type conditions
                (// same bond order and same aromaticity flag (either both on or off)
                ac1.getBond(i).getOrder() == ac2.getBond(j).getOrder() && ac1.getBond(i).getFlag(CDKConstants.ISAROMATIC) == ac2.getBond(j).getFlag(CDKConstants.ISAROMATIC)) || (// both bond are aromatic
                ac1.getBond(i).getFlag(CDKConstants.ISAROMATIC) && ac2.getBond(j).getFlag(CDKConstants.ISAROMATIC))) && (// atom type conditions
                (// a1 = a2 && b1 = b2
                ac1.getBond(i).getBegin().getSymbol().equals(ac2.getBond(j).getBegin().getSymbol()) && ac1.getBond(i).getEnd().getSymbol().equals(ac2.getBond(j).getEnd().getSymbol())) || (// a1 = b2 && b1 = a2
                ac1.getBond(i).getBegin().getSymbol().equals(ac2.getBond(j).getEnd().getSymbol()) && ac1.getBond(i).getEnd().getSymbol().equals(ac2.getBond(j).getBegin().getSymbol())))) {
                    gr.addNode(new RNode(i, j));
                }
            }
        }
    }
}
Also used : CDKException(org.openscience.cdk.exception.CDKException) IBond(org.openscience.cdk.interfaces.IBond) IQueryAtom(org.openscience.cdk.isomorphism.matchers.IQueryAtom) IQueryBond(org.openscience.cdk.isomorphism.matchers.IQueryBond) RNode(org.openscience.cdk.isomorphism.mcss.RNode) IQueryAtomContainer(org.openscience.cdk.isomorphism.matchers.IQueryAtomContainer)

Aggregations

IBond (org.openscience.cdk.interfaces.IBond)2 IQueryBond (org.openscience.cdk.isomorphism.matchers.IQueryBond)2 RNode (org.openscience.cdk.isomorphism.mcss.RNode)2 CDKException (org.openscience.cdk.exception.CDKException)1 IQueryAtom (org.openscience.cdk.isomorphism.matchers.IQueryAtom)1 IQueryAtomContainer (org.openscience.cdk.isomorphism.matchers.IQueryAtomContainer)1