Skip to content

init

__all__ = ['SphericalRegion', 'RectangularRegion', 'collect_regions', 'GridMesh']

GridMesh(box, res)

A class representing a box of equidistant points.

Initialize the class.

PARAMETER DESCRIPTION

box

A numpy array representing two 3D points, (min_x, min_y, min_z) and (max_x, max_y, max_z), that define a box.

TYPE: NDArray[float64]

res

The space between the points of the box, in the X, Y, and Z direction.

TYPE: float

points = np.array(list(zip(x.ravel(), y.ravel(), z.ravel())))

write_pdbs = write_pdbs()

__snap_float(val, res)

Snaps an arbitrary point to the nearest grid point.

PARAMETER DESCRIPTION

val

A numpy array corresponding to a 3D point.

TYPE: NDArray[float64]

res

The resolution (distance in the X, Y, and Z directions between adjacent points) of the grid.

TYPE: float

RETURNS DESCRIPTION
NDArray[float64]

A numpy array corresponding to a 3D point near val that is on a nearby grid point.

__unique_points()

Identifies unique points (rows) in an array of points.

PARAMETER DESCRIPTION

a

A n x 3 np.array representing 3D points.

RETURNS DESCRIPTION

A n x 2 np.array containing the 3D points that are unique.

expand_around_existing_points(num_pts, reso)

Add points to the current box that surround existing points, essentially increasing the resolution of the box.

For each surviving grid point, new points are placed at all integer multiples of reso within a cube of half-width num_pts x reso centred on the original point. Duplicates are removed.

PARAMETER DESCRIPTION

num_pts

An int, the number of points to place on each side of the existing points, in the X, Y, and Z directions.

res

The distance between adjacent added points.

filter_isolated_points_until_no_change(reso, number_of_neighbors)

Iteratively remove points with too few neighbors.

Points on the fringe of a pocket often have fewer grid neighbors than points in the pocket interior. This method repeatedly removes any point with fewer than number_of_neighbors neighbors (counted within the diagonal distance of one grid cell) until the point set stabilizes.

PARAMETER DESCRIPTION

res

The grid spacing. The neighbor cutoff is derived as reso x sqrt(3) x 1.1 to include diagonal (kitty-corner) neighbors.

number_of_neighbors

The minimum number of permissible neighbors.

remove_all_points_close_to_other_points(other_points, dist_cutoff, config)

Remove grid points that are within a cutoff of protein atoms.

PARAMETER DESCRIPTION

other_points

An (m, 3) array of protein-atom coordinates.

TYPE: NDArray[float64]

dist_cutoff

Grid points closer than this distance to any atom are removed.

TYPE: float

config

Configuration object (n_cores, use_ray).

TYPE: PocketVolumeConfig

remove_points_outside_convex_hull(hull, config)

Removes box points that are outside a convex hull.

PARAMETER DESCRIPTION

hull

The convex hull.

config

Configuration object containing n_cores.

separate_out_pockets()

Partition surviving points into distinct pockets.

Two points belong to the same pocket if they are connected through a chain of grid neighbors (26-connectivity, i.e., including diagonal/kitty-corner neighbors).

  1. Points are mapped to integer (i, j, k) indices by subtracting the grid minimum and dividing by the grid spacing.
  2. A 3D boolean volume is constructed and filled at the appropriate indices.
  3. scipy.ndimage.label performs connected-component labelling with 26-connectivity.
  4. Each connected component is extracted as a separate pocket.
RETURNS DESCRIPTION
list[NDArray[float64]]

A list of (n_i, 3) arrays, one per pocket, sorted in descending order of point count (largest pocket first).

to_pdb(let='X')

Converts the points in this box into a PDB representation.

PARAMETER DESCRIPTION

let

An optional string, the chain ID to use. "X" by default.

DEFAULT: 'X'

RETURNS DESCRIPTION

A PDB-formatted string.

RectangularRegion(center, lengths)

Bases: Region

A 3D rectangular region defined by its center and dimensions.

This class represents a rectangular box in 3D space, capable of generating a grid of points that fill the box.

Initialize a rectangular region.

PARAMETER DESCRIPTION

center

The x, y, and z coordinates of the center of the box.

TYPE: list[float]

lengths

The lengths of the box along the x, y, and z axes.

TYPE: list[float]

center = np.array(center)

A list of three floats representing the x, y, and z coordinates of the box's center, in Angstroms.

lengths = np.array(lengths)

A list of three floats representing the lengths of the box along the x, y, and z axes, in Angstroms.

__str__()

Returns a string representation of the rectangular region.

get_points(res)

Generates a grid of points filling the rectangular region.

PARAMETER DESCRIPTION

res

The resolution of the grid, defining the spacing between points.

RETURNS DESCRIPTION

A numpy array of shape (n, 3), where each row is a [x, y, z]

coordinate representing a point within the rectangular region.

SphericalRegion(center, radius)

Bases: Region

A 3D spherical region defined by a center and a radius.

This class represents a sphere in 3D space, capable of generating a grid of points that fill the sphere. Points outside the sphere boundary are excluded.

Initialize a spherical region.

PARAMETER DESCRIPTION

center

The x, y, and z coordinates of the center of the sphere.

TYPE: list[float]

radius

The radius of the sphere in Angstroms.

TYPE: float

center = np.array(center)

x, y, and z coordinates in Angstroms of the center.

radius = radius

Sphere radius in Angstroms.

__str__()

Returns a string representation of the spherical region.

get_points(res)

Generate grid points filling the sphere.

A cubic grid spanning [center - radius, center + radius] is constructed along each axis, then points outside the sphere are removed using a vectorized Euclidean-norm test.

PARAMETER DESCRIPTION

res

The grid spacing (Å).

TYPE: float

RETURNS DESCRIPTION
NDArray[float64]

An (n, 3) array of interior grid points.

collect_regions(spherical_configs, rectangular_configs)

Creates a collection of 3D regions from spherical and rectangular configurations.

This function takes configurations for spherical and rectangular regions, instantiates the respective region objects, and returns a combined list of these regions. Empty or invalid configurations are skipped.

PARAMETER DESCRIPTION

spherical_configs

A list of dictionaries, each specifying a spherical region. Each dictionary must have:

  • "center" (list[float]): The x, y, and z coordinates of the sphere's center.
  • "radius" (float): The radius of the sphere.

If None, no spherical regions are added.

TYPE: list[dict[str, list[float] | float]] | None

rectangular_configs

A list of dictionaries, each specifying a rectangular region. Each dictionary must have:

  • "center" (list[float]): The x, y, and z coordinates of the box's center.
  • "lengths" (list[float]): The lengths of the box along the x, y, and z axes.

If None, no rectangular regions are added.

TYPE: list[dict[str, list[float]]] | None

RETURNS DESCRIPTION
list[SphericalRegion | RectangularRegion]

A list containing SphericalRegion and RectangularRegion objects created based on the provided configurations.

Example
>>> spherical_configs = [
...     {"center": [0.0, 0.0, 0.0], "radius": 5.0},
...     {"center": [10.0, 10.0, 10.0], "radius": 3.0},
... ]
>>> rectangular_configs = [
...     {"center": [0.0, 0.0, 0.0], "lengths": [10.0, 5.0, 2.0]}
... ]
>>> regions = collect_regions(spherical_configs, rectangular_configs)
>>> for region in regions:
...     print(region)
sphere at (0.0, 0.0, 0.0), radius = 5.0
sphere at (10.0, 10.0, 10.0), radius = 3.0
box centered at (0.0, 0.0, 0.0) with dimensions (10.0, 5.0, 2.0)