use of org.openscience.cdk.isomorphism.matchers.IQueryBond in project ambit-mirror by ideaconsult.
the class SLN2ChemObject method slnBondToQueryBond.
/*
* Converts only the bond type/expression info
* connected atoms info is not handled
*/
public IQueryBond slnBondToQueryBond(SLNBond slnBo) {
currentConversionError = null;
currentConversionWarning = null;
if (slnBo == null) {
currentConversionError = "Bond is null";
return null;
}
if (slnBo.bondType == 0) {
if (slnBo.bondExpression == null)
return new AnyOrderQueryBond(SilentChemObjectBuilder.getInstance());
// TODO handle bond expression
} else {
if (slnBo.bondExpression == null) {
IQueryBond bond = null;
switch(slnBo.bondType) {
case 1:
if (conversionConfig.FlagSLNSingleBondToSingleOrAromaticBond)
bond = new SingleOrAromaticBond(SilentChemObjectBuilder.getInstance());
else if (conversionConfig.FlagSupportSingleBondAromaticityNotSpecified)
bond = new SingleBondAromaticityNotSpecified(SilentChemObjectBuilder.getInstance());
else
bond = new SingleNonAromaticBond(SilentChemObjectBuilder.getInstance());
break;
case 2:
if (conversionConfig.FlagSupportDoubleBondAromaticityNotSpecified)
bond = new DoubleBondAromaticityNotSpecified(SilentChemObjectBuilder.getInstance());
else
bond = new DoubleNonAromaticBond(SilentChemObjectBuilder.getInstance());
break;
case 3:
bond = new OrderQueryBond(IBond.Order.TRIPLE, SilentChemObjectBuilder.getInstance());
break;
}
return bond;
}
// TODO handle bond expression
}
return null;
}
use of org.openscience.cdk.isomorphism.matchers.IQueryBond in project ambit-mirror by ideaconsult.
the class SLN2ChemObject method slnContainerToQueryAtomContainer.
public IQueryAtomContainer slnContainerToQueryAtomContainer(SLNContainer slnContainer) {
clearAllErrorsAndWarnings();
IQueryAtomContainer container = new QueryAtomContainer(SilentChemObjectBuilder.getInstance());
Map<SLNAtom, IQueryAtom> convertedAtoms = new HashMap<SLNAtom, IQueryAtom>();
for (int i = 0; i < slnContainer.getAtomCount(); i++) {
SLNAtom slnAtom = (SLNAtom) slnContainer.getAtom(i);
IQueryAtom atom = slnAtomToQueryAtom(slnAtom);
if (currentConversionWarning != null)
conversionWarnings.add(currentConversionWarning + " for atom: " + (i + 1));
if (atom == null) {
conversionErrors.add(currentConversionError + " for atom: " + (i + 1));
continue;
}
container.addAtom(atom);
convertedAtoms.put(slnAtom, atom);
}
for (int i = 0; i < slnContainer.getBondCount(); i++) {
SLNBond slnBbond = (SLNBond) slnContainer.getBond(i);
IQueryBond bond = slnBondToQueryBond(slnBbond);
if (currentConversionWarning != null)
conversionWarnings.add(currentConversionWarning + " for bond: " + (i + 1));
if (bond == null) {
conversionErrors.add(currentConversionError + " for bond: " + (i + 1));
continue;
}
IAtom[] newAtoms = new IAtom[2];
newAtoms[0] = convertedAtoms.get(slnBbond.getAtom(0));
newAtoms[1] = convertedAtoms.get(slnBbond.getAtom(1));
if (newAtoms[0] == null || newAtoms[1] == null)
// one of the atoms is not converted
continue;
bond.setAtoms(newAtoms);
container.addBond(bond);
}
return container;
}
use of org.openscience.cdk.isomorphism.matchers.IQueryBond in project cdk by cdk.
the class Abbreviations method matchExact.
/**
* Internal - create a query atom container that exactly matches the molecule provided.
* Similar to {@link org.openscience.cdk.isomorphism.matchers.QueryAtomContainerCreator}
* but we can't access SMARTS query classes from that module (cdk-isomorphism).
*
* @param mol molecule
* @return query container
* @see org.openscience.cdk.isomorphism.matchers.QueryAtomContainerCreator
*/
private IQueryAtomContainer matchExact(IAtomContainer mol) {
final IChemObjectBuilder bldr = mol.getBuilder();
final IQueryAtomContainer qry = new QueryAtomContainer(mol.getBuilder());
final Map<IAtom, IAtom> atmmap = new HashMap<>();
for (IAtom atom : mol.atoms()) {
IAtom qatom = matchExact(mol, atom);
if (qatom != null) {
atmmap.put(atom, qatom);
qry.addAtom(qatom);
}
}
for (IBond bond : mol.bonds()) {
final IAtom beg = atmmap.get(bond.getBegin());
final IAtom end = atmmap.get(bond.getEnd());
// attach bond skipped
if (beg == null || end == null)
continue;
IQueryBond qbond = new QueryBond(beg, end, Expr.Type.TRUE);
qry.addBond(qbond);
}
return qry;
}
use of org.openscience.cdk.isomorphism.matchers.IQueryBond in project cdk by cdk.
the class DfState method prepare.
// prepare the query, the required stack size is returned
private int prepare(IAtom atom, IBond prev) {
int count = 0;
amap[atom.getIndex()] = 1;
for (IBond bond : atom.bonds()) {
if (bond == prev)
continue;
IAtom nbr = bond.getOther(atom);
if (amap[nbr.getIndex()] == 0) {
qbonds[numBonds++] = (IQueryBond) bond;
count += prepare(nbr, bond) + 1;
} else if (nbr.getIndex() < atom.getIndex()) {
// ring closure
++count;
qbonds[numBonds++] = (IQueryBond) bond;
}
}
return count;
}
use of org.openscience.cdk.isomorphism.matchers.IQueryBond in project cdk by cdk.
the class SmartsQueryVisitor method visit.
public Object visit(ASTRingIdentifier node, Object data) {
IQueryAtom atom = (IQueryAtom) data;
RingIdentifierAtom ringIdAtom = new RingIdentifierAtom(builder);
ringIdAtom.setAtom(atom);
IQueryBond bond;
if (node.jjtGetNumChildren() == 0) {
// implicit bond
bond = null;
} else {
bond = (IQueryBond) node.jjtGetChild(0).jjtAccept(this, data);
}
ringIdAtom.setRingBond(bond);
return ringIdAtom;
}
Aggregations