-
Notifications
You must be signed in to change notification settings - Fork 652
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve xdr cython #3892
Merged
Merged
Improve xdr cython #3892
Changes from all commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
cf93942
incremental improvements to libmdaxdr
hmacdope 398afb7
fix wrong dims
hmacdope 3a493e3
add boundscheck=False
hmacdope f2ea113
slight improvement
hmacdope f2c440c
move to module level decls
hmacdope aeb118b
try read_direct
hmacdope 9a0d58e
fix frame iteration
hmacdope 1c7df37
use direct read into array for trr
hmacdope 943e699
experimental trr read
hmacdope 6c02836
Revert "experimental trr read"
hmacdope 4381b9b
add pxd for libmdaxdr
hmacdope b121911
make timestep fat
hmacdope ec43aed
add explanation
hmacdope dc45ce6
Merge remote-tracking branch 'upstream/develop' into improve_xdr_cython
hmacdope 64de6fc
change to xvf
hmacdope 572cc65
add some notes
hmacdope f36476c
test branching on ts.positions in _read_next_timestep
hmacdope 324a4d9
add CHANGELOG
hmacdope 0162b06
fix docs
hmacdope 1c583ef
add cdef
hmacdope cfa826e
Update package/MDAnalysis/lib/formats/libmdaxdr.pxd
hmacdope bd2313d
fix inheritance
hmacdope e7dac9b
add read failure error
hmacdope 2b223e0
fix changelog
hmacdope 907b852
add to libmdanalysis
hmacdope 77a537b
fix error code checking
hmacdope fa16ab5
Merge branch 'develop' into improve_xdr_cython
orbeckst 6749992
Consolidate licenses across top directory, testsuite and package (#3939)
hmacdope 7202bea
Merge remote-tracking branch 'upstream/develop' into improve_xdr_cython
hmacdope File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
# -*- Mode: python; tab-width: 4; indent-tabs-mode:nil; coding:utf-8 -*- | ||
# vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4 | ||
# | ||
# MDAnalysis --- https://www.mdanalysis.org | ||
# Copyright (c) 2006-2017 The MDAnalysis Development Team and contributors | ||
# (see the file AUTHORS for the full list of names) | ||
# | ||
# Released under the GNU Public Licence, v2 or any higher version | ||
# | ||
# Please cite your use of MDAnalysis in published work: | ||
# | ||
# R. J. Gowers, M. Linke, J. Barnoud, T. J. E. Reddy, M. N. Melo, S. L. Seyler, | ||
# D. L. Dotson, J. Domanski, S. Buchoux, I. M. Kenney, and O. Beckstein. | ||
# MDAnalysis: A Python package for the rapid analysis of molecular dynamics | ||
# simulations. In S. Benthall and S. Rostrup editors, Proceedings of the 15th | ||
# Python in Science Conference, pages 102-109, Austin, TX, 2016. SciPy. | ||
# doi: 10.25080/majora-629e541a-00e | ||
# | ||
# N. Michaud-Agrawal, E. J. Denning, T. B. Woolf, and O. Beckstein. | ||
# MDAnalysis: A Toolkit for the Analysis of Molecular Dynamics Simulations. | ||
# J. Comput. Chem. 32 (2011), 2319--2327, doi:10.1002/jcc.21787 | ||
# | ||
|
||
import numpy as np | ||
cimport numpy as np | ||
|
||
np.import_array() | ||
from libc.stdint cimport int64_t | ||
|
||
from libc.stdio cimport SEEK_SET, SEEK_CUR, SEEK_END | ||
|
||
cdef extern from 'include/xdrfile.h': | ||
ctypedef struct XDRFILE: | ||
pass | ||
|
||
XDRFILE* xdrfile_open (char * path, char * mode) | ||
int xdrfile_close (XDRFILE * xfp) | ||
int xdr_seek(XDRFILE *xfp, int64_t pos, int whence) | ||
int64_t xdr_tell(XDRFILE *xfp) | ||
ctypedef float matrix[3][3] | ||
ctypedef float rvec[3] | ||
|
||
|
||
cdef extern from 'include/xdrfile_xtc.h': | ||
int read_xtc_natoms(char * fname, int * natoms) | ||
int read_xtc(XDRFILE * xfp, int natoms, int * step, float * time, matrix box, | ||
rvec * x, float * prec) | ||
int write_xtc(XDRFILE * xfp, int natoms, int step, float time, matrix box, | ||
rvec * x, float prec) | ||
|
||
|
||
|
||
cdef extern from 'include/xdrfile_trr.h': | ||
int read_trr_natoms(char *fname, int *natoms) | ||
int read_trr(XDRFILE *xfp, int natoms, int *step, float *time, float *_lambda, | ||
matrix box, rvec *x, rvec *v, rvec *f, int *has_prop) | ||
int write_trr(XDRFILE *xfp, int natoms, int step, float time, float _lambda, | ||
matrix box, rvec *x, rvec *v, rvec *f) | ||
|
||
|
||
cdef extern from 'include/xtc_seek.h': | ||
int read_xtc_n_frames(char *fn, int *n_frames, int *est_nframes, int64_t **offsets) | ||
|
||
|
||
cdef extern from 'include/trr_seek.h': | ||
int read_trr_n_frames(char *fn, int *n_frames, int *est_nframes, int64_t **offsets) | ||
|
||
|
||
cdef class _XDRFile: | ||
"""Base python wrapper for gromacs-xdr formats | ||
|
||
This class can be similar to the normal file objects in python. The read() | ||
function will return a frame and all information in it instead of a single | ||
line. Additionally the context-manager protocoll is supported as well. | ||
|
||
Note | ||
---- | ||
This class can't be initialized; use one of the subclasses :class:`XTCFile` or :class:`TRRFile`. | ||
""" | ||
# number of atoms | ||
cdef readonly int n_atoms | ||
# whether the file is open | ||
cdef int is_open | ||
# whether we have reached the end of the file | ||
cdef int reached_eof | ||
# the XDR file pointer | ||
cdef XDRFILE *xfp | ||
# the name of the xdr file | ||
cdef readonly fname | ||
# the current frame in the file | ||
cdef int current_frame | ||
# the file mode | ||
cdef str mode | ||
# the simulation box | ||
cdef np.ndarray box | ||
# numpy array of offsets into the fle | ||
cdef np.ndarray _offsets | ||
# whether we have the offsets | ||
cdef readonly int _has_offsets | ||
|
||
|
||
cdef class XTCFile(_XDRFile): | ||
"""File-like wrapper for gromacs XTC files.""" | ||
# precision of the XTC file | ||
cdef float precision | ||
|
||
|
||
|
||
cdef class TRRFile(_XDRFile): | ||
"""File-like wrapper for gromacs TRR files""" |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add under Fixes: XTC and TRR readers now fail with IOError when a status except EOK (=0) is detected on reading a frame instead of silently continuing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some readers had enough redundancy built in to avoid not continuing with
retcode != EOK
but at least its now done consistently.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was the pattern that protected some branches
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, good to know that we probably do not change a lot of behavior. Nevertheless, the current approach is cleaner.
(Btw, while somewhere I came across my own explanation of why TRR stops with EINTEGER and I think it was related to not being able to read the magic number.)