10
0
mirror of https://github.com/LCPQ/quantum_package synced 2024-07-03 18:05:59 +02:00
quantum_package/plugins/Full_CI_ZMQ/fci_zmq.irp.f

238 lines
8.6 KiB
Fortran
Raw Normal View History

program fci_zmq
implicit none
2016-09-08 10:12:28 +02:00
integer :: i,j,k
2016-09-23 16:16:48 +02:00
double precision, allocatable :: pt2(:)
integer :: degree
integer :: n_det_before, to_select
2016-11-22 13:00:02 +01:00
double precision :: threshold_davidson_in
2016-09-25 22:14:17 +02:00
2016-09-23 16:16:48 +02:00
allocate (pt2(N_states))
2017-04-21 22:59:42 +02:00
double precision :: hf_energy_ref
logical :: has
2017-11-22 16:23:56 +01:00
double precision :: relative_error, absolute_error
integer :: N_states_p
character*(512) :: fmt
2017-11-22 16:21:16 +01:00
2017-10-27 12:20:00 +02:00
relative_error=PT2_relative_error
absolute_error=PT2_absolute_error
2017-06-26 19:12:44 +02:00
2017-11-21 17:20:18 +01:00
pt2 = -huge(1.e0)
2017-05-03 19:23:12 +02:00
threshold_davidson_in = threshold_davidson
threshold_davidson = threshold_davidson_in * 100.d0
SOFT_TOUCH threshold_davidson
call diagonalize_CI
call save_wavefunction
2017-04-21 22:59:42 +02:00
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
if (N_det > N_det_max) then
psi_det = psi_det_sorted
psi_coef = psi_coef_sorted
N_det = N_det_max
soft_touch N_det psi_det psi_coef
call diagonalize_CI
call save_wavefunction
2017-11-22 16:21:16 +01:00
N_states_p = min(N_det,N_states)
endif
2016-07-21 13:24:25 +02:00
n_det_before = 0
2017-05-03 19:23:12 +02:00
2017-06-26 19:12:44 +02:00
character*(8) :: pt2_string
2017-04-21 22:59:42 +02:00
double precision :: correlation_energy_ratio
2017-06-26 19:12:44 +02:00
double precision :: threshold_selectors_save, threshold_generators_save
threshold_selectors_save = threshold_selectors
threshold_generators_save = threshold_generators
2017-11-21 10:43:38 +01:00
double precision :: error(N_states)
2017-06-26 19:12:44 +02:00
correlation_energy_ratio = 0.d0
2017-05-03 19:23:12 +02:00
if (.True.) then ! Avoid pre-calculation of CI_energy
do while ( &
(N_det < N_det_max) .and. &
(maxval(abs(pt2(1:N_states))) > pt2_max) .and. &
(correlation_energy_ratio <= correlation_energy_ratio_max) &
)
2017-11-22 16:21:16 +01:00
write(*,'(A)') '--------------------------------------------------------------------------------'
2017-06-26 19:12:44 +02:00
if (do_pt2) then
pt2_string = ' '
pt2 = 0.d0
2017-11-21 10:43:38 +01:00
threshold_selectors = 1.d0
threshold_generators = 1d0
SOFT_TOUCH threshold_selectors threshold_generators
call ZMQ_pt2(CI_energy, pt2,relative_error,absolute_error,error) ! Stochastic PT2
threshold_selectors = threshold_selectors_save
threshold_generators = threshold_generators_save
SOFT_TOUCH threshold_selectors threshold_generators
2017-06-26 19:12:44 +02:00
else
pt2_string = '(approx)'
endif
2017-05-03 19:23:12 +02:00
correlation_energy_ratio = (CI_energy(1) - hf_energy_ref) / &
2017-06-26 19:12:44 +02:00
(CI_energy(1) + pt2(1) - hf_energy_ref)
2017-05-03 19:23:12 +02:00
correlation_energy_ratio = min(1.d0,correlation_energy_ratio)
2017-11-22 16:21:16 +01:00
! print *, ''
! print '(A,I12)', 'Summary at N_det = ', N_det
! print '(A)', '-----------------------------------'
! print *, ''
! call write_double(6,correlation_energy_ratio, 'Correlation ratio')
! print *, ''
!
! N_states_p = min(N_det,N_states)
! print *, ''
! write(fmt,*) '(''# ============'',', N_states_p, '(1X,''=========================''))'
! write(*,fmt)
! write(fmt,*) '(12X,', N_states_p, '(6X,A5,1X,I6,8X))'
! write(*,fmt) ('State',k, k=1,N_states_p)
! write(fmt,*) '(''# ============'',', N_states_p, '(1X,''=========================''))'
! write(*,fmt)
! write(fmt,*) '(A12,', N_states_p, '(1X,F12.8,13X))'
! write(*,fmt) '# E ', CI_energy(1:N_states_p)
! if (N_states_p > 1) then
! write(*,fmt) '# Excit. (au)', CI_energy(1:N_states_p)-CI_energy(1)
! write(*,fmt) '# Excit. (eV)', (CI_energy(1:N_states_p)-CI_energy(1))*27.211396641308d0
! endif
! write(fmt,*) '(A12,', 2*N_states_p, '(1X,F12.8))'
! write(*,fmt) '# PT2'//pt2_string, (pt2(k), error(k), k=1,N_states_p)
! write(*,*) '#'
! write(*,fmt) '# E+PT2 ', (CI_energy(k)+pt2(k),error(k), k=1,N_states_p)
! if (N_states_p > 1) then
! write(*,fmt) '# Excit. (au)', ( (CI_energy(k)+pt2(k)-CI_energy(1)-pt2(1)), &
! dsqrt(error(k)*error(k)+error(1)*error(1)), k=1,N_states_p)
! write(*,fmt) '# Excit. (eV)', ( (CI_energy(k)+pt2(k)-CI_energy(1)-pt2(1))*27.211396641308d0, &
! dsqrt(error(k)*error(k)+error(1)*error(1))*27.211396641308d0, k=1,N_states_p)
! endif
! write(fmt,*) '(''# ============'',', N_states_p, '(1X,''=========================''))'
! write(*,fmt)
! print *, ''
2017-04-21 22:59:42 +02:00
2017-05-03 19:23:12 +02:00
print *, 'N_det = ', N_det
print *, 'N_states = ', N_states
print*, 'correlation_ratio = ', correlation_energy_ratio
2017-11-22 16:21:16 +01:00
do k=1, N_states_p
2017-05-03 19:23:12 +02:00
print*,'State ',k
print *, 'PT2 = ', pt2(k)
print *, 'E = ', CI_energy(k)
2017-11-21 10:43:38 +01:00
print *, 'E+PT2'//pt2_string//' = ', CI_energy(k)+pt2(k), ' +/- ', error(k)
2016-09-25 22:14:17 +02:00
enddo
2016-11-30 17:33:34 +01:00
2017-05-03 19:23:12 +02:00
print *, '-----'
if(N_states.gt.1)then
2017-11-21 17:20:18 +01:00
print *, 'Variational Energy difference (au | eV)'
2017-11-22 16:21:16 +01:00
do i=2, N_states_p
2017-11-20 15:19:00 +01:00
print*,'Delta E = ', (CI_energy(i) - CI_energy(1)), &
2017-11-21 17:20:18 +01:00
(CI_energy(i) - CI_energy(1)) * 27.211396641308d0
2017-05-03 19:23:12 +02:00
enddo
2017-11-21 17:20:18 +01:00
print *, '-----'
print*, 'Variational + perturbative Energy difference (au | eV)'
2017-11-22 16:21:16 +01:00
do i=2, N_states_p
2017-11-20 15:19:00 +01:00
print*,'Delta E = ', (CI_energy(i)+ pt2(i) - (CI_energy(1) + pt2(1))), &
2017-11-21 17:20:18 +01:00
(CI_energy(i)+ pt2(i) - (CI_energy(1) + pt2(1))) * 27.211396641308d0
2017-05-03 19:23:12 +02:00
enddo
endif
2017-11-21 14:53:32 +01:00
call ezfio_set_full_ci_zmq_energy_pt2(CI_energy(1)+pt2(1))
call dump_fci_iterations_value(N_det,CI_energy,pt2)
2016-11-30 17:33:34 +01:00
2017-05-03 19:23:12 +02:00
n_det_before = N_det
2017-11-22 16:21:16 +01:00
if (s2_eig) then
to_select = N_det/2+1
to_select = max(N_det/2+1, to_select)
to_select = min(to_select, N_det_max-n_det_before)
else
to_select = N_det
to_select = max(N_det, to_select)
to_select = min(to_select, N_det_max-n_det_before)
endif
2017-05-03 19:23:12 +02:00
call ZMQ_selection(to_select, pt2)
PROVIDE psi_coef
PROVIDE psi_det
PROVIDE psi_det_sorted
2017-05-03 22:31:38 +02:00
if (N_det >= N_det_max) then
2017-05-03 19:23:12 +02:00
threshold_davidson = threshold_davidson_in
end if
call diagonalize_CI
call save_wavefunction
call ezfio_set_full_ci_zmq_energy(CI_energy(1))
2017-06-26 19:12:44 +02:00
enddo
2016-11-30 17:33:34 +01:00
endif
2017-06-26 20:35:07 +02:00
if (N_det < N_det_max) then
threshold_davidson = threshold_davidson_in
call diagonalize_CI
call save_wavefunction
call ezfio_set_full_ci_zmq_energy(CI_energy(1))
2017-11-21 14:53:32 +01:00
call ezfio_set_full_ci_zmq_energy_pt2(CI_energy(1)+pt2(1))
2017-06-26 20:35:07 +02:00
endif
2017-06-26 19:12:44 +02:00
if (do_pt2) then
2017-03-13 00:26:21 +01:00
pt2 = 0.d0
2017-11-21 10:43:38 +01:00
threshold_selectors = 1.d0
threshold_generators = 1d0
SOFT_TOUCH threshold_selectors threshold_generators
call ZMQ_pt2(CI_energy, pt2,relative_error,absolute_error,error) ! Stochastic PT2
threshold_selectors = threshold_selectors_save
threshold_generators = threshold_generators_save
SOFT_TOUCH threshold_selectors threshold_generators
2017-10-27 12:20:00 +02:00
call ezfio_set_full_ci_zmq_energy(CI_energy(1))
2017-06-26 20:35:07 +02:00
call ezfio_set_full_ci_zmq_energy_pt2(CI_energy(1)+pt2(1))
2017-06-26 19:12:44 +02:00
endif
2017-10-27 12:20:00 +02:00
print *, 'N_det = ', N_det
print *, 'N_states = ', N_states
print*, 'correlation_ratio = ', correlation_energy_ratio
2017-11-21 14:53:32 +01:00
call dump_fci_iterations_value(N_det,CI_energy,pt2)
2017-11-22 16:21:16 +01:00
print *, ''
print '(A,I12)', 'Summary at N_det = ', N_det
print '(A)', '-----------------------------------'
print *, ''
call write_double(6,correlation_energy_ratio, 'Correlation ratio')
print *, ''
N_states_p = min(N_det,N_states)
print *, ''
write(fmt,*) '(''# ============'',', N_states_p, '(1X,''=========================''))'
write(*,fmt)
write(fmt,*) '(12X,', N_states_p, '(6X,A5,1X,I6,8X))'
write(*,fmt) ('State',k, k=1,N_states_p)
write(fmt,*) '(''# ============'',', N_states_p, '(1X,''=========================''))'
write(*,fmt)
write(fmt,*) '(A12,', N_states_p, '(1X,F12.8,13X))'
write(*,fmt) '# E ', CI_energy(1:N_states_p)
if (N_states_p > 1) then
write(*,fmt) '# Excit. (au)', CI_energy(1:N_states_p)-CI_energy(1)
write(*,fmt) '# Excit. (eV)', (CI_energy(1:N_states_p)-CI_energy(1))*27.211396641308d0
endif
write(fmt,*) '(A12,', 2*N_states_p, '(1X,F12.8))'
write(*,fmt) '# PT2'//pt2_string, (pt2(k), error(k), k=1,N_states_p)
write(*,*) '#'
write(*,fmt) '# E+PT2 ', (CI_energy(k)+pt2(k),error(k), k=1,N_states_p)
if (N_states_p > 1) then
write(*,fmt) '# Excit. (au)', ( (CI_energy(k)+pt2(k)-CI_energy(1)-pt2(1)), &
dsqrt(error(k)*error(k)+error(1)*error(1)), k=1,N_states_p)
write(*,fmt) '# Excit. (eV)', ( (CI_energy(k)+pt2(k)-CI_energy(1)-pt2(1))*27.211396641308d0, &
dsqrt(error(k)*error(k)+error(1)*error(1))*27.211396641308d0, k=1,N_states_p)
endif
write(fmt,*) '(''# ============'',', N_states_p, '(1X,''=========================''))'
write(*,fmt)
print *, ''
2017-06-26 19:12:44 +02:00
2017-11-21 17:20:18 +01:00
2017-05-03 19:23:12 +02:00
end