votca 2024.2-dev
Loading...
Searching...
No Matches
stateapplication.cc
Go to the documentation of this file.
1/*
2 * Copyright 2009-2020 The VOTCA Development Team
3 * (http://www.votca.org)
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License")
6 *
7 * You may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *
18 */
19
20// Third party includes
21#include <boost/format.hpp>
22
23// Local VOTCA includes
27#include "votca/xtp/version.h"
28
29namespace votca {
30namespace xtp {
31
33
34 namespace propt = boost::program_options;
35
36 AddProgramOptions()("file,f", propt::value<std::string>(),
37 " hdf5 state file, *.hdf5");
38 AddProgramOptions()("first-frame,i", propt::value<Index>()->default_value(0),
39 " start from this frame");
40 AddProgramOptions()("nframes,n", propt::value<Index>()->default_value(1),
41 " number of frames to process");
42 AddProgramOptions()("save,s", propt::value<bool>()->default_value(true),
43 " whether or not to save changes to state file");
44
46}
47
49 CheckRequired("file", "Please provide the state file");
51}
52
54
55 Index nframes = OptionsMap()["nframes"].as<Index>();
56 Index fframe = OptionsMap()["first-frame"].as<Index>();
57 bool save = OptionsMap()["save"].as<bool>();
58
59 // STATESAVER & PROGRESS OBSERVER
60 std::string statefile = OptionsMap()["file"].as<std::string>();
61 StateSaver statsav(statefile);
62 std::vector<Index> frames = statsav.getFrames();
63 if (frames.empty()) {
64 throw std::runtime_error("Statefile " + statefile + " not found.");
65 }
66 // INITIALIZE & RUN CALCULATORS
67 std::cout << "Initializing calculator" << std::endl;
69 std::cout << frames.size() << " frames in statefile, Ids are: ";
70 for (Index frame : frames) {
71 std::cout << frame << " ";
72 }
73 std::cout << std::endl;
74 if (fframe < Index(frames.size())) {
75 std::cout << "Starting at frame " << frames[fframe] << std::endl;
76 } else {
77 std::cout << "First frame:" << fframe
78 << " is larger than number of frames:" << Index(frames.size())
79 << std::endl;
80 return;
81 }
82
83 if ((fframe + nframes) > Index(frames.size())) {
84 nframes = Index(frames.size()) - fframe;
85 }
86
87 for (Index i = fframe; i < nframes; i++) {
88 std::cout << "Evaluating frame " << frames[i] << std::endl;
89 Topology top = statsav.ReadFrame(frames[i]);
90 EvaluateFrame(top);
91 if (save && savetoStateFile()) {
92 statsav.WriteFrame(top);
93 } else {
94 std::cout << "Changes have not been written to state file." << std::endl;
95 }
96 }
97}
98
99} // namespace xtp
100} // namespace votca
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.
virtual bool EvaluateFrame(Topology &top)=0
virtual bool savetoStateFile() const =0
virtual void ConfigCalculator()=0
virtual void AddCommandLineOpt()=0
virtual void CheckOptions()=0
Container for segments and box and atoms.
Definition topology.h:41
base class for all analysis tools
Definition basebead.h:33
Eigen::Index Index
Definition types.h:26