Search in sources :

Example 1 with BondMapping

use of algorithms.isomorphism.chains.Extension.BondMapping in project Smiles2Monomers by yoann-dufresne.

the class BonbMatchingTests method lightMatching.

@Test
public void lightMatching() {
    Extension ext = new Extension("C,1,N,0,0");
    List<BondMapping> matchs = ext.match(this.bond1, MatchingType.LIGHT);
    Assert.assertTrue(matchs.size() == 1);
}
Also used : Extension(algorithms.isomorphism.chains.Extension) BondMapping(algorithms.isomorphism.chains.Extension.BondMapping) Test(org.junit.Test)

Example 2 with BondMapping

use of algorithms.isomorphism.chains.Extension.BondMapping in project Smiles2Monomers by yoann-dufresne.

the class BonbMatchingTests method strongMatching.

@Test
public void strongMatching() {
    Extension ext = new Extension("c,1,N,0,1");
    List<BondMapping> matchs = ext.match(this.bond1, MatchingType.STRONG);
    Assert.assertTrue(matchs.size() == 1);
}
Also used : Extension(algorithms.isomorphism.chains.Extension) BondMapping(algorithms.isomorphism.chains.Extension.BondMapping) Test(org.junit.Test)

Example 3 with BondMapping

use of algorithms.isomorphism.chains.Extension.BondMapping in project Smiles2Monomers by yoann-dufresne.

the class BonbMatchingTests method noHydrogenMatching.

@Test
public void noHydrogenMatching() {
    Extension ext = new Extension("c,1,N,0,0");
    List<BondMapping> matchs = ext.match(this.bond1, MatchingType.STRONG);
    Assert.assertTrue(matchs.size() == 1);
}
Also used : Extension(algorithms.isomorphism.chains.Extension) BondMapping(algorithms.isomorphism.chains.Extension.BondMapping) Test(org.junit.Test)

Example 4 with BondMapping

use of algorithms.isomorphism.chains.Extension.BondMapping in project Smiles2Monomers by yoann-dufresne.

the class BonbMatchingTests method aromaticNoMatching.

@Test
public void aromaticNoMatching() {
    Extension ext = new Extension("C,1,N,0,1");
    List<BondMapping> matchs = ext.match(this.bond1, MatchingType.STRONG);
    Assert.assertTrue(matchs.size() == 0);
}
Also used : Extension(algorithms.isomorphism.chains.Extension) BondMapping(algorithms.isomorphism.chains.Extension.BondMapping) Test(org.junit.Test)

Example 5 with BondMapping

use of algorithms.isomorphism.chains.Extension.BondMapping in project Smiles2Monomers by yoann-dufresne.

the class Isomorphism method searchFromPreviousMapping.

/**/
public static List<MappedChain> searchFromPreviousMapping(MappedChain mc, Extension ext, int idx1, int idx2, MatchingType type) {
    IMolecule mol = mc.getChemObject().getMolecule();
    int extIdx = idx1 == -1 ? idx2 : idx1;
    List<MappedChain> mappings = new ArrayList<>();
    // Connected bonds search
    List<IBond> connectedBonds = null;
    if (extIdx == -1) {
        connectedBonds = new ArrayList<>();
        for (IBond bond : mol.bonds()) connectedBonds.add(bond);
    } else {
        IAtom extAtom = mol.getAtom(mc.getAtomsMapping().get(extIdx));
        connectedBonds = mol.getConnectedBondsList(extAtom);
    }
    for (IBond neighbor : connectedBonds) {
        // No need to search bonds already present in mapping.
        if (mc.getBondsMapping().contains(mol.getBondNumber(neighbor)))
            continue;
        List<BondMapping> bms = ext.match(neighbor, type);
        for (BondMapping bm : bms) {
            // Verification of the compatibility with previous matching
            if (idx1 != -1 && mol.getAtomNumber(bm.a0) != mc.getAtomsMapping().get(idx1))
                continue;
            if (idx2 != -1 && mol.getAtomNumber(bm.a1) != mc.getAtomsMapping().get(idx2))
                continue;
            // Creation of the new mapping
            Chain chain = new Chain(mc.getChain(), ext, idx1, idx2);
            List<Integer> atoms = new ArrayList<>(mc.getAtomsMapping());
            Map<Integer, Integer> hydrogens = new HashMap<>(mc.getHydrogensMapping());
            if (idx1 == -1) {
                int an = mol.getAtomNumber(bm.a0);
                // To avoid cycles where there is no cycle.
                if (mc.getAtomsMapping().contains(an))
                    continue;
                atoms.add(an);
                hydrogens.put(an, bm.h0);
            }
            if (idx2 == -1) {
                int an = mol.getAtomNumber(bm.a1);
                // To avoid cycles where there is no cycle.
                if (mc.getAtomsMapping().contains(an))
                    continue;
                atoms.add(an);
                hydrogens.put(an, bm.h1);
            }
            List<Integer> bonds = new ArrayList<>(mc.getBondsMapping());
            bonds.add(mol.getBondNumber(neighbor));
            List<MatchingType> matchings = new ArrayList<>(mc.getMatchings());
            matchings.add(bm.matchingType);
            MappedChain newMc = new MappedChain(mc.getChemObject(), chain, atoms, bonds, matchings, hydrogens);
            mappings.add(newMc);
        }
    }
    return mappings;
}
Also used : MappedChain(algorithms.isomorphism.chains.MappedChain) Chain(algorithms.isomorphism.chains.Chain) MappedChain(algorithms.isomorphism.chains.MappedChain) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) IBond(org.openscience.cdk.interfaces.IBond) IMolecule(org.openscience.cdk.interfaces.IMolecule) BondMapping(algorithms.isomorphism.chains.Extension.BondMapping) IAtom(org.openscience.cdk.interfaces.IAtom)

Aggregations

BondMapping (algorithms.isomorphism.chains.Extension.BondMapping)11 Extension (algorithms.isomorphism.chains.Extension)8 Test (org.junit.Test)8 ArrayList (java.util.ArrayList)3 IBond (org.openscience.cdk.interfaces.IBond)3 Chain (algorithms.isomorphism.chains.Chain)2 MappedChain (algorithms.isomorphism.chains.MappedChain)2 HashMap (java.util.HashMap)2 IMolecule (org.openscience.cdk.interfaces.IMolecule)2 ChemicalObject (model.ChemicalObject)1 Residue (model.Residue)1 IAtom (org.openscience.cdk.interfaces.IAtom)1