Search in sources :

Example 1 with IQueryBond

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;
}
Also used : AnyOrderQueryBond(org.openscience.cdk.isomorphism.matchers.smarts.AnyOrderQueryBond) SingleOrAromaticBond(ambit2.smarts.SingleOrAromaticBond) SingleBondAromaticityNotSpecified(ambit2.smarts.SingleBondAromaticityNotSpecified) DoubleNonAromaticBond(ambit2.smarts.DoubleNonAromaticBond) DoubleBondAromaticityNotSpecified(ambit2.smarts.DoubleBondAromaticityNotSpecified) AnyOrderQueryBond(org.openscience.cdk.isomorphism.matchers.smarts.AnyOrderQueryBond) OrderQueryBond(org.openscience.cdk.isomorphism.matchers.smarts.OrderQueryBond) IQueryBond(org.openscience.cdk.isomorphism.matchers.IQueryBond) SingleNonAromaticBond(ambit2.smarts.SingleNonAromaticBond)

Example 2 with IQueryBond

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;
}
Also used : HashMap(java.util.HashMap) IQueryAtom(org.openscience.cdk.isomorphism.matchers.IQueryAtom) SLNBond(ambit2.sln.SLNBond) SLNAtom(ambit2.sln.SLNAtom) IQueryBond(org.openscience.cdk.isomorphism.matchers.IQueryBond) IQueryAtomContainer(org.openscience.cdk.isomorphism.matchers.IQueryAtomContainer) QueryAtomContainer(org.openscience.cdk.isomorphism.matchers.QueryAtomContainer) IQueryAtomContainer(org.openscience.cdk.isomorphism.matchers.IQueryAtomContainer) IAtom(org.openscience.cdk.interfaces.IAtom)

Example 3 with IQueryBond

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;
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) IBond(org.openscience.cdk.interfaces.IBond) IQueryBond(org.openscience.cdk.isomorphism.matchers.IQueryBond) QueryBond(org.openscience.cdk.isomorphism.matchers.QueryBond) IQueryBond(org.openscience.cdk.isomorphism.matchers.IQueryBond) IQueryAtomContainer(org.openscience.cdk.isomorphism.matchers.IQueryAtomContainer) IChemObjectBuilder(org.openscience.cdk.interfaces.IChemObjectBuilder) QueryAtomContainer(org.openscience.cdk.isomorphism.matchers.QueryAtomContainer) IQueryAtomContainer(org.openscience.cdk.isomorphism.matchers.IQueryAtomContainer) IAtom(org.openscience.cdk.interfaces.IAtom)

Example 4 with IQueryBond

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;
}
Also used : IBond(org.openscience.cdk.interfaces.IBond) IQueryBond(org.openscience.cdk.isomorphism.matchers.IQueryBond) IAtom(org.openscience.cdk.interfaces.IAtom)

Example 5 with IQueryBond

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;
}
Also used : IQueryAtom(org.openscience.cdk.isomorphism.matchers.IQueryAtom) IQueryBond(org.openscience.cdk.isomorphism.matchers.IQueryBond) RingIdentifierAtom(org.openscience.cdk.isomorphism.matchers.smarts.RingIdentifierAtom)

Aggregations

IQueryBond (org.openscience.cdk.isomorphism.matchers.IQueryBond)23 IBond (org.openscience.cdk.interfaces.IBond)14 IAtom (org.openscience.cdk.interfaces.IAtom)10 IQueryAtom (org.openscience.cdk.isomorphism.matchers.IQueryAtom)10 IQueryAtomContainer (org.openscience.cdk.isomorphism.matchers.IQueryAtomContainer)9 CDKException (org.openscience.cdk.exception.CDKException)5 LogicalOperatorBond (org.openscience.cdk.isomorphism.matchers.smarts.LogicalOperatorBond)4 HashMap (java.util.HashMap)3 QueryAtomContainer (org.openscience.cdk.isomorphism.matchers.QueryAtomContainer)3 LinkedHashMap (java.util.LinkedHashMap)2 IAtomContainer (org.openscience.cdk.interfaces.IAtomContainer)2 RingIdentifierAtom (org.openscience.cdk.isomorphism.matchers.smarts.RingIdentifierAtom)2 RNode (org.openscience.cdk.isomorphism.mcss.RNode)2 SLNAtom (ambit2.sln.SLNAtom)1 SLNBond (ambit2.sln.SLNBond)1 DoubleBondAromaticityNotSpecified (ambit2.smarts.DoubleBondAromaticityNotSpecified)1 DoubleNonAromaticBond (ambit2.smarts.DoubleNonAromaticBond)1 SingleBondAromaticityNotSpecified (ambit2.smarts.SingleBondAromaticityNotSpecified)1 SingleNonAromaticBond (ambit2.smarts.SingleNonAromaticBond)1 SingleOrAromaticBond (ambit2.smarts.SingleOrAromaticBond)1