1 /* Copyright (C) 2004-2007 Egon Willighagen <egonw@users.sf.net> 2 * 3 * Contact: cdk-devel@lists.sourceforge.net 4 * 5 * This program is free software; you can redistribute it and/or 6 * modify it under the terms of the GNU Lesser General Public License 7 * as published by the Free Software Foundation; either version 2.1 8 * of the License, or (at your option) any later version. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public License 16 * along with this program; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 */ 19 package org.openscience.cdk.isomorphism.matchers.smarts; 20 21 import org.openscience.cdk.interfaces.IAtom; 22 import org.openscience.cdk.interfaces.IChemObjectBuilder; 23 24 import java.util.List; 25 26 /** 27 * This matches Hydrogen atoms. 28 * 29 * @cdk.module smarts 30 * @cdk.githash 31 * @cdk.keyword SMARTS 32 */ 33 @Deprecated 34 public class HydrogenAtom extends SMARTSAtom { 35 36 /** Creates a new instance. */ HydrogenAtom(IChemObjectBuilder builder)37 public HydrogenAtom(IChemObjectBuilder builder) { 38 super(builder); 39 } 40 41 /* 42 * (non-Javadoc) 43 * @see 44 * org.openscience.cdk.isomorphism.matchers.smarts.SMARTSAtom#matches(org 45 * .openscience.cdk.interfaces.IAtom) 46 */ 47 @Override matches(IAtom atom)48 public boolean matches(IAtom atom) { 49 if (!atom.getSymbol().equals("H")) { 50 return false; 51 } 52 53 if (atom.getFormalCharge() == 1) { // proton matches 54 return true; 55 } 56 57 // hydrogens connected to other hydrogens, e.g., molecular hydrogen 58 List<IAtom> list = invariants(atom).target().getConnectedAtomsList(atom); 59 for (IAtom connAtom : list) { 60 if (connAtom.getSymbol().equals("H")) { 61 return true; 62 } 63 } 64 65 // hydrogens connected to other than one other atom, e.g., bridging hydrogens 66 if (invariants(atom).degree() > 1) { 67 return true; 68 } 69 70 //isotopic hydrogen specifications, e.g. deuterium [2H] or tritium etc 71 if (atom.getMassNumber() != null) { 72 if (getMassNumber().intValue() == atom.getMassNumber().intValue()) return true; 73 } else { 74 // target atom is [H], so make sure query atom has mass number = 1 75 if (getMassNumber() == 1) return true; 76 } 77 78 return false; 79 } 80 } 81