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