Skip to content
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

WIP: Dcd cython #929

Closed
wants to merge 26 commits into from
Closed

WIP: Dcd cython #929

wants to merge 26 commits into from

Conversation

kain88-de
Copy link
Member

@kain88-de kain88-de commented Aug 8, 2016

Superseeded by #1155

Fixes #659

Changes made in this Pull Request:

  • rewrite of dcd module in cython

This is a start to completely rewrite the DCD file handling in cython. It will get rid of the convoluted python/C class mixture we have right now and instead replace all DCD file handling in a cleanly wraped DCDFile object. DCDFile is an object that acts similar to normal filehandle in python similar to XTCFile and TRRFile. This should also help in #926.

At the current stage it is only possible to open/close files.

TODO Cython DCD Wrapper

  • read frames
  • seek frames
  • write frames
  • support TimeSeries
  • write tests
  • Error Handling (throwing good exceptions)

TODO Update MDAnalysis DCD formats based readers

  • DCDReader
  • use generic Reader test for DCDReader

PR Checklist

  • Tests?
  • Docs?
  • CHANGELOG updated?
  • Issue raised/referenced?

# always propagate exceptions forward
return False

def open(self, filename, mode='r'):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to make this seek like a file object? That's required for my 239 approach

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to make it seek like the XDRFile. It is on the list to add.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would that be enough for you or do you need more seek functionality?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm just reading through. I'd prefer if seek was what you call bytes_seek
else I'm going to have to have 2 versions of everything though.

On Mon, 8 Aug 2016, 14:20 Max Linke, [email protected] wrote:

In package/MDAnalysis/lib/formats/libdcd.pyx
#929 (comment):

  •    self.open(self.fname, mode)
    
  • def dealloc(self):
  •    self.close()
    
  • def enter(self):
  •    """Support context manager"""
    
  •    return self
    
  • def exit(self, exc_type, exc_val, exc_tb):
  •    """Support context manager"""
    
  •    self.close()
    
  •    # always propagate exceptions forward
    
  •    return False
    
  • def open(self, filename, mode='r'):

would that be enough for you or do you need more seek functionality?


You are receiving this because you commented.

Reply to this email directly, view it on GitHub
https://github.com/MDAnalysis/mdanalysis/pull/929/files/baacf8a81a69438abce49716167ff7e281bbec4a#r73873127,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AI0jB-PKn7kk-nSDAlcD--tdaMBY_hjGks5qdy0DgaJpZM4Jewd6
.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will also need a tell method if that's possible

On Mon, 8 Aug 2016, 14:21 Richard Gowers, [email protected] wrote:

I'm just reading through. I'd prefer if seek was what you call bytes_seek
else I'm going to have to have 2 versions of everything though.

On Mon, 8 Aug 2016, 14:20 Max Linke, [email protected] wrote:

In package/MDAnalysis/lib/formats/libdcd.pyx
#929 (comment):

  •    self.open(self.fname, mode)
    
  • def dealloc(self):
  •    self.close()
    
  • def enter(self):
  •    """Support context manager"""
    
  •    return self
    
  • def exit(self, exc_type, exc_val, exc_tb):
  •    """Support context manager"""
    
  •    self.close()
    
  •    # always propagate exceptions forward
    
  •    return False
    
  • def open(self, filename, mode='r'):

would that be enough for you or do you need more seek functionality?


You are receiving this because you commented.

Reply to this email directly, view it on GitHub
https://github.com/MDAnalysis/mdanalysis/pull/929/files/baacf8a81a69438abce49716167ff7e281bbec4a#r73873127,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AI0jB-PKn7kk-nSDAlcD--tdaMBY_hjGks5qdy0DgaJpZM4Jewd6
.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like I wrote this should be close to a normal file object. So it will also receive a tell.

@jdetle
Copy link
Contributor

jdetle commented Aug 8, 2016

So in #916 it came up that there should be a fastio method to read backwards across a DCD file. This would allow for easy negative stepping in the timeseries function. Should this be addressed here or elsewhere? Also I hope you're aware of the work already done by @arose on porting the DCD c files to python3 objects. https://github.com/arose/simpletraj/tree/master/simpletraj/dcd

@kain88-de
Copy link
Member Author

I haven't looked much into the API yet. But negative stepping should be possible with a random seek function. Which this class should get like the XDRFile class has.

About the fork atom @arose. I'm aware of that but I rather have a clean start then the messy dcd reader we have right now. The cython version will also be easier to maintain in the long run.

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,
in press.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of scope of the PR, but the citation is out of date.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See also MDAnalysis/MDAnalysis.github.io#27 – you could open a new issue for a new comment header on all files and we can discuss there what we want to put into the new header.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And now see #993.

@kain88-de kain88-de force-pushed the dcd-cython branch 2 times, most recently from e5aebd6 to 9bad8e7 Compare August 28, 2016 17:09
@kain88-de
Copy link
Member Author

See #187 #475 and mdtraj:#1163

@tylerjereddy
Copy link
Member

@kain88-de Is there any way to break the remaining work into manageable chunks? Like, you need a cdef function that can do X or Y, accepting these arguments, and returning this value? If I / others could potentially write a few cython functions, PR them to this branch pending your revisions, etc., that might help you focus on the tougher parts.

My Cython skills are getting a little more solid, but the interaction between the pyx file and the c code here is a bit overwhelming at first glance, making it difficult to identify specific tasks that need doing, though I suppose one could just try various .dcd file handling tasks to see what is missing.

@kain88-de
Copy link
Member Author

I've updated the first post with a more detailed todo list. The wrapper can now read frames and seek in the dcd file. tests for that would be nice. You can check the libmdaxdr as an example.

https://github.com/MDAnalysis/mdanalysis/blob/develop/testsuite/MDAnalysisTests/formats/test_libmdaxdr.py

note
I'm currently not doing any operations on the dimensions read from the dcd file. This is on purpose. It will allow the wrapper to handle more dcd files and we can implement the whole dimension unpacking that varies from charm and other tools at one place in the python code. Right now it is split between python and C.

@kain88-de
Copy link
Member Author

but the interaction between the pyx file and the c code here is a bit overwhelming at first glance

Yes it's not going to be the short and good looking wrapper I anticipated. But if you have any questions about the code. Just leave a comment.


def tell(self):
"""Get current frame"""
return self.current_frame
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like you already defined the tell() method above? Sorry -- I should have noticed that, but I just realized that my test was passing (once you told me about tell) before I fetched your update to this branch.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK I removed the last commit again

@tylerjereddy
Copy link
Member

Currently when I run nosetests test_libdcd.py in python 3.5 I get the following issue:

======================================================================
ERROR: Failure: ImportError (No module named 'c_distances_openmp')
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/treddy/.local/lib/python3.5/site-packages/nose-1.3.7-py3.5.egg/nose/failure.py", line 39, in runTest
    raise self.exc_val.with_traceback(self.tb)
  File "/Users/treddy/.local/lib/python3.5/site-packages/nose-1.3.7-py3.5.egg/nose/loader.py", line 418, in loadTestsFromName
    addr.filename, addr.module)
  File "/Users/treddy/.local/lib/python3.5/site-packages/nose-1.3.7-py3.5.egg/nose/importer.py", line 47, in importFromPath
    return self.importFromDir(dir_path, fqname)
  File "/Users/treddy/.local/lib/python3.5/site-packages/nose-1.3.7-py3.5.egg/nose/importer.py", line 94, in importFromDir
    mod = load_module(part_fqname, fh, filename, desc)
  File "/Users/treddy/anaconda/envs/py35/lib/python3.5/imp.py", line 234, in load_module
    return load_source(name, filename, file)
  File "/Users/treddy/anaconda/envs/py35/lib/python3.5/imp.py", line 172, in load_source
    module = _load(spec)
  File "<frozen importlib._bootstrap>", line 693, in _load
  File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 662, in exec_module
  File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
  File "/Users/treddy/python_modules/MDAnalysis/MDA_dev/mdanalysis/testsuite/MDAnalysisTests/formats/test_libdcd.py", line 8, in <module>
    from MDAnalysis.lib.formats.libdcd import DCDFile
  File "/Users/treddy/.local/lib/python3.5/site-packages/MDAnalysis-0.16.0.dev0-py3.5-macosx-10.5-x86_64.egg/MDAnalysis/__init__.py", line 158, in <module>
    from .lib import log
  File "/Users/treddy/.local/lib/python3.5/site-packages/MDAnalysis-0.16.0.dev0-py3.5-macosx-10.5-x86_64.egg/MDAnalysis/lib/__init__.py", line 30, in <module>
    from . import distances  # distances relies on mdamath
  File "/Users/treddy/.local/lib/python3.5/site-packages/MDAnalysis-0.16.0.dev0-py3.5-macosx-10.5-x86_64.egg/MDAnalysis/lib/distances.py", line 115, in <module>
    from c_distances_openmp import OPENMP_ENABLED as USED_OPENMP
ImportError: No module named 'c_distances_openmp'

Ideas? Is there an openmp issue with python 3 for MDA at the moment?

@tylerjereddy
Copy link
Member

I note that this happen on import of MDAnalysis in py35 as well, even though the install appears to work properly.

@richardjgowers
Copy link
Member

@tylerjereddy the c_distance_openmp library always gets built, if there's no openmp it just builds it in serial

If you want to rule out openmp completely, you can hack this line in setup.py to has_openmp=False

https://github.com/MDAnalysis/mdanalysis/blob/develop/package/setup.py#L277

@kain88-de
Copy link
Member Author

you should be able to set the openmp build in the setup.cfg

@tylerjereddy
Copy link
Member

The traceback persists even if I apply both approaches, git clean -xfd, and reinstall MDA under python 3.5. Maybe there's some kind of interference on my system from something else despite the usage of a separate conda py35 environment.

@jbarnoud
Copy link
Contributor

I get the same traceback when I try to run the tests on python 3. I tried to disable openmp in setup.cfg, but I still get the same error.

@richardjgowers
Copy link
Member

@jbarnoud looking at that again, you should be able to comment out that USED_OPENMP line and maybe it will work

@jbarnoud
Copy link
Contributor

@richardjgowers This seems to work as a workaround. I opened an issue to find a proper fix.

@kain88-de kain88-de closed this Feb 3, 2017
@kain88-de kain88-de deleted the dcd-cython branch January 24, 2018 19:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

DCD Module doesn't support Python 3
6 participants