schrodinger.infra.mmbitset module¶
A pythonic wrapper for the mmbs library, providing access to bitsets.
The default error handler for the Bitset module is set to mm.error_handler. If no error handler is specified for error_handler arguments, its value is what will be used.
Copyright Schrodinger, LLC. All rights reserved.
-
class
schrodinger.infra.mmbitset.Bitset(handle=None, manage_handle=True, error_handler=None, size=None)¶ Bases:
schrodinger.infra.mmobject.MmObjectThis class represents a bitset, with each element either 1 or 0.
A bitset is similar conceptually to a Python dictionary that contains keys that are integers from 1 to the length of the bitset, and the value for each key is an on/off boolean (1 or 0).
Bitsets are usually used when keeping track of which atoms in the ct an operation needs to be performed on; in which case the length of the Bitset is the number of atoms in the ct.
An instance of Bitset can be converted to a list containing the elements that are on (i.e. set to 1) via list(bitset) and to a set via set(bitset).
This is an object-oriented wrapper for the underlying MMBS library. All state is stored in the C library. References to instances of this class can be used in direct mmbs library calls, as it will converted to the integer handle when necessary.
-
__init__(handle=None, manage_handle=True, error_handler=None, size=None)¶ Initialize an object with an existing MMBS handle or a size.
By default, the MMBS resources will be managed by the object. To keep these from being cleaned up on object deletion, set manage_handle=False.
Parameters: size (int) – The size to use for a newly created bitset.
-
classmethod
from_list(size, on_list)¶ Alternative constructor; returns a Bitset object initialized from a Python list.
- Example usage:
- bs = Bitset.from_list(st.atom_total, selected_atoms)
where <st> is the structure object, and <selected_atoms> is a list of atom indices.
Parameters: - size (int) – The size to use for a newly created bitset.
- on_list – Turn on the bits that are present in this iterable. Each item should be an int between 1 and <size>.
-
static
initialize(error_handler=None)¶ Initialize all libs that mmbs is dependent upon.
-
static
terminate()¶ Terminate the libs that were initiated in Bitset.initialize().
-
size()¶ Return the capacity (i.e. maximum index) of the Bitset.
-
resize(size)¶ Modify the capacity of the Bitset.
-
count()¶ Return the number of index values that are set to ‘on’.
-
get(index)¶ Get the value of the index.
Returns True if the index value is on, False if it is off.
-
set(index)¶ Set the index value to ‘on’.
-
unset(index)¶ Set the index value to ‘off’.
-
range(start, finish)¶ Set all bits in a range from “start” to “finish”
-
fill()¶ Set all bits to on.
-
__repr__()¶ Return a Python representation string for this bitset.
-
__str__()¶ Return a string of this bitset.
-
__class__¶ alias of
builtins.type
-
__del__()¶ Decrement the reference count. If the handle is being actively managed, call _delete when it the count hits zero.
-
__delattr__¶ Implement delattr(self, name).
-
__dict__= mappingproxy({'__module__': 'schrodinger.infra.mmbitset', '__doc__': '\n This class represents a bitset, with each element either 1 or 0.\n\n A bitset is similar conceptually to a Python dictionary that contains\n keys that are integers from 1 to the length of the bitset, and the value\n for each key is an on/off boolean (1 or 0).\n\n Bitsets are usually used when keeping track of which atoms in the ct an\n operation needs to be performed on; in which case the length of the Bitset\n is the number of atoms in the ct.\n\n An instance of Bitset can be converted to a list containing the elements\n that are on (i.e. set to 1) via list(bitset) and to a set via set(bitset).\n\n This is an object-oriented wrapper for the underlying MMBS library. All\n state is stored in the C library. References to instances of this class\n can be used in direct mmbs library calls, as it will converted to the\n integer handle when necessary.\n\n ', '__init__': <function Bitset.__init__>, '_delete': <function Bitset._delete>, 'from_list': <classmethod object>, 'initialize': <staticmethod object>, 'terminate': <staticmethod object>, 'size': <function Bitset.size>, 'resize': <function Bitset.resize>, 'count': <function Bitset.count>, 'get': <function Bitset.get>, 'set': <function Bitset.set>, 'unset': <function Bitset.unset>, 'range': <function Bitset.range>, 'fill': <function Bitset.fill>, '__repr__': <function Bitset.__repr__>, '__str__': <function Bitset.__str__>, '__iter__': <function Bitset.__iter__>, '__len__': <function Bitset.__len__>})¶
-
__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.
-
__int__()¶ Return the handle of the object so that the object reference can be used in functions that expect an integer handle.
-
__iter__()¶ Return an iterator for this bitset. Loops over all of the ON bits.
-
__le__¶ Return self<=value.
-
__lt__¶ Return self<value.
-
__module__= 'schrodinger.infra.mmbitset'¶
-
__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
-
__setattr__¶ Implement setattr(self, name, value).
-
__sizeof__() → int¶ size of object in memory, in bytes
-
__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)
-
__len__()¶ Returns the size of the bitset (Number of ON and OFF bits)
-