| 35 |
|
* |
| 36 |
|
* [1] Meineke, et al., J. Comp. Chem. 26, 252-271 (2005). |
| 37 |
|
* [2] Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006). |
| 38 |
< |
* [3] Sun, Lin & Gezelter, J. Chem. Phys. 128, 24107 (2008). |
| 38 |
> |
* [3] Sun, Lin & Gezelter, J. Chem. Phys. 128, 234107 (2008). |
| 39 |
|
* [4] Kuang & Gezelter, J. Chem. Phys. 133, 164101 (2010). |
| 40 |
|
* [5] Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011). |
| 41 |
|
*/ |
| 48 |
|
#include "optimization/StatusFunction.hpp" |
| 49 |
|
#include "optimization/OptimizationFactory.hpp" |
| 50 |
|
|
| 51 |
– |
|
| 52 |
– |
|
| 51 |
|
#ifdef IS_MPI |
| 52 |
|
#include <mpi.h> |
| 53 |
|
#endif |
| 55 |
|
using namespace QuantLib; |
| 56 |
|
namespace OpenMD { |
| 57 |
|
|
| 58 |
< |
FluctuatingChargePropagator::FluctuatingChargePropagator(SimInfo* info, |
| 59 |
< |
ForceManager* fm) : |
| 62 |
< |
info_(info), forceMan_(fm), hasFlucQ_(false) { |
| 58 |
> |
FluctuatingChargePropagator::FluctuatingChargePropagator(SimInfo* info) : |
| 59 |
> |
info_(info), hasFlucQ_(false), forceMan_(NULL), initialized_(false) { |
| 60 |
|
|
| 61 |
+ |
Globals* simParams = info_->getSimParams(); |
| 62 |
+ |
fqParams_ = simParams->getFluctuatingChargeParameters(); |
| 63 |
+ |
} |
| 64 |
+ |
|
| 65 |
+ |
FluctuatingChargePropagator::~FluctuatingChargePropagator() { |
| 66 |
+ |
} |
| 67 |
+ |
|
| 68 |
+ |
void FluctuatingChargePropagator::setForceManager(ForceManager* forceMan) { |
| 69 |
+ |
forceMan_ = forceMan; |
| 70 |
+ |
} |
| 71 |
+ |
|
| 72 |
+ |
void FluctuatingChargePropagator::initialize() { |
| 73 |
|
if (info_->usesFluctuatingCharges()) { |
| 74 |
|
if (info_->getNFluctuatingCharges() > 0) { |
| 66 |
– |
|
| 75 |
|
hasFlucQ_ = true; |
| 76 |
< |
Globals* simParams = info_->getSimParams(); |
| 77 |
< |
fqParams_ = simParams->getFluctuatingChargeParameters(); |
| 70 |
< |
|
| 76 |
> |
fqConstraints_ = new FluctuatingChargeConstraints(info_); |
| 77 |
> |
fqConstraints_->setConstrainRegions(fqParams_->getConstrainRegions()); |
| 78 |
|
} |
| 79 |
|
} |
| 80 |
< |
} |
| 80 |
> |
|
| 81 |
> |
if (!hasFlucQ_) { |
| 82 |
> |
initialized_ = true; |
| 83 |
> |
return; |
| 84 |
> |
} |
| 85 |
|
|
| 75 |
– |
void FluctuatingChargePropagator::initialize() { |
| 76 |
– |
|
| 77 |
– |
if (!hasFlucQ_) return; |
| 78 |
– |
|
| 86 |
|
SimInfo::MoleculeIterator i; |
| 87 |
|
Molecule::FluctuatingChargeIterator j; |
| 88 |
|
Molecule* mol; |
| 89 |
|
Atom* atom; |
| 90 |
|
|
| 91 |
< |
for (mol = info_->beginMolecule(i); mol != NULL; |
| 92 |
< |
mol = info_->nextMolecule(i)) { |
| 93 |
< |
for (atom = mol->beginFluctuatingCharge(j); atom != NULL; |
| 94 |
< |
atom = mol->nextFluctuatingCharge(j)) { |
| 95 |
< |
atom->setFlucQPos(0.0); |
| 96 |
< |
atom->setFlucQVel(0.0); |
| 97 |
< |
} |
| 98 |
< |
} |
| 99 |
< |
|
| 100 |
< |
std::cerr << "doing a minimization\n"; |
| 91 |
> |
// For single-minima flucq, this ensures a net neutral system, but |
| 92 |
> |
// for multiple minima, this is no longer the right thing to do: |
| 93 |
> |
// |
| 94 |
> |
// for (mol = info_->beginMolecule(i); mol != NULL; |
| 95 |
> |
// mol = info_->nextMolecule(i)) { |
| 96 |
> |
// for (atom = mol->beginFluctuatingCharge(j); atom != NULL; |
| 97 |
> |
// atom = mol->nextFluctuatingCharge(j)) { |
| 98 |
> |
// atom->setFlucQPos(0.0); |
| 99 |
> |
// atom->setFlucQVel(0.0); |
| 100 |
> |
// } |
| 101 |
> |
// } |
| 102 |
|
|
| 103 |
< |
FluctuatingChargeObjectiveFunction flucQobjf(info_, forceMan_, fqConstraints_); |
| 103 |
> |
FluctuatingChargeObjectiveFunction flucQobjf(info_, forceMan_, |
| 104 |
> |
fqConstraints_); |
| 105 |
> |
|
| 106 |
|
DynamicVector<RealType> initCoords = flucQobjf.setInitialCoords(); |
| 107 |
< |
Problem problem(flucQobjf, *(new NoConstraint()), *(new NoStatus()), initCoords); |
| 107 |
> |
Problem problem(flucQobjf, *(new NoConstraint()), *(new NoStatus()), |
| 108 |
> |
initCoords); |
| 109 |
> |
|
| 110 |
|
EndCriteria endCriteria(1000, 100, 1e-5, 1e-5, 1e-5); |
| 111 |
+ |
|
| 112 |
|
OptimizationMethod* minim = OptimizationFactory::getInstance()->createOptimization("SD", info_); |
| 113 |
|
|
| 114 |
+ |
DumpStatusFunction dsf(info_); // we want a dump file written |
| 115 |
+ |
// every iteration |
| 116 |
|
minim->minimize(problem, endCriteria); |
| 117 |
< |
|
| 117 |
> |
cerr << "back from minim\n"; |
| 118 |
> |
initialized_ = true; |
| 119 |
|
} |
| 120 |
|
|
| 105 |
– |
|
| 121 |
|
void FluctuatingChargePropagator::applyConstraints() { |
| 122 |
+ |
if (!initialized_) initialize(); |
| 123 |
|
if (!hasFlucQ_) return; |
| 108 |
– |
|
| 124 |
|
fqConstraints_->applyConstraints(); |
| 125 |
|
} |
| 126 |
|
} |