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:
object
This 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>.
-
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’.
-
invert
()¶ Invert the bits in the set.
-
range
(start, finish)¶ Set all bits in a range from “start” to “finish”
-
fill
()¶ Set all bits to on.
-
all
()¶ Are all bits on?
-
copy
()¶ Create another bitset that is a duplicate of this one.
-
__len__
()¶ Returns the size of the bitset (Number of ON and OFF bits)
-