votca 2025.1-dev
Loading...
Searching...
No Matches
gmxtrajectoryreader.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 <cstdlib>
20#include <filesystem>
21#include <iostream>
22
23// Third party includes
24#include <gromacs/utility/programcontext.h>
25#include <gromacs/version.h>
26
27// Local VOTCA includes
28#include "votca/csg/topology.h"
29
30// Local private VOTCA includes
31#include "gmxtrajectoryreader.h"
32
33namespace votca {
34namespace csg {
35
36bool GMXTrajectoryReader::Open(const std::string &file) {
37 filename_ = file;
38 return true;
39}
40
42
44 gmx_output_env_t *oenv;
45 gmx::TimeUnit timeunit = gmx::TimeUnit::Picoseconds;
46 XvgFormat xvg = XvgFormat::None;
47#if GMX_VERSION >= 20230000
48 const std::filesystem::path path = filename_;
49#else
50 char *path = (char *)filename_.c_str();
51#endif
52 output_env_init(&oenv, gmx::getProgramContext(), timeunit, FALSE, xvg, 0);
53 if (!read_first_frame(oenv, &gmx_status_, path, &gmx_frame_,
54 TRX_READ_X | TRX_READ_V | TRX_READ_F)) {
55 throw std::runtime_error(std::string("cannot open ") + filename_);
56 }
57 output_env_done(oenv);
58
59 Eigen::Matrix3d m;
60 for (Index i = 0; i < 3; i++) {
61 for (Index j = 0; j < 3; j++) {
62 m(i, j) = gmx_frame_.box[j][i];
63 }
64 }
65 conf.setBox(m);
66 conf.setTime(gmx_frame_.time);
67 conf.setStep(gmx_frame_.step);
68 std::cout << std::endl;
69
70 if (gmx_frame_.natoms != (Index)conf.Beads().size()) {
71 throw std::runtime_error(
72 "number of beads in trajectory do not match topology");
73 }
74
75 // conf.HasPos(true);
76 // conf.HasF( gmx_frame_.bF);
77
78 for (Index i = 0; i < gmx_frame_.natoms; i++) {
79 Eigen::Vector3d r = {gmx_frame_.x[i][XX], gmx_frame_.x[i][YY],
80 gmx_frame_.x[i][ZZ]};
81 conf.getBead(i)->setPos(r);
82 if (gmx_frame_.bF) {
83 Eigen::Vector3d f = {gmx_frame_.f[i][XX], gmx_frame_.f[i][YY],
84 gmx_frame_.f[i][ZZ]};
85 conf.getBead(i)->setF(f);
86 }
87 if (gmx_frame_.bV) {
88 Eigen::Vector3d v = {gmx_frame_.v[i][XX], gmx_frame_.v[i][YY],
89 gmx_frame_.v[i][ZZ]};
90 conf.getBead(i)->setVel(v);
91 }
92 }
93 return true;
94}
95
97 gmx_output_env_t *oenv;
98 gmx::TimeUnit timeunit = gmx::TimeUnit::Picoseconds;
99 XvgFormat xvg = XvgFormat::None;
100 output_env_init(&oenv, gmx::getProgramContext(), timeunit, FALSE, xvg, 0);
101 if (!read_next_frame(oenv, gmx_status_, &gmx_frame_)) {
102 return false;
103 }
104 output_env_done(oenv);
105
106 Eigen::Matrix3d m;
107 for (Index i = 0; i < 3; i++) {
108 for (Index j = 0; j < 3; j++) {
109 m(i, j) = gmx_frame_.box[j][i];
110 }
111 }
112 conf.setTime(gmx_frame_.time);
113 conf.setStep(gmx_frame_.step);
114 conf.setBox(m);
115
116 // conf.HasF( gmx_frame_.bF);
117
118 for (Index i = 0; i < gmx_frame_.natoms; i++) {
119 Eigen::Vector3d r = {gmx_frame_.x[i][XX], gmx_frame_.x[i][YY],
120 gmx_frame_.x[i][ZZ]};
121 conf.getBead(i)->setPos(r);
122 if (gmx_frame_.bF) {
123 Eigen::Vector3d f = {gmx_frame_.f[i][XX], gmx_frame_.f[i][YY],
124 gmx_frame_.f[i][ZZ]};
125 conf.getBead(i)->setF(f);
126 }
127 if (gmx_frame_.bV) {
128 Eigen::Vector3d v = {gmx_frame_.v[i][XX], gmx_frame_.v[i][YY],
129 gmx_frame_.v[i][ZZ]};
130 conf.getBead(i)->setVel(v);
131 }
132 }
133 return true;
134}
135
136} // namespace csg
137} // namespace votca
virtual void setPos(const Eigen::Vector3d &bead_position)
Definition basebead.h:161
void setF(const Eigen::Vector3d &bead_force)
Definition bead.h:356
void setVel(const Eigen::Vector3d &r)
Definition bead.h:315
bool FirstFrame(Topology &conf) override
read in the first frame
bool NextFrame(Topology &conf) override
read in the next frame
bool Open(const std::string &file) override
open a trejectory file
topology of the whole system
Definition topology.h:81
void setBox(const Eigen::Matrix3d &box, BoundaryCondition::eBoxtype boxtype=BoundaryCondition::typeAuto)
Definition topology.h:272
BeadContainer & Beads()
Definition topology.h:169
void setTime(double t)
Definition topology.h:311
Bead * getBead(const Index i)
Returns a pointer to the bead with index i.
Definition topology.h:227
void setStep(Index s)
Definition topology.h:323
Provides a means for comparing floating point numbers.
Definition basebead.h:33
Eigen::Index Index
Definition types.h:26