From 07c542a86e7200b20f05cbc4b6234879af1adb2e Mon Sep 17 00:00:00 2001 From: haakoek Date: Thu, 28 May 2020 13:06:19 +0200 Subject: [PATCH 1/4] allow for nfrozen orbitals, default is nfrozen=0 --- quantum_systems/system.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/quantum_systems/system.py b/quantum_systems/system.py index 0856ad8..d5df40e 100644 --- a/quantum_systems/system.py +++ b/quantum_systems/system.py @@ -16,17 +16,17 @@ class QuantumSystem(metaclass=abc.ABCMeta): states. """ - def __init__(self, n, basis_set): + def __init__(self, n, basis_set, nfrozen=0): self._basis_set = basis_set assert n <= self._basis_set.l self.np = self._basis_set.np - self.set_system_size(n, self._basis_set.l) + self.set_system_size(n, self._basis_set.l, nfrozen) self._time_evolution_operator = None - def set_system_size(self, n, l): + def set_system_size(self, n, l, nfrozen): """Function setting the system size. Note that ``l`` should correspond to the length of each axis of the matrix elements. @@ -43,8 +43,9 @@ def set_system_size(self, n, l): self.n = n self.l = l self.m = self.l - self.n + self.nfrozen = nfrozen - self.o = slice(0, self.n) + self.o = slice(nfrozen, self.n) self.v = slice(self.n, self.l) @abc.abstractmethod @@ -65,7 +66,7 @@ def change_module(self, np): def change_basis(self, C, C_tilde=None): self._basis_set.change_basis(C, C_tilde) - self.set_system_size(self.n, self._basis_set.l) + self.set_system_size(self.n, self._basis_set.l, self.nfrozen) @abc.abstractmethod def change_to_hf_basis(self, *args, **kwargs): From c8764f36f4b9c884d350f307afd89028a5032601 Mon Sep 17 00:00:00 2001 From: haakoek Date: Thu, 28 May 2020 13:07:26 +0200 Subject: [PATCH 2/4] add nfrozen argument to construct_pyscf_rhf --- quantum_systems/custom_system.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/quantum_systems/custom_system.py b/quantum_systems/custom_system.py index 9efb441..6cb6bbc 100644 --- a/quantum_systems/custom_system.py +++ b/quantum_systems/custom_system.py @@ -111,6 +111,7 @@ def construct_pyscf_system_rhf( verbose=False, charge=0, cart=False, + nfrozen=0, **kwargs, ): """Convenience function setting up a closed-shell atom or a molecule from @@ -215,7 +216,7 @@ def construct_pyscf_system_rhf( bs.dipole_moment = dipole_integrals bs.change_module(np=np) - system = SpatialOrbitalSystem(n, bs) + system = SpatialOrbitalSystem(n, bs, nfrozen=nfrozen) system.change_basis(C) return ( From 537f2b924512607eecdeba1be7f1c91e52f5dfd4 Mon Sep 17 00:00:00 2001 From: haakoek Date: Thu, 28 May 2020 13:08:21 +0200 Subject: [PATCH 3/4] compute ref. energy and construct fock matrix must use all occupied orbitals, including those that are frozen --- quantum_systems/general_orbital_system.py | 4 ++-- quantum_systems/spatial_orbital_system.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/quantum_systems/general_orbital_system.py b/quantum_systems/general_orbital_system.py index 4f2f25e..afddbcd 100644 --- a/quantum_systems/general_orbital_system.py +++ b/quantum_systems/general_orbital_system.py @@ -55,7 +55,7 @@ def compute_reference_energy(self): The reference energy. """ - o, v = self.o, self.v + o, v = slice(0, self.n), self.v return self.np.trace(self.h[o, o]) + 0.5 * self.np.trace( self.np.trace(self.u[o, o, o, o], axis1=1, axis2=3) @@ -91,7 +91,7 @@ def construct_fock_matrix(self, h, u, f=None): """ np = self.np - o, v = (self.o, self.v) + o, v = (slice(0, self.n), self.v) if f is None: f = np.zeros_like(h) diff --git a/quantum_systems/spatial_orbital_system.py b/quantum_systems/spatial_orbital_system.py index 0ab0da1..1d90048 100644 --- a/quantum_systems/spatial_orbital_system.py +++ b/quantum_systems/spatial_orbital_system.py @@ -109,7 +109,7 @@ def compute_reference_energy(self): The reference energy. """ - o, v = self.o, self.v + o, v = slice(0, self.n), self.v return ( 2 * self.np.trace(self.h[o, o]) @@ -147,7 +147,7 @@ def construct_fock_matrix(self, h, u, f=None): The filled Fock matrix. """ np = self.np - o, v = (self.o, self.v) + o, v = (slice(0, self.n), self.v) if f is None: f = np.zeros_like(h) From 1d3421f15e8ba3ec203cbdda538e033bf9987682 Mon Sep 17 00:00:00 2001 From: haakoek Date: Mon, 15 Jun 2020 13:17:50 +0200 Subject: [PATCH 4/4] set conv_tol rhf --- quantum_systems/custom_system.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/quantum_systems/custom_system.py b/quantum_systems/custom_system.py index 6cb6bbc..dc31c80 100644 --- a/quantum_systems/custom_system.py +++ b/quantum_systems/custom_system.py @@ -112,6 +112,7 @@ def construct_pyscf_system_rhf( charge=0, cart=False, nfrozen=0, + conv_tol=1e-10, **kwargs, ): """Convenience function setting up a closed-shell atom or a molecule from @@ -188,6 +189,7 @@ def construct_pyscf_system_rhf( l = mol.nao hf = pyscf.scf.RHF(mol) + hf.conv_tol=conv_tol hf_energy = hf.kernel() if not hf.converged: