Skip to content

Commit

Permalink
Add Chemfiles reader (#38)
Browse files Browse the repository at this point in the history
* add chemfiles and ase reader

* add chemfiles test

* update test

* pre-commit setup

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* update tests

* update READEM.md

* bump version

* support energies

* add cell

* support box

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
PythonFZ and pre-commit-ci[bot] authored May 16, 2023
1 parent ec6e781 commit 2b1a654
Show file tree
Hide file tree
Showing 15 changed files with 410 additions and 299 deletions.
44 changes: 44 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
default_language_version:
python: python3
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: check-added-large-files
- id: check-case-conflict
- id: check-docstring-first
- id: check-executables-have-shebangs
- id: check-json
- id: check-merge-conflict
args: ['--assume-in-merge']
- id: check-toml
- id: check-yaml
- id: debug-statements
- id: end-of-file-fixer
- id: mixed-line-ending
args: ['--fix=lf']
- id: sort-simple-yaml
- id: trailing-whitespace
- repo: https://github.com/psf/black
rev: 23.3.0
hooks:
- id: black
- repo: https://github.com/PyCQA/isort
rev: 5.12.0
hooks:
- id: isort
- repo: https://github.com/codespell-project/codespell
rev: v2.2.4
hooks:
- id: codespell
additional_dependencies: ["tomli"]
- repo: https://github.com/charliermarsh/ruff-pre-commit
# Ruff version.
rev: 'v0.0.267'
hooks:
- id: ruff
- repo: https://github.com/executablebooks/mdformat
rev: 0.7.16
hooks:
- id: mdformat
args: ["--wrap=80"]
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -248,4 +248,4 @@ CONTRIBUTION AGREEMENT

By contributing to the BVLC/caffe repository through pull-request, comment,
or otherwise, the contributor releases their content to the
license and copyright terms herein.
license and copyright terms herein.
34 changes: 25 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,18 @@

# ZnH5MD - High Performance Interface for H5MD Trajectories

ZnH5MD allows easy access to simulation results from H5MD trajectories.
It provides a Python interface and can convert existing data to H5MD files as well as export to other formats.
ZnH5MD allows easy access to simulation results from H5MD trajectories. It
provides a Python interface and can convert existing data to H5MD files as well
as export to other formats.

```
pip install znh5md["dask"]
```

## Example
In the following example we investigate an H5MD dump from LAMMPS with 1000 atoms and 201 configurations:

In the following example we investigate an H5MD dump from LAMMPS with 1000 atoms
and 201 configurations:

```python
import znh5md
Expand All @@ -38,13 +42,19 @@ for item in traj.position.batch(size=27, axis=0):
```

## ASE Atoms

You can use ZnH5MD to store ASE Atoms objects in the H5MD format.

> ZnH5MD does not support all features of ASE Atoms objects. It s important to note that unsupported parts are silently ignored and no error is raised.
> ZnH5MD does not support all features of ASE Atoms objects. It s important to
> note that unsupported parts are silently ignored and no error is raised.
> The ASEH5MD interface will not provide any time and step information.
> If you have a list of Atoms with different PBC values, you can use `znh5md.io.AtomsReader(atoms, use_pbc_group=True)`. This will create a `pbc` group in `box/` that also contains `step` and `time`. This is not an official H5MD specification so it can cause issues with other tools. If you don't specify this, the pbc of the first atoms in the list will be applied.
> If you have a list of Atoms with different PBC values, you can use
> `znh5md.io.AtomsReader(atoms, use_pbc_group=True)`. This will create a `pbc`
> group in `box/` that also contains `step` and `time`. This is not an official
> H5MD specification so it can cause issues with other tools. If you don't
> specify this, the pbc of the first atoms in the list will be applied.
```python
import znh5md
Expand All @@ -55,18 +65,24 @@ atoms: list[ase.Atoms]
db = znh5md.io.DataWriter(filename="db.h5")
db.initialize_database_groups()

db.add(znh5md.io.AtomsReader(atoms))
db.add(znh5md.io.AtomsReader(atoms)) # or znh5md.io.ChemfilesReader

data = znh5md.ASEH5MD("db.h5")
data.get_atoms_list() == atoms
```

## CLI

ZnH5MD provides a small set of CLI tools:

- `znh5md view <file.h5>` to view the File using `ase.visualize`
- `znh5md export <file.h5> <file.xyz>` to export the file to `.xyz` or any other supported file format
- `znh5md convert <file.xyz> <file.h5>` to save a `file.xyz` as `file.h5` in the H5MD standard.
- `znh5md export <file.h5> <file.xyz>` to export the file to `.xyz` or any other
supported file format
- `znh5md convert <file.xyz> <file.h5>` to save a `file.xyz` as `file.h5` in the
H5MD standard.

## More examples
A complete documentation is still work in progress. In the meantime, I can recommend looking at the tests, especially `test_znh5md.py` to learn more about slicing and batching.

A complete documentation is still work in progress. In the meantime, I can
recommend looking at the tests, especially `test_znh5md.py` to learn more about
slicing and batching.
Loading

0 comments on commit 2b1a654

Please sign in to comment.