Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for density evaluations #94

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added tests/data_horton_hhe_cart_density_rand.npy
Binary file not shown.
Binary file added tests/data_horton_hhe_cart_dm_rand.npy
Binary file not shown.
Binary file added tests/data_horton_hhe_sph_density_rand.npy
Binary file not shown.
Binary file added tests/data_horton_hhe_sph_dm_rand.npy
Binary file not shown.
32 changes: 32 additions & 0 deletions tests/test_density.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,38 @@ def test_evaluate_density_horton():
)


def test_evaluate_density_horton_nonidentity_dm():
"""Test gbasis.evals.density.evaluate_density against result from HORTON.

The test case is diatomic with H and He separated by 0.8 angstroms with basis set ANO-RCC.
Density matrix here is not an identity matrix and is instead a random symmetric matrix.

"""
basis_dict = parse_nwchem(find_datafile("data_anorcc.nwchem"))
points = np.array([[0, 0, 0], [0.8, 0, 0]])
basis = make_contractions(basis_dict, ["H", "He"], points)
basis = [HortonContractions(i.angmom, i.coord, i.coeffs, i.exps) for i in basis]

grid_1d = np.linspace(-2, 2, num=5)
grid_x, grid_y, grid_z = np.meshgrid(grid_1d, grid_1d, grid_1d)
grid_3d = np.vstack([grid_x.ravel(), grid_y.ravel(), grid_z.ravel()]).T
grid_3d = np.ascontiguousarray(grid_3d)

horton_density = np.load(find_datafile("data_horton_hhe_cart_density_rand.npy"))
density_matrix = np.load(find_datafile("data_horton_hhe_cart_dm_rand.npy"))
Comment on lines +317 to +318
Copy link
Member

@FarnazH FarnazH Jan 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This tests against HORTON (based on these test files included in the repo), so I don't understand why a random density matrix is used. @maximilianvz, can you update this test and its files to use a real example?


assert np.allclose(
evaluate_density(density_matrix, basis, grid_3d, coord_type="cartesian"), horton_density
)

horton_density = np.load(find_datafile("data_horton_hhe_sph_density_rand.npy"))
density_matrix = np.load(find_datafile("data_horton_hhe_sph_dm_rand.npy"))

assert np.allclose(
evaluate_density(density_matrix, basis, grid_3d, coord_type="spherical"), horton_density
)


def test_evaluate_density_gradient_horton():
"""Test gbasis.evals.density.evaluate_density_gradient against result from HORTON.

Expand Down