atomium.utilities
Contains various file handling helper functions.
- atomium.utilities.fetch(code, *args, **kwargs)[source]
Fetches a file from a remote location via HTTP.
If a PDB code is given, the .cif form of that struture will be fetched from the RCSB servers. If that code is given an extension, that file format will be obtained instead of .cif. If a URL is given, the function will simply look in that location.
For example:
>>> atomium.fetch('1lol.mmtf', file_dict=True)
This will get the .mmtf version of structure 1LOL, but only go as far as converting it to an atomium file dictionary.
- Parameters
code (str) – the file to fetch.
file_dict (bool) – if
True
, parsing will stop at the filedict
.data_dict (bool) – if
True
, parsing will stop at the datadict
.
- Raises
ValueError – if no file is found.
- Return type
File
- atomium.utilities.fetch_over_ssh(hostname, username, path, *args, password=None, **kwargs)[source]
Fetches a file from a remote location via SSH.
- Parameters
hostname (str) – the remote location.
username (str) – the username to use.
path (str) – the file location on the remote machine.
password (str) – if needed, the password to use.
file_dict (bool) – if
True
, parsing will stop at the filedict
.data_dict (bool) – if
True
, parsing will stop at the datadict
.
- Return type
File
- atomium.utilities.get_parse_functions(filestring, path)[source]
Works out which parsing functions to use for a given filestring and returns them.
(If this cannot be inferred from the path string, atomium will guess based on the filestring contents.)
- Parameters
filestring (str) – the filestring to inspect.
path (str) – the path to inspect.
- Return type
tuple
- atomium.utilities.open(path, *args, **kwargs)[source]
Opens a file at a given path, works out what filetype it is, and parses it accordingly.
For example:
>>> atomium.open('/path/to/file.pdb', data_dict=True)
This will parse file.pdb as a .pdb file, but only go as far as converting it to an atomium data dictionary.
If the file extension is .gz, the file will be unzipped first.
- Parameters
path (str) – the location of the file.
file_dict (bool) – if
True
, parsing will stop at the filedict
.data_dict (bool) – if
True
, parsing will stop at the datadict
.
- Return type
File
- atomium.utilities.parse_string(filestring, path, file_dict=False, data_dict=False)[source]
Takes a filestring and parses it in the appropriate way. You must provide the string to parse itself, and some other string that ends in either .cif, .mmtf, or .cif - that will determine how the file is parsed.
(If this cannot be inferred from the path string, atomium will guess based on the filestring contents.)
- Parameters
filestring (str) – the contents of some file.
path (str) – the filename of the file of origin.
file_dict (bool) – if
True
, parsing will stop at the filedict
.data_dict (bool) – if
True
, parsing will stop at the datadict
.
- Return type
File