Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
88a3e0f
Update documentation for the relationship between CIF grammar and the…
janbridley Dec 8, 2025
39a9396
Fix string format
janbridley Dec 8, 2025
e283d39
Unix-style wildcards doc
janbridley Dec 8, 2025
aaf5ad5
Remove exclamation points
janbridley Dec 8, 2025
c498b9d
Clean up development guide
janbridley Dec 8, 2025
6db5a2a
Swap to RST link style for doc comment
janbridley Dec 8, 2025
f77c6f8
Update type hints
janbridley Dec 8, 2025
5e82c5c
Add type hints where they cannot be inferred
janbridley Dec 8, 2025
4d0ba4d
Standardize error handling for gemmi tests
janbridley Dec 8, 2025
d032730
Clean up unused TODOs
janbridley Dec 8, 2025
ea0e515
One straggler TODO
janbridley Dec 8, 2025
92ef1f3
Note TODO
janbridley Dec 8, 2025
3550eae
Swap note -> attention admonition
janbridley Dec 8, 2025
8b0e7ff
Swap to caution
janbridley Dec 8, 2025
81ef61a
One more caution
janbridley Dec 8, 2025
f9522b7
Add GSD requirement for testing
janbridley Dec 8, 2025
c66d871
Fix typos
janbridley Dec 8, 2025
2fef24d
Add HOOMD-Blue example and examples toc section
janbridley Dec 8, 2025
e083212
Add LAMMPS example
janbridley Dec 8, 2025
fe34e8d
Fix LAMMPS example
janbridley Dec 8, 2025
13b2823
Remove unused line
janbridley Dec 8, 2025
9398394
Add noisy data and fix headers
janbridley Dec 8, 2025
6357459
Final title
janbridley Dec 8, 2025
a8d80f4
Doctest LAMMPS output
janbridley Dec 8, 2025
239dc7e
Add example on numerical precision
janbridley Dec 9, 2025
81b0771
Update requirements file for py3.14
janbridley Dec 9, 2025
6ec6f29
Update changelog.rst
janbridley Dec 9, 2025
1b5be04
Fix label in CHANGELOG
janbridley Dec 9, 2025
ab33ab2
Pre-compile patterns for unit cell evaluation
janbridley Dec 10, 2025
4129943
Add example for setting Wyckoff sites
janbridley Dec 10, 2025
fbf40fb
Fix doctest-requires
janbridley Dec 10, 2025
21a5c3f
Add warning for setting structure
janbridley Dec 10, 2025
2287526
Fix type annotation
janbridley Dec 10, 2025
a624d3a
Include only necessary data
janbridley Dec 10, 2025
d3c189c
Merge branch 'doc/grammar' into feat/set_basis
janbridley Dec 10, 2025
84c08e3
sphinx-inline-tabs
janbridley Dec 12, 2025
6ca3a23
Description of Wyckoff postions
janbridley Dec 12, 2025
02c7740
Move up table and fix formatting
janbridley Dec 12, 2025
0860b82
Merge branch 'main' into feat/set_basis
janbridley Dec 12, 2025
ff427e7
Restore heading
janbridley Dec 12, 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
Prev Previous commit
Next Next commit
Add HOOMD-Blue example and examples toc section
  • Loading branch information
janbridley committed Dec 8, 2025
commit 2fef24d05e9484866a7c2eef5dcb247dbe6db382
88 changes: 88 additions & 0 deletions doc/source/example_simulation.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
Initializing Molecular Simulations with ``parsnip``
===================================================

When performing molecular simulations of solid materials, it is often useful to
initialize your system in a crystal structure. **parsnip** makes this extremely easy!

HOOMD-Blue
^^^^^^^^^^

HOOMD-Blue can operate directly on array data, so we can move data directly from
**parsnip** to the simulation itself.

.. testsetup::

>>> import os
>>> import numpy as np
>>> if "doc/source" not in os.getcwd(): os.chdir("doc/source")
>>> from parsnip import CifFile
>>> filename = "example_file.cif"
>>> cif = CifFile(filename)
>>> # Mock HOOMD import, as it is not available via pip install
>>> import gsd.hoomd as hoomd
>>> hoomd.Snapshot = hoomd.Frame
>>> snapshot = hoomd.Snapshot()
>>> # Pre-initialize the data arrays, as gsd does not support HOOMD's arr[:]
>>> # pattern for assignment. This data will be overwritten in the doctest.
>>> snapshot.particles.position = np.full((4, 3), -999.0)
>>> snapshot.particles.typeid = np.full((4,), -999)

.. doctest::

>>> import hoomd # doctest: +SKIP
>>> from parsnip import CifFile
>>> filename = "example_file.cif"
>>> cif = CifFile(filename)

>>> snapshot = hoomd.Snapshot() # doctest: +SKIP
>>> snapshot.particles.N = len(cif.build_unit_cell())
>>> snapshot.particles.position[:] = cif.build_unit_cell()
>>> snapshot.configuration.box = cif.box
>>> snapshot.particles.types = ["Particle"]

>>> snapshot.replicate(nx=2, ny=2, nz=3) # 2 x 2 x 3 supercell # doctest: +SKIP
>>> assert snapshot.particles.N == (2 * 2 * 3) * len(pos) # doctest: +SKIP


Once the snapshot is constructed, it can be attached to a simulation as follows:

.. doctest-skip::

>>> import hoomd
>>> simulation = hoomd.Simulation(device=hoomd.device.CPU())
>>> simulation.create_state_from_snapshot(snapshot)

If we want to extract additional data for our simulation, there are a few extra steps.
In HOOMD-Blue, ``particle.types`` are unique string identifiers that get mapped to
individual particles via the ``particles.typeid`` array. The following code extracts
``_atom_site_type_label`` data and assigns the "Cu" atom type to all particles. For
structures with multiple atom sites, the ``particles.typeid`` array will have nonzero
entries that correspond with other type labels.


.. doctest::

>>> from collections import defaultdict

>>> labels, pos = cif.build_unit_cell(additional_columns=["_atom_site_type_symbol"])
>>> # ... initialize the snapshot's `N`, `box`, and `position` data as above

>>> particle_type_map = defaultdict(list)
>>> for i, label in enumerate(labels.squeeze(axis=1)):
... particle_type_map[label].append(i)
>>> particle_type_map["Cu"] # Atoms 1-4 have the type symbol "Cu"
[0, 1, 2, 3]

>>> # Construct the TypeIDs that map our atomic symbol to the corresponding position
>>> typeid_array = np.ones(len(snapshot.particles.position), dtype=int)
>>> for typeid, label in enumerate(particle_type_map.keys()):
... typeid_array[particle_type_map[label]] = typeid
>>> snapshot.particles.typeid[:] = typeid_array
>>> snapshot.particles.typeid
array([0, 0, 0, 0])

>>> snapshot.particles.types = [str(key) for key in particle_type_map.keys()]
>>> snapshot.particles.types
['Cu']

>>> assert len(snapshot.particles.types) == len(cif["_atom_site_type_symbol"])
18 changes: 18 additions & 0 deletions doc/source/examples.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
.. _examples:

========
Examples
========

This tutorial provides a complete introduction to **parsnip**, including its place in
the broader simulation and data science ecosystems. We begin by illustrating how
**parsnip** aids in simulation initialization in two common libraries, HOOMD-Blue and
LAMMPS. We then highlight **parsnip**'s class-leading performance reconstructing noisy
experimental data. We conclude with a tutorial on using **parsnip** to generate new
structures from existing data.


.. toctree::
:maxdepth: 2

example_simulation
1 change: 1 addition & 0 deletions doc/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

installation
quickstart
examples


.. toctree::
Expand Down
Loading