 |
RDKit
Open-source cheminformatics and machine learning.
|
Go to the documentation of this file.
23 #ifndef RDKITMOLDRAW2D_H
24 #define RDKITMOLDRAW2D_H
38 double r = 0.0,
g = 0.0,
b = 0.0,
a = 1.0;
43 return r == other.
r &&
g == other.
g &&
b == other.
b &&
a == other.
a;
46 bool ignoreAlpha =
true)
const {
47 return fabs(
r - other.
r) <= tol && fabs(
g - other.
g) <= tol &&
48 fabs(
b - other.
b) <= tol &&
49 (ignoreAlpha || fabs(
a - other.
a) <= tol);
52 return {
r + other.
r,
g + other.
g,
b + other.
b,
a + other.
a};
55 return {
r - other.
r,
g - other.
g,
b - other.
b,
a - other.
a};
59 return {
r / v,
g / v,
b / v,
a / v};
99 palette[1] = palette[6] =
DrawColour(0.0, 0.0, 0.0);
116 bool atomLabelDeuteriumTritium =
118 bool dummiesAreAttachments =
false;
119 bool circleAtoms =
true;
121 bool continuousHighlight =
true;
123 bool fillHighlights =
true;
125 double highlightRadius = 0.3;
127 int flagCloseContactsDist = 3;
129 bool includeAtomTags =
132 bool clearBackground =
true;
136 int legendFontSize = 12;
138 int maxFontSize = 40;
140 double annotationFontScale = 0.75;
144 double multipleBondOffset = 0.15;
148 double additionalAtomLabelPadding = 0.0;
155 int bondLineWidth = -1;
157 int highlightBondWidthMultiplier = 8;
159 bool prepareMolsBeforeDrawing =
true;
172 double fixedBondLength =
186 bool atomHighlightsAreCircles =
false;
189 bool centreMoleculesBeforeDrawing =
false;
193 highlightColourPalette.emplace_back(
195 highlightColourPalette.emplace_back(
DrawColour(1., .8, .6));
196 highlightColourPalette.emplace_back(
198 highlightColourPalette.emplace_back(
200 highlightColourPalette.emplace_back(
DrawColour(.87, .63, .87));
201 highlightColourPalette.emplace_back(
203 highlightColourPalette.emplace_back(
205 highlightColourPalette.emplace_back(
DrawColour(.64, .76, .34));
206 highlightColourPalette.emplace_back(
208 highlightColourPalette.emplace_back(
DrawColour(.20, .63, .79));
218 typedef enum {
START, MIDDLE, END } AlignType;
236 MolDraw2D(
int width,
int height,
int panelWidth,
int panelHeight)
237 : needs_scale_(true),
240 panel_width_(panelWidth > 0 ? panelWidth : width),
241 panel_height_(panelHeight > 0 ? panelHeight : height),
274 const ROMol &mol,
const std::string &legend,
275 const std::vector<int> *highlight_atoms,
276 const std::vector<int> *highlight_bonds,
277 const std::map<int, DrawColour> *highlight_atom_map =
nullptr,
278 const std::map<int, DrawColour> *highlight_bond_map =
nullptr,
279 const std::map<int, double> *highlight_radii =
nullptr,
int confId = -1);
283 const ROMol &mol,
const std::vector<int> *highlight_atoms =
nullptr,
284 const std::map<int, DrawColour> *highlight_map =
nullptr,
285 const std::map<int, double> *highlight_radii =
nullptr,
int confId = -1);
289 const ROMol &mol,
const std::string &legend,
290 const std::vector<int> *highlight_atoms =
nullptr,
291 const std::map<int, DrawColour> *highlight_map =
nullptr,
292 const std::map<int, double> *highlight_radii =
nullptr,
int confId = -1);
296 const ROMol &mol,
const std::vector<int> *highlight_atoms,
297 const std::vector<int> *highlight_bonds,
298 const std::map<int, DrawColour> *highlight_atom_map =
nullptr,
299 const std::map<int, DrawColour> *highlight_bond_map =
nullptr,
300 const std::map<int, double> *highlight_radii =
nullptr,
int confId = -1);
317 const ROMol &mol,
const std::string &legend,
318 const std::map<
int, std::vector<DrawColour>> &highlight_atom_map,
319 const std::map<
int, std::vector<DrawColour>> &highlight_bond_map,
320 const std::map<int, double> &highlight_radii,
321 const std::map<int, int> &highlight_linewidth_multipliers,
351 const std::vector<ROMol *> &mols,
352 const std::vector<std::string> *legends =
nullptr,
353 const std::vector<std::vector<int>> *highlight_atoms =
nullptr,
354 const std::vector<std::vector<int>> *highlight_bonds =
nullptr,
355 const std::vector<std::map<int, DrawColour>> *highlight_atom_maps =
357 const std::vector<std::map<int, DrawColour>> *highlight_bond_maps =
359 const std::vector<std::map<int, double>> *highlight_radii =
nullptr,
360 const std::vector<int> *confIds =
nullptr);
376 const std::vector<DrawColour> *highlightColorsReactants =
nullptr,
377 const std::vector<int> *confIds =
nullptr);
398 const std::pair<double, double> &screen_cds)
const;
403 virtual int width()
const {
return width_; }
405 virtual int height()
const {
return height_; }
413 double scale()
const {
return scale_; }
417 const std::vector<int> *highlight_atoms =
nullptr,
418 const std::map<int, double> *highlight_radii =
nullptr);
423 const std::vector<std::vector<int>> *highlight_atoms,
424 const std::vector<std::map<int, double>> *highlight_radii,
425 const std::vector<int> *confIds,
426 std::vector<std::unique_ptr<RWMol>> &tmols);
447 virtual double fontSize()
const {
return font_size_; }
487 double &label_height)
const = 0;
491 double &label_width,
double &label_height)
const;
508 const std::string &align_char,
int align,
528 double ang1,
double ang2);
535 unsigned int nSegments = 16);
539 unsigned int nSegments = 16,
540 double vertOffset = 0.05);
558 return at_cds_[activeMolIdx_];
561 const std::vector<std::pair<std::string, OrientType>> &
atomSyms()
const {
563 return atom_syms_[activeMolIdx_];
567 bool asPolygon =
false,
double frac = 0.05,
568 double angle =
M_PI / 6);
577 int width_, height_, panel_width_, panel_height_;
579 double x_min_, y_min_, x_range_, y_range_;
580 double x_trans_, y_trans_;
581 int x_offset_, y_offset_;
593 std::vector<std::vector<Point2D>> at_cds_;
594 std::vector<std::vector<int>> atomic_nums_;
595 std::vector<std::vector<std::pair<std::string, OrientType>>> atom_syms_;
596 std::vector<std::vector<std::shared_ptr<StringRect>>> atom_notes_;
597 std::vector<std::vector<std::shared_ptr<StringRect>>> bond_notes_;
602 virtual void drawChar(
char c,
const Point2D &cds) = 0;
607 int atom_idx,
const std::vector<int> *highlight_atoms =
nullptr,
608 const std::map<int, DrawColour> *highlight_map =
nullptr);
609 DrawColour getColourByAtomicNum(
int atomic_num);
612 std::unique_ptr<RWMol> setupDrawMolecule(
613 const ROMol &mol,
const std::vector<int> *highlight_atoms,
614 const std::map<int, double> *highlight_radii,
int confId,
int width,
618 void pushDrawDetails();
619 void popDrawDetails();
622 std::unique_ptr<RWMol> setupMoleculeDraw(
623 const ROMol &mol,
const std::vector<int> *highlight_atoms,
624 const std::map<int, double> *highlight_radii,
int confId = -1);
628 void drawBonds(
const ROMol &draw_mol,
629 const std::vector<int> *highlight_atoms =
nullptr,
630 const std::map<int, DrawColour> *highlight_atom_map =
nullptr,
631 const std::vector<int> *highlight_bonds =
nullptr,
632 const std::map<int, DrawColour> *highlight_bond_map =
nullptr,
633 const std::vector<std::pair<DrawColour, DrawColour>>
634 *bond_colours =
nullptr);
636 void finishMoleculeDraw(
const ROMol &draw_mol,
637 const std::vector<DrawColour> &atom_colours);
638 void drawLegend(
const std::string &legend);
640 void drawHighlightedAtom(
int atom_idx,
const std::vector<DrawColour> &colours,
641 const std::map<int, double> *highlight_radii);
646 StringRect calcLabelRect(
const std::string &label, OrientType orient,
647 const Point2D &label_coords)
const;
650 void calcLabelEllipse(
int atom_idx,
651 const std::map<int, double> *highlight_radii,
652 Point2D ¢re,
double &xradius,
653 double &yradius)
const;
661 void calcAtomAnnotationPosition(
const ROMol &mol,
const Atom *atom,
665 void drawHighlightedBonds(
667 const std::map<
int, std::vector<DrawColour>> &highlight_bond_map,
668 const std::map<int, int> &highlight_linewidth_multipliers,
669 const std::map<int, double> *highlight_radii);
670 int getHighlightBondWidth(
672 const std::map<int, int> *highlight_linewidth_multipliers)
const;
675 void adjustLineEndForHighlight(
int at_idx,
676 const std::map<int, double> *highlight_radii,
679 void extractAtomCoords(
const ROMol &mol,
int confId,
bool updateBBox);
680 void extractAtomSymbols(
const ROMol &mol);
681 void extractAtomNotes(
const ROMol &mol);
682 void extractBondNotes(
const ROMol &mol);
692 void drawAtomLabel(
int atom_num,
693 const std::vector<int> *highlight_atoms =
nullptr,
694 const std::map<int, DrawColour> *highlight_map =
nullptr);
695 void drawAtomLabel(
int atom_num,
const DrawColour &draw_colour);
696 virtual void drawAnnotation(
const std::string ¬e,
697 const std::shared_ptr<StringRect> ¬e_rect);
698 void drawRadicals(
const ROMol &mol);
702 double getNoteStartAngle(
const ROMol &mol,
const Atom *atom)
const;
707 const ROMol &mol,
unsigned int atom_idx);
712 bool doesNoteClashNbourBonds(
const StringRect ¬e_rect,
const ROMol &mol,
713 const Atom *atom)
const;
715 bool doesNoteClashAtomLabels(
const StringRect ¬e_rect,
717 unsigned int atom_idx)
const;
718 bool doesNoteClashOtherNotes(
const StringRect ¬e_rect)
const;
722 std::vector<std::string> atomLabelToPieces(
int atom_num)
const;
723 std::vector<std::string> atomLabelToPieces(
const std::string &label,
724 OrientType orient)
const;
741 void adjustBondEndForLabel(
int atnum,
const Point2D &nbr_cds,
745 std::pair<std::string, OrientType> getAtomSymbolAndOrientation(
746 const Atom &atom,
const ROMol &mol)
const;
747 std::string getAtomSymbol(
const Atom &atom)
const;
748 OrientType getAtomOrientation(
const Atom &atom,
const Point2D &nbr_sum)
const;
751 void adjustScaleForAtomLabels(
const std::vector<int> *highlight_atoms,
752 const std::map<int, double> *highlight_radii);
753 void adjustScaleForAnnotation(
754 const std::vector<std::shared_ptr<StringRect>> ¬es);
758 const ROMol &mol,
const std::vector<int> *highlight_atoms,
759 const std::vector<int> *highlight_bonds,
760 const std::map<int, DrawColour> *highlight_atom_map,
761 const std::map<int, DrawColour> *highlight_bond_map,
762 const std::map<int, double> *highlight_radii);
769 const ROMol &mol,
const Bond *bond,
int at1_idx,
int at2_idx,
770 const std::vector<int> *highlight_atoms =
nullptr,
771 const std::map<int, DrawColour> *highlight_atom_map =
nullptr,
772 const std::vector<int> *highlight_bonds =
nullptr,
773 const std::map<int, DrawColour> *highlight_bond_map =
nullptr,
774 const std::vector<std::pair<DrawColour, DrawColour>> *bond_colours =
801 Point2D &arrowEnd, std::vector<double> &plusLocs,
802 double spacing,
const std::vector<int> *confIds);
805 double &minY,
int confId,
bool shiftAgents,
826 #endif // RDKITMOLDRAW2D_H
#define RDKIT_MOLDRAW2D_EXPORT
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 calcCorners(Point2D &tl, Point2D &tr, Point2D &br, Point2D &bl) const
ColourPalette atomColourPalette
Point2D calcPerpendicular(const Point2D &cds1, const Point2D &cds2) const
RDKIT_MOLDRAW2D_EXPORT void addBondIndices(const ROMol &mol)
add annotations with bond indices.
void setScale(int width, int height, const Point2D &minv, const Point2D &maxv)
explicitly sets the scaling factors for the drawing
Point2D offset() const
returns the drawing offset (in drawing coords)
virtual void drawTriangle(const Point2D &cds1, const Point2D &cds2, const Point2D &cds3)
draw a triangle
DrawColour operator+(const DrawColour &other) const
bool isLinearAtom(const Atom &atom) const
DrawColour operator/(double v) const
StringRect(const Point2D &in_cds)
void calcTripleBondLines(double offset, const Bond *bond, const Point2D &at1_cds, const Point2D &at2_cds, Point2D &l1s, Point2D &l1f, Point2D &l2s, Point2D &l2f) const
const MolDrawOptions & drawOptions() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
virtual void setFillPolys(bool val)
returns either or not polygons should be filled
virtual void clearDrawing()=0
clears the contents of the drawing
virtual void highlightCloseContacts()
virtual Point2D getAtomCoords(const std::pair< int, int > &screen_cds) const
std::vector< unsigned int > DashPattern
void setOffset(int x, int y)
sets the drawing offset (in drawing coords)
virtual void setColour(const DrawColour &col)
sets the current draw color
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)
std::vector< std::vector< int > > atomRegions
double scale() const
returns the drawing scale (conversion from molecular coords -> drawing
RDKIT_MOLDRAW2D_EXPORT void addStereoAnnotation(const ROMol &mol)
add R/S and E/Z annotation to atoms and bonds respectively.
bool setStringDrawMode(const std::string &instring, TextDrawType &draw_mode, int &i) const
class for representing a bond
virtual bool fillPolys() const
set whether or not polygons are being filled
virtual Point2D getAtomCoords(const std::pair< double, double > &screen_cds) const
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...
RWMol is a molecule class that is intended to be edited.
virtual void drawRect(const Point2D &cds1, const Point2D &cds2)
draw a rectangle
RDKIT_MOLDRAW2D_EXPORT void addAtomIndices(const ROMol &mol)
add annotations with atom indices.
virtual void setDash(const DashPattern &patt)
sets the current dash pattern
void get2DCoordsMol(RWMol &mol, double &offset, double spacing, double &maxY, double &minY, int confId, bool shiftAgents, double coordScale)
#define RDUNUSED_PARAM(x)
void centrePicture(int width, int height)
RDKIT_MOLDRAW2D_EXPORT bool doLinesIntersect(const Point2D &l1s, const Point2D &l1f, const Point2D &l2s, const Point2D &l2f, Point2D *ip=nullptr)
virtual int lineWidth() const
returns the current line width
RDKIT_MOLDRAW2D_EXPORT bool doesLineIntersectLabel(const Point2D &ls, const Point2D &lf, const StringRect &lab_rect)
virtual bool supportsAnnotations()
The class for representing atoms.
Point2D minPt() const
returns the minimum point of the drawing (in molecular coords)
const std::vector< Point2D > & atomCoords() const
void assignBWPalette(ColourPalette &palette)
virtual void drawStrings(const std::vector< std::string > &labels, const Point2D &cds, OrientType orient)
virtual void drawArc(const Point2D ¢re, double radius, double ang1, double ang2)
virtual unsigned int getDrawLineWidth()
void calculateScale(int width, int height, const std::vector< int > *highlight_atoms=nullptr, const std::map< int, double > *highlight_radii=nullptr)
calculates the drawing scale (conversion from molecular coords -> drawing
pulls in the core RDKit functionality
virtual int height() const
return the height of the drawing area.
virtual void drawEllipse(const Point2D &cds1, const Point2D &cds2)
draw an ellipse
virtual void setFontSize(double new_size)
std::map< int, DrawColour > ColourPalette
virtual void drawArc(const Point2D ¢re, double xradius, double yradius, double ang1, double ang2)
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
void get2DCoordsForReaction(ChemicalReaction &rxn, Point2D &arrowBegin, Point2D &arrowEnd, std::vector< double > &plusLocs, double spacing, const std::vector< int > *confIds)
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 Point2D getDrawCoords(int at_num) const
returns the drawing coordinates of a particular atom
virtual void drawString(const std::string &str, const Point2D &cds, AlignType align)
This is a class for storing and applying general chemical reactions.
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 drawAttachmentLine(const Point2D &cds1, const Point2D &cds2, const DrawColour &col, double len=1.0, unsigned int nSegments=16)
virtual int width() const
return the width of the drawing area.
virtual void drawLine(const Point2D &cds1, const Point2D &cds2)=0
draws a line from cds1 to cds2 using the current drawing style
virtual int panelWidth() const
return the width of the drawing panels.
virtual const DashPattern & dash() const
returns the current dash pattern
virtual void setLineWidth(int width)
sets the current line width
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
DrawColour operator*(double v) const
virtual void drawPolygon(const std::vector< Point2D > &cds)=0
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 double fontSize() const
returns the font size (in molecule units)
std::vector< DrawColour > highlightColourPalette
MolDraw2D is the base class for doing 2D renderings of molecules.
DrawColour(double r, double g, double b, double a=1.0)
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 Point2D getDrawCoords(const Point2D &mol_cds) const
MolDrawOptions & drawOptions()
returns our current drawing options
void assignDefaultPalette(ColourPalette &palette)
bool operator==(const DrawColour &other) const
#define PRECONDITION(expr, mess)
bool doesItIntersect(const StringRect &other) const
std::map< int, std::string > atomLabels
bool feq(const DrawColour &other, double tol=0.001, bool ignoreAlpha=true) const
MolDraw2D(int width, int height, int panelWidth, int panelHeight)
constructor for a particular size
double drawFontSize() const
virtual void drawString(const std::string &str, const Point2D &cds)
drawString centres the string on cds.
void getLabelSize(const std::string &label, OrientType orient, double &label_width, double &label_height) const
std::ostream & operator<<(std::ostream &oss, const MolDraw2D::OrientType &o)
const std::vector< std::pair< std::string, OrientType > > & atomSyms() const
returns the atomic symbols of the current molecule
DrawColour operator-(const DrawColour &other) const
virtual void getStringSize(const std::string &label, double &label_width, double &label_height) const =0
Point2D range() const
returns the width and height of the grid (in molecular coords)
virtual void drawReaction(const ChemicalReaction &rxn, bool highlightByReactant=false, const std::vector< DrawColour > *highlightColorsReactants=nullptr, const std::vector< int > *confIds=nullptr)
draw a ChemicalReaction
virtual void 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...
virtual int panelHeight() const
return the height of the drawing panels.
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 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 DrawColour colour() const
returns the current draw color
virtual void alignString(const std::string &str, const std::string &align_char, int align, const Point2D &in_cds, Point2D &out_cds) const
virtual Point2D getAtomCoords(int at_num) const
returns the molecular coordinates of a particular atom