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;
}
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);
}
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);
}
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);
}
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);
}
Aggregations