Eigenstate / vmd-python

Installable VMD as a python module
Other
129 stars 24 forks source link

Accessing volumetric data as numpy arrays #16

Open OleinikovasV opened 6 years ago

OleinikovasV commented 6 years ago

Dear developers! I got interested in using this module to employ VMD's volmap functionality to calculate density grids and do comparisons while in python environment. While I am successful in making the calculations (after loading vmd and a trajectory) via evaltcl: vmd.evaltcl('volmap density [atomselect 0 "name CA"] -res 1.0 -allframes -mol 0') However, I am only able to save the files as ".dx" via tcleval and no direct access to the grid data that could be further manipulated. Some manipulation is available through volutil package but it also just reads/writes ".dx" files and does not keep them as referable objects. It also is just passable through tcleval. (so hardly any upgrade from using a .tcl scripts).

Would it be possible to interface the volumetric data as 3D numpy arrays via *vmd.vmdnumpy** ? That would be fantastic!

Many thanks for your comments.

jvermaas commented 6 years ago

I think you'll want to look at the output of "help(atomsel)" after you've imported the atomsel interface in python. There is a mdffsim command that will get you the data directly. There is also a "get_volumetric" command within the "molecule" module that will get you a loaded volumetric dataset into a numpy friendly format.

jvermaas commented 6 years ago

Whoops, my bad. I introduced both of those features after 1.9.3 was released, so those features aren't included in these builds. In principle all you'd need to do is copy over py_molecule.C and py_atomsel.C from an alpha version of VMD or the public CVS repository.

Eigenstate commented 6 years ago

I do need to update the code to 1.9.4... the main obstacle to this is I need to upstream all of my Python 3 compatibility stuff and now everything is so out of sync it'll take me a while... This is on my to-do list :)

I do work with volumetric data a lot and use gridDataFormats from mdanalysis which lets me work with volumetric data as numpy arrays: https://www.mdanalysis.org/GridDataFormats/. It'll both read and write dx files.

OleinikovasV commented 6 years ago

In principle all you'd need to do is copy over py_molecule.C and py_atomsel.C from an alpha version of VMD or the public CVS repository.

@jvermaas , thanks, I have found now the previous thread about this in VMD mailing-list. The source code of the post 1.9.3 (alpha) release is still not available on the website. I have requested a CVS account, however.. Still hoping that you will be able to patch it here soonish :) Thanks a lot to you both!

jvermaas commented 6 years ago

Ok, I've updated the fork I've got of this, and added the updated version of py_molecule.C there. I'm not entirely positive that it works with python 3, mostly since I never tried.