ample.util.ample_util module

Various miscellaneous functions

exception FileNotFoundError[source]

Bases: exceptions.Exception

amoptd_fix_path(optd, newroot)[source]

Update all the paths in an AMPLE results dictionary to be rooted at newroot

Parameters:
  • optd (dict) – AMPLE results dictionary
  • newroot (str) – Path to the AMPLE root directory (topdir containing MRBUMP dir etc.)
disable_logging(*args, **kwds)[source]

A context manager to disable logging within a block.

Parameters:
  • logger (logging.Logger) – logger instance
  • highet_level (int) – loglevel that will be set for the duration of the context
extract_tar(archive, directory=None, filenames=None, suffixes=None)[source]

Extract one or more files from a tar file into a specified directory

Parameters:
  • archive (str) – tar archive to extract from
  • directory (str) – directory to extract files into
  • filenames (list) – a list of files to extract from the archive
  • suffixes (list) – only extract a file if the suffix is in the list
Returns:

A list of the extracted files

Return type:

list

extract_zip(filename, directory, suffixes=None)[source]
filename_append(filename=None, astr=None, directory=None, separator='_')[source]

Append astr to filename, before the suffix, and return the new filename.

find_exe(executable, dirs=None)[source]

Find the executable exename.

Parameters:
  • executable (str) – The name of the program or the path to an existing executable
  • dirs (list, tuple, optional) – Additional directories to search for the location
ideal_helices(optd)[source]

Get some ideal helices

Parameters:nresidues (int) – Number of residues to be used
Returns:
  • pdbs (list)
  • ensemble_options (dict)
  • ensembles_data (list)
is_exe(fpath)[source]

Check if an executable exists

Parameters:fpath (str) – The path to the executable
Returns:
Return type:bool
is_file(fpath)[source]

Check if a file exists

Parameters:fpath (str) – The path to the file
Returns:
Return type:bool
make_workdir(run_dir, ccp4i2=False, MAX_WORKDIRS=100)[source]

Make a work directory rooted at run_dir and return its path

Parameters:
  • run_dir (str) – The path to a run directory where the job was started
  • ccp4i2 (bool, optional) – Indicate if we are running under CCP4I2
Returns:

work_dir – The path to the working directory

Return type:

str

read_amoptd(amoptd_fname)[source]

Read a PICKLE-formatted AMPLE options file

Parameters:amoptd_fname (str) – The path to the PICKLE-formatted AMPLE options file
Returns:amoptd – AMPLE options from saved state
Return type:dict
run_command(cmd, logfile=None, directory=None, dolog=True, stdin=None, check=False, **kwargs)[source]

Execute a command and return the exit code.

Parameters:
  • cmd (list) – Command to run as a list
  • stdin (str or filehandle, optional) – Stdin for the command
  • logfile (str, optional) – The path to the logfile
  • directory (str, optional) – The directory to run the job in (cwd assumed)
  • dolog (bool, optional) – Whether to output info to the system log [default: False]
Returns:

returncode – Subprocess exit code

Return type:

int

Notes

We take care of outputting stuff to the logs and opening/closing logfiles

saveAmoptd(*args)[source]

Save AMPLE options to a PICKLE-formatted file

See also

save_amoptd()

Warning

This function was deprecated and will be removed in future releases. Please use save_amoptd() instead.

save_amoptd(amoptd)[source]

Save AMPLE options to a PICKLE-formatted file

Parameters:amoptd (dict) – AMPLE options from saved state
tmpFileName()[source]

Return a filename for a temporary file

See also

tmp_file_name()

Warning

This function was deprecated and will be removed in future releases. Please use tmp_file_name() instead.

tmp_file_name(delete=True, directory=None, suffix='')[source]

Return a filename for a temporary file

Parameters:
  • delete (bool, optional) – Flag whether the temporary file should be deleted [default: True]
  • directory (str, optional) – Path to a directory to write the files to.
  • suffix (str, optional) – A suffix to the temporary filename