Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/pyscf/pyscf
Browse files Browse the repository at this point in the history
pulling from master of pyscf
  • Loading branch information
hung.pham committed Jan 4, 2024
2 parents 3534c15 + d366a06 commit 55fd06d
Show file tree
Hide file tree
Showing 17 changed files with 513 additions and 126 deletions.
1 change: 1 addition & 0 deletions pyscf/cc/gccsd.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,7 @@ def _make_eris_incore(mycc, mo_coeff=None, ao2mofn=None):
mo = mo_a + mo_b
eri = ao2mo.kernel(mycc._scf._eri, mo)
if eri.size == nmo**4: # if mycc._scf._eri is a complex array
eri = eri.reshape(nmo**2, nmo**2)
sym_forbid = (orbspin[:,None] != orbspin).ravel()
else: # 4-fold symmetry
sym_forbid = (orbspin[:,None] != orbspin)[np.tril_indices(nmo)]
Expand Down
1 change: 0 additions & 1 deletion pyscf/dft/rks.py
Original file line number Diff line number Diff line change
Expand Up @@ -539,5 +539,4 @@ def to_gpu(self):
obj = lib.to_gpu(hf.SCF.reset(self.view(RKS)))
# Attributes only defined in gpu4pyscf.RKS
obj.screen_tol = 1e-14
obj.disp = None
return obj
1 change: 0 additions & 1 deletion pyscf/dft/uks.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,5 +203,4 @@ def to_gpu(self):
obj = lib.to_gpu(SCF.reset(self.view(UKS)))
# Attributes only defined in gpu4pyscf.RKS
obj.screen_tol = 1e-14
obj.disp = None
return obj
10 changes: 7 additions & 3 deletions pyscf/grad/mp2.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,12 +241,16 @@ def converged(self):


def _shell_prange(mol, start, stop, blksize):
l = mol._bas[start:stop,gto.ANG_OF]
if mol.cart:
dims = (l+1)*(l+2)//2 * mol._bas[start:stop,gto.NCTR_OF]
else:
dims = (l*2+1) * mol._bas[start:stop,gto.NCTR_OF]
nao = 0
ib0 = start
for ib in range(start, stop):
now = (mol.bas_angular(ib)*2+1) * mol.bas_nctr(ib)
for ib, now in zip(range(start, stop), dims):
nao += now
if nao > blksize and nao > now:
if nao > blksize:
yield (ib0, ib, nao-now)
ib0 = ib
nao = now
Expand Down
8 changes: 8 additions & 0 deletions pyscf/grad/test/test_mp2.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,14 @@ def test_symmetrize(self):
g = mol.RHF.run().MP2().run().Gradients().kernel()
self.assertAlmostEqual(lib.fp(g), 0.049987975650731625, 6)

# issue 1985
def test_cart_gto(self):
mol1 = mol.copy()
mol1.cart = True
mol1.basis = '6-31g*'
g = mol.RHF.run().MP2().run().Gradients().kernel()
self.assertAlmostEqual(lib.fp(g), -0.03568120792884476, 6)


if __name__ == "__main__":
print("Tests for MP2 gradients")
Expand Down
65 changes: 27 additions & 38 deletions pyscf/gto/mole.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ def str2atm(line):
return list(zip(z, c.tolist()))

#TODO: sort exponents
def format_basis(basis_tab):
def format_basis(basis_tab, sort_basis=True):
'''Convert the input :attr:`Mole.basis` to the internal data format.
``{ atom: [(l, ((-exp, c_1, c_2, ..),
Expand Down Expand Up @@ -457,10 +457,16 @@ def format_basis(basis_tab):
fmt_basis = {}
for atom, atom_basis in basis_tab.items():
symb = _atom_symbol(atom)
fmt_basis[symb] = basis_converter(symb, atom_basis)

if len(fmt_basis[symb]) == 0:
_basis = basis_converter(symb, atom_basis)
if len(_basis) == 0:
raise BasisNotFoundError('Basis not found for %s' % symb)

# Sort basis accroding to angular momentum. This is important for method
# decontract_basis, which assumes that basis functions with the same
# angular momentum are grouped together. Related to issue #1620 #1770
if sort_basis:
_basis = sorted([b for b in _basis if b], key=lambda b: b[0])
fmt_basis[symb] = _basis
return fmt_basis

def _generate_basis_converter():
Expand Down Expand Up @@ -503,11 +509,6 @@ def converter(symb, raw_basis):
_basis.extend(nparray_to_list(rawb))
else:
_basis = nparray_to_list(raw_basis)

# Sort basis accroding to angular momentum. This is important for method
# decontract_basis, which assumes that basis functions with the same
# angular momentum are grouped together. Related to issue #1620 #1770
_basis = sorted([b for b in _basis if b], key=lambda b: b[0])
return _basis
return converter

Expand Down Expand Up @@ -654,6 +655,8 @@ def _to_full_contraction(mol, bas_idx):
bas_idx = ib0 + numpy.where(mol._bas[ib0:ib1,ANG_OF] == l)[0]
if len(bas_idx) == 0:
continue
if bas_idx[0] + len(bas_idx) != bas_idx[-1] + 1:
raise NotImplementedError('Discontinuous bases of same angular momentum')

mol_exps, b_coeff = _to_full_contraction(mol, bas_idx)
nprim, nc = b_coeff.shape
Expand Down Expand Up @@ -2523,11 +2526,13 @@ def build(self, dump_input=True, parse_arg=ARGPARSE,
if self.verbose >= logger.WARN:
self.check_sanity()

self._atom = self.format_atom(self.atom, unit=self.unit)
if self.atom:
self._atom = self.format_atom(self.atom, unit=self.unit)
uniq_atoms = {a[0] for a in self._atom}

_basis = _parse_default_basis(self.basis, uniq_atoms)
self._basis = self.format_basis(_basis)
if self.basis:
_basis = _parse_default_basis(self.basis, uniq_atoms)
self._basis = self.format_basis(_basis)
env = self._env[:PTR_ENV_START]
self._atm, self._bas, self._env = \
self.make_env(self._atom, self._basis, env, self.nucmod,
Expand Down Expand Up @@ -2643,30 +2648,12 @@ def _build_symmetry(self, *args, **kwargs):
for ir in self.irrep_id]
return self

@lib.with_doc(format_atom.__doc__)
def format_atom(self, atom, origin=0, axes=None, unit='Ang'):
return format_atom(atom, origin, axes, unit)

@lib.with_doc(format_basis.__doc__)
def format_basis(self, basis_tab):
return format_basis(basis_tab)

@lib.with_doc(format_pseudo.__doc__)
def format_pseudo(self, pseudo_tab):
return format_pseudo(pseudo_tab)

@lib.with_doc(format_ecp.__doc__)
def format_ecp(self, ecp_tab):
return format_ecp(ecp_tab)

@lib.with_doc(expand_etb.__doc__)
def expand_etb(self, l, n, alpha, beta):
return expand_etb(l, n, alpha, beta)

@lib.with_doc(expand_etbs.__doc__)
def expand_etbs(self, etbs):
return expand_etbs(etbs)
etbs = expand_etbs
format_atom = staticmethod(format_atom)
format_basis = staticmethod(format_basis)
format_pseudo = staticmethod(format_pseudo)
format_ecp = staticmethod(format_ecp)
expand_etb = staticmethod(expand_etb)
expand_etbs = etbs = staticmethod(expand_etbs)

@lib.with_doc(make_env.__doc__)
def make_env(self, atoms, basis, pre_env=[], nucmod={}, nucprop=None):
Expand Down Expand Up @@ -3713,7 +3700,7 @@ def __getattr__(self, key):
'_repr_mimebundle_'):
# https://github.com/mewwts/addict/issues/26
# https://github.com/jupyter/notebook/issues/2014
raise AttributeError
raise AttributeError(f'Mole object has no attribute {key}')

# Import all available modules. Some methods are registered to other
# classes/modules when importing modules in __all__.
Expand All @@ -3734,8 +3721,10 @@ def __getattr__(self, key):
if xc in dft.XC:
mf.xc = xc
key = 'TDDFT'
else:
elif 'CI' in key or 'CC' in key or 'CAS' in key or 'MP' in key:
mf = scf.HF(self)
else:
raise AttributeError(f'Mole object has no attribute {key}')

method = getattr(mf, key)

Expand Down
2 changes: 1 addition & 1 deletion pyscf/lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ if(ENABLE_XCFUN AND BUILD_XCFUN)
GIT_REPOSITORY https://github.com/dftlibs/xcfun.git
GIT_TAG a89b783
# This patch adds the xcfun derivative order up to 5
PATCH_COMMAND git apply ${PROJECT_SOURCE_DIR}/libxcfun.patch
PATCH_COMMAND git apply --reject ${PROJECT_SOURCE_DIR}/libxcfun.patch
PREFIX ${PROJECT_BINARY_DIR}/deps
INSTALL_DIR ${PROJECT_SOURCE_DIR}/deps
CMAKE_ARGS -DCMAKE_BUILD_TYPE=RELEASE -DBUILD_SHARED_LIBS=1
Expand Down
3 changes: 3 additions & 0 deletions pyscf/lib/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -1340,7 +1340,10 @@ def to_gpu(method):
gpu4pyscf objects.
'''
import cupy
from pyscf import gto
for key, val in method.__dict__.items():
if isinstance(val, gto.MoleBase):
continue
if isinstance(val, numpy.ndarray):
setattr(method, key, cupy.asarray(val))
elif hasattr(val, 'to_gpu'):
Expand Down
5 changes: 4 additions & 1 deletion pyscf/lo/boys.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,10 @@ def dipole_integral(mol, mo_coeff, charge_center=None):
return dip

def atomic_init_guess(mol, mo_coeff):
s = mol.intor_symmetric('int1e_ovlp')
if getattr(mol, 'pbc_intor', None):
s = mol.pbc_intor('int1e_ovlp', hermi=1)
else:
s = mol.intor_symmetric('int1e_ovlp')
c = orth.orth_ao(mol, s=s)
mo = reduce(numpy.dot, (c.conj().T, s, mo_coeff))
# Find the AOs which have largest overlap to MOs
Expand Down
Loading

0 comments on commit 55fd06d

Please sign in to comment.