diff --git a/ocaml/.gitignore b/ocaml/.gitignore index dff732e4..40acbec5 100644 --- a/ocaml/.gitignore +++ b/ocaml/.gitignore @@ -5,37 +5,39 @@ qptypes_generator.byte _build qp_create_ezfio_from_xyz.native qp_set_ddci.native -qp_run.native qp_print.native +qp_edit.native qp_set_mo_class.native qp_basis_clean.native +qp_run.native qp_edit.native test_mo_label.byte -test_bitlist.byte +test_determinants.byte test_point3d.byte test_elements.byte test_basis.byte -test_gto.byte -test_determinants.byte -test_excitation.byte -test_atom.byte test_molecule.byte +test_gto.byte +test_excitation.byte +test_bitlist.byte +test_atom.byte test_mo_label -test_bitlist +test_determinants test_point3d test_elements test_basis -test_gto -test_determinants -test_excitation -test_atom test_molecule +test_gto +test_excitation +test_bitlist +test_atom qp_create_ezfio_from_xyz qp_set_ddci -qp_run qp_print +qp_edit qp_set_mo_class qp_basis_clean +qp_run Input_determinants.ml Input_perturbation.ml Input_pseudo.ml diff --git a/test/bats/qp.bats b/test/bats/qp.bats new file mode 100644 index 00000000..82194bf7 --- /dev/null +++ b/test/bats/qp.bats @@ -0,0 +1,79 @@ +#!/usr/bin/env bats + +# float number comparison +# Compare two number ($1, $2) with a given precision ($3) +# If the number are not equal, the exit is 1 else is 0 + +# So we strip the "-", is the abs value of the poor +function eq() { + awk -v n1=${1#-} -v n2=${2#-} -v p=$3 'BEGIN{ if ((n1-n2)^2 < p^2) exit 0; exit 1}' +} + +source ${QP_ROOT}/install/EZFIO/Bash/ezfio.sh + +TEST_DIR=${QP_ROOT}/test/work/ +cd ${TEST_DIR} + +@test "init HBO STO-3G" { + cp ${QP_ROOT}/test/input/HBO.xyz . + qp_create_ezfio_from_xyz -b "STO-3G" HBO.xyz + qp_edit -c HBO.ezfio +} + + +@test "hartree fock HBO STO-3G" { + run init HBO STO-3G + qp_run SCF HBO.ezfio + # Check energy + ezfio set_file HBO.ezfio + energy="$(ezfio get hartree_fock energy)" + eq $energy -98.82519856228865 1E-6 +} + +@test "full ci HBO STO-3G" { + run init HBO STO-3G + + ezfio set_file HBO.ezfio + ezfio set perturbation do_pt2_end 1 + ezfio set determinants n_det_max 10000 + + qp_run full_ci HBO.ezfio + energy="$(ezfio get full_ci energy)" + eq $energy -98.9661013229156 1E-6 + energy_pt2="$(ezfio get full_ci energy_pt2)" + eq $energy_pt2 -98.966293393389 1E-6 +} + + +@test "cas_sd_selected HBO STO-3G" { + run hartree fock HBO STO-3G + ezfio set_file HBO.ezfio + ezfio set perturbation do_pt2_end 0 + ezfio set determinants n_det_max 1000 + qp_set_mo_class HBO.ezfio -core "[1-2]" -inact "[3-5]" -act "[6-9]" -virt "[10-11]" + qp_run cas_sd_selected HBO.ezfio + # Check energy + energy="$(ezfio get cas_sd energy)" + eq $energy -98.9640982255169 1E-6 +} + +@test "mrcc_cassd HBO STO-3G" { + run cas_sd_selected fock HBO STO-3G + ezfio set_file HBO.ezfio + ezfio set determinants threshold_generators 1 + ezfio set determinants read_wf 1 + qp_run mrcc_cassd HBO.ezfio + # Check energy + energy="$(ezfio get mrcc_cassd energy)" + eq $energy -98.9647967033634 1E-6 +} + +@test "script conversion HBO.out" { + cp ${QP_ROOT}/test/input/HBO.out . + qp_convert_output_to_ezfio.py HBO.out + qp_edit -c HBO.out.ezfio + qp_run SCF HBO.out.ezfio + ezfio set_file HBO.out.ezfio + energy="$(ezfio get hartree_fock energy)" + eq $energy -100.0185822553404 1E-6 +} diff --git a/testing_no_regression/HBO.out b/test/input/HBO.out similarity index 100% rename from testing_no_regression/HBO.out rename to test/input/HBO.out diff --git a/testing_no_regression/HBO.xyz b/test/input/HBO.xyz similarity index 100% rename from testing_no_regression/HBO.xyz rename to test/input/HBO.xyz diff --git a/testing_no_regression/SO2.xyz b/testing_no_regression/SO2.xyz deleted file mode 100644 index 5b6fca03..00000000 --- a/testing_no_regression/SO2.xyz +++ /dev/null @@ -1,5 +0,0 @@ -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 diff --git a/testing_no_regression/methane.xyz b/testing_no_regression/methane.xyz deleted file mode 100644 index ce509a90..00000000 --- a/testing_no_regression/methane.xyz +++ /dev/null @@ -1,7 +0,0 @@ -5 -methane molecule (in ångströms) -C 0.000000 0.000000 0.000000 -H 0.000000 0.000000 1.089000 -H 1.026719 0.000000 -0.363000 -H -0.513360 -0.889165 -0.363000 -H -0.513360 0.889165 -0.363000 diff --git a/testing_no_regression/unit_test.py b/testing_no_regression/unit_test.py deleted file mode 100755 index 6c4ae6b9..00000000 --- a/testing_no_regression/unit_test.py +++ /dev/null @@ -1,399 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- -import unittest -import subprocess -import os -import sys - -from ezfio import ezfio -from collections import defaultdict -from collections import namedtuple - -Energy = namedtuple('Energy', ['without_pseudo', 'with_pseudo']) - -# ~#~#~ # -# O p t # -# ~#~#~ # - -precision = 5.e-7 - -# A test get a geo file and a basis file. -# A global dict containt the result for this test -# A test return True or Raise a error ! -# More ezfio condition you set, beter it is - - -# You cannot order the test flow. -# So if you dont whant to remarque on test (for example the HF), set -# a global variable and check for it -global has_hf_alredy -has_hf_alredy = False - -global filename_check - - -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 - DO NOT CHECK IS THE EZFIO FOLDER ALREADY EXIST - ''' - - if not ezfio_name: - ezfio_name = geo - - 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) - -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" + "\n".join(l_msg) - - -# _ -# / |_ _ _ | 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.integrals_bielec_disk_access_ao_integrals = "Write" - cmd = "qp_edit -c {0}.ezfio".format(filename) - subprocess.check_call([cmd], shell=True) - - # Test 2 - ezfio.integrals_bielec_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 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, 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(defaultdict) - - ref_energy["sto-3g"]["methane"] = Energy(-39.7267433402, None) - ref_energy["vdz"]["SO2"] = Energy(None, -41.48912297776174) -# ref_energy["vdz"]["HBO"] = Energy(None, -19.1198231418) - ref_energy["vdz"]["HBO"] = Energy(None, -19.1198254041) - - # ~#~#~#~#~#~#~#~#~#~#~#~#~#~#~ # - # G l o b a l _ v a r i a b l e # - # ~#~#~#~#~#~#~#~#~#~#~#~#~#~#~ # - - global has_hf_alredy - has_hf_alredy = True - - # ~#~#~#~ # - # I n i t # - # ~#~#~#~ # - - init_folder(geo, basis, mult, pseudo) - ezfio.set_file("{0}.ezfio".format(geo)) - - # ~#~#~#~#~#~#~#~#~#~#~#~#~ # - # S e t _ p a r a m e t e r # - # ~#~#~#~#~#~#~#~#~#~#~#~#~ # - ezfio.integrals_bielec_direct = False - ezfio.integrals_bielec_threshold_ao = 1.e-15 - ezfio.integrals_bielec_disk_access_ao_integrals = "None" - - ezfio.integrals_bielec_threshold_mo = 1.e-15 - ezfio.integrals_bielec_disk_access_mo_integrals = "None" - - ezfio.hartree_fock_mo_guess_type = "Huckel" - ezfio.hartree_fock_thresh_scf = 1.e-10 - ezfio.hartree_fock_n_it_scf_max = 100 - - ezfio.pseudo_do_pseudo = pseudo - - # ~#~#~ # - # R u n # - # ~#~#~ # - -# cmd = "{0}/Hartree_Fock/SCF {1}.ezfio/".format(QP_src,geo) - cmd = "qp_run SCF {0}.ezfio/".format(geo) - subprocess.check_call([cmd], shell=True) - - # ~#~#~#~#~ # - # C h e c k # - # ~#~#~#~#~ # - - 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, pseudo): - """ - Run a Full_ci with 10k with the TruePT2 - EZFIO path = geo.ezfio - """ - - # ~#~#~#~#~#~#~#~#~#~ # - # R e f _ e n e r g y # - # ~#~#~#~#~#~#~#~#~#~ # - - ref_energy_var = defaultdict(dict) - ref_energy_pt2 = defaultdict(dict) - - ref_energy_var["sto-3g"]["methane"] = Energy(-39.8058687211, None) - ref_energy_pt2["sto-3g"]["methane"] = Energy(-39.8059180427, None) - - # ~#~#~#~ # - # I n i t # - # ~#~#~#~ # - - ezfio.set_file("{0}.ezfio".format(geo)) - - # ~#~#~#~#~#~#~#~#~#~#~#~#~ # - # S e t _ p a r a m e t e r # - # ~#~#~#~#~#~#~#~#~#~#~#~#~ # - - ezfio.determinants_n_det_max = 10000 - ezfio.determinants_n_det_max_jacobi = 10000 - ezfio.determinants_n_states = 1 - ezfio.determinants_read_wf = 1 - ezfio.determinants_s2_eig = False - - ezfio.determinants_threshold_generators = 0.99 - ezfio.determinants_threshold_selectors = 0.999 - - ezfio.perturbation_do_pt2_end = True - ezfio.perturbation_pt2_max = 1.e-4 - - # ~#~#~ # - # R u n # - # ~#~#~ # - -# cmd = "{0}/Full_CI/full_ci {1}.ezfio/".format(QP_src,geo) - cmd = "qp_run full_ci {0}.ezfio/".format(geo) - subprocess.check_call([cmd], shell=True) - - # ~#~#~#~#~ # - # C h e c k # - # ~#~#~#~#~ # - - cur_var = ezfio.get_full_ci_energy() - cur_pt2 = ezfio.get_full_ci_energy_pt2() - - 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] - - if all(t): - return True - else: - raise ValueError(get_error_message([ref_var, ref_pt2], - [cur_var, cur_pt2])) - - -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, pseudo) - except: - raise - else: - return_code = True - - # ~#~#~#~#~#~#~#~ # - # F i n a l i z e # - # ~#~#~#~#~#~#~#~ # - - if return_code: - subprocess.call(["rm -R {0}.ezfio".format(geo)], shell=True) - return return_code - - -# _ -# / |_ _ _ | _. ._ _ _ ._ _ ._ _|_ -# \_ | | (/_ (_ |< (_| |_) (_ (_) | | \/ (/_ | |_ -# | | __ -def check_convert(path_out): - ''' - Path_out is the out_file - ''' - - # ~#~#~#~#~#~#~#~#~#~ # - # R e f _ e n e r g y # - # ~#~#~#~#~#~#~#~#~#~ # - - ref_energy = defaultdict(dict) - - ref_energy["HBO.out"] = -100.0185822589 - - # ~#~#~#~#~#~#~#~#~#~#~#~#~ # - # S e t _ p a r a m e t e r # - # ~#~#~#~#~#~#~#~#~#~#~#~#~ # - cmd = "qp_convert_output_to_ezfio.py {0}".format(path_out) - subprocess.check_call([cmd], shell=True) - - # Test 2 - cmd = "qp_edit -c {0}.ezfio".format(path_out) - subprocess.check_call([cmd], shell=True) - - cmd = "qp_run SCF {0}.ezfio".format(path_out) - subprocess.check_call([cmd], shell=True) - - # ~#~#~#~#~ # - # C h e c k # - # ~#~#~#~#~ # - - ezfio.set_file("{0}.ezfio".format(path_out)) - - cur_e = ezfio.get_hartree_fock_energy() - ref_e = ref_energy[path_out] - - if abs(cur_e - ref_e) <= precision: - subprocess.call(["rm -R {0}.ezfio".format(path_out)], shell=True) - return True - else: - raise ValueError(get_error_message([ref_e], [cur_e])) - - -# ___ -# | _ _ _|_ -# | (/_ _> |_ -# -class ValueTest(unittest.TestCase): - - 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="HBO", - basis="vdz", - mult=1, - pseudo=True)) - - -class ConvertTest(unittest.TestCase): - def test_check_convert_hf_energy(self): - self.assertTrue(check_convert("HBO.out")) - - -class InputTest(unittest.TestCase): - - def test_check_disk_acess(self): - self.assertTrue(check_disk_acess(geo="methane", - basis="un-ccemd-ref")) - - def test_check_mo_guess(self): - self.assertTrue(check_mo_guess(geo="methane", - basis="maug-cc-pVDZ")) - -if __name__ == '__main__': - unittest.main()