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