use of org.openscience.cdk.isomorphism.matchers.smarts.AromaticOrSingleQueryBond in project cdk by cdk.
the class SmartsQueryVisitor method visit.
public Object visit(ASTSmarts node, Object data) {
SMARTSAtom atom;
SMARTSBond bond = null;
ASTAtom first = (ASTAtom) node.jjtGetChild(0);
atom = (SMARTSAtom) first.jjtAccept(this, null);
if (data != null) {
// this is a sub smarts
bond = (SMARTSBond) ((Object[]) data)[1];
IAtom prev = (SMARTSAtom) ((Object[]) data)[0];
if (bond == null) {
// since no bond was specified it could be aromatic or single
bond = new AromaticOrSingleQueryBond(builder);
bond.setAtoms(new IAtom[] { prev, atom });
} else {
bond.setAtoms(new IAtom[] { prev, atom });
}
if (neighbors.containsKey(prev)) {
neighbors.get(prev).add(atom);
}
query.addBond(bond);
bond = null;
}
// first ATOM in expresion
query.addAtom(atom);
if (tetrahedral.get(query.getAtomCount() - 1)) {
List<IAtom> localNeighbors = new ArrayList<>(query.getConnectedAtomsList(atom));
localNeighbors.add(atom);
neighbors.put(atom, localNeighbors);
}
// now process the rest of the bonds/atoms
for (int i = 1; i < node.jjtGetNumChildren(); i++) {
Node child = node.jjtGetChild(i);
if (child instanceof ASTLowAndBond) {
bond = (SMARTSBond) child.jjtAccept(this, data);
} else if (child instanceof ASTAtom) {
SMARTSAtom newAtom = (SMARTSAtom) child.jjtAccept(this, null);
if (bond == null) {
// since no bond was specified it could be aromatic or single
bond = new AromaticOrSingleQueryBond(builder);
}
bond.setAtoms(new IAtom[] { atom, newAtom });
query.addBond(bond);
query.addAtom(newAtom);
if (neighbors.containsKey(atom)) {
neighbors.get(atom).add(newAtom);
}
if (tetrahedral.get(query.getAtomCount() - 1)) {
List<IAtom> localNeighbors = new ArrayList<>(query.getConnectedAtomsList(newAtom));
localNeighbors.add(newAtom);
neighbors.put(newAtom, localNeighbors);
}
atom = newAtom;
bond = null;
} else if (child instanceof ASTSmarts) {
// another smarts
child.jjtAccept(this, new Object[] { atom, bond });
bond = null;
} else if (child instanceof ASTRingIdentifier) {
handleRingClosure(atom, (ASTRingIdentifier) child);
} else {
throw new IllegalStateException("Unhandled node type: " + child.getClass());
}
}
return query;
}
Aggregations