From 4dd50301f16c99611b6b53d6cfdba8709355bdbd Mon Sep 17 00:00:00 2001 From: Anthony Scemama Date: Fri, 21 Apr 2017 22:34:25 +0200 Subject: [PATCH 1/3] Merge Anouar (#53) * Fix THE QMCPACK Determinant print * Add correlation_energy_ratio_max as an exit criterion * Fix Print * Fix ENDIF * Fix comment --- plugins/Full_CI_ZMQ/fci_zmq.irp.f | 37 ++++++++++++++++--- plugins/Perturbation/EZFIO.cfg | 9 ++++- .../qmcpack/qp_convert_qmcpack_to_ezfio.py | 21 +++-------- 3 files changed, 44 insertions(+), 23 deletions(-) diff --git a/plugins/Full_CI_ZMQ/fci_zmq.irp.f b/plugins/Full_CI_ZMQ/fci_zmq.irp.f index fcc38954..585e40e3 100644 --- a/plugins/Full_CI_ZMQ/fci_zmq.irp.f +++ b/plugins/Full_CI_ZMQ/fci_zmq.irp.f @@ -9,7 +9,13 @@ program fci_zmq double precision :: threshold_davidson_in allocate (pt2(N_states)) - + + IF (correlation_energy_ratio_max .NE. 1.d0) THEN + + DOUBLE PRECISION :: hf_energy_ref + CALL ezfio_get_hartree_fock_energy(hf_energy_ref) + END IF + pt2 = 1.d0 threshold_davidson_in = threshold_davidson threshold_davidson = threshold_davidson_in * 100.d0 @@ -41,15 +47,34 @@ program fci_zmq E_CI_before(1:N_states) = CI_energy(1:N_states) n_det_before = 0 + do while ( (N_det < N_det_max) .and. (maxval(abs(pt2(1:N_states))) > pt2_max) ) + + + IF (correlation_energy_ratio_max .NE. 1.d0) THEN + DOUBLE PRECISION :: correlation_energy_var, correlation_energy_var_ratio + + correlation_energy_var = MAXVAL(E_CI_before) - hf_energy_ref + correlation_energy_var_ratio = correlation_energy_var / (correlation_energy_var + MAXVAL(pt2(:))) + + IF (correlation_energy_ratio_max < correlation_energy_var_ratio) THEN + EXIT + ENDIF - print *, 'N_det = ', N_det - print *, 'N_states = ', N_states + ENDIF + + + print *, 'N_det = ', N_det + print *, 'N_states = ', N_states + IF (correlation_energy_ratio_max .NE. 1.d0) THEN + print*, 'correlation_ratio = ', correlation_energy_var + ENDIF + do k=1, N_states print*,'State ',k - print *, 'PT2 = ', pt2(k) - print *, 'E = ', CI_energy(k) - print *, 'E(before)+PT2 = ', E_CI_before(k)+pt2(k) + print *, 'PT2 = ', pt2(k) + print *, 'E = ', CI_energy(k) + print *, 'E(before)+PT2 = ', E_CI_before(k)+pt2(k) enddo print *, '-----' if(N_states.gt.1)then diff --git a/plugins/Perturbation/EZFIO.cfg b/plugins/Perturbation/EZFIO.cfg index 4f0457a2..19c6c52d 100644 --- a/plugins/Perturbation/EZFIO.cfg +++ b/plugins/Perturbation/EZFIO.cfg @@ -14,10 +14,17 @@ default: 0.0001 [var_pt2_ratio] type: Normalized_float doc: The selection process stops when the energy ratio variational/(variational+PT2) - is equal to var_pt2_ratio + is equal to var_pt2_ratio. (Obsolete. Need to be removed) interface: ezfio,provider,ocaml default: 0.75 +[correlation_energy_ratio_max] +type: Normalized_float +doc: The selection process stops at a fixed correlation ratio (usefull for getting same accuracy between molecules) + Defined as (E_CI-E_HF)/ (E_CI+PT2 - E_HF) If Ratio eq 1 it will not be used. (E_HF) is not required. +interface: ezfio,provider,ocaml +default: 1.00 + [threshold_generators_pt2] type: Threshold doc: Thresholds on generators (fraction of the norm) for final PT2 calculation diff --git a/plugins/qmcpack/qp_convert_qmcpack_to_ezfio.py b/plugins/qmcpack/qp_convert_qmcpack_to_ezfio.py index a1f47ccd..3298129d 100755 --- a/plugins/qmcpack/qp_convert_qmcpack_to_ezfio.py +++ b/plugins/qmcpack/qp_convert_qmcpack_to_ezfio.py @@ -183,9 +183,6 @@ def get_nb_permutation(str_): def order_l_l_sym(l_l_sym): - - l_order_mo = [i for i,_ in enumerate(l_l_sym)] - n = 1 for i in range(len(l_l_sym)): if n != 1: @@ -195,11 +192,11 @@ def order_l_l_sym(l_l_sym): l = l_l_sym[i] n = get_nb_permutation(l[2]) - l_l_sym[i:i + n], l_order_mo[i:i+n] = zip(*sorted(zip(l_l_sym[i:i + n],l_order_mo[i:i+n]), - key=lambda x: x[0][2], - cmp=compare_gamess_style)) + l_l_sym[i:i + n] = sorted(l_l_sym[i:i + n], + key=lambda x: x[2], + cmp=compare_gamess_style) - return l_l_sym, l_order_mo + return l_l_sym #========================== @@ -208,13 +205,8 @@ def order_l_l_sym(l_l_sym): l_sym_without_header = sym_raw.split("\n")[3:-2] l_l_sym_raw = [i.split() for i in l_sym_without_header] -print len(l_l_sym_raw) - l_l_sym_expend_sym = expend_sym_l(l_l_sym_raw) -print len(l_l_sym_expend_sym) - -l_l_sym_ordered, l_order_mo = order_l_l_sym(l_l_sym_expend_sym) - +l_l_sym_ordered = order_l_l_sym(l_l_sym_expend_sym) #======== #MO COEF @@ -356,7 +348,6 @@ d_rep={"+":"1","-":"0"} det_without_header = det_raw[pos+2::] - for line_raw in det_without_header.split("\n"): line = line_raw @@ -364,10 +355,8 @@ for line_raw in det_without_header.split("\n"): try: float(line) except ValueError: - line_order = [line_raw[i] for i in l_order_mo] line= "".join([d_rep[x] if x in d_rep else x for x in line_raw]) print line.strip() print "END_DET" - From 23d7794109078cd1fe9104b791cfba354baabc0a Mon Sep 17 00:00:00 2001 From: Anthony Scemama Date: Fri, 21 Apr 2017 22:59:42 +0200 Subject: [PATCH 2/3] Cleaned correlation_energy_ratio_max --- plugins/CAS_SD_ZMQ/cassd_zmq.irp.f | 30 ++++++++++++++++--- plugins/Full_CI_ZMQ/fci_zmq.irp.f | 46 ++++++++++++++---------------- plugins/Perturbation/EZFIO.cfg | 11 ++----- src/Utils/util.irp.f | 30 +++++-------------- 4 files changed, 57 insertions(+), 60 deletions(-) diff --git a/plugins/CAS_SD_ZMQ/cassd_zmq.irp.f b/plugins/CAS_SD_ZMQ/cassd_zmq.irp.f index 5b364400..0d079680 100644 --- a/plugins/CAS_SD_ZMQ/cassd_zmq.irp.f +++ b/plugins/CAS_SD_ZMQ/cassd_zmq.irp.f @@ -9,6 +9,15 @@ program fci_zmq allocate (pt2(N_states)) + double precision :: hf_energy_ref + logical :: has + call ezfio_has_hartree_fock_energy(has) + if (has) then + call ezfio_get_hartree_fock_energy(hf_energy_ref) + else + hf_energy_ref = ref_bitmask_energy + endif + pt2 = 1.d0 threshold_davidson_in = threshold_davidson threshold_davidson = threshold_davidson_in * 100.d0 @@ -41,10 +50,23 @@ program fci_zmq print*,'Beginning the selection ...' E_CI_before(1:N_states) = CI_energy(1:N_states) - do while ( (N_det < N_det_max) .and. (maxval(abs(pt2(1:N_states))) > pt2_max) ) - - print *, 'N_det = ', N_det - print *, 'N_states = ', N_states + double precision :: correlation_energy_ratio + correlation_energy_ratio = E_CI_before(1) - hf_energy_ref + correlation_energy_ratio = correlation_energy_ratio / (correlation_energy_ratio + pt2(1)) + + do while ( & + (N_det < N_det_max) .and. & + (maxval(abs(pt2(1:N_states))) > pt2_max) .and. & + (correlation_energy_ratio < correlation_energy_ratio_max) & + ) + + correlation_energy_ratio = E_CI_before(1) - hf_energy_ref + correlation_energy_ratio = correlation_energy_ratio / (correlation_energy_ratio + pt2(1)) + + print *, 'N_det = ', N_det + print *, 'N_states = ', N_states + print*, 'correlation_ratio = ', correlation_energy_ratio + do k=1, N_states print*,'State ',k print *, 'PT2 = ', pt2(k) diff --git a/plugins/Full_CI_ZMQ/fci_zmq.irp.f b/plugins/Full_CI_ZMQ/fci_zmq.irp.f index 585e40e3..e12033b4 100644 --- a/plugins/Full_CI_ZMQ/fci_zmq.irp.f +++ b/plugins/Full_CI_ZMQ/fci_zmq.irp.f @@ -10,11 +10,14 @@ program fci_zmq allocate (pt2(N_states)) - IF (correlation_energy_ratio_max .NE. 1.d0) THEN - - DOUBLE PRECISION :: hf_energy_ref - CALL ezfio_get_hartree_fock_energy(hf_energy_ref) - END IF + double precision :: hf_energy_ref + logical :: has + call ezfio_has_hartree_fock_energy(has) + if (has) then + call ezfio_get_hartree_fock_energy(hf_energy_ref) + else + hf_energy_ref = ref_bitmask_energy + endif pt2 = 1.d0 threshold_davidson_in = threshold_davidson @@ -47,28 +50,22 @@ program fci_zmq E_CI_before(1:N_states) = CI_energy(1:N_states) n_det_before = 0 + double precision :: correlation_energy_ratio + correlation_energy_ratio = E_CI_before(1) - hf_energy_ref + correlation_energy_ratio = correlation_energy_ratio / (correlation_energy_ratio + pt2(1)) - do while ( (N_det < N_det_max) .and. (maxval(abs(pt2(1:N_states))) > pt2_max) ) + do while ( & + (N_det < N_det_max) .and. & + (maxval(abs(pt2(1:N_states))) > pt2_max) .and. & + (correlation_energy_ratio < correlation_energy_ratio_max) & + ) - - IF (correlation_energy_ratio_max .NE. 1.d0) THEN - DOUBLE PRECISION :: correlation_energy_var, correlation_energy_var_ratio - - correlation_energy_var = MAXVAL(E_CI_before) - hf_energy_ref - correlation_energy_var_ratio = correlation_energy_var / (correlation_energy_var + MAXVAL(pt2(:))) - - IF (correlation_energy_ratio_max < correlation_energy_var_ratio) THEN - EXIT - ENDIF - - ENDIF - + correlation_energy_ratio = E_CI_before(1) - hf_energy_ref + correlation_energy_ratio = correlation_energy_ratio / (correlation_energy_ratio + pt2(1)) print *, 'N_det = ', N_det print *, 'N_states = ', N_states - IF (correlation_energy_ratio_max .NE. 1.d0) THEN - print*, 'correlation_ratio = ', correlation_energy_var - ENDIF + print*, 'correlation_ratio = ', correlation_energy_ratio do k=1, N_states print*,'State ',k @@ -76,6 +73,7 @@ program fci_zmq print *, 'E = ', CI_energy(k) print *, 'E(before)+PT2 = ', E_CI_before(k)+pt2(k) enddo + print *, '-----' if(N_states.gt.1)then print*,'Variational Energy difference' @@ -130,8 +128,8 @@ program fci_zmq double precision :: relative_error relative_error=1.d-3 pt2 = 0.d0 - call ZMQ_pt2(pt2,relative_error) - !call ZMQ_selection(0, pt2)! pour non-stochastic + call ZMQ_pt2(pt2,relative_error) ! Stochastic PT2 + !call ZMQ_selection(0, pt2) ! Deterministic PT2 print *, 'Final step' print *, 'N_det = ', N_det print *, 'N_states = ', N_states diff --git a/plugins/Perturbation/EZFIO.cfg b/plugins/Perturbation/EZFIO.cfg index 19c6c52d..3f8c84dd 100644 --- a/plugins/Perturbation/EZFIO.cfg +++ b/plugins/Perturbation/EZFIO.cfg @@ -11,17 +11,10 @@ doc: The selection process stops when the largest PT2 (for all the state) is low interface: ezfio,provider,ocaml default: 0.0001 -[var_pt2_ratio] -type: Normalized_float -doc: The selection process stops when the energy ratio variational/(variational+PT2) - is equal to var_pt2_ratio. (Obsolete. Need to be removed) -interface: ezfio,provider,ocaml -default: 0.75 - [correlation_energy_ratio_max] type: Normalized_float -doc: The selection process stops at a fixed correlation ratio (usefull for getting same accuracy between molecules) - Defined as (E_CI-E_HF)/ (E_CI+PT2 - E_HF) If Ratio eq 1 it will not be used. (E_HF) is not required. +doc: The selection process stops at a fixed correlation ratio (useful for getting same accuracy between molecules) + Defined as (E_CI-E_HF)/ (E_CI+PT2 - E_HF). (E_HF) is not required. interface: ezfio,provider,ocaml default: 1.00 diff --git a/src/Utils/util.irp.f b/src/Utils/util.irp.f index 4001e9df..d3b20a10 100644 --- a/src/Utils/util.irp.f +++ b/src/Utils/util.irp.f @@ -234,30 +234,14 @@ double precision function dble_logfact(n) result(logfact2) ! n!! END_DOC integer :: n - double precision, save :: memo(1:100) - integer, save :: memomax = 1 - - ASSERT (iand(n,1) /= 0) - if (n<=memomax) then - if (n<3) then - logfact2 = 0.d0 - else - logfact2 = memo(n) - endif - return - endif - - integer :: i - memo(1) = 0.d0 - do i=memomax+2,min(n,99),2 - memo(i) = memo(i-2)+ dlog(dble(i)) - enddo - memomax = min(n,99) - logfact2 = memo(memomax) - - do i=101,n,2 - logfact2 += dlog(dble(i)) + integer :: k + double precision :: prod + prod=0.d0 + do k=2,n,2 + prod=prod+dlog(dfloat(k)) enddo + logfact2=prod + return end function From 6fc08e610d70225320da647dac1c32e7791d66b7 Mon Sep 17 00:00:00 2001 From: Anthony Scemama Date: Fri, 21 Apr 2017 23:18:09 +0200 Subject: [PATCH 3/3] Forgot file --- plugins/Perturbation/var_pt2_ratio_provider.irp.f | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 plugins/Perturbation/var_pt2_ratio_provider.irp.f diff --git a/plugins/Perturbation/var_pt2_ratio_provider.irp.f b/plugins/Perturbation/var_pt2_ratio_provider.irp.f new file mode 100644 index 00000000..43bcbf3e --- /dev/null +++ b/plugins/Perturbation/var_pt2_ratio_provider.irp.f @@ -0,0 +1,10 @@ +BEGIN_PROVIDER [ double precision, var_pt2_ratio ] + implicit none + BEGIN_DOC + ! The selection process stops when the energy ratio variational/(variational+PT2) + ! is equal to var_pt2_ratio + END_DOC + + var_pt2_ratio = correlation_energy_ratio_max +END_PROVIDER +