File: MQN.cpp

package info (click to toggle)
rdkit 201403-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 62,288 kB
  • ctags: 15,156
  • sloc: cpp: 125,376; python: 55,674; java: 4,831; ansic: 4,178; xml: 2,499; sql: 1,775; yacc: 1,551; lex: 1,051; makefile: 353; fortran: 183; sh: 148; cs: 93
file content (162 lines) | stat: -rw-r--r-- 4,808 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
// $Id$
//
//  Copyright (C) 2013 Greg Landrum
//
//   @@ 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/Descriptors/MolDescriptors.h>
#include <GraphMol/Descriptors/Lipinski.h>
#include <boost/foreach.hpp>
#include <vector>
#include <algorithm>

namespace RDKit{
  namespace Descriptors {
    std::vector<unsigned int> calcMQNs(const ROMol &mol,
                                      bool force){
      // FIX: use force value to enable caching
      std::vector<unsigned int> res(42,0);

      // ---------------------------------------------------
      // atom-centered things
      // Note: We're not doing exactly the same thing
      //       as the original paper on polarity counts
      //       since we're using different donor and acceptor
      //       definitions.
      ROMol::VERTEX_ITER atBegin,atEnd;
      boost::tie(atBegin,atEnd) = mol.getVertices();  
      while(atBegin!=atEnd){
        const ATOM_SPTR at=mol[*atBegin];
        ++atBegin;
        unsigned int nHs = at->getTotalNumHs();
        unsigned int nRings=mol.getRingInfo()->numAtomRings(at->getIdx());
        switch(at->getAtomicNum()){
        case 0:
        case 1:
          break;
        case 6:
          res[0]++;break;
        case 9:
          res[1]++;break;
        case 17:
          res[2]++;break;
        case 35:
          res[3]++;break;
        case 53:
          res[4]++;break;
        case 16:
          res[5]++;break;
        case 15:
          res[6]++;break;
        case 7:
          if(!nRings) res[7]++;
          else res[8]++;
          if(at->getDegree()!=4){
            res[19]++; // number of acceptor sites
            res[20]++; // number of acceptor atoms
          }
          if(nHs){
            res[21]+=nHs; // number of donor sites
            res[22]++; // number of donor atoms
          }
          break;
        case 8:
          if(!nRings) res[9]++;
          else res[10]++;
          res[20]++; // number of acceptor atoms
          if(at->getFormalCharge()!=-1){
            res[19]+=2; // number of acceptor sites
          } else {
            res[19]+=3; // number of acceptor sites
          }
          if(nHs){
            res[21]+=nHs; // number of donor sites
            res[22]++; // number of donor atoms
          }
          break;
        default:
          res[11]++;break;
        }

        if(at->getFormalCharge()>0) res[24]++; // positive charges
        else if(at->getFormalCharge()<0) res[23]++; // negative charges

        if(at->getAtomicNum()!=1){
          switch(at->getDegree()){
          case 1:
            res[25]++;
            break;
          case 2:
            if(!nRings) res[26]++;
            else res[29]++;
            break;
          case 3:
            if(!nRings) res[27]++;
            else res[30]++;
            break;
          case 4:
            if(!nRings) res[28]++;
            else res[31]++;
            break;
          }
          if(nRings>=2) res[40]++;
        }
      }
      
      // ---------------------------------------------------
      // bond counts:
      unsigned int nAromatic=0;
      ROMol::EDGE_ITER firstB,lastB;
      boost::tie(firstB,lastB) = mol.getEdges();
      while(firstB!=lastB){
        const BOND_SPTR bond = mol[*firstB];
        if(bond->getIsAromatic()) ++nAromatic;
        unsigned int nRings=mol.getRingInfo()->numBondRings(bond->getIdx());
        switch(bond->getBondType()){
        case Bond::SINGLE:
          if(!nRings) res[12]++;
          else res[15]++;
          break;
        case Bond::DOUBLE:
          if(!nRings) res[13]++;
          else res[16]++;
          break;
        case Bond::TRIPLE:
          if(!nRings) res[14]++;
          else res[17]++;
          break;
        default:
          break;
        }
        if(nRings>=2) res[41]++;
        ++firstB;
      }
      // rather than do the work to kekulize the molecule, we cheat
      // by just dividing the number of aromatic bonds evenly among the
      // cyclic single bond and cyclic double bond bins and give any
      // remainder to the single bonds
      res[15] += nAromatic/2;
      res[16] += nAromatic/2;
      if(nAromatic%2) res[15]++;
      res[18] = calcNumRotatableBonds(mol);

      // ---------------------------------------------------
      //  ring size counts
      BOOST_FOREACH(const INT_VECT &iv,mol.getRingInfo()->atomRings()){
        if(iv.size()<10){
          res[iv.size()+29]++;
        } else {
          res[39]++;
        }
      }
      
      return res;
    }
  } // end of namespace Descriptors
} // end of namespace RDKit