Skip to content

Commit

Permalink
Option to enable/disable mapped reaction alignment.
Browse files Browse the repository at this point in the history
  • Loading branch information
johnmay committed Jun 8, 2016
1 parent e16b3da commit 50b0a7d
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 8 deletions.
Expand Up @@ -194,6 +194,11 @@ public final class DepictionGenerator {
*/
private Color[] atomMapColors = null;

/**
* Reactions are aligned such that mapped atoms have the same coordinates on the left/right.
*/
private boolean alignMappedReactions = true;

/**
* Object that should be highlighted
*/
Expand Down Expand Up @@ -681,6 +686,7 @@ private boolean ensure2dLayout(IAtomContainer container) throws CDKException {
*/
private void ensure2dLayout(IReaction rxn) throws CDKException {
StructureDiagramGenerator sdg = new StructureDiagramGenerator();
sdg.setAlignMappedReaction(alignMappedReactions);
sdg.generateCoordinates(rxn);
}

Expand Down Expand Up @@ -853,6 +859,19 @@ public DepictionGenerator withRxnTitle() {
true);
}

/**
* Specifies that reactions with atom-atom mappings should have their reactants/product
* coordinates aligned. Default: true.
*
* @param val setting value
* @return new generator for method chaining
*/
public DepictionGenerator withMappedRxnAlign(boolean val) {
DepictionGenerator copy = new DepictionGenerator();
copy.alignMappedReactions = val;
return copy;
}

/**
* Set the color annotations (e.g. atom-numbers) will appear in.
*
Expand Down
Expand Up @@ -111,19 +111,19 @@ public class StructureDiagramGenerator {
private IRingSet sssr;
private double bondLength = DEFAULT_BOND_LENGTH;
private Vector2d firstBondVector;
private RingPlacer ringPlacer = new RingPlacer();
private AtomPlacer atomPlacer = new AtomPlacer();
private MacroCycleLayout macroPlacer = null;
private List<IRingSet> ringSystems = null;
private Set<IAtom> afix = null;
private Set<IBond> bfix = null;
private boolean useIdentTemplates = true;
private RingPlacer ringPlacer = new RingPlacer();
private AtomPlacer atomPlacer = new AtomPlacer();
private MacroCycleLayout macroPlacer = null;
private List<IRingSet> ringSystems = null;
private Set<IAtom> afix = null;
private Set<IBond> bfix = null;
private boolean useIdentTemplates = true;
private boolean alignMappedReaction = true;

// show we orient the structure (false: keep de facto ring systems drawn
// the right way up)
private boolean selectOrientation = true;


/**
* Identity templates - for laying out primary ring system.
*/
Expand Down Expand Up @@ -176,6 +176,7 @@ public final void generateCoordinates(IAtomContainer mol) throws CDKException {
/**
* <p>Convenience method to generate 2D coordinates for a reaction. If atom-atom
* maps are present on a reaction, the substructures are automatically aligned.</p>
* <p>This feature can be disabled by changing the {@link #setAlignMappedReaction(boolean)}</p>
*
* @param reaction reaction to layout
* @throws CDKException problem with layout
Expand All @@ -186,6 +187,8 @@ public final void generateCoordinates(final IReaction reaction) throws CDKExcept
for (IAtomContainer product : reaction.getProducts().atomContainers()) {
setMolecule(product, false);
generateCoordinates();
if (!alignMappedReaction)
continue;
for (IBond bond : product.bonds()) {
Integer begidx = bond.getAtom(0).getProperty(CDKConstants.ATOM_ATOM_MAPPING);
Integer endidx = bond.getAtom(1).getProperty(CDKConstants.ATOM_ATOM_MAPPING);
Expand Down Expand Up @@ -375,6 +378,15 @@ public void setMolecule(IAtomContainer molecule) {
setMolecule(molecule, true);
}

/**
* Set whether reaction reactants should be allignned to their product.
*
* @param align align setting
*/
public void setAlignMappedReaction(boolean align) {
this.alignMappedReaction = align;
}

/**
* Returns the molecule, usually used after a call of generateCoordinates()
*
Expand Down

0 comments on commit 50b0a7d

Please sign in to comment.