ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/trunk/src/applications/staticProps/NanoLength.cpp
Revision: 1942
Committed: Tue Nov 5 18:33:42 2013 UTC (11 years, 5 months ago) by gezelter
File size: 6521 byte(s)
Log Message:
Fixed some warning messages and NanoVolume issues.

File Contents

# Content
1 /* Copyright (c) 2006, 2009, 2010 The University of Notre Dame. All Rights Reserved.
2 *
3 * The University of Notre Dame grants you ("Licensee") a
4 * non-exclusive, royalty free, license to use, modify and
5 * redistribute this software in source and binary code form, provided
6 * that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the
14 * distribution.
15 *
16 * This software is provided "AS IS," without a warranty of any
17 * kind. All express or implied conditions, representations and
18 * warranties, including any implied warranty of merchantability,
19 * fitness for a particular purpose or non-infringement, are hereby
20 * excluded. The University of Notre Dame and its licensors shall not
21 * be liable for any damages suffered by licensee as a result of
22 * using, modifying or distributing the software or its
23 * derivatives. In no event will the University of Notre Dame or its
24 * licensors be liable for any lost revenue, profit or data, or for
25 * direct, indirect, special, consequential, incidental or punitive
26 * damages, however caused and regardless of the theory of liability,
27 * arising out of the use of or inability to use software, even if the
28 * University of Notre Dame has been advised of the possibility of
29 * such damages.
30 *
31 * SUPPORT OPEN SCIENCE! If you use OpenMD or its source code in your
32 * research, please cite the appropriate papers when you publish your
33 * work. Good starting points are:
34 *
35 * [1] Meineke, et al., J. Comp. Chem. 26, 252-271 (2005).
36 * [2] Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006).
37 * [3] Sun, Lin & Gezelter, J. Chem. Phys. 128, 234107 (2008).
38 * [4] Kuang & Gezelter, J. Chem. Phys. 133, 164101 (2010).
39 * [5] Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011).
40 */
41
42 #include "applications/staticProps/NanoLength.hpp"
43 #include "utils/simError.h"
44 #include "io/DumpReader.hpp"
45 #include "primitives/Molecule.hpp"
46 #include "utils/NumericConstant.hpp"
47
48 using namespace OpenMD;
49
50 bool pairComparator( const evIndex& l, const evIndex& r) {
51 return l.first < r.first;
52 }
53
54 NanoLength::NanoLength(SimInfo* info,
55 const std::string& filename,
56 const std::string& sele)
57 : StaticAnalyser(info, filename), selectionScript_(sele), evaluator_(info),
58 seleMan_(info) {
59 setOutputName(getPrefix(filename) + ".length");
60
61 osq.open(getOutputFileName().c_str());
62
63 evaluator_.loadScriptString(sele);
64 if (!evaluator_.isDynamic()) {
65 seleMan_.setSelectionSet(evaluator_.evaluate());
66 }
67 frameCounter_ = 0;
68 }
69
70 void NanoLength::process() {
71 Molecule* mol;
72 RigidBody* rb;
73 SimInfo::MoleculeIterator mi;
74 Molecule::RigidBodyIterator rbIter;
75 StuntDouble* sd;
76 Vector3d vec;
77 int i;
78
79 DumpReader reader(info_, dumpFilename_);
80 int nFrames = reader.getNFrames();
81 frameCounter_ = 0;
82
83 theAtoms_.reserve(info_->getNGlobalAtoms());
84
85 for (int istep = 0; istep < nFrames; istep += step_) {
86 reader.readFrame(istep);
87 frameCounter_++;
88 currentSnapshot_ = info_->getSnapshotManager()->getCurrentSnapshot();
89 RealType time = currentSnapshot_->getTime();
90
91 // Clear pos vector between each frame.
92 theAtoms_.clear();
93
94 if (evaluator_.isDynamic()) {
95 seleMan_.setSelectionSet(evaluator_.evaluate());
96 }
97
98 // update the positions of atoms which belong to the rigidbodies
99
100 for (mol = info_->beginMolecule(mi); mol != NULL;
101 mol = info_->nextMolecule(mi)) {
102 for (rb = mol->beginRigidBody(rbIter); rb != NULL;
103 rb = mol->nextRigidBody(rbIter)) {
104 rb->updateAtoms();
105 }
106 }
107
108 // outer loop is over the selected StuntDoubles:
109
110 for (sd = seleMan_.beginSelected(i); sd != NULL;
111 sd = seleMan_.nextSelected(i)) {
112 theAtoms_.push_back(sd);
113 }
114
115 RealType rodLength = getLength(theAtoms_);
116
117 osq.precision(7);
118 if (osq.is_open()){
119 osq << time << "\t" << rodLength << std::endl;
120 }
121 }
122 osq.close();
123 }
124
125 RealType NanoLength::getLength(std::vector<StuntDouble*> atoms) {
126 Vector3d COM(0.0);
127 RealType mass = 0.0;
128 RealType mtmp;
129 for (std::vector<StuntDouble*>::iterator i = atoms.begin();
130 i != atoms.end(); ++i) {
131 mtmp = (*i)->getMass();
132 mass += mtmp;
133 COM += (*i)->getPos() * mtmp;
134 }
135 COM /= mass;
136
137 // Moment of Inertia calculation
138 Mat3x3d Itmp(0.0);
139 for (std::vector<StuntDouble*>::iterator i = atoms.begin();
140 i != atoms.end(); ++i) {
141
142 Mat3x3d IAtom(0.0);
143 mtmp = (*i)->getMass();
144 Vector3d delta = (*i)->getPos() - COM;
145 IAtom -= outProduct(delta, delta) * mtmp;
146 RealType r2 = delta.lengthSquare();
147 IAtom(0, 0) += mtmp * r2;
148 IAtom(1, 1) += mtmp * r2;
149 IAtom(2, 2) += mtmp * r2;
150 Itmp += IAtom;
151 }
152
153 //diagonalize
154 Vector3d evals;
155 Mat3x3d evects;
156 Mat3x3d::diagonalize(Itmp, evals, evects);
157
158 // we need to re-order the axes so that the smallest moment of
159 // inertia (which corresponds to the long axis of the rod) is
160 // along the z-axis. We'll just reverse the order of the three
161 // axes. Python has an argsort function, but we had to invent our
162 // own:
163
164 std::vector<evIndex> evals_prime;
165 for (int i = 0; i < 3; i++)
166 evals_prime.push_back(std::make_pair(evals[i], i));
167 std::sort(evals_prime.begin(), evals_prime.end(), pairComparator);
168
169 RotMat3x3d A;
170 Mat3x3d I;
171
172 for (int i = 0; i < 3; i++) {
173 int index = evals_prime[2-i].second;
174 A.setColumn(i, evects.getColumn(index));
175 I(i,i) = evals[index];
176 }
177
178 // now project the delta from the center of mass onto the long
179 // axis of the object
180
181 Vector3d longAxis = A.getColumn(2);
182 RealType axisLength = longAxis.length();
183 RealType projmin = 0.0;
184 RealType projmax = 0.0;
185
186 for (std::vector<StuntDouble*>::iterator i = atoms.begin();
187 i != atoms.end(); ++i) {
188 Vector3d delta = (*i)->getPos() - COM;
189 RealType projection = dot(delta, longAxis) / axisLength;
190 if (projection > projmax) projmax = projection;
191 if (projection < projmin) projmin = projection;
192 }
193
194 return projmax - projmin;
195 }
196
197

Properties

Name Value
svn:eol-style native