ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/trunk/src/applications/staticProps/NanoLength.cpp
Revision: 1796
Committed: Mon Sep 10 18:38:44 2012 UTC (12 years, 7 months ago) by gezelter
File size: 6500 byte(s)
Log Message:
Updating MPI calls to C++, fixing a DumpWriter bug, cleaning cruft

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

Properties

Name Value
svn:eol-style native