bool EEMCharges::ComputeCharges(OBMol &mol) { mol.SetPartialChargesPerceived(); if(_parameters.empty()) _loadParameters(); // Copied from spectrophore.cpp // CHI and ETA unsigned int _nAtoms = mol.NumAtoms(); unsigned int dim(_nAtoms + 1); std::vector<double> CHI(dim); double** ETA = new double*[dim]; for (unsigned int i = 0; i < dim; ++i) { ETA[i] = new double[dim]; } double totalCharge(0.0); unsigned int i(0); double hardness; double electronegativity; for (OpenBabel::OBMolAtomIter atom(mol); atom; atom++, i++) { int n = atom->GetAtomicNum(); int b = atom->HighestBondOrder(); // Search for parameters for a particular atom type bool found = false; for(unsigned int j = 0; j < _parameters.size(); j++) { if((_parameters[j].Z == n && _parameters[j].bond_order == b) || (_parameters[j].Z == n && _parameters[j].bond_order == - 1) || (_parameters[j].Z == -1 && _parameters[j].bond_order == -1)) { electronegativity = _parameters[j].A; hardness = _parameters[j].B; found = true; break; } } if(!found) { std::stringstream ss; ss << "No parameters found for: " << etab.GetSymbol(n) << " " << b << ". EEM charges were not calculated for the molecule." << std::endl; obErrorLog.ThrowError(__FUNCTION__, ss.str(), obError); return false; } CHI[i] = -electronegativity; ETA[i][i] = hardness; // Adjust the total molecular charge totalCharge += atom->GetFormalCharge(); } // Complete CHI CHI[_nAtoms] = totalCharge; // Complete ETA OBAtom *rAtom, *cAtom; for (unsigned int r = 0; r < _nAtoms; ++r) { rAtom = mol.GetAtom(r+1); // Atom index for (unsigned int c = r + 1; c < _nAtoms; ++c) { cAtom = mol.GetAtom(c+1); // Atom index ETA[r][c] = _kappa / cAtom->GetDistance(rAtom); ETA[c][r] = ETA[r][c]; } } for (unsigned int i = 0; i < dim; ++i) { ETA[i][_nAtoms] = -1.0; ETA[_nAtoms][i] = +1.0; } ETA[_nAtoms][_nAtoms] = 0.0; // Solve the matrix equation _solveMatrix(ETA, &(CHI[0]), dim); // CHI will contain the values OBAtom *atom; for (unsigned int i = 0; i < _nAtoms; ++i) { atom = mol.GetAtom(i+1); // atom index issue atom->SetPartialCharge(CHI[i]); } OBChargeModel::FillChargeVectors(mol); // Cleanup for(unsigned int i = 0; i < dim; i++) delete [] ETA[i]; delete [] ETA; return true; }
CPS_START_NAMESPACE /*! \file \brief Routine used internally in the DiracOpWilson class. $Id: wilson_mdag.C,v 1.2 2011-02-26 00:19:27 chulwoo Exp $ */ //-------------------------------------------------------------------- // CVS keywords // // $Author: chulwoo $ // $Date: 2011-02-26 00:19:27 $ // $Header: /home/chulwoo/CPS/repo/CVS/cps_only/cps_pp/src/util/dirac_op/d_op_wilson/sse/wilson_mdag.C,v 1.2 2011-02-26 00:19:27 chulwoo Exp $ // $Id: wilson_mdag.C,v 1.2 2011-02-26 00:19:27 chulwoo Exp $ // $Name: not supported by cvs2svn $ // $Locker: $ // $Revision: 1.2 $ // $Source: /home/chulwoo/CPS/repo/CVS/cps_only/cps_pp/src/util/dirac_op/d_op_wilson/sse/wilson_mdag.C,v $ // $State: Exp $ // //-------------------------------------------------------------------- CPS_END_NAMESPACE #include <util/data_types.h> #include <util/wilson.h> #include <util/dirac_op.h> CPS_START_NAMESPACE //! Access to the elements of the \e SU(3) matrix /*! Gets the element of the \e SU(3) matrix \e u with row \e row, column \e col and complex component \e d */ #define U(r,row,col,d,n,cb) *(u+(r+2*(row+3*(col+3*(d+4*(n+vol[0]*(cb))))))) //! Access to the elements of a spinor vector. /*! Gets the element of the spinor \e psi with spin \e s, colour \e c and complex component \e r */ #define PSI(r,c,s,n) *(psi+(r+2*(c+3*(s+4*(n))))) //! As above, but the vector is called chi #define CHI(r,c,s,n) *(chi+(r+2*(c+3*(s+4*(n))))) #define TMP1(r,c,s,n) *(tmp1+(r+2*(c+3*(s+4*(n))))) void wilson_mdag(IFloat *chi_f, IFloat *u_f, IFloat *psi_f, IFloat kappa_f, Wilson *wilson_p) { IFloat *tmp1_f; int vol; int r, c, s, n; /*--------------------------------------------------------------------------*/ /* Initializations */ /*--------------------------------------------------------------------------*/ vol = wilson_p->vol[0]; tmp1_f = wilson_p->af[0]; Float *chi = (Float *) chi_f; Float *psi = (Float *) psi_f; Float kappa = Float(kappa_f); /*--------------------------------------------------------------------------*/ /* DslashDag_E0 */ /*--------------------------------------------------------------------------*/ wilson_dslash(tmp1_f, u_f, psi_f, 1, 1, wilson_p); /*--------------------------------------------------------------------------*/ /* DslashDag_0E */ /*--------------------------------------------------------------------------*/ wilson_dslash(chi_f, u_f, tmp1_f, 0, 1, wilson_p); /*--------------------------------------------------------------------------*/ /* [1_OO - kappa * DslashDag_0E * DslashDag_E0] ] */ /*--------------------------------------------------------------------------*/ for(n=0;n<vol;n++){ for(s=0;s<4;s++){ for(c=0;c<3;c++){ for(r=0;r<2;r++){ CHI(r,c,s,n) = ( PSI(r,c,s,n) - kappa*kappa * CHI(r,c,s,n)); } } } } DiracOp::CGflops += vol*24*2; }
void OBSpectrophore::_calculateProperties(OpenBabel::OBMol* mol) { // // PROPERTY 1: ATOMIC PARTIAL CHARGES [0] // // CHI and ETA unsigned int dim(_nAtoms + 1); std::vector<double> CHI(dim); double** ETA = new double*[dim]; double** ETA2 = new double*[dim]; // A copy for the electrophilicity later on for (unsigned int i = 0; i < dim; ++i) { ETA[i] = new double[dim]; ETA2[i] = new double[dim]; } double totalCharge(0.0); unsigned int i(0); unsigned int n; double hardness; double electronegativity; for (OpenBabel::OBMolAtomIter atom(mol); atom; ++atom) { n = (unsigned int) atom->GetAtomicNum(); switch (n) { case 1: // H hardness = 0.65971; electronegativity = 0.20606; break; case 3: // Li hardness = 0.32966; electronegativity = 0.36237; break; case 5: // B hardness = 0.32966; electronegativity = 0.36237; break; case 6: // C hardness = 0.32966; electronegativity = 0.36237; break; case 7: // N hardness = 0.34519; electronegativity = 0.49279; break; case 8: // O hardness = 0.54428; electronegativity = 0.73013; break; case 9: // F hardness = 0.72664; electronegativity = 0.72052; break; case 11: // Na hardness = 0.32966; electronegativity = 0.36237; break; case 12: // Mg hardness = 0.32966; electronegativity = 0.36237; break; case 14: // Si hardness = 0.32966; electronegativity = 0.36237; break; case 15: // P hardness = 0.32966; electronegativity = 0.36237; break; case 16: // S hardness = 0.20640; electronegativity = 0.62020; break; case 17: // Cl hardness = 0.32966; electronegativity = 0.36237; break; case 19: // K hardness = 0.32966; electronegativity = 0.36237; break; case 20: // Ca hardness = 0.32966; electronegativity = 0.36237; break; case 26: // Fe hardness = 0.32966; electronegativity = 0.36237; break; case 29: // Cu hardness = 0.32966; electronegativity = 0.36237; break; case 30: // Zn hardness = 0.32966; electronegativity = 0.36237; break; case 35: // Br hardness = 0.54554; electronegativity = 0.70052; break; case 53: // I hardness = 0.30664; electronegativity = 0.68052; break; default: hardness = 0.65971; electronegativity = 0.20606; break; } CHI[i] = -electronegativity; ETA[i][i] = 2.0 * hardness; // Adjust the total molecular charge totalCharge += atom->GetFormalCharge(); // Increment ++i; } // Complete CHI CHI[_nAtoms] = totalCharge; // Complete ETA double d; for (unsigned int r = 0; r < _nAtoms; ++r) { for (unsigned int c = r + 1; c < _nAtoms; ++c) { d = (_oricoor[r][0] - _oricoor[c][0]) * (_oricoor[r][0] - _oricoor[c][0]); d += (_oricoor[r][1] - _oricoor[c][1]) * (_oricoor[r][1] - _oricoor[c][1]); d += (_oricoor[r][2] - _oricoor[c][2]) * (_oricoor[r][2] - _oricoor[c][2]); ETA[r][c] = 0.529176 / sqrt(d); // 0.529176: Angstrom to au ETA[c][r] = ETA[r][c]; } } for (unsigned int i = 0; i < dim; ++i) { ETA[i][_nAtoms] = -1.0; ETA[_nAtoms][i] = +1.0; } ETA[_nAtoms][_nAtoms] = 0.0; // Make ETA2 a copy of ETA for (unsigned int r(0); r < dim; ++r) { for (unsigned int c(0); c < dim; ++c) { ETA2[r][c] = ETA[r][c]; } } // Solve the matrix equation _solveMatrix(ETA, &(CHI[0]), dim); // CHI will contain the values // Add values to property matrix for (unsigned int i = 0; i < _nAtoms; ++i) { _property[i][0] = CHI[i]; } double CHIeq2 = CHI[dim - 1] * CHI[dim - 1]; // For electrophilicity later on // Clean for (unsigned int i = 0; i < dim; ++i) { delete[] ETA[i]; ETA[i] = NULL; } delete[] ETA; ETA = NULL; // // PROPERTY 2: ATOMIC LIPOPHILICITY VALUES [1] // unsigned int a(0); for (OpenBabel::OBMolAtomIter atom(mol); atom; ++atom) { n = (unsigned int) atom->GetAtomicNum(); switch (n) { case 1: // H if (atom->GetValence()) { if (atom->IsNonPolarHydrogen()) // Non-polar H { _property[a][1] = -0.018; } else // Polar H { _property[a][1] = -0.374; } } else { _property[a][1] = -0.175; } break; case 6: // C _property[a][1] = 0.271; break; case 7: // N _property[a][1] = -0.137; break; case 8: // O _property[a][1] = -0.321; break; case 9: // F _property[a][1] = 0.217; break; case 16: // S _property[a][1] = 0.385; break; case 17: // Cl _property[a][1] = 0.632; break; case 35: // Br _property[a][1] = 0.815; break; case 53: // I _property[a][1] = 0.198; break; default: // The rest _property[a][1] = -0.175; break; } // Increment ++a; } // // PROPERTY 3: ATOMIC SHAPE DEVIATIONS [2] // for (unsigned int a(0); a < _nAtoms; ++a) { for (unsigned int c(0); c < 3; ++c) { _coor[a][c] = _oricoor[a][c]; } } double COG[3]; // Center of geometry for (unsigned int c(0); c < 3; ++c) { COG[c] = _coor[0][c]; for (unsigned int a(1); a < _nAtoms; ++a) { COG[c] += _coor[a][c]; } COG[c] /= _nAtoms; } // Shift molecules to COG and calculate individual distances std::vector<double> distance(_nAtoms); double averageDistance(0.0); for (unsigned int a(0); a < _nAtoms; ++a) { distance[a] = 0.0; for (unsigned int c(0); c < 3; ++c) { _coor[a][c] -= COG[c]; distance[a] += _coor[a][c] * _coor[a][c]; } distance[a] = sqrt(distance[a]); averageDistance += distance[a]; } averageDistance /= _nAtoms; // Set relative to average distance for (unsigned int a(0); a < _nAtoms; ++a) { distance[a] -= averageDistance; distance[a] *= averageDistance; } // Add property for (unsigned int a(0); a < _nAtoms; ++a) { _property[a][2] = distance[a]; } // // PROPERTY 4: ATOMIC ELECTROPHILICITY [3] // // CHI and ETA2 for (unsigned int i(0); i < dim; ++i) { CHI[i] = 1.0; } CHI[_nAtoms] = 0.0; // Complete ETA2 for (unsigned int i = 0; i < dim; ++i) { ETA2[i][_nAtoms] = 0.0; ETA2[_nAtoms][i] = 1.0; } ETA2[_nAtoms][_nAtoms] = -1.0; // Solve the matrix equation _solveMatrix(ETA2, &(CHI[0]), dim); // CHI will contain the values // Add values to property matrix for (unsigned int i = 0; i < _nAtoms; ++i) { _property[i][3] = CHI[i] * CHIeq2; } // Clean for (unsigned int i = 0; i < dim; ++i) { delete[] ETA2[i]; ETA2[i] = NULL; } delete[] ETA2; ETA2 = NULL; // // Return // return; }