23 #ifndef RDKITMOLDRAW2D_H
24 #define RDKITMOLDRAW2D_H
42 double r = 0.0, g = 0.0, b = 0.0, a = 1.0;
45 : r(r), g(g), b(b), a(a){};
47 return r == other.
r && g == other.
g && b == other.
b && a == other.
a;
50 bool ignoreAlpha =
true)
const {
51 return fabs(r - other.
r) <= tol && fabs(g - other.
g) <= tol &&
52 fabs(b - other.
b) <= tol &&
53 (ignoreAlpha || fabs(a - other.
a) <= tol);
56 return {r + other.
r, g + other.
g, b + other.
b, a + other.
a};
59 return {r - other.
r, g - other.
g, b - other.
b, a - other.
a};
63 return {r / v, g / v, b / v, a / v};
100 double padding)
const {
101 double wb2 = padding +
width_ / 2.0;
102 double hb2 = padding +
height_ / 2.0;
124 if ((otl.
x >= ttl.
x && otl.
x <= ttr.
x && otl.
y >= tbl.
y &&
126 (otr.
x >= ttl.
x && otr.
x <= ttr.
x && otr.
y >= tbl.
y &&
128 (obr.
x >= ttl.
x && obr.
x <= ttr.
x && obr.
y >= tbl.
y &&
130 (obl.
x >= ttl.
x && obl.
x <= ttr.
x && obl.
y >= tbl.
y &&
134 if ((ttl.
x >= otl.
x && ttl.
x <= otr.
x && ttl.
y >= obl.
y &&
136 (ttr.
x >= otl.
x && ttr.
x <= otr.
x && ttr.
y >= obl.
y &&
138 (tbr.
x >= otl.
x && tbr.
x <= otr.
x && tbr.
y >= obl.
y &&
140 (tbl.
x >= otl.
x && tbl.
x <= otr.
x && tbl.
y >= obl.
y &&
155 palette[1] = palette[6] =
DrawColour(0.0, 0.0, 0.0);
172 bool atomLabelDeuteriumTritium =
174 bool dummiesAreAttachments =
false;
175 bool circleAtoms =
true;
177 bool continuousHighlight =
true;
179 bool fillHighlights =
true;
181 double highlightRadius = 0.3;
183 int flagCloseContactsDist = 3;
185 bool includeAtomTags =
188 bool clearBackground =
true;
192 int legendFontSize = 16;
194 int maxFontSize = 40;
197 double annotationFontScale = 0.5;
199 std::string fontFile =
"";
203 double multipleBondOffset = 0.15;
207 double additionalAtomLabelPadding = 0.0;
214 int bondLineWidth = 2;
215 bool scaleBondWidth =
false;
216 bool scaleHighlightBondWidth =
true;
217 int highlightBondWidthMultiplier = 8;
219 bool prepareMolsBeforeDrawing =
true;
232 double fixedBondLength =
246 bool atomHighlightsAreCircles =
false;
249 bool centreMoleculesBeforeDrawing =
false;
251 bool explicitMethyl =
false;
252 bool includeRadicals =
255 bool includeMetadata =
260 highlightColourPalette.emplace_back(
262 highlightColourPalette.emplace_back(
DrawColour(1., .8, .6));
263 highlightColourPalette.emplace_back(
265 highlightColourPalette.emplace_back(
267 highlightColourPalette.emplace_back(
DrawColour(.87, .63, .87));
268 highlightColourPalette.emplace_back(
270 highlightColourPalette.emplace_back(
272 highlightColourPalette.emplace_back(
DrawColour(.64, .76, .34));
273 highlightColourPalette.emplace_back(
275 highlightColourPalette.emplace_back(
DrawColour(.20, .63, .79));
294 MolDraw2D(
int width,
int height,
int panelWidth,
int panelHeight);
300 virtual void initDrawing() = 0;
301 virtual void initTextDrawer(
bool noFreetype) = 0;
335 const ROMol &mol,
const std::string &legend,
336 const std::vector<int> *highlight_atoms,
337 const std::vector<int> *highlight_bonds,
338 const std::map<int, DrawColour> *highlight_atom_map =
nullptr,
339 const std::map<int, DrawColour> *highlight_bond_map =
nullptr,
340 const std::map<int, double> *highlight_radii =
nullptr,
int confId = -1);
344 const ROMol &mol,
const std::vector<int> *highlight_atoms =
nullptr,
345 const std::map<int, DrawColour> *highlight_map =
nullptr,
346 const std::map<int, double> *highlight_radii =
nullptr,
int confId = -1);
350 const ROMol &mol,
const std::string &legend,
351 const std::vector<int> *highlight_atoms =
nullptr,
352 const std::map<int, DrawColour> *highlight_map =
nullptr,
353 const std::map<int, double> *highlight_radii =
nullptr,
int confId = -1);
357 const ROMol &mol,
const std::vector<int> *highlight_atoms,
358 const std::vector<int> *highlight_bonds,
359 const std::map<int, DrawColour> *highlight_atom_map =
nullptr,
360 const std::map<int, DrawColour> *highlight_bond_map =
nullptr,
361 const std::map<int, double> *highlight_radii =
nullptr,
int confId = -1);
378 const ROMol &mol,
const std::string &legend,
379 const std::map<
int, std::vector<DrawColour>> &highlight_atom_map,
380 const std::map<
int, std::vector<DrawColour>> &highlight_bond_map,
381 const std::map<int, double> &highlight_radii,
382 const std::map<int, int> &highlight_linewidth_multipliers,
412 const std::vector<ROMol *> &mols,
413 const std::vector<std::string> *legends =
nullptr,
414 const std::vector<std::vector<int>> *highlight_atoms =
nullptr,
415 const std::vector<std::vector<int>> *highlight_bonds =
nullptr,
416 const std::vector<std::map<int, DrawColour>> *highlight_atom_maps =
418 const std::vector<std::map<int, DrawColour>> *highlight_bond_maps =
420 const std::vector<std::map<int, double>> *highlight_radii =
nullptr,
421 const std::vector<int> *confIds =
nullptr);
437 const std::vector<DrawColour> *highlightColorsReactants =
nullptr,
438 const std::vector<int> *confIds =
nullptr);
459 const std::pair<double, double> &screen_cds)
const;
464 virtual int width()
const {
return width_; }
466 virtual int height()
const {
return height_; }
471 virtual int drawHeight()
const {
return panel_height_ - legend_height_; }
475 double scale()
const {
return scale_; }
479 const std::vector<int> *highlight_atoms =
nullptr,
480 const std::map<int, double> *highlight_radii =
nullptr);
485 const std::vector<std::vector<int>> *highlight_atoms,
486 const std::vector<std::map<int, double>> *highlight_radii,
487 const std::vector<int> *confIds,
488 std::vector<std::unique_ptr<RWMol>> &tmols);
494 const ROMol *mol =
nullptr);
522 virtual void setLineWidth(
int width) { drawOptions().bondLineWidth = width; }
524 virtual int lineWidth()
const {
return drawOptions().bondLineWidth; }
534 double &label_height)
const;
538 double &label_width,
double &label_height)
const;
541 const Point2D &cds,
double &x_min,
double &y_min,
542 double &x_max,
double &y_max)
const;
563 double ang1,
double ang2);
570 unsigned int nSegments = 16);
574 unsigned int nSegments = 16,
575 double vertOffset = 0.05);
593 return at_cds_[activeMolIdx_];
596 const std::vector<std::pair<std::string, OrientType>> &
atomSyms()
const {
598 return atom_syms_[activeMolIdx_];
602 bool asPolygon =
false,
double frac = 0.05,
603 double angle =
M_PI / 6);
615 int width_, height_, panel_width_, panel_height_, legend_height_;
617 double x_min_, y_min_, x_range_, y_range_;
618 double x_trans_, y_trans_;
619 int x_offset_, y_offset_;
627 std::vector<std::vector<Point2D>> at_cds_;
628 std::vector<std::vector<int>> atomic_nums_;
629 std::vector<std::vector<std::pair<std::string, OrientType>>> atom_syms_;
635 std::vector<std::vector<std::shared_ptr<StringRect>>> atom_notes_;
636 std::vector<std::vector<std::shared_ptr<StringRect>>> bond_notes_;
637 std::vector<std::vector<std::pair<std::shared_ptr<StringRect>,
OrientType>>>
645 int atom_idx,
const std::vector<int> *highlight_atoms =
nullptr,
646 const std::map<int, DrawColour> *highlight_map =
nullptr);
647 DrawColour getColourByAtomicNum(
int atomic_num);
650 std::unique_ptr<RWMol> setupDrawMolecule(
651 const ROMol &mol,
const std::vector<int> *highlight_atoms,
652 const std::map<int, double> *highlight_radii,
int confId,
int width,
656 void pushDrawDetails();
657 void popDrawDetails();
660 std::unique_ptr<RWMol> setupMoleculeDraw(
661 const ROMol &mol,
const std::vector<int> *highlight_atoms,
662 const std::map<int, double> *highlight_radii,
int confId = -1);
663 void setupTextDrawer();
668 void drawBonds(
const ROMol &draw_mol,
669 const std::vector<int> *highlight_atoms =
nullptr,
670 const std::map<int, DrawColour> *highlight_atom_map =
nullptr,
671 const std::vector<int> *highlight_bonds =
nullptr,
672 const std::map<int, DrawColour> *highlight_bond_map =
nullptr,
673 const std::vector<std::pair<DrawColour, DrawColour>>
674 *bond_colours =
nullptr);
676 void finishMoleculeDraw(
const ROMol &draw_mol,
677 const std::vector<DrawColour> &atom_colours);
678 void drawLegend(
const std::string &legend);
680 void drawHighlightedAtom(
int atom_idx,
const std::vector<DrawColour> &colours,
681 const std::map<int, double> *highlight_radii);
687 const Point2D &label_coords)
const;
690 void calcLabelEllipse(
int atom_idx,
691 const std::map<int, double> *highlight_radii,
692 Point2D ¢re,
double &xradius,
693 double &yradius)
const;
701 void calcAtomAnnotationPosition(
const ROMol &mol,
const Atom *atom,
705 void drawHighlightedBonds(
707 const std::map<
int, std::vector<DrawColour>> &highlight_bond_map,
708 const std::map<int, int> &highlight_linewidth_multipliers,
709 const std::map<int, double> *highlight_radii);
710 int getHighlightBondWidth(
712 const std::map<int, int> *highlight_linewidth_multipliers)
const;
715 void adjustLineEndForHighlight(
int at_idx,
716 const std::map<int, double> *highlight_radii,
719 void extractAtomCoords(
const ROMol &mol,
int confId,
bool updateBBox);
720 void extractAtomSymbols(
const ROMol &mol);
721 void extractAtomNotes(
const ROMol &mol);
722 void extractBondNotes(
const ROMol &mol);
723 void extractRadicals(
const ROMol &mol);
734 void drawAtomLabel(
int atom_num,
735 const std::vector<int> *highlight_atoms =
nullptr,
736 const std::map<int, DrawColour> *highlight_map =
nullptr);
739 void drawRadicals(
const ROMol &mol);
743 double getNoteStartAngle(
const ROMol &mol,
const Atom *atom)
const;
748 const std::vector<std::shared_ptr<StringRect>> &rects,
749 const ROMol &mol,
unsigned int atom_idx);
751 const std::vector<std::shared_ptr<StringRect>> &rects,
755 bool doesNoteClashNbourBonds(
757 const std::vector<std::shared_ptr<StringRect>> &rects,
const ROMol &mol,
758 const Atom *atom)
const;
760 bool doesNoteClashAtomLabels(
762 const std::vector<std::shared_ptr<StringRect>> &rects,
const ROMol &mol,
763 unsigned int atom_idx)
const;
764 bool doesNoteClashOtherNotes(
766 const std::vector<std::shared_ptr<StringRect>> &rects)
const;
784 void adjustBondEndForLabel(
int atnum,
const Point2D &nbr_cds,
788 std::pair<std::string, OrientType> getAtomSymbolAndOrientation(
789 const Atom &atom)
const;
790 std::string getAtomSymbol(
const Atom &atom,
OrientType orientation)
const;
794 void adjustScaleForAtomLabels(
const std::vector<int> *highlight_atoms,
795 const std::map<int, double> *highlight_radii);
796 void adjustScaleForRadicals(
const ROMol &mol);
797 void adjustScaleForAnnotation(
798 const std::vector<std::shared_ptr<StringRect>> ¬es);
801 virtual void updateMetadata(
const ROMol &mol,
int confId) {
811 unsigned int d_numMetadataEntries = 0;
814 const ROMol &mol,
const std::vector<int> *highlight_atoms,
815 const std::vector<int> *highlight_bonds,
816 const std::map<int, DrawColour> *highlight_atom_map,
817 const std::map<int, DrawColour> *highlight_bond_map,
818 const std::map<int, double> *highlight_radii);
825 const ROMol &mol,
const Bond *bond,
int at1_idx,
int at2_idx,
826 const std::vector<int> *highlight_atoms =
nullptr,
827 const std::map<int, DrawColour> *highlight_atom_map =
nullptr,
828 const std::vector<int> *highlight_bonds =
nullptr,
829 const std::map<int, DrawColour> *highlight_bond_map =
nullptr,
830 const std::vector<std::pair<DrawColour, DrawColour>> *bond_colours =
834 const std::shared_ptr<StringRect> ¬e_rect);
860 Point2D &arrowEnd, std::vector<double> &plusLocs,
861 double spacing,
const std::vector<int> *confIds);
864 double &minY,
int confId,
bool shiftAgents,
880 double padding = 0.0);
#define RDUNUSED_PARAM(x)
#define PRECONDITION(expr, mess)
pulls in the core RDKit functionality
The class for representing atoms.
class for representing a bond
This is a class for storing and applying general chemical reactions.
MolDraw2D is the base class for doing 2D renderings of molecules.
virtual void tagAtoms(const ROMol &mol)
void calculateScale(int width, int height, const std::vector< ROMol * > &mols, const std::vector< std::vector< int >> *highlight_atoms, const std::vector< std::map< int, double >> *highlight_radii, const std::vector< int > *confIds, std::vector< std::unique_ptr< RWMol >> &tmols)
overload
void getStringExtremes(const std::string &label, OrientType orient, const Point2D &cds, double &x_min, double &y_min, double &x_max, double &y_max) const
virtual void drawBond(const ROMol &mol, const Bond *bond, int at1_idx, int at2_idx, const std::vector< int > *highlight_atoms=nullptr, const std::map< int, DrawColour > *highlight_atom_map=nullptr, const std::vector< int > *highlight_bonds=nullptr, const std::map< int, DrawColour > *highlight_bond_map=nullptr, const std::vector< std::pair< DrawColour, DrawColour >> *bond_colours=nullptr)
virtual void drawMoleculeWithHighlights(const ROMol &mol, const std::string &legend, const std::map< int, std::vector< DrawColour >> &highlight_atom_map, const std::map< int, std::vector< DrawColour >> &highlight_bond_map, const std::map< int, double > &highlight_radii, const std::map< int, int > &highlight_linewidth_multipliers, int confId=-1)
draw molecule with multiple colours allowed per atom.
void setScale(int width, int height, const Point2D &minv, const Point2D &maxv, const ROMol *mol=nullptr)
explicitly sets the scaling factors for the drawing
void centrePicture(int width, int height)
virtual int panelWidth() const
return the width of the drawing panels.
virtual void drawTriangle(const Point2D &cds1, const Point2D &cds2, const Point2D &cds3)
draw a triangle
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_
virtual void drawString(const std::string &str, const Point2D &cds, TextAlignType align)
virtual Point2D getAtomCoords(int at_num) const
returns the molecular coordinates of a particular atom
virtual void getStringSize(const std::string &label, double &label_width, double &label_height) const
Point2D calcPerpendicular(const Point2D &cds1, const Point2D &cds2) const
virtual void drawMolecule(const ROMol &mol, const std::vector< int > *highlight_atoms, const std::vector< int > *highlight_bonds, const std::map< int, DrawColour > *highlight_atom_map=nullptr, const std::map< int, DrawColour > *highlight_bond_map=nullptr, const std::map< int, double > *highlight_radii=nullptr, int confId=-1)
This is an overloaded member function, provided for convenience. It differs from the above function o...
void getLabelSize(const std::string &label, OrientType orient, double &label_width, double &label_height) const
virtual void highlightCloseContacts()
virtual int drawHeight() const
virtual void drawLine(const Point2D &cds1, const Point2D &cds2)=0
draws a line from cds1 to cds2 using the current drawing style
virtual void drawArc(const Point2D ¢re, 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
virtual void drawArc(const Point2D ¢re, double radius, double ang1, double ang2)
virtual void drawEllipse(const Point2D &cds1, const Point2D &cds2)
draw an ellipse
virtual void drawMolecules(const std::vector< ROMol * > &mols, const std::vector< std::string > *legends=nullptr, const std::vector< std::vector< int >> *highlight_atoms=nullptr, const std::vector< std::vector< int >> *highlight_bonds=nullptr, const std::vector< std::map< int, DrawColour >> *highlight_atom_maps=nullptr, const std::vector< std::map< int, DrawColour >> *highlight_bond_maps=nullptr, const std::vector< std::map< int, double >> *highlight_radii=nullptr, const std::vector< int > *confIds=nullptr)
draw multiple molecules in a grid
virtual void drawMolecule(const ROMol &mol, const std::string &legend, const std::vector< int > *highlight_atoms=nullptr, const std::map< int, DrawColour > *highlight_map=nullptr, const std::map< int, double > *highlight_radii=nullptr, int confId=-1)
This is an overloaded member function, provided for convenience. It differs from the above function o...
virtual void clearDrawing()=0
clears the contents of the drawing
virtual int height() const
return the height of the drawing area.
virtual void setDash(const DashPattern &patt)
sets the current dash pattern
virtual DrawColour colour() const
returns the current draw color
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
virtual void drawAtomLabel(int atom_num, const DrawColour &draw_colour)
Point2D range() const
returns the width and height of the grid (in molecular coords)
bool isLinearAtom(const Atom &atom) const
MolDrawOptions & drawOptions()
returns our current drawing options
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()
void setOffset(int x, int y)
sets the drawing offset (in drawing coords)
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.
virtual void setFillPolys(bool val)
returns either or not polygons should be filled
void get2DCoordsMol(RWMol &mol, double &offset, double spacing, double &maxY, double &minY, int confId, bool shiftAgents, double coordScale)
virtual void drawRect(const Point2D &cds1, const Point2D &cds2)
draw a rectangle
void calcTripleBondLines(double offset, const Bond *bond, const Point2D &at1_cds, const Point2D &at2_cds, Point2D &l1s, Point2D &l1f, Point2D &l2s, Point2D &l2f) const
void calcDoubleBondLines(const ROMol &mol, double offset, const Bond *bond, const Point2D &at1_cds, const Point2D &at2_cds, Point2D &l1s, Point2D &l1f, Point2D &l2s, Point2D &l2f) const
virtual void drawAnnotation(const std::string ¬e, const std::shared_ptr< StringRect > ¬e_rect)
virtual int panelHeight() const
return the height of the drawing panels.
const std::vector< std::pair< std::string, OrientType > > & atomSyms() const
returns the atomic symbols of the current molecule
Point2D minPt() const
returns the minimum point of the drawing (in molecular coords)
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
Point2D offset() const
returns the drawing offset (in drawing coords)
std::vector< std::pair< std::string, std::string > > d_metadata
virtual const DashPattern & dash() const
returns the current dash pattern
virtual double fontSize() const
font size in drawing coordinate units. That's probably pixels.
double scale() const
returns the drawing scale (conversion from molecular coords -> drawing
void get2DCoordsForReaction(ChemicalReaction &rxn, Point2D &arrowBegin, Point2D &arrowEnd, std::vector< double > &plusLocs, double spacing, const std::vector< int > *confIds)
virtual void drawAttachmentLine(const Point2D &cds1, const Point2D &cds2, const DrawColour &col, double len=1.0, unsigned int nSegments=16)
const std::vector< Point2D > & atomCoords() const
virtual int lineWidth() const
returns the current line width
void calculateScale(int width, int height, const ROMol &mol, const std::vector< int > *highlight_atoms=nullptr, const std::map< int, double > *highlight_radii=nullptr)
calculates the drawing scale (conversion from molecular coords -> drawing
const MolDrawOptions & drawOptions() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
virtual void drawString(const std::string &str, const Point2D &cds)
drawString centres the string on cds.
virtual void drawPolygon(const std::vector< Point2D > &cds)=0
RWMol is a molecule class that is intended to be edited.
#define RDKIT_MOLDRAW2D_EXPORT
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
RDKIT_MOLDRAW2D_EXPORT bool doesLineIntersectLabel(const Point2D &ls, const Point2D &lf, const StringRect &lab_rect, double padding=0.0)
std::vector< unsigned int > DashPattern
void assignDefaultPalette(ColourPalette &palette)
RDKIT_MOLDRAW2D_EXPORT bool doLinesIntersect(const Point2D &l1s, const Point2D &l1f, const Point2D &l2s, const Point2D &l2f, Point2D *ip=nullptr)
std::map< int, DrawColour > ColourPalette
void assignBWPalette(ColourPalette &palette)
bool feq(const DrawColour &other, double tol=0.001, bool ignoreAlpha=true) const
DrawColour operator+(const DrawColour &other) const
DrawColour operator/(double v) const
DrawColour operator*(double v) const
DrawColour(double r, double g, double b, double a=1.0)
DrawColour operator-(const DrawColour &other) const
bool operator==(const DrawColour &other) const
std::vector< std::vector< int > > atomRegions
std::map< int, std::string > atomLabels
ColourPalette atomColourPalette
std::vector< DrawColour > highlightColourPalette
StringRect(const Point2D &offset, const Point2D &g_centre, double w, double h)
void calcCorners(Point2D &tl, Point2D &tr, Point2D &br, Point2D &bl, double padding) const
bool doesItIntersect(const StringRect &other) const