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