diff --git a/src/tequila/quantumchemistry/qc_base.py b/src/tequila/quantumchemistry/qc_base.py index 9c3342fb..a70d5677 100644 --- a/src/tequila/quantumchemistry/qc_base.py +++ b/src/tequila/quantumchemistry/qc_base.py @@ -684,7 +684,7 @@ def orthonormalize_basis_orbitals(self): # backward compatibility return self.use_native_orbitals() - def use_native_orbitals(self, inplace=False, core: list = None, *args, **kwargs): + def use_native_orbitals(self, inplace=False, core: list = [], *args, **kwargs): """ Parameters ---------- @@ -786,23 +786,39 @@ def get_core(active): co.sort() return co + def active_to_active(active): + ''' + translates active indices from canonical/the original basis to the native coeffs + ''' + ov = numpy.zeros(shape=(len(self.integral_manager.orbitals))) + for i in active: + for j in range(len(d)): + ov[j] += numpy.abs(inner(c.T[i], d.T[j], s)) + act = [] + for i in range(len(active)): + idx = numpy.argmax(ov) + act.append(idx) + ov[idx] = 0. + act.sort() + return act + active = None - if not self.integral_manager.active_space_is_trivial() and core is None: - core = [i.idx_total for i in self.integral_manager.orbitals if i.idx is None] if "active" in kwargs: active = kwargs["active"] kwargs.pop("active") - if core is None: + if not len(core): core = get_core(active) else: - if active is None: - if core is None: + if not len(core): + if not self.integral_manager.active_space_is_trivial(): + active = [i.idx_total for i in self.integral_manager.orbitals if i.idx is not None] + active = active_to_active(active) + core = [i.idx_total for i in self.integral_manager.orbitals if i.idx is None] + else: core = [] active = [i for i in range(len(self.integral_manager.orbitals))] - else: - if isinstance(core, int): - core = [core] - active = get_active(core) + else: + active = get_active(core) assert len(active) + len(core) == len(self.integral_manager.orbitals) to_active = [i for i in range(len(self.integral_manager.orbitals)) if i not in core] to_active = {active[i]: to_active[i] for i in range(len(active))}