Skip to content

Commit

Permalink
Clean up reaction layout in DepictionGenerator, no longer need to lay…
Browse files Browse the repository at this point in the history
… them out one by one.
  • Loading branch information
johnmay committed Jun 7, 2016
1 parent 0a9b2d2 commit b77a127
Showing 1 changed file with 5 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,6 @@ public final class DepictionGenerator {
*/
private final List<IGenerator<IAtomContainer>> gens = new ArrayList<>();

/**
* Structure diagram generator instance.
*/
private final StructureDiagramGenerator sdg = new StructureDiagramGenerator();

/**
* Flag to indicate atom numbers should be displayed.
*/
Expand Down Expand Up @@ -239,8 +234,6 @@ public DepictionGenerator(Font font) {
// since it depends on raster (px) vs vector (mm)
setParam(BasicSceneGenerator.Margin.class, AUTOMATIC);
setParam(RendererModel.Padding.class, AUTOMATIC);

sdg.setUseTemplates(false);
}

/**
Expand Down Expand Up @@ -457,6 +450,7 @@ public Depiction depict(IReaction rxn) throws CDKException {
myHighlight.putAll(highlight);
highlight.clear();

ensure2dLayout(rxn);
final List<Double> reactantScales = prepareCoords(reactants);
final List<Double> productScales = prepareCoords(products);
final List<Double> agentScales = prepareCoords(agents);
Expand Down Expand Up @@ -672,11 +666,8 @@ private Bounds generateReactionConditions(IReaction chemObj, Color fg, double sc
*/
private boolean ensure2dLayout(IAtomContainer container) throws CDKException {
if (!GeometryUtil.has2DCoordinates(container)) {
// SDG - mutable state is not thread safe :(
synchronized (sdg) {
sdg.setMolecule(container, false);
sdg.generateCoordinates();
}
StructureDiagramGenerator sdg = new StructureDiagramGenerator();
sdg.generateCoordinates(container);
return true;
}
return false;
Expand All @@ -689,12 +680,8 @@ private boolean ensure2dLayout(IAtomContainer container) throws CDKException {
* @throws CDKException coordinates could not be generated
*/
private void ensure2dLayout(IReaction rxn) throws CDKException {
for (IAtomContainer mol : rxn.getReactants().atomContainers())
ensure2dLayout(mol);
for (IAtomContainer mol : rxn.getProducts().atomContainers())
ensure2dLayout(mol);
for (IAtomContainer mol : rxn.getAgents().atomContainers())
ensure2dLayout(mol);
StructureDiagramGenerator sdg = new StructureDiagramGenerator();
sdg.generateCoordinates(rxn);
}

/**
Expand Down

0 comments on commit b77a127

Please sign in to comment.