From 25eaa9572977b903de24d5c11ad345cecd744728 Mon Sep 17 00:00:00 2001 From: fishjojo Date: Wed, 9 Oct 2024 13:00:15 -0700 Subject: [PATCH] fix uccsd failing for empty active space --- pyscf/cc/ccsd.py | 2 ++ pyscf/cc/uccsd.py | 6 +++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/pyscf/cc/ccsd.py b/pyscf/cc/ccsd.py index c6270567ab..383b8a8969 100644 --- a/pyscf/cc/ccsd.py +++ b/pyscf/cc/ccsd.py @@ -611,6 +611,8 @@ def _contract_s1vvvv_t2(mycc, mol, vvvv, t2, out=None, verbose=None): # vvvv == None means AO-direct CCSD. It should redirect to # _contract_s4vvvv_t2(mycc, mol, vvvv, t2, out, verbose) assert (vvvv is not None) + if t2.size == 0: + return numpy.zeros_like(t2) time0 = logger.process_clock(), logger.perf_counter() log = logger.new_logger(mycc, verbose) diff --git a/pyscf/cc/uccsd.py b/pyscf/cc/uccsd.py index c23ebe7684..ff2fb79624 100644 --- a/pyscf/cc/uccsd.py +++ b/pyscf/cc/uccsd.py @@ -396,12 +396,12 @@ def vector_to_amplitudes(vector, nmo, nocc): nvir = nvira + nvirb nov = nocc * nvir size = nov + nocc*(nocc-1)//2*nvir*(nvir-1)//2 - if vector.size == size: + sizea = nocca * nvira + nocca*(nocca-1)//2*nvira*(nvira-1)//2 + sizeb = noccb * nvirb + noccb*(noccb-1)//2*nvirb*(nvirb-1)//2 + if vector.size == size and sizea > 0 and sizeb > 0: #return ccsd.vector_to_amplitudes_s4(vector, nmo, nocc) raise RuntimeError('Input vector is GCCSD vector') else: - sizea = nocca * nvira + nocca*(nocca-1)//2*nvira*(nvira-1)//2 - sizeb = noccb * nvirb + noccb*(noccb-1)//2*nvirb*(nvirb-1)//2 sections = np.cumsum([sizea, sizeb]) veca, vecb, t2ab = np.split(vector, sections) t1a, t2aa = ccsd.vector_to_amplitudes_s4(veca, nmoa, nocca)