<filename>netket/custom/ab_initio_ham.py
import netket as nk
from netket.custom.fermionic_hilbert import Fermions
from netket.custom.fermion_operator import SparseHermitianFermionOperator, FermionSumOperators, FermionTotalSpinNumberOperator
import numpy as np


class AbInitio(FermionSumOperators):
    def __init__(self, hi, one_body_mat, two_body_mat):
        n_orbitals = hi.size

        # 1B part
        t = one_body_mat - 0.5 * np.einsum("pqqs->ps", two_body_mat)
        prefactors = []
        sites = []
        spins = []
        for i in range(n_orbitals):
            for j in range(n_orbitals):
                prefactors.append(t[i,j])
                prefactors.append(t[i,j])
                sites.append([[j, i]])
                sites.append([[j, i]])
                spins.append([0])
                spins.append([1])

        one_body = SparseHermitianFermionOperator(hi, np.array(prefactors).astype(np.complex128), np.array(sites).astype(int), np.array(spins).astype(np.uint8))

        # 2B part
        prefactors = []
        sites = []
        spins = []
        for i in range(n_orbitals):
            for j in range(n_orbitals):
                for k in range(n_orbitals):
                    for l in range(n_orbitals):
                        prefactors.append(0.5*two_body_mat[i,j,k,l])
                        prefactors.append(0.5*two_body_mat[i,j,k,l])
                        prefactors.append(two_body_mat[i,j,k,l])
                        sites.append([[j, i],[l,k]])
                        sites.append([[j, i],[l,k]])
                        sites.append([[j, i],[l,k]])
                        spins.append([0,0])
                        spins.append([1,1])
                        spins.append([0,1])

        two_body = SparseHermitianFermionOperator(hi, np.array(prefactors).astype(np.complex128), np.array(sites).astype(int), np.array(spins).astype(np.uint8))

        super().__init__([one_body, two_body])
<filename>netket/custom/ab_initio_ham.py
import netket as nk
from netket.custom.fermionic_hilbert import Fermions
from netket.custom.fermion_operator import SparseHermitianFermionOperator, FermionSumOperators, FermionTotalSpinNumberOperator
import numpy as np


class AbInitio(FermionSumOperators):
    def __init__(self, hi, one_body_mat, two_body_mat):
        n_orbitals = hi.size

        # 1B part
        t = one_body_mat - 0.5 * np.einsum("pqqs->ps", two_body_mat)
        prefactors = []
        sites = []
        spins = []
        for i in range(n_orbitals):
            for j in range(n_orbitals):
                prefactors.append(t[i,j])
                prefactors.append(t[i,j])
                sites.append([[j, i]])
                sites.append([[j, i]])
                spins.append([0])
                spins.append([1])

        one_body = SparseHermitianFermionOperator(hi, np.array(prefactors).astype(np.complex128), np.array(sites).astype(int), np.array(spins).astype(np.uint8))

        # 2B part
        prefactors = []
        sites = []
        spins = []
        for i in range(n_orbitals):
            for j in range(n_orbitals):
                for k in range(n_orbitals):
                    for l in range(n_orbitals):
                        prefactors.append(0.5*two_body_mat[i,j,k,l])
                        prefactors.append(0.5*two_body_mat[i,j,k,l])
                        prefactors.append(two_body_mat[i,j,k,l])
                        sites.append([[j, i],[l,k]])
                        sites.append([[j, i],[l,k]])
                        sites.append([[j, i],[l,k]])
                        spins.append([0,0])
                        spins.append([1,1])
                        spins.append([0,1])

        two_body = SparseHermitianFermionOperator(hi, np.array(prefactors).astype(np.complex128), np.array(sites).astype(int), np.array(spins).astype(np.uint8))

        super().__init__([one_body, two_body])
# 1B part # 2B part