~ubuntu-branches/ubuntu/saucy/rdkit/saucy-proposed

« back to all changes in this revision

Viewing changes to Code/GraphMol/SmilesParse/SmilesWrite.cpp

  • Committer: Package Import Robot
  • Author(s): Michael Banck
  • Date: 2012-05-18 15:09:10 UTC
  • mfrom: (2.1.2 sid)
  • Revision ID: package-import@ubuntu.com-20120518150910-0wavbii0kr13pifa
Tags: 201203-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// $Id: SmilesWrite.cpp 1775 2011-07-01 03:42:35Z glandrum $
 
1
// $Id: SmilesWrite.cpp 2004 2012-03-26 03:12:37Z glandrum $
2
2
//
3
3
//  Copyright (C) 2002-2010 Greg Landrum and Rational Discovery LLC
4
4
//
238
238
      return res.str();
239
239
    }
240
240
 
241
 
    std::string GetBondSmiles(const Bond *bond,int atomToLeftIdx,bool doKekule){
 
241
    std::string GetBondSmiles(const Bond *bond,int atomToLeftIdx,bool doKekule,bool allBondsExplicit){
242
242
      PRECONDITION(bond,"bad bond");
243
243
      if(atomToLeftIdx<0) atomToLeftIdx=bond->getBeginAtomIdx();
244
244
 
283
283
          // FIX: we should be able to dump kekulized smiles
284
284
          //   currently this is possible by removing all
285
285
          //   isAromatic flags, but there should maybe be another way
286
 
          if( aromatic && !bond->getIsAromatic() ) res << "-";
 
286
          if(allBondsExplicit) res<<"-";
 
287
          else if( aromatic && !bond->getIsAromatic() ) res << "-";
287
288
        }
288
289
        break;
289
290
      case Bond::DOUBLE:
304
305
            break;
305
306
          }
306
307
        }
307
 
        if(!aromatic) res << ":";
 
308
        if(allBondsExplicit) res << ":";
 
309
        else if(!aromatic) res << ":";
308
310
        break;
309
311
      case Bond::DATIVE:
310
312
        if(atomToLeftIdx>=0 &&
319
321
 
320
322
    std::string FragmentSmilesConstruct(ROMol &mol,int atomIdx,
321
323
                                        std::vector<Canon::AtomColors> &colors,
322
 
                                        INT_VECT &ranks,bool doKekule){
 
324
                                        INT_VECT &ranks,bool doKekule,bool canonical,
 
325
                                        bool allBondsExplicit){
323
326
 
324
327
      Canon::MolStack molStack;
325
328
      // try to prevent excessive reallocation
329
332
 
330
333
      std::map<int,int> ringClosureMap;
331
334
      int ringIdx,closureVal;
 
335
      if(!canonical) mol.setProp("_StereochemDone",1);
 
336
 
332
337
      Canon::canonicalizeFragment(mol,atomIdx,colors,ranks,
333
 
                                  molStack);
 
338
                                    molStack);
334
339
      Bond *bond=0;
335
340
      BOOST_FOREACH(Canon::MolStackElem mSE,molStack){
336
341
        switch(mSE.type){
341
346
        case Canon::MOL_STACK_BOND:
342
347
          bond = mSE.obj.bond;
343
348
          //std::cout<<"\t\tBond: "<<bond->getIdx()<<std::endl;
344
 
          res << GetBondSmiles(bond,mSE.number,doKekule);
 
349
          res << GetBondSmiles(bond,mSE.number,doKekule,allBondsExplicit);
345
350
          break;
346
351
        case Canon::MOL_STACK_RING:
347
352
          ringIdx = mSE.number;
402
407
  // decisions and I'm gonna want to smack myself for doing this,
403
408
  // but we'll try anyway.
404
409
  std::string MolToSmiles(ROMol &mol,bool doIsomericSmiles,
405
 
                          bool doKekule,int rootedAtAtom,bool canonical){
 
410
                          bool doKekule,int rootedAtAtom,bool canonical,
 
411
                          bool allBondsExplicit){
406
412
    PRECONDITION(rootedAtAtom<0||static_cast<unsigned int>(rootedAtAtom)<mol.getNumAtoms(),
407
413
                 "rootedAtomAtom must be less than the number of atoms");
408
414
    if(!mol.getNumAtoms()) return "";
427
433
    std::string res;
428
434
 
429
435
    for(ROMol::AtomIterator atIt=tmol.beginAtoms();atIt!=tmol.endAtoms();atIt++){
430
 
      (*atIt)->updatePropertyCache();
 
436
      (*atIt)->updatePropertyCache(false);
431
437
    }
432
438
 
433
439
    unsigned int nAtoms=tmol.getNumAtoms();
473
479
      CHECK_INVARIANT(nextAtomIdx>=0,"no start atom found");
474
480
 
475
481
      subSmi = SmilesWrite::FragmentSmilesConstruct(tmol, nextAtomIdx, colors,
476
 
                                                    ranks,doKekule);
 
482
                                                    ranks,doKekule,canonical,allBondsExplicit);
477
483
 
478
484
      res += subSmi;
479
485
      colorIt = std::find(colors.begin(),colors.end(),Canon::WHITE_NODE);