From e9bd3ee0967a298e82a785151a78e455d0230c38 Mon Sep 17 00:00:00 2001 From: Anthony Scemama Date: Fri, 30 Jul 2021 00:57:03 +0200 Subject: [PATCH 1/5] Fixed dressing --- devel/dmc_dress/dmc_dress.irp.f | 13 +++++++++++++ devel/dmc_dress/dressing_vector.irp.f | 9 +++++---- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/devel/dmc_dress/dmc_dress.irp.f b/devel/dmc_dress/dmc_dress.irp.f index f79b98b..07e1aa4 100644 --- a/devel/dmc_dress/dmc_dress.irp.f +++ b/devel/dmc_dress/dmc_dress.irp.f @@ -7,13 +7,26 @@ program diagonalize_h END_DOC read_wf = .True. touch read_wf + call pre call routine call save_wavefunction_general(N_det,N_states,psi_det_sorted,size(psi_coef_sorted,1),psi_coef_sorted) end +subroutine pre + implicit none + double precision, allocatable :: left(:,:), right(:,:), tmp(:,:), res(:,:) + allocate (left(1,1:N_det), right(1:N_det,1), tmp(1:N_det,1), res(1,1)) + left(1,1:N_det) = psi_coef(1:N_det,1) + right(1:N_det,1) = psi_coef(1:N_det,1) + + tmp(1:N_det,1:1) = matmul(h_matrix_dressed(1:N_det,1:N_det), right(1:N_det,1:1)) + res(1:1,1:1) = matmul(left(1:1,1:N_det), tmp(1:N_det,1:1)) + print *, 'E_in = ', res(1,1) +end subroutine routine implicit none psi_coef(1:N_det,1) = ci_eigenvectors_dressed(1:N_det,1) print*,'N_det = ',N_det + print *, 'E = ', ci_energy_dressed(1) + nuclear_repulsion SOFT_TOUCH psi_coef end diff --git a/devel/dmc_dress/dressing_vector.irp.f b/devel/dmc_dress/dressing_vector.irp.f index 9f79996..c6db764 100644 --- a/devel/dmc_dress/dressing_vector.irp.f +++ b/devel/dmc_dress/dressing_vector.irp.f @@ -3,21 +3,22 @@ implicit none BEGIN_DOC ! \Delta_{state-specific}. \Psi + ! Diagonal element is divided by 2 because Delta = D + D^t END_DOC integer :: i,ii,k,j, l double precision :: f, tmp - double precision, external :: u_dot_v - logical, external :: detEq dressing_column_h(:,:) = 0.d0 dressing_column_s(:,:) = 0.d0 l = dressed_column_idx(1) do j = 1, n_det - dressing_column_h(j,1) = 0.5d0*dmc_delta_h(j) - dressing_column_h(l,1) -= 0.5d0 * psi_coef(j,1) * dmc_delta_h(j) /psi_coef(l,1) + dressing_column_h(j,1) = dmc_delta_h(j) + dressing_column_h(l,1) -= psi_coef(j,1) * dmc_delta_h(j) /psi_coef(l,1) enddo + dressing_column_h(l,1) = dressing_column_h(l,1) * 0.5d0 + END_PROVIDER From 47b41fd82d9b40c2fd57a9e04caf3b2263e03564 Mon Sep 17 00:00:00 2001 From: Anthony Scemama Date: Sat, 31 Jul 2021 01:17:07 +0200 Subject: [PATCH 2/5] Dressing OK --- devel/dmc_dress/dmc_dress.irp.f | 5 +++-- devel/dmc_dress/dressing_vector.irp.f | 10 +++++++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/devel/dmc_dress/dmc_dress.irp.f b/devel/dmc_dress/dmc_dress.irp.f index 07e1aa4..4302499 100644 --- a/devel/dmc_dress/dmc_dress.irp.f +++ b/devel/dmc_dress/dmc_dress.irp.f @@ -1,4 +1,4 @@ -program diagonalize_h +program dmc_dress implicit none BEGIN_DOC ! Program that extracts the lowest states of the Hamiltonian dressed by the QMC @@ -9,7 +9,7 @@ program diagonalize_h touch read_wf call pre call routine - call save_wavefunction_general(N_det,N_states,psi_det_sorted,size(psi_coef_sorted,1),psi_coef_sorted) +! call save_wavefunction_general(N_det,N_states,psi_det_sorted,size(psi_coef_sorted,1),psi_coef_sorted) end subroutine pre @@ -22,6 +22,7 @@ subroutine pre tmp(1:N_det,1:1) = matmul(h_matrix_dressed(1:N_det,1:N_det), right(1:N_det,1:1)) res(1:1,1:1) = matmul(left(1:1,1:N_det), tmp(1:N_det,1:1)) print *, 'E_in = ', res(1,1) + print *, 'HPsi/c0 = ', tmp(1,1)/psi_coef(1,1) end subroutine routine implicit none diff --git a/devel/dmc_dress/dressing_vector.irp.f b/devel/dmc_dress/dressing_vector.irp.f index c6db764..b6f8641 100644 --- a/devel/dmc_dress/dressing_vector.irp.f +++ b/devel/dmc_dress/dressing_vector.irp.f @@ -14,10 +14,14 @@ l = dressed_column_idx(1) do j = 1, n_det - dressing_column_h(j,1) = dmc_delta_h(j) - dressing_column_h(l,1) -= psi_coef(j,1) * dmc_delta_h(j) /psi_coef(l,1) + if (j == l) cycle + dressing_column_h(j,1) = dmc_delta_h(j) + dressing_column_h(l,1) -= psi_coef(j,1) * dmc_delta_h(j) / psi_coef(l,1) enddo - dressing_column_h(l,1) = dressing_column_h(l,1) * 0.5d0 + dressing_column_h(l,1) += dmc_delta_h(l) + dressing_column_h(l,1) *= 0.5d0 + + print *, 'COUCOU XXX' END_PROVIDER From 6d5ec01e0172ab71282adf0b329ead1ce7f21a55 Mon Sep 17 00:00:00 2001 From: Anthony Scemama Date: Sat, 31 Jul 2021 02:41:34 +0200 Subject: [PATCH 3/5] dmc_dress OK --- devel/dmc_dress/dmc_dress.irp.f | 5 ++++- devel/dmc_dress/dressing_vector.irp.f | 14 +++++++++----- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/devel/dmc_dress/dmc_dress.irp.f b/devel/dmc_dress/dmc_dress.irp.f index 4302499..e3c413a 100644 --- a/devel/dmc_dress/dmc_dress.irp.f +++ b/devel/dmc_dress/dmc_dress.irp.f @@ -15,6 +15,7 @@ end subroutine pre implicit none double precision, allocatable :: left(:,:), right(:,:), tmp(:,:), res(:,:) + integer :: i allocate (left(1,1:N_det), right(1:N_det,1), tmp(1:N_det,1), res(1,1)) left(1,1:N_det) = psi_coef(1:N_det,1) right(1:N_det,1) = psi_coef(1:N_det,1) @@ -22,7 +23,9 @@ subroutine pre tmp(1:N_det,1:1) = matmul(h_matrix_dressed(1:N_det,1:N_det), right(1:N_det,1:1)) res(1:1,1:1) = matmul(left(1:1,1:N_det), tmp(1:N_det,1:1)) print *, 'E_in = ', res(1,1) - print *, 'HPsi/c0 = ', tmp(1,1)/psi_coef(1,1) + do i=1,N_det + print *, 'HPsi/c0 = ', tmp(i,1)/psi_coef(i,1) + enddo end subroutine routine implicit none diff --git a/devel/dmc_dress/dressing_vector.irp.f b/devel/dmc_dress/dressing_vector.irp.f index b6f8641..71c59c8 100644 --- a/devel/dmc_dress/dressing_vector.irp.f +++ b/devel/dmc_dress/dressing_vector.irp.f @@ -8,6 +8,12 @@ integer :: i,ii,k,j, l double precision :: f, tmp + double precision, allocatable :: delta(:) + + allocate(delta(N_det)) + delta(1:N_det) = dmc_delta_h(1:N_det) + + call dset_order(delta,psi_bilinear_matrix_order_reverse,N_det) dressing_column_h(:,:) = 0.d0 dressing_column_s(:,:) = 0.d0 @@ -15,14 +21,12 @@ l = dressed_column_idx(1) do j = 1, n_det if (j == l) cycle - dressing_column_h(j,1) = dmc_delta_h(j) - dressing_column_h(l,1) -= psi_coef(j,1) * dmc_delta_h(j) / psi_coef(l,1) + dressing_column_h(j,1) = delta(j) + dressing_column_h(l,1) -= psi_coef(j,1) * delta(j) / psi_coef(l,1) enddo - dressing_column_h(l,1) += dmc_delta_h(l) + dressing_column_h(l,1) += delta(l) dressing_column_h(l,1) *= 0.5d0 - print *, 'COUCOU XXX' - END_PROVIDER From ef9028dcd7c48d7338fe4a56eafb84b929d75d3f Mon Sep 17 00:00:00 2001 From: Anthony Scemama Date: Sat, 31 Jul 2021 03:18:28 +0200 Subject: [PATCH 4/5] diag saves wf --- devel/dmc_dress/dmc_dress.irp.f | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/devel/dmc_dress/dmc_dress.irp.f b/devel/dmc_dress/dmc_dress.irp.f index e3c413a..72a78b4 100644 --- a/devel/dmc_dress/dmc_dress.irp.f +++ b/devel/dmc_dress/dmc_dress.irp.f @@ -9,7 +9,7 @@ program dmc_dress touch read_wf call pre call routine -! call save_wavefunction_general(N_det,N_states,psi_det_sorted,size(psi_coef_sorted,1),psi_coef_sorted) + call save_wavefunction_general(N_det,N_states,psi_det_sorted,size(psi_coef_sorted,1),psi_coef_sorted) end subroutine pre From e153c88f62235e6f67ea3b779a368f0491c69cc5 Mon Sep 17 00:00:00 2001 From: Anthony Scemama Date: Sat, 31 Jul 2021 03:19:16 +0200 Subject: [PATCH 5/5] Add dress.py --- devel/dmc_dress/dress.py | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100755 devel/dmc_dress/dress.py diff --git a/devel/dmc_dress/dress.py b/devel/dmc_dress/dress.py new file mode 100755 index 0000000..53f585b --- /dev/null +++ b/devel/dmc_dress/dress.py @@ -0,0 +1,40 @@ +#!/usr/bin/env python + +import numpy as np +import subprocess +import sys +import os + +QP_PATH=os.environ["QP_ROOT"]+"/external/ezfio/Python/" + +sys.path.insert(0,QP_PATH) + +from ezfio import ezfio + +def read_hamiltonian(inp): + text = subprocess.run(["qmcchem", "result", inp], capture_output=True).stdout + inside = None + h = [] + s = [] + norm = None + for line in text.splitlines(): + line = str(line) + print (line) + if "Psi_norm :" in line: + norm = float(line.split()[3]) + if "]" in line: + inside = None + if inside == "H": + data = line.split() + h.append(float(data[3])) + elif "Ci_dress" in line: + inside = "H" + h = np.array(h)/norm + + return h + + +h = read_hamiltonian(sys.argv[1]) +ezfio.set_file(sys.argv[1]) +ezfio.set_dmc_dress_dmc_delta_h(h) +print(h)