OpenMD 3.0
Molecular Dynamics in the Open
Loading...
Searching...
No Matches
OrderParameterProbZ.cpp
1/*
2 * Copyright (c) 2004-present, The University of Notre Dame. All rights
3 * reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright notice,
12 * this list of conditions and the following disclaimer in the documentation
13 * and/or other materials provided with the distribution.
14 *
15 * 3. Neither the name of the copyright holder nor the names of its
16 * contributors may be used to endorse or promote products derived from
17 * this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
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, 234107 (2008).
38 * [4] Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011).
39 * [5] Kuang & Gezelter, Mol. Phys., 110, 691-701 (2012).
40 * [6] Lamichhane, Gezelter & Newman, J. Chem. Phys. 141, 134109 (2014).
41 * [7] Lamichhane, Newman & Gezelter, J. Chem. Phys. 141, 134110 (2014).
42 * [8] Bhattarai, Newman & Gezelter, Phys. Rev. B 99, 094106 (2019).
43 */
44
45/*
46 * Computes the Cos\theta distribution along preferred axis for the selected
47 * atom
48 */
49
50#include "applications/staticProps/OrderParameterProbZ.hpp"
51
52#include <algorithm>
53#include <fstream>
54
55#include "brains/Thermo.hpp"
56#include "io/DumpReader.hpp"
58#include "math/Vector3.hpp"
60#include "types/FixedChargeAdapter.hpp"
61#include "types/FluctuatingChargeAdapter.hpp"
62#include "utils/simError.h"
63
64namespace OpenMD {
65
66 OrderParameterProbZ::OrderParameterProbZ(
67 SimInfo* info, const std::string& filename, const std::string& sele,
68 const RealType dipoleX, const RealType dipoleY, const RealType dipoleZ,
69 int nbins, int axis) :
70 StaticAnalyser(info, filename, nbins),
71 selectionScript_(sele), evaluator_(info), seleMan_(info), thermo_(info),
72 nbins_(nbins), axis_(axis) {
73 evaluator_.loadScriptString(sele);
74 if (!evaluator_.isDynamic()) {
75 seleMan_.setSelectionSet(evaluator_.evaluate());
76 }
77
78 // fixed number of bins
79 Count_.resize(nbins);
80 std::fill(Count_.begin(), Count_.end(), 0);
81
82 switch (axis_) {
83 case 0:
84 axisLabel_ = "x";
85 refAxis_ = Vector3d(1, 0, 0);
86 break;
87 case 1:
88 axisLabel_ = "y";
89 refAxis_ = Vector3d(0, 1, 0);
90 break;
91 case 2:
92 default:
93 axisLabel_ = "z";
94 refAxis_ = Vector3d(0, 0, 1);
95 break;
96 }
97
98 dipoleVector_ = Vector3d(dipoleX, dipoleY, dipoleZ);
99 dipoleVector_.normalize();
100
101 setOutputName(getPrefix(filename) + ".OrderProb");
102 }
103
104 void OrderParameterProbZ::process() {
105 StuntDouble* sd;
106 int ii;
107 RealType orderMin = -1.0;
108 RealType orderMax = 1.0;
109 RealType deltaOrder = (orderMax - orderMin) / nbins_;
110
111 bool usePeriodicBoundaryConditions_ =
112 info_->getSimParams()->getUsePeriodicBoundaryConditions();
113
114 DumpReader reader(info_, dumpFilename_);
115 int nFrames = reader.getNFrames();
116 totalCount_ = 0;
117 for (int istep = 0; istep < nFrames; istep += step_) {
118 reader.readFrame(istep);
119 currentSnapshot_ = info_->getSnapshotManager()->getCurrentSnapshot();
120
121 if (evaluator_.isDynamic()) {
122 seleMan_.setSelectionSet(evaluator_.evaluate());
123 }
124
125 // wrap the stuntdoubles into a cell and find order parameter
126
127 for (sd = seleMan_.beginSelected(ii); sd != NULL;
128 sd = seleMan_.nextSelected(ii)) {
129 Vector3d pos = sd->getPos();
130 if (usePeriodicBoundaryConditions_) currentSnapshot_->wrapVector(pos);
131 sd->setPos(pos);
132 }
133 SquareMatrix3<RealType> rotMat;
134 Vector3d rotatedDipoleVector;
135 RealType ctheta;
136 for (sd = seleMan_.beginSelected(ii); sd != NULL;
137 sd = seleMan_.nextSelected(ii)) {
138 if (sd->isDirectional() || sd->isRigidBody()) {
139 rotMat = sd->getA();
140 rotatedDipoleVector = rotMat * dipoleVector_;
141 rotatedDipoleVector.normalize();
142 ctheta = dot(rotatedDipoleVector, refAxis_);
143 int index = int((ctheta - orderMin) / deltaOrder);
144 Count_[index]++;
145 totalCount_++;
146 }
147 }
148 }
149
150 writeOrderCount();
151 }
152
153 void OrderParameterProbZ::writeOrderCount() {
154 std::ofstream rdfStream(outputFilename_.c_str());
155 if (rdfStream.is_open()) {
156 rdfStream << "#Order count probablity "
157 << "\n";
158 rdfStream << "#selection: (" << selectionScript_ << ")\n";
159 rdfStream << "# Prefered Axis:" << axisLabel_
160 << "\n##Order\tProbOrderCount\n";
161 for (unsigned int i = 0; i < Count_.size(); ++i) {
162 RealType order = i * (2.0 / Count_.size());
163 RealType prop;
164 if (totalCount_ == 0)
165 prop = Count_[i];
166 else
167 prop = Count_[i] / totalCount_;
168 rdfStream << order << "\t" << prop << "\n";
169 }
170
171 } else {
172 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
173 "OrderProb: unable to open %s\n", outputFilename_.c_str());
174 painCave.isFatal = 1;
175 simError();
176 }
177
178 rdfStream.close();
179 }
180} // namespace OpenMD
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...
Definition SimInfo.hpp:93
SnapshotManager * getSnapshotManager()
Returns the snapshot manager.
Definition SimInfo.hpp:248
void wrapVector(Vector3d &v)
Wrapping the vector according to periodic boundary condition.
Definition Snapshot.cpp:337
Snapshot * getCurrentSnapshot()
Returns the pointer of current snapshot.
"Don't move, or you're dead! Stand up! Captain, we've got them!"
RotMat3x3d getA()
Returns the current rotation matrix of this stuntDouble.
Vector3d getPos()
Returns the current position of this stuntDouble.
void setPos(const Vector3d &pos)
Sets the current position of this stuntDouble.
bool isRigidBody()
Tests if this stuntDouble is a rigid body.
bool isDirectional()
Tests if this stuntDouble is a directional one.
void normalize()
Normalizes this vector in place.
Definition Vector.hpp:402
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)