AlGDock/ForceFields/OBC/ReferenceObc_BAK.cpp
//double ReferenceObc::computeBornEnergyForces(const vector<RealVec>& atomCoordinates,
//                                           const vector<double>& partialCharges, vector<RealVec>& inputForces) {
double ReferenceObc::computeBornEnergyForces(const vector& atomCoordinates,
const vector& partialCharges, vector& inputForces) {
double ReferenceObc :: computeBornEnergyForces ( const vector& atomCoordinates const vector& partialCharges vector& inputForces ) {
double ReferenceObc::computeBornEnergy(const ObcParameters* obcParameters,
                                       const vector3* atomCoordinates,
                                       const vector<double>& partialCharges,
                                       const double* Igrid) {
    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 four    = static_cast<double>(4.0);
    static const double half    = static_cast<double>(0.5);
    static const double fourth  = static_cast<double>(0.25);
    static const double eighth  = static_cast<double>(0.125);
    const int numberOfAtoms = obcParameters->getNumberOfAtoms();
    const double strength = obcParameters->getStrength();
    const double dielectricOffset = obcParameters->getDielectricOffset();
    const double cutoffDistance = obcParameters->getCutoffDistance();
    const double soluteDielectric = obcParameters->getSoluteDielectric();
    const double solventDielectric = obcParameters->getSolventDielectric();
    double preFactor;
    if (soluteDielectric != zero && solventDielectric != zero)
        preFactor = two*obcParameters->getElectricConstant()*((one/soluteDielectric) - (one/solventDielectric));
    else
        preFactor = zero;
    vector<double> bornRadii(numberOfAtoms);
    computeBornRadii(obcParameters, atomCoordinates, Igrid, bornRadii);
    double obcEnergy                 = zero;
    vector<double> bornForces(numberOfAtoms, 0.0);
    if (includeAceApproximation()) {
       computeAceNonPolarForce(obcParameters, bornRadii, &obcEnergy, bornForces);
    }
    for (int atomI = 0; atomI < numberOfAtoms; atomI++) {
       double partialChargeI = preFactor*partialCharges[atomI];
       for (int atomJ = atomI; atomJ < numberOfAtoms; atomJ++) {
          double deltaR[OpenMM::ReferenceForce::LastDeltaRIndex];
          OpenMM::ReferenceForce::getDeltaR(atomCoordinates[atomI], atomCoordinates[atomJ], deltaR);
          if (obcParameters->getUseCutoff() && deltaR[OpenMM::ReferenceForce::RIndex] > cutoffDistance)
              continue;
          double r2                 = deltaR[OpenMM::ReferenceForce::R2Index];
          double alpha2_ij          = bornRadii[atomI]*bornRadii[atomJ];
          double D_ij               = r2/(four*alpha2_ij);
          double expTerm            = EXP(-D_ij);
          double denominator2       = r2 + alpha2_ij*expTerm; 
          double denominator        = SQRT(denominator2); 
          double Gpol               = (partialChargeI*partialCharges[atomJ])/denominator; 
          double dGpol_dalpha2_ij   = -half*Gpol*expTerm*(one + D_ij)/denominator2;
          double energy = Gpol;
          if (atomI != atomJ) {
              if (obcParameters->getUseCutoff())
                  energy -= partialChargeI*partialCharges[atomJ]/cutoffDistance;
              bornForces[atomJ]        += dGpol_dalpha2_ij*bornRadii[atomI];
              deltaX                   *= dGpol_dr;
              deltaY                   *= dGpol_dr;
              deltaZ                   *= dGpol_dr;
              inputForces[atomI][0]    -= deltaX;
              inputForces[atomI][1]    -= deltaY;
              inputForces[atomI][2]    -= deltaZ;
              inputForces[atomJ][0]    += deltaX;
              inputForces[atomJ][1]    += deltaY;
              inputForces[atomJ][2]    += deltaZ;
          } else {
             energy *= half;
          }
          obcEnergy         += strength*energy;
          bornForces[atomI] += dGpol_dalpha2_ij*bornRadii[atomJ];
       }
    }
    return obcEnergy;
}
double ReferenceObc :: computeBornEnergy ( const ObcParameters * obcParameters , const vector3 * atomCoordinates , const vector < double > & partialCharges , const double * Igrid ) { 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 four = static_cast < double > ( 4.0 ) ; static const double half = static_cast < double > ( 0.5 ) ; static const double fourth = static_cast < double > ( 0.25 ) ; static const double eighth = static_cast < double > ( 0.125 ) ; const int numberOfAtoms = obcParameters -> getNumberOfAtoms ( ) ; const double strength = obcParameters -> getStrength ( ) ; const double dielectricOffset = obcParameters -> getDielectricOffset ( ) ; const double cutoffDistance = obcParameters -> getCutoffDistance ( ) ; const double soluteDielectric = obcParameters -> getSoluteDielectric ( ) ; const double solventDielectric = obcParameters -> getSolventDielectric ( ) ; double preFactor ; if ( soluteDielectric != zero && solventDielectric != zero ) preFactor = two * obcParameters -> getElectricConstant ( ) * ( ( one / soluteDielectric ) - ( one / solventDielectric ) ) ; else preFactor = zero ; vector < double > bornRadii ( numberOfAtoms ) ; computeBornRadii ( obcParameters , atomCoordinates , Igrid , bornRadii ) ; double obcEnergy = zero ; vector < double > bornForces ( numberOfAtoms , 0.0 ) ; if ( includeAceApproximation ( ) ) { computeAceNonPolarForce ( obcParameters , bornRadii , & obcEnergy , bornForces ) ; } for ( int atomI = 0 ; atomI < numberOfAtoms ; atomI ++ ) { double partialChargeI = preFactor * partialCharges [ atomI ] ; for ( int atomJ = atomI ; atomJ < numberOfAtoms ; atomJ ++ ) { double deltaR [ OpenMM :: ReferenceForce :: LastDeltaRIndex ] ; OpenMM :: ReferenceForce :: getDeltaR ( atomCoordinates [ atomI ] , atomCoordinates [ atomJ ] , deltaR ) ; if ( obcParameters -> getUseCutoff ( ) && deltaR [ OpenMM :: ReferenceForce :: RIndex ] > cutoffDistance ) continue ; double r2 = deltaR [ OpenMM :: ReferenceForce :: R2Index ] ; double alpha2_ij = bornRadii [ atomI ] * bornRadii [ atomJ ] ; double D_ij = r2 / ( four * alpha2_ij ) ; double expTerm = EXP ( - D_ij ) ; double denominator2 = r2 + alpha2_ij * expTerm ; double denominator = SQRT ( denominator2 ) ; double Gpol = ( partialChargeI * partialCharges [ atomJ ] ) / denominator ; double energy = Gpol ; if ( atomI != atomJ ) { if ( obcParameters -> getUseCutoff ( ) ) energy -= partialChargeI * partialCharges [ atomJ ] / cutoffDistance ; } else { energy *= half ; } obcEnergy += strength * energy ; } } return obcEnergy ; }
double ReferenceObc::computeBornEnergyForces(const vector<RealVec>& atomCoordinates,
const vector<double>& partialCharges, vector<RealVec>& inputForces) {
double ReferenceObc :: computeBornEnergyForces ( const vector<RealVec > & atomCoordinates const vector<double > & partialCharges vector<RealVec > & inputForces ) {
// --------------------------------------------------------------------------------------- //    static const double three   = static_cast<double>(3.0); // constants // --------------------------------------------------------------------------------------- // compute Born radii // set energy/forces to zero // --------------------------------------------------------------------------------------- // compute the nonpolar solvation via ACE approximation //    cout << "ObcEnergy, after Ace:" << obcEnergy << std::endl; // --------------------------------------------------------------------------------------- // first main loop //          double deltaX             = deltaR[OpenMM::ReferenceForce::XIndex]; //          double deltaY             = deltaR[OpenMM::ReferenceForce::YIndex]; //          double deltaZ             = deltaR[OpenMM::ReferenceForce::ZIndex]; //          double dGpol_dr           = -Gpol*(one - fourth*expTerm)/denominator2;   // //          double dGpol_dalpha2_ij   = -half*Gpol*expTerm*(one + D_ij)/denominator2; //              bornForces[atomJ]        += dGpol_dalpha2_ij*bornRadii[atomI]; //              deltaX                   *= dGpol_dr; //              deltaY                   *= dGpol_dr; //              deltaZ                   *= dGpol_dr; //              inputForces[atomI][0]    -= deltaX; //              inputForces[atomI][1]    -= deltaY; //              inputForces[atomI][2]    -= deltaZ; // //              inputForces[atomJ][0]    += deltaX; //              inputForces[atomJ][1]    += deltaY; //              inputForces[atomJ][2]    += deltaZ; //          bornForces[atomI] += dGpol_dalpha2_ij*bornRadii[atomJ];