-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathflatten_xtc.cpp
134 lines (116 loc) · 3.93 KB
/
flatten_xtc.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
//
//
// This source code is part of
//
// M D S C T K
//
// Molecular Dynamics Spectral Clustering ToolKit
//
// VERSION 1.2.5
// Written by Joshua L. Phillips.
// Copyright (c) 2012-2016, Joshua L. Phillips.
// Check out http://www.cs.mtsu.edu/~jphillips/software.html for more
// information.
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as
// published by the Free Software Foundation; either version 2 of the
// License, or (at your option) any later version.
//
// If you want to redistribute modifications, please consider that
// derived work must not be called official MDSCTK. Details are found
// in the README & LICENSE files - if they are missing, get the
// official version at github.com/jlphillipsphd/mdsctk/.
//
// To help us fund MDSCTK development, we humbly ask that you cite the
// papers on the package - you can find them in the top README file.
//
// For more info, check our website at
// http://www.cs.mtsu.edu/~jphillips/software.html
//
//
// Local
#include "config.h"
#include "mdsctk.h"
int main(int argc, char* argv[]) {
const char* program_name = "flatten_xtc";
bool optsOK = true;
gmx::initForCommandLine(&argc,&argv);
copyright(program_name);
cout << " Exports the provided xtc file into a simple 32-bit." << endl;
cout << " flat file." << endl;
cout << endl;
cout << " Use -h or --help to see the complete list of options." << endl;
cout << endl;
// Option vars...
string xtc_filename;
string output_filename;
// Declare the supported options.
po::options_description cmdline_options;
po::options_description program_options("Program options");
program_options.add_options()
("help,h", "show this help message and exit")
("xtc-file,x", po::value<string>(&xtc_filename)->default_value("traj.xtc"), "Input: Trajectory file (string:filename)")
("output-file,o", po::value<string>(&output_filename)->default_value("traj.crd"), "Output: Flattened trajectory file (string:filename)")
;
cmdline_options.add(program_options);
po::variables_map vm;
po::store(po::parse_command_line(argc, argv, cmdline_options), vm);
po::notify(vm);
if (vm.count("help")) {
cout << "usage: " << program_name << " [options]" << endl;
cout << cmdline_options << endl;
return 1;
}
if (!optsOK) {
return -1;
}
cout << "Running with the following options:" << endl;
cout << "xtc-file = " << xtc_filename << endl;
cout << "output-file = " << output_filename << endl;
cout << endl;
// Main variables
int natoms;
int nframes = 0;
int lframes = 0;
int rframes = 0;
t_fileio *my_file;
ofstream outfile;
rvec* mycoords = NULL;
// Used when reading XTC files...
int step = 1;
float time = 0.0;
float start_time = 0.0;
matrix box;
float prec = 0.001;
gmx_bool bOK = 1;
// Get number of atoms and allocate data structures
my_file = open_xtc(xtc_filename.c_str(),"r");
read_first_xtc(my_file,&natoms, &step, &time, box, &mycoords, &prec, &bOK);
close_xtc(my_file);
my_file = open_xtc(xtc_filename.c_str(),"r");
mycoords = new rvec[natoms];
outfile.open(output_filename.c_str());
// Convert coordinates
while (read_next_xtc(my_file, natoms, &step, &time, box, mycoords, &prec, &bOK)) {
outfile.write((char*) mycoords, (sizeof(rvec)*natoms));
nframes++;
if (nframes == 1) {
start_time = time;
}
}
// Clean up
close_xtc(my_file);
outfile.close();
cout << "XTC Statistics - " << xtc_filename << endl;
cout << "Number of frames: " << nframes << endl;
cout << "Nunber of atoms: " << natoms << endl;
cout << "Start time: " << start_time << endl;
cout << "End time: " << time << endl;
cout << "Precision: " << prec << endl;
cout << endl;
cout << "All frames flattened..." << endl;
cout << endl;
delete [] mycoords;
return 0;
}