diff --git a/tests/data/cp.in b/tests/data/cp.in new file mode 100644 index 0000000..d321d1c --- /dev/null +++ b/tests/data/cp.in @@ -0,0 +1,49 @@ + &control + title = ' Water Molecule ', + calculation = 'cp', + restart_mode = 'from_scratch', + ndr = 51, + ndw = 51, + nstep = 100, + iprint = 100, + isave = 100, + tstress = .TRUE., + tprnfor = .TRUE., + dt = 5.0d0, + etot_conv_thr = 1.d-9, + ekin_conv_thr = 1.d-4, + prefix = 'h2o' + verbosity = 'medium' + / + &system + ibrav = 14, + celldm(1) = 12.0, + celldm(2) = 1.0, + celldm(3) = 1.0, + celldm(4) = 0.0, + celldm(5) = 0.0, + celldm(6) = 0.0, + nat = 3, + ntyp = 2, + nbnd = 4, + ecutwfc = 80.0, + / + &electrons + emass = 400.d0, + emass_cutoff = 2.5d0, + orthogonalization = 'ortho', + electron_dynamics = 'damp', + electron_damping = 0.2 + / + &ions + ion_dynamics = 'none', + ion_radius(1) = 0.8d0, + ion_radius(2) = 0.8d0, + / +ATOMIC_SPECIES + O 16.0d0 O.blyp-mt.UPF + H 1.00d0 H.blyp-vbc.UPF +ATOMIC_POSITIONS (bohr) + O 0.0099 0.0099 0.0000 0 0 0 + H 1.8325 -0.2243 -0.0001 1 1 1 + H -0.2243 1.8325 0.0002 1 1 1 diff --git a/tests/data/extractor_ref/cp.json b/tests/data/extractor_ref/cp.json new file mode 100644 index 0000000..592c168 --- /dev/null +++ b/tests/data/extractor_ref/cp.json @@ -0,0 +1,20 @@ +{ + "structure": { + "positions": [ + [0.005238854365041, 0.005238854365041, 0.0], + [0.9697172347411749, -0.11869444788673698, -5.2917720858999996e-5], + [-0.11869444788673698, 0.9697172347411749, 0.00010583544171799999] + ], + "species": { + "names": ["O", "H"], + "masses": [16.0, 1.0], + "pseudo_file_names": ["O.blyp-mt.UPF", "H.blyp-vbc.UPF"] + }, + "cell": [ + [6.350126503079999, 0.0, 0.0], + [0.0, 6.350126503079999, 0.0], + [0.0, 0.0, 6.350126503079999] + ], + "atom_names": ["O", "H", "H"] + } +} diff --git a/tests/data/extractor_ref/pw.json b/tests/data/extractor_ref/pw.json new file mode 100644 index 0000000..18db192 --- /dev/null +++ b/tests/data/extractor_ref/pw.json @@ -0,0 +1,21 @@ +{ + "structure": { + "positions": [ + [0.005238854365041, 0.005238854365041, 0.0], + [0.9697172347411749, -0.11869444788673698, -5.2917720858999996e-5], + [-0.11869444788673698, 0.9697172347411749, 0.00010583544171799999] + ], + "species": { + "names": ["O", "H"], + "masses": [16.0, 1.0], + "pseudo_file_names": ["O.blyp-mt.UPF", "H.blyp-vbc.UPF"] + }, + "cell": [ + [6.350126503079999, 0.0, 0.0], + [0.0, 6.350126503079999, 0.0], + [0.0, 0.0, 6.350126503079999] + ], + "atom_names": ["O", "H", "H"] + }, + "k-points": { "type": "gamma" } +} diff --git a/tests/data/pw.in b/tests/data/pw.in new file mode 100644 index 0000000..4464849 --- /dev/null +++ b/tests/data/pw.in @@ -0,0 +1,27 @@ + &control + calculation = 'relax', + / + &system + ibrav = 1, + celldm(1) = 12.0, + nat = 3, + ntyp = 2, + nbnd = 4, + ecutwfc = 80, + ecutfock=160, + input_dft = 'X3LYP' + exxdiv_treatment = 'gygi-baldereschi' + x_gamma_extrapolation = .TRUE. + / + &electrons + / + &ions + / +ATOMIC_SPECIES + O 16.0d0 O.blyp-mt.UPF + H 1.00d0 H.blyp-vbc.UPF +ATOMIC_POSITIONS (bohr) + O 0.0099 0.0099 0.0000 + H 1.8325 -0.2243 -0.0001 + H -0.2243 1.8325 0.0002 +K_POINTS gamma diff --git a/tests/test_extractor.py b/tests/test_extractor.py new file mode 100644 index 0000000..7f8356f --- /dev/null +++ b/tests/test_extractor.py @@ -0,0 +1,14 @@ +import json +from pathlib import Path + +import pytest +from qe_tools.extractors import extract + + +@pytest.mark.parametrize("parser", ["pw", "cp"]) +def test_input_dict_extraction(parser: str): + datadir = Path(__file__).resolve().parent / "data" + filepath = datadir / f"{parser}.in" + refpath = datadir / "extractor_ref" / f"{parser}.json" + with open(refpath) as reference: + assert extract(filepath.as_posix(), parser) == json.load(reference)