Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
60f205f
WIP on doctests
janbridley Jan 15, 2025
474d8eb
Add sphinx-copybutton and notfound
janbridley Jan 15, 2025
1b8d934
messy wip on sybil
janbridley Jan 15, 2025
6ec1619
Further wip
janbridley Jan 15, 2025
f22e876
Remove .doctrees
janbridley Jan 15, 2025
90cd64a
Remove CIFTEST
janbridley Jan 15, 2025
8ed9575
Swap to pytest-doctestplus
janbridley Jan 15, 2025
6511b22
Remove unused files
janbridley Jan 15, 2025
186148b
Clean up settings
janbridley Jan 15, 2025
9cbd851
Fix read_cell_params interaction with cast_values
janbridley Jan 15, 2025
445f199
Clean up conf.py
janbridley Jan 15, 2025
a3c17f2
Update filepath for docstrings
janbridley Jan 15, 2025
3e18f34
Clean up pyproject.toml
janbridley Jan 15, 2025
1c89cfa
Fix formatting for doctests
janbridley Jan 15, 2025
2640240
Finalize indentation for quickstart.rst
janbridley Jan 15, 2025
9b8a429
Update requirements.in files
janbridley Jan 15, 2025
ae30d9c
Update doc/requirements.txt
janbridley Jan 15, 2025
a4ed0ae
Update requirements files
janbridley Jan 15, 2025
49efea4
Fix return None example
janbridley Jan 15, 2025
38fcb7b
Lint
janbridley Jan 15, 2025
eb9ec19
Fix pytest-doctestplus version
janbridley Jan 15, 2025
22ceb58
Update `cell` to return box-like
janbridley Jan 16, 2025
6837f40
Clarify docs for CifFile.cell
janbridley Jan 16, 2025
0dfb7d4
Final cleanup of freud tests
janbridley Jan 16, 2025
170c986
Install freud on ubuntu-latest tests
janbridley Jan 16, 2025
d2b5fc4
Add missing doctest: +SKIP
janbridley Jan 16, 2025
bfa08da
Use pytest importorskip
janbridley Jan 16, 2025
959f3df
Remove freud from ci
janbridley Jan 16, 2025
a049245
Fix doctest-requires block
janbridley Jan 16, 2025
7ae4ff4
Standardize spelling of angstrom
janbridley Jan 16, 2025
7331d04
Rename cell to box
janbridley Jan 16, 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
Fix formatting for doctests
  • Loading branch information
janbridley committed Jan 15, 2025
commit 1c89cfa8df9d72ee9e6211a920a0fc1b6cf23d36
80 changes: 40 additions & 40 deletions doc/source/quickstart.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ Let's assume we have the file my_file.cif in the current directory, and these ar
Reading Keys
^^^^^^^^^^^^


Now, let's read extract the key-value pairs from our cif file. This subset of data
usually contains information to reconstruct the system's unit cell, and provides
information regarding the origin of the data.


.. testsetup::

>>> import os
>>> os.chdir("doc/source")
>>> if "doc/source" not in os.getcwd(): os.chdir("doc/source")

.. doctest::

Expand All @@ -28,34 +28,33 @@ information regarding the origin of the data.
>>> cif = CifFile(filename)

>>> cif.pairs
{
... '_journal_year': '1999',
... '_journal_page_first': '0',
... '_journal_page_last': '123',
... '_chemical_name_mineral': "'Copper FCC'",
... '_chemical_formula_sum': "'Cu'",
... '_cell_length_a': '3.6',
... '_cell_length_b': '3.6',
... '_cell_length_c': '3.6',
... '_cell_angle_alpha': '90.0',
... '_cell_angle_beta': '90.0',
... '_cell_angle_gamma': '90.0'
... '_symmetry_space_group_name_H-M': 'Fm-3m'
... }
{'_journal_year': '1999',
'_journal_page_first': '0',
'_journal_page_last': '123',
'_chemical_name_mineral': "'Copper FCC'",
'_chemical_formula_sum': "'Cu'",
'_cell_length_a': '3.6',
'_cell_length_b': '3.6',
'_cell_length_c': '3.6',
'_cell_angle_alpha': '90.0',
'_cell_angle_beta': '90.0',
'_cell_angle_gamma': '90.0',
'_symmetry_space_group_name_H-M': "'Fm-3m'"}


A `dict`-like getter syntax is provided to key-value pairs. Single keys function exactly
as a python dict, while lists of keys return lists of values. Keys not present in the
:attr:`~.pairs` dict instead return :code:`None`.

.. doctest:: python
.. doctest::

>>> cif["_journal_year"]
'1999'

>>> cif["_not_in_pairs"]
... None

>>> # Multiple keys can be accessed simultaneously!
# Multiple keys can be accessed simultaneously!
>>> cif[["_cell_length_a", "_cell_length_b", "_cell_length_c"]]
['3.6', '3.6', '3.6']

Expand All @@ -65,7 +64,7 @@ be lossy. Setting the :attr:`~.cast_values` property to :code:`True` reprocesses
data, converting to float or int where possible. Note that once data is reprocessed,
a new CifFile object must be created to restore the original string data

.. doctest:: python
.. doctest::

>>> cif.cast_values = True # Reprocess our `pairs` dict

Expand Down Expand Up @@ -97,30 +96,25 @@ list of such arrays, although the :attr:`~.get_from_loops` method is often more
convenient.


.. doctest:: python

.. doctest::

>>> len(cif.loops)
2

>>> cif.loops[0]
array(
... [[('Cu1', '0.0000000000', '0.0000000000', '0.0000000000', 'Cu', 'a')]],
... dtype=[
... ('_atom_site_label', '<U12'),
... ('_atom_site_fract_x', '<U12'),
... ('_atom_site_fract_y', '<U12'),
... ('_atom_site_fract_z', '<U12'),
... ('_atom_site_type_symbol', '<U12'),
... ('_atom_site_Wyckoff_label', '<U12')
... ]
... )
array([[('Cu1', '0.0000000000', '0.0000000000', '0.0000000000', 'Cu', 'a')]],
dtype=[
('_atom_site_label', '<U12'),
('_atom_site_fract_x', '<U12'),
('_atom_site_fract_y', '<U12'),
('_atom_site_fract_z', '<U12'),
('_atom_site_type_symbol', '<U12'),
('_atom_site_Wyckoff_label', '<U12')])

>>> cif.loops[0]["_atom_site_label"]
array([['Cu1']], dtype='<U12')


>>> # (Unstructured) slices of tables can be easily accessed!
# (Unstructured) slices of tables can be easily accessed!
>>> xyz = cif.get_from_loops(["_atom_site_fract_x", "_atom_site_fract_y", "_atom_site_fract_z"])

>>> xyz
Expand Down Expand Up @@ -153,10 +147,16 @@ file), set :code:`fractional=False`

.. _`freud`: https://freud.readthedocs.io/en/latest/modules/data.html#freud.data.UnitCell

.. doctest:: python
.. doctest::

>>> cif.build_unit_cell(fractional=True)
array([[0. , 0. , 0. ],
[0. , 0.5, 0.5],
[0.5, 0. , 0.5],
[0.5, 0.5, 0. ]])


.. doctest-requires:: freud

>>> pos = cif.build_unit_cell(fractional=True)
array([[0. , 0. , 0. ],
... [0. , 0.5, 0.5],
... [0.5, 0. , 0.5],
... [0.5, 0.5, 0. ]])
>>> import freud
>>> raise ValueError