Skip to content

Commit

Permalink
Allow SMARTS expressions of the form [h0] and [!h0] analogous to [H0]…
Browse files Browse the repository at this point in the history
… and [!H0]. Previously this was not possible to null handling semantics.

Signed-off-by: Egon Willighagen <egonw@users.sourceforge.net>
  • Loading branch information
johnmay authored and egonw committed Nov 21, 2014
1 parent 464eeda commit 4949cd9
Showing 1 changed file with 10 additions and 18 deletions.
Expand Up @@ -32,28 +32,17 @@
public class ImplicitHCountAtom extends SMARTSAtom {

private static final long serialVersionUID = 6752937431492584928L;
private final int hcount;

/**
* Creates a new instance
*
* @param hCount
* @param hcount
*/
public ImplicitHCountAtom(int hCount, IChemObjectBuilder builder) {
public ImplicitHCountAtom(int hcount, IChemObjectBuilder builder) {
super(builder);
this.setImplicitHydrogenCount(hCount);
}

/**
* Returns the implicit hydrogen count of an atom
*
* @param atom an atom
* @return obtain the implicit hydrogen count, 0 if null
*/
private int getIMPH(IAtom atom) {
if (atom.getImplicitHydrogenCount() == CDKConstants.UNSET)
return 0;
else
return atom.getImplicitHydrogenCount();
this.hcount = hcount;
this.setImplicitHydrogenCount(hcount);
}

/*
Expand All @@ -64,7 +53,10 @@ private int getIMPH(IAtom atom) {
*/
@Override
public boolean matches(IAtom atom) {
return (getIMPH(atom) != 0 && getIMPH(atom) == getIMPH(this));
// h counts should be set before match throw runtime exception?
if (atom.getImplicitHydrogenCount() == null)
return false;
return atom.getImplicitHydrogenCount() == hcount;
}

/*
Expand All @@ -76,7 +68,7 @@ public String toString() {
StringBuilder s = new StringBuilder();
s.append("ImplicitHCountAtom(");
s.append(this.hashCode()).append(", ");
s.append("IH:" + getIMPH(this));
s.append("IH:" + hcount);
s.append(')');
return s.toString();
}
Expand Down

0 comments on commit 4949cd9

Please sign in to comment.