schrodinger.models.parameters module

schrodinger.models.parameters.classandinstancemethod(func)

Decorator used to indicate that a particular method in a class declaration should work as both a class method and an instance method. Only works when used in a HybridMethodsMixin subclass. Example:

class Foo(HybridMethodsMixin):
    x = 1

    @classandinstancemethod:
    def bar(self):
        print(x)

f = Foo()
f.x = 3
Foo.bar()  # prints '1'
f.bar()  # prints '3'
class schrodinger.models.parameters.HybridMethodsMixin(*args, **kwargs)

Bases: object

Mixin that allows the use of the classandinstancemethod decorator.

__init__(*args, **kwargs)
schrodinger.models.parameters.abstract_only(method, *args, **kwargs)
schrodinger.models.parameters.concrete_only(method, *args, **kwargs)
schrodinger.models.parameters.descriptor_only(method, *args, **kwargs)
class schrodinger.models.parameters.ParamType(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: enum.Enum

ABSTRACT = 'Abstract'
CONCRETE = 'Concrete'
DESCRIPTOR = 'Descriptor'
class schrodinger.models.parameters.SignalType

Bases: object

Changed = 'Changed'
Mutated = 'mutated'
ItemChanged = 'itemChanged'
Replaced = 'Replaced'
class schrodinger.models.parameters.NonParamAttribute

Bases: object

This class can be used to declare a public attribute on a CompoundParam. Declared public attributes can be used without error.

Example usage:

class Coord(CompoundParam):
    x: int
    y: int
    note = NonParamAttribute()

coord = Coord()
coord.note = "hello" # No error
class schrodinger.models.parameters.Param(*args, _param_type=<object object>, **kwargs)

Bases: schrodinger.models.parameters.HybridMethodsMixin, PyQt6.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 Coord(CompoundParam):
    x: int
    y: int

An instance of the Coord class can be created normally, and Params can be accessed as normal attributes:

coord = Coord()
coord.x = 4

When a Param value is set, the valueChanged signal is emitted. Params can be serialized and deserialized to and from JSON. Params can also be nested:

class Atom(CompoundParam):
    coord: Coord
    element: str
DataClass

alias of object

__init__(default_value=<object object>, DataClass=None, deepcopyable=True, *, _param_type=<object object>)
Parameters
  • default_value (object) – The value to use in constructing the default value for the param. A new param will have the value returned by DataClass(default_value).

  • DataClass (type) – The type to use for values of this param.

  • deepcopyable (bool) – Whether values of this param are deepcopyable. If this param is not deepcopyable and its owner param is deepcopied, the copy’s subparam value will be identical.

  • _param_type – For internal use only.

initAbstract()
getTypeHint()
classmethod paramName()

Get the name of the param:

# Can be called on an abstract param:
print(Coord.x.paramName()) # 'x'

# ...or on an instance of a CompoundParam
a = Atom()
a.coord.paramName() # 'coord'
classmethod ownerChain()

Returns a list of param owners starting from the toplevel param and ending with self. Examples:

foo.bar.atom.coord.ownerChain() will return [foo, bar, atom, coord] where every item is a concrete param.

Foo.bar.atom.coord.x.ownerChain() will return [Foo, Foo.bar, Foo.atom.coord, Foo.atom.coord.x] where every item is an abstract params.

classmethod owner()

Get the owner of the param:

# Can be called on an abstract param:
assert Coord.x.owner() == Coord

# ...or on an instance of a CompoundParam
a = Atom()
assert a.coord.owner() == a
classmethod isAbstract()

Whether the param is an “abstract” param.

classmethod getParamValue(obj)

Enables access to a param value on a compound param via an abstract param reference:

a = Atom()
assert Atom.coord.x.getParamValue(a) == 0 # ints default to 0
a.coord.x = 3
assert Atom.coord.x.getParamValue(a) == 3
Parameters

param (CompoundParam) – The owner param to get a param value from

classmethod setParamValue(obj, value)

Set the value of a param on an object by specifying the instance and the value:

# Setting the param value of a basic param
a = Atom()
Atom.coord.x.setParamValue(a, 5)
assert a.coord.x == 5

# setParamValue can also be used to set the value of CompoundParams
c = Coord()
c.x = 10
atom.coord.setParamValue(a, c)
assert atom.coord.x == 10
Parameters
  • param – The owner param to set a subparam value of.

  • value – The value to set the subparam value to.

classmethod defaultValue()

Returns the default value for this abstract param:

default_atom = Atom.defaultValue()
assert Atom.coord.x == 0
classmethod getParamSignal(obj, signal_type='Changed')
class schrodinger.models.parameters.FloatParam(*args, _param_type=<object object>, **kwargs)

Bases: schrodinger.models.parameters.Param

DataClass

alias of float

class schrodinger.models.parameters.IntParam(*args, _param_type=<object object>, **kwargs)

Bases: schrodinger.models.parameters.Param

DataClass

alias of int

class schrodinger.models.parameters.StructureParam(*args, _param_type=<object object>, **kwargs)

Bases: schrodinger.models.parameters.Param

DataClass

alias of schrodinger.structure._structure.Structure

__init__(*args, **kwargs)
Parameters
  • default_value (object) – The value to use in constructing the default value for the param. A new param will have the value returned by DataClass(default_value).

  • DataClass (type) – The type to use for values of this param.

  • deepcopyable (bool) – Whether values of this param are deepcopyable. If this param is not deepcopyable and its owner param is deepcopied, the copy’s subparam value will be identical.

  • _param_type – For internal use only.

class schrodinger.models.parameters.StringParam(*args, _param_type=<object object>, **kwargs)

Bases: schrodinger.models.parameters.Param

DataClass

alias of str

class schrodinger.models.parameters.BoolParam(*args, _param_type=<object object>, **kwargs)

Bases: schrodinger.models.parameters.Param

DataClass

alias of bool

class schrodinger.models.parameters.TupleParam(*args, _param_type=<object object>, **kwargs)

Bases: schrodinger.models.parameters.Param

DataClass

alias of tuple

class schrodinger.models.parameters.CompoundParamMeta(name, parents, dct, **kwargs)

Bases: PyQt6.sip.wrappertype

class schrodinger.models.parameters.CompoundParamMixin

Bases: object

A base class for sharing params between classes. For example:

class ColorMixin(CompoundParamMixin):
    color: str = 'red'

class ColoredSquare(ColorMixin, CompoundParam):
    length: int = 5

class ColoredTriangle(ColorMixin, CompoundParam):
    base: int = 5
    height: int = 3

Both ColoredSquare and ColoredTriangle will have a param color.

class schrodinger.models.parameters.CompoundParam(*args, _param_type=<object object>, **kwargs)

Bases: schrodinger.models.json.JsonableClassMixin, schrodinger.models.parameters._MutateToMatchMixin, schrodinger.models.parameters.Param

All CompoundParam instances are automatically serializable if their subparams are serializable. To serialize and deserialize, use the schrodinger json module:

from schrodinger.models import json
class Coord(parameters.CompoundParam):
    x: int
    y: int

c1 = Coord(x=1, y=2)
c1_string = json.dumps(c1)
c2 = json.loads(c1_string, DataClass=Coord)
assert c1 == c2
valueChanged

pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL

types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.

skip_eq_check()
block_signal_propagation()
classmethod configureParam()

Override this class method to set up the abstract param class (e.g. setParamReference on child params.)

classmethod setReference(param1, param2)

Call this class method from configureParam to indicate that two params should be kept in sync. The initial values will start with the default value of param1. Example:

class Square(CompoundParam):
    width: float = 5
    height: float = 10

    @classmethod
    def configureParam(cls):
        super().configureParam()
        cls.setReference(cls.width, cls.height)

square = Square()
assert square.width == square.height == 5 # Default value of width
                                          # takes priority
square.height = 7
assert square.width == square.height == 7
square.width = 6
assert square.width == square.height == 6
Parameters
  • param1 – The first abstract param to keep synced

  • param2 – The second abstract param. After instantiation, this param will take on the value of param1.

__init__(default_value=<object object>, _param_type=<object object>, **kwargs)
DataClass

This class can be used to declare a public attribute on a CompoundParam. Declared public attributes can be used without error.

Example usage:

class Coord(CompoundParam):
    x: int
    y: int
    note = NonParamAttribute()

coord = Coord()
coord.note = "hello" # No error
initializeValue()

Override to dynamically set up the default value of the param. Useful for default values that are determined at runtime. This is called any time the param is reset.

initConcrete()

Override to customize initialization of concrete params.

classmethod getSubParam(name)

Get the value of a subparam using the string name:

c = Coord()
assert c.getSubParam('x') == 0

Note

Using the string name to access params is generally discouraged, but can be useful for serializing/deserializing param data.

Parameters

name (str) – The name of the subparam to get the value for.

classmethod getSubParams()

Return a dictionary mapping subparam names to their values.

classmethod defaultValue()

Returns the default value for this abstract param:

default_atom = Atom.defaultValue()
assert Atom.coord.x == 0
classmethod getJsonBlacklist()

Override to customize what params are serialized.

Implementations should return a list of abstract params that should be omitted from serialization.

..NOTE

Returned abstract params must be direct child params of cls, e.g. cls.name, not cls.coord.x.

getAbstractParam()

Return the corresponding abstract param for this instance.

isDefault()

Whether the current value of this instance matches the default value.

setValue(value=None, **kwargs)

Set the value of this CompoundParam to match value.

Parameters
  • value – The value to set this CompoundParam to. It should be the same type as this CompoundParam.

  • kwargs – For internal use only.

toDict()

Return a dictionary version of this CompoundParam. The returned dictionary is fully nested and contains no CompoundParam instances

a = Atom()
a_dict = a.toDict()
assert a_dict['coord']['x'] == 0
assert a_dict['coord'] == {'x':0, 'y':0}
reset(*abstract_params)

Resets this compound param to its default value:

class Line(CompoundParam):
    start = Coord(x=1, y=2)
    end = Coord(x=4, y=5)
line = Line()
line.start.x = line.end.x = 10
assert line.start.x == line.end.x == 10
line.reset()
assert line.start.x == 1
assert line.end.x == 4

Any number of abstract params may be passed in to perform a partial reset of only the specified params:

line.start.x = line.end.x = 10
line.reset(Line.start.x)  # resets just start.x
assert line.start.x == 1
assert line.end.x == 10

line.reset(Line.end)      # resets the entire end point
assert line.end.x == 4

line.start.y = line.end.y = 10
line.reset(Line.start.y, Line.end.y)  # resets the y-coord of both
assert line.start.y == 2
assert line.end.y == 5
toJsonImplementation()

Returns a JSON representation of this value object.

Warning

This should never be called directly.

classmethod fromJsonImplementation(json_dict)

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

Warning

This should never be called directly.

classmethod addSubParam(name, param, update_owner=True)
schrodinger.models.parameters.ParamModel

DEPRECATED

Used to be a placeholder in case we wanted to add any logic for the top- level model.

exception schrodinger.models.parameters.ParamAttributeError

Bases: RuntimeError

We catch AttributeError`s raised inside of DataClass initialization and inside of param __get__ and __set__ methods and reraise them as `ParamAttributeError`s. If we allow them to be raised as normal `AttributeError`s then `QObject.__getattr__ will swallow the exception and its helpful traceback and raise a different and vague exception.

If you see this error, it’s most likely caused by an attempt to access an attribute that doesn’t exist in a param’s DataClass.

class schrodinger.models.parameters.ParamDict

Bases: dict

A helper class to distinguish between dicts used to represent params and regular dicts. It has no additional functionality and should be used sparingly.

schrodinger.models.parameters.get_all_replaced_signals(obj, abs_param=None)
schrodinger.models.parameters.get_all_atomic_subparams(abs_param)
schrodinger.models.parameters.get_all_compound_subparams(param)
schrodinger.models.parameters.permissive_issubclass(obj, cls)

Return issubclass(obj, cls) without raising an exception if obj is not a class. Usable with typing classes as well.

class schrodinger.models.parameters.EnumParam(*args, _param_type=<object object>, **kwargs)

Bases: schrodinger.models.parameters.Param

__init__(enum_class, default_value=<object object>, *args, **kwargs)

EnumParam must be initialized with the Enum class that this param is to be based on as well as the default value.

Parameters
  • enum_class (enum.Enum) – the enum class to base this pram on

  • default_value (a member of the enum_class) – The default enum value. If not provided, the param will default to the first value of the enum.

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(*args, _param_type=<object object>, **kwargs)

Bases: schrodinger.models.parameters.Param

Base class for mutable params (eg lists, sets, dicts, etc). Child classes should specify the names of mutation methods on the class, the method used to match an instance of the class to another instance (eg ‘extend’ for list), what methods take iterables, and the actual DataClass. Upon subclass declaration, the DataClass will be dynamically wrapped so signals are emitted whenever an instance is mutated.

MUTATE_METHOD_NAMES = ()
REPLACE_METHOD_NAME = None
ITERABLE_ARG_METHOD_NAMES = None
DataClass = None
__init__(default_value=<object object>, *args, **kwargs)
Parameters
  • default_value (object) – The value to use in constructing the default value for the param. A new param will have the value returned by DataClass(default_value).

  • DataClass (type) – The type to use for values of this param.

  • deepcopyable (bool) – Whether values of this param are deepcopyable. If this param is not deepcopyable and its owner param is deepcopied, the copy’s subparam value will be identical.

  • _param_type – For internal use only.

class schrodinger.models.parameters.DictParam(*args, _param_type=<object object>, **kwargs)

Bases: schrodinger.models.parameters.BaseMutableParam

A Param to represent dictionaries. Values of this param will have a mutated signal that will be emitted whenever any mutation method is called.

The constructor optionally takes a value_class keyword argument to specify what type of class the values will be. This information will be used for jsonifying the dictionary if specified. (Note that non-string keys are not currently supported for jsonification. This may change in the future. See PANEL-13029).

DataClass

alias of schrodinger.models.parameters.BaseMutableParam.__init_subclass__.<locals>.DataClassWithSignal

MUTATE_METHOD_NAMES = ('__setitem__', '__delitem__', 'pop', 'popitem', 'clear', 'update', 'setdefault')
ITERABLE_ARG_METHOD_NAMES = {'update'}
REPLACE_METHOD_NAME = 'update'
__init__(value_class=None, **kwargs)
Parameters
  • default_value (object) – The value to use in constructing the default value for the param. A new param will have the value returned by DataClass(default_value).

  • DataClass (type) – The type to use for values of this param.

  • deepcopyable (bool) – Whether values of this param are deepcopyable. If this param is not deepcopyable and its owner param is deepcopied, the copy’s subparam value will be identical.

  • _param_type – For internal use only.

getTypeHint()
class schrodinger.models.parameters.ItemClassMixin(item_class, **kwargs)

Bases: object

__init__(item_class, **kwargs)
class schrodinger.models.parameters.ListParam(*args, _param_type=<object object>, **kwargs)

Bases: schrodinger.models.parameters.ItemClassMixin, schrodinger.models.parameters.BaseMutableParam

A Param to represent lists. Values of this param will have a mutated signal that will be emitted whenever any mutation method is called.

The constructor optionally takes a item_class keyword argument to specify what type of class the items in the list will be. This information will be used for jsonifying the list if specified.

DataClass

alias of schrodinger.models.parameters.BaseMutableParam.__init_subclass__.<locals>.DataClassWithSignal

MUTATE_METHOD_NAMES = ('__setitem__', 'append', 'insert', '__delitem__', 'pop', 'remove', 'extend', 'reverse', 'sort', 'clear', '__iadd__')
ITERABLE_ARG_METHOD_NAMES = {'extend'}
REPLACE_METHOD_NAME = 'extend'
__init__(item_class=None, **kwargs)
Parameters
  • default_value (object) – The value to use in constructing the default value for the param. A new param will have the value returned by DataClass(default_value).

  • DataClass (type) – The type to use for values of this param.

  • deepcopyable (bool) – Whether values of this param are deepcopyable. If this param is not deepcopyable and its owner param is deepcopied, the copy’s subparam value will be identical.

  • _param_type – For internal use only.

getTypeHint()
class schrodinger.models.parameters.SetParam(*args, _param_type=<object object>, **kwargs)

Bases: schrodinger.models.parameters.ItemClassMixin, schrodinger.models.parameters.BaseMutableParam

A Param to represent sets. Values of this param will have a mutated signal that will be emitted whenever any elment is added or removed from the set.

The constructor optionally takes a item_class keyword argument to specify what type of class the items in the list will be. This information will be used for jsonifying the set if specified.

DataClass

alias of schrodinger.models.parameters.BaseMutableParam.__init_subclass__.<locals>.DataClassWithSignal

MUTATE_METHOD_NAMES = {'add', 'clear', 'difference_update', 'discard', 'intersection_update', 'pop', 'remove', 'symmetric_difference_update', 'update'}
ITERABLE_ARG_METHOD_NAMES = {'difference_update', 'intersection_update', 'symmetric_difference_update', 'update'}
REPLACE_METHOD_NAME = 'update'
__init__(item_class=None, **kwargs)
Parameters
  • default_value (object) – The value to use in constructing the default value for the param. A new param will have the value returned by DataClass(default_value).

  • DataClass (type) – The type to use for values of this param.

  • deepcopyable (bool) – Whether values of this param are deepcopyable. If this param is not deepcopyable and its owner param is deepcopied, the copy’s subparam value will be identical.

  • _param_type – For internal use only.

getTypeHint()
class schrodinger.models.parameters.ParamListParam(*args, _param_type=<object object>, **kwargs)

Bases: schrodinger.models.parameters.ListParam

A list param that contains CompoundParam instances. Signals will be emitted any time an item in the list changes or the contents of the list itself change. See _SignalContainer and _PLPSignalContainer for information on specific signals.

__init__(item_class, *args, **kwargs)
Parameters
  • default_value (object) – The value to use in constructing the default value for the param. A new param will have the value returned by DataClass(default_value).

  • DataClass (type) – The type to use for values of this param.

  • deepcopyable (bool) – Whether values of this param are deepcopyable. If this param is not deepcopyable and its owner param is deepcopied, the copy’s subparam value will be identical.

  • _param_type – For internal use only.

DataClass

alias of schrodinger.models.parameters.BaseMutableParam.__init_subclass__.<locals>.DataClassWithSignal