Generating Cube Files

This example will illustrate how to generate .cube files using UniformGrid from Grid package for various functions that CuChemTools can compute. There are many scalar-functions that CuChemTools can compute that can be used to substitute any function (e.g. density, laplacian) below.

[1]:
from cugbasis import Molecule

file_path = r"./ALA_ALA_peptide_uwb97xd_def2svpd.fchk"
mol = Molecule(file_path)
[2]:
from grid.cubic import UniformGrid

grid = UniformGrid.from_molecule(mol.atnums, mol.atcoords, spacing=0.13, extension=10.0, weight="Rectangle")
print(f"Origin of grid:   {grid.origin}")
print(f"Cubic Grid Axes:  {grid.axes}")
print(f"Cubic Grid Shape: {grid.shape}")
print(f"Number of Points: {len(grid.points)}")

Origin of grid:   [23.83113906 34.61384519  5.25461588]
Cubic Grid Axes:  [[-0.0488626  -0.05321598  0.10807639]
 [ 0.04014544 -0.11715483 -0.03953591]
 [-0.11358164 -0.01851498 -0.06046822]]
Cubic Grid Shape: [279 245 199]
Number of Points: 13602645

Density

[3]:
import numpy as np

dens = mol.compute_density(grid.points)

print(f"Total number of electrons:       {np.sum(mol.atnums)}")
print(f"Integration of electron density: {grid.integrate(dens)}")

# Generate cube file for the density
grid.generate_cube("density_ala_ala.cube", dens, mol.atcoords, mol.atnums)

# Load the cube file
grid_2, grid_data = UniformGrid.from_cube("./density_ala_ala.cube", weight="Rectangle", return_data=True)

print(f"Integration Using Loaded Cube:   {grid_2.integrate(grid_data['data'])}")
print(f"Do both densities match:         {np.all(np.abs(dens - grid_data['data']) < 1e-3)}")
Total number of electrons:       108
Integration of electron density: 107.9762750986812
Integration Using Loaded Cube:   107.97634587639091
Do both densities match:         True

Laplacian

[4]:
lap = mol.compute_laplacian(grid.points)

# Generate cube file for the density
grid.generate_cube("lap_ala_ala.cube", lap, mol.atcoords, mol.atnums)

# Load the cube file
#grid_2, grid_data = UniformGrid.from_cube("./lap_ala_ala.cube", weight="Rectangle", return_data=True)
#lap_2 = grid_data["data"]

Reduced Density Gradient

[5]:
rdg = mol.compute_reduced_density_gradient(grid.points)

# Generate cube file for the density
grid.generate_cube("rdg_ala_ala.cube", rdg, mol.atcoords, mol.atnums)

# Load the cube file
#grid_2, grid_data = UniformGrid.from_cube("./rdg_ala_ala.cube", weight="Rectangle", return_data=True)
#rdg_2 = grid_data["data"]