packing_defect.core.grid

Classes

DefectGrid(box_xy[, dx, dy, hz])

2D grid accumulator for membrane packing defects.

class packing_defect.core.grid.DefectGrid(box_xy, dx=1.0, dy=1.0, hz=None)[source]

Bases: object

2D grid accumulator for membrane packing defects.

The grid is defined over the XY plane and tracks two leaflets (“up” and “dw”). Each grid cell stores an integer code identifying the type of defect stamped there and a per-leaflet depth value used to keep only the most exposed atom per cell.

Parameters:
  • box_xy (tuple[float, float]) – Box lengths along X and Y in the same units as positions.

  • dx (float, optional) – Grid spacing along X and Y.

  • dy (float, optional) – Grid spacing along X and Y.

  • hz (float, optional) – Mid-plane Z used to separate leaflets; when omitted, callers should ensure consistent leaflet assignment when calling update.

Variables:
  • grid (dict[str, np.ndarray]) – Integer codes for each leaflet, shape (nx, ny).

  • zdepth (dict[str, np.ndarray]) – Depth tracker per leaflet used to keep the outermost atom per cell.

  • ny (nx,) – Number of grid bins along X and Y.

  • dy (dx,) – Grid spacings along X and Y.

cluster_sizes(leaflet)[source]

Return connected-component sizes for a leaflet.

Parameters:

leaflet ({"up", "dw"}) – Leaflet to analyze.

Returns:

Sizes (in grid cells) of each connected component.

Return type:

list[int]

get_binary_mask(leaflet: str, threshold: int) ndarray[source]

Return a binary mask where grid values equal threshold.

Parameters:
  • leaflet ({"up", "dw"}) – Leaflet to extract.

  • threshold (int) – Code value considered as a defect in the mask.

Returns:

Binary array of shape (nx, ny) where matches are 1 else 0.

Return type:

np.ndarray

get_coordinates(leaflet, code)[source]

Coordinates of grid cell centers matching code.

Parameters:
  • leaflet ({"up", "dw"}) – Leaflet to query.

  • code (int) – Integer code to match.

Returns:

Arrays of X and Y coordinates of matching grid centers.

Return type:

tuple[np.ndarray, np.ndarray]

update(x, y, z, r, code, leaflet)[source]

Stamp a circular defect into the grid.

For the selected leaflet, all grid cells whose centers fall within the effective radius are assigned code. The most exposed atom along Z wins per cell: for “up” we keep the maximum Z, for “dw” the minimum Z.

Parameters:
  • x (float) – Atom coordinates.

  • y (float) – Atom coordinates.

  • z (float) – Atom coordinates.

  • r (float) – Stamp radius.

  • code (int) – Integer code to write into covered cells.

  • leaflet ({"up", "dw"}) – Target leaflet.