{"action":"created","issue":{"url":"https://api.github.com/repos/MDAnalysis/mdanalysis/issues/419","labels_url":"https://api.github.com/repos/MDAnalysis/mdanalysis/issues/419/labels{/name}","comments_url":"https://api.github.com/repos/MDAnalysis/mdanalysis/issues/419/comments","events_url":"https://api.github.com/repos/MDAnalysis/mdanalysis/issues/419/events","html_url":"https://github.com/MDAnalysis/mdanalysis/issues/419","id":105272756,"number":419,"title":"rewrite xdrlib","user":{"login":"kain88-de","id":4302678,"avatar_url":"https://avatars.githubusercontent.com/u/4302678?v=3","gravatar_id":"","url":"https://api.github.com/users/kain88-de","html_url":"https://github.com/kain88-de","followers_url":"https://api.github.com/users/kain88-de/followers","following_url":"https://api.github.com/users/kain88-de/following{/other_user}","gists_url":"https://api.github.com/users/kain88-de/gists{/gist_id}","starred_url":"https://api.github.com/users/kain88-de/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kain88-de/subscriptions","organizations_url":"https://api.github.com/users/kain88-de/orgs","repos_url":"https://api.github.com/users/kain88-de/repos","events_url":"https://api.github.com/users/kain88-de/events{/privacy}","received_events_url":"https://api.github.com/users/kain88-de/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/MDAnalysis/mdanalysis/labels/Component-Readers","name":"Component-Readers","color":"0052cc"},{"url":"https://api.github.com/repos/MDAnalysis/mdanalysis/labels/Format-Gromacs","name":"Format-Gromacs","color":"006b75"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-09-07T22:23:13Z","updated_at":"2015-09-08T08:33:20Z","closed_at":null,"body":"I've been thinking about the way to best port the old xdrlib code to cython. I noticed that the old code basically reads like no information about the xtc in the beginning and after that only checks the xyz data and time.\r\n\r\nMy current idea is to write a class that acts as a file handle with the follwing API methods.\r\n\r\n```python\r\ndef number_atoms(self)\r\n    return self._natoms\r\n\r\ndef frame(self, SEEK)\r\n    # magic\r\n    return xyz, time\r\n\r\ndef next_frame(self):\r\n    # magic\r\n    return xyz, time\r\n```\r\n\r\nInside this class is all of the error handling from the xdrlib done, if anything happens an exception is raised. The class should also work with context managers. This should best encapsulate xtc parsing.\r\n\r\nThis should also allow simple usages like this for quick and dirty xtc parsing\r\n\r\n```python\r\nwith xtc_parser(fname) as xtc:\r\n    while not xtc.eof():\r\n        xyz, time = xtc.next_frame()\r\n```\r\n\r\nDid I miss some important information that we need to get from the xtc as well? And could this be a good approach for the DCD parser as well? If so then we could simplify/unify quite a bit of the coordinate parsing."},"comment":{"url":"https://api.github.com/repos/MDAnalysis/mdanalysis/issues/comments/138477778","html_url":"https://github.com/MDAnalysis/mdanalysis/issues/419#issuecomment-138477778","issue_url":"https://api.github.com/repos/MDAnalysis/mdanalysis/issues/419","id":138477778,"user":{"login":"richardjgowers","id":9249543,"avatar_url":"https://avatars.githubusercontent.com/u/9249543?v=3","gravatar_id":"","url":"https://api.github.com/users/richardjgowers","html_url":"https://github.com/richardjgowers","followers_url":"https://api.github.com/users/richardjgowers/followers","following_url":"https://api.github.com/users/richardjgowers/following{/other_user}","gists_url":"https://api.github.com/users/richardjgowers/gists{/gist_id}","starred_url":"https://api.github.com/users/richardjgowers/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/richardjgowers/subscriptions","organizations_url":"https://api.github.com/users/richardjgowers/orgs","repos_url":"https://api.github.com/users/richardjgowers/repos","events_url":"https://api.github.com/users/richardjgowers/events{/privacy}","received_events_url":"https://api.github.com/users/richardjgowers/received_events","type":"User","site_admin":false},"created_at":"2015-09-08T08:33:20Z","updated_at":"2015-09-08T08:33:20Z","body":"I've been tidying the API from the top down, so various implementations (DCD) are a little messy at the bottom.  The basic gist of it is a Reader holds a Timestep object.  The Reader fills the Timestep object with data and returns it.\r\n\r\nIf you look in `coordinates/base.py` there's the ProtoReader class which basically needs the following two methods to be defined by subclasses:\r\n * `_read_next_timestep()` - fill Timestep with whatever is next in the trajectory\r\n * `_read_frame()` - seek randomly and grab this frame (not everyone can seek easily, so optional)"}}