From 7a031b3356dcd1c50be1af774044d4ab28b83868 Mon Sep 17 00:00:00 2001 From: Abdallah Ammar Date: Sat, 31 Jul 2021 14:07:03 +0200 Subject: [PATCH 01/16] post QMC py --- devel/dmc_dress/dress_SVD.py | 174 +++++++++++++ devel/svdwf/SVD.slurm | 24 ++ devel/svdwf/cr2_work/LOBD_VMC.py | 261 ++++++++++++++++++++ devel/svdwf/cr2_work/LOBD_compactVMC.py | 225 +++++++++++++++++ devel/svdwf/cr2_work/LOBD_postVMC.py | 175 +++++++++++++ devel/svdwf/cr2_work/LOBD_postcompactSVD.py | 173 +++++++++++++ devel/svdwf/qmcchemRun.slurm | 31 +++ devel/svdwf/qpRun.slurm | 35 +++ devel/svdwf/run_py.slurm | 26 ++ 9 files changed, 1124 insertions(+) create mode 100755 devel/dmc_dress/dress_SVD.py create mode 100644 devel/svdwf/SVD.slurm create mode 100644 devel/svdwf/cr2_work/LOBD_VMC.py create mode 100644 devel/svdwf/cr2_work/LOBD_compactVMC.py create mode 100644 devel/svdwf/cr2_work/LOBD_postVMC.py create mode 100644 devel/svdwf/cr2_work/LOBD_postcompactSVD.py create mode 100644 devel/svdwf/qmcchemRun.slurm create mode 100644 devel/svdwf/qpRun.slurm create mode 100644 devel/svdwf/run_py.slurm diff --git a/devel/dmc_dress/dress_SVD.py b/devel/dmc_dress/dress_SVD.py new file mode 100755 index 0000000..0e52d38 --- /dev/null +++ b/devel/dmc_dress/dress_SVD.py @@ -0,0 +1,174 @@ +#!/usr/bin/env python + +import numpy as np +import subprocess +import sys, os +import time +from datetime import datetime + +QP_PATH=os.environ["QP_ROOT"]+"/external/ezfio/Python/" +sys.path.insert(0,QP_PATH) + +from ezfio import ezfio + + +#____________________________________________________________________________________ +# +def get_energy(): + energy_buffer = subprocess.check_output( + ['qmcchem', 'result', '-e', 'e_loc', EZFIO_file] + , encoding='UTF-8') + + if energy_buffer.strip() != "": + energy_buffer = energy_buffer.splitlines()[-1] + _, energy, error = [float(x) for x in energy_buffer.split()] + return energy, error + else: + return None, None +#____________________________________________________________________________________ + + + +#____________________________________________________________________________________ +# +def read_scalar(scalar): + + scal_txt = scalar + ' : ' + beg_read = results.find(scal_txt) + len(scal_txt) + scal_buf = results[beg_read:beg_read+100].split('\n')[0].split() + + scal_val , scal_err = float( scal_buf[0] ) , float( scal_buf[2] ) + + return(scal_val,scal_err) +#____________________________________________________________________________________ + + + + +#____________________________________________________________________________________ +# +def read_ci_dress_svd(): + + Ci_dress_svd_val = np.zeros((n_svd)) + Ci_dress_svd_err = np.zeros((n_svd)) + + beg_read = results.find('Ci_dress_svd : [ ') + len( 'Ci_dress_svd : [ ' ) + end_read = len(results) + vect_buf = results[beg_read:end_read] + vect_buf = vect_buf.split( '\n' ) + + for iline in range(1, n_svd+1): + line = vect_buf[iline].split() + + # check + indc = int( line[0] ) + if( indc != iline ): + print(' Error in reading Ci_dress_svd') + print(' indc = {}'.format(indc) ) + print(' iline = {}'.format(iline) ) + break + + else: + Ci_dress_svd_val[indc-1] = float( line[2] ) + Ci_dress_svd_err[indc-1] = float( line[4] ) + # !!! + # !!! + # !!! + + return(Ci_dress_svd_val,Ci_dress_svd_err) +#____________________________________________________________________________________ + + +#____________________________________________________________________________________ +# +def get_ci_dress(): + + U_svd = np.array(ezfio.get_spindeterminants_psi_svd_alpha()) + V_svd = np.array(ezfio.get_spindeterminants_psi_svd_beta()) + U_svd = U_svd[0,:,:].T + V_svd = V_svd[0,:,:].T + + ci_dress_mat_val = np.dot(U_svd,np.dot(np.diagflat(Ci_dress_svd_val),V_svd.T)) + ci_dress_mat_err = np.dot(U_svd,np.dot(np.diagflat(Ci_dress_svd_err),V_svd.T)) + print(ci_dress_mat_val.shape) + + n_det = ezfio.get_spindeterminants_n_det() + i_row = np.array(ezfio.get_spindeterminants_psi_coef_matrix_rows()) + j_col = np.array(ezfio.get_spindeterminants_psi_coef_matrix_columns()) + + Ci_dress_val = np.zeros((n_det)) + Ci_dress_err = np.zeros((n_det)) + for k in range(n_det): + i = i_row[k] - 1 + j = j_col[k] - 1 + Ci_dress_val[k] = ci_dress_mat_val[i,j] + Ci_dress_err[k] = ci_dress_mat_err[i,j] + + Ci_dress_val = Ci_dress_val / psi_norm + Ci_dress_err = Ci_dress_err / psi_norm + + return(Ci_dress_val,Ci_dress_err) +#____________________________________________________________________________________ + + + + +#____________________________________________________________________________________ +# +def save_to_file(v_val,v_err, name_f): + + with open(name_f, 'a') as ff: + for i in range(len(v_val)): + ff.write(' {} {} {}\n'.format(i, v_val[i], v_err[i])) +#____________________________________________________________________________________ + + + +if __name__ == '__main__': + t0 = time.time() + + # _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ + # + #EZFIO_file = sys.argv[1] + EZFIO_file = "/home/aammar/qp2/src/svdwf/cr2_work/cr2_1p6_dress" + # _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ + + ezfio.set_file(EZFIO_file) + + n_svd = ezfio.get_spindeterminants_n_svd_coefs() + + print(" ") + print(" Today's date:", datetime.now() ) + print(" EZFIO file = {}".format(EZFIO_file)) + print(" n_svd = {}\n".format(n_svd) ) + + t_read = time.time() + print(' getting QMCCHEM results from {}'.format(EZFIO_file) ) + results = subprocess.check_output(['qmcchem', 'result', EZFIO_file], encoding='UTF-8') + print(' getting results after {} minutes \n'.format( (time.time()-t_read)/60. )) + + # read QMC results + E_loc, ErrE_loc = get_energy() + print(' E_loc = {} +/- {}'.format(E_loc, ErrE_loc)) + print(' {} <= E_loc <= {}\n'.format(E_loc-ErrE_loc,E_loc+ErrE_loc)) + + E_loc_qmcvar, ErrE_loc_qmcvar = read_scalar('E_loc_qmcvar') + print(' E_loc_qmcvar = {} +/- {} \n'.format(E_loc_qmcvar,ErrE_loc_qmcvar)) + + psi_norm, Errpsi_norm = read_scalar('Psi_norm') + print(' psi_norm = {} +/- {}\n'.format(psi_norm,Errpsi_norm)) + + psi_norm_qmcvar, Errpsi_norm_qmcvar = read_scalar('Psi_norm_qmcvar') + print(' Psi_norm_qmcvar = {} +/- {} \n'.format(psi_norm_qmcvar, Errpsi_norm_qmcvar)) + + Ci_dress_svd_val, Ci_dress_svd_err = read_ci_dress_svd() + save_to_file(Ci_dress_svd_val,Ci_dress_svd_err, 'ci_dress_svd.txt') + + Ci_dress_val, Ci_dress_err = get_ci_dress() + save_to_file(Ci_dress_val,Ci_dress_err, 'ci_dress.txt') + #ezfio.set_dmc_dress_dmc_delta_h(Ci_dress_val) + + + print("end after {:.3f} minutes".format((time.time()-t0)/60.) ) + # !!! +# !!! diff --git a/devel/svdwf/SVD.slurm b/devel/svdwf/SVD.slurm new file mode 100644 index 0000000..18eaf05 --- /dev/null +++ b/devel/svdwf/SVD.slurm @@ -0,0 +1,24 @@ +#!/bin/bash +# +#SBATCH --job-name=SLURM_h2o_631g_SVD +#SBATCH --output=SLURM_h2o_631g_SVD.out +# +#SBATCH --mail-type=ALL +#SBATCH --mail-user=aammar@irsamc.ups-tlse.fr +# +#SBATCH -N 1 +#SBATCH -n 1 +#SBATCH -c 4 +#SBATCH -t 0:10:00 +##SBATCH --exclusive +# +# +srun hostname +echo "Running on `hostname`" +# +echo "Kicking off $SLURM_NPROCS compute servers on $SLURM_NNODES nodes" +echo "Nodes are\n `scontrol show hostname`" +# +~/qp2/bin/qpsh +qp_run Evar_TruncSVD h2o_631g >> h2o_631g_SVD.out +# diff --git a/devel/svdwf/cr2_work/LOBD_VMC.py b/devel/svdwf/cr2_work/LOBD_VMC.py new file mode 100644 index 0000000..335b3c2 --- /dev/null +++ b/devel/svdwf/cr2_work/LOBD_VMC.py @@ -0,0 +1,261 @@ +# !!! +import sys, os +QMCCHEM_PATH=os.environ["QMCCHEM_PATH"] +sys.path.insert(0,QMCCHEM_PATH+"/EZFIO/Python/") + + +from ezfio import ezfio +from math import sqrt +from datetime import datetime +import time +import numpy as np +import subprocess +from scipy.linalg import eig, eigh + + + +# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! +def get_energy(): + buffer = subprocess.check_output(['qmcchem', 'result', '-e', 'e_loc', EZFIO_file], encoding='UTF-8') + if buffer.strip() != "": + buffer = buffer.splitlines()[-1] + _, energy, error = [float(x) for x in buffer.split()] + return energy, error + else: + return None, None +# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! + + + + +# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! +def get_Ci_h_matrix_svd(): + + Ci_h_matrix_svd = np.zeros( (n_svd,n_svd) ) + SErr_H = np.zeros( (n_svd,n_svd) ) + + beg_Ci_h_matrix_svd = results.find('Ci_h_matrix_svd : [ ') + len( 'Ci_h_matrix_svd : [ ' ) + end_Ci_h_matrix_svd = len(results) + Ci_h_matrix_svd_buf = results[beg_Ci_h_matrix_svd:end_Ci_h_matrix_svd] + Ci_h_matrix_svd_buf = Ci_h_matrix_svd_buf.split( '\n' ) + + for iline in range(1, n_svd**2+1): + + line = Ci_h_matrix_svd_buf[iline].split() + indc = int( line[0] ) + errS = float( line[4] ) + if( indc != iline ): + print(' Error in reading Ci_h_matrix_svd') + print(' indc = {}'.format(indc) ) + print(' iline = {}'.format(iline) ) + break + else: + irow = indc % n_svd + icol = indc // n_svd + if( irow!=0 ): + Ci_h_matrix_svd[irow-1][icol] = float( line[2] ) + SErr_H [irow-1][icol] = float( line[4] ) + + #ci_tmp = Ci_h_matrix_svd[irow-1][icol] + #er_tmp = SErr_H [irow-1][icol] + #if(ci_tmp>0): + # Ci_h_matrix_svd[irow-1][icol] = max(0 , ci_tmp - er_tmp) + #else: + # Ci_h_matrix_svd[irow-1][icol] = min(0 , ci_tmp + er_tmp) + + else: + Ci_h_matrix_svd[n_svd-1][icol-1] = float( line[2] ) + SErr_H [n_svd-1][icol-1] = float( line[4] ) + + #ci_tmp = Ci_h_matrix_svd[n_svd-1][icol-1] + #er_tmp = SErr_H [n_svd-1][icol-1] + #if(ci_tmp>0): + # Ci_h_matrix_svd[n_svd-1][icol-1] = max(0 , ci_tmp - er_tmp) + #else: + # Ci_h_matrix_svd[n_svd-1][icol-1] = min(0 , ci_tmp + er_tmp) + + return(Ci_h_matrix_svd,SErr_H) +# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! + + + +# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! +def get_Ci_overlap_matrix_svd(): + + Ci_overlap_matrix_svd = np.zeros( (n_svd,n_svd) ) + SErr_O = np.zeros( (n_svd,n_svd) ) + + beg_Ci_overlap_matrix_svd = results.find('Ci_overlap_matrix_svd : [ ') + len( 'Ci_overlap_matrix_svd : [ ' ) + end_Ci_overlap_matrix_svd = len(results) + Ci_overlap_matrix_svd_buf = results[beg_Ci_overlap_matrix_svd:end_Ci_overlap_matrix_svd] + Ci_overlap_matrix_svd_buf = Ci_overlap_matrix_svd_buf.split( '\n' ) + + for iline in range(1, n_svd**2+1): + + line = Ci_overlap_matrix_svd_buf[iline].split() + indc = int( line[0] ) + errS = float( line[4] ) + if( indc != iline ): + print(' Error in reading Ci_overlap_matrix_svd') + print(' indc = {}'.format(indc)) + print(' iline = {}'.format(iline)) + break + else: + irow = indc % n_svd + icol = indc // n_svd + if( irow!=0 ): + Ci_overlap_matrix_svd[irow-1][icol] = float( line[2] ) + SErr_O [irow-1][icol] = float( line[4] ) + + #ci_tmp = Ci_overlap_matrix_svd[irow-1][icol] + #er_tmp = SErr_O [irow-1][icol] + #if(ci_tmp>0): + # Ci_overlap_matrix_svd[irow-1][icol] = max(0 , ci_tmp - er_tmp) + #else: + # Ci_overlap_matrix_svd[irow-1][icol] = min(0 , ci_tmp + er_tmp) + + else: + Ci_overlap_matrix_svd[n_svd-1][icol-1] = float( line[2] ) + SErr_O [n_svd-1][icol-1] = float( line[4] ) + + #ci_tmp = Ci_overlap_matrix_svd[n_svd-1][icol-1] + #er_tmp = SErr_O [n_svd-1][icol-1] + #if(ci_tmp>0): + # Ci_overlap_matrix_svd[n_svd-1][icol-1] = max(0 , ci_tmp - er_tmp) + #else: + # Ci_overlap_matrix_svd[n_svd-1][icol-1] = min(0 , ci_tmp + er_tmp) + + # !!! + # !!! + # !!! + + return(Ci_overlap_matrix_svd,SErr_O) +# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! + + + +# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! +def check_symmetric(a, tol=1e-3): + return np.all(np.abs(a-a.T) < tol) +# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! + + + +# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! +def get_Esvd(): + + # read CI_SVD matrices + Ci_h_matrix_svd , SErr_H = get_Ci_h_matrix_svd() + Ci_overlap_matrix_svd, SErr_O = get_Ci_overlap_matrix_svd() + + #print( 'Ci_h_matrix_svd is symmetric ? {}' .format(check_symmetric(Ci_h_matrix_svd)) ) + #print( 'Ci_overlap_matrix_svd is symmetric ? {}' .format(check_symmetric(Ci_overlap_matrix_svd)) ) + + if( save_SVD_QMCmat ): + with open('SVD_QMCmat.txt', 'a') as ff: + for i in range(n_svd): + for j in range(n_svd): + ff.write('{} {} {} {} {} {} \n'.format(i,j + , Ci_h_matrix_svd[i,j] , SErr_H[i,j] + , Ci_overlap_matrix_svd[i,j] , SErr_O[i,j] )) + + # symmetrise and diagonalise + aa = Ci_h_matrix_svd + aa = 0.5*( aa + aa.T ) + bb = Ci_overlap_matrix_svd + eigvals_svd, vr = eig(aa, bb, left=False, right=True, overwrite_a=True, overwrite_b=True, + check_finite=True, homogeneous_eigvals=False) + + #print( eigvals_svd + E_toadd ) + recouvre_svd = np.abs(psi_svd_coeff @ vr) + ind_gssvd = np.argmax(recouvre_svd) + + E_svd = eigvals_svd[ind_gssvd] + E_toadd + + return( E_svd, vr[:,ind_gssvd] ) +# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! + + + + +if __name__ == '__main__': + + t0 = time.time() + + # ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ # + #EZFIO_file = "Cr2_TSVD30" + #EZFIO_file = "Cr2_TSVD100" + #EZFIO_file = "Cr2_TSVD200" + #EZFIO_file = "Cr2_TSVD924_0" + #EZFIO_file = "Cr2_TSVD924_1" + #EZFIO_file = "Cr2_TSVD924_2" + + #EZFIO_file = "Cr2_TSVD30_it1" + #EZFIO_file = "Cr2_TSVD100_it1" + #EZFIO_file = "Cr2_TSVD200_it1" + #EZFIO_file = "Cr2_TSVD924_0_it1" + #EZFIO_file = "Cr2_TSVD924_1_it1" + EZFIO_file = "Cr2_TSVD924_2_it1" + + #EZFIO_file = "Cr2_TSVD200_minmaxit1" + + #EZFIO_file = "Cr2_TSVD30_it2" + + E_toadd = 64.8242130309350 + # ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ # + + ezfio.set_file(EZFIO_file) + n_svd = ezfio.get_spindeterminants_n_svd_coefs() + psi_svd_coeff = np.array(ezfio.get_spindeterminants_psi_svd_coefs()) + + print(" ") + print(" Today's date:", datetime.now() ) + print(" EZFIO file = {}".format(EZFIO_file)) + print(" n_svd = {}\n".format(n_svd) ) + + t_read = time.time() + print(' getting QMCCHEM results from {}'.format(EZFIO_file) ) + results = subprocess.check_output(['qmcchem', 'result', EZFIO_file], encoding='UTF-8') + print(' getting results after {} minutes \n'.format( (time.time()-t_read)/60. )) + + if( len(results)<100): + print(' result is empty \n') + exit() + + Eloc, ErrEloc = get_energy() + print(' Eloc = {} +/- {}'.format(Eloc, ErrEloc)) + print(' {} <= Eloc <= {}'.format(Eloc-ErrEloc,Eloc+ErrEloc)) + #print(' initial svd coeff = {}\n'.format(psi_svd_coeff)) + + save_SVD_QMCmat = True + #save_SVD_QMCmat = False + + print('') + E_svd, sigma_svd = get_Esvd() + print(' svd enegry = {}'.format(E_svd) ) + sigma_svd = sigma_svd * np.sign(sigma_svd[0]) + #print(' svd coeff = {}'.format(sigma_svd)) + print('') + + # ___________________________________________________________________________ + # ___________________________________________________________________________ + # + save_to_EZFIO = 'svd_QMC' + #save_to_EZFIO = '' + + if( save_to_EZFIO == 'svd_QMC' ): + ezfio.set_spindeterminants_psi_svd_coefs( sigma_svd ) + direc_svdcoeff = EZFIO_file + '/spindeterminants/psi_svd_coefs.gz' + print(' {} is modified'.format(direc_svdcoeff) ) + else: + print(' exit with no modifications in {} EZFIO'.format(EZFIO_file)) + # ___________________________________________________________________________ + # ___________________________________________________________________________ + # + + print("end after {:.3f} minutes".format((time.time()-t0)/60.) ) + + # !!! +# !!! + +~ diff --git a/devel/svdwf/cr2_work/LOBD_compactVMC.py b/devel/svdwf/cr2_work/LOBD_compactVMC.py new file mode 100644 index 0000000..dea6941 --- /dev/null +++ b/devel/svdwf/cr2_work/LOBD_compactVMC.py @@ -0,0 +1,225 @@ +# !!! +import sys, os +QMCCHEM_PATH=os.environ["QMCCHEM_PATH"] +sys.path.insert(0,QMCCHEM_PATH+"/EZFIO/Python/") + + +from ezfio import ezfio +from math import sqrt +from datetime import datetime +import time +import numpy as np +import subprocess +from scipy.linalg import eig, eigh + + + +# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! +def get_energy(): + buffer = subprocess.check_output(['qmcchem', 'result', '-e', 'e_loc', EZFIO_file], encoding='UTF-8') + if buffer.strip() != "": + buffer = buffer.splitlines()[-1] + _, energy, error = [float(x) for x in buffer.split()] + return energy, error + else: + return None, None +# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! + + + +# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! +def get_Ci_h_matrix_modifsvd(): + + Ci_h_matrix_modifsvd = np.zeros( (n_modifsvd,n_modifsvd) ) + SErr_H = np.zeros( (n_modifsvd,n_modifsvd) ) + + beg_Ci_h_matrix_modifsvd = results.find('Ci_h_matrix_modifsvd : [ ') + len( 'Ci_h_matrix_modifsvd : [ ' ) + end_Ci_h_matrix_modifsvd = len(results) + Ci_h_matrix_modifsvd_buf = results[beg_Ci_h_matrix_modifsvd:end_Ci_h_matrix_modifsvd] + Ci_h_matrix_modifsvd_buf = Ci_h_matrix_modifsvd_buf.split( '\n' ) + + for iline in range(1, n_modifsvd**2+1): + + line = Ci_h_matrix_modifsvd_buf[iline].split() + indc = int( line[0] ) + errS = float( line[4] ) + if( indc != iline ): + print(' Error in reading Ci_h_matrix_modifsvd') + print(' indc = {}'.format(indc) ) + print(' iline = {}'.format(iline) ) + break + else: + irow = indc % n_modifsvd + icol = indc // n_modifsvd + if( irow!=0 ): + Ci_h_matrix_modifsvd[irow-1][icol] = float( line[2] ) + SErr_H [irow-1][icol] = float( line[4] ) + else: + Ci_h_matrix_modifsvd[n_modifsvd-1][icol-1] = float( line[2] ) + SErr_H [n_modifsvd-1][icol-1] = float( line[4] ) + # !!! + # !!! + + return(Ci_h_matrix_modifsvd,SErr_H) +# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! + + + +# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! +def get_Ci_overlap_matrix_modifsvd(): + + Ci_overlap_matrix_modifsvd = np.zeros( (n_modifsvd,n_modifsvd) ) + SErr_O = np.zeros( (n_modifsvd,n_modifsvd) ) + + beg_Ci_overlap_matrix_modifsvd = results.find('Ci_overlap_matrix_modifsvd : [ ') + len( 'Ci_overlap_matrix_modifsvd : [ ' ) + end_Ci_overlap_matrix_modifsvd = len(results) + Ci_overlap_matrix_modifsvd_buf = results[beg_Ci_overlap_matrix_modifsvd:end_Ci_overlap_matrix_modifsvd] + Ci_overlap_matrix_modifsvd_buf = Ci_overlap_matrix_modifsvd_buf.split( '\n' ) + + for iline in range(1, n_modifsvd**2+1): + + line = Ci_overlap_matrix_modifsvd_buf[iline].split() + indc = int( line[0] ) + errS = float( line[4] ) + if( indc != iline ): + print(' Error in reading Ci_overlap_matrix_modifsvd') + print(' indc = {}'.format(indc)) + print(' iline = {}'.format(iline)) + break + else: + irow = indc % n_modifsvd + icol = indc // n_modifsvd + if( irow!=0 ): + Ci_overlap_matrix_modifsvd[irow-1][icol] = float( line[2] ) + SErr_O [irow-1][icol] = float( line[4] ) + else: + Ci_overlap_matrix_modifsvd[n_modifsvd-1][icol-1] = float( line[2] ) + SErr_O [n_modifsvd-1][icol-1] = float( line[4] ) + + return(Ci_overlap_matrix_modifsvd,SErr_O) +# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! + + + + +# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! +def check_symmetric(a, tol=1e-3): + return np.all(np.abs(a-a.T) < tol) +# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! + + + +# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! +def get_Esvd(): + + Ci_h_matrix_modifsvd , SErr_H = get_Ci_h_matrix_modifsvd() + Ci_overlap_matrix_modifsvd, SErr_O = get_Ci_overlap_matrix_modifsvd() + + if( save_compactSVD_QMCmat ): + with open('compactSVD_QMCmat.txt', 'a') as ff: + for i in range(n_modifsvd): + for j in range(n_modifsvd): + ff.write('{} {} {} {} {} {} \n'.format(i,j + , Ci_h_matrix_modifsvd[i,j] , SErr_H[i,j] + , Ci_overlap_matrix_modifsvd[i,j] , SErr_O[i,j] )) + + # symmetrise and diagonalise + aa = Ci_h_matrix_modifsvd + aa = 0.5*( aa + aa.T ) + bb = Ci_overlap_matrix_modifsvd + eigvals_modifsvd, vr = eig(aa, bb, left=False, right=True, overwrite_a=True, overwrite_b=True, + check_finite=True, homogeneous_eigvals=False) + + psi_tmp = psi_svd_coefs[0,0:n_modifsvd] + recouvre_modifsvd = np.abs(psi_tmp @ vr) + ind_gssvd = np.argmax(recouvre_modifsvd) + + E_modifsvd = eigvals_modifsvd[ind_gssvd] + E_toadd + + return( E_modifsvd, vr[:,ind_gssvd] ) +# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! + + + + +if __name__ == '__main__': + + t0 = time.time() + + # ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ # + #EZFIO_file = "Cr2_compactSVD30" + + + + EZFIO_file = "Cr2_compactSVD30_it1" + + E_toadd = 64.8242130309350 + # ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ # + + ezfio.set_file(EZFIO_file) + n_svd = ezfio.get_spindeterminants_n_svd_coefs() + n_modifsvd = ezfio.get_spindeterminants_n_modifsvd_coefs() + psi_svd_coefs = np.array(ezfio.get_spindeterminants_psi_svd_coefs()) + + print(" ") + print(" Today's date:", datetime.now() ) + print(" EZFIO file = {}".format(EZFIO_file)) + print(" n_svd = {}".format(n_svd) ) + print(" n_modifsvd = {}\n".format(n_modifsvd) ) + + t_read = time.time() + print(' getting QMCCHEM results from {}'.format(EZFIO_file) ) + results = subprocess.check_output(['qmcchem', 'result', EZFIO_file], encoding='UTF-8') + print(' getting results after {} minutes \n'.format( (time.time()-t_read)/60. )) + + if( len(results)<100): + print(' result is empty \n') + exit() + + Eloc, ErrEloc = get_energy() + print(' Eloc = {} +/- {}'.format(Eloc, ErrEloc)) + print(' {} <= Eloc <= {}'.format(Eloc-ErrEloc,Eloc+ErrEloc)) + #print(' initial svd coeff = {}\n'.format(psi_svd_coefs)) + + save_compactSVD_QMCmat = True + + print('') + E_compactsvd, sigma_compactsvd = get_Esvd() + print(' compact svd enegry = {}'.format(E_compactsvd) ) + sigma_compactsvd = sigma_compactsvd * np.sign(sigma_compactsvd[0]) + print(' compact svd coeff = {}\n'.format(sigma_compactsvd)) + + #print(' compact svd factor = {}\n'.format(sigma_compactsvd[n_modifsvd-1])) + + # ___________________________________________________________________________ + # ___________________________________________________________________________ + # + #save_to_EZFIO = 'compactsvd_QMC' + save_to_EZFIO = '' + + if( save_to_EZFIO == 'compactsvd_QMC' ): + ezfio_sigma_svd = np.zeros((n_svd)) + + for i in range(n_modifsvd-1): + ezfio_sigma_svd[i] = sigma_compactsvd[i] + for i in range(n_modifsvd-1, n_svd): + ezfio_sigma_svd[i] = psi_svd_coefs[0,i] * sigma_compactsvd[n_modifsvd-1] + + #print(' new svd coeff = {}\n'.format(ezfio_sigma_svd)) + + ezfio.set_spindeterminants_psi_svd_coefs( ezfio_sigma_svd ) + direc_svdcoeff = EZFIO_file + '/spindeterminants/psi_svd_coefs.gz' + print(' {} is modified'.format(direc_svdcoeff) ) + else: + print(' no modifications has been done in {}'.format(EZFIO_file)) + # ___________________________________________________________________________ + # ___________________________________________________________________________ + + print("end after {:.3f} minutes".format((time.time()-t0)/60.) ) + + # !!! +# !!! + +~ +~ + diff --git a/devel/svdwf/cr2_work/LOBD_postVMC.py b/devel/svdwf/cr2_work/LOBD_postVMC.py new file mode 100644 index 0000000..0d2f933 --- /dev/null +++ b/devel/svdwf/cr2_work/LOBD_postVMC.py @@ -0,0 +1,175 @@ +# !!! +import sys, os +QMCCHEM_PATH=os.environ["QMCCHEM_PATH"] +sys.path.insert(0,QMCCHEM_PATH+"/EZFIO/Python/") + + +from ezfio import ezfio +from math import sqrt +from datetime import datetime +import time +import numpy as np +import subprocess +from scipy.linalg import eig, eigh + + + +# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! +def get_energy(): + buffer = subprocess.check_output(['qmcchem', 'result', '-e', 'e_loc', EZFIO_file], encoding='UTF-8') + if buffer.strip() != "": + buffer = buffer.splitlines()[-1] + _, energy, error = [float(x) for x in buffer.split()] + return energy, error + else: + return None, None +# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! + + + + +# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! +def get_Ci_h_matrix_svd(): + + Ci_h_matrix_svd = np.zeros( (n_svd,n_svd) ) + SErr_H = np.zeros( (n_svd,n_svd) ) + + f = open(VMCmat_file, 'r') + Lines = f.readlines() + for line in Lines: + line = line.split() + ii = int ( line[0] ) + jj = int ( line[1] ) + Ci_h_matrix_svd[ii][jj] = float( line[2] ) + SErr_H [ii][jj] = float( line[3] ) + + return(Ci_h_matrix_svd,SErr_H) +# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! + + + +# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! +def get_Ci_overlap_matrix_svd(): + + Ci_overlap_matrix_svd = np.zeros( (n_svd,n_svd) ) + SErr_O = np.zeros( (n_svd,n_svd) ) + + f = open(VMCmat_file, 'r') + Lines = f.readlines() + for line in Lines: + line = line.split() + ii = int ( line[0] ) + jj = int ( line[1] ) + Ci_overlap_matrix_svd[ii][jj] = float( line[4] ) + SErr_O [ii][jj] = float( line[5] ) + + return(Ci_overlap_matrix_svd,SErr_O) +# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! + + + +# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! +def check_symmetric(a, tol=1e-3): + return np.all(np.abs(a-a.T) < tol) +# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! + + + +# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! +def get_Esvd(): + + # read CI_SVD matrices + Ci_h_matrix_svd , SErr_H = get_Ci_h_matrix_svd() + Ci_overlap_matrix_svd, SErr_O = get_Ci_overlap_matrix_svd() + + #print( 'Ci_h_matrix_svd is symmetric ? {}' .format(check_symmetric(Ci_h_matrix_svd)) ) + #print( 'Ci_overlap_matrix_svd is symmetric ? {}' .format(check_symmetric(Ci_overlap_matrix_svd)) ) + + # symmetrise and diagonalise + aa = Ci_h_matrix_svd + aa = 0.5*( aa + aa.T ) + bb = Ci_overlap_matrix_svd + eigvals_svd, vr = eig(aa, bb, left=False, right=True, overwrite_a=True, overwrite_b=True, + check_finite=True, homogeneous_eigvals=False) + + #print( eigvals_svd + E_toadd ) + recouvre_svd = np.abs(psi_svd_coeff @ vr) + ind_gssvd = np.argmax(recouvre_svd) + + E_svd = eigvals_svd[ind_gssvd] + E_toadd + + return( E_svd, vr[:,ind_gssvd] ) +# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! + + + + +if __name__ == '__main__': + + t0 = time.time() + + # ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ # + #EZFIO_file = "Cr2_TSVD30" + #EZFIO_file = "Cr2_TSVD100" + #EZFIO_file = "Cr2_TSVD200" + #EZFIO_file = "Cr2_TSVD924" + #EZFIO_file = "Cr2_TSVD924_1" + + #EZFIO_file = "Cr2_TSVD30_it1" + #EZFIO_file = "Cr2_TSVD100_it1" + #EZFIO_file = "Cr2_TSVD200_it1" + EZFIO_file = "Cr2_TSVD924_1_it1" + + #EZFIO_file = "Cr2_TSVD200_minmaxit1" + + #EZFIO_file = "Cr2_TSVD30_it2" + + E_toadd = 64.8242130309350 + # ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ # + + ezfio.set_file(EZFIO_file) + n_svd = ezfio.get_spindeterminants_n_svd_coefs() + psi_svd_coeff = np.array(ezfio.get_spindeterminants_psi_svd_coefs()) + + print(" ") + print(" Today's date:", datetime.now() ) + print(" EZFIO file = {}".format(EZFIO_file)) + print(" n_svd = {}\n".format(n_svd) ) + + #VMCmat_list = [ 'SVD_QMCmat_FSVD_2b.txt' , 'SVD_QMCmat_FSVD_3b.txt' , 'SVD_QMCmat_FSVD_0.txt' ] + #VMCmat_list = [ 'SVD_QMCmat_FSVD_2b_1.txt', 'SVD_QMCmat_FSVD_3b_1.txt' + # , 'SVD_QMCmat_FSVD_4b_1.txt', 'SVD_QMCmat_FSVD_5b_1.txt' + # , 'SVD_QMCmat_FSVD_1.txt' ] + #for VMCmat_file in VMCmat_list: + # print(" SVD matrices file = {}".format(VMCmat_file)) + # E_svd, sigma_svd = get_Esvd() + # print(' svd enegry = {} \n'.format(E_svd) ) + + + VMCmat_file = 'SVD_QMCmat_FSVD_4b_1.txt' + print(" SVD matrices file = {}".format(VMCmat_file)) + E_svd, sigma_svd = get_Esvd() + sigma_svd = sigma_svd * np.sign(sigma_svd[0]) + print(' svd coeff = {}'.format(sigma_svd)) + + # ___________________________________________________________________________ + # ___________________________________________________________________________ + # + #save_to_EZFIO = 'svd_QMC' + save_to_EZFIO = '' + + if( save_to_EZFIO == 'svd_QMC' ): + ezfio.set_spindeterminants_psi_svd_coefs( sigma_svd ) + direc_svdcoeff = EZFIO_file + '/spindeterminants/psi_svd_coefs.gz' + print(' {} is modified'.format(direc_svdcoeff) ) + else: + pass + # ___________________________________________________________________________ + # ___________________________________________________________________________ + + print("end after {:.3f} minutes".format((time.time()-t0)/60.) ) + + # !!! +# !!! + +~ diff --git a/devel/svdwf/cr2_work/LOBD_postcompactSVD.py b/devel/svdwf/cr2_work/LOBD_postcompactSVD.py new file mode 100644 index 0000000..a4c30b2 --- /dev/null +++ b/devel/svdwf/cr2_work/LOBD_postcompactSVD.py @@ -0,0 +1,173 @@ +# !!! +import sys, os +QMCCHEM_PATH=os.environ["QMCCHEM_PATH"] +sys.path.insert(0,QMCCHEM_PATH+"/EZFIO/Python/") + + +from ezfio import ezfio +from math import sqrt +from datetime import datetime +import time +import numpy as np +import subprocess +from scipy.linalg import eig, eigh + + + +# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! +def get_energy(): + buffer = subprocess.check_output(['qmcchem', 'result', '-e', 'e_loc', EZFIO_file], encoding='UTF-8') + if buffer.strip() != "": + buffer = buffer.splitlines()[-1] + _, energy, error = [float(x) for x in buffer.split()] + return energy, error + else: + return None, None +# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! + + + +# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! +def get_Ci_h_matrix_modifsvd(): + + Ci_h_matrix_modifsvd = np.zeros( (n_modifsvd,n_modifsvd) ) + SErr_H = np.zeros( (n_modifsvd,n_modifsvd) ) + + f = open(compactVMCmat_file, 'r') + Lines = f.readlines() + for line in Lines: + line = line.split() + ii = int ( line[0] ) + jj = int ( line[1] ) + Ci_h_matrix_modifsvd[ii][jj] = float( line[2] ) + SErr_H [ii][jj] = float( line[3] ) + + return(Ci_h_matrix_modifsvd,SErr_H) +# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! + + + + +# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! +def get_Ci_overlap_matrix_modifsvd(): + + Ci_overlap_matrix_modifsvd = np.zeros( (n_modifsvd,n_modifsvd) ) + SErr_O = np.zeros( (n_modifsvd,n_modifsvd) ) + + f = open(compactVMCmat_file, 'r') + Lines = f.readlines() + for line in Lines: + line = line.split() + ii = int ( line[0] ) + jj = int ( line[1] ) + Ci_overlap_matrix_modifsvd[ii][jj] = float( line[4] ) + SErr_O [ii][jj] = float( line[5] ) + + return(Ci_overlap_matrix_modifsvd,SErr_O) +# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! + + + +# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! +def check_symmetric(a, tol=1e-3): + return np.all(np.abs(a-a.T) < tol) +# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! + + + +# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! +def get_Esvd(): + + Ci_h_matrix_modifsvd , SErr_H = get_Ci_h_matrix_modifsvd() + Ci_overlap_matrix_modifsvd, SErr_O = get_Ci_overlap_matrix_modifsvd() + + # symmetrise and diagonalise + aa = Ci_h_matrix_modifsvd + aa = 0.5*( aa + aa.T ) + bb = Ci_overlap_matrix_modifsvd + eigvals_modifsvd, vr = eig(aa, bb, left=False, right=True, overwrite_a=True, overwrite_b=True, + check_finite=True, homogeneous_eigvals=False) + + psi_tmp = psi_svd_coefs[0,0:n_modifsvd] + recouvre_modifsvd = np.abs(psi_tmp @ vr) + ind_gssvd = np.argmax(recouvre_modifsvd) + + E_modifsvd = eigvals_modifsvd[ind_gssvd] + E_toadd + + return( E_modifsvd, vr[:,ind_gssvd] ) +# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! + + + + +if __name__ == '__main__': + + t0 = time.time() + + # ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ # + #EZFIO_file = "Cr2_compactSVD30" + + #EZFIO_file = "Cr2_compactSVD30_it1" + EZFIO_file = "Cr2_compactSVD30_it1_1" + + E_toadd = 64.8242130309350 + # ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ # + + ezfio.set_file(EZFIO_file) + n_svd = ezfio.get_spindeterminants_n_svd_coefs() + n_modifsvd = ezfio.get_spindeterminants_n_modifsvd_coefs() + psi_svd_coefs = np.array(ezfio.get_spindeterminants_psi_svd_coefs()) + + print(" ") + print(" Today's date:", datetime.now() ) + print(" EZFIO file = {}".format(EZFIO_file)) + print(" n_svd = {}".format(n_svd) ) + print(" n_modifsvd = {}\n".format(n_modifsvd) ) + #print(' initial svd coeff = {}\n'.format(psi_svd_coefs)) + + compactVMCmat_list = [ 'compactSVD_QMCmat_1.txt' , 'compactSVD_QMCmat_2.txt' ] + for compactVMCmat_file in compactVMCmat_list: + print(" compactSVD matrices file = {}".format(compactVMCmat_file)) + E_compactsvd, sigma_compactsvd = get_Esvd() + print(' compact svd enegry = {}'.format(E_compactsvd) ) + + print('') + compactVMCmat_file = 'compactSVD_QMCmat_1.txt' + print(" compactSVD matrices file = {}".format(compactVMCmat_file)) + E_compactsvd, sigma_compactsvd = get_Esvd() + sigma_compactsvd = sigma_compactsvd * np.sign(sigma_compactsvd[0]) + print(' compact svd enegry = {}'.format(E_compactsvd) ) + print(' compact svd coeff = {}\n'.format(sigma_compactsvd)) + + print(' compact svd factor = {}\n'.format(sigma_compactsvd[n_modifsvd-1])) + + # ___________________________________________________________________________ + # ___________________________________________________________________________ + # + #save_to_EZFIO = 'compactsvd_QMC' + save_to_EZFIO = '' + + if( save_to_EZFIO == 'compactsvd_QMC' ): + ezfio_sigma_svd = np.zeros((n_svd)) + + for i in range(n_modifsvd-1): + ezfio_sigma_svd[i] = sigma_compactsvd[i] + for i in range(n_modifsvd-1, n_svd): + ezfio_sigma_svd[i] = psi_svd_coefs[0,i] * sigma_compactsvd[n_modifsvd-1] + + #print(' new svd coeff = {}\n'.format(ezfio_sigma_svd)) + + ezfio.set_spindeterminants_psi_svd_coefs( ezfio_sigma_svd ) + direc_svdcoeff = EZFIO_file + '/spindeterminants/psi_svd_coefs.gz' + print(' {} is modified'.format(direc_svdcoeff) ) + else: + print(' no modifications has been done in {}'.format(EZFIO_file)) + # ___________________________________________________________________________ + # ___________________________________________________________________________ + + print("end after {:.3f} minutes".format((time.time()-t0)/60.) ) + + # !!! +# !!! + +~ diff --git a/devel/svdwf/qmcchemRun.slurm b/devel/svdwf/qmcchemRun.slurm new file mode 100644 index 0000000..58e0ad6 --- /dev/null +++ b/devel/svdwf/qmcchemRun.slurm @@ -0,0 +1,31 @@ +#!/bin/bash +# +#SBATCH --job-name=QMC_n20_2h2 +#SBATCH --output=%x_%j.out +# +#SBATCH --mail-type=ALL +#SBATCH --mail-user=aammar@irsamc.ups-tlse.fr +# +#SBATCH -N 1 +#SBATCH -n 32 +#SBATCH -c 1 +#SBATCH -t 24:00:00 +#SBATCH -p xeonv4 +#SBATCH --exclusive +# +# +# +srun hostname +echo "Running on `hostname`" +# +echo "Kicking off $SLURM_NPROCS compute servers on $SLURM_NNODES nodes" +echo "Nodes are\n `scontrol show hostname`" +# +source ~/qmcchem/qmcchemrc +# +##qmcchem edit -c -j None -l 10 -t 120 h2o_631g >> qmcchem_h2o_631g.out +#qmcchem edit -c -j None -l 600 -t 10000 h2o_631g >> qmcchem_h2o_631g.out +#qmcchem run h2o_631g_frez_Jopt_nsvd10_iter2postsvd >> qmcchem_h2o_631g_frez_Jopt_nsvd10_iter2postsvd.out +# +qmcchem run 2h2_work/2h2_cisd_nsvd20 >> QMC_2h2_nsvd20.out +# diff --git a/devel/svdwf/qpRun.slurm b/devel/svdwf/qpRun.slurm new file mode 100644 index 0000000..f627081 --- /dev/null +++ b/devel/svdwf/qpRun.slurm @@ -0,0 +1,35 @@ +#!/bin/bash +# +##SBATCH --job-name=buildpsi_h2o_pv +#SBATCH --job-name=diag_f2 +#SBATCH --output=%x_%j.out +#SBATCH --mail-type=ALL +#SBATCH --mail-user=aammar@irsamc.ups-tlse.fr +# +#SBATCH -N 1 +#SBATCH -n 1 +#SBATCH -c 32 +##SBATCH -c 1 +#SBATCH -t 72:00:00 +#SBATCH -p xeonv2 +#SBATCH --exclusive +# +srun hostname +echo "Running on `hostname`" +echo "Kicking off $SLURM_NPROCS compute servers on $SLURM_NNODES nodes" +echo "Nodes are\n `scontrol show hostname`" +# +#qp create_ezfio -b 6-31g h2o.xyz -o h2o_631g +#qp create_ezfio -p bfd -b cc-pvdz_ecp_bfd h2o.xyz -o h2o_pseudo +# +~/qp2/bin/qpsh +# +#qp_run scf h2o_631g >> scf_h2o_631g.out +#qp_run cisd h2o_631g >> cisd_h2o_631g.out +# +#qp_run buildpsi_postsvd_pv h2o_work/h2o_631g_frez_cisd >> buildpsi_postsvd_h2o_631g_frez_cisd.dat +# +#qp_run diag_H_npostsvd h2o_work/h2o_631g_frez_fci >> diag_H_npostsvd.dat +qp_run diag_H_npostsvd_pv f2_work/f2_cisd >> diag_H_npostsvd_pv_f2.dat +#qp_run diag_H_npostsvd_pv h2o_work/h2o_631g_frez_cisd >> diag_H_npostsvd_pv_h2o.dat +# diff --git a/devel/svdwf/run_py.slurm b/devel/svdwf/run_py.slurm new file mode 100644 index 0000000..6157724 --- /dev/null +++ b/devel/svdwf/run_py.slurm @@ -0,0 +1,26 @@ +#!/bin/bash +#SBATCH --job-name=RSVD +#SBATCH --output=%x_%j.out +# +#SBATCH --mail-type=ALL +#SBATCH --mail-user=aammar@irsamc.ups-tlse.fr +# +#SBATCH -N 1 +#SBATCH -n 1 +#SBATCH -c 1 +#SBATCH -t 250:00:00 +#SBATCH -p xeonv2 +###SBATCH --exclusive +# +# +# +srun hostname +echo "Running on `hostname`" +# +echo "Kicking off $SLURM_NPROCS compute servers on $SLURM_NNODES nodes" +echo "Nodes are\n `scontrol show hostname`" +# +source ~/qmcchem/qmcchemrc +# +python perform_RSVD.py >> RSVD_py.out + From 43393ddc97ee3a77566a57c4c62f8304fd1370dd Mon Sep 17 00:00:00 2001 From: Abdallah Ammar Date: Sat, 31 Jul 2021 14:26:26 +0200 Subject: [PATCH 02/16] dress SVD --- devel/dmc_dress/dress_SVD.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/devel/dmc_dress/dress_SVD.py b/devel/dmc_dress/dress_SVD.py index 0e52d38..ac5bac9 100755 --- a/devel/dmc_dress/dress_SVD.py +++ b/devel/dmc_dress/dress_SVD.py @@ -90,7 +90,6 @@ def get_ci_dress(): ci_dress_mat_val = np.dot(U_svd,np.dot(np.diagflat(Ci_dress_svd_val),V_svd.T)) ci_dress_mat_err = np.dot(U_svd,np.dot(np.diagflat(Ci_dress_svd_err),V_svd.T)) - print(ci_dress_mat_val.shape) n_det = ezfio.get_spindeterminants_n_det() i_row = np.array(ezfio.get_spindeterminants_psi_coef_matrix_rows()) @@ -166,7 +165,15 @@ if __name__ == '__main__': Ci_dress_val, Ci_dress_err = get_ci_dress() save_to_file(Ci_dress_val,Ci_dress_err, 'ci_dress.txt') - #ezfio.set_dmc_dress_dmc_delta_h(Ci_dress_val) + + + # _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ + # + # SAVE TO EZFIO + # + ezfio.set_dmc_dress_dmc_delta_h(Ci_dress_val) + # _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ + # print("end after {:.3f} minutes".format((time.time()-t0)/60.) ) From 7b442c5341af99240dcee21ee8b0fe0f589643fe Mon Sep 17 00:00:00 2001 From: Abdallah Ammar Date: Tue, 2 Nov 2021 16:18:07 +0100 Subject: [PATCH 03/16] svdwf with tc --- devel/dmc_dress/dmc_dress.irp.f | 2 +- devel/dmc_dress/dress_SVD.py | 7 +- .../CO_work/decomp/PILC_decomp/T_decomp.py | 361 +++++++++++++ devel/svdwf/FSVD_trunc.irp.f | 122 +++-- devel/svdwf/RSVD_ijHkl_det.irp.f | 311 +++++++++++ devel/svdwf/SQ_klHkl_v1.irp.f | 511 ++++++++++++++++++ devel/svdwf/SVD_rank.irp.f | 62 +++ devel/svdwf/TSVD_err.irp.f | 116 ++++ devel/svdwf/checkSVD_EZ.irp.f | 106 ++++ devel/svdwf/cr2_work/invSVD.py | 131 +++++ devel/svdwf/delta_2bTSVD_v0.irp.f | 203 +++++++ devel/svdwf/delta_3bSVD_v0.irp.f | 164 ++++++ devel/svdwf/delta_3bSVD_v1.irp.f | 195 +++++++ devel/svdwf/delta_4bTSVD_v0.irp.f | 305 +++++++++++ devel/svdwf/delta_FSVD_v0.irp.f | 250 +++++++++ devel/svdwf/delta_FSVD_v1.irp.f | 197 +++++++ devel/svdwf/delta_FSVD_v2.irp.f | 145 +++++ devel/svdwf/delta_diagSVD_v0.irp.f | 147 +++++ devel/svdwf/delta_svd_v1.irp.f | 221 ++++++++ devel/svdwf/delta_svd_v2.irp.f | 167 ++++++ .../f2_work/decomp/PILC_decomp/T_decomp.py | 347 ++++++++++++ .../f2_work/decomp/SVD_decomp/SVD_decomp.py | 348 ++++++++++++ .../svdwf/f2_work/f2_opt/SVD_opt/Evmc_TSVD.py | 251 +++++++++ .../svdwf/f2_work/f2_opt/SVD_opt/LOBD_VMC.py | 216 ++++++++ .../f2_work/f2_opt/SVD_opt/LOBD_compactVMC.py | 225 ++++++++ .../f2_work/f2_opt/SVD_opt/LOBD_postVMC.py | 166 ++++++ .../f2_opt/SVD_opt/LOBD_postcompactSVD.py | 173 ++++++ .../f2_work/f2_opt/dress_opt/dress_SVD.py | 188 +++++++ devel/svdwf/f2_work/f2_opt/dress_opt/info.txt | 25 + .../f2_opt/opt_Jas/modif_powell_imp.py | 504 +++++++++++++++++ .../f2_opt/opt_Jas/opt_jast_freegrad.py | 254 +++++++++ .../h2o_work/FN_test/cc_pCVDZ/QMC_nsvd.py | 176 ++++++ .../FN_test/cc_pCVDZ/read_selectedSVD.py | 62 +++ devel/svdwf/invFSVD_det.irp.f | 199 +++++++ devel/svdwf/invFSVD_spindet.irp.f | 120 ++++ devel/svdwf/kl_H_kl_v1.irp.f | 136 ++--- devel/svdwf/kl_H_kl_v2.irp.f | 55 +- devel/svdwf/printSQ_ab_T_gd_v0.irp.f | 402 ++++++++++++++ devel/svdwf/printSQ_ij_T_kl.irp.f | 257 +++++++++ devel/svdwf/print_2e_integrals.irp.f | 48 ++ devel/svdwf/print_ij_H_kl_det.irp.f | 129 +++++ devel/svdwf/print_ij_H_kl_det_v0.irp.f | 144 +++++ devel/svdwf/print_ij_H_kl_det_v1.irp.f | 110 ++++ devel/svdwf/print_ij_H_kl_v0.irp.f | 225 ++++++++ devel/svdwf/print_ij_H_kl_v1.irp.f | 280 ++++++++++ devel/svdwf/psiSVD_naiv1by1_v1.irp.f | 44 +- devel/svdwf/psiSVD_naivBbyB_v2.irp.f | 334 ++++++++++++ devel/svdwf/psiSVD_pt2_v1.irp.f | 27 +- devel/svdwf/saveSVD_asEZ.irp.f | 150 +++++ 49 files changed, 9096 insertions(+), 222 deletions(-) create mode 100644 devel/svdwf/CO_work/decomp/PILC_decomp/T_decomp.py create mode 100644 devel/svdwf/RSVD_ijHkl_det.irp.f create mode 100644 devel/svdwf/SQ_klHkl_v1.irp.f create mode 100644 devel/svdwf/SVD_rank.irp.f create mode 100644 devel/svdwf/TSVD_err.irp.f create mode 100644 devel/svdwf/checkSVD_EZ.irp.f create mode 100644 devel/svdwf/cr2_work/invSVD.py create mode 100644 devel/svdwf/delta_2bTSVD_v0.irp.f create mode 100644 devel/svdwf/delta_3bSVD_v0.irp.f create mode 100644 devel/svdwf/delta_3bSVD_v1.irp.f create mode 100644 devel/svdwf/delta_4bTSVD_v0.irp.f create mode 100644 devel/svdwf/delta_FSVD_v0.irp.f create mode 100644 devel/svdwf/delta_FSVD_v1.irp.f create mode 100644 devel/svdwf/delta_FSVD_v2.irp.f create mode 100644 devel/svdwf/delta_diagSVD_v0.irp.f create mode 100644 devel/svdwf/delta_svd_v1.irp.f create mode 100644 devel/svdwf/delta_svd_v2.irp.f create mode 100644 devel/svdwf/f2_work/decomp/PILC_decomp/T_decomp.py create mode 100644 devel/svdwf/f2_work/decomp/SVD_decomp/SVD_decomp.py create mode 100644 devel/svdwf/f2_work/f2_opt/SVD_opt/Evmc_TSVD.py create mode 100644 devel/svdwf/f2_work/f2_opt/SVD_opt/LOBD_VMC.py create mode 100644 devel/svdwf/f2_work/f2_opt/SVD_opt/LOBD_compactVMC.py create mode 100644 devel/svdwf/f2_work/f2_opt/SVD_opt/LOBD_postVMC.py create mode 100644 devel/svdwf/f2_work/f2_opt/SVD_opt/LOBD_postcompactSVD.py create mode 100755 devel/svdwf/f2_work/f2_opt/dress_opt/dress_SVD.py create mode 100644 devel/svdwf/f2_work/f2_opt/dress_opt/info.txt create mode 100644 devel/svdwf/f2_work/f2_opt/opt_Jas/modif_powell_imp.py create mode 100644 devel/svdwf/f2_work/f2_opt/opt_Jas/opt_jast_freegrad.py create mode 100644 devel/svdwf/h2o_work/FN_test/cc_pCVDZ/QMC_nsvd.py create mode 100644 devel/svdwf/h2o_work/FN_test/cc_pCVDZ/read_selectedSVD.py create mode 100644 devel/svdwf/invFSVD_det.irp.f create mode 100644 devel/svdwf/invFSVD_spindet.irp.f create mode 100644 devel/svdwf/printSQ_ab_T_gd_v0.irp.f create mode 100644 devel/svdwf/printSQ_ij_T_kl.irp.f create mode 100644 devel/svdwf/print_2e_integrals.irp.f create mode 100644 devel/svdwf/print_ij_H_kl_det.irp.f create mode 100644 devel/svdwf/print_ij_H_kl_det_v0.irp.f create mode 100644 devel/svdwf/print_ij_H_kl_det_v1.irp.f create mode 100644 devel/svdwf/print_ij_H_kl_v0.irp.f create mode 100644 devel/svdwf/print_ij_H_kl_v1.irp.f create mode 100644 devel/svdwf/psiSVD_naivBbyB_v2.irp.f create mode 100644 devel/svdwf/saveSVD_asEZ.irp.f diff --git a/devel/dmc_dress/dmc_dress.irp.f b/devel/dmc_dress/dmc_dress.irp.f index 72a78b4..c3d1d37 100644 --- a/devel/dmc_dress/dmc_dress.irp.f +++ b/devel/dmc_dress/dmc_dress.irp.f @@ -7,7 +7,7 @@ program dmc_dress END_DOC read_wf = .True. touch read_wf - call pre +! call pre call routine call save_wavefunction_general(N_det,N_states,psi_det_sorted,size(psi_coef_sorted,1),psi_coef_sorted) end diff --git a/devel/dmc_dress/dress_SVD.py b/devel/dmc_dress/dress_SVD.py index ac5bac9..3393ecf 100755 --- a/devel/dmc_dress/dress_SVD.py +++ b/devel/dmc_dress/dress_SVD.py @@ -116,7 +116,7 @@ def get_ci_dress(): # def save_to_file(v_val,v_err, name_f): - with open(name_f, 'a') as ff: + with open(name_f, 'w') as ff: for i in range(len(v_val)): ff.write(' {} {} {}\n'.format(i, v_val[i], v_err[i])) #____________________________________________________________________________________ @@ -129,7 +129,8 @@ if __name__ == '__main__': # _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ # #EZFIO_file = sys.argv[1] - EZFIO_file = "/home/aammar/qp2/src/svdwf/cr2_work/cr2_1p6_dress" + #EZFIO_file = "/home/aammar/qp2/src/svdwf/cr2_work/cr2_1p6_dress" + EZFIO_file = "/home/aammar/qp2/src/svdwf/cr2_work/cr2_1p6_dress_0" # _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ezfio.set_file(EZFIO_file) @@ -171,7 +172,7 @@ if __name__ == '__main__': # # SAVE TO EZFIO # - ezfio.set_dmc_dress_dmc_delta_h(Ci_dress_val) + #ezfio.set_dmc_dress_dmc_delta_h(Ci_dress_val) # _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ # diff --git a/devel/svdwf/CO_work/decomp/PILC_decomp/T_decomp.py b/devel/svdwf/CO_work/decomp/PILC_decomp/T_decomp.py new file mode 100644 index 0000000..196647c --- /dev/null +++ b/devel/svdwf/CO_work/decomp/PILC_decomp/T_decomp.py @@ -0,0 +1,361 @@ +#!/usr/bin/env python + +from ezfio import ezfio +import numpy as np +import sys + +import time +from datetime import datetime + +import matplotlib.pyplot as plt +#import seaborn as sns +from matplotlib.colors import LogNorm + +# ____________________________________________________________________________________________ +# +def read_AO_2eCoulomb(): + + lines = [] + with open(ao_file) as f_in: + for line in f_in: + lines.append( float(line) ) + + J = np.zeros((ao_num2,ao_num2)) + + i_l = 0 + for mu in range(ao_num): + for nu in range(ao_num): + ii = nu + ao_num * mu + + for sig in range(ao_num): + for lam in range(ao_num): + jj = lam + ao_num * sig + + J[ii,jj] = lines[i_l] + i_l += 1 + + return(J) +# ____________________________________________________________________________________________ +# ____________________________________________________________________________________________ + + + + +# ____________________________________________________________________________________________ +# +def read_H_det(): + + H_det = np.zeros((n_det_alpha*n_det_beta,n_det_alpha*n_det_beta)) + with open("fort.7000") as f_in: + for line in f_in: + ll = line.split() + + i = int( ll[0] ) - 1 + j = int( ll[1] ) - 1 + ii = j + n_det_beta * i + + k = int( ll[2] ) - 1 + l = int( ll[3] ) - 1 + jj = l + n_det_beta * k + + H_det[ii,jj] = float(ll[4]) + + return(H_det) +# ____________________________________________________________________________________________ +# ____________________________________________________________________________________________ + + + +# ____________________________________________________________________________________________ +# +def read_T(): + + lines = [] + with open("ij_T_kl.dat") as f_in: + for line in f_in: + lines.append( float(line) ) + + T = np.zeros( (n_det_alpha*n_det_beta,n_det_alpha*n_det_beta) ) + + i_l = 0 + for i in range(n_det_alpha): + for j in range(n_det_beta): + ii = j + n_det_beta * i + + for k in range(n_det_alpha): + for l in range(n_det_beta): + jj = l + n_det_beta * k + + T[ii,jj] = lines[i_l] + i_l += 1 + + return(T) +# ____________________________________________________________________________________________ +# ____________________________________________________________________________________________ + + + + +# ____________________________________________________________________________________________ +# +def check_symmetric(a, rtol=1e-05, atol=1e-08): + return( np.allclose(a, a.T, rtol=rtol, atol=atol) ) +# ____________________________________________________________________________________________ +# ____________________________________________________________________________________________ + + + +# ____________________________________________________________________________________________ +# +def plot_mat(M, xstep, ystep, namefile): + + Mp = np.abs(M) + 1e-15 + ax = sns.heatmap(Mp, linewidths=0.0, rasterized=True, norm=LogNorm()) + + # x axis + ax.xaxis.tick_top() + xgrid = np.arange(1, M.shape[1]+1, xstep-1) + plt.xticks( np.arange(0, M.shape[1], xstep-1) + .5, xgrid ) + + # y axis + ygrid = np.arange(1, M.shape[0]+1, ystep-1) + plt.yticks( np.arange(0, M.shape[0], ystep-1) + .5, ygrid ) + + plt.savefig(namefile) + + plt.clf() +# ____________________________________________________________________________________________ +# ____________________________________________________________________________________________ + + + +# ____________________________________________________________________________________________ +# +def incomplete_Cholesky(M, ma, mb, theta_CD): + + D = np.zeros((ma,mb)) + for lam in range(ma): + for sig in range(mb): + ii = sig + mb * lam + D[sig,lam] = M[ii,ii] + + # find the maximum + val_max = np.amax(D) + ind_max = np.where(D == val_max) + sig_max = ind_max[0][0] + lam_max = ind_max[1][0] + ii_max = sig_max + mb * lam_max + #print( sig_max, lam_max, D[sig_max,lam_max], val_max ) + + # define the initial resudual + mab = ma * mb + R = np.zeros((mab)) + R[:] = M[:,ii_max] + + m = 0 + L = np.zeros((mab)) + List_vec = [] + while(val_max>theta_CD): + + if(m>0): + # update the residual + for ii in range(mab): + sumii = 0 + for i in range(m): + sumii += List_vec[i][ii] * List_vec[i][ii_max] + R[ii] = M[ii,ii_max] - sumii + + # compute Cholesky vector + L = R / np.sqrt(val_max) + List_vec.append(L) + + # update diagonals + for lam in range(ma): + for sig in range(mb): + ii = sig + mb * lam + D[sig,lam] = D[sig,lam] - L[ii]*L[ii] + + m += 1 + + # find the new maximum + val_max = np.amax(D) + ind_max = np.where(D == val_max) + sig_max = ind_max[0][0] + lam_max = ind_max[1][0] + ii_max = sig_max + mb * lam_max + + return(m, List_vec) +# ____________________________________________________________________________________________ +# ____________________________________________________________________________________________ + + + + +# ____________________________________________________________________________________________ +# +def err_p_estim(M, List_vec): + + mM = M.shape[0] + mL = len(List_vec) + + normM = np.linalg.norm(M) + + L_CD = np.zeros((mM,mL)) + for i in range(mL): + L_CD[:,i] = List_vec[i] + print(" size of L_CD: {} MB\n".format( sys.getsizeof(L_CD) / 1024. ) ) + + err_p = 100. * np.linalg.norm( M - np.dot(L_CD, L_CD.T) ) / normM + + return( L_CD, err_p , normM) +# ____________________________________________________________________________________________ +# ____________________________________________________________________________________________ + + + +# ____________________________________________________________________________________________ +# +def save_L_CD(List_vec, file_List): + + with open(file_List, 'w') as the_file: + for i in range(List_vec.shape[0]): + for j in range(List_vec.shape[1]): + ff.write(" {:+e} \n".format(List_vec[i,j])) +# ____________________________________________________________________________________________ +# ____________________________________________________________________________________________ + + + +# ____________________________________________________________________________________________________________________________________ +# ____________________________________________________________________________________________________________________________________ +# +if __name__=="__main__": + + t_beg = time.time() + + print("") + print(" date and time = {} \n".format(datetime.now().strftime("%d/%m/%Y %H:%M:%S"))) + + + EZFIO_name = "/home/aammar/qp2/src/svdwf/f2_work/f2_fci" + ezfio.set_file(EZFIO_name) + + # ------------------------------------------------------------------------------------------------------ + # 2-e integrals in AO basis + # ------------------------------------------------------------------------------------------------------ + + ao_num = ezfio.get_ao_basis_ao_num() + ao_num2 = ao_num * ao_num + print(" nb of AO = {} \n".format(ao_num)) + + ao_file = "/home/aammar/qp2/src/svdwf/f2_work/ao_2eCoulombIntegrals.txt" + J = read_AO_2eCoulomb() + print(" size of J: {} MB ".format( sys.getsizeof(J) / 1024. ) ) + print(" J is symmetric ? {} ".format(check_symmetric(J)) ) + + #plot_mat(J, ao_num, ao_num, 'J.pdf') + + # pivoted incomplete Cholesky decomposition + theta_CD_J = 1e-02 + m_J, List_vec_J = incomplete_Cholesky(J, ao_num, ao_num, theta_CD_J) + print(" nb of L_CD vectors = {} for theta = {}".format(m_J,theta_CD_J)) + + # check error + L_CD_J, err_p_J, normJ = err_p_estim(J, List_vec_J) + print(" norm of J = {} \n".format(normJ)) + print(" error estimation on J = {} % \n".format(err_p_J)) + + save_L_CD(L_CD_J, 'L_CD_J.txt') + + #plot_mat(L_CD_J, 2, ao_num, 'L_CD_J.pdf') + # ------------------------------------------------------------------------------------------------------ + # ------------------------------------------------------------------------------------------------------ + + + + print('\n \n \n') + + + + # ------------------------------------------------------------------------------------------------------ + # < d_i d_j | T | d_k d_l > + # ------------------------------------------------------------------------------------------------------ + +# n_det_alpha = ezfio.get_spindeterminants_n_det_alpha() +# n_det_beta = ezfio.get_spindeterminants_n_det_beta () +# n_ab = n_det_alpha * n_det_beta +# print(" n_det_alpha = {} ".format(n_det_alpha)) +# print(" n_det_beta = {} \n".format(n_det_beta )) +# +# T = read_T() +# print(" T is symmetric ? {} \n".format(check_symmetric(T)) ) +# +# plot_mat(T, 50, 50, 'T.pdf') +# +# +# # pivoted incomplete Cholesky decomposition +# theta_CD_T = 1.5 +# m_T, List_vec_T = incomplete_Cholesky(T, n_det_alpha, n_det_beta, theta_CD_T) +# print(" nb of L_CD vectors = {} for theta = {}".format(m_T,theta_CD_T)) +# +# # check error +# L_CD_T, err_p_T, normT = err_p_estim(T, List_vec_T) +# print(" norm of T = {} ".format(normT)) +# print(" error estimation on T = {} % \n".format(err_p_T)) +# +# plot_mat(L_CD_T, 2, n_det_beta, 'L_CD_T.pdf') + # ------------------------------------------------------------------------------------------------------ + # ------------------------------------------------------------------------------------------------------ + + + + + + print('\n \n \n') + + + # ------------------------------------------------------------------------------------------------------ + # < d_i d_j | H | d_k d_l > + # + # WARNING: this isn't semipositive definite + # ------------------------------------------------------------------------------------------------------ +# +# # get H_det +# n_det_alpha = ezfio.get_spindeterminants_n_det_alpha() +# n_det_beta = ezfio.get_spindeterminants_n_det_beta () +# n_ab = n_det_alpha * n_det_beta +# print(" n_det_alpha = {} ".format(n_det_alpha)) +# print(" n_det_beta = {} \n".format(n_det_beta )) +# +# H_det = read_H_det() +# print(" size of H_det: {} MB ".format( sys.getsizeof(H_det) / 1024. ) ) +# print(" H_det is symmetric ? {} \n".format(check_symmetric(H_det)) ) +# +# # plot H_det +# H_det = H_det + 1e-15 +# plot_mat(H_det, 50, 50, 'H_det.pdf') +# +# +# # pivoted incomplete Cholesky decomposition +# theta_CD_H_det = 1e-02 +# m_H_det, List_vec_H_det = incomplete_Cholesky(H_det, n_det_alpha, n_det_beta, theta_CD_H_det) +# print(" nb of L_CD_H_det vectors = {} for a precision of {}".format(m_H_det,theta_CD_H_det)) +# #print(" size of L_CD_H_det: {} MB\n".format( sys.getsizeof(List_vec_H_det) / 1024. ) ) +# +# # check error +# L_CD_H_det, err_p_H_det, normH_det = err_p_estim(H_det, List_vec_H_det) +# print(" norm of H_det = {} \n".format(normH_det)) +# print(" error estimation on H_det = {} % \n".format(err_p_H_det)) +# +# plot_mat(L_CD_H_det, 2, n_det_beta, 'L_CD_H_det.pdf') + # ------------------------------------------------------------------------------------------------------ + # ------------------------------------------------------------------------------------------------------ + + + + print('\n\n') + t_end = time.time() + print(' end after {} min'.format((t_end-t_beg)/60.)) +# ____________________________________________________________________________________________________________________________________ +# ____________________________________________________________________________________________________________________________________ +# ____________________________________________________________________________________________________________________________________ diff --git a/devel/svdwf/FSVD_trunc.irp.f b/devel/svdwf/FSVD_trunc.irp.f index 3abf6a8..e0c6f38 100644 --- a/devel/svdwf/FSVD_trunc.irp.f +++ b/devel/svdwf/FSVD_trunc.irp.f @@ -1,14 +1,18 @@ program FSVD_trunc - implicit none + BEGIN_DOC - ! study precision variation with truncated SVD + ! perform a Full SVD + ! then truncate if you want END_DOC + + implicit none + read_wf = .True. TOUCH read_wf - ! !!! + call run() - ! !!! + end @@ -18,9 +22,16 @@ subroutine run integer :: mm, nn, i_state, low_rank, lrank_min, lrank_max integer :: i, j, k, l + double precision :: norm_psi, err_verif, err_tmp + double precision, allocatable :: U_FSVD(:,:), D_FSVD(:), Vt_FSVD(:,:), A_FSVD(:,:) double precision, allocatable :: Uezfio(:,:,:), Dezfio(:,:), Vezfio(:,:,:) + double precision, allocatable :: US(:,:), A_TSVD(:,:) + + double precision :: t0, t1, t2 + + call CPU_TIME(t0) i_state = 1 mm = n_det_alpha_unique @@ -42,28 +53,68 @@ subroutine run call svd_s( A_FSVD, size(A_FSVD,1), U_FSVD, size(U_FSVD,1), D_FSVD, Vt_FSVD, size(Vt_FSVD,1), mm, nn) print *, ' --- Full SVD: ok --- ' + call CPU_TIME(t1) + print *, (t1-t0)/60.d0, 'min' - !lrank_min = 100 - !lrank_max = nn - !do low_rank = lrank_min, lrank_max, 1 - ! err_verif = 0.d0 - ! do j = 1, nn - ! do i = 1, mm - ! err_tmp = 0.d0 - ! do l = 1, low_rank - ! err_tmp = err_tmp + D_FSVD(l) * U_FSVD(i,l) * Vt_FSVD(l,j) - ! enddo - ! err_verif = err_verif + (A_FSVD(i,j)-err_tmp) * (A_FSVD(i,j)-err_tmp) - ! enddo - ! enddo - ! print*, ' low rank = ', low_rank - ! print*, ' err verif (%) = ', 100.d0 * dsqrt(err_verif/norm_psi) - !enddo - ! ------------------------------------------------------------------------------------------------ - ! set to EZFIO for a fixed low rank + ! ---------------------------------------------------------------------- + ! check error + ! ---------------------------------------------------------------------- low_rank = min(mm,nn) + + !low_rank = 45 + !low_rank = 30 + !low_rank = 15 + + ! CO_old + !low_rank = 51 + !low_rank = 144 + ! CO_old + !low_rank = 133 + + !low_rank = 36 + !low_rank = 18 + !low_rank = 9 + !low_rank = 1 + + ! US = U x SV : + allocate( US(mm,low_rank) ) + US(:,:) = 0.d0 + do i = 1, mm + do l = 1, low_rank + US(i,l) = U_FSVD(i,l) * D_FSVD(l) + enddo + enddo + + ! A_TSVD = US x Vt_FSVD + allocate( A_TSVD(mm,nn) ) + A_TSVD(:,:) = 0.d0 + call dgemm( 'N', 'N', mm, nn, low_rank, 1.d0 & + , US , size(US ,1) & + , Vt_FSVD, size(Vt_FSVD,1) & + , 0.d0, A_TSVD, size(A_TSVD,1) ) + deallocatE(US) + + ! |A_FSVD-A_TSVD| + err_verif = 0.d0 + do j = 1, nn + do i = 1, mm + err_tmp = A_FSVD(i,j) - A_TSVD(i,j) + err_verif = err_verif + err_tmp * err_tmp + enddo + enddo + print*, ' rank = ', low_rank + print*, ' err verif (%) = ', 100.d0 * dsqrt(err_verif/norm_psi) + + deallocate( A_FSVD , A_TSVD ) + ! ---------------------------------------------------------------------- + + + ! ---------------------------------------------------------------------- + ! set to EZFIO for a fixed low rank + ! ---------------------------------------------------------------------- + allocate( Uezfio(mm,low_rank,1), Dezfio(low_rank,1), Vezfio(nn,low_rank,1)) do l = 1, low_rank @@ -76,22 +127,27 @@ subroutine run enddo enddo - !call ezfio_set_spindeterminants_n_det(N_det) - !call ezfio_set_spindeterminants_n_states(N_states) - !call ezfio_set_spindeterminants_n_det_alpha(n_det_alpha_unique) - !call ezfio_set_spindeterminants_n_det_beta(n_det_beta_unique) - !call ezfio_set_spindeterminants_psi_coef_matrix_rows(psi_bilinear_matrix_rows) - !call ezfio_set_spindeterminants_psi_coef_matrix_columns(psi_bilinear_matrix_columns) - !call ezfio_set_spindeterminants_psi_coef_matrix_values(psi_bilinear_matrix_values) + deallocate( U_FSVD, D_FSVD, Vt_FSVD ) + + call ezfio_set_spindeterminants_n_det(N_det) + call ezfio_set_spindeterminants_n_states(N_states) + call ezfio_set_spindeterminants_n_det_alpha(n_det_alpha_unique) + call ezfio_set_spindeterminants_n_det_beta(n_det_beta_unique) + call ezfio_set_spindeterminants_psi_coef_matrix_rows(psi_bilinear_matrix_rows) + call ezfio_set_spindeterminants_psi_coef_matrix_columns(psi_bilinear_matrix_columns) + call ezfio_set_spindeterminants_psi_coef_matrix_values(psi_bilinear_matrix_values) call ezfio_set_spindeterminants_n_svd_coefs(low_rank) call ezfio_set_spindeterminants_psi_svd_alpha(Uezfio) call ezfio_set_spindeterminants_psi_svd_beta(Vezfio ) call ezfio_set_spindeterminants_psi_svd_coefs(Dezfio) - - ! ------------------------------------------------------------------------------------------------ - deallocate( Uezfio, Dezfio, Vezfio ) - deallocate( U_FSVD, D_FSVD, Vt_FSVD ) + ! ---------------------------------------------------------------------- + + + call CPU_TIME(t2) + print *, '' + print *, ' end after' + print *, (t2-t0)/60.d0, 'min' end diff --git a/devel/svdwf/RSVD_ijHkl_det.irp.f b/devel/svdwf/RSVD_ijHkl_det.irp.f new file mode 100644 index 0000000..6c1e80f --- /dev/null +++ b/devel/svdwf/RSVD_ijHkl_det.irp.f @@ -0,0 +1,311 @@ +program RSVD_ijHkl_det + + BEGIN_DOC + ! + ! decompose < di dj | H | dk dl > by a RSVD: + ! + ! H_{ik jl} = < di dj | H | dk dl > + ! = \sum_{s=1}^{n_svd} U_{ik s} V_{jl s} + ! = \sum_{s=1}^{n_svd} U_{ik s} U_{jl s} + ! + ! where n_svd << min( NaxNa , NbxNb ) + ! + END_DOC + + read_wf = .true. + TOUCH read_wf + + call run() + +end + + + + +subroutine run() + + implicit none + + integer(bit_kind) :: det1(N_int,2), det2(N_int,2) + integer :: degree, i_state + double precision :: h12 + + integer*8 :: dim_Hdet + integer*8, allocatable :: Hdet_ik(:), Hdet_jl(:) + double precision, allocatable :: Hdet_v(:) + + integer :: dim_U , dim_V, dim_RSVD + + double precision :: t_beg, t_end + + call wall_time(t_beg) + + i_state = 1 + det1(:,1) = psi_det_alpha_unique(:,1) + det2(:,1) = psi_det_alpha_unique(:,1) + det1(:,2) = psi_det_beta_unique(:,1) + det2(:,2) = psi_det_beta_unique(:,1) + call get_excitation_degree_spin(det1(1,1),det2(1,1),degree,N_int) + call get_excitation_degree(det1,det2,degree,N_int) + call i_H_j(det1, det2, N_int, h12) + + + ! sparse representation of < di dj | H | dk dl > + !dim_Hdet = 7486379362 + dim_Hdet = 1000000 + allocate( Hdet_ik(dim_Hdet), Hdet_jl(dim_Hdet), Hdet_v(dim_Hdet) ) + call const_ij_hdet_kl_sparse(dim_hdet, hdet_ik, hdet_jl, hdet_v) + + + ! decompose Hdet by a Randomized SVD + dim_U = n_det_alpha_unique * n_det_alpha_unique + dim_V = n_det_beta_unique * n_det_beta_unique + dim_RSVD = min(dim_U, dim_V) + dim_RSVD = min(5000, dim_RSVD) + + call perform_RSVD(dim_U, dim_V, dim_RSVD, dim_Hdet, Hdet_ik, Hdet_jl, Hdet_v) + deallocate( Hdet_ik, Hdet_jl, Hdet_v ) + + call wall_time(t_end) + print *, ' end after (min)', (t_end-t_beg)/60.d0 + +end +! _________________________________________________________________________________________________ +! _________________________________________________________________________________________________ +! _________________________________________________________________________________________________ + + + + + + +! _________________________________________________________________________________________________ +! +subroutine const_ij_Hdet_kl_sparse(dim_Hdet, Hdet_ik, Hdet_jl, Hdet_v) + + implicit none + + integer*8, intent(in) :: dim_Hdet + + integer*8, intent(out) :: Hdet_ik(dim_Hdet), Hdet_jl(dim_Hdet) + double precision, intent(out) :: Hdet_v(dim_Hdet) + + integer(bit_kind) :: det1(N_int,2), det2(N_int,2) + integer :: degree + + integer :: na, nb, i, j, k, l, ii + double precision :: h12 + + double precision :: t1, t2 + + print *, "" + print *, " start const_ij_Hdet_kl_sparse" + call wall_time(t1) + + na = n_det_alpha_unique + nb = n_det_beta_unique + + ii = 0 + !$OMP PARALLEL DEFAULT(NONE) & + !$OMP PRIVATE(i,j,k,l,ii,h12,det1,det2,degree) & + !$OMP SHARED(na,nb,psi_det_alpha_unique,psi_det_beta_unique, & + !$OMP N_int,Hdet_ik,Hdet_jl,Hdet_v) + !$OMP DO + do l = 1, nb + det2(:,2) = psi_det_beta_unique(:,l) + do j = 1, nb + det1(:,2) = psi_det_beta_unique(:,j) + + call get_excitation_degree_spin(det1(1,2),det2(1,2),degree,N_int) + if(degree .gt. 2) cycle + + do k = 1, na + det2(:,1) = psi_det_alpha_unique(:,k) + do i = 1, na + det1(:,1) = psi_det_alpha_unique(:,i) + + call get_excitation_degree(det1,det2,degree,N_int) + if(degree .gt. 2) cycle + + call i_H_j(det1, det2, N_int, h12) + if(dabs(h12) .le. (1d-15)) cycle + + ii = ii + 1 + Hdet_ik(ii) = (i-1)*na + k + Hdet_jl(ii) = (j-1)*na + l + Hdet_v (ii) = h12 + enddo + enddo + enddo + enddo + !$OMP END DO + !$OMP END PARALLEL + + call wall_time(t2) + print *, " end const_ij_Hdet_kl_sparse after (min) ", (t2-t1)/60. + print *, "" + + if( ii .ne. dim_Hdet) then + print*, ' error in const_ij_Hdet_kl_sparse' + print*, ' dim supposed = ', dim_Hdet + print*, ' dim foundedi = ', ii + stop + end if + + return +end subroutine const_ij_Hdet_kl_sparse +! _________________________________________________________________________________________________ +! _________________________________________________________________________________________________ + + + + + +! _________________________________________________________________________________________________ +! +subroutine perform_RSVD(dim_U, dim_V, dim_RSVD, dim_Hdet, Hdet_ik, Hdet_jl, Hdet_v) + + include 'constants.include.F' + + implicit none + + integer, intent(in) :: dim_U, dim_V, dim_RSVD + integer*8, intent(in) :: dim_Hdet + integer*8, intent(in) :: Hdet_ik(dim_Hdet), Hdet_jl(dim_Hdet) + double precision, intent(in) :: Hdet_v(dim_Hdet) + + integer :: na, nb + integer :: iter, iter_max + integer :: ii, rr, ik, jl + double precision, allocatable :: GR(:,:) + double precision, allocatable :: Z(:,:), P(:,:), Yt(:,:), UYt(:,:) + double precision, allocatable :: U(:,:), V(:,:), D(:) + + na = n_det_alpha_unique + nb = n_det_beta_unique + + ! Z = Hdet x G + ! G: random gauss dist + allocate( Z(dim_U,dim_RSVD) ) + Z(:,:) = 0 + !$OMP PARALLEL DEFAULT(NONE) PRIVATE(ii, rr, ik, GR) & + !$OMP SHARED(dim_Hdet, dim_RSVD, Z, Hdet_ik, Hdet_v) + allocate( GR(dim_Hdet,2) ) + !$OMP DO + do rr = 1, dim_RSVD + call random_number(GR) + GR(:,1) = dsqrt(-2.d0*dlog(GR(:,1))) + GR(:,1) = GR(:,1) * dcos(dtwo_pi*GR(:,2)) + do ii = 1, dim_Hdet + ik = Hdet_ik(ii) + !jl = Hdet_jl(ii) + Z(ik,rr) = Z(ik,rr) + Hdet_v(ii) * GR(ii,1) + enddo + enddo + !$OMP END DO + deallocate(GR) + !$OMP END PARALLEL + + + ! parameter + iter_max = 10 + allocate( P(dim_V,dim_RSVD) ) + ! ------------------------------------------------------------------------------------------ + ! Power iterations + ! + do iter = 1, iter_max + + print *, ' power iteration ', iter, '/', iter_max + + !$OMP PARALLEL DEFAULT(NONE) PRIVATE(ii, rr, ik, jl) & + !$OMP SHARED(dim_Hdet, dim_RSVD, Z, P, Hdet_ik, Hdet_jl, Hdet_v) + + !$OMP DO + ! P = Hdet.T x Z + do rr = 1, dim_RSVD + P(:,rr) = 0.d0 + do ii = 1, dim_Hdet + ik = Hdet_ik(ii) + jl = Hdet_jl(ii) + P(jl,rr) = P(jl,rr) + Hdet_v(ii) * Z(ik,rr) + enddo + enddo + !$OMP END DO + + !$OMP BARRIER + + !$OMP DO + do rr = 1, dim_RSVD + Z(:,rr) = 0.d0 + do ii = 1, dim_Hdet + ik = Hdet_ik(ii) + jl = Hdet_jl(ii) + Z(ik,rr) = Z(ik,rr) + Hdet_v(ii) * P(jl,rr) + enddo + enddo + !$OMP END DO + + !$OMP END PARALLEL + + call ortho_qr(Z, size(Z,1), dim_U, dim_RSVD) + + enddo + ! + ! ------------------------------------------------------------------------------------------ + + ! Y = Z.T x Hdet + ! Yt = Hdet.T x Z + allocate( Yt(dim_V,dim_RSVD) ) + !$OMP PARALLEL DEFAULT(NONE) PRIVATE(ii, rr, ik, jl) & + !$OMP SHARED(dim_Hdet, dim_RSVD, Z, Yt, Hdet_ik, Hdet_jl, Hdet_v) + !$OMP DO + do rr = 1, dim_RSVD + Yt(:,rr) = 0.d0 + do ii = 1, dim_Hdet + ik = Hdet_ik(ii) + jl = Hdet_jl(ii) + Yt(jl,rr) = Yt(jl,rr) + Z(ik,rr) * Hdet_v(ii) + enddo + enddo + !$OMP END DO + !$OMP END PARALLEL + + ! Y = U x D x Vt + ! Yt = V x D x Ut + allocate( D(dim_RSVD), V(dim_V,dim_RSVD), UYt(dim_RSVD,dim_RSVD) ) + call svd(Yt, size(Yt,1), V, size(V,1), D, UYt, size(UYt,1), dim_V, dim_RSVD) + deallocate( Yt ) + + ! U = Z x UY + allocate( U(dim_U,dim_RSVD) ) + call dgemm('N', 'T', dim_U, dim_RSVD, dim_RSVD, 1.d0, Z, size(Z,1), UYt, size(UYt,1), 0.d0, U, size(U,1)) + deallocate( UYt, Z ) + + open(unit=41, file='u_det.txt', action='write') + do rr = 1, dim_RSVD + do ii = 1, dim_U + write(41,*) U(ii,rr) + enddo + enddo + close(41) + + ! v = u because H is symmetric + !open(unit=41, file='v_det.txt', action='write') + ! do rr = 1, dim_RSVD + ! do ii = 1, dim_V + ! write(41,*) V(ii,rr) + ! enddo + ! enddo + !close(41) + + open(unit=41, file='d_det.txt', action='write') + do rr = 1, dim_RSVD + write(41,*) D(rr), sum( D(1:rr)**2 ) + enddo + close(41) + + deallocate( U, D, V ) + +end subroutine perform_RSVD +! _________________________________________________________________________________________________ +! _________________________________________________________________________________________________ diff --git a/devel/svdwf/SQ_klHkl_v1.irp.f b/devel/svdwf/SQ_klHkl_v1.irp.f new file mode 100644 index 0000000..100b2ef --- /dev/null +++ b/devel/svdwf/SQ_klHkl_v1.irp.f @@ -0,0 +1,511 @@ +program SQ_klHkl_v1 + + implicit none + + BEGIN_DOC + ! perturbative approach to build psi_postsvd + END_DOC + + read_wf = .True. + TOUCH read_wf + + PROVIDE N_int + + call run() +end + + +subroutine run + + USE OMP_LIB + USE bitmasks + + implicit none + + integer(bit_kind) :: det1(N_int,2), det2(N_int,2) + integer :: degree, i_state + + integer :: i, j, k, l, m, n + double precision :: x, y, h12 + + double precision, allocatable :: Uref(:,:), Dref(:), Vtref(:,:), Aref(:,:), Vref(:,:) + + integer :: rank_max + double precision :: E0, overlop, Ept2 + double precision, allocatable :: H0(:,:) + double precision, allocatable :: eigvec0(:,:), eigval0(:), coeff_psi(:), coeff_tmp(:) + + integer :: ii, ia, ib + double precision, allocatable :: Hdiag(:), Hkl_save(:,:), Hkl_1d(:), Hkl_tmp(:,:), Hdiag_tmp(:) + + integer :: na_new, nb_new, ind_new, ind_gs + double precision :: ctmp, coeff_new + double precision, allocatable :: epsil(:), epsil_energ(:), check_ov(:) + + double precision, allocatable :: Uezfio(:,:,:), Dezfio(:,:), Vezfio(:,:,:) + + integer :: ibeg_alpha, ibeg_beta, iend_alpha, iend_beta + integer :: n_toselect, na_max, nb_max + integer, allocatable :: numalpha_toselect(:), numbeta_toselect(:) + + double precision :: t_beg, t_end, ti, tf + integer :: nb_taches + + !$OMP PARALLEL + nb_taches = OMP_GET_NUM_THREADS() + !$OMP END PARALLEL + + call wall_time(ti) + + i_state = 1 + + det1(:,1) = psi_det_alpha_unique(:,1) + det2(:,1) = psi_det_alpha_unique(:,1) + det1(:,2) = psi_det_beta_unique(:,1) + det2(:,2) = psi_det_beta_unique(:,1) + call get_excitation_degree_spin(det1(1,1),det2(1,1),degree,N_int) + call get_excitation_degree(det1,det2,degree,N_int) + call i_H_j(det1, det2, N_int, h12) + + ! --------------------------------------------------------------------------------------- + ! construct the initial CISD matrix + + print *, ' ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~' + print *, ' CISD matrix:', n_det_alpha_unique,'x',n_det_beta_unique + print *, ' N det :', N_det + print *, ' ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~' + + allocate( Aref(n_det_alpha_unique,n_det_beta_unique) ) + Aref(:,:) = 0.d0 + do k = 1, N_det + i = psi_bilinear_matrix_rows(k) + j = psi_bilinear_matrix_columns(k) + Aref(i,j) = psi_bilinear_matrix_values(k,i_state) + enddo + + ! + ! --------------------------------------------------------------------------------------- + + + + ! --------------------------------------------------------------------------------------- + ! perform a Full SVD + + allocate( Uref(n_det_alpha_unique,n_det_alpha_unique) ) + allocate( Dref(min(n_det_alpha_unique,n_det_beta_unique)) ) + allocate( Vtref(n_det_beta_unique,n_det_beta_unique) ) + + call wall_time(t_beg) + call svd_s(Aref, size(Aref,1), Uref, size(Uref,1), Dref, Vtref & + , size(Vtref,1), n_det_alpha_unique, n_det_beta_unique) + call wall_time(t_end) + print *, " SVD is performed after (min)", (t_end-t_beg)/60. + + deallocate( Aref , Dref ) + + allocate( Vref(n_det_beta_unique,n_det_beta_unique) ) + do l = 1, n_det_beta_unique + do i = 1, n_det_beta_unique + Vref(i,l) = Vtref(l,i) + enddo + enddo + deallocate( Vtref ) + + ! + ! --------------------------------------------------------------------------------------- + + + + ! --------------------------------------------------------------------------------------- + ! numerote | k l > toselect + + ibeg_alpha = 1 + iend_alpha = n_det_alpha_unique + na_max = iend_alpha - ibeg_alpha + 1 + + ibeg_beta = 1 + iend_beta = n_det_beta_unique + nb_max = iend_beta - ibeg_beta + 1 + + n_toselect = na_max * nb_max + + print *, ' na_max = ', na_max + print *, ' nb_max = ', nb_max + print *, ' n_toselect = ', n_toselect + + allocate( numalpha_toselect(n_toselect) , numbeta_toselect(n_toselect) ) + k = 0 + do i = ibeg_alpha, iend_alpha + do j = ibeg_beta, iend_beta + k = k + 1 + numalpha_toselect(k) = i + numbeta_toselect (k) = j + enddo + enddo + if( k.ne.n_toselect ) then + print *, " error in numbering" + stop + endif + + ! + ! --------------------------------------------------------------------------------------- + + double precision, allocatable :: A_ik(:,:), B_jl(:,:), T(:,:,:,:) + allocate( A_ik(n_det_alpha_unique,n_det_alpha_unique) , B_jl(n_det_beta_unique,n_det_beta_unique) ) + allocate( T(n_det_alpha_unique,n_det_alpha_unique,n_det_beta_unique,n_det_beta_unique ) ) + call const_AB(A_ik, B_jl) + call const_2b(T) + + allocate( Hdiag(n_toselect) ) + call const_Hdiag(n_toselect, Uref, Vref, numalpha_toselect, numbeta_toselect, A_ik, B_jl, T, Hdiag) + + deallocate( A_ik, B_jl, T ) + + open(UNIT=11, FILE="SQ_klHkl_v1.dat", ACTION="WRITE") + do i = 1, n_toselect + write(11, '(2(I5,2X), 5X, E15.7)') numalpha_toselect(i), numbeta_toselect(i), Hdiag(i) + enddo + close(11) + + deallocate( Hdiag ) + deallocate( Uref, Vref ) + deallocate( numalpha_toselect, numbeta_toselect ) + + call wall_time(tf) + + print *, ' ___________________________________________________________________' + print *, ' ' + !print *, " Execution avec ", nb_taches, " threads" + print *, " Execution avec 1 threads" + print *, " total elapsed time (min) = ", (tf-ti)/60.d0 + print *, ' ___________________________________________________________________' + + +end + + + + !/-\! !/-\! !/-\! !/-\! !/-\! !/-\! !/-\! !/-\! !/-\! + !---! !---! !---! !---! !---! !---! !---! !---! !---! + ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! + !___! !___! !___! !___! !___! !___! !___! !___! !___! + !___! !___! !___! !___! !___! !___! !___! !___! !___! + + !/-\! !/-\! !/-\! !/-\! !/-\! !/-\! !/-\! !/-\! !/-\! + !---! !---! !---! !---! !---! !---! !---! !---! !---! + ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! + !___! !___! !___! !___! !___! !___! !___! !___! !___! + !___! !___! !___! !___! !___! !___! !___! !___! !___! + + !/-\! !/-\! !/-\! !/-\! !/-\! !/-\! !/-\! !/-\! !/-\! + !---! !---! !---! !---! !---! !---! !---! !---! !---! + ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! + !___! !___! !___! !___! !___! !___! !___! !___! !___! + !___! !___! !___! !___! !___! !___! !___! !___! !___! + + !/-\! !/-\! !/-\! !/-\! !/-\! !/-\! !/-\! !/-\! !/-\! + !---! !---! !---! !---! !---! !---! !---! !---! !---! + ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! + !___! !___! !___! !___! !___! !___! !___! !___! !___! + !___! !___! !___! !___! !___! !___! !___! !___! !___! + + +subroutine const_AB(A_ik, B_jl) + + USE bitmasks + implicit none + + ! see one_e_dm_mo_alpha & one_e_dm_mo_beta in determinants/density_matrix.irp.f + + double precision, intent(out) :: A_ik(n_det_alpha_unique,n_det_alpha_unique) + double precision, intent(out) :: B_jl(n_det_beta_unique ,n_det_beta_unique ) + + integer :: na, nb + integer :: i, k, j, l, e + + integer(bit_kind) :: deti(N_int), detk(N_int), detj(N_int), detl(N_int) + double precision :: phase + integer :: degree, h1, h2, p1, p2 + integer :: exc(0:2,2) + + integer :: list(N_int*bit_kind_size), n_elements + + na = n_det_alpha_unique + nb = n_det_beta_unique + + A_ik(:,:) = 0.d0 + B_jl(:,:) = 0.d0 + + ! ----------------------------------------------------------------------------------------------------------- + ! Diagonal part + ! ----------------------------------------------------------------------------------------------------------- + + do i = 1, na + deti(1:N_int) = psi_det_alpha_unique(1:N_int,i) + list = 0 + call bitstring_to_list(deti, list, n_elements, N_int) + do e = 1, elec_alpha_num + A_ik(i,i) += mo_one_e_integrals(list(e),list(e)) + enddo + enddo + + do j = 1, nb + detj(1:N_int) = psi_det_beta_unique(1:N_int,j) + list = 0 + call bitstring_to_list(detj, list, n_elements, N_int) + do e = 1, elec_beta_num + B_jl(j,j) += mo_one_e_integrals(list(e),list(e)) + enddo + enddo + ! ----------------------------------------------------------------------------------------------------------- + ! ----------------------------------------------------------------------------------------------------------- + + + + ! ----------------------------------------------------------------------------------------------------------- + ! degree = 1 + ! ----------------------------------------------------------------------------------------------------------- + + do i = 1, na + deti(1:N_int) = psi_det_alpha_unique(1:N_int,i) + list = 0 + call bitstring_to_list(deti, list, n_elements, N_int) + do k = 1, na + detk(1:N_int) = psi_det_alpha_unique(1:N_int,k) + call get_excitation_degree_spin(deti, detk, degree, N_int) + if(degree .eq. 1) then + exc = 0 + call get_single_excitation_spin(deti, detk, exc, phase, N_int) + call decode_exc_spin(exc, h1, p1, h2, p2) + A_ik(i,k) += phase * mo_one_e_integrals(h1,p1) + !A_ik(i,k) += phase * mo_one_e_integrals(p1,h1) + endif + enddo + enddo + + do j = 1, nb + detj(1:N_int) = psi_det_beta_unique(1:N_int,j) + list = 0 + call bitstring_to_list(detj, list, n_elements, N_int) + do l = 1, nb + detl(1:N_int) = psi_det_beta_unique(1:N_int,l) + call get_excitation_degree_spin(detj, detl, degree, N_int) + if(degree .eq. 1) then + exc = 0 + call get_single_excitation_spin(detj, detl, exc, phase, N_int) + call decode_exc_spin(exc, h1, p1, h2, p2) + B_jl(j,l) += phase * mo_one_e_integrals(h1,p1) + !B_jl(j,l) += phase * mo_one_e_integrals(p1,h1) + endif + enddo + enddo + ! ----------------------------------------------------------------------------------------------------------- + ! ----------------------------------------------------------------------------------------------------------- + + return +end subroutine const_AB + + + + + +subroutine const_2b(T) + + USE bitmasks + implicit none + + double precision, external :: get_two_e_integral + + double precision, intent(out) :: T(n_det_alpha_unique,n_det_alpha_unique,n_det_beta_unique,n_det_beta_unique ) + + integer :: na, nb + integer :: i, k, j, l + + integer(bit_kind) :: psi_ij(N_int,2), psi_kl(N_int,2) + double precision :: phase + integer :: degree, h1, h2, p1, p2, s1, s2, e1, e2 + integer :: ii, jj + integer :: exc(0:2,2,2) + + integer :: occ(N_int*bit_kind_size,2), n_occ_alpha + + double precision :: two_body_fact + + na = n_det_alpha_unique + nb = n_det_beta_unique + + T(:,:,:,:) = 0.d0 + + ! ----------------------------------------------------------------------------------------------------------------- + do i = 1, na + psi_ij(1:N_int,1) = psi_det_alpha_unique(1:N_int,i) + do j = 1, nb + psi_ij(1:N_int,2) = psi_det_beta_unique(1:N_int,j) + + call bitstring_to_list(psi_ij(1,1), occ(1,1), n_occ_alpha, N_int) + call bitstring_to_list(psi_ij(1,2), occ(1,2), n_occ_alpha, N_int) + + do k = 1, na + psi_kl(1:N_int,1) = psi_det_alpha_unique(1:N_int,k) + do l = 1, nb + psi_kl(1:N_int,2) = psi_det_beta_unique(1:N_int,l) + + call get_excitation_degree(psi_ij, psi_kl, degree, N_int) + + two_body_fact = 0.d0 + + if(degree .eq. 2) then + + call get_double_excitation(psi_ij, psi_kl, exc, phase, N_int) + call decode_exc(exc, degree, h1, p1, h2, p2, s1, s2) + + select case(s1+s2) + case(2,4) + two_body_fact += phase * get_two_e_integral(h1, h2, p1, p2, mo_integrals_map) + two_body_fact -= phase * get_two_e_integral(h1, h2, p2, p1, mo_integrals_map) + case(3) + two_body_fact += 0.5d0 * phase * get_two_e_integral(h1, h2, p1, p2, mo_integrals_map) + two_body_fact += 0.5d0 * phase * get_two_e_integral(h2, h1, p2, p1, mo_integrals_map) + end select + + else if(degree .eq. 1) then + + call get_single_excitation(psi_ij, psi_kl, exc, phase, N_int) + call decode_exc(exc, degree, h1, p1, h2, p2, s1, s2) + + select case(s1) + case(1) + do ii = 1, elec_alpha_num + p2 = occ(ii,1) + h2 = p2 + two_body_fact += 0.5d0 * phase * get_two_e_integral(h1, h2, p1, p2, mo_integrals_map) + two_body_fact -= 0.5d0 * phase * get_two_e_integral(h1, h2, p2, p1, mo_integrals_map) + two_body_fact += 0.5d0 * phase * get_two_e_integral(h2, h1, p2, p1, mo_integrals_map) + two_body_fact -= 0.5d0 * phase * get_two_e_integral(h2, h1, p1, p2, mo_integrals_map) + enddo + do ii = 1, elec_beta_num + p2 = occ(ii,2) + h2 = p2 + two_body_fact += 0.5d0 * phase * get_two_e_integral(h1, h2, p1, p2, mo_integrals_map) + two_body_fact += 0.5d0 * phase * get_two_e_integral(h2, h1, p2, p1, mo_integrals_map) + enddo + case(2) + do ii = 1, elec_alpha_num + p2 = occ(ii,1) + h2 = p2 + two_body_fact += 0.5d0 * phase * get_two_e_integral(h1, h2, p1, p2, mo_integrals_map) + two_body_fact += 0.5d0 * phase * get_two_e_integral(h2, h1, p2, p1, mo_integrals_map) + enddo + do ii = 1, elec_beta_num + p2 = occ(ii,2) + h2 = p2 + two_body_fact += 0.5d0 * phase * get_two_e_integral(h1, h2, p1, p2, mo_integrals_map) + two_body_fact -= 0.5d0 * phase * get_two_e_integral(h1, h2, p2, p1, mo_integrals_map) + two_body_fact += 0.5d0 * phase * get_two_e_integral(h2, h1, p2, p1, mo_integrals_map) + two_body_fact -= 0.5d0 * phase * get_two_e_integral(h2, h1, p1, p2, mo_integrals_map) + enddo + end select + + else if(degree .eq. 0) then + + do ii = 1, elec_alpha_num + e1 = occ(ii,1) + do jj = 1, elec_alpha_num + e2 = occ(jj,1) + two_body_fact += 0.5d0 * get_two_e_integral(e1, e2, e1, e2, mo_integrals_map) + two_body_fact -= 0.5d0 * get_two_e_integral(e1, e2, e2, e1, mo_integrals_map) + enddo + do jj = 1, elec_beta_num + e2 = occ(jj,2) + two_body_fact += 0.5d0 * get_two_e_integral(e1, e2, e1, e2, mo_integrals_map) + two_body_fact += 0.5d0 * get_two_e_integral(e2, e1, e2, e1, mo_integrals_map) + enddo + enddo + do ii = 1, elec_beta_num + e1 = occ(ii,2) + do jj = 1, elec_beta_num + e2 = occ(jj,2) + two_body_fact += 0.5d0 * get_two_e_integral(e1, e2, e1, e2, mo_integrals_map) + two_body_fact -= 0.5d0 * get_two_e_integral(e1, e2, e2, e1, mo_integrals_map) + enddo + enddo + + end if + + T(i,k,j,l) = two_body_fact + enddo + enddo + enddo + enddo + ! ----------------------------------------------------------------------------------------------------------------- + + return +end subroutine const_2b + + + + + + + + + + + +subroutine const_Hdiag(n_toselect, Uref, Vref, numalpha_toselect, numbeta_toselect & + , A_ik, B_jl, T, Hdiag) + + implicit none + + integer, intent(in) :: n_toselect + integer, intent(in) :: numalpha_toselect(n_toselect), numbeta_toselect(n_toselect) + double precision, intent(in) :: Uref(n_det_alpha_unique,n_det_alpha_unique) + double precision, intent(in) :: Vref(n_det_beta_unique ,n_det_beta_unique) + double precision, intent(in) :: A_ik(n_det_alpha_unique,n_det_alpha_unique) + double precision, intent(in) :: B_jl(n_det_beta_unique ,n_det_beta_unique ) + double precision, intent(in) :: T(n_det_alpha_unique,n_det_alpha_unique,n_det_beta_unique,n_det_beta_unique ) + double precision, intent(out) :: Hdiag(n_toselect) + + integer :: na, nb + integer :: i, j, k, l, ii, jj, n + + na = n_det_alpha_unique + nb = n_det_beta_unique + + Hdiag(:) = 0.d0 + do n = 1, n_toselect + ii = numalpha_toselect(n) + jj = numbeta_toselect (n) + + do i = 1, na + do k = 1, na + Hdiag(n) += Uref(i,ii) * Uref(k,ii) * A_ik(i,k) + enddo + enddo + + do j = 1, nb + do l = 1, nb + Hdiag(n) += Vref(j,jj) * Vref(l,jj) * B_jl(j,l) + enddo + enddo + + do i = 1, na + do k = 1, na + do j = 1, nb + do l = 1, nb + Hdiag(n) += Uref(i,ii) * Uref(k,ii) * Vref(j,jj) * Vref(l,jj) * T(i,k,j,l) + enddo + enddo + enddo + enddo + + enddo + + + return +end subroutine const_Hdiag + + + + + diff --git a/devel/svdwf/SVD_rank.irp.f b/devel/svdwf/SVD_rank.irp.f new file mode 100644 index 0000000..62b6596 --- /dev/null +++ b/devel/svdwf/SVD_rank.irp.f @@ -0,0 +1,62 @@ + +program SVD_rank + + BEGIN_DOC + ! rank SVD + END_DOC + + implicit none + + read_wf = .True. + TOUCH read_wf + + call run() + +end + + +subroutine run + + implicit none + + integer :: mm, nn, mn, i_state, low_r + double precision, allocatable :: Uezf_FSVD(:,:,:), Dezf_FSVD(:,:), Vezf_FSVD(:,:,:) + double precision, allocatable :: Uezf_TSVD(:,:,:), Dezf_TSVD(:,:), Vezf_TSVD(:,:,:) + + i_state = 1 + mm = n_det_alpha_unique + nn = n_det_beta_unique + mn = min(mm,nn) + + + ! read TSVD + allocate( Uezf_FSVD(mm,mm,1), Dezf_FSVD(mn,1), Vezf_FSVD(nn,nn,1) ) + call ezfio_get_spindeterminants_psi_svd_alpha(Uezf_FSVD) + call ezfio_get_spindeterminants_psi_svd_beta (Vezf_FSVD) + call ezfio_get_spindeterminants_psi_svd_coefs(Dezf_FSVD) + + ! new TSVD + low_r = 100 + call ezfio_set_spindeterminants_n_svd_coefs(low_r) + + Dezf_TSVD( 1:low_r,1) = Dezf_FSVD( 1:low_r,1) + Uezf_TSVD(1:mm,1:low_r,1) = Uezf_FSVD(1:mm,1:low_r,1) + Vezf_TSVD(1:nn,1:low_r,1) = Vezf_FSVD(1:nn,1:low_r,1) + deallocate( Uezf_FSVD, Dezf_FSVD, Vezf_FSVD ) + + call ezfio_set_spindeterminants_psi_svd_alpha(Uezf_TSVD) + call ezfio_set_spindeterminants_psi_svd_beta (Vezf_TSVD) + call ezfio_set_spindeterminants_psi_svd_coefs(Dezf_TSVD) + deallocate( Uezf_TSVD, Dezf_TSVD, Vezf_TSVD ) + + + + !call ezfio_set_spindeterminants_n_det(N_det) + !call ezfio_set_spindeterminants_n_states(N_states) + !call ezfio_set_spindeterminants_n_det_alpha(n_det_alpha_unique) + !call ezfio_set_spindeterminants_n_det_beta(n_det_beta_unique) + !call ezfio_set_spindeterminants_psi_coef_matrix_rows(psi_bilinear_matrix_rows) + !call ezfio_set_spindeterminants_psi_coef_matrix_columns(psi_bilinear_matrix_columns) + !call ezfio_set_spindeterminants_psi_coef_matrix_values(psi_bilinear_matrix_values) + +end diff --git a/devel/svdwf/TSVD_err.irp.f b/devel/svdwf/TSVD_err.irp.f new file mode 100644 index 0000000..2f7833a --- /dev/null +++ b/devel/svdwf/TSVD_err.irp.f @@ -0,0 +1,116 @@ + +program TSVD_err + + BEGIN_DOC + ! study precision variation with truncated SVD + END_DOC + + implicit none + + read_wf = .True. + TOUCH read_wf + + call run() + +end + + +subroutine run + + implicit none + + integer :: mm, nn, i_state, low_rank, lrank_min, lrank_max + integer :: i, j, k, l + double precision :: norm_psi, err_verif, err_tmp + double precision, allocatable :: U_FSVD(:,:), D_FSVD(:), Vt_FSVD(:,:), A_FSVD(:,:) + double precision, allocatable :: US(:,:), A_TSVD(:,:) + + double precision :: tmp_acc + double precision, allocatable :: D2_FSVD(:) + + double precision :: t0, t1, t2 + + call CPU_TIME(t0) + + i_state = 1 + mm = n_det_alpha_unique + nn = n_det_beta_unique + + print *, ' matrix dimensions:', mm,'x',nn + print *, ' N det:', N_det + + allocate( A_FSVD(mm,nn), U_FSVD(mm,mm), D_FSVD(min(mm,nn)), Vt_FSVD(nn,nn) ) + + norm_psi = 0.d0 + A_FSVD(:,:) = 0.d0 + do k = 1, N_det + i = psi_bilinear_matrix_rows(k) + j = psi_bilinear_matrix_columns(k) + A_FSVD(i,j) = psi_bilinear_matrix_values(k,i_state) + norm_psi += psi_bilinear_matrix_values(k,i_state) * psi_bilinear_matrix_values(k,i_state) + enddo + + call svd_s( A_FSVD, size(A_FSVD,1), U_FSVD, size(U_FSVD,1), D_FSVD, Vt_FSVD, size(Vt_FSVD,1), mm, nn) + print *, ' --- Full SVD: ok after --- ' + call CPU_TIME(t1) + print *, (t1-t0)/60.d0, 'min' + + +! ! US = U x SV : +! allocate( US(mm,min(mm,nn)) ) +! US(:,:) = 0.d0 +! do i = 1, mm +! do l = 1, min(mm,nn) +! US(i,l) = U_FSVD(i,l) * D_FSVD(l) +! enddo +! enddo +! +! allocate( A_TSVD(mm,nn) ) +! A_TSVD(:,:) = 0.d0 +! lrank_min = 1 +! lrank_max = min(mm,nn) +! do low_rank = lrank_min, lrank_max, 1 +! +! ! A_TSVD = US x Vt_FSVD +! call dgemm( 'N', 'N', mm, nn, low_rank, 1.d0 & +! , US , size(US ,1) & +! , Vt_FSVD, size(Vt_FSVD,1) & +! , 0.d0, A_TSVD, size(A_TSVD,1) ) +! ! |A_FSVD-A_TSVD| +! err_verif = 0.d0 +! do j = 1, nn +! do i = 1, mm +! err_tmp = A_FSVD(i,j) - A_TSVD(i,j) +! err_verif = err_verif + err_tmp * err_tmp +! enddo +! enddo +! print*, low_rank, 100.d0 * dsqrt(err_verif/norm_psi) +! enddo +! deallocate( A_TSVD , US ) + + deallocate( A_FSVD, U_FSVD, Vt_FSVD ) + + allocate( D2_FSVD(min(mm,nn)) ) + do i = 1, min(mm,nn) + tmp_acc = 0.d0 + do j = 1, i + tmp_acc = tmp_acc + D_FSVD(j) * D_FSVD(j) + enddo + D2_FSVD(i) = tmp_acc + enddo + open(unit=11, file='d_svd.txt',action='write') + do i = 1, min(mm,nn) + write(11, *) D_FSVD(i), D2_FSVD(i), 1.d0-D2_FSVD(i) + enddo + close(11) + deallocate( D2_FSVD ) + + deallocate( D_FSVD ) + + + call CPU_TIME(t2) + print *, '' + print *, ' end after' + print *, (t2-t0)/60.d0, 'min' + +end diff --git a/devel/svdwf/checkSVD_EZ.irp.f b/devel/svdwf/checkSVD_EZ.irp.f new file mode 100644 index 0000000..dd64c8a --- /dev/null +++ b/devel/svdwf/checkSVD_EZ.irp.f @@ -0,0 +1,106 @@ + +program checkSVD_EZ + + BEGIN_DOC + ! save SVD manually + END_DOC + + implicit none + read_wf = .True. + TOUCH read_wf + + call run() + +end + + +subroutine run + + implicit none + + integer :: mm, nn, i_state, low_rank, lrank_min, lrank_max + integer :: i, j, k, l + double precision :: norm_psi, err_verif, err_tmp + + double precision, allocatable :: U_FSVD(:,:), D_FSVD(:), Vt_FSVD(:,:), V_FSVD(:,:), A_FSVD(:,:) + double precision, allocatable :: U_read(:,:), D_read(:), V_read(:,:) + + double precision :: t0, t1, t2 + + call CPU_TIME(t0) + + i_state = 1 + mm = n_det_alpha_unique + nn = n_det_beta_unique + + print *, ' matrix dimensions:', mm,'x',nn + print *, ' N det:', N_det + + allocate( A_FSVD(mm,nn), U_FSVD(mm,mm), D_FSVD(min(mm,nn)), Vt_FSVD(nn,nn) ) + + norm_psi = 0.d0 + A_FSVD(:,:) = 0.d0 + do k = 1, N_det + i = psi_bilinear_matrix_rows(k) + j = psi_bilinear_matrix_columns(k) + A_FSVD(i,j) = psi_bilinear_matrix_values(k,i_state) + norm_psi += psi_bilinear_matrix_values(k,i_state) * psi_bilinear_matrix_values(k,i_state) + enddo + + call svd_s( A_FSVD, size(A_FSVD,1), U_FSVD, size(U_FSVD,1), D_FSVD, Vt_FSVD, size(Vt_FSVD,1), mm, nn) + print *, ' --- Full SVD: ok --- ' + call CPU_TIME(t1) + print *, (t1-t0)/60.d0, 'min' + + deallocate( A_FSVD ) + allocate( V_FSVD(nn,nn) ) + do i = 1, nn + do j = 1, nn + V_FSVD(i,j) = Vt_FSVD(j,i) + enddo + enddo + deallocate(Vt_FSVD) + ! ------------------------------------------ + + + allocate( U_read(mm,mm), D_read(min(mm,nn)), V_read(nn,nn) ) + call ezfio_get_spindeterminants_psi_svd_coefs(D_read) + call ezfio_get_spindeterminants_psi_svd_alpha(U_read) + call ezfio_get_spindeterminants_psi_svd_beta (V_read) + + err_verif = 0.d0 + do i = 1, min(mm,nn) + err_tmp = D_FSVD(i) - D_read(i) + err_verif += err_tmp * err_tmp + enddo + print *, ' error on D:', err_verif + deallocate( D_FSVD, D_read ) + + err_verif = 0.d0 + do j = 1, nn + do i = 1, mm + err_tmp = U_FSVD(i,j) - U_read(i,j) + err_verif = err_verif + err_tmp * err_tmp + enddo + enddo + print *, ' error on U:', err_verif + deallocate( U_FSVD, U_read ) + + err_verif = 0.d0 + do j = 1, nn + do i = 1, mm + err_tmp = V_FSVD(i,j) - V_read(i,j) + err_verif = err_verif + err_tmp * err_tmp + enddo + enddo + print *, ' error on V:', err_verif + deallocate( V_FSVD, V_read ) + + + + call CPU_TIME(t2) + print *, '' + print *, ' end after' + print *, (t2-t0)/60.d0, 'min' + +end diff --git a/devel/svdwf/cr2_work/invSVD.py b/devel/svdwf/cr2_work/invSVD.py new file mode 100644 index 0000000..1f5b104 --- /dev/null +++ b/devel/svdwf/cr2_work/invSVD.py @@ -0,0 +1,131 @@ +#!/usr/bin/env python + +import numpy as np +import subprocess +import sys, os +import time +from datetime import datetime + +QP_PATH=os.environ["QP_ROOT"]+"/external/ezfio/Python/" +sys.path.insert(0,QP_PATH) + +from ezfio import ezfio + +#____________________________________________________________________________________ +# +def read_ci_dress_svd(): + + Ci_dress_svd_val = np.zeros((n_svd)) + Ci_dress_svd_err = np.zeros((n_svd)) + + beg_read = results.find('Ci_dress_svd : [ ') + len( 'Ci_dress_svd : [ ' ) + end_read = len(results) + vect_buf = results[beg_read:end_read] + vect_buf = vect_buf.split( '\n' ) + + for iline in range(1, n_svd+1): + line = vect_buf[iline].split() + + # check + indc = int( line[0] ) + if( indc != iline ): + print(' Error in reading Ci_dress_svd') + print(' indc = {}'.format(indc) ) + print(' iline = {}'.format(iline) ) + break + + else: + Ci_dress_svd_val[indc-1] = float( line[2] ) + Ci_dress_svd_err[indc-1] = float( line[4] ) + # !!! + # !!! + # !!! + + return(Ci_dress_svd_val,Ci_dress_svd_err) +#____________________________________________________________________________________ + + +#____________________________________________________________________________________ +# +def SVD_to_C(): + + d_svd = np.array(ezfio.get_spindeterminants_psi_svd_coefs()) + U_svd = np.array(ezfio.get_spindeterminants_psi_svd_alpha()) + V_svd = np.array(ezfio.get_spindeterminants_psi_svd_beta()) + + d_svd = d_svd[0,:] + U_svd = U_svd[0,:,:].T + V_svd = V_svd[0,:,:].T + + C_mat_val = np.dot(U_svd,np.dot(np.diagflat(d_svd),V_svd.T)) + + n_det = ezfio.get_spindeterminants_n_det() + i_row = np.array(ezfio.get_spindeterminants_psi_coef_matrix_rows()) + j_col = np.array(ezfio.get_spindeterminants_psi_coef_matrix_columns()) + + C_val = np.zeros((n_det)) + for k in range(n_det): + i = i_row[k] - 1 + j = j_col[k] - 1 + C_val[k] = C_mat_val[i,j] + + return(C_val) +#____________________________________________________________________________________ + + + + +#____________________________________________________________________________________ +# +def save_to_file(v_val, name_f): + + with open(name_f, 'a') as ff: + for i in range(len(v_val)): + ff.write(' {} {}\n'.format(i, v_val[i])) +#____________________________________________________________________________________ + + + +if __name__ == '__main__': + t0 = time.time() + + # _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ + # + #EZFIO_file = sys.argv[1] + + #EZFIO_file = "/home/aammar/qp2/src/svdwf/cr2_work/cr2_1p6_compactSVD50_DMC_fast" + EZFIO_file = "/home/aammar/qp2/src/svdwf/cr2_work/cr2_1p6_compactSVD50_DMC_fast_2" + #EZFIO_file = "/home/aammar/qp2/src/svdwf/cr2_work/cr2_1p6_compactSVD50_it1_DMC_fast" + + #EZFIO_file = "/home/aammar/qp2/src/svdwf/cr2_work/cr2_1p6_TSVD50_DMC_fast" + #EZFIO_file = "/home/aammar/qp2/src/svdwf/cr2_work/cr2_1p6_TSVD50_it1_DMC_fast" + # _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ + + ezfio.set_file(EZFIO_file) + + n_svd = ezfio.get_spindeterminants_n_svd_coefs() + + print(" ") + print(" Today's date:", datetime.now() ) + print(" EZFIO file = {}".format(EZFIO_file)) + print(" n_svd = {}\n".format(n_svd) ) + if(n_svd <= 0): + print(" n_svd <=0") + break + + C_val = SVD_to_C() + print(C_val) + #save_to_file(C_val, 'C_val.txt') + + # _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ + # + # SAVE TO EZFIO + # + ezfio.set_spindeterminants_psi_coef_matrix_values( C_val ) + ezfio.set_spindeterminants_n_svd_coefs(-1) + # _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ + # + + print("end after {:.3f} minutes".format((time.time()-t0)/60.) ) + # !!! +# !!! diff --git a/devel/svdwf/delta_2bTSVD_v0.irp.f b/devel/svdwf/delta_2bTSVD_v0.irp.f new file mode 100644 index 0000000..a57facf --- /dev/null +++ b/devel/svdwf/delta_2bTSVD_v0.irp.f @@ -0,0 +1,203 @@ +program delta_2bTSVD_v0 + + BEGIN_DOC + ! !!! + END_DOC + + implicit none + + read_wf = .True. + touch read_wf + + call run() + +end + + + +subroutine run() + + implicit none + + integer :: ii, ii_i, ii_j, k, l + integer :: na, nb, nsvd + integer :: n_TSVD + integer :: n_tmp + double precision, allocatable :: U(:,:), V(:,:) + + double precision, allocatable :: delta0_det(:), delta1_det(:) + double precision, allocatable :: delta_O(:,:), delta_D(:) + double precision, allocatable :: delta_tmp(:) + + double precision :: t1, t2 + + na = n_det_alpha_unique + nb = n_det_beta_unique + + call ezfio_get_spindeterminants_n_svd_coefs(nsvd) + allocate( u(na,nsvd) , v(nb,nsvd) ) + + print *, ' start read SVD vectors' + call wall_time(t1) + call ezfio_get_spindeterminants_psi_svd_alpha(U) + call ezfio_get_spindeterminants_psi_svd_beta (V) + call wall_time(t2) + print *, ' end read SVD vectors after (min)', (t2-t1)/60.d0 + + allocate( delta0_det(N_det) ) + call ezfio_get_dmc_dress_dmc_delta_h(delta0_det) + + + ! --------------------------------------------- + ! --------------------------------------------- + ! parameters + ! + !n_TSVD = 100 + read *, n_TSVD + + print *, " --- delta_2bTSVD_v0 ---" + print *, " n_TSVD =", n_TSVD + print *, " tot =", n_TSVD * n_TSVD + & + nsvd - n_TSVD + ! + ! --------------------------------------------- + ! --------------------------------------------- + ! --------------------------------------------- + + n_tmp = n_TSVD + 1 + + allocate( delta_O(1:n_TSVD,1:n_TSVD) ) + allocate( delta_D(n_tmp:nsvd) ) + call obtenir_deltaSVD_2b(nsvd, n_TSVD, U, V, delta0_det, delta_O, delta_D) + deallocate( delta0_det ) + + allocate( delta1_det(N_det) ) + delta1_det(1:N_det) = 0.d0 + + !$OMP PARALLEL DEFAULT(NONE) & + !$OMP SHARED(nsvd, n_TSVD, n_tmp, N_det, U, V, delta1_det, delta_O, delta_D & + !$OMP , psi_bilinear_matrix_rows, psi_bilinear_matrix_columns) & + !$OMP PRIVATE(k, l, ii, ii_i, ii_j, delta_tmp) + allocate( delta_tmp(N_det) ) + delta_tmp(1:N_det) = 0.d0 + !$OMP DO + do ii = 1, N_det + ii_i = psi_bilinear_matrix_rows (ii) + ii_j = psi_bilinear_matrix_columns(ii) + do l = 1, n_TSVD + delta_tmp(ii) = delta_tmp(ii) + U(ii_i,l) * V(ii_j,l) * delta_D(l) + do k = 1, n_TSVD + delta_tmp(ii) = delta_tmp(ii) + U(ii_i,k) * V(ii_j,l) * delta_O(k,l) + enddo + enddo + enddo + !$OMP END DO + !$OMP CRITICAL + do ii = 1, N_det + delta1_det(ii) = delta1_det(ii) + delta_tmp(ii) + enddo + !$OMP END CRITICAL + deallocate( delta_tmp ) + !$OMP END PARALLEL + + deallocate( U , V ) + deallocate( delta_O , delta_D ) + + call ezfio_set_dmc_dress_dmc_delta_h(delta1_det) + deallocate( delta1_det ) + +end + + + + + +! _______________________________________________________________________________________________________ +! +! [ delta_SVD ]_kl = < dup_SVD ddn_SVD | H_tilde - H | psi > +! = \sum_{i,j} U_{i,k} V_{j,l} < dup_i ddn_j | H_tilde - H | psi > +! +subroutine obtenir_deltaSVD_2b(nsvd, n_TSVD, U, V, delta0_det, delta_O, delta_D) + + implicit none + + integer, intent(in) :: nsvd, n_TSVD + double precision, intent(in) :: U(n_det_alpha_unique,nsvd), V(n_det_beta_unique,nsvd) + double precision, intent(in) :: delta0_det(N_det) + + double precision, intent(out) :: delta_O(1:n_TSVD,1:n_TSVD) + double precision, intent(out) :: delta_D(n_TSVD+1:nsvd) + + integer :: n_tmp + integer :: k, l, ii, ii_i, ii_j + double precision, allocatable :: delta_tmp(:,:), delta1d_tmp(:) + + n_tmp = n_TSVD + 1 + + + ! -------------------------------------------------------------------------------- + ! + delta_O(1:n_TSVD,1:n_TSVD) = 0.d0 + !$OMP PARALLEL DEFAULT(NONE) & + !$OMP SHARED(n_TSVD, N_det, U, V, delta0_det, delta_O & + !$OMP , psi_bilinear_matrix_rows, psi_bilinear_matrix_columns) & + !$OMP PRIVATE(k, l, ii, ii_i, ii_j, delta_tmp) + allocate( delta_tmp(1:n_TSVD,1:n_TSVD) ) + delta_tmp(1:n_TSVD,1:n_TSVD) = 0.d0 + !$OMP DO + do l = 1, n_TSVD + do k = 1, n_TSVD + do ii = 1, N_det + ii_i = psi_bilinear_matrix_rows (ii) + ii_j = psi_bilinear_matrix_columns(ii) + delta_tmp(k,l) = delta_tmp(k,l) + U(ii_i,k) * V(ii_j,l) * delta0_det(ii) + enddo + enddo + enddo + !$OMP END DO + !$OMP CRITICAL + do l = 1, n_TSVD + do k = 1, n_TSVD + delta_O(k,l) = delta_O(k,l) + delta_tmp(k,l) + enddo + enddo + !$OMP END CRITICAL + deallocate(delta_tmp) + !$OMP END PARALLEL + ! + ! -------------------------------------------------------------------------------- + + + + ! -------------------------------------------------------------------------------- + ! + delta_D(n_tmp:nsvd) = 0.d0 + !$OMP PARALLEL DEFAULT(NONE) & + !$OMP SHARED(nsvd, n_tmp, N_det, U, V, delta0_det, delta_D & + !$OMP , psi_bilinear_matrix_rows, psi_bilinear_matrix_columns) & + !$OMP PRIVATE(l, ii, ii_i, ii_j, delta1d_tmp) + allocate( delta1d_tmp(n_tmp:nsvd) ) + delta1d_tmp(n_tmp:nsvd) = 0.d0 + !$OMP DO + do l = n_tmp, nsvd + do ii = 1, N_det + ii_i = psi_bilinear_matrix_rows (ii) + ii_j = psi_bilinear_matrix_columns(ii) + delta1d_tmp(l) = delta1d_tmp(l) + U(ii_i,l) * V(ii_j,l) * delta0_det(ii) + enddo + enddo + !$OMP END DO + !$OMP CRITICAL + do l = n_tmp, nsvd + delta_D(l) = delta_D(l) + delta1d_tmp(l) + enddo + !$OMP END CRITICAL + deallocate(delta1d_tmp) + !$OMP END PARALLEL + ! + ! -------------------------------------------------------------------------------- + + return +end subroutine obtenir_deltaSVD_2b +! _______________________________________________________________________________________________________ +! _______________________________________________________________________________________________________ diff --git a/devel/svdwf/delta_3bSVD_v0.irp.f b/devel/svdwf/delta_3bSVD_v0.irp.f new file mode 100644 index 0000000..c6ffce6 --- /dev/null +++ b/devel/svdwf/delta_3bSVD_v0.irp.f @@ -0,0 +1,164 @@ +program delta_3bSVD_v0 + + BEGIN_DOC + ! !!! + END_DOC + + implicit none + + read_wf = .True. + touch read_wf + + call run() + +end + + + +subroutine run() + + implicit none + + integer :: ii, ii_i, ii_j, k, l + integer :: na, nb, nsvd + integer :: n_tmp, n_TSVD + double precision, allocatable :: U(:,:), V(:,:), S(:) + + double precision, allocatable :: delta0_det(:), delta1_det(:), deltaSVD_kl(:,:) + double precision, allocatable :: delta_tmp(:) + + na = n_det_alpha_unique + nb = n_det_beta_unique + + ! read SVD vectors + call ezfio_get_spindeterminants_n_svd_coefs(nsvd) + allocate( U(na,nsvd), S(nsvd), V(nb,nsvd) ) + call ezfio_get_spindeterminants_psi_svd_alpha(U) + call ezfio_get_spindeterminants_psi_svd_beta (V) + call ezfio_get_spindeterminants_psi_svd_coefs(S) + + allocate( delta0_det(N_det) ) + call ezfio_get_dmc_dress_dmc_delta_h(delta0_det) + + allocate( deltaSVD_kl(nsvd,nsvd) ) + deltaSVD_kl(1:nsvd,1:nsvd) = 0.d0 + call obtenir_deltaSVD_kl(nsvd, U, V, delta0_det, deltaSVD_kl) + + + + ! --------------------------------------------- + ! parameters + n_TSVD = 4 + ! --------------------------------------------- + + + + n_tmp = n_TSVD + 1 + + ! [ delta ]_mn = \sum_{k,l} U_{m,k} delta_SVD_{k,l} V_{n,l} + allocate( delta1_det(N_det) ) + delta1_det(1:N_det) = 0.d0 + + !$OMP PARALLEL DEFAULT(NONE) & + !$OMP SHARED(nsvd, n_TSVD, n_tmp, N_det, U, V, deltaSVD_kl, delta1_det & + !$OMP , psi_bilinear_matrix_rows, psi_bilinear_matrix_columns) & + !$OMP PRIVATE(k, l, ii, ii_i, ii_j, delta_tmp) + + allocate( delta_tmp(N_det) ) + delta_tmp(1:N_det) = 0.d0 + + !$OMP DO + do ii = 1, N_det + ii_i = psi_bilinear_matrix_rows (ii) + ii_j = psi_bilinear_matrix_columns(ii) + + do l = 1, n_TSVD + do k = 1, nsvd + delta_tmp(ii) = delta_tmp(ii) + U(ii_i,k) * V(ii_j,l) * deltaSVD_kl(k,l) + enddo + enddo + do l = n_tmp, nsvd + do k = 1, n_TSVD + delta_tmp(ii) = delta_tmp(ii) + U(ii_i,k) * V(ii_j,l) * deltaSVD_kl(k,l) + enddo + enddo + + enddo + !$OMP END DO + + !$OMP CRITICAL + do ii = 1, N_det + delta1_det(ii) = delta1_det(ii) + delta_tmp(ii) + enddo + !$OMP END CRITICAL + + deallocate( delta_tmp ) + !$OMP END PARALLEL + + call ezfio_set_dmc_dress_dmc_delta_h(delta1_det) + + deallocate( U , S , V ) + deallocate( deltaSVD_kl ) + deallocate( delta0_det , delta1_det ) + +end + + + + + +! _______________________________________________________________________________________________________ +! +! [ delta_SVD ]_kl = < dup_SVD ddn_SVD | H_tilde - H | psi > +! = \sum_{i,j} U_{i,k} V_{j,l} < dup_i ddn_j | H_tilde - H | psi > +! +subroutine obtenir_deltaSVD_kl(nsvd, U, V, delta0_det, deltaSVD_kl) + + implicit none + + integer, intent(in) :: nsvd + double precision, intent(in) :: U(n_det_alpha_unique,nsvd), V(n_det_beta_unique,nsvd) + double precision, intent(in) :: delta0_det(N_det) + + double precision, intent(out) :: deltaSVD_kl(nsvd,nsvd) + + integer :: k, l, ii, ii_i, ii_j + double precision, allocatable :: delta_tmp(:,:) + + deltaSVD_kl(1:nsvd,1:nsvd) = 0.d0 + + !$OMP PARALLEL DEFAULT(NONE) & + !$OMP SHARED(nsvd, N_det, U, V, delta0_det, deltaSVD_kl & + !$OMP , psi_bilinear_matrix_rows, psi_bilinear_matrix_columns) & + !$OMP PRIVATE(k, l, ii, ii_i, ii_j, delta_tmp) + + allocate( delta_tmp(nsvd,nsvd) ) + delta_tmp(1:nsvd,1:nsvd) = 0.d0 + + !$OMP DO + do l = 1, nsvd + do k = 1, nsvd + do ii = 1, N_det + ii_i = psi_bilinear_matrix_rows (ii) + ii_j = psi_bilinear_matrix_columns(ii) + delta_tmp(k,l) = delta_tmp(k,l) + U(ii_i,k) * V(ii_j,l) * delta0_det(ii) + enddo + enddo + enddo + !$OMP END DO + + !$OMP CRITICAL + do l = 1, nsvd + do k = 1, nsvd + deltaSVD_kl(k,l) = deltaSVD_kl(k,l) + delta_tmp(k,l) + enddo + enddo + !$OMP END CRITICAL + + deallocate(delta_tmp) + !$OMP END PARALLEL + + return +end subroutine obtenir_deltaSVD_kl +! _______________________________________________________________________________________________________ +! _______________________________________________________________________________________________________ diff --git a/devel/svdwf/delta_3bSVD_v1.irp.f b/devel/svdwf/delta_3bSVD_v1.irp.f new file mode 100644 index 0000000..6ae6eb0 --- /dev/null +++ b/devel/svdwf/delta_3bSVD_v1.irp.f @@ -0,0 +1,195 @@ +program delta_3bSVD_v1 + + BEGIN_DOC + ! !!! + END_DOC + + implicit none + + read_wf = .True. + touch read_wf + + call run() + +end + + + +subroutine run() + + implicit none + + integer :: ii, ii_i, ii_j, k, l + integer :: na, nb, nsvd + integer :: n_tmp, n_TSVD + double precision, allocatable :: U(:,:), V(:,:), S(:) + + double precision, allocatable :: delta0_det(:), delta1_det(:) + double precision, allocatable :: deltaSVD1_kl(:,:), deltaSVD2_kl(:,:) + double precision, allocatable :: delta_tmp(:) + + na = n_det_alpha_unique + nb = n_det_beta_unique + + call ezfio_get_spindeterminants_n_svd_coefs(nsvd) + + ! read SVD vectors + allocate( u(na,nsvd) , v(nb,nsvd) ) + call ezfio_get_spindeterminants_psi_svd_alpha(U) + call ezfio_get_spindeterminants_psi_svd_beta (V) + +! allocate( s(nsvd) ) +! call ezfio_get_spindeterminants_psi_svd_coefs(S) + + allocate( delta0_det(N_det) ) + call ezfio_get_dmc_dress_dmc_delta_h(delta0_det) + + + ! --------------------------------------------- + ! parameters + + n_TSVD = 50 + + print *, " --- delta_3bSVD_v1 ---" + print *, " n_TSVD =", n_TSVD + print *, " tot =", nsvd * n_TSVD + & + (nsvd-n_TSVD)*n_TSVD + + ! + ! --------------------------------------------- + + n_tmp = n_TSVD + 1 + + allocate( deltaSVD1_kl(1:nsvd,1:n_TSVD) , deltaSVD2_kl(1:n_TSVD,n_tmp:nsvd) ) + call obtenir_deltaSVD_3b(nsvd, n_TSVD, U, V, delta0_det, deltaSVD1_kl, deltaSVD2_kl) + deallocate( delta0_det ) + + ! [ delta ]_mn = \sum_{k,l} U_{m,k} delta_SVD_{k,l} V_{n,l} + allocate( delta1_det(N_det) ) + delta1_det(1:N_det) = 0.d0 + + !$OMP PARALLEL DEFAULT(NONE) & + !$OMP SHARED(nsvd, n_TSVD, n_tmp, N_det, U, V, delta1_det, deltaSVD1_kl & + !$OMP , deltaSVD2_kl, psi_bilinear_matrix_rows, psi_bilinear_matrix_columns) & + !$OMP PRIVATE(k, l, ii, ii_i, ii_j, delta_tmp) + allocate( delta_tmp(N_det) ) + delta_tmp(1:N_det) = 0.d0 + !$OMP DO + do ii = 1, N_det + ii_i = psi_bilinear_matrix_rows (ii) + ii_j = psi_bilinear_matrix_columns(ii) + do l = 1, n_TSVD + do k = 1, nsvd + delta_tmp(ii) = delta_tmp(ii) + U(ii_i,k) * V(ii_j,l) * deltaSVD1_kl(k,l) + enddo + enddo + do l = n_tmp, nsvd + do k = 1, n_TSVD + delta_tmp(ii) = delta_tmp(ii) + U(ii_i,k) * V(ii_j,l) * deltaSVD2_kl(k,l) + enddo + enddo + enddo + !$OMP END DO + !$OMP CRITICAL + do ii = 1, N_det + delta1_det(ii) = delta1_det(ii) + delta_tmp(ii) + enddo + !$OMP END CRITICAL + deallocate( delta_tmp ) + !$OMP END PARALLEL + +! deallocate( S ) + deallocate( U , V ) + deallocate( deltaSVD1_kl, deltaSVD2_kl ) + + call ezfio_set_dmc_dress_dmc_delta_h(delta1_det) + deallocate( delta1_det ) + +end + + + + + +! _______________________________________________________________________________________________________ +! +! [ delta_SVD ]_kl = < dup_SVD ddn_SVD | H_tilde - H | psi > +! = \sum_{i,j} U_{i,k} V_{j,l} < dup_i ddn_j | H_tilde - H | psi > +! +subroutine obtenir_deltaSVD_3b(nsvd, n_TSVD, U, V, delta0_det, deltaSVD1_kl, deltaSVD2_kl) + + implicit none + + integer, intent(in) :: nsvd, n_TSVD + double precision, intent(in) :: U(n_det_alpha_unique,nsvd), V(n_det_beta_unique,nsvd) + double precision, intent(in) :: delta0_det(N_det) + + double precision, intent(out) :: deltaSVD1_kl(1:nsvd,1:n_TSVD) + double precision, intent(out) :: deltaSVD2_kl(1:n_TSVD,n_TSVD+1:nsvd) + + integer :: n_tmp + integer :: k, l, ii, ii_i, ii_j + double precision, allocatable :: delta_tmp(:,:) + + n_tmp = n_TSVD + 1 + deltaSVD1_kl(1:nsvd,1:n_TSVD) = 0.d0 + deltaSVD2_kl(1:n_TSVD,n_tmp:nsvd) = 0.d0 + + !$OMP PARALLEL DEFAULT(NONE) & + !$OMP SHARED(nsvd, n_TSVD, N_det, U, V, delta0_det, deltaSVD1_kl & + !$OMP , psi_bilinear_matrix_rows, psi_bilinear_matrix_columns) & + !$OMP PRIVATE(k, l, ii, ii_i, ii_j, delta_tmp) + allocate( delta_tmp(1:nsvd,1:n_TSVD) ) + delta_tmp(1:nsvd,1:n_TSVD) = 0.d0 + !$OMP DO + do l = 1, n_TSVD + do k = 1, nsvd + do ii = 1, N_det + ii_i = psi_bilinear_matrix_rows (ii) + ii_j = psi_bilinear_matrix_columns(ii) + delta_tmp(k,l) = delta_tmp(k,l) + U(ii_i,k) * V(ii_j,l) * delta0_det(ii) + enddo + enddo + enddo + !$OMP END DO + !$OMP CRITICAL + do l = 1, n_TSVD + do k = 1, nsvd + deltaSVD1_kl(k,l) = deltaSVD1_kl(k,l) + delta_tmp(k,l) + enddo + enddo + !$OMP END CRITICAL + deallocate(delta_tmp) + !$OMP END PARALLEL + + !$OMP PARALLEL DEFAULT(NONE) & + !$OMP SHARED(nsvd, n_TSVD, n_tmp, N_det, U, V, delta0_det, deltaSVD2_kl & + !$OMP , psi_bilinear_matrix_rows, psi_bilinear_matrix_columns) & + !$OMP PRIVATE(k, l, ii, ii_i, ii_j, delta_tmp) + allocate( delta_tmp(1:n_TSVD,n_tmp:nsvd) ) + delta_tmp(1:n_TSVD,n_tmp:nsvd) = 0.d0 + !$OMP DO + do l = n_tmp, nsvd + do k = 1, n_TSVD + do ii = 1, N_det + ii_i = psi_bilinear_matrix_rows (ii) + ii_j = psi_bilinear_matrix_columns(ii) + delta_tmp(k,l) = delta_tmp(k,l) + U(ii_i,k) * V(ii_j,l) * delta0_det(ii) + enddo + enddo + enddo + !$OMP END DO + !$OMP CRITICAL + do l = n_tmp, nsvd + do k = 1, n_TSVD + deltaSVD2_kl(k,l) = deltaSVD2_kl(k,l) + delta_tmp(k,l) + enddo + enddo + !$OMP END CRITICAL + deallocate(delta_tmp) + !$OMP END PARALLEL + + return +end subroutine obtenir_deltaSVD_3b +! _______________________________________________________________________________________________________ +! _______________________________________________________________________________________________________ diff --git a/devel/svdwf/delta_4bTSVD_v0.irp.f b/devel/svdwf/delta_4bTSVD_v0.irp.f new file mode 100644 index 0000000..62496ef --- /dev/null +++ b/devel/svdwf/delta_4bTSVD_v0.irp.f @@ -0,0 +1,305 @@ +program delta_4bTSVD_v0 + + BEGIN_DOC + ! !!! + END_DOC + + implicit none + + read_wf = .True. + touch read_wf + + call run() + +end + + + +subroutine run() + + implicit none + + integer :: ii, ii_i, ii_j, k, l + integer :: na, nb, nsvd + integer :: n_TSVD, La, lla, Lb, llb + integer :: n_tmp + double precision, allocatable :: U(:,:), V(:,:) + + double precision, allocatable :: delta0_det(:), delta1_det(:) + double precision, allocatable :: delta_O(:,:), delta_D(:), delta_A(:,:), delta_B(:,:) + double precision, allocatable :: delta_tmp(:) + + double precision :: t1, t2 + + na = n_det_alpha_unique + nb = n_det_beta_unique + + call ezfio_get_spindeterminants_n_svd_coefs(nsvd) + allocate( u(na,nsvd) , v(nb,nsvd) ) + + print *, ' start read SVD vectors' + call wall_time(t1) + call ezfio_get_spindeterminants_psi_svd_alpha(U) + call ezfio_get_spindeterminants_psi_svd_beta (V) + call wall_time(t2) + print *, ' end read SVD vectors after (min)', (t2-t1)/60.d0 + + allocate( delta0_det(N_det) ) + call ezfio_get_dmc_dress_dmc_delta_h(delta0_det) + + + ! --------------------------------------------- + ! --------------------------------------------- + ! parameters + ! + !n_TSVD = 100 + read *, n_TSVD + + !La = nsvd + !lla = 3 + read *, La + read *, lla + + !Lb = nsvd + !llb = 3 + read *, Lb + read *, llb + + print *, " --- delta_4bTSVD_v0 ---" + print *, " n_TSVD =", n_TSVD + print *, " La =", La + print *, " lla =", lla + print *, " Lb =", Lb + print *, " llb =", llb + print *, " tot =", (La-n_TSVD)*lla + & + (Lb-n_TSVD)*llb + & + n_TSVD * n_TSVD + & + nsvd - n_TSVD + ! + ! --------------------------------------------- + ! --------------------------------------------- + ! --------------------------------------------- + + n_tmp = n_TSVD + 1 + + allocate( delta_O(1:n_TSVD,1:n_TSVD) ) + allocate( delta_A(n_tmp:La,1:lla) ) + allocate( delta_B(1:llb,n_tmp:Lb) ) + allocate( delta_D(n_tmp:nsvd) ) + call obtenir_deltaSVD_4b( nsvd, n_TSVD, La, lla, Lb, llb, U, V, delta0_det & + , delta_O, delta_A, delta_B, delta_D ) + deallocate( delta0_det ) + + allocate( delta1_det(N_det) ) + delta1_det(1:N_det) = 0.d0 + + !$OMP PARALLEL DEFAULT(NONE) & + !$OMP SHARED(nsvd, n_TSVD, n_tmp, La, lla, Lb, llb, N_det, U, V & + !$OMP , delta1_det, delta_O, delta_D, delta_A, delta_B & + !$OMP , psi_bilinear_matrix_rows, psi_bilinear_matrix_columns) & + !$OMP PRIVATE(k, l, ii, ii_i, ii_j, delta_tmp) + allocate( delta_tmp(N_det) ) + delta_tmp(1:N_det) = 0.d0 + !$OMP DO + do ii = 1, N_det + ii_i = psi_bilinear_matrix_rows (ii) + ii_j = psi_bilinear_matrix_columns(ii) + do l = 1, n_TSVD + delta_tmp(ii) = delta_tmp(ii) + U(ii_i,l) * V(ii_j,l) * delta_D(l) + do k = 1, n_TSVD + delta_tmp(ii) = delta_tmp(ii) + U(ii_i,k) * V(ii_j,l) * delta_O(k,l) + enddo + enddo + do l = 1, lla + do k = n_tmp, La + delta_tmp(ii) = delta_tmp(ii) + U(ii_i,k) * V(ii_j,l) * delta_A(k,l) + enddo + enddo + do l = n_tmp, Lb + do k = 1, llb + delta_tmp(ii) = delta_tmp(ii) + U(ii_i,k) * V(ii_j,l) * delta_B(k,l) + enddo + enddo + enddo + !$OMP END DO + !$OMP CRITICAL + do ii = 1, N_det + delta1_det(ii) = delta1_det(ii) + delta_tmp(ii) + enddo + !$OMP END CRITICAL + deallocate( delta_tmp ) + !$OMP END PARALLEL + + deallocate( U , V ) + deallocate( delta_O, delta_A, delta_B, delta_D ) + + call ezfio_set_dmc_dress_dmc_delta_h(delta1_det) + deallocate( delta1_det ) + +end + + + + + +! _______________________________________________________________________________________________________ +! +! [ delta_SVD ]_kl = < dup_SVD ddn_SVD | H_tilde - H | psi > +! = \sum_{i,j} U_{i,k} V_{j,l} < dup_i ddn_j | H_tilde - H | psi > +! +subroutine obtenir_deltaSVD_4b( nsvd, n_TSVD, La, lla, Lb, llb, U, V, delta0_det & + , delta_O, delta_A, delta_B, delta_D ) + + implicit none + + integer, intent(in) :: nsvd, n_TSVD, La, lla, Lb, llb + double precision, intent(in) :: U(n_det_alpha_unique,nsvd), V(n_det_beta_unique,nsvd) + double precision, intent(in) :: delta0_det(N_det) + + double precision, intent(out) :: delta_O(1:n_TSVD,1:n_TSVD) + double precision, intent(out) :: delta_A(n_TSVD+1:La,1:lla) + double precision, intent(out) :: delta_B(1:llb,n_TSVD+1:Lb) + double precision, intent(out) :: delta_D(n_TSVD+1:nsvd) + + integer :: n_tmp + integer :: k, l, ii, ii_i, ii_j + double precision, allocatable :: delta_tmp(:,:), delta1d_tmp(:) + + n_tmp = n_TSVD + 1 + + + ! -------------------------------------------------------------------------------- + ! + delta_O(1:n_TSVD,1:n_TSVD) = 0.d0 + !$OMP PARALLEL DEFAULT(NONE) & + !$OMP SHARED(n_TSVD, N_det, U, V, delta0_det, delta_O & + !$OMP , psi_bilinear_matrix_rows, psi_bilinear_matrix_columns) & + !$OMP PRIVATE(k, l, ii, ii_i, ii_j, delta_tmp) + allocate( delta_tmp(1:n_TSVD,1:n_TSVD) ) + delta_tmp(1:n_TSVD,1:n_TSVD) = 0.d0 + !$OMP DO + do l = 1, n_TSVD + do k = 1, n_TSVD + do ii = 1, N_det + ii_i = psi_bilinear_matrix_rows (ii) + ii_j = psi_bilinear_matrix_columns(ii) + delta_tmp(k,l) = delta_tmp(k,l) + U(ii_i,k) * V(ii_j,l) * delta0_det(ii) + enddo + enddo + enddo + !$OMP END DO + !$OMP CRITICAL + do l = 1, n_TSVD + do k = 1, n_TSVD + delta_O(k,l) = delta_O(k,l) + delta_tmp(k,l) + enddo + enddo + !$OMP END CRITICAL + deallocate(delta_tmp) + !$OMP END PARALLEL + ! + ! -------------------------------------------------------------------------------- + + + + ! -------------------------------------------------------------------------------- + ! + delta_D(n_tmp:nsvd) = 0.d0 + !$OMP PARALLEL DEFAULT(NONE) & + !$OMP SHARED(nsvd, n_tmp, N_det, U, V, delta0_det, delta_D & + !$OMP , psi_bilinear_matrix_rows, psi_bilinear_matrix_columns) & + !$OMP PRIVATE(l, ii, ii_i, ii_j, delta1d_tmp) + allocate( delta1d_tmp(n_tmp:nsvd) ) + delta1d_tmp(n_tmp:nsvd) = 0.d0 + !$OMP DO + do l = n_tmp, nsvd + do ii = 1, N_det + ii_i = psi_bilinear_matrix_rows (ii) + ii_j = psi_bilinear_matrix_columns(ii) + delta1d_tmp(l) = delta1d_tmp(l) + U(ii_i,l) * V(ii_j,l) * delta0_det(ii) + enddo + enddo + !$OMP END DO + !$OMP CRITICAL + do l = n_tmp, nsvd + delta_D(l) = delta_D(l) + delta1d_tmp(l) + enddo + !$OMP END CRITICAL + deallocate(delta1d_tmp) + !$OMP END PARALLEL + ! + ! -------------------------------------------------------------------------------- + + + + + ! -------------------------------------------------------------------------------- + ! + delta_A(n_tmp:La,1:lla) = 0.d0 + !$OMP PARALLEL DEFAULT(NONE) & + !$OMP SHARED(n_tmp, La, lla, N_det, U, V, delta0_det, delta_A & + !$OMP , psi_bilinear_matrix_rows, psi_bilinear_matrix_columns) & + !$OMP PRIVATE(k, l, ii, ii_i, ii_j, delta_tmp) + allocate( delta_tmp(n_tmp:La,1:lla) ) + delta_tmp(n_tmp:La,1:lla) = 0.d0 + !$OMP DO + do l = 1, lla + do k = n_tmp, La + do ii = 1, N_det + ii_i = psi_bilinear_matrix_rows (ii) + ii_j = psi_bilinear_matrix_columns(ii) + delta_tmp(k,l) = delta_tmp(k,l) + U(ii_i,k) * V(ii_j,l) * delta0_det(ii) + enddo + enddo + enddo + !$OMP END DO + !$OMP CRITICAL + do l = 1, lla + do k = n_tmp, La + delta_A(k,l) = delta_A(k,l) + delta_tmp(k,l) + enddo + enddo + !$OMP END CRITICAL + deallocate(delta_tmp) + !$OMP END PARALLEL + ! + ! -------------------------------------------------------------------------------- + + + + ! -------------------------------------------------------------------------------- + ! + delta_B(1:llb,n_tmp:Lb) = 0.d0 + !$OMP PARALLEL DEFAULT(NONE) & + !$OMP SHARED(n_tmp, Lb, llb, N_det, U, V, delta0_det, delta_B & + !$OMP , psi_bilinear_matrix_rows, psi_bilinear_matrix_columns) & + !$OMP PRIVATE(k, l, ii, ii_i, ii_j, delta_tmp) + allocate( delta_tmp(1:llb,n_tmp:Lb) ) + delta_tmp(1:llb,n_tmp:Lb) = 0.d0 + !$OMP DO + do l = n_tmp, Lb + do k = 1, llb + do ii = 1, N_det + ii_i = psi_bilinear_matrix_rows (ii) + ii_j = psi_bilinear_matrix_columns(ii) + delta_tmp(k,l) = delta_tmp(k,l) + U(ii_i,k) * V(ii_j,l) * delta0_det(ii) + enddo + enddo + enddo + !$OMP END DO + !$OMP CRITICAL + do l = n_tmp, Lb + do k = 1, llb + delta_B(k,l) = delta_B(k,l) + delta_tmp(k,l) + enddo + enddo + !$OMP END CRITICAL + deallocate(delta_tmp) + !$OMP END PARALLEL + ! + ! -------------------------------------------------------------------------------- + + return +end subroutine obtenir_deltaSVD_4b +! _______________________________________________________________________________________________________ +! _______________________________________________________________________________________________________ diff --git a/devel/svdwf/delta_FSVD_v0.irp.f b/devel/svdwf/delta_FSVD_v0.irp.f new file mode 100644 index 0000000..33119d1 --- /dev/null +++ b/devel/svdwf/delta_FSVD_v0.irp.f @@ -0,0 +1,250 @@ +program delta_FSVD_v0 + + BEGIN_DOC + ! !!! + END_DOC + + implicit none + + read_wf = .True. + touch read_wf + + my_grid_becke = .True. + my_n_pt_r_grid = 30 + my_n_pt_a_grid = 170 + touch my_grid_becke my_n_pt_r_grid my_n_pt_a_grid + + extra_grid_type_sgn = 1 + touch extra_grid_type_sgn + + my_extra_grid_becke = .False. + touch my_extra_grid_becke + + print*,'Warning : the Becke grid parameters are automatically set to ' + print*,'my_n_pt_a_grid = ',my_n_pt_a_grid + print*,'my_n_pt_r_grid = ',my_n_pt_r_grid + if(linear_tc) then + three_body_h_tc = .False. + touch three_body_h_tc + grad_squared = .False. + touch grad_squared + endif + if(read_tc_ints) then + call read_fcidump_1_tc + endif + + call run() + +end + + + +subroutine run() + + implicit none + + integer :: ii, ii_i, ii_j, k, l + integer :: na, nb, nsvd + double precision, allocatable :: U(:,:), V(:,:), S(:) + double precision, allocatable :: deltaDet_ex(:), deltaDet_ap(:), deltaSVD_kl(:,:) + + na = n_det_alpha_unique + nb = n_det_beta_unique + + ! read SVD vectors + call ezfio_get_spindeterminants_n_svd_coefs(nsvd) + allocate( U(na,nsvd), S(nsvd), V(nb,nsvd) ) + call ezfio_get_spindeterminants_psi_svd_alpha(U) + call ezfio_get_spindeterminants_psi_svd_beta (V) + call ezfio_get_spindeterminants_psi_svd_coefs(S) + + !allocate( deltaSVD_kk(nsvd) ) + !call obtenir_deltaSVD_kk(nsvd, U, V, deltaSVD_kk) + allocate( deltaSVD_kl(nsvd,nsvd) ) + call obtenir_deltaSVD_kl(nsvd, U, V, deltaSVD_kl) + + allocate( deltaDet_ex(N_det) , deltaDet_ap(N_det) ) + do ii = 1, N_det + ii_i = psi_bilinear_matrix_rows (ii) + ii_j = psi_bilinear_matrix_columns(ii) + + deltaDet_ex(ii) = 0.d0 + deltaDet_ap(ii) = 0.d0 + do k = 1, nsvd + deltaDet_ap(ii) = deltaDet_ap(ii) + U(ii_i,k) * V(ii_j,k) * deltaSVD_kl(k,k) + do l = 1, nsvd + deltaDet_ex(ii) = deltaDet_ex(ii) + U(ii_i,k) * V(ii_j,l) * deltaSVD_kl(k,l) + enddo + enddo + + print *, deltaDet_ex(ii) , deltaDet_ap(ii) + enddo + + !call ezfio_set_dmc_dress_dmc_delta_h(delta_Det_ex) + + deallocate( U , S , V ) + deallocate( deltaSVD_kl ) + deallocate( deltaDet_ex , deltaDet_ap ) + +end + + + + +! _______________________________________________________________________________________________________ +! +! [ delta_SVD ]_kk = < dup_SVD ddn_SVD | H_tilde - H | psi > +! = \sum_{i,j} U_{i,k} V_{j,k} < dup_i ddn_j | H_tilde - H | psi > +! +subroutine obtenir_deltaSVD_kk(nsvd, U, V, deltaSVD_kk) + + implicit none + + integer, intent(in) :: nsvd + double precision, intent(in) :: U(n_det_alpha_unique,nsvd), V(n_det_beta_unique,nsvd) + double precision, intent(out) :: deltaSVD_kk(nsvd) + + integer :: i_state, na, nb + integer :: k, ii, jj, ii_i, ii_j, jj_i, jj_j + double precision :: tmp_k, tmp_ij, coef_jj + + integer(bit_kind) :: det_ii(N_int,2), det_jj(N_int,2) + double precision :: hmono, heff, hderiv, hthree, htilde_ij, hij, delta_mat + + PROVIDE scalar_mu_r_pot_physicist_mo deriv_mu_r_pot_physicist_mo + PROVIDE three_body_3_index three_body_3_index_exch_12 three_body_3_index_exch_13 three_body_3_index_exch_23 + PROVIDE three_body_5_index three_body_5_index_exch_13 three_body_5_index_exch_32 + PROVIDE three_body_4_index three_body_4_index_exch_12 three_body_4_index_exch_12_part + + + i_state = 1 + na = n_det_alpha_unique + nb = n_det_beta_unique + + deltaSVD_kk(:) = 0.d0 + do k = 1, nsvd + + tmp_k = 0.d0 + do ii = 1, N_det + ii_i = psi_bilinear_matrix_rows (ii) + ii_j = psi_bilinear_matrix_columns(ii) + + det_ii(:,1) = psi_det_alpha_unique(:,ii_i) + det_ii(:,2) = psi_det_beta_unique (:,ii_j) + + !tmp_ij = < dup_i ddn_j | H_tilde - H | psi > + tmp_ij = 0.d0 + do jj = 1, N_det + jj_i = psi_bilinear_matrix_rows (jj) + jj_j = psi_bilinear_matrix_columns(jj) + + coef_jj = psi_bilinear_matrix_values(jj,i_state) + det_jj(:,1) = psi_det_alpha_unique(:,jj_i) + det_jj(:,2) = psi_det_beta_unique (:,jj_j) + + call htilde_mat(det_ii, det_jj, hmono, heff, hderiv, hthree, htilde_ij) + call i_H_j(det_ii, det_jj, N_int, hij) + delta_mat = htilde_ij - hij + + tmp_ij = tmp_ij + coef_jj * delta_mat + enddo + + tmp_k = tmp_k + U(ii_i,k) * V(ii_j,k) * tmp_ij + enddo + + deltaSVD_kk(k) = tmp_k + enddo + + return +end subroutine obtenir_deltaSVD_kk +! _______________________________________________________________________________________________________ +! _______________________________________________________________________________________________________ + + + + + + +! _______________________________________________________________________________________________________ +! +! [ delta_SVD ]_kl = < dup_SVD ddn_SVD | H_tilde - H | psi > +! = \sum_{i,j} U_{i,k} V_{j,l} < dup_i ddn_j | H_tilde - H | psi > +! +subroutine obtenir_deltaSVD_kl(nsvd, U, V, deltaSVD_kl) + + implicit none + + integer, intent(in) :: nsvd + double precision, intent(in) :: U(n_det_alpha_unique,nsvd), V(n_det_beta_unique,nsvd) + double precision, intent(out) :: deltaSVD_kl(nsvd,nsvd) + + integer :: i_state, na, nb + integer :: k, l, ii, jj, ii_i, ii_j, jj_i, jj_j + double precision :: tmp_kl, tmp_ij, coef_jj + + integer(bit_kind) :: det_ii(N_int,2), det_jj(N_int,2) + double precision :: hmono, heff, hderiv, hthree, htilde_ij, hij, delta_mat + + PROVIDE scalar_mu_r_pot_physicist_mo deriv_mu_r_pot_physicist_mo + PROVIDE three_body_3_index three_body_3_index_exch_12 three_body_3_index_exch_13 three_body_3_index_exch_23 + PROVIDE three_body_5_index three_body_5_index_exch_13 three_body_5_index_exch_32 + PROVIDE three_body_4_index three_body_4_index_exch_12 three_body_4_index_exch_12_part + + i_state = 1 + na = n_det_alpha_unique + nb = n_det_beta_unique + + ! ! ! + det_ii(:,1) = psi_det_alpha_unique(:,1) + det_ii(:,2) = psi_det_beta_unique (:,1) + det_jj(:,1) = psi_det_alpha_unique(:,1) + det_jj(:,2) = psi_det_beta_unique (:,1) + call htilde_mat(det_ii, det_jj, hmono, heff, hderiv, hthree, htilde_ij) + call i_H_j(det_ii, det_jj, N_int, hij) + ! ! ! + + + print *, ' --- start delta SVD calcul ---' + + deltaSVD_kl(:,:) = 0.d0 + do k = 1, nsvd + do l = 1, nsvd + + tmp_kl = 0.d0 + do ii = 1, N_det + ii_i = psi_bilinear_matrix_rows (ii) + ii_j = psi_bilinear_matrix_columns(ii) + + det_ii(:,1) = psi_det_alpha_unique(:,ii_i) + det_ii(:,2) = psi_det_beta_unique (:,ii_j) + + !tmp_ij = < dup_i ddn_j | H_tilde - H | psi > + tmp_ij = 0.d0 + do jj = 1, N_det + jj_i = psi_bilinear_matrix_rows (jj) + jj_j = psi_bilinear_matrix_columns(jj) + + coef_jj = psi_bilinear_matrix_values(jj,i_state) + det_jj(:,1) = psi_det_alpha_unique(:,jj_i) + det_jj(:,2) = psi_det_beta_unique (:,jj_j) + + call htilde_mat(det_ii, det_jj, hmono, heff, hderiv, hthree, htilde_ij) + call i_H_j(det_ii, det_jj, N_int, hij) + delta_mat = htilde_ij - hij + + tmp_ij = tmp_ij + coef_jj * delta_mat + enddo + + tmp_kl = tmp_kl + U(ii_i,k) * V(ii_j,l) * tmp_ij + enddo + + deltaSVD_kl(k,l) = tmp_kl + enddo + enddo + + print *, ' --- end delta SVD calcul ---' + + return +end subroutine obtenir_deltaSVD_kl +! _______________________________________________________________________________________________________ +! _______________________________________________________________________________________________________ diff --git a/devel/svdwf/delta_FSVD_v1.irp.f b/devel/svdwf/delta_FSVD_v1.irp.f new file mode 100644 index 0000000..0ecaf6f --- /dev/null +++ b/devel/svdwf/delta_FSVD_v1.irp.f @@ -0,0 +1,197 @@ +program delta_FSVD_v1 + + BEGIN_DOC + ! !!! + END_DOC + + implicit none + + read_wf = .True. + touch read_wf + + my_grid_becke = .True. + my_n_pt_r_grid = 30 + my_n_pt_a_grid = 170 + touch my_grid_becke my_n_pt_r_grid my_n_pt_a_grid + + extra_grid_type_sgn = 1 + touch extra_grid_type_sgn + + my_extra_grid_becke = .False. + touch my_extra_grid_becke + + print*,'Warning : the Becke grid parameters are automatically set to ' + print*,'my_n_pt_a_grid = ',my_n_pt_a_grid + print*,'my_n_pt_r_grid = ',my_n_pt_r_grid + if(linear_tc) then + three_body_h_tc = .False. + touch three_body_h_tc + grad_squared = .False. + touch grad_squared + endif + if(read_tc_ints) then + call read_fcidump_1_tc + endif + + call run() + +end + + + +subroutine run() + + implicit none + + integer :: ii, ii_i, ii_j, k, l + integer :: na, nb, nsvd + double precision, allocatable :: U(:,:), V(:,:), S(:) + double precision, allocatable :: deltaDet_ex(:), deltaDet_ap(:), deltaSVD_kl(:,:) + + na = n_det_alpha_unique + nb = n_det_beta_unique + + ! read SVD vectors + call ezfio_get_spindeterminants_n_svd_coefs(nsvd) + allocate( U(na,nsvd), S(nsvd), V(nb,nsvd) ) + call ezfio_get_spindeterminants_psi_svd_alpha(U) + call ezfio_get_spindeterminants_psi_svd_beta (V) + call ezfio_get_spindeterminants_psi_svd_coefs(S) + + !allocate( deltaSVD_kk(nsvd) ) + !call obtenir_deltaSVD_kk(nsvd, U, V, deltaSVD_kk) + allocate( deltaSVD_kl(nsvd,nsvd) ) + call obtenir_deltaSVD_kl(nsvd, U, V, deltaSVD_kl) + + allocate( deltaDet_ex(N_det) , deltaDet_ap(N_det) ) + do ii = 1, N_det + ii_i = psi_bilinear_matrix_rows (ii) + ii_j = psi_bilinear_matrix_columns(ii) + + deltaDet_ex(ii) = 0.d0 +! deltaDet_ap(ii) = 0.d0 + do k = 1, nsvd +! deltaDet_ap(ii) = deltaDet_ap(ii) + U(ii_i,k) * V(ii_j,k) * deltaSVD_kl(k,k) + do l = 1, nsvd + deltaDet_ex(ii) = deltaDet_ex(ii) + U(ii_i,k) * V(ii_j,l) * deltaSVD_kl(k,l) + enddo + enddo + +! print *, deltaDet_ex(ii) , deltaDet_ap(ii) + enddo + + call ezfio_set_dmc_dress_dmc_delta_h(deltaDet_ex) + + deallocate( U , S , V ) + deallocate( deltaSVD_kl ) + deallocate( deltaDet_ex , deltaDet_ap ) + +end + + + + + +! _______________________________________________________________________________________________________ +! +! [ delta_SVD ]_kl = < dup_SVD ddn_SVD | H_tilde - H | psi > +! = \sum_{i,j} U_{i,k} V_{j,l} < dup_i ddn_j | H_tilde - H | psi > +! +subroutine obtenir_deltaSVD_kl(nsvd, U, V, deltaSVD_kl) + + use bitmasks + implicit none + + integer, intent(in) :: nsvd + double precision, intent(in) :: U(n_det_alpha_unique,nsvd), V(n_det_beta_unique,nsvd) + double precision, intent(out) :: deltaSVD_kl(nsvd,nsvd) + + integer :: i_state + integer :: k, l, ii, jj, ii_i, ii_j, jj_i, jj_j + + integer(bit_kind) :: det_ii(N_int,2), det_jj(N_int,2) + double precision :: hmono, heff, hderiv, hthree, htilde_ij, hij, delta_mat + + double precision, allocatable :: delta_det(:) + + PROVIDE scalar_mu_r_pot_physicist_mo deriv_mu_r_pot_physicist_mo + PROVIDE three_body_3_index three_body_3_index_exch_12 three_body_3_index_exch_13 three_body_3_index_exch_23 + PROVIDE three_body_5_index three_body_5_index_exch_13 three_body_5_index_exch_32 + PROVIDE three_body_4_index three_body_4_index_exch_12 three_body_4_index_exch_12_part + + + i_state = 1 + + ! ! ! + det_ii(:,1) = psi_det_alpha_unique(:,1) + det_ii(:,2) = psi_det_beta_unique (:,1) + det_jj(:,1) = psi_det_alpha_unique(:,1) + det_jj(:,2) = psi_det_beta_unique (:,1) + call htilde_mat(det_ii, det_jj, hmono, heff, hderiv, hthree, htilde_ij) + call i_H_j(det_ii, det_jj, N_int, hij) + ! ! ! + + print *, ' --- start delta SVD calcul ---' + + ! ------------------------------------------------------------------------- + ! < dup_i ddn_j | H_tilde - H | psi > + allocate( delta_det(N_det) ) + delta_det(:) = 0.d0 + + !$OMP PARALLEL DO DEFAULT(NONE) SCHEDULE(dynamic,8) & + !$OMP SHARED(N_det, i_state, N_int, psi_bilinear_matrix_rows & + !$OMP , psi_bilinear_matrix_columns, psi_bilinear_matrix_values & + !$OMP , psi_det_alpha_unique, psi_det_beta_unique, delta_det) & + !$OMP PRIVATE(ii, ii_i, ii_j, jj, jj_i, jj_j, det_ii, det_jj & + !$OMP , hmono, heff, hderiv, hthree, htilde_ij, hij) + do ii = 1, N_det + ii_i = psi_bilinear_matrix_rows (ii) + ii_j = psi_bilinear_matrix_columns(ii) + + det_ii(:,1) = psi_det_alpha_unique(:,ii_i) + det_ii(:,2) = psi_det_beta_unique (:,ii_j) + + do jj = 1, N_det + jj_i = psi_bilinear_matrix_rows (jj) + jj_j = psi_bilinear_matrix_columns(jj) + + det_jj(:,1) = psi_det_alpha_unique(:,jj_i) + det_jj(:,2) = psi_det_beta_unique (:,jj_j) + + call htilde_mat(det_ii, det_jj, hmono, heff, hderiv, hthree, htilde_ij) + call i_H_j(det_ii, det_jj, N_int, hij) + + delta_det(ii) = delta_det(ii) + (htilde_ij-hij) * psi_bilinear_matrix_values(jj,i_state) + enddo + enddo + !$OMP END PARALLEL DO + ! ------------------------------------------------------------------------- + + + !call dset_order(delta_det, psi_bilinear_matrix_order, N_det) + + deltaSVD_kl(:,:) = 0.d0 + !$OMP PARALLEL DO DEFAULT(NONE) SCHEDULE(dynamic,8) & + !$OMP SHARED(nsvd, N_det, U, V, delta_det, deltaSVD_kl & + !$OMP , psi_bilinear_matrix_rows, psi_bilinear_matrix_columns) & + !$OMP PRIVATE(k, l, ii, ii_i, ii_j) + do l = 1, nsvd + do k = 1, nsvd + do ii = 1, N_det + ii_i = psi_bilinear_matrix_rows (ii) + ii_j = psi_bilinear_matrix_columns(ii) + + deltaSVD_kl(k,l) = deltaSVD_kl(k,l) + U(ii_i,k) * V(ii_j,l) * delta_det(ii) + enddo + enddo + enddo + !$OMP END PARALLEL DO + + deallocate( delta_det ) + + print *, ' --- end delta SVD calcul ---' + + return +end subroutine obtenir_deltaSVD_kl +! _______________________________________________________________________________________________________ +! _______________________________________________________________________________________________________ diff --git a/devel/svdwf/delta_FSVD_v2.irp.f b/devel/svdwf/delta_FSVD_v2.irp.f new file mode 100644 index 0000000..9bb59e0 --- /dev/null +++ b/devel/svdwf/delta_FSVD_v2.irp.f @@ -0,0 +1,145 @@ +program delta_FSVD_v2 + + BEGIN_DOC + ! !!! + END_DOC + + implicit none + + read_wf = .True. + touch read_wf + + call run() + +end + + + +subroutine run() + + implicit none + + integer :: ii, ii_i, ii_j, k, l + integer :: na, nb, nsvd + double precision, allocatable :: U(:,:), V(:,:), S(:) + + double precision, allocatable :: delta0_det(:), delta1_det(:), deltaSVD_kl(:,:) + double precision, allocatable :: delta_tmp(:) + + na = n_det_alpha_unique + nb = n_det_beta_unique + + ! read SVD vectors + call ezfio_get_spindeterminants_n_svd_coefs(nsvd) + allocate( U(na,nsvd), S(nsvd), V(nb,nsvd) ) + call ezfio_get_spindeterminants_psi_svd_alpha(U) + call ezfio_get_spindeterminants_psi_svd_beta (V) + call ezfio_get_spindeterminants_psi_svd_coefs(S) + + allocate( delta0_det(N_det) ) + call ezfio_get_dmc_dress_dmc_delta_h(delta0_det) + + allocate( deltaSVD_kl(nsvd,nsvd) ) + deltaSVD_kl(:,:) = 0.d0 + call obtenir_deltaSVD_kl(nsvd, U, V, delta0_det, deltaSVD_kl) + + ! [ delta ]_mn = \sum_{k,l} U_{m,k} delta_SVD_{k,l} V_{n,l} + allocate( delta1_det(N_det) ) + delta1_det(1:N_det) = 0.d0 + + !$OMP PARALLEL DEFAULT(NONE) & + !$OMP SHARED(nsvd, N_det, U, V, deltaSVD_kl, delta1_det & + !$OMP , psi_bilinear_matrix_rows, psi_bilinear_matrix_columns) & + !$OMP PRIVATE(k, l, ii, ii_i, ii_j, delta_tmp) + + allocate( delta_tmp(N_det) ) + delta_tmp(1:N_det) = 0.d0 + + !$OMP DO + do ii = 1, N_det + ii_i = psi_bilinear_matrix_rows (ii) + ii_j = psi_bilinear_matrix_columns(ii) + do l = 1, nsvd + do k = 1, nsvd + delta_tmp(ii) = delta_tmp(ii) + U(ii_i,k) * V(ii_j,l) * deltaSVD_kl(k,l) + enddo + enddo + enddo + !$OMP END DO + + !$OMP CRITICAL + do ii = 1, N_det + delta1_det(ii) = delta1_det(ii) + delta_tmp(ii) + enddo + !$OMP END CRITICAL + + deallocate( delta_tmp ) + !$OMP END PARALLEL + + call ezfio_set_dmc_dress_dmc_delta_h(delta1_det) + + deallocate( U , S , V ) + deallocate( deltaSVD_kl ) + deallocate( delta0_det , delta1_det ) + +end + + + + + +! _______________________________________________________________________________________________________ +! +! [ delta_SVD ]_kl = < dup_SVD ddn_SVD | H_tilde - H | psi > +! = \sum_{i,j} U_{i,k} V_{j,l} < dup_i ddn_j | H_tilde - H | psi > +! +subroutine obtenir_deltaSVD_kl(nsvd, U, V, delta0_det, deltaSVD_kl) + + implicit none + + integer, intent(in) :: nsvd + double precision, intent(in) :: U(n_det_alpha_unique,nsvd), V(n_det_beta_unique,nsvd) + double precision, intent(in) :: delta0_det(N_det) + + double precision, intent(out) :: deltaSVD_kl(nsvd,nsvd) + + integer :: k, l, ii, ii_i, ii_j + double precision, allocatable :: delta_tmp(:,:) + + deltaSVD_kl(1:nsvd,1:nsvd) = 0.d0 + + !$OMP PARALLEL DEFAULT(NONE) & + !$OMP SHARED(nsvd, N_det, U, V, delta0_det, deltaSVD_kl & + !$OMP , psi_bilinear_matrix_rows, psi_bilinear_matrix_columns) & + !$OMP PRIVATE(k, l, ii, ii_i, ii_j, delta_tmp) + + allocate( delta_tmp(nsvd,nsvd) ) + delta_tmp(1:nsvd,1:nsvd) = 0.d0 + + !$OMP DO + do l = 1, nsvd + do k = 1, nsvd + do ii = 1, N_det + ii_i = psi_bilinear_matrix_rows (ii) + ii_j = psi_bilinear_matrix_columns(ii) + delta_tmp(k,l) = delta_tmp(k,l) + U(ii_i,k) * V(ii_j,l) * delta0_det(ii) + enddo + enddo + enddo + !$OMP END DO + + !$OMP CRITICAL + do l = 1, nsvd + do k = 1, nsvd + deltaSVD_kl(k,l) = deltaSVD_kl(k,l) + delta_tmp(k,l) + enddo + enddo + !$OMP END CRITICAL + + deallocate(delta_tmp) + !$OMP END PARALLEL + + return +end subroutine obtenir_deltaSVD_kl +! _______________________________________________________________________________________________________ +! _______________________________________________________________________________________________________ diff --git a/devel/svdwf/delta_diagSVD_v0.irp.f b/devel/svdwf/delta_diagSVD_v0.irp.f new file mode 100644 index 0000000..873c751 --- /dev/null +++ b/devel/svdwf/delta_diagSVD_v0.irp.f @@ -0,0 +1,147 @@ +program delta_diagSVD_v0 + + BEGIN_DOC + ! !!! + END_DOC + + implicit none + + read_wf = .True. + touch read_wf + + call run() + +end + + + +subroutine run() + + implicit none + + integer :: ii, ii_i, ii_j, k + integer :: na, nb, nsvd, n_TSVD + double precision, allocatable :: U(:,:), V(:,:), S(:) + + double precision, allocatable :: delta0_det(:), delta1_det(:), deltaSVD_kk(:) + double precision, allocatable :: delta_tmp(:) + + na = n_det_alpha_unique + nb = n_det_beta_unique + + ! read SVD vectors + call ezfio_get_spindeterminants_n_svd_coefs(nsvd) + + allocate( U(na,nsvd) , V(nb,nsvd) ) + call ezfio_get_spindeterminants_psi_svd_alpha(U) + call ezfio_get_spindeterminants_psi_svd_beta (V) + + allocate( delta0_det(N_det) ) + call ezfio_get_dmc_dress_dmc_delta_h(delta0_det) + + allocate( deltaSVD_kk(nsvd) ) + deltaSVD_kk(1:nsvd) = 0.d0 + call obtenir_deltaSVD_kk(nsvd, U, V, delta0_det, deltaSVD_kk) + deallocate( delta0_det ) + + + ! --------------------------------------------- + ! parameters + + n_TSVD = nsvd + + print *, " --- delta_diagSVD_v0 ---" + print *, " n_TSVD =", n_TSVD + print *, " tot =", n_TSVD + + ! + ! --------------------------------------------- + + + ! [ delta ]_mn = \sum_{k} U_{m,k} delta_SVD_{k,k} V_{n,k} + allocate( delta1_det(N_det) ) + delta1_det(:) = 0.d0 + + !$OMP PARALLEL DEFAULT(NONE) & + !$OMP SHARED(n_TSVD, N_det, U, V, deltaSVD_kk, delta1_det & + !$OMP , psi_bilinear_matrix_rows, psi_bilinear_matrix_columns) & + !$OMP PRIVATE(k, ii, ii_i, ii_j, delta_tmp) + allocate( delta_tmp(N_det) ) + delta_tmp(:) = 0.d0 + !$OMP DO + do ii = 1, N_det + ii_i = psi_bilinear_matrix_rows (ii) + ii_j = psi_bilinear_matrix_columns(ii) + do k = 1, n_TSVD + delta_tmp(ii) = delta_tmp(ii) + U(ii_i,k) * V(ii_j,k) * deltaSVD_kk(k) + enddo + enddo + !$OMP END DO + !$OMP CRITICAL + do ii = 1, N_det + delta1_det(ii) = delta1_det(ii) + delta_tmp(ii) + enddo + !$OMP END CRITICAL + deallocate( delta_tmp ) + !$OMP END PARALLEL + + deallocate( U , V ) + deallocate( deltaSVD_kk ) + + call ezfio_set_dmc_dress_dmc_delta_h(delta1_det) + deallocate( delta1_det ) + + +end + + + + + +! _______________________________________________________________________________________________________ +! +! [ delta_SVD ]_kk = < dup_SVD ddn_SVD | H_tilde - H | psi > +! = \sum_{i,j} U_{i,k} V_{j,k} < dup_i ddn_j | H_tilde - H | psi > +! +subroutine obtenir_deltaSVD_kk(nsvd, U, V, delta0_det, deltaSVD_kk) + + implicit none + + integer, intent(in) :: nsvd + double precision, intent(in) :: U(n_det_alpha_unique,nsvd), V(n_det_beta_unique,nsvd) + double precision, intent(in) :: delta0_det(N_det) + + double precision, intent(out) :: deltaSVD_kk(nsvd) + + integer :: k, ii, ii_i, ii_j + double precision, allocatable :: delta_tmp(:) + + deltaSVD_kk(1:nsvd) = 0.d0 + + !$OMP PARALLEL DEFAULT(NONE) & + !$OMP SHARED(nsvd, N_det, U, V, delta0_det, deltaSVD_kk & + !$OMP , psi_bilinear_matrix_rows, psi_bilinear_matrix_columns) & + !$OMP PRIVATE(k, ii, ii_i, ii_j, delta_tmp) + allocate( delta_tmp(nsvd) ) + delta_tmp(1:nsvd) = 0.d0 + !$OMP DO + do k = 1, nsvd + do ii = 1, N_det + ii_i = psi_bilinear_matrix_rows (ii) + ii_j = psi_bilinear_matrix_columns(ii) + delta_tmp(k) = delta_tmp(k) + U(ii_i,k) * V(ii_j,k) * delta0_det(ii) + enddo + enddo + !$OMP END DO + !$OMP CRITICAL + do k = 1, nsvd + deltaSVD_kk(k) = deltaSVD_kk(k) + delta_tmp(k) + enddo + !$OMP END CRITICAL + deallocate(delta_tmp) + !$OMP END PARALLEL + + return +end subroutine obtenir_deltaSVD_kk +! _______________________________________________________________________________________________________ +! _______________________________________________________________________________________________________ diff --git a/devel/svdwf/delta_svd_v1.irp.f b/devel/svdwf/delta_svd_v1.irp.f new file mode 100644 index 0000000..cd4d986 --- /dev/null +++ b/devel/svdwf/delta_svd_v1.irp.f @@ -0,0 +1,221 @@ +program delta_svd_v1 + + BEGIN_DOC + ! !!! + END_DOC + + implicit none + + read_wf = .true. + TOUCH read_wf + + call run() + +end + + + +subroutine run() + + implicit none + + integer :: ii, ii_i, ii_j, k, l + integer :: na, nb, nsvd + double precision, allocatable :: U(:,:), V(:,:), S(:) + double precision, allocatable :: deltaDet_ex(:), deltaDet_ap(:), deltaSVD_kl(:,:) + + na = n_det_alpha_unique + nb = n_det_beta_unique + + ! read SVD vectors + call ezfio_get_spindeterminants_n_svd_coefs(nsvd) + allocate( U(na,nsvd), S(nsvd), V(nb,nsvd) ) + call ezfio_get_spindeterminants_psi_svd_alpha(U) + call ezfio_get_spindeterminants_psi_svd_beta (V) + call ezfio_get_spindeterminants_psi_svd_coefs(S) + + !allocate( deltaSVD_kk(nsvd) ) + !call obtenir_deltaSVD_kk(nsvd, U, V, deltaSVD_kk) + allocate( deltaSVD_kl(nsvd,nsvd) ) + call obtenir_deltaSVD_kl(nsvd, U, V, deltaSVD_kl) + + allocate( deltaDet_ex(N_det) , deltaDet_ap(N_det) ) + do ii = 1, N_det + ii_i = psi_bilinear_matrix_rows (ii) + ii_j = psi_bilinear_matrix_columns(ii) + + deltaDet_ex(ii) = 0.d0 + deltaDet_ap(ii) = 0.d0 + do k = 1, nsvd + deltaDet_ap(ii) = deltaDet_ap(ii) + U(ii_i,k) * V(ii_j,k) * deltaSVD_kl(k,k) + do l = 1, nsvd + deltaDet_ex(ii) = deltaDet_ex(ii) + U(ii_i,k) * V(ii_j,l) * deltaSVD_kl(k,l) + enddo + enddo + + print *, deltaDet_ex(ii) , deltaDet_ap(ii) + enddo + + !call ezfio_set_dmc_dress_dmc_delta_h(delta_Det_ex) + + deallocate( U , S , V ) + deallocate( deltaSVD_kl ) + deallocate( deltaDet_ex , deltaDet_ap ) + +end + + + + +! _______________________________________________________________________________________________________ +! +! [ delta_SVD ]_kk = < dup_SVD ddn_SVD | H_tilde - H | psi > +! = \sum_{i,j} U_{i,k} V_{j,k} < dup_i ddn_j | H_tilde - H | psi > +! +subroutine obtenir_deltaSVD_kk(nsvd, U, V, deltaSVD_kk) + + implicit none + + integer, intent(in) :: nsvd + double precision, intent(in) :: U(n_det_alpha_unique,nsvd), V(n_det_beta_unique,nsvd) + double precision, intent(out) :: deltaSVD_kk(nsvd) + + integer :: i_state, na, nb + integer :: k, ii, jj, ii_i, ii_j, jj_i, jj_j + double precision :: tmp_k, tmp_ij, coef_jj + + integer(bit_kind) :: det_ii(N_int,2), det_jj(N_int,2) + double precision :: hmono, heff, hderiv, hthree, htilde_ij, hij, delta_mat + + PROVIDE scalar_mu_r_pot_physicist_mo deriv_mu_r_pot_physicist_mo + PROVIDE three_body_3_index three_body_3_index_exch_12 three_body_3_index_exch_13 three_body_3_index_exch_23 + PROVIDE three_body_5_index three_body_5_index_exch_13 three_body_5_index_exch_32 + PROVIDE three_body_4_index three_body_4_index_exch_12 three_body_4_index_exch_12_part + + + i_state = 1 + na = n_det_alpha_unique + nb = n_det_beta_unique + + deltaSVD_kk(:) = 0.d0 + do k = 1, nsvd + + tmp_k = 0.d0 + do ii = 1, N_det + ii_i = psi_bilinear_matrix_rows (ii) + ii_j = psi_bilinear_matrix_columns(ii) + + det_ii(:,1) = psi_det_alpha_unique(:,ii_i) + det_ii(:,2) = psi_det_beta_unique (:,ii_j) + + !tmp_ij = < dup_i ddn_j | H_tilde - H | psi > + tmp_ij = 0.d0 + do jj = 1, N_det + jj_i = psi_bilinear_matrix_rows (jj) + jj_j = psi_bilinear_matrix_columns(jj) + + coef_jj = psi_bilinear_matrix_values(jj,i_state) + det_jj(:,1) = psi_det_alpha_unique(:,jj_i) + det_jj(:,2) = psi_det_beta_unique (:,jj_j) + + call htilde_mat(det_ii, det_jj, hmono, heff, hderiv, hthree, htilde_ij) + call i_H_j(det_ii, det_jj, N_int, hij) + delta_mat = htilde_ij - hij + + tmp_ij = tmp_ij + coef_jj * delta_mat + enddo + + tmp_k = tmp_k + U(ii_i,k) * V(ii_j,k) * tmp_ij + enddo + + deltaSVD_kk(k) = tmp_k + enddo + + return +end subroutine obtenir_deltaSVD_kk +! _______________________________________________________________________________________________________ +! _______________________________________________________________________________________________________ + + + + + + +! _______________________________________________________________________________________________________ +! +! [ delta_SVD ]_kl = < dup_SVD ddn_SVD | H_tilde - H | psi > +! = \sum_{i,j} U_{i,k} V_{j,l} < dup_i ddn_j | H_tilde - H | psi > +! +subroutine obtenir_deltaSVD_kl(nsvd, U, V, deltaSVD_kl) + + implicit none + + integer, intent(in) :: nsvd + double precision, intent(in) :: U(n_det_alpha_unique,nsvd), V(n_det_beta_unique,nsvd) + double precision, intent(out) :: deltaSVD_kl(nsvd,nsvd) + + integer :: i_state, na, nb + integer :: k, l, ii, jj, ii_i, ii_j, jj_i, jj_j + double precision :: tmp_kl, tmp_ij, coef_jj + + integer(bit_kind) :: det_ii(N_int,2), det_jj(N_int,2) + double precision :: hmono, heff, hderiv, hthree, htilde_ij, hij, delta_mat + + PROVIDE scalar_mu_r_pot_physicist_mo deriv_mu_r_pot_physicist_mo + PROVIDE three_body_3_index three_body_3_index_exch_12 three_body_3_index_exch_13 three_body_3_index_exch_23 + PROVIDE three_body_5_index three_body_5_index_exch_13 three_body_5_index_exch_32 + PROVIDE three_body_4_index three_body_4_index_exch_12 three_body_4_index_exch_12_part + + i_state = 1 + na = n_det_alpha_unique + nb = n_det_beta_unique + + ! ! ! + det_ii(:,1) = psi_det_alpha_unique(:,1) + det_ii(:,2) = psi_det_beta_unique (:,1) + det_jj(:,1) = psi_det_alpha_unique(:,1) + det_jj(:,2) = psi_det_beta_unique (:,1) + call htilde_mat(det_ii, det_jj, hmono, heff, hderiv, hthree, htilde_ij) + call i_H_j(det_ii, det_jj, N_int, hij) + ! ! ! + + deltaSVD_kl(:,:) = 0.d0 + do k = 1, nsvd + do l = 1, nsvd + + tmp_kl = 0.d0 + do ii = 1, N_det + ii_i = psi_bilinear_matrix_rows (ii) + ii_j = psi_bilinear_matrix_columns(ii) + + det_ii(:,1) = psi_det_alpha_unique(:,ii_i) + det_ii(:,2) = psi_det_beta_unique (:,ii_j) + + !tmp_ij = < dup_i ddn_j | H_tilde - H | psi > + tmp_ij = 0.d0 + do jj = 1, N_det + jj_i = psi_bilinear_matrix_rows (jj) + jj_j = psi_bilinear_matrix_columns(jj) + + coef_jj = psi_bilinear_matrix_values(jj,i_state) + det_jj(:,1) = psi_det_alpha_unique(:,jj_i) + det_jj(:,2) = psi_det_beta_unique (:,jj_j) + + call htilde_mat(det_ii, det_jj, hmono, heff, hderiv, hthree, htilde_ij) + call i_H_j(det_ii, det_jj, N_int, hij) + delta_mat = htilde_ij - hij + + tmp_ij = tmp_ij + coef_jj * delta_mat + enddo + + tmp_kl = tmp_kl + U(ii_i,k) * V(ii_j,l) * tmp_ij + enddo + + deltaSVD_kl(k,l) = tmp_kl + enddo + enddo + + return +end subroutine obtenir_deltaSVD_kl +! _______________________________________________________________________________________________________ +! _______________________________________________________________________________________________________ diff --git a/devel/svdwf/delta_svd_v2.irp.f b/devel/svdwf/delta_svd_v2.irp.f new file mode 100644 index 0000000..bbc2a5e --- /dev/null +++ b/devel/svdwf/delta_svd_v2.irp.f @@ -0,0 +1,167 @@ +program delta_svd_v2 + + BEGIN_DOC + ! !!! + END_DOC + + implicit none + + read_wf = .true. + TOUCH read_wf + + call run() + +end + + + +subroutine run() + + implicit none + + integer :: ii, ii_i, ii_j, k, l + integer :: na, nb, nsvd + double precision, allocatable :: U(:,:), V(:,:), S(:) + double precision, allocatable :: deltaDet_ex(:), deltaDet_ap(:), deltaSVD_kl(:,:) + + na = n_det_alpha_unique + nb = n_det_beta_unique + + ! read SVD vectors + call ezfio_get_spindeterminants_n_svd_coefs(nsvd) + allocate( U(na,nsvd), S(nsvd), V(nb,nsvd) ) + call ezfio_get_spindeterminants_psi_svd_alpha(U) + call ezfio_get_spindeterminants_psi_svd_beta (V) + call ezfio_get_spindeterminants_psi_svd_coefs(S) + + !allocate( deltaSVD_kk(nsvd) ) + !call obtenir_deltaSVD_kk(nsvd, U, V, deltaSVD_kk) + allocate( deltaSVD_kl(nsvd,nsvd) ) + call obtenir_deltaSVD_kl(nsvd, U, V, deltaSVD_kl) + + allocate( deltaDet_ex(N_det) , deltaDet_ap(N_det) ) + do ii = 1, N_det + ii_i = psi_bilinear_matrix_rows (ii) + ii_j = psi_bilinear_matrix_columns(ii) + + deltaDet_ex(ii) = 0.d0 + deltaDet_ap(ii) = 0.d0 + do k = 1, nsvd + deltaDet_ap(ii) = deltaDet_ap(ii) + U(ii_i,k) * V(ii_j,k) * deltaSVD_kl(k,k) + do l = 1, nsvd + deltaDet_ex(ii) = deltaDet_ex(ii) + U(ii_i,k) * V(ii_j,l) * deltaSVD_kl(k,l) + enddo + enddo + + print *, deltaDet_ex(ii) , deltaDet_ap(ii) + enddo + + !call ezfio_set_dmc_dress_dmc_delta_h(delta_Det_ex) + + deallocate( U , S , V ) + deallocate( deltaSVD_kl ) + deallocate( deltaDet_ex , deltaDet_ap ) + +end + + + + + +! _______________________________________________________________________________________________________ +! +! [ delta_SVD ]_kl = < dup_SVD ddn_SVD | H_tilde - H | psi > +! = \sum_{i,j} U_{i,k} V_{j,l} < dup_i ddn_j | H_tilde - H | psi > +! +subroutine obtenir_deltaSVD_kl(nsvd, U, V, deltaSVD_kl) + + implicit none + + integer, intent(in) :: nsvd + double precision, intent(in) :: U(n_det_alpha_unique,nsvd), V(n_det_beta_unique,nsvd) + double precision, intent(out) :: deltaSVD_kl(nsvd,nsvd) + + integer :: i_state + integer :: k, l, ii, jj, ii_i, ii_j, jj_i, jj_j + + integer(bit_kind) :: det_ii(N_int,2), det_jj(N_int,2) + double precision :: hmono, heff, hderiv, hthree, htilde_ij, hij, delta_mat + + double precision, allocatable :: delta_det(:) + + PROVIDE scalar_mu_r_pot_physicist_mo deriv_mu_r_pot_physicist_mo + PROVIDE three_body_3_index three_body_3_index_exch_12 three_body_3_index_exch_13 three_body_3_index_exch_23 + PROVIDE three_body_5_index three_body_5_index_exch_13 three_body_5_index_exch_32 + PROVIDE three_body_4_index three_body_4_index_exch_12 three_body_4_index_exch_12_part + + + i_state = 1 + + ! ! ! + det_ii(:,1) = psi_det_alpha_unique(:,1) + det_ii(:,2) = psi_det_beta_unique (:,1) + det_jj(:,1) = psi_det_alpha_unique(:,1) + det_jj(:,2) = psi_det_beta_unique (:,1) + call htilde_mat(det_ii, det_jj, hmono, heff, hderiv, hthree, htilde_ij) + call i_H_j(det_ii, det_jj, N_int, hij) + ! ! ! + + + ! ------------------------------------------------------------------------- + ! < dup_i ddn_j | H_tilde - H | psi > + allocate( delta_det(N_det) ) + delta_det(:) = 0.d0 + + !$OMP PARALLEL DO DEFAULT(NONE) SCHEDULE(dynamic,8) & + !$OMP SHARED(N_det, i_state, N_int, psi_bilinear_matrix_rows & + !$OMP , psi_bilinear_matrix_columns, psi_bilinear_matrix_values & + !$OMP , psi_det_alpha_unique, psi_det_beta_unique, delta_det) & + !$OMP PRIVATE(ii, ii_i, ii_j, jj, jj_i, jj_j, det_ii, det_jj & + !$OMP , hmono, heff, hderiv, hthree, htilde_ij, hij) + do ii = 1, N_det + ii_i = psi_bilinear_matrix_rows (ii) + ii_j = psi_bilinear_matrix_columns(ii) + + det_ii(:,1) = psi_det_alpha_unique(:,ii_i) + det_ii(:,2) = psi_det_beta_unique (:,ii_j) + + do jj = 1, N_det + jj_i = psi_bilinear_matrix_rows (jj) + jj_j = psi_bilinear_matrix_columns(jj) + + det_jj(:,1) = psi_det_alpha_unique(:,jj_i) + det_jj(:,2) = psi_det_beta_unique (:,jj_j) + + call htilde_mat(det_ii, det_jj, hmono, heff, hderiv, hthree, htilde_ij) + call i_H_j(det_ii, det_jj, N_int, hij) + + delta_det(ii) = delta_det(ii) + (htilde_ij-hij) * psi_bilinear_matrix_values(jj,i_state) + enddo + enddo + !$OMP END PARALLEL DO + ! ------------------------------------------------------------------------- + + + deltaSVD_kl(:,:) = 0.d0 + !$OMP PARALLEL DO DEFAULT(NONE) SCHEDULE(dynamic,8) & + !$OMP SHARED(nsvd, N_det, U, V, delta_det, deltaSVD_kl & + !$OMP , psi_bilinear_matrix_rows, psi_bilinear_matrix_columns) & + !$OMP PRIVATE(k, l, ii, ii_i, ii_j) + do l = 1, nsvd + do k = 1, nsvd + do ii = 1, N_det + ii_i = psi_bilinear_matrix_rows (ii) + ii_j = psi_bilinear_matrix_columns(ii) + + deltaSVD_kl(k,l) = deltaSVD_kl(k,l) + U(ii_i,k) * V(ii_j,l) * delta_det(ii) + enddo + enddo + enddo + !$OMP END PARALLEL DO + + deallocate( delta_det ) + + return +end subroutine obtenir_deltaSVD_kl +! _______________________________________________________________________________________________________ +! _______________________________________________________________________________________________________ diff --git a/devel/svdwf/f2_work/decomp/PILC_decomp/T_decomp.py b/devel/svdwf/f2_work/decomp/PILC_decomp/T_decomp.py new file mode 100644 index 0000000..590e33a --- /dev/null +++ b/devel/svdwf/f2_work/decomp/PILC_decomp/T_decomp.py @@ -0,0 +1,347 @@ +#!/usr/bin/env python + +from ezfio import ezfio +import numpy as np +import sys + +import time +from datetime import datetime + +import matplotlib.pyplot as plt +#import seaborn as sns +from matplotlib.colors import LogNorm + +# ____________________________________________________________________________________________ +# +def read_AO_2eCoulomb(): + + lines = [] + with open(ao_file) as f_in: + for line in f_in: + lines.append( float(line) ) + + J = np.zeros((ao_num2,ao_num2)) + + i_l = 0 + for mu in range(ao_num): + for nu in range(ao_num): + ii = nu + ao_num * mu + + for sig in range(ao_num): + for lam in range(ao_num): + jj = lam + ao_num * sig + + J[ii,jj] = lines[i_l] + i_l += 1 + + return(J) +# ____________________________________________________________________________________________ +# ____________________________________________________________________________________________ + + + + +# ____________________________________________________________________________________________ +# +def read_H_det(): + + H_det = np.zeros((n_det_alpha*n_det_beta,n_det_alpha*n_det_beta)) + with open("fort.7000") as f_in: + for line in f_in: + ll = line.split() + + i = int( ll[0] ) - 1 + j = int( ll[1] ) - 1 + ii = j + n_det_beta * i + + k = int( ll[2] ) - 1 + l = int( ll[3] ) - 1 + jj = l + n_det_beta * k + + H_det[ii,jj] = float(ll[4]) + + return(H_det) +# ____________________________________________________________________________________________ +# ____________________________________________________________________________________________ + + + +# ____________________________________________________________________________________________ +# +def read_T(): + + lines = [] + with open("ij_T_kl.dat") as f_in: + for line in f_in: + lines.append( float(line) ) + + T = np.zeros( (n_det_alpha*n_det_beta,n_det_alpha*n_det_beta) ) + + i_l = 0 + for i in range(n_det_alpha): + for j in range(n_det_beta): + ii = j + n_det_beta * i + + for k in range(n_det_alpha): + for l in range(n_det_beta): + jj = l + n_det_beta * k + + T[ii,jj] = lines[i_l] + i_l += 1 + + return(T) +# ____________________________________________________________________________________________ +# ____________________________________________________________________________________________ + + + + +# ____________________________________________________________________________________________ +# +def check_symmetric(a, rtol=1e-05, atol=1e-08): + return( np.allclose(a, a.T, rtol=rtol, atol=atol) ) +# ____________________________________________________________________________________________ +# ____________________________________________________________________________________________ + + + +# ____________________________________________________________________________________________ +# +def plot_mat(M, xstep, ystep, namefile): + + Mp = np.abs(M) + 1e-15 + ax = sns.heatmap(Mp, linewidths=0.0, rasterized=True, norm=LogNorm()) + + # x axis + ax.xaxis.tick_top() + xgrid = np.arange(1, M.shape[1]+1, xstep-1) + plt.xticks( np.arange(0, M.shape[1], xstep-1) + .5, xgrid ) + + # y axis + ygrid = np.arange(1, M.shape[0]+1, ystep-1) + plt.yticks( np.arange(0, M.shape[0], ystep-1) + .5, ygrid ) + + plt.savefig(namefile) + + plt.clf() +# ____________________________________________________________________________________________ +# ____________________________________________________________________________________________ + + + +# ____________________________________________________________________________________________ +# +def incomplete_Cholesky(M, ma, mb, theta_CD): + + D = np.zeros((ma,mb)) + for lam in range(ma): + for sig in range(mb): + ii = sig + mb * lam + D[sig,lam] = M[ii,ii] + + # find the maximum + val_max = np.amax(D) + ind_max = np.where(D == val_max) + sig_max = ind_max[0][0] + lam_max = ind_max[1][0] + ii_max = sig_max + mb * lam_max + #print( sig_max, lam_max, D[sig_max,lam_max], val_max ) + + # define the initial resudual + mab = ma * mb + R = np.zeros((mab)) + R[:] = M[:,ii_max] + + m = 0 + L = np.zeros((mab)) + List_vec = [] + while(val_max>theta_CD): + + if(m>0): + # update the residual + for ii in range(mab): + sumii = 0 + for i in range(m): + sumii += List_vec[i][ii] * List_vec[i][ii_max] + R[ii] = M[ii,ii_max] - sumii + + # compute Cholesky vector + L = R / np.sqrt(val_max) + List_vec.append(L) + + # update diagonals + for lam in range(ma): + for sig in range(mb): + ii = sig + mb * lam + D[sig,lam] = D[sig,lam] - L[ii]*L[ii] + + m += 1 + + # find the new maximum + val_max = np.amax(D) + ind_max = np.where(D == val_max) + sig_max = ind_max[0][0] + lam_max = ind_max[1][0] + ii_max = sig_max + mb * lam_max + + return(m, List_vec) +# ____________________________________________________________________________________________ +# ____________________________________________________________________________________________ + + + + +# ____________________________________________________________________________________________ +# +def err_p_estim(M, List_vec): + + mM = M.shape[0] + mL = len(List_vec) + + normM = np.linalg.norm(M) + + L_CD = np.zeros((mM,mL)) + for i in range(mL): + L_CD[:,i] = List_vec[i] + print(" size of L_CD: {} MB\n".format( sys.getsizeof(L_CD) / 1024. ) ) + + err_p = 100. * np.linalg.norm( M - np.dot(L_CD, L_CD.T) ) / normM + + return( L_CD, err_p , normM) +# ____________________________________________________________________________________________ +# ____________________________________________________________________________________________ + + + + +# ____________________________________________________________________________________________________________________________________ +# ____________________________________________________________________________________________________________________________________ +# +if __name__=="__main__": + + t_beg = time.time() + + print("") + print(" date and time = {} \n".format(datetime.now().strftime("%d/%m/%Y %H:%M:%S"))) + + + EZFIO_name = "/home/aammar/qp2/src/svdwf/f2_work/f2_fci" + ezfio.set_file(EZFIO_name) + + # ------------------------------------------------------------------------------------------------------ + # 2-e integrals in AO basis + # ------------------------------------------------------------------------------------------------------ + + ao_num = ezfio.get_ao_basis_ao_num() + ao_num2 = ao_num * ao_num + print(" nb of AO = {} \n".format(ao_num)) + + ao_file = "/home/aammar/qp2/src/svdwf/f2_work/ao_2eCoulombIntegrals.txt" + J = read_AO_2eCoulomb() + print(" size of J: {} MB ".format( sys.getsizeof(J) / 1024. ) ) + print(" J is symmetric ? {} ".format(check_symmetric(J)) ) + + #plot_mat(J, ao_num, ao_num, 'J.pdf') + + # pivoted incomplete Cholesky decomposition + theta_CD_J = 1e-02 + m_J, List_vec_J = incomplete_Cholesky(J, ao_num, ao_num, theta_CD_J) + print(" nb of L_CD vectors = {} for theta = {}".format(m_J,theta_CD_J)) + + # check error + L_CD_J, err_p_J, normJ = err_p_estim(J, List_vec_J) + print(" norm of J = {} \n".format(normJ)) + print(" error estimation on J = {} % \n".format(err_p_J)) + + #plot_mat(L_CD_J, 2, ao_num, 'L_CD_J.pdf') + # ------------------------------------------------------------------------------------------------------ + # ------------------------------------------------------------------------------------------------------ + + + + print('\n \n \n') + + + + # ------------------------------------------------------------------------------------------------------ + # < d_i d_j | T | d_k d_l > + # ------------------------------------------------------------------------------------------------------ + +# n_det_alpha = ezfio.get_spindeterminants_n_det_alpha() +# n_det_beta = ezfio.get_spindeterminants_n_det_beta () +# n_ab = n_det_alpha * n_det_beta +# print(" n_det_alpha = {} ".format(n_det_alpha)) +# print(" n_det_beta = {} \n".format(n_det_beta )) +# +# T = read_T() +# print(" T is symmetric ? {} \n".format(check_symmetric(T)) ) +# +# plot_mat(T, 50, 50, 'T.pdf') +# +# +# # pivoted incomplete Cholesky decomposition +# theta_CD_T = 1.5 +# m_T, List_vec_T = incomplete_Cholesky(T, n_det_alpha, n_det_beta, theta_CD_T) +# print(" nb of L_CD vectors = {} for theta = {}".format(m_T,theta_CD_T)) +# +# # check error +# L_CD_T, err_p_T, normT = err_p_estim(T, List_vec_T) +# print(" norm of T = {} ".format(normT)) +# print(" error estimation on T = {} % \n".format(err_p_T)) +# +# plot_mat(L_CD_T, 2, n_det_beta, 'L_CD_T.pdf') + # ------------------------------------------------------------------------------------------------------ + # ------------------------------------------------------------------------------------------------------ + + + + + + print('\n \n \n') + + + # ------------------------------------------------------------------------------------------------------ + # < d_i d_j | H | d_k d_l > + # + # WARNING: this isn't semipositive definite + # ------------------------------------------------------------------------------------------------------ +# +# # get H_det +# n_det_alpha = ezfio.get_spindeterminants_n_det_alpha() +# n_det_beta = ezfio.get_spindeterminants_n_det_beta () +# n_ab = n_det_alpha * n_det_beta +# print(" n_det_alpha = {} ".format(n_det_alpha)) +# print(" n_det_beta = {} \n".format(n_det_beta )) +# +# H_det = read_H_det() +# print(" size of H_det: {} MB ".format( sys.getsizeof(H_det) / 1024. ) ) +# print(" H_det is symmetric ? {} \n".format(check_symmetric(H_det)) ) +# +# # plot H_det +# H_det = H_det + 1e-15 +# plot_mat(H_det, 50, 50, 'H_det.pdf') +# +# +# # pivoted incomplete Cholesky decomposition +# theta_CD_H_det = 1e-02 +# m_H_det, List_vec_H_det = incomplete_Cholesky(H_det, n_det_alpha, n_det_beta, theta_CD_H_det) +# print(" nb of L_CD_H_det vectors = {} for a precision of {}".format(m_H_det,theta_CD_H_det)) +# #print(" size of L_CD_H_det: {} MB\n".format( sys.getsizeof(List_vec_H_det) / 1024. ) ) +# +# # check error +# L_CD_H_det, err_p_H_det, normH_det = err_p_estim(H_det, List_vec_H_det) +# print(" norm of H_det = {} \n".format(normH_det)) +# print(" error estimation on H_det = {} % \n".format(err_p_H_det)) +# +# plot_mat(L_CD_H_det, 2, n_det_beta, 'L_CD_H_det.pdf') + # ------------------------------------------------------------------------------------------------------ + # ------------------------------------------------------------------------------------------------------ + + + + print('\n\n') + t_end = time.time() + print(' end after {} min'.format((t_end-t_beg)/60.)) +# ____________________________________________________________________________________________________________________________________ +# ____________________________________________________________________________________________________________________________________ +# ____________________________________________________________________________________________________________________________________ diff --git a/devel/svdwf/f2_work/decomp/SVD_decomp/SVD_decomp.py b/devel/svdwf/f2_work/decomp/SVD_decomp/SVD_decomp.py new file mode 100644 index 0000000..dea1a58 --- /dev/null +++ b/devel/svdwf/f2_work/decomp/SVD_decomp/SVD_decomp.py @@ -0,0 +1,348 @@ +#!/usr/bin/env python + +from ezfio import ezfio +import numpy as np +import sys + +import time +from datetime import datetime + +import matplotlib.pyplot as plt +#import seaborn as sns +from matplotlib.colors import LogNorm + + +# ____________________________________________________________________________________________ +# +def read_Hsvd(): + + Hsvd = np.zeros((n_det_alpha*n_det_beta,n_det_alpha*n_det_beta)) + n_zero = 0 + with open("fort.7070") as f_in: + #with open("fort.7071") as f_in: + for line in f_in: + ll = line.split() + + i = int( ll[0] ) - 1 + j = int( ll[1] ) - 1 + ii = j + n_det_beta * i + + k = int( ll[2] ) - 1 + l = int( ll[3] ) - 1 + jj = l + n_det_beta * k + + Hsvd[ii,jj] = float(ll[4]) + if( abs(Hsvd[ii,jj]) <= 1e-12): + n_zero += 1 + + print(' nb of zero element in Hsvd = {}/{}'.format( + n_zero, n_det_alpha*n_det_beta*n_det_alpha*n_det_beta )) + print(' % of zero element in Hsvd = {}\n'.format( + 100. * n_zero / (n_det_alpha*n_det_beta*n_det_alpha*n_det_beta) )) + return(Hsvd) +# ____________________________________________________________________________________________ +# ____________________________________________________________________________________________ + + +# ____________________________________________________________________________________________ +# +def read_Hdet(): + + Hdet = np.zeros((n_ab,n_ab)) + + n_zero = 0 + with open("hdet_file") as f_in: + for line in f_in: + ll = line.split() + + i = int( ll[0] ) - 1 + j = int( ll[1] ) - 1 + ii = j + n_det_beta * i + + k = int( ll[2] ) - 1 + l = int( ll[3] ) - 1 + jj = l + n_det_beta * k + + Hdet[ii,jj] = float(ll[4]) + + if( abs(Hdet[ii,jj]) <= 1e-12): + n_zero += 1 + + print(' nb of zero element in Hdet = {}/{}'.format(n_zero, n_ab*n_ab)) + print(' % of zero element in Hdet = {} \n'.format(100.*n_zero/(n_ab*n_ab))) + + return(Hdet) +# ____________________________________________________________________________________________ +# ____________________________________________________________________________________________ + + + + +# ____________________________________________________________________________________________ +# +def read_Tdet(): + + lines = [] + with open("ij_T_kl.dat") as f_in: + for line in f_in: + lines.append( float(line) ) + + Tdet = np.zeros( (n_det_alpha*n_det_beta,n_det_alpha*n_det_beta) ) + + i_l = 0 + n_zero = 0 + for i in range(n_det_alpha): + for j in range(n_det_beta): + ii = j + n_det_beta * i + + for k in range(n_det_alpha): + for l in range(n_det_beta): + jj = l + n_det_beta * k + + Tdet[ii,jj] = lines[i_l] + i_l += 1 + + if( abs(Tdet[ii,jj]) <= 1e-12): + n_zero += 1 + + print(' nb of zero element in Tdet = {}/{}'.format( + n_zero, n_det_alpha*n_det_beta*n_det_alpha*n_det_beta )) + print(' % of zero element in Tdet = {}\n'.format( + 100. * n_zero / (n_det_alpha*n_det_beta*n_det_alpha*n_det_beta) )) + + return(Tdet) +# ____________________________________________________________________________________________ +# ____________________________________________________________________________________________ + + + + + +# ____________________________________________________________________________________________ +# +def read_Tsvd(): + + lines = [] + with open("ab_T_gd_v0.dat") as f_in: + for line in f_in: + lines.append( float(line) ) + + Tsvd = np.zeros( (n_det_alpha*n_det_beta,n_det_alpha*n_det_beta) ) + + i_l = 0 + n_zero = 0 + for i in range(n_det_alpha): + for j in range(n_det_beta): + ii = j + n_det_beta * i + + for k in range(n_det_alpha): + for l in range(n_det_beta): + jj = l + n_det_beta * k + + Tsvd[ii,jj] = lines[i_l] + i_l += 1 + + if( abs(Tsvd[ii,jj]) <= 1e-12): + n_zero += 1 + + print(' nb of zero element in Tsvd = {}/{}'.format( + n_zero, n_det_alpha*n_det_beta*n_det_alpha*n_det_beta )) + print(' % of zero element in Tsvd = {}\n'.format( + 100. * n_zero / (n_det_alpha*n_det_beta*n_det_alpha*n_det_beta) )) + + return(Tsvd) +# ____________________________________________________________________________________________ +# ____________________________________________________________________________________________ + + + +# ____________________________________________________________________________________________ +# +def read_AO_2eCoulomb(): + + lines = [] + with open(ao_file) as f_in: + for line in f_in: + lines.append( float(line) ) + + J = np.zeros((ao_num2,ao_num2)) + + i_l = 0 + n_zero = 0 + for mu in range(ao_num): + for nu in range(ao_num): + ii = nu + ao_num * mu + + for sig in range(ao_num): + for lam in range(ao_num): + jj = lam + ao_num * sig + + J[ii,jj] = lines[i_l] + i_l += 1 + + if( abs(J[ii,jj]) <= 1e-12): + n_zero += 1 + + print(' nb of zero element in J = {}/{}'.format(n_zero, ao_num2*ao_num2)) + print(' % of zero element in J = {}\n'.format(100.*n_zero/(ao_num2*ao_num2))) + + return(J) +# ____________________________________________________________________________________________ +# ____________________________________________________________________________________________ + + + +# ____________________________________________________________________________________________ +# +def check_symmetric(a, rtol=1e-05, atol=1e-08): + if( np.allclose(a, a.T, rtol=rtol, atol=atol) ): + return( True ) + else: + print(' | a - aT | / | a | = {} %'.format( + 100. * np.linalg.norm(a-a.T) / np.linalg.norm(a) )) + return( False ) +# ____________________________________________________________________________________________ +# ____________________________________________________________________________________________ + + + +# ____________________________________________________________________________________________ +# +def plot_mat(M, xstep, ystep, namefile): + + Mp = np.abs(M) + 1e-15 + ax = sns.heatmap(Mp, linewidths=0.0, rasterized=True, norm=LogNorm()) + + # x axis + ax.xaxis.tick_top() + xgrid = np.arange(1, M.shape[1]+1, xstep-1) + plt.xticks( np.arange(0, M.shape[1], xstep-1) + .5, xgrid ) + + # y axis + ygrid = np.arange(1, M.shape[0]+1, ystep-1) + plt.yticks( np.arange(0, M.shape[0], ystep-1) + .5, ygrid ) + + plt.savefig(namefile) + + plt.clf() +# ____________________________________________________________________________________________ +# ____________________________________________________________________________________________ + + + +# ____________________________________________________________________________________________ +# +def save_SVs(): + + with open('sing_val.txt', 'w') as ff: + for i in range(s.shape[0]): + ff.write("{:+e}\n".format(s[i])) +# ____________________________________________________________________________________________ +# ____________________________________________________________________________________________ + + + + + + + + + + + + + + + +# ____________________________________________________________________________________________ +# ____________________________________________________________________________________________ +# +if __name__=="__main__": + + t0 = time.time() + + print("") + print(" date and time = {} \n".format(datetime.now().strftime("%d/%m/%Y %H:%M:%S"))) + + EZFIO_name = "/home/aammar/qp2/src/svdwf/f2_work/f2_fci" + ezfio.set_file(EZFIO_name) + + + # -------------------- read M ------------------------------ + + n_det_alpha = ezfio.get_spindeterminants_n_det_alpha() + n_det_beta = ezfio.get_spindeterminants_n_det_beta () + n_ab = n_det_alpha * n_det_beta + print(" n_det_alpha = {} ".format(n_det_alpha)) + print(" n_det_beta = {} \n".format(n_det_beta )) + + # < i j | H | k l > in det basis + hdet_file = "/home/aammar/qp2/src/svdwf/f2_work/fort.7000" + M = read_Hdet() + + #M = read_Hsvd() + #M = read_Tdet() + #M = read_Tsvd() + + + #ao_num = ezfio.get_ao_basis_ao_num() + #ao_num2 = ao_num * ao_num + #print(" nb of AO = {} \n".format(ao_num)) + + # 2-e integrals in AO basis + #ao_file = "/home/aammar/qp2/src/svdwf/f2_work/ao_2eCoulombIntegrals.txt" + #M = read_AO_2eCoulomb() + + #plot_mat(M, 50, 50, 'Hdet.pdf') + #plot_mat(M, 50, 50, 'Hsvd.pdf') + #plot_mat(M, 50, 50, 'Tdet.pdf') + #plot_mat(M, 50, 50, 'Tsvd.pdf') + # -------------------------------------------------------------------- + # -------------------------------------------------------------------- + + + + # -------------------- perform SVD ------------------------------ + + norm_M = np.linalg.norm(M) + print(" size of M: {} MB ".format( sys.getsizeof(M) / 1024. ) ) + print(" M is symmetric ? {} \n".format(check_symmetric(M)) ) + + u, s, vt = np.linalg.svd(M, full_matrices=False) + + n_FSVD = s.shape[0] + err_p = 100. * np.linalg.norm( + M - np.dot( u, np.dot(np.diag(s),vt) ) + ) / norm_M + print(' n_FSVD = {}, err(%) = {}\n'.format(n_FSVD,err_p)) + # -------------------------------------------------------------------- + # -------------------------------------------------------------------- + + save_SVs() + + + # -------------------- T SVD ----------------------------- + # truncatad SVD + + print(' n_FSVD err(%)') + for n_TSVD in range(1,n_FSVD): + + u_T, s_T, vt_T = u[:,0:n_TSVD], s[0:n_TSVD], vt[0:n_TSVD,:] + + err_p = 100. * np.linalg.norm( + M - np.dot( u_T, np.dot(np.diag(s_T),vt_T) ) + ) / norm_M + + print(' {} {:+e}'.format(n_TSVD,err_p)) + + # -------------------------------------------------------------------- + # -------------------------------------------------------------------- + + + + print("") + print(" end after {} min".format((-t0+time.time())/60.)) +# ____________________________________________________________________________________________ +# ____________________________________________________________________________________________ +# ____________________________________________________________________________________________ + diff --git a/devel/svdwf/f2_work/f2_opt/SVD_opt/Evmc_TSVD.py b/devel/svdwf/f2_work/f2_opt/SVD_opt/Evmc_TSVD.py new file mode 100644 index 0000000..e2bf666 --- /dev/null +++ b/devel/svdwf/f2_work/f2_opt/SVD_opt/Evmc_TSVD.py @@ -0,0 +1,251 @@ +# !!! +import sys, os +QMCCHEM_PATH=os.environ["QMCCHEM_PATH"] +sys.path.insert(0,QMCCHEM_PATH+"/EZFIO/Python/") + + +from ezfio import ezfio +from math import sqrt +from datetime import datetime +import time +import numpy as np +import subprocess +from scipy.linalg import eig, eigh + + + +# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! +def get_energy(): + buffer = subprocess.check_output(['qmcchem', 'result', '-e', 'e_loc', EZFIO_file], encoding='UTF-8') + if buffer.strip() != "": + buffer = buffer.splitlines()[-1] + _, energy, error = [float(x) for x in buffer.split()] + return energy, error + else: + return None, None +# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! + + + + +# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! +def get_Ci_h_matrix_svd(): + + Ci_h_matrix_svd = np.zeros( (n_svd,n_svd) ) + SErr_H = np.zeros( (n_svd,n_svd) ) + + beg_Ci_h_matrix_svd = results.find('Ci_h_matrix_svd : [ ') + len( 'Ci_h_matrix_svd : [ ' ) + end_Ci_h_matrix_svd = len(results) + Ci_h_matrix_svd_buf = results[beg_Ci_h_matrix_svd:end_Ci_h_matrix_svd] + Ci_h_matrix_svd_buf = Ci_h_matrix_svd_buf.split( '\n' ) + + for iline in range(1, n_svd**2+1): + + line = Ci_h_matrix_svd_buf[iline].split() + indc = int( line[0] ) + errS = float( line[4] ) + if( indc != iline ): + print(' Error in reading Ci_h_matrix_svd') + print(' indc = {}'.format(indc) ) + print(' iline = {}'.format(iline) ) + break + else: + irow = indc % n_svd + icol = indc // n_svd + if( irow!=0 ): + Ci_h_matrix_svd[irow-1][icol] = float( line[2] ) + SErr_H [irow-1][icol] = float( line[4] ) + else: + Ci_h_matrix_svd[n_svd-1][icol-1] = float( line[2] ) + SErr_H [n_svd-1][icol-1] = float( line[4] ) + + return(Ci_h_matrix_svd,SErr_H) +# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! + + + +# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! +def get_Ci_overlap_matrix_svd(): + + Ci_overlap_matrix_svd = np.zeros( (n_svd,n_svd) ) + SErr_O = np.zeros( (n_svd,n_svd) ) + + beg_Ci_overlap_matrix_svd = results.find('Ci_overlap_matrix_svd : [ ') + len( 'Ci_overlap_matrix_svd : [ ' ) + end_Ci_overlap_matrix_svd = len(results) + Ci_overlap_matrix_svd_buf = results[beg_Ci_overlap_matrix_svd:end_Ci_overlap_matrix_svd] + Ci_overlap_matrix_svd_buf = Ci_overlap_matrix_svd_buf.split( '\n' ) + + for iline in range(1, n_svd**2+1): + + line = Ci_overlap_matrix_svd_buf[iline].split() + indc = int( line[0] ) + errS = float( line[4] ) + if( indc != iline ): + print(' Error in reading Ci_overlap_matrix_svd') + print(' indc = {}'.format(indc)) + print(' iline = {}'.format(iline)) + break + else: + irow = indc % n_svd + icol = indc // n_svd + if( irow!=0 ): + Ci_overlap_matrix_svd[irow-1][icol] = float( line[2] ) + SErr_O [irow-1][icol] = float( line[4] ) + else: + Ci_overlap_matrix_svd[n_svd-1][icol-1] = float( line[2] ) + SErr_O [n_svd-1][icol-1] = float( line[4] ) + + return(Ci_overlap_matrix_svd,SErr_O) +# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! + + + +# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! +def check_symmetric(a, tol=1e-3): + return np.all(np.abs(a-a.T) < tol) +# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! + + + + + +# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! +def save_QMCmat(): + + with open('SVD_QMCmat.txt', 'a') as ff: + for i in range(n_svd): + for j in range(n_svd): + ff.write('{} {} {} {} {} {} \n'.format(i,j + , Ci_h_matrix_svd[i,j] , SErr_H[i,j] + , Ci_overlap_matrix_svd[i,j] , SErr_O[i,j] )) +# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! + + + + + +# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! +def get_Esvd(): + + # symmetrise and diagonalise + aa = Ci_h_matrix_svd + aa = 0.5*( aa + aa.T ) + bb = Ci_overlap_matrix_svd + eigvals_svd, vr = eig(aa, bb, left=False, right=True, overwrite_a=True, overwrite_b=True, + check_finite=True, homogeneous_eigvals=False) + + #print( eigvals_svd + E_toadd ) + recouvre_svd = np.abs(psi_svd_coeff @ vr) + ind_gssvd = np.argmax(recouvre_svd) + + E_svd = eigvals_svd[ind_gssvd] + E_toadd + + return( E_svd, vr[:,ind_gssvd] ) +# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! + + + + + +# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! +def Evmc_Tsvd(n_Tsvd): + + # symmetrise and diagonalise + aa = Ci_h_matrix_svd[0:n_Tsvd,0:n_Tsvd] + aa = 0.5*( aa + aa.T ) + bb = Ci_overlap_matrix_svd[0:n_Tsvd,0:n_Tsvd] + bb = 0.5*( bb + bb.T ) + + eig_Tsvd, vr_Tsvd = eig(aa, bb, left=False, right=True, overwrite_a=True, overwrite_b=True, + check_finite=True, homogeneous_eigvals=False) + + recouvre_Tsvd = np.abs(psi_svd_coeff[0:n_Tsvd] @ vr_Tsvd) + ind_gssvd = np.argmax(recouvre_Tsvd) + + E_Tsvd = eig_Tsvd[ind_gssvd] + E_toadd + + return( E_Tsvd, vr_Tsvd[:,ind_gssvd] ) +# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! + + + + +# _________________________________________________________________________________________________ +# _________________________________________________________________________________________________ +# +if __name__ == '__main__': + + t0 = time.time() + print(" ") + print(" Today's date: \n", datetime.now() ) + + + # ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ # + #EZFIO_file = "/home/aammar/qp2/src/svdwf/f2_work/f2_opt/SVD_opt/f2_cisd" + + E_toadd = 30.35863309325590 + # ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ # + + + ezfio.set_file(EZFIO_file) + n_svd = ezfio.get_spindeterminants_n_svd_coefs() + psi_svd_coeff = np.array(ezfio.get_spindeterminants_psi_svd_coefs()) + + print(" EZFIO file = {}".format(EZFIO_file)) + print(" n_svd = {}\n".format(n_svd) ) + + t_read = time.time() + print(' getting QMCCHEM results from {}'.format(EZFIO_file) ) + results = subprocess.check_output(['qmcchem', 'result', EZFIO_file], encoding='UTF-8') + print(' getting results after {} minutes \n'.format( (time.time()-t_read)/60. )) + + if( len(results)<100): + print(' result is empty \n') + exit() + + Eloc, ErrEloc = get_energy() + print(' Eloc = {} +/- {}'.format(Eloc, ErrEloc)) + print(' {} <= Eloc <= {}\n'.format(Eloc-ErrEloc,Eloc+ErrEloc)) + #print(' initial svd coeff = {}\n'.format(psi_svd_coeff)) + + + # read CI_SVD matrices + Ci_h_matrix_svd , SErr_H = get_Ci_h_matrix_svd() + Ci_overlap_matrix_svd, SErr_O = get_Ci_overlap_matrix_svd() + #print( 'Ci_h_matrix_svd is symmetric ? {}' .format(check_symmetric(Ci_h_matrix_svd)) ) + #print( 'Ci_overlap_matrix_svd is symmetric ? {}' .format(check_symmetric(Ci_overlap_matrix_svd)) ) + + #save_QMCmat() + + + for n_Tsvd in range(n_svd): + E_Tsvd, _ = Evmc_Tsvd(n_Tsvd) + print(' n_Tsvd = {}, E_Tsvd = {}'.format(n_Tsvd,E_Tsvd) ) + print('') + + + + # ___________________________________________________________________________ + # ___________________________________________________________________________ + # + save_to_EZFIO = '' + + #save_to_EZFIO = 'svd_QMC' + #n_TSVD = ... + #_, sigma_svd = Evmc_Tsvd(n_Tsvd) + + if( save_to_EZFIO == 'svd_QMC' ): + ezfio.set_spindeterminants_psi_svd_coefs( sigma_svd ) + direc_svdcoeff = EZFIO_file + '/spindeterminants/psi_svd_coefs.gz' + print(' {} is modified'.format(direc_svdcoeff) ) + else: + print(' exit with no modifications in {} EZFIO'.format(EZFIO_file)) + # ___________________________________________________________________________ + # ___________________________________________________________________________ + + + + print("end after {:.3f} minutes".format((time.time()-t0)/60.) ) +# _________________________________________________________________________________________________~ +# _________________________________________________________________________________________________ +# _________________________________________________________________________________________________ diff --git a/devel/svdwf/f2_work/f2_opt/SVD_opt/LOBD_VMC.py b/devel/svdwf/f2_work/f2_opt/SVD_opt/LOBD_VMC.py new file mode 100644 index 0000000..c163160 --- /dev/null +++ b/devel/svdwf/f2_work/f2_opt/SVD_opt/LOBD_VMC.py @@ -0,0 +1,216 @@ +# !!! +import sys, os +QMCCHEM_PATH=os.environ["QMCCHEM_PATH"] +sys.path.insert(0,QMCCHEM_PATH+"/EZFIO/Python/") + + +from ezfio import ezfio +from math import sqrt +from datetime import datetime +import time +import numpy as np +import subprocess +from scipy.linalg import eig, eigh + + + +# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! +def get_energy(): + buffer = subprocess.check_output(['qmcchem', 'result', '-e', 'e_loc', EZFIO_file], encoding='UTF-8') + if buffer.strip() != "": + buffer = buffer.splitlines()[-1] + _, energy, error = [float(x) for x in buffer.split()] + return energy, error + else: + return None, None +# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! + + + + +# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! +def get_Ci_h_matrix_svd(): + + Ci_h_matrix_svd = np.zeros( (n_svd,n_svd) ) + SErr_H = np.zeros( (n_svd,n_svd) ) + + beg_Ci_h_matrix_svd = results.find('Ci_h_matrix_svd : [ ') + len( 'Ci_h_matrix_svd : [ ' ) + end_Ci_h_matrix_svd = len(results) + Ci_h_matrix_svd_buf = results[beg_Ci_h_matrix_svd:end_Ci_h_matrix_svd] + Ci_h_matrix_svd_buf = Ci_h_matrix_svd_buf.split( '\n' ) + + for iline in range(1, n_svd**2+1): + + line = Ci_h_matrix_svd_buf[iline].split() + indc = int( line[0] ) + errS = float( line[4] ) + if( indc != iline ): + print(' Error in reading Ci_h_matrix_svd') + print(' indc = {}'.format(indc) ) + print(' iline = {}'.format(iline) ) + break + else: + irow = indc % n_svd + icol = indc // n_svd + if( irow!=0 ): + Ci_h_matrix_svd[irow-1][icol] = float( line[2] ) + SErr_H [irow-1][icol] = float( line[4] ) + else: + Ci_h_matrix_svd[n_svd-1][icol-1] = float( line[2] ) + SErr_H [n_svd-1][icol-1] = float( line[4] ) + + return(Ci_h_matrix_svd,SErr_H) +# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! + + + +# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! +def get_Ci_overlap_matrix_svd(): + + Ci_overlap_matrix_svd = np.zeros( (n_svd,n_svd) ) + SErr_O = np.zeros( (n_svd,n_svd) ) + + beg_Ci_overlap_matrix_svd = results.find('Ci_overlap_matrix_svd : [ ') + len( 'Ci_overlap_matrix_svd : [ ' ) + end_Ci_overlap_matrix_svd = len(results) + Ci_overlap_matrix_svd_buf = results[beg_Ci_overlap_matrix_svd:end_Ci_overlap_matrix_svd] + Ci_overlap_matrix_svd_buf = Ci_overlap_matrix_svd_buf.split( '\n' ) + + for iline in range(1, n_svd**2+1): + + line = Ci_overlap_matrix_svd_buf[iline].split() + indc = int( line[0] ) + errS = float( line[4] ) + if( indc != iline ): + print(' Error in reading Ci_overlap_matrix_svd') + print(' indc = {}'.format(indc)) + print(' iline = {}'.format(iline)) + break + else: + irow = indc % n_svd + icol = indc // n_svd + if( irow!=0 ): + Ci_overlap_matrix_svd[irow-1][icol] = float( line[2] ) + SErr_O [irow-1][icol] = float( line[4] ) + else: + Ci_overlap_matrix_svd[n_svd-1][icol-1] = float( line[2] ) + SErr_O [n_svd-1][icol-1] = float( line[4] ) + + return(Ci_overlap_matrix_svd,SErr_O) +# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! + + + +# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! +def check_symmetric(a, tol=1e-3): + return np.all(np.abs(a-a.T) < tol) +# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! + + + +# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! +def get_Esvd(): + + # read CI_SVD matrices + Ci_h_matrix_svd , SErr_H = get_Ci_h_matrix_svd() + Ci_overlap_matrix_svd, SErr_O = get_Ci_overlap_matrix_svd() + + #print( 'Ci_h_matrix_svd is symmetric ? {}' .format(check_symmetric(Ci_h_matrix_svd)) ) + #print( 'Ci_overlap_matrix_svd is symmetric ? {}' .format(check_symmetric(Ci_overlap_matrix_svd)) ) + + if( save_SVD_QMCmat ): + with open('SVD_QMCmat.txt', 'a') as ff: + for i in range(n_svd): + for j in range(n_svd): + ff.write('{} {} {} {} {} {} \n'.format(i,j + , Ci_h_matrix_svd[i,j] , SErr_H[i,j] + , Ci_overlap_matrix_svd[i,j] , SErr_O[i,j] )) + + # symmetrise and diagonalise + aa = Ci_h_matrix_svd + aa = 0.5*( aa + aa.T ) + bb = Ci_overlap_matrix_svd + eigvals_svd, vr = eig(aa, bb, left=False, right=True, overwrite_a=True, overwrite_b=True, + check_finite=True, homogeneous_eigvals=False) + + #print( eigvals_svd + E_toadd ) + recouvre_svd = np.abs(psi_svd_coeff @ vr) + ind_gssvd = np.argmax(recouvre_svd) + + E_svd = eigvals_svd[ind_gssvd] + E_toadd + + return( E_svd, vr[:,ind_gssvd] ) +# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! + + + + + +# _________________________________________________________________________________________________ +# _________________________________________________________________________________________________ +# +if __name__ == '__main__': + + t0 = time.time() + print(" ") + print(" Today's date: \n", datetime.now() ) + + + # ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ # + #EZFIO_file = "/home/aammar/qp2/src/svdwf/f2_work/f2_opt/SVD_opt/f2_cisd" + + E_toadd = 30.35863309325590 + # ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ # + + + ezfio.set_file(EZFIO_file) + n_svd = ezfio.get_spindeterminants_n_svd_coefs() + psi_svd_coeff = np.array(ezfio.get_spindeterminants_psi_svd_coefs()) + + print(" EZFIO file = {}".format(EZFIO_file)) + print(" n_svd = {}\n".format(n_svd) ) + + t_read = time.time() + print(' getting QMCCHEM results from {}'.format(EZFIO_file) ) + results = subprocess.check_output(['qmcchem', 'result', EZFIO_file], encoding='UTF-8') + print(' getting results after {} minutes \n'.format( (time.time()-t_read)/60. )) + + if( len(results)<100): + print(' result is empty \n') + exit() + + Eloc, ErrEloc = get_energy() + print(' Eloc = {} +/- {}'.format(Eloc, ErrEloc)) + print(' {} <= Eloc <= {}'.format(Eloc-ErrEloc,Eloc+ErrEloc)) + #print(' initial svd coeff = {}\n'.format(psi_svd_coeff)) + + save_SVD_QMCmat = True + #save_SVD_QMCmat = False + + print('') + E_svd, sigma_svd = get_Esvd() + print(' svd enegry = {}'.format(E_svd) ) + sigma_svd = sigma_svd * np.sign(sigma_svd[0]) + #print(' svd coeff = {}'.format(sigma_svd)) + print('') + + # ___________________________________________________________________________ + # ___________________________________________________________________________ + # + #save_to_EZFIO = 'svd_QMC' + save_to_EZFIO = '' + + if( save_to_EZFIO == 'svd_QMC' ): + ezfio.set_spindeterminants_psi_svd_coefs( sigma_svd ) + direc_svdcoeff = EZFIO_file + '/spindeterminants/psi_svd_coefs.gz' + print(' {} is modified'.format(direc_svdcoeff) ) + else: + print(' exit with no modifications in {} EZFIO'.format(EZFIO_file)) + # ___________________________________________________________________________ + # ___________________________________________________________________________ + + + + print("end after {:.3f} minutes".format((time.time()-t0)/60.) ) +# _________________________________________________________________________________________________~ +# _________________________________________________________________________________________________ +# _________________________________________________________________________________________________ diff --git a/devel/svdwf/f2_work/f2_opt/SVD_opt/LOBD_compactVMC.py b/devel/svdwf/f2_work/f2_opt/SVD_opt/LOBD_compactVMC.py new file mode 100644 index 0000000..dea6941 --- /dev/null +++ b/devel/svdwf/f2_work/f2_opt/SVD_opt/LOBD_compactVMC.py @@ -0,0 +1,225 @@ +# !!! +import sys, os +QMCCHEM_PATH=os.environ["QMCCHEM_PATH"] +sys.path.insert(0,QMCCHEM_PATH+"/EZFIO/Python/") + + +from ezfio import ezfio +from math import sqrt +from datetime import datetime +import time +import numpy as np +import subprocess +from scipy.linalg import eig, eigh + + + +# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! +def get_energy(): + buffer = subprocess.check_output(['qmcchem', 'result', '-e', 'e_loc', EZFIO_file], encoding='UTF-8') + if buffer.strip() != "": + buffer = buffer.splitlines()[-1] + _, energy, error = [float(x) for x in buffer.split()] + return energy, error + else: + return None, None +# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! + + + +# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! +def get_Ci_h_matrix_modifsvd(): + + Ci_h_matrix_modifsvd = np.zeros( (n_modifsvd,n_modifsvd) ) + SErr_H = np.zeros( (n_modifsvd,n_modifsvd) ) + + beg_Ci_h_matrix_modifsvd = results.find('Ci_h_matrix_modifsvd : [ ') + len( 'Ci_h_matrix_modifsvd : [ ' ) + end_Ci_h_matrix_modifsvd = len(results) + Ci_h_matrix_modifsvd_buf = results[beg_Ci_h_matrix_modifsvd:end_Ci_h_matrix_modifsvd] + Ci_h_matrix_modifsvd_buf = Ci_h_matrix_modifsvd_buf.split( '\n' ) + + for iline in range(1, n_modifsvd**2+1): + + line = Ci_h_matrix_modifsvd_buf[iline].split() + indc = int( line[0] ) + errS = float( line[4] ) + if( indc != iline ): + print(' Error in reading Ci_h_matrix_modifsvd') + print(' indc = {}'.format(indc) ) + print(' iline = {}'.format(iline) ) + break + else: + irow = indc % n_modifsvd + icol = indc // n_modifsvd + if( irow!=0 ): + Ci_h_matrix_modifsvd[irow-1][icol] = float( line[2] ) + SErr_H [irow-1][icol] = float( line[4] ) + else: + Ci_h_matrix_modifsvd[n_modifsvd-1][icol-1] = float( line[2] ) + SErr_H [n_modifsvd-1][icol-1] = float( line[4] ) + # !!! + # !!! + + return(Ci_h_matrix_modifsvd,SErr_H) +# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! + + + +# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! +def get_Ci_overlap_matrix_modifsvd(): + + Ci_overlap_matrix_modifsvd = np.zeros( (n_modifsvd,n_modifsvd) ) + SErr_O = np.zeros( (n_modifsvd,n_modifsvd) ) + + beg_Ci_overlap_matrix_modifsvd = results.find('Ci_overlap_matrix_modifsvd : [ ') + len( 'Ci_overlap_matrix_modifsvd : [ ' ) + end_Ci_overlap_matrix_modifsvd = len(results) + Ci_overlap_matrix_modifsvd_buf = results[beg_Ci_overlap_matrix_modifsvd:end_Ci_overlap_matrix_modifsvd] + Ci_overlap_matrix_modifsvd_buf = Ci_overlap_matrix_modifsvd_buf.split( '\n' ) + + for iline in range(1, n_modifsvd**2+1): + + line = Ci_overlap_matrix_modifsvd_buf[iline].split() + indc = int( line[0] ) + errS = float( line[4] ) + if( indc != iline ): + print(' Error in reading Ci_overlap_matrix_modifsvd') + print(' indc = {}'.format(indc)) + print(' iline = {}'.format(iline)) + break + else: + irow = indc % n_modifsvd + icol = indc // n_modifsvd + if( irow!=0 ): + Ci_overlap_matrix_modifsvd[irow-1][icol] = float( line[2] ) + SErr_O [irow-1][icol] = float( line[4] ) + else: + Ci_overlap_matrix_modifsvd[n_modifsvd-1][icol-1] = float( line[2] ) + SErr_O [n_modifsvd-1][icol-1] = float( line[4] ) + + return(Ci_overlap_matrix_modifsvd,SErr_O) +# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! + + + + +# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! +def check_symmetric(a, tol=1e-3): + return np.all(np.abs(a-a.T) < tol) +# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! + + + +# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! +def get_Esvd(): + + Ci_h_matrix_modifsvd , SErr_H = get_Ci_h_matrix_modifsvd() + Ci_overlap_matrix_modifsvd, SErr_O = get_Ci_overlap_matrix_modifsvd() + + if( save_compactSVD_QMCmat ): + with open('compactSVD_QMCmat.txt', 'a') as ff: + for i in range(n_modifsvd): + for j in range(n_modifsvd): + ff.write('{} {} {} {} {} {} \n'.format(i,j + , Ci_h_matrix_modifsvd[i,j] , SErr_H[i,j] + , Ci_overlap_matrix_modifsvd[i,j] , SErr_O[i,j] )) + + # symmetrise and diagonalise + aa = Ci_h_matrix_modifsvd + aa = 0.5*( aa + aa.T ) + bb = Ci_overlap_matrix_modifsvd + eigvals_modifsvd, vr = eig(aa, bb, left=False, right=True, overwrite_a=True, overwrite_b=True, + check_finite=True, homogeneous_eigvals=False) + + psi_tmp = psi_svd_coefs[0,0:n_modifsvd] + recouvre_modifsvd = np.abs(psi_tmp @ vr) + ind_gssvd = np.argmax(recouvre_modifsvd) + + E_modifsvd = eigvals_modifsvd[ind_gssvd] + E_toadd + + return( E_modifsvd, vr[:,ind_gssvd] ) +# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! + + + + +if __name__ == '__main__': + + t0 = time.time() + + # ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ # + #EZFIO_file = "Cr2_compactSVD30" + + + + EZFIO_file = "Cr2_compactSVD30_it1" + + E_toadd = 64.8242130309350 + # ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ # + + ezfio.set_file(EZFIO_file) + n_svd = ezfio.get_spindeterminants_n_svd_coefs() + n_modifsvd = ezfio.get_spindeterminants_n_modifsvd_coefs() + psi_svd_coefs = np.array(ezfio.get_spindeterminants_psi_svd_coefs()) + + print(" ") + print(" Today's date:", datetime.now() ) + print(" EZFIO file = {}".format(EZFIO_file)) + print(" n_svd = {}".format(n_svd) ) + print(" n_modifsvd = {}\n".format(n_modifsvd) ) + + t_read = time.time() + print(' getting QMCCHEM results from {}'.format(EZFIO_file) ) + results = subprocess.check_output(['qmcchem', 'result', EZFIO_file], encoding='UTF-8') + print(' getting results after {} minutes \n'.format( (time.time()-t_read)/60. )) + + if( len(results)<100): + print(' result is empty \n') + exit() + + Eloc, ErrEloc = get_energy() + print(' Eloc = {} +/- {}'.format(Eloc, ErrEloc)) + print(' {} <= Eloc <= {}'.format(Eloc-ErrEloc,Eloc+ErrEloc)) + #print(' initial svd coeff = {}\n'.format(psi_svd_coefs)) + + save_compactSVD_QMCmat = True + + print('') + E_compactsvd, sigma_compactsvd = get_Esvd() + print(' compact svd enegry = {}'.format(E_compactsvd) ) + sigma_compactsvd = sigma_compactsvd * np.sign(sigma_compactsvd[0]) + print(' compact svd coeff = {}\n'.format(sigma_compactsvd)) + + #print(' compact svd factor = {}\n'.format(sigma_compactsvd[n_modifsvd-1])) + + # ___________________________________________________________________________ + # ___________________________________________________________________________ + # + #save_to_EZFIO = 'compactsvd_QMC' + save_to_EZFIO = '' + + if( save_to_EZFIO == 'compactsvd_QMC' ): + ezfio_sigma_svd = np.zeros((n_svd)) + + for i in range(n_modifsvd-1): + ezfio_sigma_svd[i] = sigma_compactsvd[i] + for i in range(n_modifsvd-1, n_svd): + ezfio_sigma_svd[i] = psi_svd_coefs[0,i] * sigma_compactsvd[n_modifsvd-1] + + #print(' new svd coeff = {}\n'.format(ezfio_sigma_svd)) + + ezfio.set_spindeterminants_psi_svd_coefs( ezfio_sigma_svd ) + direc_svdcoeff = EZFIO_file + '/spindeterminants/psi_svd_coefs.gz' + print(' {} is modified'.format(direc_svdcoeff) ) + else: + print(' no modifications has been done in {}'.format(EZFIO_file)) + # ___________________________________________________________________________ + # ___________________________________________________________________________ + + print("end after {:.3f} minutes".format((time.time()-t0)/60.) ) + + # !!! +# !!! + +~ +~ + diff --git a/devel/svdwf/f2_work/f2_opt/SVD_opt/LOBD_postVMC.py b/devel/svdwf/f2_work/f2_opt/SVD_opt/LOBD_postVMC.py new file mode 100644 index 0000000..7274b0d --- /dev/null +++ b/devel/svdwf/f2_work/f2_opt/SVD_opt/LOBD_postVMC.py @@ -0,0 +1,166 @@ +# !!! +import sys, os +QMCCHEM_PATH=os.environ["QMCCHEM_PATH"] +sys.path.insert(0,QMCCHEM_PATH+"/EZFIO/Python/") + + +from ezfio import ezfio +from math import sqrt +from datetime import datetime +import time +import numpy as np +import subprocess +from scipy.linalg import eig, eigh + + + +# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! +def get_energy(): + buffer = subprocess.check_output(['qmcchem', 'result', '-e', 'e_loc', EZFIO_file], encoding='UTF-8') + if buffer.strip() != "": + buffer = buffer.splitlines()[-1] + _, energy, error = [float(x) for x in buffer.split()] + return energy, error + else: + return None, None +# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! + + + + +# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! +def get_Ci_h_matrix_svd(): + + Ci_h_matrix_svd = np.zeros( (n_svd,n_svd) ) + SErr_H = np.zeros( (n_svd,n_svd) ) + + f = open(VMCmat_file, 'r') + Lines = f.readlines() + for line in Lines: + line = line.split() + ii = int ( line[0] ) + jj = int ( line[1] ) + Ci_h_matrix_svd[ii][jj] = float( line[2] ) + SErr_H [ii][jj] = float( line[3] ) + + return(Ci_h_matrix_svd,SErr_H) +# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! + + + +# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! +def get_Ci_overlap_matrix_svd(): + + Ci_overlap_matrix_svd = np.zeros( (n_svd,n_svd) ) + SErr_O = np.zeros( (n_svd,n_svd) ) + + f = open(VMCmat_file, 'r') + Lines = f.readlines() + for line in Lines: + line = line.split() + ii = int ( line[0] ) + jj = int ( line[1] ) + Ci_overlap_matrix_svd[ii][jj] = float( line[4] ) + SErr_O [ii][jj] = float( line[5] ) + + return(Ci_overlap_matrix_svd,SErr_O) +# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! + + + +# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! +def check_symmetric(a, tol=1e-3): + return np.all(np.abs(a-a.T) < tol) +# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! + + + +# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! +def get_Esvd(): + + # read CI_SVD matrices + Ci_h_matrix_svd , SErr_H = get_Ci_h_matrix_svd() + Ci_overlap_matrix_svd, SErr_O = get_Ci_overlap_matrix_svd() + + #print( 'Ci_h_matrix_svd is symmetric ? {}' .format(check_symmetric(Ci_h_matrix_svd)) ) + #print( 'Ci_overlap_matrix_svd is symmetric ? {}' .format(check_symmetric(Ci_overlap_matrix_svd)) ) + + # symmetrise and diagonalise + aa = Ci_h_matrix_svd + aa = 0.5*( aa + aa.T ) + bb = Ci_overlap_matrix_svd + eigvals_svd, vr = eig(aa, bb, left=False, right=True, overwrite_a=True, overwrite_b=True, + check_finite=True, homogeneous_eigvals=False) + + #print( eigvals_svd + E_toadd ) + recouvre_svd = np.abs(psi_svd_coeff @ vr) + ind_gssvd = np.argmax(recouvre_svd) + + E_svd = eigvals_svd[ind_gssvd] + E_toadd + + return( E_svd, vr[:,ind_gssvd] ) +# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! + + + + + +# _________________________________________________________________________________________________ +# _________________________________________________________________________________________________ +# +if __name__ == '__main__': + + t0 = time.time() + print(" ") + print(" Today's date:\n", datetime.now() ) + + # ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ # + + #EZFIO_file = "Cr2_TSVD30_it2" + + E_toadd = 30.35863309325590 + # ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ # + + ezfio.set_file(EZFIO_file) + n_svd = ezfio.get_spindeterminants_n_svd_coefs() + psi_svd_coeff = np.array(ezfio.get_spindeterminants_psi_svd_coefs()) + + print(" EZFIO file = {}".format(EZFIO_file)) + print(" n_svd = {}\n".format(n_svd) ) + + #VMCmat_list = [ 'SVD_QMCmat_FSVD_2b.txt' , 'SVD_QMCmat_FSVD_3b.txt' , 'SVD_QMCmat_FSVD_0.txt' ] + #VMCmat_list = [ 'SVD_QMCmat_FSVD_2b_1.txt', 'SVD_QMCmat_FSVD_3b_1.txt' + # , 'SVD_QMCmat_FSVD_4b_1.txt', 'SVD_QMCmat_FSVD_5b_1.txt' + # , 'SVD_QMCmat_FSVD_1.txt' ] + #for VMCmat_file in VMCmat_list: + # print(" SVD matrices file = {}".format(VMCmat_file)) + # E_svd, sigma_svd = get_Esvd() + # print(' svd enegry = {} \n'.format(E_svd) ) + + + VMCmat_file = 'SVD_QMCmat_FSVD_4b_1.txt' + print(" SVD matrices file = {}".format(VMCmat_file)) + E_svd, sigma_svd = get_Esvd() + sigma_svd = sigma_svd * np.sign(sigma_svd[0]) + print(' svd coeff = {}'.format(sigma_svd)) + + # ___________________________________________________________________________ + # ___________________________________________________________________________ + # + #save_to_EZFIO = 'svd_QMC' + save_to_EZFIO = '' + + if( save_to_EZFIO == 'svd_QMC' ): + ezfio.set_spindeterminants_psi_svd_coefs( sigma_svd ) + direc_svdcoeff = EZFIO_file + '/spindeterminants/psi_svd_coefs.gz' + print(' {} is modified'.format(direc_svdcoeff) ) + else: + pass + # ___________________________________________________________________________ + # ___________________________________________________________________________ + + print("end after {:.3f} minutes".format((time.time()-t0)/60.) ) +# _________________________________________________________________________________________________ +# _________________________________________________________________________________________________ +# _________________________________________________________________________________________________ +~ diff --git a/devel/svdwf/f2_work/f2_opt/SVD_opt/LOBD_postcompactSVD.py b/devel/svdwf/f2_work/f2_opt/SVD_opt/LOBD_postcompactSVD.py new file mode 100644 index 0000000..a4c30b2 --- /dev/null +++ b/devel/svdwf/f2_work/f2_opt/SVD_opt/LOBD_postcompactSVD.py @@ -0,0 +1,173 @@ +# !!! +import sys, os +QMCCHEM_PATH=os.environ["QMCCHEM_PATH"] +sys.path.insert(0,QMCCHEM_PATH+"/EZFIO/Python/") + + +from ezfio import ezfio +from math import sqrt +from datetime import datetime +import time +import numpy as np +import subprocess +from scipy.linalg import eig, eigh + + + +# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! +def get_energy(): + buffer = subprocess.check_output(['qmcchem', 'result', '-e', 'e_loc', EZFIO_file], encoding='UTF-8') + if buffer.strip() != "": + buffer = buffer.splitlines()[-1] + _, energy, error = [float(x) for x in buffer.split()] + return energy, error + else: + return None, None +# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! + + + +# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! +def get_Ci_h_matrix_modifsvd(): + + Ci_h_matrix_modifsvd = np.zeros( (n_modifsvd,n_modifsvd) ) + SErr_H = np.zeros( (n_modifsvd,n_modifsvd) ) + + f = open(compactVMCmat_file, 'r') + Lines = f.readlines() + for line in Lines: + line = line.split() + ii = int ( line[0] ) + jj = int ( line[1] ) + Ci_h_matrix_modifsvd[ii][jj] = float( line[2] ) + SErr_H [ii][jj] = float( line[3] ) + + return(Ci_h_matrix_modifsvd,SErr_H) +# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! + + + + +# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! +def get_Ci_overlap_matrix_modifsvd(): + + Ci_overlap_matrix_modifsvd = np.zeros( (n_modifsvd,n_modifsvd) ) + SErr_O = np.zeros( (n_modifsvd,n_modifsvd) ) + + f = open(compactVMCmat_file, 'r') + Lines = f.readlines() + for line in Lines: + line = line.split() + ii = int ( line[0] ) + jj = int ( line[1] ) + Ci_overlap_matrix_modifsvd[ii][jj] = float( line[4] ) + SErr_O [ii][jj] = float( line[5] ) + + return(Ci_overlap_matrix_modifsvd,SErr_O) +# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! + + + +# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! +def check_symmetric(a, tol=1e-3): + return np.all(np.abs(a-a.T) < tol) +# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! + + + +# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! +def get_Esvd(): + + Ci_h_matrix_modifsvd , SErr_H = get_Ci_h_matrix_modifsvd() + Ci_overlap_matrix_modifsvd, SErr_O = get_Ci_overlap_matrix_modifsvd() + + # symmetrise and diagonalise + aa = Ci_h_matrix_modifsvd + aa = 0.5*( aa + aa.T ) + bb = Ci_overlap_matrix_modifsvd + eigvals_modifsvd, vr = eig(aa, bb, left=False, right=True, overwrite_a=True, overwrite_b=True, + check_finite=True, homogeneous_eigvals=False) + + psi_tmp = psi_svd_coefs[0,0:n_modifsvd] + recouvre_modifsvd = np.abs(psi_tmp @ vr) + ind_gssvd = np.argmax(recouvre_modifsvd) + + E_modifsvd = eigvals_modifsvd[ind_gssvd] + E_toadd + + return( E_modifsvd, vr[:,ind_gssvd] ) +# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! + + + + +if __name__ == '__main__': + + t0 = time.time() + + # ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ # + #EZFIO_file = "Cr2_compactSVD30" + + #EZFIO_file = "Cr2_compactSVD30_it1" + EZFIO_file = "Cr2_compactSVD30_it1_1" + + E_toadd = 64.8242130309350 + # ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ # + + ezfio.set_file(EZFIO_file) + n_svd = ezfio.get_spindeterminants_n_svd_coefs() + n_modifsvd = ezfio.get_spindeterminants_n_modifsvd_coefs() + psi_svd_coefs = np.array(ezfio.get_spindeterminants_psi_svd_coefs()) + + print(" ") + print(" Today's date:", datetime.now() ) + print(" EZFIO file = {}".format(EZFIO_file)) + print(" n_svd = {}".format(n_svd) ) + print(" n_modifsvd = {}\n".format(n_modifsvd) ) + #print(' initial svd coeff = {}\n'.format(psi_svd_coefs)) + + compactVMCmat_list = [ 'compactSVD_QMCmat_1.txt' , 'compactSVD_QMCmat_2.txt' ] + for compactVMCmat_file in compactVMCmat_list: + print(" compactSVD matrices file = {}".format(compactVMCmat_file)) + E_compactsvd, sigma_compactsvd = get_Esvd() + print(' compact svd enegry = {}'.format(E_compactsvd) ) + + print('') + compactVMCmat_file = 'compactSVD_QMCmat_1.txt' + print(" compactSVD matrices file = {}".format(compactVMCmat_file)) + E_compactsvd, sigma_compactsvd = get_Esvd() + sigma_compactsvd = sigma_compactsvd * np.sign(sigma_compactsvd[0]) + print(' compact svd enegry = {}'.format(E_compactsvd) ) + print(' compact svd coeff = {}\n'.format(sigma_compactsvd)) + + print(' compact svd factor = {}\n'.format(sigma_compactsvd[n_modifsvd-1])) + + # ___________________________________________________________________________ + # ___________________________________________________________________________ + # + #save_to_EZFIO = 'compactsvd_QMC' + save_to_EZFIO = '' + + if( save_to_EZFIO == 'compactsvd_QMC' ): + ezfio_sigma_svd = np.zeros((n_svd)) + + for i in range(n_modifsvd-1): + ezfio_sigma_svd[i] = sigma_compactsvd[i] + for i in range(n_modifsvd-1, n_svd): + ezfio_sigma_svd[i] = psi_svd_coefs[0,i] * sigma_compactsvd[n_modifsvd-1] + + #print(' new svd coeff = {}\n'.format(ezfio_sigma_svd)) + + ezfio.set_spindeterminants_psi_svd_coefs( ezfio_sigma_svd ) + direc_svdcoeff = EZFIO_file + '/spindeterminants/psi_svd_coefs.gz' + print(' {} is modified'.format(direc_svdcoeff) ) + else: + print(' no modifications has been done in {}'.format(EZFIO_file)) + # ___________________________________________________________________________ + # ___________________________________________________________________________ + + print("end after {:.3f} minutes".format((time.time()-t0)/60.) ) + + # !!! +# !!! + +~ diff --git a/devel/svdwf/f2_work/f2_opt/dress_opt/dress_SVD.py b/devel/svdwf/f2_work/f2_opt/dress_opt/dress_SVD.py new file mode 100755 index 0000000..be0d52f --- /dev/null +++ b/devel/svdwf/f2_work/f2_opt/dress_opt/dress_SVD.py @@ -0,0 +1,188 @@ +#!/usr/bin/env python + +import numpy as np +import subprocess +import sys, os +import time +from datetime import datetime + +QP_PATH=os.environ["QP_ROOT"]+"/external/ezfio/Python/" +sys.path.insert(0,QP_PATH) + +from ezfio import ezfio + + +#____________________________________________________________________________________ +# +def get_energy(): + energy_buffer = subprocess.check_output( + ['qmcchem', 'result', '-e', 'e_loc', EZFIO_file] + , encoding='UTF-8') + + if energy_buffer.strip() != "": + energy_buffer = energy_buffer.splitlines()[-1] + _, energy, error = [float(x) for x in energy_buffer.split()] + return energy, error + else: + return None, None +#____________________________________________________________________________________ + + + +#____________________________________________________________________________________ +# +def read_scalar(scalar): + + scal_txt = scalar + ' : ' + beg_read = results.find(scal_txt) + len(scal_txt) + scal_buf = results[beg_read:beg_read+100].split('\n')[0].split() + + scal_val , scal_err = float( scal_buf[0] ) , float( scal_buf[2] ) + + return(scal_val,scal_err) +#____________________________________________________________________________________ + + + + +#____________________________________________________________________________________ +# +def read_ci_dress_svd(): + + Ci_dress_svd_val = np.zeros((n_svd)) + Ci_dress_svd_err = np.zeros((n_svd)) + + beg_read = results.find('Ci_dress_svd : [ ') + len( 'Ci_dress_svd : [ ' ) + end_read = len(results) + vect_buf = results[beg_read:end_read] + vect_buf = vect_buf.split( '\n' ) + + for iline in range(1, n_svd+1): + line = vect_buf[iline].split() + + # check + indc = int( line[0] ) + if( indc != iline ): + print(' Error in reading Ci_dress_svd') + print(' indc = {}'.format(indc) ) + print(' iline = {}'.format(iline) ) + break + else: + Ci_dress_svd_val[indc-1] = float( line[2] ) + Ci_dress_svd_err[indc-1] = float( line[4] ) + + return(Ci_dress_svd_val,Ci_dress_svd_err) +#____________________________________________________________________________________ + + +#____________________________________________________________________________________ +# +def get_ci_dress(): + + U_svd = np.array(ezfio.get_spindeterminants_psi_svd_alpha()) + V_svd = np.array(ezfio.get_spindeterminants_psi_svd_beta()) + U_svd = U_svd[0,:,:].T + V_svd = V_svd[0,:,:].T + + ci_dress_mat_val = np.dot(U_svd,np.dot(np.diagflat(Ci_dress_svd_val),V_svd.T)) + ci_dress_mat_err = np.dot(U_svd,np.dot(np.diagflat(Ci_dress_svd_err),V_svd.T)) + + n_det = ezfio.get_spindeterminants_n_det() + i_row = np.array(ezfio.get_spindeterminants_psi_coef_matrix_rows()) + j_col = np.array(ezfio.get_spindeterminants_psi_coef_matrix_columns()) + + Ci_dress_val = np.zeros((n_det)) + Ci_dress_err = np.zeros((n_det)) + for k in range(n_det): + i = i_row[k] - 1 + j = j_col[k] - 1 + Ci_dress_val[k] = ci_dress_mat_val[i,j] + Ci_dress_err[k] = ci_dress_mat_err[i,j] + + Ci_dress_val = Ci_dress_val / psi_norm + Ci_dress_err = Ci_dress_err / psi_norm + + return(Ci_dress_val,Ci_dress_err) +#____________________________________________________________________________________ + + + + +#____________________________________________________________________________________ +# +def save_to_file(v_val,v_err, name_f): + + with open(name_f, 'w') as ff: + for i in range(len(v_val)): + ff.write(' {} {} {}\n'.format(i, v_val[i], v_err[i])) +#____________________________________________________________________________________ + + + + + + +# _________________________________________________________________________________________________ +# _________________________________________________________________________________________________ +# +if __name__ == '__main__': + + t0 = time.time() + print(" ") + print(" Today's date:\n", datetime.now() ) + + # _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ + # + #EZFIO_file = sys.argv[1] + EZFIO_file = "/home/aammar/qp2/src/svdwf/f2_work/f2_opt/dress_opt/f2_cisd" + # _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ + + ezfio.set_file(EZFIO_file) + + n_svd = ezfio.get_spindeterminants_n_svd_coefs() + + print(" EZFIO file = {}".format(EZFIO_file)) + print(" n_svd = {}\n".format(n_svd) ) + + t_read = time.time() + print(' getting QMCCHEM results from {}'.format(EZFIO_file) ) + results = subprocess.check_output(['qmcchem', 'result', EZFIO_file], encoding='UTF-8') + print(' getting results after {} minutes \n'.format( (time.time()-t_read)/60. )) + + + # -------------------- + # read QMC results + E_loc, ErrE_loc = get_energy() + print(' E_loc = {} +/- {}'.format(E_loc, ErrE_loc)) + print(' {} <= E_loc <= {}\n'.format(E_loc-ErrE_loc,E_loc+ErrE_loc)) + + E_loc_qmcvar, ErrE_loc_qmcvar = read_scalar('E_loc_qmcvar') + print(' E_loc_qmcvar = {} +/- {} \n'.format(E_loc_qmcvar,ErrE_loc_qmcvar)) + + psi_norm, Errpsi_norm = read_scalar('Psi_norm') + print(' psi_norm = {} +/- {}\n'.format(psi_norm,Errpsi_norm)) + + psi_norm_qmcvar, Errpsi_norm_qmcvar = read_scalar('Psi_norm_qmcvar') + print(' Psi_norm_qmcvar = {} +/- {} \n'.format(psi_norm_qmcvar, Errpsi_norm_qmcvar)) + + Ci_dress_svd_val, Ci_dress_svd_err = read_ci_dress_svd() + # -------------------- + # -------------------- + + Ci_dress_val, Ci_dress_err = get_ci_dress() + + save_to_file(Ci_dress_svd_val,Ci_dress_svd_err, 'ci_dress_svd.txt') + save_to_file(Ci_dress_val,Ci_dress_err, 'ci_dress.txt') + + # _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ + # + # SAVE TO EZFIO + # + #ezfio.set_dmc_dress_dmc_delta_h(Ci_dress_val) + # _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ + # + + print("end after {:.3f} minutes".format((time.time()-t0)/60.) ) +# _________________________________________________________________________________________________ +# _________________________________________________________________________________________________ +# _________________________________________________________________________________________________ diff --git a/devel/svdwf/f2_work/f2_opt/dress_opt/info.txt b/devel/svdwf/f2_work/f2_opt/dress_opt/info.txt new file mode 100644 index 0000000..1e7584d --- /dev/null +++ b/devel/svdwf/f2_work/f2_opt/dress_opt/info.txt @@ -0,0 +1,25 @@ + + + + 1- prepare the dressing vector in EZFIO/dmc_dress/dmc_delta_h with: + + [aammar@lcpq-curie dress_opt]$ python dress_SVD.py + + + + 2- run: + + [aammar@lcpq-curie dress_opt]$ qp run dmc_dress + + + + 3- update the wavefunction in the EZFIO with: + + [aammar@lcpq-curie dress_opt]$ qp run dmc_dress + + + + 4- to do the calculation without SVD, put -1 for n_SVD + in EZFIO/spindeterminants/n_svd_coefs. Otherwise, run: + + [aammar@lcpq-curie dress_opt]$ qp run FSVD_trunc diff --git a/devel/svdwf/f2_work/f2_opt/opt_Jas/modif_powell_imp.py b/devel/svdwf/f2_work/f2_opt/opt_Jas/modif_powell_imp.py new file mode 100644 index 0000000..0dfb3a4 --- /dev/null +++ b/devel/svdwf/f2_work/f2_opt/opt_Jas/modif_powell_imp.py @@ -0,0 +1,504 @@ +# ******NOTICE*************** +# optimize.py module by Travis E. Oliphant +# +# You may copy and use this module as you see fit with no +# guarantee implied provided you keep this notice in all copies. +# *****END NOTICE************ + +import numpy +from numpy import asarray, eye, squeeze, sum + +class Brent: + #need to rethink design of __init__ + def __init__(self, func, args=(), tol=1.48e-8, maxiter=500, + full_output=0): + self.func = func + self.args = args + self.tol = tol + self.maxiter = maxiter + self._mintol = 1.0e-11 + self._cg = 0.3819660 + self.xmin = None + self.fval = None + self.iter = 0 + self.funcalls = 0 + + #need to rethink design of set_bracket (new options, etc) + def set_bracket(self, brack = None): + self.brack = brack + def get_bracket_info(self): + #set up + func = self.func + args = self.args + brack = self.brack + ### BEGIN core bracket_info code ### + ### carefully DOCUMENT any CHANGES in core ## + if brack is None: + xa,xb,xc,fa,fb,fc,funcalls = bracket(func, args=args) + elif len(brack) == 2: + xa,xb,xc,fa,fb,fc,funcalls = bracket(func, xa=brack[0], + xb=brack[1], args=args) + elif len(brack) == 3: + xa,xb,xc = brack + if (xa > xc): # swap so xa < xc can be assumed + dum = xa; xa=xc; xc=dum + assert ((xa < xb) and (xb < xc)), "Not a bracketing interval." + fa = func(*((xa,)+args)) + fb = func(*((xb,)+args)) + fc = func(*((xc,)+args)) + assert ((fb=xmid): deltax=a-x # do a golden section step + else: deltax=b-x + rat = _cg*deltax + else: # do a parabolic step + tmp1 = (x-w)*(fx-fv) + tmp2 = (x-v)*(fx-fw) + p = (x-v)*tmp2 - (x-w)*tmp1; + tmp2 = 2.0*(tmp2-tmp1) + if (tmp2 > 0.0): p = -p + tmp2 = abs(tmp2) + dx_temp = deltax + deltax= rat + # check parabolic fit + if ((p > tmp2*(a-x)) and (p < tmp2*(b-x)) and (abs(p) < abs(0.5*tmp2*dx_temp))): + rat = p*1.0/tmp2 # if parabolic step is useful. + u = x + rat + if ((u-a) < tol2 or (b-u) < tol2): + if xmid-x >= 0: rat = tol1 + else: rat = -tol1 + else: + if (x>=xmid): deltax=a-x # if it's not do a golden section step + else: deltax=b-x + rat = _cg*deltax + + if (abs(rat) < tol1): # update by at least tol1 + if rat >= 0: u = x + tol1 + else: u = x - tol1 + else: + u = x + rat + fu = func(*((u,)+self.args)) # calculate new output value + funcalls += 1 + + if (fu > fx): # if it's bigger than current + if (u= x): a = x + else: b = x + v=w; w=x; x=u + fv=fw; fw=fx; fx=fu + + iter += 1 + ################################# + #END CORE ALGORITHM + ################################# + + self.xmin = x + self.fval = fx + self.iter = iter + self.funcalls = funcalls + + def get_result(self, full_output=False): + if full_output: + return self.xmin, self.fval, self.iter, self.funcalls + else: + return self.xmin + +def wrap_function(function, args): + ncalls = [0] + def function_wrapper(x): + ncalls[0] += 1 + return function(x, *args) + return ncalls, function_wrapper + +def brent(func, args=(), brack=None, tol=1.48e-8, full_output=0, maxiter=500): + """Given a function of one-variable and a possible bracketing interval, + return the minimum of the function isolated to a fractional precision of + tol. + + Parameters + ---------- + func : callable f(x,*args) + Objective function. + args + Additional arguments (if present). + brack : tuple + Triple (a,b,c) where (a f(xb) < f(xc). It doesn't always mean that obtained + solution will satisfy xa<=x<=xb + + Parameters + ---------- + func : callable f(x,*args) + Objective function to minimize. + xa, xb : float + Bracketing interval. + args : tuple + Additional arguments (if present), passed to `func`. + grow_limit : float + Maximum grow limit. + maxiter : int + Maximum number of iterations to perform. + + Returns + ------- + xa, xb, xc : float + Bracket. + fa, fb, fc : float + Objective function values in bracket. + funcalls : int + Number of function evaluations made. + + """ + _gold = 1.618034 + _verysmall_num = 1e-21 + fa = func(*(xa,)+args) + fb = func(*(xb,)+args) + if (fa < fb): # Switch so fa > fb + dum = xa; xa = xb; xb = dum + dum = fa; fa = fb; fb = dum + xc = xb + _gold*(xb-xa) + fc = func(*((xc,)+args)) + funcalls = 3 + iter = 0 + while (fc < fb): + tmp1 = (xb - xa)*(fb-fc) + tmp2 = (xb - xc)*(fb-fa) + val = tmp2-tmp1 + if abs(val) < _verysmall_num: + denom = 2.0*_verysmall_num + else: + denom = 2.0*val + w = xb - ((xb-xc)*tmp2-(xb-xa)*tmp1)/denom + wlim = xb + grow_limit*(xc-xb) + if iter > maxiter: + #raise RuntimeError, "Too many iterations." + raise RuntimeError("Too many iterations.") + iter += 1 + if (w-xc)*(xb-w) > 0.0: + fw = func(*((w,)+args)) + funcalls += 1 + if (fw < fc): + xa = xb; xb=w; fa=fb; fb=fw + return xa, xb, xc, fa, fb, fc, funcalls + elif (fw > fb): + xc = w; fc=fw + return xa, xb, xc, fa, fb, fc, funcalls + w = xc + _gold*(xc-xb) + fw = func(*((w,)+args)) + funcalls += 1 + elif (w-wlim)*(wlim-xc) >= 0.0: + w = wlim + fw = func(*((w,)+args)) + funcalls += 1 + elif (w-wlim)*(xc-w) > 0.0: + fw = func(*((w,)+args)) + funcalls += 1 + if (fw < fc): + xb=xc; xc=w; w=xc+_gold*(xc-xb) + fb=fc; fc=fw; fw=func(*((w,)+args)) + funcalls += 1 + else: + w = xc + _gold*(xc-xb) + fw = func(*((w,)+args)) + funcalls += 1 + xa=xb; xb=xc; xc=w + fa=fb; fb=fc; fc=fw + return xa, xb, xc, fa, fb, fc, funcalls + + + + +def _linesearch_powell(func, p, xi, tol=1e-3): + """Line-search algorithm using fminbound. + + Find the minimium of the function ``func(x0+ alpha*direc)``. + + """ + def myfunc(alpha): + return func(p + alpha * xi) + alpha_min, fret, iter, num = brent(myfunc, full_output=1, tol=tol) + xi = alpha_min*xi + return squeeze(fret), p+xi, xi + + +def fmin_powell(func, x0, args=(), xtol=1e-4, ftol=1e-4, maxiter=None, + maxfun=None, full_output=0, disp=1, retall=0, callback=None, + direc=None): + """Minimize a function using modified Powell's method. + + Parameters + ---------- + func : callable f(x,*args) + Objective function to be minimized. + x0 : ndarray + Initial guess. + args : tuple + Eextra arguments passed to func. + callback : callable + An optional user-supplied function, called after each + iteration. Called as ``callback(xk)``, where ``xk`` is the + current parameter vector. + direc : ndarray + Initial direction set. + + Returns + ------- + xopt : ndarray + Parameter which minimizes `func`. + fopt : number + Value of function at minimum: ``fopt = func(xopt)``. + direc : ndarray + Current direction set. + iter : int + Number of iterations. + funcalls : int + Number of function calls made. + warnflag : int + Integer warning flag: + 1 : Maximum number of function evaluations. + 2 : Maximum number of iterations. + allvecs : list + List of solutions at each iteration. + + Other Parameters + ---------------- + xtol : float + Line-search error tolerance. + ftol : float + Relative error in ``func(xopt)`` acceptable for convergence. + maxiter : int + Maximum number of iterations to perform. + maxfun : int + Maximum number of function evaluations to make. + full_output : bool + If True, fopt, xi, direc, iter, funcalls, and + warnflag are returned. + disp : bool + If True, print convergence messages. + retall : bool + If True, return a list of the solution at each iteration. + + Notes + ----- + Uses a modification of Powell's method to find the minimum of + a function of N variables. + + """ + # we need to use a mutable object here that we can update in the + # wrapper function + fcalls, func = wrap_function(func, args) + x = asarray(x0).flatten() + if retall: + allvecs = [x] + N = len(x) + rank = len(x.shape) + if not -1 < rank < 2: + #raise ValueError, "Initial guess must be a scalar or rank-1 sequence." + raise ValueError("Initial guess must be a scalar or rank-1 sequence.") + if maxiter is None: + maxiter = N * 1000 + if maxfun is None: + maxfun = N * 1000 + + + if direc is None: + direc = eye(N, dtype=float) + else: + direc = asarray(direc, dtype=float) + + fval = squeeze(func(x)) + x1 = x.copy() + iter = 0; + ilist = range(N) + while True: + fx = fval + bigind = 0 + delta = 0.0 + for i in ilist: + direc1 = direc[i] + fx2 = fval + fval, x, direc1 = _linesearch_powell(func, x, direc1, tol=xtol*100) + if (fx2 - fval) > delta: + delta = fx2 - fval + bigind = i + iter += 1 + if callback is not None: + callback(x) + if retall: + allvecs.append(x) + if (2.0*(fx - fval) <= ftol*(abs(fx)+abs(fval))+1e-20): break + if fcalls[0] >= maxfun: break + if iter >= maxiter: break + + # Construct the extrapolated point + direc1 = x - x1 + x2 = 2*x - x1 + x1 = x.copy() + fx2 = squeeze(func(x2)) + + if (fx > fx2): + t = 2.0*(fx+fx2-2.0*fval) + temp = (fx-fval-delta) + t *= temp*temp + temp = fx-fx2 + t -= delta*temp*temp + if t < 0.0: + fval, x, direc1 = _linesearch_powell(func, x, direc1, + tol=xtol*100) + direc[bigind] = direc[-1] + direc[-1] = direc1 + + warnflag = 0 + if fcalls[0] >= maxfun: + warnflag = 1 + if disp: + print("Warning: Maximum number of function evaluations has been exceeded.") + elif iter >= maxiter: + warnflag = 2 + if disp: + print("Warning: Maximum number of iterations has been exceeded") + else: + if disp: + print("Optimization terminated successfully.") + print(" Current function value: %f" % fval) + print(" Iterations: %d" % iter) + print(" Function evaluations: %d" % fcalls[0]) + + x = squeeze(x) + + if full_output: + retlist = x, fval, direc, iter, fcalls[0], warnflag + if retall: + retlist += (allvecs,) + else: + retlist = x + if retall: + retlist = (x, allvecs) + + return retlist + +# +# Scipy powell optimization method does not have xmin, xmax. The following +# is just a simple wrapper on the optimization method. +# +def my_fmin_powell( fcn, x0, xmin, xmax, args=(), xtol=1e-4, ftol=1e-4, + maxiter=None, maxfev=None, full_output=0, verbose=0, + retall=0, callback=None, direc=None): + + FUNC_MAX = numpy.float_(numpy.finfo(numpy.float_).max) + + N = len( x0 ) + if maxiter is None: + maxiter = N * 1000 + + if maxfev is None: + maxfev = N * 1000 + + def _outside_limits(x, xmin, xmax): + return (numpy.any(x < xmin) or numpy.any(x > xmax)) + + myxmin = asarray( xmin ) + myxmax = asarray( xmax ) + orig_fcn = fcn + def fcn(x_new): + if _outside_limits(x_new, myxmin, myxmax): + return FUNC_MAX + return orig_fcn(x_new) + + result = fmin_powell( fcn, asarray(x0), args=args, xtol=xtol, ftol=ftol, + maxiter=maxiter, full_output=1, disp=verbose, + retall=retall, callback=callback, direc=direc ) + xpar = result[ 0 ] + fval = result[ 1 ] + nfev = result[ 4 ] + warnflag = result[ 5 ] + + key = { + 0: (True, 'Optimization terminated successfully.'), + 1: (False, + 'number of function evaluations has exceeded maxfev=%d' % maxfev), + 2: (False, + 'number of iterations has exceeded maxiter=%d' % maxiter) + } + + status, msg = key.get(warnflag, (False, 'unknown status flag (%d)' % warnflag)) + retlist = (status, xpar, fval ) + retlist += ( msg, { 'info' : warnflag, 'nfev': nfev } ) + return retlist + diff --git a/devel/svdwf/f2_work/f2_opt/opt_Jas/opt_jast_freegrad.py b/devel/svdwf/f2_work/f2_opt/opt_Jas/opt_jast_freegrad.py new file mode 100644 index 0000000..c869e50 --- /dev/null +++ b/devel/svdwf/f2_work/f2_opt/opt_Jas/opt_jast_freegrad.py @@ -0,0 +1,254 @@ + +import sys, os +QMCCHEM_PATH=os.environ["QMCCHEM_PATH"] +sys.path.insert(0,QMCCHEM_PATH+"/EZFIO/Python/") +from ezfio import ezfio +from datetime import datetime +import time +import numpy as np +import subprocess +import atexit +import scipy as sp +import scipy.optimize +from math import sqrt +from modif_powell_imp import my_fmin_powell + + + + +#------------------------------------------------------------------------------ +def make_atom_map(): + labels = {} + dimension = 0 + # i: label of nuclei + # k: counter of nuclei + for i,k in enumerate(ezfio.nuclei_nucl_label): + if k in labels: + labels[k].append(i) + else: + labels[k] = [dimension, i] + dimension += 1 + atom_map = [[] for i in range(dimension)] + for atom in labels.keys(): + l = labels[atom] + atom_map[l[0]] = l[1:] + return atom_map +#------------------------------------------------------------------------------ +#------------------------------------------------------------------------------ + + + +#------------------------------------------------------------------------------ +def get_params_pen(): + d = ezfio.jastrow_jast_pen + return np.array([d[m[0]] for m in atom_map]) +#------------------------------------------------------------------------------ +#------------------------------------------------------------------------------ + + + +#------------------------------------------------------------------------------ +def set_params_pen(x): + y = list(ezfio.jastrow_jast_pen) + for i,m in enumerate(atom_map): + for j in m: + y[j] = x[i] + ezfio.set_jastrow_jast_pen(y) +#------------------------------------------------------------------------------ +#------------------------------------------------------------------------------ + + + +#------------------------------------------------------------------------------ +def get_params_b(): + b = ezfio.get_jastrow_jast_b_up_up() + return b +#------------------------------------------------------------------------------ +#------------------------------------------------------------------------------ + + + + +#------------------------------------------------------------------------------ +def set_params_b(b): + ezfio.set_jastrow_jast_b_up_up(b) + ezfio.set_jastrow_jast_b_up_dn(b) +#------------------------------------------------------------------------------ +#------------------------------------------------------------------------------ + + + + +#------------------------------------------------------------------------------ +def get_energy(): + buffer = subprocess.check_output( + ['qmcchem', 'result', '-e', 'e_loc', EZFIO_file], encoding='UTF-8') + if buffer.strip() != "": + buffer = buffer.splitlines()[-1] + _, energy, error = [float(x) for x in buffer.split()] + return energy, error + else: + return None, None +#------------------------------------------------------------------------------ +#------------------------------------------------------------------------------ + + + + +#------------------------------------------------------------------------------ +def get_variance(): + buffer = subprocess.check_output( + ['qmcchem', 'result', '-e', 'e_loc_qmcvar', EZFIO_file], encoding='UTF-8') + if buffer.strip() != "": + buffer = buffer.splitlines()[-1] + _, variance, error = [float(x) for x in buffer.split()] + return variance, error + else: + return None, None +#------------------------------------------------------------------------------ +#------------------------------------------------------------------------------ + + + +#------------------------------------------------------------------------------ +def set_vmc_params(block_time,total_time): + subprocess.check_output(['qmcchem', 'edit', '-c', '-j', 'Simple', + '-t', str(total_time), + '-l', str(block_time), EZFIO_file]) +#------------------------------------------------------------------------------ +#------------------------------------------------------------------------------ + + +#------------------------------------------------------------------------------ +def run_qmc(): + return subprocess.check_output(['qmcchem', 'run', EZFIO_file]) +#------------------------------------------------------------------------------ +#------------------------------------------------------------------------------ + + + +#------------------------------------------------------------------------------ +def stop_qmc(): + subprocess.check_output(['qmcchem', 'stop', EZFIO_file]) +#------------------------------------------------------------------------------ +#------------------------------------------------------------------------------ + + + +#------------------------------------------------------------------------------ +def f(x): + + global i_fev + global memo_energy + print(' eval {} of f on:'.format(i_fev)) + print(' nuc param Jast = {}'.format(x[:-1])) + print(' b param Jast = {}'.format(x[-1])) + h = str(x) + if h in memo_energy: + return memo_energy[h] + + i_fev = i_fev + 1 + + set_params_pen(x[:-1]) + set_params_b(x[-1]) + block_time_f = 300 + total_time_f = 1000 + set_vmc_params(block_time_f, total_time_f) + + loc_err = 10. + ii = 0 + ii_max = 5 + energy = None + err = None + while( thresh < loc_err ): + run_qmc() + energy, err = get_energy() + if( (energy is None) or (err is None) ): + continue + elif( memo_energy['fmin'] < (energy-2.*err) ): + print(" %d energy: %f %f "%(ii, energy, err)) + break + else: + loc_err = err + ii = ii + 1 + print(" %d energy: %f %f "%(ii, energy, err)) + if( ii_max < ii ): + break + print(" ") + + memo_energy[h] = energy + err + memo_energy['fmin'] = min(energy, memo_energy['fmin']) + + return energy +#------------------------------------------------------------------------------ +#------------------------------------------------------------------------------ + + + + + + + +#_____________________________________________________________________________________________________________ +# +if __name__ == '__main__': + + t0 = time.time() + + # # # ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ # # # + EZFIO_file = "/home/aammar/qp2/src/svdwf/f2_work/f2_opt/opt_Jas/f2_Jastopt" + ezfio.set_file(EZFIO_file) + + # PARAMETERS + thresh = 1.e-2 + + # maximum allowed number of function evaluations + N_fev = 50 + # # # ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ # # # + + + print(" Today's date:", datetime.now() ) + print(" EZFIO file = {}".format(EZFIO_file)) + + # map nuclei to a list + # for f2 this will give: atom_map = [[0, 1]] + atom_map = make_atom_map() + + n_par = len(atom_map) # nb of nclear parameters + n_par = n_par + 1 # e-e parameter b + print(' nb of parameters = {}'.format(n_par)) + + x = get_params_pen() + print(' initial pen: {}'.format(x)) + + b_par = get_params_b() + print(' initial b: {}'.format(b_par)) + + x = np.append(x, b_par) + + + + i_fev = 1 + memo_energy = {'fmin': 100.} + + x_min = [ (0.001) for _ in range(n_par) ] + x_max = [ (9.999) for _ in range(n_par) ] + opt = my_fmin_powell( f, x, x_min, x_max + , xtol = 0.02 + , ftol = thresh + , maxfev = N_fev + , full_output = 1 + , verbose = 1 ) + + print(" x = "+str(opt)) + + #set_params_pen(opt['x']) + print(' number of function evaluations = {}'.format(i_fev)) + print(' memo_energy: {}'.format(memo_energy)) + + + + print(" end after {:.3f} minutes".format((time.time()-t0)/60.) ) +#_____________________________________________________________________________________________________________ +#_____________________________________________________________________________________________________________ +#_____________________________________________________________________________________________________________ diff --git a/devel/svdwf/h2o_work/FN_test/cc_pCVDZ/QMC_nsvd.py b/devel/svdwf/h2o_work/FN_test/cc_pCVDZ/QMC_nsvd.py new file mode 100644 index 0000000..52ab390 --- /dev/null +++ b/devel/svdwf/h2o_work/FN_test/cc_pCVDZ/QMC_nsvd.py @@ -0,0 +1,176 @@ +import sys, os +QMCCHEM_PATH=os.environ["QMCCHEM_PATH"] +sys.path.insert(0,QMCCHEM_PATH+"/EZFIO/Python/") + +from ezfio import ezfio +from datetime import datetime +import time +import numpy as np +import subprocess +from scipy.linalg import eig, eigh + + +# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! +def get_energy(): + buffer = subprocess.check_output( ['qmcchem', 'result', '-e', 'e_loc', EZFIO_file] + , encoding='UTF-8' ) + if buffer.strip() != "": + buffer = buffer.splitlines()[-1] + _, energy, error = [float(x) for x in buffer.split()] + return energy, error + else: + return None, None +# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! + + +# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! +def run_qmc(): + return subprocess.check_output(['qmcchem', 'run', EZFIO_file]) + +def stop_qmc(): + subprocess.check_output(['qmcchem', 'stop', EZFIO_file]) + +def set_vmc_params(): + subprocess.check_output(['qmcchem', 'edit', '-c', '-j', 'None' + , '-m', 'SRMC' + , '-s', 'Brownian' + , '-l', str(block_time) + , '--time-step=0.0005' + , '-t', str(total_time) + , EZFIO_file]) +# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! + + +# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! +def get_Aref(): + Aref = np.zeros( (n_alpha, n_beta) ) + for k in range(n_det): + i = A_rows[k] - 1 + j = A_cols[k] - 1 + Aref[i,j] = A_vals[0][k] + return( Aref ) +# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! + + +# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! +def check_svd_error( A, U, S, Vt ): + norm_A = np.linalg.norm(A, ord='fro') + A_SVD = np.linalg.multi_dot([ U, np.diag(S), Vt ]) + err_SVD = 100. * np.linalg.norm( A - A_SVD, ord="fro") / norm_A + print(' error between A_SVD and Aref = {} %\n'.format(err_SVD) ) +# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! + + +# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! +def TSVD_save_EZFIO(): + + U_toEZFIO = np.zeros( ( 1, U_TSVD.shape[1], U_TSVD.shape[0] ) ) + V_toEZFIO = np.zeros( ( 1, V_TSVD.shape[1], V_TSVD.shape[0] ) ) + U_toEZFIO[0,:,:] = U_TSVD.T + V_toEZFIO[0,:,:] = V_TSVD.T + + ezfio.set_spindeterminants_n_svd_coefs( low_rank ) + ezfio.set_spindeterminants_psi_svd_alpha( U_toEZFIO ) + ezfio.set_spindeterminants_psi_svd_beta ( V_toEZFIO ) + ezfio.set_spindeterminants_psi_svd_coefs( S_TSVD ) + + print(' SVD vectors & coeff are saved to EZFIO ') +# ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! ~ ! + + + + +if __name__ == '__main__': + + t0 = time.time() + print(" Today's date:", datetime.now() ) + + # EZFIO file + EZFIO_file = "/home/aammar/qp2/src/svdwf/h2o_work/FN_test/cc_pCVDZ/h2o_dz_nsvd" + ezfio.set_file(EZFIO_file) + print(" filename = {}".format(EZFIO_file)) + + # parameters + energ_nuc = 9.194966082434476 + + # get spindeterminant data from EZFIO + n_alpha = ezfio.get_spindeterminants_n_det_alpha() + n_beta = ezfio.get_spindeterminants_n_det_beta() + A_rows = np.array(ezfio.get_spindeterminants_psi_coef_matrix_rows() ) + A_cols = np.array(ezfio.get_spindeterminants_psi_coef_matrix_columns()) + A_vals = np.array(ezfio.get_spindeterminants_psi_coef_matrix_values() ) + n_det = A_rows.shape[0] + print(' ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~') + print(' matrix: {} x {}'.format(n_alpha,n_beta)) + print(' n_det = {}'.format(n_det)) + print(' ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~') + # construct intial dense matrix + Aref = get_Aref() + # perform initial Full SVD + print(' ----- Performing Full SVD ----- ') + U_FSVD, S_FSVD, Vt_FSVD = np.linalg.svd(Aref, full_matrices=False) + V_FSVD = Vt_FSVD.T + #print(' initial psi coeff = {}\n'.format(S_FSVD)) + check_svd_error( Aref, U_FSVD, S_FSVD, Vt_FSVD ) + + # run QMC before SVD + block_time = 500 # in sec + total_time = 3000 # in sec + set_vmc_params() + run_qmc() + t_read = time.time() + print(' getting QMCCHEM results from {}'.format(EZFIO_file) ) + results = subprocess.check_output(['qmcchem', 'result', EZFIO_file], encoding='UTF-8') + print(' getting results after {} minutes \n'.format( (time.time()-t_read)/60. )) + Eloc, ErrEloc = get_energy() + print(' Eloc = {} +/- {}'.format(Eloc, ErrEloc)) + print(' {} <= Eloc <= {} \n'.format(Eloc-ErrEloc,Eloc+ErrEloc)) + + #_________________________________________________________________________________________ + # + # loop over truncated rank + #_________________________________________________________________________________________ + + low_rank_min = 5 + low_rank_max = 31 + + for low_rank in range( low_rank_min, low_rank_max+1, 2 ): + + t_it = time.time() + print(" SVD iteration rank = {}".format(low_rank)) + + # SVD naive truncation + U_TSVD = U_FSVD[:, 0:low_rank+1] + V_TSVD = V_FSVD[:, 0:low_rank+1] + Vt_TSVD = V_TSVD.T + S_TSVD = S_FSVD[0:low_rank+1] + + # check truncated SVD error + check_svd_error( Aref, U_TSVD, S_TSVD, Vt_TSVD ) + + # save new coefficients to EZFIO + TSVD_save_EZFIO() + + # set QMC settings and run + block_time = 500 # in sec + total_time = 3000 # in sec + set_vmc_params() + run_qmc() + + # read QMC=CHEM results + t_read = time.time() + print(' getting QMCCHEM results from {}'.format(EZFIO_file) ) + results = subprocess.check_output(['qmcchem', 'result', EZFIO_file], encoding='UTF-8') + print(' getting results after {} minutes \n'.format( (time.time()-t_read)/60. )) + + # < E_loc > + Eloc, ErrEloc = get_energy() + print(' Eloc = {} +/- {}'.format(Eloc, ErrEloc)) + print(' {} <= Eloc <= {} \n'.format(Eloc-ErrEloc,Eloc+ErrEloc)) + + print(" iteration time = {:.3f} minutes \n".format((time.time()-t_it)/60.) ) + #_________________________________________________________________________________________ + + print(" end after {:.3f} minutes".format((time.time()-t0)/60.) ) + +# end diff --git a/devel/svdwf/h2o_work/FN_test/cc_pCVDZ/read_selectedSVD.py b/devel/svdwf/h2o_work/FN_test/cc_pCVDZ/read_selectedSVD.py new file mode 100644 index 0000000..f1e7efc --- /dev/null +++ b/devel/svdwf/h2o_work/FN_test/cc_pCVDZ/read_selectedSVD.py @@ -0,0 +1,62 @@ + +import numpy as np +from ezfio import ezfio +from datetime import datetime +import time +from matplotlib import pyplot as plt +from scipy.sparse import coo_matrix + + + +def plot_coo_matrix(m): + if not isinstance(m, coo_matrix): + m = coo_matrix(m) + fig = plt.figure() + ax = fig.add_subplot(111, facecolor='black') + ax.plot(m.col, m.row, 's', color='white', ms=1) + ax.set_xlim(0, m.shape[1]) + ax.set_ylim(0, m.shape[0]) + ax.set_aspect('equal') + for spine in ax.spines.values(): + spine.set_visible(False) + ax.invert_yaxis() + ax.set_aspect('equal') + ax.set_xticks([]) + ax.set_yticks([]) + return ax + + +if __name__ == "__main__": + + t0 = time.time() + + EZFIO_file = "/home/aammar/qp2/src/svdwf/h2o_work/FN_test/cc_pCVDZ/h2o_dz" + ezfio.set_file(EZFIO_file) + print(" EZFIO = {}\n".format(EZFIO_file)) + + n_alpha = ezfio.get_spindeterminants_n_det_alpha() + n_beta = ezfio.get_spindeterminants_n_det_beta() + print(' matrix: {} x {}\n'.format(n_alpha,n_beta)) + + n_selected = 15 * 15 + + # selected with v2 + f = open("fort.222", "r") + lines = f.readlines() + f.close() + E_v2 = float(lines[-1].split()[4]) + deltaE_v2 = np.zeros((n_alpha,n_beta)) + rows, cols, vals = [], [], [] + print("E_v2 = {}\n".format(E_v2)) + for i in range(n_selected): + line = lines[i].split() + ia, ib = int(line[1]), int(line[2]) + deltaE_v2[ia,ib] = float(line[3])/E_v2 + rows.append(ia) + cols.append(ib) + vals.append(deltaE_v2[ia,ib]) + + m = coo_matrix((vals, (rows, cols)), shape=(n_alpha,n_beta)) + ax = plot_coo_matrix(m) + ax.figure.savefig("selected_SVD.pdf") + diff --git a/devel/svdwf/invFSVD_det.irp.f b/devel/svdwf/invFSVD_det.irp.f new file mode 100644 index 0000000..3e6fb24 --- /dev/null +++ b/devel/svdwf/invFSVD_det.irp.f @@ -0,0 +1,199 @@ + +program invFSVD_det + + BEGIN_DOC + ! build CI matrix from SVD vectors + END_DOC + + implicit none + + read_wf = .True. + TOUCH read_wf + + call run() + +end + + +subroutine run + + implicit none + + integer :: mm, nn, i_state, low_rank + integer :: i, j, k, l + double precision :: tmp1, eps_det + double precision, allocatable :: U_SVD(:,:), D_SVD(:), V_SVD(:,:), A_SVD(:,:), US(:,:) + double precision, allocatable :: newpsi_rows(:), newpsi_columns(:), newpsi_values(:) + double precision :: t0, t1, t2 + + call CPU_TIME(t0) + + i_state = 1 + mm = n_det_alpha_unique + nn = n_det_beta_unique + print *, ' matrix dimensions:', mm,'x',nn + print *, ' N det:', N_det + + call ezfio_get_spindeterminants_n_svd_coefs(low_rank) + print *, ' SVD rank:', low_rank + + allocate( U_SVD(mm,low_rank), D_SVD(low_rank), V_SVD(nn,low_rank) ) + call ezfio_get_spindeterminants_psi_svd_alpha(U_SVD) + call ezfio_get_spindeterminants_psi_svd_beta (V_SVD) + call ezfio_get_spindeterminants_psi_svd_coefs(D_SVD) + print *, ' read EZFIO SVD vectors OK' + + ! US = U x S : + allocate( US(mm,low_rank) ) + US(:,:) = 0.d0 + do i = 1, mm + do l = 1, low_rank + US(i,l) = U_SVD(i,l) * D_SVD(l) + enddo + enddo + print *, ' U x D: ok' + deallocate( U_SVD , D_SVD ) + + ! A_TSVD = US x V.T + allocate( A_SVD(mm,nn) ) + A_SVD(:,:) = 0.d0 + call dgemm( 'N', 'T', mm, nn, low_rank, 1.d0 & + , US , size(US ,1) & + , V_SVD , size(V_SVD,1) & + , 0.d0, A_SVD, size(A_SVD,1) ) + print *, ' U x D x Vt: ok' + deallocatE(US) + + call ezfio_set_spindeterminants_n_states(N_states) + call ezfio_set_spindeterminants_n_det_alpha(n_det_alpha_unique) + call ezfio_set_spindeterminants_n_det_beta(n_det_beta_unique) + + print *, 'EZFIO set n_det_alpha and n_det_beta' + + ! --------------- + eps_det = 1d-13 + print *, ' det coeff thresh for consideration =', eps_det + ! --------------- + + + k = 0 + do j = 1, nn + do i = 1, mm + tmp1 = A_SVD(i,j) + if( dabs(tmp1) .lt. (eps_det) ) cycle + k = k + 1 + enddo + enddo + print *, ' non zero elements = ', k + + +! call generate_all_alpha_beta_det_products +! call save_wavefunction + + call all_ab_det(eps_det, A_SVD) + call update_SVDWF(eps_det, k, A_SVD) + + deallocate( A_SVD ) + + + call CPU_TIME(t2) + print *, '' + print *, ' end after' + print *, (t2-t0)/60.d0, 'min' + +end + + + +subroutine update_SVDWF(eps_det, n_ab, A_SVD) + + implicit none + + integer , intent(in) :: n_ab + double precision, intent(in) :: eps_det + double precision, intent(in) :: A_SVD(n_det_alpha_unique,n_det_beta_unique) + + integer :: i, j, l + integer(bit_kind), allocatable :: tmp_det(:,:,:) + double precision, allocatable :: tmp_coef(:) + + + PROVIDE H_apply_buffer_allocated + + allocate( tmp_coef(n_ab) ) + allocate (tmp_det(N_int,2,n_ab)) + + l = 0 + do j = 1, N_det_beta_unique + do i = 1, N_det_alpha_unique + + if( (dabs(A_SVD(i,j)) .ge. eps_det) .and. (l.le.n_ab) ) then + l = l + 1 + tmp_det(1:N_int,1,l) = psi_det_alpha_unique(1:N_int,i) + tmp_det(1:N_int,2,l) = psi_det_beta_unique (1:N_int,j) + tmp_coef(l) = A_SVD(i,j) + endif + + enddo + enddo + print *, ' l_max =', l + print *, ' n_ab =', n_ab + + !call save_wavefunction_general(ndet,nstates ,psidet ,dim_psicoef,psicoef ) + call save_wavefunction_general(l ,n_states,tmp_det,l ,tmp_coef) + + deallocate(tmp_coef) + deallocate(tmp_det) + +end subroutine update_SVDWF + + + + + +subroutine all_ab_det(eps_det, A_SVD) + + implicit none + + double precision, intent(in) :: eps_det + double precision, intent(in) :: A_SVD(n_det_alpha_unique,n_det_beta_unique) + + integer :: i, j, k, l + integer :: iproc + integer(bit_kind), allocatable :: tmp_det(:,:,:) + + integer, external :: get_index_in_psi_det_sorted_bit + logical, external :: is_in_wavefunction + + PROVIDE H_apply_buffer_allocated + + !$OMP PARALLEL DEFAULT(NONE) SHARED(psi_coef_sorted_bit, N_det_beta_unique, & + !$OMP N_det_alpha_unique, N_int, psi_det_alpha_unique, psi_det_beta_unique, & + !$OMP eps_det, A_SVD ) & + !$OMP PRIVATE(i,j,k,l,tmp_det,iproc) + !$ iproc = omp_get_thread_num() + allocate (tmp_det(N_int,2,N_det_alpha_unique)) + !$OMP DO SCHEDULE(static,8) + do j=1,N_det_beta_unique + l = 1 + do i=1,N_det_alpha_unique + do k=1,N_int + tmp_det(k,1,l) = psi_det_alpha_unique(k,i) + tmp_det(k,2,l) = psi_det_beta_unique (k,j) + enddo + if( (.not.is_in_wavefunction(tmp_det(1,1,l),N_int)) .and. (dabs(A_SVD(i,j)) .ge. eps_det) ) then + l = l + 1 + endif + enddo + call fill_H_apply_buffer_no_selection(l-1, tmp_det, N_int, iproc) + enddo + !$OMP END DO + deallocate(tmp_det) + !$OMP END PARALLEL + + call copy_H_apply_buffer_to_wf + SOFT_TOUCH psi_det psi_coef N_det N_det_beta_unique N_det_alpha_unique psi_det_alpha_unique psi_det_beta_unique + + print *, ' new n_det =', N_det + +end subroutine all_ab_det() diff --git a/devel/svdwf/invFSVD_spindet.irp.f b/devel/svdwf/invFSVD_spindet.irp.f new file mode 100644 index 0000000..835487d --- /dev/null +++ b/devel/svdwf/invFSVD_spindet.irp.f @@ -0,0 +1,120 @@ + +program invFSVD_spindet + + BEGIN_DOC + ! build CI matrix from SVD vectors + END_DOC + + implicit none + + read_wf = .True. + TOUCH read_wf + + call run() + +end + + +subroutine run + + implicit none + + integer :: mm, nn, i_state, low_rank + integer :: i, j, k, l + double precision :: tmp1, eps_det + double precision, allocatable :: U_SVD(:,:), D_SVD(:), V_SVD(:,:), A_SVD(:,:), US(:,:) + double precision, allocatable :: newpsi_rows(:), newpsi_columns(:), newpsi_values(:) + double precision :: t0, t1, t2 + + call CPU_TIME(t0) + + i_state = 1 + mm = n_det_alpha_unique + nn = n_det_beta_unique + print *, ' matrix dimensions:', mm,'x',nn + print *, ' N det:', N_det + + call ezfio_get_spindeterminants_n_svd_coefs(low_rank) + print *, ' SVD rank:', low_rank + + allocate( U_SVD(mm,low_rank), D_SVD(low_rank), V_SVD(nn,low_rank) ) + call ezfio_get_spindeterminants_psi_svd_alpha(U_SVD) + call ezfio_get_spindeterminants_psi_svd_beta (V_SVD) + call ezfio_get_spindeterminants_psi_svd_coefs(D_SVD) + print *, ' read EZFIO SVD vectors OK' + + ! US = U x S : + allocate( US(mm,low_rank) ) + US(:,:) = 0.d0 + do i = 1, mm + do l = 1, low_rank + US(i,l) = U_SVD(i,l) * D_SVD(l) + enddo + enddo + print *, ' U x D: ok' + deallocate( U_SVD , D_SVD ) + + ! A_TSVD = US x V.T + allocate( A_SVD(mm,nn) ) + A_SVD(:,:) = 0.d0 + call dgemm( 'N', 'T', mm, nn, low_rank, 1.d0 & + , US , size(US ,1) & + , V_SVD , size(V_SVD,1) & + , 0.d0, A_SVD, size(A_SVD,1) ) + print *, ' U x D x Vt: ok' + deallocatE(US) + + call ezfio_set_spindeterminants_n_states(N_states) + call ezfio_set_spindeterminants_n_det_alpha(n_det_alpha_unique) + call ezfio_set_spindeterminants_n_det_beta(n_det_beta_unique) + + print *, 'EZFIO set n_det_alpha and n_det_beta' + + ! --------------- + eps_det = 1d-15 + print *, ' det coeff thresh for consideration =', eps_det + ! --------------- + + + k = 0 + do j = 1, nn + do i = 1, mm + tmp1 = A_SVD(i,j) + if( dabs(tmp1) .lt. (eps_det) ) cycle + k = k + 1 + enddo + enddo + print *, ' non zero elements = ', k + + allocate( newpsi_rows(k), newpsi_columns(k), newpsi_values(k) ) + k = 0 + do j = 1, nn + do i = 1, mm + tmp1 = A_SVD(i,j) + if( dabs(tmp1) .lt. (eps_det) ) cycle + k = k + 1 + + newpsi_rows (k) = i + newpsi_columns(k) = j + newpsi_values (k) = tmp1 + + enddo + enddo + + call ezfio_set_spindeterminants_n_det(N_det) + call ezfio_set_spindeterminants_psi_coef_matrix_columns(psi_bilinear_matrix_columns) + call ezfio_set_spindeterminants_psi_coef_matrix_values(psi_bilinear_matrix_values) + call ezfio_set_spindeterminants_psi_coef_matrix_rows(psi_bilinear_matrix_rows) + + + deallocate( A_SVD ) + deallocate( newpsi_rows, newpsi_columns, newpsi_values ) + + + + call CPU_TIME(t2) + print *, '' + print *, ' end after' + print *, (t2-t0)/60.d0, 'min' + +end diff --git a/devel/svdwf/kl_H_kl_v1.irp.f b/devel/svdwf/kl_H_kl_v1.irp.f index 6c4ea3d..dfc1ab2 100644 --- a/devel/svdwf/kl_H_kl_v1.irp.f +++ b/devel/svdwf/kl_H_kl_v1.irp.f @@ -25,34 +25,19 @@ subroutine run integer :: degree, i_state integer :: i, j, k, l, m, n + integer :: ii, ia, ib double precision :: x, y, h12 - double precision, allocatable :: Uref(:,:), Dref(:), Vtref(:,:), Aref(:,:), Vref(:,:) - - integer :: rank_max - double precision :: E0, overlop, Ept2 - double precision, allocatable :: H0(:,:) - double precision, allocatable :: eigvec0(:,:), eigval0(:), coeff_psi(:), coeff_tmp(:) - - integer :: ii, ia, ib - double precision, allocatable :: Hdiag(:), Hkl_save(:,:), Hkl_1d(:), Hkl_tmp(:,:), Hdiag_tmp(:) - - integer :: na_new, nb_new, ind_new, ind_gs - double precision :: ctmp, coeff_new - double precision, allocatable :: epsil(:), epsil_energ(:), check_ov(:) - - double precision, allocatable :: Uezfio(:,:,:), Dezfio(:,:), Vezfio(:,:,:) + double precision, allocatable :: Uref(:,:), Dref(:), Vref(:,:), Vtref(:,:), Aref(:,:) + double precision, allocatable :: Hdiag(:) integer :: ibeg_alpha, ibeg_beta, iend_alpha, iend_beta integer :: n_toselect, na_max, nb_max integer, allocatable :: numalpha_toselect(:), numbeta_toselect(:) - integer :: cantor_pairing_ij, cantor_pairing_new - integer, allocatable :: cantor_pairing(:), cantor_pairing_tmp(:) - double precision :: t_beg, t_end - integer(kind=8) :: W_tbeg, W_tend, W_tbeg_it, W_tend_it, W_ir - real(kind=8) :: W_tot_time, W_tot_time_it + integer(kind=8) :: W_tbeg, W_tend, W_ir + real(kind=8) :: W_tot_time integer :: nb_taches !$OMP PARALLEL @@ -71,14 +56,36 @@ subroutine run call get_excitation_degree(det1,det2,degree,N_int) call i_H_j(det1, det2, N_int, h12) - ! --------------------------------------------------------------------------------------- - ! construct the initial CISD matrix - print *, ' ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~' - print *, ' CISD matrix:', n_det_alpha_unique,'x',n_det_beta_unique + print *, ' CI matrix:', n_det_alpha_unique,'x',n_det_beta_unique print *, ' N det :', N_det print *, ' ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~' + + ibeg_alpha = 1 + !iend_alpha = 10 + iend_alpha = n_det_alpha_unique + + ibeg_beta = 1 + !iend_beta = 10 + iend_beta = n_det_beta_unique + + na_max = iend_alpha - ibeg_alpha + 1 + nb_max = iend_beta - ibeg_beta + 1 + n_toselect = na_max * nb_max + + print *, ' na_max = ', na_max + print *, ' nb_max = ', nb_max + print *, ' n_toselect = ', n_toselect + + ! --------------------------------------------------------------------------------------- + ! perform a Full SVD + call cpu_time(t_beg) + + allocate( Uref(n_det_alpha_unique,n_det_alpha_unique) ) + allocate( Dref(min(n_det_alpha_unique,n_det_beta_unique)) ) + allocate( Vtref(n_det_beta_unique,n_det_beta_unique) ) + ! construct the initial CI matrix allocate( Aref(n_det_alpha_unique,n_det_beta_unique) ) Aref(:,:) = 0.d0 do k = 1, N_det @@ -86,26 +93,10 @@ subroutine run j = psi_bilinear_matrix_columns(k) Aref(i,j) = psi_bilinear_matrix_values(k,i_state) enddo - - ! --------------------------------------------------------------------------------------- - - - - ! --------------------------------------------------------------------------------------- - ! perform a Full SVD - - allocate( Uref(n_det_alpha_unique,n_det_alpha_unique) ) - allocate( Dref(min(n_det_alpha_unique,n_det_beta_unique)) ) - allocate( Vtref(n_det_beta_unique,n_det_beta_unique) ) - - call cpu_time(t_beg) + ! perform a FSVD call svd_s(Aref, size(Aref,1), Uref, size(Uref,1), Dref, Vtref & , size(Vtref,1), n_det_alpha_unique, n_det_beta_unique) - call cpu_time(t_end) - print *, " SVD is performed after (min)", (t_end-t_beg)/60. - deallocate( Aref , Dref ) - allocate( Vref(n_det_beta_unique,n_det_beta_unique) ) do l = 1, n_det_beta_unique do i = 1, n_det_beta_unique @@ -114,20 +105,33 @@ subroutine run enddo deallocate( Vtref ) - ibeg_alpha = 1 - iend_alpha = n_det_alpha_unique - na_max = iend_alpha - ibeg_alpha + 1 +! ! read SVD vectors +! allocate( Uref(n_det_alpha_unique,iend_alpha) ) +! allocate( Vref(n_det_beta_unique ,iend_beta ) ) +! allocate( Dref( min(iend_alpha,iend_beta) ) ) +! open(unit=15, file="d_svd.txt", action='read') +! do i = 1, min(iend_alpha,iend_beta) +! read(15,*) Dref(i) +! enddo +! close(15) +! open(unit=15, file="u_svd.txt", action='read') +! do j = 1, iend_alpha +! do i = 1, n_det_alpha_unique +! read(15,*) Uref(i,j) +! enddo +! enddo +! close(15) +! open(unit=15, file="v_svd.txt", action='read') +! do j = 1, iend_beta +! do i = 1, n_det_beta_unique +! read(15,*) Vref(i,j) +! enddo +! enddo +! close(15) - ibeg_beta = 1 - iend_beta = n_det_beta_unique - nb_max = iend_beta - ibeg_beta + 1 - - n_toselect = na_max * nb_max - - print *, ' na_max = ', na_max - print *, ' nb_max = ', nb_max - print *, ' n_toselect = ', n_toselect - + call cpu_time(t_end) + print *, " SVD is performed after (min)", (t_end-t_beg)/60. + ! --------------------------------------------------------------------------------------- allocate( numalpha_toselect(n_toselect) , numbeta_toselect(n_toselect) ) k = 0 @@ -160,29 +164,6 @@ subroutine run deallocate( numalpha_toselect, numbeta_toselect, Hdiag ) - ! *************************************************************************************************** - ! save to ezfion - !allocate( Uezfio(n_det_alpha_unique,rank0,1), Dezfio(rank0,1), Vezfio(n_det_beta_unique,rank0,1) ) - !do l = 1, rank0 - ! Dezfio(l,1) = coeff_psi(l) - ! Uezfio(:,l,1) = U0(:,l) - ! Vezfio(:,l,1) = V0(:,l) - !enddo - !call ezfio_set_spindeterminants_n_det(N_det) - !call ezfio_set_spindeterminants_n_states(N_states) - !call ezfio_set_spindeterminants_n_det_alpha(n_det_alpha_unique) - !call ezfio_set_spindeterminants_n_det_beta(n_det_beta_unique) - !call ezfio_set_spindeterminants_psi_coef_matrix_rows(psi_bilinear_matrix_rows) - !call ezfio_set_spindeterminants_psi_coef_matrix_columns(psi_bilinear_matrix_columns) - !call ezfio_set_spindeterminants_psi_coef_matrix_values(psi_bilinear_matrix_values) - - !call ezfio_set_spindeterminants_n_svd_coefs(rank0) - !call ezfio_set_spindeterminants_psi_svd_alpha(Uezfio) - !call ezfio_set_spindeterminants_psi_svd_beta(Vezfio ) - !call ezfio_set_spindeterminants_psi_svd_coefs(Dezfio) - !deallocate( Uezfio, Dezfio, Vezfio ) - ! *************************************************************************************************** - call SYSTEM_CLOCK(COUNT=W_tend, COUNT_RATE=W_ir) @@ -193,7 +174,6 @@ subroutine run print *, " total elapsed time (min) = ", W_tot_time/60.d0 print *, ' ___________________________________________________________________' - end diff --git a/devel/svdwf/kl_H_kl_v2.irp.f b/devel/svdwf/kl_H_kl_v2.irp.f index a44f66c..b8bc8eb 100644 --- a/devel/svdwf/kl_H_kl_v2.irp.f +++ b/devel/svdwf/kl_H_kl_v2.irp.f @@ -25,31 +25,17 @@ subroutine run integer :: degree, i_state integer :: i, j, k, l, m, n + integer :: ii, ia, ib double precision :: x, y, h12 double precision, allocatable :: Uref(:,:), Dref(:), Vtref(:,:), Aref(:,:), Vref(:,:) - integer :: rank_max - double precision :: E0, overlop, Ept2 - double precision, allocatable :: H0(:,:) - double precision, allocatable :: eigvec0(:,:), eigval0(:), coeff_psi(:), coeff_tmp(:) - - integer :: ii, ia, ib - double precision, allocatable :: Hdiag(:), Hkl_save(:,:), Hkl_1d(:), Hkl_tmp(:,:), Hdiag_tmp(:) - - integer :: na_new, nb_new, ind_new, ind_gs - double precision :: ctmp, coeff_new - double precision, allocatable :: epsil(:), epsil_energ(:), check_ov(:) - - double precision, allocatable :: Uezfio(:,:,:), Dezfio(:,:), Vezfio(:,:,:) + double precision, allocatable :: Hdiag(:) integer :: ibeg_alpha, ibeg_beta, iend_alpha, iend_beta integer :: n_toselect, na_max, nb_max integer, allocatable :: numalpha_toselect(:), numbeta_toselect(:) - integer :: cantor_pairing_ij, cantor_pairing_new - integer, allocatable :: cantor_pairing(:), cantor_pairing_tmp(:) - double precision :: t_beg, t_end integer(kind=8) :: W_tbeg, W_tend, W_tbeg_it, W_tend_it, W_ir real(kind=8) :: W_tot_time, W_tot_time_it @@ -115,13 +101,15 @@ subroutine run deallocate( Vtref ) ibeg_alpha = 1 - iend_alpha = n_det_alpha_unique - na_max = iend_alpha - ibeg_alpha + 1 + iend_alpha = 100 + !iend_alpha = n_det_alpha_unique ibeg_beta = 1 - iend_beta = n_det_beta_unique - nb_max = iend_beta - ibeg_beta + 1 + iend_beta = 100 + !iend_beta = n_det_beta_unique + na_max = iend_alpha - ibeg_alpha + 1 + nb_max = iend_beta - ibeg_beta + 1 n_toselect = na_max * nb_max print *, ' na_max = ', na_max @@ -155,36 +143,10 @@ subroutine run enddo close(11) - deallocate( Uref, Vref ) deallocate( numalpha_toselect, numbeta_toselect, Hdiag ) - ! *************************************************************************************************** - ! save to ezfion - !allocate( Uezfio(n_det_alpha_unique,rank0,1), Dezfio(rank0,1), Vezfio(n_det_beta_unique,rank0,1) ) - !do l = 1, rank0 - ! Dezfio(l,1) = coeff_psi(l) - ! Uezfio(:,l,1) = U0(:,l) - ! Vezfio(:,l,1) = V0(:,l) - !enddo - !call ezfio_set_spindeterminants_n_det(N_det) - !call ezfio_set_spindeterminants_n_states(N_states) - !call ezfio_set_spindeterminants_n_det_alpha(n_det_alpha_unique) - !call ezfio_set_spindeterminants_n_det_beta(n_det_beta_unique) - !call ezfio_set_spindeterminants_psi_coef_matrix_rows(psi_bilinear_matrix_rows) - !call ezfio_set_spindeterminants_psi_coef_matrix_columns(psi_bilinear_matrix_columns) - !call ezfio_set_spindeterminants_psi_coef_matrix_values(psi_bilinear_matrix_values) - - !call ezfio_set_spindeterminants_n_svd_coefs(rank0) - !call ezfio_set_spindeterminants_psi_svd_alpha(Uezfio) - !call ezfio_set_spindeterminants_psi_svd_beta(Vezfio ) - !call ezfio_set_spindeterminants_psi_svd_coefs(Dezfio) - !deallocate( Uezfio, Dezfio, Vezfio ) - ! *************************************************************************************************** - - - call SYSTEM_CLOCK(COUNT=W_tend, COUNT_RATE=W_ir) W_tot_time = real(W_tend - W_tbeg, kind=8) / real(W_ir, kind=8) print *, ' ___________________________________________________________________' @@ -193,7 +155,6 @@ subroutine run print *, " total elapsed time (min) = ", W_tot_time/60.d0 print *, ' ___________________________________________________________________' - end diff --git a/devel/svdwf/printSQ_ab_T_gd_v0.irp.f b/devel/svdwf/printSQ_ab_T_gd_v0.irp.f new file mode 100644 index 0000000..0998643 --- /dev/null +++ b/devel/svdwf/printSQ_ab_T_gd_v0.irp.f @@ -0,0 +1,402 @@ +program printSQ_ab_T_gd_v0 + + implicit none + + BEGIN_DOC + ! perturbative approach to build psi_postsvd + END_DOC + + read_wf = .True. + TOUCH read_wf + + PROVIDE N_int + + call run() +end + + +subroutine run + + USE OMP_LIB + USE bitmasks + + implicit none + + integer(bit_kind) :: det1(N_int,2), det2(N_int,2) + integer :: degree, i_state + double precision :: h12 + + integer :: i, j, k, l + double precision, allocatable :: T(:,:,:,:) + + double precision, allocatable :: Uref(:,:), Dref(:), Vtref(:,:), Aref(:,:), Vref(:,:) + + double precision :: ti, tf + integer :: nb_taches + + !$OMP PARALLEL + nb_taches = OMP_GET_NUM_THREADS() + !$OMP END PARALLEL + + call wall_time(ti) + + i_state = 1 + + det1(:,1) = psi_det_alpha_unique(:,1) + det2(:,1) = psi_det_alpha_unique(:,1) + det1(:,2) = psi_det_beta_unique(:,1) + det2(:,2) = psi_det_beta_unique(:,1) + call get_excitation_degree_spin(det1(1,1),det2(1,1),degree,N_int) + call get_excitation_degree(det1,det2,degree,N_int) + call i_H_j(det1, det2, N_int, h12) + + + + ! --------------------------------------------------------------------------------------- + ! --------------------------------------------------------------------------------------- + ! --------------------------------------------------------------------------------------- + ! construct the initial CI matrix + + print *, ' ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~' + print *, ' CI matrix :', n_det_alpha_unique,'x',n_det_beta_unique + print *, ' N det :', N_det + print *, ' ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~' + + allocate( Aref(n_det_alpha_unique,n_det_beta_unique) ) + Aref(:,:) = 0.d0 + do k = 1, N_det + i = psi_bilinear_matrix_rows(k) + j = psi_bilinear_matrix_columns(k) + Aref(i,j) = psi_bilinear_matrix_values(k,i_state) + enddo + + allocate( Uref(n_det_alpha_unique,n_det_alpha_unique) ) + allocate( Dref(min(n_det_alpha_unique,n_det_beta_unique)) ) + allocate( Vtref(n_det_beta_unique,n_det_beta_unique) ) + call svd_s(Aref, size(Aref,1), Uref, size(Uref,1), Dref, Vtref & + , size(Vtref,1), n_det_alpha_unique, n_det_beta_unique) + print *, " ---------- Full SVD is performed ----------------- " + + allocate( Vref(n_det_beta_unique,n_det_beta_unique) ) + do l = 1, n_det_beta_unique + do i = 1, n_det_beta_unique + Vref(i,l) = Vtref(l,i) + enddo + enddo + deallocate( Aref , Vtref , Dref ) + ! --------------------------------------------------------------------------------------- + ! --------------------------------------------------------------------------------------- + ! --------------------------------------------------------------------------------------- + ! --------------------------------------------------------------------------------------- + + allocate( T(n_det_alpha_unique,n_det_beta_unique,n_det_alpha_unique,n_det_beta_unique) ) + + call const_2b(T) + call const_ab_T_gd(Uref, Vref, T) + + deallocate( T ) + deallocate( Uref , Vref ) + + call wall_time(tf) + + print *, ' ___________________________________________________________________' + print *, ' ' + !print *, " Execution avec ", nb_taches, " threads" + print *, " Execution avec 1 threads" + print *, " total elapsed time (min) = ", (tf-ti)/60.d0 + print *, ' ___________________________________________________________________' + + +end + + + + !/-\! !/-\! !/-\! !/-\! !/-\! !/-\! !/-\! !/-\! !/-\! + !---! !---! !---! !---! !---! !---! !---! !---! !---! + ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! + !___! !___! !___! !___! !___! !___! !___! !___! !___! + !___! !___! !___! !___! !___! !___! !___! !___! !___! + + !/-\! !/-\! !/-\! !/-\! !/-\! !/-\! !/-\! !/-\! !/-\! + !---! !---! !---! !---! !---! !---! !---! !---! !---! + ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! + !___! !___! !___! !___! !___! !___! !___! !___! !___! + !___! !___! !___! !___! !___! !___! !___! !___! !___! + + !/-\! !/-\! !/-\! !/-\! !/-\! !/-\! !/-\! !/-\! !/-\! + !---! !---! !---! !---! !---! !---! !---! !---! !---! + ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! + !___! !___! !___! !___! !___! !___! !___! !___! !___! + !___! !___! !___! !___! !___! !___! !___! !___! !___! + + !/-\! !/-\! !/-\! !/-\! !/-\! !/-\! !/-\! !/-\! !/-\! + !---! !---! !---! !---! !---! !---! !---! !---! !---! + ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! + !___! !___! !___! !___! !___! !___! !___! !___! !___! + !___! !___! !___! !___! !___! !___! !___! !___! !___! + + + + +subroutine const_2b(T) + + USE bitmasks + implicit none + + double precision, external :: get_two_e_integral + + double precision, intent(out) :: T(n_det_alpha_unique,n_det_beta_unique,n_det_alpha_unique,n_det_beta_unique ) + + integer :: na, nb + integer :: i, k, j, l + + integer(bit_kind) :: psi_ij(N_int,2), psi_kl(N_int,2) + double precision :: phase + integer :: degree, h1, h2, p1, p2, s1, s2, e1, e2 + integer :: ii, jj + integer :: exc(0:2,2,2) + + integer :: occ(N_int*bit_kind_size,2), n_occ_alpha + + double precision :: two_body_fact + + na = n_det_alpha_unique + nb = n_det_beta_unique + + T(:,:,:,:) = 0.d0 + + ! ----------------------------------------------------------------------------------------------------------------- + do i = 1, na + psi_ij(1:N_int,1) = psi_det_alpha_unique(1:N_int,i) + do j = 1, nb + psi_ij(1:N_int,2) = psi_det_beta_unique(1:N_int,j) + + call bitstring_to_list(psi_ij(1,1), occ(1,1), n_occ_alpha, N_int) + call bitstring_to_list(psi_ij(1,2), occ(1,2), n_occ_alpha, N_int) + + do k = 1, na + psi_kl(1:N_int,1) = psi_det_alpha_unique(1:N_int,k) + do l = 1, nb + psi_kl(1:N_int,2) = psi_det_beta_unique(1:N_int,l) + + call get_excitation_degree(psi_ij, psi_kl, degree, N_int) + + two_body_fact = 0.d0 + + if(degree .eq. 2) then + + call get_double_excitation(psi_ij, psi_kl, exc, phase, N_int) + call decode_exc(exc, degree, h1, p1, h2, p2, s1, s2) + + select case(s1+s2) + case(2,4) + two_body_fact += phase * get_two_e_integral(h1, h2, p1, p2, mo_integrals_map) + two_body_fact -= phase * get_two_e_integral(h1, h2, p2, p1, mo_integrals_map) + case(3) + two_body_fact += 0.5d0 * phase * get_two_e_integral(h1, h2, p1, p2, mo_integrals_map) + two_body_fact += 0.5d0 * phase * get_two_e_integral(h2, h1, p2, p1, mo_integrals_map) + end select + + else if(degree .eq. 1) then + + call get_single_excitation(psi_ij, psi_kl, exc, phase, N_int) + call decode_exc(exc, degree, h1, p1, h2, p2, s1, s2) + + select case(s1) + case(1) + do ii = 1, elec_alpha_num + p2 = occ(ii,1) + h2 = p2 + two_body_fact += 0.5d0 * phase * get_two_e_integral(h1, h2, p1, p2, mo_integrals_map) + two_body_fact -= 0.5d0 * phase * get_two_e_integral(h1, h2, p2, p1, mo_integrals_map) + two_body_fact += 0.5d0 * phase * get_two_e_integral(h2, h1, p2, p1, mo_integrals_map) + two_body_fact -= 0.5d0 * phase * get_two_e_integral(h2, h1, p1, p2, mo_integrals_map) + enddo + do ii = 1, elec_beta_num + p2 = occ(ii,2) + h2 = p2 + two_body_fact += 0.5d0 * phase * get_two_e_integral(h1, h2, p1, p2, mo_integrals_map) + two_body_fact += 0.5d0 * phase * get_two_e_integral(h2, h1, p2, p1, mo_integrals_map) + enddo + case(2) + do ii = 1, elec_alpha_num + p2 = occ(ii,1) + h2 = p2 + two_body_fact += 0.5d0 * phase * get_two_e_integral(h1, h2, p1, p2, mo_integrals_map) + two_body_fact += 0.5d0 * phase * get_two_e_integral(h2, h1, p2, p1, mo_integrals_map) + enddo + do ii = 1, elec_beta_num + p2 = occ(ii,2) + h2 = p2 + two_body_fact += 0.5d0 * phase * get_two_e_integral(h1, h2, p1, p2, mo_integrals_map) + two_body_fact -= 0.5d0 * phase * get_two_e_integral(h1, h2, p2, p1, mo_integrals_map) + two_body_fact += 0.5d0 * phase * get_two_e_integral(h2, h1, p2, p1, mo_integrals_map) + two_body_fact -= 0.5d0 * phase * get_two_e_integral(h2, h1, p1, p2, mo_integrals_map) + enddo + end select + + else if(degree .eq. 0) then + + do ii = 1, elec_alpha_num + e1 = occ(ii,1) + do jj = 1, elec_alpha_num + e2 = occ(jj,1) + two_body_fact += 0.5d0 * get_two_e_integral(e1, e2, e1, e2, mo_integrals_map) + two_body_fact -= 0.5d0 * get_two_e_integral(e1, e2, e2, e1, mo_integrals_map) + enddo + do jj = 1, elec_beta_num + e2 = occ(jj,2) + two_body_fact += 0.5d0 * get_two_e_integral(e1, e2, e1, e2, mo_integrals_map) + two_body_fact += 0.5d0 * get_two_e_integral(e2, e1, e2, e1, mo_integrals_map) + enddo + enddo + do ii = 1, elec_beta_num + e1 = occ(ii,2) + do jj = 1, elec_beta_num + e2 = occ(jj,2) + two_body_fact += 0.5d0 * get_two_e_integral(e1, e2, e1, e2, mo_integrals_map) + two_body_fact -= 0.5d0 * get_two_e_integral(e1, e2, e2, e1, mo_integrals_map) + enddo + enddo + + end if + + T(i,j,k,l) = two_body_fact + enddo + enddo + enddo + enddo + ! ----------------------------------------------------------------------------------------------------------------- + + return +end subroutine const_2b + + + + + + + + + + + + +subroutine const_ab_T_gd(Uref, Vref, T) + + implicit none + + double precision, intent(in) :: Uref(n_det_alpha_unique,n_det_alpha_unique) + double precision, intent(in) :: Vref(n_det_beta_unique ,n_det_beta_unique) + double precision, intent(in) :: T(n_det_alpha_unique,n_det_beta_unique,n_det_alpha_unique,n_det_beta_unique ) + + integer :: na, nb + + integer :: i, j, k, l, ii, jj, kk, ll + double precision :: h12, T_abgd, sum_i, sum_j, sum_k, sum_l + + double precision, allocatable :: tmp1(:,:,:,:), tmp2(:,:,:,:) + + double precision :: t1, t2 + + print *, "" + print *, " start const_ab_T_gd" + call wall_time(t1) + + na = n_det_alpha_unique + nb = n_det_beta_unique + + allocate( tmp1(na,nb,na,nb) ) + tmp1(:,:,:,:) = 0.d0 + do ii = 1, na + + do l = 1, nb + do j = 1, nb + do k = 1, na + + sum_i = 0.d0 + do i = 1, na + sum_i = sum_i + T(i,j,k,l) * Uref(i,ii) + enddo + + tmp1(ii,j,k,l) = sum_i + enddo + enddo + enddo + enddo + + allocate( tmp2(na,nb,na,nb) ) + tmp2(:,:,:,:) = 0.d0 + do ii = 1, na + do jj = 1, nb + do k = 1, na + do l = 1, nb + sum_j = 0.d0 + do j = 1, nb + sum_j = sum_j + tmp1(ii,j,k,l) * Vref(j,jj) + enddo + tmp2(ii,jj,k,l) = sum_j + enddo + enddo + enddo + enddo + deallocate(tmp1) + + allocate( tmp1(na,nb,na,nb) ) + tmp1(:,:,:,:) = 0.d0 + do ii = 1, na + do jj = 1, nb + do kk = 1, na + do l = 1, nb + sum_k = 0.d0 + do k = 1, na + sum_k = sum_k + tmp2(ii,jj,k,l) * Uref(k,kk) + enddo + tmp1(ii,jj,kk,l) = sum_k + enddo + enddo + enddo + enddo + deallocate(tmp2) + + allocate( tmp2(na,nb,na,nb) ) + tmp2(:,:,:,:) = 0.d0 + do ii = 1, na + do jj = 1, nb + do kk = 1, na + do ll = 1, nb + sum_l = 0.d0 + do l = 1, nb + sum_l = sum_l + tmp1(ii,jj,kk,l) * Vref(l,ll) + enddo + tmp2(ii,jj,kk,ll) = sum_l + enddo + enddo + enddo + enddo + deallocate(tmp1) + + open(UNIT=11, FILE="ab_T_gd_v0.dat", ACTION="WRITE") + do ii = 1, na + do jj = 1, nb + do kk = 1, na + do ll = 1, nb + T_abgd = tmp2(ii,jj,kk,ll) + write(11, '((F15.8))') T_abgd + enddo + enddo + enddo + enddo + close(11) + + deallocate(tmp2) + + call wall_time(t2) + print *, " end const_ab_T_gd after (min) ", (t2-t1)/60. + print *, "" + + return +end subroutine const_ab_T_gd + + + diff --git a/devel/svdwf/printSQ_ij_T_kl.irp.f b/devel/svdwf/printSQ_ij_T_kl.irp.f new file mode 100644 index 0000000..2bc920b --- /dev/null +++ b/devel/svdwf/printSQ_ij_T_kl.irp.f @@ -0,0 +1,257 @@ +program printSQ_ij_T_kl + + implicit none + + BEGIN_DOC + ! perturbative approach to build psi_postsvd + END_DOC + + read_wf = .True. + TOUCH read_wf + + PROVIDE N_int + + call run() +end + + +subroutine run + + USE OMP_LIB + USE bitmasks + + implicit none + + integer(bit_kind) :: det1(N_int,2), det2(N_int,2) + integer :: degree, i_state + double precision :: h12 + + integer :: i, j, k, l + double precision, allocatable :: T(:,:,:,:) + + double precision :: ti, tf + integer :: nb_taches + + !$OMP PARALLEL + nb_taches = OMP_GET_NUM_THREADS() + !$OMP END PARALLEL + + call wall_time(ti) + + i_state = 1 + + det1(:,1) = psi_det_alpha_unique(:,1) + det2(:,1) = psi_det_alpha_unique(:,1) + det1(:,2) = psi_det_beta_unique(:,1) + det2(:,2) = psi_det_beta_unique(:,1) + call get_excitation_degree_spin(det1(1,1),det2(1,1),degree,N_int) + call get_excitation_degree(det1,det2,degree,N_int) + call i_H_j(det1, det2, N_int, h12) + + + ! --------------------------------------------------------------------------------------- + ! construct the initial CI matrix + + print *, ' ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~' + print *, ' CI matrix :', n_det_alpha_unique,'x',n_det_beta_unique + print *, ' N det :', N_det + print *, ' ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~' + + ! --------------------------------------------------------------------------------------- + ! --------------------------------------------------------------------------------------- + + + allocate( T(n_det_alpha_unique,n_det_beta_unique,n_det_alpha_unique,n_det_beta_unique) ) + call const_2b(T) + + open(UNIT=11, FILE="ij_T_kl.dat", ACTION="WRITE") + do i = 1, n_det_alpha_unique + do j = 1, n_det_beta_unique + do k = 1, n_det_alpha_unique + do l = 1, n_det_beta_unique + write(11, '(E15.7)') T(i,j,k,l) + !write(11, '(4(I5,2X), 5X, E15.7)') i, j, k, l, T(i,j,k,l) + enddo + enddo + enddo + enddo + close(11) + + deallocate( T ) + + call wall_time(tf) + + print *, ' ___________________________________________________________________' + print *, ' ' + !print *, " Execution avec ", nb_taches, " threads" + print *, " Execution avec 1 threads" + print *, " total elapsed time (min) = ", (tf-ti)/60.d0 + print *, ' ___________________________________________________________________' + + +end + + + + !/-\! !/-\! !/-\! !/-\! !/-\! !/-\! !/-\! !/-\! !/-\! + !---! !---! !---! !---! !---! !---! !---! !---! !---! + ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! + !___! !___! !___! !___! !___! !___! !___! !___! !___! + !___! !___! !___! !___! !___! !___! !___! !___! !___! + + !/-\! !/-\! !/-\! !/-\! !/-\! !/-\! !/-\! !/-\! !/-\! + !---! !---! !---! !---! !---! !---! !---! !---! !---! + ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! + !___! !___! !___! !___! !___! !___! !___! !___! !___! + !___! !___! !___! !___! !___! !___! !___! !___! !___! + + !/-\! !/-\! !/-\! !/-\! !/-\! !/-\! !/-\! !/-\! !/-\! + !---! !---! !---! !---! !---! !---! !---! !---! !---! + ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! + !___! !___! !___! !___! !___! !___! !___! !___! !___! + !___! !___! !___! !___! !___! !___! !___! !___! !___! + + !/-\! !/-\! !/-\! !/-\! !/-\! !/-\! !/-\! !/-\! !/-\! + !---! !---! !---! !---! !---! !---! !---! !---! !---! + ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! + !___! !___! !___! !___! !___! !___! !___! !___! !___! + !___! !___! !___! !___! !___! !___! !___! !___! !___! + + + + +subroutine const_2b(T) + + USE bitmasks + implicit none + + double precision, external :: get_two_e_integral + + double precision, intent(out) :: T(n_det_alpha_unique,n_det_beta_unique,n_det_alpha_unique,n_det_beta_unique ) + + integer :: na, nb + integer :: i, k, j, l + + integer(bit_kind) :: psi_ij(N_int,2), psi_kl(N_int,2) + double precision :: phase + integer :: degree, h1, h2, p1, p2, s1, s2, e1, e2 + integer :: ii, jj + integer :: exc(0:2,2,2) + + integer :: occ(N_int*bit_kind_size,2), n_occ_alpha + + double precision :: two_body_fact + + na = n_det_alpha_unique + nb = n_det_beta_unique + + T(:,:,:,:) = 0.d0 + + ! ----------------------------------------------------------------------------------------------------------------- + do i = 1, na + psi_ij(1:N_int,1) = psi_det_alpha_unique(1:N_int,i) + do j = 1, nb + psi_ij(1:N_int,2) = psi_det_beta_unique(1:N_int,j) + + call bitstring_to_list(psi_ij(1,1), occ(1,1), n_occ_alpha, N_int) + call bitstring_to_list(psi_ij(1,2), occ(1,2), n_occ_alpha, N_int) + + do k = 1, na + psi_kl(1:N_int,1) = psi_det_alpha_unique(1:N_int,k) + do l = 1, nb + psi_kl(1:N_int,2) = psi_det_beta_unique(1:N_int,l) + + call get_excitation_degree(psi_ij, psi_kl, degree, N_int) + + two_body_fact = 0.d0 + + if(degree .eq. 2) then + + call get_double_excitation(psi_ij, psi_kl, exc, phase, N_int) + call decode_exc(exc, degree, h1, p1, h2, p2, s1, s2) + + select case(s1+s2) + case(2,4) + two_body_fact += phase * get_two_e_integral(h1, h2, p1, p2, mo_integrals_map) + two_body_fact -= phase * get_two_e_integral(h1, h2, p2, p1, mo_integrals_map) + case(3) + two_body_fact += 0.5d0 * phase * get_two_e_integral(h1, h2, p1, p2, mo_integrals_map) + two_body_fact += 0.5d0 * phase * get_two_e_integral(h2, h1, p2, p1, mo_integrals_map) + end select + + else if(degree .eq. 1) then + + call get_single_excitation(psi_ij, psi_kl, exc, phase, N_int) + call decode_exc(exc, degree, h1, p1, h2, p2, s1, s2) + + select case(s1) + case(1) + do ii = 1, elec_alpha_num + p2 = occ(ii,1) + h2 = p2 + two_body_fact += 0.5d0 * phase * get_two_e_integral(h1, h2, p1, p2, mo_integrals_map) + two_body_fact -= 0.5d0 * phase * get_two_e_integral(h1, h2, p2, p1, mo_integrals_map) + two_body_fact += 0.5d0 * phase * get_two_e_integral(h2, h1, p2, p1, mo_integrals_map) + two_body_fact -= 0.5d0 * phase * get_two_e_integral(h2, h1, p1, p2, mo_integrals_map) + enddo + do ii = 1, elec_beta_num + p2 = occ(ii,2) + h2 = p2 + two_body_fact += 0.5d0 * phase * get_two_e_integral(h1, h2, p1, p2, mo_integrals_map) + two_body_fact += 0.5d0 * phase * get_two_e_integral(h2, h1, p2, p1, mo_integrals_map) + enddo + case(2) + do ii = 1, elec_alpha_num + p2 = occ(ii,1) + h2 = p2 + two_body_fact += 0.5d0 * phase * get_two_e_integral(h1, h2, p1, p2, mo_integrals_map) + two_body_fact += 0.5d0 * phase * get_two_e_integral(h2, h1, p2, p1, mo_integrals_map) + enddo + do ii = 1, elec_beta_num + p2 = occ(ii,2) + h2 = p2 + two_body_fact += 0.5d0 * phase * get_two_e_integral(h1, h2, p1, p2, mo_integrals_map) + two_body_fact -= 0.5d0 * phase * get_two_e_integral(h1, h2, p2, p1, mo_integrals_map) + two_body_fact += 0.5d0 * phase * get_two_e_integral(h2, h1, p2, p1, mo_integrals_map) + two_body_fact -= 0.5d0 * phase * get_two_e_integral(h2, h1, p1, p2, mo_integrals_map) + enddo + end select + + else if(degree .eq. 0) then + + do ii = 1, elec_alpha_num + e1 = occ(ii,1) + do jj = 1, elec_alpha_num + e2 = occ(jj,1) + two_body_fact += 0.5d0 * get_two_e_integral(e1, e2, e1, e2, mo_integrals_map) + two_body_fact -= 0.5d0 * get_two_e_integral(e1, e2, e2, e1, mo_integrals_map) + enddo + do jj = 1, elec_beta_num + e2 = occ(jj,2) + two_body_fact += 0.5d0 * get_two_e_integral(e1, e2, e1, e2, mo_integrals_map) + two_body_fact += 0.5d0 * get_two_e_integral(e2, e1, e2, e1, mo_integrals_map) + enddo + enddo + do ii = 1, elec_beta_num + e1 = occ(ii,2) + do jj = 1, elec_beta_num + e2 = occ(jj,2) + two_body_fact += 0.5d0 * get_two_e_integral(e1, e2, e1, e2, mo_integrals_map) + two_body_fact -= 0.5d0 * get_two_e_integral(e1, e2, e2, e1, mo_integrals_map) + enddo + enddo + + end if + + T(i,j,k,l) = two_body_fact + enddo + enddo + enddo + enddo + ! ----------------------------------------------------------------------------------------------------------------- + + return +end subroutine const_2b + + + diff --git a/devel/svdwf/print_2e_integrals.irp.f b/devel/svdwf/print_2e_integrals.irp.f new file mode 100644 index 0000000..053131b --- /dev/null +++ b/devel/svdwf/print_2e_integrals.irp.f @@ -0,0 +1,48 @@ +program print_2e_integrals + + BEGIN_DOC + ! script to print 2-electron Coulomb integrals + END_DOC + + implicit none + + read_wf = .true. + TOUCH read_wf + + call run() + +end + + + +subroutine run() + + implicit none + + integer :: i, j, k, l + double precision, external :: get_ao_two_e_integral + + print *, ' ao_num = ', ao_num + +! provide ao_two_e_integrals_in_map +! print *, hf_energy + + ! Map of Atomic integrals + ! i(r1) j(r2) 1/r12 k(r1) l(r2) + ! https://quantum-package.readthedocs.io/en/master/modules/ao_two_e_ints.html + open(unit=11, file='ao_2eCoulombIntegrals.txt', action='write') + do i = 1, ao_num + do k = 1, ao_num + do j = 1, ao_num + do l = 1, ao_num +! write(11, '(e15.8)') get_two_e_integral(i, j, k, l, ao_integrals_map) + write(11, *) get_ao_two_e_integral(i, j, k, l, ao_integrals_map) + enddo + enddo + enddo + enddo + close(11) + +end + + diff --git a/devel/svdwf/print_ij_H_kl_det.irp.f b/devel/svdwf/print_ij_H_kl_det.irp.f new file mode 100644 index 0000000..32fa6b0 --- /dev/null +++ b/devel/svdwf/print_ij_H_kl_det.irp.f @@ -0,0 +1,129 @@ +program print_ij_H_kl_det + + implicit none + + BEGIN_DOC + ! perturbative approach to build psi_postsvd + ! without OMP + END_DOC + + read_wf = .True. + TOUCH read_wf + + PROVIDE N_int + + call run() +end + + +subroutine run + + USE OMP_LIB + + implicit none + + integer(bit_kind) :: det1(N_int,2), det2(N_int,2) + integer :: degree, i_state + double precision :: h12 + + integer(kind=8) :: W_tbeg, W_tend, W_tbeg_it, W_tend_it, W_ir + real(kind=8) :: W_tot_time + integer :: nb_taches + + !$OMP PARALLEL + nb_taches = OMP_GET_NUM_THREADS() + !$OMP END PARALLEL + + call SYSTEM_CLOCK(COUNT=W_tbeg, COUNT_RATE=W_ir) + + i_state = 1 + + det1(:,1) = psi_det_alpha_unique(:,1) + det2(:,1) = psi_det_alpha_unique(:,1) + det1(:,2) = psi_det_beta_unique(:,1) + det2(:,2) = psi_det_beta_unique(:,1) + call get_excitation_degree_spin(det1(1,1),det2(1,1),degree,N_int) + call get_excitation_degree(det1,det2,degree,N_int) + call i_H_j(det1, det2, N_int, h12) + + ! --------------------------------------------------------------------------------------- + ! construct the initial CI matrix + + print *, ' ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~' + print *, ' CISD matrix:', n_det_alpha_unique,'x',n_det_beta_unique + print *, ' N det :', N_det + print *, ' ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~' + + ! --------------------------------------------------------------------------------------- + + ! get < d_i d_j | H | d_k d_l > in det basis + call const_ij_H_kl_det() + + + call SYSTEM_CLOCK(COUNT=W_tend, COUNT_RATE=W_ir) + W_tot_time = real(W_tend - W_tbeg, kind=8) / real(W_ir, kind=8) + print *, ' ___________________________________________________________________' + print *, ' ' + !print *, " Execution avec ", nb_taches, "threads" + print *, " Execution avec 1 threads" + print *, " total elapsed time (min) = ", W_tot_time/60.d0 + print *, ' ___________________________________________________________________' + +end + + + + + +subroutine const_ij_H_kl_det() + + implicit none + + integer(bit_kind) :: det1(N_int,2) + integer(bit_kind) :: det2(N_int,2) + integer :: degree, na, nb + + integer :: i, j, k, l + double precision :: h12 + + double precision :: t1, t2 + + print *, "" + print *, " start const_ij_H_kl_det" + call wall_time(t1) + + na = n_det_alpha_unique + nb = n_det_beta_unique + + do l = 1, nb + det2(:,2) = psi_det_beta_unique(:,l) + do j = 1, nb + det1(:,2) = psi_det_beta_unique(:,j) + + call get_excitation_degree_spin(det1(1,2),det2(1,2),degree,N_int) + if(degree .gt. 2) cycle + + do k = 1, na + det2(:,1) = psi_det_alpha_unique(:,k) + do i = 1, na + det1(:,1) = psi_det_alpha_unique(:,i) + + call get_excitation_degree(det1,det2,degree,N_int) + if(degree .gt. 2) cycle + + call i_H_j(det1, det2, N_int, h12) + if(h12 .eq. 0.d0) cycle + + write(7000, '(4(I4,2X),(F15.8))') i, j, k, l, h12 + enddo + enddo + enddo + enddo + + call wall_time(t2) + print *, " end const_ij_H_kl_det after (min) ", (t2-t1)/60. + print *, "" + + return +end subroutine const_ij_H_kl_det + diff --git a/devel/svdwf/print_ij_H_kl_det_v0.irp.f b/devel/svdwf/print_ij_H_kl_det_v0.irp.f new file mode 100644 index 0000000..9aa8e6c --- /dev/null +++ b/devel/svdwf/print_ij_H_kl_det_v0.irp.f @@ -0,0 +1,144 @@ +program print_ij_H_kl_det_v0 + + implicit none + + BEGIN_DOC + ! perturbative approach to build psi_postsvd + ! without OMP + END_DOC + + read_wf = .True. + TOUCH read_wf + + PROVIDE N_int + + call run() +end + + +subroutine run + + USE OMP_LIB + + implicit none + + integer(bit_kind) :: det1(N_int,2), det2(N_int,2) + integer :: degree, i_state + double precision :: h12 + + integer(kind=8) :: W_tbeg, W_tend, W_tbeg_it, W_tend_it, W_ir + real(kind=8) :: W_tot_time + integer :: nb_taches + + !$OMP PARALLEL + nb_taches = OMP_GET_NUM_THREADS() + !$OMP END PARALLEL + + call SYSTEM_CLOCK(COUNT=W_tbeg, COUNT_RATE=W_ir) + + i_state = 1 + + det1(:,1) = psi_det_alpha_unique(:,1) + det2(:,1) = psi_det_alpha_unique(:,1) + det1(:,2) = psi_det_beta_unique(:,1) + det2(:,2) = psi_det_beta_unique(:,1) + call get_excitation_degree_spin(det1(1,1),det2(1,1),degree,N_int) + call get_excitation_degree(det1,det2,degree,N_int) + call i_H_j(det1, det2, N_int, h12) + + ! --------------------------------------------------------------------------------------- + ! construct the initial CI matrix + + print *, ' ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~' + print *, ' CISD matrix:', n_det_alpha_unique,'x',n_det_beta_unique + print *, ' N det :', N_det + print *, ' ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~' + + ! --------------------------------------------------------------------------------------- + + ! get < d_i d_j | H | d_k d_l > in det basis + call const_ij_H_kl_det() + + + call SYSTEM_CLOCK(COUNT=W_tend, COUNT_RATE=W_ir) + W_tot_time = real(W_tend - W_tbeg, kind=8) / real(W_ir, kind=8) + print *, ' ___________________________________________________________________' + print *, ' ' + !print *, " Execution avec ", nb_taches, "threads" + print *, " Execution avec 1 threads" + print *, " total elapsed time (min) = ", W_tot_time/60.d0 + print *, ' ___________________________________________________________________' + +end + + + + + +subroutine const_ij_H_kl_det() + + implicit none + + integer(bit_kind) :: det1(N_int,2) + integer(bit_kind) :: det2(N_int,2) + integer :: degree, na, nb + + integer :: i, j, k, l + double precision :: h12 + + double precision :: nb_nz, n_tot + + double precision :: t1, t2 + + print *, "" + print *, " start const_ij_H_kl_det" + call wall_time(t1) + + na = n_det_alpha_unique + nb = n_det_beta_unique + + nb_nz = 0.d0 + do l = 1, nb + det2(:,2) = psi_det_beta_unique(:,l) + do j = 1, nb + det1(:,2) = psi_det_beta_unique(:,j) + + call get_excitation_degree_spin(det1(1,2),det2(1,2),degree,N_int) + if(degree .gt. 2) cycle + + do k = 1, na + det2(:,1) = psi_det_alpha_unique(:,k) + do i = 1, na + det1(:,1) = psi_det_alpha_unique(:,i) + + call get_excitation_degree(det1,det2,degree,N_int) + if(degree .gt. 2) cycle + + call i_H_j(det1, det2, N_int, h12) + if(dabs(h12).le.(1d-12)) cycle + + ! need nbs + nb_nz = nb_nz + 1.d0 + write(7000, '(4(I8,2X),(F20.13))') i, j, k, l, h12 + enddo + enddo + enddo + enddo + + n_tot = dble(na)**2 * dble(nb)**2 + + print *, ' na = ', na + print *, ' nb = ', nb + + print *, ' nb non zero elemenets = ', nb_nz + print *, ' n_tot = ', n_tot + + print *, ' % non zero elemenets = ', 100.d0 * dexp( dlog(nb_nz) - dlog(n_tot) ) + + call wall_time(t2) + print *, " end const_ij_H_kl_det after (min) ", (t2-t1)/60. + print *, "" + + return +end subroutine const_ij_H_kl_det + diff --git a/devel/svdwf/print_ij_H_kl_det_v1.irp.f b/devel/svdwf/print_ij_H_kl_det_v1.irp.f new file mode 100644 index 0000000..92db895 --- /dev/null +++ b/devel/svdwf/print_ij_H_kl_det_v1.irp.f @@ -0,0 +1,110 @@ +program print_ij_H_kl_det_v1 + + implicit none + + BEGIN_DOC + ! perturbative approach to build psi_postsvd + ! without OMP + END_DOC + + read_wf = .True. + TOUCH read_wf + + PROVIDE N_int + + call run() +end + + +subroutine run + + implicit none + + integer(bit_kind) :: det1(N_int,2), det2(N_int,2) + integer :: degree + double precision :: h12 + + det1(:,1) = psi_det_alpha_unique(:,1) + det2(:,1) = psi_det_alpha_unique(:,1) + det1(:,2) = psi_det_beta_unique(:,1) + det2(:,2) = psi_det_beta_unique(:,1) + call get_excitation_degree_spin(det1(1,1),det2(1,1),degree,N_int) + call get_excitation_degree(det1,det2,degree,N_int) + call i_H_j(det1, det2, N_int, h12) + + print *, ' ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~' + print *, ' CI matrix:', n_det_alpha_unique,'x',n_det_beta_unique + print *, ' N det :', N_det + print *, ' ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~' + + + ! get < d_i d_j | H | d_k d_l > in det basis + call const_ij_Hdet_kl_sparse() + +end + + + + +! _________________________________________________________________________________________________ +! +subroutine const_ij_Hdet_kl_sparse() + + implicit none + + integer(bit_kind) :: det1(N_int,2), det2(N_int,2) + integer :: degree + + integer :: na, nb, i, j, k, l, ii + double precision :: h12 + + double precision :: t1, t2 + + print *, "" + print *, " start const_ij_Hdet_kl_sparse" + call wall_time(t1) + + na = n_det_alpha_unique + nb = n_det_beta_unique + + ii = 0 + !$OMP PARALLEL DEFAULT(NONE) PRIVATE(i,j,k,l,h12,det1,det2,degree) & + !$OMP SHARED(na,nb,psi_det_alpha_unique,psi_det_beta_unique,N_int) + !$OMP DO + do l = 1, nb + det2(:,2) = psi_det_beta_unique(:,l) + do j = 1, nb + det1(:,2) = psi_det_beta_unique(:,j) + + call get_excitation_degree_spin(det1(1,2),det2(1,2),degree,N_int) + if(degree .gt. 2) cycle + + do k = 1, na + det2(:,1) = psi_det_alpha_unique(:,k) + do i = 1, na + det1(:,1) = psi_det_alpha_unique(:,i) + + call get_excitation_degree(det1,det2,degree,N_int) + if(degree .gt. 2) cycle + + call i_H_j(det1, det2, N_int, h12) + if(dabs(h12) .le. (1d-9)) cycle + + write(7001, '(4(I8,2X),(F15.8))') i, j, k, l, h12 + + enddo + enddo + enddo + enddo + !$OMP END DO + !$OMP END PARALLEL + + call wall_time(t2) + print *, " end const_ij_Hdet_kl_sparse after (min) ", (t2-t1)/60. + print *, "" + + return +end subroutine const_ij_Hdet_kl_sparse +! _________________________________________________________________________________________________ +! _________________________________________________________________________________________________ + diff --git a/devel/svdwf/print_ij_H_kl_v0.irp.f b/devel/svdwf/print_ij_H_kl_v0.irp.f new file mode 100644 index 0000000..f12c669 --- /dev/null +++ b/devel/svdwf/print_ij_H_kl_v0.irp.f @@ -0,0 +1,225 @@ +program print_ij_H_kl_v0 + + implicit none + + BEGIN_DOC + ! perturbative approach to build psi_postsvd + ! without OMP + END_DOC + + read_wf = .True. + TOUCH read_wf + + PROVIDE N_int + + call run() +end + + +subroutine run + + USE OMP_LIB + + implicit none + + integer(bit_kind) :: det1(N_int,2), det2(N_int,2) + integer :: degree, i_state + + integer :: i, j, k, l, m, n + double precision :: x, y, h12 + + double precision, allocatable :: Uref(:,:), Dref(:), Vtref(:,:), Aref(:,:), Vref(:,:) + + integer :: rank_max + double precision :: E0, overlop, Ept2 + double precision, allocatable :: H0(:,:) + double precision, allocatable :: eigvec0(:,:), eigval0(:), coeff_psi(:), coeff_tmp(:) + + integer :: ii, ia, ib + double precision, allocatable :: Hdiag(:), Hkl_save(:,:), Hkl_1d(:), Hkl_tmp(:,:), Hdiag_tmp(:) + + integer :: na_new, nb_new, ind_new, ind_gs + double precision :: ctmp, coeff_new + double precision, allocatable :: epsil(:), epsil_energ(:), check_ov(:) + + double precision, allocatable :: Uezfio(:,:,:), Dezfio(:,:), Vezfio(:,:,:) + + integer :: ibeg_alpha, ibeg_beta, iend_alpha, iend_beta + integer :: n_toselect, na_max, nb_max + integer, allocatable :: numalpha_toselect(:), numbeta_toselect(:) + + integer :: cantor_pairing_ij, cantor_pairing_new + integer, allocatable :: cantor_pairing(:), cantor_pairing_tmp(:) + + double precision :: t_beg, t_end + integer(kind=8) :: W_tbeg, W_tend, W_tbeg_it, W_tend_it, W_ir + real(kind=8) :: W_tot_time, W_tot_time_it + integer :: nb_taches + + !$OMP PARALLEL + nb_taches = OMP_GET_NUM_THREADS() + !$OMP END PARALLEL + + call SYSTEM_CLOCK(COUNT=W_tbeg, COUNT_RATE=W_ir) + + i_state = 1 + + det1(:,1) = psi_det_alpha_unique(:,1) + det2(:,1) = psi_det_alpha_unique(:,1) + det1(:,2) = psi_det_beta_unique(:,1) + det2(:,2) = psi_det_beta_unique(:,1) + call get_excitation_degree_spin(det1(1,1),det2(1,1),degree,N_int) + call get_excitation_degree(det1,det2,degree,N_int) + call i_H_j(det1, det2, N_int, h12) + + ! --------------------------------------------------------------------------------------- + ! construct the initial CISD matrix + + print *, ' ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~' + print *, ' CISD matrix:', n_det_alpha_unique,'x',n_det_beta_unique + print *, ' N det :', N_det + print *, ' ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~' + + allocate( Aref(n_det_alpha_unique,n_det_beta_unique) ) + Aref(:,:) = 0.d0 + do k = 1, N_det + i = psi_bilinear_matrix_rows(k) + j = psi_bilinear_matrix_columns(k) + Aref(i,j) = psi_bilinear_matrix_values(k,i_state) + enddo + + ! --------------------------------------------------------------------------------------- + + + + ! --------------------------------------------------------------------------------------- + ! perform a Full SVD + + allocate( Uref(n_det_alpha_unique,n_det_alpha_unique) ) + allocate( Dref(min(n_det_alpha_unique,n_det_beta_unique)) ) + allocate( Vtref(n_det_beta_unique,n_det_beta_unique) ) + + call cpu_time(t_beg) + call svd_s(Aref, size(Aref,1), Uref, size(Uref,1), Dref, Vtref & + , size(Vtref,1), n_det_alpha_unique, n_det_beta_unique) + call cpu_time(t_end) + print *, " SVD is performed after (min)", (t_end-t_beg)/60. + + deallocate( Aref , Dref ) + + allocate( Vref(n_det_beta_unique,n_det_beta_unique) ) + do l = 1, n_det_beta_unique + do i = 1, n_det_beta_unique + Vref(i,l) = Vtref(l,i) + enddo + enddo + deallocate( Vtref ) + + + + + ! get < u_i v_j | H | u_k v_l > for all vectors + call const_ij_H_kl(Uref, Vref) + + deallocate( Uref, Vref ) + + + call SYSTEM_CLOCK(COUNT=W_tend, COUNT_RATE=W_ir) + W_tot_time = real(W_tend - W_tbeg, kind=8) / real(W_ir, kind=8) + print *, ' ___________________________________________________________________' + print *, ' ' + !print *, " Execution avec ", nb_taches, "threads" + print *, " Execution avec 1 threads" + print *, " total elapsed time (min) = ", W_tot_time/60.d0 + print *, ' ___________________________________________________________________' + + +end + + + + + + + + + +subroutine const_ij_H_kl(Uref, Vref) + + implicit none + + double precision, intent(in) :: Uref(n_det_alpha_unique,n_det_alpha_unique) + double precision, intent(in) :: Vref(n_det_beta_unique ,n_det_beta_unique) + + integer(bit_kind) :: det1(N_int,2) + integer(bit_kind) :: det2(N_int,2) + integer :: degree, na, nb + + integer :: i, j, k, l, ii, jj, kk, ll + double precision :: h12, h_abgd, sum_i, sum_j, sum_k, sum_l + + double precision :: t1, t2 + + print *, "" + print *, " start const_ij_H_kl" + call wall_time(t1) + + na = n_det_alpha_unique + nb = n_det_beta_unique + + do ii = 1, na + do jj = 1, nb + do kk = 1, na + do ll = 1, nb + + sum_l = 0.d0 + do l = 1, nb + det2(:,2) = psi_det_beta_unique(:,l) + + sum_j = 0.d0 + do j = 1, nb + det1(:,2) = psi_det_beta_unique(:,j) + + call get_excitation_degree_spin(det1(1,2),det2(1,2),degree,N_int) + if(degree .gt. 2) cycle + + sum_k = 0.d0 + do k = 1, na + det2(:,1) = psi_det_alpha_unique(:,k) + + sum_i = 0.d0 + do i = 1, na + det1(:,1) = psi_det_alpha_unique(:,i) + + call get_excitation_degree(det1,det2,degree,N_int) + if(degree .gt. 2) cycle + + call i_H_j(det1, det2, N_int, h12) + if(h12 .eq. 0.d0) cycle + + sum_i = sum_i + h12 * Uref(i,ii) + enddo + + sum_k = sum_k + sum_i * Uref(k,kk) + enddo + + sum_j = sum_j + sum_k * Vref(j,jj) + enddo + + sum_l = sum_l + sum_j * Vref(l,ll) + enddo + + h_abgd = sum_l + write(7070, '(4(I4,2X),(F15.8))') ii, jj, kk, ll, h_abgd + enddo + enddo + enddo + enddo + + call wall_time(t2) + print *, " end const_ij_H_kl after (min) ", (t2-t1)/60. + print *, "" + + return +end subroutine const_ij_H_kl + diff --git a/devel/svdwf/print_ij_H_kl_v1.irp.f b/devel/svdwf/print_ij_H_kl_v1.irp.f new file mode 100644 index 0000000..e734431 --- /dev/null +++ b/devel/svdwf/print_ij_H_kl_v1.irp.f @@ -0,0 +1,280 @@ +program print_ij_H_kl_v1 + + implicit none + + BEGIN_DOC + ! perturbative approach to build psi_postsvd + ! without OMP + END_DOC + + read_wf = .True. + TOUCH read_wf + + PROVIDE N_int + + call run() +end + + +subroutine run + + USE OMP_LIB + + implicit none + + integer(bit_kind) :: det1(N_int,2), det2(N_int,2) + integer :: degree, i_state + + integer :: i, j, k, l, m, n + double precision :: x, y, h12 + + double precision, allocatable :: Uref(:,:), Dref(:), Vtref(:,:), Aref(:,:), Vref(:,:) + + integer :: rank_max + double precision :: E0, overlop, Ept2 + double precision, allocatable :: H0(:,:) + double precision, allocatable :: eigvec0(:,:), eigval0(:), coeff_psi(:), coeff_tmp(:) + + integer :: ii, ia, ib + double precision, allocatable :: Hdiag(:), Hkl_save(:,:), Hkl_1d(:), Hkl_tmp(:,:), Hdiag_tmp(:) + + integer :: na_new, nb_new, ind_new, ind_gs + double precision :: ctmp, coeff_new + double precision, allocatable :: epsil(:), epsil_energ(:), check_ov(:) + + double precision, allocatable :: Uezfio(:,:,:), Dezfio(:,:), Vezfio(:,:,:) + + integer :: ibeg_alpha, ibeg_beta, iend_alpha, iend_beta + integer :: n_toselect, na_max, nb_max + integer, allocatable :: numalpha_toselect(:), numbeta_toselect(:) + + integer :: cantor_pairing_ij, cantor_pairing_new + integer, allocatable :: cantor_pairing(:), cantor_pairing_tmp(:) + + double precision :: t_beg, t_end + integer(kind=8) :: W_tbeg, W_tend, W_tbeg_it, W_tend_it, W_ir + real(kind=8) :: W_tot_time, W_tot_time_it + integer :: nb_taches + + !$OMP PARALLEL + nb_taches = OMP_GET_NUM_THREADS() + !$OMP END PARALLEL + + call SYSTEM_CLOCK(COUNT=W_tbeg, COUNT_RATE=W_ir) + + i_state = 1 + + det1(:,1) = psi_det_alpha_unique(:,1) + det2(:,1) = psi_det_alpha_unique(:,1) + det1(:,2) = psi_det_beta_unique(:,1) + det2(:,2) = psi_det_beta_unique(:,1) + call get_excitation_degree_spin(det1(1,1),det2(1,1),degree,N_int) + call get_excitation_degree(det1,det2,degree,N_int) + call i_H_j(det1, det2, N_int, h12) + + ! --------------------------------------------------------------------------------------- + ! construct the initial CISD matrix + + print *, ' ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~' + print *, ' CISD matrix:', n_det_alpha_unique,'x',n_det_beta_unique + print *, ' N det :', N_det + print *, ' ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~' + + allocate( Aref(n_det_alpha_unique,n_det_beta_unique) ) + Aref(:,:) = 0.d0 + do k = 1, N_det + i = psi_bilinear_matrix_rows(k) + j = psi_bilinear_matrix_columns(k) + Aref(i,j) = psi_bilinear_matrix_values(k,i_state) + enddo + + ! --------------------------------------------------------------------------------------- + + + + ! --------------------------------------------------------------------------------------- + ! perform a Full SVD + + allocate( Uref(n_det_alpha_unique,n_det_alpha_unique) ) + allocate( Dref(min(n_det_alpha_unique,n_det_beta_unique)) ) + allocate( Vtref(n_det_beta_unique,n_det_beta_unique) ) + + call cpu_time(t_beg) + call svd_s(Aref, size(Aref,1), Uref, size(Uref,1), Dref, Vtref & + , size(Vtref,1), n_det_alpha_unique, n_det_beta_unique) + call cpu_time(t_end) + print *, " SVD is performed after (min)", (t_end-t_beg)/60. + + deallocate( Aref , Dref ) + + allocate( Vref(n_det_beta_unique,n_det_beta_unique) ) + do l = 1, n_det_beta_unique + do i = 1, n_det_beta_unique + Vref(i,l) = Vtref(l,i) + enddo + enddo + deallocate( Vtref ) + + + + + ! get < u_i v_j | H | u_k v_l > for all vectors + call const_ij_H_kl(Uref, Vref) + + deallocate( Uref, Vref ) + + + call SYSTEM_CLOCK(COUNT=W_tend, COUNT_RATE=W_ir) + W_tot_time = real(W_tend - W_tbeg, kind=8) / real(W_ir, kind=8) + print *, ' ___________________________________________________________________' + print *, ' ' + !print *, " Execution avec ", nb_taches, "threads" + print *, " Execution avec 1 threads" + print *, " total elapsed time (min) = ", W_tot_time/60.d0 + print *, ' ___________________________________________________________________' + + +end + + + + + + + + + +subroutine const_ij_H_kl(Uref, Vref) + + implicit none + + double precision, intent(in) :: Uref(n_det_alpha_unique,n_det_alpha_unique) + double precision, intent(in) :: Vref(n_det_beta_unique ,n_det_beta_unique) + + integer(bit_kind) :: det1(N_int,2) + integer(bit_kind) :: det2(N_int,2) + integer :: degree, na, nb + + integer :: i, j, k, l, ii, jj, kk, ll + double precision :: h12, h_abgd, sum_i, sum_j, sum_k, sum_l + + double precision, allocatable :: tmp1(:,:,:,:), tmp2(:,:,:,:) + + double precision :: t1, t2 + + print *, "" + print *, " start const_ij_H_kl" + call wall_time(t1) + + na = n_det_alpha_unique + nb = n_det_beta_unique + + allocate( tmp1(na,nb,na,nb) ) + tmp1(:,:,:,:) = 0.d0 + do ii = 1, na + + do l = 1, nb + det2(:,2) = psi_det_beta_unique(:,l) + do j = 1, nb + det1(:,2) = psi_det_beta_unique(:,j) + + call get_excitation_degree_spin(det1(1,2),det2(1,2),degree,N_int) + if(degree .gt. 2) cycle + + do k = 1, na + det2(:,1) = psi_det_alpha_unique(:,k) + + sum_i = 0.d0 + do i = 1, na + det1(:,1) = psi_det_alpha_unique(:,i) + + call get_excitation_degree(det1,det2,degree,N_int) + if(degree .gt. 2) cycle + + call i_H_j(det1, det2, N_int, h12) + if(h12 .eq. 0.d0) cycle + + sum_i = sum_i + h12 * Uref(i,ii) + !sum_i = sum_i + h12 * Uref(ii,i) + enddo + + tmp1(ii,j,k,l) = sum_i + enddo + enddo + enddo + enddo + + allocate( tmp2(na,nb,na,nb) ) + tmp2(:,:,:,:) = 0.d0 + do ii = 1, na + do jj = 1, nb + do k = 1, na + do l = 1, nb + sum_j = 0.d0 + do j = 1, nb + sum_j = sum_j + tmp1(ii,j,k,l) * Vref(j,jj) + !sum_j = sum_j + tmp1(ii,j,k,l) * Vref(jj,j) + enddo + tmp2(ii,jj,k,l) = sum_j + enddo + enddo + enddo + enddo + deallocate(tmp1) + + allocate( tmp1(na,nb,na,nb) ) + tmp1(:,:,:,:) = 0.d0 + do ii = 1, na + do jj = 1, nb + do kk = 1, na + do l = 1, nb + sum_k = 0.d0 + do k = 1, na + sum_k = sum_k + tmp2(ii,jj,k,l) * Uref(k,kk) + !sum_k = sum_k + tmp2(ii,jj,k,l) * Uref(kk,k) + enddo + tmp1(ii,jj,kk,l) = sum_k + enddo + enddo + enddo + enddo + deallocate(tmp2) + + allocate( tmp2(na,nb,na,nb) ) + tmp2(:,:,:,:) = 0.d0 + do ii = 1, na + do jj = 1, nb + do kk = 1, na + do ll = 1, nb + sum_l = 0.d0 + do l = 1, nb + sum_l = sum_l + tmp1(ii,jj,kk,l) * Vref(l,ll) + !sum_l = sum_l + tmp1(ii,jj,kk,l) * Vref(ll,l) + enddo + tmp2(ii,jj,kk,ll) = sum_l + enddo + enddo + enddo + enddo + deallocate(tmp1) + + do ii = 1, na + do jj = 1, nb + do kk = 1, na + do ll = 1, nb + h_abgd = tmp2(ii,jj,kk,ll) + write(7071, '(4(I4,2X),(F15.8))') ii, jj, kk, ll, h_abgd + enddo + enddo + enddo + enddo + + deallocate(tmp2) + + call wall_time(t2) + print *, " end const_ij_H_kl after (min) ", (t2-t1)/60. + print *, "" + + return +end subroutine const_ij_H_kl + diff --git a/devel/svdwf/psiSVD_naiv1by1_v1.irp.f b/devel/svdwf/psiSVD_naiv1by1_v1.irp.f index 33f1fb9..ad09478 100644 --- a/devel/svdwf/psiSVD_naiv1by1_v1.irp.f +++ b/devel/svdwf/psiSVD_naiv1by1_v1.irp.f @@ -72,7 +72,7 @@ subroutine run ! construct the initial CISD matrix print *, ' ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~' - print *, ' CISD matrix:', n_det_alpha_unique,'x',n_det_beta_unique + print *, ' CI matrix:', n_det_alpha_unique,'x',n_det_beta_unique print *, ' N det :', N_det print *, ' ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~' @@ -317,23 +317,23 @@ subroutine run ind_gs = MAXLOC( check_ov, DIM=1 ) overlop = check_ov(ind_gs) E0 = eigval0(ind_gs)+nuclear_repulsion - coeff_psi(:) = eigvec0(:,ind_gs) - - deallocate( check_ov, eigval0, eigvec0 ) - - ! --------------------------------------------------------------------------------------- - print*, ' space dimen = ', n_selected print*, ' E bef diag = ', Em print*, ' E aft diag = ', E0 print*, ' overlop = ', overlop print*, ' index = ', ind_gs + do i = 1, n_selected + print *, eigvec0(i,ind_gs) + enddo + !coeff_psi(:) = eigvec0(:,ind_gs) + + deallocate( check_ov, eigval0, eigvec0 ) + + ! --------------------------------------------------------------------------------------- write(211, '( 3(I5,3X), 4(F15.8,3X) )') n_selected, na_new, nb_new, Em, E0, overlop - - ! --------------------------------------------------------------------------------------- ! remove selected pair | na_new nb_new > @@ -355,30 +355,6 @@ subroutine run !________________________________________________________________________________________________________ - - ! *************************************************************************************************** - ! save to ezfion - !allocate( Uezfio(n_det_alpha_unique,rank0,1), Dezfio(rank0,1), Vezfio(n_det_beta_unique,rank0,1) ) - !do l = 1, rank0 - ! Dezfio(l,1) = coeff_psi(l) - ! Uezfio(:,l,1) = U0(:,l) - ! Vezfio(:,l,1) = V0(:,l) - !enddo - !call ezfio_set_spindeterminants_n_det(N_det) - !call ezfio_set_spindeterminants_n_states(N_states) - !call ezfio_set_spindeterminants_n_det_alpha(n_det_alpha_unique) - !call ezfio_set_spindeterminants_n_det_beta(n_det_beta_unique) - !call ezfio_set_spindeterminants_psi_coef_matrix_rows(psi_bilinear_matrix_rows) - !call ezfio_set_spindeterminants_psi_coef_matrix_columns(psi_bilinear_matrix_columns) - !call ezfio_set_spindeterminants_psi_coef_matrix_values(psi_bilinear_matrix_values) - - !call ezfio_set_spindeterminants_n_svd_coefs(rank0) - !call ezfio_set_spindeterminants_psi_svd_alpha(Uezfio) - !call ezfio_set_spindeterminants_psi_svd_beta(Vezfio ) - !call ezfio_set_spindeterminants_psi_svd_coefs(Dezfio) - !deallocate( Uezfio, Dezfio, Vezfio ) - ! *************************************************************************************************** - call SYSTEM_CLOCK(COUNT=W_tend, COUNT_RATE=W_ir) W_tot_time = real(W_tend - W_tbeg, kind=8) / real(W_ir, kind=8) print *, ' ___________________________________________________________________' @@ -392,7 +368,7 @@ subroutine run deallocate( Dref ) deallocate( Uref, Vref ) -deallocate( coeff_psi ) + !deallocate( coeff_psi ) deallocate( numalpha_selected, numbeta_selected ) deallocate( H0, Hdiag ) diff --git a/devel/svdwf/psiSVD_naivBbyB_v2.irp.f b/devel/svdwf/psiSVD_naivBbyB_v2.irp.f new file mode 100644 index 0000000..35ea752 --- /dev/null +++ b/devel/svdwf/psiSVD_naivBbyB_v2.irp.f @@ -0,0 +1,334 @@ +program psiSVD_naivBbyB_v2 + + BEGIN_DOC + ! diagonal H in the FSVD space + END_DOC + + implicit none + + read_wf = .True. + TOUCH read_wf + + PROVIDE N_int + + call run() +end + + +subroutine run + + implicit none + + integer(bit_kind) :: det1(N_int,2), det2(N_int,2) + integer :: degree, i_state + double precision :: h12, tol_h + + integer :: na, nb + integer :: n_FSVD, n_TSVD + integer :: i, j, k, l + + double precision, allocatable :: Uref(:,:), Dref(:), Vtref(:,:), Aref(:,:), Vref(:,:) + + double precision :: t_beg, t_end + + call wall_time(t_beg) + + i_state = 1 + det1(:,1) = psi_det_alpha_unique(:,1) + det2(:,1) = psi_det_alpha_unique(:,1) + det1(:,2) = psi_det_beta_unique(:,1) + det2(:,2) = psi_det_beta_unique(:,1) + call get_excitation_degree_spin(det1(1,1),det2(1,1),degree,N_int) + call get_excitation_degree(det1,det2,degree,N_int) + call i_H_j(det1, det2, N_int, h12) + + na = n_det_alpha_unique + nb = n_det_beta_unique + n_FSVD = min(na,nb) + + ! --------------------------------------------------------------------------------------- + ! construct the initial CI matrix + ! + print *, ' ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~' + print *, ' CI matrix:', na, 'x', nb + print *, ' N det :', N_det + print *, ' ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~' + + allocate( Aref(na,nb) ) + Aref(:,:) = 0.d0 + do k = 1, N_det + i = psi_bilinear_matrix_rows(k) + j = psi_bilinear_matrix_columns(k) + Aref(i,j) = psi_bilinear_matrix_values(k,i_state) + enddo + ! + ! --------------------------------------------------------------------------------------- + + ! --------------------------------------------------------------------------------------- + ! perform a Full SVD + ! + allocate( Uref(na,na), Dref(n_FSVD), Vtref(nb,nb) ) + call svd_s(Aref, size(Aref,1), Uref, size(Uref,1), Dref, Vtref, size(Vtref,1), na, nb) + deallocate( Aref ) + + allocate( Vref(n_det_beta_unique,n_det_beta_unique) ) + do l = 1, nb + do i = 1, nb + Vref(i,l) = Vtref(l,i) + enddo + enddo + deallocate( Vtref ) + ! + ! --------------------------------------------------------------------------------------- + + + tol_h = 1d-12 + do i = 2, n_FSVD, 10 + call diag_hsvd(i, n_FSVD, tol_h, Uref, Vref, Dref) + enddo + call diag_hsvd(n_FSVD, n_FSVD, tol_h, Uref, Vref, Dref) + + deallocate( Dref, Uref, Vref ) + + call wall_time(t_end) + print *, ' ' + print *, " total elapsed time (min) = ", (t_end-t_beg)/60.d0 + +end + + + +! ____________________________________________________________________________________________________________ +! +! H_svd(a,b,c,d) = sum_{i,j,k,l} H_det(i,j,k,l) U(i,a) V(j,b) U(k,c) V(l,d) +! +subroutine diag_hsvd(n_TSVD, n_FSVD, tol_h, Uref, Vref, Dref) + + implicit none + + integer, intent(in) :: n_TSVD, n_FSVD + double precision, intent(in) :: tol_h + double precision, intent(in) :: Uref(n_det_alpha_unique,n_det_alpha_unique) + double precision, intent(in) :: Vref(n_det_beta_unique ,n_det_beta_unique) + double precision, intent(in) :: Dref(n_FSVD) + + integer(bit_kind) :: det1(N_int,2), det2(N_int,2) + integer :: degree + double precision :: h12, x + + integer :: na, nb, n_selec + integer :: i, j, k, l + integer :: a, b, c, d + + double precision, allocatable :: H_SVD(:,:,:,:) + double precision, allocatable :: tmp1(:,:,:,:), tmp2(:,:,:,:) + + integer :: ii, ind_gs + double precision :: E0, overlop + double precision, allocatable :: eigvec(:,:), eigval(:), check_ov(:) + + double precision :: t1, t2, t3 + + na = n_det_alpha_unique + nb = n_det_beta_unique + + n_selec = n_TSVD * n_TSVD + + ! --------------------------------------------------------------------------------------- + ! + call wall_time(t1) + print *, '' + print *, ' start const psiHpsi in SVD space ...' + + allocate( tmp1(nb,nb,n_TSVD,n_TSVD) ) + tmp1(:,:,:,:) = 0.d0 + + !$OMP PARALLEL DEFAULT(NONE) & + !$OMP PRIVATE(a, c, i, j, k, l, h12, x, det1, det2, degree, tmp2) & + !$OMP SHARED(na, nb, psi_det_alpha_unique, psi_det_beta_unique, & + !$OMP N_int, n_TSVD, tol_h, Uref, tmp1) + allocate( tmp2(nb,nb,n_TSVD,n_TSVD) ) + tmp2(:,:,:,:) = 0.d0 + !$OMP DO COLLAPSE(2) SCHEDULE(DYNAMIC,8) + do l = 1, nb + do j = 1, nb + det2(:,2) = psi_det_beta_unique(:,l) + det1(:,2) = psi_det_beta_unique(:,j) + call get_excitation_degree_spin(det1(1,2),det2(1,2),degree,N_int) + if(degree .gt. 2) cycle + + do k = 1, na + det2(:,1) = psi_det_alpha_unique(:,k) + do i = 1, na + det1(:,1) = psi_det_alpha_unique(:,i) + call get_excitation_degree(det1,det2,degree,N_int) + if(degree .gt. 2) cycle + call i_H_j(det1, det2, N_int, h12) + if(dabs(h12) .lt. tol_h) cycle + + ! tmp2(j,l,a,c) = sum_{i,k} H(i,j,k,l) U(i,a) U(k,c) + do c = 1, n_TSVD + x = Uref(k,c) * h12 + if(dabs(x) .lt. tol_h) cycle + do a = 1, n_TSVD + tmp2(j,l,a,c) += Uref(i,a) * x + enddo + enddo + + enddo + enddo + enddo + enddo + !$OMP END DO + + ! tmp1 = tmp2 + !$OMP CRITICAL + do a = 1, n_TSVD + do c = 1, n_TSVD + do l = 1, nb + do j = 1, nb + tmp1(j,l,a,c) += tmp2(j,l,a,c) + enddo + enddo + enddo + enddo + !$OMP END CRITICAL + deallocate( tmp2 ) + !$OMP END PARALLEL + + ! tmp2_{l,a,c,b} = sum_{j} tmp1_{j,l,a,c} V_{j,b} + allocate( tmp2(nb,n_TSVD,n_TSVD,n_TSVD) ) + call DGEMM('T', 'N', nb*n_TSVD*n_TSVD, n_TSVD, nb, 1.d0 & + , tmp1, size(tmp1,1) & + , Vref, size(Vref,1) & + , 0.d0, tmp2, size(tmp2,1)*size(tmp2,2)*size(tmp2,3) ) + deallocate(tmp1) + + ! tmp1_{d,a,c,b} = sum_{l} tmp2_{l,a,c,b} V_{l,d} + allocate( tmp1(n_TSVD,n_TSVD,n_TSVD,n_TSVD) ) + call DGEMM('T', 'N', n_TSVD*n_TSVD*n_TSVD, n_TSVD, nb, 1.d0 & + , tmp2, size(tmp2,1) & + , Vref, size(Vref,1) & + , 0.d0, tmp1, size(tmp1,1)*size(tmp1,2)*size(tmp1,3) ) + deallocate( tmp2 ) + + allocate( H_SVD(n_TSVD,n_TSVD,n_TSVD,n_TSVD) ) + H_SVD(:,:,:,:) = 0.d0 + do d = 1, n_TSVD + do c = 1, n_TSVD + do b = 1, n_TSVD + do a = 1, n_TSVD + H_SVD(a,b,c,d) = tmp1(d,a,c,b) + enddo + enddo + enddo + enddo + deallocate( tmp1 ) + + call wall_time(t2) + print *, ' end const psiHpsi in SVD space after (min)', (t2-t1)/60.d0 + print *, '' + ! + ! --------------------------------------------------------------------------------------- + + + + ! --------------------------------------------------------------------------------------- + ! + print *, '' + print *, ' diagonalize psiHpsi in SVD space ...' + + allocate( eigvec(n_selec,n_selec), eigval(n_selec) ) + call lapack_diag(eigval, eigvec, H_SVD, n_selec, n_selec) + deallocate(H_SVD) + + ! get the postsvd ground state + allocate( check_ov(n_selec) ) + do l = 1, n_selec + overlop = 0.d0 + do i = 1, n_TSVD + ii = i + (i-1) * n_TSVD + overlop = overlop + eigvec(ii,l) * Dref(i) + enddo + check_ov(l) = dabs(overlop) + enddo + ind_gs = MAXLOC( check_ov, DIM=1 ) + overlop = check_ov(ind_gs) + E0 = eigval(ind_gs) + nuclear_repulsion + + print *, ' - - - - - - - - - - - - ' + print *, ' n_TSVD = ', n_TSVD + print *, ' space dimen = ', n_selec + + print *, ' gs num = ', ind_gs + print *, ' overlop = ', overlop + + print *, ' diag energy = ', E0 + print *, ' eigen vector: ' + do i = 1, n_selec + print *, eigvec(i,ind_gs) + enddo + print *, ' - - - - - - - - - - - - ' + + write(222, *) n_TSVD, n_selec, E0, overlop + + deallocate( check_ov, eigval, eigvec ) + + call wall_time(t3) + print *, ' end diag in SVD space after (min)', (t3-t2)/60.d0 + print *, '' + ! + ! --------------------------------------------------------------------------------------- + + return +end subroutine diag_hsvd +! ____________________________________________________________________________________________________________ +! ____________________________________________________________________________________________________________ + + + + + + +! ! --------------------------------------------------------------------------------------- +! ! H0 in det basis +! +! call wall_time(ti) +! print *, '' +! print *, ' start const psiHpsi in det space ...' +! +! tol_h = 1d-15 +! allocate( H0_det(na,nb,na,nb) ) +! H0_det(:,:,:,:) = 0.d0 +! +! !$OMP PARALLEL DEFAULT(NONE) & +! !$OMP PRIVATE(i, j, k, l, h12, det1, det2, degree) & +! !$OMP SHARED(na, nb, psi_det_alpha_unique,psi_det_beta_unique, & +! !$OMP N_int, H0, tol_h) +! !$OMP DO COLLAPSE(2) SCHEDULE(DYNAMIC,8) +! do l = 1, nb +! do j = 1, nb +! det2(:,2) = psi_det_beta_unique(:,l) +! det1(:,2) = psi_det_beta_unique(:,j) +! call get_excitation_degree_spin(det1(1,2),det2(1,2),degree,N_int) +! if(degree .gt. 2) cycle +! do k = 1, na +! det2(:,1) = psi_det_alpha_unique(:,k) +! do i = 1, na +! det1(:,1) = psi_det_alpha_unique(:,i) +! call get_excitation_degree(det1,det2,degree,N_int) +! if(degree .gt. 2) cycle +! call i_H_j(det1, det2, N_int, h12) +! if(dabs(h12) .lt. tol_h) cycle +! H0(i,j,k,l) = h12 +! enddo +! enddo +! enddo +! enddo +! !$OMP END DO +! !$OMP END PARALLEL +! +! call wall_time(tf) +! print *, ' end const psiHpsi in det space after (min)', (ti-tf)/60.d0 +! print *, '' +! ! --------------------------------------------------------------------------------------- diff --git a/devel/svdwf/psiSVD_pt2_v1.irp.f b/devel/svdwf/psiSVD_pt2_v1.irp.f index fa11ed3..4fc7927 100644 --- a/devel/svdwf/psiSVD_pt2_v1.irp.f +++ b/devel/svdwf/psiSVD_pt2_v1.irp.f @@ -77,7 +77,7 @@ subroutine run ! construct the initial CISD matrix print *, ' ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~' - print *, ' CISD matrix:', n_det_alpha_unique,'x',n_det_beta_unique + print *, ' CI matrix:', n_det_alpha_unique,'x',n_det_beta_unique print *, ' N det :', N_det print *, ' ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~' @@ -440,30 +440,6 @@ subroutine run !________________________________________________________________________________________________________ - - ! *************************************************************************************************** - ! save to ezfion - !allocate( Uezfio(n_det_alpha_unique,rank0,1), Dezfio(rank0,1), Vezfio(n_det_beta_unique,rank0,1) ) - !do l = 1, rank0 - ! Dezfio(l,1) = coeff_psi(l) - ! Uezfio(:,l,1) = U0(:,l) - ! Vezfio(:,l,1) = V0(:,l) - !enddo - !call ezfio_set_spindeterminants_n_det(N_det) - !call ezfio_set_spindeterminants_n_states(N_states) - !call ezfio_set_spindeterminants_n_det_alpha(n_det_alpha_unique) - !call ezfio_set_spindeterminants_n_det_beta(n_det_beta_unique) - !call ezfio_set_spindeterminants_psi_coef_matrix_rows(psi_bilinear_matrix_rows) - !call ezfio_set_spindeterminants_psi_coef_matrix_columns(psi_bilinear_matrix_columns) - !call ezfio_set_spindeterminants_psi_coef_matrix_values(psi_bilinear_matrix_values) - - !call ezfio_set_spindeterminants_n_svd_coefs(rank0) - !call ezfio_set_spindeterminants_psi_svd_alpha(Uezfio) - !call ezfio_set_spindeterminants_psi_svd_beta(Vezfio ) - !call ezfio_set_spindeterminants_psi_svd_coefs(Dezfio) - !deallocate( Uezfio, Dezfio, Vezfio ) - ! *************************************************************************************************** - call SYSTEM_CLOCK(COUNT=W_tend, COUNT_RATE=W_ir) W_tot_time = real(W_tend - W_tbeg, kind=8) / real(W_ir, kind=8) print *, ' ___________________________________________________________________' @@ -473,7 +449,6 @@ subroutine run print *, ' ___________________________________________________________________' - deallocate( Dref ) deallocate( Uref, Vref ) diff --git a/devel/svdwf/saveSVD_asEZ.irp.f b/devel/svdwf/saveSVD_asEZ.irp.f new file mode 100644 index 0000000..f0dc469 --- /dev/null +++ b/devel/svdwf/saveSVD_asEZ.irp.f @@ -0,0 +1,150 @@ + +program saveSVD_asEZ + + BEGIN_DOC + ! save SVD manually + END_DOC + + implicit none + read_wf = .True. + TOUCH read_wf + + call run() + +end + + +subroutine run + + implicit none + + integer :: mm, nn, i_state, low_rank, lrank_min, lrank_max + integer :: i, j, k, l + double precision :: norm_psi, err_verif, err_tmp + double precision, allocatable :: U_FSVD(:,:), D_FSVD(:), Vt_FSVD(:,:), A_FSVD(:,:) + double precision, allocatable :: Uezfio(:,:,:), Dezfio(:,:), Vezfio(:,:,:) + double precision, allocatable :: US(:,:), A_TSVD(:,:) + double precision :: t0, t1, t2 + + call CPU_TIME(t0) + + i_state = 1 + mm = n_det_alpha_unique + nn = n_det_beta_unique + + print *, ' matrix dimensions:', mm,'x',nn + print *, ' N det:', N_det + + allocate( A_FSVD(mm,nn), U_FSVD(mm,mm), D_FSVD(min(mm,nn)), Vt_FSVD(nn,nn) ) + + norm_psi = 0.d0 + A_FSVD(:,:) = 0.d0 + do k = 1, N_det + i = psi_bilinear_matrix_rows(k) + j = psi_bilinear_matrix_columns(k) + A_FSVD(i,j) = psi_bilinear_matrix_values(k,i_state) + norm_psi += psi_bilinear_matrix_values(k,i_state) * psi_bilinear_matrix_values(k,i_state) + enddo + + call svd_s( A_FSVD, size(A_FSVD,1), U_FSVD, size(U_FSVD,1), D_FSVD, Vt_FSVD, size(Vt_FSVD,1), mm, nn) + print *, ' --- Full SVD: ok --- ' + call CPU_TIME(t1) + print *, (t1-t0)/60.d0, 'min' + + + ! ------------------------------------------ + + + !low_rank = 24 + low_rank = min(mm,nn) + + ! US = U x SV : + allocate( US(mm,low_rank) ) + US(:,:) = 0.d0 + do i = 1, mm + do l = 1, low_rank + US(i,l) = U_FSVD(i,l) * D_FSVD(l) + enddo + enddo + + ! A_TSVD = US x Vt_FSVD + allocate( A_TSVD(mm,nn) ) + A_TSVD(:,:) = 0.d0 + call dgemm( 'N', 'N', mm, nn, low_rank, 1.d0 & + , US , size(US ,1) & + , Vt_FSVD, size(Vt_FSVD,1) & + , 0.d0, A_TSVD, size(A_TSVD,1) ) + deallocatE(US) + + ! |A_FSVD-A_TSVD| + err_verif = 0.d0 + do j = 1, nn + do i = 1, mm + err_tmp = A_FSVD(i,j) - A_TSVD(i,j) + err_verif = err_verif + err_tmp * err_tmp + enddo + enddo + print*, ' rank = ', low_rank + print*, ' err verif (%) = ', 100.d0 * dsqrt(err_verif/norm_psi) + + deallocate( A_FSVD , A_TSVD ) + + + ! ------------------------------------------------------------------------------------------------ + ! set to EZFIO for a fixed low rank + allocate( Uezfio(mm,low_rank,1), Dezfio(low_rank,1), Vezfio(nn,low_rank,1)) + + do l = 1, low_rank + Dezfio(l,1) = D_FSVD(l) + do j = 1, mm + Uezfio(j,l,1) = U_FSVD(j,l) + enddo + do j = 1, nn + Vezfio(j,l,1) = Vt_FSVD(l,j) + enddo + enddo + + deallocate( U_FSVD, D_FSVD, Vt_FSVD ) + + !call ezfio_set_spindeterminants_n_det(N_det) + !call ezfio_set_spindeterminants_n_states(N_states) + !call ezfio_set_spindeterminants_n_det_alpha(n_det_alpha_unique) + !call ezfio_set_spindeterminants_n_det_beta(n_det_beta_unique) + !call ezfio_set_spindeterminants_psi_coef_matrix_rows(psi_bilinear_matrix_rows) + !call ezfio_set_spindeterminants_psi_coef_matrix_columns(psi_bilinear_matrix_columns) + !call ezfio_set_spindeterminants_psi_coef_matrix_values(psi_bilinear_matrix_values) + + call ezfio_set_spindeterminants_n_svd_coefs(low_rank) + call ezfio_set_spindeterminants_psi_svd_coefs(Dezfio) + deallocate( Dezfio) + + ! does not work for big matrices + !call ezfio_set_spindeterminants_psi_svd_alpha(Uezfio) + !call ezfio_set_spindeterminants_psi_svd_beta(Vezfio ) + + open(unit=11, file="u_svd.txt", action='write') + do l = 1, low_rank + do i = 1, mm + write(11,*) Uezfio(i,l,1) + enddo + enddo + close(11) + deallocate( Uezfio ) + + open(unit=11, file="v_svd.txt", action='write') + do l = 1, low_rank + do i = 1, nn + write(11,*) Vezfio(i,l,1) + enddo + enddo + close(11) + deallocate( Vezfio ) + + ! ------------------------------------------------------------------------------------------------ + + call CPU_TIME(t2) + print *, '' + print *, ' end after' + print *, (t2-t0)/60.d0, 'min' + +end From 5905fc563cf13f38185238487d6986a2d5cb47e0 Mon Sep 17 00:00:00 2001 From: Abdallah Ammar Date: Mon, 1 Aug 2022 12:06:37 +0200 Subject: [PATCH 04/16] dmc SVD param --- devel/dmc_dress/EZFIO.cfg | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/devel/dmc_dress/EZFIO.cfg b/devel/dmc_dress/EZFIO.cfg index 88bc4ff..c193977 100644 --- a/devel/dmc_dress/EZFIO.cfg +++ b/devel/dmc_dress/EZFIO.cfg @@ -4,3 +4,39 @@ doc: Dressing matrix obtained from DMC size: (determinants.n_det) interface: ezfio, provider +[la] +interface: ezfio +doc: min rows nb of delta in SVD basis +type: integer +default: 0 + +[lb] +interface: ezfio +doc: min cols nb of delta in SVD basis +type: integer +default: 0 + +[ld] +interface: ezfio +doc: min diag elements of delta in SVD basis +type: integer +default: 0 + +[lla] +interface: ezfio +doc: max rows nb of delta in SVD basis +type: integer +default: 0 + +[llb] +interface: ezfio +doc: max cols nb of delta in SVD basis +type: integer +default: 0 + +[lld] +interface: ezfio +doc: max diag elements of delta in SVD basis +type: integer +default: 0 + From 7cf48160e68d083edb673cd2ba5930246e70715c Mon Sep 17 00:00:00 2001 From: AbdAmmar Date: Wed, 7 Sep 2022 14:55:34 +0200 Subject: [PATCH 05/16] dressing multi states --- devel/dmc_dress/EZFIO.cfg | 2 +- devel/dmc_dress/dmc_dress_1state.irp.f | 36 +++++++++ devel/dmc_dress/dmc_dress_multistate.irp.f | 37 ++++++++++ devel/dmc_dress/dressing_vector.irp.f | 85 ++++++++++++++++------ 4 files changed, 138 insertions(+), 22 deletions(-) create mode 100644 devel/dmc_dress/dmc_dress_1state.irp.f create mode 100644 devel/dmc_dress/dmc_dress_multistate.irp.f diff --git a/devel/dmc_dress/EZFIO.cfg b/devel/dmc_dress/EZFIO.cfg index c193977..912d150 100644 --- a/devel/dmc_dress/EZFIO.cfg +++ b/devel/dmc_dress/EZFIO.cfg @@ -1,7 +1,7 @@ [dmc_delta_h] type: double precision doc: Dressing matrix obtained from DMC -size: (determinants.n_det) +size: (determinants.n_det,determinants.n_states) interface: ezfio, provider [la] diff --git a/devel/dmc_dress/dmc_dress_1state.irp.f b/devel/dmc_dress/dmc_dress_1state.irp.f new file mode 100644 index 0000000..a1f9dd3 --- /dev/null +++ b/devel/dmc_dress/dmc_dress_1state.irp.f @@ -0,0 +1,36 @@ +program dmc_dress_1state + implicit none + BEGIN_DOC +! Program that extracts the lowest states of the Hamiltonian dressed by the QMC +! dressing vector stored in :option:`dmc_dressing dmc_delta_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(:,:) + 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) + + 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) + do i=1,N_det + print *, 'HPsi/c0 = ', tmp(i,1)/psi_coef(i,1) + enddo +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/dmc_dress_multistate.irp.f b/devel/dmc_dress/dmc_dress_multistate.irp.f new file mode 100644 index 0000000..28d4be3 --- /dev/null +++ b/devel/dmc_dress/dmc_dress_multistate.irp.f @@ -0,0 +1,37 @@ +program dmc_dress_multistate + + BEGIN_DOC + ! Program that extracts the lowest states of the Hamiltonian dressed by the QMC + ! dressing vector stored in :option:`dmc_dressing dmc_delta_h` + ! + END_DOC + + implicit none + + read_wf = .True. + touch read_wf + + call routine() + call save_wavefunction_general(N_det, N_states, psi_det_sorted, size(psi_coef_sorted, 1), psi_coef_sorted) + +end + +! --- + +subroutine routine + + implicit none + integer :: k + + do k = 1, N_states + print *, ' state:', k + psi_coef(1:N_det,k) = ci_eigenvectors_nonsym_dressed(1:N_det,k) + print *, 'E = ', ci_energy_nonsym_dressed(k) + nuclear_repulsion + enddo + + SOFT_TOUCH psi_coef + +end + +! --- + diff --git a/devel/dmc_dress/dressing_vector.irp.f b/devel/dmc_dress/dressing_vector.irp.f index 71c59c8..09939c7 100644 --- a/devel/dmc_dress/dressing_vector.irp.f +++ b/devel/dmc_dress/dressing_vector.irp.f @@ -1,33 +1,76 @@ + +! --- + BEGIN_PROVIDER [ double precision, dressing_column_h, (N_det,N_states) ] &BEGIN_PROVIDER [ double precision, dressing_column_s, (N_det,N_states) ] - 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, allocatable :: delta(:) + BEGIN_DOC + ! \Delta_{state-specific}. \Psi + ! Diagonal element is divided by 2 because Delta = D + D^t + END_DOC - allocate(delta(N_det)) - delta(1:N_det) = dmc_delta_h(1:N_det) + implicit none + integer :: i,ii,k,j, l + double precision :: f, tmp + double precision, allocatable :: delta(:) - call dset_order(delta,psi_bilinear_matrix_order_reverse,N_det) + allocate(delta(N_det)) + delta(1:N_det) = dmc_delta_h(1:N_det,1) - dressing_column_h(:,:) = 0.d0 - dressing_column_s(:,:) = 0.d0 + call dset_order(delta,psi_bilinear_matrix_order_reverse,N_det) - l = dressed_column_idx(1) - do j = 1, n_det - if (j == l) cycle - 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) += delta(l) - dressing_column_h(l,1) *= 0.5d0 + dressing_column_h(:,:) = 0.d0 + dressing_column_s(:,:) = 0.d0 + + l = dressed_column_idx(1) + do j = 1, n_det + if(j == l) cycle + 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) += delta(l) + dressing_column_h(l,1) *= 0.5d0 + + deallocate(delta) END_PROVIDER +! --- +BEGIN_PROVIDER [ double precision, dressing_delta, (N_det, N_states) ] + + BEGIN_DOC + ! + ! dressing_delta is: + ! [\delta_K]_I = < I | \tilde{H} - H | \Phi_K > + ! + END_DOC + + implicit none + integer :: i, j, k + double precision, allocatable :: delta(:,:) + + dressing_delta(1:N_det,1:N_states) = 0.d0 + + allocate(delta(N_det,N_states)) + + do k = 1, N_states + + do j = 1, N_det + delta(j,k) = dmc_delta_h(j,k) + enddo + + call dset_order(delta(1:N_det,k), psi_bilinear_matrix_order_reverse, N_det) + + do j = 1, N_det + dressing_delta(j,k) = delta(j,k) + enddo + + enddo + + deallocate(delta) + +END_PROVIDER + +! --- From 29803d77ae04f9373fc5c49846ab229724f2621d Mon Sep 17 00:00:00 2001 From: AbdAmmar Date: Tue, 4 Oct 2022 14:25:43 +0200 Subject: [PATCH 06/16] save_for_qmcchem ok --- devel/qmcchem/save_for_qmcchem.irp.f | 2 ++ 1 file changed, 2 insertions(+) diff --git a/devel/qmcchem/save_for_qmcchem.irp.f b/devel/qmcchem/save_for_qmcchem.irp.f index c7bcf46..ef37689 100644 --- a/devel/qmcchem/save_for_qmcchem.irp.f +++ b/devel/qmcchem/save_for_qmcchem.irp.f @@ -43,3 +43,5 @@ program save_for_qmc close(iunit) end + +! --- From c52dcd8846df5432c867d450b664f92462acc7d2 Mon Sep 17 00:00:00 2001 From: Anthony Scemama Date: Sat, 31 Dec 2022 12:48:26 +0100 Subject: [PATCH 07/16] Removed debug in trexio --- devel/cc/denominators.irp.f | 3 +++ devel/trexio/import_trexio_integrals.irp.f | 6 +++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/devel/cc/denominators.irp.f b/devel/cc/denominators.irp.f index d605086..3af8e4e 100644 --- a/devel/cc/denominators.irp.f +++ b/devel/cc/denominators.irp.f @@ -21,6 +21,7 @@ BEGIN_PROVIDER [ double precision, delta_OV, (spin_occ_num, spin_vir_num) ] do i=1,spin_occ_num delta_OV(i,a) = eO(i) - eV(a) ! delta_OV(i,a) = min(eO(i) - eV(a), -1.d-3) + if (delta_OV(i,a) == 0.d0) delta_OV(i,a) = 1.d-1 enddo enddo @@ -39,6 +40,7 @@ BEGIN_PROVIDER [ double precision, delta_OOVV, (spin_occ_num,spin_occ_num,spin_v do j=1,spin_occ_num do i=1,spin_occ_num delta_OOVV(i,j,a,b) = delta_OV(i,a) + delta_OV(j,b) + if (delta_OOVV(i,j,a,b) == 0.d0) delta_OOVV(i,j,a,b) = 1.d-1 enddo enddo enddo @@ -60,6 +62,7 @@ BEGIN_PROVIDER [ double precision, delta_OOOVVV, (spin_occ_num,spin_occ_num,spin do j=1,spin_occ_num do i=1,spin_occ_num delta_OOOVVV(i,j,k,a,b,c) = delta_OV(i,a) + delta_OV(j,b) + delta_OV(k,c) + if (delta_OOOVVV(i,j,k,a,b,c) == 0.d0) delta_OOOVVV(i,j,k,a,b,c) = 1.d-1 enddo enddo enddo diff --git a/devel/trexio/import_trexio_integrals.irp.f b/devel/trexio/import_trexio_integrals.irp.f index 865f95c..901cc70 100644 --- a/devel/trexio/import_trexio_integrals.irp.f +++ b/devel/trexio/import_trexio_integrals.irp.f @@ -111,7 +111,7 @@ subroutine run integer*8 :: offset, icount - open(unit=104,file='tmp') +! open(unit=104,file='tmp') offset = 0_8 icount = BUFSIZE rc = TREXIO_SUCCESS @@ -125,7 +125,7 @@ subroutine run integral = V(m) call two_e_integrals_index(i, j, k, l, buffer_i(m) ) buffer_values(m) = integral - write(104,'(4(I5,X),2D22.15)') i,j,k,l, integral +! write(104,'(4(I5,X),2D22.15)') i,j,k,l, integral enddo call insert_into_ao_integrals_map(int(icount,4),buffer_i,buffer_values) offset = offset + icount @@ -134,7 +134,7 @@ subroutine run endif end do n_integrals = offset - close(104) +! close(104) call map_sort(ao_integrals_map) call map_unique(ao_integrals_map) From b72ea96670f097dc35ccbcd0f3950de897caa684 Mon Sep 17 00:00:00 2001 From: Anthony Scemama Date: Thu, 9 Mar 2023 10:50:44 +0100 Subject: [PATCH 08/16] Added export_trexio routine --- devel/qmcchem/NEED | 1 + devel/qmcchem/install | 23 + devel/qmcchem/save_for_qmcchem.irp.f | 2 + devel/trexio/export_trexio.irp.f | 527 +-------------------- devel/trexio/export_trexio_routines.irp.f | 524 ++++++++++++++++++++ devel/trexio/import_trexio_integrals.irp.f | 4 +- devel/trexio/qp_import_trexio.py | 1 + 7 files changed, 555 insertions(+), 527 deletions(-) create mode 100755 devel/qmcchem/install create mode 100644 devel/trexio/export_trexio_routines.irp.f diff --git a/devel/qmcchem/NEED b/devel/qmcchem/NEED index afb53ca..ee5861a 100644 --- a/devel/qmcchem/NEED +++ b/devel/qmcchem/NEED @@ -1,4 +1,5 @@ determinants davidson_undressed fci +trexio zmq diff --git a/devel/qmcchem/install b/devel/qmcchem/install new file mode 100755 index 0000000..edc5e26 --- /dev/null +++ b/devel/qmcchem/install @@ -0,0 +1,23 @@ +#!/bin/bash + +# Check if the QP_ROOT environment variable is set. +if [[ -z ${QP_ROOT} ]] +then + print "The QP_ROOT environment variable is not set." + print "Please reload the quantum_package.rc file." + exit -1 +fi + +pkg-config --libs trexio > LIB + +scripts_list="qp_import_trexio.py" + +# Destroy ONLY the symbolic link for the scripts to be used in the +# ${QP_ROOT}/scripts/ directory. +for i in $scripts_list +do + find ${QP_ROOT}/scripts/$i -type l -delete +done + +# Create symlink in scripts +ln --symbolic ${PWD}/qp_import_trexio.py $QP_ROOT/scripts diff --git a/devel/qmcchem/save_for_qmcchem.irp.f b/devel/qmcchem/save_for_qmcchem.irp.f index c7bcf46..b56c97e 100644 --- a/devel/qmcchem/save_for_qmcchem.irp.f +++ b/devel/qmcchem/save_for_qmcchem.irp.f @@ -42,4 +42,6 @@ program save_for_qmc write(iunit,*) e_ref close(iunit) + call export_trexio end + diff --git a/devel/trexio/export_trexio.irp.f b/devel/trexio/export_trexio.irp.f index f537fbc..3ae0dcb 100644 --- a/devel/trexio/export_trexio.irp.f +++ b/devel/trexio/export_trexio.irp.f @@ -1,530 +1,7 @@ -program export_trexio +program export_trexio_prog implicit none read_wf = .True. SOFT_TOUCH read_wf - call run + call export_trexio end -subroutine run - use trexio - implicit none - BEGIN_DOC - ! Exports the wave function in TREXIO format - END_DOC - - integer(trexio_t) :: f ! TREXIO file handle - integer(trexio_exit_code) :: rc - double precision, allocatable :: factor(:) - - print *, 'TREXIO file : '//trim(trexio_filename) - print *, '' - - call system('cp '//trim(trexio_filename)//' '//trim(trexio_filename)//'.bak') - if (backend == 0) then - f = trexio_open(trexio_filename, 'u', TREXIO_HDF5, rc) - else if (backend == 1) then - f = trexio_open(trexio_filename, 'u', TREXIO_TEXT, rc) - endif - if (f == 0_8) then - print *, 'Unable to open TREXIO file for writing' - print *, 'rc = ', rc - stop -1 - endif - -! ------------------------------------------------------------------------------ - -! Electrons -! --------- - - print *, 'Electrons' - - rc = trexio_write_electron_up_num(f, elec_alpha_num) - call trexio_assert(rc, TREXIO_SUCCESS) - - rc = trexio_write_electron_dn_num(f, elec_beta_num) - call trexio_assert(rc, TREXIO_SUCCESS) - - -! Nuclei -! ------ - - print *, 'Nuclei' - - rc = trexio_write_nucleus_num(f, nucl_num) - call trexio_assert(rc, TREXIO_SUCCESS) - - rc = trexio_write_nucleus_charge(f, nucl_charge) - call trexio_assert(rc, TREXIO_SUCCESS) - - rc = trexio_write_nucleus_coord(f, nucl_coord_transp) - call trexio_assert(rc, TREXIO_SUCCESS) - - rc = trexio_write_nucleus_label(f, nucl_label, 32) - call trexio_assert(rc, TREXIO_SUCCESS) - - rc = trexio_write_nucleus_repulsion(f, nuclear_repulsion) - call trexio_assert(rc, TREXIO_SUCCESS) - - -! Pseudo-potentials -! ----------------- - - if (do_pseudo) then - - print *, 'ECP' - integer :: num - - num = 0 - do k=1,pseudo_klocmax - do i=1,nucl_num - if (pseudo_dz_k(i,k) /= 0.d0) then - num = num+1 - end if - end do - end do - - do l=0,pseudo_lmax - do k=1,pseudo_kmax - do i=1,nucl_num - if (pseudo_dz_kl(i,k,l) /= 0.d0) then - num = num+1 - end if - end do - end do - end do - - integer, allocatable :: ang_mom(:), nucleus_index(:), power(:), lmax(:) - double precision, allocatable :: exponent(:), coefficient(:) - - allocate(ang_mom(num), nucleus_index(num), exponent(num), coefficient(num), power(num), & - lmax(nucl_num) ) - - do i=1,nucl_num - lmax(i) = -1 - do l=0,pseudo_lmax - do k=1,pseudo_kmax - if (pseudo_dz_kl_transp(k,l,i) /= 0.d0) then - lmax(i) = max(lmax(i), l) - end if - end do - end do - end do - - j = 0 - do i=1,nucl_num - do k=1,pseudo_klocmax - if (pseudo_dz_k_transp(k,i) /= 0.d0) then - j = j+1 - ang_mom(j) = lmax(i)+1 - nucleus_index(j) = i - exponent(j) = pseudo_dz_k_transp(k,i) - coefficient(j) = pseudo_v_k_transp(k,i) - power(j) = pseudo_n_k_transp(k,i) - end if - end do - - do l=0,lmax(i) - do k=1,pseudo_kmax - if (pseudo_dz_kl_transp(k,l,i) /= 0.d0) then - j = j+1 - ang_mom(j) = l - nucleus_index(j) = i - exponent(j) = pseudo_dz_kl_transp(k,l,i) - coefficient(j) = pseudo_v_kl_transp(k,l,i) - power(j) = pseudo_n_kl_transp(k,l,i) - end if - end do - end do - end do - - - lmax(:) = lmax(:)+1 - rc = trexio_write_ecp_max_ang_mom_plus_1(f, lmax) - call trexio_assert(rc, TREXIO_SUCCESS) - - rc = trexio_write_ecp_z_core(f, int(nucl_charge_remove)) - call trexio_assert(rc, TREXIO_SUCCESS) - - rc = trexio_write_ecp_num(f, num) - call trexio_assert(rc, TREXIO_SUCCESS) - - rc = trexio_write_ecp_ang_mom(f, ang_mom) - call trexio_assert(rc, TREXIO_SUCCESS) - - rc = trexio_write_ecp_nucleus_index(f, nucleus_index) - call trexio_assert(rc, TREXIO_SUCCESS) - - rc = trexio_write_ecp_exponent(f, exponent) - call trexio_assert(rc, TREXIO_SUCCESS) - - rc = trexio_write_ecp_coefficient(f, coefficient) - call trexio_assert(rc, TREXIO_SUCCESS) - - rc = trexio_write_ecp_power(f, power) - call trexio_assert(rc, TREXIO_SUCCESS) - - endif - - -! Basis -! ----- - - print *, 'Basis' - - - rc = trexio_write_basis_type(f, 'Gaussian', len('Gaussian')) - call trexio_assert(rc, TREXIO_SUCCESS) - - rc = trexio_write_basis_prim_num(f, prim_num) - call trexio_assert(rc, TREXIO_SUCCESS) - - rc = trexio_write_basis_shell_num(f, shell_num) - call trexio_assert(rc, TREXIO_SUCCESS) - - rc = trexio_write_basis_nucleus_index(f, basis_nucleus_index) - call trexio_assert(rc, TREXIO_SUCCESS) - - rc = trexio_write_basis_shell_ang_mom(f, shell_ang_mom) - call trexio_assert(rc, TREXIO_SUCCESS) - - allocate(factor(shell_num)) - if (ao_normalized) then - factor(1:shell_num) = shell_normalization_factor(1:shell_num) - else - factor(1:shell_num) = 1.d0 - endif - rc = trexio_write_basis_shell_factor(f, factor) - call trexio_assert(rc, TREXIO_SUCCESS) - - deallocate(factor) - - rc = trexio_write_basis_shell_index(f, shell_index) - call trexio_assert(rc, TREXIO_SUCCESS) - - rc = trexio_write_basis_exponent(f, prim_expo) - call trexio_assert(rc, TREXIO_SUCCESS) - - rc = trexio_write_basis_coefficient(f, prim_coef) - call trexio_assert(rc, TREXIO_SUCCESS) - - allocate(factor(prim_num)) - if (primitives_normalized) then - factor(1:prim_num) = prim_normalization_factor(1:prim_num) - else - factor(1:prim_num) = 1.d0 - endif - rc = trexio_write_basis_prim_factor(f, factor) - call trexio_assert(rc, TREXIO_SUCCESS) - deallocate(factor) - - -! Atomic orbitals -! --------------- - - print *, 'AOs' - - rc = trexio_write_ao_num(f, ao_num) - call trexio_assert(rc, TREXIO_SUCCESS) - - rc = trexio_write_ao_cartesian(f, 1) - call trexio_assert(rc, TREXIO_SUCCESS) - - rc = trexio_write_ao_shell(f, ao_shell) - call trexio_assert(rc, TREXIO_SUCCESS) - - integer :: i, pow0(3), powA(3), j, k, l, nz - double precision :: normA, norm0, C_A(3), overlap_x, overlap_z, overlap_y, c - nz=100 - - C_A(1) = 0.d0 - C_A(2) = 0.d0 - C_A(3) = 0.d0 - - allocate(factor(ao_num)) - if (ao_normalized) then - do i=1,ao_num - l = ao_first_of_shell(ao_shell(i)) - factor(i) = (ao_coef_normalized(i,1)+tiny(1.d0))/(ao_coef_normalized(l,1)+tiny(1.d0)) - enddo - else - factor(:) = 1.d0 - endif - rc = trexio_write_ao_normalization(f, factor) - call trexio_assert(rc, TREXIO_SUCCESS) - deallocate(factor) - -! One-e AO integrals -! ------------------ - - if (export_ao_one_e_ints) then - print *, 'AO one-e integrals' - - rc = trexio_write_ao_1e_int_overlap(f,ao_overlap) - call trexio_assert(rc, TREXIO_SUCCESS) - - rc = trexio_write_ao_1e_int_kinetic(f,ao_kinetic_integrals) - call trexio_assert(rc, TREXIO_SUCCESS) - - rc = trexio_write_ao_1e_int_potential_n_e(f,ao_integrals_n_e) - call trexio_assert(rc, TREXIO_SUCCESS) - - if (do_pseudo) then - rc = trexio_write_ao_1e_int_ecp(f, ao_pseudo_integrals_local + ao_pseudo_integrals_non_local) - call trexio_assert(rc, TREXIO_SUCCESS) - endif - - rc = trexio_write_ao_1e_int_core_hamiltonian(f,ao_one_e_integrals) - call trexio_assert(rc, TREXIO_SUCCESS) - end if - -! Two-e AO integrals -! ------------------ - - if (export_ao_two_e_ints) then - print *, 'AO two-e integrals' - PROVIDE ao_two_e_integrals_in_map - - integer(8), parameter :: BUFSIZE=10000_8 - double precision :: eri_buffer(BUFSIZE), integral - integer(4) :: eri_index(4,BUFSIZE) - integer(8) :: icount, offset - - double precision, external :: get_ao_two_e_integral - - - icount = 0_8 - offset = 0_8 - do l=1,ao_num - do k=1,ao_num - do j=l,ao_num - do i=k,ao_num - if (i==j .and. k= 0_8) then - rc = trexio_write_ao_2e_int_eri(f, offset, icount, eri_index, eri_buffer) - call trexio_assert(rc, TREXIO_SUCCESS) - end if - end if - - -! Molecular orbitals -! ------------------ - - print *, 'MOs' - - rc = trexio_write_mo_type(f, mo_label, len(trim(mo_label))) - call trexio_assert(rc, TREXIO_SUCCESS) - - rc = trexio_write_mo_num(f, mo_num) - call trexio_assert(rc, TREXIO_SUCCESS) - - rc = trexio_write_mo_coefficient(f, mo_coef) - call trexio_assert(rc, TREXIO_SUCCESS) - -! if (trim(mo_label) == 'Canonical') then -! rc = trexio_write_mo_energy(f, fock_matrix_diag_mo) -! call trexio_assert(rc, TREXIO_SUCCESS) -! endif - - -! One-e MO integrals -! ------------------ - - if (export_mo_two_e_ints) then - print *, 'MO one-e integrals' - - rc = trexio_write_mo_1e_int_kinetic(f,mo_kinetic_integrals) - call trexio_assert(rc, TREXIO_SUCCESS) - - rc = trexio_write_mo_1e_int_potential_n_e(f,mo_integrals_n_e) - call trexio_assert(rc, TREXIO_SUCCESS) - - if (do_pseudo) then - rc = trexio_write_mo_1e_int_ecp(f,mo_pseudo_integrals_local) - call trexio_assert(rc, TREXIO_SUCCESS) - endif - - rc = trexio_write_mo_1e_int_core_hamiltonian(f,mo_one_e_integrals) - call trexio_assert(rc, TREXIO_SUCCESS) - end if - -! Two-e MO integrals -! ------------------ - - if (export_mo_two_e_ints) then - print *, 'MO two-e integrals' - PROVIDE mo_two_e_integrals_in_map - - double precision, external :: mo_two_e_integral - - - icount = 0_8 - offset = 0_8 - do l=1,mo_num - do k=1,mo_num - do j=l,mo_num - do i=k,mo_num - if (i==j .and. k 0_8) then - rc = trexio_write_mo_2e_int_eri(f, offset, icount, eri_index, eri_buffer) - call trexio_assert(rc, TREXIO_SUCCESS) - end if - end if - - - -! One-e RDM -! --------- - - rc = trexio_write_rdm_1e(f,one_e_dm_mo) - call trexio_assert(rc, TREXIO_SUCCESS) - - rc = trexio_write_rdm_1e_up(f,one_e_dm_mo_alpha_average) - call trexio_assert(rc, TREXIO_SUCCESS) - - rc = trexio_write_rdm_1e_dn(f,one_e_dm_mo_beta_average) - call trexio_assert(rc, TREXIO_SUCCESS) - - -! Two-e RDM -! --------- - - if (export_rdm) then - PROVIDE two_e_dm_mo - print *, 'Two-e RDM' - - icount = 0_8 - offset = 0_8 - do l=1,mo_num - do k=1,mo_num - do j=1,mo_num - do i=1,mo_num - integral = two_e_dm_mo(i,j,k,l) - if (integral == 0.d0) cycle - icount += 1_8 - eri_buffer(icount) = integral - eri_index(1,icount) = i - eri_index(2,icount) = j - eri_index(3,icount) = k - eri_index(4,icount) = l - if (icount == BUFSIZE) then - rc = trexio_write_rdm_2e(f, offset, icount, eri_index, eri_buffer) - call trexio_assert(rc, TREXIO_SUCCESS) - offset += icount - icount = 0_8 - end if - end do - end do - end do - end do - - if (icount >= 0_8) then - rc = trexio_write_rdm_2e(f, offset, icount, eri_index, eri_buffer) - call trexio_assert(rc, TREXIO_SUCCESS) - end if - end if - - -! ------------------------------------------------------------------------------ - - ! Determinants - ! ------------ - - integer*8, allocatable :: det_buffer(:,:,:) - double precision, allocatable :: coef_buffer(:,:) - integer :: nint - -! rc = trexio_read_determinant_int64_num(f, nint) -! call trexio_assert(rc, TREXIO_SUCCESS) - nint = N_int - if (nint /= N_int) then - stop 'Problem with N_int' - endif - allocate ( det_buffer(nint, 2, BUFSIZE), coef_buffer(BUFSIZE, n_states) ) - - icount = 0_8 - offset = 0_8 - rc = trexio_write_state_num(f, n_states) - call trexio_assert(rc, TREXIO_SUCCESS) - - rc = trexio_set_state (f, 0) - call trexio_assert(rc, TREXIO_SUCCESS) - do k=1,n_det - icount += 1_8 - det_buffer(1:nint, 1:2, icount) = psi_det(1:N_int, 1:2, k) - coef_buffer(icount,1:N_states) = psi_coef(k,1:N_states) - if (icount == BUFSIZE) then - call trexio_assert(rc, TREXIO_SUCCESS) - rc = trexio_write_determinant_list(f, offset, icount, det_buffer) - call trexio_assert(rc, TREXIO_SUCCESS) - do i=1,N_states - rc = trexio_set_state (f, i-1) - call trexio_assert(rc, TREXIO_SUCCESS) - rc = trexio_write_determinant_coefficient(f, offset, icount, coef_buffer(1,i)) - end do - rc = trexio_set_state (f, 0) - offset += icount - icount = 0_8 - end if - end do - - if (icount >= 0_8) then - call trexio_assert(rc, TREXIO_SUCCESS) - rc = trexio_write_determinant_list(f, offset, icount, det_buffer) - call trexio_assert(rc, TREXIO_SUCCESS) - do i=1,N_states - rc = trexio_set_state (f, i-1) - call trexio_assert(rc, TREXIO_SUCCESS) - rc = trexio_write_determinant_coefficient(f, offset, icount, coef_buffer(1,i)) - end do - rc = trexio_set_state (f, 0) - end if - - deallocate ( det_buffer, coef_buffer ) - - rc = trexio_close(f) - call trexio_assert(rc, TREXIO_SUCCESS) - -end - - -! -*- mode: f90 -*- diff --git a/devel/trexio/export_trexio_routines.irp.f b/devel/trexio/export_trexio_routines.irp.f new file mode 100644 index 0000000..44415b9 --- /dev/null +++ b/devel/trexio/export_trexio_routines.irp.f @@ -0,0 +1,524 @@ +subroutine export_trexio + use trexio + implicit none + BEGIN_DOC + ! Exports the wave function in TREXIO format + END_DOC + + integer(trexio_t) :: f ! TREXIO file handle + integer(trexio_exit_code) :: rc + double precision, allocatable :: factor(:) + + print *, 'TREXIO file : '//trim(trexio_filename) + print *, '' + + call system('cp '//trim(trexio_filename)//' '//trim(trexio_filename)//'.bak') + if (backend == 0) then + f = trexio_open(trexio_filename, 'u', TREXIO_HDF5, rc) + else if (backend == 1) then + f = trexio_open(trexio_filename, 'u', TREXIO_TEXT, rc) + endif + if (f == 0_8) then + print *, 'Unable to open TREXIO file for writing' + print *, 'rc = ', rc + stop -1 + endif + call ezfio_set_trexio_trexio_file(trexio_filename) + +! ------------------------------------------------------------------------------ + +! Electrons +! --------- + + print *, 'Electrons' + + rc = trexio_write_electron_up_num(f, elec_alpha_num) + call trexio_assert(rc, TREXIO_SUCCESS) + + rc = trexio_write_electron_dn_num(f, elec_beta_num) + call trexio_assert(rc, TREXIO_SUCCESS) + + +! Nuclei +! ------ + + print *, 'Nuclei' + + rc = trexio_write_nucleus_num(f, nucl_num) + call trexio_assert(rc, TREXIO_SUCCESS) + + rc = trexio_write_nucleus_charge(f, nucl_charge) + call trexio_assert(rc, TREXIO_SUCCESS) + + rc = trexio_write_nucleus_coord(f, nucl_coord_transp) + call trexio_assert(rc, TREXIO_SUCCESS) + + rc = trexio_write_nucleus_label(f, nucl_label, 32) + call trexio_assert(rc, TREXIO_SUCCESS) + + rc = trexio_write_nucleus_repulsion(f, nuclear_repulsion) + call trexio_assert(rc, TREXIO_SUCCESS) + + +! Pseudo-potentials +! ----------------- + + if (do_pseudo) then + + print *, 'ECP' + integer :: num + + num = 0 + do k=1,pseudo_klocmax + do i=1,nucl_num + if (pseudo_dz_k(i,k) /= 0.d0) then + num = num+1 + end if + end do + end do + + do l=0,pseudo_lmax + do k=1,pseudo_kmax + do i=1,nucl_num + if (pseudo_dz_kl(i,k,l) /= 0.d0) then + num = num+1 + end if + end do + end do + end do + + integer, allocatable :: ang_mom(:), nucleus_index(:), power(:), lmax(:) + double precision, allocatable :: exponent(:), coefficient(:) + + allocate(ang_mom(num), nucleus_index(num), exponent(num), coefficient(num), power(num), & + lmax(nucl_num) ) + + do i=1,nucl_num + lmax(i) = -1 + do l=0,pseudo_lmax + do k=1,pseudo_kmax + if (pseudo_dz_kl_transp(k,l,i) /= 0.d0) then + lmax(i) = max(lmax(i), l) + end if + end do + end do + end do + + j = 0 + do i=1,nucl_num + do k=1,pseudo_klocmax + if (pseudo_dz_k_transp(k,i) /= 0.d0) then + j = j+1 + ang_mom(j) = lmax(i)+1 + nucleus_index(j) = i + exponent(j) = pseudo_dz_k_transp(k,i) + coefficient(j) = pseudo_v_k_transp(k,i) + power(j) = pseudo_n_k_transp(k,i) + end if + end do + + do l=0,lmax(i) + do k=1,pseudo_kmax + if (pseudo_dz_kl_transp(k,l,i) /= 0.d0) then + j = j+1 + ang_mom(j) = l + nucleus_index(j) = i + exponent(j) = pseudo_dz_kl_transp(k,l,i) + coefficient(j) = pseudo_v_kl_transp(k,l,i) + power(j) = pseudo_n_kl_transp(k,l,i) + end if + end do + end do + end do + + + lmax(:) = lmax(:)+1 + rc = trexio_write_ecp_max_ang_mom_plus_1(f, lmax) + call trexio_assert(rc, TREXIO_SUCCESS) + + rc = trexio_write_ecp_z_core(f, int(nucl_charge_remove)) + call trexio_assert(rc, TREXIO_SUCCESS) + + rc = trexio_write_ecp_num(f, num) + call trexio_assert(rc, TREXIO_SUCCESS) + + rc = trexio_write_ecp_ang_mom(f, ang_mom) + call trexio_assert(rc, TREXIO_SUCCESS) + + rc = trexio_write_ecp_nucleus_index(f, nucleus_index) + call trexio_assert(rc, TREXIO_SUCCESS) + + rc = trexio_write_ecp_exponent(f, exponent) + call trexio_assert(rc, TREXIO_SUCCESS) + + rc = trexio_write_ecp_coefficient(f, coefficient) + call trexio_assert(rc, TREXIO_SUCCESS) + + rc = trexio_write_ecp_power(f, power) + call trexio_assert(rc, TREXIO_SUCCESS) + + endif + + +! Basis +! ----- + + print *, 'Basis' + + + rc = trexio_write_basis_type(f, 'Gaussian', len('Gaussian')) + call trexio_assert(rc, TREXIO_SUCCESS) + + rc = trexio_write_basis_prim_num(f, prim_num) + call trexio_assert(rc, TREXIO_SUCCESS) + + rc = trexio_write_basis_shell_num(f, shell_num) + call trexio_assert(rc, TREXIO_SUCCESS) + + rc = trexio_write_basis_nucleus_index(f, basis_nucleus_index) + call trexio_assert(rc, TREXIO_SUCCESS) + + rc = trexio_write_basis_shell_ang_mom(f, shell_ang_mom) + call trexio_assert(rc, TREXIO_SUCCESS) + + allocate(factor(shell_num)) + if (ao_normalized) then + factor(1:shell_num) = shell_normalization_factor(1:shell_num) + else + factor(1:shell_num) = 1.d0 + endif + rc = trexio_write_basis_shell_factor(f, factor) + call trexio_assert(rc, TREXIO_SUCCESS) + + deallocate(factor) + + rc = trexio_write_basis_shell_index(f, shell_index) + call trexio_assert(rc, TREXIO_SUCCESS) + + rc = trexio_write_basis_exponent(f, prim_expo) + call trexio_assert(rc, TREXIO_SUCCESS) + + rc = trexio_write_basis_coefficient(f, prim_coef) + call trexio_assert(rc, TREXIO_SUCCESS) + + allocate(factor(prim_num)) + if (primitives_normalized) then + factor(1:prim_num) = prim_normalization_factor(1:prim_num) + else + factor(1:prim_num) = 1.d0 + endif + rc = trexio_write_basis_prim_factor(f, factor) + call trexio_assert(rc, TREXIO_SUCCESS) + deallocate(factor) + + +! Atomic orbitals +! --------------- + + print *, 'AOs' + + rc = trexio_write_ao_num(f, ao_num) + call trexio_assert(rc, TREXIO_SUCCESS) + + rc = trexio_write_ao_cartesian(f, 1) + call trexio_assert(rc, TREXIO_SUCCESS) + + rc = trexio_write_ao_shell(f, ao_shell) + call trexio_assert(rc, TREXIO_SUCCESS) + + integer :: i, pow0(3), powA(3), j, k, l, nz + double precision :: normA, norm0, C_A(3), overlap_x, overlap_z, overlap_y, c + nz=100 + + C_A(1) = 0.d0 + C_A(2) = 0.d0 + C_A(3) = 0.d0 + + allocate(factor(ao_num)) + if (ao_normalized) then + do i=1,ao_num + l = ao_first_of_shell(ao_shell(i)) + factor(i) = (ao_coef_normalized(i,1)+tiny(1.d0))/(ao_coef_normalized(l,1)+tiny(1.d0)) + enddo + else + factor(:) = 1.d0 + endif + rc = trexio_write_ao_normalization(f, factor) + call trexio_assert(rc, TREXIO_SUCCESS) + deallocate(factor) + +! One-e AO integrals +! ------------------ + + if (export_ao_one_e_ints) then + print *, 'AO one-e integrals' + + rc = trexio_write_ao_1e_int_overlap(f,ao_overlap) + call trexio_assert(rc, TREXIO_SUCCESS) + + rc = trexio_write_ao_1e_int_kinetic(f,ao_kinetic_integrals) + call trexio_assert(rc, TREXIO_SUCCESS) + + rc = trexio_write_ao_1e_int_potential_n_e(f,ao_integrals_n_e) + call trexio_assert(rc, TREXIO_SUCCESS) + + if (do_pseudo) then + rc = trexio_write_ao_1e_int_ecp(f, ao_pseudo_integrals_local + ao_pseudo_integrals_non_local) + call trexio_assert(rc, TREXIO_SUCCESS) + endif + + rc = trexio_write_ao_1e_int_core_hamiltonian(f,ao_one_e_integrals) + call trexio_assert(rc, TREXIO_SUCCESS) + end if + +! Two-e AO integrals +! ------------------ + + if (export_ao_two_e_ints) then + print *, 'AO two-e integrals' + PROVIDE ao_two_e_integrals_in_map + + integer(8), parameter :: BUFSIZE=10000_8 + double precision :: eri_buffer(BUFSIZE), integral + integer(4) :: eri_index(4,BUFSIZE) + integer(8) :: icount, offset + + double precision, external :: get_ao_two_e_integral + + + icount = 0_8 + offset = 0_8 + do l=1,ao_num + do k=1,ao_num + do j=l,ao_num + do i=k,ao_num + if (i==j .and. k= 0_8) then + rc = trexio_write_ao_2e_int_eri(f, offset, icount, eri_index, eri_buffer) + call trexio_assert(rc, TREXIO_SUCCESS) + end if + end if + + +! Molecular orbitals +! ------------------ + + print *, 'MOs' + + rc = trexio_write_mo_type(f, mo_label, len(trim(mo_label))) + call trexio_assert(rc, TREXIO_SUCCESS) + + rc = trexio_write_mo_num(f, mo_num) + call trexio_assert(rc, TREXIO_SUCCESS) + + rc = trexio_write_mo_coefficient(f, mo_coef) + call trexio_assert(rc, TREXIO_SUCCESS) + +! if (trim(mo_label) == 'Canonical') then +! rc = trexio_write_mo_energy(f, fock_matrix_diag_mo) +! call trexio_assert(rc, TREXIO_SUCCESS) +! endif + + +! One-e MO integrals +! ------------------ + + if (export_mo_two_e_ints) then + print *, 'MO one-e integrals' + + rc = trexio_write_mo_1e_int_kinetic(f,mo_kinetic_integrals) + call trexio_assert(rc, TREXIO_SUCCESS) + + rc = trexio_write_mo_1e_int_potential_n_e(f,mo_integrals_n_e) + call trexio_assert(rc, TREXIO_SUCCESS) + + if (do_pseudo) then + rc = trexio_write_mo_1e_int_ecp(f,mo_pseudo_integrals_local) + call trexio_assert(rc, TREXIO_SUCCESS) + endif + + rc = trexio_write_mo_1e_int_core_hamiltonian(f,mo_one_e_integrals) + call trexio_assert(rc, TREXIO_SUCCESS) + end if + +! Two-e MO integrals +! ------------------ + + if (export_mo_two_e_ints) then + print *, 'MO two-e integrals' + PROVIDE mo_two_e_integrals_in_map + + double precision, external :: mo_two_e_integral + + + icount = 0_8 + offset = 0_8 + do l=1,mo_num + do k=1,mo_num + do j=l,mo_num + do i=k,mo_num + if (i==j .and. k 0_8) then + rc = trexio_write_mo_2e_int_eri(f, offset, icount, eri_index, eri_buffer) + call trexio_assert(rc, TREXIO_SUCCESS) + end if + end if + + + +! One-e RDM +! --------- + + rc = trexio_write_rdm_1e(f,one_e_dm_mo) + call trexio_assert(rc, TREXIO_SUCCESS) + + rc = trexio_write_rdm_1e_up(f,one_e_dm_mo_alpha_average) + call trexio_assert(rc, TREXIO_SUCCESS) + + rc = trexio_write_rdm_1e_dn(f,one_e_dm_mo_beta_average) + call trexio_assert(rc, TREXIO_SUCCESS) + + +! Two-e RDM +! --------- + + if (export_rdm) then + PROVIDE two_e_dm_mo + print *, 'Two-e RDM' + + icount = 0_8 + offset = 0_8 + do l=1,mo_num + do k=1,mo_num + do j=1,mo_num + do i=1,mo_num + integral = two_e_dm_mo(i,j,k,l) + if (integral == 0.d0) cycle + icount += 1_8 + eri_buffer(icount) = integral + eri_index(1,icount) = i + eri_index(2,icount) = j + eri_index(3,icount) = k + eri_index(4,icount) = l + if (icount == BUFSIZE) then + rc = trexio_write_rdm_2e(f, offset, icount, eri_index, eri_buffer) + call trexio_assert(rc, TREXIO_SUCCESS) + offset += icount + icount = 0_8 + end if + end do + end do + end do + end do + + if (icount >= 0_8) then + rc = trexio_write_rdm_2e(f, offset, icount, eri_index, eri_buffer) + call trexio_assert(rc, TREXIO_SUCCESS) + end if + end if + + +! ------------------------------------------------------------------------------ + + ! Determinants + ! ------------ + + integer*8, allocatable :: det_buffer(:,:,:) + double precision, allocatable :: coef_buffer(:,:) + integer :: nint + +! rc = trexio_read_determinant_int64_num(f, nint) +! call trexio_assert(rc, TREXIO_SUCCESS) + nint = N_int + if (nint /= N_int) then + stop 'Problem with N_int' + endif + allocate ( det_buffer(nint, 2, BUFSIZE), coef_buffer(BUFSIZE, n_states) ) + + icount = 0_8 + offset = 0_8 + rc = trexio_write_state_num(f, n_states) + call trexio_assert(rc, TREXIO_SUCCESS) + + rc = trexio_set_state (f, 0) + call trexio_assert(rc, TREXIO_SUCCESS) + do k=1,n_det + icount += 1_8 + det_buffer(1:nint, 1:2, icount) = psi_det(1:N_int, 1:2, k) + coef_buffer(icount,1:N_states) = psi_coef(k,1:N_states) + if (icount == BUFSIZE) then + call trexio_assert(rc, TREXIO_SUCCESS) + rc = trexio_write_determinant_list(f, offset, icount, det_buffer) + call trexio_assert(rc, TREXIO_SUCCESS) + do i=1,N_states + rc = trexio_set_state (f, i-1) + call trexio_assert(rc, TREXIO_SUCCESS) + rc = trexio_write_determinant_coefficient(f, offset, icount, coef_buffer(1,i)) + end do + rc = trexio_set_state (f, 0) + offset += icount + icount = 0_8 + end if + end do + + if (icount >= 0_8) then + call trexio_assert(rc, TREXIO_SUCCESS) + rc = trexio_write_determinant_list(f, offset, icount, det_buffer) + call trexio_assert(rc, TREXIO_SUCCESS) + do i=1,N_states + rc = trexio_set_state (f, i-1) + call trexio_assert(rc, TREXIO_SUCCESS) + rc = trexio_write_determinant_coefficient(f, offset, icount, coef_buffer(1,i)) + end do + rc = trexio_set_state (f, 0) + end if + + deallocate ( det_buffer, coef_buffer ) + + rc = trexio_close(f) + call trexio_assert(rc, TREXIO_SUCCESS) + +end + + +! -*- mode: f90 -*- diff --git a/devel/trexio/import_trexio_integrals.irp.f b/devel/trexio/import_trexio_integrals.irp.f index 865f95c..4d8e3da 100644 --- a/devel/trexio/import_trexio_integrals.irp.f +++ b/devel/trexio/import_trexio_integrals.irp.f @@ -111,7 +111,7 @@ subroutine run integer*8 :: offset, icount - open(unit=104,file='tmp') +! open(unit=104,file='tmp') offset = 0_8 icount = BUFSIZE rc = TREXIO_SUCCESS @@ -125,7 +125,7 @@ subroutine run integral = V(m) call two_e_integrals_index(i, j, k, l, buffer_i(m) ) buffer_values(m) = integral - write(104,'(4(I5,X),2D22.15)') i,j,k,l, integral +! write(104,'(4(I5,X),2D22.15)') i,j,k,l, integral enddo call insert_into_ao_integrals_map(int(icount,4),buffer_i,buffer_values) offset = offset + icount diff --git a/devel/trexio/qp_import_trexio.py b/devel/trexio/qp_import_trexio.py index 4f691ea..b1f37de 100755 --- a/devel/trexio/qp_import_trexio.py +++ b/devel/trexio/qp_import_trexio.py @@ -150,6 +150,7 @@ def write_ezfio(trexio_filename, filename): nucl_shell_num.append(m) m = 0 prev = i + print (len(nucl_shell_num), nucl_num) assert (len(nucl_shell_num) == nucl_num) shell_prim_num = [] From ddc3f28a67697598d4466d2eee492fff213a5a39 Mon Sep 17 00:00:00 2001 From: Anthony Scemama Date: Mon, 3 Apr 2023 15:53:19 +0200 Subject: [PATCH 09/16] Fixed set_ao_basis_ao_prim_num_max --- devel/trexio/qp_import_trexio.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/devel/trexio/qp_import_trexio.py b/devel/trexio/qp_import_trexio.py index b1f37de..b682022 100755 --- a/devel/trexio/qp_import_trexio.py +++ b/devel/trexio/qp_import_trexio.py @@ -150,7 +150,6 @@ def write_ezfio(trexio_filename, filename): nucl_shell_num.append(m) m = 0 prev = i - print (len(nucl_shell_num), nucl_num) assert (len(nucl_shell_num) == nucl_num) shell_prim_num = [] @@ -239,7 +238,7 @@ def write_ezfio(trexio_filename, filename): coef.append(coefficient[j]) expo.append(exponent[j]) - ezfio.set_ao_basis_ao_prim_num_max(prim_num_max) +# ezfio.set_ao_basis_ao_prim_num_max(prim_num_max) ezfio.set_ao_basis_ao_coef(coef) ezfio.set_ao_basis_ao_expo(expo) ezfio.set_ao_basis_ao_basis("Read from TREXIO") From cfbae398c785f5b1c138862c27a1c0d9e566ceb5 Mon Sep 17 00:00:00 2001 From: Anthony Scemama Date: Mon, 24 Apr 2023 01:42:04 +0200 Subject: [PATCH 10/16] TREXIO --- devel/fci_complete/generate_fci.irp.f | 3 +- devel/mpn/generate_fci.irp.f | 3 +- devel/trexio/import_trexio_integrals.irp.f | 4 +- devel/trexio/qp_import_trexio.py | 105 ++++++++++----------- 4 files changed, 57 insertions(+), 58 deletions(-) diff --git a/devel/fci_complete/generate_fci.irp.f b/devel/fci_complete/generate_fci.irp.f index 5ea3fc2..fcbe5d5 100644 --- a/devel/fci_complete/generate_fci.irp.f +++ b/devel/fci_complete/generate_fci.irp.f @@ -36,7 +36,8 @@ subroutine generate_fci_space call configuration_to_dets_size(act_bitmask,n_det_alpha_unique,elec_alpha_num-ncore,N_int) TOUCH n_det_alpha_unique - integer :: k,n,m, t, t1, t2 + integer :: k,n,m + integer(bit_kind) :: t, t1, t2 k=0 n = elec_alpha_num m = norb - n diff --git a/devel/mpn/generate_fci.irp.f b/devel/mpn/generate_fci.irp.f index 5108862..78863ba 100644 --- a/devel/mpn/generate_fci.irp.f +++ b/devel/mpn/generate_fci.irp.f @@ -26,7 +26,8 @@ subroutine generate_fci_space call configuration_to_dets_size(o,n_det_alpha_unique,elec_alpha_num-ncore,N_int) TOUCH n_det_alpha_unique - integer :: k,n,m, t, t1, t2 + integer :: k,n,m + integer(bit_kind) :: t, t1, t2 k=0 n = elec_alpha_num m = mo_num - n diff --git a/devel/trexio/import_trexio_integrals.irp.f b/devel/trexio/import_trexio_integrals.irp.f index 22ac61e..cf610e3 100644 --- a/devel/trexio/import_trexio_integrals.irp.f +++ b/devel/trexio/import_trexio_integrals.irp.f @@ -13,10 +13,10 @@ subroutine run integer(trexio_t) :: f ! TREXIO file handle integer(trexio_exit_code) :: rc - integer ::i,j,k,l,m + integer ::i,j,k,l + integer(8) :: m, n_integrals double precision :: integral - integer :: n_integrals integer(key_kind), allocatable :: buffer_i(:) real(integral_kind), allocatable :: buffer_values(:) diff --git a/devel/trexio/qp_import_trexio.py b/devel/trexio/qp_import_trexio.py index b682022..165fb9d 100755 --- a/devel/trexio/qp_import_trexio.py +++ b/devel/trexio/qp_import_trexio.py @@ -67,15 +67,9 @@ def write_ezfio(trexio_filename, filename): except: trexio_file = trexio.File(trexio_filename,mode='r',back_end=trexio.TREXIO_HDF5) - basis_type = trexio.read_basis_type(trexio_file) -# if basis_type.lower() != "gaussian": -# raise TypeError - ezfio.set_file(filename) ezfio.set_trexio_trexio_file(trexio_filename) - - print("Nuclei\t\t...\t", end=' ') charge = trexio.read_nucleus_charge(trexio_file) @@ -117,66 +111,69 @@ def write_ezfio(trexio_filename, filename): print("Basis\t\t...\t", end=' ') - ezfio.set_basis_basis("Read from TREXIO") + try: + basis_type = trexio.read_basis_type(trexio_file) + + if basis_type.lower() != "gaussian": + raise TypeError - shell_num = trexio.read_basis_shell_num(trexio_file) - prim_num = trexio.read_basis_prim_num(trexio_file) + shell_num = trexio.read_basis_shell_num(trexio_file) + prim_num = trexio.read_basis_prim_num(trexio_file) + ang_mom = trexio.read_basis_shell_ang_mom(trexio_file) + nucl_index = trexio.read_basis_nucleus_index(trexio_file) + exponent = trexio.read_basis_exponent(trexio_file) + coefficient = trexio.read_basis_coefficient(trexio_file) + shell_index = trexio.read_basis_shell_index(trexio_file) + ao_shell = trexio.read_ao_shell(trexio_file) - ezfio.set_basis_shell_num(shell_num) - ezfio.set_basis_prim_num(prim_num) + ezfio.set_basis_basis("Read from TREXIO") + ezfio.set_basis_shell_num(shell_num) + ezfio.set_basis_prim_num(prim_num) + ezfio.set_basis_shell_ang_mom(ang_mom) + ezfio.set_basis_basis_nucleus_index([ x+1 for x in nucl_index ]) + ezfio.set_basis_prim_expo(exponent) + ezfio.set_basis_prim_coef(coefficient) - ang_mom = trexio.read_basis_shell_ang_mom(trexio_file) - nucl_index = trexio.read_basis_nucleus_index(trexio_file) + nucl_shell_num = [] + prev = None + m = 0 + for i in ao_shell: + if i != prev: + m += 1 + if prev is None or nucl_index[i] != nucl_index[prev]: + nucl_shell_num.append(m) + m = 0 + prev = i + assert (len(nucl_shell_num) == nucl_num) - ezfio.set_basis_shell_ang_mom(ang_mom) - ezfio.set_basis_basis_nucleus_index([ x+1 for x in nucl_index ]) + shell_prim_num = [] + prev = shell_index[0] + count = 0 + for i in shell_index: + if i != prev: + shell_prim_num.append(count) + count = 0 + count += 1 + prev = i + shell_prim_num.append(count) - exponent = trexio.read_basis_exponent(trexio_file) - coefficient = trexio.read_basis_coefficient(trexio_file) + assert (len(shell_prim_num) == shell_num) - ezfio.set_basis_prim_expo(exponent) - ezfio.set_basis_prim_coef(coefficient) - - shell_index = trexio.read_basis_shell_index(trexio_file) - ao_shell = trexio.read_ao_shell(trexio_file) - - nucl_shell_num = [] - prev = None - m = 0 - for i in ao_shell: - if i != prev: - m += 1 - if prev is None or nucl_index[i] != nucl_index[prev]: - nucl_shell_num.append(m) - m = 0 - prev = i - assert (len(nucl_shell_num) == nucl_num) - - shell_prim_num = [] - prev = shell_index[0] - count = 0 - for i in shell_index: - if i != prev: - shell_prim_num.append(count) - count = 0 - count += 1 - prev = i - shell_prim_num.append(count) - - assert (len(shell_prim_num) == shell_num) - - ezfio.set_basis_shell_prim_num(shell_prim_num) - ezfio.set_basis_shell_index([x+1 for x in shell_index]) - ezfio.set_basis_nucleus_shell_num(nucl_shell_num) + ezfio.set_basis_shell_prim_num(shell_prim_num) + ezfio.set_basis_shell_index([x+1 for x in shell_index]) + ezfio.set_basis_nucleus_shell_num(nucl_shell_num) - shell_factor = trexio.read_basis_shell_factor(trexio_file) - prim_factor = trexio.read_basis_prim_factor(trexio_file) + shell_factor = trexio.read_basis_shell_factor(trexio_file) + prim_factor = trexio.read_basis_prim_factor(trexio_file) - print("OK") + print("OK") + except: + print("None") print("AOS\t\t...\t", end=' ') + ao_shell = trexio.read_ao_shell(trexio_file) cartesian = trexio.read_ao_cartesian(trexio_file) if not cartesian: raise TypeError('Only cartesian TREXIO files can be converted') From 400ec36d26c78132beced263be52a774f905a4b6 Mon Sep 17 00:00:00 2001 From: Anthony Scemama Date: Thu, 4 May 2023 14:31:49 +0200 Subject: [PATCH 11/16] Added cholesky vectors in export --- devel/trexio/EZFIO.cfg | 12 ++++ devel/trexio/export_trexio_routines.irp.f | 78 +++++++++++++++++++++++ 2 files changed, 90 insertions(+) diff --git a/devel/trexio/EZFIO.cfg b/devel/trexio/EZFIO.cfg index 396fa5c..8606e90 100644 --- a/devel/trexio/EZFIO.cfg +++ b/devel/trexio/EZFIO.cfg @@ -34,9 +34,21 @@ doc: If True, export two-electron integrals in AO basis interface: ezfio, ocaml, provider default: False +[export_ao_two_e_ints_cholesky] +type: logical +doc: If True, export Cholesky-decomposed two-electron integrals in AO basis +interface: ezfio, ocaml, provider +default: False + [export_mo_two_e_ints] type: logical doc: If True, export two-electron integrals in MO basis interface: ezfio, ocaml, provider default: False +[export_mo_two_e_ints_cholesky] +type: logical +doc: If True, export Cholesky-decomposed two-electron integrals in MO basis +interface: ezfio, ocaml, provider +default: False + diff --git a/devel/trexio/export_trexio_routines.irp.f b/devel/trexio/export_trexio_routines.irp.f index 44415b9..b226ce4 100644 --- a/devel/trexio/export_trexio_routines.irp.f +++ b/devel/trexio/export_trexio_routines.irp.f @@ -319,6 +319,44 @@ subroutine export_trexio end if end if +! Two-e AO integrals - Cholesky +! ----------------------------- + + if (export_ao_two_e_ints_cholesky) then + print *, 'AO two-e integrals Cholesky' + + rc = trexio_write_ao_2e_int_eri_cholesky_num(f, cholesky_ao_num) + call trexio_assert(rc, TREXIO_SUCCESS) + + icount = 0_8 + offset = 0_8 + do k=1,cholesky_ao_num + do j=1,ao_num + do i=1,ao_num + integral = cholesky_ao(i,j,k) + if (integral == 0.d0) cycle + icount += 1_8 + eri_buffer(icount) = integral + eri_index(1,icount) = i + eri_index(2,icount) = j + eri_index(3,icount) = k + if (icount == BUFSIZE) then + rc = trexio_write_ao_2e_int_eri_cholesky(f, offset, icount, eri_index, eri_buffer) + call trexio_assert(rc, TREXIO_SUCCESS) + offset += icount + icount = 0_8 + end if + end do + end do + end do + + if (icount > 0_8) then + rc = trexio_write_ao_2e_int_eri_cholesky(f, offset, icount, eri_index, eri_buffer) + call trexio_assert(rc, TREXIO_SUCCESS) + end if + end if + + ! Molecular orbitals ! ------------------ @@ -404,6 +442,46 @@ subroutine export_trexio end if end if +! Two-e MO integrals - Cholesky +! ----------------------------- + + if (export_mo_two_e_ints_cholesky) then + print *, 'MO two-e integrals Cholesky' + PROVIDE mo_two_e_integrals_in_map + + icount = 0_8 + offset = 0_8 + do l=1,mo_num + do k=1,mo_num + do j=l,mo_num + do i=k,mo_num + if (i==j .and. k 0_8) then + rc = trexio_write_mo_2e_int_eri(f, offset, icount, eri_index, eri_buffer) + call trexio_assert(rc, TREXIO_SUCCESS) + end if + end if + ! One-e RDM From 5fd6574601bd398c13180deee678e80690b523fb Mon Sep 17 00:00:00 2001 From: Anthony Scemama Date: Thu, 4 May 2023 15:54:46 +0200 Subject: [PATCH 12/16] Cholesky MOs in TREXIO --- devel/trexio/export_trexio_routines.irp.f | 46 +++++++++++------------ 1 file changed, 21 insertions(+), 25 deletions(-) diff --git a/devel/trexio/export_trexio_routines.irp.f b/devel/trexio/export_trexio_routines.irp.f index b226ce4..9d8381f 100644 --- a/devel/trexio/export_trexio_routines.irp.f +++ b/devel/trexio/export_trexio_routines.irp.f @@ -447,43 +447,39 @@ subroutine export_trexio if (export_mo_two_e_ints_cholesky) then print *, 'MO two-e integrals Cholesky' - PROVIDE mo_two_e_integrals_in_map + + rc = trexio_write_mo_2e_int_eri_cholesky_num(f, cholesky_ao_num) + call trexio_assert(rc, TREXIO_SUCCESS) icount = 0_8 offset = 0_8 - do l=1,mo_num - do k=1,mo_num - do j=l,mo_num - do i=k,mo_num - if (i==j .and. k 0_8) then - rc = trexio_write_mo_2e_int_eri(f, offset, icount, eri_index, eri_buffer) + rc = trexio_write_mo_2e_int_eri_cholesky(f, offset, icount, eri_index, eri_buffer) call trexio_assert(rc, TREXIO_SUCCESS) end if end if - ! One-e RDM ! --------- From e71d81aaefe0af94fd3020d970a13dc038c05306 Mon Sep 17 00:00:00 2001 From: Anthony Scemama Date: Thu, 4 May 2023 16:37:00 +0200 Subject: [PATCH 13/16] Fixed dimensions in cholesky --- devel/trexio/export_trexio_routines.irp.f | 27 +++++++++++++---------- devel/trexio/install | 2 +- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/devel/trexio/export_trexio_routines.irp.f b/devel/trexio/export_trexio_routines.irp.f index 9d8381f..c983d45 100644 --- a/devel/trexio/export_trexio_routines.irp.f +++ b/devel/trexio/export_trexio_routines.irp.f @@ -322,6 +322,9 @@ subroutine export_trexio ! Two-e AO integrals - Cholesky ! ----------------------------- + integer(4) :: chol_index(3,BUFSIZE) + double precision :: chol_buffer(BUFSIZE) + if (export_ao_two_e_ints_cholesky) then print *, 'AO two-e integrals Cholesky' @@ -336,12 +339,12 @@ subroutine export_trexio integral = cholesky_ao(i,j,k) if (integral == 0.d0) cycle icount += 1_8 - eri_buffer(icount) = integral - eri_index(1,icount) = i - eri_index(2,icount) = j - eri_index(3,icount) = k + chol_buffer(icount) = integral + chol_index(1,icount) = i + chol_index(2,icount) = j + chol_index(3,icount) = k if (icount == BUFSIZE) then - rc = trexio_write_ao_2e_int_eri_cholesky(f, offset, icount, eri_index, eri_buffer) + rc = trexio_write_ao_2e_int_eri_cholesky(f, offset, icount, chol_index, chol_buffer) call trexio_assert(rc, TREXIO_SUCCESS) offset += icount icount = 0_8 @@ -351,7 +354,7 @@ subroutine export_trexio end do if (icount > 0_8) then - rc = trexio_write_ao_2e_int_eri_cholesky(f, offset, icount, eri_index, eri_buffer) + rc = trexio_write_ao_2e_int_eri_cholesky(f, offset, icount, chol_index, chol_buffer) call trexio_assert(rc, TREXIO_SUCCESS) end if end if @@ -459,12 +462,12 @@ subroutine export_trexio integral = cholesky_mo(i,j,k) if (integral == 0.d0) cycle icount += 1_8 - eri_buffer(icount) = integral - eri_index(1,icount) = i - eri_index(2,icount) = j - eri_index(3,icount) = k + chol_buffer(icount) = integral + chol_index(1,icount) = i + chol_index(2,icount) = j + chol_index(3,icount) = k if (icount == BUFSIZE) then - rc = trexio_write_mo_2e_int_eri_cholesky(f, offset, icount, eri_index, eri_buffer) + rc = trexio_write_mo_2e_int_eri_cholesky(f, offset, icount, chol_index, chol_buffer) call trexio_assert(rc, TREXIO_SUCCESS) offset += icount icount = 0_8 @@ -474,7 +477,7 @@ subroutine export_trexio end do if (icount > 0_8) then - rc = trexio_write_mo_2e_int_eri_cholesky(f, offset, icount, eri_index, eri_buffer) + rc = trexio_write_mo_2e_int_eri_cholesky(f, offset, icount, chol_index, chol_buffer) call trexio_assert(rc, TREXIO_SUCCESS) end if end if diff --git a/devel/trexio/install b/devel/trexio/install index edc5e26..4f967c9 100755 --- a/devel/trexio/install +++ b/devel/trexio/install @@ -16,7 +16,7 @@ scripts_list="qp_import_trexio.py" # ${QP_ROOT}/scripts/ directory. for i in $scripts_list do - find ${QP_ROOT}/scripts/$i -type l -delete + find ${QP_ROOT}/scripts/$i -type l -delete 2> /dev/null done # Create symlink in scripts From 192f4c6913cb0eedfd1b69c76759720253901d55 Mon Sep 17 00:00:00 2001 From: Anthony Scemama Date: Thu, 4 May 2023 17:49:41 +0200 Subject: [PATCH 14/16] Fixed one-two electron --- devel/trexio/export_trexio_routines.irp.f | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/devel/trexio/export_trexio_routines.irp.f b/devel/trexio/export_trexio_routines.irp.f index c983d45..8635eb7 100644 --- a/devel/trexio/export_trexio_routines.irp.f +++ b/devel/trexio/export_trexio_routines.irp.f @@ -384,7 +384,7 @@ subroutine export_trexio ! One-e MO integrals ! ------------------ - if (export_mo_two_e_ints) then + if (export_mo_one_e_ints) then print *, 'MO one-e integrals' rc = trexio_write_mo_1e_int_kinetic(f,mo_kinetic_integrals) From 6f04cc0eb0b4e8688bc735eeb93aaaca28b8e4ab Mon Sep 17 00:00:00 2001 From: Anthony Scemama Date: Wed, 10 May 2023 14:44:30 +0200 Subject: [PATCH 15/16] Allow no basis set --- devel/trexio/import_trexio_integrals.irp.f | 30 +++-- devel/trexio/qp_import_trexio.py | 147 ++++++++++++--------- 2 files changed, 99 insertions(+), 78 deletions(-) diff --git a/devel/trexio/import_trexio_integrals.irp.f b/devel/trexio/import_trexio_integrals.irp.f index cf610e3..9f9ad9d 100644 --- a/devel/trexio/import_trexio_integrals.irp.f +++ b/devel/trexio/import_trexio_integrals.irp.f @@ -1,8 +1,22 @@ program import_integrals_ao - call run + use trexio + implicit none + integer(trexio_t) :: f ! TREXIO file handle + integer(trexio_exit_code) :: rc + + f = trexio_open(trexio_filename, 'r', TREXIO_AUTO, rc) + if (f == 0_8) then + print *, 'Unable to open TREXIO file for reading' + print *, 'rc = ', rc + stop -1 + endif + + call run(f) + rc = trexio_close(f) + call trexio_assert(rc, TREXIO_SUCCESS) end -subroutine run +subroutine run(f) use trexio use map_module implicit none @@ -10,7 +24,7 @@ subroutine run ! Program to import integrals from TREXIO END_DOC - integer(trexio_t) :: f ! TREXIO file handle + integer(trexio_t), intent(in) :: f ! TREXIO file handle integer(trexio_exit_code) :: rc integer ::i,j,k,l @@ -25,16 +39,6 @@ subroutine run double precision, allocatable :: V(:) integer , allocatable :: Vi(:,:) double precision :: s - PROVIDE ao_num - - f = trexio_open(trexio_filename, 'r', TREXIO_AUTO, rc) - if (f == 0_8) then - print *, 'Unable to open TREXIO file for reading' - print *, 'rc = ', rc - stop -1 - endif - - if (trexio_has_nucleus_repulsion(f) == TREXIO_SUCCESS) then rc = trexio_read_nucleus_repulsion(f, s) diff --git a/devel/trexio/qp_import_trexio.py b/devel/trexio/qp_import_trexio.py index 165fb9d..399ebac 100755 --- a/devel/trexio/qp_import_trexio.py +++ b/devel/trexio/qp_import_trexio.py @@ -72,22 +72,30 @@ def write_ezfio(trexio_filename, filename): print("Nuclei\t\t...\t", end=' ') - charge = trexio.read_nucleus_charge(trexio_file) - ezfio.set_nuclei_nucl_num(len(charge)) - ezfio.set_nuclei_nucl_charge(charge) + charge = [0.] + if trexio.has_nucleus(trexio_file): + charge = trexio.read_nucleus_charge(trexio_file) + ezfio.set_nuclei_nucl_num(len(charge)) + ezfio.set_nuclei_nucl_charge(charge) - coord = trexio.read_nucleus_coord(trexio_file) - coord = np.transpose(coord) - ezfio.set_nuclei_nucl_coord(coord) + coord = trexio.read_nucleus_coord(trexio_file) + coord = np.transpose(coord) + ezfio.set_nuclei_nucl_coord(coord) - label = trexio.read_nucleus_label(trexio_file) - nucl_num = trexio.read_nucleus_num(trexio_file) + label = trexio.read_nucleus_label(trexio_file) + nucl_num = trexio.read_nucleus_num(trexio_file) - # Transformt H1 into H - import re - p = re.compile(r'(\d*)$') - label = [p.sub("", x).capitalize() for x in label] - ezfio.set_nuclei_nucl_label(label) + # Transformt H1 into H + import re + p = re.compile(r'(\d*)$') + label = [p.sub("", x).capitalize() for x in label] + ezfio.set_nuclei_nucl_label(label) + + else: + ezfio.set_nuclei_nucl_num(1) + ezfio.set_nuclei_nucl_charge([0.]) + ezfio.set_nuclei_nucl_coord([0.,0.,0.]) + ezfio.set_nuclei_nucl_label(["X"]) print("OK") @@ -104,6 +112,9 @@ def write_ezfio(trexio_filename, filename): except: num_alpha = sum(charge) - num_beta + if num_alpha == 0: + print("\n\nError: There are zero electrons in the TREXIO file.\n\n") + sys.exit(1) ezfio.set_electrons_elec_alpha_num(num_alpha) ezfio.set_electrons_elec_beta_num(num_beta) @@ -111,10 +122,11 @@ def write_ezfio(trexio_filename, filename): print("Basis\t\t...\t", end=' ') + shell_num = 0 try: basis_type = trexio.read_basis_type(trexio_file) - - if basis_type.lower() != "gaussian": + + if basis_type.lower() not in ["gaussian", "slater"]: raise TypeError shell_num = trexio.read_basis_shell_num(trexio_file) @@ -173,72 +185,77 @@ def write_ezfio(trexio_filename, filename): print("AOS\t\t...\t", end=' ') - ao_shell = trexio.read_ao_shell(trexio_file) - cartesian = trexio.read_ao_cartesian(trexio_file) + try: + cartesian = trexio.read_ao_cartesian(trexio_file) + except: + cartesian = True + if not cartesian: raise TypeError('Only cartesian TREXIO files can be converted') ao_num = trexio.read_ao_num(trexio_file) ezfio.set_ao_basis_ao_num(ao_num) - at = [ nucl_index[i]+1 for i in ao_shell ] - ezfio.set_ao_basis_ao_nucl(at) + if shell_num > 0: + ao_shell = trexio.read_ao_shell(trexio_file) + at = [ nucl_index[i]+1 for i in ao_shell ] + ezfio.set_ao_basis_ao_nucl(at) - num_prim0 = [ 0 for i in range(shell_num) ] - for i in shell_index: - num_prim0[i] += 1 + num_prim0 = [ 0 for i in range(shell_num) ] + for i in shell_index: + num_prim0[i] += 1 - coef = {} - expo = {} - for i,c in enumerate(coefficient): - idx = shell_index[i] - if idx in coef: - coef[idx].append(c) - expo[idx].append(exponent[i]) - else: - coef[idx] = [c] - expo[idx] = [exponent[i]] + coef = {} + expo = {} + for i,c in enumerate(coefficient): + idx = shell_index[i] + if idx in coef: + coef[idx].append(c) + expo[idx].append(exponent[i]) + else: + coef[idx] = [c] + expo[idx] = [exponent[i]] - coefficient = [] - exponent = [] - power_x = [] - power_y = [] - power_z = [] - num_prim = [] + coefficient = [] + exponent = [] + power_x = [] + power_y = [] + power_z = [] + num_prim = [] - for i in range(shell_num): - for x,y,z in generate_xyz(ang_mom[i]): - power_x.append(x) - power_y.append(y) - power_z.append(z) - coefficient.append(coef[i]) - exponent.append(expo[i]) - num_prim.append(num_prim0[i]) + for i in range(shell_num): + for x,y,z in generate_xyz(ang_mom[i]): + power_x.append(x) + power_y.append(y) + power_z.append(z) + coefficient.append(coef[i]) + exponent.append(expo[i]) + num_prim.append(num_prim0[i]) - assert (len(coefficient) == ao_num) - ezfio.set_ao_basis_ao_power(power_x + power_y + power_z) - ezfio.set_ao_basis_ao_prim_num(num_prim) + assert (len(coefficient) == ao_num) + ezfio.set_ao_basis_ao_power(power_x + power_y + power_z) + ezfio.set_ao_basis_ao_prim_num(num_prim) - prim_num_max = max( [ len(x) for x in coefficient ] ) + prim_num_max = max( [ len(x) for x in coefficient ] ) - for i in range(ao_num): - coefficient[i] += [0. for j in range(len(coefficient[i]), prim_num_max)] - exponent [i] += [0. for j in range(len(exponent[i]), prim_num_max)] + for i in range(ao_num): + coefficient[i] += [0. for j in range(len(coefficient[i]), prim_num_max)] + exponent [i] += [0. for j in range(len(exponent[i]), prim_num_max)] - coefficient = reduce(lambda x, y: x + y, coefficient, []) - exponent = reduce(lambda x, y: x + y, exponent , []) + coefficient = reduce(lambda x, y: x + y, coefficient, []) + exponent = reduce(lambda x, y: x + y, exponent , []) - coef = [] - expo = [] - for i in range(prim_num_max): - for j in range(i, len(coefficient), prim_num_max): - coef.append(coefficient[j]) - expo.append(exponent[j]) + coef = [] + expo = [] + for i in range(prim_num_max): + for j in range(i, len(coefficient), prim_num_max): + coef.append(coefficient[j]) + expo.append(exponent[j]) -# ezfio.set_ao_basis_ao_prim_num_max(prim_num_max) - ezfio.set_ao_basis_ao_coef(coef) - ezfio.set_ao_basis_ao_expo(expo) - ezfio.set_ao_basis_ao_basis("Read from TREXIO") +# ezfio.set_ao_basis_ao_prim_num_max(prim_num_max) + ezfio.set_ao_basis_ao_coef(coef) + ezfio.set_ao_basis_ao_expo(expo) + ezfio.set_ao_basis_ao_basis("Read from TREXIO") print("OK") From ad2b6b97c6e45c93a016a057ef0cac3e63319a1e Mon Sep 17 00:00:00 2001 From: Anthony Scemama Date: Tue, 16 May 2023 15:43:23 +0200 Subject: [PATCH 16/16] Removed TREXIO plugin: introduced in QP. --- devel/trexio/EZFIO.cfg | 54 -- devel/trexio/NEED | 8 - devel/trexio/README.rst | 4 - devel/trexio/export_trexio.irp.f | 7 - devel/trexio/export_trexio_routines.irp.f | 601 ------------------ devel/trexio/import_trexio_determinants.irp.f | 79 --- devel/trexio/import_trexio_integrals.irp.f | 146 ----- devel/trexio/install | 23 - devel/trexio/qp_import_trexio.py | 414 ------------ devel/trexio/trexio_file.irp.f | 20 - devel/trexio/trexio_module.F90 | 1 - devel/trexio/uninstall | 20 - 12 files changed, 1377 deletions(-) delete mode 100644 devel/trexio/EZFIO.cfg delete mode 100644 devel/trexio/NEED delete mode 100644 devel/trexio/README.rst delete mode 100644 devel/trexio/export_trexio.irp.f delete mode 100644 devel/trexio/export_trexio_routines.irp.f delete mode 100644 devel/trexio/import_trexio_determinants.irp.f delete mode 100644 devel/trexio/import_trexio_integrals.irp.f delete mode 100755 devel/trexio/install delete mode 100755 devel/trexio/qp_import_trexio.py delete mode 100644 devel/trexio/trexio_file.irp.f delete mode 100644 devel/trexio/trexio_module.F90 delete mode 100755 devel/trexio/uninstall diff --git a/devel/trexio/EZFIO.cfg b/devel/trexio/EZFIO.cfg deleted file mode 100644 index 8606e90..0000000 --- a/devel/trexio/EZFIO.cfg +++ /dev/null @@ -1,54 +0,0 @@ -[backend] -type: integer -doc: Back-end used in TREXIO. 0: HDF5, 1:Text -interface: ezfio, ocaml, provider -default: 0 - -[trexio_file] -type: character*(256) -doc: Name of the exported TREXIO file -interface: ezfio, ocaml, provider -default: None - -[export_rdm] -type: logical -doc: If True, export two-body reduced density matrix -interface: ezfio, ocaml, provider -default: False - -[export_ao_one_e_ints] -type: logical -doc: If True, export one-electron integrals in AO basis -interface: ezfio, ocaml, provider -default: False - -[export_mo_one_e_ints] -type: logical -doc: If True, export one-electron integrals in MO basis -interface: ezfio, ocaml, provider -default: False - -[export_ao_two_e_ints] -type: logical -doc: If True, export two-electron integrals in AO basis -interface: ezfio, ocaml, provider -default: False - -[export_ao_two_e_ints_cholesky] -type: logical -doc: If True, export Cholesky-decomposed two-electron integrals in AO basis -interface: ezfio, ocaml, provider -default: False - -[export_mo_two_e_ints] -type: logical -doc: If True, export two-electron integrals in MO basis -interface: ezfio, ocaml, provider -default: False - -[export_mo_two_e_ints_cholesky] -type: logical -doc: If True, export Cholesky-decomposed two-electron integrals in MO basis -interface: ezfio, ocaml, provider -default: False - diff --git a/devel/trexio/NEED b/devel/trexio/NEED deleted file mode 100644 index 625463a..0000000 --- a/devel/trexio/NEED +++ /dev/null @@ -1,8 +0,0 @@ -ezfio_files -determinants -mo_one_e_ints -mo_two_e_ints -ao_two_e_ints -ao_one_e_ints -two_body_rdm -hartree_fock diff --git a/devel/trexio/README.rst b/devel/trexio/README.rst deleted file mode 100644 index 5f1ba3b..0000000 --- a/devel/trexio/README.rst +++ /dev/null @@ -1,4 +0,0 @@ -====== -trexio -====== - diff --git a/devel/trexio/export_trexio.irp.f b/devel/trexio/export_trexio.irp.f deleted file mode 100644 index 3ae0dcb..0000000 --- a/devel/trexio/export_trexio.irp.f +++ /dev/null @@ -1,7 +0,0 @@ -program export_trexio_prog - implicit none - read_wf = .True. - SOFT_TOUCH read_wf - call export_trexio -end - diff --git a/devel/trexio/export_trexio_routines.irp.f b/devel/trexio/export_trexio_routines.irp.f deleted file mode 100644 index 8635eb7..0000000 --- a/devel/trexio/export_trexio_routines.irp.f +++ /dev/null @@ -1,601 +0,0 @@ -subroutine export_trexio - use trexio - implicit none - BEGIN_DOC - ! Exports the wave function in TREXIO format - END_DOC - - integer(trexio_t) :: f ! TREXIO file handle - integer(trexio_exit_code) :: rc - double precision, allocatable :: factor(:) - - print *, 'TREXIO file : '//trim(trexio_filename) - print *, '' - - call system('cp '//trim(trexio_filename)//' '//trim(trexio_filename)//'.bak') - if (backend == 0) then - f = trexio_open(trexio_filename, 'u', TREXIO_HDF5, rc) - else if (backend == 1) then - f = trexio_open(trexio_filename, 'u', TREXIO_TEXT, rc) - endif - if (f == 0_8) then - print *, 'Unable to open TREXIO file for writing' - print *, 'rc = ', rc - stop -1 - endif - call ezfio_set_trexio_trexio_file(trexio_filename) - -! ------------------------------------------------------------------------------ - -! Electrons -! --------- - - print *, 'Electrons' - - rc = trexio_write_electron_up_num(f, elec_alpha_num) - call trexio_assert(rc, TREXIO_SUCCESS) - - rc = trexio_write_electron_dn_num(f, elec_beta_num) - call trexio_assert(rc, TREXIO_SUCCESS) - - -! Nuclei -! ------ - - print *, 'Nuclei' - - rc = trexio_write_nucleus_num(f, nucl_num) - call trexio_assert(rc, TREXIO_SUCCESS) - - rc = trexio_write_nucleus_charge(f, nucl_charge) - call trexio_assert(rc, TREXIO_SUCCESS) - - rc = trexio_write_nucleus_coord(f, nucl_coord_transp) - call trexio_assert(rc, TREXIO_SUCCESS) - - rc = trexio_write_nucleus_label(f, nucl_label, 32) - call trexio_assert(rc, TREXIO_SUCCESS) - - rc = trexio_write_nucleus_repulsion(f, nuclear_repulsion) - call trexio_assert(rc, TREXIO_SUCCESS) - - -! Pseudo-potentials -! ----------------- - - if (do_pseudo) then - - print *, 'ECP' - integer :: num - - num = 0 - do k=1,pseudo_klocmax - do i=1,nucl_num - if (pseudo_dz_k(i,k) /= 0.d0) then - num = num+1 - end if - end do - end do - - do l=0,pseudo_lmax - do k=1,pseudo_kmax - do i=1,nucl_num - if (pseudo_dz_kl(i,k,l) /= 0.d0) then - num = num+1 - end if - end do - end do - end do - - integer, allocatable :: ang_mom(:), nucleus_index(:), power(:), lmax(:) - double precision, allocatable :: exponent(:), coefficient(:) - - allocate(ang_mom(num), nucleus_index(num), exponent(num), coefficient(num), power(num), & - lmax(nucl_num) ) - - do i=1,nucl_num - lmax(i) = -1 - do l=0,pseudo_lmax - do k=1,pseudo_kmax - if (pseudo_dz_kl_transp(k,l,i) /= 0.d0) then - lmax(i) = max(lmax(i), l) - end if - end do - end do - end do - - j = 0 - do i=1,nucl_num - do k=1,pseudo_klocmax - if (pseudo_dz_k_transp(k,i) /= 0.d0) then - j = j+1 - ang_mom(j) = lmax(i)+1 - nucleus_index(j) = i - exponent(j) = pseudo_dz_k_transp(k,i) - coefficient(j) = pseudo_v_k_transp(k,i) - power(j) = pseudo_n_k_transp(k,i) - end if - end do - - do l=0,lmax(i) - do k=1,pseudo_kmax - if (pseudo_dz_kl_transp(k,l,i) /= 0.d0) then - j = j+1 - ang_mom(j) = l - nucleus_index(j) = i - exponent(j) = pseudo_dz_kl_transp(k,l,i) - coefficient(j) = pseudo_v_kl_transp(k,l,i) - power(j) = pseudo_n_kl_transp(k,l,i) - end if - end do - end do - end do - - - lmax(:) = lmax(:)+1 - rc = trexio_write_ecp_max_ang_mom_plus_1(f, lmax) - call trexio_assert(rc, TREXIO_SUCCESS) - - rc = trexio_write_ecp_z_core(f, int(nucl_charge_remove)) - call trexio_assert(rc, TREXIO_SUCCESS) - - rc = trexio_write_ecp_num(f, num) - call trexio_assert(rc, TREXIO_SUCCESS) - - rc = trexio_write_ecp_ang_mom(f, ang_mom) - call trexio_assert(rc, TREXIO_SUCCESS) - - rc = trexio_write_ecp_nucleus_index(f, nucleus_index) - call trexio_assert(rc, TREXIO_SUCCESS) - - rc = trexio_write_ecp_exponent(f, exponent) - call trexio_assert(rc, TREXIO_SUCCESS) - - rc = trexio_write_ecp_coefficient(f, coefficient) - call trexio_assert(rc, TREXIO_SUCCESS) - - rc = trexio_write_ecp_power(f, power) - call trexio_assert(rc, TREXIO_SUCCESS) - - endif - - -! Basis -! ----- - - print *, 'Basis' - - - rc = trexio_write_basis_type(f, 'Gaussian', len('Gaussian')) - call trexio_assert(rc, TREXIO_SUCCESS) - - rc = trexio_write_basis_prim_num(f, prim_num) - call trexio_assert(rc, TREXIO_SUCCESS) - - rc = trexio_write_basis_shell_num(f, shell_num) - call trexio_assert(rc, TREXIO_SUCCESS) - - rc = trexio_write_basis_nucleus_index(f, basis_nucleus_index) - call trexio_assert(rc, TREXIO_SUCCESS) - - rc = trexio_write_basis_shell_ang_mom(f, shell_ang_mom) - call trexio_assert(rc, TREXIO_SUCCESS) - - allocate(factor(shell_num)) - if (ao_normalized) then - factor(1:shell_num) = shell_normalization_factor(1:shell_num) - else - factor(1:shell_num) = 1.d0 - endif - rc = trexio_write_basis_shell_factor(f, factor) - call trexio_assert(rc, TREXIO_SUCCESS) - - deallocate(factor) - - rc = trexio_write_basis_shell_index(f, shell_index) - call trexio_assert(rc, TREXIO_SUCCESS) - - rc = trexio_write_basis_exponent(f, prim_expo) - call trexio_assert(rc, TREXIO_SUCCESS) - - rc = trexio_write_basis_coefficient(f, prim_coef) - call trexio_assert(rc, TREXIO_SUCCESS) - - allocate(factor(prim_num)) - if (primitives_normalized) then - factor(1:prim_num) = prim_normalization_factor(1:prim_num) - else - factor(1:prim_num) = 1.d0 - endif - rc = trexio_write_basis_prim_factor(f, factor) - call trexio_assert(rc, TREXIO_SUCCESS) - deallocate(factor) - - -! Atomic orbitals -! --------------- - - print *, 'AOs' - - rc = trexio_write_ao_num(f, ao_num) - call trexio_assert(rc, TREXIO_SUCCESS) - - rc = trexio_write_ao_cartesian(f, 1) - call trexio_assert(rc, TREXIO_SUCCESS) - - rc = trexio_write_ao_shell(f, ao_shell) - call trexio_assert(rc, TREXIO_SUCCESS) - - integer :: i, pow0(3), powA(3), j, k, l, nz - double precision :: normA, norm0, C_A(3), overlap_x, overlap_z, overlap_y, c - nz=100 - - C_A(1) = 0.d0 - C_A(2) = 0.d0 - C_A(3) = 0.d0 - - allocate(factor(ao_num)) - if (ao_normalized) then - do i=1,ao_num - l = ao_first_of_shell(ao_shell(i)) - factor(i) = (ao_coef_normalized(i,1)+tiny(1.d0))/(ao_coef_normalized(l,1)+tiny(1.d0)) - enddo - else - factor(:) = 1.d0 - endif - rc = trexio_write_ao_normalization(f, factor) - call trexio_assert(rc, TREXIO_SUCCESS) - deallocate(factor) - -! One-e AO integrals -! ------------------ - - if (export_ao_one_e_ints) then - print *, 'AO one-e integrals' - - rc = trexio_write_ao_1e_int_overlap(f,ao_overlap) - call trexio_assert(rc, TREXIO_SUCCESS) - - rc = trexio_write_ao_1e_int_kinetic(f,ao_kinetic_integrals) - call trexio_assert(rc, TREXIO_SUCCESS) - - rc = trexio_write_ao_1e_int_potential_n_e(f,ao_integrals_n_e) - call trexio_assert(rc, TREXIO_SUCCESS) - - if (do_pseudo) then - rc = trexio_write_ao_1e_int_ecp(f, ao_pseudo_integrals_local + ao_pseudo_integrals_non_local) - call trexio_assert(rc, TREXIO_SUCCESS) - endif - - rc = trexio_write_ao_1e_int_core_hamiltonian(f,ao_one_e_integrals) - call trexio_assert(rc, TREXIO_SUCCESS) - end if - -! Two-e AO integrals -! ------------------ - - if (export_ao_two_e_ints) then - print *, 'AO two-e integrals' - PROVIDE ao_two_e_integrals_in_map - - integer(8), parameter :: BUFSIZE=10000_8 - double precision :: eri_buffer(BUFSIZE), integral - integer(4) :: eri_index(4,BUFSIZE) - integer(8) :: icount, offset - - double precision, external :: get_ao_two_e_integral - - - icount = 0_8 - offset = 0_8 - do l=1,ao_num - do k=1,ao_num - do j=l,ao_num - do i=k,ao_num - if (i==j .and. k= 0_8) then - rc = trexio_write_ao_2e_int_eri(f, offset, icount, eri_index, eri_buffer) - call trexio_assert(rc, TREXIO_SUCCESS) - end if - end if - -! Two-e AO integrals - Cholesky -! ----------------------------- - - integer(4) :: chol_index(3,BUFSIZE) - double precision :: chol_buffer(BUFSIZE) - - if (export_ao_two_e_ints_cholesky) then - print *, 'AO two-e integrals Cholesky' - - rc = trexio_write_ao_2e_int_eri_cholesky_num(f, cholesky_ao_num) - call trexio_assert(rc, TREXIO_SUCCESS) - - icount = 0_8 - offset = 0_8 - do k=1,cholesky_ao_num - do j=1,ao_num - do i=1,ao_num - integral = cholesky_ao(i,j,k) - if (integral == 0.d0) cycle - icount += 1_8 - chol_buffer(icount) = integral - chol_index(1,icount) = i - chol_index(2,icount) = j - chol_index(3,icount) = k - if (icount == BUFSIZE) then - rc = trexio_write_ao_2e_int_eri_cholesky(f, offset, icount, chol_index, chol_buffer) - call trexio_assert(rc, TREXIO_SUCCESS) - offset += icount - icount = 0_8 - end if - end do - end do - end do - - if (icount > 0_8) then - rc = trexio_write_ao_2e_int_eri_cholesky(f, offset, icount, chol_index, chol_buffer) - call trexio_assert(rc, TREXIO_SUCCESS) - end if - end if - - - -! Molecular orbitals -! ------------------ - - print *, 'MOs' - - rc = trexio_write_mo_type(f, mo_label, len(trim(mo_label))) - call trexio_assert(rc, TREXIO_SUCCESS) - - rc = trexio_write_mo_num(f, mo_num) - call trexio_assert(rc, TREXIO_SUCCESS) - - rc = trexio_write_mo_coefficient(f, mo_coef) - call trexio_assert(rc, TREXIO_SUCCESS) - -! if (trim(mo_label) == 'Canonical') then -! rc = trexio_write_mo_energy(f, fock_matrix_diag_mo) -! call trexio_assert(rc, TREXIO_SUCCESS) -! endif - - -! One-e MO integrals -! ------------------ - - if (export_mo_one_e_ints) then - print *, 'MO one-e integrals' - - rc = trexio_write_mo_1e_int_kinetic(f,mo_kinetic_integrals) - call trexio_assert(rc, TREXIO_SUCCESS) - - rc = trexio_write_mo_1e_int_potential_n_e(f,mo_integrals_n_e) - call trexio_assert(rc, TREXIO_SUCCESS) - - if (do_pseudo) then - rc = trexio_write_mo_1e_int_ecp(f,mo_pseudo_integrals_local) - call trexio_assert(rc, TREXIO_SUCCESS) - endif - - rc = trexio_write_mo_1e_int_core_hamiltonian(f,mo_one_e_integrals) - call trexio_assert(rc, TREXIO_SUCCESS) - end if - -! Two-e MO integrals -! ------------------ - - if (export_mo_two_e_ints) then - print *, 'MO two-e integrals' - PROVIDE mo_two_e_integrals_in_map - - double precision, external :: mo_two_e_integral - - - icount = 0_8 - offset = 0_8 - do l=1,mo_num - do k=1,mo_num - do j=l,mo_num - do i=k,mo_num - if (i==j .and. k 0_8) then - rc = trexio_write_mo_2e_int_eri(f, offset, icount, eri_index, eri_buffer) - call trexio_assert(rc, TREXIO_SUCCESS) - end if - end if - -! Two-e MO integrals - Cholesky -! ----------------------------- - - if (export_mo_two_e_ints_cholesky) then - print *, 'MO two-e integrals Cholesky' - - rc = trexio_write_mo_2e_int_eri_cholesky_num(f, cholesky_ao_num) - call trexio_assert(rc, TREXIO_SUCCESS) - - icount = 0_8 - offset = 0_8 - do k=1,cholesky_ao_num - do j=1,mo_num - do i=1,mo_num - integral = cholesky_mo(i,j,k) - if (integral == 0.d0) cycle - icount += 1_8 - chol_buffer(icount) = integral - chol_index(1,icount) = i - chol_index(2,icount) = j - chol_index(3,icount) = k - if (icount == BUFSIZE) then - rc = trexio_write_mo_2e_int_eri_cholesky(f, offset, icount, chol_index, chol_buffer) - call trexio_assert(rc, TREXIO_SUCCESS) - offset += icount - icount = 0_8 - end if - end do - end do - end do - - if (icount > 0_8) then - rc = trexio_write_mo_2e_int_eri_cholesky(f, offset, icount, chol_index, chol_buffer) - call trexio_assert(rc, TREXIO_SUCCESS) - end if - end if - - -! One-e RDM -! --------- - - rc = trexio_write_rdm_1e(f,one_e_dm_mo) - call trexio_assert(rc, TREXIO_SUCCESS) - - rc = trexio_write_rdm_1e_up(f,one_e_dm_mo_alpha_average) - call trexio_assert(rc, TREXIO_SUCCESS) - - rc = trexio_write_rdm_1e_dn(f,one_e_dm_mo_beta_average) - call trexio_assert(rc, TREXIO_SUCCESS) - - -! Two-e RDM -! --------- - - if (export_rdm) then - PROVIDE two_e_dm_mo - print *, 'Two-e RDM' - - icount = 0_8 - offset = 0_8 - do l=1,mo_num - do k=1,mo_num - do j=1,mo_num - do i=1,mo_num - integral = two_e_dm_mo(i,j,k,l) - if (integral == 0.d0) cycle - icount += 1_8 - eri_buffer(icount) = integral - eri_index(1,icount) = i - eri_index(2,icount) = j - eri_index(3,icount) = k - eri_index(4,icount) = l - if (icount == BUFSIZE) then - rc = trexio_write_rdm_2e(f, offset, icount, eri_index, eri_buffer) - call trexio_assert(rc, TREXIO_SUCCESS) - offset += icount - icount = 0_8 - end if - end do - end do - end do - end do - - if (icount >= 0_8) then - rc = trexio_write_rdm_2e(f, offset, icount, eri_index, eri_buffer) - call trexio_assert(rc, TREXIO_SUCCESS) - end if - end if - - -! ------------------------------------------------------------------------------ - - ! Determinants - ! ------------ - - integer*8, allocatable :: det_buffer(:,:,:) - double precision, allocatable :: coef_buffer(:,:) - integer :: nint - -! rc = trexio_read_determinant_int64_num(f, nint) -! call trexio_assert(rc, TREXIO_SUCCESS) - nint = N_int - if (nint /= N_int) then - stop 'Problem with N_int' - endif - allocate ( det_buffer(nint, 2, BUFSIZE), coef_buffer(BUFSIZE, n_states) ) - - icount = 0_8 - offset = 0_8 - rc = trexio_write_state_num(f, n_states) - call trexio_assert(rc, TREXIO_SUCCESS) - - rc = trexio_set_state (f, 0) - call trexio_assert(rc, TREXIO_SUCCESS) - do k=1,n_det - icount += 1_8 - det_buffer(1:nint, 1:2, icount) = psi_det(1:N_int, 1:2, k) - coef_buffer(icount,1:N_states) = psi_coef(k,1:N_states) - if (icount == BUFSIZE) then - call trexio_assert(rc, TREXIO_SUCCESS) - rc = trexio_write_determinant_list(f, offset, icount, det_buffer) - call trexio_assert(rc, TREXIO_SUCCESS) - do i=1,N_states - rc = trexio_set_state (f, i-1) - call trexio_assert(rc, TREXIO_SUCCESS) - rc = trexio_write_determinant_coefficient(f, offset, icount, coef_buffer(1,i)) - end do - rc = trexio_set_state (f, 0) - offset += icount - icount = 0_8 - end if - end do - - if (icount >= 0_8) then - call trexio_assert(rc, TREXIO_SUCCESS) - rc = trexio_write_determinant_list(f, offset, icount, det_buffer) - call trexio_assert(rc, TREXIO_SUCCESS) - do i=1,N_states - rc = trexio_set_state (f, i-1) - call trexio_assert(rc, TREXIO_SUCCESS) - rc = trexio_write_determinant_coefficient(f, offset, icount, coef_buffer(1,i)) - end do - rc = trexio_set_state (f, 0) - end if - - deallocate ( det_buffer, coef_buffer ) - - rc = trexio_close(f) - call trexio_assert(rc, TREXIO_SUCCESS) - -end - - -! -*- mode: f90 -*- diff --git a/devel/trexio/import_trexio_determinants.irp.f b/devel/trexio/import_trexio_determinants.irp.f deleted file mode 100644 index 1759bb9..0000000 --- a/devel/trexio/import_trexio_determinants.irp.f +++ /dev/null @@ -1,79 +0,0 @@ -program import_determinants_ao - call run -end - -subroutine run - use trexio - use map_module - implicit none - BEGIN_DOC -! Program to import determinants from TREXIO - END_DOC - - integer(trexio_t) :: f ! TREXIO file handle - integer(trexio_exit_code) :: rc - - integer :: m - - double precision, allocatable :: coef_buffer(:,:) - integer*8 , allocatable :: det_buffer(:,:,:) - - f = trexio_open(trexio_filename, 'r', TREXIO_AUTO, rc) - if (f == 0_8) then - print *, 'Unable to open TREXIO file for reading' - print *, 'rc = ', rc - stop -1 - endif - - - - ! Determinants - ! ------------ - - integer :: nint, nstates - integer :: bufsize - - rc = trexio_read_state_num(f, nstates) - call trexio_assert(rc, TREXIO_SUCCESS) - -! rc = trexio_read_determinant_int64_num(f, nint) -! call trexio_assert(rc, TREXIO_SUCCESS) - nint = N_int - if (nint /= N_int) then - stop 'Problem with N_int' - endif - - integer*8 :: offset, icount - - rc = trexio_read_determinant_num(f, bufsize) - call trexio_assert(rc, TREXIO_SUCCESS) - print *, 'N_det = ', bufsize - - allocate ( det_buffer(nint, 2, bufsize), coef_buffer(bufsize, n_states) ) - - - offset = 0_8 - icount = bufsize - - rc = trexio_read_determinant_list(f, offset, icount, det_buffer) - call trexio_assert(rc, TREXIO_SUCCESS) - if (icount /= bufsize) then - print *, 'error: bufsize /= N_det: ', bufsize, icount - stop -1 - endif - - do m=1,nstates - rc = trexio_set_state(f, m-1) - call trexio_assert(rc, TREXIO_SUCCESS) - rc = trexio_read_determinant_coefficient(f, offset, icount, coef_buffer(1,m)) - call trexio_assert(rc, TREXIO_SUCCESS) - if (icount /= bufsize) then - print *, 'error: bufsize /= N_det for state', m, ':', icount, bufsize - stop -1 - endif - enddo - - call save_wavefunction_general(bufsize,nstates,det_buffer,size(coef_buffer,1),coef_buffer) - - -end diff --git a/devel/trexio/import_trexio_integrals.irp.f b/devel/trexio/import_trexio_integrals.irp.f deleted file mode 100644 index 9f9ad9d..0000000 --- a/devel/trexio/import_trexio_integrals.irp.f +++ /dev/null @@ -1,146 +0,0 @@ -program import_integrals_ao - use trexio - implicit none - integer(trexio_t) :: f ! TREXIO file handle - integer(trexio_exit_code) :: rc - - f = trexio_open(trexio_filename, 'r', TREXIO_AUTO, rc) - if (f == 0_8) then - print *, 'Unable to open TREXIO file for reading' - print *, 'rc = ', rc - stop -1 - endif - - call run(f) - rc = trexio_close(f) - call trexio_assert(rc, TREXIO_SUCCESS) -end - -subroutine run(f) - use trexio - use map_module - implicit none - BEGIN_DOC -! Program to import integrals from TREXIO - END_DOC - - integer(trexio_t), intent(in) :: f ! TREXIO file handle - integer(trexio_exit_code) :: rc - - integer ::i,j,k,l - integer(8) :: m, n_integrals - double precision :: integral - - integer(key_kind), allocatable :: buffer_i(:) - real(integral_kind), allocatable :: buffer_values(:) - - - double precision, allocatable :: A(:,:) - double precision, allocatable :: V(:) - integer , allocatable :: Vi(:,:) - double precision :: s - - if (trexio_has_nucleus_repulsion(f) == TREXIO_SUCCESS) then - rc = trexio_read_nucleus_repulsion(f, s) - call trexio_assert(rc, TREXIO_SUCCESS) - if (rc /= TREXIO_SUCCESS) then - print *, irp_here, rc - print *, 'Error reading nuclear repulsion' - stop -1 - endif - call ezfio_set_nuclei_nuclear_repulsion(s) - call ezfio_set_nuclei_io_nuclear_repulsion('Read') - endif - - ! AO integrals - ! ------------ - - allocate(A(ao_num, ao_num)) - - - if (trexio_has_ao_1e_int_overlap(f) == TREXIO_SUCCESS) then - rc = trexio_read_ao_1e_int_overlap(f, A) - if (rc /= TREXIO_SUCCESS) then - print *, irp_here - print *, 'Error reading AO overlap' - stop -1 - endif - call ezfio_set_ao_one_e_ints_ao_integrals_overlap(A) - call ezfio_set_ao_one_e_ints_io_ao_integrals_overlap('Read') - endif - - if (trexio_has_ao_1e_int_kinetic(f) == TREXIO_SUCCESS) then - rc = trexio_read_ao_1e_int_kinetic(f, A) - if (rc /= TREXIO_SUCCESS) then - print *, irp_here - print *, 'Error reading AO kinetic integrals' - stop -1 - endif - call ezfio_set_ao_one_e_ints_ao_integrals_kinetic(A) - call ezfio_set_ao_one_e_ints_io_ao_integrals_kinetic('Read') - endif - -! if (trexio_has_ao_1e_int_ecp(f) == TREXIO_SUCCESS) then -! rc = trexio_read_ao_1e_int_ecp(f, A) -! if (rc /= TREXIO_SUCCESS) then -! print *, irp_here -! print *, 'Error reading AO ECP local integrals' -! stop -1 -! endif -! call ezfio_set_ao_one_e_ints_ao_integrals_pseudo(A) -! call ezfio_set_ao_one_e_ints_io_ao_integrals_pseudo('Read') -! endif - - if (trexio_has_ao_1e_int_potential_n_e(f) == TREXIO_SUCCESS) then - rc = trexio_read_ao_1e_int_potential_n_e(f, A) - if (rc /= TREXIO_SUCCESS) then - print *, irp_here - print *, 'Error reading AO potential N-e integrals' - stop -1 - endif - call ezfio_set_ao_one_e_ints_ao_integrals_n_e(A) - call ezfio_set_ao_one_e_ints_io_ao_integrals_n_e('Read') - endif - - deallocate(A) - - ! AO 2e integrals - ! --------------- - PROVIDE ao_integrals_map - - integer*4 :: BUFSIZE - BUFSIZE=ao_num**2 - allocate(buffer_i(BUFSIZE), buffer_values(BUFSIZE)) - allocate(Vi(4,BUFSIZE), V(BUFSIZE)) - - integer*8 :: offset, icount - - offset = 0_8 - icount = BUFSIZE - rc = TREXIO_SUCCESS - do while (icount == size(V)) - rc = trexio_read_ao_2e_int_eri(f, offset, icount, Vi, V) - do m=1,icount - i = Vi(1,m) - j = Vi(2,m) - k = Vi(3,m) - l = Vi(4,m) - integral = V(m) - call two_e_integrals_index(i, j, k, l, buffer_i(m) ) - buffer_values(m) = integral - enddo - call insert_into_ao_integrals_map(int(icount,4),buffer_i,buffer_values) - offset = offset + icount - if (rc /= TREXIO_SUCCESS) then - exit - endif - end do - n_integrals = offset - - call map_sort(ao_integrals_map) - call map_unique(ao_integrals_map) - - call map_save_to_disk(trim(ezfio_filename)//'/work/ao_ints',ao_integrals_map) - call ezfio_set_ao_two_e_ints_io_ao_two_e_integrals('Read') - -end diff --git a/devel/trexio/install b/devel/trexio/install deleted file mode 100755 index 4f967c9..0000000 --- a/devel/trexio/install +++ /dev/null @@ -1,23 +0,0 @@ -#!/bin/bash - -# Check if the QP_ROOT environment variable is set. -if [[ -z ${QP_ROOT} ]] -then - print "The QP_ROOT environment variable is not set." - print "Please reload the quantum_package.rc file." - exit -1 -fi - -pkg-config --libs trexio > LIB - -scripts_list="qp_import_trexio.py" - -# Destroy ONLY the symbolic link for the scripts to be used in the -# ${QP_ROOT}/scripts/ directory. -for i in $scripts_list -do - find ${QP_ROOT}/scripts/$i -type l -delete 2> /dev/null -done - -# Create symlink in scripts -ln --symbolic ${PWD}/qp_import_trexio.py $QP_ROOT/scripts diff --git a/devel/trexio/qp_import_trexio.py b/devel/trexio/qp_import_trexio.py deleted file mode 100755 index 399ebac..0000000 --- a/devel/trexio/qp_import_trexio.py +++ /dev/null @@ -1,414 +0,0 @@ -#!/usr/bin/env python3 -""" -convert TREXIO file to EZFIO - -Usage: - qp_import_trexio [-o EZFIO_DIR] FILE - -Options: - -o --output=EZFIO_DIR Produced directory - by default is FILE.ezfio - -""" - -import sys -import os -import trexio -import numpy as np -from functools import reduce -from ezfio import ezfio -from docopt import docopt - - -try: - QP_ROOT = os.environ["QP_ROOT"] - QP_EZFIO = os.environ["QP_EZFIO"] -except KeyError: - print("Error: QP_ROOT environment variable not found.") - sys.exit(1) -else: - sys.path = [QP_EZFIO + "/Python", - QP_ROOT + "/install/resultsFile", - QP_ROOT + "/install", - QP_ROOT + "/scripts"] + sys.path - - -def generate_xyz(l): - - def create_z(x,y,z): - return (x, y, l-(x+y)) - - def create_y(accu,x,y,z): - if y == 0: - result = [create_z(x,y,z)] + accu - else: - result = create_y([create_z(x,y,z)] + accu , x, y-1, z) - return result - - def create_x(accu,x,y,z): - if x == 0: - result = create_y([], x,y,z) + accu - else: - xnew = x-1 - ynew = l-xnew - result = create_x(create_y([],x,y,z) + accu , xnew, ynew, z) - return result - - result = create_x([], l, 0, 0) - result.reverse() - return result - - - -def write_ezfio(trexio_filename, filename): - - try: - trexio_file = trexio.File(trexio_filename,mode='r',back_end=trexio.TREXIO_TEXT) - except: - trexio_file = trexio.File(trexio_filename,mode='r',back_end=trexio.TREXIO_HDF5) - - ezfio.set_file(filename) - ezfio.set_trexio_trexio_file(trexio_filename) - - print("Nuclei\t\t...\t", end=' ') - - charge = [0.] - if trexio.has_nucleus(trexio_file): - charge = trexio.read_nucleus_charge(trexio_file) - ezfio.set_nuclei_nucl_num(len(charge)) - ezfio.set_nuclei_nucl_charge(charge) - - coord = trexio.read_nucleus_coord(trexio_file) - coord = np.transpose(coord) - ezfio.set_nuclei_nucl_coord(coord) - - label = trexio.read_nucleus_label(trexio_file) - nucl_num = trexio.read_nucleus_num(trexio_file) - - # Transformt H1 into H - import re - p = re.compile(r'(\d*)$') - label = [p.sub("", x).capitalize() for x in label] - ezfio.set_nuclei_nucl_label(label) - - else: - ezfio.set_nuclei_nucl_num(1) - ezfio.set_nuclei_nucl_charge([0.]) - ezfio.set_nuclei_nucl_coord([0.,0.,0.]) - ezfio.set_nuclei_nucl_label(["X"]) - - print("OK") - - - print("Electrons\t...\t", end=' ') - - try: - num_beta = trexio.read_electron_dn_num(trexio_file) - except: - num_beta = sum(charge)//2 - - try: - num_alpha = trexio.read_electron_up_num(trexio_file) - except: - num_alpha = sum(charge) - num_beta - - if num_alpha == 0: - print("\n\nError: There are zero electrons in the TREXIO file.\n\n") - sys.exit(1) - ezfio.set_electrons_elec_alpha_num(num_alpha) - ezfio.set_electrons_elec_beta_num(num_beta) - - print("OK") - - print("Basis\t\t...\t", end=' ') - - shell_num = 0 - try: - basis_type = trexio.read_basis_type(trexio_file) - - if basis_type.lower() not in ["gaussian", "slater"]: - raise TypeError - - shell_num = trexio.read_basis_shell_num(trexio_file) - prim_num = trexio.read_basis_prim_num(trexio_file) - ang_mom = trexio.read_basis_shell_ang_mom(trexio_file) - nucl_index = trexio.read_basis_nucleus_index(trexio_file) - exponent = trexio.read_basis_exponent(trexio_file) - coefficient = trexio.read_basis_coefficient(trexio_file) - shell_index = trexio.read_basis_shell_index(trexio_file) - ao_shell = trexio.read_ao_shell(trexio_file) - - ezfio.set_basis_basis("Read from TREXIO") - ezfio.set_basis_shell_num(shell_num) - ezfio.set_basis_prim_num(prim_num) - ezfio.set_basis_shell_ang_mom(ang_mom) - ezfio.set_basis_basis_nucleus_index([ x+1 for x in nucl_index ]) - ezfio.set_basis_prim_expo(exponent) - ezfio.set_basis_prim_coef(coefficient) - - nucl_shell_num = [] - prev = None - m = 0 - for i in ao_shell: - if i != prev: - m += 1 - if prev is None or nucl_index[i] != nucl_index[prev]: - nucl_shell_num.append(m) - m = 0 - prev = i - assert (len(nucl_shell_num) == nucl_num) - - shell_prim_num = [] - prev = shell_index[0] - count = 0 - for i in shell_index: - if i != prev: - shell_prim_num.append(count) - count = 0 - count += 1 - prev = i - shell_prim_num.append(count) - - assert (len(shell_prim_num) == shell_num) - - ezfio.set_basis_shell_prim_num(shell_prim_num) - ezfio.set_basis_shell_index([x+1 for x in shell_index]) - ezfio.set_basis_nucleus_shell_num(nucl_shell_num) - - - shell_factor = trexio.read_basis_shell_factor(trexio_file) - prim_factor = trexio.read_basis_prim_factor(trexio_file) - - print("OK") - except: - print("None") - - print("AOS\t\t...\t", end=' ') - - try: - cartesian = trexio.read_ao_cartesian(trexio_file) - except: - cartesian = True - - if not cartesian: - raise TypeError('Only cartesian TREXIO files can be converted') - - ao_num = trexio.read_ao_num(trexio_file) - ezfio.set_ao_basis_ao_num(ao_num) - - if shell_num > 0: - ao_shell = trexio.read_ao_shell(trexio_file) - at = [ nucl_index[i]+1 for i in ao_shell ] - ezfio.set_ao_basis_ao_nucl(at) - - num_prim0 = [ 0 for i in range(shell_num) ] - for i in shell_index: - num_prim0[i] += 1 - - coef = {} - expo = {} - for i,c in enumerate(coefficient): - idx = shell_index[i] - if idx in coef: - coef[idx].append(c) - expo[idx].append(exponent[i]) - else: - coef[idx] = [c] - expo[idx] = [exponent[i]] - - coefficient = [] - exponent = [] - power_x = [] - power_y = [] - power_z = [] - num_prim = [] - - for i in range(shell_num): - for x,y,z in generate_xyz(ang_mom[i]): - power_x.append(x) - power_y.append(y) - power_z.append(z) - coefficient.append(coef[i]) - exponent.append(expo[i]) - num_prim.append(num_prim0[i]) - - assert (len(coefficient) == ao_num) - ezfio.set_ao_basis_ao_power(power_x + power_y + power_z) - ezfio.set_ao_basis_ao_prim_num(num_prim) - - prim_num_max = max( [ len(x) for x in coefficient ] ) - - for i in range(ao_num): - coefficient[i] += [0. for j in range(len(coefficient[i]), prim_num_max)] - exponent [i] += [0. for j in range(len(exponent[i]), prim_num_max)] - - coefficient = reduce(lambda x, y: x + y, coefficient, []) - exponent = reduce(lambda x, y: x + y, exponent , []) - - coef = [] - expo = [] - for i in range(prim_num_max): - for j in range(i, len(coefficient), prim_num_max): - coef.append(coefficient[j]) - expo.append(exponent[j]) - -# ezfio.set_ao_basis_ao_prim_num_max(prim_num_max) - ezfio.set_ao_basis_ao_coef(coef) - ezfio.set_ao_basis_ao_expo(expo) - ezfio.set_ao_basis_ao_basis("Read from TREXIO") - - print("OK") - - - # _ - # |\/| _ _ |_) _. _ o _ - # | | (_) _> |_) (_| _> | _> - # - - print("MOS\t\t...\t", end=' ') - - labels = { "Canonical" : "Canonical", - "RHF" : "Canonical", - "BOYS" : "Localized", - "ROHF" : "Canonical", - "UHF" : "Canonical", - "Natural": "Natural" } - try: - label = labels[trexio.read_mo_type(trexio_file)] - except: - label = "None" - ezfio.set_mo_basis_mo_label(label) - - try: - clss = trexio.read_mo_class(trexio_file) - core = [ i for i in clss if i.lower() == "core" ] - inactive = [ i for i in clss if i.lower() == "inactive" ] - active = [ i for i in clss if i.lower() == "active" ] - virtual = [ i for i in clss if i.lower() == "virtual" ] - deleted = [ i for i in clss if i.lower() == "deleted" ] - except trexio.Error: - pass - - try: - mo_num = trexio.read_mo_num(trexio_file) - ezfio.set_mo_basis_mo_num(mo_num) - - MoMatrix = trexio.read_mo_coefficient(trexio_file) - ezfio.set_mo_basis_mo_coef(MoMatrix) - - mo_occ = [ 0. for i in range(mo_num) ] - for i in range(num_alpha): - mo_occ[i] += 1. - for i in range(num_beta): - mo_occ[i] += 1. - ezfio.set_mo_basis_mo_occ(mo_occ) - except: - pass - - print("OK") - - - print("Pseudos\t\t...\t", end=' ') - - ezfio.set_pseudo_do_pseudo(False) - - if trexio.has_ecp_ang_mom(trexio_file): - ezfio.set_pseudo_do_pseudo(True) - max_ang_mom_plus_1 = trexio.read_ecp_max_ang_mom_plus_1(trexio_file) - z_core = trexio.read_ecp_z_core(trexio_file) - ang_mom = trexio.read_ecp_ang_mom(trexio_file) - nucleus_index = trexio.read_ecp_nucleus_index(trexio_file) - exponent = trexio.read_ecp_exponent(trexio_file) - coefficient = trexio.read_ecp_coefficient(trexio_file) - power = trexio.read_ecp_power(trexio_file) - - lmax = max( max_ang_mom_plus_1 ) - 1 - ezfio.set_pseudo_pseudo_lmax(lmax) - ezfio.set_pseudo_nucl_charge_remove(z_core) - - prev_center = None - ecp = {} - for i in range(len(ang_mom)): - center = nucleus_index[i] - if center != prev_center: - ecp[center] = { "lmax": max_ang_mom_plus_1[center], - "zcore": z_core[center], - "contr": {} } - for j in range(max_ang_mom_plus_1[center]+1): - ecp[center]["contr"][j] = [] - - ecp[center]["contr"][ang_mom[i]].append( (coefficient[i], power[i], exponent[i]) ) - prev_center = center - - ecp_loc = {} - ecp_nl = {} - kmax = 0 - klocmax = 0 - for center in ecp: - ecp_nl [center] = {} - for k in ecp[center]["contr"]: - if k == ecp[center]["lmax"]: - ecp_loc[center] = ecp[center]["contr"][k] - klocmax = max(len(ecp_loc[center]), klocmax) - else: - ecp_nl [center][k] = ecp[center]["contr"][k] - kmax = max(len(ecp_nl [center][k]), kmax) - - ezfio.set_pseudo_pseudo_klocmax(klocmax) - ezfio.set_pseudo_pseudo_kmax(kmax) - - pseudo_n_k = [[0 for _ in range(nucl_num)] for _ in range(klocmax)] - pseudo_v_k = [[0. for _ in range(nucl_num)] for _ in range(klocmax)] - pseudo_dz_k = [[0. for _ in range(nucl_num)] for _ in range(klocmax)] - pseudo_n_kl = [[[0 for _ in range(nucl_num)] for _ in range(kmax)] for _ in range(lmax+1)] - pseudo_v_kl = [[[0. for _ in range(nucl_num)] for _ in range(kmax)] for _ in range(lmax+1)] - pseudo_dz_kl = [[[0. for _ in range(nucl_num)] for _ in range(kmax)] for _ in range(lmax+1)] - for center in ecp_loc: - for k in range( len(ecp_loc[center]) ): - v, n, dz = ecp_loc[center][k] - pseudo_n_k[k][center] = n - pseudo_v_k[k][center] = v - pseudo_dz_k[k][center] = dz - - ezfio.set_pseudo_pseudo_n_k(pseudo_n_k) - ezfio.set_pseudo_pseudo_v_k(pseudo_v_k) - ezfio.set_pseudo_pseudo_dz_k(pseudo_dz_k) - - for center in ecp_nl: - for l in range( len(ecp_nl[center]) ): - for k in range( len(ecp_nl[center][l]) ): - v, n, dz = ecp_nl[center][l][k] - pseudo_n_kl[l][k][center] = n - pseudo_v_kl[l][k][center] = v - pseudo_dz_kl[l][k][center] = dz - - ezfio.set_pseudo_pseudo_n_kl(pseudo_n_kl) - ezfio.set_pseudo_pseudo_v_kl(pseudo_v_kl) - ezfio.set_pseudo_pseudo_dz_kl(pseudo_dz_kl) - - - print("OK") - - - - -def get_full_path(file_path): - file_path = os.path.expanduser(file_path) - file_path = os.path.expandvars(file_path) - return file_path - - -if __name__ == '__main__': - ARGUMENTS = docopt(__doc__) - - FILE = get_full_path(ARGUMENTS['FILE']) - trexio_filename = FILE - - if ARGUMENTS["--output"]: - EZFIO_FILE = get_full_path(ARGUMENTS["--output"]) - else: - EZFIO_FILE = "{0}.ezfio".format(FILE) - - write_ezfio(trexio_filename, EZFIO_FILE) - sys.stdout.flush() - diff --git a/devel/trexio/trexio_file.irp.f b/devel/trexio/trexio_file.irp.f deleted file mode 100644 index c989774..0000000 --- a/devel/trexio/trexio_file.irp.f +++ /dev/null @@ -1,20 +0,0 @@ -BEGIN_PROVIDER [ character*(1024), trexio_filename ] - implicit none - BEGIN_DOC - ! Name of the TREXIO file - END_DOC - character*(1024) :: prefix - - trexio_filename = trexio_file - - if (trexio_file == 'None') then - prefix = trim(ezfio_work_dir)//trim(ezfio_filename) - if (backend == 0) then - trexio_filename = trim(prefix)//'.h5' - else if (backend == 1) then - trexio_filename = trim(prefix) - endif - endif -END_PROVIDER - - diff --git a/devel/trexio/trexio_module.F90 b/devel/trexio/trexio_module.F90 deleted file mode 100644 index acd0849..0000000 --- a/devel/trexio/trexio_module.F90 +++ /dev/null @@ -1 +0,0 @@ -#include "trexio_f.f90" diff --git a/devel/trexio/uninstall b/devel/trexio/uninstall deleted file mode 100755 index 9c9f0f1..0000000 --- a/devel/trexio/uninstall +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/bash - -# Check if the QP_ROOT environment variable is set. -if [[ -z ${QP_ROOT} ]] -then - print "The QP_ROOT environment variable is not set." - print "Please reload the quantum_package.rc file." - exit -1 -fi - -scripts_list="qp_import_trexio.py" - -# Destroy ONLY the symbolic link for the scripts to be used in the -# ${QP_ROOT}/scripts/ directory. -for i in $scripts_list -do - find ${QP_ROOT}/scripts/$i -type l -delete -done - -