-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrajectory.cpp
74 lines (68 loc) · 2.07 KB
/
trajectory.cpp
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include "trajectory.hh"
using namespace std;
trajectory::trajectory(int nr, int nt){
flag_init = true;
n_atoms = nr;
n_times = nt;
atoms = (atom**) malloc(nt * sizeof(atom*));
for(int t = 0; t < n_times; t++){
atoms[t] = (atom*) malloc(n_atoms * sizeof(atom));
}
bx = (box*) malloc(nt * sizeof(box));
}
trajectory::~trajectory(){
for(int t = 0; t < n_times; t++){
free(atoms[t]);
}
free(atoms);
free(bx);
}
void trajectory::load_traj_from_single_dump(bool flag_vel, bool flag_force, bool flage_normalized, bool flag_wrapped){
int iniLine = 5;
ifstream inputFile(dump_file_name);
if (!inputFile)
{
cout << "ERROR: no input file: " << dump_file_name << endl;
exit(1);
}
string temp;
int tempInd;
double x, y, z, tmpVal;
for(int t = 0; t < n_times; t++){
cout << "loading time: " << t << endl;
for(int j = 0; j < iniLine; j++){
getline(inputFile,temp);
}
inputFile >> bx[t].x_min >> bx[t].x_max ;
bx[t].cal_LX();
inputFile >> bx[t].y_min >> bx[t].y_max ;
bx[t].cal_LY();
inputFile >> bx[t].z_min >> bx[t].z_max ;
bx[t].cal_LZ();
getline(inputFile,temp);
getline(inputFile,temp);
for(int i = 0 ; i < n_atoms; i++){
inputFile >> tempInd;
if(flag_vel && flag_force && flage_normalized && !flag_wrapped){
inputFile >> atoms[t][tempInd - 1].type >> x >> y >> z >> atoms[t][tempInd - 1].f.x >> atoms[t][tempInd - 1].f.y >> atoms[t][tempInd - 1].f.z >> atoms[t][tempInd - 1].vel.x >> atoms[t][tempInd - 1].vel.y >> atoms[t][tempInd - 1].vel.z;
atoms[t][tempInd - 1].pos.x = x;
atoms[t][tempInd - 1].pos.y = y;
atoms[t][tempInd - 1].pos.z = z;
atoms[t][tempInd - 1].revert_norm(bx[t]);
atoms[t][tempInd - 1].posU = atoms[t][tempInd - 1].pos;
atoms[t][tempInd - 1].pos = atoms[t][tempInd - 1].apply_pbc(bx[t]);
}
}
getline(inputFile, temp);
}
inputFile.close();
}
void trajectory::set_dumpFile_path(string dump_path){
size_t spac;
spac = dump_path.find("*");
if(spac > 0 && spac <= dump_path.size()){
cout << "the dump_path for trajectories should not include *" << endl;
exit(12);
}
dump_file_name = dump_path;
}