schrodinger.utils.scollections module¶
- schrodinger.utils.scollections.partition_values(num_values: int, num_bins: int) list[int] ¶
Partitions num_values as equally as possible over num_bins and returns the population of each bin. For example, if num_values is 1007 and num_bins is 5, this function would return [201, 202, 201, 202, 201].
- schrodinger.utils.scollections.split_list(input_list, num_chunks)¶
Split a list into N equal chunks.
Note: function is similar to numpy.split_array.
- Parameters
input_list (list) – The list to split
num_chunks (int) – The desired number of chunks
- 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)¶
- __contains__(obj)¶
x.__contains__(y) <==> y in x.
- __len__()¶
Return len(self).
- 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.
- class schrodinger.utils.scollections.IdItemsView(id_dict, id_map)¶
Bases:
collections.abc.ItemsView
- __init__(id_dict, id_map)¶
- __contains__(item)¶
- __len__()¶
- 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)¶
- setdefault(k[, d]) D.get(k,d), also set D[k]=d if k not in D ¶
- __contains__(obj)¶
True if the dictionary has the specified key, 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 ¶
- 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. ¶
- copy() a shallow copy of D ¶
- 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)¶
- classmethod fromIterable(iterable)¶
- setdefault(k[, d]) D.get(k,d), also set D[k]=d if k not in D ¶
- 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 todefaultdict
. 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.
- class schrodinger.utils.scollections.DefaultFactoryDict(factory_func, *args, **kwargs)¶
Bases:
schrodinger.utils.scollections.DefaultFactoryDictMixin
,dict
A basic
dict
using theDefaultFactoryDictMixin
. This is separated from the mixin to allow otherdict
subclasses to easily subclassDefaultFactoryDictMixin
.- Example usage::
stringified_objs = DefaultFactoryDict(str) assert 1 not in stringified_objs print(stringified_objs[1]) # ‘1’