13 #ifndef _RD_MOLDRAWING_H_ 14 #define _RD_MOLDRAWING_H_ 17 #include <boost/foreach.hpp> 18 #include <boost/lexical_cast.hpp> 45 void drawLine(std::vector<ElementType> &res,
int atnum1,
int atnum2,
46 int lineWidth,
int dashed,
double x1,
double y1,
double x2,
49 res.push_back(static_cast<ElementType>(lineWidth));
50 res.push_back(dashed);
51 res.push_back(static_cast<ElementType>(atnum1));
52 res.push_back(static_cast<ElementType>(atnum2));
53 res.push_back(static_cast<ElementType>(x1));
54 res.push_back(static_cast<ElementType>(y1));
55 res.push_back(static_cast<ElementType>(x2));
56 res.push_back(static_cast<ElementType>(y2));
60 std::string symbol =
"";
61 OrientType orient =
C;
68 bool leftToRight =
true;
73 symbol = boost::lexical_cast<std::string>(isotope) + symbol;
78 symbol +=
":" + mapNum;
84 h += boost::lexical_cast<std::string>(nHs);
93 std::string sgn =
"+";
99 sgn += boost::lexical_cast<std::string>(chg);
104 symbol = sgn + symbol;
109 if (fabs(nbrSum.
y) > 1) {
110 islope = nbrSum.
x / fabs(nbrSum.
y);
114 if (fabs(islope) > .85) {
129 return std::make_pair(symbol, orient);
134 const std::vector<int> *highlightAtoms = 0,
135 bool includeAtomCircles =
false,
136 unsigned int dotsPerAngstrom = 100,
137 double dblBondOffset = 0.3,
138 double dblBondLengthFrac = 0.8,
139 double angstromsPerChar = 0.20) {
143 std::vector<ElementType> res;
145 res.push_back(static_cast<ElementType>(dotsPerAngstrom));
152 std::vector<std::pair<std::string, OrientType> > atomSymbols;
153 ROMol::VERTEX_ITER bAts, eAts;
155 while (bAts != eAts) {
156 ROMol::OEDGE_ITER nbr, endNbrs;
158 boost::tie(nbr, endNbrs) = mol.
getAtomBonds(mol[*bAts].
get());
160 locs[mol[*bAts]->getIdx()].y);
161 while (nbr != endNbrs) {
164 int a2Idx = bond->getOtherAtomIdx(mol[*bAts]->getIdx());
168 atomSymbols.push_back(
176 double minx = 1e6, miny = 1e6, maxx = -1e6, maxy = -1e6;
177 for (
unsigned int i = 0; i < mol.
getNumAtoms(); ++i) {
181 boost::tie(symbol, orient) = atomSymbols[i];
190 minx = pt.
x - symbol.size() / 2 * angstromsPerChar;
193 minx = pt.
x - symbol.size() * angstromsPerChar;
203 maxx = pt.
x + symbol.size() / 2 * angstromsPerChar;
206 maxx = pt.
x + symbol.size() * angstromsPerChar;
212 miny = pt.
y - 1.5 * angstromsPerChar;
215 maxy = pt.
y + angstromsPerChar;
218 minx = std::min(pt.
x, minx);
219 miny = std::min(pt.
y, miny);
220 maxx = std::max(pt.
x, maxx);
221 maxy = std::max(pt.
y, maxy);
224 double dimx = (maxx - minx), dimy = (maxy - miny);
226 res.push_back(static_cast<ElementType>(dotsPerAngstrom * 0));
227 res.push_back(static_cast<ElementType>(dotsPerAngstrom * 0));
228 res.push_back(static_cast<ElementType>(dotsPerAngstrom * dimx));
229 res.push_back(static_cast<ElementType>(dotsPerAngstrom * dimy));
233 while (bAts != eAts) {
234 int a1Idx = mol[*bAts]->getIdx();
236 ROMol::OEDGE_ITER nbr, endNbrs;
238 boost::tie(nbr, endNbrs) = mol.
getAtomBonds(mol[*bAts].
get());
239 while (nbr != endNbrs) {
242 int a2Idx = bond->getOtherAtomIdx(a1Idx);
244 if (highlightAtoms &&
245 std::find(highlightAtoms->begin(), highlightAtoms->end(), a1Idx) !=
246 highlightAtoms->end() &&
247 std::find(highlightAtoms->begin(), highlightAtoms->end(), a2Idx) !=
248 highlightAtoms->end()) {
253 if (a2Idx < a1Idx)
continue;
256 int atnum1 = mol[*bAts]->getAtomicNum();
271 perp *= dblBondOffset;
272 startP += (obv * (1. - dblBondLengthFrac) / 2);
273 endP -= (obv * (1. - dblBondLengthFrac) / 2);
275 perp *= 0.5 * dblBondOffset;
278 dotsPerAngstrom * (startP.
x + perp.
x),
279 dotsPerAngstrom * (startP.
y + perp.
y),
280 dotsPerAngstrom * (endP.x + perp.
x),
281 dotsPerAngstrom * (endP.y + perp.
y));
284 dotsPerAngstrom * (startP.
x - perp.
x),
285 dotsPerAngstrom * (startP.
y - perp.
y),
286 dotsPerAngstrom * (endP.x - perp.
x),
287 dotsPerAngstrom * (endP.y - perp.
y));
290 dotsPerAngstrom * (startP.
x - perp.
x),
291 dotsPerAngstrom * (startP.
y - perp.
y),
292 dotsPerAngstrom * (endP.x - perp.
x),
293 dotsPerAngstrom * (endP.y - perp.
y));
299 dotsPerAngstrom * (a1.x), dotsPerAngstrom * (a1.y),
300 dotsPerAngstrom * (a2.
x), dotsPerAngstrom * (a2.
y));
303 dotsPerAngstrom * (a1.x), dotsPerAngstrom * (a1.y),
304 dotsPerAngstrom * (a2.
x), dotsPerAngstrom * (a2.
y));
309 dotsPerAngstrom * a1.x, dotsPerAngstrom * a1.y,
310 dotsPerAngstrom * a2.
x, dotsPerAngstrom * a2.
y);
324 ROMol::OEDGE_ITER nbr2, endNbrs2;
325 boost::tie(nbr2, endNbrs2) = mol.
getAtomBonds(mol[*bAts].
get());
326 while (nbr2 != endNbrs2) {
329 if (bond2->getIdx() == bond->getIdx() ||
332 bool sharedRing =
false;
333 BOOST_FOREACH (
const INT_VECT &ring,
335 if (std::find(ring.begin(), ring.end(), bond->getIdx()) !=
337 std::find(ring.begin(), ring.end(), bond2->getIdx()) !=
345 int a3Idx = bond2->getOtherAtomIdx(a1Idx);
346 if (a3Idx != a2Idx) {
348 locs[a3Idx].y - miny);
357 perp *= dblBondOffset;
360 a1 + obv * (.5 * (1. - dblBondLengthFrac));
362 obv *= dblBondLengthFrac;
366 dotsPerAngstrom * (offsetStart.
x + perp.
x),
367 dotsPerAngstrom * (offsetStart.
y + perp.
y),
368 dotsPerAngstrom * (offsetStart.
x + obv.x + perp.
x),
369 dotsPerAngstrom * (offsetStart.
y + obv.y + perp.
y));
375 boost::tie(symbol, orient) = atomSymbols[a1Idx];
376 if (symbol !=
"" || includeAtomCircles) {
378 res.push_back(mol[*bAts]->getAtomicNum());
379 res.push_back(static_cast<ElementType>(dotsPerAngstrom * a1.
x));
380 res.push_back(static_cast<ElementType>(dotsPerAngstrom * a1.
y));
381 res.push_back(static_cast<ElementType>(symbol.length()));
382 if (symbol.length()) {
383 BOOST_FOREACH (
char c, symbol) {
384 res.push_back(static_cast<ElementType>(c));
387 res.push_back(static_cast<ElementType>(orient));
397 const std::vector<int> *highlightAtoms = 0,
398 bool kekulize =
true,
399 bool includeAtomCircles =
false) {
412 std::vector<int> drawing =
413 DrawMol(*cp, -1, highlightAtoms, includeAtomCircles);
boost::shared_ptr< Bond > BOND_SPTR
const Conformer & getConformer(int id=-1) const
std::pair< std::string, OrientType > getAtomSymbolAndOrientation(const Atom &atom, RDGeom::Point2D nbrSum)
void Kekulize(RWMol &mol, bool markAtomsBonds=true, unsigned int maxBackTracks=100)
Kekulizes the molecule.
std::vector< int > MolToDrawing(const RDKit::ROMol &mol, const std::vector< int > *highlightAtoms=0, bool kekulize=true, bool includeAtomCircles=false)
ATOM_ITER_PAIR getVertices()
returns an iterator pair for looping over all Atoms
unsigned int numBondRings(unsigned int idx) const
returns the number of rings bond idx is involved in
int findSSSR(const ROMol &mol, std::vector< std::vector< int > > &res)
finds a molecule's Smallest Set of Smallest Rings
RWMol is a molecule class that is intended to be edited.
unsigned int getNumAtoms(bool onlyExplicit=1) const
returns our number of atoms
const VECT_INT_VECT & bondRings() const
returns our bond-rings vectors
const std::string molAtomMapNumber
unsigned int getTotalNumHs(bool includeNeighbors=false) const
returns the total number of Hs (implicit and explicit) that this Atom is bound to ...
unsigned int getNumConformers() const
unsigned int getNumRadicalElectrons() const
returns the number of radical electrons for this Atom
std::vector< Point3D > POINT3D_VECT
pulls in the core RDKit functionality
ROMol is a molecule class that is intended to have a fixed topology.
bool hasProp(const char *key) const
returns whether or not we have a property with name key
RingInfo * getRingInfo() const
unsigned int getIsotope() const
returns our isotope number
double dotProduct(const Point2D &other) const
std::vector< int > INT_VECT
int getFormalCharge() const
returns the formal charge of this atom
Includes a bunch of functionality for handling Atom and Bond queries.
std::vector< ElementType > DrawMol(const ROMol &mol, int confId=-1, const std::vector< int > *highlightAtoms=0, bool includeAtomCircles=false, unsigned int dotsPerAngstrom=100, double dblBondOffset=0.3, double dblBondLengthFrac=0.8, double angstromsPerChar=0.20)
int getAtomicNum() const
returns our atomic number
OBOND_ITER_PAIR getAtomBonds(Atom const *at) const
provides access to all Bond objects connected to an Atom
unsigned int compute2DCoords(RDKit::ROMol &mol, const RDGeom::INT_POINT2D_MAP *coordMap=0, bool canonOrient=false, bool clearConfs=true, unsigned int nFlipsPerSample=0, unsigned int nSamples=0, int sampleSeed=0, bool permuteDeg4Nodes=false)
Generate 2D coordinates (a depiction) for a molecule.
unsigned int getDegree() const
Atom * getAtomWithIdx(unsigned int idx)
returns a pointer to a particular Atom
std::string getSymbol() const
returns our symbol (determined by our atomic number)
The class for representing atoms.
void getProp(const char *key, T &res) const
allows retrieval of a particular property value
bool isInitialized() const
checks to see if we've been properly initialized
void drawLine(std::vector< ElementType > &res, int atnum1, int atnum2, int lineWidth, int dashed, double x1, double y1, double x2, double y2)