--- trunk/src/restraints/ThermoIntegrationForceManager.cpp 2005/03/10 15:10:24 417 +++ trunk/src/restraints/ThermoIntegrationForceManager.cpp 2009/11/25 20:02:06 1390 @@ -1,4 +1,4 @@ - /* +/* * Copyright (c) 2005 The University of Notre Dame. All Rights Reserved. * * The University of Notre Dame grants you ("Licensee") a @@ -6,19 +6,10 @@ * redistribute this software in source and binary code form, provided * that the following conditions are met: * - * 1. Acknowledgement of the program authors must be made in any - * publication of scientific results based in part on use of the - * program. An acceptable form of acknowledgement is citation of - * the article in which the program was described (Matthew - * A. Meineke, Charles F. Vardeman II, Teng Lin, Christopher - * J. Fennell and J. Daniel Gezelter, "OOPSE: An Object-Oriented - * Parallel Simulation Engine for Molecular Dynamics," - * J. Comput. Chem. 26, pp. 252-271 (2005)) - * - * 2. Redistributions of source code must retain the above copyright + * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * - * 3. Redistributions in binary form must reproduce the above copyright + * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the * distribution. @@ -37,60 +28,63 @@ * arising out of the use of or inability to use software, even if the * University of Notre Dame has been advised of the possibility of * such damages. + * + * SUPPORT OPEN SCIENCE! If you use OpenMD or its source code in your + * research, please cite the appropriate papers when you publish your + * work. Good starting points are: + * + * [1] Meineke, et al., J. Comp. Chem. 26, 252-271 (2005). + * [2] Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006). + * [3] Sun, Lin & Gezelter, J. Chem. Phys. 128, 24107 (2008). + * [4] Vardeman & Gezelter, in progress (2009). */ -#include + #include "restraints/ThermoIntegrationForceManager.hpp" -#include "integrators/Integrator.hpp" -#include "primitives/Molecule.hpp" -#include "utils/simError.h" -#include "utils/OOPSEConstant.hpp" -#include "utils/StringUtils.hpp" -namespace oopse { +#ifdef IS_MPI +#include +#endif + +namespace OpenMD { ThermoIntegrationForceManager::ThermoIntegrationForceManager(SimInfo* info): - ForceManager(info){ + RestraintForceManager(info){ currSnapshot_ = info_->getSnapshotManager()->getCurrentSnapshot(); simParam = info_->getSimParams(); - if (simParam->haveThermIntLambda()){ - tIntLambda_ = simParam->getThermIntLambda(); + if (simParam->haveThermodynamicIntegrationLambda()){ + tIntLambda_ = simParam->getThermodynamicIntegrationLambda(); } else{ tIntLambda_ = 1.0; sprintf(painCave.errMsg, - "ThermoIntegration error: the transformation parameter (lambda) was\n" - "\tnot specified. OOPSE will use a default value of %f. To set\n" - "\tlambda, use the thermodynamicIntegrationLambda variable.\n", + "ThermoIntegration error: the transformation parameter\n" + "\t(lambda) was not specified. OpenMD will use a default\n" + "\tvalue of %f. To set lambda, use the \n" + "\tthermodynamicIntegrationLambda variable.\n", tIntLambda_); painCave.isFatal = 0; simError(); } - if (simParam->haveThermIntK()){ - tIntK_ = simParam->getThermIntK(); + if (simParam->haveThermodynamicIntegrationK()){ + tIntK_ = simParam->getThermodynamicIntegrationK(); } else{ tIntK_ = 1.0; sprintf(painCave.errMsg, - "ThermoIntegration Warning: the tranformation parameter exponent\n" - "\t(k) was not specified. OOPSE will use a default value of %f.\n" - "\tTo set k, use the thermodynamicIntegrationK variable.\n", + "ThermoIntegration Warning: the tranformation parameter\n" + "\texponent (k) was not specified. OpenMD will use a default\n" + "\tvalue of %f. To set k, use the thermodynamicIntegrationK\n" + "\tvariable.\n", tIntK_); painCave.isFatal = 0; simError(); } - if (simParam->getUseSolidThermInt()) { - // build a restraint object - restraint_ = new Restraints(info_, tIntLambda_, tIntK_); - - } - // build the scaling factor used to modulate the forces and torques factor_ = pow(tIntLambda_, tIntK_); - } ThermoIntegrationForceManager::~ThermoIntegrationForceManager(){ @@ -105,12 +99,13 @@ namespace oopse { StuntDouble* integrableObject; Vector3d frc; Vector3d trq; + Mat3x3d tempTau; - curSnapshot = info_->getSnapshotManager()->getCurrentSnapshot(); - // perform the standard calcForces first ForceManager::calcForces(needPotential, needStress); + curSnapshot = info_->getSnapshotManager()->getCurrentSnapshot(); + // now scale forces and torques of all the integrableObjects for (mol = info_->beginMolecule(mi); mol != NULL; @@ -128,26 +123,46 @@ namespace oopse { integrableObject->setTrq(trq); } } - - // set vraw to be the unmodulated potential - lrPot_ = curSnapshot->statData[Stats::POTENTIAL_ENERGY]; - curSnapshot->statData[Stats::VRAW] = lrPot_; - - // modulate the potential and update the snapshot - lrPot_ *= factor_; - curSnapshot->statData[Stats::POTENTIAL_ENERGY] = lrPot_; } - // do crystal restraint forces for thermodynamic integration - if (simParam->getUseSolidThermInt()) { - - lrPot_ += restraint_->Calc_Restraint_Forces(); - curSnapshot->statData[Stats::POTENTIAL_ENERGY] = lrPot_; - - vHarm_ = restraint_->getVharm(); - curSnapshot->statData[Stats::VHARM] = vHarm_; - } + // set vraw to be the unmodulated potential + lrPot_ = curSnapshot->statData[Stats::LONG_RANGE_POTENTIAL]; + curSnapshot->statData[Stats::VRAW] = lrPot_; - } - + // modulate the potential and update the snapshot + lrPot_ *= factor_; + curSnapshot->statData[Stats::LONG_RANGE_POTENTIAL] = lrPot_; + + // scale the pressure tensor + tempTau = curSnapshot->statData.getTau(); + tempTau *= factor_; + curSnapshot->statData.setTau(tempTau); + + // now, on to the applied restraining potentials (if needed): + RealType restPot_local = 0.0; + RealType vHarm_local = 0.0; + + if (simParam->getUseRestraints()) { + // do restraints from RestraintForceManager: + //restPot_local = doRestraints(1.0 - factor_); + restPot_local = doRestraints(1.0 - factor_); + vHarm_local = getUnscaledPotential(); + } + +#ifdef IS_MPI + RealType restPot; + MPI::COMM_WORLD.Allreduce(&restPot_local, &restPot, 1, + MPI::REALTYPE, MPI::SUM); + MPI::COMM_WORLD.Allreduce(&vHarm_local, &vHarm_, 1, + MPI::REALTYPE, MPI::SUM); + lrPot_ += restPot; +#else + lrPot_ += restPot_local; + vHarm_ = vHarm_local; +#endif + + // give the final values to stats + curSnapshot->statData[Stats::LONG_RANGE_POTENTIAL] = lrPot_; + curSnapshot->statData[Stats::VHARM] = vHarm_; + } }