From 780b0276ee315fecdc251b0316b989c764ea9ab2 Mon Sep 17 00:00:00 2001 From: Thomas Applencourt Date: Wed, 1 Apr 2015 14:26:42 +0200 Subject: [PATCH] Amelioration of unit test --- src/Hartree_Fock/EZFIO.cfg | 2 +- tests/unit_test/unit_test.py | 144 +++++++++++++++++++++++++++++++---- 2 files changed, 131 insertions(+), 15 deletions(-) diff --git a/src/Hartree_Fock/EZFIO.cfg b/src/Hartree_Fock/EZFIO.cfg index 87f1a878..e2b0ea5a 100644 --- a/src/Hartree_Fock/EZFIO.cfg +++ b/src/Hartree_Fock/EZFIO.cfg @@ -19,4 +19,4 @@ default: Huckel [energy] type: double precision doc: Calculated HF energy -interface: output \ No newline at end of file +interface: output diff --git a/tests/unit_test/unit_test.py b/tests/unit_test/unit_test.py index 5a1ed2dd..eb9b1e79 100755 --- a/tests/unit_test/unit_test.py +++ b/tests/unit_test/unit_test.py @@ -31,8 +31,10 @@ precision = 5.e-8 global has_hf_alredy has_hf_alredy = False +global filename_check -def init_folder(geo, basis, mult=1): + +def init_folder(geo, basis, mult=1, 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 @@ -42,10 +44,12 @@ def init_folder(geo, basis, mult=1): cmd = "cp {0}/tests/{1}.xyz .".format(qpackage_root, geo) subprocess.check_call([cmd], shell=True) - cmd = "qp_create_ezfio_from_xyz -b {0} -m {1} {2}.xyz".format(basis, - mult, - geo) - subprocess.check_call([cmd], shell=True) + if not ezfio_name: + ezfio_name = geo + + 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) def get_error_message(l_exepected, l_cur): @@ -54,11 +58,98 @@ def get_error_message(l_exepected, l_cur): return "\n".join(l_msg) -def check_hf(geo, basis): - ezfio.bielec_integrals_disk_access_ao_integrals = "None" +# _ +# / |_ _ _ | o ._ ._ _|_ +# \_ | | (/_ (_ |< | | | |_) |_| |_ +# | + +def check_disk_acess(geo, basis, mult=1): + + import uuid + filename = str(uuid.uuid4()) + + # ~#~#~#~ # + # I n i t # + # ~#~#~#~ # + + init_folder(geo, basis, mult, ezfio_name=filename) + ezfio.set_file("{0}.ezfio".format(filename)) + + # ~#~#~#~#~#~#~#~#~#~#~#~#~ # + # S e t _ p a r a m e t e r # + # ~#~#~#~#~#~#~#~#~#~#~#~#~ # + + # Test 1 + ezfio.bielec_integrals_disk_access_ao_integrals = "Write" + cmd = "qp_edit -c {0}.ezfio".format(filename) + subprocess.check_call([cmd], shell=True) + + # Test 2 + ezfio.bielec_integrals_disk_access_ao_integrals = "IculeAcess" + cmd = "qp_edit -c {0}.ezfio".format(filename) + + try: + subprocess.check_call([cmd], shell=True) + return_code = False + except subprocess.CalledProcessError: + return_code = True + + # ~#~#~#~#~#~#~#~ # + # F i n a l i z e # + # ~#~#~#~#~#~#~#~ # + + if return_code: + subprocess.call(["rm -R {0}.ezfio".format(filename)], shell=True) + return return_code -def run_hf(geo, basis): +def check_mo_guess(geo, basis, mult=1): + + import uuid + filename = str(uuid.uuid4()) + + # ~#~#~#~ # + # I n i t # + # ~#~#~#~ # + + init_folder(geo, basis, mult, ezfio_name=filename) + ezfio.set_file("{0}.ezfio".format(filename)) + + # ~#~#~#~#~#~#~#~#~#~#~#~#~ # + # S e t _ p a r a m e t e r # + # ~#~#~#~#~#~#~#~#~#~#~#~#~ # + + # Test 1 + ezfio.hartree_fock_mo_guess_type = "Huckel" + cmd = "qp_edit -c {0}.ezfio".format(filename) + subprocess.check_call([cmd], shell=True) + + # Test 2 + ezfio.hartree_fock_mo_guess_type = "IculeGuess" + cmd = "qp_edit -c {0}.ezfio".format(filename) + + try: + subprocess.check_call([cmd], shell=True) + return_code = False + except subprocess.CalledProcessError: + return_code = True + + # ~#~#~#~#~#~#~#~ # + # F i n a l i z e # + # ~#~#~#~#~#~#~#~ # + + if return_code: + subprocess.call(["rm -R {0}.ezfio".format(filename)], shell=True) + return return_code + + +# _ +# / |_ _ _ | _. | _ _ +# \_ | | (/_ (_ |< \/ (_| | |_| (/_ _> +# + + +def run_hf(geo, basis, mult=1): """ Run a simle by default hf EZFIO path = geo.ezfio @@ -82,7 +173,7 @@ def run_hf(geo, basis): # I n i t # # ~#~#~#~ # - init_folder(geo, basis) + init_folder(geo, basis, mult) ezfio.set_file("{0}.ezfio".format(geo)) # ~#~#~#~#~#~#~#~#~#~#~#~#~ # @@ -176,18 +267,43 @@ def run_full_ci_10k_pt2_end(geo, basis): [cur_var, cur_pt2])) -def run_big_test(geo, basis): +def hf_then_10k_test(geo, basis): if not has_hf_alredy: run_hf(geo, basis) - run_full_ci_10k_pt2_end(geo, basis) - return True + try: + run_full_ci_10k_pt2_end(geo, basis) + return_code = True + except: + return_code = False + + # ~#~#~#~#~#~#~#~ # + # F i n a l i z e # + # ~#~#~#~#~#~#~#~ # + + if return_code: + subprocess.call(["rm -R {0}.ezfio".format(geo)], shell=True) + return return_code -class SimplisticTest(unittest.TestCase): +# ___ +# | _ _ _|_ +# | (/_ _> |_ +# +class ValueTest(unittest.TestCase): def test_full_ci_10k_pt2_end(self): - self.assertTrue(run_big_test("methane", "sto-3g")) + self.assertTrue(hf_then_10k_test("methane", "sto-3g")) + + +class InputTest(unittest.TestCase): + + def test_check_disk_acess(self): + self.assertTrue(check_disk_acess("methane", "un-ccemd-ref")) + + def test_check_mo_guess(self): + self.assertTrue(check_mo_guess("methane", "maug-cc-pVDZ")) + if __name__ == '__main__': unittest.main()