Search in sources :

Example 1 with AromaticQueryBond

use of org.openscience.cdk.isomorphism.matchers.smarts.AromaticQueryBond in project ambit-mirror by ideaconsult.

the class SmartsManager method addBond.

void addBond(IQueryAtomContainer container, IAtom atom0, IAtom atom1, IBond bond) {
    IBond newBond = null;
    if (bond instanceof AnyOrderQueryBond)
        newBond = new AnyOrderQueryBond(bond.getBuilder());
    else if (bond instanceof OrderQueryBond) {
        newBond = new AnyOrderQueryBond(bond.getBuilder());
        newBond.setOrder(bond.getOrder());
    } else if (bond instanceof AromaticQueryBond)
        newBond = new AromaticQueryBond(bond.getBuilder());
    else if (bond instanceof RingQueryBond)
        newBond = new RingQueryBond(bond.getBuilder());
    else if (bond instanceof SmartsBondExpression) {
        newBond = new SmartsBondExpression(bond.getBuilder());
        ((SmartsBondExpression) newBond).tokens = ((SmartsBondExpression) bond).tokens;
    } else {
        // by default single bond. Any way this should not be called
        newBond = new AnyOrderQueryBond(bond.getBuilder());
        newBond.setOrder(IBond.Order.SINGLE);
    }
    IAtom[] atoms = new IAtom[2];
    atoms[0] = atom0;
    atoms[1] = atom1;
    newBond.setAtoms(atoms);
    container.addBond(newBond);
}
Also used : AnyOrderQueryBond(org.openscience.cdk.isomorphism.matchers.smarts.AnyOrderQueryBond) IBond(org.openscience.cdk.interfaces.IBond) AromaticQueryBond(org.openscience.cdk.isomorphism.matchers.smarts.AromaticQueryBond) AnyOrderQueryBond(org.openscience.cdk.isomorphism.matchers.smarts.AnyOrderQueryBond) OrderQueryBond(org.openscience.cdk.isomorphism.matchers.smarts.OrderQueryBond) IAtom(org.openscience.cdk.interfaces.IAtom)

Example 2 with AromaticQueryBond

use of org.openscience.cdk.isomorphism.matchers.smarts.AromaticQueryBond in project ambit-mirror by ideaconsult.

the class SmartsToChemObject method toBond.

public IBond toBond(IBond b) {
    if (b instanceof SmartsBondExpression)
        return (smartsExpressionToBond((SmartsBondExpression) b));
    if (b instanceof SingleOrAromaticBond) {
        IBond bond = MoleculeTools.newBond(SilentChemObjectBuilder.getInstance());
        bond.setOrder(IBond.Order.SINGLE);
        mFlagConfirmAromaticBond = true;
        return (bond);
    }
    if (// This case returns a bond with
    b instanceof AromaticQueryBond) // order null!! Must be handled carefully!
    {
        IBond bond = MoleculeTools.newBond(SilentChemObjectBuilder.getInstance());
        bond.setOrder(b.getOrder());
        bond.setFlag(CDKConstants.ISAROMATIC, true);
        return (bond);
    }
    if (b instanceof OrderQueryBond) {
        IBond bond = MoleculeTools.newBond(SilentChemObjectBuilder.getInstance());
        bond.setOrder(b.getOrder());
        return (bond);
    }
    if (b instanceof SingleNonAromaticBond) {
        IBond bond = MoleculeTools.newBond(SilentChemObjectBuilder.getInstance());
        bond.setOrder(IBond.Order.SINGLE);
        return (bond);
    }
    if (b instanceof SingleBondAromaticityNotSpecified) {
        IBond bond = MoleculeTools.newBond(SilentChemObjectBuilder.getInstance());
        bond.setOrder(IBond.Order.SINGLE);
        return (bond);
    }
    if (b instanceof DoubleNonAromaticBond) {
        IBond bond = MoleculeTools.newBond(SilentChemObjectBuilder.getInstance());
        bond.setOrder(IBond.Order.DOUBLE);
        return (bond);
    }
    if (b instanceof DoubleBondAromaticityNotSpecified) {
        IBond bond = MoleculeTools.newBond(SilentChemObjectBuilder.getInstance());
        bond.setOrder(IBond.Order.DOUBLE);
        return (bond);
    }
    // RingQueryBond
    return (null);
}
Also used : IBond(org.openscience.cdk.interfaces.IBond) AromaticQueryBond(org.openscience.cdk.isomorphism.matchers.smarts.AromaticQueryBond) OrderQueryBond(org.openscience.cdk.isomorphism.matchers.smarts.OrderQueryBond)

Example 3 with AromaticQueryBond

use of org.openscience.cdk.isomorphism.matchers.smarts.AromaticQueryBond in project ambit-mirror by ideaconsult.

the class SmartsParser method addBond.

void addBond(IQueryAtom atom0, IQueryAtom atom1) {
    if (curBond == null) {
        switch(curBondType) {
            case SmartsConst.BT_ANY:
                curBond = new AnyOrderQueryBond(atom0.getBuilder());
                break;
            case SmartsConst.BT_SINGLE:
                if (mSupportSingleBondAromaticityNotSpecified)
                    curBond = new SingleBondAromaticityNotSpecified(atom0.getBuilder());
                else
                    curBond = new SingleNonAromaticBond(atom0.getBuilder());
                break;
            case SmartsConst.BT_DOUBLE:
                if (mSupportDoubleBondAromaticityNotSpecified)
                    curBond = new DoubleBondAromaticityNotSpecified(atom0.getBuilder());
                else
                    curBond = new DoubleNonAromaticBond(atom0.getBuilder());
                break;
            case SmartsConst.BT_TRIPLE:
                curBond = new OrderQueryBond(IBond.Order.TRIPLE, atom0.getBuilder());
                break;
            /*
			 * case SmartsConst.BT_DOUBLE: curBond = new DoubleStereoBond();
			 * break;
			 */
            case SmartsConst.BT_AROMATIC:
                curBond = new AromaticQueryBond(atom0.getBuilder());
                break;
            case SmartsConst.BT_RING:
                curBond = new RingQueryBond(atom0.getBuilder());
                break;
            case SmartsConst.BT_DOWN:
            case SmartsConst.BT_UP:
            case SmartsConst.BT_DOWNUNSPEC:
            case SmartsConst.BT_UPUNSPEC:
                // Directional bond is treated as a single bond.
                // Additionally this bond is stored in contaner directionaBonds
                // for further processing
                curBond = new OrderQueryBond(IBond.Order.SINGLE, atom0.getBuilder());
                directionalBonds.add(curBond);
                directions.add(new Integer(curBondType));
                break;
            case SmartsConst.BT_UNDEFINED:
                curBond = new SingleOrAromaticBond(atom0.getBuilder());
                break;
        }
    }
    IAtom[] atoms = new IAtom[2];
    atoms[0] = (IAtom) atom0;
    atoms[1] = (IAtom) atom1;
    curBond.setAtoms(atoms);
    container.addBond(curBond);
    curFragment.addBond(curBond);
// System.out.println("--> " +
// SmartsHelper.bondToStringExhaustive(container,curBond));
// System.out.println(SmartsHelper.getBondsString(container)+"\n");
}
Also used : AnyOrderQueryBond(org.openscience.cdk.isomorphism.matchers.smarts.AnyOrderQueryBond) AromaticQueryBond(org.openscience.cdk.isomorphism.matchers.smarts.AromaticQueryBond) AnyOrderQueryBond(org.openscience.cdk.isomorphism.matchers.smarts.AnyOrderQueryBond) OrderQueryBond(org.openscience.cdk.isomorphism.matchers.smarts.OrderQueryBond) IAtom(org.openscience.cdk.interfaces.IAtom)

Example 4 with AromaticQueryBond

use of org.openscience.cdk.isomorphism.matchers.smarts.AromaticQueryBond in project cdk by cdk.

the class SmartsQueryVisitor method handleRingClosure.

private void handleRingClosure(IQueryAtom atom, ASTRingIdentifier ringIdentifier) {
    RingIdentifierAtom ringIdAtom = (RingIdentifierAtom) ringIdentifier.jjtAccept(this, atom);
    // if there is already a RingIdentifierAtom, create a bond between
    // them and add the bond to the query
    int ringId = ringIdentifier.getRingId();
    // ring digit > 9 - expand capacity
    if (ringId >= ringAtoms.length)
        ringAtoms = Arrays.copyOf(ringAtoms, 100);
    // Ring Open
    if (ringAtoms[ringId] == null) {
        ringAtoms[ringId] = ringIdAtom;
        if (neighbors.containsKey(atom)) {
            neighbors.get(atom).add(ringIdAtom);
        }
    } else // Ring Close
    {
        IQueryBond ringBond;
        // first check if the two bonds ma
        if (ringAtoms[ringId].getRingBond() == null) {
            if (ringIdAtom.getRingBond() == null) {
                if (atom instanceof AromaticSymbolAtom && ringAtoms[ringId].getAtom() instanceof AromaticSymbolAtom) {
                    ringBond = new AromaticQueryBond(builder);
                } else {
                    ringBond = new RingBond(builder);
                }
            } else {
                ringBond = ringIdAtom.getRingBond();
            }
        } else {
            // Here I assume the bond are always same. This should be checked by the parser already
            ringBond = ringAtoms[ringId].getRingBond();
        }
        ringBond.setAtoms(new IAtom[] { ringAtoms[ringId].getAtom(), atom });
        query.addBond(ringBond);
        // placeholder reference
        if (neighbors.containsKey(ringAtoms[ringId].getAtom())) {
            List<IAtom> localNeighbors = neighbors.get(ringAtoms[ringId].getAtom());
            localNeighbors.set(localNeighbors.indexOf(ringAtoms[ringId]), atom);
        }
        if (neighbors.containsKey(atom)) {
            neighbors.get(atom).add(ringAtoms[ringId].getAtom());
        }
        ringAtoms[ringId] = null;
    }
}
Also used : AromaticSymbolAtom(org.openscience.cdk.isomorphism.matchers.smarts.AromaticSymbolAtom) AromaticQueryBond(org.openscience.cdk.isomorphism.matchers.smarts.AromaticQueryBond) IQueryBond(org.openscience.cdk.isomorphism.matchers.IQueryBond) RingIdentifierAtom(org.openscience.cdk.isomorphism.matchers.smarts.RingIdentifierAtom) RingBond(org.openscience.cdk.isomorphism.matchers.smarts.RingBond) IAtom(org.openscience.cdk.interfaces.IAtom)

Example 5 with AromaticQueryBond

use of org.openscience.cdk.isomorphism.matchers.smarts.AromaticQueryBond in project cdk by cdk.

the class SmartsQueryVisitor method visit.

public Object visit(ASTSimpleBond node, Object data) {
    SMARTSBond bond = null;
    switch(node.getBondType()) {
        case SMARTSParserConstants.S_BOND:
            bond = new OrderQueryBond(IBond.Order.SINGLE, builder);
            break;
        case SMARTSParserConstants.D_BOND:
            bond = new OrderQueryBond(IBond.Order.DOUBLE, builder);
            doubleBonds.add(bond);
            break;
        case SMARTSParserConstants.T_BOND:
            bond = new OrderQueryBond(IBond.Order.TRIPLE, builder);
            break;
        case SMARTSParserConstants.DOLLAR:
            bond = new OrderQueryBond(IBond.Order.QUADRUPLE, builder);
            break;
        case SMARTSParserConstants.ANY_BOND:
            bond = new AnyOrderQueryBond(builder);
            break;
        case SMARTSParserConstants.AR_BOND:
            bond = new AromaticQueryBond(builder);
            break;
        case SMARTSParserConstants.R_BOND:
            bond = new RingBond(builder);
            break;
        case SMARTSParserConstants.UP_S_BOND:
            bond = new StereoBond(builder, StereoBond.Direction.UP, false);
            stereoBonds.add(bond);
            break;
        case SMARTSParserConstants.DN_S_BOND:
            bond = new StereoBond(builder, StereoBond.Direction.DOWN, false);
            stereoBonds.add(bond);
            break;
        case SMARTSParserConstants.UP_OR_UNSPECIFIED_S_BOND:
            bond = new StereoBond(builder, StereoBond.Direction.UP, true);
            stereoBonds.add(bond);
            break;
        case SMARTSParserConstants.DN_OR_UNSPECIFIED_S_BOND:
            bond = new StereoBond(builder, StereoBond.Direction.DOWN, true);
            stereoBonds.add(bond);
            break;
        default:
            logger.error("Un parsed bond: " + node);
            break;
    }
    return bond;
}
Also used : AnyOrderQueryBond(org.openscience.cdk.isomorphism.matchers.smarts.AnyOrderQueryBond) SMARTSBond(org.openscience.cdk.isomorphism.matchers.smarts.SMARTSBond) AromaticQueryBond(org.openscience.cdk.isomorphism.matchers.smarts.AromaticQueryBond) OrderQueryBond(org.openscience.cdk.isomorphism.matchers.smarts.OrderQueryBond) AnyOrderQueryBond(org.openscience.cdk.isomorphism.matchers.smarts.AnyOrderQueryBond) RingBond(org.openscience.cdk.isomorphism.matchers.smarts.RingBond) StereoBond(org.openscience.cdk.isomorphism.matchers.smarts.StereoBond)

Aggregations

AromaticQueryBond (org.openscience.cdk.isomorphism.matchers.smarts.AromaticQueryBond)6 OrderQueryBond (org.openscience.cdk.isomorphism.matchers.smarts.OrderQueryBond)4 IAtom (org.openscience.cdk.interfaces.IAtom)3 IBond (org.openscience.cdk.interfaces.IBond)3 AnyOrderQueryBond (org.openscience.cdk.isomorphism.matchers.smarts.AnyOrderQueryBond)3 RingBond (org.openscience.cdk.isomorphism.matchers.smarts.RingBond)2 Test (org.junit.Test)1 IQueryBond (org.openscience.cdk.isomorphism.matchers.IQueryBond)1 QueryAtomContainer (org.openscience.cdk.isomorphism.matchers.QueryAtomContainer)1 AromaticSymbolAtom (org.openscience.cdk.isomorphism.matchers.smarts.AromaticSymbolAtom)1 RingIdentifierAtom (org.openscience.cdk.isomorphism.matchers.smarts.RingIdentifierAtom)1 SMARTSBond (org.openscience.cdk.isomorphism.matchers.smarts.SMARTSBond)1 StereoBond (org.openscience.cdk.isomorphism.matchers.smarts.StereoBond)1