API Reference¶
- class atomvoxelizer.VoxelGrid(cell, resolution=None, gpts=None, dtype=<class 'numpy.float32'>)[source]¶
Bases:
objectPeriodic voxel grid implemented with NumPy only.
- backend_name = 'numpy'¶
- plot_2D(axis='z', index=None, position=None, threshold=0.1, draw_cell=True, real_space=True)[source]¶
Plot a 2D slice of the voxel grid along
axis.
- plot_3D(threshold=0.1, s=5, draw_cell=True)[source]¶
Plot voxels with values above
thresholdin real space.
- sample_voxels_in_range(min_val=0.0, max_val=1.0, min_dist=0.0, return_indices=False, seed=None)[source]¶
Yield voxel positions or indices whose values lie in [min_val, max_val].
When returning real-space positions,
min_distenforces a minimum Euclidean separation in Angstrom between yielded samples.
Experimental Field Grids¶
These classes are experimental. The default implementation uses NumPy, and the Numba field-grid backend is available when Numba is installed. CuPy and Taichi field-grid backends are not implemented. See Concepts for the field-grid model.
- class atomvoxelizer.FieldVoxelGrid(cell, resolution=None, gpts=None, dtype=<class 'numpy.float32'>, value_shape=(3, ), components=None)[source]¶
Bases:
VoxelGridPeriodic voxel grid where each voxel stores an arbitrary-shaped value.
This NumPy-only prototype mirrors the geometric indexing behavior of
atomvoxelizer.VoxelGrid, but stores values with shape(*gpts, *value_shape). Examples:value_shape=()stores scalar values.value_shape=(1,)stores scalar values as length-1 vectors.value_shape=(3,)stores real-space vectors and enables themask="normal"sphere mask.value_shape=(3, 3)stores a matrix at each voxel.
- backend_name = 'numpy-field'¶
- normalize_values(inplace=True)[source]¶
Normalize nonzero voxel values and leave zero values unchanged.
- normalize_vectors(inplace=True)[source]¶
Normalize nonzero voxel values.
Kept as a convenience alias for the first vector-field prototype.
- plot_quiver_3D(stride=1, min_norm=0.0, normalize=False, ax=None, length=1.0)[source]¶
Plot a sampled 3D quiver view of a three-component vector field.
- plot_quiver_slice(axis='z', index=None, position=None, stride=1, min_norm=0.0, normalize=False, ax=None, scale=None)[source]¶
Plot a 2D quiver slice through a three-component vector field.
- quiver_3d_data(stride=1, min_norm=0.0, normalize=False)[source]¶
Return 3D quiver data for a three-component vector field.
- quiver_slice_data(axis='z', index=None, position=None, stride=1, min_norm=0.0, normalize=False)[source]¶
Return 2D quiver data for a slice through a three-component vector field.
- sample_voxels_in_range(min_val=0.0, max_val=1.0, min_dist=0.0, return_indices=False, seed=None)[source]¶
Yield voxel positions or indices whose values lie in [min_val, max_val].
When returning real-space positions,
min_distenforces a minimum Euclidean separation in Angstrom between yielded samples.
- class atomvoxelizer.VectorVoxelGrid(cell, resolution=None, gpts=None, dtype=<class 'numpy.float32'>, components=3, value_shape=None)[source]¶
Bases:
FieldVoxelGridConvenience field grid with a three-component vector value by default.
Optional Backends¶
These classes require their optional backend packages to be installed in the documentation/build environment.
- class atomvoxelizer.VoxelGridCuPy(cell, resolution=None, gpts=None, dtype=<class 'numpy.float32'>)[source]¶
Bases:
VoxelGridCuPy-backed voxel grid.
The class keeps the same public API as
atomvoxelizer.VoxelGrid, uses the Numba backend as its base when available, storesgridas a CuPy array, and overrides the mutating sphere operations.- property backend_name¶
str(object=’’) -> str str(bytes_or_buffer[, encoding[, errors]]) -> str
Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.__str__() (if defined) or repr(object). encoding defaults to sys.getdefaultencoding(). errors defaults to ‘strict’.
Analysis¶
- class atomvoxelizer.VoxelGridAnalysis(voxel_grid)[source]¶
Bases:
objectAnalyze connected voxel volumes and their surfaces.
- analyze_mask(selected, connectivity=1, periodic=True, surface_method='marching-cubes')[source]¶
Return volume and surface area for connected regions in a boolean mask.
- analyze_probe_accessibility(positions, radii, probe_radius, connectivity=1, periodic=True, surface_method='voxel-faces', write_grid=False)[source]¶
Analyze probe-center accessible volume and surface area.
This is a probe-center analysis: atom exclusion radii are inflated by
probe_radiusand accessible voxels are positions where the probe center fits. Volumes therefore describe the region available to the probe center. Surface areas describe the boundary of that accessible center region.
- analyze_regions(min_value=None, max_value=None, threshold=None, above=True, connectivity=1, periodic=True, surface_method='marching-cubes')[source]¶
Return volume and marching-cubes area for each connected region.
- static area_angstrom2_to_m2_per_g(area_angstrom2, mass_amu)[source]¶
Convert a cell/supercell area from Angstrom^2 to m^2/g.
- property cell¶
- connected_components(selected, connectivity=1, periodic=True)[source]¶
Label connected components in a boolean mask.
- property gpts¶
- property grid¶
- mask(min_value=None, max_value=None, threshold=None, above=True)[source]¶
Build a boolean mask from voxel values.
- mesh_at_value(level, periodic=True, clip_periodic=True)[source]¶
Return a marching-cubes mesh for a scalar voxel value.
levelis interpreted in the units stored in the voxel grid. For a distance-mask grid this traces the surface at a fixed distance from the nearest atom. Vertices are returned in real-space coordinates and faces index into that vertex array. Periodic meshes are clipped to the primary cell by default so boundary-crossing triangles are cut at the cell edge instead of being wrapped across the cell.
- probe_accessible_mask(positions, radii, probe_radius, write_grid=False)[source]¶
Return voxels accessible to the center of a spherical probe.
positionsmust have shape(N, 3)andradiimust contain one atom radius per position. A voxel is accessible when a probe center at that voxel does not overlap any atom, so atoms are excluded with radiusradii + probe_radius.The input voxel grid is used as the geometry template. By default, the existing grid values are not modified. Set
write_grid=Trueto store the binary accessible mask inself.voxel_grid.gridas 1 for accessible voxels and 0 for excluded voxels.
- probe_accessible_surface_area(positions, radii, probe_radius, samples_per_atom=1000, surface_radius_scale=1.0)[source]¶
Estimate probe-accessible surface area by sampling inflated atom surfaces.
Points are placed deterministically on each sphere with a Fibonacci sphere rule. A sampled point contributes to the area when it does not overlap the inflated sphere around any other atom under periodic boundary conditions.
surface_radius_scaledefaults to 1.0 for a hard-sphere contact surface. PoreBlazer uses 1.122 for its nitrogen accessible surface area calculation.
- surface_area(selected, periodic=True)[source]¶
Estimate the surface area of a boolean region with marching cubes.
- surface_area_at_value(level, periodic=True, clip_periodic=True)[source]¶
Estimate the area of a scalar isosurface at
level.
- surface_area_voxel_faces(selected, periodic=True)[source]¶
Estimate surface area by counting exposed voxel faces.
This is faster than marching cubes and avoids tiled periodic volumes. It is a grid-face estimate rather than a smoothed triangular surface, so it is most useful for fast convergence scans or large grids.
- static volume_angstrom3_to_cm3_per_g(volume_angstrom3, mass_amu)[source]¶
Convert a cell/supercell volume from Angstrom^3 to cm^3/g.
- property voxel_volume¶
- class atomvoxelizer.ProbeAccessibleResult(probe_radius, accessible_voxel_count, accessible_volume, accessible_surface_area, regions, accessible_mask)[source]¶
Bases:
objectProbe-center accessible volume and surface summary.
- Parameters:
probe_radius (float)
accessible_voxel_count (int)
accessible_volume (float)
accessible_surface_area (float)
regions (list[VoxelRegion])
accessible_mask (ndarray)
- accessible_mask: ndarray¶
- accessible_surface_area: float¶
- accessible_volume: float¶
- accessible_voxel_count: int¶
- probe_radius: float¶
- regions: list[VoxelRegion]¶