votca 2024-dev
Loading...
Searching...
No Matches
traj_force.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 <cstdio>
21#include <fstream>
22#include <iostream>
23#include <sstream>
24
25// VOTCA includes
26#include <votca/tools/linalg.h>
27#include <votca/tools/table.h>
28
29// Local VOTCA includes
30#include <votca/csg/beadlist.h>
31
32// Local private includes
33#include "traj_force.h"
34
35int main(int argc, char **argv) {
36 TrajForce app;
37 return app.Exec(argc, argv);
38}
39
43 "scale",
44 boost::program_options::value<double>(&scale_)->default_value(-1.0),
45 " scaling factor for trajectory forces")(
46 "trj-force", boost::program_options::value<string>(),
47 " atomistic reference "
48 "trajectory containing forces "
49 "to add/subtract")("out", boost::program_options::value<string>(),
50 " output "
51 "trajectory "
52 "file with "
53 "resultant "
54 "forces");
55}
56
59 CheckRequired("trj", "no trajectory file specified");
60 CheckRequired("trj-force", "no reference trajectory file specified");
61 CheckRequired("out", "no output trajectory file specified");
62
63 return true;
64}
65
69 TrjReaderFactory().Create(OptionsMap()["trj-force"].as<string>());
70 if (trjreader_force_ == nullptr) {
71 throw runtime_error(string("input format not supported: ") +
72 OptionsMap()["trj-force"].as<string>());
73 }
74 // open the trajectory
75 trjreader_force_->Open(OptionsMap()["trj-force"].as<string>());
76 // read in first frame
77 trjreader_force_->FirstFrame(top_force_);
78
79 // output trajectory file
80 trjwriter_ = TrjWriterFactory().Create(OptionsMap()["out"].as<string>());
81 if (trjwriter_ == nullptr) {
82 throw runtime_error(string("output trajectory format not supported: ") +
83 OptionsMap()["out"].as<string>());
84 }
85 bool append = true;
86 trjwriter_->Open(OptionsMap()["out"].as<string>(), append);
87}
88
90 cout << "\nWe are done, thank you very much!" << endl;
91 trjreader_force_->Close();
92 trjwriter_->Close();
93}
94
96
98 if (conf->BeadCount() != top_force_.BeadCount()) {
99 throw std::runtime_error(
100 "number of beads in topology and reference force topology does not "
101 "match");
102 }
103 for (votca::Index i = 0; i < conf->BeadCount(); ++i) {
104
105 // \todo check why "conf" HasForce() is false
106 // Since "conf" topology Force is set to false
107 // for now using top_force_ to store resultant output forces
108
109 top_force_.getBead(i)->F() =
110 conf->getBead(i)->getF() + scale_ * top_force_.getBead(i)->getF();
111 Eigen::Vector3d d =
112 conf->getBead(i)->getPos() - top_force_.getBead(i)->getPos();
113 if (d.norm() > 1e-6) {
114 throw std::runtime_error(
115 "One or more bead positions in trajectory and reference force "
116 "trajectory differ by more than 1e-6");
117 }
118 }
119
120 trjwriter_->Write(&top_force_);
121 trjreader_force_->NextFrame(top_force_);
122}
Adds/subtracts forces from given atomistic trajectories.
Definition traj_force.h:39
void Initialize(void) override
Initialize application data.
Definition traj_force.cc:40
Topology top_force_
Definition traj_force.h:66
void BeginEvaluate(Topology *top, Topology *top_atom) override
called before the first frame
Definition traj_force.cc:66
std::unique_ptr< TrajectoryWriter > trjwriter_
Definition traj_force.h:68
void WriteOutFiles()
Write results to output files.
Definition traj_force.cc:95
void EndEvaluate() override
called after the last frame
Definition traj_force.cc:89
void EvalConfiguration(Topology *conf, Topology *conf_atom) override
called for each frame which is mapped
Definition traj_force.cc:97
std::unique_ptr< TrajectoryReader > trjreader_force_
Definition traj_force.h:67
double scale_
Scaling of forces, +1 for addition and -1 for subtraction.
Definition traj_force.h:61
bool EvaluateOptions() override
Process command line options.
Definition traj_force.cc:57
virtual const Eigen::Vector3d & getPos() const
Definition basebead.h:166
const Eigen::Vector3d & getF() const
get the force acting on the bead
Definition bead.h:361
Eigen::Vector3d & F()
Definition bead.h:210
bool EvaluateOptions() override
Process command line options.
void Initialize() override
Initialize application data.
topology of the whole system
Definition topology.h:81
Index BeadCount() const
Definition topology.h:150
Bead * getBead(const Index i)
Returns a pointer to the bead with index i.
Definition topology.h:227
void CopyTopologyData(Topology *top)
copy topology data of different topology
Definition topology.cc:102
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 CheckRequired(const std::string &option_name, const std::string &error_msg="")
Check weather required option is set.
FileFormatFactory< TrajectoryWriter > & TrjWriterFactory()
FileFormatFactory< TrajectoryReader > & TrjReaderFactory()
Eigen::Index Index
Definition types.h:26
int main(int argc, char **argv)
Definition traj_force.cc:35