schrodinger.models.parameters module¶
-
class
schrodinger.models.parameters.
BaseMutableParam
(default_value=None)¶ Bases:
schrodinger.models.parameters.Param
-
MUTATE_METHOD_NAMES
= ()¶
-
-
class
schrodinger.models.parameters.
BoolParam
(default_value=None)¶ Bases:
schrodinger.models.parameters.Param
-
DataClass
¶ alias of
bool
-
-
class
schrodinger.models.parameters.
CompoundParam
(default_value=None, **kwargs)¶ Bases:
schrodinger.models.parameters.Param
A collection of Params that itself is a Param. Instances of this class are used as both descriptors and as return values from the descriptor. This allows sub-params to be accessed in the most natural way (i.e. param = container.param, subparam = param.subparam), since the return value of the first descriptor has the descriptors for the sub-params.
To create a compound param, subclass and add params as class attributes. Example:
- class Coordinate(CompoundParam):
- x = FloatParam() y = FloatParam() z = FloatParam(4) # Specify default value
Since CompoundsParams are Params, they can also be included within other compound params:
- class Line(CompoundParam):
- startpoint = Coordinate() endpoint = Coordinate(x=3, y=2) # specify default value by kwargs
Signal propagation. Executing the following lines:
l = Line() l.endpoint.x = 5
- will result in multiple signals being emitted:
- l.endpoint.xChanged l.endpoint.valueChanged l.endpointChanged l.valueChanged
For any nested param, the change can be detected via either the paramChagned signal or the generic valueChanged signal. For a top-level param, only the valueChanged signal will be available.
Compound params can also be serialized to JSON and deserialized from JSON.
WARNING: as descriptors, instances of this class will not behave normally if used as class variables.
-
fromJson
(json_str)¶ Sets the value of this compound param value object from a JSON string.
-
isDefault
()¶
-
reset
()¶
-
setValue
(value)¶ Set the value of this compound param instance
Parameters: value (self.DataClass or dict) – either another param instance of the same type or a dictionary mapping the sub-param names to values.
-
toDict
()¶
-
toJson
()¶ Returns a JSON representation of this value object.
-
class
schrodinger.models.parameters.
DictParam
(default_value=None)¶ Bases:
schrodinger.models.parameters.BaseMutableParam
-
DataClass
¶ alias of
dict
-
MUTATE_METHOD_NAMES
= ('__setitem__', '__delitem__', 'pop', 'popitem', 'clear', 'update', 'setdefault')¶
-
-
class
schrodinger.models.parameters.
EnumParam
(enum_class, default_value, *args, **kwargs)¶
-
class
schrodinger.models.parameters.
FloatParam
(default_value=None)¶ Bases:
schrodinger.models.parameters.Param
-
DataClass
¶ alias of
float
-
-
class
schrodinger.models.parameters.
IntParam
(default_value=None)¶ Bases:
schrodinger.models.parameters.Param
-
DataClass
¶ alias of
int
-
-
class
schrodinger.models.parameters.
ListParam
(default_value=None)¶ Bases:
schrodinger.models.parameters.BaseMutableParam
-
DataClass
¶ alias of
list
-
MUTATE_METHOD_NAMES
= ('__setitem__', 'append', 'insert', '__delitem__', 'pop', 'remove', 'extend', 'reverse')¶
-
-
class
schrodinger.models.parameters.
MutableSignalMeta
¶ Bases:
type
This metaclass modifies the creation of a new object by adding a mutated signal and modifying any methods named in MUTATE_METHOD_NAMES to emit the mutated signal whenever they’re called
-
class
schrodinger.models.parameters.
Param
(default_value=None)¶ Bases:
PyQt5.QtCore.QObject
Base class for all Param classes. A Param is a descriptor for storing data, which means that a single Param instance will manage the data values for multiple instances of the class that owns it.
- class Owner(object):
- data_x = IntParam() data_y = IntParam()
An instance of the Owner class can be created normally, and params can be accessed as normal attributes:
owner_instance = Owner() owner_instance.data_x = 4
When a Param value is set, the valueChanged signal is emitted. Params can be serialized and deserialized to and from JSON.
WARNING: as descriptors, instances of this class will not behave normally if used as class variables.
-
DataClass
= None¶
-
class
NO_VALUE
¶ Bases:
tuple
-
is_abstract
= True¶
-
ownerChain
()¶ Returns the owner chain for this param. This works for regular params and abstract params. Examples:
foo.bar.atom.coord.ownerChain() will return [foo, bar, atom, coord] where every item is a regular param.
Foo.bar.atom.coord.x.ownerChain() will return [Foo, bar, atom.coord, x] where Foo is a class and all other items are abstract params.
-
suspend_signals
(*args, **kwds)¶
-
valueChanged
¶
-
class
schrodinger.models.parameters.
ParamListParam
(item_class, *args, **kwargs)¶ Bases:
schrodinger.models.parameters.ListParam
A list param that contains CompoundParam (or ParamModel) instances. Any time the value of an item in the list is changed, the ParamListParam will emit an itemChanged signal.
-
class
schrodinger.models.parameters.
ParamMeta
¶ Bases:
sip.wrappertype
This metaclass modifies the creation of CompoundParam instances in the following ways:
1) Stores the names of subparams on the subparam descriptor object. For example:
- class Coord(CompoundParam):
- x = IntParam() y = IntParam()
In this example, the descriptor x.param_name == ‘x’.
2) A signal is dynamically added to the compound param for each subparam. The signal is names <subparam-name>Changed. (ex. coord.xChanged and coord.yChanged). This way, subclasses of CompoundParam do not need to explicitly define signals for each subparam.
-
class
schrodinger.models.parameters.
ParamModel
(default_value=None, **kwargs)¶ Bases:
schrodinger.models.parameters.CompoundParam
Inherit all functionality of
CompoundParam
with name that designates this class as a model. Models should themselves be parameters so that their corresponding view can be easily incorporated into a parent view. In this case, the model of the parent view will contain the model of the child view as a parameter.WARNING: as descriptors, instances of this class will not behave normally if used as class variables.
-
setParamMapper
(param_mapper)¶ Sets the primary param mapper for this model. This allows the model itself to trigger the updating of values either to or from the mapped objects. Pass in None to clear the mapper.
Parameters: param_mapper (mappers.AbstractParamMapper or None) – the primary param mapper for this model
-
updateModel
()¶ Retrieves values from the mapped target object and updates this model accordingly.
-
updateTarget
()¶ Updates the mapped target object with the current values of this model.
-
-
class
schrodinger.models.parameters.
StringParam
(default_value=None)¶ Bases:
schrodinger.models.parameters.Param
-
DataClass
¶ alias of
str
-
-
schrodinger.models.parameters.
generate_method
(parent_cls, method_name, signal)¶ Creates a new method with the given name that first calls the method of the same name from the parent class and then emits the specified signal.
Parameters: - parent_cls – the parent class
- method_name (str) – the name of the new method to be generated
- signal (QtCore.pyqtSignal) – the signal that should be emitted whenever the method is called
-
schrodinger.models.parameters.
get_obj_param_value
(obj, param)¶ Enables access to a param value on an object via an abstract param reference. The abstract reference is the one which begins with a class rather than an instance. Example, for an instance a1 of class Atom:
val = get_obj_param_value(a1, Atom.coord.x)val should have the value of a1.coord.x, e.g. a
float
. It can also return a non-fundamental type, for exampleval = get_obj_param_value(a1, Atom.coord)In this case, val is a1.coord, an instance of a Coord class that has x and y attributes.
Parameters: - obj – the instance from which to get the param value
- param (
Param
) – an abstract Param reference that belongs to obj
-
schrodinger.models.parameters.
get_obj_param_values
(obj)¶ Given an object that has params, return a dictionary of all its params values, keyed by the name of each param.
-
schrodinger.models.parameters.
get_obj_params
(obj)¶ Given an object that has params, return a dictionary of all its params, keyed by the name of each param.
-
schrodinger.models.parameters.
get_param_signal
(model, param)¶
-
schrodinger.models.parameters.
is_abstract_param
(param)¶
-
schrodinger.models.parameters.
obj_params_from_value
(obj, value)¶ Updates the values of all params in an object using the values specified in a dictionary of values keyed by param name.
Parameters: - obj (object) – an object that has one or more params as member variables.
- value (dict | object) – a representation of a parameter, which can be dictionary of param names and desired values or an object with params, which will be converted into a dictionary. Any param on value which does not correspond to a param on the object will result in a ValueError being raised.
-
schrodinger.models.parameters.
param_value_to_dict
(value)¶ Takes any representation of a param and returns a dictionary representation of param values keyed by param name. Compound params are represented as nested dictionaries. The representation can be a dictionary or an object with params.
Parameters: value (dict | object) – an dictionary or an object that has one or more params as member variables.
-
schrodinger.models.parameters.
set_obj_param_value
(obj, param, value)¶ Set the value of a param on an instance by specifying the instance, an abstract param reference, and the value. Example, for an instance a1 of class Atom:
set_obj_param_value(a1, Atom.coord.x, 5)
This should set the value of a1.coord.x to 5. This function can also be used to set the value of more complicated parameters, e.g.
c = Coord() c.x = 5 c.y = 1 set_obj_param_value(a1, Atom.coord, c)
This should set the value of a1.coord.x to 5 and the value of a1.coord.y to 1. If the Coord class had any other attributes, it would overwrite the values of those as well in a1.coord.
Parameters: - obj – the instance from which to get the param value
- param (
Param
) – an abstract Param reference - value – the value to set