Skip to content

Commit

Permalink
Format SMARTS atoms that need to be updated.
Browse files Browse the repository at this point in the history
Signed-off-by: Stephan Beisken <sbeisken@gmail.com>
Signed-off-by: Egon Willighagen <egonw@users.sourceforge.net>
  • Loading branch information
johnmay authored and egonw committed Dec 18, 2013
1 parent 8cc06f9 commit 2532eee
Show file tree
Hide file tree
Showing 2 changed files with 203 additions and 200 deletions.
Expand Up @@ -29,71 +29,64 @@
/**
* This matches Hydrogen atoms.
*
* @cdk.module smarts
* @cdk.module smarts
* @cdk.githash
* @cdk.keyword SMARTS
* @cdk.keyword SMARTS
*/
public class HydrogenAtom extends SMARTSAtom {
/**
* Local copy of IAtomContainer.
*/
private IAtomContainer atomContainer;
/** Local copy of IAtomContainer. */
private IAtomContainer atomContainer;

/**
* Creates a new instance.
*
*/
public HydrogenAtom(IChemObjectBuilder builder) {
super(builder);
}
/** Creates a new instance. */
public HydrogenAtom(IChemObjectBuilder builder) {
super(builder);
}

/* (non-Javadoc)
* @see org.openscience.cdk.isomorphism.matchers.smarts.SMARTSAtom#matches(org.openscience.cdk.interfaces.IAtom)
*/
public boolean matches(IAtom atom) {
if (!atom.getSymbol().equals("H")) {
return false;
}
if (atom.getFormalCharge() == 1) { // proton matches
return true;
}
// hydrogens connected to other hydrogens, e.g., molecular hydrogen
List<IAtom> list = atomContainer.getConnectedAtomsList(atom);
for (IAtom connAtom: list) {
if (connAtom.getSymbol().equals("H")) {
return true;
}
}
// hydrogens connected to other than one other atom, e.g., bridging hydrogens
if (invariants(atom).degree() > 1) {
return true;
}
//isotopic hydrogen specifications, e.g. deuterium [2H] or tritium etc
/* (non-Javadoc)
* @see org.openscience.cdk.isomorphism.matchers.smarts.SMARTSAtom#matches(org.openscience.cdk.interfaces.IAtom)
*/
public boolean matches(IAtom atom) {
if (!atom.getSymbol().equals("H")) {
return false;
}

if (atom.getFormalCharge() == 1) { // proton matches
return true;
}

// hydrogens connected to other hydrogens, e.g., molecular hydrogen
List<IAtom> list = atomContainer.getConnectedAtomsList(atom);
for (IAtom connAtom : list) {
if (connAtom.getSymbol().equals("H")) {
return true;
}
}

// hydrogens connected to other than one other atom, e.g., bridging hydrogens
if (invariants(atom).degree() > 1) {
return true;
}

//isotopic hydrogen specifications, e.g. deuterium [2H] or tritium etc
if (atom.getMassNumber() != null) {
if (getMassNumber().intValue() == atom.getMassNumber().intValue()) return true;
} else {
if (getMassNumber().intValue() == atom.getMassNumber().intValue())
return true;
}
else {
// target atom is [H], so make sure query atom has mass number = 1
if (getMassNumber() == 1) return true;
}

return false;
}

/**
* Returns local copy of IAtomContainer.
*/
public IAtomContainer getAtomContainer() {
return atomContainer;
}
return false;
}

/** Returns local copy of IAtomContainer. */
public IAtomContainer getAtomContainer() {
return atomContainer;
}

/**
* Sets IAtomContainer.
*/
public void setAtomContainer(IAtomContainer atomContainer) {
this.atomContainer = atomContainer;
}
/** Sets IAtomContainer. */
public void setAtomContainer(IAtomContainer atomContainer) {
this.atomContainer = atomContainer;
}
}

0 comments on commit 2532eee

Please sign in to comment.