RDKit
Open-source cheminformatics and machine learning.
MolDraw2D.h
Go to the documentation of this file.
1 //
2 // @@ All Rights Reserved @@
3 // This file is part of the RDKit.
4 // The contents are covered by the terms of the BSD license
5 // which is included in the file license.txt, found at the root
6 // of the RDKit source tree.
7 //
8 // Original author: David Cosgrove (AstraZeneca)
9 // 27th May 2014
10 //
11 // This class makes a 2D drawing of an RDKit molecule.
12 // It draws heavily on $RDBASE/GraphMol/MolDrawing/MolDrawing.h.
13 // One purpose of this is to make it easier to overlay annotations on top of
14 // the molecule drawing, which is difficult to do from the output of
15 // MolDrawing.h
16 // The class design philosophy echoes a standard one:
17 // a virtual base class defines the interface and does all
18 // the heavy lifting and concrete derived classes implement
19 // library-specific drawing code such as drawing lines, writing strings
20 // etc.
21 
22 #include <RDGeneral/export.h>
23 #ifndef RDKITMOLDRAW2D_H
24 #define RDKITMOLDRAW2D_H
25 
26 #include <vector>
27 
28 #include <Geometry/point.h>
29 #include <GraphMol/RDKitBase.h>
31 
32 // ****************************************************************************
33 using RDGeom::Point2D;
34 
35 namespace RDKit {
36 
37 struct DrawColour {
38  double r = 0.0, g = 0.0, b = 0.0, a = 1.0;
39  DrawColour() = default;
40  DrawColour(double r, double g, double b, double a = 1.0)
41  : r(r), g(g), b(b), a(a){};
42  bool operator==(const DrawColour &other) const {
43  return r == other.r && g == other.g && b == other.b && a == other.a;
44  }
45  bool feq(const DrawColour &other, double tol = 0.001,
46  bool ignoreAlpha = true) const {
47  return fabs(r - other.r) <= tol && fabs(g - other.g) <= tol &&
48  fabs(b - other.b) <= tol &&
49  (ignoreAlpha || fabs(a - other.a) <= tol);
50  };
51  DrawColour operator+(const DrawColour &other) const {
52  return {r + other.r, g + other.g, b + other.b, a + other.a};
53  }
54  DrawColour operator-(const DrawColour &other) const {
55  return {r - other.r, g - other.g, b - other.b, a - other.a};
56  }
57  DrawColour operator/(double v) const {
58  PRECONDITION(v != 0.0, "divide by zero");
59  return {r / v, g / v, b / v, a / v};
60  }
61  DrawColour operator*(double v) const { return {r * v, g * v, b * v, a * v}; }
62 };
63 
64 // for holding dimensions of the rectangle round a string.
65 struct StringRect {
67  double width_, height_;
68  int clash_score_; // rough measure of how badly it clashed with other things
69  // lower is better, 0 is no clash.
71  : centre_(0.0, 0.0), width_(0.0), height_(0.0), clash_score_(0) {}
72  StringRect(const Point2D &in_cds)
73  : centre_(in_cds), width_(0.0), height_(0.0), clash_score_(0) {}
74  // tl is top, left; br is bottom, right
75  void calcCorners(Point2D &tl, Point2D &tr, Point2D &br, Point2D &bl) const {
76  double wb2 = width_ / 2.0;
77  double hb2 = height_ / 2.0;
78  tl = Point2D(centre_.x - wb2, centre_.y + hb2);
79  tr = Point2D(centre_.x + wb2, centre_.y + hb2);
80  br = Point2D(centre_.x + wb2, centre_.y - hb2);
81  bl = Point2D(centre_.x - wb2, centre_.y - hb2);
82  }
83  bool doesItIntersect(const StringRect &other) const {
84  if (fabs(centre_.x - other.centre_.x) < (width_ + other.width_) / 2.0 &&
85  fabs(centre_.y - other.centre_.y) < (height_ + other.height_) / 2.0) {
86  return true;
87  }
88  return false;
89  }
90 };
91 
92 typedef std::map<int, DrawColour> ColourPalette;
93 typedef std::vector<unsigned int> DashPattern;
94 
95 inline void assignDefaultPalette(ColourPalette &palette) {
96  palette.clear();
97  palette[-1] = DrawColour(0, 0, 0);
98  palette[0] = DrawColour(0.5, 0.5, 0.5);
99  palette[1] = palette[6] = DrawColour(0.0, 0.0, 0.0);
100  palette[7] = DrawColour(0.0, 0.0, 1.0);
101  palette[8] = DrawColour(1.0, 0.0, 0.0);
102  palette[9] = DrawColour(0.2, 0.8, 0.8);
103  palette[15] = DrawColour(1.0, 0.5, 0.0);
104  palette[16] = DrawColour(0.8, 0.8, 0.0);
105  palette[17] = DrawColour(0.0, 0.802, 0.0);
106  palette[35] = DrawColour(0.5, 0.3, 0.1);
107  palette[53] = DrawColour(0.63, 0.12, 0.94);
108 };
109 
110 inline void assignBWPalette(ColourPalette &palette) {
111  palette.clear();
112  palette[-1] = DrawColour(0, 0, 0);
113 };
114 
116  bool atomLabelDeuteriumTritium =
117  false; // toggles replacing 2H with D and 3H with T
118  bool dummiesAreAttachments = false; // draws "breaks" at dummy atoms
119  bool circleAtoms = true; // draws circles under highlighted atoms
120  DrawColour highlightColour{1, 0.5, 0.5}; // default highlight color
121  bool continuousHighlight = true; // highlight by drawing an outline
122  // *underneath* the molecule
123  bool fillHighlights = true; // fill the areas used to highlight atoms and
124  // atom regions
125  double highlightRadius = 0.3; // default if nothing given for a particular
126  // atom. units are "Angstrom"
127  int flagCloseContactsDist = 3; // if positive, this will be used as a cutoff
128  // (in pixels) for highlighting close contacts
129  bool includeAtomTags =
130  false; // toggles inclusion of atom tags in the output. does
131  // not make sense for all renderers.
132  bool clearBackground = true; // toggles clearing the background before
133  // drawing a molecule
134  DrawColour backgroundColour{
135  1, 1, 1}; // color to be used while clearing the background
136  int legendFontSize = 12; // font size (in pixels) to be used for the legend
137  // (if present)
138  int maxFontSize = 40; // maximum size in pixels for font in drawn molecule.
139  // -1 means no max.
140  double annotationFontScale = 0.75; // scales font relative to atom labels for
141  // atom and bond annotation.
142  DrawColour legendColour{0, 0,
143  0}; // color to be used for the legend (if present)
144  double multipleBondOffset = 0.15; // offset (in Angstrom) for the extra lines
145  // in a multiple bond
146  double padding =
147  0.05; // fraction of empty space to leave around the molecule
148  double additionalAtomLabelPadding = 0.0; // additional padding to leave
149  // around atom labels. Expressed as
150  // a fraction of the font size.
151  std::map<int, std::string> atomLabels; // replacement labels for atoms
152  std::vector<std::vector<int>> atomRegions; // regions
153  DrawColour symbolColour{
154  0, 0, 0}; // color to be used for the symbols and arrows in reactions
155  int bondLineWidth = -1; // if positive, this overrides the default line width
156  // when drawing bonds
157  int highlightBondWidthMultiplier = 8; // what to multiply standard bond width
158  // by for highlighting.
159  bool prepareMolsBeforeDrawing = true; // call prepareMolForDrawing() on each
160  // molecule passed to drawMolecules()
161  std::vector<DrawColour> highlightColourPalette; // defining 10 default colors
162  // for highlighting atoms and bonds
163  // or reactants in a reactions
164  ColourPalette atomColourPalette; // the palette used to assign
165  // colors to atoms based on
166  // atomic number.
167  double fixedScale =
168  -1.0; // fixes scale to this fraction of draw window width, so
169  // an average bond is this fraction of the width. If
170  // scale comes out smaller than this, reduces scale, but
171  // won't make it larger. The default of -1.0 means no fix.
172  double fixedBondLength =
173  -1.0; // fixes the bond length (and hence the scale) to
174  // always be this number of pixels. Assuming a bond
175  // length in coordinates is 1, as is normal. If
176  // scale comes out smaller than this, reduces scale,
177  // but won't make it larger. The default -1.0 means no
178  // fix. If both fixedScale and fixedBondLength are >
179  // 0.0, fixedScale wins.
180  double rotate = 0.0; // angle in degrees to rotate coords by about centre
181  // before drawing.
182  bool addAtomIndices = false; // adds atom indices to drawings.
183  bool addBondIndices = false; // adds bond indices to drawings.
184 
185  bool addStereoAnnotation = false; // adds E/Z and R/S to drawings.
186  bool atomHighlightsAreCircles = false; // forces atom highlights always to be
187  // circles. Default (false) is to put
188  // ellipses round longer labels.
189  bool centreMoleculesBeforeDrawing = false; // moves the centre of the drawn
190  // molecule to (0,0)
191 
193  highlightColourPalette.emplace_back(
194  DrawColour(1., 1., .67)); // popcorn yellow
195  highlightColourPalette.emplace_back(DrawColour(1., .8, .6)); // sand
196  highlightColourPalette.emplace_back(
197  DrawColour(1., .71, .76)); // light pink
198  highlightColourPalette.emplace_back(
199  DrawColour(.8, 1., .8)); // offwhitegreen
200  highlightColourPalette.emplace_back(DrawColour(.87, .63, .87)); // plum
201  highlightColourPalette.emplace_back(
202  DrawColour(.76, .94, .96)); // pastel blue
203  highlightColourPalette.emplace_back(
204  DrawColour(.67, .67, 1.)); // periwinkle
205  highlightColourPalette.emplace_back(DrawColour(.64, .76, .34)); // avocado
206  highlightColourPalette.emplace_back(
207  DrawColour(.56, .93, .56)); // light green
208  highlightColourPalette.emplace_back(DrawColour(.20, .63, .79)); // peacock
209  assignDefaultPalette(atomColourPalette);
210  };
211 };
212 
213 //! MolDraw2D is the base class for doing 2D renderings of molecules
215  public:
216  enum class OrientType: unsigned char { C = 0, N, E, S, W };
217  // for aligning the drawing of text to the passed in coords.
218  typedef enum { START, MIDDLE, END } AlignType;
219  typedef enum {
220  TextDrawNormal = 0,
222  TextDrawSubscript
223  } TextDrawType;
224 
225  //! constructor for a particular size
226  /*!
227  \param width : width (in pixels) of the rendering
228  \param height : height (in pixels) of the rendering
229  \param panelWidth : (optional) width (in pixels) of a single panel
230  \param panelHeight : (optional) height (in pixels) of a single panel
231 
232  The \c panelWidth and \c panelHeight arguments are used to provide the
233  sizes of the panels individual molecules are drawn in when
234  \c drawMolecules() is called.
235  */
236  MolDraw2D(int width, int height, int panelWidth, int panelHeight)
237  : needs_scale_(true),
238  width_(width),
239  height_(height),
240  panel_width_(panelWidth > 0 ? panelWidth : width),
241  panel_height_(panelHeight > 0 ? panelHeight : height),
242  scale_(1.0),
243  x_trans_(0.0),
244  y_trans_(0.0),
245  x_offset_(0),
246  y_offset_(0),
247  font_size_(0.5),
248  curr_width_(2),
249  fill_polys_(true),
250  activeMolIdx_(-1) {}
251 
252  virtual ~MolDraw2D() {}
253 
254  //! draw a single molecule
255  /*!
256  \param mol : the molecule to draw
257  \param legend : the legend (to be drawn under the molecule)
258  \param highlight_atoms : (optional) vector of atom ids to highlight
259  \param highlight_atoms : (optional) vector of bond ids to highlight
260  \param highlight_atom_map : (optional) map from atomId -> DrawColour
261  providing the highlight colors. If not provided the default highlight colour
262  from \c drawOptions() will be used.
263  \param highlight_bond_map : (optional) map from bondId -> DrawColour
264  providing the highlight colors. If not provided the default highlight colour
265  from \c drawOptions() will be used.
266  \param highlight_radii : (optional) map from atomId -> radius (in molecule
267  coordinates) for the radii of atomic highlights. If not provided the default
268  value from \c drawOptions() will be used.
269  \param confId : (optional) conformer ID to be used for atomic
270  coordinates
271 
272  */
273  virtual void drawMolecule(
274  const ROMol &mol, const std::string &legend,
275  const std::vector<int> *highlight_atoms,
276  const std::vector<int> *highlight_bonds,
277  const std::map<int, DrawColour> *highlight_atom_map = nullptr,
278  const std::map<int, DrawColour> *highlight_bond_map = nullptr,
279  const std::map<int, double> *highlight_radii = nullptr, int confId = -1);
280 
281  //! \overload
282  virtual void drawMolecule(
283  const ROMol &mol, const std::vector<int> *highlight_atoms = nullptr,
284  const std::map<int, DrawColour> *highlight_map = nullptr,
285  const std::map<int, double> *highlight_radii = nullptr, int confId = -1);
286 
287  //! \overload
288  virtual void drawMolecule(
289  const ROMol &mol, const std::string &legend,
290  const std::vector<int> *highlight_atoms = nullptr,
291  const std::map<int, DrawColour> *highlight_map = nullptr,
292  const std::map<int, double> *highlight_radii = nullptr, int confId = -1);
293 
294  //! \overload
295  virtual void drawMolecule(
296  const ROMol &mol, const std::vector<int> *highlight_atoms,
297  const std::vector<int> *highlight_bonds,
298  const std::map<int, DrawColour> *highlight_atom_map = nullptr,
299  const std::map<int, DrawColour> *highlight_bond_map = nullptr,
300  const std::map<int, double> *highlight_radii = nullptr, int confId = -1);
301 
302  //! draw molecule with multiple colours allowed per atom.
303  /*!
304  \param mol : the molecule to draw
305  \param legend : the legend (to be drawn under the molecule)
306  \param highlight_atom_map : map from atomId -> DrawColours
307  providing the highlight colours.
308  \param highlight_bond_map : map from bondId -> DrawColours
309  providing the highlight colours.
310  \param highlight_radii : map from atomId -> radius (in molecule
311  coordinates) for the radii of atomic highlights. If not provided for an
312  index, the default value from \c drawOptions() will be used.
313  \param confId : (optional) conformer ID to be used for atomic
314  coordinates
315  */
317  const ROMol &mol, const std::string &legend,
318  const std::map<int, std::vector<DrawColour>> &highlight_atom_map,
319  const std::map<int, std::vector<DrawColour>> &highlight_bond_map,
320  const std::map<int, double> &highlight_radii,
321  const std::map<int, int> &highlight_linewidth_multipliers,
322  int confId = -1);
323 
324  //! draw multiple molecules in a grid
325  /*!
326  \param mols : the molecules to draw
327  \param legends : (optional) the legends (to be drawn under the
328  molecules)
329  \param highlight_atoms : (optional) vectors of atom ids to highlight
330  \param highlight_atoms : (optional) vectors of bond ids to highlight
331  \param highlight_atom_map : (optional) maps from atomId -> DrawColour
332  providing the highlight colors. If not provided the default highlight colour
333  from \c drawOptions() will be used.
334  \param highlight_bond_map : (optional) maps from bondId -> DrawColour
335  providing the highlight colors. If not provided the default highlight colour
336  from \c drawOptions() will be used.
337  \param highlight_radii : (optional) maps from atomId -> radius (in molecule
338  coordinates) for the radii of atomic highlights. If not provided the default
339  value from \c drawOptions() will be used.
340  \param confId : (optional) conformer IDs to be used for atomic
341  coordinates
342 
343  The \c panelWidth and \c panelHeight values will be used to determine the
344  number of rows and columns to be drawn. Theres not a lot of error checking
345  here, so if you provide too many molecules for the number of panes things
346  are likely to get screwed up.
347  If the number of rows or columns ends up being <= 1, molecules will be
348  being drawn in a single row/column.
349  */
350  virtual void drawMolecules(
351  const std::vector<ROMol *> &mols,
352  const std::vector<std::string> *legends = nullptr,
353  const std::vector<std::vector<int>> *highlight_atoms = nullptr,
354  const std::vector<std::vector<int>> *highlight_bonds = nullptr,
355  const std::vector<std::map<int, DrawColour>> *highlight_atom_maps =
356  nullptr,
357  const std::vector<std::map<int, DrawColour>> *highlight_bond_maps =
358  nullptr,
359  const std::vector<std::map<int, double>> *highlight_radii = nullptr,
360  const std::vector<int> *confIds = nullptr);
361 
362  //! draw a ChemicalReaction
363  /*!
364  \param rxn : the reaction to draw
365  \param highlightByReactant : (optional) if this is set, atoms and bonds will
366  be highlighted based on which reactant they come from. Atom map numbers
367  will not be shown.
368  \param highlightColorsReactants : (optional) provide a vector of colors for
369  the
370  reactant highlighting.
371  \param confIds : (optional) vector of confIds to use for rendering. These
372  are numbered by reactants, then agents, then products.
373  */
374  virtual void drawReaction(
375  const ChemicalReaction &rxn, bool highlightByReactant = false,
376  const std::vector<DrawColour> *highlightColorsReactants = nullptr,
377  const std::vector<int> *confIds = nullptr);
378 
379  //! \name Transformations
380  //@{
381  // transform a set of coords in the molecule's coordinate system
382  // to drawing system coordinates and vice versa. Note that the coordinates
383  // have
384  // the origin in the top left corner, which is how Qt and Cairo have it, no
385  // doubt a holdover from X Windows. This means that a higher y value will be
386  // nearer the bottom of the screen. This doesn't really matter except when
387  // doing text superscripts and subscripts.
388 
389  //! transform a point from the molecule coordinate system into the drawing
390  //! coordinate system
391  virtual Point2D getDrawCoords(const Point2D &mol_cds) const;
392  //! returns the drawing coordinates of a particular atom
393  virtual Point2D getDrawCoords(int at_num) const;
394  virtual Point2D getAtomCoords(const std::pair<int, int> &screen_cds) const;
395  //! transform a point from drawing coordinates to the molecule coordinate
396  //! system
398  const std::pair<double, double> &screen_cds) const;
399  //! returns the molecular coordinates of a particular atom
400  virtual Point2D getAtomCoords(int at_num) const;
401  //@}
402  //! return the width of the drawing area.
403  virtual int width() const { return width_; }
404  //! return the height of the drawing area.
405  virtual int height() const { return height_; }
406  //! return the width of the drawing panels.
407  virtual int panelWidth() const { return panel_width_; }
408  //! return the height of the drawing panels.
409  virtual int panelHeight() const { return panel_height_; }
410 
411  //! returns the drawing scale (conversion from molecular coords -> drawing
412  // coords)
413  double scale() const { return scale_; }
414  //! calculates the drawing scale (conversion from molecular coords -> drawing
415  // coords)
416  void calculateScale(int width, int height,
417  const std::vector<int> *highlight_atoms = nullptr,
418  const std::map<int, double> *highlight_radii = nullptr);
419  //! overload
420  // calculate a single scale that will suit all molecules. For use by
421  // drawMolecules primarily.
422  void calculateScale(int width, int height, const std::vector<ROMol *> &mols,
423  const std::vector<std::vector<int>> *highlight_atoms,
424  const std::vector<std::map<int, double>> *highlight_radii,
425  const std::vector<int> *confIds,
426  std::vector<std::unique_ptr<RWMol>> &tmols);
427  // set [xy]_trans_ to the middle of the draw area in molecule coords
428  void centrePicture(int width, int height);
429 
430  //! explicitly sets the scaling factors for the drawing
431  void setScale(int width, int height, const Point2D &minv,
432  const Point2D &maxv);
433  //! sets the drawing offset (in drawing coords)
434  void setOffset(int x, int y) {
435  x_offset_ = x;
436  y_offset_ = y;
437  }
438  //! returns the drawing offset (in drawing coords)
439  Point2D offset() const { return Point2D(x_offset_, y_offset_); }
440 
441  //! returns the minimum point of the drawing (in molecular coords)
442  Point2D minPt() const { return Point2D(x_min_, y_min_); }
443  //! returns the width and height of the grid (in molecular coords)
444  Point2D range() const { return Point2D(x_range_, y_range_); }
445 
446  //! returns the font size (in molecule units)
447  virtual double fontSize() const { return font_size_; }
448  double drawFontSize() const;
449 
450  //! set font size in molecule coordinate units. That's probably Angstrom for
451  //! RDKit.
452  virtual void setFontSize(double new_size);
453 
454  //! sets the current draw color
455  virtual void setColour(const DrawColour &col) { curr_colour_ = col; }
456  //! returns the current draw color
457  virtual DrawColour colour() const { return curr_colour_; }
458  //! sets the current dash pattern
459  virtual void setDash(const DashPattern &patt) { curr_dash_ = patt; }
460  //! returns the current dash pattern
461  virtual const DashPattern &dash() const { return curr_dash_; }
462 
463  //! sets the current line width
464  virtual void setLineWidth(int width) { curr_width_ = width; }
465  //! returns the current line width
466  virtual int lineWidth() const { return curr_width_; }
467 
468  //! establishes whether to put string draw mode into super- or sub-script
469  //! mode based on contents of instring from i onwards. Increments i
470  //! appropriately
471  //! \returns true or false depending on whether it did something or not
472  bool setStringDrawMode(const std::string &instring, TextDrawType &draw_mode,
473  int &i) const;
474  //! clears the contents of the drawing
475  virtual void clearDrawing() = 0;
476  //! draws a line from \c cds1 to \c cds2 using the current drawing style
477  virtual void drawLine(const Point2D &cds1, const Point2D &cds2) = 0;
478 
479  //! using the current scale, work out the size of the label in molecule
480  //! coordinates.
481  /*!
482  Bear in mind when implementing this, that, for example, NH2 will appear as
483  NH<sub>2</sub> to convey that the 2 is a subscript, and this needs to
484  accounted for in the width and height.
485  */
486  virtual void getStringSize(const std::string &label, double &label_width,
487  double &label_height) const = 0;
488  // get the overall size of the label, allowing for it being split
489  // into pieces according to orientation.
490  void getLabelSize(const std::string &label, OrientType orient,
491  double &label_width, double &label_height) const;
492  //! drawString centres the string on cds.
493  virtual void drawString(const std::string &str, const Point2D &cds);
494  // unless the specific drawer over-rides this overload, it will just call
495  // the first one. SVG for one needs the alignment flag.
496  virtual void drawString(const std::string &str, const Point2D &cds,
497  AlignType align);
498  // draw the vector of strings from cds putting the nth+1 at the end of
499  // the nth. Aligns them according to OrientType.
500  virtual void drawStrings(const std::vector<std::string> &labels,
501  const Point2D &cds, OrientType orient);
502  // calculate where to put the centre of the str so that the first/last
503  // character, which might have <sub> or <sup> labels, is at in_cds.
504  // Normally, the whole string would be centred on in_cds.
505  // If align is 0, it's left aligned, 1 it's right aligned, anything
506  // else and it's not done at all.
507  virtual void alignString(const std::string &str,
508  const std::string &align_char, int align,
509  const Point2D &in_cds, Point2D &out_cds) const;
510 
511  //! draw a polygon. Note that if fillPolys() returns false, it
512  //! doesn't close the path. If you want it to in that case, you
513  //! do it explicitly yourself.
514  virtual void drawPolygon(const std::vector<Point2D> &cds) = 0;
515  //! draw a triangle
516  virtual void drawTriangle(const Point2D &cds1, const Point2D &cds2,
517  const Point2D &cds3);
518  //! draw an ellipse
519  virtual void drawEllipse(const Point2D &cds1, const Point2D &cds2);
520  // draw the arc of a circle between ang1 and ang2. Note that 0 is
521  // at 3 o-clock and 90 at 12 o'clock as you'd expect from your maths.
522  // ang2 must be > ang1 - it won't draw backwards. This is not enforced.
523  // Angles in degrees.
524  virtual void drawArc(const Point2D &centre, double radius, double ang1,
525  double ang2);
526  // and a general ellipse form
527  virtual void drawArc(const Point2D &centre, double xradius, double yradius,
528  double ang1, double ang2);
529  //! draw a rectangle
530  virtual void drawRect(const Point2D &cds1, const Point2D &cds2);
531  //! draw a line indicating the presence of an attachment point (normally a
532  //! squiggle line perpendicular to a bond)
533  virtual void drawAttachmentLine(const Point2D &cds1, const Point2D &cds2,
534  const DrawColour &col, double len = 1.0,
535  unsigned int nSegments = 16);
536  //! draw a wavy line like that used to indicate unknown stereochemistry
537  virtual void drawWavyLine(const Point2D &cds1, const Point2D &cds2,
538  const DrawColour &col1, const DrawColour &col2,
539  unsigned int nSegments = 16,
540  double vertOffset = 0.05);
541  //! adds additional information about the atoms to the output. Does not make
542  //! sense for all renderers.
543  virtual void tagAtoms(const ROMol &mol) { RDUNUSED_PARAM(mol); };
544  //! set whether or not polygons are being filled
545  virtual bool fillPolys() const { return fill_polys_; }
546  //! returns either or not polygons should be filled
547  virtual void setFillPolys(bool val) { fill_polys_ = val; }
548 
549  //! returns our current drawing options
550  MolDrawOptions &drawOptions() { return options_; }
551  //! \overload
552  const MolDrawOptions &drawOptions() const { return options_; }
553 
554  //! returns the coordinates of the atoms of the current molecule in molecular
555  //! coordinates
556  const std::vector<Point2D> &atomCoords() const {
557  PRECONDITION(activeMolIdx_ >= 0, "no index");
558  return at_cds_[activeMolIdx_];
559  };
560  //! returns the atomic symbols of the current molecule
561  const std::vector<std::pair<std::string, OrientType>> &atomSyms() const {
562  PRECONDITION(activeMolIdx_ >= 0, "no index");
563  return atom_syms_[activeMolIdx_];
564  };
565  //! Draw an arrow with either lines or a filled head (when asPolygon is true)
566  virtual void drawArrow(const Point2D &cds1, const Point2D &cds2,
567  bool asPolygon = false, double frac = 0.05,
568  double angle = M_PI / 6);
569 
570  // reset to default values all the things the c'tor sets
571  void tabulaRasa();
572 
573  virtual bool supportsAnnotations() { return true; }
574 
575  private:
576  bool needs_scale_;
577  int width_, height_, panel_width_, panel_height_;
578  double scale_;
579  double x_min_, y_min_, x_range_, y_range_;
580  double x_trans_, y_trans_;
581  int x_offset_, y_offset_; // translation in screen coordinates
582  // font_size_ in molecule coordinate units. Default 0.5 (a bit bigger
583  // than the default width of a double bond)
584  double font_size_;
585  int curr_width_;
586  bool fill_polys_;
587  int activeMolIdx_;
588 
589  DrawColour curr_colour_;
590  DashPattern curr_dash_;
591  MolDrawOptions options_;
592 
593  std::vector<std::vector<Point2D>> at_cds_; // from mol
594  std::vector<std::vector<int>> atomic_nums_;
595  std::vector<std::vector<std::pair<std::string, OrientType>>> atom_syms_;
596  std::vector<std::vector<std::shared_ptr<StringRect>>> atom_notes_;
597  std::vector<std::vector<std::shared_ptr<StringRect>>> bond_notes_;
598 
599  Point2D bbox_[2];
600 
601  // draw the char, with the bottom left hand corner at cds
602  virtual void drawChar(char c, const Point2D &cds) = 0;
603 
604  // return a DrawColour based on the contents of highlight_atoms or
605  // highlight_map, falling back to atomic number by default
606  DrawColour getColour(
607  int atom_idx, const std::vector<int> *highlight_atoms = nullptr,
608  const std::map<int, DrawColour> *highlight_map = nullptr);
609  DrawColour getColourByAtomicNum(int atomic_num);
610 
611  // set the system up to draw the molecule including calculating the scale.
612  std::unique_ptr<RWMol> setupDrawMolecule(
613  const ROMol &mol, const std::vector<int> *highlight_atoms,
614  const std::map<int, double> *highlight_radii, int confId, int width,
615  int height);
616  // copies of atom coords, atomic symbols etc. are stashed for convenience.
617  // these put empty collections onto the stack and pop the off when done.
618  void pushDrawDetails();
619  void popDrawDetails();
620 
621  // do the initial setup bits for drawing a molecule.
622  std::unique_ptr<RWMol> setupMoleculeDraw(
623  const ROMol &mol, const std::vector<int> *highlight_atoms,
624  const std::map<int, double> *highlight_radii, int confId = -1);
625  // if bond_colours is given, it must have an entry for every bond, and it
626  // trumps everything else. First in pair is bonds begin atom, second is
627  // end atom.
628  void drawBonds(const ROMol &draw_mol,
629  const std::vector<int> *highlight_atoms = nullptr,
630  const std::map<int, DrawColour> *highlight_atom_map = nullptr,
631  const std::vector<int> *highlight_bonds = nullptr,
632  const std::map<int, DrawColour> *highlight_bond_map = nullptr,
633  const std::vector<std::pair<DrawColour, DrawColour>>
634  *bond_colours = nullptr);
635  // do the finishing touches to the drawing
636  void finishMoleculeDraw(const ROMol &draw_mol,
637  const std::vector<DrawColour> &atom_colours);
638  void drawLegend(const std::string &legend);
639  // draw a circle in the requested colour(s) around the atom.
640  void drawHighlightedAtom(int atom_idx, const std::vector<DrawColour> &colours,
641  const std::map<int, double> *highlight_radii);
642  // calculate the rectangle that goes round the string, taking its
643  // orientation into account. Centre of StringRect
644  // won't be the same as label_coords, necessarily, as the string might
645  // be offset according to orient.
646  StringRect calcLabelRect(const std::string &label, OrientType orient,
647  const Point2D &label_coords) const;
648  // calculate parameters for an ellipse that roughly goes round the label
649  // of the given atom.
650  void calcLabelEllipse(int atom_idx,
651  const std::map<int, double> *highlight_radii,
652  Point2D &centre, double &xradius,
653  double &yradius) const;
654  // these both assume there is a note on the atom or bond. That should
655  // have been checked by the calling function. StringRect will have a
656  // width of -1.0 if there's a problem.
657  StringRect calcAnnotationPosition(const ROMol &mol, const Atom *atom);
658  StringRect calcAnnotationPosition(const ROMol &mol, const Bond *bond);
659  // find where to put the given annotation around an atom. Starting
660  // search at angle start_ang, in degrees.
661  void calcAtomAnnotationPosition(const ROMol &mol, const Atom *atom,
662  double start_ang, StringRect &rect);
663 
664  // draw 1 or more coloured line along bonds
665  void drawHighlightedBonds(
666  const ROMol &mol,
667  const std::map<int, std::vector<DrawColour>> &highlight_bond_map,
668  const std::map<int, int> &highlight_linewidth_multipliers,
669  const std::map<int, double> *highlight_radii);
670  int getHighlightBondWidth(
671  int bond_idx,
672  const std::map<int, int> *highlight_linewidth_multipliers) const;
673  // move p2 so that the line defined by p1 to p2 touches the ellipse for the
674  // atom highlighted.
675  void adjustLineEndForHighlight(int at_idx,
676  const std::map<int, double> *highlight_radii,
677  Point2D p1, Point2D &p2) const;
678 
679  void extractAtomCoords(const ROMol &mol, int confId, bool updateBBox);
680  void extractAtomSymbols(const ROMol &mol);
681  void extractAtomNotes(const ROMol &mol);
682  void extractBondNotes(const ROMol &mol);
683 
684  virtual void drawLine(const Point2D &cds1, const Point2D &cds2,
685  const DrawColour &col1, const DrawColour &col2);
686  void drawWedgedBond(const Point2D &cds1, const Point2D &cds2,
687  bool draw_dashed, const DrawColour &col1,
688  const DrawColour &col2);
689  // draw an arrow for a dative bond, with the arrowhead at cds2.
690  void drawDativeBond(const Point2D &cds1, const Point2D &cds2,
691  const DrawColour &col1, const DrawColour &col2);
692  void drawAtomLabel(int atom_num,
693  const std::vector<int> *highlight_atoms = nullptr,
694  const std::map<int, DrawColour> *highlight_map = nullptr);
695  void drawAtomLabel(int atom_num, const DrawColour &draw_colour);
696  virtual void drawAnnotation(const std::string &note,
697  const std::shared_ptr<StringRect> &note_rect);
698  void drawRadicals(const ROMol &mol);
699  // find a good starting point for scanning round the annotation
700  // atom. If we choose well, the first angle should be the one.
701  // Returns angle in radians.
702  double getNoteStartAngle(const ROMol &mol, const Atom *atom) const;
703  // see if the note will clash with anything else drawn on the molecule.
704  // note_vec should have unit length. note_rad is the radius along
705  // note_vec that the note will be drawn.
706  bool doesAtomNoteClash(StringRect &note_rect, const StringRect &atsym_rect,
707  const ROMol &mol, unsigned int atom_idx);
708  bool doesBondNoteClash(StringRect &note_rect, const ROMol &mol,
709  const Bond *bond);
710  // does the note_vec form an unacceptably acute angle with one of the
711  // bonds from atom to its neighbours.
712  bool doesNoteClashNbourBonds(const StringRect &note_rect, const ROMol &mol,
713  const Atom *atom) const;
714  // does the note intersect with atsym, and if not, any other atom symbol.
715  bool doesNoteClashAtomLabels(const StringRect &note_rect,
716  const StringRect &atsym_rect, const ROMol &mol,
717  unsigned int atom_idx) const;
718  bool doesNoteClashOtherNotes(const StringRect &note_rect) const;
719  // take the label for the given atom and return the individual pieces
720  // that need to be drawn for it. So NH<sub>2</sub> will return
721  // "N", "H<sub>2</sub>".
722  std::vector<std::string> atomLabelToPieces(int atom_num) const;
723  std::vector<std::string> atomLabelToPieces(const std::string &label,
724  OrientType orient) const;
725  // cds1 and cds2 are 2 atoms in a ring. Returns the perpendicular pointing
726  // into the ring.
727  Point2D bondInsideRing(const ROMol &mol, const Bond *bond,
728  const Point2D &cds1, const Point2D &cds2) const;
729  // cds1 and cds2 are 2 atoms in a chain double bond. Returns the
730  // perpendicular pointing into the inside of the bond
731  Point2D bondInsideDoubleBond(const ROMol &mol, const Bond *bond) const;
732  // calculate normalised perpendicular to vector between two coords, such
733  // that
734  // it's inside the angle made between (1 and 2) and (2 and 3).
735  Point2D calcInnerPerpendicular(const Point2D &cds1, const Point2D &cds2,
736  const Point2D &cds3) const;
737 
738  // take the coords for atnum, with neighbour nbr_cds, and move cds out to
739  // accommodate
740  // the label associated with it.
741  void adjustBondEndForLabel(int atnum, const Point2D &nbr_cds,
742  Point2D &cds) const;
743 
744  // adds LaTeX-like annotation for super- and sub-script.
745  std::pair<std::string, OrientType> getAtomSymbolAndOrientation(
746  const Atom &atom, const ROMol &mol) const;
747  std::string getAtomSymbol(const Atom &atom) const;
748  OrientType getAtomOrientation(const Atom &atom, const Point2D &nbr_sum) const;
749 
750  // things used by calculateScale.
751  void adjustScaleForAtomLabels(const std::vector<int> *highlight_atoms,
752  const std::map<int, double> *highlight_radii);
753  void adjustScaleForAnnotation(
754  const std::vector<std::shared_ptr<StringRect>> &notes);
755 
756  protected:
758  const ROMol &mol, const std::vector<int> *highlight_atoms,
759  const std::vector<int> *highlight_bonds,
760  const std::map<int, DrawColour> *highlight_atom_map,
761  const std::map<int, DrawColour> *highlight_bond_map,
762  const std::map<int, double> *highlight_radii);
763 
764  virtual void highlightCloseContacts();
765  // if bond_colours is given, it must have an entry for every bond, and it
766  // trumps everything else. First in pair is bonds begin atom, second is
767  // end atom.
768  virtual void drawBond(
769  const ROMol &mol, const Bond *bond, int at1_idx, int at2_idx,
770  const std::vector<int> *highlight_atoms = nullptr,
771  const std::map<int, DrawColour> *highlight_atom_map = nullptr,
772  const std::vector<int> *highlight_bonds = nullptr,
773  const std::map<int, DrawColour> *highlight_bond_map = nullptr,
774  const std::vector<std::pair<DrawColour, DrawColour>> *bond_colours =
775  nullptr);
776 
777  // calculate normalised perpendicular to vector between two coords
778  Point2D calcPerpendicular(const Point2D &cds1, const Point2D &cds2) const;
779  // assuming there's a double bond between atom1 and atom2, calculate
780  // the ends of the 2 lines that should be used to draw it, distance
781  // offset apart. Includes bonds of type AROMATIC.
782  void calcDoubleBondLines(const ROMol &mol, double offset, const Bond *bond,
783  const Point2D &at1_cds, const Point2D &at2_cds,
784  Point2D &l1s, Point2D &l1f, Point2D &l2s,
785  Point2D &l2f) const;
786  // returns true if atom has degree 2 and both bonds are close to
787  // linear.
788  bool isLinearAtom(const Atom &atom) const;
789  // and the same for triple bonds. One line is from atom to atom,
790  // so it doesn't need a separate return.
791  void calcTripleBondLines(double offset, const Bond *bond,
792  const Point2D &at1_cds, const Point2D &at2_cds,
793  Point2D &l1s, Point2D &l1f, Point2D &l2s,
794  Point2D &l2f) const;
795 
796  // calculate the width to draw a line in draw coords.
797  virtual unsigned int getDrawLineWidth();
798 
799  // sort out coords and scale for drawing reactions.
801  Point2D &arrowEnd, std::vector<double> &plusLocs,
802  double spacing, const std::vector<int> *confIds);
803  // despite the name, this is only ever used for molecules in a reaction.
804  void get2DCoordsMol(RWMol &mol, double &offset, double spacing, double &maxY,
805  double &minY, int confId, bool shiftAgents,
806  double coordScale);
807 };
808 
809 // return true if the line l1s->l1f intersects line l2s->l2f. If ip is not
810 // nullptr, the intersection point is stored in it.
812  const Point2D &l1f,
813  const Point2D &l2s,
814  const Point2D &l2f,
815  Point2D *ip = nullptr);
816 // return true if line ls->lf intersects (or is fully inside) the
817 // rectangle of the string.
819  const Point2D &lf,
820  const StringRect &lab_rect);
821 
822 std::ostream& operator<<(std::ostream &oss, const MolDraw2D::OrientType &o);
823 
824 } // namespace RDKit
825 
826 #endif // RDKITMOLDRAW2D_H
RDKIT_MOLDRAW2D_EXPORT
#define RDKIT_MOLDRAW2D_EXPORT
Definition: export.h:398
RDKit::MolDraw2D::drawMoleculeWithHighlights
virtual void drawMoleculeWithHighlights(const ROMol &mol, const std::string &legend, const std::map< int, std::vector< DrawColour >> &highlight_atom_map, const std::map< int, std::vector< DrawColour >> &highlight_bond_map, const std::map< int, double > &highlight_radii, const std::map< int, int > &highlight_linewidth_multipliers, int confId=-1)
draw molecule with multiple colours allowed per atom.
RDKit::DrawColour::b
double b
Definition: MolDraw2D.h:38
RDKit::StringRect::calcCorners
void calcCorners(Point2D &tl, Point2D &tr, Point2D &br, Point2D &bl) const
Definition: MolDraw2D.h:75
RDKit::StringRect::height_
double height_
Definition: MolDraw2D.h:67
RDKit::MolDrawOptions::atomColourPalette
ColourPalette atomColourPalette
Definition: MolDraw2D.h:164
RDKit::MolDraw2D::calcPerpendicular
Point2D calcPerpendicular(const Point2D &cds1, const Point2D &cds2) const
RDKit::MolDraw2D_detail::addBondIndices
RDKIT_MOLDRAW2D_EXPORT void addBondIndices(const ROMol &mol)
add annotations with bond indices.
Definition: MolDraw2DDetails.h:89
RDKit::MolDraw2D::setScale
void setScale(int width, int height, const Point2D &minv, const Point2D &maxv)
explicitly sets the scaling factors for the drawing
RDKit::MolDraw2D::offset
Point2D offset() const
returns the drawing offset (in drawing coords)
Definition: MolDraw2D.h:439
RDKit::MolDraw2D::drawTriangle
virtual void drawTriangle(const Point2D &cds1, const Point2D &cds2, const Point2D &cds3)
draw a triangle
RDKit::DrawColour::operator+
DrawColour operator+(const DrawColour &other) const
Definition: MolDraw2D.h:51
RDKit::MolDraw2D::isLinearAtom
bool isLinearAtom(const Atom &atom) const
point.h
RDKit::DrawColour::operator/
DrawColour operator/(double v) const
Definition: MolDraw2D.h:57
RDKit::StringRect::StringRect
StringRect(const Point2D &in_cds)
Definition: MolDraw2D.h:72
RDKit::MolDraw2D::calcTripleBondLines
void calcTripleBondLines(double offset, const Bond *bond, const Point2D &at1_cds, const Point2D &at2_cds, Point2D &l1s, Point2D &l1f, Point2D &l2s, Point2D &l2f) const
RDKit::MolDraw2D::drawOptions
const MolDrawOptions & drawOptions() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: MolDraw2D.h:552
RDKit::MolDraw2D::setFillPolys
virtual void setFillPolys(bool val)
returns either or not polygons should be filled
Definition: MolDraw2D.h:547
RDKit::MolDraw2D::clearDrawing
virtual void clearDrawing()=0
clears the contents of the drawing
RDKit::MolDraw2D::highlightCloseContacts
virtual void highlightCloseContacts()
RDKit::MolDraw2D::getAtomCoords
virtual Point2D getAtomCoords(const std::pair< int, int > &screen_cds) const
RDKit::MolDraw2D::~MolDraw2D
virtual ~MolDraw2D()
Definition: MolDraw2D.h:252
RDKit::DashPattern
std::vector< unsigned int > DashPattern
Definition: MolDraw2D.h:93
RDKit::MolDraw2D::setOffset
void setOffset(int x, int y)
sets the drawing offset (in drawing coords)
Definition: MolDraw2D.h:434
RDKit::MolDraw2D::setColour
virtual void setColour(const DrawColour &col)
sets the current draw color
Definition: MolDraw2D.h:455
RDKit::MolDraw2D::drawArrow
virtual void drawArrow(const Point2D &cds1, const Point2D &cds2, bool asPolygon=false, double frac=0.05, double angle=M_PI/6)
Draw an arrow with either lines or a filled head (when asPolygon is true)
RDKit::StringRect::StringRect
StringRect()
Definition: MolDraw2D.h:70
RDKit::MolDrawOptions::atomRegions
std::vector< std::vector< int > > atomRegions
Definition: MolDraw2D.h:152
RDKit::MolDraw2D::scale
double scale() const
returns the drawing scale (conversion from molecular coords -> drawing
Definition: MolDraw2D.h:413
RDGeom::Point2D::y
double y
Definition: point.h:260
RDKit::MolDraw2D_detail::addStereoAnnotation
RDKIT_MOLDRAW2D_EXPORT void addStereoAnnotation(const ROMol &mol)
add R/S and E/Z annotation to atoms and bonds respectively.
Definition: MolDraw2DDetails.h:56
RDKit::DrawColour::DrawColour
DrawColour()=default
RDKit::MolDraw2D::setStringDrawMode
bool setStringDrawMode(const std::string &instring, TextDrawType &draw_mode, int &i) const
RDKit::Bond
class for representing a bond
Definition: Bond.h:47
RDKit::MolDraw2D::fillPolys
virtual bool fillPolys() const
set whether or not polygons are being filled
Definition: MolDraw2D.h:545
RDKit::MolDraw2D::getAtomCoords
virtual Point2D getAtomCoords(const std::pair< double, double > &screen_cds) const
RDKit::MolDraw2D::drawMolecule
virtual void drawMolecule(const ROMol &mol, const std::vector< int > *highlight_atoms=nullptr, const std::map< int, DrawColour > *highlight_map=nullptr, const std::map< int, double > *highlight_radii=nullptr, int confId=-1)
This is an overloaded member function, provided for convenience. It differs from the above function o...
RDKit::RWMol
RWMol is a molecule class that is intended to be edited.
Definition: RWMol.h:31
RDKit::MolDrawOptions::MolDrawOptions
MolDrawOptions()
Definition: MolDraw2D.h:192
RDKit::MolDraw2D::drawRect
virtual void drawRect(const Point2D &cds1, const Point2D &cds2)
draw a rectangle
RDKit::MolDraw2D_detail::addAtomIndices
RDKIT_MOLDRAW2D_EXPORT void addAtomIndices(const ROMol &mol)
add annotations with atom indices.
Definition: MolDraw2DDetails.h:73
RDKit::MolDraw2D::setDash
virtual void setDash(const DashPattern &patt)
sets the current dash pattern
Definition: MolDraw2D.h:459
RDKit::MolDraw2D::TextDrawSuperscript
@ TextDrawSuperscript
Definition: MolDraw2D.h:221
RDKit::MolDraw2D::get2DCoordsMol
void get2DCoordsMol(RWMol &mol, double &offset, double spacing, double &maxY, double &minY, int confId, bool shiftAgents, double coordScale)
RDUNUSED_PARAM
#define RDUNUSED_PARAM(x)
Definition: Invariant.h:197
RDKit::MolDraw2D::centrePicture
void centrePicture(int width, int height)
RDKit::MolDraw2D::tagAtoms
virtual void tagAtoms(const ROMol &mol)
Definition: MolDraw2D.h:543
RDKit::doLinesIntersect
RDKIT_MOLDRAW2D_EXPORT bool doLinesIntersect(const Point2D &l1s, const Point2D &l1f, const Point2D &l2s, const Point2D &l2f, Point2D *ip=nullptr)
RDKit::StringRect::clash_score_
int clash_score_
Definition: MolDraw2D.h:68
RDKit::MolDraw2D::lineWidth
virtual int lineWidth() const
returns the current line width
Definition: MolDraw2D.h:466
RDKit::doesLineIntersectLabel
RDKIT_MOLDRAW2D_EXPORT bool doesLineIntersectLabel(const Point2D &ls, const Point2D &lf, const StringRect &lab_rect)
RDKit::MolDraw2D::supportsAnnotations
virtual bool supportsAnnotations()
Definition: MolDraw2D.h:573
RDKit::Atom
The class for representing atoms.
Definition: Atom.h:69
RDKit::MolDraw2D::minPt
Point2D minPt() const
returns the minimum point of the drawing (in molecular coords)
Definition: MolDraw2D.h:442
RDKit::MolDraw2D::atomCoords
const std::vector< Point2D > & atomCoords() const
Definition: MolDraw2D.h:556
RDKit::assignBWPalette
void assignBWPalette(ColourPalette &palette)
Definition: MolDraw2D.h:110
RDKit::DrawColour
Definition: MolDraw2D.h:37
RDKit::MolDraw2D::drawStrings
virtual void drawStrings(const std::vector< std::string > &labels, const Point2D &cds, OrientType orient)
M_PI
#define M_PI
Definition: MMFF/Params.h:27
RDKit::MolDraw2D::drawArc
virtual void drawArc(const Point2D &centre, double radius, double ang1, double ang2)
RDKit::MolDraw2D::getDrawLineWidth
virtual unsigned int getDrawLineWidth()
RDKit::ROMol
Definition: ROMol.h:171
RDKit::MolDraw2D::calculateScale
void calculateScale(int width, int height, const std::vector< int > *highlight_atoms=nullptr, const std::map< int, double > *highlight_radii=nullptr)
calculates the drawing scale (conversion from molecular coords -> drawing
RDKitBase.h
pulls in the core RDKit functionality
RDKit::MolDraw2D::height
virtual int height() const
return the height of the drawing area.
Definition: MolDraw2D.h:405
RDKit::MolDraw2D::drawEllipse
virtual void drawEllipse(const Point2D &cds1, const Point2D &cds2)
draw an ellipse
RDKit::MolDraw2D::tabulaRasa
void tabulaRasa()
RDKit::MolDraw2D::setFontSize
virtual void setFontSize(double new_size)
RDKit::ColourPalette
std::map< int, DrawColour > ColourPalette
Definition: MolDraw2D.h:92
RDKit::MolDraw2D::drawArc
virtual void drawArc(const Point2D &centre, double xradius, double yradius, double ang1, double ang2)
RDKit::MolDraw2D::drawWavyLine
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
RDKit::MolDraw2D::get2DCoordsForReaction
void get2DCoordsForReaction(ChemicalReaction &rxn, Point2D &arrowBegin, Point2D &arrowEnd, std::vector< double > &plusLocs, double spacing, const std::vector< int > *confIds)
RDKit::MolDraw2D::drawMolecules
virtual void drawMolecules(const std::vector< ROMol * > &mols, const std::vector< std::string > *legends=nullptr, const std::vector< std::vector< int >> *highlight_atoms=nullptr, const std::vector< std::vector< int >> *highlight_bonds=nullptr, const std::vector< std::map< int, DrawColour >> *highlight_atom_maps=nullptr, const std::vector< std::map< int, DrawColour >> *highlight_bond_maps=nullptr, const std::vector< std::map< int, double >> *highlight_radii=nullptr, const std::vector< int > *confIds=nullptr)
draw multiple molecules in a grid
Reaction.h
RDKit::MolDraw2D::getDrawCoords
virtual Point2D getDrawCoords(int at_num) const
returns the drawing coordinates of a particular atom
RDKit::MolDraw2D::drawString
virtual void drawString(const std::string &str, const Point2D &cds, AlignType align)
RDKit::ChemicalReaction
This is a class for storing and applying general chemical reactions.
Definition: Reaction.h:120
RDKit::MolDraw2D::drawBond
virtual void drawBond(const ROMol &mol, const Bond *bond, int at1_idx, int at2_idx, const std::vector< int > *highlight_atoms=nullptr, const std::map< int, DrawColour > *highlight_atom_map=nullptr, const std::vector< int > *highlight_bonds=nullptr, const std::map< int, DrawColour > *highlight_bond_map=nullptr, const std::vector< std::pair< DrawColour, DrawColour >> *bond_colours=nullptr)
RDKit::MolDraw2D::drawAttachmentLine
virtual void drawAttachmentLine(const Point2D &cds1, const Point2D &cds2, const DrawColour &col, double len=1.0, unsigned int nSegments=16)
RDKit::MolDraw2D::width
virtual int width() const
return the width of the drawing area.
Definition: MolDraw2D.h:403
RDKit::DrawColour::r
double r
Definition: MolDraw2D.h:38
RDKit::MolDraw2D::OrientType
OrientType
Definition: MolDraw2D.h:216
RDKit::MolDraw2D::drawLine
virtual void drawLine(const Point2D &cds1, const Point2D &cds2)=0
draws a line from cds1 to cds2 using the current drawing style
RDKit::MolDraw2D::panelWidth
virtual int panelWidth() const
return the width of the drawing panels.
Definition: MolDraw2D.h:407
RDKit::MolDraw2D::dash
virtual const DashPattern & dash() const
returns the current dash pattern
Definition: MolDraw2D.h:461
RDKit::MolDraw2D::setLineWidth
virtual void setLineWidth(int width)
sets the current line width
Definition: MolDraw2D.h:464
RDKit::StringRect
Definition: MolDraw2D.h:65
RDKit::MolDraw2D::calculateScale
void calculateScale(int width, int height, const std::vector< ROMol * > &mols, const std::vector< std::vector< int >> *highlight_atoms, const std::vector< std::map< int, double >> *highlight_radii, const std::vector< int > *confIds, std::vector< std::unique_ptr< RWMol >> &tmols)
overload
RDKit::DrawColour::operator*
DrawColour operator*(double v) const
Definition: MolDraw2D.h:61
RDKit::MolDraw2D::drawPolygon
virtual void drawPolygon(const std::vector< Point2D > &cds)=0
RDKit::MolDraw2D::calcDoubleBondLines
void calcDoubleBondLines(const ROMol &mol, double offset, const Bond *bond, const Point2D &at1_cds, const Point2D &at2_cds, Point2D &l1s, Point2D &l1f, Point2D &l2s, Point2D &l2f) const
RDKit::MolDraw2D::fontSize
virtual double fontSize() const
returns the font size (in molecule units)
Definition: MolDraw2D.h:447
RDKit::MolDrawOptions::highlightColourPalette
std::vector< DrawColour > highlightColourPalette
Definition: MolDraw2D.h:161
RDKit
Std stuff.
Definition: Atom.h:30
RDKit::MolDraw2D
MolDraw2D is the base class for doing 2D renderings of molecules.
Definition: MolDraw2D.h:214
RDKit::DrawColour::DrawColour
DrawColour(double r, double g, double b, double a=1.0)
Definition: MolDraw2D.h:40
RDKit::MolDraw2D::drawMolecule
virtual void drawMolecule(const ROMol &mol, const std::string &legend, const std::vector< int > *highlight_atoms=nullptr, const std::map< int, DrawColour > *highlight_map=nullptr, const std::map< int, double > *highlight_radii=nullptr, int confId=-1)
This is an overloaded member function, provided for convenience. It differs from the above function o...
RDKit::MolDrawOptions
Definition: MolDraw2D.h:115
RDKit::MolDraw2D::getDrawCoords
virtual Point2D getDrawCoords(const Point2D &mol_cds) const
RDKit::DrawColour::g
double g
Definition: MolDraw2D.h:38
RDGeom::Point2D
Definition: point.h:258
RDKit::MolDraw2D::drawOptions
MolDrawOptions & drawOptions()
returns our current drawing options
Definition: MolDraw2D.h:550
RDKit::assignDefaultPalette
void assignDefaultPalette(ColourPalette &palette)
Definition: MolDraw2D.h:95
RDKit::DrawColour::operator==
bool operator==(const DrawColour &other) const
Definition: MolDraw2D.h:42
PRECONDITION
#define PRECONDITION(expr, mess)
Definition: Invariant.h:110
RDKit::StringRect::doesItIntersect
bool doesItIntersect(const StringRect &other) const
Definition: MolDraw2D.h:83
RDKit::MolDrawOptions::atomLabels
std::map< int, std::string > atomLabels
Definition: MolDraw2D.h:151
RDKit::DrawColour::feq
bool feq(const DrawColour &other, double tol=0.001, bool ignoreAlpha=true) const
Definition: MolDraw2D.h:45
RDKit::MolDraw2D::MolDraw2D
MolDraw2D(int width, int height, int panelWidth, int panelHeight)
constructor for a particular size
Definition: MolDraw2D.h:236
RDKit::MolDraw2D::drawFontSize
double drawFontSize() const
RDKit::MolDraw2D::drawString
virtual void drawString(const std::string &str, const Point2D &cds)
drawString centres the string on cds.
RDKit::MolDraw2D::getLabelSize
void getLabelSize(const std::string &label, OrientType orient, double &label_width, double &label_height) const
RDKit::operator<<
std::ostream & operator<<(std::ostream &oss, const MolDraw2D::OrientType &o)
RDKit::MolDraw2D::atomSyms
const std::vector< std::pair< std::string, OrientType > > & atomSyms() const
returns the atomic symbols of the current molecule
Definition: MolDraw2D.h:561
RDKit::DrawColour::operator-
DrawColour operator-(const DrawColour &other) const
Definition: MolDraw2D.h:54
RDKit::DrawColour::a
double a
Definition: MolDraw2D.h:38
RDKit::MolDraw2D::getStringSize
virtual void getStringSize(const std::string &label, double &label_width, double &label_height) const =0
RDKit::MolDraw2D::range
Point2D range() const
returns the width and height of the grid (in molecular coords)
Definition: MolDraw2D.h:444
RDKit::MolDraw2D::drawReaction
virtual void drawReaction(const ChemicalReaction &rxn, bool highlightByReactant=false, const std::vector< DrawColour > *highlightColorsReactants=nullptr, const std::vector< int > *confIds=nullptr)
draw a ChemicalReaction
RDKit::MolDraw2D::drawMolecule
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=nullptr, const std::map< int, DrawColour > *highlight_bond_map=nullptr, const std::map< int, double > *highlight_radii=nullptr, int confId=-1)
This is an overloaded member function, provided for convenience. It differs from the above function o...
RDGeom::Point2D::x
double x
Definition: point.h:260
RDKit::MolDraw2D::panelHeight
virtual int panelHeight() const
return the height of the drawing panels.
Definition: MolDraw2D.h:409
RDKit::MolDraw2D::TextDrawType
TextDrawType
Definition: MolDraw2D.h:219
RDKit::MolDraw2D::doContinuousHighlighting
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)
RDKit::MolDraw2D::START
@ START
Definition: MolDraw2D.h:218
RDKit::MolDraw2D::AlignType
AlignType
Definition: MolDraw2D.h:218
RDKit::MolDraw2D::drawMolecule
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=nullptr, const std::map< int, DrawColour > *highlight_bond_map=nullptr, const std::map< int, double > *highlight_radii=nullptr, int confId=-1)
draw a single molecule
RDKit::StringRect::centre_
Point2D centre_
Definition: MolDraw2D.h:66
RDKit::StringRect::width_
double width_
Definition: MolDraw2D.h:67
RDKit::MolDraw2D::colour
virtual DrawColour colour() const
returns the current draw color
Definition: MolDraw2D.h:457
RDKit::MolDraw2D::alignString
virtual void alignString(const std::string &str, const std::string &align_char, int align, const Point2D &in_cds, Point2D &out_cds) const
export.h
RDKit::MolDraw2D::getAtomCoords
virtual Point2D getAtomCoords(int at_num) const
returns the molecular coordinates of a particular atom