mirror of
https://github.com/LCPQ/quantum_package
synced 2024-12-23 04:43:50 +01:00
Add Pseudo Unit Test for SO2
This commit is contained in:
parent
763e77444d
commit
ad3d6317b2
@ -10,6 +10,9 @@ Documentation
|
||||
.. Do not edit this section. It was auto-generated from the
|
||||
.. NEEDED_MODULES file.
|
||||
|
||||
`fcidump <http://github.com/LCPQ/quantum_package/tree/master/src/FCIdump/fcidump.irp.f#L1>`_
|
||||
Undocumented
|
||||
|
||||
|
||||
|
||||
Needed Modules
|
||||
|
5
tests/SO2.xyz
Normal file
5
tests/SO2.xyz
Normal file
@ -0,0 +1,5 @@
|
||||
3
|
||||
SO2 Geo: Experiment Mult: 1 symmetry: 32
|
||||
O 0.0 1.2371 0.7215
|
||||
O 0.0 -1.2371 0.7215
|
||||
S 0.0 0.0 0.0
|
@ -12,6 +12,9 @@ sys.path = [EZFIO + "/Python"] + sys.path
|
||||
|
||||
from ezfio import ezfio
|
||||
from collections import defaultdict
|
||||
from collections import namedtuple
|
||||
|
||||
Energy = namedtuple('Energy', ['without_pseudo', 'with_pseudo'])
|
||||
|
||||
# ~#~#~ #
|
||||
# O p t #
|
||||
@ -34,7 +37,7 @@ has_hf_alredy = False
|
||||
global filename_check
|
||||
|
||||
|
||||
def init_folder(geo, basis, mult=1, ezfio_name=None):
|
||||
def init_folder(geo, basis, mult=1, pseudo=False, ezfio_name=None):
|
||||
'''
|
||||
Take a geo in arg (aka a existing geo.xyz in test/)
|
||||
And create the geo.ezfio with the adeguate basis and multipliciti
|
||||
@ -47,15 +50,21 @@ def init_folder(geo, basis, mult=1, ezfio_name=None):
|
||||
if not ezfio_name:
|
||||
ezfio_name = geo
|
||||
|
||||
cmd = "qp_create_ezfio_from_xyz -b {0} -m {1} {2}.xyz -o {3}.ezfio"
|
||||
if pseudo:
|
||||
cmd = "qp_create_ezfio_from_xyz -b {0} -m {1} {2}.xyz -p -o {3}.ezfio"
|
||||
else:
|
||||
cmd = "qp_create_ezfio_from_xyz -b {0} -m {1} {2}.xyz -o {3}.ezfio"
|
||||
|
||||
subprocess.check_call([cmd.format(basis, mult, geo, ezfio_name)],
|
||||
shell=True)
|
||||
|
||||
subprocess.call(["rm {0}.xyz".format(geo)], shell=True)
|
||||
|
||||
|
||||
def get_error_message(l_exepected, l_cur):
|
||||
l_msg = ["Need {0} get {1} error is {2}".format(i, j, abs(i - j))
|
||||
for i, j in zip(l_exepected, l_cur)]
|
||||
return "\n".join(l_msg)
|
||||
return "\n" + "\n".join(l_msg)
|
||||
|
||||
|
||||
# _
|
||||
@ -146,18 +155,20 @@ def check_mo_guess(geo, basis, mult=1):
|
||||
# / |_ _ _ | _. | _ _
|
||||
# \_ | | (/_ (_ |< \/ (_| | |_| (/_ _>
|
||||
#
|
||||
def run_hf(geo, basis, mult=1):
|
||||
def run_hf(geo, basis, mult=1, pseudo=False, remove_after_sucess=True):
|
||||
"""
|
||||
Run a simle by default hf
|
||||
EZFIO path = geo.ezfio
|
||||
"""
|
||||
|
||||
# ~#~#~#~#~#~#~#~#~#~ #
|
||||
# R e f _ e n e r g y #
|
||||
# ~#~#~#~#~#~#~#~#~#~ #
|
||||
|
||||
ref_energy = defaultdict(dict)
|
||||
ref_energy = defaultdict(defaultdict)
|
||||
|
||||
ref_energy["sto-3g"]["methane"] = -39.7267433402
|
||||
ref_energy["sto-3g"]["methane"] = Energy(-39.7267433402, None)
|
||||
ref_energy["vdz"]["SO2"] = Energy(None, -41.48912297776174)
|
||||
|
||||
# ~#~#~#~#~#~#~#~#~#~#~#~#~#~#~ #
|
||||
# G l o b a l _ v a r i a b l e #
|
||||
@ -170,7 +181,7 @@ def run_hf(geo, basis, mult=1):
|
||||
# I n i t #
|
||||
# ~#~#~#~ #
|
||||
|
||||
init_folder(geo, basis, mult)
|
||||
init_folder(geo, basis, mult, pseudo)
|
||||
ezfio.set_file("{0}.ezfio".format(geo))
|
||||
|
||||
# ~#~#~#~#~#~#~#~#~#~#~#~#~ #
|
||||
@ -187,7 +198,7 @@ def run_hf(geo, basis, mult=1):
|
||||
ezfio.hartree_fock_thresh_scf = 1.e-10
|
||||
ezfio.hartree_fock_n_it_scf_max = 100
|
||||
|
||||
ezfio.pseudo_integrals_do_pseudo = False
|
||||
ezfio.pseudo_integrals_do_pseudo = pseudo
|
||||
|
||||
# ~#~#~ #
|
||||
# R u n #
|
||||
@ -201,15 +212,25 @@ def run_hf(geo, basis, mult=1):
|
||||
# ~#~#~#~#~ #
|
||||
|
||||
cur_e = ezfio.get_hartree_fock_energy()
|
||||
|
||||
ref_e = ref_energy[basis][geo]
|
||||
if pseudo:
|
||||
ref_e = ref_e.with_pseudo
|
||||
else:
|
||||
ref_e = ref_e.without_pseudo
|
||||
|
||||
if abs(cur_e - ref_e) <= precision:
|
||||
|
||||
if remove_after_sucess:
|
||||
subprocess.call(["rm -R {0}.ezfio".format(geo)], shell=True)
|
||||
|
||||
return True
|
||||
|
||||
else:
|
||||
raise ValueError(get_error_message([ref_e], [cur_e]))
|
||||
|
||||
|
||||
def run_full_ci_10k_pt2_end(geo, basis):
|
||||
def run_full_ci_10k_pt2_end(geo, basis, pseudo):
|
||||
"""
|
||||
Run a Full_ci with 10k with the TruePT2
|
||||
EZFIO path = geo.ezfio
|
||||
@ -222,8 +243,8 @@ def run_full_ci_10k_pt2_end(geo, basis):
|
||||
ref_energy_var = defaultdict(dict)
|
||||
ref_energy_pt2 = defaultdict(dict)
|
||||
|
||||
ref_energy_var["sto-3g"]["methane"] = -0.398058753535695E+02
|
||||
ref_energy_pt2["sto-3g"]["methane"] = -0.398059182483741E+02
|
||||
ref_energy_var["sto-3g"]["methane"] = Energy(-0.398058753535695E+02, None)
|
||||
ref_energy_pt2["sto-3g"]["methane"] = Energy(-0.398059182483741E+02, None)
|
||||
|
||||
# ~#~#~#~ #
|
||||
# I n i t #
|
||||
@ -256,6 +277,13 @@ def run_full_ci_10k_pt2_end(geo, basis):
|
||||
ref_var = ref_energy_var[basis][geo]
|
||||
ref_pt2 = ref_energy_pt2[basis][geo]
|
||||
|
||||
if pseudo:
|
||||
ref_var = ref_var.with_pseudo
|
||||
ref_pt2 = ref_pt2.with_pseudo
|
||||
else:
|
||||
ref_var = ref_var.without_pseudo
|
||||
ref_pt2 = ref_pt2.without_pseudo
|
||||
|
||||
t = [abs(cur_var - ref_var) <= precision,
|
||||
abs(cur_pt2 - ref_pt2) <= precision]
|
||||
|
||||
@ -266,15 +294,16 @@ def run_full_ci_10k_pt2_end(geo, basis):
|
||||
[cur_var, cur_pt2]))
|
||||
|
||||
|
||||
def hf_then_10k_test(geo, basis):
|
||||
if not has_hf_alredy:
|
||||
run_hf(geo, basis)
|
||||
def hf_then_10k_test(geo, basis, mult=1, pseudo=False):
|
||||
|
||||
run_hf(geo, basis, mult, pseudo, remove_after_sucess=False)
|
||||
|
||||
try:
|
||||
run_full_ci_10k_pt2_end(geo, basis)
|
||||
return_code = True
|
||||
run_full_ci_10k_pt2_end(geo, basis, pseudo)
|
||||
except:
|
||||
return_code = False
|
||||
raise
|
||||
else:
|
||||
return_code = True
|
||||
|
||||
# ~#~#~#~#~#~#~#~ #
|
||||
# F i n a l i z e #
|
||||
@ -335,15 +364,27 @@ def check_convert(path_out):
|
||||
else:
|
||||
raise ValueError(get_error_message([ref_e], [cur_e]))
|
||||
|
||||
|
||||
# ___
|
||||
# | _ _ _|_
|
||||
# | (/_ _> |_
|
||||
#
|
||||
class ValueTest(unittest.TestCase):
|
||||
|
||||
def test_full_ci_10k_pt2_end(self):
|
||||
self.assertTrue(hf_then_10k_test("methane", "sto-3g"))
|
||||
def test_hf_then_full_ci_10k_pt2_end(self):
|
||||
self.assertTrue(hf_then_10k_test(geo="methane",
|
||||
basis="sto-3g",
|
||||
mult=1,
|
||||
pseudo=False))
|
||||
|
||||
def test_hf(self):
|
||||
self.assertTrue(run_hf(geo="SO2",
|
||||
basis="vdz",
|
||||
mult=1,
|
||||
pseudo=True))
|
||||
|
||||
|
||||
class ConvertTest(unittest.TestCase):
|
||||
def test_check_convert_hf_energy(self):
|
||||
self.assertTrue(check_convert("HBO.out"))
|
||||
|
||||
@ -351,11 +392,12 @@ class ValueTest(unittest.TestCase):
|
||||
class InputTest(unittest.TestCase):
|
||||
|
||||
def test_check_disk_acess(self):
|
||||
self.assertTrue(check_disk_acess("methane", "un-ccemd-ref"))
|
||||
self.assertTrue(check_disk_acess(geo="methane",
|
||||
basis="un-ccemd-ref"))
|
||||
|
||||
def test_check_mo_guess(self):
|
||||
self.assertTrue(check_mo_guess("methane", "maug-cc-pVDZ"))
|
||||
|
||||
self.assertTrue(check_mo_guess(geo="methane",
|
||||
basis="maug-cc-pVDZ"))
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
Loading…
Reference in New Issue
Block a user