votca 2024.2-dev
Loading...
Searching...
No Matches
radii.cc
Go to the documentation of this file.
1/*
2 * Copyright 2009 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 <cstdlib>
20
21// VOTCA includes
22#include <votca/tools/average.h>
24
25// Local VOTCA includes
27
28using namespace std;
29using namespace votca::csg;
30
32 string ProgramName() override { return "radii"; }
33 void HelpText(ostream &out) override {
34 out << "calculate gyration- and hydrodynamic radius for a specific "
35 "molecule or molecule type";
36 }
37
38 // some program options are added here
39 void Initialize() override;
40
41 // we want to process a trajectory
42 bool DoTrajectory() override { return true; }
43
44 // write out results in EndEvaluate
45 void EndEvaluate() override;
46 // do calculation in this function
47 void EvalConfiguration(Topology *top, Topology *top_ref) override;
48
49 protected:
50 // inverse hydrodynamic radius average
52 // radius of gyration squared average
54 // mass weighted radius of gyration squared average
56};
57
58int main(int argc, char **argv) {
59 CsgRadiiApp app;
60
61 return app.Exec(argc, argv);
62}
63
65 // loop over all molecules
66 for (const auto &mol : top->Molecules()) {
67 // does the id match if given?
68 if (OptionsMap().count("mol")) {
69 if (OptionsMap()["mol"].as<votca::Index>() != mol.getId() + 1) {
70 continue;
71 }
72 }
73 // otherwise does the name pattern match?
74 else if (!votca::tools::wildcmp(OptionsMap()["molname"].as<string>(),
75 mol.getName())) {
76 continue; // if not skip this molecule
77 }
78
79 // Number of beads in the molecule
80 votca::Index N = mol.BeadCount();
81
82 // sqared tensor of gyration for current snapshot
83 double r_gyr_sq = 0;
84 // inverse hydrodynamic radius for current snapshot
85 double inv_r_hydr = 0;
86
87 // loop over all bead pairs in molecule
88 for (votca::Index i = 0; i < N; ++i) {
89 for (votca::Index j = i + 1; j < N; ++j) {
90 // distance between bead i and j
91 Eigen::Vector3d r_ij =
92 mol.getBead(i)->getPos() - mol.getBead(j)->getPos();
93 // radius of gyration squared
94 r_gyr_sq += r_ij.squaredNorm() / (double)(N * N);
95 // hydrodynamic radius
96 inv_r_hydr += 2. / (r_ij.norm() * (double(N * N)));
97 }
98 }
99
100 // add calculated values to the averages
101 r_gyr_sq_.Process(r_gyr_sq);
102 inv_r_hydr_.Process(inv_r_hydr);
103
104 // calculate the mass weighted tensor of gyration
105 // first calculate mass + center of mass
106 double M = 0;
107 Eigen::Vector3d cm(0, 0, 0);
108 for (votca::Index i = 0; i < N; ++i) {
109 M += mol.getBead(i)->getMass();
110 cm += mol.getBead(i)->getPos() * mol.getBead(i)->getMass();
111 }
112 cm /= M;
113 // now tensor of gyration based on cm
114 double r_gyr_m_sq = 0;
115 for (votca::Index i = 0; i < N; ++i) {
116 Eigen::Vector3d r_ij = mol.getBead(i)->getPos() - cm;
117 r_gyr_m_sq += mol.getBead(i)->getMass() * r_ij.squaredNorm();
118 }
119 r_gyr_m_sq /= M;
120
121 // add to average
122 r_gyr_m_sq_.Process(r_gyr_m_sq);
123 }
124}
125
126// output everything when processing frames is done
128 cout << "\n\n------------------------------\n";
129 cout << "radius of gyration: " << sqrt(r_gyr_sq_.getAvg())
130 << endl;
131 cout << "mass weighted radius of gyration: " << sqrt(r_gyr_m_sq_.getAvg())
132 << endl;
133 cout << "hydrodynamic radius: " << 1. / inv_r_hydr_.getAvg()
134 << endl;
135 cout << "------------------------------\n";
136}
137
138// add our user program options
141 // add program option to pick molecule
142 AddProgramOptions("Molecule filter options")(
143 "mol", boost::program_options::value<votca::Index>(), "molecule number")(
144 "molname", boost::program_options::value<string>()->default_value("*"),
145 "pattern for molecule name");
146}
void HelpText(ostream &out) override
help text of application without version information
Definition radii.cc:33
string ProgramName() override
program name
Definition radii.cc:32
void EndEvaluate() override
called after the last frame
Definition radii.cc:127
bool DoTrajectory() override
overload and return true to enable trajectory command line options
Definition radii.cc:42
void EvalConfiguration(Topology *top, Topology *top_ref) override
Definition radii.cc:64
void Initialize() override
Initialize application data.
Definition radii.cc:139
votca::tools::Average< double > r_gyr_sq_
Definition radii.cc:53
votca::tools::Average< double > r_gyr_m_sq_
Definition radii.cc:55
votca::tools::Average< double > inv_r_hydr_
Definition radii.cc:51
void Initialize() override
Initialize application data.
topology of the whole system
Definition topology.h:81
MoleculeContainer & Molecules()
Definition topology.h:182
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
void Process(const T &value)
Definition average.h:48
const T & getAvg() const
Definition average.h:83
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)
Definition radii.cc:58