SINGROUP / pycp2k

Python Cp2k interface
GNU Lesser General Public License v3.0
90 stars 28 forks source link

Support reading molecule through MDAnalysis? #11

Open xiki-tempula opened 3 years ago

xiki-tempula commented 3 years ago

Currently, the ASE is used for loading coordinate, box size and element information. I wonder if it is possible to load the data through MDAnalysis.Universe? The coordinate, cell, atom type can be accessed via

>>> from MDAnalysis import Universe
>>> from MDAnalysis.tests.datafiles import CRD
>>> u = Universe(CRD)
>>> u.dimensions
array([0., 0., 0., 0., 0., 0.], dtype=float32)
>>> u.atoms.positions
array([[-11.921,  26.307,  10.41 ],
       [-11.447,  26.741,   9.595],
       [-12.44 ,  27.042,  10.926],
       ...,
       [-12.616,  28.099,  21.258],
       [-13.786,  28.568,  21.198],
       [-12.417,  26.877,  21.494]], dtype=float32)
>>> u.atoms.types
array(['N', 'H', 'H', ..., 'C', 'O', 'O'], dtype=object)
lauri-codes commented 3 years ago

Hi @xiki-tempula,

The slightly inconvenient method would be to use MDAnalysis.Universe to fill the input tree manually, or first convert it into an ase.Atoms object and use create_cell/create_coords.

It should be extremely simple to also add support for MDAnalysis.Universe in the create_cell/create_coords methods. Do you think you could create a pull request for this implementation? I would be glad to include it.

xiki-tempula commented 3 years ago

@lauri-codes I will give it a try. I wonder how should one pass elements to pycp2k?