9
1
mirror of https://github.com/QuantumPackage/qp2.git synced 2024-11-09 06:53:38 +01:00
qp2/src/cipsi/cipsi.irp.f

166 lines
5.5 KiB
Fortran
Raw Normal View History

2019-01-25 11:39:31 +01:00
subroutine run_cipsi
implicit none
2020-08-28 00:10:46 +02:00
use selection_types
2019-01-25 11:39:31 +01:00
BEGIN_DOC
! Selected Full Configuration Interaction with deterministic selection and
! stochastic PT2.
END_DOC
integer :: i,j,k
2020-08-31 01:45:36 +02:00
type(pt2_type) :: pt2_data, pt2_data_err
2020-08-28 16:05:53 +02:00
double precision, allocatable :: zeros(:)
2020-06-12 23:45:23 +02:00
integer :: to_select
logical, external :: qp_stop
2019-01-25 11:39:31 +01:00
2020-06-12 23:45:23 +02:00
double precision :: threshold_generators_save
2019-01-25 11:39:31 +01:00
double precision :: rss
double precision, external :: memory_of_double
2020-08-28 00:10:46 +02:00
PROVIDE H_apply_buffer_allocated
2020-06-12 23:45:23 +02:00
threshold_generators = 1.d0
SOFT_TOUCH threshold_generators
2019-01-25 11:39:31 +01:00
rss = memory_of_double(N_states)*4.d0
call check_mem(rss,irp_here)
2020-08-28 16:05:53 +02:00
allocate (zeros(N_states))
call pt2_alloc(pt2_data, N_states)
2020-08-31 01:45:36 +02:00
call pt2_alloc(pt2_data_err, N_states)
2019-01-25 11:39:31 +01:00
double precision :: hf_energy_ref
logical :: has
double precision :: relative_error
relative_error=PT2_relative_error
2019-06-05 18:57:17 +02:00
zeros = 0.d0
2020-08-28 16:05:53 +02:00
pt2_data % pt2 = -huge(1.e0)
pt2_data % rpt2 = -huge(1.e0)
2020-08-31 22:39:40 +02:00
pt2_data % overlap(:,:) = 0.d0
2020-08-28 00:10:46 +02:00
pt2_data % variance = huge(1.e0)
2019-01-25 11:39:31 +01:00
if (s2_eig) then
call make_s2_eigenfunction
endif
call diagonalize_CI
call save_wavefunction
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
if (s2_eig) then
call make_s2_eigenfunction
endif
call diagonalize_CI
call save_wavefunction
endif
double precision :: correlation_energy_ratio
correlation_energy_ratio = 0.d0
do while ( &
(N_det < N_det_max) .and. &
2023-02-16 14:15:15 +01:00
(maxval(abs(pt2_data % pt2(1:N_states))) > pt2_max) .and. &
(maxval(abs(pt2_data % variance(1:N_states))) > variance_max) .and. &
2020-06-12 23:45:23 +02:00
(correlation_energy_ratio <= correlation_energy_ratio_max) &
2019-01-25 11:39:31 +01:00
)
write(*,'(A)') '--------------------------------------------------------------------------------'
2020-06-12 23:45:23 +02:00
to_select = int(sqrt(dble(N_states))*dble(N_det)*selection_factor)
to_select = max(N_states_diag, to_select)
2019-01-25 11:39:31 +01:00
if (do_pt2) then
2020-08-31 01:45:36 +02:00
call pt2_dealloc(pt2_data)
call pt2_dealloc(pt2_data_err)
call pt2_alloc(pt2_data, N_states)
call pt2_alloc(pt2_data_err, N_states)
2020-06-12 23:45:23 +02:00
threshold_generators_save = threshold_generators
2019-01-25 11:39:31 +01:00
threshold_generators = 1.d0
SOFT_TOUCH threshold_generators
2020-08-31 01:45:36 +02:00
call ZMQ_pt2(psi_energy_with_nucl_rep,pt2_data,pt2_data_err,relative_error, 0) ! Stochastic PT2
2019-01-25 11:39:31 +01:00
threshold_generators = threshold_generators_save
SOFT_TOUCH threshold_generators
2020-06-12 23:45:23 +02:00
else
2020-08-31 01:45:36 +02:00
call pt2_dealloc(pt2_data)
call pt2_alloc(pt2_data, N_states)
2020-08-28 00:10:46 +02:00
call ZMQ_selection(to_select, pt2_data)
2019-01-25 11:39:31 +01:00
endif
correlation_energy_ratio = (psi_energy_with_nucl_rep(1) - hf_energy_ref) / &
2020-08-28 16:05:53 +02:00
(psi_energy_with_nucl_rep(1) + pt2_data % rpt2(1) - hf_energy_ref)
2019-01-25 11:39:31 +01:00
correlation_energy_ratio = min(1.d0,correlation_energy_ratio)
call write_double(6,correlation_energy_ratio, 'Correlation ratio')
2020-08-28 00:10:46 +02:00
call print_summary(psi_energy_with_nucl_rep, &
pt2_data, pt2_data_err, N_det,N_configuration,N_states,psi_s2)
2019-01-25 11:39:31 +01:00
2020-08-28 16:05:53 +02:00
call save_energy(psi_energy_with_nucl_rep, pt2_data % pt2)
2019-01-25 11:39:31 +01:00
2023-04-24 00:50:07 +02:00
call increment_n_iter(psi_energy_with_nucl_rep, pt2_data)
2019-01-25 11:39:31 +01:00
call print_extrapolated_energy()
2023-03-11 22:36:20 +01:00
call print_mol_properties()
2023-04-24 00:50:07 +02:00
call write_cipsi_json(pt2_data,pt2_data_err)
2019-01-25 11:39:31 +01:00
2020-06-12 23:45:23 +02:00
if (qp_stop()) exit
2019-01-25 11:39:31 +01:00
2020-06-12 23:45:23 +02:00
! Add selected determinants
call copy_H_apply_buffer_to_wf()
2021-01-19 18:28:00 +01:00
if (save_wf_after_selection) then
call save_wavefunction
endif
2019-01-25 11:39:31 +01:00
PROVIDE psi_coef
PROVIDE psi_det
PROVIDE psi_det_sorted
call diagonalize_CI
call save_wavefunction
2019-06-05 18:57:17 +02:00
call save_energy(psi_energy_with_nucl_rep, zeros)
2020-08-28 00:10:46 +02:00
if (qp_stop()) exit
2019-01-25 11:39:31 +01:00
enddo
2023-05-04 11:54:29 +02:00
! If stopped because N_det > N_det_max, do an extra iteration to compute the PT2
if ((.not.qp_stop()).and. &
(N_det > N_det_max) .and. &
(maxval(abs(pt2_data % pt2(1:N_states))) > pt2_max) .and. &
(maxval(abs(pt2_data % variance(1:N_states))) > variance_max) .and.&
(correlation_energy_ratio <= correlation_energy_ratio_max) &
) then
2019-01-25 11:39:31 +01:00
if (do_pt2) then
2020-08-31 01:45:36 +02:00
call pt2_dealloc(pt2_data)
call pt2_dealloc(pt2_data_err)
call pt2_alloc(pt2_data, N_states)
call pt2_alloc(pt2_data_err, N_states)
2019-01-25 11:39:31 +01:00
threshold_generators = 1d0
SOFT_TOUCH threshold_generators
2020-08-31 01:45:36 +02:00
call ZMQ_pt2(psi_energy_with_nucl_rep, pt2_data, pt2_data_err, relative_error, 0) ! Stochastic PT2
2019-01-25 11:39:31 +01:00
SOFT_TOUCH threshold_generators
endif
print *, 'N_det = ', N_det
print *, 'N_cfg = ', N_configuration
2019-01-25 11:39:31 +01:00
print *, 'N_states = ', N_states
print*, 'correlation_ratio = ', correlation_energy_ratio
2020-08-28 16:05:53 +02:00
call save_energy(psi_energy_with_nucl_rep, pt2_data % pt2)
2020-08-28 00:10:46 +02:00
call print_summary(psi_energy_with_nucl_rep(1:N_states), &
pt2_data, pt2_data_err, N_det,N_configuration,N_states,psi_s2)
2023-04-24 00:50:07 +02:00
call increment_n_iter(psi_energy_with_nucl_rep, pt2_data)
2019-01-25 11:39:31 +01:00
call print_extrapolated_energy()
2023-03-11 22:36:20 +01:00
call print_mol_properties()
2023-04-24 00:50:07 +02:00
call write_cipsi_json(pt2_data,pt2_data_err)
2019-01-25 11:39:31 +01:00
endif
2020-08-31 01:45:36 +02:00
call pt2_dealloc(pt2_data)
call pt2_dealloc(pt2_data_err)
2019-01-25 11:39:31 +01:00
end
2023-04-24 00:50:07 +02:00