Skip to content

Commit

Permalink
Change the order of components when aligned such that it matches the …
Browse files Browse the repository at this point in the history
…order they are bonded in the product.
  • Loading branch information
johnmay committed Sep 26, 2016
1 parent a9c32b1 commit 0d267c3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
Expand Up @@ -436,6 +436,8 @@ private static void setIfMissing(IChemObject chemObject, String key, String val)
*/
public Depiction depict(IReaction rxn) throws CDKException {

ensure2dLayout(rxn); // can reorder components!

final Color fgcol = getParameterValue(StandardGenerator.AtomColor.class).getAtomColor(rxn.getBuilder()
.newInstance(IAtom.class, "C"));

Expand Down Expand Up @@ -466,7 +468,6 @@ 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 @@ -273,6 +273,19 @@ public final void generateCoordinates(final IReaction reaction) throws CDKExcept
generateCoordinates();
}

// reorder reactants such that they are in the same order they appear on the right
reaction.getReactants().sortAtomContainers(new Comparator<IAtomContainer>() {
@Override
public int compare(IAtomContainer a, IAtomContainer b) {
Point2d aCenter = GeometryUtil.get2DCenter(a);
Point2d bCenter = GeometryUtil.get2DCenter(b);
if (aCenter == null || bCenter == null)
return 0;
else
return Double.compare(aCenter.x, bCenter.x);
}
});

} else {
for (IAtomContainer mol : reaction.getReactants().atomContainers())
generateCoordinates(mol);
Expand Down

0 comments on commit 0d267c3

Please sign in to comment.