Skip to content

Commit

Permalink
NEO: allow dashes/underscores in nuclear basis name
Browse files Browse the repository at this point in the history
  • Loading branch information
zc62 committed Apr 11, 2024
1 parent d928ae3 commit 2834675
Showing 1 changed file with 72 additions and 37 deletions.
109 changes: 72 additions & 37 deletions pyscf/neo/mole.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ def build_nuc_mole(mol, index, atom_index, nuc_basis, frac=None):
nuc.atom_index = atom_index
nuc.index = index

# e.g., PB4-D, PB4D and PB4_D will all be converted to pb4d
nuc_basis = nuc_basis.replace('-', '').replace('_', '').lower()
nuc_basis = nuc_basis.lower() # e.g., PB4D will be converted to pb4d
dirnow = os.path.realpath(os.path.join(__file__, '..'))
if 'H+' in mol.atom_symbol(atom_index): # H+ for deuterium
try:
Expand All @@ -71,50 +70,86 @@ def build_nuc_mole(mol, index, atom_index, nuc_basis, frac=None):
x[1][0] *= numpy.sqrt((2.01410177811 - nist.E_MASS / nist.ATOMIC_MASS)
/ (1.007825 - nist.E_MASS / nist.ATOMIC_MASS))
except FileNotFoundError:
m = re.search("(\d+)s(\d+)p(\d+)d(\d+)?f?", nuc_basis)
if m:
# even-tempered basis for D
alpha = 4
beta = numpy.sqrt(2)
if m.group(4) is None:
basis = gto.expand_etbs([(0, int(m.group(1)), alpha, beta), (1, int(m.group(2)), alpha, beta),
(2, int(m.group(3)), alpha, beta)])
try:
# try basis name without dashes/underscores
# e.g., PB4-D, PB4_D and pb4-_-d will be converted to pb4d
nuc_basis_without_dash_underscore = nuc_basis.replace('-', '').replace('_', '')
with open(os.path.join(dirnow, 'basis/'+nuc_basis_without_dash_underscore+'.dat'), 'r') as f:
basis = gto.basis.parse(f.read())
for x in basis:
x[1][0] *= numpy.sqrt((2.01410177811 - nist.E_MASS / nist.ATOMIC_MASS)
/ (1.007825 - nist.E_MASS / nist.ATOMIC_MASS))
except FileNotFoundError:
m = re.search("(\d+)s(\d+)p(\d+)d(\d+)?f?", nuc_basis)
if m:
# even-tempered basis for D
alpha = 4
beta = numpy.sqrt(2)
if m.group(4) is None:
basis = gto.expand_etbs([(0, int(m.group(1)), alpha, beta),
(1, int(m.group(2)), alpha, beta),
(2, int(m.group(3)), alpha, beta)])
else:
basis = gto.expand_etbs([(0, int(m.group(1)), alpha, beta),
(1, int(m.group(2)), alpha, beta),
(2, int(m.group(3)), alpha, beta),
(3, int(m.group(4)), alpha, beta)])
else:
basis = gto.expand_etbs([(0, int(m.group(1)), alpha, beta), (1, int(m.group(2)), alpha, beta),
(2, int(m.group(3)), alpha, beta), (3, int(m.group(4)), alpha, beta)])
else:
raise ValueError('Unsupported nuclear basis %s', nuc_basis)
raise ValueError('Unsupported nuclear basis %s', nuc_basis)
elif 'H*' in mol.atom_symbol(atom_index): # H* for muonium
with open(os.path.join(dirnow, 'basis/'+nuc_basis+'.dat'), 'r') as f:
basis = gto.basis.parse(f.read())
# read in H basis, but scale the exponents by sqrt(mass_mu/mass_H)
for x in basis:
x[1][0] *= numpy.sqrt(0.1134289259 / (1.007825 - nist.E_MASS / nist.ATOMIC_MASS))
try:
with open(os.path.join(dirnow, 'basis/'+nuc_basis+'.dat'), 'r') as f:
basis = gto.basis.parse(f.read())
# read in H basis, but scale the exponents by sqrt(mass_mu/mass_H)
for x in basis:
x[1][0] *= numpy.sqrt(0.1134289259 / (1.007825 - nist.E_MASS / nist.ATOMIC_MASS))
except FileNotFoundError:
nuc_basis_without_dash_underscore = nuc_basis.replace('-', '').replace('_', '')
with open(os.path.join(dirnow, 'basis/'+nuc_basis_without_dash_underscore+'.dat'), 'r') as f:
basis = gto.basis.parse(f.read())
for x in basis:
x[1][0] *= numpy.sqrt(0.1134289259 / (1.007825 - nist.E_MASS / nist.ATOMIC_MASS))
elif 'H#' in mol.atom_symbol(atom_index): # H# for HeMu
with open(os.path.join(dirnow, 'basis/'+nuc_basis+'.dat'), 'r') as f:
basis = gto.basis.parse(f.read())
# read in H basis, but scale the exponents by sqrt(mass_HeMu/mass_H)
for x in basis:
x[1][0] *= numpy.sqrt((4.002603254 - 2 * nist.E_MASS / nist.ATOMIC_MASS + 0.1134289259)
/ (1.007825 - nist.E_MASS / nist.ATOMIC_MASS))
try:
with open(os.path.join(dirnow, 'basis/'+nuc_basis+'.dat'), 'r') as f:
basis = gto.basis.parse(f.read())
# read in H basis, but scale the exponents by sqrt(mass_HeMu/mass_H)
for x in basis:
x[1][0] *= numpy.sqrt((4.002603254 - 2 * nist.E_MASS / nist.ATOMIC_MASS + 0.1134289259)
/ (1.007825 - nist.E_MASS / nist.ATOMIC_MASS))
except FileNotFoundError:
nuc_basis_without_dash_underscore = nuc_basis.replace('-', '').replace('_', '')
with open(os.path.join(dirnow, 'basis/'+nuc_basis_without_dash_underscore+'.dat'), 'r') as f:
basis = gto.basis.parse(f.read())
for x in basis:
x[1][0] *= numpy.sqrt((4.002603254 - 2 * nist.E_MASS / nist.ATOMIC_MASS + 0.1134289259)
/ (1.007825 - nist.E_MASS / nist.ATOMIC_MASS))
elif mol.atom_pure_symbol(atom_index) == 'H':
try:
with open(os.path.join(dirnow, 'basis/'+nuc_basis+'.dat'), 'r') as f:
basis = gto.basis.parse(f.read())
except FileNotFoundError:
m = re.search("(\d+)s(\d+)p(\d+)d(\d+)?f?", nuc_basis)
if m:
# even-tempered basis for H
alpha = 2 * numpy.sqrt(2)
beta = numpy.sqrt(2)
if m.group(4) is None:
basis = gto.expand_etbs([(0, int(m.group(1)), alpha, beta), (1, int(m.group(2)), alpha, beta),
(2, int(m.group(3)), alpha, beta)])
try:
nuc_basis_without_dash_underscore = nuc_basis.replace('-', '').replace('_', '')
with open(os.path.join(dirnow, 'basis/'+nuc_basis_without_dash_underscore+'.dat'), 'r') as f:
basis = gto.basis.parse(f.read())
except FileNotFoundError:
m = re.search("(\d+)s(\d+)p(\d+)d(\d+)?f?", nuc_basis)
if m:
# even-tempered basis for H
alpha = 2 * numpy.sqrt(2)
beta = numpy.sqrt(2)
if m.group(4) is None:
basis = gto.expand_etbs([(0, int(m.group(1)), alpha, beta),
(1, int(m.group(2)), alpha, beta),
(2, int(m.group(3)), alpha, beta)])
else:
basis = gto.expand_etbs([(0, int(m.group(1)), alpha, beta),
(1, int(m.group(2)), alpha, beta),
(2, int(m.group(3)), alpha, beta),
(3, int(m.group(4)), alpha, beta)])
else:
basis = gto.expand_etbs([(0, int(m.group(1)), alpha, beta), (1, int(m.group(2)), alpha, beta),
(2, int(m.group(3)), alpha, beta), (3, int(m.group(4)), alpha, beta)])
else:
raise ValueError('Unsupported nuclear basis %s', nuc_basis)
raise ValueError('Unsupported nuclear basis %s', nuc_basis)

else:
# even-tempered basis
Expand Down

0 comments on commit 2834675

Please sign in to comment.