Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support frozen core #44

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion quantum_systems/custom_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ def construct_pyscf_system_rhf(
verbose=False,
charge=0,
cart=False,
nfrozen=0,
conv_tol=1e-10,
**kwargs,
):
"""Convenience function setting up a closed-shell atom or a molecule from
Expand Down Expand Up @@ -187,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:
Expand Down Expand Up @@ -215,7 +218,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 (
Expand Down
4 changes: 2 additions & 2 deletions quantum_systems/general_orbital_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions quantum_systems/spatial_orbital_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down Expand Up @@ -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)
Expand Down
11 changes: 6 additions & 5 deletions quantum_systems/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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
Expand All @@ -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):
Expand Down