molgri.wrappers

All project-applicable wrappers.

Specifically, functionality for:
  • timing the function and writing out the result

  • using saved data if it exists

  • marking deprecated functions

Functions

deprecated(my_method)

Mark functions or methods that may be removed in the future.

save_or_use_saved(my_method)

This can be used on any method that provides data for plotting (important if data production takes a long time).

time_method(my_method)

This wrapper times the execution of a method and prints the duration of the execution.

molgri.wrappers.time_method(my_method)

This wrapper times the execution of a method and prints the duration of the execution.

Args:
my_method: method with first argument self, the class it belongs to must implement a method

self.get_decorator_name() label with value like ‘grid ico_15’ or ‘pseudotrajectory H2O_HCl_ico_15_full’

Returns:

what my_method returns

molgri.wrappers.save_or_use_saved(my_method)

This can be used on any method that provides data for plotting (important if data production takes a long time). Able to save any python objects: if numpy array will save as .npy, if pandas DataFrame as .csv, everything else as pickle.

Requirements:

the class must have an attribute self.use_saved (bool) the class must have a method get_name() which provides a name that is suitable for saving (no whitespace etc) the method should not have any parameters that are commonly changed or their values should be part of the name (otherwise you risk reading and using data with old parameters)

Args:

my_method: around which method the wrapper is applied

Returns:

whatever the original method would return, either freshly created or read from a file

molgri.wrappers.deprecated(my_method)

Mark functions or methods that may be removed in the future. Raises a warning.