diff --git a/ocaml/.gitignore b/ocaml/.gitignore index cbd77939..0319c135 100644 --- a/ocaml/.gitignore +++ b/ocaml/.gitignore @@ -38,12 +38,12 @@ qp_print qp_run qp_set_ddci qp_set_mo_class -Input_determinants.ml -Input_hartree_fock.ml Input_integrals_bielec.ml +Input_pseudo.ml Input_perturbation.ml Input_properties.ml -Input_pseudo.ml +Input_determinants.ml +Input_hartree_fock.ml qp_edit.ml qp_edit qp_edit.native diff --git a/plugins/CAS_SD/.gitignore b/plugins/CAS_SD/.gitignore index b8827b3b..9b54df80 100644 --- a/plugins/CAS_SD/.gitignore +++ b/plugins/CAS_SD/.gitignore @@ -24,6 +24,7 @@ Selectors_full Utils cas_sd cas_sd_selected +cas_sd_selected_no_skip ezfio_interface.irp.f irpf90.make irpf90_entities diff --git a/plugins/CAS_SD/README.rst b/plugins/CAS_SD/README.rst index 82bc3032..058ec971 100644 --- a/plugins/CAS_SD/README.rst +++ b/plugins/CAS_SD/README.rst @@ -13,11 +13,11 @@ Documentation .. Do not edit this section. It was auto-generated from the .. by the `update_README.py` script. -`full_ci `_ +`full_ci `_ Undocumented -`h_apply_cas_sd `_ +`h_apply_cas_sd `_ Calls H_apply on the HF determinant and selects all connected single and double excitations (of the same symmetry). Auto-generated by the ``generate_h_apply`` script. @@ -28,58 +28,58 @@ Documentation Assume N_int is already provided. -`h_apply_cas_sd_monoexc `_ +`h_apply_cas_sd_monoexc `_ Generate all single excitations of key_in using the bit masks of holes and particles. Assume N_int is already provided. -`h_apply_cas_sd_pt2 `_ +`h_apply_cas_sd_pt2 `_ Calls H_apply on the HF determinant and selects all connected single and double excitations (of the same symmetry). Auto-generated by the ``generate_h_apply`` script. -`h_apply_cas_sd_pt2_diexc `_ +`h_apply_cas_sd_pt2_diexc `_ Generate all double excitations of key_in using the bit masks of holes and particles. Assume N_int is already provided. -`h_apply_cas_sd_pt2_monoexc `_ +`h_apply_cas_sd_pt2_monoexc `_ Generate all single excitations of key_in using the bit masks of holes and particles. Assume N_int is already provided. -`h_apply_cas_sd_selected `_ +`h_apply_cas_sd_selected `_ Calls H_apply on the HF determinant and selects all connected single and double excitations (of the same symmetry). Auto-generated by the ``generate_h_apply`` script. -`h_apply_cas_sd_selected_diexc `_ +`h_apply_cas_sd_selected_diexc `_ Generate all double excitations of key_in using the bit masks of holes and particles. Assume N_int is already provided. -`h_apply_cas_sd_selected_monoexc `_ +`h_apply_cas_sd_selected_monoexc `_ Generate all single excitations of key_in using the bit masks of holes and particles. Assume N_int is already provided. -`h_apply_cas_sd_selected_no_skip `_ +`h_apply_cas_sd_selected_no_skip `_ Calls H_apply on the HF determinant and selects all connected single and double excitations (of the same symmetry). Auto-generated by the ``generate_h_apply`` script. -`h_apply_cas_sd_selected_no_skip_diexc `_ +`h_apply_cas_sd_selected_no_skip_diexc `_ Generate all double excitations of key_in using the bit masks of holes and particles. Assume N_int is already provided. -`h_apply_cas_sd_selected_no_skip_monoexc `_ +`h_apply_cas_sd_selected_no_skip_monoexc `_ Generate all single excitations of key_in using the bit masks of holes and particles. Assume N_int is already provided. diff --git a/plugins/CAS_SD/tree_dependency.png b/plugins/CAS_SD/tree_dependency.png index 185c2b27..d3d98e3c 100644 Binary files a/plugins/CAS_SD/tree_dependency.png and b/plugins/CAS_SD/tree_dependency.png differ diff --git a/plugins/CISD_selected/README.rst b/plugins/CISD_selected/README.rst index c83bd7da..57a8a196 100644 --- a/plugins/CISD_selected/README.rst +++ b/plugins/CISD_selected/README.rst @@ -43,7 +43,6 @@ Documentation particles. Assume N_int is already provided. - `h_apply_cisd_selection_dipole_moment_z_monoexc `_ Generate all single excitations of key_in using the bit masks of holes and particles. diff --git a/plugins/Full_CI/README.rst b/plugins/Full_CI/README.rst index d94675eb..7465089f 100644 --- a/plugins/Full_CI/README.rst +++ b/plugins/Full_CI/README.rst @@ -14,7 +14,7 @@ Documentation Undocumented -`h_apply_fci `_ +`h_apply_fci `_ Calls H_apply on the HF determinant and selects all connected single and double excitations (of the same symmetry). Auto-generated by the ``generate_h_apply`` script. @@ -25,126 +25,126 @@ Documentation Assume N_int is already provided. -`h_apply_fci_mono `_ +`h_apply_fci_mono `_ Calls H_apply on the HF determinant and selects all connected single and double excitations (of the same symmetry). Auto-generated by the ``generate_h_apply`` script. -`h_apply_fci_mono_diexc `_ +`h_apply_fci_mono_diexc `_ Generate all double excitations of key_in using the bit masks of holes and particles. Assume N_int is already provided. -`h_apply_fci_mono_monoexc `_ +`h_apply_fci_mono_monoexc `_ Generate all single excitations of key_in using the bit masks of holes and particles. Assume N_int is already provided. -`h_apply_fci_monoexc `_ +`h_apply_fci_monoexc `_ Generate all single excitations of key_in using the bit masks of holes and particles. Assume N_int is already provided. -`h_apply_fci_no_skip `_ +`h_apply_fci_no_skip `_ Calls H_apply on the HF determinant and selects all connected single and double excitations (of the same symmetry). Auto-generated by the ``generate_h_apply`` script. -`h_apply_fci_no_skip_diexc `_ +`h_apply_fci_no_skip_diexc `_ Generate all double excitations of key_in using the bit masks of holes and particles. Assume N_int is already provided. -`h_apply_fci_no_skip_monoexc `_ +`h_apply_fci_no_skip_monoexc `_ Generate all single excitations of key_in using the bit masks of holes and particles. Assume N_int is already provided. -`h_apply_fci_pt2 `_ +`h_apply_fci_pt2 `_ Calls H_apply on the HF determinant and selects all connected single and double excitations (of the same symmetry). Auto-generated by the ``generate_h_apply`` script. -`h_apply_fci_pt2_diexc `_ +`h_apply_fci_pt2_diexc `_ Generate all double excitations of key_in using the bit masks of holes and particles. Assume N_int is already provided. -`h_apply_fci_pt2_monoexc `_ +`h_apply_fci_pt2_monoexc `_ Generate all single excitations of key_in using the bit masks of holes and particles. Assume N_int is already provided. -`h_apply_pt2_mono_delta_rho `_ +`h_apply_pt2_mono_delta_rho `_ Calls H_apply on the HF determinant and selects all connected single and double excitations (of the same symmetry). Auto-generated by the ``generate_h_apply`` script. -`h_apply_pt2_mono_delta_rho_diexc `_ +`h_apply_pt2_mono_delta_rho_diexc `_ Generate all double excitations of key_in using the bit masks of holes and particles. Assume N_int is already provided. -`h_apply_pt2_mono_delta_rho_monoexc `_ +`h_apply_pt2_mono_delta_rho_monoexc `_ Generate all single excitations of key_in using the bit masks of holes and particles. Assume N_int is already provided. -`h_apply_pt2_mono_di_delta_rho `_ +`h_apply_pt2_mono_di_delta_rho `_ Calls H_apply on the HF determinant and selects all connected single and double excitations (of the same symmetry). Auto-generated by the ``generate_h_apply`` script. -`h_apply_pt2_mono_di_delta_rho_diexc `_ +`h_apply_pt2_mono_di_delta_rho_diexc `_ Generate all double excitations of key_in using the bit masks of holes and particles. Assume N_int is already provided. -`h_apply_pt2_mono_di_delta_rho_monoexc `_ +`h_apply_pt2_mono_di_delta_rho_monoexc `_ Generate all single excitations of key_in using the bit masks of holes and particles. Assume N_int is already provided. -`h_apply_select_mono_delta_rho `_ +`h_apply_select_mono_delta_rho `_ Calls H_apply on the HF determinant and selects all connected single and double excitations (of the same symmetry). Auto-generated by the ``generate_h_apply`` script. -`h_apply_select_mono_delta_rho_diexc `_ +`h_apply_select_mono_delta_rho_diexc `_ Generate all double excitations of key_in using the bit masks of holes and particles. Assume N_int is already provided. -`h_apply_select_mono_delta_rho_monoexc `_ +`h_apply_select_mono_delta_rho_monoexc `_ Generate all single excitations of key_in using the bit masks of holes and particles. Assume N_int is already provided. -`h_apply_select_mono_di_delta_rho `_ +`h_apply_select_mono_di_delta_rho `_ Calls H_apply on the HF determinant and selects all connected single and double excitations (of the same symmetry). Auto-generated by the ``generate_h_apply`` script. -`h_apply_select_mono_di_delta_rho_diexc `_ +`h_apply_select_mono_di_delta_rho_diexc `_ Generate all double excitations of key_in using the bit masks of holes and particles. Assume N_int is already provided. -`h_apply_select_mono_di_delta_rho_monoexc `_ +`h_apply_select_mono_di_delta_rho_monoexc `_ Generate all single excitations of key_in using the bit masks of holes and particles. Assume N_int is already provided. diff --git a/plugins/Full_CI/tree_dependency.png b/plugins/Full_CI/tree_dependency.png index caedb2e0..ad7dcd84 100644 Binary files a/plugins/Full_CI/tree_dependency.png and b/plugins/Full_CI/tree_dependency.png differ diff --git a/plugins/Generators_CAS/tree_dependency.png b/plugins/Generators_CAS/tree_dependency.png index 5bbc55d0..7f32349e 100644 Binary files a/plugins/Generators_CAS/tree_dependency.png and b/plugins/Generators_CAS/tree_dependency.png differ diff --git a/plugins/Generators_full/tree_dependency.png b/plugins/Generators_full/tree_dependency.png index 94ad6358..c2656d20 100644 Binary files a/plugins/Generators_full/tree_dependency.png and b/plugins/Generators_full/tree_dependency.png differ diff --git a/plugins/Hartree_Fock/tree_dependency.png b/plugins/Hartree_Fock/tree_dependency.png index cb1d9738..8a43fb0d 100644 Binary files a/plugins/Hartree_Fock/tree_dependency.png and b/plugins/Hartree_Fock/tree_dependency.png differ diff --git a/plugins/MRCC_CASSD/.gitignore b/plugins/MRCC_CASSD/.gitignore index d81ca7b8..11ad4321 100644 --- a/plugins/MRCC_CASSD/.gitignore +++ b/plugins/MRCC_CASSD/.gitignore @@ -29,4 +29,4 @@ ezfio_interface.irp.f irpf90.make irpf90_entities mrcc_cassd -tags \ No newline at end of file +tags diff --git a/plugins/MRCC_Utils/README.rst b/plugins/MRCC_Utils/README.rst index 71392798..7c26f9f7 100644 --- a/plugins/MRCC_Utils/README.rst +++ b/plugins/MRCC_Utils/README.rst @@ -94,7 +94,7 @@ Documentation Undocumented -`h_apply_mrcc `_ +`h_apply_mrcc `_ Calls H_apply on the HF determinant and selects all connected single and double excitations (of the same symmetry). Auto-generated by the ``generate_h_apply`` script. @@ -105,7 +105,7 @@ Documentation Assume N_int is already provided. -`h_apply_mrcc_monoexc `_ +`h_apply_mrcc_monoexc `_ Generate all single excitations of key_in using the bit masks of holes and particles. Assume N_int is already provided. diff --git a/plugins/MRCC_Utils/mrcc_general.irp.f b/plugins/MRCC_Utils/mrcc_general.irp.f index cbebd127..92b33f6c 100644 --- a/plugins/MRCC_Utils/mrcc_general.irp.f +++ b/plugins/MRCC_Utils/mrcc_general.irp.f @@ -1,5 +1,12 @@ subroutine run_mrcc implicit none + call set_generators_bitmasks_as_holes_and_particles + call mrcc_iterations +end + +subroutine mrcc_iterations + implicit none + integer :: i,j double precision :: E_new, E_old, delta_e @@ -24,7 +31,37 @@ subroutine run_mrcc call save_wavefunction enddo call write_double(6,ci_energy_dressed(1),"Final MRCC energy") - call ezfio_set_mrcc_energy(ci_energy_dressed(1)) + call ezfio_set_mrcc_cassd_energy(ci_energy_dressed(1)) call save_wavefunction end + +subroutine set_generators_bitmasks_as_holes_and_particles + implicit none + integer :: i,k + do k = 1, N_generators_bitmask + do i = 1, N_int + ! Pure single part + generators_bitmask(i,1,1,k) = holes_operators(i,1) ! holes for pure single exc alpha + generators_bitmask(i,1,2,k) = particles_operators(i,1) ! particles for pure single exc alpha + generators_bitmask(i,2,1,k) = holes_operators(i,2) ! holes for pure single exc beta + generators_bitmask(i,2,2,k) = particles_operators(i,2) ! particles for pure single exc beta + + ! Double excitation + generators_bitmask(i,1,3,k) = holes_operators(i,1) ! holes for first single exc alpha + generators_bitmask(i,1,4,k) = particles_operators(i,1) ! particles for first single exc alpha + generators_bitmask(i,2,3,k) = holes_operators(i,2) ! holes for first single exc beta + generators_bitmask(i,2,4,k) = particles_operators(i,2) ! particles for first single exc beta + + generators_bitmask(i,1,5,k) = holes_operators(i,1) ! holes for second single exc alpha + generators_bitmask(i,1,6,k) = particles_operators(i,1) ! particles for second single exc alpha + generators_bitmask(i,2,5,k) = holes_operators(i,2) ! holes for second single exc beta + generators_bitmask(i,2,6,k) = particles_operators(i,2) ! particles for second single exc beta + + enddo + enddo + touch generators_bitmask + + + +end diff --git a/plugins/MRCC_Utils/mrcc_utils.irp.f b/plugins/MRCC_Utils/mrcc_utils.irp.f index d8ed5250..2226acb2 100644 --- a/plugins/MRCC_Utils/mrcc_utils.irp.f +++ b/plugins/MRCC_Utils/mrcc_utils.irp.f @@ -63,7 +63,7 @@ BEGIN_PROVIDER [ double precision, h_matrix_dressed, (N_det,N_det,N_states) ] i =idx_ref(ii) h_matrix_dressed(i,i,istate) += delta_ii(ii,istate) do jj = 1, N_det_non_ref - j =idx_ref(jj) + j =idx_non_ref(jj) h_matrix_dressed(i,j,istate) += delta_ij(ii,jj,istate) h_matrix_dressed(j,i,istate) += delta_ij(ii,jj,istate) enddo diff --git a/plugins/MRCC_Utils_new/README.rst b/plugins/MRCC_Utils_new/README.rst new file mode 100644 index 00000000..0b12d7fc --- /dev/null +++ b/plugins/MRCC_Utils_new/README.rst @@ -0,0 +1,23 @@ +=========== +MRCC Module +=========== + +Needed Modules +============== + +.. Do not edit this section. It was auto-generated from the +.. by the `update_README.py` script. + +.. image:: tree_dependency.png + +* `Perturbation `_ +* `Selectors_full `_ +* `Generators_full `_ +* `Psiref_Utils `_ + +Documentation +============= + +.. Do not edit this section. It was auto-generated from the +.. by the `update_README.py` script. + diff --git a/plugins/MRCC_Utils_new/davidson.irp.f b/plugins/MRCC_Utils_new/davidson.irp.f new file mode 100644 index 00000000..0c7bebbd --- /dev/null +++ b/plugins/MRCC_Utils_new/davidson.irp.f @@ -0,0 +1,430 @@ +subroutine davidson_diag_mrcc(dets_in,u_in,energies,dim_in,sze,N_st,Nint,iunit,istate) + use bitmasks + implicit none + BEGIN_DOC + ! Davidson diagonalization. + ! + ! dets_in : bitmasks corresponding to determinants + ! + ! u_in : guess coefficients on the various states. Overwritten + ! on exit + ! + ! dim_in : leftmost dimension of u_in + ! + ! sze : Number of determinants + ! + ! N_st : Number of eigenstates + ! + ! iunit : Unit number for the I/O + ! + ! Initial guess vectors are not necessarily orthonormal + END_DOC + integer, intent(in) :: dim_in, sze, N_st, Nint, iunit, istate + integer(bit_kind), intent(in) :: dets_in(Nint,2,sze) + double precision, intent(inout) :: u_in(dim_in,N_st) + double precision, intent(out) :: energies(N_st) + double precision, allocatable :: H_jj(:) + + double precision :: diag_h_mat_elem + integer :: i + ASSERT (N_st > 0) + ASSERT (sze > 0) + ASSERT (Nint > 0) + ASSERT (Nint == N_int) + PROVIDE mo_bielec_integrals_in_map + allocate(H_jj(sze)) + + !$OMP PARALLEL DEFAULT(NONE) & + !$OMP SHARED(sze,H_jj,N_det_ref,dets_in,Nint,istate,delta_ii,idx_ref) & + !$OMP PRIVATE(i) + !$OMP DO SCHEDULE(guided) + do i=1,sze + H_jj(i) = diag_h_mat_elem(dets_in(1,1,i),Nint) + enddo + !$OMP END DO + !$OMP DO SCHEDULE(guided) + do i=1,N_det_ref + H_jj(idx_ref(i)) += delta_ii(i,istate) + enddo + !$OMP END DO + !$OMP END PARALLEL + + call davidson_diag_hjj_mrcc(dets_in,u_in,H_jj,energies,dim_in,sze,N_st,Nint,iunit,istate) + deallocate (H_jj) +end + +subroutine davidson_diag_hjj_mrcc(dets_in,u_in,H_jj,energies,dim_in,sze,N_st,Nint,iunit,istate) + use bitmasks + implicit none + BEGIN_DOC + ! Davidson diagonalization with specific diagonal elements of the H matrix + ! + ! H_jj : specific diagonal H matrix elements to diagonalize de Davidson + ! + ! dets_in : bitmasks corresponding to determinants + ! + ! u_in : guess coefficients on the various states. Overwritten + ! on exit + ! + ! dim_in : leftmost dimension of u_in + ! + ! sze : Number of determinants + ! + ! N_st : Number of eigenstates + ! + ! iunit : Unit for the I/O + ! + ! Initial guess vectors are not necessarily orthonormal + END_DOC + integer, intent(in) :: dim_in, sze, N_st, Nint, istate + integer(bit_kind), intent(in) :: dets_in(Nint,2,sze) + double precision, intent(in) :: H_jj(sze) + integer, intent(in) :: iunit + double precision, intent(inout) :: u_in(dim_in,N_st) + double precision, intent(out) :: energies(N_st) + + integer :: iter + integer :: i,j,k,l,m + logical :: converged + + double precision :: overlap(N_st,N_st) + double precision :: u_dot_v, u_dot_u + + integer, allocatable :: kl_pairs(:,:) + integer :: k_pairs, kl + + integer :: iter2 + double precision, allocatable :: W(:,:,:), U(:,:,:), R(:,:) + double precision, allocatable :: y(:,:,:,:), h(:,:,:,:), lambda(:) + double precision :: diag_h_mat_elem + double precision :: residual_norm(N_st) + character*(16384) :: write_buffer + double precision :: to_print(2,N_st) + double precision :: cpu, wall + + PROVIDE det_connections + + call write_time(iunit) + call wall_time(wall) + call cpu_time(cpu) + write(iunit,'(A)') '' + write(iunit,'(A)') 'Davidson Diagonalization' + write(iunit,'(A)') '------------------------' + write(iunit,'(A)') '' + call write_int(iunit,N_st,'Number of states') + call write_int(iunit,sze,'Number of determinants') + write(iunit,'(A)') '' + write_buffer = '===== ' + do i=1,N_st + write_buffer = trim(write_buffer)//' ================ ================' + enddo + write(iunit,'(A)') trim(write_buffer) + write_buffer = ' Iter' + do i=1,N_st + write_buffer = trim(write_buffer)//' Energy Residual' + enddo + write(iunit,'(A)') trim(write_buffer) + write_buffer = '===== ' + do i=1,N_st + write_buffer = trim(write_buffer)//' ================ ================' + enddo + write(iunit,'(A)') trim(write_buffer) + + allocate( & + kl_pairs(2,N_st*(N_st+1)/2), & + W(sze,N_st,davidson_sze_max), & + U(sze,N_st,davidson_sze_max), & + R(sze,N_st), & + h(N_st,davidson_sze_max,N_st,davidson_sze_max), & + y(N_st,davidson_sze_max,N_st,davidson_sze_max), & + lambda(N_st*davidson_sze_max)) + + ASSERT (N_st > 0) + ASSERT (sze > 0) + ASSERT (Nint > 0) + ASSERT (Nint == N_int) + + ! Initialization + ! ============== + + k_pairs=0 + do l=1,N_st + do k=1,l + k_pairs+=1 + kl_pairs(1,k_pairs) = k + kl_pairs(2,k_pairs) = l + enddo + enddo + + !$OMP PARALLEL DEFAULT(NONE) & + !$OMP SHARED(U,sze,N_st,overlap,kl_pairs,k_pairs, & + !$OMP Nint,dets_in,u_in) & + !$OMP PRIVATE(k,l,kl,i) + + + ! Orthonormalize initial guess + ! ============================ + + !$OMP DO + do kl=1,k_pairs + k = kl_pairs(1,kl) + l = kl_pairs(2,kl) + if (k/=l) then + overlap(k,l) = u_dot_v(U_in(1,k),U_in(1,l),sze) + overlap(l,k) = overlap(k,l) + else + overlap(k,k) = u_dot_u(U_in(1,k),sze) + endif + enddo + !$OMP END DO + !$OMP END PARALLEL + + call ortho_lowdin(overlap,size(overlap,1),N_st,U_in,size(U_in,1),sze) + + ! Davidson iterations + ! =================== + + converged = .False. + + do while (.not.converged) + + !$OMP PARALLEL DEFAULT(NONE) & + !$OMP PRIVATE(k,i) SHARED(U,u_in,sze,N_st) + do k=1,N_st + !$OMP DO + do i=1,sze + U(i,k,1) = u_in(i,k) + enddo + !$OMP END DO + enddo + !$OMP END PARALLEL + + do iter=1,davidson_sze_max-1 + + ! Compute W_k = H |u_k> + ! ---------------------- + + do k=1,N_st + call H_u_0_mrcc(W(1,k,iter),U(1,k,iter),H_jj,sze,dets_in,Nint,istate) + enddo + + ! Compute h_kl = = + ! ------------------------------------------- + + do l=1,N_st + do k=1,N_st + do iter2=1,iter-1 + h(k,iter2,l,iter) = u_dot_v(U(1,k,iter2),W(1,l,iter),sze) + h(k,iter,l,iter2) = h(k,iter2,l,iter) + enddo + enddo + do k=1,l + h(k,iter,l,iter) = u_dot_v(U(1,k,iter),W(1,l,iter),sze) + h(l,iter,k,iter) = h(k,iter,l,iter) + enddo + enddo + + !DEBUG H MATRIX + !do i=1,iter + ! print '(10(x,F16.10))', h(1,i,1,1:i) + !enddo + !print *, '' + !END + + ! Diagonalize h + ! ------------- + call lapack_diag(lambda,y,h,N_st*davidson_sze_max,N_st*iter) + + ! Express eigenvectors of h in the determinant basis + ! -------------------------------------------------- + + do k=1,N_st + do i=1,sze + U(i,k,iter+1) = 0.d0 + W(i,k,iter+1) = 0.d0 + do l=1,N_st + do iter2=1,iter + U(i,k,iter+1) = U(i,k,iter+1) + U(i,l,iter2)*y(l,iter2,k,1) + W(i,k,iter+1) = W(i,k,iter+1) + W(i,l,iter2)*y(l,iter2,k,1) + enddo + enddo + enddo + enddo + + ! Compute residual vector + ! ----------------------- + + do k=1,N_st + do i=1,sze + R(i,k) = lambda(k) * U(i,k,iter+1) - W(i,k,iter+1) + enddo + residual_norm(k) = u_dot_u(R(1,k),sze) + to_print(1,k) = lambda(k) + nuclear_repulsion + to_print(2,k) = residual_norm(k) + enddo + + write(iunit,'(X,I3,X,100(X,F16.10,X,E16.6))'), iter, to_print(:,1:N_st) + call davidson_converged(lambda,residual_norm,wall,iter,cpu,N_st,converged) + if (converged) then + exit + endif + + + ! Davidson step + ! ------------- + + do k=1,N_st + do i=1,sze + U(i,k,iter+1) = -1.d0/max(H_jj(i) - lambda(k),1.d-2) * R(i,k) + enddo + enddo + + ! Gram-Schmidt + ! ------------ + + double precision :: c + do k=1,N_st + do iter2=1,iter + do l=1,N_st + c = u_dot_v(U(1,k,iter+1),U(1,l,iter2),sze) + do i=1,sze + U(i,k,iter+1) -= c * U(i,l,iter2) + enddo + enddo + enddo + do l=1,k-1 + c = u_dot_v(U(1,k,iter+1),U(1,l,iter+1),sze) + do i=1,sze + U(i,k,iter+1) -= c * U(i,l,iter+1) + enddo + enddo + call normalize( U(1,k,iter+1), sze ) + enddo + + !DEBUG : CHECK OVERLAP + !print *, '===' + !do k=1,iter+1 + ! do l=1,k + ! c = u_dot_v(U(1,1,k),U(1,1,l),sze) + ! print *, k,l, c + ! enddo + !enddo + !print *, '===' + !pause + !END DEBUG + + + enddo + + if (.not.converged) then + iter = davidson_sze_max-1 + endif + + ! Re-contract to u_in + ! ----------- + + do k=1,N_st + energies(k) = lambda(k) + do i=1,sze + u_in(i,k) = 0.d0 + do iter2=1,iter + do l=1,N_st + u_in(i,k) += U(i,l,iter2)*y(l,iter2,k,1) + enddo + enddo + enddo + enddo + + enddo + + write_buffer = '===== ' + do i=1,N_st + write_buffer = trim(write_buffer)//' ================ ================' + enddo + write(iunit,'(A)') trim(write_buffer) + write(iunit,'(A)') '' + call write_time(iunit) + + deallocate ( & + kl_pairs, & + W, & + U, & + R, & + h, & + y, & + lambda & + ) + abort_here = abort_all +end + +subroutine H_u_0_mrcc(v_0,u_0,H_jj,n,keys_tmp,Nint,istate) + use bitmasks + implicit none + BEGIN_DOC + ! Computes v_0 = H|u_0> + ! + ! n : number of determinants + ! + ! H_jj : array of + END_DOC + integer, intent(in) :: n,Nint,istate + double precision, intent(out) :: v_0(n) + double precision, intent(in) :: u_0(n) + double precision, intent(in) :: H_jj(n) + integer(bit_kind),intent(in) :: keys_tmp(Nint,2,n) + integer, allocatable :: idx(:) + double precision :: hij + double precision, allocatable :: vt(:) + integer :: i,j,k,l, jj,ii + integer :: i0, j0 + ASSERT (Nint > 0) + ASSERT (Nint == N_int) + ASSERT (n>0) + PROVIDE ref_bitmask_energy delta_ij + integer, parameter :: block_size = 157 + !$OMP PARALLEL DEFAULT(NONE) & + !$OMP PRIVATE(i,hij,j,k,idx,jj,ii,vt) & + !$OMP SHARED(n_det_ref,n_det_non_ref,idx_ref,idx_non_ref,n,H_jj,u_0,keys_tmp,Nint,v_0,istate,delta_ij) + !$OMP DO SCHEDULE(static) + do i=1,n + v_0(i) = H_jj(i) * u_0(i) + enddo + !$OMP END DO + allocate(idx(0:n), vt(n)) + Vt = 0.d0 + !$OMP DO SCHEDULE(guided) + do i=1,n + idx(0) = i + call filter_connected_davidson(keys_tmp,keys_tmp(1,1,i),Nint,i-1,idx) + do jj=1,idx(0) + j = idx(jj) + if ( (dabs(u_0(j)) > 1.d-7).or.((dabs(u_0(i)) > 1.d-7)) ) then + call i_H_j(keys_tmp(1,1,j),keys_tmp(1,1,i),Nint,hij) + hij = hij + vt (i) = vt (i) + hij*u_0(j) + vt (j) = vt (j) + hij*u_0(i) + endif + enddo + enddo + !$OMP END DO + + !$OMP DO SCHEDULE(guided) + do ii=1,n_det_ref + i = idx_ref(ii) + do jj = 1, n_det_non_ref + j = idx_non_ref(jj) + vt (i) = vt (i) + delta_ij(ii,jj,istate)*u_0(j) + vt (j) = vt (j) + delta_ij(ii,jj,istate)*u_0(i) + enddo + enddo + !$OMP END DO + !$OMP CRITICAL + do i=1,n + v_0(i) = v_0(i) + vt(i) + enddo + !$OMP END CRITICAL + deallocate(idx,vt) + !$OMP END PARALLEL +end + + diff --git a/plugins/MRCC_Utils_new/mrcc_amplitudes.irp.f b/plugins/MRCC_Utils_new/mrcc_amplitudes.irp.f new file mode 100644 index 00000000..8d1bce33 --- /dev/null +++ b/plugins/MRCC_Utils_new/mrcc_amplitudes.irp.f @@ -0,0 +1,85 @@ +subroutine get_excitation_operators_for_one_ref(det_ref,i_state,ndetnonref,N_connect_ref,excitation_operators,amplitudes_phase_less,index_connected) + use bitmasks + implicit none + integer(bit_kind), intent(in) :: det_ref(N_int,2) + integer, intent(in) :: i_state,ndetnonref + integer*2, intent(out) :: excitation_operators(5,ndetnonref) + integer, intent(out) :: index_connected(ndetnonref) + integer, intent(out) :: N_connect_ref + double precision, intent(out) :: amplitudes_phase_less(ndetnonref) + + integer :: i,j,k,l,degree,h1,p1,h2,p2,s1,s2 + integer :: exc(0:2,2,2) + double precision :: phase,hij + BEGIN_DOC +! This subroutine provides all the amplitudes and excitation operators +! that one needs to go from the reference to the non reference wave function +! you enter with det_ref that is a reference determinant +! +! N_connect_ref is the number of determinants belonging to psi_non_ref +! that are connected to det_ref. +! +! amplitudes_phase_less(i) = amplitude phase less t_{I->i} = * lambda_mrcc(i) * phase(I->i) +! +! excitation_operators(:,i) represents the holes and particles that +! link the ith connected determinant to det_ref +! if :: +! excitation_operators(5,i) = 2 :: double excitation alpha +! excitation_operators(5,i) = -2 :: double excitation beta +!!! excitation_operators(1,i) :: hole 1 +!!! excitation_operators(2,i) :: particle 1 +!!! excitation_operators(3,i) :: hole 2 +!!! excitation_operators(4,i) :: particle 2 +! else if :: +! excitation_operators(5,i) = 1 :: single excitation alpha +!!! excitation_operators(1,i) :: hole 1 +!!! excitation_operators(2,i) :: particle 1 +! else if :: +! excitation_operators(5,i) = -1 :: single excitation beta +!!! excitation_operators(3,i) :: hole 1 +!!! excitation_operators(4,i) :: particle 1 +! else if :: +!!! excitation_operators(5,i) = 0 :: double excitation alpha/beta +!!! excitation_operators(1,i) :: hole 1 alpha +!!! excitation_operators(2,i) :: particle 1 alpha +!!! excitation_operators(3,i) :: hole 2 beta +!!! excitation_operators(4,i) :: particle 2 beta + END_DOC + N_connect_ref = 0 + do i = 1, ndetnonref + call i_H_j_phase_out(det_ref,psi_non_ref(1,1,i),N_int,hij,phase,exc,degree) +! if(dabs(hij).le.mo_integrals_threshold)cycle + N_connect_ref +=1 + index_connected(N_connect_ref) = i + call decode_exc(exc,degree,h1,p1,h2,p2,s1,s2) + amplitudes_phase_less(N_connect_ref) = hij * lambda_mrcc(i_state,i) !*phase + + if(degree==2)then + excitation_operators(1,N_connect_ref) = h1 + excitation_operators(2,N_connect_ref) = p1 + excitation_operators(3,N_connect_ref) = h2 + excitation_operators(4,N_connect_ref) = p2 + if(s1==s2.and.s1==1)then ! double alpha + excitation_operators(5,N_connect_ref)= 2 + elseif(s1==s2.and.s1==2)then ! double beta + excitation_operators(5,N_connect_ref)=-2 + else + excitation_operators(5,N_connect_ref)= 0 ! double alpha/beta + endif + elseif(degree==1)then + if(s1==1)then ! mono alpha + excitation_operators(5,N_connect_ref)= 1 + excitation_operators(1,N_connect_ref) = h1 + excitation_operators(2,N_connect_ref) = p1 + else ! mono beta + excitation_operators(5,N_connect_ref)=-1 + excitation_operators(3,N_connect_ref) = h1 + excitation_operators(4,N_connect_ref) = p1 + endif + else + N_connect_ref-=1 + endif + + enddo + +end diff --git a/plugins/MRCC_Utils_new/mrcc_dress.irp.f b/plugins/MRCC_Utils_new/mrcc_dress.irp.f new file mode 100644 index 00000000..eb06b14a --- /dev/null +++ b/plugins/MRCC_Utils_new/mrcc_dress.irp.f @@ -0,0 +1,129 @@ +subroutine mrcc_dress(ndetref,ndetnonref,nstates,delta_ij_,delta_ii_) + use bitmasks + implicit none + integer, intent(in) :: ndetref,nstates,ndetnonref + double precision, intent(inout) :: delta_ii_(ndetref,nstates),delta_ij_(ndetref,ndetnonref,nstates) + integer :: i,j,k,l + integer :: i_state + integer :: N_connect_ref + integer*2,allocatable :: excitation_operators(:,:) + double precision, allocatable :: amplitudes_phase_less(:) + double precision, allocatable :: coef_test(:) + integer(bit_kind), allocatable :: key_test(:,:) + integer, allocatable :: index_connected(:) + integer :: i_hole,i_particle,ispin,i_ok,connected_to_ref,index_wf + integer, allocatable :: idx_vector(:), degree_vector(:) + double precision :: phase_ij + double precision :: dij,phase_la + double precision :: hij,phase + integer :: exc(0:2,2,2),degree + logical :: is_in_wavefunction + allocate(excitation_operators(5,N_det_non_ref)) + allocate(amplitudes_phase_less(N_det_non_ref)) + allocate(key_test(N_int,2)) + allocate(index_connected(N_det_non_ref)) + allocate(idx_vector(0:N_det_non_ref)) + allocate(degree_vector(N_det_non_ref)) + i_state = 1 + + do i = 1, N_det_ref + call get_excitation_operators_for_one_ref(psi_ref(1,1,i),i_state,N_det_non_ref,N_connect_ref,excitation_operators,amplitudes_phase_less,index_connected) + print*,'N_connect_ref =',N_connect_ref + do l = 1, N_det_non_ref + double precision :: t_il,phase_il,hil + call i_H_j_phase_out(psi_ref(1,1,i),psi_non_ref(1,1,l),N_int,hil,phase_il,exc,degree) + t_il = hil * lambda_mrcc(i_state,l) + ! loop on the non ref determinants + do j = 1, N_connect_ref + ! loop on the excitation operators linked to i + if(j==l)cycle + do k = 1, N_int + key_test(k,1) = psi_non_ref(k,1,l) + key_test(k,2) = psi_non_ref(k,2,l) + enddo + ! we apply the excitation operator T_I->j + call apply_excitation_operator(key_test,excitation_operators(1,j),i_ok) + if(i_ok.ne.1)cycle + ! we check if such determinant is already in the wave function + if(is_in_wavefunction(key_test,N_int,N_det))cycle + ! we get the phase for psi_non_ref(l) -> T_I->j |psi_non_ref(l)> + call get_excitation(psi_non_ref(1,1,l),key_test,exc,degree,phase_la,N_int) + ! we get the phase T_I->j + call i_H_j_phase_out(psi_ref(1,1,i),psi_non_ref(1,1,index_connected(j)),N_int,hij,phase_ij,exc,degree) + ! we compute the contribution to the coef of key_test + dij = t_il * hij * phase_la *phase_ij *lambda_mrcc(i_state,index_connected(j)) * 0.5d0 + ! we compute the interaction of such determinant with all the non_ref dets + call get_excitation_degree_vector(psi_non_ref,key_test,degree_vector,N_int,N_det_non_ref,idx_vector) + do k = 1, idx_vector(0) + call i_H_j_phase_out(key_test,psi_non_ref(1,1,idx_vector(k)),N_int,hij,phase,exc,degree) + delta_ij_(i,idx_vector(k),i_state) += hij * dij + enddo + enddo + if(dabs(psi_ref_coef(i,i_state)).le.5.d-5)cycle +! delta_ij_(i,l,i_state) = delta_ij_(i,l,i_state) * 0.5d0 + delta_ii_(i,i_state) -= delta_ij_(i,l,i_state) * psi_non_ref_coef(l,i_state) / psi_ref_coef(i,i_state) + enddo + enddo + + deallocate(excitation_operators) + deallocate(amplitudes_phase_less) + deallocate(key_test) + deallocate(idx_vector) + deallocate(degree_vector) + +end + + + +subroutine apply_excitation_operator(key_in,excitation_operator,i_ok) + use bitmasks + implicit none + integer(bit_kind), intent(inout) :: key_in + integer, intent (out) :: i_ok + integer*2 :: excitation_operator(5) + integer :: i_particle,i_hole,ispin + ! Do excitation + if(excitation_operator(5)==1)then ! mono alpha + i_hole = excitation_operator(1) + i_particle = excitation_operator(2) + ispin = 1 + call do_mono_excitation(key_in,i_hole,i_particle,ispin,i_ok) + else if (excitation_operator(5)==-1)then ! mono beta + i_hole = excitation_operator(3) + i_particle = excitation_operator(4) + ispin = 2 + call do_mono_excitation(key_in,i_hole,i_particle,ispin,i_ok) + else if (excitation_operator(5) == -2 )then ! double beta + i_hole = excitation_operator(1) + i_particle = excitation_operator(2) + ispin = 2 + call do_mono_excitation(key_in,i_hole,i_particle,ispin,i_ok) + if(i_ok.ne.1)return + i_hole = excitation_operator(3) + i_particle = excitation_operator(4) + ispin = 2 + call do_mono_excitation(key_in,i_hole,i_particle,ispin,i_ok) + + else if (excitation_operator(5) == 2 )then ! double alpha + i_hole = excitation_operator(1) + i_particle = excitation_operator(2) + ispin = 1 + call do_mono_excitation(key_in,i_hole,i_particle,ispin,i_ok) + if(i_ok.ne.1)return + i_hole = excitation_operator(3) + i_particle = excitation_operator(4) + ispin = 1 + call do_mono_excitation(key_in,i_hole,i_particle,ispin,i_ok) + + else if (excitation_operator(5) == 0 )then ! double alpha/alpha + i_hole = excitation_operator(1) + i_particle = excitation_operator(2) + ispin = 1 + call do_mono_excitation(key_in,i_hole,i_particle,ispin,i_ok) + if(i_ok.ne.1)return + i_hole = excitation_operator(3) + i_particle = excitation_operator(4) + ispin = 2 + call do_mono_excitation(key_in,i_hole,i_particle,ispin,i_ok) + endif +end diff --git a/plugins/MRCC_Utils_new/mrcc_general.irp.f b/plugins/MRCC_Utils_new/mrcc_general.irp.f new file mode 100644 index 00000000..245fcb05 --- /dev/null +++ b/plugins/MRCC_Utils_new/mrcc_general.irp.f @@ -0,0 +1,67 @@ +subroutine run_mrcc + implicit none + call set_generators_bitmasks_as_holes_and_particles + call mrcc_iterations +end + +subroutine mrcc_iterations + implicit none + + integer :: i,j + + double precision :: E_new, E_old, delta_e + integer :: iteration + E_new = 0.d0 + delta_E = 1.d0 + iteration = 0 + do while (delta_E > 1.d-8) + iteration += 1 + print *, '===========================' + print *, 'MRCC Iteration', iteration + print *, '===========================' + print *, '' + E_old = sum(ci_energy_dressed) + call write_double(6,ci_energy_dressed(1),"MRCC energy") + call diagonalize_ci_dressed + E_new = sum(ci_energy_dressed) + delta_E = dabs(E_new - E_old) +! stop + if (iteration > 200) then + exit + endif + enddo + call write_double(6,ci_energy_dressed(1),"Final MRCC energy") + call ezfio_set_mrcc_cassd_energy(ci_energy_dressed(1)) + call save_wavefunction + +end + +subroutine set_generators_bitmasks_as_holes_and_particles + implicit none + integer :: i,k + do k = 1, N_generators_bitmask + do i = 1, N_int + ! Pure single part + generators_bitmask(i,1,1,k) = holes_operators(i,1) ! holes for pure single exc alpha + generators_bitmask(i,1,2,k) = particles_operators(i,1) ! particles for pure single exc alpha + generators_bitmask(i,2,1,k) = holes_operators(i,2) ! holes for pure single exc beta + generators_bitmask(i,2,2,k) = particles_operators(i,2) ! particles for pure single exc beta + + ! Double excitation + generators_bitmask(i,1,3,k) = holes_operators(i,1) ! holes for first single exc alpha + generators_bitmask(i,1,4,k) = particles_operators(i,1) ! particles for first single exc alpha + generators_bitmask(i,2,3,k) = holes_operators(i,2) ! holes for first single exc beta + generators_bitmask(i,2,4,k) = particles_operators(i,2) ! particles for first single exc beta + + generators_bitmask(i,1,5,k) = holes_operators(i,1) ! holes for second single exc alpha + generators_bitmask(i,1,6,k) = particles_operators(i,1) ! particles for second single exc alpha + generators_bitmask(i,2,5,k) = holes_operators(i,2) ! holes for second single exc beta + generators_bitmask(i,2,6,k) = particles_operators(i,2) ! particles for second single exc beta + + enddo + enddo + touch generators_bitmask + + + +end diff --git a/plugins/MRCC_Utils_new/mrcc_utils.irp.f b/plugins/MRCC_Utils_new/mrcc_utils.irp.f new file mode 100644 index 00000000..d97696e5 --- /dev/null +++ b/plugins/MRCC_Utils_new/mrcc_utils.irp.f @@ -0,0 +1,179 @@ + BEGIN_PROVIDER [ double precision, lambda_mrcc, (N_states,psi_det_size) ] +&BEGIN_PROVIDER [ double precision, lambda_pert, (N_states,psi_det_size) ] + implicit none + BEGIN_DOC + ! cm/ or perturbative 1/Delta_E(m) + END_DOC + integer :: i,k + double precision :: ihpsi(N_states), hii + integer :: i_ok + i_ok = 0 + + do i=1,N_det_non_ref + call i_h_psi(psi_non_ref(1,1,i), psi_ref, psi_ref_coef, N_int, N_det_ref,& + size(psi_ref_coef,1), n_states, ihpsi) + call i_h_j(psi_non_ref(1,1,i),psi_non_ref(1,1,i),N_int,hii) + do k=1,N_states + lambda_pert(k,i) = 1.d0 / (psi_ref_energy_diagonalized(k)-hii) + if (dabs(ihpsi(k)).le.1.d-3) then + i_ok +=1 + lambda_mrcc(k,i) = lambda_pert(k,i) + else + lambda_mrcc(k,i) = psi_non_ref_coef(i,k)/ihpsi(k) + endif + enddo + enddo + print*,'N_det_non_ref = ',N_det_non_ref + print*,'Number of Perturbatively treated determinants = ',i_ok + print*,'psi_coef_ref_ratio = ',psi_ref_coef(2,1)/psi_ref_coef(1,1) + +END_PROVIDER + + + + +!BEGIN_PROVIDER [ double precision, delta_ij_non_ref, (N_det_non_ref, N_det_non_ref,N_states) ] +!implicit none +!BEGIN_DOC +!! Dressing matrix in SD basis +!END_DOC +!delta_ij_non_ref = 0.d0 +!call H_apply_mrcc_simple(delta_ij_non_ref,N_det_non_ref) +!END_PROVIDER + + BEGIN_PROVIDER [ double precision, delta_ij, (N_det_ref,N_det_non_ref,N_states) ] +&BEGIN_PROVIDER [ double precision, delta_ii, (N_det_ref,N_states) ] + implicit none + BEGIN_DOC + ! Dressing matrix in N_det basis + END_DOC + integer :: i,j,m + delta_ij = 0.d0 + delta_ii = 0.d0 + call mrcc_dress(N_det_ref,N_det_non_ref,N_states,delta_ij,delta_ii) + write(33,*)delta_ij + write(34,*)delta_ii +END_PROVIDER + +BEGIN_PROVIDER [ double precision, h_matrix_dressed, (N_det,N_det,N_states) ] + implicit none + BEGIN_DOC + ! Dressed H with Delta_ij + END_DOC + integer :: i, j,istate,ii,jj + do istate = 1,N_states + do j=1,N_det + do i=1,N_det + h_matrix_dressed(i,j,istate) = h_matrix_all_dets(i,j) + enddo + enddo + do ii = 1, N_det_ref + i =idx_ref(ii) + h_matrix_dressed(i,i,istate) += delta_ii(ii,istate) + do jj = 1, N_det_non_ref + j =idx_non_ref(jj) + h_matrix_dressed(i,j,istate) += delta_ij(ii,jj,istate) + h_matrix_dressed(j,i,istate) += delta_ij(ii,jj,istate) + enddo + enddo + enddo +END_PROVIDER + + + BEGIN_PROVIDER [ double precision, CI_electronic_energy_dressed, (N_states_diag) ] +&BEGIN_PROVIDER [ double precision, CI_eigenvectors_dressed, (N_det,N_states_diag) ] +&BEGIN_PROVIDER [ double precision, CI_eigenvectors_s2_dressed, (N_states_diag) ] + implicit none + BEGIN_DOC + ! Eigenvectors/values of the CI matrix + END_DOC + integer :: i,j + + do j=1,N_states_diag + do i=1,N_det + CI_eigenvectors_dressed(i,j) = psi_coef(i,j) + enddo + enddo + + if (diag_algorithm == "Davidson") then + + integer :: istate + istate = 1 + call davidson_diag_mrcc(psi_det,CI_eigenvectors_dressed,CI_electronic_energy_dressed,& + size(CI_eigenvectors_dressed,1),N_det,N_states_diag,N_int,output_determinants,istate) + + else if (diag_algorithm == "Lapack") then + + double precision, allocatable :: eigenvectors(:,:), eigenvalues(:) + allocate (eigenvectors(size(H_matrix_dressed,1),N_det)) + allocate (eigenvalues(N_det)) + call lapack_diag(eigenvalues,eigenvectors, & + H_matrix_dressed,size(H_matrix_dressed,1),N_det) + CI_electronic_energy_dressed(:) = 0.d0 + do i=1,N_det + CI_eigenvectors_dressed(i,1) = eigenvectors(i,1) + enddo + integer :: i_state + double precision :: s2 + i_state = 0 + if (s2_eig) then + do j=1,N_det + call get_s2_u0(psi_det,eigenvectors(1,j),N_det,N_det,s2) + if(dabs(s2-expected_s2).le.0.3d0)then + i_state += 1 + do i=1,N_det + CI_eigenvectors_dressed(i,i_state) = eigenvectors(i,j) + enddo + CI_electronic_energy_dressed(i_state) = eigenvalues(j) + CI_eigenvectors_s2_dressed(i_state) = s2 + endif + if (i_state.ge.N_states_diag) then + exit + endif + enddo + else + do j=1,N_states_diag + call get_s2_u0(psi_det,eigenvectors(1,j),N_det,N_det,s2) + i_state += 1 + do i=1,N_det + CI_eigenvectors_dressed(i,i_state) = eigenvectors(i,j) + enddo + CI_electronic_energy_dressed(i_state) = eigenvalues(j) + CI_eigenvectors_s2_dressed(i_state) = s2 + enddo + endif + deallocate(eigenvectors,eigenvalues) + endif + +END_PROVIDER + +BEGIN_PROVIDER [ double precision, CI_energy_dressed, (N_states_diag) ] + implicit none + BEGIN_DOC + ! N_states lowest eigenvalues of the dressed CI matrix + END_DOC + + integer :: j + character*(8) :: st + call write_time(output_determinants) + do j=1,N_states_diag + CI_energy_dressed(j) = CI_electronic_energy_dressed(j) + nuclear_repulsion + enddo + +END_PROVIDER + +subroutine diagonalize_CI_dressed + implicit none + BEGIN_DOC +! Replace the coefficients of the CI states by the coefficients of the +! eigenstates of the CI matrix + END_DOC + integer :: i,j + do j=1,N_states_diag + do i=1,N_det + psi_coef(i,j) = CI_eigenvectors_dressed(i,j) + enddo + enddo + SOFT_TOUCH psi_coef + +end diff --git a/plugins/MRCC_Utils_new/tree_dependency.png b/plugins/MRCC_Utils_new/tree_dependency.png new file mode 100644 index 00000000..500e5d43 Binary files /dev/null and b/plugins/MRCC_Utils_new/tree_dependency.png differ diff --git a/plugins/Molden/.gitignore b/plugins/Molden/.gitignore index 95cab459..dad27c9b 100644 --- a/plugins/Molden/.gitignore +++ b/plugins/Molden/.gitignore @@ -1,18 +1,18 @@ -# Automatically created by /home/giner/quantum_package/scripts/module/module_handler.py -IRPF90_temp -IRPF90_man -irpf90_entities -tags -irpf90.make -Makefile -Makefile.depend -.ninja_log +# Automatically created by $QP_ROOT/scripts/module/module_handler.py .ninja_deps -ezfio_interface.irp.f -Ezfio_files -MO_Basis -Utils +.ninja_log AO_Basis Electrons +Ezfio_files +IRPF90_man +IRPF90_temp +MO_Basis +Makefile +Makefile.depend Nuclei +Utils +ezfio_interface.irp.f +irpf90.make +irpf90_entities print_mo +tags \ No newline at end of file diff --git a/plugins/Perturbation/README.rst b/plugins/Perturbation/README.rst index 7be62489..aad453e8 100644 --- a/plugins/Perturbation/README.rst +++ b/plugins/Perturbation/README.rst @@ -90,32 +90,32 @@ Documentation routine. -`perturb_buffer_by_mono_dipole_moment_z `_ +`perturb_buffer_by_mono_dipole_moment_z `_ Applly pertubration ``dipole_moment_z`` to the buffer of determinants generated in the H_apply routine. -`perturb_buffer_by_mono_epstein_nesbet `_ +`perturb_buffer_by_mono_epstein_nesbet `_ Applly pertubration ``epstein_nesbet`` to the buffer of determinants generated in the H_apply routine. -`perturb_buffer_by_mono_epstein_nesbet_2x2 `_ +`perturb_buffer_by_mono_epstein_nesbet_2x2 `_ Applly pertubration ``epstein_nesbet_2x2`` to the buffer of determinants generated in the H_apply routine. -`perturb_buffer_by_mono_epstein_nesbet_sc2 `_ +`perturb_buffer_by_mono_epstein_nesbet_sc2 `_ Applly pertubration ``epstein_nesbet_sc2`` to the buffer of determinants generated in the H_apply routine. -`perturb_buffer_by_mono_epstein_nesbet_sc2_no_projected `_ +`perturb_buffer_by_mono_epstein_nesbet_sc2_no_projected `_ Applly pertubration ``epstein_nesbet_sc2_no_projected`` to the buffer of determinants generated in the H_apply routine. -`perturb_buffer_by_mono_epstein_nesbet_sc2_projected `_ +`perturb_buffer_by_mono_epstein_nesbet_sc2_projected `_ Applly pertubration ``epstein_nesbet_sc2_projected`` to the buffer of determinants generated in the H_apply routine. @@ -125,7 +125,7 @@ Documentation routine. -`perturb_buffer_by_mono_moller_plesset `_ +`perturb_buffer_by_mono_moller_plesset `_ Applly pertubration ``moller_plesset`` to the buffer of determinants generated in the H_apply routine. @@ -135,32 +135,32 @@ Documentation routine. -`perturb_buffer_dipole_moment_z `_ +`perturb_buffer_dipole_moment_z `_ Applly pertubration ``dipole_moment_z`` to the buffer of determinants generated in the H_apply routine. -`perturb_buffer_epstein_nesbet `_ +`perturb_buffer_epstein_nesbet `_ Applly pertubration ``epstein_nesbet`` to the buffer of determinants generated in the H_apply routine. -`perturb_buffer_epstein_nesbet_2x2 `_ +`perturb_buffer_epstein_nesbet_2x2 `_ Applly pertubration ``epstein_nesbet_2x2`` to the buffer of determinants generated in the H_apply routine. -`perturb_buffer_epstein_nesbet_sc2 `_ +`perturb_buffer_epstein_nesbet_sc2 `_ Applly pertubration ``epstein_nesbet_sc2`` to the buffer of determinants generated in the H_apply routine. -`perturb_buffer_epstein_nesbet_sc2_no_projected `_ +`perturb_buffer_epstein_nesbet_sc2_no_projected `_ Applly pertubration ``epstein_nesbet_sc2_no_projected`` to the buffer of determinants generated in the H_apply routine. -`perturb_buffer_epstein_nesbet_sc2_projected `_ +`perturb_buffer_epstein_nesbet_sc2_projected `_ Applly pertubration ``epstein_nesbet_sc2_projected`` to the buffer of determinants generated in the H_apply routine. @@ -170,7 +170,7 @@ Documentation routine. -`perturb_buffer_moller_plesset `_ +`perturb_buffer_moller_plesset `_ Applly pertubration ``moller_plesset`` to the buffer of determinants generated in the H_apply routine. diff --git a/plugins/Psiref_Utils/psi_ref.irp.f b/plugins/Psiref_Utils/psi_ref.irp.f deleted file mode 100644 index 852df2d3..00000000 --- a/plugins/Psiref_Utils/psi_ref.irp.f +++ /dev/null @@ -1,36 +0,0 @@ -use bitmasks - - BEGIN_PROVIDER [ integer(bit_kind), psi_ref, (N_int,2,psi_det_size) ] -&BEGIN_PROVIDER [ double precision, psi_ref_coef, (psi_det_size,n_states) ] -&BEGIN_PROVIDER [ integer, idx_ref, (psi_det_size) ] -&BEGIN_PROVIDER [ integer, N_det_ref ] - implicit none - BEGIN_DOC - ! Reference wave function, defined as determinants with coefficients > 0.05 - ! idx_ref gives the indice of the ref determinant in psi_det. - END_DOC - integer :: i, k, l - logical :: good - N_det_ref = 0 - do i=1,N_det - good = .False. - do l = 1, N_states - psi_ref_coef(i,l) = 0.d0 - good = good.or.(dabs(psi_coef(i,l)) > 0.05d0) - enddo - if (good) then - N_det_ref = N_det_ref+1 - do k=1,N_int - psi_ref(k,1,N_det_ref) = psi_det(k,1,i) - psi_ref(k,2,N_det_ref) = psi_det(k,2,i) - enddo - idx_ref(N_det_ref) = i - do k=1,N_states - psi_ref_coef(N_det_ref,k) = psi_coef(i,k) - enddo - endif - enddo - call write_int(output_determinants,N_det_ref, 'Number of determinants in the reference') - -END_PROVIDER - diff --git a/plugins/Psiref_Utils/psi_ref_excitations_operators.irp.f b/plugins/Psiref_Utils/psi_ref_excitations_operators.irp.f new file mode 100644 index 00000000..d1fe493e --- /dev/null +++ b/plugins/Psiref_Utils/psi_ref_excitations_operators.irp.f @@ -0,0 +1,45 @@ +use bitmasks + + BEGIN_PROVIDER [integer(bit_kind), holes_operators, (N_int,2)] +&BEGIN_PROVIDER [integer(bit_kind), particles_operators, (N_int,2)] + + BEGIN_DOC + ! holes_operators represents an array of integers where all the holes have + ! been done going from psi_ref to psi_non_ref + ! particles_operators represents an array of integers where all the particles have + ! been done going from psi_ref to psi_non_ref + END_DOC + holes_operators = 0_bit_kind + particles_operators = 0_bit_kind + implicit none + integer(bit_kind), allocatable :: key_test(:,:) + integer(bit_kind), allocatable :: holes(:,:),particles(:,:) + allocate(key_test(N_int,2)) + allocate(holes(N_int,2),particles(N_int,2)) + integer :: i,j,k + print*,'providing holes_operators and particles_operators' + do i = 1, N_det_ref + do j = 1, N_det_non_ref + do k = 1, N_int + key_test(k,1) = xor(psi_ref(k,1,i),psi_non_ref(k,1,j)) + key_test(k,2) = xor(psi_ref(k,2,i),psi_non_ref(k,2,j)) + enddo + do k = 1,N_int + holes(k,1) = iand(psi_ref(k,1,i),key_test(k,1)) + holes(k,2) = iand(psi_ref(k,2,i),key_test(k,2)) + particles(k,1) = iand(psi_non_ref(k,1,j),key_test(k,1)) + particles(k,2) = iand(psi_non_ref(k,2,j),key_test(k,2)) + enddo + do k = 1, N_int + holes_operators(k,1) = ior(holes_operators(k,1),holes(k,1)) + holes_operators(k,2) = ior(holes_operators(k,2),holes(k,2)) + particles_operators(k,1) = ior(particles_operators(k,1),particles(k,1)) + particles_operators(k,2) = ior(particles_operators(k,2),particles(k,2)) + enddo + enddo + enddo + + deallocate(key_test) + deallocate(holes,particles) + +END_PROVIDER diff --git a/scripts/generate_h_apply.py b/scripts/generate_h_apply.py index ce944864..51ef5090 100755 --- a/scripts/generate_h_apply.py +++ b/scripts/generate_h_apply.py @@ -28,6 +28,7 @@ filterhole filterparticle do_double_excitations check_double_excitation +filter_vvvv_excitation """.split() class H_apply(object): @@ -51,7 +52,7 @@ class H_apply(object): !$OMP accu,i_a,hole_tmp,particle_tmp,occ_particle_tmp, & !$OMP occ_hole_tmp,key_idx,i_b,j_b,key,N_elec_in_key_part_1,& !$OMP N_elec_in_key_hole_1,N_elec_in_key_part_2, & - !$OMP N_elec_in_key_hole_2,ia_ja_pairs) & + !$OMP N_elec_in_key_hole_2,ia_ja_pairs,key_union_hole_part) & !$OMP SHARED(key_in,N_int,elec_num_tab,mo_tot_num, & !$OMP hole_1, particl_1, hole_2, particl_2, & !$OMP elec_alpha_num,i_generator) FIRSTPRIVATE(iproc)""" @@ -126,6 +127,21 @@ class H_apply(object): self["check_double_excitation"] = """ check_double_excitation = .False. """ + + def filter_vvvv_excitation(self): + self["filter_vvvv_excitation"] = """ + key_union_hole_part = 0_bit_kind + call set_bite_to_integer(i_a,key_union_hole_part,N_int) + call set_bite_to_integer(j_a,key_union_hole_part,N_int) + call set_bite_to_integer(i_b,key_union_hole_part,N_int) + call set_bite_to_integer(j_b,key_union_hole_part,N_int) + do jtest_vvvv = 1, N_int + if(iand(key_union_hole_part(jtest_vvvv),virt_bitmask(jtest_vvvv,1).ne.key_union_hole_part(jtest_vvvv)))then + b_cycle = .False. + endif + enddo + if(b_cycle) cycle + """ def set_filter_holes(self): self["filterhole"] = """ if(iand(ibset(0_bit_kind,j),hole(k,other_spin)).eq.0_bit_kind )cycle diff --git a/src/Bitmask/README.rst b/src/Bitmask/README.rst index f8d44248..258419e8 100644 --- a/src/Bitmask/README.rst +++ b/src/Bitmask/README.rst @@ -62,7 +62,7 @@ Documentation Transform a bit string to a string for printing -`cas_bitmask `_ +`cas_bitmask `_ Bitmasks for CAS reference determinants. (N_int, alpha/beta, CAS reference) @@ -70,6 +70,10 @@ Documentation Bitmask to include all possible single excitations from Hartree-Fock +`core_bitmask `_ + Reunion of the inactive, active and virtual bitmasks + + `debug_det `_ Subroutine to print the content of a determinant in '+-' notation and hexadecimal representation. @@ -84,7 +88,27 @@ Documentation Bitmask to include all possible MOs -`generators_bitmask `_ +`generators_bitmask `_ + Bitmasks for generator determinants. + (N_int, alpha/beta, hole/particle, generator). + .br + 3rd index is : + .br + * 1 : hole for single exc + .br + * 2 : particle for single exc + .br + * 3 : hole for 1st exc of double + .br + * 4 : particle for 1st exc of double + .br + * 5 : hole for 2nd exc of double + .br + * 6 : particle for 2nd exc of double + .br + + +`generators_bitmask_restart `_ Bitmasks for generator determinants. (N_int, alpha/beta, hole/particle, generator). .br @@ -108,24 +132,36 @@ Documentation Hartree Fock bit mask -`i_bitmask_gen `_ +`i_bitmask_gen `_ Current bitmask for the generators -`inact_bitmask `_ +`inact_bitmask `_ Bitmasks for the inactive orbitals that are excited in post CAS method +`inact_virt_bitmask `_ + Reunion of the inactive and virtual bitmasks + + `is_a_two_holes_two_particles `_ Undocumented +`list_inact `_ + Undocumented + + `list_to_bitstring `_ Returns the physical string "string(N_int,2)" from the array of occupations "list(N_int*bit_kind_size,2) -`n_cas_bitmask `_ +`list_virt `_ + Undocumented + + +`n_cas_bitmask `_ Number of bitmasks for CAS @@ -133,10 +169,18 @@ Documentation Number of bitmasks for generators +`n_inact_orb `_ + Bitmasks for the inactive orbitals that are excited in post CAS method + + `n_int `_ Number of 64-bit integers needed to represent determinants as binary strings +`n_virt_orb `_ + Bitmasks for the inactive orbitals that are excited in post CAS method + + `number_of_holes `_ Undocumented @@ -165,6 +209,14 @@ Documentation Reference bit mask, used in Slater rules, chosen as Hartree-Fock bitmask -`virt_bitmask `_ +`reunion_of_bitmask `_ + Reunion of the inactive, active and virtual bitmasks + + +`unpaired_alpha_electrons `_ + Bitmask reprenting the unpaired alpha electrons in the HF_bitmask + + +`virt_bitmask `_ Bitmasks for the inactive orbitals that are excited in post CAS method diff --git a/src/Bitmask/bitmasks.irp.f b/src/Bitmask/bitmasks.irp.f index 2d044ca5..044fa18b 100644 --- a/src/Bitmask/bitmasks.irp.f +++ b/src/Bitmask/bitmasks.irp.f @@ -97,6 +97,53 @@ BEGIN_PROVIDER [ integer, N_generators_bitmask ] END_PROVIDER + + + +BEGIN_PROVIDER [ integer(bit_kind), generators_bitmask_restart, (N_int,2,6,N_generators_bitmask) ] + implicit none + BEGIN_DOC + ! Bitmasks for generator determinants. + ! (N_int, alpha/beta, hole/particle, generator). + ! + ! 3rd index is : + ! + ! * 1 : hole for single exc + ! + ! * 2 : particle for single exc + ! + ! * 3 : hole for 1st exc of double + ! + ! * 4 : particle for 1st exc of double + ! + ! * 5 : hole for 2nd exc of double + ! + ! * 6 : particle for 2nd exc of double + ! + END_DOC + logical :: exists + PROVIDE ezfio_filename + + call ezfio_has_bitmasks_generators(exists) + if (exists) then + call ezfio_get_bitmasks_generators(generators_bitmask_restart) + else + integer :: k, ispin + do k=1,N_generators_bitmask + do ispin=1,2 + generators_bitmask_restart(:,ispin,s_hole ,k) = full_ijkl_bitmask(:,d_hole1) + generators_bitmask_restart(:,ispin,s_part ,k) = full_ijkl_bitmask(:,d_part1) + generators_bitmask_restart(:,ispin,d_hole1,k) = full_ijkl_bitmask(:,d_hole1) + generators_bitmask_restart(:,ispin,d_part1,k) = full_ijkl_bitmask(:,d_part1) + generators_bitmask_restart(:,ispin,d_hole2,k) = full_ijkl_bitmask(:,d_hole2) + generators_bitmask_restart(:,ispin,d_part2,k) = full_ijkl_bitmask(:,d_part2) + enddo + enddo + endif + +END_PROVIDER + + BEGIN_PROVIDER [ integer(bit_kind), generators_bitmask, (N_int,2,6,N_generators_bitmask) ] implicit none BEGIN_DOC @@ -176,38 +223,144 @@ BEGIN_PROVIDER [ integer(bit_kind), cas_bitmask, (N_int,2,N_cas_bitmask) ] ! Bitmasks for CAS reference determinants. (N_int, alpha/beta, CAS reference) END_DOC logical :: exists - integer :: i + integer :: i,i_part,i_gen,j PROVIDE ezfio_filename call ezfio_has_bitmasks_cas(exists) if (exists) then + print*,'---------------------' + print*,'CAS BITMASK RESTART' call ezfio_get_bitmasks_cas(cas_bitmask) + print*,'---------------------' else + if(N_generators_bitmask == 1)then do i=1,N_cas_bitmask cas_bitmask(:,:,i) = iand(not(HF_bitmask(:,:)),full_ijkl_bitmask(:,:)) enddo + else + i_part = 2 + i_gen = 1 + do j = 1, N_cas_bitmask + do i = 1, N_int + cas_bitmask(i,1,j) = generators_bitmask_restart(i,1,i_part,i_gen) + cas_bitmask(i,2,j) = generators_bitmask_restart(i,2,i_part,i_gen) + enddo + enddo + endif endif END_PROVIDER BEGIN_PROVIDER [ integer(bit_kind), inact_bitmask, (N_int,2) ] &BEGIN_PROVIDER [ integer(bit_kind), virt_bitmask, (N_int,2) ] +&BEGIN_PROVIDER [ integer, n_inact_orb ] +&BEGIN_PROVIDER [ integer, n_virt_orb ] implicit none BEGIN_DOC ! Bitmasks for the inactive orbitals that are excited in post CAS method END_DOC logical :: exists - integer :: j + integer :: j,i + integer :: i_hole,i_part,i_gen PROVIDE ezfio_filename - do j = 1, N_int - inact_bitmask(j,1) = xor(generators_bitmask(j,1,1,1),cas_bitmask(j,1,1)) - inact_bitmask(j,2) = xor(generators_bitmask(j,2,1,1),cas_bitmask(j,2,1)) - virt_bitmask(j,1) = xor(generators_bitmask(j,1,2,1),cas_bitmask(j,1,1)) - virt_bitmask(j,2) = xor(generators_bitmask(j,2,2,1),cas_bitmask(j,2,1)) - enddo +!do j = 1, N_int +! inact_bitmask(j,1) = xor(generators_bitmask(j,1,1,1),cas_bitmask(j,1,1)) +! inact_bitmask(j,2) = xor(generators_bitmask(j,2,1,1),cas_bitmask(j,2,1)) +! virt_bitmask(j,1) = xor(generators_bitmask(j,1,2,1),cas_bitmask(j,1,1)) +! virt_bitmask(j,2) = xor(generators_bitmask(j,2,2,1),cas_bitmask(j,2,1)) +!enddo + n_inact_orb = 0 + n_virt_orb = 0 + if(N_generators_bitmask == 1)then + do j = 1, N_int + inact_bitmask(j,1) = xor(generators_bitmask_restart(j,1,1,1),cas_bitmask(j,1,1)) + inact_bitmask(j,2) = xor(generators_bitmask_restart(j,2,1,1),cas_bitmask(j,2,1)) + virt_bitmask(j,1) = xor(generators_bitmask_restart(j,1,2,1),cas_bitmask(j,1,1)) + virt_bitmask(j,2) = xor(generators_bitmask_restart(j,2,2,1),cas_bitmask(j,2,1)) + n_inact_orb += popcnt(inact_bitmask(j,1)) + n_virt_orb += popcnt(virt_bitmask(j,1)) + enddo + else + i_hole = 1 + i_gen = 1 + do i = 1, N_int + inact_bitmask(i,1) = generators_bitmask(i,1,i_hole,i_gen) + inact_bitmask(i,2) = generators_bitmask(i,2,i_hole,i_gen) + n_inact_orb += popcnt(inact_bitmask(i,1)) + enddo + i_part = 2 + i_gen = 3 + do i = 1, N_int + virt_bitmask(i,1) = generators_bitmask(i,1,i_part,i_gen) + virt_bitmask(i,2) = generators_bitmask(i,2,i_part,i_gen) + n_virt_orb += popcnt(virt_bitmask(i,1)) + enddo + endif END_PROVIDER + + + BEGIN_PROVIDER [ integer, list_inact, (n_inact_orb)] + &BEGIN_PROVIDER [ integer, list_virt, (n_virt_orb)] + implicit none + integer :: occ_inact(N_int*bit_kind_size) + integer :: itest,i + occ_inact = 0 + call bitstring_to_list(inact_bitmask(1,1), occ_inact(1), itest, N_int) + ASSERT(itest==n_inact_orb) + do i = 1, n_inact_orb + list_inact(i) = occ_inact(i) + enddo + + occ_inact = 0 + call bitstring_to_list(virt_bitmask(1,1), occ_inact(1), itest, N_int) + ASSERT(itest==n_virt_orb) + do i = 1, n_virt_orb + list_virt(i) = occ_inact(i) + enddo + + END_PROVIDER + + BEGIN_PROVIDER [ integer(bit_kind), reunion_of_bitmask, (N_int,2)] + implicit none + BEGIN_DOC + ! Reunion of the inactive, active and virtual bitmasks + END_DOC + integer :: i,j + do i = 1, N_int + reunion_of_bitmask(i,1) = ior(ior(cas_bitmask(i,1,1),inact_bitmask(i,1)),virt_bitmask(i,1)) + reunion_of_bitmask(i,2) = ior(ior(cas_bitmask(i,2,1),inact_bitmask(i,2)),virt_bitmask(i,2)) + enddo + END_PROVIDER + + + BEGIN_PROVIDER [ integer(bit_kind), inact_virt_bitmask, (N_int,2)] + implicit none + BEGIN_DOC + ! Reunion of the inactive and virtual bitmasks + END_DOC + integer :: i,j + do i = 1, N_int + inact_virt_bitmask(i,1) = ior(inact_bitmask(i,1),virt_bitmask(i,1)) + inact_virt_bitmask(i,2) = ior(inact_bitmask(i,2),virt_bitmask(i,2)) + enddo + END_PROVIDER + + BEGIN_PROVIDER [ integer(bit_kind), core_bitmask, (N_int,2)] + implicit none + BEGIN_DOC + ! Reunion of the inactive, active and virtual bitmasks + END_DOC + integer :: i,j + do i = 1, N_int + core_bitmask(i,1) = iand(ref_bitmask(i,1),reunion_of_bitmask(i,1)) + core_bitmask(i,2) = iand(ref_bitmask(i,2),reunion_of_bitmask(i,2)) + enddo + END_PROVIDER + + + BEGIN_PROVIDER [ integer, i_bitmask_gen ] implicit none BEGIN_DOC @@ -217,3 +370,14 @@ BEGIN_PROVIDER [ integer, i_bitmask_gen ] END_PROVIDER + BEGIN_PROVIDER [ integer(bit_kind), unpaired_alpha_electrons, (N_int)] + implicit none + BEGIN_DOC + ! Bitmask reprenting the unpaired alpha electrons in the HF_bitmask + END_DOC + integer :: i + unpaired_alpha_electrons = 0_bit_kind + do i = 1, N_int + unpaired_alpha_electrons(i) = xor(HF_bitmask(i,1),HF_bitmask(i,2)) + enddo + END_PROVIDER diff --git a/src/Determinants/.gitignore b/src/Determinants/.gitignore index 516d3a70..6190b425 100644 --- a/src/Determinants/.gitignore +++ b/src/Determinants/.gitignore @@ -16,13 +16,17 @@ Nuclei Pseudo Utils det_svd +diag_and_save ezfio_interface.irp.f guess_doublet guess_singlet guess_triplet irpf90.make irpf90_entities +print_cas_energy +print_s2 program_initial_determinants save_natorb +save_wf_only_monos tags truncate_wf \ No newline at end of file diff --git a/src/Determinants/H_apply.template.f b/src/Determinants/H_apply.template.f index a9a282ae..3a05ee0d 100644 --- a/src/Determinants/H_apply.template.f +++ b/src/Determinants/H_apply.template.f @@ -18,6 +18,7 @@ subroutine $subroutine_diexc(key_in, hole_1,particl_1, hole_2, particl_2, i_gene integer(bit_kind), allocatable :: hole_save(:,:) integer(bit_kind), allocatable :: key(:,:),hole(:,:), particle(:,:) integer(bit_kind), allocatable :: hole_tmp(:,:), particle_tmp(:,:) + integer(bit_kind), allocatable :: key_union_hole_part(:) integer :: ii,i,jj,j,k,ispin,l integer, allocatable :: occ_particle(:,:), occ_hole(:,:) integer, allocatable :: occ_particle_tmp(:,:), occ_hole_tmp(:,:) @@ -31,6 +32,7 @@ subroutine $subroutine_diexc(key_in, hole_1,particl_1, hole_2, particl_2, i_gene integer, allocatable :: ib_jb_pairs(:,:) double precision :: diag_H_mat_elem integer :: iproc + integer :: jtest_vvvv integer(omp_lock_kind), save :: lck, ifirst=0 if (ifirst == 0) then !$ call omp_init_lock(lck) @@ -38,6 +40,7 @@ subroutine $subroutine_diexc(key_in, hole_1,particl_1, hole_2, particl_2, i_gene endif logical :: check_double_excitation + logical :: b_cycle check_double_excitation = .True. iproc = iproc_in @@ -50,7 +53,7 @@ subroutine $subroutine_diexc(key_in, hole_1,particl_1, hole_2, particl_2, i_gene key(N_int,2),hole(N_int,2), particle(N_int,2), hole_tmp(N_int,2),& particle_tmp(N_int,2), occ_particle(N_int*bit_kind_size,2), & occ_hole(N_int*bit_kind_size,2), occ_particle_tmp(N_int*bit_kind_size,2),& - occ_hole_tmp(N_int*bit_kind_size,2)) + occ_hole_tmp(N_int*bit_kind_size,2),key_union_hole_part(N_int)) $init_thread @@ -151,6 +154,7 @@ subroutine $subroutine_diexc(key_in, hole_1,particl_1, hole_2, particl_2, i_gene ASSERT (j_b > 0) ASSERT (j_b <= mo_tot_num) if (array_pairs(i_b,j_b)) then + $filter_vvvv_excitation i+= 1 ib_jb_pairs(1,i) = i_b ib_jb_pairs(2,i) = j_b @@ -200,6 +204,7 @@ subroutine $subroutine_diexc(key_in, hole_1,particl_1, hole_2, particl_2, i_gene ASSERT (j_b <= mo_tot_num) if (j_b <= j_a) cycle if (array_pairs(i_b,j_b)) then + $filter_vvvv_excitation i+= 1 ib_jb_pairs(1,i) = i_b ib_jb_pairs(2,i) = j_b @@ -245,7 +250,7 @@ subroutine $subroutine_diexc(key_in, hole_1,particl_1, hole_2, particl_2, i_gene key,hole, particle, hole_tmp,& particle_tmp, occ_particle, & occ_hole, occ_particle_tmp,& - occ_hole_tmp,array_pairs) + occ_hole_tmp,array_pairs,key_union_hole_part) $omp_end_parallel $finalization end @@ -278,6 +283,7 @@ subroutine $subroutine_monoexc(key_in, hole_1,particl_1,i_generator,iproc_in $pa integer :: N_elec_in_key_hole_1(2),N_elec_in_key_part_1(2) integer :: N_elec_in_key_hole_2(2),N_elec_in_key_part_2(2) logical :: is_a_two_holes_two_particles + integer(bit_kind), allocatable :: key_union_hole_part(:) integer, allocatable :: ia_ja_pairs(:,:,:) logical, allocatable :: array_pairs(:,:) @@ -305,7 +311,7 @@ subroutine $subroutine_monoexc(key_in, hole_1,particl_1,i_generator,iproc_in $pa key(N_int,2),hole(N_int,2), particle(N_int,2), hole_tmp(N_int,2),& particle_tmp(N_int,2), occ_particle(N_int*bit_kind_size,2), & occ_hole(N_int*bit_kind_size,2), occ_particle_tmp(N_int*bit_kind_size,2),& - occ_hole_tmp(N_int*bit_kind_size,2)) + occ_hole_tmp(N_int*bit_kind_size,2),key_union_hole_part(N_int)) $init_thread !!!! First couple hole particle do j = 1, N_int @@ -376,7 +382,7 @@ subroutine $subroutine_monoexc(key_in, hole_1,particl_1,i_generator,iproc_in $pa key,hole, particle, hole_tmp,& particle_tmp, occ_particle, & occ_hole, occ_particle_tmp,& - occ_hole_tmp) + occ_hole_tmp,key_union_hole_part) $omp_end_parallel $finalization diff --git a/src/Determinants/README.rst b/src/Determinants/README.rst index 823cdd39..9529a268 100644 --- a/src/Determinants/README.rst +++ b/src/Determinants/README.rst @@ -221,7 +221,7 @@ Documentation Build connection proxy between determinants -`det_num `_ +`det_num `_ det_num @@ -621,6 +621,10 @@ Documentation Undocumented +`print_psi_cas `_ + Undocumented + + `psi_average_norm_contrib `_ Contribution of determinants to the state-averaged density @@ -831,7 +835,11 @@ Documentation Undocumented -`s2_eig `_ +`routine_count_mono_save_mono `_ + Undocumented + + +`s2_eig `_ Force the wave function to be an eigenfunction of S^2 @@ -863,10 +871,22 @@ Documentation Save the wave function into the EZFIO file +`save_wavefunction_specified `_ + Save the wave function into the EZFIO file + + `save_wavefunction_unsorted `_ Save the wave function into the EZFIO file +`save_wf `_ + Undocumented + + +`set_bite_to_integer `_ + Undocumented + + `set_natural_mos `_ Set natural orbitals, obtained by diagonalization of the one-body density matrix in the MO basis diff --git a/src/Determinants/create_excitations.irp.f b/src/Determinants/create_excitations.irp.f index a33525c7..a2acc8df 100644 --- a/src/Determinants/create_excitations.irp.f +++ b/src/Determinants/create_excitations.irp.f @@ -34,3 +34,14 @@ subroutine do_mono_excitation(key_in,i_hole,i_particle,ispin,i_ok) i_ok = -1 endif end + +subroutine set_bite_to_integer(i_physical,key,Nint) + use bitmasks + implicit none + integer, intent(in) :: i_physical,Nint + integer(bit_kind), intent(inout) :: key(Nint) + integer :: k,j,i + k = ishft(i_physical-1,-bit_kind_shift)+1 + j = i_physical-ishft(k-1,bit_kind_shift)-1 + key(k) = ibset(key(k),j) +end diff --git a/src/Determinants/davidson.irp.f b/src/Determinants/davidson.irp.f index c3167a9e..bd44284d 100644 --- a/src/Determinants/davidson.irp.f +++ b/src/Determinants/davidson.irp.f @@ -12,7 +12,7 @@ BEGIN_PROVIDER [ integer, davidson_sze_max ] ! Max number of Davidson sizes END_DOC ASSERT (davidson_sze_max <= davidson_iter_max) - davidson_sze_max = 8*N_states_diag + davidson_sze_max = min(8,2*N_states_diag) END_PROVIDER subroutine davidson_diag(dets_in,u_in,energies,dim_in,sze,N_st,Nint,iunit) diff --git a/src/Determinants/determinants.irp.f b/src/Determinants/determinants.irp.f index 6834a745..d1c36163 100644 --- a/src/Determinants/determinants.irp.f +++ b/src/Determinants/determinants.irp.f @@ -749,3 +749,91 @@ end +subroutine save_wavefunction_specified(ndet,nstates,psidet,psicoef,ndetsave,index_det_save) + implicit none + BEGIN_DOC +! Save the wave function into the EZFIO file + END_DOC + use bitmasks + integer, intent(in) :: ndet,nstates + integer(bit_kind), intent(in) :: psidet(N_int,2,ndet) + double precision, intent(in) :: psicoef(ndet,nstates) + integer, intent(in) :: index_det_save(ndet) + integer, intent(in) :: ndetsave + integer*8, allocatable :: psi_det_save(:,:,:) + double precision, allocatable :: psi_coef_save(:,:) + integer*8 :: det_8(100) + integer(bit_kind) :: det_bk((100*8)/bit_kind) + integer :: N_int2 + equivalence (det_8, det_bk) + + integer :: i,k + + PROVIDE progress_bar + call start_progress(7,'Saving wfunction',0.d0) + + progress_bar(1) = 1 + progress_value = dble(progress_bar(1)) + call ezfio_set_determinants_N_int(N_int) + progress_bar(1) = 2 + progress_value = dble(progress_bar(1)) + call ezfio_set_determinants_bit_kind(bit_kind) + progress_bar(1) = 3 + progress_value = dble(progress_bar(1)) + call ezfio_set_determinants_N_det(ndetsave) + progress_bar(1) = 4 + progress_value = dble(progress_bar(1)) + call ezfio_set_determinants_n_states(nstates) + progress_bar(1) = 5 + progress_value = dble(progress_bar(1)) + call ezfio_set_determinants_mo_label(mo_label) + + progress_bar(1) = 6 + progress_value = dble(progress_bar(1)) + + N_int2 = (N_int*bit_kind)/8 + allocate (psi_det_save(N_int2,2,ndetsave)) + do i=1,ndetsave + do k=1,N_int + det_bk(k) = psidet(k,1,index_det_save(i)) + enddo + do k=1,N_int2 + psi_det_save(k,1,i) = det_8(k) + enddo + do k=1,N_int + det_bk(k) = psidet(k,2,index_det_save(i)) + enddo + do k=1,N_int2 + psi_det_save(k,2,i) = det_8(k) + enddo + enddo + call ezfio_set_determinants_psi_det(psi_det_save) + deallocate (psi_det_save) + + progress_bar(1) = 7 + progress_value = dble(progress_bar(1)) + allocate (psi_coef_save(ndetsave,nstates)) + double precision :: accu_norm(nstates) + accu_norm = 0.d0 + do k=1,nstates + do i=1,ndetsave + accu_norm(k) = accu_norm(k) + psicoef(index_det_save(i),k) * psicoef(index_det_save(i),k) + psi_coef_save(i,k) = psicoef(index_det_save(i),k) + enddo + enddo + do k = 1, nstates + accu_norm(k) = 1.d0/dsqrt(accu_norm(k)) + enddo + do k=1,nstates + do i=1,ndetsave + psi_coef_save(i,k) = psi_coef_save(i,k) * accu_norm(k) + enddo + enddo + + call ezfio_set_determinants_psi_coef(psi_coef_save) + call write_int(output_determinants,ndet,'Saved determinants') + call stop_progress + deallocate (psi_coef_save) +end + + diff --git a/src/Determinants/slater_rules.irp.f b/src/Determinants/slater_rules.irp.f index a8b394d9..faf2e704 100644 --- a/src/Determinants/slater_rules.irp.f +++ b/src/Determinants/slater_rules.irp.f @@ -1095,13 +1095,9 @@ subroutine H_u_0(v_0,u_0,H_jj,n,keys_tmp,Nint) !$OMP PARALLEL DEFAULT(NONE) & !$OMP PRIVATE(i,hij,j,k,idx,jj,vt) & !$OMP SHARED(n,H_jj,u_0,keys_tmp,Nint,v_0,davidson_threshold) - !$OMP DO SCHEDULE(static) - do i=1,n - v_0(i) = H_jj(i) * u_0(i) - enddo - !$OMP END DO allocate(idx(0:n), vt(n)) Vt = 0.d0 + v_0 = 0.d0 !$OMP DO SCHEDULE(guided) do i=1,n idx(0) = i @@ -1123,6 +1119,9 @@ subroutine H_u_0(v_0,u_0,H_jj,n,keys_tmp,Nint) !$OMP END CRITICAL deallocate(idx,vt) !$OMP END PARALLEL + do i=1,n + v_0(i) += H_jj(i) * u_0(i) + enddo end diff --git a/src/Ezfio_files/README.rst b/src/Ezfio_files/README.rst new file mode 100644 index 00000000..f880b144 --- /dev/null +++ b/src/Ezfio_files/README.rst @@ -0,0 +1,164 @@ +================== +Ezfio_files Module +================== + +This modules essentially contains the name of the EZFIO directory in the +``ezfio_filename`` variable. This is read as the first argument of the +command-line, or as the ``QP_INPUT`` environment variable. +Documentation +============= + +.. Do not edit this section. It was auto-generated from the +.. by the `update_README.py` script. + +`ezfio_filename `_ + Name of EZFIO file. It is obtained from the QPACKAGE_INPUT environment + variable if it is set, or as the 1st argument of the command line. + + +`getunitandopen `_ + :f: + file name + .br + :mode: + 'R' : READ, UNFORMATTED + 'W' : WRITE, UNFORMATTED + 'r' : READ, FORMATTED + 'w' : WRITE, FORMATTED + 'a' : APPEND, FORMATTED + 'x' : READ/WRITE, FORMATTED + .br + + +`output_ao_basis `_ + Output file for AO_Basis + + +`output_bitmask `_ + Output file for Bitmask + + +`output_cas_sd `_ + Output file for CAS_SD + + +`output_cisd `_ + Output file for CISD + + +`output_cisd_sc2_selected `_ + Output file for CISD_SC2_selected + + +`output_cisd_selected `_ + Output file for CISD_selected + + +`output_cpu_time_0 `_ + Initial CPU and wall times when printing in the output files + + +`output_ddci_selected `_ + Output file for DDCI_selected + + +`output_determinants `_ + Output file for Determinants + + +`output_electrons `_ + Output file for Electrons + + +`output_ezfio_files `_ + Output file for Ezfio_files + + +`output_full_ci `_ + Output file for Full_CI + + +`output_generators_cas `_ + Output file for Generators_CAS + + +`output_generators_full `_ + Output file for Generators_full + + +`output_hartree_fock `_ + Output file for Hartree_Fock + + +`output_integrals_bielec `_ + Output file for Integrals_Bielec + + +`output_integrals_monoelec `_ + Output file for Integrals_Monoelec + + +`output_loc_cele `_ + Output file for loc_cele + + +`output_mo_basis `_ + Output file for MO_Basis + + +`output_moguess `_ + Output file for MOGuess + + +`output_molden `_ + Output file for Molden + + +`output_nuclei `_ + Output file for Nuclei + + +`output_perturbation `_ + Output file for Perturbation + + +`output_properties `_ + Output file for Properties + + +`output_pseudo `_ + Output file for Pseudo + + +`output_selectors_full `_ + Output file for Selectors_full + + +`output_singlerefmethod `_ + Output file for SingleRefMethod + + +`output_utils `_ + Output file for Utils + + +`output_wall_time_0 `_ + Initial CPU and wall times when printing in the output files + + +`write_bool `_ + Write an logical value in output + + +`write_double `_ + Write a double precision value in output + + +`write_int `_ + Write an integer value in output + + +`write_time `_ + Write a time stamp in the output for chronological reconstruction + + diff --git a/src/Nuclei/README.rst b/src/Nuclei/README.rst index 9f0b15d9..63e6c6ae 100644 --- a/src/Nuclei/README.rst +++ b/src/Nuclei/README.rst @@ -27,7 +27,7 @@ Documentation Array of the name of element, sorted by nuclear charge (integer) -`nucl_charge `_ +`nucl_charge `_ Nuclear charges @@ -69,11 +69,11 @@ Documentation nucl_dist_vec : Nucleus-nucleus distances vectors -`nucl_label `_ +`nucl_label `_ Nuclear labels -`nucl_num `_ +`nucl_num `_ Number of nuclei diff --git a/src/Pseudo/README.rst b/src/Pseudo/README.rst index 84a555da..5aa338ea 100644 --- a/src/Pseudo/README.rst +++ b/src/Pseudo/README.rst @@ -26,7 +26,7 @@ Documentation test -`pseudo_dz_kl `_ +`pseudo_dz_kl `_ test @@ -42,7 +42,7 @@ Documentation test -`pseudo_kmax `_ +`pseudo_kmax `_ test @@ -50,7 +50,7 @@ Documentation test -`pseudo_n_k `_ +`pseudo_n_k `_ test