-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtraj.cpp
More file actions
56 lines (44 loc) · 989 Bytes
/
traj.cpp
File metadata and controls
56 lines (44 loc) · 989 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include "traj.h"
using namespace std;
Traj::Traj(const char *xtcfile)
{
//get number of atoms
read_xtc_natoms((char*)xtcfile,&natoms);
//open xtc file
trj = xdrfile_open(xtcfile,"r");
if (trj == NULL) {
printf("ERROR: trajectory file %s cannot be read.\n",xtcfile);
exit(EXIT_FAILURE);
}
//initialize vars
nT = 0;
x = new rvec[natoms];
}
Traj::~Traj()
{
delete[] x;
xdrfile_close(trj);
}
//read next step of trajectory
int Traj::next(const bool convertFlag)
{
//read one timestep, returns 0 if success
int stat=read_xtc(trj,natoms,&step,&t,boxT,x,&prec);
//return if finished reading file
if (stat) return stat;
if (convertFlag) convert();
nT++;
return stat;
}
void Traj::convert()
{
for (int jj=0; jj<natoms; jj++)
for (int kk=0; kk<DIM; kk++)
x[jj][kk]*=A0INV;
for (int ii=0; ii<DIM; ii++)
box[ii]=boxT[ii][ii]*A0INV;
}
void Traj::getBox(rvec &out) const {
for (int kk=0; kk<DIM; kk++)
out[kk]=box[kk];
}