Class CDKHydrogenAdder

java.lang.Object
org.openscience.cdk.tools.CDKHydrogenAdder

public class CDKHydrogenAdder extends Object
Adds implicit hydrogens based on atom type definitions. The class assumes that CDK atom types are already detected. A full code example is:
   IAtomContainer methane = new AtomContainer();
   IAtom carbon = new Atom("C");
   methane.addAtom(carbon);
   CDKAtomTypeMatcher matcher = CDKAtomTypeMatcher.getInstance(methane.getNewBuilder());
   for (IAtom atom : methane.atoms) {
     IAtomType type = matcher.findMatchingAtomType(methane, atom);
     AtomTypeManipulator.configure(atom, type);
   }
   CDKHydrogenAdder adder = CDKHydrogenAdder.getInstance(methane.getNewBuilder());
   adder.addImplicitHydrogens(methane);
 

If you want to add the hydrogens to a specific atom only, use this example:

   IAtomContainer ethane = new AtomContainer();
   IAtom carbon1 = new Atom("C");
   IAtom carbon2 = new Atom("C");
   ethane.addAtom(carbon1);
   ethane.addAtom(carbon2);
   CDKAtomTypeMatcher matcher = CDKAtomTypeMatcher.getInstance(ethane.getNewBuilder());
   IAtomType type = matcher.findMatchingAtomType(ethane, carbon1);
   AtomTypeManipulator.configure(carbon1, type);
   CDKHydrogenAdder adder = CDKHydrogenAdder.getInstance(ethane.getNewBuilder());
   adder.addImplicitHydrogens(ethane, carbon1);
 
Author:
egonw
Source code:
main
Belongs to CDK module:
valencycheck
  • Method Details

    • getInstance

      public static CDKHydrogenAdder getInstance(IChemObjectBuilder builder)
    • addImplicitHydrogens

      public void addImplicitHydrogens(IAtomContainer container) throws CDKException
      Sets implicit hydrogen counts for all atoms in the given IAtomContainer.
      Parameters:
      container - The molecule to which H's will be added
      Throws:
      CDKException - Throws if insufficient information is present
      Keywords:
      hydrogens, adding
    • addImplicitHydrogens

      public void addImplicitHydrogens(IAtomContainer container, IAtom atom) throws CDKException
      Sets the implicit hydrogen count for the indicated IAtom in the given IAtomContainer. If the atom type is "X", then the atom is assigned zero implicit hydrogens.
      Parameters:
      container - The molecule to which H's will be added
      atom - IAtom to set the implicit hydrogen count for
      Throws:
      CDKException - Throws if insufficient information is present