votca 2024.2-dev
Loading...
Searching...
No Matches
sphericalorder.cc
Go to the documentation of this file.
1/*
2 * Copyright 2009-2021 The VOTCA Development Team (http://www.votca.org)
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 */
17
18// Standard includes
19#include <cmath>
20#include <cstdlib>
21#include <fstream>
22#include <iostream>
23
24// Third party includes
25#include <boost/program_options.hpp>
26#include <boost/tokenizer.hpp>
27
28// VOTCA includes
29#include <votca/tools/average.h>
31
32// Local VOTCA includes
33#include <votca/csg/cgengine.h>
35
36using namespace std;
37using namespace votca::csg;
38
40 public:
41 string ProgramName() override { return "sphericalorder"; }
42
43 void HelpText(ostream &out) override {
44
45 out << "!! EXPERIMENTAL !! Calculate spherical order parameter.\n"
46 " Needs non-spherical beads in mapping.\n\n";
47 }
48
49 void Initialize() override {
52 "filter",
53 boost::program_options::value<string>(&filter_)->default_value("*"),
54 "filter molecule names")(
55 "radialcut",
56 boost::program_options::value<double>(&radialcutoff_)
57 ->default_value(0.0),
58 "radial cutoff: distance from center where bead is considered")(
59 "minrad",
60 boost::program_options::value<double>(&minrad_)->default_value(0.0),
61 "minimal distance a parcle has to be apart from center to be "
62 "considerd")(
63 "refmol",
64 boost::program_options::value<string>(&refmol_)->default_value(""),
65 "Reference molecule")(
66 "rbinw",
67 boost::program_options::value<double>(&rbinw_)->default_value(0),
68 "Do multiple r_bins multiple histograms");
69 }
70
71 bool EvaluateOptions() override {
73 // CheckRequired("radialcut");
74 return true;
75 }
76
77 bool DoTrajectory() override { return true; }
78 bool DoMapping() override { return true; }
79
80 void BeginEvaluate(Topology *top, Topology *) override {
81
82 string filter;
83
84 filter = OptionsMap()["filter"].as<string>();
85
86 minrad_ = 0;
87
88 radialcutoff_ = OptionsMap()["radialcut"].as<double>();
89 minrad_ = OptionsMap()["minrad"].as<double>();
90 refmol_ = OptionsMap()["refmol"].as<string>();
91 rbinw_ = OptionsMap()["rbinw"].as<double>();
92
93 if (rbinw_ == 0 && radialcutoff_ <= 0) {
94 throw runtime_error(" radialcut_ > 0 has to be specified");
95 }
96
97 setFilter(filter);
98
99 file_u_.open("hist_u.xvg");
100 if (!file_u_) {
101 throw runtime_error("cannot open hist_u.xvg for output");
102 }
103 file_v_.open("hist_v.xvg");
104 if (!file_v_) {
105 throw runtime_error("cannot open hist_v.xvg for output");
106 }
107 file_w_.open("hist_w.xvg");
108 if (!file_w_) {
109 throw runtime_error("cannot open hist_w.xvg for output");
110 }
111
112 n_ = 0;
113
114 Eigen::Matrix3d box = top->getBox();
115 Eigen::Vector3d a = box.col(0);
116
117 if (refmol_ == "") {
118
119 ref_ = box.rowwise().sum() / 2;
120
121 cout << "Refernce is center of box " << ref_ << endl;
122 }
123
124 boxl = a.norm() / 2;
125 if (rbinw_ > 0) {
126 rbins_ = (votca::Index)(boxl / rbinw_) + 1;
127 cout << "radial bins " << rbins_ << endl;
128 } else {
129 rbins_ = 1;
130 cout << "considering atoms between " << minrad_ << " and "
131 << radialcutoff_ << endl;
132 }
133
134 nbin_ = 100;
135 hist_u_ = Eigen::MatrixXd::Zero(rbins_, nbin_);
136 hist_v_ = Eigen::MatrixXd::Zero(rbins_, nbin_);
137 hist_w_ = Eigen::MatrixXd::Zero(rbins_, nbin_);
138 nmol_ = Eigen::VectorXi::Zero(rbins_);
139 }
140
141 void EndEvaluate() override {
142
143 cout << "Average number of molecules within cutoff " << endl;
144 for (votca::Index i = 0; i < rbins_; i++) {
145 cout << (double)i * rbinw_ << " " << (double)nmol_[i] / (double)n_
146 << endl;
147 }
148
149 double exp_value = 1.0 / (double)nbin_;
150 double orderparam = 0;
151
152 for (votca::Index n = 0; n < nbin_; n++) {
153 hist_u_(0, n) /= (double)nmol_[0]; // normalize to numberframes and avg.
154 // number of molecules
155 hist_v_(0, n) /= (double)nmol_[0];
156 hist_w_(0, n) /= (double)nmol_[0];
157
158 file_u_ << (double)n * 2 / double(nbin_ - 1) << " " << hist_u_(0, n)
159 << endl;
160 file_v_ << (double)n * 2 / double(nbin_ - 1) << " " << hist_v_(0, n)
161 << endl;
162 file_w_ << (double)n * 2 / double(nbin_ - 1) << " " << hist_w_(0, n)
163 << endl;
164
165 orderparam += (hist_u_(0, n) - exp_value) * (hist_u_(0, n) - exp_value);
166 }
167
168 orderparam = sqrt(orderparam / (double)nbin_);
169
170 cout << "Orderparam " << radialcutoff_ << " " << orderparam << endl;
171
172 file_u_.close();
173 file_v_.close();
174 file_w_.close();
175 };
176
177 void EvalConfiguration(Topology *conf, Topology * = nullptr) override {
178
179 Eigen::Vector3d eR;
180 votca::Index nu, nv, nw;
181 Eigen::Vector3d u, v, w;
182
183 if (refmol_ != "") {
184 for (const auto &bead : conf->Beads()) {
185 if (votca::tools::wildcmp(refmol_, bead.getName())) {
186 ref_ = bead.getPos();
187 }
188 }
189 }
190
191 for (const auto &bead : conf->Beads()) {
192 if (!votca::tools::wildcmp(filter_, bead.getName())) {
193 continue;
194 }
195 if (votca::tools::wildcmp(refmol_, bead.getName())) {
196 continue;
197 }
198
199 eR = bead.getPos() - ref_;
200 if ((eR.norm() < radialcutoff_ && eR.norm() > minrad_) || rbins_ != 1) {
201 // cout << eR << endl;
202 votca::Index rb = 0;
203 if (rbinw_ > 0) {
204 rb = (votca::Index)((eR.norm()) / boxl * (double)rbins_);
205 }
206 if (rb >= rbins_) {
207 continue;
208 }
209
210 eR.normalize();
211 u = bead.getU();
212 v = bead.getV();
213 w = bead.getW();
214 u.normalize();
215 v.normalize();
216 w.normalize();
217
218 nu = (votca::Index)((eR.dot(u) + 1) / 2) * nbin_;
219 nv = (votca::Index)((eR.dot(v) + 1) / 2) * nbin_;
220 nw = (votca::Index)((eR.dot(w) + 1) / 2) * nbin_;
221
222 hist_u_(rb, nu) += 1;
223 hist_v_(rb, nv) += 1;
224 hist_w_(rb, nw) += 1;
225 nmol_[rb]++;
226 }
227 }
228
229 n_++;
230 }
231
232 void setOut(const string &filename) { filename_ = filename; }
233
234 void setFilter(const string &filter) { filter_ = filter; }
235
236 protected:
237 ofstream file_;
238 string filename_;
240 Eigen::Vector3d ref_;
241 ofstream file_u_;
242 ofstream file_v_;
243 ofstream file_w_;
244 Eigen::MatrixXd hist_u_;
245 Eigen::MatrixXd hist_v_;
246 Eigen::MatrixXd hist_w_;
248 Eigen::VectorXi nmol_;
250 double minrad_;
252 double rbinw_;
253 double boxl;
254
255 string filter_;
256 string refmol_;
257};
258
259int main(int argc, char **argv) {
260 CGOrderParam app;
261 return app.Exec(argc, argv);
262}
string ProgramName() override
program name
Eigen::MatrixXd hist_v_
bool EvaluateOptions() override
Process command line options.
bool DoMapping() override
overload and return true to enable mapping command line options
Eigen::MatrixXd hist_w_
votca::Index n_
void EndEvaluate() override
called after the last frame
Eigen::Vector3d ref_
bool DoTrajectory() override
overload and return true to enable trajectory command line options
void Initialize() override
Initialize application data.
void setOut(const string &filename)
votca::Index rbins_
void BeginEvaluate(Topology *top, Topology *) override
called before the first frame
Eigen::VectorXi nmol_
void EvalConfiguration(Topology *conf, Topology *=nullptr) override
void HelpText(ostream &out) override
help text of application without version information
votca::Index nbin_
Eigen::MatrixXd hist_u_
void setFilter(const string &filter)
bool EvaluateOptions() override
Process command line options.
void Initialize() override
Initialize application data.
topology of the whole system
Definition topology.h:81
BeadContainer & Beads()
Definition topology.h:169
const Eigen::Matrix3d & getBox() const
Definition topology.h:298
int Exec(int argc, char **argv)
executes the program
boost::program_options::variables_map & OptionsMap()
get available program options & descriptions
boost::program_options::options_description_easy_init AddProgramOptions(const std::string &group="")
add option for command line
STL namespace.
int wildcmp(const char *wild, const char *string)
Definition tokenizer.cc:28
Eigen::Index Index
Definition types.h:26
int main(int argc, char **argv)