13 #ifndef _RD_MOLDRAWING_H_ 14 #define _RD_MOLDRAWING_H_ 17 #include <boost/foreach.hpp> 18 #include <boost/lexical_cast.hpp> 58 int atnum1 ,
int atnum2 ,
int lineWidth ,
int dashed ,
59 double x1 ,
double y1 ,
60 double x2 ,
double y2 ) {
62 res.push_back(
LINE );
63 res.push_back( static_cast<ElementType>(lineWidth) );
64 res.push_back(dashed);
65 res.push_back( static_cast<ElementType>(atnum1) );
66 res.push_back( static_cast<ElementType>(atnum2) );
67 res.push_back( static_cast<ElementType>(x1) );
68 res.push_back( static_cast<ElementType>(y1) );
69 res.push_back( static_cast<ElementType>(x2) );
70 res.push_back( static_cast<ElementType>(y2) );
74 std::string symbol=
"";
84 bool leftToRight=
true;
89 symbol = boost::lexical_cast<std::string>(isotope)+symbol;
94 symbol +=
":" + mapNum;
100 h += boost::lexical_cast<std::string>(nHs);
102 if(leftToRight) symbol += h;
103 else symbol = h+symbol;
113 sgn += boost::lexical_cast<std::string>(chg);
115 if(leftToRight) symbol+=sgn;
116 else symbol = sgn+symbol;
121 if(fabs(nbrSum.
y)>1){
122 islope=nbrSum.
x/fabs(nbrSum.
y);
126 if(fabs(islope)>.85){
141 return std::make_pair(symbol,orient);
146 const std::vector<int> *highlightAtoms=0,
147 bool includeAtomCircles=
false,
148 unsigned int dotsPerAngstrom=100,
149 double dblBondOffset=0.3,
150 double dblBondLengthFrac=0.8,
151 double angstromsPerChar=0.20
156 std::vector<ElementType> res;
158 res.push_back(static_cast<ElementType>(dotsPerAngstrom));
165 std::vector< std::pair<std::string,OrientType> > atomSymbols;
166 ROMol::VERTEX_ITER bAts,eAts;
169 ROMol::OEDGE_ITER nbr,endNbrs;
171 boost::tie(nbr,endNbrs) = mol.
getAtomBonds(mol[*bAts].
get());
173 locs[mol[*bAts]->getIdx()].y);
177 int a2Idx=bond->getOtherAtomIdx(mol[*bAts]->getIdx());
189 double minx=1e6,miny=1e6,maxx=-1e6,maxy=-1e6;
194 boost::tie(symbol,orient)=atomSymbols[i];
203 minx = pt.
x-symbol.size()/2*angstromsPerChar;
206 minx = pt.
x-symbol.size()*angstromsPerChar;
216 maxx = pt.
x+symbol.size()/2*angstromsPerChar;
219 maxx = pt.
x+symbol.size()*angstromsPerChar;
225 miny = pt.
y-1.5*angstromsPerChar;
228 maxy = pt.
y+angstromsPerChar;
231 minx=std::min(pt.
x,minx);
232 miny=std::min(pt.
y,miny);
233 maxx=std::max(pt.
x,maxx);
234 maxy=std::max(pt.
y,maxy);
237 double dimx=(maxx-minx),dimy=(maxy-miny);
239 res.push_back(static_cast<ElementType>(dotsPerAngstrom*0));
240 res.push_back(static_cast<ElementType>(dotsPerAngstrom*0));
241 res.push_back(static_cast<ElementType>(dotsPerAngstrom*dimx));
242 res.push_back(static_cast<ElementType>(dotsPerAngstrom*dimy));
247 int a1Idx=mol[*bAts]->getIdx();
249 ROMol::OEDGE_ITER nbr,endNbrs;
251 boost::tie(nbr,endNbrs) = mol.
getAtomBonds(mol[*bAts].
get());
255 int a2Idx=bond->getOtherAtomIdx(a1Idx);
259 std::find(highlightAtoms->begin(),highlightAtoms->end(),a1Idx)
260 != highlightAtoms->end()
262 std::find(highlightAtoms->begin(),highlightAtoms->end(),a2Idx)
263 != highlightAtoms->end() ){
268 if(a2Idx<a1Idx)
continue;
271 int atnum1 = mol[*bAts]->getAtomicNum();
284 perp *= dblBondOffset;
285 startP+=(obv*(1.-dblBondLengthFrac)/2);
286 endP-=(obv*(1.-dblBondLengthFrac)/2);
288 perp *= 0.5 * dblBondOffset;
291 dotsPerAngstrom*(startP.
x+perp.
x) ,
292 dotsPerAngstrom*(startP.
y+perp.
y) ,
293 dotsPerAngstrom*(endP.x+perp.
x) ,
294 dotsPerAngstrom*(endP.y+perp.
y) );
297 dotsPerAngstrom*(startP.
x-perp.
x) ,
298 dotsPerAngstrom*(startP.
y-perp.
y) ,
299 dotsPerAngstrom*(endP.x-perp.
x) ,
300 dotsPerAngstrom*(endP.y-perp.
y) );
303 dotsPerAngstrom*(startP.
x-perp.
x) ,
304 dotsPerAngstrom*(startP.
y-perp.
y) ,
305 dotsPerAngstrom*(endP.x-perp.
x) ,
306 dotsPerAngstrom*(endP.y-perp.
y) );
312 dotsPerAngstrom*(a1.x) ,
313 dotsPerAngstrom*(a1.y) ,
314 dotsPerAngstrom*(a2.
x) ,
315 dotsPerAngstrom*(a2.
y) );
318 dotsPerAngstrom*(a1.x) ,
319 dotsPerAngstrom*(a1.y) ,
320 dotsPerAngstrom*(a2.
x) ,
321 dotsPerAngstrom*(a2.
y) );
326 dotsPerAngstrom*a1.x ,
327 dotsPerAngstrom*a1.y ,
328 dotsPerAngstrom*a2.
x ,
329 dotsPerAngstrom*a2.
y );
343 ROMol::OEDGE_ITER nbr2,endNbrs2;
344 boost::tie(nbr2,endNbrs2) = mol.
getAtomBonds(mol[*bAts].
get());
345 while(nbr2!=endNbrs2){
348 if(bond2->getIdx()==bond->getIdx() ||
350 bool sharedRing=
false;
352 if(std::find(ring.begin(),ring.end(),bond->getIdx())!=ring.end() &&
353 std::find(ring.begin(),ring.end(),bond2->getIdx())!=ring.end()){
360 int a3Idx=bond2->getOtherAtomIdx(a1Idx);
371 perp *= dblBondOffset;
375 obv *= dblBondLengthFrac;
378 dotsPerAngstrom*(offsetStart.
x+perp.
x) ,
379 dotsPerAngstrom*(offsetStart.
y+perp.
y) ,
380 dotsPerAngstrom*(offsetStart.
x+obv.x+perp.
x) ,
381 dotsPerAngstrom*(offsetStart.
y+obv.y+perp.
y) );
387 boost::tie(symbol,orient)=atomSymbols[a1Idx];
388 if(symbol!=
"" || includeAtomCircles ){
390 res.push_back(mol[*bAts]->getAtomicNum());
391 res.push_back(static_cast<ElementType>(dotsPerAngstrom*a1.
x));
392 res.push_back(static_cast<ElementType>(dotsPerAngstrom*a1.
y));
393 res.push_back(static_cast<ElementType>(symbol.length()));
395 BOOST_FOREACH(
char c, symbol){
396 res.push_back(static_cast<ElementType>(c));
399 res.push_back(static_cast<ElementType>(orient));
409 bool kekulize=
true,
bool includeAtomCircles=
false){
422 std::vector<int> drawing=
DrawMol(*cp,-1,highlightAtoms,includeAtomCircles);
boost::shared_ptr< Bond > BOND_SPTR
void Kekulize(RWMol &mol, bool markAtomsBonds=true, unsigned int maxBackTracks=100)
Kekulizes the molecule.
unsigned int getNumConformers() const
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
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 getTotalNumHs(bool includeNeighbors=false) const
returns the total number of Hs (implicit and explicit) that this Atom is bound to ...
unsigned int getNumRadicalElectrons() const
returns the number of radical electrons for this Atom
unsigned int getIsotope() const
returns our isotope number
const std::string molAtomMapNumber
unsigned int getNumAtoms(bool onlyExplicit=1) const
returns our number of atoms
std::vector< Point3D > POINT3D_VECT
void getProp(const char *key, T &res) const
allows retrieval of a particular property value
pulls in the core RDKit functionality
ROMol is a molecule class that is intended to have a fixed topology.
unsigned int getDegree() const
const Conformer & getConformer(int id=-1) const
double dotProduct(const Point2D &other) const
int getAtomicNum() const
returns our atomic number
std::vector< int > INT_VECT
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)
const VECT_INT_VECT & bondRings() const
returns our bond-rings vectors
std::pair< std::string, OrientType > getAtomSymbolAndOrientation(const Atom &atom, RDGeom::Point2D nbrSum)
RingInfo * getRingInfo() const
bool hasProp(const char *key) const
returns whether or not we have a property with name key
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 numBondRings(unsigned int idx) const
returns the number of rings bond idx is involved in
std::string getSymbol() const
returns our symbol (determined by our atomic number)
Atom * getAtomWithIdx(unsigned int idx)
returns a pointer to a particular Atom
int getFormalCharge() const
returns the formal charge of this atom
OBOND_ITER_PAIR getAtomBonds(Atom const *at) const
provides access to all Bond objects connected to an Atom
bool isInitialized() const
checks to see if we've been properly initialized
The class for representing atoms.
void drawLine(std::vector< ElementType > &res, int atnum1, int atnum2, int lineWidth, int dashed, double x1, double y1, double x2, double y2)