File: sanitTest.cpp

package info (click to toggle)
rdkit 201203-3
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 37,840 kB
  • sloc: cpp: 93,902; python: 51,897; java: 5,192; ansic: 3,497; xml: 2,499; sql: 1,641; yacc: 1,518; lex: 1,076; makefile: 325; fortran: 183; sh: 153; cs: 51
file content (102 lines) | stat: -rw-r--r-- 2,437 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
//  $Id: sanitTest.cpp 1625 2011-01-13 04:22:56Z glandrum $
// 
//   Copyright (C) 2002-2006 Rational Discovery LLC
//
//   @@ 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 <GraphMol/RDKitBase.h>
#include <GraphMol/RDKitQueries.h>
#include <GraphMol/SmilesParse/SmilesParse.h>
#include <GraphMol/SmilesParse/SmilesWrite.h>

#include <stdlib.h>
#include <iostream>
#include <fstream>
#include <RDGeneral/types.h>
#include <RDGeneral/Invariant.h>
#include <RDGeneral/RDLog.h>
#include <GraphMol/MolOps.h>
#include <GraphMol/SanitException.h>

using namespace RDKit;

int testArom(RWMol m) {
  //BOOST_LOG(rdErrorLog) << "********************************************\n";
  //BOOST_LOG(rdErrorLog) << "Testing aromaticity :\n";

  int res = MolOps::setAromaticity(m);

  //BOOST_LOG(rdErrorLog) << "\nDone testing aromaticity \n";
  //BOOST_LOG(rdErrorLog) << "********************************************\n";
  return res;
}

void testKekule(RWMol &m) {
  MolOps::Kekulize(m);
}

void getSmiles(std::string line, std::string &smi) {
  int x = line.find("\t");
  if (x == -1) {
    x = line.find(" ");
  }

  smi = line.substr(0,x);
  std::string rem = line.substr(x+1, line.length() - x);
  x = rem.find(" ");
  std::string name;
  name = rem.substr(0, x);
  
  BOOST_LOG(rdInfoLog) << smi << " " << name << " " ;
}

int main(int argc, char *argv[]) {
  RDLog::InitLogs();
  std::string fname;
  if (argc > 1) {
    fname = argv[1];
  }
  else {
    BOOST_LOG(rdErrorLog) << "Pass in the list of smiles\n";
  }
  
  std::ifstream inStream(fname.c_str());
  const int MAX_LINE_LEN = 256;
  char inLine[MAX_LINE_LEN];
  std::string tmpstr;
  std::string smi;
  inStream.getline(inLine, MAX_LINE_LEN,'\n');
  tmpstr = inLine;
  //MolOps molop;
  while (tmpstr.size() > 0) {
    getSmiles(tmpstr, smi);
    RWMol *m = SmilesToMol(smi, 0, 0);
    
    try {
      //testKekule(*m);
      
      MolOps::sanitizeMol(*m);

      int nar;
      m->getProp("numArom", nar);
      BOOST_LOG(rdInfoLog)<< nar << "\n";

      //MolOps::setHybridization(*m);
      delete m;
    }
    catch (MolSanitizeException){
      BOOST_LOG(rdErrorLog) << smi << "\n";
      delete m;
    }
    inStream.getline(inLine, MAX_LINE_LEN,'\n');
    tmpstr = inLine;
  }
  return 1;
}