OpenMD 3.2
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 following paper when you publish your work:
33 *
34 * [1] Drisko et al., J. Open Source Softw. 9, 7004 (2024).
35 *
36 * Good starting points for code and simulation methodology are:
37 *
38 * [2] Meineke, et al., J. Comp. Chem. 26, 252-271 (2005).
39 * [3] Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006).
40 * [4] Sun, Lin & Gezelter, J. Chem. Phys. 128, 234107 (2008).
41 * [5] Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011).
42 * [6] Kuang & Gezelter, Mol. Phys., 110, 691-701 (2012).
43 * [7] Lamichhane, Gezelter & Newman, J. Chem. Phys. 141, 134109 (2014).
44 * [8] Bhattarai, Newman & Gezelter, Phys. Rev. B 99, 094106 (2019).
45 * [9] Drisko & Gezelter, J. Chem. Theory Comput. 20, 4986-4997 (2024).
46 */
47
48/*
49 * Computes the Cos\theta distribution along preferred axis for the selected
50 * atom
51 */
52
53#include "applications/staticProps/OrderParameterProbZ.hpp"
54
55#include <algorithm>
56#include <fstream>
57
58#include "brains/Thermo.hpp"
59#include "io/DumpReader.hpp"
61#include "math/Vector3.hpp"
63#include "types/FixedChargeAdapter.hpp"
64#include "types/FluctuatingChargeAdapter.hpp"
65#include "utils/simError.h"
66
67namespace OpenMD {
68
69 OrderParameterProbZ::OrderParameterProbZ(
70 SimInfo* info, const std::string& filename, const std::string& sele,
71 const RealType dipoleX, const RealType dipoleY, const RealType dipoleZ,
72 int nbins, int axis) :
73 StaticAnalyser(info, filename, nbins),
74 selectionScript_(sele), evaluator_(info), seleMan_(info), thermo_(info),
75 nbins_(nbins), axis_(axis) {
76 evaluator_.loadScriptString(sele);
77 if (!evaluator_.isDynamic()) {
78 seleMan_.setSelectionSet(evaluator_.evaluate());
79 }
80
81 // fixed number of bins
82 Count_.resize(nbins);
83 std::fill(Count_.begin(), Count_.end(), 0);
84
85 switch (axis_) {
86 case 0:
87 axisLabel_ = "x";
88 refAxis_ = Vector3d(1, 0, 0);
89 break;
90 case 1:
91 axisLabel_ = "y";
92 refAxis_ = Vector3d(0, 1, 0);
93 break;
94 case 2:
95 default:
96 axisLabel_ = "z";
97 refAxis_ = Vector3d(0, 0, 1);
98 break;
99 }
100
101 dipoleVector_ = Vector3d(dipoleX, dipoleY, dipoleZ);
102 dipoleVector_.normalize();
103
104 setOutputName(getPrefix(filename) + ".OrderProb");
105 }
106
107 void OrderParameterProbZ::process() {
108 StuntDouble* sd;
109 int ii;
110 RealType orderMin = -1.0;
111 RealType orderMax = 1.0;
112 RealType deltaOrder = (orderMax - orderMin) / nbins_;
113
114 bool usePeriodicBoundaryConditions_ =
115 info_->getSimParams()->getUsePeriodicBoundaryConditions();
116
117 DumpReader reader(info_, dumpFilename_);
118 int nFrames = reader.getNFrames();
119 totalCount_ = 0;
120 for (int istep = 0; istep < nFrames; istep += step_) {
121 reader.readFrame(istep);
122 currentSnapshot_ = info_->getSnapshotManager()->getCurrentSnapshot();
123
124 if (evaluator_.isDynamic()) {
125 seleMan_.setSelectionSet(evaluator_.evaluate());
126 }
127
128 // wrap the stuntdoubles into a cell and find order parameter
129
130 for (sd = seleMan_.beginSelected(ii); sd != NULL;
131 sd = seleMan_.nextSelected(ii)) {
132 Vector3d pos = sd->getPos();
133 if (usePeriodicBoundaryConditions_) currentSnapshot_->wrapVector(pos);
134 sd->setPos(pos);
135 }
136 SquareMatrix3<RealType> rotMat;
137 Vector3d rotatedDipoleVector;
138 RealType ctheta;
139 for (sd = seleMan_.beginSelected(ii); sd != NULL;
140 sd = seleMan_.nextSelected(ii)) {
141 if (sd->isDirectional() || sd->isRigidBody()) {
142 rotMat = sd->getA();
143 rotatedDipoleVector = rotMat * dipoleVector_;
144 rotatedDipoleVector.normalize();
145 ctheta = dot(rotatedDipoleVector, refAxis_);
146 int index = int((ctheta - orderMin) / deltaOrder);
147 Count_[index]++;
148 totalCount_++;
149 }
150 }
151 }
152
153 writeOrderCount();
154 }
155
156 void OrderParameterProbZ::writeOrderCount() {
157 std::ofstream rdfStream(outputFilename_.c_str());
158 if (rdfStream.is_open()) {
159 rdfStream << "#Order count probablity "
160 << "\n";
161 rdfStream << "#selection: (" << selectionScript_ << ")\n";
162 rdfStream << "# Prefered Axis:" << axisLabel_
163 << "\n##Order\tProbOrderCount\n";
164 for (unsigned int i = 0; i < Count_.size(); ++i) {
165 RealType order = i * (2.0 / Count_.size());
166 RealType prop;
167 if (totalCount_ == 0)
168 prop = Count_[i];
169 else
170 prop = Count_[i] / totalCount_;
171 rdfStream << order << "\t" << prop << "\n";
172 }
173
174 } else {
175 snprintf(painCave.errMsg, MAX_SIM_ERROR_MSG_LENGTH,
176 "OrderProb: unable to open %s\n", outputFilename_.c_str());
177 painCave.isFatal = 1;
178 simError();
179 }
180
181 rdfStream.close();
182 }
183} // namespace OpenMD
One of the heavy-weight classes of OpenMD, SimInfo maintains objects and variables relating to the cu...
Definition SimInfo.hpp:96
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)