Search in sources :

Example 1 with StereoBond

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

the class SmartsQueryVisitor method visit.

public Object visit(ASTGroup node, Object data) {
    IAtomContainer fullQuery = (IAtomContainer) data;
    if (fullQuery == null)
        fullQuery = new QueryAtomContainer(builder);
    // keeps track of component grouping
    int[] components = fullQuery.getProperty("COMPONENT.GROUPING") != null ? fullQuery.getProperty("COMPONENT.GROUPING", int[].class) : new int[0];
    int maxId = 0;
    if (components.length > 0) {
        for (int id : components) if (id > maxId)
            maxId = id;
    }
    for (int i = 0; i < node.jjtGetNumChildren(); i++) {
        ASTSmarts smarts = (ASTSmarts) node.jjtGetChild(i);
        ringAtoms = new RingIdentifierAtom[10];
        query = new QueryAtomContainer(builder);
        smarts.jjtAccept(this, null);
        // update component info
        if (components.length > 0 || smarts.componentId() > 0) {
            components = Arrays.copyOf(components, 1 + fullQuery.getAtomCount() + query.getAtomCount());
            int id = smarts.componentId();
            Arrays.fill(components, fullQuery.getAtomCount(), components.length, id);
            if (id > maxId)
                maxId = id;
        }
        fullQuery.add(query);
    }
    // only store if there was a component grouping
    if (maxId > 0) {
        // we left space to store how many groups there were
        components[components.length - 1] = maxId;
        fullQuery.setProperty("COMPONENT.GROUPING", components);
    }
    // create tetrahedral elements
    for (IAtom atom : neighbors.keySet()) {
        List<IAtom> localNeighbors = neighbors.get(atom);
        if (localNeighbors.size() == 4) {
            fullQuery.addStereoElement(new TetrahedralChirality(atom, localNeighbors.toArray(new IAtom[4]), // <- to be modified later
            ITetrahedralChirality.Stereo.CLOCKWISE));
        } else if (localNeighbors.size() == 5) {
            // remove central atom (which represented implicit part)
            localNeighbors.remove(atom);
            fullQuery.addStereoElement(new TetrahedralChirality(atom, localNeighbors.toArray(new IAtom[4]), // <- to be modified later
            ITetrahedralChirality.Stereo.CLOCKWISE));
        }
    }
    // handle logical bonds i.e. C/C-,=C/C
    for (IBond bond : doubleBonds) {
        IAtom left = bond.getBegin();
        IAtom right = bond.getEnd();
        StereoBond leftBond = findStereoBond(left);
        StereoBond rightBond = findStereoBond(right);
        if (leftBond == null || rightBond == null)
            continue;
        Conformation conformation = leftBond.direction(left) == rightBond.direction(right) ? Conformation.TOGETHER : Conformation.OPPOSITE;
        fullQuery.addStereoElement(new DoubleBondStereochemistry(bond, new IBond[] { leftBond, rightBond }, conformation));
    }
    return fullQuery;
}
Also used : ITetrahedralChirality(org.openscience.cdk.interfaces.ITetrahedralChirality) TetrahedralChirality(org.openscience.cdk.stereo.TetrahedralChirality) IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) DoubleBondStereochemistry(org.openscience.cdk.stereo.DoubleBondStereochemistry) IBond(org.openscience.cdk.interfaces.IBond) QueryAtomContainer(org.openscience.cdk.isomorphism.matchers.QueryAtomContainer) IQueryAtomContainer(org.openscience.cdk.isomorphism.matchers.IQueryAtomContainer) IAtom(org.openscience.cdk.interfaces.IAtom) StereoBond(org.openscience.cdk.isomorphism.matchers.smarts.StereoBond) Conformation(org.openscience.cdk.interfaces.IDoubleBondStereochemistry.Conformation)

Example 2 with StereoBond

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

StereoBond (org.openscience.cdk.isomorphism.matchers.smarts.StereoBond)2 IAtom (org.openscience.cdk.interfaces.IAtom)1 IAtomContainer (org.openscience.cdk.interfaces.IAtomContainer)1 IBond (org.openscience.cdk.interfaces.IBond)1 Conformation (org.openscience.cdk.interfaces.IDoubleBondStereochemistry.Conformation)1 ITetrahedralChirality (org.openscience.cdk.interfaces.ITetrahedralChirality)1 IQueryAtomContainer (org.openscience.cdk.isomorphism.matchers.IQueryAtomContainer)1 QueryAtomContainer (org.openscience.cdk.isomorphism.matchers.QueryAtomContainer)1 AnyOrderQueryBond (org.openscience.cdk.isomorphism.matchers.smarts.AnyOrderQueryBond)1 AromaticQueryBond (org.openscience.cdk.isomorphism.matchers.smarts.AromaticQueryBond)1 OrderQueryBond (org.openscience.cdk.isomorphism.matchers.smarts.OrderQueryBond)1 RingBond (org.openscience.cdk.isomorphism.matchers.smarts.RingBond)1 SMARTSBond (org.openscience.cdk.isomorphism.matchers.smarts.SMARTSBond)1 DoubleBondStereochemistry (org.openscience.cdk.stereo.DoubleBondStereochemistry)1 TetrahedralChirality (org.openscience.cdk.stereo.TetrahedralChirality)1