Skip to content

Commit

Permalink
Added some tests about the electronic structure ground state
Browse files Browse the repository at this point in the history
  • Loading branch information
LaurentRDC committed Jun 21, 2022
1 parent d9a7236 commit e516402
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
3 changes: 3 additions & 0 deletions crystals/atom.py
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,9 @@ def __init__(self, shells: Dict[Union[str, Orbital], int]):
for k, v in shells.items():
self.__setitem__(k, v)

def __iter__(self):
yield from self._structure

def __setitem__(self, key: Union[str, Orbital], value: int):
# We check that the number of electrons in each Orbital does not
# go above maximum possible.
Expand Down
13 changes: 13 additions & 0 deletions crystals/tests/test_atom.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,19 @@ def test_orbital_maximum_electrons():
assert maxima[shell.value[-1]] == Orbital.maximum_electrons(shell)


@pytest.mark.parametrize("element, structure", (["C", {"1s": 2, "2s": 2, "2p": 2}],))
def test_electronic_structure_ground_state_examples(element, structure):
gs = ElectronicStructure.ground_state(element)
assert gs == ElectronicStructure(shells=structure)


@pytest.mark.parametrize("element", range(1, 24))
def test_electronic_structure_ground_state_num_electrons(element):
gs = ElectronicStructure.ground_state(element)
num_electrons = sum(gs[k] for k in gs)
assert num_electrons == element


def test_electronic_structure_maximum_electrons():
"""Test that an error is raised for impossible electronic structures."""
with pytest.raises(ValueError):
Expand Down

0 comments on commit e516402

Please sign in to comment.