schrodinger.utils.scollections module

class schrodinger.utils.scollections.IdSet(initial_set=None)

Bases: collections.abc.MutableSet, set

An id set is a set that uses the id of an object as the key instead of the hash. This means that two objects that compare equal but are different instances will be stored separately since id(obj1) != id(obj2).

NOTE: Using this set with python’s builtin immutable datatypes is /strongly/ discouraged (e.g. str and int are not guaranteed to have different ids for separate instances)

__init__(initial_set=None)

Initialize self. See help(type(self)) for accurate signature.

__contains__(obj)

x.__contains__(y) <==> y in x.

__iter__()

Implement iter(self).

__len__()

Return len(self).

__copy__()
__deepcopy__()
copy()

Return a shallow copy of a set.

classmethod fromIterable(iterable)
isdisjoint(other)

Return True if two sets have a null intersection.

issubset(other)

Report whether another set contains this set.

issuperset(other)

Report whether this set contains another set.

union(*other_sets)

Return the union of sets as a new set.

(i.e. all elements that are in either set.)

intersection(*other_sets)

Return the intersection of two sets as a new set.

(i.e. all elements that are in both sets.)

difference(*other_sets)

Return the difference of two or more sets as a new set.

(i.e. all elements that are in this set but not the others.)

symmetric_difference(*other_sets)

Return the symmetric difference of two sets as a new set.

(i.e. all elements that are in exactly one of the sets.)

update(*other_sets)

Update a set with the union of itself and others.

intersection_update(*other_sets)

Update a set with the intersection of itself and another.

difference_update(*other_sets)

Remove all elements of another set from this set.

symmetric_difference_update(*other_sets)

Update a set with the symmetric difference of itself and another.

add(obj)

Add an element.

discard(obj)

Remove an element. Do not raise an exception if absent.

__abstractmethods__ = frozenset()
__and__(other)
__class__

alias of abc.ABCMeta

__delattr__

Implement delattr(self, name).

__dict__ = mappingproxy({'__module__': 'schrodinger.utils.scollections', '__doc__': "\n An id set is a set that uses the id of an object as the key instead of the\n hash. This means that two objects that compare equal but are different\n instances will be stored separately since id(obj1) != id(obj2).\n\n NOTE: Using this set with python's builtin immutable datatypes is /strongly/\n discouraged (e.g. str and int are not guaranteed to have different ids\n for separate instances)\n ", '__init__': <function IdSet.__init__>, '__contains__': <function IdSet.__contains__>, '__iter__': <function IdSet.__iter__>, '__len__': <function IdSet.__len__>, '__copy__': <function IdSet.__copy__>, '__deepcopy__': <function IdSet.__deepcopy__>, 'copy': <function IdSet.copy>, 'fromIterable': <classmethod object>, 'isdisjoint': <function IdSet.isdisjoint>, 'issubset': <function IdSet.issubset>, 'issuperset': <function IdSet.issuperset>, 'union': <function IdSet.union>, 'intersection': <function IdSet.intersection>, 'difference': <function IdSet.difference>, 'symmetric_difference': <function IdSet.symmetric_difference>, 'update': <function IdSet.update>, 'intersection_update': <function IdSet.intersection_update>, 'difference_update': <function IdSet.difference_update>, 'symmetric_difference_update': <function IdSet.symmetric_difference_update>, 'add': <function IdSet.add>, 'discard': <function IdSet.discard>, '_checkOtherSets': <function IdSet._checkOtherSets>, '__dict__': <attribute '__dict__' of 'IdSet' objects>, '__abstractmethods__': frozenset(), '_abc_registry': <_weakrefset.WeakSet object>, '_abc_cache': <_weakrefset.WeakSet object>, '_abc_negative_cache': <_weakrefset.WeakSet object>, '_abc_negative_cache_version': 49})
__dir__() → list

default dir() implementation

__eq__(other)

Return self==value.

__format__()

default object formatter

__ge__(other)

Return self>=value.

__getattribute__

Return getattr(self, name).

__gt__(other)

Return self>value.

__hash__ = None
__iand__(it)
__init_subclass__()

This method is called when a class is subclassed.

The default implementation does nothing. It may be overridden to extend subclasses.

__ior__(it)
__isub__(it)
__ixor__(it)
__le__(other)

Return self<=value.

__lt__(other)

Return self<value.

__module__ = 'schrodinger.utils.scollections'
__ne__

Return self!=value.

__new__()

Create and return a new object. See help(type) for accurate signature.

__or__(other)
__rand__(other)
__reduce__()

Return state information for pickling.

__reduce_ex__()

helper for pickle

__repr__

Return repr(self).

__ror__(other)
__rsub__(other)
__rxor__(other)
__setattr__

Implement setattr(self, name, value).

__sizeof__() → size of S in memory, in bytes
__slots__ = ()
__str__

Return str(self).

__sub__(other)
classmethod __subclasshook__(C)

Abstract classes can override this to customize issubclass().

This is invoked early on by abc.ABCMeta.__subclasscheck__(). It should return True, False or NotImplemented. If it returns NotImplemented, the normal algorithm is used. Otherwise, it overrides the normal algorithm (and the outcome is cached).

__xor__(other)
clear()

This is slow (creates N new iterators!) but effective.

pop()

Return the popped value. Raise KeyError if empty.

remove(value)

Remove an element. If not a member, raise a KeyError.

class schrodinger.utils.scollections.IdItemsView(id_dict, id_map)

Bases: collections.abc.ItemsView

__init__(id_dict, id_map)

Initialize self. See help(type(self)) for accurate signature.

__contains__(item)
__iter__()
__next__()
__len__()
__abstractmethods__ = frozenset()
__and__(other)
__class__

alias of abc.ABCMeta

__delattr__

Implement delattr(self, name).

__dict__ = mappingproxy({'__module__': 'schrodinger.utils.scollections', '__init__': <function IdItemsView.__init__>, '__contains__': <function IdItemsView.__contains__>, '__iter__': <function IdItemsView.__iter__>, '__next__': <function IdItemsView.__next__>, '__len__': <function IdItemsView.__len__>, '__dict__': <attribute '__dict__' of 'IdItemsView' objects>, '__weakref__': <attribute '__weakref__' of 'IdItemsView' objects>, '__doc__': None, '__abstractmethods__': frozenset(), '_abc_registry': <_weakrefset.WeakSet object>, '_abc_cache': <_weakrefset.WeakSet object>, '_abc_negative_cache': <_weakrefset.WeakSet object>, '_abc_negative_cache_version': 49})
__dir__() → list

default dir() implementation

__eq__(other)

Return self==value.

__format__()

default object formatter

__ge__(other)

Return self>=value.

__getattribute__

Return getattr(self, name).

__gt__(other)

Return self>value.

__hash__ = None
__init_subclass__()

This method is called when a class is subclassed.

The default implementation does nothing. It may be overridden to extend subclasses.

__le__(other)

Return self<=value.

__lt__(other)

Return self<value.

__module__ = 'schrodinger.utils.scollections'
__ne__

Return self!=value.

__new__()

Create and return a new object. See help(type) for accurate signature.

__or__(other)
__rand__(other)
__reduce__()

helper for pickle

__reduce_ex__()

helper for pickle

__repr__()

Return repr(self).

__ror__(other)
__rsub__(other)
__rxor__(other)
__setattr__

Implement setattr(self, name, value).

__sizeof__() → int

size of object in memory, in bytes

__slots__ = ()
__str__

Return str(self).

__sub__(other)
classmethod __subclasshook__(C)

Abstract classes can override this to customize issubclass().

This is invoked early on by abc.ABCMeta.__subclasscheck__(). It should return True, False or NotImplemented. If it returns NotImplemented, the normal algorithm is used. Otherwise, it overrides the normal algorithm (and the outcome is cached).

__weakref__

list of weak references to the object (if defined)

__xor__(other)
isdisjoint(other)

Return True if two sets have a null intersection.

class schrodinger.utils.scollections.IdDict(initial_dict=None)

Bases: collections.abc.MutableMapping, dict

An id dict is a dictionary that uses the id of an object as the key instead of the hash. This means that two objects that compare equal but are different instances will be stored separately since id(obj1) != id(obj2).

NOTE: Using this dict with python’s builtin immutable datatypes is /strongly/ discouraged (e.g. str and int are not guaranteed to have different ids for separate instances)

__init__(initial_dict=None)

Initialize self. See help(type(self)) for accurate signature.

__getitem__(obj)

x.__getitem__(y) <==> x[y]

__setitem__(obj, value)

Set self[key] to value.

__delitem__(obj)

Delete self[key].

setdefault(k[, d]) → D.get(k,d), also set D[k]=d if k not in D
__contains__(obj)

True if D has a key k, else False.

__len__()

Return len(self).

items() → a set-like object providing a view on D's items
keys() → a set-like object providing a view on D's keys
__eq__(other)

Return self==value.

__iter__()

Implement iter(self).

__repr__()

Return repr(self).

has_key(obj)
update([E, ]**F) → None. Update D from mapping/iterable E and F.

If E present and has a .keys() method, does: for k in E: D[k] = E[k] If E present and lacks .keys() method, does: for (k, v) in E: D[k] = v In either case, this is followed by: for k, v in F.items(): D[k] = v

updateFromIterable(iterable)
classmethod fromIterable(iterable)
clear() → None. Remove all items from D.
__abstractmethods__ = frozenset()
__class__

alias of abc.ABCMeta

__delattr__

Implement delattr(self, name).

__dict__ = mappingproxy({'__module__': 'schrodinger.utils.scollections', '__doc__': "\n An id dict is a dictionary that uses the id of an object as the key\n instead of the hash. This means that two objects that compare equal but are\n different instances will be stored separately since id(obj1) != id(obj2).\n\n NOTE: Using this dict with python's builtin immutable datatypes is /strongly/\n discouraged (e.g. str and int are not guaranteed to have different ids\n for separate instances)\n ", '__init__': <function IdDict.__init__>, '__getitem__': <function IdDict.__getitem__>, '__setitem__': <function IdDict.__setitem__>, '__delitem__': <function IdDict.__delitem__>, 'setdefault': <function IdDict.setdefault>, '__contains__': <function IdDict.__contains__>, '__len__': <function IdDict.__len__>, 'items': <function IdDict.items>, 'keys': <function IdDict.keys>, '__eq__': <function IdDict.__eq__>, '__iter__': <function IdDict.__iter__>, '__repr__': <function IdDict.__repr__>, 'has_key': <function IdDict.has_key>, 'update': <function IdDict.update>, 'updateFromIterable': <function IdDict.updateFromIterable>, 'fromIterable': <classmethod object>, 'clear': <function IdDict.clear>, '__dict__': <attribute '__dict__' of 'IdDict' objects>, '__weakref__': <attribute '__weakref__' of 'IdDict' objects>, '__hash__': None, '__abstractmethods__': frozenset(), '_abc_registry': <_weakrefset.WeakSet object>, '_abc_cache': <_weakrefset.WeakSet object>, '_abc_negative_cache': <_weakrefset.WeakSet object>, '_abc_negative_cache_version': 49})
__dir__() → list

default dir() implementation

__format__()

default object formatter

__ge__

Return self>=value.

__getattribute__

Return getattr(self, name).

__gt__

Return self>value.

__hash__ = None
__init_subclass__()

This method is called when a class is subclassed.

The default implementation does nothing. It may be overridden to extend subclasses.

__le__

Return self<=value.

__lt__

Return self<value.

__module__ = 'schrodinger.utils.scollections'
__ne__

Return self!=value.

__new__()

Create and return a new object. See help(type) for accurate signature.

__reduce__()

helper for pickle

__reduce_ex__()

helper for pickle

__reversed__ = None
__setattr__

Implement setattr(self, name, value).

__sizeof__() → size of D in memory, in bytes
__slots__ = ()
__str__

Return str(self).

classmethod __subclasshook__(C)

Abstract classes can override this to customize issubclass().

This is invoked early on by abc.ABCMeta.__subclasscheck__(). It should return True, False or NotImplemented. If it returns NotImplemented, the normal algorithm is used. Otherwise, it overrides the normal algorithm (and the outcome is cached).

__weakref__

list of weak references to the object (if defined)

copy() → a shallow copy of D
fromkeys()

Returns a new dict with keys from iterable and values equal to value.

get(k[, d]) → D[k] if k in D, else d. d defaults to None.
pop(k[, d]) → v, remove specified key and return the corresponding value.

If key is not found, d is returned if given, otherwise KeyError is raised.

popitem() → (k, v), remove and return some (key, value) pair

as a 2-tuple; but raise KeyError if D is empty.

values() → an object providing a view on D's values
class schrodinger.utils.scollections.DefaultIdDict(default_factory)

Bases: schrodinger.utils.scollections.IdDict

A dict that is both an id dict and a defaultdict.

__init__(default_factory)

Initialize self. See help(type(self)) for accurate signature.

__getitem__(obj)

x.__getitem__(y) <==> x[y]

classmethod fromIterable(iterable)
setdefault(k[, d]) → D.get(k,d), also set D[k]=d if k not in D
__abstractmethods__ = frozenset()
__class__

alias of abc.ABCMeta

__contains__(obj)

True if D has a key k, else False.

__delattr__

Implement delattr(self, name).

__delitem__(obj)

Delete self[key].

__dict__ = mappingproxy({'__module__': 'schrodinger.utils.scollections', '__doc__': '\n A dict that is both an id dict and a defaultdict.\n ', '__init__': <function DefaultIdDict.__init__>, '__getitem__': <function DefaultIdDict.__getitem__>, 'fromIterable': <classmethod object>, 'setdefault': <function DefaultIdDict.setdefault>, '__abstractmethods__': frozenset(), '_abc_registry': <_weakrefset.WeakSet object>, '_abc_cache': <_weakrefset.WeakSet object>, '_abc_negative_cache': <_weakrefset.WeakSet object>, '_abc_negative_cache_version': 49})
__dir__() → list

default dir() implementation

__eq__(other)

Return self==value.

__format__()

default object formatter

__ge__

Return self>=value.

__getattribute__

Return getattr(self, name).

__gt__

Return self>value.

__hash__ = None
__init_subclass__()

This method is called when a class is subclassed.

The default implementation does nothing. It may be overridden to extend subclasses.

__iter__()

Implement iter(self).

__le__

Return self<=value.

__len__()

Return len(self).

__lt__

Return self<value.

__module__ = 'schrodinger.utils.scollections'
__ne__

Return self!=value.

__new__()

Create and return a new object. See help(type) for accurate signature.

__reduce__()

helper for pickle

__reduce_ex__()

helper for pickle

__repr__()

Return repr(self).

__reversed__ = None
__setattr__

Implement setattr(self, name, value).

__setitem__(obj, value)

Set self[key] to value.

__sizeof__() → size of D in memory, in bytes
__slots__ = ()
__str__

Return str(self).

classmethod __subclasshook__(C)

Abstract classes can override this to customize issubclass().

This is invoked early on by abc.ABCMeta.__subclasscheck__(). It should return True, False or NotImplemented. If it returns NotImplemented, the normal algorithm is used. Otherwise, it overrides the normal algorithm (and the outcome is cached).

__weakref__

list of weak references to the object (if defined)

clear() → None. Remove all items from D.
copy() → a shallow copy of D
fromkeys()

Returns a new dict with keys from iterable and values equal to value.

get(k[, d]) → D[k] if k in D, else d. d defaults to None.
has_key(obj)
items() → a set-like object providing a view on D's items
keys() → a set-like object providing a view on D's keys
pop(k[, d]) → v, remove specified key and return the corresponding value.

If key is not found, d is returned if given, otherwise KeyError is raised.

popitem() → (k, v), remove and return some (key, value) pair

as a 2-tuple; but raise KeyError if D is empty.

update([E, ]**F) → None. Update D from mapping/iterable E and F.

If E present and has a .keys() method, does: for k in E: D[k] = E[k] If E present and lacks .keys() method, does: for (k, v) in E: D[k] = v In either case, this is followed by: for k, v in F.items(): D[k] = v

updateFromIterable(iterable)
values() → an object providing a view on D's values
class schrodinger.utils.scollections.DefaultFactoryDictMixin(factory_func, *args, **kwargs)

Bases: object

A mixin to use with dict’s that allows the dict to use a factory function similar to defaultdict. The key distinction here is that the factory function will be passed the key itself instead of called without any arguments.

Note

Despite the name, this mixin works with classes as well. When passed a class, the constructor will be called and passed the keys.

Warning

This mixin will not work with factory functions that expect only one tuple as an argument. This is due to the way __getitem__ packages up all keys in a single call into one tuple.

__init__(factory_func, *args, **kwargs)
Parameters:factory_fun (callable) – A callable to create a value from.
__missing__(key)
__class__

alias of builtins.type

__delattr__

Implement delattr(self, name).

__dict__ = mappingproxy({'__module__': 'schrodinger.utils.scollections', '__doc__': "\n A mixin to use with `dict`'s that allows the dict to use a factory function\n similar to `defaultdict`. The key distinction here is that the factory\n function will be passed the key itself instead of called without any\n arguments.\n\n .. NOTE::\n Despite the name, this mixin works with classes as well. When passed\n a class, the constructor will be called and passed the keys.\n\n .. WARNING::\n This mixin will not work with factory functions that expect only one\n tuple as an argument. This is due to the way `__getitem__` packages up\n all keys in a single call into one tuple.\n ", '__init__': <function DefaultFactoryDictMixin.__init__>, '__missing__': <function DefaultFactoryDictMixin.__missing__>, '__dict__': <attribute '__dict__' of 'DefaultFactoryDictMixin' objects>, '__weakref__': <attribute '__weakref__' of 'DefaultFactoryDictMixin' objects>})
__dir__() → list

default dir() implementation

__eq__

Return self==value.

__format__()

default object formatter

__ge__

Return self>=value.

__getattribute__

Return getattr(self, name).

__gt__

Return self>value.

__hash__

Return hash(self).

__init_subclass__()

This method is called when a class is subclassed.

The default implementation does nothing. It may be overridden to extend subclasses.

__le__

Return self<=value.

__lt__

Return self<value.

__module__ = 'schrodinger.utils.scollections'
__ne__

Return self!=value.

__new__()

Create and return a new object. See help(type) for accurate signature.

__reduce__()

helper for pickle

__reduce_ex__()

helper for pickle

__repr__

Return repr(self).

__setattr__

Implement setattr(self, name, value).

__sizeof__() → int

size of object in memory, in bytes

__str__

Return str(self).

__subclasshook__()

Abstract classes can override this to customize issubclass().

This is invoked early on by abc.ABCMeta.__subclasscheck__(). It should return True, False or NotImplemented. If it returns NotImplemented, the normal algorithm is used. Otherwise, it overrides the normal algorithm (and the outcome is cached).

__weakref__

list of weak references to the object (if defined)

class schrodinger.utils.scollections.DefaultFactoryDict(factory_func, *args, **kwargs)

Bases: schrodinger.utils.scollections.DefaultFactoryDictMixin, dict

A basic dict using the DefaultFactoryDictMixin. This is separated from the mixin to allow other dict subclasses to easily subclass DefaultFactoryDictMixin.

Example usage::
stringified_objs = DefaultFactoryDict(str) assert 1 not in stringified_objs print(stringified_objs[1]) # ‘1’
__class__

alias of builtins.type

__contains__()

True if D has a key k, else False.

__delattr__

Implement delattr(self, name).

__delitem__

Delete self[key].

__dict__ = mappingproxy({'__module__': 'schrodinger.utils.scollections', '__doc__': "\n A basic `dict` using the `DefaultFactoryDictMixin`. This is separated\n from the mixin to allow other `dict` subclasses to easily subclass\n `DefaultFactoryDictMixin`.\n\n Example usage::\n stringified_objs = DefaultFactoryDict(str)\n assert 1 not in stringified_objs\n print(stringified_objs[1]) # '1'\n ", '__dict__': <attribute '__dict__' of 'DefaultFactoryDict' objects>, '__weakref__': <attribute '__weakref__' of 'DefaultFactoryDict' objects>})
__dir__() → list

default dir() implementation

__eq__

Return self==value.

__format__()

default object formatter

__ge__

Return self>=value.

__getattribute__

Return getattr(self, name).

__getitem__()

x.__getitem__(y) <==> x[y]

__gt__

Return self>value.

__hash__ = None
__init__(factory_func, *args, **kwargs)
Parameters:factory_fun (callable) – A callable to create a value from.
__init_subclass__()

This method is called when a class is subclassed.

The default implementation does nothing. It may be overridden to extend subclasses.

__iter__

Implement iter(self).

__le__

Return self<=value.

__len__

Return len(self).

__lt__

Return self<value.

__missing__(key)
__module__ = 'schrodinger.utils.scollections'
__ne__

Return self!=value.

__new__()

Create and return a new object. See help(type) for accurate signature.

__reduce__()

helper for pickle

__reduce_ex__()

helper for pickle

__repr__

Return repr(self).

__setattr__

Implement setattr(self, name, value).

__setitem__

Set self[key] to value.

__sizeof__() → size of D in memory, in bytes
__str__

Return str(self).

__subclasshook__()

Abstract classes can override this to customize issubclass().

This is invoked early on by abc.ABCMeta.__subclasscheck__(). It should return True, False or NotImplemented. If it returns NotImplemented, the normal algorithm is used. Otherwise, it overrides the normal algorithm (and the outcome is cached).

__weakref__

list of weak references to the object (if defined)

clear() → None. Remove all items from D.
copy() → a shallow copy of D
fromkeys()

Returns a new dict with keys from iterable and values equal to value.

get(k[, d]) → D[k] if k in D, else d. d defaults to None.
items() → a set-like object providing a view on D's items
keys() → a set-like object providing a view on D's keys
pop(k[, d]) → v, remove specified key and return the corresponding value.

If key is not found, d is returned if given, otherwise KeyError is raised

popitem() → (k, v), remove and return some (key, value) pair as a

2-tuple; but raise KeyError if D is empty.

setdefault(k[, d]) → D.get(k,d), also set D[k]=d if k not in D
update([E, ]**F) → None. Update D from dict/iterable E and F.

If E is present and has a .keys() method, then does: for k in E: D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k]

values() → an object providing a view on D's values