votca 2025.1-dev
Loading...
Searching...
No Matches
csg_gmxtopol.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 <fstream>
20#include <iostream>
21
22// Third party includes
23#include <boost/format.hpp>
24
25// Local VOTCA includes
27
28using namespace votca::csg;
29using namespace std;
30
32 public:
33 string ProgramName() override { return "csg_gmxtopol"; }
34 void HelpText(ostream &out) override {
35 out << "Create skeleton for gromacs topology based on atomistic topology\n"
36 "and a mapping file. File still needs to be modified by the user.";
37 }
38
39 bool DoMapping(void) override { return true; }
40
41 void Initialize(void) override;
42 bool EvaluateOptions(void) override {
44 CheckRequired("out", "no output topology specified");
45 return true;
46 }
47 bool EvaluateTopology(Topology *top, Topology *top_ref) override;
48
49 protected:
50 void WriteAtoms(ostream &out, Molecule &cg);
51 void WriteInteractions(ostream &out, const Topology &top, Molecule &cg);
52 void WriteMolecule(ostream &out, const Topology &top, Molecule &cg);
53};
54
58 "out", boost::program_options::value<string>(),
59 "output topology (will create .top and in future also .itp)");
60}
61
63 if (top->MoleculeCount() > 1) {
64 cout << "WARNING: cannot create topology for topology with"
65 "multiple molecules, using only first molecule\n";
66 }
67 ofstream fl;
68 fl.open((OptionsMap()["out"].as<string>() + ".top"));
69 WriteMolecule(fl, *top, *(top->MoleculeByIndex(0)));
70 fl.close();
71 return true;
72}
73
74void GmxTopolApp::WriteAtoms(ostream &out, Molecule &cg) {
75 out << "[atoms]\n";
76 out << "; nr type resnr residue atom cgnr charge mass\n";
77 for (votca::Index i = 0; i < cg.BeadCount(); ++i) {
78 Bead *b = cg.getBead(i);
79 out << boost::format("%d %s 1 RES %s %d %f %f\n") % (i + 1) % b->getType() %
80 b->getName() % (i + 1) % b->getQ() % b->getMass();
81 }
82 out << endl;
83}
84
85void GmxTopolApp::WriteInteractions(ostream &out, const Topology &top,
86 Molecule &cg) {
87 votca::Index nb = -1;
88
89 for (const Interaction *ic : top.BondedInteractions()) {
90 if (ic->getMolecule() != cg.getId()) {
91 continue;
92 }
93 if (nb != ic->BeadCount()) {
94 nb = ic->BeadCount();
95 switch (nb) {
96 case 2:
97 out << "\n[ bonds ]\n";
98 break;
99 case 3:
100 out << "\n[ angles ]\n";
101 break;
102 case 4:
103 out << "\n[ dihedrals ]\n";
104 break;
105 default:
106 string err = "cannot handle number of beads in interaction:";
107 err += to_string(ic->getMolecule() + 1) + ":" + ic->getGroup();
108 err += ":" + to_string(ic->getIndex() + 1);
109 throw runtime_error(err);
110 }
111 }
112 for (votca::Index i = 0; i < nb; ++i) {
113 out << ic->getBeadId(i) + 1 << " ";
114 }
115 out << " 1 ; ";
116 out << to_string(ic->getMolecule() + 1);
117 out << ":" + ic->getGroup();
118 out << ":" + to_string(ic->getIndex() + 1) << endl;
119 }
120}
121
122void GmxTopolApp::WriteMolecule(ostream &out, const Topology &top,
123 Molecule &cg) {
124 out << "[ moleculetype ]\n";
125 out << cg.getName() << " 3\n\n";
126
127 WriteAtoms(out, cg);
128 WriteInteractions(out, top, cg);
129}
130
131int main(int argc, char **argv) {
132 GmxTopolApp app;
133 return app.Exec(argc, argv);
134}
void WriteInteractions(ostream &out, const Topology &top, Molecule &cg)
bool EvaluateOptions(void) override
Process command line options.
string ProgramName() override
program name
void WriteMolecule(ostream &out, const Topology &top, Molecule &cg)
void HelpText(ostream &out) override
help text of application without version information
bool DoMapping(void) override
overload and return true to enable mapping command line options
void Initialize(void) override
Initialize application data.
void WriteAtoms(ostream &out, Molecule &cg)
bool EvaluateTopology(Topology *top, Topology *top_ref) override
called after topology was loaded
virtual const std::string getType() const noexcept
Definition basebead.h:84
std::string getName() const
Gets the name of the bead.
Definition basebead.h:58
virtual const double & getMass() const noexcept
Definition basebead.h:104
information about a bead
Definition bead.h:50
virtual const double & getQ() const
Definition bead.h:67
bool EvaluateOptions() override
Process command line options.
void Initialize() override
Initialize application data.
base class for all interactions
Definition interaction.h:40
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
Index getId() const
get the molecule ID
Definition molecule.h:48
topology of the whole system
Definition topology.h:81
Index MoleculeCount() const
number of molecules in the system
Definition topology.h:144
Molecule * MoleculeByIndex(Index index)
Definition topology.h:470
InteractionContainer & BondedInteractions()
Definition topology.h:189
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.
int main(int argc, char **argv)
STL namespace.
Eigen::Index Index
Definition types.h:26