-
Notifications
You must be signed in to change notification settings - Fork 1
/
gmxsystem.h
104 lines (80 loc) · 2.7 KB
/
gmxsystem.h
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
#ifndef GMXSYSTEM_H_
#define GMXSYSTEM_H_
#ifndef CPLUSPLUS
#define CPLUSPLUS 1
#endif
#include "mdsystem.h"
#include "trrfile.h"
#include "xtcfile.h"
#include "grofile.h"
namespace gromacs {
//! The template class forms the basis for working with gromacs systems and reading coordinate files. Both TRR and XTC file formats are available. To load either, the appropriate class type has to be used in the template. TRRFile for .trr, and XTCFile for xtc
template <class T>
class GMXSystem : public MDSystem {
public:
GMXSystem (const std::string gro_filepath, const std::string xdr_filepath);
void LoadNext ();
void LoadFirst ();
Atom_ptr_vec& Atoms () { return _gro.Atoms(); }
AtomPtr Atoms (const int index) { return _gro.Atoms(index); }
Atom_it begin () { return _gro.begin(); }
Atom_it end () { return _gro.end(); }
Mol_ptr_vec& Molecules () { return _gro.Molecules(); }
Mol_it begin_mols () const { return _gro.begin_mols(); }
Mol_it end_mols () const { return _gro.end_mols(); }
MolPtr Molecules (int index) { return _gro.Molecules(index); }
int NumMols () const { return _gro.NumMols(); }
AtomPtr operator[] (int index) { return _gro[index]; }
int NumAtoms () const { return (int)_gro.NumAtoms(); }
int size () const { return (int)_gro.size(); }
//! output to stdout some info parsed from the .gro file
void PrintGROInfo () const { _gro.Print(); }
//! output (lot's of) info parsed from the xdr/trajectory file
void PrintXDRInfo () const { _xdr.PrintInfo(); }
private:
gromacs::GROFile _gro;
//! either TRRFile or XTCFile
T _xdr;
void _ParseMolecules ();
};
template <class T>
GMXSystem<T>::GMXSystem (const std::string gro_filepath, const std::string xdrfile_path)
// ***** need to figure out how to delegate either trr or xtc files here ****
:
_gro(gro_filepath), _xdr(xdrfile_path)
{
this->_ParseMolecules();
}
template <class T>
void GMXSystem<T>::LoadFirst() {
_xdr.LoadFirst();
this->_ParseMolecules();
}
template <class T>
void GMXSystem<T>::LoadNext() {
_xdr.LoadNext();
this->_ParseMolecules();
}
template <>
void GMXSystem<XTCFile>::_ParseMolecules () {
VecR_it coord_it = _xdr.begin_coords();
for (Atom_it it = _gro.begin(); it != _gro.end(); it++) {
(*it)->Position(*coord_it);
++coord_it;
}
}
template <>
void GMXSystem<TRRFile>::_ParseMolecules () {
VecR_it coord_it = _xdr.begin_coords();
VecR_it vel_it = _xdr.begin_vels();
VecR_it force_it = _xdr.begin_forces();
for (Atom_it it = _gro.begin(); it != _gro.end(); it++) {
(*it)->Position(*coord_it);
(*it)->Force(*force_it);
++coord_it;
++vel_it;
++force_it;
}
}
} // namespace gromacs
#endif