RDKit: AtomSymbol.h Source File

| RDKit Open-source cheminformatics and machine learning.

Loading...
Searching...
No Matches
AtomSymbol.h
Go to the documentation of this file.
1//
2// Copyright (C) 2021-2022 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 (CozChemIx Limited)
11//
12// This class is a helper class used by MolDraw2D to draw an ROMol.
13// It is not part of the public API and is not intended to be used except
14// by MolDraw2D.
15// It holds the information needed to draw an atom symbol, including
16// all the extra bits like isotope labels.
17
18#ifndef RDKIT_ATOMSYMBOL_H
19#define RDKIT_ATOMSYMBOL_H
20
21#include <string>
22
23#include <GraphMol/MolDraw2D/DrawText.h>
24#include <GraphMol/MolDraw2D/MolDraw2DHelpers.h>
25
26namespace RDKit {
27
28class MolDraw2D;
29
30 namespace MolDraw2D_detail {
31
32 class AtomSymbol {
33 public:
34 ~AtomSymbol() = default;
35
36 /*!
37 *
38 * @param symbol : the full symbol
39 * @param atIdx : index of atom that this is the symbol of
40 * @param orient : text orientation (up, down, left, right)
41 * @param cds : coords for symbol
42 * @param colour : colour for symbol
43 * @param textDrawer : instance of DrawText to get the character sizes
44 * etc.
45 */
46 AtomSymbol(const std::string &symbol, int atIdx, OrientType orient,
47 const Point2D &cds, const DrawColour &colour,
48 DrawText &textDrawer);
49
50 AtomSymbol(const AtomSymbol &) = delete;
51 AtomSymbol(AtomSymbol &&) = delete;
52 AtomSymbol &operator=(const AtomSymbol &) = delete;
53 AtomSymbol &operator=(AtomSymbol &&) = delete;
54
55 std::string symbol_;
56 int atIdx_;
57 OrientType orient_;
58 Point2D cds_;
59 DrawColour colour_;
60 DrawText &textDrawer_;
61
62 std::vector<std::shared_ptr<StringRect>> rects_;
63 std::vector<TextDrawType> drawModes_;
64 std::vector<char> drawChars_;
65
66 // expects xmin etc to be initialised to something sensible.
67 void findExtremes(double &xmin, double &xmax, double &ymin,
68 double &ymax) const;
69 // scaleFactor moves the cds_, but the fontScaleFactor changes rects_, because
70 // we might be scaling the font differently from the drawing as a whole.
71 void scale(const Point2D &scaleFactor);
72 void move(const Point2D &trans);
73 void recalculateRects();
74 void draw(MolDraw2D &molDrawer) const;
75 bool doesRectClash(const StringRect &rect, double padding) const;
76 // Because a colon is a lot shorter than other characters, there are cases,
77 // such as rxn_test1_2 in rxn_test1.cpp, where a vertical bond can slip
78 // between the atom symbol and the atom map (C:8 in that case) which looks
79 // a bit pants. This stretches the colon to be the same height as the
80 // smaller of the chars on either side.
81 void adjustColons();
82
83 // this is for debugging almost always.
84 void drawRects(MolDraw2D &molDrawer) const;
85};
86
87} // namespace MolDraw2D_detail
88} // namespace RDKit
89
90#endif // RDKIT_ATOMSYMBOL_H
DrawText.h
MolDraw2DHelpers.h
RDGeom::Point2D
Definition point.h:284
RDKit::MolDraw2D_detail::AtomSymbol::scale
void scale(const Point2D &scaleFactor)
RDKit::MolDraw2D_detail::AtomSymbol::rects_
std::vector< std::shared_ptr< StringRect > > rects_
Definition AtomSymbol.h:62
RDKit::MolDraw2D_detail::AtomSymbol::doesRectClash
bool doesRectClash(const StringRect &rect, double padding) const
RDKit::MolDraw2D_detail::AtomSymbol::textDrawer_
DrawText & textDrawer_
Definition AtomSymbol.h:60
RDKit::MolDraw2D_detail::AtomSymbol::AtomSymbol
AtomSymbol(AtomSymbol &&)=delete
RDKit::MolDraw2D_detail::AtomSymbol::operator=
AtomSymbol & operator=(AtomSymbol &&)=delete
RDKit::MolDraw2D_detail::AtomSymbol::cds_
Point2D cds_
Definition AtomSymbol.h:58
RDKit::MolDraw2D_detail::AtomSymbol::~AtomSymbol
~AtomSymbol()=default
RDKit::MolDraw2D_detail::AtomSymbol::recalculateRects
void recalculateRects()
RDKit::MolDraw2D_detail::AtomSymbol::move
void move(const Point2D &trans)
RDKit::MolDraw2D_detail::AtomSymbol::atIdx_
int atIdx_
Definition AtomSymbol.h:56
RDKit::MolDraw2D_detail::AtomSymbol::drawModes_
std::vector< TextDrawType > drawModes_
Definition AtomSymbol.h:63
RDKit::MolDraw2D_detail::AtomSymbol::operator=
AtomSymbol & operator=(const AtomSymbol &)=delete
RDKit::MolDraw2D_detail::AtomSymbol::AtomSymbol
AtomSymbol(const std::string &symbol, int atIdx, OrientType orient, const Point2D &cds, const DrawColour &colour, DrawText &textDrawer)
RDKit::MolDraw2D_detail::AtomSymbol::drawRects
void drawRects(MolDraw2D &molDrawer) const
RDKit::MolDraw2D_detail::AtomSymbol::colour_
DrawColour colour_
Definition AtomSymbol.h:59
RDKit::MolDraw2D_detail::AtomSymbol::draw
void draw(MolDraw2D &molDrawer) const
RDKit::MolDraw2D_detail::AtomSymbol::findExtremes
void findExtremes(double &xmin, double &xmax, double &ymin, double &ymax) const
RDKit::MolDraw2D_detail::AtomSymbol::AtomSymbol
AtomSymbol(const AtomSymbol &)=delete
RDKit::MolDraw2D_detail::AtomSymbol::drawChars_
std::vector< char > drawChars_
Definition AtomSymbol.h:64
RDKit::MolDraw2D_detail::AtomSymbol::symbol_
std::string symbol_
Definition AtomSymbol.h:55
RDKit::MolDraw2D_detail::AtomSymbol::orient_
OrientType orient_
Definition AtomSymbol.h:57
RDKit::MolDraw2D_detail::AtomSymbol::adjustColons
void adjustColons()
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
symbol
static const char * symbol[119]
Definition mf.h:257
RDKit::MolDraw2D_detail
Definition AtomSymbol.h:30
RDKit::MolDraw2D_detail::OrientType
OrientType
Definition MolDraw2DHelpers.h:26
RDKit
Std stuff.
Definition Abbreviations.h:19
RDKit::DrawColour
Definition MolDraw2DHelpers.h:40
RDKit::MolDraw2D_detail::StringRect
Definition StringRect.h:24