ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/branches/development/src/applications/staticProps/NanoLength.cpp
Revision: 1665
Committed: Tue Nov 22 20:38:56 2011 UTC (13 years, 6 months ago) by gezelter
File size: 6560 byte(s)
Log Message:
updated copyright notices

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, 24107 (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), seleMan_(info) {
58 setOutputName(getPrefix(filename) + ".length");
59
60 osq.open(getOutputFileName().c_str());
61
62 evaluator_.loadScriptString(sele);
63 if (!evaluator_.isDynamic()) {
64 seleMan_.setSelectionSet(evaluator_.evaluate());
65 }
66 frameCounter_ = 0;
67 }
68
69 void NanoLength::process() {
70 Molecule* mol;
71 Atom* atom;
72 RigidBody* rb;
73 int myIndex;
74 SimInfo::MoleculeIterator mi;
75 Molecule::RigidBodyIterator rbIter;
76 Molecule::AtomIterator ai;
77 StuntDouble* sd;
78 Vector3d vec;
79 int i,j;
80
81 DumpReader reader(info_, dumpFilename_);
82 int nFrames = reader.getNFrames();
83 frameCounter_ = 0;
84
85 theAtoms_.reserve(info_->getNGlobalAtoms());
86
87 for (int istep = 0; istep < nFrames; istep += step_) {
88 reader.readFrame(istep);
89 frameCounter_++;
90 currentSnapshot_ = info_->getSnapshotManager()->getCurrentSnapshot();
91 RealType time = currentSnapshot_->getTime();
92
93 // Clear pos vector between each frame.
94 theAtoms_.clear();
95
96 if (evaluator_.isDynamic()) {
97 seleMan_.setSelectionSet(evaluator_.evaluate());
98 }
99
100 // update the positions of atoms which belong to the rigidbodies
101
102 for (mol = info_->beginMolecule(mi); mol != NULL;
103 mol = info_->nextMolecule(mi)) {
104 for (rb = mol->beginRigidBody(rbIter); rb != NULL;
105 rb = mol->nextRigidBody(rbIter)) {
106 rb->updateAtoms();
107 }
108 }
109
110 // outer loop is over the selected StuntDoubles:
111
112 for (sd = seleMan_.beginSelected(i); sd != NULL;
113 sd = seleMan_.nextSelected(i)) {
114 theAtoms_.push_back(sd);
115 }
116
117 RealType rodLength = getLength(theAtoms_);
118
119 osq.precision(7);
120 if (osq.is_open()){
121 osq << time << "\t" << rodLength << std::endl;
122 }
123 }
124 }
125
126 RealType NanoLength::getLength(std::vector<StuntDouble*> atoms) {
127 Vector3d COM(0.0);
128 RealType mass = 0.0;
129 RealType mtmp;
130 for (std::vector<StuntDouble*>::iterator i = atoms.begin();
131 i != atoms.end(); ++i) {
132 mtmp = (*i)->getMass();
133 mass += mtmp;
134 COM += (*i)->getPos() * mtmp;
135 }
136 COM /= mass;
137
138 // Moment of Inertia calculation
139 Mat3x3d Itmp(0.0);
140 for (std::vector<StuntDouble*>::iterator i = atoms.begin();
141 i != atoms.end(); ++i) {
142
143 Mat3x3d IAtom(0.0);
144 mtmp = (*i)->getMass();
145 Vector3d delta = (*i)->getPos() - COM;
146 IAtom -= outProduct(delta, delta) * mtmp;
147 RealType r2 = delta.lengthSquare();
148 IAtom(0, 0) += mtmp * r2;
149 IAtom(1, 1) += mtmp * r2;
150 IAtom(2, 2) += mtmp * r2;
151 Itmp += IAtom;
152 }
153
154 //diagonalize
155 Vector3d evals;
156 Mat3x3d evects;
157 Mat3x3d::diagonalize(Itmp, evals, evects);
158
159 // we need to re-order the axes so that the smallest moment of
160 // inertia (which corresponds to the long axis of the rod) is
161 // along the z-axis. We'll just reverse the order of the three
162 // axes. Python has an argsort function, but we had to invent our
163 // own:
164
165 std::vector<evIndex> evals_prime;
166 for (int i = 0; i < 3; i++)
167 evals_prime.push_back(std::make_pair(evals[i], i));
168 std::sort(evals_prime.begin(), evals_prime.end(), pairComparator);
169
170 RotMat3x3d A;
171 Mat3x3d I;
172
173 for (int i = 0; i < 3; i++) {
174 int index = evals_prime[2-i].second;
175 A.setColumn(i, evects.getColumn(index));
176 I(i,i) = evals[index];
177 }
178
179 // now project the delta from the center of mass onto the long
180 // axis of the object
181
182 Vector3d longAxis = A.getColumn(2);
183 RealType axisLength = longAxis.length();
184 RealType projmin = 0.0;
185 RealType projmax = 0.0;
186
187 for (std::vector<StuntDouble*>::iterator i = atoms.begin();
188 i != atoms.end(); ++i) {
189 Vector3d delta = (*i)->getPos() - COM;
190 RealType projection = dot(delta, longAxis) / axisLength;
191 if (projection > projmax) projmax = projection;
192 if (projection < projmin) projmin = projection;
193 }
194
195 return projmax - projmin;
196 }
197
198

Properties

Name Value
svn:eol-style native