expr.and(new Expr(ISOTOPE, atom.getMassNumber())); if (atom.isAromatic()) { if (optset.contains(AROMATIC_ELEMENT)) { expr.and(new Expr(AROMATIC_ELEMENT, atom.getAtomicNumber())); } else { if (optset.contains(IS_AROMATIC)) { if (optset.contains(ELEMENT)) expr.and(new Expr(AROMATIC_ELEMENT, atom.getAtomicNumber())); else expr.and(new Expr(Expr.Type.IS_AROMATIC)); } else if (optset.contains(ELEMENT)) { expr.and(new Expr(ELEMENT, atom.getAtomicNumber())); expr.and(new Expr(ALIPHATIC_ELEMENT, atom.getAtomicNumber())); } else { if (optset.contains(IS_ALIPHATIC)) { if (optset.contains(ELEMENT)) expr.and(new Expr(ALIPHATIC_ELEMENT, atom.getAtomicNumber())); else expr.and(new Expr(Expr.Type.IS_ALIPHATIC)); } else if (optset.contains(ELEMENT)) { expr.and(new Expr(ELEMENT, atom.getAtomicNumber()));
/** * Make a query atom that matches atomic number, h count, valence, and * connectivity. This effectively provides an exact match for that atom * type. * * @param mol molecule * @param atom atom of molecule * @return the query atom (null if attachment point) */ private IQueryAtom matchExact(final IAtomContainer mol, final IAtom atom) { final IChemObjectBuilder bldr = atom.getBuilder(); int elem = atom.getAtomicNumber(); // attach atom skipped if (elem == 0) return null; int hcnt = atom.getImplicitHydrogenCount(); int val = hcnt; int con = hcnt; for (IBond bond : mol.getConnectedBondsList(atom)) { val += bond.getOrder().numeric(); con++; if (bond.getOther(atom).getAtomicNumber() == 1) hcnt++; } Expr expr = new Expr(Expr.Type.ELEMENT, elem) .and(new Expr(Expr.Type.TOTAL_DEGREE, con)) .and(new Expr(Expr.Type.TOTAL_H_COUNT, hcnt)) .and(new Expr(Expr.Type.VALENCE, val)); return new QueryAtom(expr); }
/** * Make a query atom that matches atomic number, h count, valence, and * connectivity. This effectively provides an exact match for that atom * type. * * @param mol molecule * @param atom atom of molecule * @return the query atom (null if attachment point) */ private IQueryAtom matchExact(final IAtomContainer mol, final IAtom atom) { final IChemObjectBuilder bldr = atom.getBuilder(); int elem = atom.getAtomicNumber(); // attach atom skipped if (elem == 0) return null; int hcnt = atom.getImplicitHydrogenCount(); int val = hcnt; int con = hcnt; for (IBond bond : mol.getConnectedBondsList(atom)) { val += bond.getOrder().numeric(); con++; if (bond.getOther(atom).getAtomicNumber() == 1) hcnt++; } Expr expr = new Expr(Expr.Type.ELEMENT, elem) .and(new Expr(Expr.Type.TOTAL_DEGREE, con)) .and(new Expr(Expr.Type.TOTAL_H_COUNT, hcnt)) .and(new Expr(Expr.Type.VALENCE, val)); return new QueryAtom(expr); }
@Test public void singleOrDoubleInRing2() { Expr expr = new Expr(IS_IN_RING) .and(new Expr(SINGLE_OR_DOUBLE)); assertThat(Smarts.generateBond(expr), is("@;-,=")); }
@Test public void useExplAnd2() { Expr expr = new Expr(DEGREE, 1).and( new Expr(ISOTOPE, 2) ); assertThat(Smarts.generateAtom(expr), is("[D&2]")); }
@Test public void alwaysFalseAnd() { assertThat(new Expr(FALSE).and(new Expr(TRUE)), is(new Expr(FALSE))); }
@Test public void useExplAnd1() { Expr expr = new Expr(ALIPHATIC_ELEMENT, 6).and( new Expr(RING_SMALLEST, 6) ); assertThat(Smarts.generateAtom(expr), is("[C&r6]")); }
@Test public void alwaysTrueAnd() { assertThat(new Expr(TRUE).and(new Expr(TRUE)), is(new Expr(TRUE))); }
/** * Utility, combine this expression with another, using conjunction. * The expression will only match if both conditions are met. * * @param expr the other expression * @return self for chaining */ public Expr and(Expr expr) { if (type == Type.TRUE) { set(expr); } else if (expr.type != Type.TRUE) { if (type.isLogical() && !expr.type.isLogical()) { if (type == AND) right.and(expr); else setLogical(Type.AND, expr, new Expr(this)); } else { setLogical(Type.AND, new Expr(this), expr); } } return this; }
for (IAtom atom : mol.atoms()) { ReactionRole role = atom.getProperty(CDKConstants.REACTION_ROLE); ((QueryAtom) atom).getExpression().and( new Expr(Expr.Type.REACTION_ROLE, role.ordinal()) Expr bexpr = determineBondStereo(leftExpr, rightExpr); if (bexpr != null) { expr.and(bexpr); expr = new Expr(SINGLE_OR_AROMATIC); else expr.and(new Expr(SINGLE_OR_AROMATIC)); ((QueryBond) bond).setExpression(expr);
@Test public void testLeftBalancedAnd2() { Expr expr1 = new Expr(ELEMENT, 9); Expr expr2 = new Expr(DEGREE, 2).and(new Expr(HAS_IMPLICIT_HYDROGEN)); expr2.and(expr1); assertThat(expr2.left().type(), is(DEGREE)); assertThat(expr2.right().type(), is(AND)); assertThat(expr2.right().left().type(), is(HAS_IMPLICIT_HYDROGEN)); assertThat(expr2.right().right().type(), is(ELEMENT)); }
@Test public void useLowPrecedenceAnd() { Expr expr = new Expr(ELEMENT, 8).and( new Expr(DEGREE, 2).or( new Expr(DEGREE, 1))); assertThat(Smarts.generateAtom(expr), is("[#8;D2,D]")); }
@Test public void singleOrDoubleInRing() { Expr expr = new Expr(IS_IN_RING) .and(new Expr(ALIPHATIC_ORDER, 1) .or(new Expr(ALIPHATIC_ORDER, 2))); assertThat(Smarts.generateBond(expr), is("@;-,=")); }
@Test public void testToString() { assertThat(new Expr(TRUE).toString(), is("TRUE")); assertThat(new Expr(ELEMENT, 8).toString(), is("ELEMENT=8")); assertThat(new Expr(ELEMENT, 8).or(new Expr(DEGREE, 3)).toString(), is("OR(ELEMENT=8,DEGREE=3)")); assertThat(new Expr(ELEMENT, 8).and(new Expr(DEGREE, 3)).toString(), is("AND(ELEMENT=8,DEGREE=3)")); assertThat(new Expr(ELEMENT, 8).negate().toString(), is("NOT(ELEMENT=8)")); assertThat(new Expr(RECURSIVE, null).toString(), is("RECURSIVE(...)")); }
switch (currOp) { case '&': dest.and(expr); break; case ',':
switch (currOp) { case '&': dest.and(expr); break; case ',':