Package schrodinger :: Package infra :: Module mmbitset :: Class Bitset
[hide private]
[frames] | no frames]

Class Bitset

       object --+    
                |    
mmobject.MmObject --+
                    |
                   Bitset

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.

Instance Methods [hide private]
 
__init__(self, handle=None, manage_handle=True, error_handler=None, size=None)
Initialize an object with an existing MMBS handle or a size.
 
_delete(self)
A function to terminate this object.
 
size(self)
Return the capacity (i.e.
 
resize(self, size)
Modify the capacity of the Bitset.
 
count(self)
Return the number of index values that are set to 'on'.
 
get(self, index)
Get the value of the index.
 
set(self, index)
Set the index value to 'on'.
 
unset(self, index)
Set the index value to 'off'.
 
bsand(self, other)
Return a Bitset of items that are both ON in this set and ON in the <other> set.
 
range(self, start, finish)
Set all bits in a range from "start" to "finish"
 
fill(self)
Set all bits to on.
 
__repr__(self)
Return a Python representation string for this bitset.
 
__str__(self)
Return a string of this bitset.
 
__iter__(self)
Return an iterator for this bitset.
 
__len__(self)
Returns the size of the bitset (Number of ON and OFF bits)
 
getOffIterator(self)
Allows looping over all of the OFF bits

Inherited from mmobject.MmObject: __del__, __int__

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __setattr__, __sizeof__, __subclasshook__

Class Methods [hide private]
 
from_list(cls, size, on_list)
Alternative constructor; returns a Bitset object initialized from a Python list.
Static Methods [hide private]
 
initialize(error_handler=None)
Initialize all libs that mmbs is dependent upon.
 
terminate()
Terminate the libs that were initiated in Bitset.initialize().
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, handle=None, manage_handle=True, error_handler=None, size=None)
(Constructor)

 

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.
Overrides: object.__init__

from_list(cls, size, on_list)
Class Method

 

Alternative constructor; returns a Bitset object initialized from a
Python list.

Example usage:
    bs = Bitset(st.atom_total, selected_atoms)
where <st> is the structure object, and <selected_atoms> is a list of
atom indices.

@param size: The size to use for a newly created bitset.
@type size: int

@param on_list: Turn on the bits that are present in this iterable.
    Each item should be an int between 1 and <size>.

size(self)

 

Return the capacity (i.e. maximum index) of the Bitset.

get(self, index)

 

Get the value of the index.

Returns True if the index value is on, False if it is off.

__repr__(self)
(Representation operator)

 

Return a Python representation string for this bitset.

Overrides: object.__repr__

__str__(self)
(Informal representation operator)

 

Return a string of this bitset.

Overrides: object.__str__

__iter__(self)

 

Return an iterator for this bitset. Loops over all of the ON bits.