votca 2024.2-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 char format[100];
38 Index i, l, vpr;
39 Topology *top = conf;
40
41 fprintf(out_, "%s\n", "what a nice title");
42 fprintf(out_, "%5ld\n", top->BeadCount());
43
44 bool v = top->HasVel();
45 Index pr = 3; // precision of writeout, given by the spec
46
47 /* build format string for printing,
48 something like "%8.3f" for x and "%8.4f" for v */
49
50 l = pr + 5;
51 vpr = pr + 1;
52 if (v) {
53 sprintf(format,
54 "%%%ld.%ldf%%%ld.%ldf%%%ld.%ldf%%%ld.%ldf%%%ld.%ldf%%%ld.%ldf\n", l,
55 pr, l, pr, l, pr, l, vpr, l, vpr, l, vpr);
56 } else {
57 sprintf(format, "%%%ld.%ldf%%%ld.%ldf%%%ld.%ldf\n", l, pr, l, pr, l, pr);
58 }
59
60 for (i = 0; i < top->BeadCount(); i++) {
61 Index resnr = top->getBead(i)->getResnr();
62 string resname = top->getResidue(resnr).getName();
63 string atomname = top->getBead(i)->getName();
64
65 fprintf(out_, "%5ld%-5.5s%5.5s%5ld", (resnr + 1) % 100000, resname.c_str(),
66 atomname.c_str(), (i + 1) % 100000);
67 /* next fprintf uses built format string */
68 Eigen::Vector3d r = conf->getBead(i)->getPos();
69
70 if (v) {
71 Eigen::Vector3d vv = conf->getBead(i)->getVel();
72 fprintf(out_, format, r.x(), r.y(), r.z(), vv.x(), vv.y(), vv.z());
73 } else {
74 fprintf(out_, format, r.x(), r.y(), r.z());
75 }
76 }
77
78 // write the box
79 Eigen::Matrix3d box = conf->getBox();
80
81 if (pr < 5) {
82 pr = 5;
83 }
84 l = pr + 5;
85
86 Eigen::Matrix3d box_offdiag = box;
87 box_offdiag.diagonal().array() = 0.0;
88
89 if (box_offdiag.isApproxToConstant(0, 1e-9)) {
90 sprintf(format,
91 "%%%ld.%ldf%%%ld.%ldf%%%ld.%ldf"
92 "%%%ld.%ldf%%%ld.%ldf%%%ld.%ldf%%%ld.%ldf%%%ld.%ldf%%%ld.%ldf\n",
93 l, pr, l, pr, l, pr, l, pr, l, pr, l, pr, l, pr, l, pr, l, pr);
94 fprintf(out_, format, box(0, 0), box(1, 1), box(2, 2), box(1, 0), box(2, 0),
95 box(0, 1), box(2, 1), box(0, 2), box(1, 2));
96 } else {
97 sprintf(format, "%%%ld.%ldf%%%ld.%ldf%%%ld.%ldf\n", l, pr, l, pr, l, pr);
98 fprintf(out_, format, box(0, 0), box(1, 1), box(2, 2));
99 }
100 fflush(out_);
101}
102
103} // namespace csg
104} // 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
STL namespace.
base class for all analysis tools
Definition basebead.h:33
Eigen::Index Index
Definition types.h:26