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

Improve support for ASE's io library #238

Merged
merged 6 commits into from
Jan 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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