diff --git a/docs/conf.py b/docs/conf.py index da93d409..4272e940 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -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): diff --git a/docs/grid.rst b/docs/grid.rst index aee07514..f27e8d87 100644 --- a/docs/grid.rst +++ b/docs/grid.rst @@ -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 @@ -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 diff --git a/docs/hkl.rst b/docs/hkl.rst index 9ad77fcd..8cd5d77f 100644 --- a/docs/hkl.rst +++ b/docs/hkl.rst @@ -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 @@ -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 @@ -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) @@ -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) diff --git a/docs/mol.rst b/docs/mol.rst index 7fff8350..5c0d42a1 100644 --- a/docs/mol.rst +++ b/docs/mol.rst @@ -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::