RDKit: MolDraw2D.h Source File

| RDKit Open-source cheminformatics and machine learning.

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