From 0e4871c1eb95ea2f5e09770f9cd231095c586655 Mon Sep 17 00:00:00 2001
From: Kostas Vilkelis <kostasvilkelis@gmail.com>
Date: Fri, 23 Feb 2024 01:48:50 +0100
Subject: [PATCH] evaluate mfModels on a kgrid

---
 codes/model.py | 17 ++++++++++-------
 codes/utils.py | 20 ++++++++++++++++++++
 2 files changed, 30 insertions(+), 7 deletions(-)

diff --git a/codes/model.py b/codes/model.py
index 379ce4e..95dfb2b 100644
--- a/codes/model.py
+++ b/codes/model.py
@@ -1,6 +1,6 @@
-from . import utils
+from . import utils, hf
 import numpy as np
-import hf
+
 
 class BaseMfModel:
     """
@@ -15,7 +15,7 @@ class BaseMfModel:
         Interaction potential V(k) evaluated on a k-point grid.
     filling : float
         Filling factor of the system.
-    
+
     Methods
     -------
     densityMatrix(mf_k)
@@ -24,6 +24,7 @@ class BaseMfModel:
     meanField(rho)
         Calculates the mean-field correction from a given density matrix.
     """
+
     def __init__(self, H0_k, V_k, filling):
         """
         Parameters
@@ -45,7 +46,7 @@ class BaseMfModel:
         ----------
         mf_k : nd-array
             Mean-field correction to the non-interacting hamiltonian.
-        
+
         Returns
         -------
         rho : nd-array
@@ -70,13 +71,15 @@ class BaseMfModel:
         """
         return hf.compute_mf(rho, self.V_k)
 
+
 class MfModel(BaseMfModel):
     """
     BaseMfModel with the non-interacting hamiltonian and the interaction
     potential given as tight-binding models.
+    The model is defined on a regular k-point grid.
     """
 
-    def __init__(self, tb_model, filling, int_model):
+    def __init__(self, tb_model, int_model, filling, nk=100):
         """
         Parameters
         ----------
@@ -91,8 +94,8 @@ class MfModel(BaseMfModel):
         self.filling = filling
         dim = len([*tb_model.keys()][0])
         if dim > 0:
-            self.H0_k = utils.model2hk(tb_model=tb_model)
-            self.V_k = utils.model2hk(tb_model=int_model)
+            self.H0_k = utils.tb2grid(tb_model, nk=nk)
+            self.V_k = utils.tb2grid(int_model, nk=nk)
         if dim == 0:
             self.H0_k = tb_model[()]
             self.V_k = int_model[()]
\ No newline at end of file
diff --git a/codes/utils.py b/codes/utils.py
index 442437d..a1d7c1a 100644
--- a/codes/utils.py
+++ b/codes/utils.py
@@ -229,6 +229,26 @@ def kgrid_hamiltonian(nk, hk, dim, return_ks=False, hermitian=True):
         return ham.reshape(*shape), ks
     else:
         return ham.reshape(*shape)
+    
+
+def tb2grid(tb_model, nk):
+    """
+    Fourier transforms and evaluates the model on a regular k-point grid.
+    
+    Parameters
+    ----------
+    tb_model : dict
+        Tight-binding model.
+    nk : int
+        Number of k-points per dimension.
+    
+    Returns
+    -------
+    H_k : nd-array
+        Model evaluated on a k-point grid.
+    """
+    dim = len([*tb_model.keys()][0])
+    return kgrid_hamiltonian(nk, model2hk(tb_model), dim)
 
 
 def build_interacting_syst(builder, lattice, func_onsite, func_hop, max_neighbor=1):
-- 
GitLab