votca 2024-dev
Loading...
Searching...
No Matches
gmxtrajectorywriter.cc
Go to the documentation of this file.
1/*
2 * Copyright 2009-2020 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 <string>
20
21// Local private VOTCA includes
22#include "gmxtrajectorywriter.h"
23
24// Third party includes
25#include <gromacs/fileio/trxio.h>
26#include <gromacs/trajectory/trajectoryframe.h>
27
28// this one is needed because of bool is defined in one of the headers included
29// by gmx
30#undef bool
31
32namespace votca {
33namespace csg {
34
35void GMXTrajectoryWriter::Open(std::string file, bool) {
36 file_ = open_trx((char *)file.c_str(), "w");
37}
38
39void GMXTrajectoryWriter::Close() { close_trx(file_); }
40
42 Index N = conf->BeadCount();
43 t_trxframe frame;
44 rvec *x = new rvec[N];
45 rvec *v = nullptr;
46 rvec *f = nullptr;
47 Eigen::Matrix3d box = conf->getBox();
48
49 frame.natoms = (int)N;
50 frame.bTime = true;
51 frame.time = real(conf->getTime());
52 frame.bStep = true;
53 frame.x = x;
54 frame.bLambda = false;
55 frame.bAtoms = false;
56 frame.bPrec = false;
57 frame.bX = true;
58 frame.bF = conf->HasForce();
59 frame.bBox = true;
60 frame.bV = conf->HasVel();
61
62 for (Index i = 0; i < 3; i++) {
63 for (Index j = 0; j < 3; j++) {
64 frame.box[j][i] = real(box(i, j));
65 }
66 }
67
68 for (Index i = 0; i < N; ++i) {
69 Eigen::Vector3d pos = conf->getBead(i)->getPos();
70 x[i][0] = real(pos.x());
71 x[i][1] = real(pos.y());
72 x[i][2] = real(pos.z());
73 }
74
75 if (frame.bV) {
76 v = new rvec[N];
77 for (Index i = 0; i < N; ++i) {
78 frame.v = v;
79 Eigen::Vector3d vel = conf->getBead(i)->getVel();
80 v[i][0] = real(vel.x());
81 v[i][1] = real(vel.y());
82 v[i][2] = real(vel.z());
83 }
84 }
85 if (frame.bF) {
86 f = new rvec[N];
87 for (Index i = 0; i < N; ++i) {
88 frame.f = f;
89 Eigen::Vector3d force = conf->getBead(i)->getF();
90 f[i][0] = real(force.x());
91 f[i][1] = real(force.y());
92 f[i][2] = real(force.z());
93 }
94 }
95
96 write_trxframe(file_, &frame, nullptr);
97
98 delete[] x;
99 if (frame.bV) {
100 delete[] v;
101 }
102 if (frame.bF) {
103 delete[] f;
104 }
105}
106
107} // namespace csg
108} // namespace votca
virtual const Eigen::Vector3d & getPos() const
Definition basebead.h:166
const Eigen::Vector3d & getF() const
get the force acting on the bead
Definition bead.h:361
const Eigen::Vector3d & getVel() const
Definition bead.h:320
void Write(Topology *conf) override
void Open(std::string file, bool=false) override
topology of the whole system
Definition topology.h:81
double getTime() const
Definition topology.h:317
const Eigen::Matrix3d & getBox() const
Definition topology.h:298
Index BeadCount() const
Definition topology.h:150
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