Search in sources :

Example 1 with AnyAtom

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

the class SLN2ChemObject method slnAtomToQueryAtom.

public IQueryAtom slnAtomToQueryAtom(SLNAtom slnAt) {
    currentConversionError = null;
    currentConversionWarning = null;
    if (slnAt == null) {
        currentConversionError = "SNLAtom is null";
        return null;
    }
    if (slnAt.atomType == 0) {
        if (slnAt.atomExpression == null || slnAt.atomExpression.tokens.isEmpty()) {
            if (slnAt.numHAtom == 0)
                return new AnyAtom(SilentChemObjectBuilder.getInstance());
        }
        // Handle Any atom as an expression
        // slnAt.numHAtom > 0 info is added into the expression
        SmartsAtomExpression atExpr = slnAtomToSmartsAtomExpression(slnAt);
        return atExpr;
    }
    // slnAt.atomType > 0
    if (slnAt.atomType < SLNConst.GlobalDictOffseet) {
        if (slnAt.atomType < SLNConst.elSymbols.length) {
            if (slnAt.atomExpression == null || slnAt.atomExpression.tokens.isEmpty()) {
                if (slnAt.numHAtom == 0) {
                    AliphaticSymbolQueryAtom atom = new AliphaticSymbolQueryAtom(SilentChemObjectBuilder.getInstance());
                    String symb = SLNConst.elSymbols[slnAt.atomType];
                    atom.setSymbol(symb);
                    atom.setAtomicNumber(PeriodicTable.getAtomicNumber(symb));
                    return atom;
                } else {
                // Since there are H atoms they define an expression
                // slnAt.numHAtom > 0 info is added into the expression
                }
            }
            // Create an expression
            SmartsAtomExpression atExpr = slnAtomToSmartsAtomExpression(slnAt);
            return atExpr;
        } else {
            // TODO
            return null;
        }
    } else {
        // TODO
        return null;
    }
}
Also used : AliphaticSymbolQueryAtom(ambit2.smarts.AliphaticSymbolQueryAtom) AnyAtom(org.openscience.cdk.isomorphism.matchers.smarts.AnyAtom) SmartsAtomExpression(ambit2.smarts.SmartsAtomExpression)

Example 2 with AnyAtom

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

the class SLN2ChemObject method queryAtomToSLNAtom.

public SLNAtom queryAtomToSLNAtom(IQueryAtom queryAtom) {
    currentConversionError = null;
    currentConversionWarning = null;
    if (queryAtom == null) {
        currentConversionError = "Atom is null";
        return null;
    }
    if (queryAtom instanceof SmartsAtomExpression) {
    // TODO
    }
    boolean FlagKnownAtomType = false;
    SLNAtom slnAt = new SLNAtom(builder);
    if (queryAtom instanceof AnyAtom) {
        slnAt.atomType = 0;
        slnAt.atomName = "Any";
        FlagKnownAtomType = true;
    }
    if (FlagKnownAtomType)
        return slnAt;
    else
        return null;
/*
         * SLNAtom slnAt = new SLNAtom(builder);		
			String atomName = atom.getSymbol();
			for (int i = 0; i < SLNConst.elSymbols.length; i++)
			if (atomName.equals(SLNConst.elSymbols[i]))
			{	
				slnAt.atomType = i;
				break;
			}	
		    slnAt.atomName = atomName;         
         
		if (a instanceof AliphaticSymbolQueryAtom)
			return (a.getSymbol());

		if (a instanceof AromaticSymbolQueryAtom)
			return (a.getSymbol().toLowerCase());

		if (a instanceof AliphaticAtom)
			return ("A");

		if (a instanceof AromaticAtom)
			return ("a");		
         */
}
Also used : SLNAtom(ambit2.sln.SLNAtom) SmartsAtomExpression(ambit2.smarts.SmartsAtomExpression) AnyAtom(org.openscience.cdk.isomorphism.matchers.smarts.AnyAtom)

Example 3 with AnyAtom

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

the class SmartsParser method parseSpecialSymbol.

void parseSpecialSymbol() {
    switch(smarts.charAt(curChar)) {
        case // Any atom
        '*':
            IQueryAtom curAtom = new AnyAtom(SilentChemObjectBuilder.getInstance());
            curChar++;
            addAtom(curAtom);
            break;
        // Bond expression symbols - bond types and logical operations
        case '-':
        case '=':
        case '#':
        case '~':
        case '/':
        case '\\':
        case ':':
        case '@':
        case '!':
        case '&':
        case ',':
        case ';':
            parseBondExpression();
            break;
        case // Atom index which > 9 (has two digits)
        '%':
            parseAtomIndex();
            break;
        case '(':
            if (prevAtom == null) {
                if (FlagCLG) {
                    if (curComponent > 0) {
                        newError("Incorrect nested componet brackets", curChar + 1, "");
                    } else {
                        brackets.push(prevAtom);
                        maxCompNumber++;
                        curComponent = maxCompNumber;
                    }
                } else
                    newError("Component Level Grouping is off: incorrect openning brackect", curChar + 1, "");
            } else
                brackets.push(prevAtom);
            curChar++;
            break;
        case ')':
            if (brackets.empty()) {
                // System.out.println("curChar = " + curChar);
                newError("Incorrect closing brackect", curChar + 1, "");
                return;
            }
            ;
            // Not empty brackets stack guarantees that curChar > 0
            if (smarts.charAt(curChar - 1) == '(') {
                newError("Empty branch/substituent ", curChar + 1, "");
                // This prevents generation of another error
                brackets.pop();
                // "There are unclosed brackets"
                return;
            }
            ;
            prevAtom = brackets.pop();
            if (prevAtom == null)
                curComponent = 0;
            curChar++;
            break;
        case '[':
            parseAtomExpression();
            break;
        case ']':
            newError("Incorrect closing bracket ']' ", curChar + 1, "");
            break;
        case '.':
            if (FlagCLG) {
                curChar++;
                prevAtom = null;
                curBond = null;
                curBondType = SmartsConst.BT_UNDEFINED;
            } else
                newError("Zero bond order (disclosure) is not allowed. Component Level Grouping is off.", curChar + 1, "");
            break;
        default:
            newError("Incorrect symbol", curChar + 1, "");
            break;
    }
}
Also used : IQueryAtom(org.openscience.cdk.isomorphism.matchers.IQueryAtom) AnyAtom(org.openscience.cdk.isomorphism.matchers.smarts.AnyAtom)

Example 4 with AnyAtom

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

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

the class SMARTSTest method testSMARTS.

@Test
public void testSMARTS() throws Exception {
    IChemObjectBuilder builder = DefaultChemObjectBuilder.getInstance();
    SmilesParser sp = new SmilesParser(builder);
    // acetic acid anhydride
    IAtomContainer atomContainer = sp.parseSmiles("CC(=O)OC(=O)C");
    QueryAtomContainer query = new QueryAtomContainer(builder);
    AnyAtom atom1 = new AnyAtom(builder);
    SymbolQueryAtom atom2 = new SymbolQueryAtom(builder);
    atom2.setSymbol("C");
    query.addAtom(atom1);
    query.addAtom(atom2);
    query.addBond(new OrderQueryBond(atom1, atom2, IBond.Order.DOUBLE, builder));
    Assert.assertTrue(uiTester.isSubgraph(atomContainer, query));
}
Also used : SmilesParser(org.openscience.cdk.smiles.SmilesParser) IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) AnyOrderQueryBond(org.openscience.cdk.isomorphism.matchers.smarts.AnyOrderQueryBond) OrderQueryBond(org.openscience.cdk.isomorphism.matchers.OrderQueryBond) IChemObjectBuilder(org.openscience.cdk.interfaces.IChemObjectBuilder) QueryAtomContainer(org.openscience.cdk.isomorphism.matchers.QueryAtomContainer) AnyAtom(org.openscience.cdk.isomorphism.matchers.smarts.AnyAtom) SymbolQueryAtom(org.openscience.cdk.isomorphism.matchers.SymbolQueryAtom) Test(org.junit.Test)

Aggregations

AnyAtom (org.openscience.cdk.isomorphism.matchers.smarts.AnyAtom)7 IQueryAtom (org.openscience.cdk.isomorphism.matchers.IQueryAtom)4 Test (org.junit.Test)3 IAtomContainer (org.openscience.cdk.interfaces.IAtomContainer)3 QueryAtomContainer (org.openscience.cdk.isomorphism.matchers.QueryAtomContainer)3 SmartsAtomExpression (ambit2.smarts.SmartsAtomExpression)2 IAtom (org.openscience.cdk.interfaces.IAtom)2 IBond (org.openscience.cdk.interfaces.IBond)2 IChemObjectBuilder (org.openscience.cdk.interfaces.IChemObjectBuilder)2 IQueryAtomContainer (org.openscience.cdk.isomorphism.matchers.IQueryAtomContainer)2 OrderQueryBond (org.openscience.cdk.isomorphism.matchers.OrderQueryBond)2 SymbolQueryAtom (org.openscience.cdk.isomorphism.matchers.SymbolQueryAtom)2 AliphaticSymbolAtom (org.openscience.cdk.isomorphism.matchers.smarts.AliphaticSymbolAtom)2 SLNAtom (ambit2.sln.SLNAtom)1 AliphaticSymbolQueryAtom (ambit2.smarts.AliphaticSymbolQueryAtom)1 List (java.util.List)1 Atom (org.openscience.cdk.Atom)1 AtomContainer (org.openscience.cdk.AtomContainer)1 Bond (org.openscience.cdk.Bond)1 AliphaticAtom (org.openscience.cdk.isomorphism.matchers.smarts.AliphaticAtom)1