10
1
mirror of https://gitlab.com/scemama/qmcchem.git synced 2024-12-22 04:13:31 +01:00

More precise Ylm

This commit is contained in:
Anthony Scemama 2020-05-24 03:02:00 +02:00
parent e9706cee7a
commit 9b191eaa7b
3 changed files with 102 additions and 58 deletions

View File

@ -7,6 +7,7 @@ import sys
import os import os
import time import time
import subprocess import subprocess
from math import sqrt
QMCCHEM_PATH=os.environ["QMCCHEM_PATH"] QMCCHEM_PATH=os.environ["QMCCHEM_PATH"]
@ -15,7 +16,7 @@ sys.path.insert(0,QMCCHEM_PATH+"/EZFIO/Python/")
from ezfio import ezfio from ezfio import ezfio
# PARAMETERS # PARAMETERS
thresh = 1.e-3 thresh = 1.e-2
block_time = 20 block_time = 20
def main(): def main():
@ -59,6 +60,17 @@ def main():
else: else:
return None, None return None, None
def get_variance():
buffer = subprocess.check_output(['qmcchem', 'result', '-e',
'e_loc_qmcvar', filename],
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_params_pen(x): def set_params_pen(x):
x = np.abs(x) x = np.abs(x)
@ -70,7 +82,7 @@ def main():
def run_qmc(): def run_qmc():
subprocess.check_output(['qmcchem', 'run', filename]) return subprocess.check_output(['qmcchem', 'run', filename])
def stop_qmc(): def stop_qmc():
@ -108,30 +120,40 @@ def main():
atexit.register(stop_qmc) atexit.register(stop_qmc)
err = thresh+1. err = thresh+1.
time.sleep(block_time/2) time.sleep(3.*block_time/4.)
local_thresh = thresh local_thresh = thresh
while err > local_thresh: while err > local_thresh:
time.sleep(block_time) time.sleep(block_time)
energy, err = get_energy() e, e_err = get_energy()
if energy is not None: variance, v_err = get_variance()
print(" %f %f"%(energy, err)) if e is None or variance is None:
if (energy-2.*err) > memo_energy['fmin']+thresh: continue
local_thresh = 10.*thresh energy = e + variance
else: err = sqrt(e_err*e_err+v_err*v_err)
err = local_thresh+1. print(" %f %f %f %f %f %f"%(e, e_err, variance, v_err, energy, err))
if (energy-2.*err) > memo_energy['fmin']+thresh:
local_thresh = 10.*thresh
elif (energy+2.*err) < memo_energy['fmin']-thresh:
local_thresh = 10.*thresh
# Check if PID is still running # Check if PID is still running
try: os.kill(pid,0) try:
except OSError: err = 0. os.kill(pid,0)
except OSError:
print("---")
break
stop_qmc() stop_qmc()
os.wait() os.wait()
memo_energy[h] = energy memo_energy[h] = energy + err
memo_energy['fmin'] = min(energy, memo_energy['fmin']) memo_energy['fmin'] = min(energy, memo_energy['fmin'])
return energy return energy
def run(): def run():
x = get_params_pen() x = get_params_pen()
if sum(x) == 0.:
jast_a_up_dn = ezfio.jastrow_jast_a_up_dn
x += jast_a_up_dn
opt = sp.optimize.minimize(f,x,method="Powell", opt = sp.optimize.minimize(f,x,method="Powell",
options= {'disp':True, 'ftol':thresh,'xtol':0.02}) options= {'disp':True, 'ftol':thresh,'xtol':0.02})
print("x = "+str(opt)) print("x = "+str(opt))

View File

@ -50,12 +50,12 @@ BEGIN_PROVIDER [ integer*8, seed, (5) ]
END_DOC END_DOC
integer :: iargc integer :: iargc
integer*8 :: i,j integer*8 :: i,j
integer*4 :: clock(12) integer*4 :: clock(33)
double precision :: r double precision :: r
integer*8 :: pid8 integer*8 :: pid8
read(current_PID,*) pid8 read(current_PID,*) pid8
pid8 = iand( shiftl(pid8, 32), pid8) pid8 = iand( shiftl(pid8, 32), pid8)
do i=1,12 do i=1,size(clock)
clock(i) = i clock(i) = i
enddo enddo
call system_clock(count=clock(1)) call system_clock(count=clock(1))

View File

@ -183,8 +183,10 @@ BEGIN_PROVIDER [ double precision, v_pseudo_local, (elec_num) ]
cycle cycle
endif endif
select case (pseudo_n_k(i,k)) select case (pseudo_n_k(i,k))
case (-3)
rn = nucl_elec_dist_inv(i,l)*nucl_elec_dist_inv(i,l)*nucl_elec_dist_inv(i,l)
case (-2) case (-2)
rn = nucl_elec_dist_inv(i,l)*nucl_elec_dist_inv(i,l) rn = nucl_elec_dist_inv(i,l)*nucl_elec_dist_inv(i,l)
case (-1) case (-1)
rn = nucl_elec_dist_inv(i,l) rn = nucl_elec_dist_inv(i,l)
case (0) case (0)
@ -193,6 +195,8 @@ BEGIN_PROVIDER [ double precision, v_pseudo_local, (elec_num) ]
rn = r rn = r
case (2) case (2)
rn = r*r rn = r*r
case (3)
rn = r*r*r
case default case default
rn = r**pseudo_n_k(i,k) rn = r**pseudo_n_k(i,k)
end select end select
@ -229,18 +233,22 @@ BEGIN_PROVIDER [ double precision, v_pseudo_non_local, (pseudo_non_loc_dim_8,ele
select case (pseudo_n_kl(i,k,l)) select case (pseudo_n_kl(i,k,l))
case (0) case (0)
rn = 1.d0 rn = 1.d0
case (-1)
rn = nucl_elec_dist_inv(i,j)
case (1) case (1)
rn = r rn = r
case (-1)
rn = nucl_elec_dist_inv(i,j)
case (2) case (2)
rn = r*r rn = r2
case (-2) case (-2)
rn = nucl_elec_dist_inv(i,j)*nucl_elec_dist_inv(i,j) rn = nucl_elec_dist_inv(i,j)*nucl_elec_dist_inv(i,j)
case (3)
rn = r2*r
case (-3)
rn = nucl_elec_dist_inv(i,j)*nucl_elec_dist_inv(i,j)*nucl_elec_dist_inv(i,j)
case default case default
rn = r**pseudo_n_kl(i,k,l) rn = r**pseudo_n_kl(i,k,l)
end select end select
tmp(l) += pseudo_v_kl(i,k,l) * exp(-alpha) * rn tmp(l) += pseudo_v_kl(i,k,l) * dexp(-alpha) * rn
enddo enddo
enddo enddo
do l=0,pseudo_lmax do l=0,pseudo_lmax
@ -317,16 +325,20 @@ BEGIN_PROVIDER [ double precision, pseudo_mo_term, (mo_num,elec_num) ]
END_PROVIDER END_PROVIDER
real function ylm(l,m,x,y,z,r_inv) double precision function ylm(l,m,x_,y_,z_,r_inv)
implicit none implicit none
include 'constants.F' include 'constants.F'
BEGIN_DOC BEGIN_DOC
! Y(l,m) evaluated at x,y,z ! Y(l,m) evaluated at x,y,z
END_DOC END_DOC
integer, intent(in) :: l,m integer, intent(in) :: l,m
real, intent(in) :: x,y,z,r_inv real, intent(in) :: x_,y_,z_,r_inv
double precision :: x, y, z
x = x_
y = y_
z = z_
ylm = 0.5 * one_over_sqpi ylm = 0.5d0 * one_over_sqpi
select case(l) select case(l)
case(0) case(0)
@ -344,37 +356,47 @@ real function ylm(l,m,x,y,z,r_inv)
end select end select
case(2) case(2)
ylm = ylm * r_inv * r_inv * sqrt(5.) ylm = ylm * r_inv * r_inv * dsqrt(5.d0)
select case (m) select case (m)
case(-2) case(-2)
ylm = ylm * sqrt(3.) * x * y ylm = ylm * sq3 * x * y
case(-1) case(-1)
ylm = ylm * sqrt(3.) * y * z ylm = ylm * sq3 * y * z
case(0) case(0)
ylm = ylm * 0.5 * (2.*z*z - x*x - y*y) ! ylm = ylm * 0.5d0 * (2.d0*z*z - x*x - y*y)
! ylm = ylm * 0.5d0 * (z*z - x*x + z*z - y*y)
ylm = ylm * 0.5d0 * ( (z+x)*(z-x) + (z+y)*(z-y) )
case(1) case(1)
ylm = ylm * sqrt(3.) * z * x ylm = ylm * sq3 * z * x
case(2) case(2)
ylm = ylm * 0.5 * sqrt(3.) * (x*x - y*y) ! ylm = ylm * 0.5d0 * sq3 * (x*x - y*y)
ylm = ylm * 0.5d0 * sq3 * (x+y)*(x-y)
end select end select
case(3) case(3)
ylm = ylm * r_inv * r_inv * r_inv * sqrt(7.) ylm = ylm * r_inv * r_inv * r_inv * dsqrt(7.d0)
select case (m) select case (m)
case(-3) case(-3)
ylm = ylm * 0.25 * sqrt(10.) * (3.*x*x - y*y) ! ylm = ylm * 0.25d0 * dsqrt(10.d0) * (3.d0*x*x - y*y)
ylm = ylm * 0.25d0 * dsqrt(10.d0) * (2.d0*x*x + (x+y)*(x-y))
case(-2) case(-2)
ylm = ylm * sqrt(15.) * x*y*z ylm = ylm * dsqrt(15.d0) * x*y*z
case(-1) case(-1)
ylm = ylm * 0.25*sqrt(6.) * y * (4.*z*z - x*x -y*y) ! ylm = ylm * 0.25d0*dsqrt(6.d0) * y * (4.d0*z*z - x*x -y*y)
ylm = ylm * 0.25d0*dsqrt(6.d0) * y * (2.d0*z*z + (z+x)*(z-x) + (z+y)*(z-y))
case(0) case(0)
ylm = ylm * 0.5 * z * (2.*z*z - 3.*(x*x + y*y)) ! ylm = ylm * 0.5d0 * z * (2.d0*z*z - 3.d0*(x*x + y*y))
! ylm = ylm * 0.5d0 * z * ( (z+x)*(z-x) + (z+y)*(z-y) - 2.d0*(x*x + y*y))
ylm = ylm * 0.5d0 * z * ( (z+x)*(z-x) + (z+y)*(z-y) - 2.d0*(x+y)*(x-y) - 4.d0*y*y)
case(1) case(1)
ylm = ylm * 0.25*sqrt(6.) * x * (4.*z*z - x*x -y*y) ! ylm = ylm * 0.25d0*dsqrt(6.d0) * x * (4.d0*z*z - x*x -y*y)
ylm = ylm * 0.25d0*dsqrt(6.d0) * x * (2.d0*z*z + (z-x)*(z+x) + (z-y)*(z+y))
case(2) case(2)
ylm = ylm * 0.5*sqrt(15.) * z * (x*x -y*y) ! ylm = ylm * 0.5d0*dsqrt(15.d0) * z * (x*x -y*y)
ylm = ylm * 0.5d0*dsqrt(15.d0) * z * (x+y)*(x-y)
case(3) case(3)
ylm = ylm * 0.25*sqrt(10.) * x * (x*x - 3. * y*y) ! ylm = ylm * 0.25d0*dsqrt(10.d0) * x * (x*x - 3.d0 * y*y)
ylm = ylm * 0.25d0*dsqrt(10.d0) * x * ( (x+y)*(x-y) - 2.d0*y*y)
end select end select
@ -395,7 +417,7 @@ BEGIN_PROVIDER [ double precision, pseudo_ylm, (pseudo_non_loc_dim_8,elec_num) ]
END_DOC END_DOC
integer :: i,j,l,m,kk integer :: i,j,l,m,kk
real, external :: ylm double precision, external :: ylm
integer, save :: ifirst = 0 integer, save :: ifirst = 0
if (ifirst == 0) then if (ifirst == 0) then