Skip to content

Commit

Permalink
Correct handling of explicit hydrogens in model builder 3D.
Browse files Browse the repository at this point in the history
Change-Id: Id35583e43ee3e6c3dbfe254a7a049d83a40d0a9c
Signed-off-by: Egon Willighagen <egonw@users.sourceforge.net>
  • Loading branch information
johnmay authored and egonw committed Mar 30, 2015
1 parent c64509b commit 60d85be
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 11 deletions.
Expand Up @@ -388,6 +388,20 @@ public IAtom getNextUnplacedHeavyAtomWithAliphaticPlacedNeighbour(IAtomContainer
return null;
}

/**
* Find the first unplaced atom.
*
* @param molecule molecule being built
* @return an unplaced heavy atom, null if none.
*/
IAtom getUnplacedHeavyAtom(IAtomContainer molecule) {
for (IAtom atom : molecule.atoms()) {
if (isUnplacedHeavyAtom(atom))
return atom;
}
return null;
}

/**
* Gets the nextPlacedHeavyAtomWithAliphaticPlacedNeigbor from an atom container or molecule.
*
Expand Down
Expand Up @@ -179,7 +179,7 @@ public IAtomContainer generate3DCoordinates(IAtomContainer molecule, boolean clo

if (ap3d.numberOfUnplacedHeavyAtoms(molecule) == 1) {
logger.debug("Only one Heavy Atom");
molecule.getAtom(0).setPoint3d(new Point3d(0.0, 0.0, 0.0));
ap3d.getUnplacedHeavyAtom(molecule).setPoint3d(new Point3d(0.0, 0.0, 0.0));
try {
atlp3d.add3DCoordinatesForSinglyBondedLigands(molecule);
} catch (CDKException ex3) {
Expand Down
Expand Up @@ -48,8 +48,11 @@
import org.openscience.cdk.silent.AtomContainer;
import org.openscience.cdk.silent.SilentChemObjectBuilder;
import org.openscience.cdk.smiles.SmilesParser;
import org.openscience.cdk.tools.manipulator.AtomContainerManipulator;
import org.openscience.cdk.tools.manipulator.ChemFileManipulator;

import static org.junit.Assert.assertNotNull;

/**
* Description of the Class
*
Expand Down Expand Up @@ -103,7 +106,7 @@ public void testModelBuilder3D_CccccC() throws Exception {
addExplicitHydrogens(mol);
mol = mb3d.generate3DCoordinates(mol, false);
for (int i = 0; i < mol.getAtomCount(); i++) {
Assert.assertNotNull(mol.getAtom(i).getPoint3d());
assertNotNull(mol.getAtom(i).getPoint3d());
}
checkAverageBondLength(mol);
//logger.debug("Layout molecule with SMILE: "+smile);
Expand All @@ -120,7 +123,7 @@ public void testModelBuilder3D_c1ccccc1C0() throws Exception {
addExplicitHydrogens(mol);
mb3d.generate3DCoordinates(mol, false);
for (int i = 0; i < mol.getAtomCount(); i++) {
Assert.assertNotNull(mol.getAtom(i).getPoint3d());
assertNotNull(mol.getAtom(i).getPoint3d());
}
checkAverageBondLength(mol);
}
Expand All @@ -136,7 +139,7 @@ public void testModelBuilder3D_Konstanz() throws Exception {
addExplicitHydrogens(mol);
mol = mb3d.generate3DCoordinates(mol, false);
for (int i = 0; i < mol.getAtomCount(); i++) {
Assert.assertNotNull(mol.getAtom(i).getPoint3d());
assertNotNull(mol.getAtom(i).getPoint3d());
}
checkAverageBondLength(mol);
}
Expand All @@ -152,7 +155,7 @@ public void xtestModelBuilder3D_Konstanz2() throws Exception {
addExplicitHydrogens(mol);
mol = mb3d.generate3DCoordinates(mol, false);
for (int i = 0; i < mol.getAtomCount(); i++) {
Assert.assertNotNull(mol.getAtom(i).getPoint3d());
assertNotNull(mol.getAtom(i).getPoint3d());
}
checkAverageBondLength(mol);
}
Expand All @@ -168,7 +171,7 @@ public void testModelBuilder3D_C1CCCCCCC1CC() throws Exception {
addExplicitHydrogens(mol);
mol = mb3d.generate3DCoordinates(mol, false);
for (int i = 0; i < mol.getAtomCount(); i++) {
Assert.assertNotNull(mol.getAtom(i).getPoint3d());
assertNotNull(mol.getAtom(i).getPoint3d());
}
checkAverageBondLength(mol);
}
Expand All @@ -192,7 +195,7 @@ public void testModelBuilder3D_CCCCCCCCCC_with2d() throws Exception {
addExplicitHydrogens(mol);
mol = mb3d.generate3DCoordinates(mol, false);
for (int i = 0; i < mol.getAtomCount(); i++) {
Assert.assertNotNull(mol.getAtom(i).getPoint3d());
assertNotNull(mol.getAtom(i).getPoint3d());
}
checkAverageBondLength(mol);
}
Expand All @@ -214,7 +217,7 @@ public void testModelBuilder3D_232() throws Exception {
IAtomContainer ac = new AtomContainer(containersList.get(0));
addExplicitHydrogens(ac);
ac = mb3d.generate3DCoordinates(ac, false);
Assert.assertNotNull(ac.getAtom(0).getPoint3d());
assertNotNull(ac.getAtom(0).getPoint3d());
checkAverageBondLength(ac);
}

Expand Down Expand Up @@ -242,7 +245,7 @@ public void testModelBuilder3D_231() throws Exception {
addExplicitHydrogens(ac);
ac = mb3d.generate3DCoordinates(ac, false);
for (int i = 0; i < ac.getAtomCount(); i++) {
Assert.assertNotNull(ac.getAtom(i).getPoint3d());
assertNotNull(ac.getAtom(i).getPoint3d());
}
checkAverageBondLength(ac);
}
Expand Down Expand Up @@ -343,7 +346,7 @@ public void testModel3D_bug_1610997() throws Exception {
try {
mol = mb3d.generate3DCoordinates(mol, false);
for (IAtom a : mol.atoms())
Assert.assertNotNull(smiles[0] + " has unplaced atom", a.getPoint3d());
assertNotNull(smiles[0] + " has unplaced atom", a.getPoint3d());
checkAverageBondLength(mol);
} catch (CDKException | CloneNotSupportedException | IOException e) {
StringWriter stackTrace = new StringWriter();
Expand Down Expand Up @@ -382,7 +385,7 @@ public void testModelBuilder3D_reserpine() throws Exception {
IAtomContainer ac = new AtomContainer(containersList.get(0));
ac = mb3d.generate3DCoordinates(ac, false);
for (int i = 0; i < ac.getAtomCount(); i++) {
Assert.assertNotNull(ac.getAtom(i).getPoint3d());
assertNotNull(ac.getAtom(i).getPoint3d());
}
checkAverageBondLength(ac);
}
Expand All @@ -398,5 +401,27 @@ public void testAlkanes() throws CDKException, IOException, CloneNotSupportedExc
false);
ModelBuilder3D.getInstance(DefaultChemObjectBuilder.getInstance()).generate3DCoordinates(branchedAlkane, false);
}

@Test
public void hydrogenAsFirstAtomInMethane() throws Exception {
SmilesParser smipar = new SmilesParser(SilentChemObjectBuilder.getInstance());
IAtomContainer methane = smipar.parseSmiles("[H]C([H])([H])[H]");
AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(methane);
ModelBuilder3D mb3d = ModelBuilder3D.getInstance(SilentChemObjectBuilder.getInstance());
mb3d.generate3DCoordinates(methane, false);
for (IAtom atom : methane.atoms())
assertNotNull(atom.getPoint3d());
}

@Test
public void hydrogenAsFirstAtomInEthane() throws Exception {
SmilesParser smipar = new SmilesParser(SilentChemObjectBuilder.getInstance());
IAtomContainer ethane = smipar.parseSmiles("[H]C([H])([H])C([H])([H])[H]");
AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(ethane);
ModelBuilder3D mb3d = ModelBuilder3D.getInstance(SilentChemObjectBuilder.getInstance());
mb3d.generate3DCoordinates(ethane, false);
for (IAtom atom : ethane.atoms())
assertNotNull(atom.getPoint3d());
}

}

0 comments on commit 60d85be

Please sign in to comment.