@TestClass(value="org.openscience.cdk.tools.CDKHydrogenAdderTest") public class CDKHydrogenAdder extends Object
IMolecule methane = new Molecule(); 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:
IMolecule ethane = new Molecule(); 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);
Modifier and Type | Method and Description |
---|---|
void |
addImplicitHydrogens(IAtomContainer container)
Sets implicit hydrogen counts for all atoms in the given IAtomContainer.
|
void |
addImplicitHydrogens(IAtomContainer container,
IAtom atom)
Sets the implicit hydrogen count for the indicated IAtom in the given IAtomContainer.
|
static CDKHydrogenAdder |
getInstance(IChemObjectBuilder builder) |
@TestMethod(value="testInstance") public static CDKHydrogenAdder getInstance(IChemObjectBuilder builder)
@TestMethod(value="testMethane,testFormaldehyde,testHCN") public void addImplicitHydrogens(IAtomContainer container) throws CDKException
container
- The molecule to which H's will be addedCDKException
- Throws if insufficient information is present@TestMethod(value="testImpHByAtom") public void addImplicitHydrogens(IAtomContainer container, IAtom atom) throws CDKException
container
- The molecule to which H's will be addedatom
- IAtom to set the implicit hydrogen count forCDKException
- Throws if insufficient information is present