RDKit
Open-source cheminformatics and machine learning.
MolDraw2DDetails.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2015 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 
11 #include <RDGeneral/export.h>
12 #ifndef RDKITMOLDRAW2DDETAILS_H
13 #define RDKITMOLDRAW2DDETAILS_H
14 
15 #include <vector>
16 
17 #include <Geometry/point.h>
18 #include <GraphMol/RDKitBase.h>
19 
20 #include <boost/tuple/tuple.hpp>
21 
22 // ****************************************************************************
23 using RDGeom::Point2D;
24 
25 namespace RDKit {
26 namespace MolDraw2D_detail {
27 // data taken from the helvetica font info in
28 // $RDBASE/rdkit/sping/PDF/pdfmetrics.py
29 const int char_widths[] = {
30  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
31  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
32  0, 0, 0, 0, 278, 278, 355, 556, 556, 889, 667, 222, 333, 333,
33  389, 584, 278, 333, 278, 278, 556, 556, 556, 556, 556, 556, 556, 556,
34  556, 556, 278, 278, 584, 584, 584, 556, 1015, 667, 667, 722, 722, 667,
35  611, 778, 722, 278, 500, 667, 556, 833, 722, 778, 667, 778, 722, 667,
36  611, 722, 667, 944, 667, 667, 611, 278, 278, 278, 469, 556, 222, 556,
37  556, 500, 556, 556, 278, 556, 556, 222, 222, 500, 222, 833, 556, 556,
38  556, 556, 333, 500, 278, 556, 500, 722, 500, 500, 500, 334, 260, 334,
39  584, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
40  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
41  0, 0, 0, 0, 0, 0, 0, 333, 556, 556, 167, 556, 556, 556,
42  556, 191, 333, 556, 333, 333, 500, 500, 0, 556, 556, 556, 278, 0,
43  537, 350, 222, 333, 333, 556, 1000, 1000, 0, 611, 0, 333, 333, 333,
44  333, 333, 333, 333, 333, 0, 333, 333, 0, 333, 333, 333, 1000, 0,
45  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
46  0, 1000, 0, 370, 0, 0, 0, 0, 556, 778, 1000, 365, 0, 0,
47  0, 0, 0, 889, 0, 0, 0, 278, 0, 0, 222, 611, 944, 611,
48  0, 0, 834};
49 
50 // angles in degrees.
51 RDKIT_MOLDRAW2D_EXPORT void arcPoints(const Point2D &cds1, const Point2D &cds2,
52  std::vector<Point2D> &res,
53  float startAng = 0, float extent = 360);
54 
55 //! add R/S and E/Z annotation to atoms and bonds respectively.
57  for (auto atom : mol.atoms()) {
58  if (atom->hasProp("_CIPCode")) {
59  std::string lab = "(" + atom->getProp<std::string>("_CIPCode") + ")";
60  atom->setProp(common_properties::atomNote, lab);
61  }
62  }
63  for (auto bond : mol.bonds()) {
64  if (bond->getStereo() == Bond::STEREOE) {
65  bond->setProp(common_properties::bondNote, "(E)");
66  } else if (bond->getStereo() == Bond::STEREOZ) {
67  bond->setProp(common_properties::bondNote, "(Z)");
68  }
69  }
70 };
71 
72 //! add annotations with atom indices.
73 RDKIT_MOLDRAW2D_EXPORT inline void addAtomIndices(const ROMol &mol) {
74  // we don't need this in the global set of tags since it will only be used
75  // here
76  if (mol.hasProp("_atomIndicesAdded")) return;
77  bool computed = true;
78  mol.setProp("_atomIndicesAdded", 1, computed);
79  for (auto atom : mol.atoms()) {
80  auto lab = std::to_string(atom->getIdx());
81  if (atom->hasProp(common_properties::atomNote)) {
82  lab += "," + atom->getProp<std::string>(common_properties::atomNote);
83  }
84  atom->setProp(common_properties::atomNote, lab);
85  }
86 };
87 
88 //! add annotations with bond indices.
89 RDKIT_MOLDRAW2D_EXPORT inline void addBondIndices(const ROMol &mol) {
90  // we don't need this in the global set of tags since it will only be used
91  // here
92  if (mol.hasProp("_bondIndicesAdded")) return;
93  bool computed = true;
94  mol.setProp("_bondIndicesAdded", 1, computed);
95  for (auto bond : mol.bonds()) {
96  auto lab = std::to_string(bond->getIdx());
97  if (bond->hasProp(common_properties::bondNote)) {
98  lab += "," + bond->getProp<std::string>(common_properties::bondNote);
99  }
100  bond->setProp(common_properties::bondNote, lab);
101  }
102 };
103 } // namespace MolDraw2D_detail
104 } // namespace RDKit
105 
106 #endif
RDKIT_MOLDRAW2D_EXPORT
#define RDKIT_MOLDRAW2D_EXPORT
Definition: export.h:398
RDKit::ROMol::bonds
CXXBondIterator< MolGraph, Bond * > bonds()
Definition: ROMol.h:264
RDKit::MolDraw2D_detail::addBondIndices
RDKIT_MOLDRAW2D_EXPORT void addBondIndices(const ROMol &mol)
add annotations with bond indices.
Definition: MolDraw2DDetails.h:89
point.h
RDKit::MolDraw2D_detail::addStereoAnnotation
RDKIT_MOLDRAW2D_EXPORT void addStereoAnnotation(const ROMol &mol)
add R/S and E/Z annotation to atoms and bonds respectively.
Definition: MolDraw2DDetails.h:56
RDKit::common_properties::atomNote
RDKIT_RDGENERAL_EXPORT const std::string atomNote
RDKit::MolDraw2D_detail::addAtomIndices
RDKIT_MOLDRAW2D_EXPORT void addAtomIndices(const ROMol &mol)
add annotations with atom indices.
Definition: MolDraw2DDetails.h:73
RDKit::RDProps::setProp
void setProp(const std::string &key, T val, bool computed=false) const
sets a property value
Definition: RDProps.h:72
RDKit::ROMol
Definition: ROMol.h:171
RDKitBase.h
pulls in the core RDKit functionality
RDKit::Bond::STEREOZ
@ STEREOZ
Definition: Bond.h:100
RDKit::common_properties::bondNote
RDKIT_RDGENERAL_EXPORT const std::string bondNote
RDKit::MolDraw2D_detail::char_widths
const int char_widths[]
Definition: MolDraw2DDetails.h:29
RDKit::MolDraw2D_detail::arcPoints
RDKIT_MOLDRAW2D_EXPORT void arcPoints(const Point2D &cds1, const Point2D &cds2, std::vector< Point2D > &res, float startAng=0, float extent=360)
RDKit
Std stuff.
Definition: Atom.h:30
RDKit::Bond::STEREOE
@ STEREOE
Definition: Bond.h:101
RDGeom::Point2D
Definition: point.h:258
RDKit::ROMol::atoms
CXXAtomIterator< MolGraph, Atom * > atoms()
C++11 Range iterator.
Definition: ROMol.h:249
RDKit::RDProps::hasProp
bool hasProp(const std::string &key) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: RDProps.h:121
export.h