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 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250
|
#include <cstdlib>
#include <iostream>
#include "MolData3Ddescriptors.h"
#include <GraphMol/RDKitBase.h>
#include <boost/math/special_functions/round.hpp>
#include "GraphMol/PartialCharges/GasteigerCharges.h"
#include "GraphMol/PartialCharges/GasteigerParams.h"
using namespace std;
MolData3Ddescriptors::MolData3Ddescriptors() {}
std::vector<double> MolData3Ddescriptors::GetUn(int numAtoms) {
std::vector<double> u(numAtoms, 1.0);
return u;
}
std::vector<double> MolData3Ddescriptors::GetRelativeMW(
const RDKit::ROMol& mol) {
double* relativeMw = data3D.getMW();
int numAtoms = mol.getNumAtoms();
std::vector<double> pol(numAtoms, 0.0);
for (int i = 0; i < numAtoms; ++i) {
pol[i] = relativeMw[mol.getAtomWithIdx(i)->getAtomicNum() - 1];
}
return pol;
}
std::vector<double> MolData3Ddescriptors::GetRelativePol(
const RDKit::ROMol& mol) {
int numAtoms = mol.getNumAtoms();
double* relativePol = data3D.getPOL();
std::vector<double> pol(numAtoms, 0.0);
for (int i = 0; i < numAtoms; ++i) {
pol[i] = relativePol[mol.getAtomWithIdx(i)->getAtomicNum() - 1];
}
return pol;
}
std::vector<double> MolData3Ddescriptors::GetRelativeVdW(
const RDKit::ROMol& mol) {
int numAtoms = mol.getNumAtoms();
double* relativeVdW = data3D.getVDW();
std::vector<double> vdw(numAtoms, 0.0);
for (int i = 0; i < numAtoms; ++i) {
vdw[i] = relativeVdW[mol.getAtomWithIdx(i)->getAtomicNum() - 1];
}
return vdw;
}
std::vector<double> MolData3Ddescriptors::GetRelativeRcov(
const RDKit::ROMol& mol) {
int numAtoms = mol.getNumAtoms();
double* rcov = data3D.getRCOV();
std::vector<double> wroc(numAtoms, 0.0);
for (int i = 0; i < numAtoms; ++i) {
wroc[i] = rcov[mol.getAtomWithIdx(i)->getAtomicNum() - 1] / rcov[5];
}
return wroc;
}
std::vector<double> MolData3Ddescriptors::GetRelativeENeg(
const RDKit::ROMol& mol) {
int numAtoms = mol.getNumAtoms();
double* relativeNeg = data3D.getNEG();
std::vector<double> neg(numAtoms, 0.0);
for (int i = 0; i < numAtoms; ++i) {
neg[i] = relativeNeg[mol.getAtomWithIdx(i)->getAtomicNum() - 1];
}
return neg;
}
std::vector<double> MolData3Ddescriptors::GetRelativeIonPol(
const RDKit::ROMol& mol) {
int numAtoms = mol.getNumAtoms();
double* absionpol = data3D.getIonPOL();
std::vector<double> ionpols(numAtoms, 0.0);
for (int i = 0; i < numAtoms; ++i) {
ionpols[i] = absionpol[mol.getAtomWithIdx(i)->getAtomicNum() - 1];
}
return ionpols;
}
std::vector<double> MolData3Ddescriptors::GetCustomAtomProp(
const RDKit::ROMol& mol, const std::string &customAtomPropName) {
int numAtoms = mol.getNumAtoms();
std::vector<double> customAtomarray(numAtoms, 0.0);
for (int i = 0; i < numAtoms; ++i) {
if (mol.getAtomWithIdx(i)->hasProp(customAtomPropName)) {
customAtomarray[i] = mol.getAtomWithIdx(i)->getProp<double>(customAtomPropName);
}
else {
customAtomarray[i] =1;
}
}
return customAtomarray;
}
std::vector<double> MolData3Ddescriptors::GetCharges(const RDKit::ROMol& mol) {
std::vector<double> charges(mol.getNumAtoms(), 0);
// use 12 iterations... can be more
RDKit::computeGasteigerCharges(mol, charges, 12, true);
return charges;
}
int MolData3Ddescriptors::GetPrincipalQuantumNumber(int AtomicNum) {
if (AtomicNum <= 2)
return 1;
else if (AtomicNum <= 10)
return 2;
else if (AtomicNum <= 18)
return 3;
else if (AtomicNum <= 36)
return 4;
else if (AtomicNum <= 54)
return 5;
else if (AtomicNum <= 86)
return 6;
else
return 7;
}
std::vector<double> MolData3Ddescriptors::GetIState(const RDKit::ROMol& mol) {
int numAtoms = mol.getNumAtoms();
std::vector<double> Is(numAtoms, 1.0); // values set to 1 for Hs
for (int i = 0; i < numAtoms; ++i) {
const RDKit::Atom* atom = mol.getAtomWithIdx(i);
int atNum = atom->getAtomicNum();
int degree = atom->getDegree(); // number of substituants (heavy of not?)
if (degree > 0 && atNum > 1) {
int h = atom->getTotalNumHs(
true); // caution getTotalNumHs(true) to count h !!!!
int dv = RDKit::PeriodicTable::getTable()->getNouterElecs(atNum) -
h; // number of valence (explicit with Hs)
int N = GetPrincipalQuantumNumber(atNum); // principal quantum number
double d = (double)degree - h; // degree-h
if (d > 0) {
Is[i] =
boost::math::round(1000 * (4.0 / (N * N) * dv + 1.0) / d) / 1000;
}
}
}
return Is;
}
std::vector<double> MolData3Ddescriptors::GetIStateDrag(
const RDKit::ROMol& mol) {
int numAtoms = mol.getNumAtoms();
std::vector<double> Is(numAtoms, 1.0);
for (int i = 0; i < numAtoms; ++i) {
const RDKit::Atom* atom = mol.getAtomWithIdx(i);
int atNum = atom->getAtomicNum();
int degree = atom->getDegree(); // number of substituants
if (degree > 0 && atNum > 1) {
int h = atom->getTotalNumHs(true);
int Zv = RDKit::PeriodicTable::getTable()->getNouterElecs(
atNum); // number of valence (explicit with Hs)
double dv = (double)Zv - h; // number of valence electron without Hs
int N = GetPrincipalQuantumNumber(atNum); // principal quantum number
double d = (double)degree - h; // degree-h
if (d > 0) {
Is[i] =
boost::math::round(1000 * (4.0 / (N * N) * dv + 1.0) / d) / 1000;
}
}
}
return Is;
}
// adaptation from EState.py
// we need the Is value only there
std::vector<double> MolData3Ddescriptors::GetEState(const RDKit::ROMol& mol) {
int numAtoms = mol.getNumAtoms();
std::vector<double> Is = GetIState(mol);
double tmp, p;
double* dist = RDKit::MolOps::getDistanceMat(mol, false, false);
std::vector<double> accum(numAtoms, 0.0);
for (int i = 0; i < numAtoms; i++) {
for (int j = i + 1; j < numAtoms; j++) {
p = dist[i * numAtoms + j] + 1;
if (p < 1e6) {
tmp = (Is[i] - Is[j]) / (p * p);
accum[i] += tmp;
accum[j] -= tmp;
}
}
}
for (int i = 0; i < numAtoms; i++) {
Is[i] += accum[i];
}
return Is;
}
// modification of previous code to follow documentation from Padel code
std::vector<double> MolData3Ddescriptors::GetEState2(const RDKit::ROMol& mol) {
int numAtoms = mol.getNumAtoms();
std::vector<double> Si = GetIState(mol);
// in WHIM definition it's write:
double tmp, p, d;
double* dist = RDKit::MolOps::getDistanceMat(mol, false, false);
std::vector<double> accum(numAtoms, 0.0);
for (int i = 0; i < numAtoms; i++) {
for (int j = i + 1; j < numAtoms; j++) {
d = dist[i * numAtoms + j];
p = dist[i * numAtoms + j] + 1;
if (d == 1) {
tmp = (Si[i] - Si[j]) / (p * p);
accum[i] += tmp;
accum[j] -= tmp;
}
}
}
// add the Accum to the Si
// WHIM Si values
// electrotopological indices are scaled thus: Si'=Si + 7 => Si' > 0
// In this case, only the nonhydrogen atoms are considered,
// and the atomic electrotopological charge of each atom depends on its atom
// neighbor.
// So we should not use all the terms in the sum but only Adj matrix cases!
// Correct the Si adding the rescaling parameter for WHIM only
for (int i = 0; i < numAtoms; i++) {
Si[i] += accum[i] + 7.0;
}
return Si;
}
|