openmmtools.storage.iodrivers.StorageIODriver

class openmmtools.storage.iodrivers.StorageIODriver(file_name, access_mode=None)[source]

Abstract class to define the basic functions any storage driver needs to read/write to the disk. The specific driver for a type of storage should be a subclass of this with its own encoders and decoders for specific file types.

Each type of variable codec should subclass Codec which has the minimum write, read, and append methods

Parameters:
file_name : string

Name of the file to read/write to of a given storage type

access_mode : string or None, Default None, accepts ‘w’, ‘r’, ‘a’

Define how to access the file in either write, read, or append mode None should behave like Python “a+” in which a file is created if not present, or opened in append if it is. How this is implemented is up to the subclass

Attributes:
access_mode

Access mode of file on disk

file_name

File name of on hard drive

Methods

add_metadata(name, value[, path]) Function to add metadata to the file.
close() Instruct how to safely close down the file.
create_storage_variable(path, type_key) Create a new variable on the disk and at the path location and store it as the given type.
get_directory(path[, create]) Get a directory-like object located at path from disk.
get_storage_variable(path) Get a variable IO object from disk at path.
set_codec(type_key, codec) Add new codifier to the specific driver class.
__init__(file_name, access_mode=None)[source]

Initialize self. See help(type(self)) for accurate signature.

Methods

__init__(file_name[, access_mode]) Initialize self.
add_metadata(name, value[, path]) Function to add metadata to the file.
close() Instruct how to safely close down the file.
create_storage_variable(path, type_key) Create a new variable on the disk and at the path location and store it as the given type.
get_directory(path[, create]) Get a directory-like object located at path from disk.
get_storage_variable(path) Get a variable IO object from disk at path.
set_codec(type_key, codec) Add new codifier to the specific driver class.

Attributes

access_mode Access mode of file on disk
file_name File name of on hard drive
access_mode

Access mode of file on disk

add_metadata(name, value, path='')[source]

Function to add metadata to the file. This can be treated as optional and can simply be a pass if you do not want your storage system to handle additional metadata

Parameters:
name : string

Name of the attribute you wish to assign

value : any, but preferred string

Extra meta data to add to the variable

path : string, Default: ‘’

Extra path pointer to add metadata to a specific location if platform allows it

close()[source]

Instruct how to safely close down the file.

create_storage_variable(path, type_key)[source]

Create a new variable on the disk and at the path location and store it as the given type.

Parameters:
path : string

The way to identify the variable on the storage system. This can be either a variable name or a full path (such as in NetCDF files)

type_key : Immutable object

Type specifies the key identifier in the _codec_type_maps added by the set_codec function. If type is not in _codec_type_maps variable, an error is raised.

Returns:
bound_codec : Codec which is linked to a specific reference on the disk.
file_name

File name of on hard drive

get_directory(path, create=True)[source]

Get a directory-like object located at path from disk.

Parameters:
path : string

Path to directory-like object on disk

create: boolean, default: True

Should create the stack of directories on the way down, similar function to mkdir -p in shell

Returns:
directory_handler : directory object as its stored on disk
get_storage_variable(path)[source]

Get a variable IO object from disk at path. Raises a KeyError or AttributeError if no storage object exists at that level

Parameters:
path : string

Path to the variable/storage object on disk

Returns:
bound_codec : Codec which is linked to a specific reference on the disk.
set_codec(type_key, codec)[source]

Add new codifier to the specific driver class. This coder must know how to read/write and append to disk.

This method also acts to overwrite any existing type <-> codec map, however, will not overwrite any codec already in use by a variable. E.g. Variable X of type T has codec A as the codecs have {T:A}. The maps is changed by set_codec(T,B) so now {T:B}, but X will still be on codec A. Unloading X and then reloading X will bind it to codec B.

Parameters:
type_key : Unique immutable object

Unique key that will be added to identify this de_encoder as part of the class

codec : Specific codifier class

Class to handle all of the encoding of decoding of the variables