Skip to content

Commit

Permalink
fix test_basis_set.py
Browse files Browse the repository at this point in the history
  • Loading branch information
EBB2675 committed Dec 4, 2024
1 parent 80c8b64 commit 4ac1076
Showing 1 changed file with 57 additions and 45 deletions.
102 changes: 57 additions & 45 deletions tests/test_basis_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,86 +422,97 @@ def test_quick_step() -> None:


@pytest.mark.parametrize(
'basis_set_name, basis_type, role',
'basis_set_name, basis_type, role, expected_name, expected_type, expected_role',
[
('cc-pVTZ', 'GTO', 'orbital'),
('def2-TZVP', 'GTO', 'auxiliary_scf'),
('aug-cc-pVDZ', 'STO', 'auxiliary_post_hf'),
('custom_basis', None, None), # Undefined type and role
('cc-pVTZ', 'GTO', 'orbital', 'cc-pVTZ', 'GTO', 'orbital'),
('def2-TZVP', 'GTO', 'auxiliary_scf', 'def2-TZVP', 'GTO', 'auxiliary_scf'),
('aug-cc-pVDZ', 'STO', 'auxiliary_post_hf', 'aug-cc-pVDZ', 'STO', 'auxiliary_post_hf'),
('custom_basis', None, None, 'custom_basis', None, None), # Undefined type and role
],
)
def test_atom_centered_basis_set_init(basis_set_name, basis_type, role) -> None:
def test_atom_centered_basis_set_init(
basis_set_name, basis_type, role, expected_name, expected_type, expected_role
):
"""Test initialization of AtomCenteredBasisSet."""
bs = AtomCenteredBasisSet(basis_set=basis_set_name, type=basis_type, role=role)
assert bs.basis_set == basis_set_name
assert bs.type == basis_type
assert bs.role == role
assert bs.basis_set == expected_name
assert bs.type == expected_type
assert bs.role == expected_role


@pytest.mark.parametrize(
'functions',
'functions, expected_count',
[
[
AtomCenteredFunction(
basis_type='spherical',
function_type='s',
n_primitive=3,
exponents=[1.0, 2.0, 3.0],
contraction_coefficients=[0.5, 0.3, 0.2],
),
],
[
AtomCenteredFunction(
basis_type='cartesian',
function_type='p',
n_primitive=1,
exponents=[0.5],
contraction_coefficients=[1.0],
),
AtomCenteredFunction(
basis_type='spherical',
function_type='d',
n_primitive=2,
exponents=[1.0, 2.0],
contraction_coefficients=[0.4, 0.6],
),
],
(
[
AtomCenteredFunction(
harmonic_type='spherical',
function_type='s',
n_primitive=3,
exponents=[1.0, 2.0, 3.0],
contraction_coefficients=[0.5, 0.3, 0.2],
),
],
1,
),
(
[
AtomCenteredFunction(
harmonic_type='cartesian',
function_type='p',
n_primitive=1,
exponents=[0.5],
contraction_coefficients=[1.0],
),
AtomCenteredFunction(
harmonic_type='spherical',
function_type='d',
n_primitive=2,
exponents=[1.0, 2.0],
contraction_coefficients=[0.4, 0.6],
),
],
2,
),
],
)
def test_atom_centered_basis_set_functional_composition(functions) -> None:
def test_atom_centered_basis_set_functional_composition(functions, expected_count):
"""Test functional composition within AtomCenteredBasisSet."""
bs = AtomCenteredBasisSet(functional_composition=functions)
assert len(bs.functional_composition) == len(functions)
assert len(bs.functional_composition) == expected_count
for f, ref_f in zip(bs.functional_composition, functions):
assert f.basis_type == ref_f.basis_type
assert f.harmonic_type == ref_f.harmonic_type
assert f.function_type == ref_f.function_type
assert f.n_primitive == ref_f.n_primitive
assert np.allclose(f.exponents, ref_f.exponents)
assert np.allclose(f.contraction_coefficients, ref_f.contraction_coefficients)


def test_atom_centered_basis_set_normalize() -> None:
def test_atom_centered_basis_set_normalize():
"""Test normalization of AtomCenteredBasisSet."""
bs = AtomCenteredBasisSet(
basis_set='cc-pVTZ',
type='GTO',
role='orbital',
functional_composition=[
AtomCenteredFunction(
basis_type='spherical',
harmonic_type='spherical',
function_type='s',
n_primitive=2,
exponents=[1.0, 2.0],
contraction_coefficients=[0.5, 0.5],
)
],
)
bs.normalize(None, logger)
# Add checks for normalized behavior, if any
bs.normalize(None, None)
# Add assertions for normalized attributes if needed
assert bs.basis_set == 'cc-pVTZ'
assert bs.type == 'GTO'
assert bs.role == 'orbital'
assert len(bs.functional_composition) == 1


def test_atom_centered_basis_set_invalid_data() -> None:
def test_atom_centered_basis_set_invalid_data():
"""Test behavior with missing or invalid data."""
bs = AtomCenteredBasisSet(
basis_set='invalid_basis',
Expand All @@ -514,7 +525,7 @@ def test_atom_centered_basis_set_invalid_data() -> None:

# Test functional composition with invalid data
invalid_function = AtomCenteredFunction(
basis_type='spherical',
harmonic_type='spherical',
function_type='s',
n_primitive=2,
exponents=[1.0], # Mismatched length
Expand All @@ -524,4 +535,5 @@ def test_atom_centered_basis_set_invalid_data() -> None:

# Call normalize to trigger validation
with pytest.raises(ValueError, match='Mismatch in number of exponents'):
invalid_function.normalize(None, logger)
invalid_function.normalize(None, None)

1 comment on commit 4ac1076

@github-actions
Copy link

Choose a reason for hiding this comment

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

Coverage

Coverage Report
FileStmtsMissCoverMissing
src/nomad_simulations
   __init__.py4250%3–4
   _version.py11282%5–6
src/nomad_simulations/schema_packages
   __init__.py15287%39–41
   atoms_state.py1902189%13–15, 201–204, 228, 283–284, 352–353, 355, 537, 549–550, 611–615, 630–634, 641
   basis_set.py2674085%8–9, 122–133, 172–185, 263–288, 522–526, 548–549, 593–596, 715, 746, 748
   general.py89891%4–7, 121, 185, 295–296, 306
   model_method.py2697871%10–12, 171–174, 177–184, 276–277, 297, 318–339, 355–381, 384–401, 587, 780, 791, 833–840, 878, 897, 977, 1034, 1109, 1223
   model_system.py3483789%45–51, 235, 254, 258, 261, 264, 290, 376–377, 454–455, 472–473, 686–689, 736–743, 917–918, 1140–1144, 1150–1151, 1159–1160, 1165, 1188
   numerical_settings.py2786776%12–14, 204–210, 280, 282–283, 286–289, 293–294, 301–304, 313–316, 320–323, 325–328, 333–336, 342–345, 532–559, 634, 669–672, 696, 699, 744, 746–749, 753, 757, 804, 808–829, 884–885, 952, 974
   outputs.py1201092%9–10, 252–255, 295–298, 323, 325, 362, 381
   physical_property.py102793%20–22, 202, 331–333
   variables.py861286%8–10, 98, 121, 145, 167, 189, 211, 233, 256, 276
src/nomad_simulations/schema_packages/properties
   band_gap.py51590%8–10, 135–136
   band_structure.py1232580%9–11, 232–265, 278, 285, 321–322, 325, 372–373, 378
   energies.py42979%7–9, 36, 57, 82, 103, 119, 134
   fermi_surface.py17476%7–9, 40
   forces.py22673%7–9, 36, 56, 79
   greens_function.py991387%7–9, 210–211, 214, 235–236, 239, 260–261, 264, 400
   hopping_matrix.py29583%7–9, 58, 94
   permittivity.py48883%7–9, 97–105
   spectral_profile.py26012851%9–11, 57–60, 95–98, 199–300, 356–368, 393–396, 416, 421–424, 466–502, 526, 573–576, 592–593, 598–604
   thermodynamics.py752764%7–9, 35, 56, 72, 81, 90, 101, 110, 137, 147, 157, 172–174, 177, 193, 213–215, 218, 234, 254–256, 259
src/nomad_simulations/schema_packages/utils
   utils.py791680%8–11, 65–74, 83–84, 89, 92, 169–170
TOTAL263553280% 

Tests Skipped Failures Errors Time
423 0 💤 0 ❌ 0 🔥 6.588s ⏱️

Please sign in to comment.