Search in sources :

Example 1 with AnyOrderQueryBond

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

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

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

the class ParserTest method testAnyOrderBond.

@Test
public void testAnyOrderBond() 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 AnyOrderQueryBond);
}
Also used : AnyOrderQueryBond(org.openscience.cdk.isomorphism.matchers.smarts.AnyOrderQueryBond) IBond(org.openscience.cdk.interfaces.IBond) QueryAtomContainer(org.openscience.cdk.isomorphism.matchers.QueryAtomContainer) Test(org.junit.Test)

Example 4 with AnyOrderQueryBond

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

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

AnyOrderQueryBond (org.openscience.cdk.isomorphism.matchers.smarts.AnyOrderQueryBond)6 OrderQueryBond (org.openscience.cdk.isomorphism.matchers.smarts.OrderQueryBond)4 AromaticQueryBond (org.openscience.cdk.isomorphism.matchers.smarts.AromaticQueryBond)3 Test (org.junit.Test)2 IAtom (org.openscience.cdk.interfaces.IAtom)2 IBond (org.openscience.cdk.interfaces.IBond)2 QueryAtomContainer (org.openscience.cdk.isomorphism.matchers.QueryAtomContainer)2 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 CDKException (org.openscience.cdk.exception.CDKException)1 IAtomContainer (org.openscience.cdk.interfaces.IAtomContainer)1 IChemObjectBuilder (org.openscience.cdk.interfaces.IChemObjectBuilder)1 IQueryBond (org.openscience.cdk.isomorphism.matchers.IQueryBond)1 OrderQueryBond (org.openscience.cdk.isomorphism.matchers.OrderQueryBond)1 SymbolAndChargeQueryAtom (org.openscience.cdk.isomorphism.matchers.SymbolAndChargeQueryAtom)1 SymbolQueryAtom (org.openscience.cdk.isomorphism.matchers.SymbolQueryAtom)1 RingBond (org.openscience.cdk.isomorphism.matchers.smarts.RingBond)1