Skip to content

Commit

Permalink
fix doctests
Browse files Browse the repository at this point in the history
  • Loading branch information
wojdyr committed Sep 20, 2023
1 parent 32e560f commit 398f931
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 10 deletions.
16 changes: 10 additions & 6 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,34 +51,38 @@
]

doctest_global_setup = '''
import os
import sys
assert sys.version_info[0] > 2, "Tests in docs are for Python 3 only"
disabled_features = []
try:
import numpy
except ImportError:
print('Tests that use NumPy are disabled.', file=sys.stderr)
disabled_features.append('NumPy')
numpy = None
try:
import pandas
except ImportError:
print('Tests that use pandas are disabled.', file=sys.stderr)
disabled_features.append('pandas')
pandas = None
try:
import networkx
except ImportError:
print('Tests that use networkx are disabled.', file=sys.stderr)
disabled_features.append('networkx')
networkx = None
try:
import pynauty
except ImportError:
print('Tests that use pynauty are disabled.', file=sys.stderr)
disabled_features.append('pynauty')
pynauty = None
import os
mdm2_unmerged_mtz_path = os.getenv('CCP4')
if mdm2_unmerged_mtz_path:
mdm2_unmerged_mtz_path += '/share/ccp4i2/demo_data/mdm2/mdm2_unmerged.mtz'
mdm2_unmerged_mtz_path += ('/lib/python3.7/site-packages/' +
'ccp4i2/demo_data/mdm2/mdm2_unmerged.mtz')
if not os.path.isfile(mdm2_unmerged_mtz_path):
mdm2_unmerged_mtz_path = None
if mdm2_unmerged_mtz_path is None:
disabled_features.append('$CCP4')
'''

def setup(app):
Expand Down
2 changes: 2 additions & 0 deletions docs/grid.rst
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ Unlike array slicing, these functions are aware of the cell repeat
(PBC) -- the block area is not limited by the unit cell boundaries.

.. doctest::
:skipif: numpy is None

>>> sub = gr.get_subarray(start=[3,3,3], shape=[2,3,4])
>>> sub.shape
Expand Down Expand Up @@ -443,6 +444,7 @@ as in NumPy MaskedArray.
The primary use for MaskedGrid is working with asymmetric unit (asu) only:

.. doctest::
:skipif: numpy is None

>>> asu = grid.masked_asu()
>>> asu # doctest: +ELLIPSIS
Expand Down
10 changes: 6 additions & 4 deletions docs/hkl.rst
Original file line number Diff line number Diff line change
Expand Up @@ -321,10 +321,10 @@ but they can be accessed directly if needed:
.. doctest::
:skipif: mdm2_unmerged_mtz_path is None

>>> batch.ints
>>> list(batch.ints)
[185, 29, 156, 0, -1, 1, -1, 0, 0, 0, 0, 0, 1, 0, 2, 1, 0, 1, 0, 1, 2, 0, 0, 0, 0, 0, 0, 0, 0]
>>> batch.floats[36:38] # start and end of phi
[80.0, 80.5]
>>> batch.floats[36], batch.floats[37] # start and end of phi
(80.0, 80.5)

One peculiarity of the MTZ format is that instead of the original Miller
indices it stores indices of the equivalent reflection in the ASU
Expand Down Expand Up @@ -1797,6 +1797,7 @@ The coefficients can be used to directly calculate the sum of Gaussians --
the structure factor contribution:

.. doctest::
:skipif: numpy is None

>>> fe_coef.calculate_sf(stol2=0.4) # argument: (sin(theta)/lambda)^2
9.303602485040315
Expand All @@ -1808,6 +1809,7 @@ In the simplest case, the atom's contribution to the electron density at a grid
point can be calculated as:

.. doctest::
:skipif: numpy is None

>>> # arguments are distance^2 and isotropic ADP
>>> fe_coef.calculate_density_iso(r2=2.3, B=50)
Expand Down Expand Up @@ -1973,7 +1975,7 @@ SpaceGroup because UnitCell already contains a list of symmetry operations).
Now we can compute structure factors from Model for any (hkl):

.. doctest::
:skipif: sys.platform == 'win32'
:skipif: sys.platform == 'win32' or numpy is None

>>> calc_e.calculate_sf_from_model(st[0], (3,4,5))
(54.50873699946033+53.39498671218277j)
Expand Down
2 changes: 2 additions & 0 deletions docs/mol.rst
Original file line number Diff line number Diff line change
Expand Up @@ -805,6 +805,8 @@ that has properties listed in the C++ section above. Examples:
import gemmi
output_path = 'out.pdb'
structure = gemmi.read_pdb('../tests/1orc.pdb')
print('Running doctest. Disabled features:',
', '.join(disabled_features) or 'none', file=sys.stderr)

.. testcode::

Expand Down

0 comments on commit 398f931

Please sign in to comment.