votca 2024.2-dev
Loading...
Searching...
No Matches
main.cc
Go to the documentation of this file.
1/*
2 * Copyright 2009-2020 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// TODO: This code need lots of cleaning up! please do not look at anything in
19// here!
20//
21
23#include "analysistool.h"
24#include "bondedstatistics.h"
25#include "stdanalysis.h"
26#include "tabulatedpotential.h"
27#include <cmath>
28#include <fstream>
29#include <iostream>
30#include <map>
31#include <string>
32#include <votca/tools/getline.h>
35
36using namespace std;
37using namespace votca::csg;
38
39class CsgBoltzmann final : public CsgApplication {
40 public:
41 string ProgramName() { return "csg_boltzmann"; }
42 void HelpText(ostream &out) {
43 out << "Performs tasks that are needed for simple boltzmann\n"
44 "inversion in an interactive environment.";
45 }
46 bool DoTrajectory() { return !OptionsMap().count("excl"); }
47 bool DoMapping() { return true; }
48
49 void Initialize();
50 bool EvaluateOptions();
51 void Run();
52
53 void InteractiveMode();
54 bool EvaluateTopology(Topology *top, Topology *top_ref);
55
56 protected:
58 Molecule &atomistic, Topology *top_cg,
59 Molecule &cg);
61};
64 AddProgramOptions("Special options")(
65 "excl", boost::program_options::value<string>(),
66 "write atomistic exclusion list to file");
67
69}
70
73 if (OptionsMap().count("excl")) {
74 CheckRequired("cg", "excl options needs a mapping file");
75 }
76 return true;
77}
78
80 if (OptionsMap().count("excl")) {
81 if (top_ref->MoleculeCount() > 1) {
82 cout << "WARNING: cannot create exclusion list for topology with"
83 "multiple molecules, using only first molecule\n";
84 }
85
86 cout << "Writing exclusion list for atomistic molecule "
87 << top_ref->MoleculeByIndex(0)->getName()
88 << " in coarse grained representation "
89 << top_ref->MoleculeByIndex(0)->getName() << endl;
90
92 top_ref, *top_ref->MoleculeByIndex(0), top, *top->MoleculeByIndex(0));
93 std::ofstream fl;
94 fl.open(OptionsMap()["excl"].as<string>());
95 fl << "# atomistic: " << top_ref->MoleculeByIndex(0)->getName()
96 << " cg: " << top_ref->MoleculeByIndex(0)->getName()
97 << " cgmap: " << OptionsMap()["cg"].as<string>() << endl;
98 fl << ex;
99 fl.close();
100
101 return false;
102 }
103 return true;
104}
105
107 Molecule &atomistic,
108 Topology *top_cg,
109 Molecule &cg) {
110 ExclusionList ex;
111 // exclude all with all
112 ex.ExcludeList(atomistic.Beads());
113 // remove exclusions from inside a mapped bead
114 for (votca::Index i = 0; i < cg.BeadCount(); ++i) {
115 std::vector<Bead *> excl_list;
116 for (votca::Index parent_bead_id : cg.getBead(i)->ParentBeads()) {
117 excl_list.push_back(top_atomistic->getBead(parent_bead_id));
118 }
119 ex.Remove(excl_list);
120 }
121 // remove exclusion which come from atomistic topology and hence bonds and
122 // angles
123 for (votca::Index i = 0; i < cg.BeadCount() - 1; ++i) {
124 for (votca::Index j = i + 1; j < cg.BeadCount(); ++j) {
125 if (top_cg->getExclusions().IsExcluded(cg.getBead(i), cg.getBead(j))) {
126
127 for (votca::Index parent_bead_id_i : cg.getBead(i)->ParentBeads()) {
128 for (votca::Index parent_bead_id_j : cg.getBead(j)->ParentBeads()) {
129 ex.RemoveExclusion(top_atomistic->getBead(parent_bead_id_i),
130 top_atomistic->getBead(parent_bead_id_j));
131 }
132 }
133 }
134 }
135 }
136 return ex;
137}
138
141 if (OptionsMap().count("excl")) {
142 return;
143 }
145}
146
148 std::map<std::string, AnalysisTool *> cmds;
151 tab.Register(cmds);
152 std.Register(cmds);
153
154 string help_text =
155 "Interactive mode, expecting commands:\n"
156 "help: show this help\n"
157 "q: quit\n"
158 "list: list all available bonds\n"
159 "vals <file> <selection>: write values to file\n"
160 "hist <file> <selection>: create histogram\n"
161 "tab <file> <selection>: create tabulated potential\n"
162 "autocor <file> <selection>: calculate autocorrelation, only one row "
163 "allowed in selection!\n"
164 "cor <file> <selection>: calculate correlations, first row is correlated "
165 "with all other rows";
166
167 cout << help_text << endl;
168
169 while (true) {
170 string line;
171 cout << "> ";
172 votca::tools::getline(cin, line);
173
174 boost::trim(line);
175
176 votca::tools::Tokenizer tok(line, " \t");
177 vector<string> args = tok.ToVector();
178
179 if (args.size() == 0) {
180 continue;
181 }
182
183 string cmd = args.front();
184 args.erase(args.begin());
185
186 if (cmd == "q") {
187 break;
188 }
189
190 std::map<string, AnalysisTool *>::iterator tool;
191 if (cmd == "help") {
192 if (args.size() == 0) {
193 cout << help_text << endl;
194 continue;
195 }
196 cmd = args.front();
197 args.erase(args.begin());
198 tool = cmds.find(cmd);
199 if (tool == cmds.end()) {
200 cout << "error, no help item found" << endl;
201 continue;
202 }
203 tool->second->Help(cmd, args);
204 cout << endl;
205 continue;
206 }
207
208 tool = cmds.find(cmd);
209 if (tool == cmds.end()) {
210 cout << "error, command not found" << endl;
211 continue;
212 }
213
214 tool->second->Command(bs_, cmd, args);
215 }
216}
217
218int main(int argc, char **argv) {
219 CsgBoltzmann app;
220 app.Exec(argc, argv);
221}
bool EvaluateTopology(Topology *top, Topology *top_ref)
called after topology was loaded
Definition main.cc:79
void HelpText(ostream &out)
help text of application without version information
Definition main.cc:42
void Initialize()
Initialize application data.
Definition main.cc:62
void Run()
Main body of application.
Definition main.cc:139
void InteractiveMode()
Definition main.cc:147
BondedStatistics bs_
Definition main.cc:60
bool DoTrajectory()
overload and return true to enable trajectory command line options
Definition main.cc:46
bool DoMapping()
overload and return true to enable mapping command line options
Definition main.cc:47
bool EvaluateOptions()
Process command line options.
Definition main.cc:71
ExclusionList CreateExclusionList(Topology *top_atomistic, Molecule &atomistic, Topology *top_cg, Molecule &cg)
Definition main.cc:106
string ProgramName()
program name
Definition main.cc:41
const std::vector< Index > & ParentBeads()
Definition bead.h:265
Class calculates data associated with bond interactions.
bool EvaluateOptions() override
Process command line options.
void Initialize() override
Initialize application data.
void AddObserver(CGObserver *observer)
void Run(void) override
Main body of application.
void RemoveExclusion(Bead *bead1, Bead *bead2)
void Remove(iterable &l)
void ExcludeList(iterable &l)
bool IsExcluded(Bead *bead1, Bead *bead2) const
information about molecules
Definition molecule.h:45
Bead * getBead(Index bead)
get the id of a bead in the molecule
Definition molecule.h:59
const std::string & getName() const
get the name of the molecule
Definition molecule.h:51
Index BeadCount() const
get the number of beads in the molecule
Definition molecule.h:65
const std::vector< Bead * > & Beads() const
Definition molecule.h:67
Tabulated Potential calculates histograms of bead interactions.
void Register(std::map< std::string, AnalysisTool * > &lib) override
topology of the whole system
Definition topology.h:81
Index MoleculeCount() const
number of molecules in the system
Definition topology.h:144
ExclusionList & getExclusions()
Definition topology.h:391
Molecule * MoleculeByIndex(Index index)
Definition topology.h:470
Bead * getBead(const Index i)
Returns a pointer to the bead with index i.
Definition topology.h:227
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.
break string into words
Definition tokenizer.h:72
std::vector< T > ToVector()
store all words in a vector of type T, does type conversion.
Definition tokenizer.h:109
int main(int argc, char **argv)
Definition main.cc:218
STL namespace.
std::istream & getline(std::istream &is, std::string &str)
Wrapper for a getline function.
Definition getline.h:35
Eigen::Index Index
Definition types.h:26
void help_text(void)
Definition part_dist.cc:43