4040---------
4141
4242.. autofunction:: from_PDB
43+ .. autofunction:: from_DOI
4344
4445"""
4546
@@ -180,10 +181,10 @@ def from_PDB(
180181 )
181182
182183
183- def from_DOI (doi , file_name , cache_path = None , remove_prefix = True ):
184+ def from_DOI (doi , file_name , remove_prefix = True , cache_path = None ):
184185 """
185- Download one or more files given the Digital Object Identifier (DOI).
186- them locally.
186+ Download one or more files given the Digital Object Identifier (DOI)
187+ and store them locally.
187188
188189 Given one DOI, this function downloads one or multiple file names from
189190 the repository and stores them in a local cache directory. If files
@@ -195,51 +196,43 @@ def from_DOI(doi, file_name, cache_path=None, remove_prefix=True):
195196 Parameters
196197 ----------
197198 doi: str
198- the name of a links o
199- file_name, : str
200- The file extension/format to download (e.g., "cif", "pdb").
201- See the Notes section below for a list of all supported file formats.
199+ The Digital Object Identifier (DOI) of the file(s) to download.
200+ file_name : str or list of str
201+ The name(s) of the file(s) to download from the repository.
202+ remove_prefix : bool
203+ If True, remove the prefix (e.g., "https://doi.org/") from the DOI string.
204+ Default is True.
202205 cache_path : str or pathlib.Path
203206 Directory where downloaded file(s) will be cached.
204207 The default ``None`` argument uses the :mod:`pooch` default cache with
205208 project name :data:`DEFAULT_CACHE_NAME_DOWNLOADER`.
206- remove_prefix : bool
207- If True, display a progress bar during file downloads. Default
208- is False.
209+
209210
210211 Returns
211212 -------
212213 :class:`~pathlib.Path` or list of :class:`~pathlib.Path`
213214 The path(s) to the downloaded file(s). Returns a single
214- :class:`~pathlib.Path` if a single pdb id is given, or a list of
215- :class:`~pathlib.Path` if multiple pdb ids are provided.
215+ :class:`~pathlib.Path` if a single DOI is given, or a list of
216+ :class:`~pathlib.Path` if multiple DOIs are provided.
216217
217218 Raises
218219 ------
219220 ValueError
220- For an invalid file format. Supported file formats are under Notes .
221+ For an invalid DOI link. See Notes for more information .
221222
222223 :class:`requests.exceptions.HTTPError`
223- If an invalid PDB code is specified.
224-
224+ If an invalid file_name is specified.
225+
225226 Notes
226227 -----
227- This function uses the `RCSB File Download Services`_ for directly
228- downloading structure files via https.
228+ The DOI link, as specified by `doi`, should be in the format of
229+ "https://doi.org/..." or "doi.org/...".
230+ The function will automatically handle the prefix removal
231+ if `remove_prefix` is set to True.
229232
230- .. _`RCSB File Download Services`:
231- https://www.rcsb.org/docs/programmatic-access/file-download-services
232-
233- The RCSB currently provides data in ``'cif'`` , ``'cif.gz'`` , ``'bcif'`` ,
234- ``'bcif.gz'`` , ``'xml'`` , ``'xml.gz'`` , ``'pdb'`` , ``'pdb.gz'``,
235- ``'pdb1'``, ``'pdb1.gz'`` file formats and can therefore be downloaded.
236- Not all of these formats can be currently read with MDAnalysis.
237-
238- Caching, controlled by the `cache_path` parameter, is handled internally by
239- :mod:`pooch`. The default cache name is taken from
240- :data:`DEFAULT_CACHE_NAME_DOWNLOADER`. To clear cache (and subsequently
241- force re-fetching), it is required to delete the cache folder
242- as specified by `cache_path`.
233+ The current backend for downloading files is :class:`pooch.DOIDownloader`
234+ which only handles downloading from Zenodo and Figshare repositories.
235+
243236
244237 Examples
245238 --------
@@ -267,8 +260,8 @@ def from_DOI(doi, file_name, cache_path=None, remove_prefix=True):
267260 .. versionadded:: 2.11.0
268261 """
269262
270- # Suppress Figshare warning of getting most current
271- # repository if none is provided
263+ # Supress warnings from pooch about not specifying
264+ # which version of the repostory to download.
272265 warnings .filterwarnings ("ignore" , category = UserWarning )
273266
274267 if remove_prefix :
@@ -284,9 +277,12 @@ def from_DOI(doi, file_name, cache_path=None, remove_prefix=True):
284277 doi = doi .replace ("doi.org/" , "doi:" )
285278
286279 fetcher = StaticFetcher (cache_path = cache_path )
287- return fetcher .fetch (
288- base_url = doi , file_name = file_name , append_db = True , downloader = "doi"
289- )
290280
291-
292- ##
281+ try :
282+ return fetcher .fetch (
283+ base_url = doi , file_name = file_name , append_db = True , downloader = "doi"
284+ )
285+ except IndexError as e :
286+ raise ValueError (
287+ f"DOI link { doi } is invalid. Please check the DOI link."
288+ )
0 commit comments