RDKit
Open-source cheminformatics and machine learning.
RDKit::MolDraw2D Class Referenceabstract

MolDraw2D is the base class for doing 2D renderings of molecules. More...

#include <MolDraw2D.h>

Inheritance diagram for RDKit::MolDraw2D:
RDKit::MolDraw2DCairo RDKit::MolDraw2DQt RDKit::MolDraw2DSVG RDKit::MolDraw2Dwx

Public Types

enum  OrientType {
  C = 0, N, E, S,
  W
}
 
enum  TextDrawType { TextDrawNormal = 0, TextDrawSuperscript, TextDrawSubscript }
 

Public Member Functions

 MolDraw2D (int width, int height, int panelWidth=-1, int panelHeight=-1)
 constructor for a particular size More...
 
virtual ~MolDraw2D ()
 
virtual void drawMolecule (const ROMol &mol, const std::string &legend, const std::vector< int > *highlight_atoms, const std::vector< int > *highlight_bonds, const std::map< int, DrawColour > *highlight_atom_map=NULL, const std::map< int, DrawColour > *highlight_bond_map=NULL, const std::map< int, double > *highlight_radii=NULL, int confId=-1)
 draw a single molecule More...
 
virtual void drawMolecule (const ROMol &mol, const std::vector< int > *highlight_atoms=NULL, const std::map< int, DrawColour > *highlight_map=NULL, const std::map< int, double > *highlight_radii=NULL, int confId=-1)
 
virtual void drawMolecule (const ROMol &mol, const std::string &legend, const std::vector< int > *highlight_atoms=NULL, const std::map< int, DrawColour > *highlight_map=NULL, const std::map< int, double > *highlight_radii=NULL, int confId=-1)
 
virtual void drawMolecule (const ROMol &mol, const std::vector< int > *highlight_atoms, const std::vector< int > *highlight_bonds, const std::map< int, DrawColour > *highlight_atom_map=NULL, const std::map< int, DrawColour > *highlight_bond_map=NULL, const std::map< int, double > *highlight_radii=NULL, int confId=-1)
 
virtual void drawMolecules (const std::vector< ROMol * > &mols, const std::vector< std::string > *legends=NULL, const std::vector< std::vector< int > > *highlight_atoms=NULL, const std::vector< std::vector< int > > *highlight_bonds=NULL, const std::vector< std::map< int, DrawColour > > *highlight_atom_maps=NULL, const std::vector< std::map< int, DrawColour > > *highlight_bond_maps=NULL, const std::vector< std::map< int, double > > *highlight_radii=NULL, const std::vector< int > *confIds=NULL)
 draw multiple molecules in a grid More...
 
virtual void drawReaction (const ChemicalReaction &rxn, bool highlightByReactant=false, const std::vector< DrawColour > *highlightColorsReactants=NULL, const std::vector< int > *confIds=NULL)
 draw a ChemicalReaction More...
 
virtual int width () const
 return the width of the drawing area. More...
 
virtual int height () const
 return the height of the drawing area. More...
 
virtual int panelWidth () const
 return the width of the drawing panels. More...
 
virtual int panelHeight () const
 return the height of the drawing panels. More...
 
double scale () const
 returns the drawing scale (conversion from molecular coords -> drawing More...
 
void calculateScale (int width, int height)
 calculates the drawing scale (conversion from molecular coords -> drawing More...
 
void calculateScale ()
 
void setScale (int width, int height, const Point2D &minv, const Point2D &maxv)
 explicitly sets the scaling factors for the drawing More...
 
void setOffset (int x, int y)
 sets the drawing offset (in drawing coords) More...
 
Point2D offset ()
 returns the drawing offset (in drawing coords) More...
 
virtual double fontSize () const
 returns the font size (in nolecule units) More...
 
virtual void setFontSize (double new_size)
 
virtual void setColour (const DrawColour &col)
 sets the current draw color More...
 
virtual DrawColour colour () const
 returns the current draw color More...
 
virtual void setDash (const DashPattern &patt)
 sets the current dash pattern More...
 
virtual const DashPatterndash () const
 returns the current dash pattern More...
 
virtual void setLineWidth (int width)
 sets the current line width More...
 
virtual int lineWidth () const
 returns the current line width More...
 
bool setStringDrawMode (const std::string &instring, TextDrawType &draw_mode, int &i) const
 
virtual void clearDrawing ()=0
 clears the contes of the drawingd] More...
 
virtual void drawLine (const Point2D &cds1, const Point2D &cds2)=0
 draws a line from cds1 to cds2 using the current drawing style More...
 
virtual void getStringSize (const std::string &label, double &label_width, double &label_height) const =0
 
virtual void drawString (const std::string &str, const Point2D &cds)
 drawString centres the string on cds. More...
 
virtual void drawPolygon (const std::vector< Point2D > &cds)=0
 draw a polygon More...
 
virtual void drawTriangle (const Point2D &cds1, const Point2D &cds2, const Point2D &cds3)
 draw a triange More...
 
virtual void drawEllipse (const Point2D &cds1, const Point2D &cds2)
 draw an ellipse More...
 
virtual void drawRect (const Point2D &cds1, const Point2D &cds2)
 draw a rectangle More...
 
virtual void drawAttachmentLine (const Point2D &cds1, const Point2D &cds2, const DrawColour &col, double len=1.0, unsigned int nSegments=16)
 
virtual void drawWavyLine (const Point2D &cds1, const Point2D &cds2, const DrawColour &col1, const DrawColour &col2, unsigned int nSegments=16, double vertOffset=0.05)
 draw a wavy line like that used to indicate unknown stereochemistry More...
 
virtual void tagAtoms (const ROMol &mol)
 
virtual bool fillPolys () const
 set whether or not polygons are being filled More...
 
virtual void setFillPolys (bool val)
 returns ehther or not polygons should be filled More...
 
MolDrawOptionsdrawOptions ()
 returns our current drawing options More...
 
const MolDrawOptionsdrawOptions () const
 
const std::vector< Point2D > & atomCoords () const
 
const std::vector< std::pair< std::string, OrientType > > & atomSyms () const
 returns the atomic symbols of the current molecule More...
 
Transformations
virtual Point2D getDrawCoords (const Point2D &mol_cds) const
 
virtual Point2D getDrawCoords (int at_num) const
 returns the drawing coordinates of a particular atom More...
 
virtual Point2D getAtomCoords (const std::pair< int, int > &screen_cds) const
 
virtual Point2D getAtomCoords (const std::pair< double, double > &screen_cds) const
 
virtual Point2D getAtomCoords (int at_num) const
 returns the molecular coordinates of a particular atom More...
 

Protected Member Functions

virtual void doContinuousHighlighting (const ROMol &mol, const std::vector< int > *highlight_atoms, const std::vector< int > *highlight_bonds, const std::map< int, DrawColour > *highlight_atom_map, const std::map< int, DrawColour > *highlight_bond_map, const std::map< int, double > *highlight_radii)
 
virtual void highlightCloseContacts ()
 
Point2D calcPerpendicular (const Point2D &cds1, const Point2D &cds2)
 

Detailed Description

MolDraw2D is the base class for doing 2D renderings of molecules.

Definition at line 132 of file MolDraw2D.h.

Member Enumeration Documentation

Enumerator

Definition at line 134 of file MolDraw2D.h.

Enumerator
TextDrawNormal 
TextDrawSuperscript 
TextDrawSubscript 

Definition at line 135 of file MolDraw2D.h.

Constructor & Destructor Documentation

RDKit::MolDraw2D::MolDraw2D ( int  width,
int  height,
int  panelWidth = -1,
int  panelHeight = -1 
)

constructor for a particular size

Parameters
width: width (in pixels) of the rendering
height: height (in pixels) of the rendering
panelWidth: (optional) width (in pixels) of a single panel
panelHeight: (optional) height (in pixels) of a single panel

The panelWidth and panelHeight arguments are used to provide the sizes of the panels individual molecules are drawn in when drawMolecules() is called.

virtual RDKit::MolDraw2D::~MolDraw2D ( )
inlinevirtual

Definition at line 154 of file MolDraw2D.h.

Member Function Documentation

const std::vector<Point2D>& RDKit::MolDraw2D::atomCoords ( ) const
inline

returns the coordinates of the atoms of the current molecule in molecular coordinates

Definition at line 385 of file MolDraw2D.h.

References PRECONDITION.

const std::vector<std::pair<std::string, OrientType> >& RDKit::MolDraw2D::atomSyms ( ) const
inline

returns the atomic symbols of the current molecule

Definition at line 390 of file MolDraw2D.h.

References RDKit::Drawing::detail::drawLine(), RDKit::Drawing::detail::getAtomSymbolAndOrientation(), and PRECONDITION.

Point2D RDKit::MolDraw2D::calcPerpendicular ( const Point2D cds1,
const Point2D cds2 
)
protected
void RDKit::MolDraw2D::calculateScale ( int  width,
int  height 
)

calculates the drawing scale (conversion from molecular coords -> drawing

void RDKit::MolDraw2D::calculateScale ( )
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 297 of file MolDraw2D.h.

References calculateScale().

Referenced by calculateScale().

virtual void RDKit::MolDraw2D::clearDrawing ( )
pure virtual

clears the contes of the drawingd]

Implemented in RDKit::MolDraw2Dwx, RDKit::MolDraw2DCairo, RDKit::MolDraw2DSVG, and RDKit::MolDraw2DQt.

virtual DrawColour RDKit::MolDraw2D::colour ( ) const
inlinevirtual

returns the current draw color

Definition at line 317 of file MolDraw2D.h.

Referenced by RDKit::MolDraw2Dwx::setColour().

virtual const DashPattern& RDKit::MolDraw2D::dash ( ) const
inlinevirtual

returns the current dash pattern

Definition at line 321 of file MolDraw2D.h.

virtual void RDKit::MolDraw2D::doContinuousHighlighting ( const ROMol mol,
const std::vector< int > *  highlight_atoms,
const std::vector< int > *  highlight_bonds,
const std::map< int, DrawColour > *  highlight_atom_map,
const std::map< int, DrawColour > *  highlight_bond_map,
const std::map< int, double > *  highlight_radii 
)
protectedvirtual
virtual void RDKit::MolDraw2D::drawAttachmentLine ( const Point2D cds1,
const Point2D cds2,
const DrawColour col,
double  len = 1.0,
unsigned int  nSegments = 16 
)
virtual

draw a line indicating the presence of an attachment point (normally a squiggle line perpendicular to a bond)

virtual void RDKit::MolDraw2D::drawEllipse ( const Point2D cds1,
const Point2D cds2 
)
virtual

draw an ellipse

Reimplemented in RDKit::MolDraw2DSVG.

virtual void RDKit::MolDraw2D::drawLine ( const Point2D cds1,
const Point2D cds2 
)
pure virtual

draws a line from cds1 to cds2 using the current drawing style

Implemented in RDKit::MolDraw2DCairo, RDKit::MolDraw2Dwx, RDKit::MolDraw2DSVG, and RDKit::MolDraw2DQt.

virtual void RDKit::MolDraw2D::drawMolecule ( const ROMol mol,
const std::string &  legend,
const std::vector< int > *  highlight_atoms,
const std::vector< int > *  highlight_bonds,
const std::map< int, DrawColour > *  highlight_atom_map = NULL,
const std::map< int, DrawColour > *  highlight_bond_map = NULL,
const std::map< int, double > *  highlight_radii = NULL,
int  confId = -1 
)
virtual

draw a single molecule

Parameters
mol: the molecule to draw
legend: the legend (to be drawn under the molecule)
highlight_atoms: (optional) vector of atom ids to highlight
highlight_atoms: (optional) vector of bond ids to highlight
highlight_atom_map: (optional) map from atomId -> DrawColour providing the highlight colors. If not provided the default highlight colour from drawOptions() will be used.
highlight_bond_map: (optional) map from bondId -> DrawColour providing the highlight colors. If not provided the default highlight colour from drawOptions() will be used.
highlight_radii: (optional) map from atomId -> radius (in molecule coordinates) for the radii of atomic highlights. If not provided the default value from drawOptions() will be used.
confId: (optional) conformer ID to be used for atomic coordinates
virtual void RDKit::MolDraw2D::drawMolecule ( const ROMol mol,
const std::vector< int > *  highlight_atoms = NULL,
const std::map< int, DrawColour > *  highlight_map = NULL,
const std::map< int, double > *  highlight_radii = NULL,
int  confId = -1 
)
virtual

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

virtual void RDKit::MolDraw2D::drawMolecule ( const ROMol mol,
const std::string &  legend,
const std::vector< int > *  highlight_atoms = NULL,
const std::map< int, DrawColour > *  highlight_map = NULL,
const std::map< int, double > *  highlight_radii = NULL,
int  confId = -1 
)
virtual

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

virtual void RDKit::MolDraw2D::drawMolecule ( const ROMol mol,
const std::vector< int > *  highlight_atoms,
const std::vector< int > *  highlight_bonds,
const std::map< int, DrawColour > *  highlight_atom_map = NULL,
const std::map< int, DrawColour > *  highlight_bond_map = NULL,
const std::map< int, double > *  highlight_radii = NULL,
int  confId = -1 
)
virtual

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

virtual void RDKit::MolDraw2D::drawMolecules ( const std::vector< ROMol * > &  mols,
const std::vector< std::string > *  legends = NULL,
const std::vector< std::vector< int > > *  highlight_atoms = NULL,
const std::vector< std::vector< int > > *  highlight_bonds = NULL,
const std::vector< std::map< int, DrawColour > > *  highlight_atom_maps = NULL,
const std::vector< std::map< int, DrawColour > > *  highlight_bond_maps = NULL,
const std::vector< std::map< int, double > > *  highlight_radii = NULL,
const std::vector< int > *  confIds = NULL 
)
virtual

draw multiple molecules in a grid

Parameters
mols: the molecules to draw
legends: (optional) the legends (to be drawn under the molecules)
highlight_atoms: (optional) vectors of atom ids to highlight
highlight_atoms: (optional) vectors of bond ids to highlight
highlight_atom_map: (optional) maps from atomId -> DrawColour providing the highlight colors. If not provided the default highlight colour from drawOptions() will be used.
highlight_bond_map: (optional) maps from bondId -> DrawColour providing the highlight colors. If not provided the default highlight colour from drawOptions() will be used.
highlight_radii: (optional) maps from atomId -> radius (in molecule coordinates) for the radii of atomic highlights. If not provided the default value from drawOptions() will be used.
confId: (optional) conformer IDs to be used for atomic coordinates

The panelWidth and panelHeight values will be used to determine the number of rows and columns to be drawn. Theres not a lot of error checking here, so if you provide too many molecules for the number of panes things are likely to get screweed up. If the number of rows or columns ends up being <= 1, molecules will be being drawn in a single row/column.

MolDrawOptions& RDKit::MolDraw2D::drawOptions ( )
inline

returns our current drawing options

Definition at line 379 of file MolDraw2D.h.

Referenced by RDKit::MolDraw2Dwx::clearDrawing().

const MolDrawOptions& RDKit::MolDraw2D::drawOptions ( ) const
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 381 of file MolDraw2D.h.

virtual void RDKit::MolDraw2D::drawPolygon ( const std::vector< Point2D > &  cds)
pure virtual
virtual void RDKit::MolDraw2D::drawReaction ( const ChemicalReaction rxn,
bool  highlightByReactant = false,
const std::vector< DrawColour > *  highlightColorsReactants = NULL,
const std::vector< int > *  confIds = NULL 
)
virtual

draw a ChemicalReaction

Parameters
rxn: the reaction to draw
highlightByReactant: (optional) if this is set, atoms and bonds will be highlighted based on which reactant they come from. Atom map numbers will not be shown.
highlightColorsReactants: (optional) provide a vector of colors for the reactant highlighting.
confIds: (optional) vector of confIds to use for rendering. These are numbered by reactants, then agents, then products.
virtual void RDKit::MolDraw2D::drawRect ( const Point2D cds1,
const Point2D cds2 
)
virtual

draw a rectangle

virtual void RDKit::MolDraw2D::drawString ( const std::string &  str,
const Point2D cds 
)
virtual

drawString centres the string on cds.

Reimplemented in RDKit::MolDraw2DSVG.

virtual void RDKit::MolDraw2D::drawTriangle ( const Point2D cds1,
const Point2D cds2,
const Point2D cds3 
)
virtual

draw a triange

virtual void RDKit::MolDraw2D::drawWavyLine ( const Point2D cds1,
const Point2D cds2,
const DrawColour col1,
const DrawColour col2,
unsigned int  nSegments = 16,
double  vertOffset = 0.05 
)
virtual

draw a wavy line like that used to indicate unknown stereochemistry

Reimplemented in RDKit::MolDraw2DCairo, and RDKit::MolDraw2DSVG.

virtual bool RDKit::MolDraw2D::fillPolys ( ) const
inlinevirtual

set whether or not polygons are being filled

Definition at line 374 of file MolDraw2D.h.

virtual double RDKit::MolDraw2D::fontSize ( ) const
inlinevirtual

returns the font size (in nolecule units)

Definition at line 309 of file MolDraw2D.h.

Referenced by RDKit::MolDraw2Dwx::setFontSize().

virtual Point2D RDKit::MolDraw2D::getAtomCoords ( const std::pair< int, int > &  screen_cds) const
virtual
virtual Point2D RDKit::MolDraw2D::getAtomCoords ( const std::pair< double, double > &  screen_cds) const
virtual

transform a point from drawing coordinates to the molecule coordinate system

virtual Point2D RDKit::MolDraw2D::getAtomCoords ( int  at_num) const
virtual

returns the molecular coordinates of a particular atom

virtual Point2D RDKit::MolDraw2D::getDrawCoords ( const Point2D mol_cds) const
virtual

transform a point from the molecule coordinate system into the drawing coordinate system

Referenced by RDKit::MolDraw2Dwx::drawLine(), and RDKit::MolDraw2Dwx::drawPolygon().

virtual Point2D RDKit::MolDraw2D::getDrawCoords ( int  at_num) const
virtual

returns the drawing coordinates of a particular atom

virtual void RDKit::MolDraw2D::getStringSize ( const std::string &  label,
double &  label_width,
double &  label_height 
) const
pure virtual

using the current scale, work out the size of the label in molecule coordinates.

Bear in mind when implementing this, that, for example, NH2 will appear as NH2 to convey that the 2 is a subscript, and this needs to accounted for in the width and height.

Implemented in RDKit::MolDraw2Dwx, RDKit::MolDraw2DCairo, RDKit::MolDraw2DSVG, and RDKit::MolDraw2DQt.

virtual int RDKit::MolDraw2D::height ( ) const
inlinevirtual

return the height of the drawing area.

Definition at line 284 of file MolDraw2D.h.

Referenced by RDKit::MolDraw2Dwx::clearDrawing(), and RDKit::MolDraw2Dwx::getStringSize().

virtual void RDKit::MolDraw2D::highlightCloseContacts ( )
protectedvirtual
virtual int RDKit::MolDraw2D::lineWidth ( ) const
inlinevirtual

returns the current line width

Definition at line 326 of file MolDraw2D.h.

References RDKit::Drawing::detail::drawLine().

Point2D RDKit::MolDraw2D::offset ( )
inline

returns the drawing offset (in drawing coords)

Definition at line 307 of file MolDraw2D.h.

virtual int RDKit::MolDraw2D::panelHeight ( ) const
inlinevirtual

return the height of the drawing panels.

Definition at line 288 of file MolDraw2D.h.

virtual int RDKit::MolDraw2D::panelWidth ( ) const
inlinevirtual

return the width of the drawing panels.

Definition at line 286 of file MolDraw2D.h.

double RDKit::MolDraw2D::scale ( ) const
inline

returns the drawing scale (conversion from molecular coords -> drawing

Definition at line 292 of file MolDraw2D.h.

Referenced by RDKit::MolDraw2Dwx::getStringSize(), and RDKit::MolDraw2Dwx::setFontSize().

virtual void RDKit::MolDraw2D::setColour ( const DrawColour col)
inlinevirtual

sets the current draw color

Reimplemented in RDKit::MolDraw2DCairo, RDKit::MolDraw2Dwx, RDKit::MolDraw2DSVG, and RDKit::MolDraw2DQt.

Definition at line 315 of file MolDraw2D.h.

Referenced by RDKit::MolDraw2Dwx::setColour().

virtual void RDKit::MolDraw2D::setDash ( const DashPattern patt)
inlinevirtual

sets the current dash pattern

Definition at line 319 of file MolDraw2D.h.

virtual void RDKit::MolDraw2D::setFillPolys ( bool  val)
inlinevirtual

returns ehther or not polygons should be filled

Definition at line 376 of file MolDraw2D.h.

virtual void RDKit::MolDraw2D::setFontSize ( double  new_size)
virtual

set font size in molecule coordinate units. That's probably Angstrom for RDKit.

Reimplemented in RDKit::MolDraw2DCairo, RDKit::MolDraw2DSVG, RDKit::MolDraw2Dwx, and RDKit::MolDraw2DQt.

Referenced by RDKit::MolDraw2Dwx::setFontSize().

virtual void RDKit::MolDraw2D::setLineWidth ( int  width)
inlinevirtual

sets the current line width

Definition at line 324 of file MolDraw2D.h.

void RDKit::MolDraw2D::setOffset ( int  x,
int  y 
)
inline

sets the drawing offset (in drawing coords)

Definition at line 302 of file MolDraw2D.h.

void RDKit::MolDraw2D::setScale ( int  width,
int  height,
const Point2D minv,
const Point2D maxv 
)

explicitly sets the scaling factors for the drawing

bool RDKit::MolDraw2D::setStringDrawMode ( const std::string &  instring,
TextDrawType draw_mode,
int &  i 
) const

establishes whether to put string draw mode into super- or sub-script mode based on contents of instring from i onwards. Increments i appropriately

Returns
true or false depending on whether it did something or not
virtual void RDKit::MolDraw2D::tagAtoms ( const ROMol mol)
inlinevirtual

adds additional information about the atoms to the output. Does not make sense for all renderers.

Reimplemented in RDKit::MolDraw2DSVG.

Definition at line 372 of file MolDraw2D.h.

References RDUNUSED_PARAM.

virtual int RDKit::MolDraw2D::width ( ) const
inlinevirtual

return the width of the drawing area.

Definition at line 282 of file MolDraw2D.h.

Referenced by RDKit::MolDraw2Dwx::clearDrawing(), and RDKit::MolDraw2Dwx::getStringSize().


The documentation for this class was generated from the following file: