Search in sources :

Example 6 with BondMapping

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

the class Isomorphism method searchFromPreviousMapping.

/**
 * Search a list of mapped blocs from a smaller mapped bloc
 * @param mb Initial mapped bloc
 * @param ext Extension to the previous mapped bloc
 * @return New mapped blocs.
 */
public static List<MappedChain> searchFromPreviousMapping(MappedChain mb, Extension ext, MatchingType type) {
    List<MappedChain> mbs = new ArrayList<>();
    ChemicalObject co = mb.getChemObject();
    IMolecule mol = co.getMolecule();
    List<Integer> neighbors = mb.getNeighborsBonds(mol);
    // Create a new bloc for each neighbor
    for (int idx : neighbors) {
        // Create bloc
        IBond nb = mol.getBond(idx);
        List<BondMapping> matchings = ext.match(nb, type);
        for (BondMapping bm : matchings) {
            int atomIdx0 = mol.getAtomNumber(bm.a0);
            int atomIdx1 = mol.getAtomNumber(bm.a1);
            int blocPosition0 = mb.getMappingIdx(atomIdx0);
            int blocPosition1 = mb.getMappingIdx(atomIdx1);
            int hydrogen0 = bm.h0;
            int hydrogen1 = bm.h1;
            Chain bloc = new Chain(mb.getChain(), ext, blocPosition0, blocPosition1);
            List<Integer> atoms = new ArrayList<>(mb.getAtomsMapping());
            if (blocPosition0 == -1)
                atoms.add(atomIdx0);
            if (blocPosition1 == -1)
                atoms.add(atomIdx1);
            List<Integer> bonds = new ArrayList<>(mb.getBondsMapping());
            bonds.add(mol.getBondNumber(nb));
            List<MatchingType> matchingTypes = new ArrayList<>(mb.getMatchings());
            matchingTypes.add(bm.matchingType);
            Map<Integer, Integer> hydrogens = new HashMap<>(mb.getHydrogensMapping());
            if (!hydrogens.containsKey(atomIdx0) || hydrogens.get(atomIdx0) <= hydrogen0)
                hydrogens.put(atomIdx0, hydrogen0);
            if (!hydrogens.containsKey(atomIdx1) || hydrogens.get(atomIdx1) <= hydrogen1)
                hydrogens.put(atomIdx1, hydrogen1);
            MappedChain newMb = new MappedChain(co, bloc, atoms, bonds, matchingTypes, hydrogens);
            if (!mbs.contains(newMb))
                mbs.add(newMb);
        }
    }
    return mbs;
}
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) ChemicalObject(model.ChemicalObject) BondMapping(algorithms.isomorphism.chains.Extension.BondMapping)

Example 7 with BondMapping

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

the class BonbMatchingTests method perfectMatching.

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

Example 8 with BondMapping

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

the class BonbMatchingTests method noPerfectMatching.

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

Example 9 with BondMapping

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

the class BonbMatchingTests method hydrogenNoMatching.

@Test
public void hydrogenNoMatching() {
    Extension ext = new Extension("c,1,N,1,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 10 with BondMapping

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

the class BonbMatchingTests method strongMatching2.

@Test
public void strongMatching2() {
    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)

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