Helpers
A small number of functions and classes are included to help organize the data.
For users
- class MDAnalysisData.base.Bunch(**kwargs)[source]
Container object for datasets
Dictionary-like object that exposes its keys as attributes.
>>> b = Bunch(a=1, b=2) >>> b['b'] 2 >>> b.b 2 >>> b.a = 3 >>> b['a'] 3 >>> b.c = 6 >>> b['c'] 6
- MDAnalysisData.base.DEFAULT_DATADIR = '~/MDAnalysis_data'
Default value for the cache directory. It can be changed by setting the environment variable
MDANALYSIS_DATA
. The current value should be queried withget_data_home()
.See also
- MDAnalysisData.base.get_data_home(data_home=None)[source]
Return the path of the MDAnalysisData data dir.
This folder is used by some large dataset loaders to avoid downloading the data several times. By default the data dir is set to a folder named ‘MDAnalysis_data’ in the user’s home directory.
Alternatively, it can be set by the
MDANALYSIS_DATA
environment variable or programmatically by giving an explicit folder path. The ‘~’ symbol is expanded to the user home folder.If the folder does not already exist, it is automatically created.
- Parameters:
data_home (str | None) – The path to MDAnalysisData data dir.
For developers
If you want to add your own dataset then you will likely use these functions in your code.
- MDAnalysisData.base.RemoteFileMetadata = <class 'MDAnalysisData.base.RemoteFileMetadata'>
Each remote resource is described by a
RemoteFileMetadata
, which is anamedtuple()
with fieldsfilename: name of the file in the local file system
url: full URL for downloading
checksum: SHA256 (can be generated with
MDAnalysisData.base._sha256()
; often it is just as convenient to run the downloader during testing and note the required SHA256 then)
- MDAnalysisData.base._fetch_remote(remote, dirname=None)[source]
Helper function to download a remote dataset into path
Fetch a dataset pointed by remote’s url, save into path using remote’s filename and ensure its integrity based on the SHA256 Checksum of the downloaded file.
- Parameters:
remote (RemoteFileMetadata) – Named tuple containing remote dataset meta information: url, filename and checksum
dirname (string) – Directory to save the file to.
- Returns:
file_path – Full path of the created file.
- Return type:
string
- MDAnalysisData.base._read_description(filename, description_dir='descr')[source]
Read the description from restructured text file.
- Parameters:
filename (str) – name of the description file under the
descr
directory
Note
All description files are supposed to be stored in the directory description_dir
="descr"
that lives in the same directory as theMDAnalysisData.base
module file. All descriptions are assumed to be in restructured text format and in UTF-8 encoding.