diff --git a/pyscf/tdscf/_lr_eig.py b/pyscf/tdscf/_lr_eig.py index 9b8e664262..d1eb444b2c 100644 --- a/pyscf/tdscf/_lr_eig.py +++ b/pyscf/tdscf/_lr_eig.py @@ -445,25 +445,25 @@ def eig(aop, x0, precond, tol_residual=1e-5, nroots=1, x0sym=None, pick=None, xt_norm = np.linalg.norm(xt, axis=1) xt_to_keep = (dx_norm > tol_residual) & (xt_norm > max(lindep**.5, tol_residual)) xt = xt[xt_to_keep] - xt /= xt_norm[xt_to_keep, None] - - if x0sym is None: - xt = _symmetric_orth(xt) - else: - xt_ir = xt_ir[xt_to_keep] - xt_orth = [] - xt_orth_ir = [] - for ir in set(xt_ir): - idx = np.where(xt_ir == ir)[0] - xt_sub = _symmetric_orth(xt[idx]) - xt_orth.append(xt_sub) - xt_orth_ir.append([ir] * len(xt_sub)) - if xt_orth: - xt = np.vstack(xt_orth) - xs_ir = np.hstack([xs_ir, *xt_orth_ir]) + if len(xt) > 0: + xt /= xt_norm[xt_to_keep, None] + if x0sym is None: + xt = _symmetric_orth(xt) else: - xt = [] - xt_orth = xt_orth_ir = xt_sub = None + xt_ir = xt_ir[xt_to_keep] + xt_orth = [] + xt_orth_ir = [] + for ir in set(xt_ir): + idx = np.where(xt_ir == ir)[0] + xt_sub = _symmetric_orth(xt[idx]) + xt_orth.append(xt_sub) + xt_orth_ir.append([ir] * len(xt_sub)) + if xt_orth: + xt = np.vstack(xt_orth) + xs_ir = np.hstack([xs_ir, *xt_orth_ir]) + else: + xt = [] + xt_orth = xt_orth_ir = xt_sub = None if len(xt) == 0: log.debug(f'Linear dependency in trial subspace. |r| for each state {dx_norm}')