ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/trunk/src/applications/staticProps/NanoLength.cpp
Revision: 1782
Committed: Wed Aug 22 02:28:28 2012 UTC (12 years, 8 months ago) by gezelter
File size: 6529 byte(s)
Log Message:
MERGE OpenMD development branch 1465:1781 into trunk

File Contents

# User Rev Content
1 gezelter 1585 /* 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 gezelter 1782 * [4] Kuang & Gezelter, J. Chem. Phys. 133, 164101 (2010).
39     * [5] Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011).
40 gezelter 1585 */
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     RigidBody* rb;
72     SimInfo::MoleculeIterator mi;
73     Molecule::RigidBodyIterator rbIter;
74     Molecule::AtomIterator ai;
75     StuntDouble* sd;
76     Vector3d vec;
77 gezelter 1782 int i;
78 gezelter 1585
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     }
123    
124     RealType NanoLength::getLength(std::vector<StuntDouble*> atoms) {
125     Vector3d COM(0.0);
126     RealType mass = 0.0;
127     RealType mtmp;
128     for (std::vector<StuntDouble*>::iterator i = atoms.begin();
129     i != atoms.end(); ++i) {
130     mtmp = (*i)->getMass();
131     mass += mtmp;
132     COM += (*i)->getPos() * mtmp;
133     }
134     COM /= mass;
135    
136     // Moment of Inertia calculation
137     Mat3x3d Itmp(0.0);
138     for (std::vector<StuntDouble*>::iterator i = atoms.begin();
139     i != atoms.end(); ++i) {
140    
141     Mat3x3d IAtom(0.0);
142     mtmp = (*i)->getMass();
143     Vector3d delta = (*i)->getPos() - COM;
144     IAtom -= outProduct(delta, delta) * mtmp;
145     RealType r2 = delta.lengthSquare();
146     IAtom(0, 0) += mtmp * r2;
147     IAtom(1, 1) += mtmp * r2;
148     IAtom(2, 2) += mtmp * r2;
149     Itmp += IAtom;
150     }
151    
152     //diagonalize
153     Vector3d evals;
154     Mat3x3d evects;
155     Mat3x3d::diagonalize(Itmp, evals, evects);
156    
157     // we need to re-order the axes so that the smallest moment of
158     // inertia (which corresponds to the long axis of the rod) is
159     // along the z-axis. We'll just reverse the order of the three
160     // axes. Python has an argsort function, but we had to invent our
161     // own:
162    
163     std::vector<evIndex> evals_prime;
164     for (int i = 0; i < 3; i++)
165     evals_prime.push_back(std::make_pair(evals[i], i));
166     std::sort(evals_prime.begin(), evals_prime.end(), pairComparator);
167    
168     RotMat3x3d A;
169     Mat3x3d I;
170    
171     for (int i = 0; i < 3; i++) {
172     int index = evals_prime[2-i].second;
173     A.setColumn(i, evects.getColumn(index));
174     I(i,i) = evals[index];
175     }
176    
177     // now project the delta from the center of mass onto the long
178     // axis of the object
179    
180     Vector3d longAxis = A.getColumn(2);
181     RealType axisLength = longAxis.length();
182     RealType projmin = 0.0;
183     RealType projmax = 0.0;
184    
185     for (std::vector<StuntDouble*>::iterator i = atoms.begin();
186     i != atoms.end(); ++i) {
187     Vector3d delta = (*i)->getPos() - COM;
188     RealType projection = dot(delta, longAxis) / axisLength;
189     if (projection > projmax) projmax = projection;
190     if (projection < projmin) projmin = projection;
191     }
192    
193     return projmax - projmin;
194     }
195    
196    

Properties

Name Value
svn:eol-style native