Skip to content

Commit 25acc84

Browse files
WardLTwanghan-iapcmHan Wang
authored
Improve support for ASE's io library (#238)
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 <[email protected]> Co-authored-by: Han Wang <[email protected]>
1 parent 59047e4 commit 25acc84

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,15 @@ The `System` or `LabeledSystem` can be constructed from the following file forma
8282
| Gromacs | gro | True | False | System | 'gromacs/gro' |
8383
| ABACUS | STRU | False | True | LabeledSystem | 'abacus/scf' |
8484
| ABACUS | cif | True | True | LabeledSystem | 'abacus/md' |
85+
| ase | structure | True | True | MultiSystems | 'ase/structure' |
8586

8687

8788
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.
8889

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

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

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

dpdata/plugins/ase.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,20 @@
99

1010
@Format.register("ase/structure")
1111
class ASEStructureFormat(Format):
12+
"""Format for the `Atomic Simulation Environment <https://wiki.fysik.dtu.dk/ase/>`_ (ase).
13+
14+
ASE supports parsing a few dozen of data formats. As described in i
15+
`the documentation <ihttps://wiki.fysik.dtu.dk/ase/ase/io/io.html>`_,
16+
many of these formats can be determined automatically.
17+
Use the `ase_fmt` keyword argument to supply the format if
18+
automatic detection fails.
19+
"""
20+
1221
def from_labeled_system(self, data, **kwargs):
1322
return data
1423

15-
def from_multi_systems(self, file_name, begin=None, end=None, step=None, fmt='traj', **kwargs):
16-
frames = ase.io.read(file_name, format=fmt, index=slice(begin, end, step))
24+
def from_multi_systems(self, file_name, begin=None, end=None, step=None, ase_fmt=None, **kwargs):
25+
frames = ase.io.read(file_name, format=ase_fmt, index=slice(begin, end, step))
1726
for atoms in frames:
1827
symbols = atoms.get_chemical_symbols()
1928
atom_names = list(set(symbols))

0 commit comments

Comments
 (0)