biotite.database.rcsb.fetch

biotite.database.rcsb.fetch(pdb_ids, format, target_path=None, overwrite=False, verbose=False)[source]

Download structure files from the RCSB PDB in various formats.

This function requires an internet connection.

Parameters
pdb_idsstr or iterable object of str

A single PDB ID or a list of PDB IDs of the structure(s) to be downloaded .

formatstr

The format of the files to be downloaded. 'pdb', 'pdbx', 'cif', 'mmcif' or 'mmtf' are allowed. However, 'pdbx', 'cif' and 'mmcif' are synonyms for the same format.

target_pathstr, optional

The target directory of the downloaded files. By default, the file content is stored in a file-like object (StringIO or BytesIO, respectively).

overwritebool, optional

If true, existing files will be overwritten. Otherwise the respective file will only be downloaded if the file does not exist yet in the specified target directory. (Default: False)

verbose: bool, optional

If true, the function will output the download progress. (Default: False)

Returns
filesstr or StringIO or BytesIO or list of (str or StringIO or BytesIO)

The file path(s) to the downloaded files. If a single string (a single ID) was given in pdb_ids, a single string is returned. If a list (or other iterable object) was given, a list of strings is returned. If no target_path was given, the file contents are stored in either StringIO or BytesIO objects.

Warning

Even if you give valid input to this function, in rare cases the database might return no or malformed data to you. In these cases the request should be retried. When the issue occurs repeatedly, the error is probably in your input.

Examples

>>> import os.path
>>> files = fetch(["1l2y", "3o5r"], "cif", path_to_directory)
>>> print([os.path.basename(file) for file in files])
['1l2y.cif', '3o5r.cif']