RDKit
Open-source cheminformatics and machine learning.
MolDraw2D.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2014-2021 David Cosgrove and other RDKit contributors
3 //
4 // @@ All Rights Reserved @@
5 // This file is part of the RDKit.
6 // The contents are covered by the terms of the BSD license
7 // which is included in the file license.txt, found at the root
8 // of the RDKit source tree.
9 //
10 // Original author: David Cosgrove (AstraZeneca)
11 // 27th May 2014
12 //
13 // This class makes a 2D drawing of an RDKit molecule.
14 // It draws heavily on $RDBASE/GraphMol/MolDrawing/MolDrawing.h.
15 // One purpose of this is to make it easier to overlay annotations on top of
16 // the molecule drawing, which is difficult to do from the output of
17 // MolDrawing.h
18 // The class design philosophy echoes a standard one:
19 // a virtual base class defines the interface and does all
20 // the heavy lifting and concrete derived classes implement
21 // library-specific drawing code such as drawing lines, writing strings
22 // etc.
23 
24 #include <RDGeneral/export.h>
25 #ifndef RDKITMOLDRAW2D_H
26 #define RDKITMOLDRAW2D_H
27 
28 #include <vector>
29 
30 #include <Geometry/point.h>
31 #include <Geometry/Transform2D.h>
32 #include <GraphMol/RDKitBase.h>
35 
36 // ****************************************************************************
37 using RDGeom::Point2D;
38 
39 namespace RDKit {
40 
41 namespace MolDraw2D_detail {
42 class DrawMol;
43 class DrawText;
44 } // namespace MolDraw2D_detail
45 
46 //! MolDraw2D is the base class for doing 2D renderings of molecules
48  public:
49  //! constructor for a particular size
50  /*!
51  \param width : width (in pixels) of the rendering
52  set this to -1 to have the canvas size set automatically
53  \param height : height (in pixels) of the rendering
54  set this to -1 to have the canvas size set automatically
55  \param panelWidth : (optional) width (in pixels) of a single panel
56  \param panelHeight : (optional) height (in pixels) of a single panel
57 
58  The \c panelWidth and \c panelHeight arguments are used to provide the
59  sizes of the panels individual molecules are drawn in when
60  \c drawMolecules() is called.
61  */
62  MolDraw2D(int width, int height, int panelWidth, int panelHeight);
63  MolDraw2D(const MolDraw2D &rhs) = delete;
64  MolDraw2D(MolDraw2D &&rhs) = delete;
65  MolDraw2D &operator=(const MolDraw2D &rhs) = delete;
66  MolDraw2D &operator=(MolDraw2D &&rhs) = delete;
67  virtual ~MolDraw2D();
68 
69  //! draw a single molecule
70  /*!
71  \param mol : the molecule to draw
72  \param legend : the legend (to be drawn under the molecule)
73  \param highlight_atoms : (optional) vector of atom ids to highlight
74  \param highlight_atoms : (optional) vector of bond ids to highlight
75  \param highlight_atom_map : (optional) map from atomId -> DrawColour
76  providing the highlight colors. If not provided the default highlight colour
77  from \c drawOptions() will be used.
78  \param highlight_bond_map : (optional) map from bondId -> DrawColour
79  providing the highlight colors. If not provided the default highlight colour
80  from \c drawOptions() will be used.
81  \param highlight_radii : (optional) map from atomId -> radius (in molecule
82  coordinates) for the radii of atomic highlights. If not provided the default
83  value from \c drawOptions() will be used.
84  \param confId : (optional) conformer ID to be used for atomic
85  coordinates
86 
87  */
89  const ROMol &mol, const std::string &legend,
90  const std::vector<int> *highlight_atoms,
91  const std::vector<int> *highlight_bonds,
92  const std::map<int, DrawColour> *highlight_atom_map = nullptr,
93  const std::map<int, DrawColour> *highlight_bond_map = nullptr,
94  const std::map<int, double> *highlight_radii = nullptr, int confId = -1);
95 
96  //! \overload
97  void drawMolecule(const ROMol &mol,
98  const std::vector<int> *highlight_atoms = nullptr,
99  const std::map<int, DrawColour> *highlight_map = nullptr,
100  const std::map<int, double> *highlight_radii = nullptr,
101  int confId = -1);
102 
103  //! \overload
104  void drawMolecule(const ROMol &mol, const std::string &legend,
105  const std::vector<int> *highlight_atoms = nullptr,
106  const std::map<int, DrawColour> *highlight_map = nullptr,
107  const std::map<int, double> *highlight_radii = nullptr,
108  int confId = -1);
109 
110  //! \overload
112  const ROMol &mol, const std::vector<int> *highlight_atoms,
113  const std::vector<int> *highlight_bonds,
114  const std::map<int, DrawColour> *highlight_atom_map = nullptr,
115  const std::map<int, DrawColour> *highlight_bond_map = nullptr,
116  const std::map<int, double> *highlight_radii = nullptr, int confId = -1);
117 
118  //! draw molecule with multiple colours allowed per atom.
119  /*!
120  \param mol : the molecule to draw
121  \param legend : the legend (to be drawn under the molecule)
122  \param highlight_atom_map : map from atomId -> DrawColours
123  providing the highlight colours.
124  \param highlight_bond_map : map from bondId -> DrawColours
125  providing the highlight colours.
126  \param highlight_radii : map from atomId -> radius (in molecule
127  coordinates) for the radii of atomic highlights. If not provided for an
128  index, the default value from \c drawOptions() will be used.
129  \param highlight_linewidth_multipliers : map from atomId -> int, used to
130  vary the width the highlight lines. Only active if
131  drawOptions().fillHighlights is false.
132  \param confId : (optional) conformer ID to be used for atomic
133  coordinates
134  */
136  const ROMol &mol, const std::string &legend,
137  const std::map<int, std::vector<DrawColour>> &highlight_atom_map,
138  const std::map<int, std::vector<DrawColour>> &highlight_bond_map,
139  const std::map<int, double> &highlight_radii,
140  const std::map<int, int> &highlight_linewidth_multipliers,
141  int confId = -1);
142 
143  //! draw multiple molecules in a grid
144  /*!
145  \param mols : the molecules to draw
146  \param legends : (optional) the legends (to be drawn under the
147  molecules)
148  \param highlight_atoms : (optional) vectors of atom ids to highlight
149  \param highlight_atoms : (optional) vectors of bond ids to highlight
150  \param highlight_atom_map : (optional) maps from atomId -> DrawColour
151  providing the highlight colors. If not provided the default highlight colour
152  from \c drawOptions() will be used.
153  \param highlight_bond_map : (optional) maps from bondId -> DrawColour
154  providing the highlight colors. If not provided the default highlight colour
155  from \c drawOptions() will be used.
156  \param highlight_radii : (optional) maps from atomId -> radius (in molecule
157  coordinates) for the radii of atomic highlights. If not provided the default
158  value from \c drawOptions() will be used.
159  \param confId : (optional) conformer IDs to be used for atomic
160  coordinates
161 
162  The \c panelWidth and \c panelHeight values will be used to determine the
163  number of rows and columns to be drawn. Theres not a lot of error checking
164  here, so if you provide too many molecules for the number of panes things
165  are likely to get screwed up.
166  If the number of rows or columns ends up being <= 1, molecules will be
167  being drawn in a single row/column.
168  */
170  const std::vector<ROMol *> &mols,
171  const std::vector<std::string> *legends = nullptr,
172  const std::vector<std::vector<int>> *highlight_atoms = nullptr,
173  const std::vector<std::vector<int>> *highlight_bonds = nullptr,
174  const std::vector<std::map<int, DrawColour>> *highlight_atom_maps =
175  nullptr,
176  const std::vector<std::map<int, DrawColour>> *highlight_bond_maps =
177  nullptr,
178  const std::vector<std::map<int, double>> *highlight_radii = nullptr,
179  const std::vector<int> *confIds = nullptr);
180 
181  //! draw a ChemicalReaction
182  /*!
183  \param rxn : the reaction to draw
184  \param highlightByReactant : (optional) if this is set, atoms and bonds will
185  be highlighted based on which reactant they come from. Atom map numbers
186  will not be shown.
187  \param highlightColorsReactants : (optional) provide a vector of colors for
188  the
189  reactant highlighting.
190  \param confIds : (optional) vector of confIds to use for rendering. These
191  are numbered by reactants, then agents, then products.
192  */
194  const ChemicalReaction &rxn, bool highlightByReactant = false,
195  const std::vector<DrawColour> *highlightColorsReactants = nullptr,
196  const std::vector<int> *confIds = nullptr);
197 
198  //! returns the size of the box for the molecule with current drawing settings
199  std::pair<int, int> getMolSize(
200  const ROMol &mol, const std::string &legend = "",
201  const std::vector<int> *highlight_atoms = nullptr,
202  const std::vector<int> *highlight_bonds = nullptr,
203  const std::map<int, DrawColour> *highlight_atom_map = nullptr,
204  const std::map<int, DrawColour> *highlight_bond_map = nullptr,
205  const std::map<int, double> *highlight_radii = nullptr, int confId = -1);
206 
207  //! clears the contents of the drawing
208  virtual void clearDrawing() {
209  if (needs_init_) {
210  initDrawing();
211  needs_init_ = false;
212  }
213  };
214  //! draws a line from \c cds1 to \c cds2 using the current drawing style
215  //! in atom coords. If rawCoords is passed as true,
216  //! the coordinates are used as is, if not they are assumed to be in
217  //! the molecule coordinate frame and converted with getDrawCoords
218  //! into canvas coords.
219  virtual void drawLine(const Point2D &cds1, const Point2D &cds2,
220  bool rawCoords = false) = 0;
221  //! draw a polygon. Note that if fillPolys() returns false, it
222  //! doesn't close the path. If you want it to in that case, you
223  //! do it explicitly yourself. If rawCoords is passed as true,
224  //! the coordinates are used as is, if not they are assumed to be in
225  //! the molecule coordinate frame and converted with getDrawCoords
226  //! into canvas coords.
227  virtual void drawPolygon(const std::vector<Point2D> &cds,
228  bool rawCoords = false) = 0;
229  //! @}
230 
231  //! A Whole bunch of drawing primitives. They may be over-ridden
232  //! by different renderers, or they may be implemented in terms of
233  //! drawLine and drawPolygon above. If rawCoords is passed as true,
234  // the coordinates are used as is, if not they are assumed to be in
235  // the molecule coordinate frame and converted with getDrawCoords
236  // into canvas coords.
237  //! draw a line where the ends are different colours
238  virtual void drawLine(const Point2D &cds1, const Point2D &cds2,
239  const DrawColour &col1, const DrawColour &col2,
240  bool rawCoords = false);
241  //! draw a triangle
242  virtual void drawTriangle(const Point2D &cds1, const Point2D &cds2,
243  const Point2D &cds3, bool rawCoords = false);
244  //! draw an ellipse
245  virtual void drawEllipse(const Point2D &cds1, const Point2D &cds2,
246  bool rawCoords = false);
247  // draw the arc of a circle between ang1 and ang2. Note that 0 is
248  // at 3 o-clock and 90 at 12 o'clock as you'd expect from your maths.
249  // ang2 must be > ang1 - it won't draw backwards. This is not enforced.
250  // Angles in degrees.
251  virtual void drawArc(const Point2D &centre, double radius, double ang1,
252  double ang2, bool rawCoords = false);
253  // and a general ellipse form
254  virtual void drawArc(const Point2D &centre, double xradius, double yradius,
255  double ang1, double ang2, bool rawCoords = false);
256  //! draw a rectangle given two opposite corners
257  virtual void drawRect(const Point2D &cds1, const Point2D &cds2,
258  bool rawCoords = false);
259  //! draw a line indicating the presence of an attachment point (normally a
260  //! squiggle line perpendicular to a bond)
261  virtual void drawAttachmentLine(const Point2D &cds1, const Point2D &cds2,
262  const DrawColour &col, double len = 1.0,
263  unsigned int nSegments = 16,
264  bool rawCoords = false);
265  //! draw a wavy line like that used to indicate unknown stereochemistry
266  virtual void drawWavyLine(const Point2D &cds1, const Point2D &cds2,
267  const DrawColour &col1, const DrawColour &col2,
268  unsigned int nSegments = 16,
269  double vertOffset = 0.05, bool rawCoords = false);
270  //! Draw an arrow with either lines or a filled head (when asPolygon is true)
271  virtual void drawArrow(const Point2D &cds1, const Point2D &cds2,
272  bool asPolygon = false, double frac = 0.05,
273  double angle = M_PI / 6,
274  const DrawColour &col = DrawColour(0.0, 0.0, 0.0),
275  bool rawCoords = false);
276  // draw a plus sign with lines at the given position.
277  virtual void drawPlus(const Point2D &cds, int plusWidth,
278  const DrawColour &col, bool rawCoords = false);
279 
280  //! drawString centres the string on cds.
281  virtual void drawString(const std::string &str, const Point2D &cds,
282  bool rawCoords = false);
283  // unless the specific drawer over-rides this overload, it will just call
284  // the first one. SVG for one needs the alignment flag.
285  virtual void drawString(const std::string &str, const Point2D &cds,
287  bool rawCoords = false);
288 
289  //! \name Transformations
290  //! @{
291  // transform a set of coords in the molecule's coordinate system
292  // to drawing system coordinates and vice versa. Note that the coordinates
293  // have
294  // the origin in the top left corner, which is how Qt and Cairo have it, no
295  // doubt a holdover from X Windows. This means that a higher y value will be
296  // nearer the bottom of the screen. This doesn't really matter except when
297  // doing text superscripts and subscripts.
298 
299  //! transform a point from the molecule coordinate system into the drawing
300  //! coordinate system.
301  //! Prefers globalDrawTrans_ if it exists, otherwise
302  //! uses drawMols_[activeMolIdx_].
303  virtual Point2D getDrawCoords(const Point2D &mol_cds) const;
304  //! returns the drawing coordinates of a particular atom
305  virtual Point2D getDrawCoords(int at_num) const;
306  //! Prefers globalDrawTrans_ if it exists, otherwise
307  //! uses drawMols_[activeMolIdx_].
308  virtual Point2D getAtomCoords(const std::pair<int, int> &screen_cds) const;
309  //! transform a point from drawing coordinates to the molecule coordinate
310  //! system. Prefers globalDrawTrans_ if it exists, otherwise
311  //! uses drawMols_[activeMolIdx_].
313  const std::pair<double, double> &screen_cds) const;
314  //! returns the molecular coordinates of a particular atom. at_num refers
315  //! to the atom in activeMolIdx_.
316  virtual Point2D getAtomCoords(int at_num) const;
317  //! @}
318  //! returns the coordinates of the atoms of the activeMolIdx_ molecule in
319  //! molecular coordinates.
320  const std::vector<Point2D> &atomCoords() const;
321  //! returns the atomic symbols of the activeMolIdx_ molecule
322  const std::vector<std::pair<std::string, MolDraw2D_detail::OrientType>>
323  &atomSyms() const;
324 
325  //! return the width of the drawing area.
326  int width() const { return width_; }
327  //! return the height of the drawing area.
328  int height() const { return height_; }
329  //! return the width of the drawing panels.
330  int panelWidth() const { return panel_width_; }
331  //! return the height of the drawing panels.
332  int panelHeight() const { return panel_height_; }
333 
334  //! when FlexiMode is set, molecules will always be drawn
335  //! with the default values for bond length, font size, etc.
336  void setFlexiMode(bool mode) {
337  flexiMode_ = mode;
338  if (mode) {
339  panel_width_ = -1;
340  panel_height_ = -1;
341  }
342  }
343  bool flexiMode() const { return flexiMode_; }
344 
345  int drawHeight() const { return panel_height_ - legend_height_; }
346  // returns the width to draw a line in draw coords.
347  double getDrawLineWidth() const;
348 
349  //! returns the drawing scale (conversion from molecular coords -> drawing
350  /// coords)
351  double scale() const;
352  //! explicitly sets the scaling factors for the drawing
353  void setScale(double newScale);
354  void setScale(int width, int height, const Point2D &minv, const Point2D &maxv,
355  const ROMol *mol = nullptr);
356  //! sets the drawing offset (in drawing coords)
357  void setOffset(int x, int y) {
358  x_offset_ = x;
359  y_offset_ = y;
360  }
361  //! returns the drawing offset (in drawing coords)
362  Point2D offset() const { return Point2D(x_offset_, y_offset_); }
363 
364  //! returns the minimum point of the drawing (in molecular coords)
365  Point2D minPt() const;
366  //! returns the width and height of the grid (in molecular coords)
367  Point2D range() const;
368 
369  //! font size in drawing coordinate units. That's probably pixels.
370  virtual double fontSize() const;
371  virtual void setFontSize(double new_size);
372 
373  //! sets the current draw color
374  virtual void setColour(const DrawColour &col) { curr_colour_ = col; }
375  //! returns the current draw color
376  virtual DrawColour colour() const { return curr_colour_; }
377  //! sets the current dash pattern
378  virtual void setDash(const DashPattern &patt) { curr_dash_ = patt; }
379  //! returns the current dash pattern
380  virtual const DashPattern &dash() const { return curr_dash_; }
381 
382  //! sets the current line width
383  virtual void setLineWidth(double width) {
384  drawOptions().bondLineWidth = width;
385  }
386  //! returns the current line width
387  virtual double lineWidth() const { return drawOptions().bondLineWidth; }
388 
389  //! using the current scale, work out the size of the label in molecule
390  //! coordinates.
391  /*!
392  Bear in mind when implementing this, that, for example, NH2 will appear as
393  NH<sub>2</sub> to convey that the 2 is a subscript, and this needs to
394  accounted for in the width and height.
395  */
396  virtual void getStringSize(const std::string &label, double &label_width,
397  double &label_height) const;
398  // get the overall size of the label, allowing for it being split
399  // into pieces according to orientation.
400  void getLabelSize(const std::string &label,
401  MolDraw2D_detail::OrientType orient, double &label_width,
402  double &label_height) const;
403  // return extremes for string in molecule coords.
404  void getStringExtremes(const std::string &label,
406  const Point2D &cds, double &x_min, double &y_min,
407  double &x_max, double &y_max) const;
408 
409  //! adds additional information about the atoms to the output. Does not make
410  //! sense for all renderers.
411  virtual void tagAtoms(const ROMol &mol) { RDUNUSED_PARAM(mol); }
412  //! set whether or not polygons are being filled
413  virtual bool fillPolys() const { return fill_polys_; }
414  //! returns either or not polygons should be filled
415  virtual void setFillPolys(bool val) { fill_polys_ = val; }
416 
417  //! returns our current drawing options
418  MolDrawOptions &drawOptions() { return options_; }
419  //! \overload
420  const MolDrawOptions &drawOptions() const { return options_; }
421 
422  virtual bool supportsAnnotations() const { return true; }
423 
424  void setActiveMolIdx(int newIdx);
425  bool hasActiveAtmIdx() const { return activeAtmIdx1_ >= 0; }
426  int getActiveAtmIdx1() const { return activeAtmIdx1_; }
427  int getActiveAtmIdx2() const { return activeAtmIdx2_; }
428  void setActiveAtmIdx(int at_idx1 = -1, int at_idx2 = -1);
429  bool hasActiveBndIdx() const { return activeBndIdx_ >= 0; }
430  int getActiveBndIdx() const { return activeBndIdx_; }
431  void setActiveBndIdx(int bnd_idx = -1) {
432  activeBndIdx_ = (bnd_idx < 0 ? -1 : bnd_idx);
433  }
434  void setActiveClass(std::string actClass = std::string("")) {
435  d_activeClass = actClass;
436  }
437  std::string getActiveClass() const { return d_activeClass; }
438 
439  protected:
440  std::unique_ptr<MolDraw2D_detail::DrawText> text_drawer_;
441  std::string d_activeClass;
442  bool needs_init_ = true;
443  std::vector<std::pair<std::string, std::string>> d_metadata;
444  unsigned int d_numMetadataEntries = 0;
445 
446  private:
447  //! \name Methods that must be provided by child classes
448  //! @{
449  virtual void initDrawing() = 0;
450  virtual void initTextDrawer(bool noFreetype) = 0;
451 
452  // if the width or height of the DrawMol was -1, the new dimensions need to be
453  // transferred to MolDraw2D.
454  void fixVariableDimensions(const MolDraw2D_detail::DrawMol &drawMol);
455 
456  // split the reaction up into the reagents, products and agents, each as
457  // a separate entity with its own scale.
458  void getReactionDrawMols(
459  const ChemicalReaction &rxn, bool highlightByReactant,
460  const std::vector<DrawColour> *highlightColorsReactants,
461  const std::vector<int> *confIds,
462  std::vector<std::shared_ptr<MolDraw2D_detail::DrawMol>> &reagents,
463  std::vector<std::shared_ptr<MolDraw2D_detail::DrawMol>> &products,
464  std::vector<std::shared_ptr<MolDraw2D_detail::DrawMol>> &agents,
465  int &plusWidth);
466  // take the given components from the reaction (bits will be either
467  // reagents, products or agents) and create the corresponding DrawMols.
468  void makeReactionComponents(
469  std::vector<RDKit::ROMOL_SPTR> const &bits,
470  const std::vector<int> *confIds, int heightToUse,
471  std::map<int, DrawColour> &atomColours,
472  std::vector<std::shared_ptr<MolDraw2D_detail::DrawMol>> &dms,
473  double &minScale, double &minFontScale);
474  // this puts a pointer to the DrawMol into _drawMols as well, hence the use
475  // of shared_ptr for reagents, products and agents above.
476  void makeReactionDrawMol(
477  RWMol &mol, int confId, int molHeight,
478  const std::vector<int> &highlightAtoms,
479  const std::vector<int> &highlightBonds,
480  const std::map<int, DrawColour> &highlightAtomMap,
481  const std::map<int, DrawColour> &highlightBondMap,
482  std::vector<std::shared_ptr<MolDraw2D_detail::DrawMol>> &mols);
483  // Strictly speaking, this isn't actually a const function, although the
484  // compiler can't spot it, because the scales of reagents etc may be changed,
485  // and they are also in drawMols_.
486  void calcReactionOffsets(
487  std::vector<std::shared_ptr<MolDraw2D_detail::DrawMol>> &reagents,
488  std::vector<std::shared_ptr<MolDraw2D_detail::DrawMol>> &products,
489  std::vector<std::shared_ptr<MolDraw2D_detail::DrawMol>> &agents,
490  int &plusWidth, std::vector<Point2D> &offsets, Point2D &arrowBeg,
491  Point2D &arrowEnd);
492  // returns the final offset. plusWidth of 0 means no pluses to be drawn.
493  int drawReactionPart(
494  std::vector<std::shared_ptr<MolDraw2D_detail::DrawMol>> &reactBit,
495  int plusWidth, int initOffset, const std::vector<Point2D> &offsets);
496  // returns a map of colours indexed by the atomMapNum. Each reagent gives
497  // a different colour.
498  void findReactionHighlights(
499  const ChemicalReaction &rxn, bool highlightByReactant,
500  const std::vector<DrawColour> *highlightColorsReactants,
501  std::map<int, DrawColour> &atomColours) const;
502 
503  int width_, height_, panel_width_, panel_height_, legend_height_;
504  // if the user calls setScale() to explicitly force a scale on the
505  // DrawMols, this is set to true.
506  bool forceScale_ = false;
507  bool flexiMode_ = false;
508  double scale_, fontScale_;
509  int x_offset_, y_offset_; // translation in screen coordinates
510  bool fill_polys_;
511  int activeMolIdx_;
512  int activeAtmIdx1_;
513  int activeAtmIdx2_;
514  int activeBndIdx_;
515  // these are shared_ptr rather than unique_ptr because the reactions
516  // keep their own copy.
517  std::vector<std::shared_ptr<MolDraw2D_detail::DrawMol>> drawMols_;
518  // this is for when we want to set up a MolDraw2D to a given scale and be
519  // able to draw molecules and arbitrary lines, arcs etc. onto it all to the
520  // same drawing transformation. If present, it will always be applied to
521  // any new drawMols_ before they are drawn. A separate class might have
522  // been better, but this is convenient.
523  std::unique_ptr<MolDraw2D_detail::DrawMol> globalDrawTrans_;
524 
525  DrawColour curr_colour_;
526  DashPattern curr_dash_;
527  MolDrawOptions options_;
528 
529  // Do the drawing, the new way
530  void startDrawing();
531  void drawTheMolecule(MolDraw2D_detail::DrawMol &drawMol);
532  void setupTextDrawer();
533 
534  virtual void updateMetadata(const ROMol &mol, int confId) {
535  RDUNUSED_PARAM(mol);
536  RDUNUSED_PARAM(confId);
537  }
538  virtual void updateMetadata(const ChemicalReaction &rxn) {
539  RDUNUSED_PARAM(rxn);
540  }
541 };
542 
543 inline void setDarkMode(MolDrawOptions &opts) {
545  opts.backgroundColour = DrawColour{0.0, 0.0, 0.0, 1.0};
546  opts.annotationColour = DrawColour{0.9, 0.9, 0.9, 1.0};
547  opts.legendColour = DrawColour{0.9, 0.9, 0.9, 1.0};
548  opts.symbolColour = DrawColour{0.9, 0.9, 0.9, 1.0};
549  opts.variableAttachmentColour = DrawColour{0.3, 0.3, 0.3, 1.0};
550 }
551 inline void setDarkMode(MolDraw2D &d2d) { setDarkMode(d2d.drawOptions()); }
552 inline void setMonochromeMode(MolDrawOptions &opts, const DrawColour &fgColour,
553  const DrawColour &bgColour) {
554  opts.atomColourPalette.clear();
555  opts.atomColourPalette[-1] = fgColour;
556  opts.backgroundColour = bgColour;
557  opts.annotationColour = fgColour;
558  opts.legendColour = fgColour;
559  opts.symbolColour = fgColour;
560  opts.variableAttachmentColour = fgColour;
561 }
562 inline void setMonochromeMode(MolDraw2D &drawer, const DrawColour &fgColour,
563  const DrawColour &bgColour) {
564  setMonochromeMode(drawer.drawOptions(), fgColour, bgColour);
565 }
566 
567 } // namespace RDKit
568 
569 #endif // RDKITMOLDRAW2D_H
#define RDUNUSED_PARAM(x)
Definition: Invariant.h:196
#define M_PI
Definition: MMFF/Params.h:27
pulls in the core RDKit functionality
This is a class for storing and applying general chemical reactions.
Definition: Reaction.h:121
MolDraw2D is the base class for doing 2D renderings of molecules.
Definition: MolDraw2D.h:47
virtual void tagAtoms(const ROMol &mol)
Definition: MolDraw2D.h:411
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...
void setActiveBndIdx(int bnd_idx=-1)
Definition: MolDraw2D.h:431
MolDraw2D & operator=(MolDraw2D &&rhs)=delete
void setScale(int width, int height, const Point2D &minv, const Point2D &maxv, const ROMol *mol=nullptr)
int panelHeight() const
return the height of the drawing panels.
Definition: MolDraw2D.h:332
virtual ~MolDraw2D()
virtual void drawLine(const Point2D &cds1, const Point2D &cds2, const DrawColour &col1, const DrawColour &col2, bool rawCoords=false)
draw a line where the ends are different colours
virtual void setFontSize(double new_size)
virtual Point2D getAtomCoords(int at_num) const
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 getStringSize(const std::string &label, double &label_width, double &label_height) const
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.
virtual void drawArrow(const Point2D &cds1, const Point2D &cds2, bool asPolygon=false, double frac=0.05, double angle=M_PI/6, const DrawColour &col=DrawColour(0.0, 0.0, 0.0), bool rawCoords=false)
Draw an arrow with either lines or a filled head (when asPolygon is true)
void drawReaction(const ChemicalReaction &rxn, bool highlightByReactant=false, const std::vector< DrawColour > *highlightColorsReactants=nullptr, const std::vector< int > *confIds=nullptr)
draw a ChemicalReaction
void setFlexiMode(bool mode)
Definition: MolDraw2D.h:336
bool hasActiveBndIdx() const
Definition: MolDraw2D.h:429
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
MolDraw2D & operator=(const MolDraw2D &rhs)=delete
int getActiveAtmIdx2() const
Definition: MolDraw2D.h:427
virtual void drawLine(const Point2D &cds1, const Point2D &cds2, bool rawCoords=false)=0
MolDraw2D(int width, int height, int panelWidth, int panelHeight)
constructor for a particular size
void getLabelSize(const std::string &label, MolDraw2D_detail::OrientType orient, double &label_width, double &label_height) const
const std::vector< std::pair< std::string, MolDraw2D_detail::OrientType > > & atomSyms() const
returns the atomic symbols of the activeMolIdx_ molecule
double getDrawLineWidth() const
std::unique_ptr< MolDraw2D_detail::DrawText > text_drawer_
Definition: MolDraw2D.h:440
virtual double lineWidth() const
returns the current line width
Definition: MolDraw2D.h:387
int height() const
return the height of the drawing area.
Definition: MolDraw2D.h:328
void getStringExtremes(const std::string &label, MolDraw2D_detail::OrientType orient, const Point2D &cds, double &x_min, double &y_min, double &x_max, double &y_max) const
virtual bool fillPolys() const
set whether or not polygons are being filled
Definition: MolDraw2D.h:413
virtual void drawWavyLine(const Point2D &cds1, const Point2D &cds2, const DrawColour &col1, const DrawColour &col2, unsigned int nSegments=16, double vertOffset=0.05, bool rawCoords=false)
draw a wavy line like that used to indicate unknown stereochemistry
virtual void drawPlus(const Point2D &cds, int plusWidth, const DrawColour &col, bool rawCoords=false)
virtual bool supportsAnnotations() const
Definition: MolDraw2D.h:422
int drawHeight() const
Definition: MolDraw2D.h:345
virtual void setDash(const DashPattern &patt)
sets the current dash pattern
Definition: MolDraw2D.h:378
virtual void drawString(const std::string &str, const Point2D &cds, bool rawCoords=false)
drawString centres the string on cds.
MolDraw2D(MolDraw2D &&rhs)=delete
virtual DrawColour colour() const
returns the current draw color
Definition: MolDraw2D.h:376
virtual void drawArc(const Point2D &centre, double radius, double ang1, double ang2, bool rawCoords=false)
virtual void setColour(const DrawColour &col)
sets the current draw color
Definition: MolDraw2D.h:374
std::pair< int, int > getMolSize(const ROMol &mol, const std::string &legend="", const std::vector< int > *highlight_atoms=nullptr, const std::vector< int > *highlight_bonds=nullptr, 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)
returns the size of the box for the molecule with current drawing settings
int getActiveAtmIdx1() const
Definition: MolDraw2D.h:426
Point2D range() const
returns the width and height of the grid (in molecular coords)
MolDraw2D(const MolDraw2D &rhs)=delete
MolDrawOptions & drawOptions()
returns our current drawing options
Definition: MolDraw2D.h:418
virtual Point2D getDrawCoords(const Point2D &mol_cds) const
virtual void drawTriangle(const Point2D &cds1, const Point2D &cds2, const Point2D &cds3, bool rawCoords=false)
draw a triangle
virtual void drawString(const std::string &str, const Point2D &cds, MolDraw2D_detail::TextAlignType align, bool rawCoords=false)
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
std::string d_activeClass
Definition: MolDraw2D.h:441
virtual void drawAttachmentLine(const Point2D &cds1, const Point2D &cds2, const DrawColour &col, double len=1.0, unsigned int nSegments=16, bool rawCoords=false)
void setOffset(int x, int y)
sets the drawing offset (in drawing coords)
Definition: MolDraw2D.h:357
virtual void setLineWidth(double width)
sets the current line width
Definition: MolDraw2D.h:383
void setActiveClass(std::string actClass=std::string(""))
Definition: MolDraw2D.h:434
virtual Point2D getAtomCoords(const std::pair< double, double > &screen_cds) const
virtual void setFillPolys(bool val)
returns either or not polygons should be filled
Definition: MolDraw2D.h:415
virtual void drawRect(const Point2D &cds1, const Point2D &cds2, bool rawCoords=false)
draw a rectangle given two opposite corners
virtual void drawPolygon(const std::vector< Point2D > &cds, bool rawCoords=false)=0
virtual void drawEllipse(const Point2D &cds1, const Point2D &cds2, bool rawCoords=false)
draw an ellipse
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...
void setActiveMolIdx(int newIdx)
int panelWidth() const
return the width of the drawing panels.
Definition: MolDraw2D.h:330
virtual void clearDrawing()
clears the contents of the drawing
Definition: MolDraw2D.h:208
Point2D minPt() const
returns the minimum point of the drawing (in molecular coords)
void setActiveAtmIdx(int at_idx1=-1, int at_idx2=-1)
Point2D offset() const
returns the drawing offset (in drawing coords)
Definition: MolDraw2D.h:362
bool hasActiveAtmIdx() const
Definition: MolDraw2D.h:425
int width() const
return the width of the drawing area.
Definition: MolDraw2D.h:326
std::vector< std::pair< std::string, std::string > > d_metadata
Definition: MolDraw2D.h:443
int getActiveBndIdx() const
Definition: MolDraw2D.h:430
virtual const DashPattern & dash() const
returns the current dash pattern
Definition: MolDraw2D.h:380
virtual double fontSize() const
font size in drawing coordinate units. That's probably pixels.
std::string getActiveClass() const
Definition: MolDraw2D.h:437
double scale() const
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 setScale(double newScale)
explicitly sets the scaling factors for the drawing
const std::vector< Point2D > & atomCoords() const
virtual void drawArc(const Point2D &centre, double xradius, double yradius, double ang1, double ang2, bool rawCoords=false)
const MolDrawOptions & drawOptions() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: MolDraw2D.h:420
bool flexiMode() const
Definition: MolDraw2D.h:343
RWMol is a molecule class that is intended to be edited.
Definition: RWMol.h:32
#define RDKIT_MOLDRAW2D_EXPORT
Definition: export.h:281
Std stuff.
Definition: Abbreviations.h:19
std::vector< double > DashPattern
void setMonochromeMode(MolDrawOptions &opts, const DrawColour &fgColour, const DrawColour &bgColour)
Definition: MolDraw2D.h:552
void assignDarkModePalette(ColourPalette &palette)
void setDarkMode(MolDrawOptions &opts)
Definition: MolDraw2D.h:543
DrawColour variableAttachmentColour
ColourPalette atomColourPalette