votca 2024.2-dev
Loading...
Searching...
No Matches
pdbwriter.h
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#ifndef VOTCA_CSG_PDBWRITER_H
19#define VOTCA_CSG_PDBWRITER_H
20
21// Standard includes
22#include <cstdio>
23
24// VOTCA includes
27
28// Local VOTCA includes
29#include "topology.h"
30#include "trajectorywriter.h"
31
32namespace votca {
33namespace csg {
34
36 public:
38
39 void Open(std::string file, bool bAppend = false) override;
40 void Close() override;
41
42 void Write(Topology *conf) override;
43
44 template <class T>
45 void WriteContainer(T &container);
46
47 void WriteHeader(std::string header);
48
49 void WriteBox(const Eigen::Matrix3d &box);
50
51 private:
52 template <class Atom>
53 std::string getName(Atom &atom) {
54 return atom.getElement();
55 }
56
57 std::string getName(const Bead &bead) { return bead.getName(); }
58
59 template <class T, class Atom>
60 std::string getResname(T &container, Atom &) {
61 return container.getType();
62 }
63 std::string getResname(Topology &conf, const Bead &bead);
64
65 template <class Atom>
66 Index getId(Atom &atom) {
67 return atom.getId();
68 }
69
70 template <class T, class Atom>
71 Index getResId(T &container, Atom &) {
72 return container.getId();
73 }
74 Index getResId(Topology &, const Bead &bead) { return bead.getResnr() + 1; }
75
76 template <class Atom>
77 void writeSymmetry(Atom &) {
78 return;
79 }
80 void writeSymmetry(const Bead &bead);
81
82 template <class Atom>
83 Eigen::Vector3d getPos(Atom &atom) {
84 return atom.getPos() * tools::conv::bohr2ang;
85 }
86
87 Eigen::Vector3d getPos(const Bead &bead) {
88 return bead.Pos() * tools::conv::nm2ang;
89 }
90
91 template <class T>
92 T &getIterable(T &container) {
93 return container;
94 }
95
96 BeadContainer &getIterable(Topology &top) { return top.Beads(); }
97
98 std::ofstream out_;
99};
100
101template <class T>
102inline void PDBWriter::WriteContainer(T &container) {
103 boost::format atomfrmt(
104 "ATOM %1$5d %2$-4s %3$-3s %4$1s%5$4d %6$8.3f%7$8.3f%8$8.3f\n");
105
106 for (const auto &atom : getIterable(container)) {
107 Eigen::Vector3d r = getPos(atom);
108 std::string resname = getResname(container, atom);
109 std::string atomname = getName(atom);
110 if (resname.size() > 3) {
111 resname = resname.substr(0, 3);
112 }
113 if (atomname.size() > 4) {
114 atomname = atomname.substr(0, 4);
115 }
116
117 out_ << atomfrmt % (getId(atom) % 100000) // atom serial number, wrapped
118 // due to pdb limitations
119 % atomname % resname % " " // chain identifier 1 char
120 % (getResId(container, atom) % 10000) // residue sequence
121 // number, wrapped due to
122 // pdb limitations
123 % r.x() % r.y() % r.z();
124 // we skip the charge
125 writeSymmetry(atom);
126 }
127 out_ << std::flush;
128}
129} // namespace csg
130} // namespace votca
131
132#endif // VOTCA_CSG_PDBWRITER_H
virtual Eigen::Vector3d & Pos()
Definition basebead.h:128
std::string getName() const
Gets the name of the bead.
Definition basebead.h:58
information about a bead
Definition bead.h:50
const Index & getResnr() const
Definition bead.h:61
std::string getName(Atom &atom)
Definition pdbwriter.h:53
std::string getResname(T &container, Atom &)
Definition pdbwriter.h:60
void writeSymmetry(Atom &)
Definition pdbwriter.h:77
Eigen::Vector3d getPos(Atom &atom)
Definition pdbwriter.h:83
std::ofstream out_
Definition pdbwriter.h:98
void WriteHeader(std::string header)
Definition pdbwriter.cc:41
Index getId(Atom &atom)
Definition pdbwriter.h:66
T & getIterable(T &container)
Definition pdbwriter.h:92
void WriteBox(const Eigen::Matrix3d &box)
Definition pdbwriter.cc:62
void Close() override
Definition pdbwriter.cc:51
Index getResId(T &container, Atom &)
Definition pdbwriter.h:71
void Write(Topology *conf) override
Definition pdbwriter.cc:53
Eigen::Vector3d getPos(const Bead &bead)
Definition pdbwriter.h:87
void WriteContainer(T &container)
Definition pdbwriter.h:102
void Open(std::string file, bool bAppend=false) override
Definition pdbwriter.cc:33
BeadContainer & getIterable(Topology &top)
Definition pdbwriter.h:96
Index getResId(Topology &, const Bead &bead)
Definition pdbwriter.h:74
std::string getName(const Bead &bead)
Definition pdbwriter.h:57
const tools::DistanceUnit distance_unit
Definition pdbwriter.h:37
topology of the whole system
Definition topology.h:81
BeadContainer & Beads()
Definition topology.h:169
boost::container::deque< Bead, void, block_bead_x4_t > BeadContainer
Definition topology.h:69
const double bohr2ang
Definition constants.h:49
const double nm2ang
Definition constants.h:50
base class for all analysis tools
Definition basebead.h:33
Eigen::Index Index
Definition types.h:26