chemaxon.marvin
Class MolPrinter

java.lang.Object
  extended by chemaxon.marvin.MolPrinter

public class MolPrinter
extends java.lang.Object

Molecule printer. This class can be used to print a molecule to a Graphics context.

Example:

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 r = new Rectangle(20, 20, 360, 200);
        g.draw(r);
        // Paint the molecule
        MolPrinter p = new MolPrinter(mol);
        p.setScale(p.maxScale(r)); // fit image in the rectangle
        p.paint(g, r);
        return im;
    }
    public static void main(String[] args) throws Exception {
        BufferedImage im = createTestImage();
        ImageIO.write(im, "png", new File("test.png"));
    }
}

Version:
5.0, 08/22/2007
Author:
Peter Csizmadia, Tamas Vertse

Constructor Summary
MolPrinter()
          Constructs a printer for an empty molecule.
MolPrinter(MDocument d)
          Constructs a printer for the specified document.
MolPrinter(MoleculeGraph m)
          Constructs a printer for the specified molecule.
 
Method Summary
 double getAtomsize()
          Get atom size in units of regular bond length.
 double getBondSpacing()
          Gets the double bond spacing.
 double getBondWidth()
          Deprecated. as of Marvin 4.1, replaced by getBondSpacing()
 int getChiralitySupport()
          Gets chirality support level.
 java.lang.String getColorScheme()
          Gets the color scheme.
 int getDispopts()
          Gets the display options.
 boolean getExplicitH()
          Are explicit hydrogens shown?
 java.lang.String getImplicitH()
          Query the display method of implicit hydrogens.
 double getMag()
          Deprecated. as of Marvin 2.9.11, replaced by getScale().
 java.lang.String getRendering()
          Gets the rendering style.
 double getScale()
          Gets the scaling factor.
 boolean isAtomSymbolsVisible()
          Gets the Atom Symbols display option.
 boolean isEzVisible()
          Gets the E/Z display option.
 boolean isSetColoringEnabled()
          Is the atom/bond set coloring enabled?
 double maxMag(java.awt.Dimension d)
          Deprecated. as of Marvin 2.9.11, replaced by maxScale(Dimension).
 double maxScale(java.awt.Dimension d)
          Calculates the maximum scaling factor for fitting the image in the specified rectangle.
 double maxScale(java.awt.Rectangle r)
          Calculates the maximum scaling factor for fitting the image in the specified rectangle.
 void paint(java.awt.Graphics g, java.awt.Rectangle r)
          Paint molecule into the center of the specified rectangle.
 void setAtomsize(double l)
          Set atom size in units of regular bond length.
 void setAtomSymbolsVisible(boolean v)
          Sets the Atom Symbols display option.
 void setBackgroundColor(java.awt.Color color)
          Sets the background color.
 void setBondSpacing(double w)
          Sets the double bond spacing.
 void setBondWidth(double w)
          Deprecated. as of Marvin 4.1, replaced by setBondSpacing(double)
 void setChiralitySupport(int l)
          Sets chirality support.
 void setColorScheme(java.lang.String s)
          Sets the color scheme.
 void setDispopts(int f)
          Sets the display options.
 void setDispopts(int f, int mask)
          Sets the display options.
 void setDoc(MDocument d)
          Sets the current document and calculates its bounds.
 void setExplicitH(boolean show)
          Sets the display method of explicit hydrogens.
 void setEzVisible(boolean v)
          Sets the E/Z display option.
 void setImplicitH(java.lang.String s)
          Sets the display method of implicit hydrogens.
 void setMag(double m)
          Deprecated. as of Marvin 2.9.11, replaced by setScale(double).
 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 setRendering(java.lang.String s)
          Sets the rendering style.
 void setScale(double m)
          Sets the scaling factor.
 void setSetColoringEnabled(boolean v)
          Enable or disable atom/bond set coloring.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MolPrinter

public MolPrinter()
Constructs a printer for an empty molecule.


MolPrinter

public MolPrinter(MoleculeGraph m)
Constructs a printer for the specified molecule.

Parameters:
m - a molecule graph
Since:
Marvin 4.1.8, 04/20/2007

MolPrinter

public MolPrinter(MDocument d)
Constructs a printer for the specified document.

Parameters:
d - the document
Since:
Marvin 4.1.8, 04/20/2007
Method Detail

getDispopts

public int getDispopts()
Gets the display options.

Returns:
display options
Since:
Marvin 2.6
See Also:
DispOptConsts

setDispopts

public void setDispopts(int f)
Sets the display options.

Parameters:
f - display options
Since:
Marvin 2.6
See Also:
DispOptConsts

setDispopts

public void setDispopts(int f,
                        int mask)
Sets the display options.

Parameters:
f - display options
mask - set bits specified here
Since:
Marvin 4.1.9, 06/05/2007
See Also:
DispOptConsts

getScale

public double getScale()
Gets the scaling factor.

Since:
Marvin 2.9.11

setScale

public void setScale(double m)
Sets the scaling factor.

Since:
Marvin 2.9.11

maxScale

public double maxScale(java.awt.Rectangle r)
Calculates the maximum scaling factor for fitting the image in the specified rectangle.

Parameters:
r - the rectangle
Since:
Marvin 4.1.8, 04/20/2007

maxScale

public double maxScale(java.awt.Dimension d)
Calculates the maximum scaling factor for fitting the image in the specified rectangle.

Parameters:
d - the size of the rectangle

getAtomsize

public double getAtomsize()
Get atom size in units of regular bond length.


setAtomsize

public void setAtomsize(double l)
Set atom size in units of regular bond length.


getBondSpacing

public double getBondSpacing()
Gets the double bond spacing.

Returns:
the bond width in C-C bond length units.
Since:
Marvin 4.1, 10/19/2005

setBondSpacing

public void setBondSpacing(double w)
Sets the double bond spacing.

width = w*1.54 Å = w*scale pixels

Parameters:
w - the bond width in C-C bond length units.
Since:
Marvin 4.1, 10/19/2005

getImplicitH

public java.lang.String getImplicitH()
Query the display method of implicit hydrogens.

Returns:
IMPLICITH_OFF_S, IMPLICITH_HETERO_S, IMPLICITH_HETEROTERM_S or IMPLICITH_ALL_S.
Since:
Marvin 2.9.11
See Also:
DispOptConsts.IMPLICITH_LEVELS

setImplicitH

public void setImplicitH(java.lang.String s)
Sets the display method of implicit hydrogens.

Parameters:
s - IMPLICITH_OFF_S, IMPLICITH_HETERO_S, IMPLICITH_HETEROTERM_S or IMPLICITH_ALL_S.
Since:
Marvin 2.9.11
See Also:
DispOptConsts.IMPLICITH_LEVELS

getColorScheme

public java.lang.String getColorScheme()
Gets the color scheme.

Returns:
MONO_SCHEME_S, CPK_SCHEME_S, SHAPELY_SCHEME_S or GROUP_SCHEME_S.
Since:
Marvin 2.9.11
See Also:
DispOptConsts.COLOR_SCHEMES

setColorScheme

public void setColorScheme(java.lang.String s)
Sets the color scheme.

Parameters:
s - MONO_SCHEME_S, CPK_SCHEME_S, SHAPELY_SCHEME_S or GROUP_SCHEME_S.
Since:
Marvin 2.9.11
See Also:
DispOptConsts.COLOR_SCHEMES

isSetColoringEnabled

public boolean isSetColoringEnabled()
Is the atom/bond set coloring enabled?

Returns:
true if enabled, false if disabled
Since:
Marvin 3.3

setSetColoringEnabled

public void setSetColoringEnabled(boolean v)
Enable or disable atom/bond set coloring.

Parameters:
v - true to enable, false to disable
Since:
Marvin 3.3

getRendering

public java.lang.String getRendering()
Gets the rendering style.

Returns:
WIREFRAME_RENDERING_S, WIREKNOBS_RENDERING_S, STICKS_RENDERING_S, BALLSTICK_RENDERING_S or SPACEFILL_RENDERING_S.
Since:
Marvin 2.9.11
See Also:
DispOptConsts.RENDERING_STYLES

setRendering

public void setRendering(java.lang.String s)
Sets the rendering style.

Parameters:
s - WIREFRAME_RENDERING_S, WIREKNOBS_RENDERING_S, STICKS_RENDERING_S, BALLSTICK_RENDERING_S or SPACEFILL_RENDERING_S.
Since:
Marvin 2.9.11
See Also:
DispOptConsts.RENDERING_STYLES

setBackgroundColor

public void setBackgroundColor(java.awt.Color color)
Sets the background color.

Parameters:
color - the bakcground color
Since:
Marvin 4.1.13

isAtomSymbolsVisible

public boolean isAtomSymbolsVisible()
Gets the Atom Symbols display option.

Returns:
show (true) or hide (false)
Since:
Marvin 3.3.3

setAtomSymbolsVisible

public void setAtomSymbolsVisible(boolean v)
Sets the Atom Symbols display option.

Parameters:
v - show (true) or hide (false) Atom Symbols
Since:
Marvin 3.3.3

getExplicitH

public boolean getExplicitH()
Are explicit hydrogens shown?

Returns:
show (true) or hide (false)
Since:
Marvin 3.3.3

setExplicitH

public void setExplicitH(boolean show)
Sets the display method of explicit hydrogens.

Parameters:
show - (true) or hide (false) explicit hydrogens
Since:
Marvin 3.3.3

getChiralitySupport

public int getChiralitySupport()
Gets chirality support level.

Returns:
the chirality support level
Since:
Marvin 3.3.3
See Also:
StereoConstants.CHIRALITYSUPPORT_NONE, StereoConstants.CHIRALITYSUPPORT_SELECTED, StereoConstants.CHIRALITYSUPPORT_ALL

setChiralitySupport

public void setChiralitySupport(int l)
Sets chirality support. No molecules, selected (if ABSC flag set) or all molecules.

Parameters:
l - chirality support level
Since:
Marvin 3.3.3
See Also:
StereoConstants.CHIRALITYSUPPORT_NONE, StereoConstants.CHIRALITYSUPPORT_SELECTED, StereoConstants.CHIRALITYSUPPORT_ALL

isEzVisible

public boolean isEzVisible()
Gets the E/Z display option.

Returns:
show (true) or hide (false)
Since:
Marvin 3.3.3

setEzVisible

public void setEzVisible(boolean v)
Sets the E/Z display option.

Parameters:
v - show (true) or hide (false) E/Z
Since:
Marvin 3.3.3

setMol

public void setMol(Molecule m)
Sets the current molecule and calculate its bounds.

Parameters:
m - the molecule

setMol

public void setMol(java.lang.String s)
            throws MolFormatException
Sets the current molecule and calculate its bounds.

Parameters:
s - string containing the molecule file in some known format
Throws:
MolFormatException - if the molecule string cannot be imported

setDoc

public void setDoc(MDocument d)
Sets the current document and calculates its bounds.

Parameters:
d - the document
Since:
Marvin 4.1.8, 04/20/2007

paint

public void paint(java.awt.Graphics g,
                  java.awt.Rectangle r)
Paint molecule into the center of the specified rectangle.

Parameters:
g - the graphics context
r - the rectangle

getMag

public double getMag()
Deprecated. as of Marvin 2.9.11, replaced by getScale().


setMag

public void setMag(double m)
Deprecated. as of Marvin 2.9.11, replaced by setScale(double).


maxMag

public double maxMag(java.awt.Dimension d)
Deprecated. as of Marvin 2.9.11, replaced by maxScale(Dimension).


getBondWidth

public double getBondWidth()
Deprecated. as of Marvin 4.1, replaced by getBondSpacing()

Gets bond spacing.

Returns:
the bond spacing in bond length units

setBondWidth

public void setBondWidth(double w)
Deprecated. as of Marvin 4.1, replaced by setBondSpacing(double)

Sets bond spacing.

Parameters:
w - bond spacing in bond length units