Search in sources :

Example 1 with SMARTSAtom

use of org.openscience.cdk.isomorphism.matchers.smarts.SMARTSAtom in project ambit-mirror by ideaconsult.

the class SmartsManager method getAtomMapsFromBondMaps.

/**
 * This function returns a vector of all positions (IAtoms) at which The
 * Query is matched (i.e. it first atom is matched) The full atom mapping is
 * not obtained from this function !!! This function is a helper utility for
 * the CDK isomorphism algorithm
 */
List<IAtom> getAtomMapsFromBondMaps(List bondMapping, IAtomContainer target, IAtomContainer recQuery) {
    // The query must contain at least 3 atoms and 2 bonds.
    // The first bond is always 0-1
    // Two cases are considered for the second bond:
    // a0-a1-a2 (e.g. CCC)
    // a0(-a1)-a2 (e.g. C(C)C)
    // So the common atom of bonds 0 and 1 is either atom 1 or atom 0
    // The latter assumptions are based on the way recursive SMARTS are
    // parsed
    List<IAtom> atomMaps = new ArrayList<IAtom>();
    if (recQuery.getBondCount() < 2)
        return (atomMaps);
    SMARTSBond qBond0 = (SMARTSBond) recQuery.getBond(0);
    SMARTSBond qBond1 = (SMARTSBond) recQuery.getBond(1);
    int qID0 = recQuery.getBondNumber(qBond0);
    int qID1 = recQuery.getBondNumber(qBond1);
    SMARTSAtom qAtom0 = (SMARTSAtom) recQuery.getAtom(0);
    SMARTSAtom qAtom1 = (SMARTSAtom) recQuery.getAtom(1);
    IAtom commonQAt = getBondsCommonAtom(qBond0, qBond1);
    if ((commonQAt != qAtom0) && (commonQAt != qAtom1))
        // This should never happen
        return (atomMaps);
    IBond tBond0 = null;
    IBond tBond1 = null;
    IAtom commonTAt;
    RMap map;
    List mapList;
    for (Object aList : bondMapping) {
        mapList = (List) aList;
        // Search RMaps to find the corresponding target bonds
        // (qBond0<-->tBond0, qBond1<-->tBond1)
        // Note: map.getId2 corresponds to the query; map.getId1 corresponds
        // to the target
        int found = 0;
        for (Object aMap : mapList) {
            map = (RMap) aMap;
            if (map.getId2() == qID0) {
                found++;
                tBond0 = target.getBond(map.getId1());
            }
            if (map.getId2() == qID1) {
                found++;
                tBond1 = target.getBond(map.getId1());
            }
            if (found >= 2)
                break;
        }
        if (// This should never happen
        found < 2)
            continue;
        commonTAt = getBondsCommonAtom(tBond0, tBond1);
        if (commonQAt == qAtom0)
            atomMaps.add(commonTAt);
        else {
            // So the other atom (not commonTAt) must be added to atomMaps
            if (commonTAt == tBond0.getAtom(0))
                atomMaps.add(tBond0.getAtom(1));
            else
                atomMaps.add(tBond0.getAtom(0));
        }
    }
    return (atomMaps);
}
Also used : SMARTSAtom(org.openscience.cdk.isomorphism.matchers.smarts.SMARTSAtom) SMARTSBond(org.openscience.cdk.isomorphism.matchers.smarts.SMARTSBond) ArrayList(java.util.ArrayList) IBond(org.openscience.cdk.interfaces.IBond) ArrayList(java.util.ArrayList) List(java.util.List) RMap(org.openscience.cdk.isomorphism.mcss.RMap) IAtom(org.openscience.cdk.interfaces.IAtom)

Example 2 with SMARTSAtom

use of org.openscience.cdk.isomorphism.matchers.smarts.SMARTSAtom in project ambit-mirror by ideaconsult.

the class SmartsManager method getAtomMappingsFor1AtomQuery.

List<IAtom> getAtomMappingsFor1AtomQuery(IAtomContainer target, IAtomContainer recQuery) {
    SMARTSAtom qAtom = (SMARTSAtom) recQuery.getAtom(0);
    List<IAtom> atomMaps = new ArrayList<IAtom>();
    for (int i = 0; i < target.getAtomCount(); i++) if (qAtom.matches(target.getAtom(i)))
        atomMaps.add(target.getAtom(i));
    return (atomMaps);
}
Also used : SMARTSAtom(org.openscience.cdk.isomorphism.matchers.smarts.SMARTSAtom) ArrayList(java.util.ArrayList) IAtom(org.openscience.cdk.interfaces.IAtom)

Example 3 with SMARTSAtom

use of org.openscience.cdk.isomorphism.matchers.smarts.SMARTSAtom in project ambit-mirror by ideaconsult.

the class SmartsManager method getFirstPosAtomMappingsFor2AtomQuery.

List<IAtom> getFirstPosAtomMappingsFor2AtomQuery(IAtomContainer target, IAtomContainer recQuery) {
    List<IAtom> atomMaps = new ArrayList<IAtom>();
    if (recQuery.getBondCount() == 0)
        // The two atoms must be connected otherwise
        return (atomMaps);
    // substr. search returns no matches
    SMARTSAtom qAtom0 = (SMARTSAtom) recQuery.getAtom(0);
    SMARTSAtom qAtom1 = (SMARTSAtom) recQuery.getAtom(1);
    SMARTSBond qBond = (SMARTSBond) recQuery.getBond(0);
    for (int i = 0; i < target.getAtomCount(); i++) {
        IAtom at = target.getAtom(i);
        if (qAtom0.matches(at)) {
            List ca = target.getConnectedAtomsList(at);
            for (int j = 0; j < ca.size(); j++) if (qAtom1.matches((IAtom) ca.get(j))) {
                IBond bo = target.getBond(at, (IAtom) ca.get(j));
                if (bo != null)
                    if (qBond.matches(bo)) {
                        atomMaps.add(at);
                        // for j-cycle
                        break;
                    }
            }
        }
    }
    return (atomMaps);
}
Also used : SMARTSAtom(org.openscience.cdk.isomorphism.matchers.smarts.SMARTSAtom) SMARTSBond(org.openscience.cdk.isomorphism.matchers.smarts.SMARTSBond) ArrayList(java.util.ArrayList) IBond(org.openscience.cdk.interfaces.IBond) ArrayList(java.util.ArrayList) List(java.util.List) IAtom(org.openscience.cdk.interfaces.IAtom)

Example 4 with SMARTSAtom

use of org.openscience.cdk.isomorphism.matchers.smarts.SMARTSAtom in project ambit-mirror by ideaconsult.

the class IsomorphismTester method singleAtomIsomorphism.

boolean singleAtomIsomorphism() {
    SMARTSAtom qa = (SMARTSAtom) query.getAtom(0);
    isomorphismFound = false;
    for (int i = 0; i < target.getAtomCount(); i++) {
        if (qa.matches(target.getAtom(i))) {
            isomorphismFound = true;
            break;
        }
    }
    return (isomorphismFound);
}
Also used : SMARTSAtom(org.openscience.cdk.isomorphism.matchers.smarts.SMARTSAtom)

Example 5 with SMARTSAtom

use of org.openscience.cdk.isomorphism.matchers.smarts.SMARTSAtom in project ambit-mirror by ideaconsult.

the class IsomorphismTester method getIsomorphismPositions.

public List<Integer> getIsomorphismPositions(IAtomContainer container) {
    target = container;
    FlagStoreIsomorphismNode = false;
    isomorphismNodes.clear();
    List<Integer> v = new ArrayList<Integer>();
    if (query.getAtomCount() == 1) {
        SMARTSAtom qa = (SMARTSAtom) query.getAtom(0);
        for (int i = 0; i < target.getAtomCount(); i++) {
            if (qa.matches(target.getAtom(i)))
                v.add(new Integer(i));
        }
        return (v);
    }
    TopLayer.setAtomTopLayers(target, TopLayer.TLProp);
    for (int i = 0; i < target.getAtomCount(); i++) {
        executeSequenceAtPos(i);
        if (isomorphismFound)
            v.add(new Integer(i));
    }
    return (v);
}
Also used : SMARTSAtom(org.openscience.cdk.isomorphism.matchers.smarts.SMARTSAtom) ArrayList(java.util.ArrayList)

Aggregations

SMARTSAtom (org.openscience.cdk.isomorphism.matchers.smarts.SMARTSAtom)27 ArrayList (java.util.ArrayList)12 IAtom (org.openscience.cdk.interfaces.IAtom)11 Test (org.junit.Test)8 QueryAtomContainer (org.openscience.cdk.isomorphism.matchers.QueryAtomContainer)8 List (java.util.List)6 IBond (org.openscience.cdk.interfaces.IBond)4 SMARTSBond (org.openscience.cdk.isomorphism.matchers.smarts.SMARTSBond)4 IAtomContainer (org.openscience.cdk.interfaces.IAtomContainer)3 Node (ambit2.smarts.Node)2 IChemObjectBuilder (org.openscience.cdk.interfaces.IChemObjectBuilder)2 OrderQueryBond (org.openscience.cdk.isomorphism.matchers.OrderQueryBond)2 AnyOrderQueryBond (org.openscience.cdk.isomorphism.matchers.smarts.AnyOrderQueryBond)2 ImplicitHCountAtom (org.openscience.cdk.isomorphism.matchers.smarts.ImplicitHCountAtom)2 IAtomContainerSet (org.openscience.cdk.interfaces.IAtomContainerSet)1 ITetrahedralChirality (org.openscience.cdk.interfaces.ITetrahedralChirality)1 QueryAtom (org.openscience.cdk.isomorphism.matchers.QueryAtom)1 AliphaticSymbolAtom (org.openscience.cdk.isomorphism.matchers.smarts.AliphaticSymbolAtom)1 AromaticOrSingleQueryBond (org.openscience.cdk.isomorphism.matchers.smarts.AromaticOrSingleQueryBond)1 AromaticSymbolAtom (org.openscience.cdk.isomorphism.matchers.smarts.AromaticSymbolAtom)1