Skip to content

Commit

Permalink
Deprecate and throw an exception if the bond length is attempted to b…
Browse files Browse the repository at this point in the history
…e set in the layout generator.
  • Loading branch information
johnmay committed Nov 17, 2017
1 parent 040dbbf commit 8ed23ca
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
Expand Up @@ -112,7 +112,7 @@ public class StructureDiagramGenerator {

private IAtomContainer molecule;
private IRingSet sssr;
private double bondLength = DEFAULT_BOND_LENGTH;
private final double bondLength = DEFAULT_BOND_LENGTH;
private Vector2d firstBondVector;
private RingPlacer ringPlacer = new RingPlacer();
private AtomPlacer atomPlacer = new AtomPlacer();
Expand Down Expand Up @@ -2072,13 +2072,27 @@ private void resetUnplacedRings() {
}

/**
* Set the bond length used for laying out the molecule.
* The default value is 1.5.
* This method used to set the bond length used for laying out the molecule.
* Since bond lengths in 2D are are arbitrary, the preferred way to do this
* is with {@link GeometryUtil#scaleMolecule(IAtomContainer, double)}.
*
* <pre>
* IAtomContainer mol = ...;
* sdg.generateCoordinates(mol);
* int targetBondLength = 28;
* double factor = targetBondLength/GeometryUtil.getMedianBondLength(mol);
* GeometryUtil.scaleMolecule(mol, factor);
* </pre>
*
* @param bondLength The new bondLength value
* @deprecated use {@link GeometryUtil#scaleMolecule(IAtomContainer, double)}
* @throws UnsupportedOperationException not supported
*/
@Deprecated
public void setBondLength(double bondLength) {
this.bondLength = bondLength;
throw new UnsupportedOperationException(
"Bond length should be adjusted post layout"
+ " with GeometryUtil.scaleMolecule();");
}

/**
Expand Down
Expand Up @@ -1264,4 +1264,10 @@ else if (config == IDoubleBondStereochemistry.Conformation.OPPOSITE)
assertThat(numCis, is(2));
assertThat(numTrans, is(2));
}

@Test(expected = UnsupportedOperationException.class)
public void setBondLength() {
StructureDiagramGenerator sdg = new StructureDiagramGenerator();
sdg.setBondLength(2);
}
}

0 comments on commit 8ed23ca

Please sign in to comment.