48#include "applications/staticProps/NanoLength.hpp"
52#include "utils/simError.h"
56bool pairComparator(
const evIndex& l,
const evIndex& r) {
57 return l.first < r.first;
60NanoLength::NanoLength(
SimInfo* info,
const std::string& filename,
61 const std::string& sele) :
63 selectionScript_(sele), seleMan_(info), evaluator_(info) {
64 setOutputName(
getPrefix(filename) +
".length");
66 osq.open(getOutputFileName().c_str());
68 evaluator_.loadScriptString(sele);
69 if (!evaluator_.isDynamic()) {
70 seleMan_.setSelectionSet(evaluator_.evaluate());
75void NanoLength::process() {
80 DumpReader reader(info_, dumpFilename_);
81 int nFrames = reader.getNFrames();
84 theAtoms_.reserve(info_->getNGlobalAtoms());
86 for (
int istep = 0; istep < nFrames; istep += step_) {
87 reader.readFrame(istep);
89 currentSnapshot_ = info_->getSnapshotManager()->getCurrentSnapshot();
90 RealType time = currentSnapshot_->getTime();
95 if (evaluator_.isDynamic()) {
96 seleMan_.setSelectionSet(evaluator_.evaluate());
101 for (sd = seleMan_.beginSelected(i); sd != NULL;
102 sd = seleMan_.nextSelected(i)) {
103 theAtoms_.push_back(sd);
106 RealType rodLength = getLength(theAtoms_);
109 if (osq.is_open()) { osq << time <<
"\t" << rodLength << std::endl; }
114RealType NanoLength::getLength(std::vector<StuntDouble*> atoms) {
118 for (std::vector<StuntDouble*>::iterator i = atoms.begin(); i != atoms.end();
120 mtmp = (*i)->getMass();
122 COM += (*i)->getPos() * mtmp;
128 for (std::vector<StuntDouble*>::iterator i = atoms.begin(); i != atoms.end();
131 mtmp = (*i)->getMass();
132 Vector3d delta = (*i)->getPos() - COM;
133 IAtom -= outProduct(delta, delta) * mtmp;
135 IAtom(0, 0) += mtmp * r2;
136 IAtom(1, 1) += mtmp * r2;
137 IAtom(2, 2) += mtmp * r2;
152 std::vector<evIndex> evals_prime;
153 for (
int i = 0; i < 3; i++)
154 evals_prime.push_back(std::make_pair(evals[i], i));
155 std::sort(evals_prime.begin(), evals_prime.end(), pairComparator);
160 for (
int i = 0; i < 3; i++) {
161 int index = evals_prime[2 - i].second;
163 I(i, i) = evals[index];
170 RealType axisLength = longAxis.
length();
171 RealType projmin = 0.0;
172 RealType projmax = 0.0;
174 for (std::vector<StuntDouble*>::iterator i = atoms.begin(); i != atoms.end();
176 Vector3d delta = (*i)->getPos() - COM;
177 RealType projection =
dot(delta, longAxis) / axisLength;
178 if (projection > projmax) projmax = projection;
179 if (projection < projmin) projmin = projection;
182 return projmax - projmin;
void setColumn(unsigned int col, const Vector< Real, Col > &v)
Sets a column of this matrix.
Vector< Real, Col > getColumn(unsigned int col)
Returns a column of this matrix as a vector.
One of the heavy-weight classes of OpenMD, SimInfo maintains objects and variables relating to the cu...
Real length() const
Returns the length of this vector.
Real lengthSquare() const
Returns the squared length of this vector.
This basic Periodic Table class was originally taken from the data.cpp file in OpenBabel.
Real dot(const DynamicVector< Real > &v1, const DynamicVector< Real > &v2)
Returns the dot product of two DynamicVectors.
std::string getPrefix(const std::string &str)