votca 2025.1-dev
Loading...
Searching...
No Matches
growriter.cc
Go to the documentation of this file.
1/*
2 * Copyright 2009-2025 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",
58 l, 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,
61 l, pr, l, pr);
62 }
63
64 for (i = 0; i < top->BeadCount(); i++) {
65 Index resnr = top->getBead(i)->getResnr();
66 string resname = top->getResidue(resnr).getName();
67 string atomname = top->getBead(i)->getName();
68
69 fprintf(out_, "%5ld%-5.5s%5.5s%5ld", (resnr + 1) % 100000, resname.c_str(),
70 atomname.c_str(), (i + 1) % 100000);
71 /* next fprintf uses built format string */
72 Eigen::Vector3d r = conf->getBead(i)->getPos();
73
74 if (v) {
75 Eigen::Vector3d vv = conf->getBead(i)->getVel();
76 fprintf(out_, format, r.x(), r.y(), r.z(), vv.x(), vv.y(), vv.z());
77 } else {
78 fprintf(out_, format, r.x(), r.y(), r.z());
79 }
80 }
81
82 // write the box
83 Eigen::Matrix3d box = conf->getBox();
84
85 if (pr < 5) {
86 pr = 5;
87 }
88 l = pr + 5;
89
90 Eigen::Matrix3d box_offdiag = box;
91 box_offdiag.diagonal().array() = 0.0;
92
93 if (box_offdiag.isApproxToConstant(0, 1e-9)) {
94 snprintf(format, MAX_FMT_STR_LEN,
95 "%%%ld.%ldf%%%ld.%ldf%%%ld.%ldf"
96 "%%%ld.%ldf%%%ld.%ldf%%%ld.%ldf%%%ld.%ldf%%%ld.%ldf%%%ld.%ldf\n",
97 l, pr, l, pr, l, pr, l, pr, l, pr, l, pr, l, pr, l, pr, l, pr);
98 fprintf(out_, format, box(0, 0), box(1, 1), box(2, 2), box(1, 0), box(2, 0),
99 box(0, 1), box(2, 1), box(0, 2), box(1, 2));
100 } else {
101 snprintf(format, MAX_FMT_STR_LEN, "%%%ld.%ldf%%%ld.%ldf%%%ld.%ldf\n", l, pr,
102 l, pr, l, pr);
103 fprintf(out_, format, box(0, 0), box(1, 1), box(2, 2));
104 }
105 fflush(out_);
106}
107
108} // namespace csg
109} // 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
Provides a means for comparing floating point numbers.
Definition basebead.h:33
Eigen::Index Index
Definition types.h:26