insane/core.py
def resize_pbc_for_lipids(pbc, relL, relU, absL, absU,
                          uparea, area, hole, proteins):
    """
    Adapt the size of the box to accomodate the lipids.

    The PBC is changed **in place**.
    """
    if any(relL) and any(relU):
        # Determine box from size
        # If one leaflet is defined with an absolute number of lipids
        # then the other leaflet (with relative numbers) will follow
        # from that.
        # box/d/x/y/z needed to define unit cell

        # box is set up already...
        # yet it may be set to 0, then there is nothing we can do.
        if 0 in (pbc.x, pbc.y, pbc.z):
            raise PBCException('Not enough information to set the box size.')
    elif any(absL) or any(absU):
        # All numbers are absolute.. determine size from number of lipids
        # Box x/y will be set, d/dz/z is needed to set third box vector.
        # The area is needed to determine the size of the x/y plane OR
        # the area will be SET if a box is given.

        if pbc.z == 0:
            raise PBCException('Not enough information to set the box size.')

        if 0 in (pbc.x, pbc.y):
            # We do not know what size the box should be. 
            # Let X and Y be the same.
            #T This does not agree with the default pbc being hexagonal...
            pbc.x = pbc.y = 1
        # A scaling factor is needed for the box
        # This is the area for the given number of lipids
        upsize = sum(absU) * uparea
        losize = sum(absL) * area
        # This is the size of the hole, going through both leaflets
        holesize = np.pi * hole ** 2
        # This is the area of the PBC xy plane
        xysize = pbc.x * pbc.y
        # This is the total area of the proteins per leaflet (IMPLEMENT!)
        psize_up = sum([p.areaxy(0, 2.4) for p in proteins])
        psize_lo = sum([p.areaxy(-2.4, 0) for p in proteins])
        # So this is unavailable:
        unavail_up = holesize + psize_up
        unavail_lo = holesize + psize_lo
        # This is the current area marked for lipids
        # xysize_up = xysize - unavail_up
        # xysize_lo = xysize - unavail_lo
        # This is how much the unit cell xy needs to be scaled
        # to accomodate the fixed amount of lipids with given area.
        upscale = (upsize + unavail_up)/xysize
        loscale = (losize + unavail_lo)/xysize
        area_scale = max(upscale, loscale)
        aspect_ratio = pbc.x / pbc.y
        scale_x = np.sqrt(area_scale / aspect_ratio)
        scale_y = np.sqrt(area_scale / aspect_ratio)
        pbc.box[:2,:] *= math.sqrt(area_scale)
def resize_pbc_for_lipids(pbc, relL, relU, absL, absU,
                          uparea, area, hole, proteins):
    """
    Adapt the size of the box to accomodate the lipids.

    The PBC is changed **in place**.
    """
    if any(relL) and any(relU):
        # Determine box from size
        # If one leaflet is defined with an absolute number of lipids
        # then the other leaflet (with relative numbers) will follow
        # from that.
        # box/d/x/y/z needed to define unit cell

        # box is set up already...
        # yet it may be set to 0, then there is nothing we can do.
        if 0 in (pbc.x, pbc.y, pbc.z):
            raise PBCException('Not enough information to set the box size.')
    elif any(absL) or any(absU):
        # All numbers are absolute.. determine size from number of lipids
        # Box x/y will be set, d/dz/z is needed to set third box vector.
        # The area is needed to determine the size of the x/y plane OR
        # the area will be SET if a box is given.

        if pbc.z == 0:
            raise PBCException('Not enough information to set the box size.')

        if 0 in (pbc.x, pbc.y):
            # We do not know what size the box should be. 
            # Let X and Y be the same.
            #T This does not agree with the default pbc being hexagonal...
            pbc.x = pbc.y = 1
        # A scaling factor is needed for the box
        # This is the area for the given number of lipids
        upsize = sum(absU) * uparea
        losize = sum(absL) * area
        # This is the size of the hole, going through both leaflets
        holesize = np.pi * hole ** 2
        # This is the area of the PBC xy plane
        xysize = pbc.x * pbc.y
        # This is the total area of the proteins per leaflet (IMPLEMENT!)
        psize_up = sum([p.areaxy(0, 2.4) for p in proteins])
        psize_lo = sum([p.areaxy(-2.4, 0) for p in proteins])
        # So this is unavailable:
        unavail_up = holesize + psize_up
        unavail_lo = holesize + psize_lo
        # This is the current area marked for lipids
        # xysize_up = xysize - unavail_up
        # xysize_lo = xysize - unavail_lo
        # This is how much the unit cell xy needs to be scaled
        # to accomodate the fixed amount of lipids with given area.
        upscale = (upsize + unavail_up)/xysize
        loscale = (losize + unavail_lo)/xysize
        area_scale = max(upscale, loscale)
        aspect_ratio = pbc.x / pbc.y
        scale_x = np.sqrt(area_scale / aspect_ratio)
        scale_y = np.sqrt(area_scale / aspect_ratio)
        pbc.box[:2,:] *= math.sqrt(area_scale)
def resize_pbc_for_lipids ( pbc , relL , relU , absL , absU , uparea , area , hole , proteins ) : if any ( relL ) and any ( relU ) : # Determine box from size # If one leaflet is defined with an absolute number of lipids # then the other leaflet (with relative numbers) will follow # from that. # box/d/x/y/z needed to define unit cell # box is set up already... # yet it may be set to 0, then there is nothing we can do. if 0 in ( pbc . x , pbc . y , pbc . z ) : raise PBCException ( 'Not enough information to set the box size.' ) elif any ( absL ) or any ( absU ) : # All numbers are absolute.. determine size from number of lipids # Box x/y will be set, d/dz/z is needed to set third box vector. # The area is needed to determine the size of the x/y plane OR # the area will be SET if a box is given. if pbc . z == 0 : raise PBCException ( 'Not enough information to set the box size.' ) if 0 in ( pbc . x , pbc . y ) : # We do not know what size the box should be.  # Let X and Y be the same. #T This does not agree with the default pbc being hexagonal... pbc . x = pbc . y = 1 # A scaling factor is needed for the box # This is the area for the given number of lipids upsize = sum ( absU ) * uparea losize = sum ( absL ) * area # This is the size of the hole, going through both leaflets holesize = np . pi * hole ** 2 # This is the area of the PBC xy plane xysize = pbc . x * pbc . y # This is the total area of the proteins per leaflet (IMPLEMENT!) psize_up = sum ( [ p . areaxy ( 0 , 2.4 ) for p in proteins ] ) psize_lo = sum ( [ p . areaxy ( - 2.4 , 0 ) for p in proteins ] ) # So this is unavailable: unavail_up = holesize + psize_up unavail_lo = holesize + psize_lo # This is the current area marked for lipids # xysize_up = xysize - unavail_up # xysize_lo = xysize - unavail_lo # This is how much the unit cell xy needs to be scaled # to accomodate the fixed amount of lipids with given area. upscale = ( upsize + unavail_up ) / xysize loscale = ( losize + unavail_lo ) / xysize area_scale = max ( upscale , loscale ) aspect_ratio = pbc . x / pbc . y scale_x = np . sqrt ( area_scale / aspect_ratio ) scale_y = np . sqrt ( area_scale / aspect_ratio ) pbc . box [ : 2 , : ] *= math . sqrt ( area_scale )
Adapt the size of the box to accomodate the lipids.

    The PBC is changed **in place**.
Adapt the size of the box to accomodate the lipids .