Search in sources :

Example 1 with RingBond

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

use of org.openscience.cdk.isomorphism.matchers.smarts.RingBond 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)2 RingBond (org.openscience.cdk.isomorphism.matchers.smarts.RingBond)2 IAtom (org.openscience.cdk.interfaces.IAtom)1 IQueryBond (org.openscience.cdk.isomorphism.matchers.IQueryBond)1 AnyOrderQueryBond (org.openscience.cdk.isomorphism.matchers.smarts.AnyOrderQueryBond)1 AromaticSymbolAtom (org.openscience.cdk.isomorphism.matchers.smarts.AromaticSymbolAtom)1 OrderQueryBond (org.openscience.cdk.isomorphism.matchers.smarts.OrderQueryBond)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