schrodinger.application.msv.utils module¶
- schrodinger.application.msv.utils.get_rolling_average(data, window_padding=4)[source]¶
Returns the running average of data in a window
- Parameters
data (list) – Data to average. Must not contain any None values.
window_padding (int) – The number of elements on either side of a given element to include in the average. Must be greater than 0.
- Returns
A list of rolling averages. This list does not contain any values for the first or last
window_padding
elements ofdata
, as those positions do not have a fully populated window. (Note that this list does not containNone`s in those positions. It is simply 2 * window_padding elements shorter than `data
.)- Return type
list
- schrodinger.application.msv.utils.const(method)[source]¶
A decorator that adds a ‘const’ attribute to a method. This decorator is used in conjunction with
WrapperMetaClass
below and must only be applied to methods in a wrapped class that do not modify the state of the class (similar to theconst
method declaration in C++).
- class schrodinger.application.msv.utils.DocstringWrapperMetaClass(clsname, bases, dct, *, wraps=None)[source]¶
Bases:
type
A metaclass for a class that wraps another class. This metaclass copies docstrings from wrapped methods to reimplemented wrapper methods of the same name.
- __init__(*args, **kwargs)¶
- mro()¶
Return a type’s method resolution order.
- class schrodinger.application.msv.utils.QtDocstringWrapperMetaClass(clsname, bases, dct, *, wraps=None)[source]¶
Bases:
schrodinger.application.msv.utils.DocstringWrapperMetaClass
,sip.wrappertype
A metaclass for QObject subclasses that wraps another class. This metaclass only copies docstrings from wrapped methods to reimplemented wrapper methods of the same name.
- __init__(*args, **kwargs)¶
- mro()¶
Return a type’s method resolution order.
- class schrodinger.application.msv.utils.WrapperMetaClass(clsname, bases, dct, *, wraps=None, wrapped_name=None, instance_attrs=None)[source]¶
Bases:
schrodinger.application.msv.utils.QtDocstringWrapperMetaClass
This metaclass makes it easy to create a class that wraps another one. In particular, this is intended to help in creating an undoable version of the wrapped class. Methods that don’t modify the state of the wrapped class (which must be indicated using the
@const
decorator) may be called directly on the wrapper. Custom undoable wrappings will need to be written for any methods that do modify the state of the wrapped class.See the tests for this class for a simple example.
In general, if class A wraps class B, then:
Every static method, class method, public class attribute, and property on B is accessible from A, unless A already has attributes with the same name defined
Every method on B decorated by @const will be available from A, unless A already has a method with the same name defined. Note that @const methods from B will take precedence over methods that A inherits. (This ensures that common magic methods like
__str__
and__repr__
will get wrapped properly.)Every instance attribute on B named in instance_attrs will be available from A.
This may sound like a clumsy reinvention of classical inheritance. But it can be useful to use a wrapper when we want the wrapped class to be able to call any of its own methods without any danger of the wrapper methods being called, while at the same time ensuring that we can conveniently provide the same interface from the wrapped class. For example, we have a ProteinAlignment class that encapsulates operations on structured collections of protein sequences. We use this metaclass to create an undoable ProteinAlignment that presents an identical interface but that can safely perform redo and undo operations by manipulating the protein alignment it wraps.
- classmethod makeMethodDelegate(meth_name, wrapped_class, wrapped_name)[source]¶
Returns a method that delegates method calls to the wrapped instance
- Parameters
meth_name (str) – The name of the method to wrap
- classmethod makeClassMethodDelegate(meth_name, wrapped_class)[source]¶
Returns a class method that delegates class method calls to the wrapped class
- Parameters
meth_name (str) – The name of the method to wrap
- classmethod makeProperty(prop_name, getter, setter, wrapped_name)[source]¶
Returns a property that delegates property access to the wrapped instance
- Parameters
prop_name (str) – The name of the property
getter (bool) – Whether to add a getter
setter (bool) – Whether to add a setter
- Returns
A property which delegates to the wrapped object
- Return type
property
- __init__(*args, **kwargs)¶
- mro()¶
Return a type’s method resolution order.