votca 2024.2-dev
Loading...
Searching...
No Matches
pdbwriter.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 <cstdio>
20#include <string>
21
22// Third party includes
23#include <boost/format.hpp>
24
25// Local VOTCA includes
26#include "votca/csg/pdbwriter.h"
27
28namespace votca {
29namespace csg {
30
31using namespace std;
32
33void PDBWriter::Open(string file, bool bAppend) {
34 if (bAppend) {
35 out_.open(file, std::ios_base::app);
36 } else {
37 out_.open(file);
38 }
39}
40
41void PDBWriter::WriteHeader(std::string header) {
42 if (header.size() < 10 || header.substr(0, 10) != "HEADER ") {
43 out_ << "HEADER ";
44 }
45 out_ << header;
46 if (header.back() != '\n') {
47 out_ << "\n";
48 }
49}
50
51void PDBWriter::Close() { out_.close(); }
52
54
55 out_ << boost::format("MODEL %1$4d\n") % (conf->getStep() + 1)
56 << std::flush;
57 ;
59 out_ << "ENDMDL" << std::endl;
60}
61
62void PDBWriter::WriteBox(const Eigen::Matrix3d &box) {
63 boost::format boxfrmt("CRYST1%1$9.3f%2$9.3f%3$9.3f%4$7.2f%5$7.2f%6$7.2f\n");
64 double a = box.col(0).norm();
65 double b = box.col(1).norm();
66 double c = box.col(2).norm();
67 double alpha =
68 180 / tools::conv::Pi * std::acos(box.col(1).dot(box.col(2)) / (b * c));
69 double beta =
70 180 / tools::conv::Pi * std::acos(box.col(0).dot(box.col(2)) / (a * c));
71 double gamma =
72 180 / tools::conv::Pi * std::acos(box.col(0).dot(box.col(1)) / (a * b));
73 out_ << boxfrmt % a % b % c % alpha % beta % gamma;
74}
75
76void PDBWriter::writeSymmetry(const Bead &bead) {
77 if (bead.getSymmetry() > 1) {
78 Eigen::Vector3d r = 10 * bead.getPos();
79 boost::format beadfrmt(
80 "HETATM%1$5d %2$4s %3$3s %4$1s%5$4d %6$8.3f%7$8.3f%8$8.3f\n");
81 Eigen::Vector3d ru = 0.1 * bead.getU() + r;
82
83 out_ << beadfrmt % (bead.getId() + 1) % 100000 // atom serial number
84 % bead.getName() // atom name
85 % "REU" // residue name
86 % " " // chain identifier 1 char
87 % (bead.getResnr() + 1) // residue sequence number
88 % ru.x() % ru.y() % ru.z(); // we skip the charge
89
90 if (bead.getSymmetry() > 2) {
91 Eigen::Vector3d rv = 0.1 * bead.getV() + r;
92 out_ << beadfrmt % (bead.getId() + 1) % 100000 // atom serial number
93 % bead.getName() // atom name
94 % "REV" // residue name
95 % " " // chain identifier 1 char
96 % (bead.getResnr() + 1) // residue sequence number
97 % rv.x() % rv.y() % rv.z(); // we skip the charge
98 }
99 }
100 return;
101}
102
103std::string PDBWriter::getResname(Topology &conf, const Bead &bead) {
104 if (bead.getResnr() < conf.ResidueCount()) {
105 return conf.getResidue(bead.getResnr()).getName();
106 } else {
107 return "";
108 }
109}
110} // namespace csg
111} // namespace votca
virtual const Eigen::Vector3d & getPos() const
Definition basebead.h:166
std::string getName() const
Gets the name of the bead.
Definition basebead.h:58
Index getId() const noexcept
Gets the id of the bead.
Definition basebead.h:52
information about a bead
Definition bead.h:50
const Eigen::Vector3d & getU() const
get first orientation (normal vector) vector of bead
Definition bead.h:331
const Index & getResnr() const
Definition bead.h:61
const Eigen::Vector3d & getV() const
get second orientation vector of bead
Definition bead.h:341
Symmetry getSymmetry() const
Definition bead.h:86
std::string getResname(T &container, Atom &)
Definition pdbwriter.h:60
void writeSymmetry(Atom &)
Definition pdbwriter.h:77
std::ofstream out_
Definition pdbwriter.h:98
void WriteHeader(std::string header)
Definition pdbwriter.cc:41
void WriteBox(const Eigen::Matrix3d &box)
Definition pdbwriter.cc:62
void Close() override
Definition pdbwriter.cc:51
void Write(Topology *conf) override
Definition pdbwriter.cc:53
void WriteContainer(T &container)
Definition pdbwriter.h:102
void Open(std::string file, bool bAppend=false) override
Definition pdbwriter.cc:33
const std::string & getName() const
get the name of the residue
Definition residue.h:52
topology of the whole system
Definition topology.h:81
Index ResidueCount() const
Definition topology.h:156
Index getStep() const
Definition topology.h:329
Residue & getResidue(const Index i)
Definition topology.h:229
STL namespace.
const double Pi
Definition constants.h:36
base class for all analysis tools
Definition basebead.h:33