schrodinger.models.parameters module

schrodinger.models.parameters.is_abstract_param(param)
class schrodinger.models.parameters.Param(default_value=None, DataClass=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. Example:

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 correctly if used as class variables.

Variables:
  • DataClass (type) – The type of data the param describes.
  • is_abstract (bool) – Whether this param is an abstract (ie class attribute) param.
  • valueChanged (QtCore.pyqtSignal) – A signal emitted whenever the param is changed.
  • default_value (DataClass) – The default value of the param. If unset, the default value is whatever value is created when calling DataClass()
  • param_name (str) – The name of the attribute this param is set as. For example, Owner.data_x.param_name would be ‘data_x’.
  • instance_attr_name (str) – The name of the attribute used to store param values on instances.
  • abstract_attr_name (str) – The name of the attribute used to store abstract params on class objects.
valueChanged
suspend_signals()
is_abstract = True
DataClass

alias of builtins.object

owner()

Returns the owner of this param. Works for both concrete and abstract params. Returns None if the param has no owner. Follows the same rules as ownerChain.

ownerChain()

Returns the owner chain for this param. This works for concrete 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.

class schrodinger.models.parameters.CompoundParam(default_value=None, **kwargs)

Bases: schrodinger.models.json.JsonableClassMixin, 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 paramChanged 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 correctly if used as class variables.

aboutToReplace
toDict()
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.
replace(value)

Replace this concrete param with the new value. The new value will be added to the owner in place of the current one and signals from the new value will be propagated.

Parameters:value
reset(*args)

Resets this compound param to it’s default value. If no arguments are passed in, the entire param is reset. Any number of abstract params may be optionally passed in to perform a partial reset to default value of specified sub-params. For example, given a compound param with two xyz coordinates as endpoints:

class Line(CompoundParam):
start = Coord(x=1, y=2, z=3) end = Coord(x=4, y=5, z=6)

line = Line()

We can reset the entire line:

line.reset()

Or just certain parts:

line.reset(Line.start.x) # resets just start.x line.start.reset(Coord.x) # another way to reset start.x line.reset(Line.end) # resets the entire end point line.reset(Line.start.z, Line.end.z) # resets the z-coord of both
Parameters:args – abstract sub-params of self
toJsonImplementation()

Returns a JSON representation of this value object.

classmethod fromJsonImplementation(json_dict)

Sets the value of this compound param value object from a JSON dict.

isDefault()
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.

schrodinger.models.parameters.is_toplevel_param(param, obj)

Determine whether the abstract param represents the entire compound param instance as opposed to a field in the compound param. Examples:

is_toplevel_param(Coord, coord) # True is_toplevel_param(Coord.x, coord) # False is_toplevel_param(Atom.coord, atom.coord) # False
Parameters:
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) – a dictionary or an object that has one or more params as member variables.
schrodinger.models.parameters.set_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.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 example:

val = get_obj_param_value(a1, Atom.coord)

In this case, val is a1.coord, an instance of a Coord class that has x and :code`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.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
schrodinger.models.parameters.get_abstract_param(concrete_param)

Get the abstract param that corresponds to a concrete param

schrodinger.models.parameters.get_obj_abstract_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_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.

class schrodinger.models.parameters.SignalType

Bases: object

Changed = 'Changed'
Mutated = 'mutated'
ItemChanged = 'itemChanged'
Replaced = 'Replaced'
schrodinger.models.parameters.get_param_signal(model, abstract_param, signal_type='Changed')
schrodinger.models.parameters.get_replaced_signal(param)
Parameters:param – the concrete compound param to get the replaced signal for
schrodinger.models.parameters.get_all_replaced_signals(obj)
class schrodinger.models.parameters.FloatParam(default_value=None, DataClass=None)

Bases: schrodinger.models.parameters.Param

DataClass

alias of builtins.float

class schrodinger.models.parameters.IntParam(default_value=None, DataClass=None)

Bases: schrodinger.models.parameters.Param

DataClass

alias of builtins.int

class schrodinger.models.parameters.StringParam(default_value=None, DataClass=None)

Bases: schrodinger.models.parameters.Param

DataClass

alias of builtins.str

class schrodinger.models.parameters.BoolParam(default_value=None, DataClass=None)

Bases: schrodinger.models.parameters.Param

DataClass

alias of builtins.bool

class schrodinger.models.parameters.EnumParam(enum_class, default_value, *args, **kwargs)

Bases: schrodinger.models.parameters.Param

schrodinger.models.parameters.generate_method(parent_cls, method_name, signal_name)

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
class schrodinger.models.parameters.BaseMutableParam(default_value=None, DataClass=None)

Bases: schrodinger.models.parameters.Param

MUTATE_METHOD_NAMES = ()
REPLACE_METHOD_NAME = None
class schrodinger.models.parameters.DictParam(default_value=None, DataClass=None)

Bases: schrodinger.models.parameters.BaseMutableParam

DataClass

alias of BaseMutableParam.__init_subclass__.<locals>.DataClassWithSignal

MUTATE_METHOD_NAMES = ('__setitem__', '__delitem__', 'pop', 'popitem', 'clear', 'update', 'setdefault')
REPLACE_METHOD_NAME = 'update'
class schrodinger.models.parameters.IdDictParam(default_value=None, DataClass=None)

Bases: schrodinger.models.parameters.DictParam

DataClass

alias of BaseMutableParam.__init_subclass__.<locals>.DataClassWithSignal

MUTATE_METHOD_NAMES = ('__setitem__', '__delitem__', 'pop', 'popitem', 'clear', 'update', 'setdefault', 'updateFromIterable')
class schrodinger.models.parameters.ListParam(default_value=None, DataClass=None)

Bases: schrodinger.models.parameters.BaseMutableParam

DataClass

alias of BaseMutableParam.__init_subclass__.<locals>.DataClassWithSignal

MUTATE_METHOD_NAMES = ('__setitem__', 'append', 'insert', '__delitem__', 'pop', 'remove', 'extend', 'reverse', 'sort', 'clear', '__iadd__')
REPLACE_METHOD_NAME = 'extend'
class schrodinger.models.parameters.SetParam(default_value=None, DataClass=None)

Bases: schrodinger.models.parameters.BaseMutableParam

DataClass

alias of BaseMutableParam.__init_subclass__.<locals>.DataClassWithSignal

MUTATE_METHOD_NAMES = {'pop', 'intersection_update', 'remove', 'add', 'update', 'clear', 'difference_update', 'symmetric_difference_update', 'discard'}
REPLACE_METHOD_NAME = 'update'
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.