1 |
< |
/* |
1 |
> |
/* |
2 |
|
* Copyright (c) 2005 The University of Notre Dame. All Rights Reserved. |
3 |
|
* |
4 |
|
* The University of Notre Dame grants you ("Licensee") a |
6 |
|
* redistribute this software in source and binary code form, provided |
7 |
|
* that the following conditions are met: |
8 |
|
* |
9 |
< |
* 1. Acknowledgement of the program authors must be made in any |
10 |
< |
* publication of scientific results based in part on use of the |
11 |
< |
* program. An acceptable form of acknowledgement is citation of |
12 |
< |
* the article in which the program was described (Matthew |
13 |
< |
* A. Meineke, Charles F. Vardeman II, Teng Lin, Christopher |
14 |
< |
* J. Fennell and J. Daniel Gezelter, "OOPSE: An Object-Oriented |
15 |
< |
* Parallel Simulation Engine for Molecular Dynamics," |
16 |
< |
* J. Comput. Chem. 26, pp. 252-271 (2005)) |
17 |
< |
* |
18 |
< |
* 2. Redistributions of source code must retain the above copyright |
9 |
> |
* 1. Redistributions of source code must retain the above copyright |
10 |
|
* notice, this list of conditions and the following disclaimer. |
11 |
|
* |
12 |
< |
* 3. Redistributions in binary form must reproduce the above copyright |
12 |
> |
* 2. Redistributions in binary form must reproduce the above copyright |
13 |
|
* notice, this list of conditions and the following disclaimer in the |
14 |
|
* documentation and/or other materials provided with the |
15 |
|
* distribution. |
28 |
|
* arising out of the use of or inability to use software, even if the |
29 |
|
* University of Notre Dame has been advised of the possibility of |
30 |
|
* such damages. |
31 |
+ |
* |
32 |
+ |
* SUPPORT OPEN SCIENCE! If you use OpenMD or its source code in your |
33 |
+ |
* research, please cite the appropriate papers when you publish your |
34 |
+ |
* work. Good starting points are: |
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). |
39 |
+ |
* [4] Kuang & Gezelter, J. Chem. Phys. 133, 164101 (2010). |
40 |
+ |
* [5] Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011). |
41 |
|
*/ |
42 |
|
|
43 |
|
/** |
51 |
|
#include "integrators/VelocityVerletIntegrator.hpp" |
52 |
|
#include "integrators/DLM.hpp" |
53 |
|
#include "utils/StringUtils.hpp" |
54 |
+ |
#include "utils/ProgressBar.hpp" |
55 |
|
|
56 |
< |
namespace oopse { |
57 |
< |
VelocityVerletIntegrator::VelocityVerletIntegrator(SimInfo *info) : Integrator(info), rotAlgo(NULL) { |
56 |
> |
namespace OpenMD { |
57 |
> |
VelocityVerletIntegrator::VelocityVerletIntegrator(SimInfo *info) : Integrator(info), rotAlgo(NULL) { |
58 |
|
dt2 = 0.5 * dt; |
59 |
|
rotAlgo = new DLM(); |
60 |
|
rattle = new Rattle(info); |
61 |
< |
} |
62 |
< |
|
63 |
< |
VelocityVerletIntegrator::~VelocityVerletIntegrator() { |
61 |
> |
} |
62 |
> |
|
63 |
> |
VelocityVerletIntegrator::~VelocityVerletIntegrator() { |
64 |
|
delete rotAlgo; |
65 |
|
delete rattle; |
66 |
< |
} |
67 |
< |
|
68 |
< |
void VelocityVerletIntegrator::initialize(){ |
69 |
< |
|
70 |
< |
forceMan_->init(); |
71 |
< |
|
72 |
< |
// remove center of mass drift velocity (in case we passed in a configuration |
73 |
< |
// that was drifting |
66 |
> |
} |
67 |
> |
|
68 |
> |
void VelocityVerletIntegrator::initialize(){ |
69 |
> |
|
70 |
> |
forceMan_->initialize(); |
71 |
> |
|
72 |
> |
// remove center of mass drift velocity (in case we passed in a |
73 |
> |
// configuration that was drifting) |
74 |
|
velocitizer_->removeComDrift(); |
75 |
< |
|
75 |
> |
|
76 |
|
// initialize the forces before the first step |
77 |
< |
calcForce(true, true); |
78 |
< |
|
79 |
< |
//execute constraint algorithm to make sure at the very beginning the system is constrained |
77 |
> |
calcForce(); |
78 |
> |
|
79 |
> |
// execute the constraint algorithm to make sure that the system is |
80 |
> |
// constrained at the very beginning |
81 |
|
if (info_->getNGlobalConstraints() > 0) { |
82 |
< |
rattle->constraintA(); |
83 |
< |
calcForce(true, true); |
84 |
< |
rattle->constraintB(); |
85 |
< |
info_->getSnapshotManager()->advance();//copy the current snapshot to previous snapshot |
82 |
> |
rattle->constraintA(); |
83 |
> |
calcForce(); |
84 |
> |
rattle->constraintB(); |
85 |
> |
//copy the current snapshot to previous snapshot |
86 |
> |
info_->getSnapshotManager()->advance(); |
87 |
|
} |
88 |
< |
|
88 |
> |
|
89 |
|
if (needVelocityScaling) { |
90 |
< |
velocitizer_->velocitize(targetScalingTemp); |
90 |
> |
velocitizer_->velocitize(targetScalingTemp); |
91 |
|
} |
92 |
|
|
93 |
|
dumpWriter = createDumpWriter(); |
94 |
< |
eorWriter = createEorWriter(); |
94 |
> |
|
95 |
|
statWriter = createStatWriter(); |
96 |
+ |
|
97 |
+ |
dumpWriter->writeDumpAndEor(); |
98 |
|
|
99 |
< |
dumpWriter->writeDump(); |
100 |
< |
eorWriter->writeDump(); |
95 |
< |
|
99 |
> |
progressBar = new ProgressBar(); |
100 |
> |
|
101 |
|
//save statistics, before writeStat, we must save statistics |
102 |
|
thermo.saveStat(); |
103 |
|
saveConservedQuantity(); |
104 |
< |
statWriter->writeStat(currentSnapshot_->statData); |
104 |
> |
if (simParams->getUseRNEMD()) |
105 |
> |
rnemd_->getStarted(); |
106 |
|
|
107 |
+ |
statWriter->writeStat(currentSnapshot_->statData); |
108 |
+ |
|
109 |
|
currSample = sampleTime + currentSnapshot_->getTime(); |
110 |
< |
currStatus = statusTime + currentSnapshot_->getTime();; |
111 |
< |
currThermal = thermalTime + + currentSnapshot_->getTime(); |
110 |
> |
currStatus = statusTime + currentSnapshot_->getTime(); |
111 |
> |
currThermal = thermalTime + currentSnapshot_->getTime(); |
112 |
> |
if (needReset) { |
113 |
> |
currReset = resetTime + currentSnapshot_->getTime(); |
114 |
> |
} |
115 |
> |
if (simParams->getUseRNEMD()){ |
116 |
> |
currRNEMD = RNEMD_exchangeTime + currentSnapshot_->getTime(); |
117 |
> |
} |
118 |
|
needPotential = false; |
119 |
|
needStress = false; |
120 |
< |
|
121 |
< |
} |
122 |
< |
|
123 |
< |
void VelocityVerletIntegrator::doIntegrate() { |
124 |
< |
|
125 |
< |
|
120 |
> |
|
121 |
> |
} |
122 |
> |
|
123 |
> |
void VelocityVerletIntegrator::doIntegrate() { |
124 |
> |
|
125 |
> |
|
126 |
|
initialize(); |
127 |
< |
|
127 |
> |
|
128 |
|
while (currentSnapshot_->getTime() < runTime) { |
129 |
< |
|
130 |
< |
preStep(); |
131 |
< |
|
132 |
< |
integrateStep(); |
133 |
< |
|
134 |
< |
postStep(); |
135 |
< |
|
129 |
> |
|
130 |
> |
preStep(); |
131 |
> |
|
132 |
> |
integrateStep(); |
133 |
> |
|
134 |
> |
postStep(); |
135 |
> |
|
136 |
|
} |
137 |
< |
|
137 |
> |
|
138 |
|
finalize(); |
139 |
< |
|
140 |
< |
} |
139 |
> |
|
140 |
> |
} |
141 |
|
|
142 |
|
|
143 |
< |
void VelocityVerletIntegrator::preStep() { |
144 |
< |
double difference = currentSnapshot_->getTime() + dt - currStatus; |
143 |
> |
void VelocityVerletIntegrator::preStep() { |
144 |
> |
RealType difference = currentSnapshot_->getTime() + dt - currStatus; |
145 |
> |
|
146 |
> |
if (difference > 0 || fabs(difference) < OpenMD::epsilon) { |
147 |
> |
needPotential = true; |
148 |
> |
needStress = true; |
149 |
> |
} |
150 |
> |
} |
151 |
|
|
152 |
< |
if (difference > 0 || fabs(difference) < oopse::epsilon) { |
133 |
< |
needPotential = true; |
134 |
< |
needStress = true; |
135 |
< |
} |
152 |
> |
void VelocityVerletIntegrator::postStep() { |
153 |
|
|
154 |
< |
} |
154 |
> |
//save snapshot |
155 |
> |
info_->getSnapshotManager()->advance(); |
156 |
> |
|
157 |
> |
//increase time |
158 |
> |
currentSnapshot_->increaseTime(dt); |
159 |
> |
|
160 |
> |
if (needVelocityScaling) { |
161 |
> |
if (currentSnapshot_->getTime() >= currThermal) { |
162 |
> |
velocitizer_->velocitize(targetScalingTemp); |
163 |
> |
currThermal += thermalTime; |
164 |
> |
} |
165 |
> |
} |
166 |
> |
if (useRNEMD) { |
167 |
> |
if (currentSnapshot_->getTime() >= currRNEMD) { |
168 |
> |
rnemd_->doRNEMD(); |
169 |
> |
currRNEMD += RNEMD_exchangeTime; |
170 |
> |
} |
171 |
> |
rnemd_->collectData(); |
172 |
> |
} |
173 |
> |
|
174 |
> |
if (currentSnapshot_->getTime() >= currSample) { |
175 |
> |
dumpWriter->writeDumpAndEor(); |
176 |
> |
|
177 |
> |
currSample += sampleTime; |
178 |
> |
} |
179 |
> |
|
180 |
> |
if (currentSnapshot_->getTime() >= currStatus) { |
181 |
> |
//save statistics, before writeStat, we must save statistics |
182 |
> |
thermo.saveStat(); |
183 |
> |
saveConservedQuantity(); |
184 |
|
|
185 |
< |
void VelocityVerletIntegrator::postStep() { |
185 |
> |
if (simParams->getUseRNEMD()) { |
186 |
> |
rnemd_->getStatus(); |
187 |
> |
} |
188 |
|
|
189 |
< |
//save snapshot |
142 |
< |
info_->getSnapshotManager()->advance(); |
189 |
> |
statWriter->writeStat(currentSnapshot_->statData); |
190 |
|
|
191 |
< |
//increase time |
192 |
< |
currentSnapshot_->increaseTime(dt); |
146 |
< |
|
147 |
< |
if (needVelocityScaling) { |
148 |
< |
if (currentSnapshot_->getTime() >= currThermal) { |
149 |
< |
velocitizer_->velocitize(targetScalingTemp); |
150 |
< |
currThermal += thermalTime; |
151 |
< |
} |
152 |
< |
} |
191 |
> |
progressBar->setStatus(currentSnapshot_->getTime(), runTime); |
192 |
> |
progressBar->update(); |
193 |
|
|
194 |
< |
if (currentSnapshot_->getTime() >= currSample) { |
195 |
< |
dumpWriter->writeDump(); |
196 |
< |
eorWriter->writeDump(); |
197 |
< |
currSample += sampleTime; |
198 |
< |
} |
194 |
> |
needPotential = false; |
195 |
> |
needStress = false; |
196 |
> |
currStatus += statusTime; |
197 |
> |
} |
198 |
> |
|
199 |
> |
if (needReset && currentSnapshot_->getTime() >= currReset) { |
200 |
> |
resetIntegrator(); |
201 |
> |
currReset += resetTime; |
202 |
> |
} |
203 |
> |
} |
204 |
|
|
160 |
– |
if (currentSnapshot_->getTime() >= currStatus) { |
161 |
– |
//save statistics, before writeStat, we must save statistics |
162 |
– |
thermo.saveStat(); |
163 |
– |
saveConservedQuantity(); |
164 |
– |
statWriter->writeStat(currentSnapshot_->statData); |
205 |
|
|
206 |
< |
needPotential = false; |
207 |
< |
needStress = false; |
208 |
< |
currStatus += statusTime; |
169 |
< |
} |
170 |
< |
|
171 |
< |
|
172 |
< |
} |
173 |
< |
|
174 |
< |
|
175 |
< |
void VelocityVerletIntegrator::finalize() { |
176 |
< |
|
177 |
< |
dumpWriter->writeDump(); |
178 |
< |
eorWriter->writeDump(); |
179 |
< |
|
206 |
> |
void VelocityVerletIntegrator::finalize() { |
207 |
> |
dumpWriter->writeEor(); |
208 |
> |
|
209 |
|
delete dumpWriter; |
181 |
– |
delete eorWriter; |
210 |
|
delete statWriter; |
211 |
< |
|
211 |
> |
|
212 |
|
dumpWriter = NULL; |
185 |
– |
eorWriter = NULL; |
213 |
|
statWriter = NULL; |
214 |
< |
|
215 |
< |
} |
214 |
> |
|
215 |
> |
} |
216 |
|
|
217 |
< |
void VelocityVerletIntegrator::integrateStep() { |
218 |
< |
|
217 |
> |
void VelocityVerletIntegrator::integrateStep() { |
218 |
> |
|
219 |
|
moveA(); |
220 |
< |
calcForce(needPotential, needStress); |
220 |
> |
calcForce(); |
221 |
|
moveB(); |
222 |
< |
} |
222 |
> |
} |
223 |
|
|
224 |
|
|
225 |
< |
void VelocityVerletIntegrator::calcForce(bool needPotential, |
226 |
< |
bool needStress) { |
227 |
< |
forceMan_->calcForces(needPotential, needStress); |
201 |
< |
} |
225 |
> |
void VelocityVerletIntegrator::calcForce() { |
226 |
> |
forceMan_->calcForces(); |
227 |
> |
} |
228 |
|
|
229 |
< |
DumpWriter* VelocityVerletIntegrator::createDumpWriter() { |
230 |
< |
return new DumpWriter(info_, info_->getDumpFileName()); |
231 |
< |
} |
229 |
> |
DumpWriter* VelocityVerletIntegrator::createDumpWriter() { |
230 |
> |
return new DumpWriter(info_); |
231 |
> |
} |
232 |
|
|
233 |
< |
DumpWriter* VelocityVerletIntegrator::createEorWriter() { |
208 |
< |
return new DumpWriter(info_, getPrefix(info_->getDumpFileName()) + ".eor"); |
209 |
< |
} |
233 |
> |
StatWriter* VelocityVerletIntegrator::createStatWriter() { |
234 |
|
|
235 |
< |
StatWriter* VelocityVerletIntegrator::createStatWriter() { |
236 |
< |
return new StatWriter(info_->getStatFileName()); |
237 |
< |
} |
235 |
> |
std::string statFileFormatString = simParams->getStatFileFormat(); |
236 |
> |
StatsBitSet mask = parseStatFileFormat(statFileFormatString); |
237 |
> |
|
238 |
> |
// if we're doing a thermodynamic integration, we'll want the raw |
239 |
> |
// potential as well as the full potential: |
240 |
|
|
241 |
+ |
|
242 |
+ |
if (simParams->getUseThermodynamicIntegration()) |
243 |
+ |
mask.set(Stats::VRAW); |
244 |
|
|
245 |
< |
} //end namespace oopse |
245 |
> |
// if we've got restraints turned on, we'll also want a report of the |
246 |
> |
// total harmonic restraints |
247 |
> |
if (simParams->getUseRestraints()){ |
248 |
> |
mask.set(Stats::VHARM); |
249 |
> |
} |
250 |
> |
|
251 |
> |
if (simParams->havePrintPressureTensor() && |
252 |
> |
simParams->getPrintPressureTensor()){ |
253 |
> |
mask.set(Stats::PRESSURE_TENSOR_XX); |
254 |
> |
mask.set(Stats::PRESSURE_TENSOR_XY); |
255 |
> |
mask.set(Stats::PRESSURE_TENSOR_XZ); |
256 |
> |
mask.set(Stats::PRESSURE_TENSOR_YX); |
257 |
> |
mask.set(Stats::PRESSURE_TENSOR_YY); |
258 |
> |
mask.set(Stats::PRESSURE_TENSOR_YZ); |
259 |
> |
mask.set(Stats::PRESSURE_TENSOR_ZX); |
260 |
> |
mask.set(Stats::PRESSURE_TENSOR_ZY); |
261 |
> |
mask.set(Stats::PRESSURE_TENSOR_ZZ); |
262 |
> |
} |
263 |
> |
|
264 |
> |
if (simParams->getAccumulateBoxDipole()) { |
265 |
> |
mask.set(Stats::BOX_DIPOLE_X); |
266 |
> |
mask.set(Stats::BOX_DIPOLE_Y); |
267 |
> |
mask.set(Stats::BOX_DIPOLE_Z); |
268 |
> |
} |
269 |
> |
|
270 |
> |
if (simParams->haveTaggedAtomPair() && simParams->havePrintTaggedPairDistance()) { |
271 |
> |
if (simParams->getPrintTaggedPairDistance()) { |
272 |
> |
mask.set(Stats::TAGGED_PAIR_DISTANCE); |
273 |
> |
} |
274 |
> |
} |
275 |
> |
|
276 |
> |
if (simParams->getUseRNEMD()) { |
277 |
> |
mask.set(Stats::RNEMD_EXCHANGE_TOTAL); |
278 |
> |
} |
279 |
> |
|
280 |
> |
|
281 |
> |
return new StatWriter(info_->getStatFileName(), mask); |
282 |
> |
} |
283 |
> |
|
284 |
> |
|
285 |
> |
} //end namespace OpenMD |