|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectchemaxon.marvin.MolPrinter
public class MolPrinter
Molecule renderer that can draw a molecule to a graphics context using various display settings.
Example of usage:
import chemaxon.marvin.MolPrinter;
import chemaxon.struc.Molecule;
import chemaxon.formats.MolImporter;
import java.awt.Color;
import java.awt.Rectangle;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
public class MolPrinterTest {
static BufferedImage createTestImage() throws IOException {
// Create a molecule
Molecule mol = MolImporter.importMol("CN1C=NC2=C1C(=O)N(C)C(=O)N2C");
// Create a writable image
BufferedImage im = new BufferedImage(400, 400,
BufferedImage.TYPE_INT_ARGB);
Graphics2D g = im.createGraphics();
// Clear background
g.setColor(Color.white);
g.fillRect(0, 0, im.getWidth(), im.getHeight());
// Draw the bounding rectangle
g.setColor(Color.red);
Rectangle rect = new Rectangle(20, 20, 360, 200);
g.draw(rect);
// Paint the molecule
MolPrinter molPrinter = new MolPrinter(mol);
molPrinter.setScale(molPrinter.maxScale(rect)); // fit image in the rectangle
molPrinter.setBackgroundColor(Color.white);
molPrinter.paint(g, rect);
return im;
}
public static void main(String[] args) throws Exception {
BufferedImage im = createTestImage();
ImageIO.write(im, "png", new File("test.png"));
}
}
| Constructor Summary | |
|---|---|
MolPrinter()
Constructs a molecule renderer for an empty molecule. |
|
MolPrinter(MDocument d)
Constructs a molecule renderer for the specified document. |
|
MolPrinter(MoleculeGraph m)
Constructs a molecule renderer for the specified molecule. |
|
| Method Summary | |
|---|---|
double |
getAtomsize()
Deprecated. As of Marvin 5.2.2, replaced by getAtomSize(). |
double |
getAtomSize()
Returns the atom size in units of regular bond length. |
java.awt.Color |
getBackgroundColor()
Returns the current background color. |
double |
getBallRadius()
Gets the ball radius for "ball and stick" mode. |
double |
getBondSpacing()
Returns the double bond spacing that is the distance of the two lines representing a double bond. |
double |
getBondWidth()
Deprecated. as of Marvin 4.1, replaced by getBondSpacing() |
java.awt.Rectangle |
getBoundingRectangle(MoleculeGraph[] mols)
Returns the bounding rectangle of the specified molecules using the current scale factor. |
java.lang.String |
getCarbonVisibility()
Returns the visibility style of the C labels on Carbon atoms. |
int |
getChiralitySupport()
Returns the current chirality display mode. |
java.lang.String |
getColorScheme()
Returns the current color scheme. |
java.lang.String |
getCoordinateBondStyle()
Gets the coordinate bond line style when both atoms are single. |
java.lang.String |
getCoordinateBondStyleAtMulticenter()
Gets the coordinate bond line style. |
int |
getDisplayQuality()
Gets the display quality. |
int |
getDispopts()
Returns the actual display options. |
int |
getDispoptsExt()
Returns the actual extended display options. |
java.lang.String |
getDownWedge()
Gets the down wedge orientation. |
java.lang.String |
getImplicitH()
Returns the display method of implicit hydrogens. |
java.lang.String |
getLigandOrderVisibility()
Gets the ligand order visibility setting. |
java.lang.String |
getRendering()
Returns the rendering style of atoms and bonds. |
double |
getScale()
Returns the scale factor in units of regular bond length. |
double |
getStickThickness()
Gets the 3D stick's diameter. |
double |
getWireThickness()
Gets the line thickness for wireframe mode. |
boolean |
isAtomMappingVisible()
Returns true if atom mapping is visible. |
boolean |
isAtomNumbersVisible()
Returns true if atom numbers are visible. |
boolean |
isAtomPropertiesVisible()
Get the atom properties visibility |
boolean |
isAtomSymbolsVisible()
Returns the atom symbol visibility of 3D mode. |
boolean |
isBondLengthVisible()
Return whether the bond length is visible or not. |
boolean |
isExplicitHVisible()
Deprecated. As of Marvin 5.5.1 this method always returns true. This method will be removed in a future release. |
boolean |
isEZLabelsVisible()
Returns the visibility state of absolute double bond stereo configuration labels. |
boolean |
isEzVisible()
Deprecated. As of Marvin 5.2.2, replaced by isEZLabelsVisible() |
boolean |
isGraphInvariantVisible()
Return whether the graph invariant is visible or not. |
boolean |
isLigandErrorVisible()
Gets the bond's ligand error visibility |
boolean |
isLonePairsAutoCalculated()
Returns the state of the automatic calculation of lone pairs. |
boolean |
isLonePairsVisible()
Returns the visibility state of lone pairs. |
boolean |
isRLogicVisible()
Is R-logic visible?. |
boolean |
isSetColoringEnabled()
Returns true if atoms and bonds are colored according to the color of the pre-defined set they belong to. |
boolean |
isTransparent()
Returns the transparency state of the painting. |
boolean |
isValenceErrorvisible()
Returns the visibility state of valence errors. |
boolean |
isValencePropertyVisible()
Gets the atom valence property visibility |
double |
maxScale(java.awt.Dimension d)
Calculates the maximum scaling factor for fitting the image in a rectangle of the specified size. |
double |
maxScale(java.awt.Rectangle r)
Calculates the maximum scaling factor for fitting the image in the specified rectangle. |
void |
molToScreenCoords(DPoint3 molcoords,
java.awt.geom.Point2D scrcoords)
Converts molecular coordinates to 2D screen coordinates. |
void |
paint(java.awt.Graphics2D g,
java.awt.Dimension d)
Paints the molecule on the specified graphics context in the given size. |
void |
paint(java.awt.Graphics2D g,
java.awt.Rectangle r)
Paints the molecule into the center of the specified rectangle. |
void |
paint(java.awt.Graphics g,
java.awt.Rectangle r)
Paints the molecule into the center of the specified rectangle. |
void |
setAtomMappingVisible(boolean v)
Sets the atom mapping visibility. |
void |
setAtomNumbersVisible(boolean v)
Sets the atom number visibility. |
void |
setAtomPropertiesVisible(boolean v)
Set the atom properties visibility |
void |
setAtomsize(double l)
Deprecated. As of Marvin 5.2.2, replaced by setAtomSize(double). |
void |
setAtomSize(double s)
Sets the size of displayed atoms in units of regular bond length. |
void |
setAtomSymbolsVisible(boolean v)
Sets atom symbol visibility in 3D mode. |
void |
setBackgroundColor(java.awt.Color color)
Sets the background color. |
void |
setBallRadius(double r)
Sets the ball radius for "ball and stick" mode. |
void |
setBondLengthVisible(boolean v)
Sets the bond length visibility |
void |
setBondSpacing(double s)
Sets the double bond spacing that is the distance of the two lines representing a double bond. |
void |
setBondWidth(double w)
Deprecated. as of Marvin 4.1, replaced by setBondSpacing(double) |
void |
setCarbonVisibility(java.lang.String s)
Sets the visibility style of the C labels on Carbon atoms. |
void |
setChiralitySupport(int l)
Sets the chirality display mode. |
void |
setColorScheme(java.lang.String s)
Sets the color scheme. |
void |
setCoordinateBondStyle(java.lang.String s)
Set the coordinate bond line style when both atoms are single. |
void |
setCoordinateBondStyleAtMulticenter(java.lang.String s)
Set the coordinate bond line style. |
void |
setDisplayQuality(int q)
Sets the display quality. |
void |
setDispopts(int f)
Modifies the display options in the advanced way of handling display options. |
void |
setDispopts(int f,
int mask)
Modifies the display options as in setDispopts(int), but affects only limited
display options using a mask. |
void |
setDispoptsExt(int f)
Modifies the extended display options in the advanced way of handling display options. |
void |
setDispoptsExt(int f,
int mask)
Modifies the extended display options as in setDispoptsExt(int), but affects only limited
display options using a mask. |
void |
setDoc(MDocument d)
Sets the current document and calculates its bounds. |
void |
setDownWedge(java.lang.String orientation)
Set the down wedge orientation. |
void |
setExplicitH(boolean show)
Deprecated. As of Marvin 5.5.1 this method does nothing. This method will be removed in a future release. |
void |
setExplicitHVisible(boolean b)
Deprecated. As of Marvin 5.5.1 this method does nothing. This method will be removed in a future release. |
void |
setEZLabelsVisible(boolean v)
Sets the visibility state of absolute double bond stereo configuration labels. |
void |
setEzVisible(boolean v)
Deprecated. As of Marvin 5.2.2, replaced by setEZLabelsVisible(boolean) |
void |
setGraphInvariantVisible(boolean v)
Sets the graph invariant visibility |
void |
setImplicitH(java.lang.String s)
Sets the display method of implicit hydrogens. |
void |
setLigandErrorVisible(boolean v)
Sets the bond's ligand error visibility |
void |
setLigandOrderVisibility(java.lang.String s)
Sets the ligand order visibility. |
void |
setLonePairsAutoCalculated(boolean v)
Sets the state of the automatic calculation of lone pairs. |
void |
setLonePairsVisible(boolean v)
Sets the visibility state of lone pairs. |
void |
setMol(Molecule m)
Sets the current molecule and calculate its bounds. |
void |
setMol(java.lang.String s)
Sets the current molecule and calculate its bounds. |
void |
setMolTemplate(Molecule m)
|
void |
setRendering(java.lang.String s)
Sets the rendering style of atoms and bonds. |
void |
setRLogicVisible(boolean v)
Set R-logic visibility. |
void |
setScale(double m)
Sets the scale factor in units of regular bond length. |
void |
setSetColoringEnabled(boolean v)
Colors atoms and bonds according to the color of the pre-defined set they belong to. |
void |
setStickThickness(double w)
Sets the 3D stick's diameter. |
void |
setTransparent(boolean transparency)
Sets the transparency state of the painting. |
void |
setValenceErrorVisible(boolean b)
Sets the visibility state of valence errors. |
void |
setValencePropertyVisible(boolean v)
Sets the atom valence propertiy visibility |
void |
setWireThickness(double w)
Sets the line thickness for wireframe mode. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public MolPrinter()
public MolPrinter(MoleculeGraph m)
m - a molecule graphpublic MolPrinter(MDocument d)
d - the document| Method Detail |
|---|
public int getDispopts()
boolean explicitHVisible =
(molPrinter.getDispopts() & DispOptConsts.EXPLICITH_FLAG) != 0;boolean explicitHVisible = molPrinter.isExplicitHVisible();
DispOptConstspublic void setDispopts(int f)
f - display options to setDispOptConsts
public void setDispopts(int f,
int mask)
setDispopts(int), but affects only limited
display options using a mask.
f - display optionsmask - the bits of the mask determine the specific display options to setDispOptConstspublic int getDispoptsExt()
DispOptConsts,
DispOptConsts.LIGAND_ORDER_OFF,
DispOptConsts.LIGAND_ORDER_ON,
DispOptConsts.LIGAND_ORDER_ONLY_WITH_DEFINITION,
DispOptConsts.ATPROP_FLAG,
DispOptConsts.RLOGIC_FLAG,
DispOptConsts.AUTOMATIC_FOG,
DispOptConsts.VALENCE_PROP_VISIBILITY_FLAGpublic void setDispoptsExt(int f)
f - display options to setsetLigandOrderVisibility(String),
setAtomPropertiesVisible(boolean),
setLigandOrderVisibility(String),
setValencePropertyVisible(boolean),
DispOptConsts,
getDispoptsExt()
public void setDispoptsExt(int f,
int mask)
setDispoptsExt(int), but affects only limited
display options using a mask.
f - display optionsmask - the bits of the mask determine the specific display options to setDispOptConsts,
getDispoptsExt()public double getScale()
public void setScale(double m)
m - displayed length of a C-C bond in pixelspublic double maxScale(java.awt.Rectangle r)
r - the rectangle to fit
public double maxScale(java.awt.Dimension d)
d - the size of the rectangle to fit
public java.awt.Rectangle getBoundingRectangle(MoleculeGraph[] mols)
paint(java.awt.Graphics2D, java.awt.Rectangle)
to draw the molecules using a certain scale factor.
Example:
molPrinter.setScale(28);
Rectangle r = molPrinter.getBoundingRectangle(mols);
BufferedImage im = new BufferedImage(r.x, r.y, BufferedImage.TYPE_INT_ARGB);
Graphics2D g = im.createGraphics();
molPrinter.paint(g, r);
Note that having an MDocument object, one can call
getBoundingRectangle(mDocument.getAllMolecules()).
mols - the molecules
public double getAtomsize()
getAtomSize().
public double getAtomSize()
public void setAtomsize(double l)
setAtomSize(double).
l - size of the displayed atom labelspublic void setAtomSize(double s)
s - size of the displayed atom labelspublic double getBondSpacing()
public double getBallRadius()
public void setBallRadius(double r)
r - the ball radiuspublic double getStickThickness()
public void setStickThickness(double w)
w - the stick thicknesspublic double getWireThickness()
public void setWireThickness(double w)
w - the line thickness in Angstromspublic void setBondSpacing(double s)
spacing = s * 1.54 Å = s * scale pixels
s - the bond spacing in regular bond length units.public java.lang.String getImplicitH()
IMPLICITH_OFF_SIMPLICITH_HETERO_SIMPLICITH_HETEROTERM_SIMPLICITH_ALL_S
DispOptConsts.IMPLICITH_LEVELSpublic void setImplicitH(java.lang.String s)
IMPLICITH_OFF_SIMPLICITH_HETERO_SIMPLICITH_HETEROTERM_SIMPLICITH_ALL_S
s - the display method as StringDispOptConsts.IMPLICITH_LEVELSpublic java.lang.String getColorScheme()
MONO_SCHEME_SCPK_SCHEME_SSHAPELY_SCHEME_SGROUP_SCHEME_S
DispOptConsts.COLOR_SCHEMESpublic void setColorScheme(java.lang.String s)
MONO_SCHEME_SCPK_SCHEME_SSHAPELY_SCHEME_SGROUP_SCHEME_S
s - the color scheme as StringDispOptConsts.COLOR_SCHEMESpublic boolean isSetColoringEnabled()
public void setSetColoringEnabled(boolean v)
v - true to enable atom/bond set coloringpublic java.lang.String getRendering()
WIREFRAME_RENDERING_SWIREKNOBS_RENDERING_SSTICKS_RENDERING_SBALLSTICK_RENDERING_SSPACEFILL_RENDERING_S
DispOptConsts.RENDERING_STYLESpublic void setRendering(java.lang.String s)
WIREFRAME_RENDERING_SWIREKNOBS_RENDERING_SSTICKS_RENDERING_SBALLSTICK_RENDERING_SSPACEFILL_RENDERING_S
s - the rendering style as StringDispOptConsts.RENDERING_STYLESpublic java.awt.Color getBackgroundColor()
public void setBackgroundColor(java.awt.Color color)
color - the desired bakcground Colorpublic boolean isAtomSymbolsVisible()
public void setAtomSymbolsVisible(boolean v)
v - show (true) or hide (false) atom symbols in 3D modepublic void setAtomNumbersVisible(boolean v)
v - true to show, false to hidepublic boolean isAtomNumbersVisible()
public void setAtomMappingVisible(boolean v)
v - true to show, false to hidepublic boolean isAtomMappingVisible()
public int getChiralitySupport()
StereoConstants.CHIRALITYSUPPORT_NONEStereoConstants.CHIRALITYSUPPORT_SELECTEDStereoConstants.CHIRALITYSUPPORT_ALL
intpublic void setChiralitySupport(int l)
StereoConstants.CHIRALITYSUPPORT_NONEStereoConstants.CHIRALITYSUPPORT_SELECTEDStereoConstants.CHIRALITYSUPPORT_ALL
l - the desired chirality display modepublic boolean isEzVisible()
isEZLabelsVisible()
public void setEzVisible(boolean v)
setEZLabelsVisible(boolean)
v - show (true) or hide (false) E/Zpublic boolean isEZLabelsVisible()
public void setEZLabelsVisible(boolean v)
v - show (true) or hide (false) E/Z labelspublic boolean isLonePairsVisible()
public void setLonePairsVisible(boolean v)
setLonePairsAutoCalculated(boolean) method too.
v - show (true) or hide (false) lone pairspublic boolean isLonePairsAutoCalculated()
public void setLonePairsAutoCalculated(boolean v)
v - true if lone pairs should be calculated automaticallypublic java.lang.String getCarbonVisibility()
DispOptConsts.CARBON_VIS_ON_SDispOptConsts.CARBON_VIS_INCHAIN_SDispOptConsts.CARBON_VIS_OFF_S
public void setCarbonVisibility(java.lang.String s)
DispOptConsts.CARBON_VIS_ON_SDispOptConsts.CARBON_VIS_INCHAIN_SDispOptConsts.CARBON_VIS_OFF_S
s - the stylepublic boolean isTransparent()
public void setTransparent(boolean transparency)
transparency - if true then the painting is in transparent mode.public boolean isValenceErrorvisible()
public void setValenceErrorVisible(boolean b)
b - true if the valence errors are drawnpublic java.lang.String getLigandOrderVisibility()
DispOptConsts.LIGAND_ORDER_OFF_S,
DispOptConsts.LIGAND_ORDER_ON_S,
DispOptConsts.LIGAND_ORDER_ONLY_WITH_DEFINITION_Spublic void setLigandOrderVisibility(java.lang.String s)
s - the ligand order visibility to setDispOptConsts.LIGAND_ORDER_OFF_S,
DispOptConsts.LIGAND_ORDER_ON_S,
DispOptConsts.LIGAND_ORDER_ONLY_WITH_DEFINITION_Spublic boolean isAtomPropertiesVisible()
public void setAtomPropertiesVisible(boolean v)
v - true to draw atom properties.public boolean isRLogicVisible()
public void setRLogicVisible(boolean v)
v - true to visible, false to invisiblepublic boolean isValencePropertyVisible()
public void setValencePropertyVisible(boolean v)
v - the valence property visibilitypublic boolean isLigandErrorVisible()
public void setLigandErrorVisible(boolean v)
v - the ligand error visibilitypublic java.lang.String getCoordinateBondStyle()
public void setCoordinateBondStyle(java.lang.String s)
s - "solid"/"arrow"public java.lang.String getCoordinateBondStyleAtMulticenter()
public void setCoordinateBondStyleAtMulticenter(java.lang.String s)
s - "solid"/"hashed"public void setMol(Molecule m)
m - the moleculepublic void setMolTemplate(Molecule m)
public void setMol(java.lang.String s)
throws MolFormatException
s - string containing the molecule file in some known format
MolFormatException - if the molecule string cannot be importedpublic void setDoc(MDocument d)
d - the document
public void paint(java.awt.Graphics g,
java.awt.Rectangle r)
g - the graphics context to paint onr - the rectangle in which the molecule is painted
public void paint(java.awt.Graphics2D g,
java.awt.Rectangle r)
g - the graphics context to paint onr - the rectangle in which the molecule is painted
public void paint(java.awt.Graphics2D g,
java.awt.Dimension d)
g - the graphics context to paint ond - the dimension of the painted moleculepublic double getBondWidth()
getBondSpacing()
public void setBondWidth(double w)
setBondSpacing(double)
w - the bond spacing in regular bond length units.
public void molToScreenCoords(DPoint3 molcoords,
java.awt.geom.Point2D scrcoords)
molcoords - molecular coordinates in Angstroms (input)scrcoords - graphics context coordinates in pixels (output)@Deprecated public void setExplicitH(boolean show)
show - show (true) or hide (false) explicit hydrogen atoms@Deprecated public boolean isExplicitHVisible()
@Deprecated public void setExplicitHVisible(boolean b)
b - show (true) or hide (false) explicit hydrogen atomspublic int getDisplayQuality()
public void setDisplayQuality(int q)
q - the display qualitypublic boolean isBondLengthVisible()
public void setBondLengthVisible(boolean v)
v - true - visible, false - invisiblepublic boolean isGraphInvariantVisible()
public void setGraphInvariantVisible(boolean v)
v - true - visible, false - invisiblepublic java.lang.String getDownWedge()
public void setDownWedge(java.lang.String orientation)
orientation - the down wedge orientation
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||