From a378c00c7b47545f54af819b41049872b56efbf5 Mon Sep 17 00:00:00 2001 From: Nico Date: Sat, 9 Dec 2023 12:01:52 +0100 Subject: [PATCH] fix factorial2 --- docs/example/single_point/h2.py | 2 +- qmctorch/wavefunction/orbitals/norm_orbital.py | 18 +++++++++++++----- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/docs/example/single_point/h2.py b/docs/example/single_point/h2.py index 27017364..3a1c603c 100644 --- a/docs/example/single_point/h2.py +++ b/docs/example/single_point/h2.py @@ -15,7 +15,7 @@ # define the wave function wf = SlaterJastrow(mol, kinetic='jacobi', - configs='ground_state', jastrow=jastrow).gto2sto() + configs='ground_state', jastrow=jastrow) #.gto2sto() # sampler sampler = Metropolis(nwalkers=1000, nstep=1000, step_size=0.25, diff --git a/qmctorch/wavefunction/orbitals/norm_orbital.py b/qmctorch/wavefunction/orbitals/norm_orbital.py index 8b7d5546..d8b346ea 100644 --- a/qmctorch/wavefunction/orbitals/norm_orbital.py +++ b/qmctorch/wavefunction/orbitals/norm_orbital.py @@ -1,6 +1,6 @@ import torch import numpy as np - +from scipy.special import factorial2 def atomic_orbital_norm(basis): """Computes the norm of the atomic orbitals @@ -141,16 +141,24 @@ def norm_gaussian_cartesian(a, b, c, exp): torch.tensor: normalization factor """ - from scipy.special import factorial2 as f2 - pref = torch.as_tensor((2 * exp / np.pi) ** (0.75)) am1 = (2 * a - 1).astype("int") x = (4 * exp) ** (a / 2) / torch.sqrt(torch.as_tensor(f2(am1))) bm1 = (2 * b - 1).astype("int") y = (4 * exp) ** (b / 2) / torch.sqrt(torch.as_tensor(f2(bm1))) - + cm1 = (2 * c - 1).astype("int") - z = (4 * exp) ** (c / 2) / torch.sqrt(torch.as_tensor(f2(cm1))) + z = (4 * exp) ** (c / 2) / torch.sqrt(torch.as_tensor(f2(cm1))) return (pref * x * y * z).type(torch.get_default_dtype()) + +def f2(x): + """Returns the f2 of x with f2(x<1) = 1 as implemented in scipy 1.10. + """ + # compute the x!! + out = factorial2(x) + + # set all the elements lower than 1 to 1 + out[out<1] = 1 + return out \ No newline at end of file