43 |
|
#include "applications/staticProps/SpatialStatistics.hpp" |
44 |
|
#include "io/DumpReader.hpp" |
45 |
|
#include "primitives/Molecule.hpp" |
46 |
+ |
#ifdef _MSC_VER |
47 |
+ |
#define isnan(x) _isnan((x)) |
48 |
+ |
#define isinf(x) (!_finite(x) && !_isnan(x)) |
49 |
+ |
#endif |
50 |
|
|
51 |
|
namespace OpenMD { |
52 |
|
|
141 |
|
processStuntDouble( sd, bin ); |
142 |
|
|
143 |
|
dynamic_cast<Accumulator *>(counts_->accumulator[bin])->add(1); |
144 |
< |
} |
144 |
> |
} |
145 |
|
} |
146 |
|
|
147 |
|
|
187 |
|
} |
188 |
|
|
189 |
|
outStream << "#######################################################\n"; |
190 |
< |
outStream << "# Standard Deviations in those quantities follow:\n"; |
190 |
> |
outStream << "# 95% confidence intervals in those quantities follow:\n"; |
191 |
|
outStream << "#######################################################\n"; |
192 |
|
|
193 |
|
for (int j = 0; j < nBins_; j++) { |
200 |
|
|
201 |
|
int n = outputData->accumulator[j]->count(); |
202 |
|
if (n != 0) { |
203 |
< |
writeStdDev( outStream, outputData, j ); |
203 |
> |
writeErrorBars( outStream, outputData, j ); |
204 |
|
} |
205 |
|
} |
206 |
|
outStream << std::endl; |
225 |
|
int n = dat->accumulator[bin]->count(); |
226 |
|
if (n == 0) return; |
227 |
|
|
224 |
– |
RealType r; |
225 |
– |
Vector3d v; |
226 |
– |
|
228 |
|
if( dat->dataType == odtReal ) { |
229 |
+ |
RealType r; |
230 |
|
dynamic_cast<Accumulator*>(dat->accumulator[bin])->getAverage(r); |
231 |
|
if (isinf(r) || isnan(r) ) { |
232 |
|
sprintf( painCave.errMsg, |
233 |
|
"SpatialStatistics detected a numerical error writing:\n" |
234 |
< |
"\t%s for bin %d", |
234 |
> |
"\t%s for bin %u", |
235 |
|
dat->title.c_str(), bin); |
236 |
|
painCave.isFatal = 1; |
237 |
|
simError(); |
240 |
|
os << "\t" << r; |
241 |
|
|
242 |
|
} else if ( dat->dataType == odtVector3 ) { |
243 |
+ |
Vector3d v; |
244 |
|
dynamic_cast<VectorAccumulator*>(dat->accumulator[bin])->getAverage(v); |
245 |
|
if (isinf(v[0]) || isnan(v[0]) || |
246 |
|
isinf(v[1]) || isnan(v[1]) || |
247 |
|
isinf(v[2]) || isnan(v[2]) ) { |
248 |
|
sprintf( painCave.errMsg, |
249 |
|
"SpatialStatistics detected a numerical error writing:\n" |
250 |
< |
"\t%s for bin %d", |
250 |
> |
"\t%s for bin %u", |
251 |
|
dat->title.c_str(), bin); |
252 |
|
painCave.isFatal = 1; |
253 |
|
simError(); |
257 |
|
} |
258 |
|
} |
259 |
|
|
260 |
< |
void SpatialStatistics::writeStdDev(ostream& os, OutputData* dat, |
260 |
> |
void SpatialStatistics::writeErrorBars(ostream& os, OutputData* dat, |
261 |
|
unsigned int bin) { |
262 |
|
assert(int(bin) < nBins_); |
263 |
|
int n = dat->accumulator[bin]->count(); |
264 |
|
if (n == 0) return; |
265 |
|
|
263 |
– |
RealType r; |
264 |
– |
Vector3d v; |
265 |
– |
|
266 |
|
if( dat->dataType == odtReal ) { |
267 |
< |
dynamic_cast<Accumulator*>(dat->accumulator[bin])->getStdDev(r); |
267 |
> |
RealType r; |
268 |
> |
dynamic_cast<Accumulator*>(dat->accumulator[bin])->get95percentConfidenceInterval(r); |
269 |
|
if (isinf(r) || isnan(r) ) { |
270 |
|
sprintf( painCave.errMsg, |
271 |
|
"SpatialStatistics detected a numerical error writing:\n" |
272 |
< |
"\tstandard deviation of %s for bin %d", |
272 |
> |
"\tstandard deviation of %s for bin %u", |
273 |
|
dat->title.c_str(), bin); |
274 |
|
painCave.isFatal = 1; |
275 |
|
simError(); |
278 |
|
os << "\t" << r; |
279 |
|
|
280 |
|
} else if ( dat->dataType == odtVector3 ) { |
281 |
< |
dynamic_cast<VectorAccumulator*>(dat->accumulator[bin])->getStdDev(v); |
281 |
> |
Vector3d v; |
282 |
> |
dynamic_cast<VectorAccumulator*>(dat->accumulator[bin])->get95percentConfidenceInterval(v); |
283 |
|
if (isinf(v[0]) || isnan(v[0]) || |
284 |
|
isinf(v[1]) || isnan(v[1]) || |
285 |
|
isinf(v[2]) || isnan(v[2]) ) { |
286 |
|
sprintf( painCave.errMsg, |
287 |
|
"SpatialStatistics detected a numerical error writing:\n" |
288 |
< |
"\tstandard deviation of %s for bin %d", |
288 |
> |
"\tstandard deviation of %s for bin %u", |
289 |
|
dat->title.c_str(), bin); |
290 |
|
painCave.isFatal = 1; |
291 |
|
simError(); |
323 |
|
} |
324 |
|
|
325 |
|
SlabStatistics::~SlabStatistics() { |
324 |
– |
delete z_; |
326 |
|
} |
327 |
|
|
328 |
|
|
329 |
|
void SlabStatistics::processFrame(int istep) { |
330 |
|
RealType z; |
331 |
+ |
|
332 |
|
hmat_ = currentSnapshot_->getHmat(); |
333 |
|
for (int i = 0; i < nBins_; i++) { |
334 |
|
z = (((RealType)i + 0.5) / (RealType)nBins_) * hmat_(2,2); |
351 |
|
|
352 |
|
ShellStatistics::ShellStatistics(SimInfo* info, const string& filename, |
353 |
|
const string& sele, int nbins) : |
354 |
< |
SpatialStatistics(info, filename, sele, nbins){ |
354 |
> |
SpatialStatistics(info, filename, sele, nbins), coordinateOrigin_(V3Zero) { |
355 |
|
|
354 |
– |
coordinateOrigin_ = V3Zero; |
356 |
|
binWidth_ = 1.0; |
357 |
|
|
358 |
+ |
Globals* simParams = info->getSimParams(); |
359 |
+ |
RNEMDParameters* rnemdParams = simParams->getRNEMDParameters(); |
360 |
+ |
bool hasCoordinateOrigin = rnemdParams->haveCoordinateOrigin(); |
361 |
+ |
|
362 |
+ |
if (hasCoordinateOrigin) { |
363 |
+ |
std::vector<RealType> co = rnemdParams->getCoordinateOrigin(); |
364 |
+ |
if (co.size() != 3) { |
365 |
+ |
sprintf(painCave.errMsg, |
366 |
+ |
"RNEMD: Incorrect number of parameters specified for coordinateOrigin.\n" |
367 |
+ |
"\tthere should be 3 parameters, but %lu were specified.\n", |
368 |
+ |
co.size()); |
369 |
+ |
painCave.isFatal = 1; |
370 |
+ |
simError(); |
371 |
+ |
} |
372 |
+ |
coordinateOrigin_.x() = co[0]; |
373 |
+ |
coordinateOrigin_.y() = co[1]; |
374 |
+ |
coordinateOrigin_.z() = co[2]; |
375 |
+ |
} else { |
376 |
+ |
coordinateOrigin_ = V3Zero; |
377 |
+ |
} |
378 |
+ |
|
379 |
|
r_ = new OutputData; |
380 |
|
r_->units = "Angstroms"; |
381 |
|
r_->title = "R"; |
393 |
|
} |
394 |
|
|
395 |
|
ShellStatistics::~ShellStatistics() { |
374 |
– |
delete r_; |
396 |
|
} |
397 |
|
|
398 |
< |
int ShellStatistics::getBin(Vector3d pos) { |
398 |
> |
int ShellStatistics::getBin(Vector3d pos) { |
399 |
|
Vector3d rPos = pos - coordinateOrigin_; |
400 |
|
return int(rPos.length() / binWidth_); |
401 |
|
} |