AlGDock/ForceFields/OBC/ReferenceObc_BAK.cpp
//void ReferenceObc::computeBornRadii(const vector<RealVec>& atomCoordinates, vector<double>& bornRadii) {
void ReferenceObc::computeBornRadii(const vector& atomCoordinates, vector& bornRadii) {
void ReferenceObc :: computeBornRadii ( const vector& atomCoordinates vector& bornRadii ) {
void ReferenceObc::computeBornRadii(const ObcParameters* obcParameters,
  const vector3* atomCoordinates,
  const double* Igrid,
  vector<double>& bornRadii) {
    static const double zero    = static_cast<double>(0.0);
    static const double one     = static_cast<double>(1.0);
    static const double two     = static_cast<double>(2.0);
    static const double three   = static_cast<double>(3.0);
    static const double half    = static_cast<double>(0.5);
    static const double fourth  = static_cast<double>(0.25);
    int numberOfAtoms                           = obcParameters->getNumberOfAtoms();
    const vector<double>& atomicRadii         = obcParameters->getAtomicRadii();
    const vector<double>& scaledRadiusFactor  = obcParameters->getScaledRadiusFactors();
    vector<double>& obcChain                  = getObcChain();
    double dielectricOffset                 = obcParameters->getDielectricOffset();
    double alphaObc                         = obcParameters->getAlphaObc();
    double betaObc                          = obcParameters->getBetaObc();
    double gammaObc                         = obcParameters->getGammaObc();
    for (int atomI = 0; atomI < numberOfAtoms; atomI++) {
       double radiusI         = atomicRadii[atomI];
       double offsetRadiusI   = radiusI - dielectricOffset;
       double radiusIInverse  = one/offsetRadiusI;
       double sum             = zero;
       for (int atomJ = 0; atomJ < numberOfAtoms; atomJ++) {
          if (atomJ != atomI) {
             double deltaR[OpenMM::ReferenceForce::LastDeltaRIndex];
             OpenMM::ReferenceForce::getDeltaR(atomCoordinates[atomI], atomCoordinates[atomJ], deltaR);
             double r               = deltaR[OpenMM::ReferenceForce::RIndex];
             if (_obcParameters->getUseCutoff() && r > _obcParameters->getCutoffDistance())
                 continue;
             double offsetRadiusJ   = atomicRadii[atomJ] - dielectricOffset; 
             double scaledRadiusJ   = offsetRadiusJ*scaledRadiusFactor[atomJ];
             double rScaledRadiusJ  = r + scaledRadiusJ;
             if (offsetRadiusI < rScaledRadiusJ) {
                double rInverse = one/r;
                double l_ij     = offsetRadiusI > FABS(r - scaledRadiusJ) ? offsetRadiusI : FABS(r - scaledRadiusJ);
                l_ij     = one/l_ij; 
                double u_ij     = one/rScaledRadiusJ; 
                double l_ij2    = l_ij*l_ij;
                double u_ij2    = u_ij*u_ij;
                double ratio    = LN((u_ij/l_ij));
                double term     = l_ij - u_ij + fourth*r*(u_ij2 - l_ij2)
                  + (half*rInverse*ratio)
                  + (fourth*scaledRadiusJ*scaledRadiusJ*rInverse)*(l_ij2 - u_ij2);
                if (offsetRadiusI < (scaledRadiusJ - r)) {
                   term += two*(radiusIInverse - l_ij);
                }
                sum += term;
             }
          }
       }
       sum              *= half; 
       if (Igrid!=NULL) {
         sum += Igrid[atomI];
       }
       sum              *= offsetRadiusI; 
       double sum2       = sum*sum;
       double sum3       = sum*sum2;
       double tanhSum    = TANH(alphaObc*sum - betaObc*sum2 + gammaObc*sum3);
       bornRadii[atomI]      = one/(one/offsetRadiusI - tanhSum/radiusI); 
       obcChain[atomI]       = offsetRadiusI*(alphaObc - two*betaObc*sum + three*gammaObc*sum2);
       obcChain[atomI]       = (one - tanhSum*tanhSum)*obcChain[atomI]/radiusI;
    }
}
void ReferenceObc :: computeBornRadii ( const ObcParameters * obcParameters , const vector3 * atomCoordinates , const double * Igrid , vector < double > & bornRadii ) { static const double zero = static_cast < double > ( 0.0 ) ; static const double one = static_cast < double > ( 1.0 ) ; static const double two = static_cast < double > ( 2.0 ) ; static const double three = static_cast < double > ( 3.0 ) ; static const double half = static_cast < double > ( 0.5 ) ; static const double fourth = static_cast < double > ( 0.25 ) ; int numberOfAtoms = obcParameters -> getNumberOfAtoms ( ) ; const vector < double > & atomicRadii = obcParameters -> getAtomicRadii ( ) ; const vector < double > & scaledRadiusFactor = obcParameters -> getScaledRadiusFactors ( ) ; vector < double > & obcChain = getObcChain ( ) ; double dielectricOffset = obcParameters -> getDielectricOffset ( ) ; double alphaObc = obcParameters -> getAlphaObc ( ) ; double betaObc = obcParameters -> getBetaObc ( ) ; double gammaObc = obcParameters -> getGammaObc ( ) ; for ( int atomI = 0 ; atomI < numberOfAtoms ; atomI ++ ) { double radiusI = atomicRadii [ atomI ] ; double offsetRadiusI = radiusI - dielectricOffset ; double radiusIInverse = one / offsetRadiusI ; double sum = zero ; for ( int atomJ = 0 ; atomJ < numberOfAtoms ; atomJ ++ ) { if ( atomJ != atomI ) { double deltaR [ OpenMM :: ReferenceForce :: LastDeltaRIndex ] ; OpenMM :: ReferenceForce :: getDeltaR ( atomCoordinates [ atomI ] , atomCoordinates [ atomJ ] , deltaR ) ; double r = deltaR [ OpenMM :: ReferenceForce :: RIndex ] ; if ( _obcParameters -> getUseCutoff ( ) && r > _obcParameters -> getCutoffDistance ( ) ) continue ; double offsetRadiusJ = atomicRadii [ atomJ ] - dielectricOffset ; double scaledRadiusJ = offsetRadiusJ * scaledRadiusFactor [ atomJ ] ; double rScaledRadiusJ = r + scaledRadiusJ ; if ( offsetRadiusI < rScaledRadiusJ ) { double rInverse = one / r ; double l_ij = offsetRadiusI > FABS ( r - scaledRadiusJ ) ? offsetRadiusI : FABS ( r - scaledRadiusJ ) ; l_ij = one / l_ij ; double u_ij = one / rScaledRadiusJ ; double l_ij2 = l_ij * l_ij ; double u_ij2 = u_ij * u_ij ; double ratio = LN ( ( u_ij / l_ij ) ) ; double term = l_ij - u_ij + fourth * r * ( u_ij2 - l_ij2 ) + ( half * rInverse * ratio ) + ( fourth * scaledRadiusJ * scaledRadiusJ * rInverse ) * ( l_ij2 - u_ij2 ) ; if ( offsetRadiusI < ( scaledRadiusJ - r ) ) { term += two * ( radiusIInverse - l_ij ) ; } sum += term ; } } } sum *= half ; if ( Igrid != NULL ) { sum += Igrid [ atomI ] ; } sum *= offsetRadiusI ; double sum2 = sum * sum ; double sum3 = sum * sum2 ; double tanhSum = TANH ( alphaObc * sum - betaObc * sum2 + gammaObc * sum3 ) ; bornRadii [ atomI ] = one / ( one / offsetRadiusI - tanhSum / radiusI ) ; obcChain [ atomI ] = offsetRadiusI * ( alphaObc - two * betaObc * sum + three * gammaObc * sum2 ) ; obcChain [ atomI ] = ( one - tanhSum * tanhSum ) * obcChain [ atomI ] / radiusI ; } }
void ReferenceObc::computeBornRadii(const vector<RealVec>& atomCoordinates, vector<double>& bornRadii) {
void ReferenceObc :: computeBornRadii ( const vector<RealVec > & atomCoordinates vector<double > & bornRadii ) {
// --------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------- // calculate Born radii // HCT code // the inverse of Eq. 10 // the inverse of Eq. 11 // the summand in Eq. 9 // this case (atom i completely inside atom j) is not considered in the original paper // Jay Ponder and the authors of Tinker recognized this and // worked out the details // OBC-specific code (Eqs. 6-8 in OBC paper) // Now sum becomes I in OBC paper // printf("Atom %d, Born radius = %f, I_HCT = %f, I_grid = %f\n", atomI, radiusI, sum, Igrid[atomI]); // TODO: Derivatives not correct after adding numerical integral. // OBC-specific code (Eqs. 6-8 in OBC paper) // Now sum becomes \Psi in OBC paper // This is the derivative of the Born radius with respect to Psi, // multiplied by offsetRadiusI and divided by BornRadii[atomI]**2