get dashes working in the cairo drawing;

additional improvements to the drawing
This commit is contained in:
Greg Landrum
2012-09-20 04:12:24 +00:00
parent af502c43cb
commit 4e90f88ab7
2 changed files with 38 additions and 14 deletions

View File

@@ -137,7 +137,7 @@ namespace RDKit {
int atnum1 = mol[*bAts]->getAtomicNum();
int atnum2 = mol.getAtomWithIdx(a2Idx)->getAtomicNum();
if( !mol.getRingInfo()->numBondRings(bond->getIdx()) && !bond->getBondType()==Bond::AROMATIC ) {
if( !mol.getRingInfo()->numBondRings(bond->getIdx()) && bond->getBondType()!=Bond::AROMATIC ) {
// acyclic bonds
RDGeom::Point2D obv=a2-a1;
RDGeom::Point2D perp=obv;
@@ -169,7 +169,8 @@ namespace RDKit {
dotsPerAngstrom*(a2.y-perp.y) );
}
} else if( bond->getBondType()==Bond::SINGLE || bond->getBondType()==Bond::TRIPLE ) {
}
if( bond->getBondType()==Bond::SINGLE || bond->getBondType()==Bond::TRIPLE ) {
DrawLine( res , atnum1 , atnum2 , lineWidth , false ,
dotsPerAngstrom*(a1.x) ,
dotsPerAngstrom*(a1.y) ,
@@ -238,12 +239,10 @@ namespace RDKit {
}
}
}
double massDiff=fabs(PeriodicTable::getTable()->getAtomicWeight(mol[*bAts]->getAtomicNum()) -
mol[*bAts]->getMass());
static double massTol=0.001;
int isotope = mol[*bAts]->getIsotope();
if(mol[*bAts]->getAtomicNum()!=6 ||
mol[*bAts]->getFormalCharge()!=0 ||
massDiff>massTol ){
isotope ){
res.push_back(ATOM);
res.push_back(mol[*bAts]->getAtomicNum());
res.push_back(static_cast<ElementType>(dotsPerAngstrom*a1.x));
@@ -254,8 +253,8 @@ namespace RDKit {
leftToRight=false;
}
if(massDiff>massTol){
symbol = boost::lexical_cast<std::string>(int(mol[*bAts]->getMass()+.1))+symbol;
if(isotope){
symbol = boost::lexical_cast<std::string>(isotope)+symbol;
}
if(mol[*bAts]->getAtomicNum()!=6){
int nHs=mol[*bAts]->getTotalNumHs();

View File

@@ -1,6 +1,6 @@
// $Id: sample.cpp 793 2008-08-17 14:33:30Z glandrum $
// $Id$
//
// Copyright (C) 2009 Greg Landrum
// Copyright (C) 2009-2012 Greg Landrum
// 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
@@ -176,6 +176,12 @@ void drawLineCairo(std::vector<int>::const_iterator &pos,
int width=*pos++;
cairo_set_line_width(cr,width*10);
int dashed=*pos++;
if(dashed){
double dashes[]={20.0,20.0};
cairo_set_dash(cr,dashes,sizeof(dashes)/sizeof(dashes[0]),0);
} else {
cairo_set_dash(cr,0,0,0);
}
int an1=*pos++;
int an2=*pos++;
int xp1 = *pos++;
@@ -256,10 +262,16 @@ void MolToCairo(const ROMol &mol,cairo_t *cr,int width,int height,
int fontSize=14,int maxDotsPerAngstrom=30){
PRECONDITION(cr,"no context");
PRECONDITION(width>0 && height>0,"bad dimensions");
RWMol cp(mol);
RDKit::MolOps::Kekulize(cp);
RDDepict::compute2DCoords(cp);
std::vector<int> drawing=RDKit::Drawing::DrawMol(cp);
RWMol *cp = new RWMol(mol);
try{
RDKit::MolOps::Kekulize(*cp);
} catch (...) {
delete cp;
cp = new RDKit::RWMol(mol);
}
RDDepict::compute2DCoords(*cp);
std::vector<int> drawing=RDKit::Drawing::DrawMol(*cp);
delete cp;
cairo_set_source_rgb (cr, 1.0, 1.0, 1.0);
cairo_rectangle(cr,0,0,width,height);
@@ -381,6 +393,19 @@ void DrawDemo(){
cairo_surface_destroy (surface);
delete mol;
}
{
RWMol *mol=SmilesToMol("Nccc(CCO)n",0,false);
mol->updatePropertyCache();
cairo_surface_t *surface =
cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 300, 300);
cairo_t *cr = cairo_create (surface);
MolToCairo(*mol,cr,300,300);
cairo_destroy (cr);
cairo_surface_write_to_png (surface, "mol4.png");
cairo_surface_destroy (surface);
delete mol;
}
#endif
}