Search in sources :

Example 1 with AromaticSymbolAtom

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

the class SmartsQueryVisitor method visit.

public Object visit(ASTExplicitAtom node, Object data) {
    IQueryAtom atom;
    String symbol = node.getSymbol();
    if ("*".equals(symbol)) {
        atom = new AnyAtom(builder);
    } else if ("A".equals(symbol)) {
        atom = new AliphaticAtom(builder);
    } else if ("a".equals(symbol)) {
        atom = new AromaticAtom(builder);
    } else if ("o".equals(symbol) || "n".equals(symbol) || "c".equals(symbol) || "s".equals(symbol) || "p".equals(symbol) || "as".equals(symbol) || "se".equals(symbol)) {
        String atomSymbol = symbol.substring(0, 1).toUpperCase() + symbol.substring(1);
        atom = new AromaticSymbolAtom(atomSymbol, builder);
    } else if ("H".equals(symbol)) {
        atom = new HydrogenAtom(builder);
        atom.setSymbol(symbol.toUpperCase());
        atom.setMassNumber(1);
    } else if ("D".equals(symbol)) {
        atom = new HydrogenAtom(builder);
        atom.setSymbol(symbol.toUpperCase());
        atom.setMassNumber(2);
    } else if ("T".equals(symbol)) {
        atom = new HydrogenAtom(builder);
        atom.setSymbol(symbol.toUpperCase());
        atom.setMassNumber(3);
    } else {
        atom = new AliphaticSymbolAtom(symbol, builder);
    }
    return atom;
}
Also used : AliphaticAtom(org.openscience.cdk.isomorphism.matchers.smarts.AliphaticAtom) AromaticSymbolAtom(org.openscience.cdk.isomorphism.matchers.smarts.AromaticSymbolAtom) HydrogenAtom(org.openscience.cdk.isomorphism.matchers.smarts.HydrogenAtom) AliphaticSymbolAtom(org.openscience.cdk.isomorphism.matchers.smarts.AliphaticSymbolAtom) IQueryAtom(org.openscience.cdk.isomorphism.matchers.IQueryAtom) AromaticAtom(org.openscience.cdk.isomorphism.matchers.smarts.AromaticAtom) AnyAtom(org.openscience.cdk.isomorphism.matchers.smarts.AnyAtom)

Example 2 with AromaticSymbolAtom

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

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

the class SmartsQueryVisitor method visit.

public Object visit(ASTElement node, Object data) {
    String symbol = node.getSymbol();
    SMARTSAtom atom;
    if ("o".equals(symbol) || "n".equals(symbol) || "c".equals(symbol) || "s".equals(symbol) || "p".equals(symbol) || "as".equals(symbol) || "se".equals(symbol)) {
        String atomSymbol = symbol.substring(0, 1).toUpperCase() + symbol.substring(1);
        atom = new AromaticSymbolAtom(atomSymbol, builder);
    } else {
        atom = new AliphaticSymbolAtom(symbol, builder);
    }
    return atom;
}
Also used : AromaticSymbolAtom(org.openscience.cdk.isomorphism.matchers.smarts.AromaticSymbolAtom) SMARTSAtom(org.openscience.cdk.isomorphism.matchers.smarts.SMARTSAtom) AliphaticSymbolAtom(org.openscience.cdk.isomorphism.matchers.smarts.AliphaticSymbolAtom)

Aggregations

AromaticSymbolAtom (org.openscience.cdk.isomorphism.matchers.smarts.AromaticSymbolAtom)3 AliphaticSymbolAtom (org.openscience.cdk.isomorphism.matchers.smarts.AliphaticSymbolAtom)2 IAtom (org.openscience.cdk.interfaces.IAtom)1 IQueryAtom (org.openscience.cdk.isomorphism.matchers.IQueryAtom)1 IQueryBond (org.openscience.cdk.isomorphism.matchers.IQueryBond)1 AliphaticAtom (org.openscience.cdk.isomorphism.matchers.smarts.AliphaticAtom)1 AnyAtom (org.openscience.cdk.isomorphism.matchers.smarts.AnyAtom)1 AromaticAtom (org.openscience.cdk.isomorphism.matchers.smarts.AromaticAtom)1 AromaticQueryBond (org.openscience.cdk.isomorphism.matchers.smarts.AromaticQueryBond)1 HydrogenAtom (org.openscience.cdk.isomorphism.matchers.smarts.HydrogenAtom)1 RingBond (org.openscience.cdk.isomorphism.matchers.smarts.RingBond)1 RingIdentifierAtom (org.openscience.cdk.isomorphism.matchers.smarts.RingIdentifierAtom)1 SMARTSAtom (org.openscience.cdk.isomorphism.matchers.smarts.SMARTSAtom)1