votca 2025-dev
 
Loading...
Searching...
No Matches
growriter.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// Local private VOTCA includes
23#include "growriter.h"
24
25namespace votca {
26namespace csg {
27
28using namespace std;
29
30void GROWriter::Open(string file, bool bAppend) {
31 out_ = fopen(file.c_str(), bAppend ? "at" : "wt");
32}
33
34void GROWriter::Close() { fclose(out_); }
35
37
38 constexpr int MAX_FMT_STR_LEN = 100;
39
40 char format[MAX_FMT_STR_LEN];
41 Index i, l, vpr;
42 Topology *top = conf;
43
44 fprintf(out_, "%s\n", "what a nice title");
45 fprintf(out_, "%5ld\n", top->BeadCount());
46
47 bool v = top->HasVel();
48 Index pr = 3; // precision of writeout, given by the spec
49
50 /* build format string for printing,
51 something like "%8.3f" for x and "%8.4f" for v */
52
53 l = pr + 5;
54 vpr = pr + 1;
55 if (v) {
56 snprintf(format, MAX_FMT_STR_LEN,
57 "%%%ld.%ldf%%%ld.%ldf%%%ld.%ldf%%%ld.%ldf%%%ld.%ldf%%%ld.%ldf\n", l,
58 pr, l, pr, l, pr, l, vpr, l, vpr, l, vpr);
59 } else {
60 snprintf(format, MAX_FMT_STR_LEN, "%%%ld.%ldf%%%ld.%ldf%%%ld.%ldf\n", l, pr, l, pr, l, pr);
61 }
62
63 for (i = 0; i < top->BeadCount(); i++) {
64 Index resnr = top->getBead(i)->getResnr();
65 string resname = top->getResidue(resnr).getName();
66 string atomname = top->getBead(i)->getName();
67
68 fprintf(out_, "%5ld%-5.5s%5.5s%5ld", (resnr + 1) % 100000, resname.c_str(),
69 atomname.c_str(), (i + 1) % 100000);
70 /* next fprintf uses built format string */
71 Eigen::Vector3d r = conf->getBead(i)->getPos();
72
73 if (v) {
74 Eigen::Vector3d vv = conf->getBead(i)->getVel();
75 fprintf(out_, format, r.x(), r.y(), r.z(), vv.x(), vv.y(), vv.z());
76 } else {
77 fprintf(out_, format, r.x(), r.y(), r.z());
78 }
79 }
80
81 // write the box
82 Eigen::Matrix3d box = conf->getBox();
83
84 if (pr < 5) {
85 pr = 5;
86 }
87 l = pr + 5;
88
89 Eigen::Matrix3d box_offdiag = box;
90 box_offdiag.diagonal().array() = 0.0;
91
92 if (box_offdiag.isApproxToConstant(0, 1e-9)) {
93 snprintf(format, MAX_FMT_STR_LEN,
94 "%%%ld.%ldf%%%ld.%ldf%%%ld.%ldf"
95 "%%%ld.%ldf%%%ld.%ldf%%%ld.%ldf%%%ld.%ldf%%%ld.%ldf%%%ld.%ldf\n",
96 l, pr, l, pr, l, pr, l, pr, l, pr, l, pr, l, pr, l, pr, l, pr);
97 fprintf(out_, format, box(0, 0), box(1, 1), box(2, 2), box(1, 0), box(2, 0),
98 box(0, 1), box(2, 1), box(0, 2), box(1, 2));
99 } else {
100 snprintf(format, MAX_FMT_STR_LEN, "%%%ld.%ldf%%%ld.%ldf%%%ld.%ldf\n", l, pr, l, pr, l, pr);
101 fprintf(out_, format, box(0, 0), box(1, 1), box(2, 2));
102 }
103 fflush(out_);
104}
105
106} // namespace csg
107} // 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
const Index & getResnr() const
Definition bead.h:61
const Eigen::Vector3d & getVel() const
Definition bead.h:320
void Write(Topology *conf) override
Definition growriter.cc:36
void Close() override
Definition growriter.cc:34
void Open(std::string file, bool bAppend=false) override
Definition growriter.cc:30
const std::string & getName() const
get the name of the residue
Definition residue.h:52
topology of the whole system
Definition topology.h:81
const Eigen::Matrix3d & getBox() const
Definition topology.h:298
Index BeadCount() const
Definition topology.h:150
Residue & getResidue(const Index i)
Definition topology.h:229
Bead * getBead(const Index i)
Returns a pointer to the bead with index i.
Definition topology.h:227
base class for all analysis tools
Definition basebead.h:33
Eigen::Index Index
Definition types.h:26