From e21654a8c2e3a2cb22781d08f85457bdc65ed50d Mon Sep 17 00:00:00 2001 From: Qiming Sun Date: Fri, 10 Nov 2023 20:33:49 -0800 Subject: [PATCH] Fix decontract_basis function when basis are missed on certain atoms. (Fix #1711) (#1943) * Fix decontract_basis when basis are missed on certain atoms. (Fix #1711) --- pyscf/gto/mole.py | 3 +++ pyscf/gto/test/test_mole.py | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/pyscf/gto/mole.py b/pyscf/gto/mole.py index 6bf7bbc7e4..c8e460afef 100644 --- a/pyscf/gto/mole.py +++ b/pyscf/gto/mole.py @@ -626,6 +626,9 @@ def _to_full_contraction(mol, bas_idx): aoslices = mol.aoslice_by_atom() for ia, (ib0, ib1) in enumerate(aoslices[:,:2]): + if ib0 == ib1: # No basis on atom ia + continue + if atoms is not None: if isinstance(atoms, str): to_apply = ((atoms == mol.atom_pure_symbol(ia)) or diff --git a/pyscf/gto/test/test_mole.py b/pyscf/gto/test/test_mole.py index 4adaa7e32a..1a91682db0 100644 --- a/pyscf/gto/test/test_mole.py +++ b/pyscf/gto/test/test_mole.py @@ -1033,6 +1033,11 @@ def test_decontract_basis(self): s = ctr_coeff.T.dot(pmol.intor('int1e_ovlp')).dot(ctr_coeff) self.assertAlmostEqual(abs(s - mol.intor('int1e_ovlp')).max(), 0, 12) + # discard basis on atom 2. (related to issue #1711) + mol._bas = mol._bas[:5] + pmol, c = mol.decontract_basis() + self.assertEqual(pmol.nbas, 14) + mol = gto.M(atom='He', basis=('ccpvdz', [[0, [5, 1]], [1, [3, 1]]])) pmol, contr_coeff = mol.decontract_basis()