Package org.openscience.cdk.depict
Class DepictionGenerator
java.lang.Object
org.openscience.cdk.depict.DepictionGenerator
A high-level API for depicting molecules and reactions.
General Usage Create a generator and reuse it for multiple depictions. Configure how the depiction will look using
One Line Quick Use For simplified use we can create a generator and use it once for a single depiction.
General Usage Create a generator and reuse it for multiple depictions. Configure how the depiction will look using
with...()
methods.
DepictionGenerator dg = new DepictionGenerator().withSize(512, 512)
.withAtomColors();
for (IAtomContainer mol : mols) {
dg.depict(mol).writeTo("~/mol.png");
}
One Line Quick Use For simplified use we can create a generator and use it once for a single depiction.
new DepictionGenerator().depict(mol)
.writeTo("~/mol.png");
The intermediate Depiction
object can write to many different formats
through a variety of API calls.
Depiction depiction = new DepictionGenerator().depict(mol);
// quick use, format determined by name by path
depiction.writeTo("~/mol.png");
depiction.writeTo("~/mol.svg");
depiction.writeTo("~/mol.pdf");
depiction.writeTo("~/mol.jpg");
// manually specify the format
depiction.writeTo(Depiction.SVG_FMT, "~/mol");
// convert to a Java buffered image
BufferedImage img = depiction.toImg();
// get the SVG XML string
String svg = depiction.toSvgStr();
- Author:
- John may
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final double
Magic value for indicating automatic parameters.static final double
Default margin for vector graphics formats.static final double
Default margin for raster graphics formats. -
Constructor Summary
ConstructorsConstructorDescriptionCreate a depiction generator using the standard sans-serif system font.DepictionGenerator
(Font font) Create a depiction generator that will render atom labels using the specified AWT font. -
Method Summary
Modifier and TypeMethodDescriptiondepict
(Iterable<IAtomContainer> mols) Depict a set of molecules, they will be depicted in a grid.depict
(Iterable<IAtomContainer> mols, int nrow, int ncol) Depict a set of molecules, they will be depicted in a grid with the specified number of rows and columns.depict
(IAtomContainer mol) Depict a single molecule.Depict a reaction.withAnnotationColor
(Color color) Set the color annotations (e.g.withAnnotationScale
(double scale) Set the size of annotations relative to atom symbols.When aromaticity is set on bonds, display this in the diagram.Color atom symbols using typical colors, oxygens are red, nitrogens are blue, etc.withAtomColors
(IAtomColorer colorer) Color atom symbols using provided colorer.Adds to the highlight the coloring of reaction atom-maps.withAtomMapHighlight
(Color[] colors) Adds to the highlight the coloring of reaction atom-maps.Display atom-atom mapping numbers on a reaction.Display atom numbers on the molecule or reaction.Display atom values on the molecule or reaction.withBackgroundColor
(Color color) Change the background color.Display atom symbols for all atoms in the molecule.withDeuteriumSymbol
(boolean v) Indicate whether 2H should be rendered as 'D'.Resize depictions to fill all available space (only if a size is specified).withHighlight
(Iterable<? extends IChemObject> chemObjs, Color color) Highlight the provided set of atoms and bonds in the depiction in the specified color.withMappedRxnAlign
(boolean val) Specifies that reactions with atom-atom mappings should have their reactants/product coordinates aligned.withMargin
(double m) Specify a desired size of margin.Display a molecule title with each depiction.Highlights are shown as an outer glow around the atom symbols and bonds rather than recoloring.withOuterGlowHighlight
(double width) Highlights are shown as an outer glow around the atom symbols and bonds rather than recoloring.withPadding
(double p) Specify a desired size of padding for molecule sets and reactions.<T extends IGeneratorParameter<S>,
S, U extends S>
DepictionGeneratorLow-level option method to set a rendering model parameter.Display a reaction title with the depiction.withSize
(double w, double h) Specify a desired size of depiction.Display atom symbols for terminal carbons (i.e.withTitleColor
(Color color) Set the color titles will appear in.withTitleScale
(double scale) Set the size of titles compared to atom symbols.withZoom
(double zoom) Specify a desired zoom factor - this changes the base size of a depiction and is used for uniformly making depictions bigger.
-
Field Details
-
AUTOMATIC
public static final double AUTOMATICMagic value for indicating automatic parameters. These can be overridden by a caller.- See Also:
-
DEFAULT_MM_MARGIN
public static final double DEFAULT_MM_MARGINDefault margin for vector graphics formats.- See Also:
-
DEFAULT_PX_MARGIN
public static final double DEFAULT_PX_MARGINDefault margin for raster graphics formats.- See Also:
-
-
Constructor Details
-
DepictionGenerator
public DepictionGenerator()Create a depiction generator using the standard sans-serif system font. -
DepictionGenerator
Create a depiction generator that will render atom labels using the specified AWT font.- Parameters:
font
- the font to use to display
-
-
Method Details
-
depict
Depict a single molecule.- Parameters:
mol
- molecule- Returns:
- depiction instance
- Throws:
CDKException
- a depiction could not be generated
-
depict
Depict a set of molecules, they will be depicted in a grid. The grid size (nrow x ncol) is determined automatically based on the number molecules.- Parameters:
mols
- molecules- Returns:
- depiction
- Throws:
CDKException
- a depiction could not be generated- See Also:
-
depict
Depict a set of molecules, they will be depicted in a grid with the specified number of rows and columns. Rows are filled first and then columns.- Parameters:
mols
- moleculesnrow
- number of rowsncol
- number of columns- Returns:
- depiction
- Throws:
CDKException
- a depiction could not be generated
-
depict
Depict a reaction.- Parameters:
rxn
- reaction instance- Returns:
- depiction
- Throws:
CDKException
- a depiction could not be generated
-
withAtomColors
Color atom symbols using typical colors, oxygens are red, nitrogens are blue, etc.- Returns:
- new generator for method chaining
- See Also:
-
withAtomColors
Color atom symbols using provided colorer.- Returns:
- new generator for method chaining
- See Also:
-
withBackgroundColor
Change the background color.- Parameters:
color
- background color- Returns:
- new generator for method chaining
- See Also:
-
withOuterGlowHighlight
Highlights are shown as an outer glow around the atom symbols and bonds rather than recoloring. The width of the glow can be set but defaults to 4x the stroke width.- Returns:
- new generator for method chaining
- See Also:
-
withOuterGlowHighlight
Highlights are shown as an outer glow around the atom symbols and bonds rather than recoloring.- Parameters:
width
- width of the outer glow relative to the bond stroke- Returns:
- new generator for method chaining
- See Also:
-
withAtomNumbers
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. Note: A depiction can not have both atom numbers and atom maps visible (but this can be achieved by manually setting the annotation).- Returns:
- new generator for method chaining
- See Also:
-
withAtomValues
Display atom values on the molecule or reaction. The values need to be assigned by
Note: A depiction can not have both atom numbers and atom maps visible (but this can be achieved by manually setting the annotation).atom.setProperty(CDKConstants.COMMENT, myValueToBeDisplayedNextToAtom);
- Returns:
- new generator for method chaining
- See Also:
-
withAtomMapNumbers
Display atom-atom mapping numbers on a reaction. Each atom map index is loaded from the propertyCDKConstants.ATOM_ATOM_MAPPING
. Note: A depiction can not have both atom numbers and atom maps visible (but this can be achieved by manually setting the annotation).- Returns:
- new generator for method chaining
- See Also:
-
withAtomMapHighlight
Adds to the highlight the coloring of reaction atom-maps. The optional color array is used as the pallet with which to highlight. If none is provided a set of high-contrast colors will be used.- Returns:
- new generator for method chaining
- See Also:
-
withAtomMapHighlight
Adds to the highlight the coloring of reaction atom-maps. The optional color array is used as the pallet with which to highlight. If none is provided a set of high-contrast colors will be used.- Parameters:
colors
- array of colors- Returns:
- new generator for method chaining
- See Also:
-
withMolTitle
Display a molecule title with each depiction. The title is specified by setting theCDKConstants.TITLE
property. For reactions only the main components have their title displayed.- Returns:
- new generator for method chaining
- See Also:
-
withRxnTitle
Display a reaction title with the depiction. The title is specified by setting theCDKConstants.TITLE
property on theIReaction
instance.- Returns:
- new generator for method chaining
- See Also:
-
withMappedRxnAlign
Specifies that reactions with atom-atom mappings should have their reactants/product coordinates aligned. Default: true.- Parameters:
val
- setting value- Returns:
- new generator for method chaining
-
withAnnotationColor
Set the color annotations (e.g. atom-numbers) will appear in.- Parameters:
color
- the color of annotations- Returns:
- new generator for method chaining
- See Also:
-
withAnnotationScale
Set the size of annotations relative to atom symbols.- Parameters:
scale
- the scale of annotations- Returns:
- new generator for method chaining
- See Also:
-
withTitleColor
Set the color titles will appear in.- Parameters:
color
- the color of titles- Returns:
- new generator for method chaining
- See Also:
-
withTitleScale
Set the size of titles compared to atom symbols.- Parameters:
scale
- the scale of titles- Returns:
- new generator for method chaining
- See Also:
-
withTerminalCarbons
Display atom symbols for terminal carbons (i.e. Methyl) groups.- Returns:
- new generator for method chaining
- See Also:
-
withCarbonSymbols
Display atom symbols for all atoms in the molecule.- Returns:
- new generator for method chaining
- See Also:
-
withHighlight
Highlight the provided set of atoms and bonds in the depiction in the specified color. Calling this methods appends to the current highlight buffer. The buffer is cleared after each depiction is generated (e.g.depict(IAtomContainer)
).- Parameters:
chemObjs
- set of atoms and bondscolor
- the color to highlight- Returns:
- new generator for method chaining
- See Also:
-
withSize
Specify a desired size of depiction. The units depend on the output format with raster images using pixels and vector graphics using millimeters. By default depictions are only ever made smaller if you would also like to make depictions fill all available space use thewithFillToFit()
option. Currently the size must either both be precisely specified (e.g. 256x256) or automatic (e.g.AUTOMATIC
xAUTOMATIC
) you cannot for example specify a fixed height and automatic width.- Parameters:
w
- max widthh
- max height- Returns:
- new generator for method chaining
- See Also:
-
withMargin
Specify a desired size of margin. The units depend on the output format with raster images using pixels and vector graphics using millimeters.- Parameters:
m
- margin- Returns:
- new generator for method chaining
- See Also:
-
withPadding
Specify a desired size of padding for molecule sets and reactions. The units depend on the output format with raster images using pixels and vector graphics using millimeters.- Parameters:
p
- padding- Returns:
- new generator for method chaining
- See Also:
-
withZoom
Specify a desired zoom factor - this changes the base size of a depiction and is used for uniformly making depictions bigger. If you would like to simply fill all available space (not recommended) usewithFillToFit()
. The zoom is a scaling factor, specifying a zoom of 2 is double size, 0.5 half size, etc.- Parameters:
zoom
- zoom factor- Returns:
- new generator for method chaining
- See Also:
-
withFillToFit
Resize depictions to fill all available space (only if a size is specified). This generally isn't wanted as very small molecules (e.g. acetaldehyde) may become huge.- Returns:
- new generator for method chaining
- See Also:
-
withAromaticDisplay
When aromaticity is set on bonds, display this in the diagram. IUPAC recommends depicting kekulé structures to avoid ambiguity but it's common practice to render delocalised rings "donuts" or "life buoys". With fused rings this can be somewhat confusing as you end up with three lines at the fusion point.
By default small rings are renders as donuts with dashed bonds used otherwise. You can use dashed bonds always by turning off theStandardGenerator.DelocalisedDonutsBondDisplay
.- Returns:
- new generator for method chaining
- See Also:
-
withDeuteriumSymbol
Indicate whether 2H should be rendered as 'D'. Default: true.- Parameters:
v
- the value- Returns:
- new generator for method chaining
-
withParam
public <T extends IGeneratorParameter<S>,S, DepictionGenerator withParamU extends S> (Class<T> key, U value) Low-level option method to set a rendering model parameter.- Type Parameters:
T
- option key typeU
- option value type- Parameters:
key
- option keyvalue
- option value- Returns:
- new generator for method chaining
-