diff --git a/package/MDAnalysis/fetch/__init__.py b/package/MDAnalysis/fetch/__init__.py index 1ebe1c8bd1c..d1df792601f 100644 --- a/package/MDAnalysis/fetch/__init__.py +++ b/package/MDAnalysis/fetch/__init__.py @@ -34,6 +34,6 @@ """ -__all__ = ["from_PDB"] +__all__ = ["from_pdb"] -from .pdb import from_PDB +from .pdb import from_pdb diff --git a/package/MDAnalysis/fetch/pdb.py b/package/MDAnalysis/fetch/pdb.py index 5820035d301..656f917d8a2 100644 --- a/package/MDAnalysis/fetch/pdb.py +++ b/package/MDAnalysis/fetch/pdb.py @@ -39,7 +39,7 @@ Functions --------- -.. autofunction:: from_PDB +.. autofunction:: from_pdb """ from pathlib import Path @@ -72,7 +72,7 @@ ) -def from_PDB( +def from_pdb( pdb_ids, cache_path=None, progressbar=False, @@ -84,7 +84,7 @@ def from_PDB( Given one or multiple PDB IDs, downloads the corresponding structure files format and stores them in a local cache directory. If files are cached on - disk, *from_PDB* will skip the download and use the cached version instead. + disk, *from_pdb* will skip the download and use the cached version instead. Returns the path(s) as a :class:`~pathlib.Path` to the downloaded file(s). @@ -140,22 +140,24 @@ def from_PDB( -------- Download a single PDB file: - >>> mda.fetch.from_PDB("1AKE", file_format="cif") + >>> import MDAnalysis as mda + >>> from MDAnalysis.fetch import from_pdb + >>> from_pdb("1AKE", file_format="cif") './MDAnalysis_pdbs/1AKE.cif' Download multiple PDB files with a progress bar: - >>> mda.fetch.from_PDB(["1AKE", "4BWZ"], progressbar=True) + >>> mda.fetch.from_pdb(["1AKE", "4BWZ"], progressbar=True) ['./MDAnalysis_pdbs/1AKE.pdb.gz', './MDAnalysis_pdbs/4BWZ.pdb.gz'] Download a single PDB file and convert it to a universe: - >>> mda.Universe(mda.fetch.from_PDB("1AKE"), file_format="pdb.gz") + >>> mda.Universe(mda.fetch.from_pdb("1AKE"), file_format="pdb.gz") Download multiple PDB files and convert each of them into a universe: - >>> [mda.Universe(pdb) for pdb in mda.fetch.from_PDB(["1AKE", "4BWZ"], progressbar=True)] + >>> [mda.Universe(pdb) for pdb in mda.fetch.from_pdb(["1AKE", "4BWZ"], progressbar=True)] [, ] @@ -164,7 +166,7 @@ def from_PDB( if not HAS_POOCH: raise ModuleNotFoundError( - "pooch is needed as a dependency for from_PDB()" + "pooch is needed as a dependency for from_pdb()" ) elif file_format not in SUPPORTED_FILE_FORMATS_DOWNLOADER: raise ValueError( diff --git a/package/MDAnalysis/lib/formats/libdcd.pyx b/package/MDAnalysis/lib/formats/libdcd.pyx index 3400fd4ae84..3f31e41ff25 100644 --- a/package/MDAnalysis/lib/formats/libdcd.pyx +++ b/package/MDAnalysis/lib/formats/libdcd.pyx @@ -138,10 +138,12 @@ cdef class DCDFile: Examples -------- - >>> from MDAnalysis.lib.formats.libdcd import DCDFile - >>> with DCDFile('foo.dcd') as f: - >>> for frame in f: - >>> print(frame.x) + .. code-block:: python + + with DCDFile("trajectory.dcd") as dcd: + header = dcd.header + for frame in dcd: + print(frame.x) Notes diff --git a/package/MDAnalysis/lib/formats/libmdaxdr.pyx b/package/MDAnalysis/lib/formats/libmdaxdr.pyx index 4a691b3ae95..7bdeda7c6c0 100644 --- a/package/MDAnalysis/lib/formats/libmdaxdr.pyx +++ b/package/MDAnalysis/lib/formats/libmdaxdr.pyx @@ -401,10 +401,11 @@ cdef class TRRFile(_XDRFile): Examples -------- - >>> from MDAnalysis.lib.formats.libmdaxdr import TRRFile - >>> with TRRFile('foo.trr') as f: - >>> for frame in f: - >>> print(frame.x) + .. code-block:: python + + with TRRFile("trajectory.trr") as f: + for frame in f: + print(frame.x) Notes ----- @@ -705,10 +706,11 @@ cdef class XTCFile(_XDRFile): Examples -------- - >>> from MDAnalysis.lib.formats.libmdaxdr import XTCFile - >>> with XTCFile('foo.trr') as f: - >>> for frame in f: - >>> print(frame.x) + .. code-block:: python + + with XTCFile("trajectory.xtc") as f: + for frame in f: + print(frame.x) Notes ----- diff --git a/package/MDAnalysis/lib/transformations.py b/package/MDAnalysis/lib/transformations.py index 27e5f01db9f..b3b2cd937bd 100644 --- a/package/MDAnalysis/lib/transformations.py +++ b/package/MDAnalysis/lib/transformations.py @@ -794,7 +794,8 @@ def decompose_matrix(matrix): True >>> S = scale_matrix(0.123) >>> scale, shear, angles, trans, persp = decompose_matrix(S) - >>> scale[0] + >>> result = float(scale[0]) + >>> result 0.123 >>> R0 = euler_matrix(1, 2, 3) >>> scale, shear, angles, trans, persp = decompose_matrix(R0) diff --git a/package/MDAnalysis/lib/util.py b/package/MDAnalysis/lib/util.py index 0f497892f13..ec4d45592b6 100644 --- a/package/MDAnalysis/lib/util.py +++ b/package/MDAnalysis/lib/util.py @@ -505,9 +505,12 @@ def greedy_splitext(p): ------- >>> from MDAnalysis.lib.util import greedy_splitext - >>> greedy_splitext("/home/joe/protein.pdb.bz2") - ('/home/joe/protein', '.pdb.bz2') - + >>> import os + >>> path, ext = greedy_splitext("/home/joe/protein.pdb.bz2") + >>> path == '/home/joe' + os.path.sep + 'protein' + True + >>> ext == '.pdb.bz2' + True """ path, root = os.path.split(p) extension = "" diff --git a/package/doc/doctest/.gitignore b/package/doc/doctest/.gitignore new file mode 100644 index 00000000000..abfa32a3f9c --- /dev/null +++ b/package/doc/doctest/.gitignore @@ -0,0 +1,5 @@ +# Sphinx doctree cache +.doctrees/ + +# Doctest output +output.txt diff --git a/package/doc/sphinx/.gitignore b/package/doc/sphinx/.gitignore new file mode 100644 index 00000000000..3d932eab753 --- /dev/null +++ b/package/doc/sphinx/.gitignore @@ -0,0 +1,2 @@ +# Generated binary test data +frame.data diff --git a/package/doc/sphinx/source/documentation_pages/lib/formats/libmdaxdr.rst b/package/doc/sphinx/source/documentation_pages/lib/formats/libmdaxdr.rst deleted file mode 100644 index f6cca2f9f4d..00000000000 --- a/package/doc/sphinx/source/documentation_pages/lib/formats/libmdaxdr.rst +++ /dev/null @@ -1,3 +0,0 @@ -.. automodule:: MDAnalysis.lib.formats.libmdaxdr - :members: - :inherited-members: diff --git a/testsuite/MDAnalysisTests/fetch/test_from_PDB.py b/testsuite/MDAnalysisTests/fetch/test_from_PDB.py index 881490680bc..12d26a10184 100644 --- a/testsuite/MDAnalysisTests/fetch/test_from_PDB.py +++ b/testsuite/MDAnalysisTests/fetch/test_from_PDB.py @@ -53,9 +53,9 @@ def test_pooch_installation(tmp_path): with pytest.raises( ModuleNotFoundError, - match="pooch is needed as a dependency for from_PDB()", + match="pooch is needed as a dependency for from_pdb()", ): - mda.fetch.from_PDB("1AKE", cache_path=tmp_path, file_format="cif") + mda.fetch.from_pdb("1AKE", cache_path=tmp_path, file_format="cif") @pytest.mark.skipif(not HAS_POOCH, reason="Pooch is not installed.") @@ -64,18 +64,18 @@ def test_pooch_installation(tmp_path): reason="Can not connect to https://files.wwpdb.org/", ) class TestDocstringExamples: - """This class tests all the examples found in from_PDB's docstring""" + """This class tests all the examples found in from_pdb's docstring""" @pytest.mark.parametrize("pdb_id", ["1AKE", "4BWZ"]) def test_one_file_download(self, tmp_path, pdb_id): - path = mda.fetch.from_PDB( + path = mda.fetch.from_pdb( pdb_id, cache_path=tmp_path, file_format="cif" ) assert isinstance(path, Path) assert Path(path).name == f"{pdb_id}.cif" def test_multiple_files_download(self, tmp_path): - list_of_path_strings = mda.fetch.from_PDB( + list_of_path_strings = mda.fetch.from_pdb( ["1AKE", "4BWZ"], cache_path=tmp_path, progressbar=True ) assert all(isinstance(pdb_id, Path) for pdb_id in list_of_path_strings) @@ -93,7 +93,7 @@ def test_multiple_files_download(self, tmp_path): ) def test_files_to_universe(self, tmp_path, pdb_id, n_atoms): u = mda.Universe( - mda.fetch.from_PDB( + mda.fetch.from_pdb( pdb_id, file_format="pdb.gz", cache_path=tmp_path, @@ -118,11 +118,11 @@ def clean_up_default_cache(): class TestExpectedBehaviors: def test_no_cache_path(self, clean_up_default_cache): - assert isinstance(mda.fetch.from_PDB("1AKE", cache_path=None), Path) + assert isinstance(mda.fetch.from_pdb("1AKE", cache_path=None), Path) def test_str_input_gives_path_output(self, tmp_path): assert isinstance( - mda.fetch.from_PDB( + mda.fetch.from_pdb( pdb_ids="1AKE", cache_path=tmp_path, file_format="cif" ), Path, @@ -130,7 +130,7 @@ def test_str_input_gives_path_output(self, tmp_path): def test_list_input_gives_list_output(self, tmp_path): assert isinstance( - mda.fetch.from_PDB(pdb_ids=["1AKE"], cache_path=tmp_path), list + mda.fetch.from_pdb(pdb_ids=["1AKE"], cache_path=tmp_path), list ) @@ -143,7 +143,7 @@ class TestExpectedErrors: def test_invalid_pdb(self, tmp_path): with pytest.raises(HTTPError): - mda.fetch.from_PDB(pdb_ids="foobar", cache_path=tmp_path) + mda.fetch.from_pdb(pdb_ids="foobar", cache_path=tmp_path) def test_invalid_file_format(self, tmp_path): with pytest.raises( @@ -153,6 +153,6 @@ def test_invalid_file_format(self, tmp_path): f"are {SUPPORTED_FILE_FORMATS_DOWNLOADER}" ), ): - mda.fetch.from_PDB( + mda.fetch.from_pdb( pdb_ids="1AKE", cache_path=tmp_path, file_format="barfoo" )