Skip to content

Commit

Permalink
Option to display atom values in depiction generator.
Browse files Browse the repository at this point in the history
  • Loading branch information
johnmay committed Aug 16, 2016
1 parent 2f50ba9 commit 623b350
Showing 1 changed file with 40 additions and 3 deletions.
Expand Up @@ -21,6 +21,7 @@
import com.google.common.collect.FluentIterable;
import org.openscience.cdk.CDKConstants;
import org.openscience.cdk.exception.CDKException;
import org.openscience.cdk.exception.InvalidSmilesException;
import org.openscience.cdk.geometry.GeometryUtil;
import org.openscience.cdk.interfaces.IAtom;
import org.openscience.cdk.interfaces.IAtomContainer;
Expand All @@ -43,12 +44,15 @@
import org.openscience.cdk.renderer.generators.IGeneratorParameter;
import org.openscience.cdk.renderer.generators.standard.SelectionVisibility;
import org.openscience.cdk.renderer.generators.standard.StandardGenerator;
import org.openscience.cdk.silent.SilentChemObjectBuilder;
import org.openscience.cdk.smiles.SmilesParser;
import org.openscience.cdk.tools.LoggingToolFactory;

import javax.vecmath.Point2d;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
Expand Down Expand Up @@ -179,6 +183,11 @@ public final class DepictionGenerator {
*/
private boolean annotateAtomNum = false;

/**
* Flag to indicate atom values should be displayed.
*/
private boolean annotateAtomVal = false;

/**
* Flag to indicate atom maps should be displayed.
*/
Expand Down Expand Up @@ -248,6 +257,7 @@ public DepictionGenerator(Font font) {
*/
private DepictionGenerator(DepictionGenerator org) {
this.annotateAtomMap = org.annotateAtomMap;
this.annotateAtomVal = org.annotateAtomVal;
this.annotateAtomNum = org.annotateAtomNum;
this.highlightAtomMap = org.highlightAtomMap;
this.atomMapColors = org.atomMapColors;
Expand Down Expand Up @@ -603,6 +613,13 @@ private IRenderingElement generate(IAtomContainer molecule, RendererModel model,
atom.setProperty(StandardGenerator.ANNOTATION_LABEL,
Integer.toString(atomNum++));
}
} else if (annotateAtomVal) {
for (IAtom atom : molecule.atoms()) {
if (atom.getProperty(StandardGenerator.ANNOTATION_LABEL) != null)
throw new UnsupportedOperationException("Multiple annotation labels are not supported.");
atom.setProperty(StandardGenerator.ANNOTATION_LABEL,
atom.getProperty(CDKConstants.COMMENT));
}
} else if (annotateAtomMap) {
for (IAtom atom : molecule.atoms()) {
if (atom.getProperty(StandardGenerator.ANNOTATION_LABEL) != null)
Expand Down Expand Up @@ -772,13 +789,33 @@ public DepictionGenerator withOuterGlowHighlight(double width) {
* @see StandardGenerator#ANNOTATION_LABEL
*/
public DepictionGenerator withAtomNumbers() {
if (annotateAtomMap)
throw new IllegalArgumentException();
if (annotateAtomMap || annotateAtomVal)
throw new IllegalArgumentException("Can not annotated atom numbers, atom values or maps are already annotated");
DepictionGenerator copy = new DepictionGenerator(this);
copy.annotateAtomNum = true;
return copy;
}

/**
* Display atom numbers on the molecule or reaction. The numbers are based on the
* ordering of atoms in the molecule data structure and not a systematic system
* such as IUPAC numbering.
* <p/>
* Note: A depiction can not have both atom numbers and atom maps visible
* (but this can be achieved by manually setting the annotation).
*
* @return new generator for method chaining
* @see #withAtomMapNumbers()
* @see StandardGenerator#ANNOTATION_LABEL
*/
public DepictionGenerator withAtomValues() {
if (annotateAtomNum || annotateAtomMap)
throw new IllegalArgumentException("Can not annotated atom values, atom numbers or maps are already annotated");
DepictionGenerator copy = new DepictionGenerator(this);
copy.annotateAtomVal = true;
return copy;
}

/**
* Display atom-atom mapping numbers on a reaction. Each atom map index
* is loaded from the property {@link CDKConstants#ATOM_ATOM_MAPPING}.
Expand All @@ -794,7 +831,7 @@ public DepictionGenerator withAtomNumbers() {
*/
public DepictionGenerator withAtomMapNumbers() {
if (annotateAtomNum)
throw new IllegalArgumentException();
throw new IllegalArgumentException("Can not annotated atom maps, atom numbers or values are already annotated");
DepictionGenerator copy = new DepictionGenerator(this);
copy.annotateAtomMap = true;
return copy;
Expand Down

0 comments on commit 623b350

Please sign in to comment.