Skip to content

Commit

Permalink
Add tests for conversion vecs wrt basis sets
Browse files Browse the repository at this point in the history
  • Loading branch information
Ali-Tehrani committed Aug 5, 2020
1 parent 6f3f76f commit ccb04a8
Showing 1 changed file with 77 additions and 1 deletion.
78 changes: 77 additions & 1 deletion iodata/test/test_overlap.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@

from ..api import load_one
from ..basis import MolecularBasis, Shell
from ..overlap import compute_overlap, OVERLAP_CONVENTIONS
from ..overlap import compute_overlap, OVERLAP_CONVENTIONS, convert_vector_basis
from ..overlap_accel import fac2, _binom
from ..overlap_cartpure import tfs

try:
from importlib_resources import path
Expand Down Expand Up @@ -107,3 +108,78 @@ def test_overlap_l1():
atcoords = np.zeros((3, 1))
with raises(ValueError):
_ = compute_overlap(dbasis, atcoords)


def test_converting_between_orthonormal_basis_set():
# Test converting from basis set of M Elements to N Elements where M <= N.
# All basis sets are assumed orthonormal and 1st basis set is assumed to be
# in the second basis set.
M = np.random.randint(1, 25)
N = np.random.randint(M, 50)
coeffs1 = np.random.random(M)
basis2_overlap = np.eye(N) # Since it is orthonormal, it is identity.

basis21_overlap = np.zeros((N, M))
for i in range(0, M):
basis21_overlap[i, i] = 1. # Since it is a subset.

coeffs2 = convert_vector_basis(coeffs1, basis2_overlap, basis21_overlap)
assert_equal(coeffs1, coeffs2[:M])
assert_equal(np.zeros(coeffs2[M:].shape), coeffs2[M:])

# Test converting in the reverse direction ie Large to small.
coeffs2 = np.random.random(N)
basis1_overlap = np.eye(M)
basis12_overlap = np.zeros((M, N))
for i in range(0, M):
basis12_overlap[i, i] = 1. # Since it is a subset.

coeffs1 = convert_vector_basis(coeffs2, basis1_overlap, basis12_overlap)
assert_equal(len(coeffs1), M)
assert_equal(coeffs1, coeffs2[:M])


def test_converting_from_cartesian_to_pure():
# Test converting simple one coefficient, S-type.
overlap_cp = tfs[0]
coeff = np.array([5.])
coeff2 = convert_vector_basis(coeff, np.eye(1), overlap_cp)
assert_equal(coeff, coeff2)

# Test converting p-type.
overlap_cp = tfs[1]
coeff = np.array([1., 2., 3.])
coeff2 = convert_vector_basis(coeff, np.eye(3), overlap_cp)
desired = np.array([3., 1., 2.])
assert_equal(coeff2, desired)

# Test converting d-type.
overlap_cp = tfs[2]
coeff = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0])
coeff2 = convert_vector_basis(coeff, np.eye(5), overlap_cp)
desired = np.array([-0.5 - 0.5 * 4.0 + 6.0, 3.0, 5.0,
0.86602540378 * 1.0 - 0.86602540378 * 4.0, 2.0])
assert_allclose(coeff2, desired)


def test_converting_from_pure_to_cartesian():
# Test converting S-type.
overlap_cp = tfs[0]
coeff = np.array([5.])
coeff2 = convert_vector_basis(coeff, np.eye(1), overlap_cp.T)
assert_equal(coeff, coeff2)

# Test converting P-type.
overlap_cp = tfs[1]
coeff = np.array([1., 2., 3.])
coeff2 = convert_vector_basis(coeff, np.eye(3), overlap_cp.T)
desired = np.array([2., 3., 1.])
assert_equal(coeff2, desired)

# Test converting D-type.
overlap_cp = tfs[2]
coeff = np.array([1., 2., 3., 4., 5.])
coeff2 = convert_vector_basis(coeff, np.eye(6), overlap_cp.T)
desired = np.array([np.sqrt(3.0) * 4.0 / 2.0 - 0.5, 5.0, 2.0,
-np.sqrt(3.0) * 4.0 / 2.0 - 0.5, 3.0, 1.0])
assert_equal(coeff2, desired)

0 comments on commit ccb04a8

Please sign in to comment.