parse_density_grid
Parse RASPA2 3D density grids to extract a 2D slice for visualization. Returns grid metadata and slice data, ready for plotting.
Instructions
Parse RASPA2 3D density grid files and extract a 2D slice (3-4).
RASPA2 writes .grid files when the simulation.input contains: WriteDensityProfile3DVTKGrid yes DensityAveragingTypeVTK number_of_molecules
The 3D grid is stored as Nx×Ny×Nz float values (row-major). This function returns the full grid metadata and ONE 2D slice. Pass the returned 'slice_data' field to plot_density_slice() to save a PNG.
KNOWN LIMITATION: This tool returns a 2D cross-section only, NOT a full 3D isosurface or volumetric render. For true 3D visualization (isosurfaces, volume rendering), export the raw 'slice_data' and use external tools such as VESTA, py3Dmol, or ParaView with the original .grid/.vtk file. To explore different planes, call this tool multiple times with different slice_axis ('x','y','z') and slice_index values.
KNOWN LIMITATION: The .grid ASCII format written by RASPA2 has minor variations across versions (header line count differs). If parsing fails (status='no_grid_files' or 'warning' in dataset), verify that WriteDensityProfile3DVTKGrid is set and check the raw file header.
Args: output_dir: Path to RASPA2 Output (or parent) directory. molecule: Optional filter on molecule name (e.g. "CO2"). slice_axis: Axis perpendicular to the slice: 'x'/'a', 'y'/'b', 'z'/'c'. slice_index: Grid-plane index along slice_axis; -1 = midpoint.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| molecule | No | ||
| output_dir | Yes | ||
| slice_axis | No | z | |
| slice_index | No |