Example #1
0
class SASAShape(Shape):
    '''
    This is a Solvent Accessible Surface Shape (SAS) for a given Diagram. It is
    used mainly to compute Solvent Accessible Surface Area (SASA)
    
    SAS is a shape of the union of balls and thus is strongly connected with Alpha SHape.
    Alpha SHape is more like a topological description of the Shape (what is connected with what), while
    SAS is the description of the actual union of balls. If you are interested only in topological aspect
    we suggest Alpha Shapes as those are a bit faster to compute.  
    
    :param diagram_or_container: Diagram or Container class to use for computations
    
    **NOTE** if Container class is used to instantiate then the class will create Diagram for internal use    
    '''
    def __init__(self, diagram_or_container):
        '''
        diagram_or_container is either Diagram or Container, if container, then Diagram is internally created
        '''
        # make sure we have diagram
        if isinstance(diagram_or_container, Diagram):
            self.diagram = diagram_or_container
        elif isinstance(diagram_or_container, Container):
            # make new diagram
            self.diagram = Diagram(diagram_or_container)
        else:
            raise TypeError(
                "AlphaShape.__init__(): Diagram or Container required but something else given"
            )
        # do rest of the initialization
        self._diagram_handle = self.diagram._diagram_handle
        # create item on the C++ side
        self._shape_handle = dmga2py.new_sasa_shape(self._diagram_handle)

    def size(self):
        '''
        :return: number of cells in this shape, the same as size in diagram
        '''
        return self.diagram.size()

    def get_cell(self, number):
        '''
        :return: one cell of this shape
        
        the class of shape depends on the type of the shape
        in SASA Shape it is SASACell for this cell that holds the COntour information (SASArcs)
        '''
        (shape_cell_handle, cell_handle,
         contour_handle) = dmga2py.sasa_shape_get_shape_cell(
             self._shape_handle, number)
        return SASACell(shape_cell_handle, cell_handle, contour_handle, number)

    def __del__(self):
        '''
        free all C++ objects if necessary
        '''
        # TODO: why it is caousing core dump???????
        dmga2py.free_object(self._shape_handle)
        pass

    def __iter__(self):
        '''
        :return: iterator over all shape cells in this shape
        '''
        return ShapeIterator(self)

    def sas_area(self):
        '''
        :return: area of all computed cells in this SASA Shape that is area of the intersection of sphere with its voronoi cell 
        '''
        return dmga2py.sasa_shape_get_area(self._shape_handle)

    def sas_volume(self):
        '''
        :return: volume of all computed cells in this SASA Shape that is volume of the intersection of ball with its voronoi cell 
        '''
        return dmga2py.sasa_shape_get_volume(self._shape_handle)
Example #2
0
class AlphaShape(Shape):
    '''
    This class represents a description of the Alpha Shape of a given Diagram
    
    :param diagram_or_container: Diagram or Container class to use for computations
    
    **NOTE** if Container class is used to instantiate then the class will create Diagram for internal use
    '''
    def __init__(self, diagram_or_container):
        '''
        diagram_or_container is either Diagram or Container, if container, then Diagram is internally created
        '''
        # make sure we have diagram
        if isinstance(diagram_or_container, Diagram):
            # print "AlphaShape::__init__(): we have Diagram"
            self.diagram = diagram_or_container
        elif isinstance(diagram_or_container, Container):
            # make new diagram
            # print "AlphaShape::__init__(): we have Container"
            self.diagram = Diagram(diagram_or_container)
        else:
            raise TypeError(
                "AlphaShape.__init__(): Diagram or Container required but something else given"
            )
        # do rest of the initialization
        self._diagram_handle = self.diagram._diagram_handle
        # print "Diagram handle =", self.diagram._diagram_handle
        # create item on the C++ side
        self._shape_handle = dmga2py.new_alpha_shape(self._diagram_handle)

    def size(self):
        '''
        :return: number of cells in this shape, the same as size in diagram
        '''
        return self.diagram.size()

    def get_cell(self, number):
        '''
        :return: one cell of this shape
        
        The class of shape depends on the type of the shape
        in Alpha Shape it is Alpha Complex (subset of...) for this cell
        '''
        (shape_cell_handle, cell_handle,
         complex_handle) = dmga2py.alpha_shape_get_shape_cell(
             self._shape_handle, number)
        # complex_handle = dmga2py.alpha_shape_get_complex(self._shape_handle, number)
        return AlphaShapeCell(shape_cell_handle, cell_handle, complex_handle)

    def __del__(self):
        '''
        free all C++ objects if necessary
        '''
        dmga2py.free_object(self._shape_handle)

    def __iter__(self):
        '''
        :return: iterator over all shape cells in this shape
        '''
        return ShapeIterator(self)

    def max_alpha_threshold(self):
        '''
        :return: max alpha_threshold - value of alpha at which all elements from diagram belongs to the alpha-complex for all cells
        
        **NOTE** max_threshold is computed only for those cells that were actually created by for 
        example get_cell() or get_cells() or if diagram has cache_on property set to ON (True).
        '''
        return dmga2py.alpha_shape_get_max_alpha_threshold(self._shape_handle)