Search in sources :

Example 1 with AromaticAtom

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

use of org.openscience.cdk.isomorphism.matchers.smarts.AromaticAtom in project ambit-mirror by ideaconsult.

the class SmartsParser method parseAtom.

void parseAtom() {
    // Parsing the atom symbols allowed to be used without brackets []
    IQueryAtom curAtom = null;
    String symb = null;
    switch(smarts.charAt(curChar)) {
        // Aromatic atoms
        case 'a':
            curAtom = new AromaticAtom(SilentChemObjectBuilder.getInstance());
            curChar++;
            break;
        case 'c':
        case 'o':
        case 'n':
        case 's':
        case 'p':
            char ch = Character.toUpperCase(smarts.charAt(curChar));
            curAtom = new AromaticSymbolQueryAtom(SilentChemObjectBuilder.getInstance());
            String atom = Character.toString(ch);
            curAtom.setSymbol(atom);
            curAtom.setAtomicNumber(PeriodicTable.getAtomicNumber(atom));
            curChar++;
            break;
        case 'C':
            symb = "C";
            curChar++;
            if (curChar < nChars) {
                if (smarts.charAt(curChar) == 'l') {
                    symb = "Cl";
                    curChar++;
                }
            }
            curAtom = new AliphaticSymbolQueryAtom(SilentChemObjectBuilder.getInstance());
            curAtom.setSymbol(symb);
            curAtom.setAtomicNumber(PeriodicTable.getAtomicNumber(symb));
            break;
        case 'B':
            symb = "B";
            curChar++;
            if (curChar < nChars) {
                if (smarts.charAt(curChar) == 'r') {
                    symb = "Br";
                    curChar++;
                }
            }
            curAtom = new AliphaticSymbolQueryAtom(SilentChemObjectBuilder.getInstance());
            curAtom.setSymbol(symb);
            break;
        case 'A':
            curAtom = new AliphaticAtom(SilentChemObjectBuilder.getInstance());
            curChar++;
            break;
        case 'O':
        case 'N':
        case 'S':
        case 'P':
        case 'F':
        case 'I':
            curAtom = new AliphaticSymbolQueryAtom(SilentChemObjectBuilder.getInstance());
            curAtom.setSymbol(Character.toString(smarts.charAt(curChar)));
            curChar++;
            break;
    }
    if (curAtom == null)
        newError("Incorrect atomic symbol", curChar + 1, "");
    else
        addAtom(curAtom);
}
Also used : AliphaticAtom(org.openscience.cdk.isomorphism.matchers.smarts.AliphaticAtom) IQueryAtom(org.openscience.cdk.isomorphism.matchers.IQueryAtom) AromaticAtom(org.openscience.cdk.isomorphism.matchers.smarts.AromaticAtom)

Aggregations

IQueryAtom (org.openscience.cdk.isomorphism.matchers.IQueryAtom)2 AliphaticAtom (org.openscience.cdk.isomorphism.matchers.smarts.AliphaticAtom)2 AromaticAtom (org.openscience.cdk.isomorphism.matchers.smarts.AromaticAtom)2 AliphaticSymbolAtom (org.openscience.cdk.isomorphism.matchers.smarts.AliphaticSymbolAtom)1 AnyAtom (org.openscience.cdk.isomorphism.matchers.smarts.AnyAtom)1 AromaticSymbolAtom (org.openscience.cdk.isomorphism.matchers.smarts.AromaticSymbolAtom)1 HydrogenAtom (org.openscience.cdk.isomorphism.matchers.smarts.HydrogenAtom)1