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