openmmtools.storage.storageinterface.StorageInterface¶
-
class
openmmtools.storage.storageinterface.StorageInterface(storage_driver)[source]¶ This class interfaces with a StorageIODriver class to internally hold what folders and variables are known to the file on the disk, and dynamically creates them on the fly. Any attempt to reference a property which is not explicitly listed below implies that you wish to define either a storage directory or variable, and creates a new StorageInterfaceVarDir (SIVD) with that name. The SIVD is what handles the read/write operations on this disk by interfacing with the StorageIODriver object you provide StorageInterface class’s __init__.
See StorageInterfaceVarDir for how the dynamic interfacing works.
Examples
Create a basic storage interface and write new my_data to disk >>> my_driver = NetCDFIODriver(‘my_store.nc’) >>> my_data = [4,2,1,6] >>> my_storage = StorageInterface(my_driver) >>> my_storage.my_variable.write(my_data)
Create a folder called “vardir” with two variables in it, “var1” and “var2” holding DATA1 and DATA2 respectively Then, fetch data from the same folders and variables as above >>> my_driver = NetCDFIODriver(‘my_store.nc’) >>> DATA1 = “some string” >>> DATA2 = (4.5, 7.0, -23.1) >>> my_storage = StorageInterface(my_driver) >>> my_storage.vardir.var1.write(DATA1) >>> my_storage.vardir.var2.write(DATA2) >>> var1 = my_storage.vardir.var1.read() >>> var2 = my_storage.vardir.var2.read()
Run some_function() to generate data over an iteration, store each value in a dynamically sized var called “looper” >>> my_driver = NetCDFIODriver(‘my_store.nc’) >>> mydata = [-1, 24, 5] >>> my_storage = StorageInterface(my_driver) >>> for i in range(10): … mydata = i**2 … my_storage.looper.append(mydata)
Attributes: file_nameReturns the protected _file_name variable, mentioned as an explicit method as it is one of the protected names
storage_driverPointer to the object which actually handles read/write operations
Methods
add_metadata(name, data)Write additional meta data to attach to the storage_driver file itself. -
__init__(storage_driver)[source]¶ Initialize the class by reading in the StorageIODriver in storage_driver. The file name is inferred from the storage driver and the read/write/append actions are handled by the SIVD class which also act on the storage_driver.
Parameters: - storage_driver : StorageIODriver object
What type of storage to use. Requires fully implemented and instanced StorageIODriver class to use.
Methods
__init__(storage_driver)Initialize the class by reading in the StorageIODriver in storage_driver. add_metadata(name, data)Write additional meta data to attach to the storage_driver file itself. Attributes
file_nameReturns the protected _file_name variable, mentioned as an explicit method as it is one of the protected names that cannot be a directory or variable pointer storage_driverPointer to the object which actually handles read/write operations -
add_metadata(name, data)[source]¶ Write additional meta data to attach to the storage_driver file itself.
Parameters: - name : string
Name of the attribute you wish to assign
- data : any, but preferred string
Extra meta data to add to the variable
Examples
Create a storage interface and add meta data >>> my_driver = NetCDFIODriver(‘my_store.nc’) >>> my_storage = StorageInterface(my_driver) >>> my_storage.add_metadata(‘my_index’, 4)
-
file_name¶ Returns the protected _file_name variable, mentioned as an explicit method as it is one of the protected names that cannot be a directory or variable pointer
Returns: - file_name : string
Name of the file on the disk
-
storage_driver¶ Pointer to the object which actually handles read/write operations
Returns: - storage_driver :
Instance of the module which handles IO actions to specific storage type requested by storage_driver string at initialization.