Skip to content

Commit

Permalink
Improve support for ASE's io library (#238)
Browse files Browse the repository at this point in the history
1. Changes keyword argument in `from_multii_systems` for
file format from `fmt` to `ase_fmt` to not collide with the
keyword argument name used in `MultiSystems.from_file`.
2. Adds documentation to the main README and ASE plugin class

Co-authored-by: Han Wang <92130845+wanghan-iapcm@users.noreply.github.com>
Co-authored-by: Han Wang <wang_han@iapcm.ac.cn>
  • Loading branch information
3 people authored Jan 15, 2022
1 parent 59047e4 commit 25acc84
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,15 @@ The `System` or `LabeledSystem` can be constructed from the following file forma
| Gromacs | gro | True | False | System | 'gromacs/gro' |
| ABACUS | STRU | False | True | LabeledSystem | 'abacus/scf' |
| ABACUS | cif | True | True | LabeledSystem | 'abacus/md' |
| ase | structure | True | True | MultiSystems | 'ase/structure' |


The Class `dpdata.MultiSystems` can read data from a dir which may contains many files of different systems, or from single xyz file which contains different systems.

Use `dpdata.MultiSystems.from_dir` to read from a directory, `dpdata.MultiSystems` will walk in the directory
Recursively and find all file with specific file_name. Supports all the file formats that `dpdata.LabeledSystem` supports.

Use `dpdata.MultiSystems.from_file` to read from single file. Now only support quip/gap/xyz format file.
Use `dpdata.MultiSystems.from_file` to read from single file. Single-file support is available for the `quip/gap/xyz` and `ase/structure` formats.

For example, for `quip/gap xyz` files, single .xyz file may contain many different configurations with different atom numbers and atom type.

Expand Down
13 changes: 11 additions & 2 deletions dpdata/plugins/ase.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,20 @@

@Format.register("ase/structure")
class ASEStructureFormat(Format):
"""Format for the `Atomic Simulation Environment <https://wiki.fysik.dtu.dk/ase/>`_ (ase).
ASE supports parsing a few dozen of data formats. As described in i
`the documentation <ihttps://wiki.fysik.dtu.dk/ase/ase/io/io.html>`_,
many of these formats can be determined automatically.
Use the `ase_fmt` keyword argument to supply the format if
automatic detection fails.
"""

def from_labeled_system(self, data, **kwargs):
return data

def from_multi_systems(self, file_name, begin=None, end=None, step=None, fmt='traj', **kwargs):
frames = ase.io.read(file_name, format=fmt, index=slice(begin, end, step))
def from_multi_systems(self, file_name, begin=None, end=None, step=None, ase_fmt=None, **kwargs):
frames = ase.io.read(file_name, format=ase_fmt, index=slice(begin, end, step))
for atoms in frames:
symbols = atoms.get_chemical_symbols()
atom_names = list(set(symbols))
Expand Down

0 comments on commit 25acc84

Please sign in to comment.