1 |
tim |
545 |
/* |
2 |
|
|
* Copyright (c) 2005 The University of Notre Dame. All Rights Reserved. |
3 |
|
|
* |
4 |
|
|
* The University of Notre Dame grants you ("Licensee") a |
5 |
|
|
* non-exclusive, royalty free, license to use, modify and |
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 |
19 |
|
|
* notice, this list of conditions and the following disclaimer. |
20 |
|
|
* |
21 |
|
|
* 3. Redistributions in binary form must reproduce the above copyright |
22 |
|
|
* notice, this list of conditions and the following disclaimer in the |
23 |
|
|
* documentation and/or other materials provided with the |
24 |
|
|
* distribution. |
25 |
|
|
* |
26 |
|
|
* This software is provided "AS IS," without a warranty of any |
27 |
|
|
* kind. All express or implied conditions, representations and |
28 |
|
|
* warranties, including any implied warranty of merchantability, |
29 |
|
|
* fitness for a particular purpose or non-infringement, are hereby |
30 |
|
|
* excluded. The University of Notre Dame and its licensors shall not |
31 |
|
|
* be liable for any damages suffered by licensee as a result of |
32 |
|
|
* using, modifying or distributing the software or its |
33 |
|
|
* derivatives. In no event will the University of Notre Dame or its |
34 |
|
|
* licensors be liable for any lost revenue, profit or data, or for |
35 |
|
|
* direct, indirect, special, consequential, incidental or punitive |
36 |
|
|
* damages, however caused and regardless of the theory of liability, |
37 |
|
|
* arising out of the use of or inability to use software, even if the |
38 |
|
|
* University of Notre Dame has been advised of the possibility of |
39 |
|
|
* such damages. |
40 |
|
|
*/ |
41 |
|
|
|
42 |
|
|
#include <algorithm> |
43 |
|
|
#include "applications/staticProps/DensityPlot.hpp" |
44 |
|
|
#include "utils/simError.h" |
45 |
|
|
#include "io/DumpReader.hpp" |
46 |
|
|
#include "primitives/Molecule.hpp" |
47 |
|
|
#include "utils/NumericConstant.hpp" |
48 |
|
|
namespace oopse { |
49 |
|
|
|
50 |
|
|
|
51 |
|
|
DensityPlot::DensityPlot(SimInfo* info, const std::string& filename, const std::string& sele, double len, int nrbins) |
52 |
|
|
: StaticAnalyser(info, filename), selectionScript_(sele), evaluator_(info), seleMan_(info), |
53 |
|
|
len_(len), nRBins_(nrbins), halfLen_(len/2) { |
54 |
|
|
|
55 |
|
|
setOutputName(getPrefix(filename) + ".density"); |
56 |
|
|
|
57 |
|
|
deltaR_ = len_ /nRBins_; |
58 |
|
|
histogram_.resize(nRBins_); |
59 |
|
|
density_.resize(nRBins_); |
60 |
|
|
|
61 |
|
|
std::fill(histogram_.begin(), histogram_.end(), 0); |
62 |
|
|
|
63 |
|
|
evaluator_.loadScriptString(sele); |
64 |
|
|
|
65 |
|
|
if (!evaluator_.isDynamic()) { |
66 |
|
|
seleMan_.setSelectionSet(evaluator_.evaluate()); |
67 |
|
|
} |
68 |
|
|
|
69 |
|
|
} |
70 |
|
|
|
71 |
|
|
void DensityPlot::process() { |
72 |
|
|
Molecule* mol; |
73 |
|
|
RigidBody* rb; |
74 |
|
|
SimInfo::MoleculeIterator mi; |
75 |
|
|
Molecule::RigidBodyIterator rbIter; |
76 |
|
|
|
77 |
|
|
DumpReader reader(info_, dumpFilename_); |
78 |
|
|
int nFrames = reader.getNFrames(); |
79 |
|
|
|
80 |
|
|
for (int i = 0; i < nFrames; i += step_) { |
81 |
|
|
reader.readFrame(i); |
82 |
|
|
currentSnapshot_ = info_->getSnapshotManager()->getCurrentSnapshot(); |
83 |
|
|
|
84 |
|
|
for (mol = info_->beginMolecule(mi); mol != NULL; mol = info_->nextMolecule(mi)) { |
85 |
|
|
//change the positions of atoms which belong to the rigidbodies |
86 |
|
|
for (rb = mol->beginRigidBody(rbIter); rb != NULL; rb = mol->nextRigidBody(rbIter)) { |
87 |
|
|
rb->updateAtoms(); |
88 |
|
|
} |
89 |
|
|
|
90 |
|
|
} |
91 |
|
|
|
92 |
|
|
Vector3d cm = info_->getCom(); |
93 |
|
|
|
94 |
|
|
if (evaluator_.isDynamic()) { |
95 |
|
|
seleMan_.setSelectionSet(evaluator_.evaluate()); |
96 |
|
|
} |
97 |
|
|
|
98 |
|
|
int i; |
99 |
|
|
for (StuntDouble* sd = seleMan_.beginSelected(i); sd != NULL; sd = seleMan_.nextSelected(i)) { |
100 |
|
|
Vector3d pos = sd->getPos() - cm; |
101 |
|
|
currentSnapshot_->wrapVector(pos); |
102 |
|
|
|
103 |
|
|
int which = (pos.z() + halfLen_) / deltaR_; |
104 |
|
|
if (which < nRBins_ && which >=0 ) { |
105 |
|
|
++histogram_[which]; |
106 |
|
|
} |
107 |
|
|
} |
108 |
|
|
|
109 |
|
|
} |
110 |
|
|
|
111 |
|
|
//std::vector<int>::iterator it = std::max_element(histogram_.begin(), histogram_.end()); |
112 |
|
|
//int maxnum = *it; |
113 |
|
|
|
114 |
|
|
int nProcessed = nFrames / step_; |
115 |
|
|
int ntot = info_->getNGlobalAtoms(); |
116 |
|
|
int maxnum = ntot * nProcessed; |
117 |
|
|
std::transform(histogram_.begin(), histogram_.end(), density_.begin(), std::bind2nd(std::divides<double>(), maxnum)); |
118 |
|
|
writeDensity(); |
119 |
|
|
|
120 |
|
|
} |
121 |
|
|
|
122 |
|
|
void DensityPlot::writeDensity() { |
123 |
|
|
std::ofstream ofs(outputFilename_.c_str(), std::ios::binary); |
124 |
|
|
if (ofs.is_open()) { |
125 |
|
|
ofs << "#g(x, y, z)\n"; |
126 |
|
|
ofs << "#selection: (" << selectionScript_ << ")\t"; |
127 |
|
|
ofs << "#nRBins = " << nRBins_ << "\t maxLen = " << len_ << "deltaR = " << deltaR_ <<"\n"; |
128 |
|
|
for (int i = 0; i < histogram_.size(); ++i) { |
129 |
|
|
ofs << i*deltaR_ - halfLen_ <<"\t" << density_[i]<< std::endl; |
130 |
|
|
} |
131 |
|
|
} else { |
132 |
|
|
|
133 |
|
|
sprintf(painCave.errMsg, "DensityPlot: unable to open %s\n", outputFilename_.c_str()); |
134 |
|
|
painCave.isFatal = 1; |
135 |
|
|
simError(); |
136 |
|
|
} |
137 |
|
|
|
138 |
|
|
ofs.close(); |
139 |
|
|
|
140 |
|
|
|
141 |
|
|
} |
142 |
|
|
|
143 |
|
|
} |
144 |
|
|
|
145 |
|
|
|