Example #1
0
def test_eigenbasis_transformation_non_orthogonal():

    basis = [HarmonicOscillator(n=i, center=0.25) for i in range(2)] + [
        HarmonicOscillator(n=i, center=-0.25) for i in range(2)
    ]

    S = pairwise_array_from_func(basis, Overlap())
    H = pairwise_array_from_func(basis, Hamiltonian(Harmonic(center=0.0)))
    eigb = EigenBasis.from_basis(basis, H, S)
    xform_H = eigb.transformed(H)

    assert is_diagonal(xform_H)
    assert np.allclose(np.diag(xform_H), eigb.energies, atol=conf.small_number)
Example #2
0
def test_pairwise_array_from_func():

    mylist = [1, 2, 3]

    expected = np.array([[2, 3, 4], [3, 4, 5], [4, 5, 6]])

    result = pairwise_array_from_func(mylist, f)

    assert np.allclose(result, expected)
Example #3
0
def test_eigen_basis_non_orthogonal():
    """
    This is the best thing I could think of to test this.
    Given a set of harmonic oscillators that aren't centered,
    see if we can reproduce the solution to a QHO
    """

    basis = [HarmonicOscillator(n=i, center=0.25) for i in range(2)] + [
        HarmonicOscillator(n=i, center=-0.25) for i in range(2)
    ]

    S = pairwise_array_from_func(basis, Overlap())
    H = pairwise_array_from_func(basis, Hamiltonian(Harmonic(center=0.0)))
    eigb = EigenBasis.from_basis(basis, H, S)

    # check the first 3 energy levels, we won't have converged
    # the higher ones wrt basis set size
    expected_energies = [(n + 0.5) for n in range(3)]

    diffs = [e1 - e2 for e1, e2 in zip(sorted(eigb.energies), expected_energies)]

    # a little lenient due to convergence of basis to keep test fast
    assert all(math.isclose(d, 0.0, abs_tol=1e-3) for d in diffs)
Example #4
0
 def R(self):
     """Calculate the distances for each atom-atom pair."""
     return pairwise_array_from_func(self.atoms, Atom.distance)
Example #5
0
 def matrix(self, basis) -> np.array:
     """Return a matrix of the operator projected onto a basis."""
     return pairwise_array_from_func(basis, self, symmetric=self.hermitian)