Search in sources :

Example 1 with OrderQueryBond

use of org.openscience.cdk.isomorphism.matchers.smarts.OrderQueryBond 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 OrderQueryBond

use of org.openscience.cdk.isomorphism.matchers.smarts.OrderQueryBond 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 3 with OrderQueryBond

use of org.openscience.cdk.isomorphism.matchers.smarts.OrderQueryBond 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 4 with OrderQueryBond

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

the class ParserTest method testDoubleBond.

@Test
public void testDoubleBond() throws Exception {
    QueryAtomContainer container = SMARTSParser.parse("C=C", DefaultChemObjectBuilder.getInstance());
    Assert.assertEquals(2, container.getAtomCount());
    Assert.assertEquals(1, container.getBondCount());
    org.openscience.cdk.interfaces.IBond bond = container.getBond(0);
    Assert.assertTrue(bond instanceof OrderQueryBond);
    OrderQueryBond qBond = (OrderQueryBond) bond;
    Assert.assertEquals(IBond.Order.DOUBLE, qBond.getOrder());
}
Also used : AnyOrderQueryBond(org.openscience.cdk.isomorphism.matchers.smarts.AnyOrderQueryBond) OrderQueryBond(org.openscience.cdk.isomorphism.matchers.smarts.OrderQueryBond) IBond(org.openscience.cdk.interfaces.IBond) QueryAtomContainer(org.openscience.cdk.isomorphism.matchers.QueryAtomContainer) Test(org.junit.Test)

Example 5 with OrderQueryBond

use of org.openscience.cdk.isomorphism.matchers.smarts.OrderQueryBond 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)

Aggregations

OrderQueryBond (org.openscience.cdk.isomorphism.matchers.smarts.OrderQueryBond)10 IBond (org.openscience.cdk.interfaces.IBond)7 AnyOrderQueryBond (org.openscience.cdk.isomorphism.matchers.smarts.AnyOrderQueryBond)7 Test (org.junit.Test)4 QueryAtomContainer (org.openscience.cdk.isomorphism.matchers.QueryAtomContainer)4 AromaticQueryBond (org.openscience.cdk.isomorphism.matchers.smarts.AromaticQueryBond)4 IAtom (org.openscience.cdk.interfaces.IAtom)3 DoubleBondAromaticityNotSpecified (ambit2.smarts.DoubleBondAromaticityNotSpecified)2 DoubleNonAromaticBond (ambit2.smarts.DoubleNonAromaticBond)2 SingleBondAromaticityNotSpecified (ambit2.smarts.SingleBondAromaticityNotSpecified)1 SingleNonAromaticBond (ambit2.smarts.SingleNonAromaticBond)1 SingleOrAromaticBond (ambit2.smarts.SingleOrAromaticBond)1 SmartsBondExpression (ambit2.smarts.SmartsBondExpression)1 SmartsToChemObject (ambit2.smarts.SmartsToChemObject)1 ArrayList (java.util.ArrayList)1 Atom (org.openscience.cdk.Atom)1 AtomContainer (org.openscience.cdk.AtomContainer)1 Bond (org.openscience.cdk.Bond)1 IAtomContainer (org.openscience.cdk.interfaces.IAtomContainer)1 IQueryAtom (org.openscience.cdk.isomorphism.matchers.IQueryAtom)1