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;
}
}
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");
*/
}
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;
}
}
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;
}
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));
}
Aggregations