Skip to content

[WIP] Add cusp correction based on atomic orbitals #4901

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 6 commits into
base: develop
Choose a base branch
from
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Add adaptive rc
Sometimes a crossing in the 2nd derivative is not found.  In that case,
increase the initial fitting range and try again.

n may not be quantum number, but we can treat it like one, especially
for 1s and 2s orbitals.

Move the lower bound for computing the reference values to 0.1.
That is, the range of values used for the initial fit is [0.1, 0.2].
This seems to work better.
  • Loading branch information
markdewing committed Jan 29, 2024
commit 6e917d2b44d313d61ca8bd670baeb0ce826e2bc4
38 changes: 21 additions & 17 deletions utils/compute_cusp_correction.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ def find_s_orbitals(fname):
bas_group = atbs["basisGroup" + str(ig)]
l = bas_group["l"][0]
n = bas_group["n"][0]
if l == 0:
if l == 0 and n in [0, 1]:
print(" ", ig, n, l)
s_orbs.append((ib, elem, ig, n, l))

Expand Down Expand Up @@ -302,7 +302,8 @@ def get_reference_vals(basis, rc=0.2):
npts = 80
uplim = np.log(rc) / np.log(10)
# xpts = np.logspace(-2.0, uplim, npts)
xpts = np.linspace(0.01, rc, npts)
# Get better results if the fit starts from 0.1 rather than a smaller value.
xpts = np.linspace(0.1, rc, npts)
vals = np.zeros(npts)

for i, x in enumerate(xpts):
Expand Down Expand Up @@ -385,10 +386,6 @@ def find_roots(initial_rc, popt, basis):

roots.sort()

# This is a big hack - not sure if it works
if len(roots) == 0:
roots = [initial_rc]

return roots


Expand Down Expand Up @@ -422,22 +419,29 @@ def compute_cusp_correction(fname_in, s_orbs, fname_out=None, root_idx=None):
if fname_out:
fout = h5py.File(fname_out, "a")

initial_rc = 0.2
for (ib, elem, bs_idx, n, l) in s_orbs:
print(f"Processing {elem} orbital {bs_idx} n = {n} l = {l}")
if elem == "H":
initial_rc = 4.0
initial_rc = 0.2
basis = bs[elem]
xpts, vals = get_reference_vals(basis[bs_idx], initial_rc)
res = optimize.curve_fit(target_f, xpts, vals, maxfev=3000)
popt = res[0]
a, alpha, c = popt
print(f" optimized a = {a} alpha = {alpha} c = {c}")

# Find possible roots to choose for actual r_c
# to keep the second derivative continuous
# Find initial_rc adaptively, so it results in at least one root
for itry in range(5):
xpts, vals = get_reference_vals(basis[bs_idx], initial_rc)
res = optimize.curve_fit(target_f, xpts, vals, maxfev=3000)
popt = res[0]
a, alpha, c = popt
print(f" optimized a = {a} alpha = {alpha} c = {c}")

# Find possible roots to choose for actual r_c
# to keep the second derivative continuous

roots = find_roots(initial_rc, popt, basis[bs_idx])

if len(roots) > 0:
break

roots = find_roots(initial_rc, popt, basis[bs_idx])
initial_rc *= 2
print("No roots found, try rc = ", initial_rc)

# print('roots',sorted(roots))
# print('roots',roots)
Expand Down