Skip to content

Commit

Permalink
Add WFN and WFX test and cleanup other WFN and WFX tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tovrstra committed Jun 20, 2024
1 parent 4672143 commit e17b6d8
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 25 deletions.
33 changes: 18 additions & 15 deletions iodata/test/test_wfn.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,31 +300,29 @@ def test_load_one_cah110_hf_sto3g_g09():
check_orthonormal(mol.mo.coeffsb, olp, 1e-5)


def check_load_dump_consistency(fn, tmpdir, fmt_from="wfn", fmt_to="wfn", atol=1.0e-6):
def check_load_dump_consistency(fn: str, tmpdir: str, atol: float = 1.0e-6):
"""Check if data is preserved after dumping and loading a WFN file.
Parameters
----------
fn : str
fn
The filename to load
tmpdir : str
tmpdir
The temporary directory to dump and load the file.
fmt_from : str
Format filename to load.
fmt_to : str
Format of filename to dump and then load again.
atol
The absolute tolerance on the numerical comparisons.
"""
with as_file(files("iodata.test.data").joinpath(fn)) as file_name:
mol1 = load_one(str(file_name), fmt=fmt_from)
fn_tmp = os.path.join(tmpdir, "foo.bar")
dump_one(mol1, fn_tmp, fmt=fmt_to)
mol2 = load_one(fn_tmp, fmt=fmt_to)
mol1 = load_one(str(file_name))
fn_tmp = os.path.join(tmpdir, "foo.wfn")
dump_one(mol1, fn_tmp)
mol2 = load_one(fn_tmp)
# compare Mulliken charges
charges1 = compute_mulliken_charges(mol1)
charges2 = compute_mulliken_charges(mol2)
assert_allclose(charges1, charges2, atol=atol)
if fmt_from == fmt_to:
if fn.endswith(".wfn"):
compare_mols(mol1, mol2, atol=atol)


Expand Down Expand Up @@ -359,15 +357,20 @@ def test_load_dump_consistency(path, tmpdir):


def test_load_dump_consistency_from_fchk_h2o(tmpdir):
check_load_dump_consistency("h2o_sto3g.fchk", tmpdir, fmt_from="fchk", fmt_to="wfn")
check_load_dump_consistency("h2o_sto3g.fchk", tmpdir)


def test_load_dump_consistency_from_molden_nh3(tmpdir):
check_load_dump_consistency("nh3_molden_cart.molden", tmpdir, fmt_from="molden", fmt_to="wfn")
check_load_dump_consistency("nh3_molden_cart.molden", tmpdir)


def test_dump_one_pure_functions(tmpdir):
with pytest.raises(PrepareDumpError):
check_load_dump_consistency("water_ccpvdz_pure_hf_g03.fchk", tmpdir)


def test_generalized():
# The Molden format does not support generalized MOs
# The WFN format does not support generalized MOs
data = create_generalized()
with pytest.raises(PrepareDumpError):
dump_one(data, "generlized.wfn")
21 changes: 11 additions & 10 deletions iodata/test/test_wfx.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,21 +46,21 @@ def helper_load_data_wfx(fn_wfx):
return load_data_wfx(lit)


def check_load_dump_consistency(fn, tmpdir):
def check_load_dump_consistency(fn: str, tmpdir: str):
"""Check if data is preserved after dumping and loading a Wfx file.
Parameters
----------
fn : str
fn
The Molekel filename to load
tmpdir : str
tmpdir
The temporary directory to dump and load the file.
"""
with as_file(files("iodata.test.data").joinpath(fn)) as file_name:
mol1 = load_one(str(file_name), fmt="wfx")
fn_tmp = os.path.join(tmpdir, "foo.bar")
dump_one(mol1, fn_tmp, fmt="wfx")
mol2 = load_one(fn_tmp, fmt="wfx")
mol1 = load_one(str(file_name))
fn_tmp = os.path.join(tmpdir, "foo.wfx")
dump_one(mol1, fn_tmp)
mol2 = load_one(fn_tmp)
compare_mols(mol1, mol2)
# compare Mulliken charges
charges1 = compute_mulliken_charges(mol1)
Expand Down Expand Up @@ -179,9 +179,10 @@ def test_dump_one_from_molden_neon(tmpdir):
)


# add this test when pure to Cartesian basis set conversion is supported
# def test_dump_one_from_mkl_li2(tmpdir):
# compare_mulliken_charges('li2.mkl', tmpdir)
def test_dump_one_pure_functions(tmpdir):
# li2.mkl contains pure functions
with pytest.raises(PrepareDumpError):
check_load_dump_consistency("water_ccpvdz_pure_hf_g03.fchk", tmpdir)


def test_load_data_wfx_h2():
Expand Down

0 comments on commit e17b6d8

Please sign in to comment.