Skip to content

Polish documentation #77

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

Open
wants to merge 65 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
3fb7627
Fix project name typo.
clpetix Mar 19, 2025
4bb1806
Add community guidelines section with contribution instructions
clpetix Mar 19, 2025
7d6d8d7
Add statement of need to landing page.
clpetix Mar 19, 2025
3197ed1
Update copyright year to 2025.
clpetix Apr 14, 2025
fb2e8ad
Add overview sections to API docs.
clpetix Apr 14, 2025
680d240
Add examples to Box class.
clpetix Apr 14, 2025
28aeaf9
Make doc strings consistent formatting for booleans.
clpetix Apr 15, 2025
75b0378
Remove redundant :class: statements in docs.
clpetix Apr 17, 2025
97e1349
Make API documentation 1 landing page.
clpetix Apr 17, 2025
4b17744
Add installation instructions for conda.
clpetix Apr 17, 2025
e5250ea
Submodule topology rather than individual topology types.
clpetix Apr 21, 2025
0e932a9
Fix formatting of class references in docstrings
clpetix Apr 28, 2025
df2434f
Add sybil testing to documentation.
clpetix May 19, 2025
69ad6e7
Ensure doc test runs when sybil is installed
mayukh33 May 20, 2025
0502450
Add sybil to requirements.txt
mayukh33 May 21, 2025
3c4df67
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 21, 2025
e339421
Minor fix
mayukh33 May 21, 2025
e77577d
Add example to the data module
mayukh33 May 21, 2025
c281b46
Add example to the dump module
mayukh33 May 21, 2025
b073323
Move confest.py to root dir.
mayukh33 May 22, 2025
6ba53b5
Add documentation for snapshot
mayukh33 May 23, 2025
0e1c759
Minor fix to box documentation
mayukh33 May 23, 2025
fca1059
Modify data documentation
mayukh33 May 23, 2025
89cc9ba
Modify the dump file documentation
mayukh33 May 23, 2025
80e5469
Ensure doc test runs if gsd.hoomd is not installed
mayukh33 May 23, 2025
9e3b4fd
Modify snapshot doc to ensure doc test runs
mayukh33 May 23, 2025
bd53a4e
Modify documentation confest to run doc test
mayukh33 May 23, 2025
973b088
Add description to data module
mayukh33 May 27, 2025
2d50991
Add description for snapshot module
mayukh33 May 27, 2025
792f736
Add description for topology module
mayukh33 May 27, 2025
3d7797b
Revert single line description deletion
mayukh33 May 28, 2025
2e93508
Change directory structure to have a flat organization
mayukh33 May 28, 2025
0efea72
Add title to LabelMap method in topology
mayukh33 May 28, 2025
58adee8
Add custom template for module, method & attribute
mayukh33 May 28, 2025
2ab9a54
Add lammspio description to README.md
mayukh33 May 28, 2025
3f2f2c2
Add topology as a module
mayukh33 May 28, 2025
51089bb
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 28, 2025
14ac4b5
Add tutorial to the documentation
mayukh33 May 29, 2025
f78dfbd
Minor fix to topology doc
mayukh33 May 29, 2025
6e522d0
Merge branch 'main' into fix/documentation
mayukh33 May 29, 2025
051441b
Modify data module documentation
mayukh33 May 29, 2025
3c785f1
Modify dump module documentation
mayukh33 May 29, 2025
9f18304
Modify snapshot module documentation
mayukh33 May 29, 2025
b3d1640
Modify topology module documentation
mayukh33 May 29, 2025
945be1d
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 29, 2025
7cffe33
Merge branch 'main' into fix/documentation
mayukh33 May 29, 2025
3ac1681
Fix error in dump documentation
mayukh33 May 29, 2025
22a73bb
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 29, 2025
ea36934
Apply pre-commit fixes
mayukh33 May 29, 2025
2fd3dd6
Fix topology documentation
mayukh33 May 29, 2025
0c7c1b2
Add documentation to box from the tutorial
mayukh33 Jun 2, 2025
8c0b215
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 2, 2025
818070f
Fix pre-commit errors
mayukh33 Jun 2, 2025
15ef37c
Add array shapes for the methods
mayukh33 Jun 5, 2025
aa590cd
Merge branch 'main' into fix/documentation
mayukh33 Jun 5, 2025
55cfa5d
Add data types associated to numpy.ndarray
mayukh33 Jun 9, 2025
a4a2f9c
Fix pre-commit errors
mayukh33 Jun 9, 2025
5deb223
Minor fix
mayukh33 Jun 9, 2025
7087c51
Update numpy.ndarray type annotations in Box, Snapshot, and Topology …
mayukh33 Jun 9, 2025
39be512
Remove unnecessary blank line in Box class docstring
mayukh33 Jun 9, 2025
4ac1e72
Refactor dimer lattice tutorial
mayukh33 Jun 9, 2025
6fe4118
Fix docstring formatting for tilt property in Box class
mayukh33 Jun 9, 2025
1127dc4
Update dimer lattice tutorial
mayukh33 Jun 23, 2025
8b9f02b
Edit documentation
mphoward Jun 30, 2025
b0eb7ee
Fix test failures
mphoward Jun 30, 2025
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ __pycache__
build
*egg-info
env
doc/source/generated
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
ci:
autofix_prs: false
autoupdate_schedule: quarterly

repos:
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2021-2024, Auburn University
Copyright (c) 2021-2025, Auburn University

All rights reserved.

Expand Down
162 changes: 4 additions & 158 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
[![PyPI downloads](https://img.shields.io/pypi/dm/lammpsio)](https://pypi.org/project/lammpsio)
[![Conda](https://img.shields.io/conda/dn/conda-forge/lammpsio)](https://anaconda.org/conda-forge/lammpsio)

Tools for working with LAMMPS data and dump files.
lammpsio provides a Python interface for reading and writing LAMMPS
data and dump files. It also enables interconversion with HOOMD-blue's
GSD format. This flexible package enables users to work with LAMMPS files
in a variety of ways that improve workflow efficiency and reproducibility.

`lammpsio` is a pure Python package that can be installed using `pip`:

Expand All @@ -13,160 +16,3 @@ Tools for working with LAMMPS data and dump files.
or `conda`:

conda install -c conda-forge lammpsio

## Snapshot

The particle configuration is stored in a `Snapshot`. A `Snapshot` holds the
data for *N* particles, the simulation `Box`, and the timestep. The `Box` follows
the LAMMPS conventions for its shape and bounds. Here is a 3-particle
configuration in an orthorhombic box centered at the origin at step 100:

box = lammpsio.Box((-2,-3,-4), (2,3,4))
snapshot = lammpsio.Snapshot(3, box, step=100)

These constructor arguments are available as attributes:

- `N`: number of particles (int)
- `box`: bounding box (`Box`)
- `step`: timestep counter (int)
- `num_types`: number of particle types (int). If `num_types is None`, then the number of types is deduced from `typeid`.

The data contained in a `Snapshot` per particle is:

- `id`: (*N*,) array atom IDs (dtype: `int`, default: runs from 1 to *N*)
- `position`: (*N*,3) array of coordinates (dtype: `float`, default: `(0,0,0)`)
- `image`: (*N*,3) array of periodic image indexes (dtype: `int`, default: `(0,0,0)`)
- `velocity`: (*N*,3) array of velocities (dtype: `float`, default: `(0,0,0)`)
- `molecule`: (*N*,) array of molecule indexes (dtype: `int`, default: `0`)
- `typeid`: (*N*,) array of type indexes (dtype: `int`, default: `1`)
- `mass`: (*N*,) array of masses (dtype: `float`, default: `1`)
- `charge`: (*N*,) array of charges (dtype: `float`, default: `0`)
Comment on lines -36 to -43
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All these default values need to be documented in the Snapshot. See what I did to Topology for an example.


The optional topology data is:

- `type_label`: Labels of particle typeids. (`LabelMap`, default: `None`)
- `bonds`: Bond data (`Bonds`, default: `None`)
- `angles`: Angle data (`Angles`, default: `None`)
- `dihedrals`: Dihedral data (`Dihedrals`, default: `None`)
- `impropers`: Improper data (`Impropers`, default: `None`)

All values of indexes will follow the LAMMPS 1-indexed convention, but the
arrays themselves are 0-indexed.

The `Snapshot` will lazily initialize these per-particle arrays as they are
accessed to save memory. Hence, accessing a per-particle property will allocate
it to default values. If you want to check if an attribute has been set, use the
corresponding `has_` method instead (e.g., `has_position()`):

snapshot.position = [[0,0,0],[1,-1,1],[1.5,2.5,-3.5]]
snapshot.typeid[2] = 2
if not snapshot.has_mass():
snapshot.mass = [2.,2.,10.]

## Topology

The topology (bond information) can be stored in `Bonds`, `Angles`, `Dihedrals`,
and `Impropers` objects. All these objects function similarly, differing only in the
number of particles that are included in a connection (2 for a bond, 3 for an angle,
4 for a dihedral or improper). Each connection has an associated `id` and `typeid`.

```py
bonds = Bonds(N=3, num_types=2)
angles = Angles(N=2, num_types=1)
```
These constructor arguments are available as attributes:

- `N`: number of connections (int)
- `num_types`: number of connection types (int). If `num_types is None`, then the number of types is deduced from `typeid`.

The data contained per connection is:
- `members`: (*N*, *M*) array of particles IDs in each topology (dtype: `int`, default: `1`),
where *M* is the number of particles in a connection.
- `id`: (*N*,) array topology IDs (dtype: `int`, default: runs from 1 to *N*)
- `typeid`: (*N*,) array of type indexes (dtype: `int`, default: `1`)

A label (type) can be associated with a connection's typeid using a `type_label`.
- `type_label`: Labels of connection typeids. (`LabelMap`, default: `None`)

All values of indexes will follow the LAMMPS 1-indexed convention, but the
arrays themselves are 0-indexed. Lazy array initialization is used as for the `Snapshot`.

## Label maps

A `LabelMap` is effectively a dictionary associating a label (type) with a particle's
or connection's typeid. These labels can be useful for tracking the meaning of
typeids. They are also automatically used when interconverting with
HOOMD GSD files that require such labels.

The keys of the `LabelMap` are the typeids, and the values are the labels. A
`LabelMap` additionally has the following attributes:

- `types`: Types in label map. (dtype: `tuple`, default: `()`)
- `typeids`: Typeids in label map. (dtype: `tuple`, default: `()`)

## Data files

A LAMMPS data file is represented by a `DataFile`. The file must be explicitly
`read()` to get a `Snapshot`:

f = lammpsio.DataFile("config.data")
snapshot = f.read()

The `atom_style` will be read from the comment in the Atoms section
of the file. If it is not present, it must be specified in the `DataFile`.
If `atom_style` is specified and also present in the file, the two must match
or an error will be raised.

There are many sections that can be stored in a data file, but `lammpsio` does
not currently understand all of them. You can check `DataFile.known_headers`,
`DataFile.unknown_headers`, `DataFile.known_bodies` and `DataFile.unknown_bodies`
for lists of what is currently supported.

A `Snapshot` can be written using the `create()` method:

f = lammpsio.DataFile.create("config2.data", snapshot)

A `DataFile` corresponding to the new file is returned by `create()`.

## Dump files

A LAMMPS dump file is represented by a `DumpFile`. The actual file format is
very flexible, but by default embeds a schema that can be read:

traj = lammpsio.DumpFile(filename="atoms.lammpstrj")

If the schema does not exist for some reason, it can be manually specified as
a dictionary. Valid keys for the schema match the names and shapes in the
`Snapshot`. The keys requiring only 1 column index are: `id`, `typeid`,
`molecule`, `charge`, and `mass`. The keys requiring 3 column indexes are
`position`, `velocity`, and `image`.

LAMMPS will dump particles in an unknown order unless you have used the
`dump_modify sort` option. If you want particles to be ordered by `id` in the
`Snapshot`, use `sort_ids=True` (default).

A `DumpFile` is iterable, so you can use it to go through all the snapshots
of a trajectory:

for snap in traj:
print(snap.step)

You can also get the number of snapshots in the `DumpFile`, but this does
require reading the entire file: so use with caution!

num_frames = len(traj)

Random access to snapshots is not currently implemented, but it may be added
in future. If you want to randomly access snapshots, you should load the
whole file into a list:

snaps = [snap for snap in traj]
print(snaps[3].step)

Keep in the mind that the memory requirements for this can be huge!

A `DumpFile` can be created from a list of snapshots:

t = lammpsio.DumpFile.create("atoms.lammpstrj", schema, snaps)

The object representing the new file is returned and can be used.
40 changes: 40 additions & 0 deletions conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import numpy

try:
import sybil
import sybil.parsers.rest

except ImportError:
sybil = None

import lammpsio

try:
import gsd.hoomd

has_gsd = True
except ModuleNotFoundError:
has_gsd = False


def setup_sybil_tests(namespace):
"""Sybil setup function."""
# Common imports.
namespace["numpy"] = numpy
namespace["lammpsio"] = lammpsio
if has_gsd:
namespace["frame"] = gsd.hoomd.Frame()
else:
namespace["frame"] = 0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why 0 and not None? And why create the Frame() here, rather than where it's needed?

I would think you would want to optionally bind "gsd" or "gsd.hoomd" in the namespace, and set it to None if the import failed.



if sybil is not None:
pytest_collect_file = sybil.Sybil(
parsers=[
sybil.parsers.rest.PythonCodeBlockParser(),
sybil.parsers.rest.SkipParser(),
],
pattern="*.py",
setup=setup_sybil_tests,
fixtures=["tmp_path"],
).pytest()
8 changes: 4 additions & 4 deletions doc/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
furo
ipython==8.10.0
ipython==9.3.0
MyST-Parser
nbsphinx==0.8.12
sphinx==6.1.3
sphinx_design==0.4.1
nbsphinx==0.9.7
sphinx==8.1.3
sphinx_design==0.6.1
sphinx_favicon==1.0.1
29 changes: 29 additions & 0 deletions doc/source/_templates/autosummary/class.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{{ fullname | escape | underline}}

.. currentmodule:: {{ module }}

.. autoclass:: {{ objname }}

{% block methods %}
{% if methods %}
.. rubric:: {{ _('Methods:') }}

.. autosummary::
{% for item in methods %}
{%- if not item in ['__init__'] %}
~{{ name }}.{{ item }}
{%- endif -%}
{%- endfor %}
{% endif %}
{% endblock %}

{% block attributes %}
{% if attributes %}
.. rubric:: {{ _('Attributes:') }}

.. autosummary::
{% for item in attributes %}
~{{ name }}.{{ item }}
{%- endfor %}
{% endif %}
{% endblock %}
40 changes: 40 additions & 0 deletions doc/source/api.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
API
---

Particle data
=============

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add short summary paragraphs for the sections of the API. I did this for the topology section.

.. autosummary::
:nosignatures:
:toctree: generated/

lammpsio.Box
lammpsio.Snapshot
lammpsio.LabelMap

Topology
========

The topology (bond information) can be stored in `Bonds`, `Angles`, `Dihedrals`,
and `Impropers` objects. All these objects function similarly, differing only in
the number of particles that are included in a connection (2 for a bond, 3 for
an angle, 4 for a dihedral or improper).

.. autosummary::
:nosignatures:
:toctree: generated/

lammpsio.Angles
lammpsio.Bonds
lammpsio.Dihedrals
lammpsio.Impropers

File formats
============

.. autosummary::
:nosignatures:
:toctree: generated/

lammpsio.DataFile
lammpsio.DumpFile
6 changes: 0 additions & 6 deletions doc/source/api/box.rst

This file was deleted.

6 changes: 0 additions & 6 deletions doc/source/api/data.rst

This file was deleted.

6 changes: 0 additions & 6 deletions doc/source/api/dump.rst

This file was deleted.

6 changes: 0 additions & 6 deletions doc/source/api/snapshot.rst

This file was deleted.

6 changes: 0 additions & 6 deletions doc/source/api/topology.rst

This file was deleted.

4 changes: 3 additions & 1 deletion doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

# -- Project information -----------------------------------------------------

project = "lammmpsio"
project = "lammpsio"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You will need to add and configure the logo somewhere in here.

year = datetime.date.today().year
copyright = f"2021-{year}, Auburn University"
author = "Michael P. Howard"
Expand Down Expand Up @@ -65,6 +65,8 @@

autosummary_generate = True

autodoc_member_order = "bysource"

autodoc_default_options = {"inherited-members": None, "special-members": False}

# -- Options for intersphinx -------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion doc/source/guide/credits.rst → doc/source/credits.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ Credits
* Michael P. Howard
* Mayukh Kundu
* Philipp Leclercq
* C. Levi Petix
* C\. Levi Petix
3 changes: 0 additions & 3 deletions doc/source/guide/examples/index.rst

This file was deleted.

2 changes: 0 additions & 2 deletions doc/source/guide/release.md

This file was deleted.

Loading