use of org.openscience.cdk.isomorphism.matchers.smarts.RingIdentifierAtom in project cdk by cdk.
the class SmartsQueryVisitor method visit.
public Object visit(ASTRingIdentifier node, Object data) {
IQueryAtom atom = (IQueryAtom) data;
RingIdentifierAtom ringIdAtom = new RingIdentifierAtom(builder);
ringIdAtom.setAtom(atom);
IQueryBond bond;
if (node.jjtGetNumChildren() == 0) {
// implicit bond
bond = null;
} else {
bond = (IQueryBond) node.jjtGetChild(0).jjtAccept(this, data);
}
ringIdAtom.setRingBond(bond);
return ringIdAtom;
}
use of org.openscience.cdk.isomorphism.matchers.smarts.RingIdentifierAtom 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;
}
}
Aggregations