use of org.openscience.cdk.isomorphism.matchers.smarts.StereoBond in project cdk by cdk.
the class SmartsQueryVisitor method visit.
public Object visit(ASTGroup node, Object data) {
IAtomContainer fullQuery = (IAtomContainer) data;
if (fullQuery == null)
fullQuery = new QueryAtomContainer(builder);
// keeps track of component grouping
int[] components = fullQuery.getProperty("COMPONENT.GROUPING") != null ? fullQuery.getProperty("COMPONENT.GROUPING", int[].class) : new int[0];
int maxId = 0;
if (components.length > 0) {
for (int id : components) if (id > maxId)
maxId = id;
}
for (int i = 0; i < node.jjtGetNumChildren(); i++) {
ASTSmarts smarts = (ASTSmarts) node.jjtGetChild(i);
ringAtoms = new RingIdentifierAtom[10];
query = new QueryAtomContainer(builder);
smarts.jjtAccept(this, null);
// update component info
if (components.length > 0 || smarts.componentId() > 0) {
components = Arrays.copyOf(components, 1 + fullQuery.getAtomCount() + query.getAtomCount());
int id = smarts.componentId();
Arrays.fill(components, fullQuery.getAtomCount(), components.length, id);
if (id > maxId)
maxId = id;
}
fullQuery.add(query);
}
// only store if there was a component grouping
if (maxId > 0) {
// we left space to store how many groups there were
components[components.length - 1] = maxId;
fullQuery.setProperty("COMPONENT.GROUPING", components);
}
// create tetrahedral elements
for (IAtom atom : neighbors.keySet()) {
List<IAtom> localNeighbors = neighbors.get(atom);
if (localNeighbors.size() == 4) {
fullQuery.addStereoElement(new TetrahedralChirality(atom, localNeighbors.toArray(new IAtom[4]), // <- to be modified later
ITetrahedralChirality.Stereo.CLOCKWISE));
} else if (localNeighbors.size() == 5) {
// remove central atom (which represented implicit part)
localNeighbors.remove(atom);
fullQuery.addStereoElement(new TetrahedralChirality(atom, localNeighbors.toArray(new IAtom[4]), // <- to be modified later
ITetrahedralChirality.Stereo.CLOCKWISE));
}
}
// handle logical bonds i.e. C/C-,=C/C
for (IBond bond : doubleBonds) {
IAtom left = bond.getBegin();
IAtom right = bond.getEnd();
StereoBond leftBond = findStereoBond(left);
StereoBond rightBond = findStereoBond(right);
if (leftBond == null || rightBond == null)
continue;
Conformation conformation = leftBond.direction(left) == rightBond.direction(right) ? Conformation.TOGETHER : Conformation.OPPOSITE;
fullQuery.addStereoElement(new DoubleBondStereochemistry(bond, new IBond[] { leftBond, rightBond }, conformation));
}
return fullQuery;
}
use of org.openscience.cdk.isomorphism.matchers.smarts.StereoBond in project cdk by cdk.
the class SmartsQueryVisitor method visit.
public Object visit(ASTSimpleBond node, Object data) {
SMARTSBond bond = null;
switch(node.getBondType()) {
case SMARTSParserConstants.S_BOND:
bond = new OrderQueryBond(IBond.Order.SINGLE, builder);
break;
case SMARTSParserConstants.D_BOND:
bond = new OrderQueryBond(IBond.Order.DOUBLE, builder);
doubleBonds.add(bond);
break;
case SMARTSParserConstants.T_BOND:
bond = new OrderQueryBond(IBond.Order.TRIPLE, builder);
break;
case SMARTSParserConstants.DOLLAR:
bond = new OrderQueryBond(IBond.Order.QUADRUPLE, builder);
break;
case SMARTSParserConstants.ANY_BOND:
bond = new AnyOrderQueryBond(builder);
break;
case SMARTSParserConstants.AR_BOND:
bond = new AromaticQueryBond(builder);
break;
case SMARTSParserConstants.R_BOND:
bond = new RingBond(builder);
break;
case SMARTSParserConstants.UP_S_BOND:
bond = new StereoBond(builder, StereoBond.Direction.UP, false);
stereoBonds.add(bond);
break;
case SMARTSParserConstants.DN_S_BOND:
bond = new StereoBond(builder, StereoBond.Direction.DOWN, false);
stereoBonds.add(bond);
break;
case SMARTSParserConstants.UP_OR_UNSPECIFIED_S_BOND:
bond = new StereoBond(builder, StereoBond.Direction.UP, true);
stereoBonds.add(bond);
break;
case SMARTSParserConstants.DN_OR_UNSPECIFIED_S_BOND:
bond = new StereoBond(builder, StereoBond.Direction.DOWN, true);
stereoBonds.add(bond);
break;
default:
logger.error("Un parsed bond: " + node);
break;
}
return bond;
}
Aggregations