45#include "applications/staticProps/NanoLength.hpp"
49#include "utils/simError.h"
53bool pairComparator(
const evIndex& l,
const evIndex& r) {
54 return l.first < r.first;
57NanoLength::NanoLength(
SimInfo* info,
const std::string& filename,
58 const std::string& sele) :
60 selectionScript_(sele), seleMan_(info), evaluator_(info) {
61 setOutputName(
getPrefix(filename) +
".length");
63 osq.open(getOutputFileName().c_str());
65 evaluator_.loadScriptString(sele);
66 if (!evaluator_.isDynamic()) {
67 seleMan_.setSelectionSet(evaluator_.evaluate());
72void NanoLength::process() {
78 int nFrames = reader.getNFrames();
83 for (
int istep = 0; istep < nFrames; istep += step_) {
84 reader.readFrame(istep);
87 RealType time = currentSnapshot_->getTime();
93 seleMan_.setSelectionSet(evaluator_.evaluate());
100 theAtoms_.push_back(sd);
103 RealType rodLength = getLength(theAtoms_);
106 if (osq.is_open()) { osq << time <<
"\t" << rodLength << std::endl; }
111RealType NanoLength::getLength(std::vector<StuntDouble*> atoms) {
115 for (std::vector<StuntDouble*>::iterator i = atoms.begin(); i != atoms.end();
117 mtmp = (*i)->getMass();
119 COM += (*i)->getPos() * mtmp;
125 for (std::vector<StuntDouble*>::iterator i = atoms.begin(); i != atoms.end();
128 mtmp = (*i)->getMass();
129 Vector3d delta = (*i)->getPos() - COM;
130 IAtom -= outProduct(delta, delta) * mtmp;
132 IAtom(0, 0) += mtmp * r2;
133 IAtom(1, 1) += mtmp * r2;
134 IAtom(2, 2) += mtmp * r2;
149 std::vector<evIndex> evals_prime;
150 for (
int i = 0; i < 3; i++)
151 evals_prime.push_back(std::make_pair(evals[i], i));
152 std::sort(evals_prime.begin(), evals_prime.end(), pairComparator);
157 for (
int i = 0; i < 3; i++) {
158 int index = evals_prime[2 - i].second;
160 I(i, i) = evals[index];
167 RealType axisLength = longAxis.
length();
168 RealType projmin = 0.0;
169 RealType projmax = 0.0;
171 for (std::vector<StuntDouble*>::iterator i = atoms.begin(); i != atoms.end();
173 Vector3d delta = (*i)->getPos() - COM;
174 RealType projection =
dot(delta, longAxis) / axisLength;
175 if (projection > projmax) projmax = projection;
176 if (projection < projmin) projmin = projection;
179 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.
bool isDynamic()
Tests if the result from evaluation of script is dynamic.
StuntDouble * nextSelected(int &i)
Finds the next selected StuntDouble in the selection.
StuntDouble * beginSelected(int &i)
Finds the first selected StuntDouble in the selection.
One of the heavy-weight classes of OpenMD, SimInfo maintains objects and variables relating to the cu...
int getNGlobalAtoms()
Returns the total number of atoms in the system.
SnapshotManager * getSnapshotManager()
Returns the snapshot manager.
Snapshot * getCurrentSnapshot()
Returns the pointer of current snapshot.
"Don't move, or you're dead! Stand up! Captain, we've got them!"
Real length()
Returns the length of this vector.
Real lengthSquare()
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)