Skip to content

Commit

Permalink
fixed examples
Browse files Browse the repository at this point in the history
  • Loading branch information
freude committed Jun 22, 2020
1 parent 3d2a186 commit ae6e48a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 86 deletions.
88 changes: 16 additions & 72 deletions examples/si_nw_band_structure.py
Original file line number Diff line number Diff line change
@@ -1,103 +1,47 @@
"""
This example demonstrates calculation of the band structure
for the silicon nanowire using a direct matrix diagonalization method.
"""
import numpy as np
from nanonet.tb import HamiltonianSp
from nanonet.tb import Orbitals
from nanonet.tb.plotting import plot_bs_split, plot_atom_positions


def radial_dep(coords):
norm_of_coords = np.linalg.norm(coords)
print(norm_of_coords)
if norm_of_coords < 3.3:
return 1
elif 3.7 > norm_of_coords > 3.3:
return 2
elif 5.0 > norm_of_coords > 3.7:
return 3
else:
return 100



def main():
"""
This function computes the band gap / band structure for Silicon Nanowire
:param path: directory path to where xyz input files are stored
:param flag: boolean statements
:return: band gap / band structure
"""
# define orbitals sets
# use a predefined basis sets
Orbitals.orbital_sets = {'Si': 'SiliconSP3D5S', 'H': 'HydrogenS'}
band_gaps = []
band_structures = []

# specify atomic coordinates file in xyz format
path = "input_samples/SiNW2.xyz"
# path = "tb/third_party/si_slab.xyz"

# hamiltonian = Hamiltonian(xyz=path, nn_distance=1.1, lead_l=[[0, 0, 1]], lead_r=[[0, 4, 3]], so_coupling=0.06)

right_lead = [0, 33, 35, 17, 16, 51, 25, 9, 53, 68, 1, 8, 24]
left_lead = [40, 66, 58, 47, 48, 71, 72, 73, 74, 65]

def sorting(coords, **kwargs):
return np.argsort(coords[:, 2])

from nanonet.tb.sorting_algorithms import sort_projection as sorting

hamiltonian = HamiltonianSp(xyz=path, nn_distance=2.4,
sort_func=sorting, left_lead=left_lead, right_lead=right_lead)
# define Hamiltonian object in the sparse format
hamiltonian = HamiltonianSp(xyz=path, nn_distance=2.4,)
hamiltonian.initialize()

# if True:
# plt.axis('off')
# plt.imshow(np.log(np.abs(hamiltonian.h_matrix)))
# plt.savefig('hamiltonian.pdf')
# plt.show()

# from tb.aux_functions import split_into_subblocks
# a, b = blocksandborders(hamiltonian.h_matrix)

# bandwidth(hamiltonian.h_matrix)

# import scipy.spatial
# from scipy import sparse
# h_matrix_sparse = sparse.csr_matrix(hamiltonian.h_matrix)
# a = scipy.sparse.csgraph.reverse_cuthill_mckee(h_matrix_sparse, symmetric_mode=True)
# h_matrix1 = hamiltonian.h_matrix[:, a]
# h_matrix1 = h_matrix1[a, :]
#
# bandwidth(h_matrix1)

# set periodic boundary conditions
a_si = 5.50
PRIMITIVE_CELL = [[0, 0, a_si]]
hamiltonian.set_periodic_bc(PRIMITIVE_CELL)

hl, h0, hr = hamiltonian.get_hamiltonians()
hl, h0, hr, _ = hamiltonian.get_hamiltonians_block_tridiagonal()

# define wave vector coordinates
num_points = 20
kk = np.linspace(0, 0.57, num_points, endpoint=True)

# compute band structure
band_structure = []

for jj in range(num_points):
print(jj)
print("{}. Processing wave vector {}".format(jj, [0, 0, kk[jj]]))
vals, _ = hamiltonian.diagonalize_periodic_bc([0, 0, kk[jj]])
band_structure.append(vals)

# visualize
band_structure = np.array(band_structure)
band_structures.append(band_structure)

cba = band_structure.copy()
vba = band_structure.copy()

cba[cba < 0] = 1000
vba[vba > 0] = -1000

band_gap = np.min(cba) - np.max(vba)
band_gaps.append(band_gap)

if True:
plot_bs_split(kk, vba, cba)
cba[cba < 0] = np.inf
vba[vba > 0] = -np.inf
plot_bs_split(kk, vba, cba)


if __name__ == '__main__':
Expand Down
15 changes: 1 addition & 14 deletions examples/si_nw_transmission.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import matplotlib.pyplot as plt
from nanonet.tb import Hamiltonian, HamiltonianSp
from nanonet.tb import Orbitals
from nanonet.tb.plotting import plot_bs_split, plot_atom_positions
from nanonet.tb.sorting_algorithms import sort_projection


def radial_dep(coords):
Expand All @@ -22,27 +22,14 @@ def radial_dep(coords):


def main():
"""
This function computes the band gap / band structure for Silicon Nanowire
:param path: directory path to where xyz input files are stored
:param flag: boolean statements
:return: band gap / band structure
"""
# define orbitals sets
Orbitals.orbital_sets = {'Si': 'SiliconSP3D5S', 'H': 'HydrogenS'}

path = "input_samples/SiNW2.xyz"

# hamiltonian = Hamiltonian(xyz=path, nn_distance=1.1, lead_l=[[0, 0, 1]], lead_r=[[0, 4, 3]], so_coupling=0.06)

right_lead = [0, 33, 35, 17, 16, 51, 25, 9, 53, 68, 1, 8, 24]
left_lead = [40, 66, 58, 47, 48, 71, 72, 73, 74, 65]

def sorting(coords, **kwargs):
return np.argsort(coords[:, 2])

from nanonet.tb.sorting_algorithms import sort_projection

start = time.time()
hamiltonian = Hamiltonian(xyz=path, nn_distance=2.4, sort_func=sort_projection, left_lead=left_lead, right_lead=right_lead)
hamiltonian.initialize()
Expand Down

0 comments on commit ae6e48a

Please sign in to comment.