Skip to content

Commit

Permalink
implemented ability to set several nn_distances instead of int_dist_func
Browse files Browse the repository at this point in the history
  • Loading branch information
freude committed May 21, 2021
1 parent 05c7db3 commit c7a37cd
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 26 deletions.
4 changes: 2 additions & 2 deletions examples/bi_bulk.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ def main():
set_tb_params(PARAMS_BI_BI1=PAR1, PARAMS_BI_BI2=PAR2, PARAMS_BI_BI3=PAR3)

# compute Hamiltonian matrices
h = Hamiltonian(xyz=path_to_xyz_file, nn_distance=4.6, so_coupling=1.5)
h.initialize(radial_dep)
h = Hamiltonian(xyz=path_to_xyz_file, nn_distance=[3.3, 3.7, 4.6], so_coupling=1.5)
h.initialize()
h.set_periodic_bc(primitive_cell)

# define wave vectors
Expand Down
76 changes: 52 additions & 24 deletions nanonet/tb/hamiltonian.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,20 @@ class Hamiltonian(BasisTB):
"""

def __init__(self, **kwargs):
"""
Parameters
----------
nn_distance : float, list
Nearest neighbour distance of distances
if the tight-binding method is beyond the first-nearest neighbour approximation (Default value = 2.39)
radial_dep : func
Radial dependence function (Default value = None)
"""

nn_distance = kwargs.get('nn_distance', 2.39)
self.int_radial_dependence = None
nn_distance = self._set_nn_distances(nn_distance)
self.compute_overlap = kwargs.get('comp_overlap', False)
self.compute_angular = kwargs.get('comp_angular_dep', True)

Expand Down Expand Up @@ -193,24 +205,9 @@ def __init__(self, **kwargs):
self.k_vector = 0 # default value of the wave vector
self.ct = None
self.radial_dependence = None
self.int_radial_dependence = None
self.so_coupling = kwargs.get('so_coupling', 0.0)

def initialize(self, int_radial_dep=None, radial_dep=None):
"""Compute matrix elements of the Hamiltonian.
Parameters
----------
int_radial_dep : func
Integer radial dependence function (Default value = None)
radial_dep : func
Radial dependence function (Default value = None)
Returns
-------
type Hamiltonian
Returns the instance of the class Hamiltonian
"""
radial_dep = kwargs.get('radial_dep', None)

if radial_dep is None:
logging.info('Radial dependence function: None')
Expand All @@ -219,15 +216,16 @@ def initialize(self, int_radial_dep=None, radial_dep=None):
logging.info('Radial dependence function:\n\n{}'.format(inspect.getsource(radial_dep)))
logging.info("\n---------------------------------\n")

if int_radial_dep is None:
logging.info('Discrete radial dependence function: None')
logging.info("\n---------------------------------\n")
else:
logging.info('Discrete radial dependence function:\n\n{}'.format(inspect.getsource(int_radial_dep)))
logging.info("\n---------------------------------\n")

self.radial_dependence = radial_dep
self.int_radial_dependence = int_radial_dep

def initialize(self):
"""Compute matrix elements of the Hamiltonian.
Returns
-------
type Hamiltonian
Returns the instance of the class Hamiltonian
"""

self._coords = [0 for _ in range(self.basis_size)]
# initialize Hamiltonian matrices
Expand Down Expand Up @@ -348,6 +346,36 @@ def diagonalize_periodic_bc(self, k_vector):

return vals[ind], vects[:, ind]

def _set_nn_distances(self, nn_dist):
if nn_dist is not None:
if isinstance(nn_dist, list):
logging.info('{} nearest neighbour interactions are taken into account.'.format(len(nn_dist)))
logging.info("\n---------------------------------\n")
nn_dist.sort()
self._nn_distance = nn_dist[-1]

def int_radial_dep(coords):
"""
Step-wise radial dependence function
"""
norm_of_coords = np.linalg.norm(coords)

ans = sum([norm_of_coords > item for item in nn_dist]) + 1

if norm_of_coords > nn_dist[-1]:
return 100
else:
return ans

self.int_radial_dependence = int_radial_dep
else:
self._nn_distance = nn_dist
else:
logging.info('The first nearest-neighbour approximation is used.')
logging.info("\n---------------------------------\n")

return self._nn_distance

def _ind2atom(self, ind):
"""
Expand Down

0 comments on commit c7a37cd

Please sign in to comment.