MolDraw2DDetails.h
Go to the documentation of this file.
//
// Copyright (C) 2015-2020 Greg Landrum
//
// @@ All Rights Reserved @@
// This file is part of the RDKit.
// The contents are covered by the terms of the BSD license
// which is included in the file license.txt, found at the root
// of the RDKit source tree.
//
#include <RDGeneral/export.h>
#ifndef RDKITMOLDRAW2DDETAILS_H
#define RDKITMOLDRAW2DDETAILS_H
#include <vector>
#include <Geometry/point.h>
#include <GraphMol/RDKitBase.h>
#include <GraphMol/MolDraw2D/MolDraw2D.h>
#include <boost/tuple/tuple.hpp>
#include <boost/format.hpp>
// ****************************************************************************
using RDGeom::Point2D;
namespace RDKit {
namespace MolDraw2D_detail {
// data taken from the helvetica font info in
// $RDBASE/rdkit/sping/PDF/pdfmetrics.py
const int char_widths[] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 278, 278, 355, 556, 556, 889, 667, 222, 333, 333,
389, 584, 278, 333, 278, 278, 556, 556, 556, 556, 556, 556, 556, 556,
556, 556, 278, 278, 584, 584, 584, 556, 1015, 667, 667, 722, 722, 667,
611, 778, 722, 278, 500, 667, 556, 833, 722, 778, 667, 778, 722, 667,
611, 722, 667, 944, 667, 667, 611, 278, 278, 278, 469, 556, 222, 556,
556, 500, 556, 556, 278, 556, 556, 222, 222, 500, 222, 833, 556, 556,
556, 556, 333, 500, 278, 556, 500, 722, 500, 500, 500, 334, 260, 334,
584, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 333, 556, 556, 167, 556, 556, 556,
556, 191, 333, 556, 333, 333, 500, 500, 0, 556, 556, 556, 278, 0,
537, 350, 222, 333, 333, 556, 1000, 1000, 0, 611, 0, 333, 333, 333,
333, 333, 333, 333, 333, 0, 333, 333, 0, 333, 333, 333, 1000, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 1000, 0, 370, 0, 0, 0, 0, 556, 778, 1000, 365, 0, 0,
0, 0, 0, 889, 0, 0, 0, 278, 0, 0, 222, 611, 944, 611,
0, 0, 834};
// angles in degrees.
RDKIT_MOLDRAW2D_EXPORT void arcPoints(const Point2D &cds1, const Point2D &cds2,
std::vector<Point2D> &res,
float startAng = 0, float extent = 360);
//! add R/S, relative stereo, and E/Z annotations to atoms and bonds
RDKIT_MOLDRAW2D_EXPORT void addStereoAnnotation(
const ROMol &mol, bool includeRelativeCIP = false);
//! add annotations with atom indices.
RDKIT_MOLDRAW2D_EXPORT inline void addAtomIndices(const ROMol &mol) {
// we don't need this in the global set of tags since it will only be used
// here
if (mol.hasProp("_atomIndicesAdded")) return;
bool computed = true;
mol.setProp("_atomIndicesAdded", 1, computed);
for (auto atom : mol.atoms()) {
auto lab = std::to_string(atom->getIdx());
if (atom->hasProp(common_properties::atomNote)) {
lab += "," + atom->getProp<std::string>(common_properties::atomNote);
}
atom->setProp(common_properties::atomNote, lab);
}
};
//! add annotations with bond indices.
RDKIT_MOLDRAW2D_EXPORT inline void addBondIndices(const ROMol &mol) {
// we don't need this in the global set of tags since it will only be used
// here
if (mol.hasProp("_bondIndicesAdded")) return;
bool computed = true;
mol.setProp("_bondIndicesAdded", 1, computed);
for (auto bond : mol.bonds()) {
auto lab = std::to_string(bond->getIdx());
if (bond->hasProp(common_properties::bondNote)) {
lab += "," + bond->getProp<std::string>(common_properties::bondNote);
}
bond->setProp(common_properties::bondNote, lab);
}
};
RDKIT_MOLDRAW2D_EXPORT std::vector<Point2D> getBracketPoints(
const Point2D &p1, const Point2D &p2, const Point2D &refPt,
const std::vector<std::pair<Point2D, Point2D>> &bondSegments,
double bracketFrac = 0.1);
RDKIT_MOLDRAW2D_EXPORT void drawShapes(MolDraw2D &drawer,
const std::vector<MolDrawShape> &shapes);
// there are a several empirically determined constants here.
RDKIT_MOLDRAW2D_EXPORT std::vector<Point2D> handdrawnLine(
Point2D cds1, Point2D cds2, double scale, bool shiftBegin = false,
bool shiftEnd = false, unsigned nSteps = 4, double deviation = 0.03,
double endShift = 0.5);
inline std::string formatDouble(double val) {
return boost::str(boost::format("%.1f") % val);
}
} // namespace MolDraw2D_detail
} // namespace RDKit
#endif
MolDraw2D.h
RDKitBase.h
pulls in the core RDKit functionality
RDGeom::Point2D
Definition: point.h:272
RDKit::MolDraw2D
MolDraw2D is the base class for doing 2D renderings of molecules.
Definition: MolDraw2D.h:337
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
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:178
RDKit::ROMol::bonds
CXXBondIterator< MolGraph, Bond * > bonds()
Definition: ROMol.h:295
RDKit::ROMol::atoms
CXXAtomIterator< MolGraph, Atom * > atoms()
C++11 Range iterator.
Definition: ROMol.h:256
export.h
RDKIT_MOLDRAW2D_EXPORT
#define RDKIT_MOLDRAW2D_EXPORT
Definition: export.h:265
RDKit::CIPLabeler::to_string
static std::string to_string(const Descriptor &desc)
Definition: Descriptor.h:54
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::MolDraw2D_detail::drawShapes
RDKIT_MOLDRAW2D_EXPORT void drawShapes(MolDraw2D &drawer, const std::vector< MolDrawShape > &shapes)
RDKit::MolDraw2D_detail::addBondIndices
RDKIT_MOLDRAW2D_EXPORT void addBondIndices(const ROMol &mol)
add annotations with bond indices.
Definition: MolDraw2DDetails.h:78
RDKit::MolDraw2D_detail::addAtomIndices
RDKIT_MOLDRAW2D_EXPORT void addAtomIndices(const ROMol &mol)
add annotations with atom indices.
Definition: MolDraw2DDetails.h:62
RDKit::MolDraw2D_detail::addStereoAnnotation
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_detail::char_widths
const int char_widths[]
Definition: MolDraw2DDetails.h:31
RDKit::MolDraw2D_detail::getBracketPoints
RDKIT_MOLDRAW2D_EXPORT std::vector< Point2D > getBracketPoints(const Point2D &p1, const Point2D &p2, const Point2D &refPt, const std::vector< std::pair< Point2D, Point2D >> &bondSegments, double bracketFrac=0.1)
RDKit::MolDraw2D_detail::formatDouble
std::string formatDouble(double val)
Definition: MolDraw2DDetails.h:106
RDKit::MolDraw2D_detail::handdrawnLine
RDKIT_MOLDRAW2D_EXPORT std::vector< Point2D > handdrawnLine(Point2D cds1, Point2D cds2, double scale, bool shiftBegin=false, bool shiftEnd=false, unsigned nSteps=4, double deviation=0.03, double endShift=0.5)
RDKit::common_properties::bondNote
RDKIT_RDGENERAL_EXPORT const std::string bondNote
RDKit::common_properties::atomNote
RDKIT_RDGENERAL_EXPORT const std::string atomNote
RDKit
Std stuff.
Definition: Abbreviations.h:18
point.h