Merge branch 'gromacs-2016'
This commit is contained in:
@ -17,6 +17,14 @@ Pygmx needs mainly two python packages to be installed, which are available in a
|
|||||||
|
|
||||||
Pygmx requires the shared library and header files of Gromacs 5.1 or higher to be installed.
|
Pygmx requires the shared library and header files of Gromacs 5.1 or higher to be installed.
|
||||||
|
|
||||||
|
Note that pygmx also supports the Gromacs-2016 version.
|
||||||
|
Checkout the followng git branch if this version of Gromacs is desired:
|
||||||
|
|
||||||
|
git checkout gromacs-2016
|
||||||
|
|
||||||
|
Note that Gromacs is backwards compatible, i. e. files produced by the 5.1 version will also work in the 2016 version.
|
||||||
|
But Gromacs-2016 is required to load files of the 2016 version.
|
||||||
|
|
||||||
#### Using a module
|
#### Using a module
|
||||||
|
|
||||||
If gromacs is installed as a module in your system, run
|
If gromacs is installed as a module in your system, run
|
||||||
|
@ -9,14 +9,15 @@ import os
|
|||||||
|
|
||||||
from .tpxio import TPXReader
|
from .tpxio import TPXReader
|
||||||
from .xtcio import XTCReader
|
from .xtcio import XTCReader
|
||||||
# from .enxio import EDRFile
|
from .enxio import EDRFile
|
||||||
from .errors import FileTypeError
|
from .errors import FileTypeError
|
||||||
from .gromacs.reader import index_filename_for_xtc
|
from .gromacs.reader import index_filename_for_xtc
|
||||||
from .gromacs.xtcindex import index_xtcfile
|
from .gromacs.xtcindex import index_xtcfile
|
||||||
|
|
||||||
FILE_EXTENSIONS = {
|
FILE_EXTENSIONS = {
|
||||||
'xtc': XTCReader,
|
'xtc': XTCReader,
|
||||||
'tpr': TPXReader
|
'tpr': TPXReader,
|
||||||
|
'edr': EDRFile,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
from cpython.array cimport array
|
from cpython.array cimport array
|
||||||
from array import array
|
from array import array
|
||||||
|
|
||||||
cimport numpy as np
|
#cimport numpy as np
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
from utility cimport *
|
from utility cimport *
|
||||||
@ -40,6 +40,7 @@ cdef extern from "gromacs/fileio/enxio.h":
|
|||||||
|
|
||||||
gmx_bool do_enx(ener_file_t ef, t_enxframe *fr)
|
gmx_bool do_enx(ener_file_t ef, t_enxframe *fr)
|
||||||
|
|
||||||
|
void free_enxframe(t_enxframe *ef)
|
||||||
|
|
||||||
|
|
||||||
cdef class EDRFile:
|
cdef class EDRFile:
|
||||||
@ -52,22 +53,29 @@ cdef class EDRFile:
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def types(self):
|
def types(self):
|
||||||
|
|
||||||
types = []
|
types = []
|
||||||
for i in range(self.n_etypes):
|
for i in range(self.n_etypes):
|
||||||
types.append(
|
types.append((self.etypes[i].name.decode(), self.etypes[i].unit.decode()))
|
||||||
|
return types
|
||||||
|
|
||||||
)
|
|
||||||
def read(self):
|
def read(self):
|
||||||
cdef t_enxframe *frame
|
cdef:
|
||||||
cdef np.ndarray[float, ndim=2] energies = np.empty((1,self.n_etypes), np.float32)
|
t_enxframe *frame
|
||||||
|
|
||||||
snew(frame, 1)
|
snew(frame, 1)
|
||||||
|
energies = array('f')
|
||||||
|
times = array('f')
|
||||||
|
|
||||||
|
i = 0
|
||||||
while do_enx(self.efile, frame):
|
while do_enx(self.efile, frame):
|
||||||
energies = np.resize(energies, (len(energies)+1, self.n_etypes))
|
times.append(frame.t)
|
||||||
for i in range(frame.nre):
|
for j in range(frame.nre):
|
||||||
energies[-1, i] = frame.ener[i].e
|
energies.append(frame.ener[j].e)
|
||||||
return energies
|
|
||||||
|
free_enxframe(frame)
|
||||||
|
sfree(frame)
|
||||||
|
|
||||||
|
return np.array(times), np.array(energies).reshape(len(times), self.n_etypes)
|
||||||
|
|
||||||
|
|
||||||
def __init__(self, filename):
|
def __init__(self, filename):
|
||||||
@ -77,7 +85,6 @@ cdef class EDRFile:
|
|||||||
|
|
||||||
self.etypes = NULL
|
self.etypes = NULL
|
||||||
do_enxnms(self.efile, &self.n_etypes, &self.etypes)
|
do_enxnms(self.efile, &self.n_etypes, &self.etypes)
|
||||||
print(self.n_etypes)
|
|
||||||
|
|
||||||
#do_enx(self.efile, self.frames)
|
#do_enx(self.efile, self.frames)
|
||||||
|
|
||||||
|
@ -2,14 +2,14 @@
|
|||||||
from utility cimport *
|
from utility cimport *
|
||||||
from math cimport *
|
from math cimport *
|
||||||
|
|
||||||
cdef extern from "gromacs/legacyheaders/types/energy.h":
|
cdef extern from "gromacs/trajectory/energy.h":
|
||||||
ctypedef struct t_energy:
|
ctypedef struct t_energy:
|
||||||
real e
|
real e
|
||||||
double eav
|
double eav
|
||||||
double esum
|
double esum
|
||||||
|
|
||||||
|
|
||||||
cdef extern from "gromacs/legacyheaders/types/inputrec.h":
|
|
||||||
|
cdef extern from "gromacs/mdtypes/inputrec.h":
|
||||||
ctypedef struct t_simtemp:
|
ctypedef struct t_simtemp:
|
||||||
pass
|
pass
|
||||||
ctypedef struct t_lambda:
|
ctypedef struct t_lambda:
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
|
|
||||||
|
from libc.stdio cimport FILE
|
||||||
|
|
||||||
from utility cimport *
|
from utility cimport *
|
||||||
from math cimport *
|
from math cimport *
|
||||||
from mdtypes cimport *
|
from mdtypes cimport *
|
||||||
@ -43,6 +45,10 @@ cdef extern from "gromacs/topology/atoms.h":
|
|||||||
ctypedef struct t_atomtypes:
|
ctypedef struct t_atomtypes:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
ctypedef struct t_grps:
|
||||||
|
int nr; # Number of different groups */
|
||||||
|
int *nm_ind; # Index in the group names */
|
||||||
|
|
||||||
#ctypedef t_atoms *t_atoms_ptr
|
#ctypedef t_atoms *t_atoms_ptr
|
||||||
|
|
||||||
cdef extern from "gromacs/topology/symtab.h":
|
cdef extern from "gromacs/topology/symtab.h":
|
||||||
@ -56,11 +62,32 @@ cdef extern from "gromacs/topology/block.h":
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
cdef extern from "gromacs/topology/idef.h":
|
cdef extern from "gromacs/topology/idef.h":
|
||||||
ctypedef struct t_ilist:
|
ctypedef struct t_ilist:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
ctypedef struct gmx_ffparams_t:
|
cdef enum t_ft_enum:
|
||||||
pass
|
F_LJ
|
||||||
|
|
||||||
|
ctypedef union t_iparams:
|
||||||
|
pass
|
||||||
|
|
||||||
|
ctypedef int t_functype
|
||||||
|
|
||||||
|
ctypedef struct gmx_cmap_t:
|
||||||
|
pass
|
||||||
|
|
||||||
|
ctypedef struct gmx_ffparams_t:
|
||||||
|
int ntypes;
|
||||||
|
int atnr;
|
||||||
|
t_functype *functype;
|
||||||
|
t_iparams *iparams;
|
||||||
|
double reppow; # The repulsion power for VdW: C12*r^-reppow */
|
||||||
|
real fudgeQQ; # The scaling factor for Coulomb 1-4: f*q1*q2 */
|
||||||
|
gmx_cmap_t cmap_grid; # The dihedral correction maps */
|
||||||
|
|
||||||
|
|
||||||
|
void pr_ffparams(FILE *fp, int indent, const char *title,
|
||||||
|
const gmx_ffparams_t *ffparams, gmx_bool bShowNumbers)
|
||||||
|
|
||||||
cdef extern from "gromacs/topology/topology.h":
|
cdef extern from "gromacs/topology/topology.h":
|
||||||
ctypedef struct gmx_moltype_t:
|
ctypedef struct gmx_moltype_t:
|
||||||
@ -81,6 +108,11 @@ cdef extern from "gromacs/topology/topology.h":
|
|||||||
|
|
||||||
ctypedef struct gmx_groups_t:
|
ctypedef struct gmx_groups_t:
|
||||||
pass
|
pass
|
||||||
|
# t_grps grps[0] # Groups of things */
|
||||||
|
# int ngrpname # Number of groupnames */
|
||||||
|
# char ***grpname # Names of the groups */
|
||||||
|
# int ngrpnr[0]
|
||||||
|
# unsigned char *grpnr[0] # Group numbers or NULL */
|
||||||
|
|
||||||
ctypedef struct gmx_mtop_t:
|
ctypedef struct gmx_mtop_t:
|
||||||
char **name # Name of the topology */
|
char **name # Name of the topology */
|
||||||
|
9586
pygmx/tpxio.c
Normal file
9586
pygmx/tpxio.c
Normal file
File diff suppressed because it is too large
Load Diff
@ -4,7 +4,7 @@
|
|||||||
from libc cimport stdio
|
from libc cimport stdio
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
cimport numpy as np
|
#cimport numpy as np
|
||||||
|
|
||||||
from utility cimport *
|
from utility cimport *
|
||||||
from math cimport *
|
from math cimport *
|
||||||
@ -34,7 +34,7 @@ cdef extern from "gromacs/fileio/tpxio.h":
|
|||||||
int *natoms,
|
int *natoms,
|
||||||
rvec *x,
|
rvec *x,
|
||||||
rvec *v,
|
rvec *v,
|
||||||
rvec *f,
|
# rvec *f,
|
||||||
gmx_mtop_t *mtop)
|
gmx_mtop_t *mtop)
|
||||||
|
|
||||||
|
|
||||||
@ -83,12 +83,17 @@ cdef atom_mass(t_atom atom):
|
|||||||
return atom.m
|
return atom.m
|
||||||
|
|
||||||
|
|
||||||
|
cdef index_groups_from_topology(gmx_mtop_t *topology):
|
||||||
|
# retrieve the index groups from the topology->groups ?
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
cdef open_tpx(const char* filename, t_inputrec *ir, matrix box, int *natoms, gmx_mtop_t *top):
|
cdef open_tpx(const char* filename, t_inputrec *ir, matrix box, int *natoms, gmx_mtop_t *top):
|
||||||
#cdef stdio.FILE *old_stderr = stdio.stderr
|
#cdef stdio.FILE *old_stderr = stdio.stderr
|
||||||
#stdio.stderr = stdio.freopen('tmp', 'w', stdio.stderr)
|
#stdio.stderr = stdio.freopen('tmp', 'w', stdio.stderr)
|
||||||
cdef char buffer[stdio.BUFSIZ]
|
cdef char buffer[stdio.BUFSIZ]
|
||||||
stdio.setbuf(stdio.stderr, buffer)
|
stdio.setbuf(stdio.stderr, buffer)
|
||||||
return_code = read_tpx(filename, ir, box, natoms, NULL, NULL, NULL, top)
|
return_code = read_tpx(filename, ir, box, natoms, NULL, NULL, top)
|
||||||
|
|
||||||
for i in range(stdio.BUFSIZ):
|
for i in range(stdio.BUFSIZ):
|
||||||
buffer[i] = 0
|
buffer[i] = 0
|
||||||
@ -97,6 +102,17 @@ cdef open_tpx(const char* filename, t_inputrec *ir, matrix box, int *natoms, gmx
|
|||||||
stdio.setbuf(stdio.stderr, NULL)
|
stdio.setbuf(stdio.stderr, NULL)
|
||||||
return return_code
|
return return_code
|
||||||
|
|
||||||
|
|
||||||
|
cdef read_ffparams(gmx_ffparams_t *ffparams, gmx_bool bShowNumbers):
|
||||||
|
cdef char buffer[stdio.BUFSIZ]
|
||||||
|
stdio.setbuf(stdio.stdout, buffer)
|
||||||
|
pr_ffparams(stdio.stdout, 0, '', ffparams, bShowNumbers)
|
||||||
|
stdio.fflush(stdio.stderr)
|
||||||
|
stdio.fseek(stdio.stderr, 0, stdio.SEEK_END)
|
||||||
|
stdio.setbuf(stdio.stderr, NULL)
|
||||||
|
return buffer
|
||||||
|
|
||||||
|
|
||||||
cdef class TPXReader:
|
cdef class TPXReader:
|
||||||
cdef:
|
cdef:
|
||||||
t_tpxheader header
|
t_tpxheader header
|
||||||
@ -178,6 +194,33 @@ cdef class TPXReader:
|
|||||||
types += mol_type * nmol
|
types += mol_type * nmol
|
||||||
return np.array(types)
|
return np.array(types)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def nsteps(self):
|
||||||
|
return self.input_record.nsteps
|
||||||
|
|
||||||
|
@property
|
||||||
|
def nstxout(self):
|
||||||
|
return self.input_record.nstxout
|
||||||
|
|
||||||
|
@property
|
||||||
|
def nstvout(self):
|
||||||
|
return self.input_record.nstvout
|
||||||
|
|
||||||
|
@property
|
||||||
|
def nstfout(self):
|
||||||
|
return self.input_record.nstfout
|
||||||
|
|
||||||
|
@property
|
||||||
|
def nstxout_compressed(self):
|
||||||
|
return self.input_record.nstxout_compressed
|
||||||
|
|
||||||
|
@property
|
||||||
|
def nstenergy(self):
|
||||||
|
return self.input_record.nstenergy
|
||||||
|
|
||||||
|
|
||||||
|
def read_ff(self):
|
||||||
|
return read_ffparams(&self.topology.ffparams, True)
|
||||||
|
|
||||||
def __cinit__(self, filename):
|
def __cinit__(self, filename):
|
||||||
filename = cstr(filename)
|
filename = cstr(filename)
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
# C-API in gromacs/utility
|
# C-API in gromacs/utility
|
||||||
|
|
||||||
#cdef extern from "inttypes.h":
|
from libc.stdint cimport int64_t
|
||||||
ctypedef unsigned long __int64
|
|
||||||
|
|
||||||
cdef extern from "gromacs/utility/basedefinitions.h":
|
cdef extern from "gromacs/utility/basedefinitions.h":
|
||||||
ctypedef int gmx_bool
|
ctypedef int gmx_bool
|
||||||
ctypedef __int64 gmx_int64_t
|
ctypedef int64_t gmx_int64_t
|
||||||
|
|
||||||
cdef extern from "gromacs/utility/real.h":
|
cdef extern from "gromacs/utility/real.h":
|
||||||
ctypedef double real
|
ctypedef double real
|
||||||
@ -15,6 +15,7 @@ cdef extern from "gromacs/utility/futil.h":
|
|||||||
|
|
||||||
cdef extern from "gromacs/utility/smalloc.h":
|
cdef extern from "gromacs/utility/smalloc.h":
|
||||||
void snew(void *ptr, int nelem)
|
void snew(void *ptr, int nelem)
|
||||||
|
void sfree(void *ptr)
|
||||||
|
|
||||||
|
|
||||||
cdef inline cstr(instr):
|
cdef inline cstr(instr):
|
||||||
|
0
pygmx/xtcindex.py
Normal file
0
pygmx/xtcindex.py
Normal file
@ -21,11 +21,11 @@ cdef extern from "gromacs/fileio/xtcio.h":
|
|||||||
void close_xtc(t_fileio *fio)
|
void close_xtc(t_fileio *fio)
|
||||||
|
|
||||||
int read_first_xtc(t_fileio *fio,
|
int read_first_xtc(t_fileio *fio,
|
||||||
int *natoms, int *step, real *time,
|
int *natoms, gmx_int64_t *step, real *time,
|
||||||
matrix box, rvec **x, real *prec, gmx_bool *_bOK)
|
matrix box, rvec **x, real *prec, gmx_bool *_bOK)
|
||||||
|
|
||||||
int read_next_xtc(t_fileio *fio,
|
int read_next_xtc(t_fileio *fio,
|
||||||
int natoms, int *step, real *time,
|
int natoms, gmx_int64_t *step, real *time,
|
||||||
matrix box, rvec *x, real *prec, gmx_bool *_bOK)
|
matrix box, rvec *x, real *prec, gmx_bool *_bOK)
|
||||||
|
|
||||||
|
|
||||||
@ -53,7 +53,8 @@ else:
|
|||||||
cdef array get_xtc_index(t_fileio *fio):
|
cdef array get_xtc_index(t_fileio *fio):
|
||||||
cdef:
|
cdef:
|
||||||
gmx_bool _bOK
|
gmx_bool _bOK
|
||||||
int natoms, step, frame, state = 1
|
int natoms, frame, state = 1
|
||||||
|
gmx_int64_t step
|
||||||
real time, prec
|
real time, prec
|
||||||
matrix box
|
matrix box
|
||||||
rvec *x
|
rvec *x
|
||||||
@ -71,10 +72,10 @@ cdef array get_xtc_index(t_fileio *fio):
|
|||||||
cdef class XTCReader:
|
cdef class XTCReader:
|
||||||
cdef:
|
cdef:
|
||||||
t_fileio *fio
|
t_fileio *fio
|
||||||
int natoms, cur_step
|
int natoms
|
||||||
|
gmx_int64_t cur_step
|
||||||
real start_time, timestep, prec, cur_time
|
real start_time, timestep, prec, cur_time
|
||||||
bint has_cache, has_times
|
bint has_cache, has_times
|
||||||
rvec *coords
|
|
||||||
array _cache, _times
|
array _cache, _times
|
||||||
public str filename
|
public str filename
|
||||||
|
|
||||||
@ -156,7 +157,7 @@ cdef class XTCReader:
|
|||||||
self.filename = filename.decode()
|
self.filename = filename.decode()
|
||||||
|
|
||||||
cdef:
|
cdef:
|
||||||
int step
|
gmx_int64_t step
|
||||||
matrix box
|
matrix box
|
||||||
gmx_bool _bOK
|
gmx_bool _bOK
|
||||||
real time, prec
|
real time, prec
|
||||||
@ -206,3 +207,33 @@ cdef class XTCReader:
|
|||||||
raise
|
raise
|
||||||
else:
|
else:
|
||||||
raise IndexError('Frame {} is out of range for trajectory of length {}.'.format(frame, len(self)))
|
raise IndexError('Frame {} is out of range for trajectory of length {}.'.format(frame, len(self)))
|
||||||
|
|
||||||
|
def __getstate__(self):
|
||||||
|
# state = self.__dict__.copy()
|
||||||
|
state = {}
|
||||||
|
state['natoms'] = self.natoms
|
||||||
|
state['cur_step'] = self.cur_step
|
||||||
|
state['start_time'] = self.start_time
|
||||||
|
state['timestep'] = self.timestep
|
||||||
|
state['prec'] = self.prec
|
||||||
|
state['cur_time'] = self.cur_time
|
||||||
|
state['has_cache'] = self.has_cache
|
||||||
|
state['has_times'] = self.has_times
|
||||||
|
state['_cache'] = self._cache
|
||||||
|
state['filename'] = self.filename
|
||||||
|
return state
|
||||||
|
|
||||||
|
def __setstate__(self, state):
|
||||||
|
self.natoms = state.pop('natoms')
|
||||||
|
self.cur_step = state.pop('cur_step')
|
||||||
|
self.start_time = state.pop('start_time')
|
||||||
|
self.timestep = state.pop('timestep')
|
||||||
|
self.prec = state.pop('prec')
|
||||||
|
self.cur_time = state.pop('cur_time')
|
||||||
|
self.has_cache = state.pop('has_cache')
|
||||||
|
self.has_times = state.pop('has_times')
|
||||||
|
self._cache = state.pop('_cache')
|
||||||
|
self.filename = state.pop('filename')
|
||||||
|
self.fio = open_xtc(self.filename.encode(), b'r')
|
||||||
|
|
||||||
|
#self.__dict__.update(state)
|
||||||
|
23
setup.py
23
setup.py
@ -22,11 +22,11 @@ if 'gromacs' in os.environ.get('LD_LIBRARY_PATH', ''):
|
|||||||
if 'gromacs' in p:
|
if 'gromacs' in p:
|
||||||
library_dirs.append(p)
|
library_dirs.append(p)
|
||||||
lib = p
|
lib = p
|
||||||
gmx_root = lib.split('lib')[0]
|
gmx_root = lib.split('lib')[0]
|
||||||
include = os.path.join(gmx_root, 'include')
|
include = os.path.join(gmx_root, 'include')
|
||||||
if os.path.exists(include):
|
if os.path.exists(include):
|
||||||
include_dirs.append(include)
|
include_dirs.append(include)
|
||||||
check_header_version(include)
|
check_header_version(include)
|
||||||
|
|
||||||
extensions = [
|
extensions = [
|
||||||
Extension(
|
Extension(
|
||||||
@ -55,13 +55,12 @@ extensions = [
|
|||||||
library_dirs=library_dirs,
|
library_dirs=library_dirs,
|
||||||
language='c++'
|
language='c++'
|
||||||
),
|
),
|
||||||
# Extension('pygmx.enxio',
|
Extension('pygmx.enxio',
|
||||||
# sources=['pygmx/enxio.pyx'],
|
sources=['pygmx/enxio.pyx'],
|
||||||
# include_dirs=include_dirs,
|
include_dirs=include_dirs,
|
||||||
# libraries=['gromacs'],
|
libraries=['gromacs'],
|
||||||
# library_dirs=library_dirs,
|
library_dirs=library_dirs,
|
||||||
# runtime_library_dirs=library_dirs,
|
language='c++'),
|
||||||
# language='c++'),
|
|
||||||
|
|
||||||
# Extension('pygmx.tngio',
|
# Extension('pygmx.tngio',
|
||||||
# sources=['pygmx/tngio.pyx'],
|
# sources=['pygmx/tngio.pyx'],
|
||||||
|
Reference in New Issue
Block a user