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

Poisson-dev and support for BTD and Overlap Matrix in NEGF #105

Open
wants to merge 191 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
191 commits
Select commit Hold shift + click to select a range
b76735f
create poisson_grid_init.py
AsymmetryChou Jan 4, 2024
1f05ecf
add init to grid
AsymmetryChou Jan 4, 2024
5eaad71
add find_atom_index
AsymmetryChou Jan 4, 2024
e8a78a0
add interface3D class
AsymmetryChou Jan 5, 2024
a505c4a
add gate potential and boundary_potential
AsymmetryChou Jan 5, 2024
4ec3d0f
add contents to interface3D
AsymmetryChou Jan 8, 2024
66b7c3b
rename poisson_gird_init to poisson_init
AsymmetryChou Jan 8, 2024
a4891ba
add region definition to gate and medium
AsymmetryChou Jan 8, 2024
d4a7000
add grid-point surface along x-axis
AsymmetryChou Jan 8, 2024
2b19aa1
add surface_grid
AsymmetryChou Jan 9, 2024
10b28d8
add flux terms
AsymmetryChou Jan 9, 2024
7800d51
add func construction_poisson
AsymmetryChou Jan 9, 2024
9ee0d25
add poisson_scf.py
AsymmetryChou Jan 9, 2024
223ec7e
add vbias term to device_preperty.py
AsymmetryChou Jan 9, 2024
2d12aaa
rename Dielectric
AsymmetryChou Jan 9, 2024
1c7643f
add poisson_negf_scf to NEGF.py
AsymmetryChou Jan 9, 2024
b29e137
find potential on each atom gird through atom_index_dict
AsymmetryChou Jan 9, 2024
4734746
add update electron density for solving Poisson equation in poisson_…
AsymmetryChou Jan 9, 2024
69f48d7
add scf break operation in poisson_negf_scf
AsymmetryChou Jan 9, 2024
79ddcc2
add negf_compute in the final part of poisson_negf_scf
AsymmetryChou Jan 9, 2024
0cd5be3
add poisson related json and read operation in NEGF
AsymmetryChou Jan 10, 2024
5d0c2e6
add eps0 in unit of F/Angstrom
AsymmetryChou Jan 10, 2024
a61c0ae
delete poisson_scf.py, which has been added to NEGF.py
AsymmetryChou Jan 10, 2024
161e396
clean import
AsymmetryChou Jan 11, 2024
c4b1e77
fix import issue and str2float in gate and dieelctric definition
AsymmetryChou Jan 12, 2024
4d18843
add argcheck for gate and dielectric
AsymmetryChou Jan 12, 2024
800264b
add grid
AsymmetryChou Jan 12, 2024
06779b9
update for run
AsymmetryChou Jan 12, 2024
281a217
fix pyamg_solver.solve bug
AsymmetryChou Jan 12, 2024
a5ed3ec
add tolerance et. to argcheck.py
AsymmetryChou Jan 12, 2024
10dbc2b
add some comments in NEGF.py and poisson_init
AsymmetryChou Jan 22, 2024
4574667
update poisson_negf_scf
AsymmetryChou Jan 23, 2024
565af97
update negf_compute
AsymmetryChou Jan 23, 2024
f326a0e
update NEGF.py and poisson_init.py
AsymmetryChou Jan 24, 2024
eb7b492
update density.py
AsymmetryChou Jan 24, 2024
6ed2bb9
update device_property.py
AsymmetryChou Jan 24, 2024
3ba5b13
find the bug calculating different kpoints but get same result
AsymmetryChou Jan 24, 2024
0f156ce
add newK_flag and newV_flag
AsymmetryChou Jan 24, 2024
616a200
add comments
AsymmetryChou Jan 24, 2024
3603b7b
make Hartree2eV unit constant the same as that for dptb-negf
AsymmetryChou Jan 25, 2024
ef21a12
fix self energy transpose in lead_property.py
AsymmetryChou Feb 1, 2024
947eb57
update NEGF.py
AsymmetryChou Mar 7, 2024
2aa9081
update density.py
AsymmetryChou Mar 7, 2024
8f4790c
update device_property.py
AsymmetryChou Mar 7, 2024
363d8d2
update lead_property.py
AsymmetryChou Mar 7, 2024
27e1ebb
add notes in lead_property.py
AsymmetryChou Mar 7, 2024
567a57a
update negf_hamiltonian_init.py
AsymmetryChou Mar 7, 2024
3cd8a8b
update a series of py files in negf, including poisson_init.py
AsymmetryChou Mar 7, 2024
98197fd
update recursive_green_cal.py
AsymmetryChou Mar 7, 2024
aab802e
update surface_green.py
AsymmetryChou Mar 7, 2024
fc9090d
update argcheck.py
AsymmetryChou Mar 7, 2024
67da37b
add abs to formula powerlaw
AsymmetryChou Mar 11, 2024
921d116
simplify real-space gird setting
AsymmetryChou Mar 11, 2024
a74f3a2
simplify boundary_points_get in poisson_init.py
AsymmetryChou Mar 11, 2024
a85e9d0
update interface class initialization
AsymmetryChou Mar 11, 2024
d22f36e
change gate to dielectric
AsymmetryChou Mar 11, 2024
eeb552a
add some notes
AsymmetryChou Mar 11, 2024
f852edd
seperate scipy and pyamg clearer
AsymmetryChou Mar 11, 2024
f1363a8
transform csr to lil when attribtue values
AsymmetryChou Mar 11, 2024
1508c58
combine construct_Jac and construct_B to a func
AsymmetryChou Mar 11, 2024
ce734a0
simplify the code for boundary conditions
AsymmetryChou Mar 11, 2024
c1699d1
change sign from hLL+v*sLL to hLL-v*sLL
AsymmetryChou Mar 12, 2024
cb77077
remove unnecessary codes in poisson_init.py
AsymmetryChou Mar 12, 2024
7a5c0e4
simplify solve_poisson_NRcycle in poisson_init.py
AsymmetryChou Mar 12, 2024
0c2f7ab
add proffiler in NEGF.py
AsymmetryChou Mar 12, 2024
5a91788
replace print by log.info
AsymmetryChou Mar 12, 2024
f3e81f9
get_hs_lead only when voltage changes
AsymmetryChou Mar 12, 2024
469a94b
move print to log
AsymmetryChou Mar 12, 2024
c1dd88a
log info update
AsymmetryChou Mar 12, 2024
a669274
simplify NEGF.py
AsymmetryChou Mar 13, 2024
cee3dd6
move Fiori cal to density.py and simplify negf_compute
AsymmetryChou Mar 13, 2024
d6449f9
add gauss integrate to Fiori method
AsymmetryChou Mar 13, 2024
7c76568
merge Fiori_gauss and Fiori_direct together
AsymmetryChou Mar 13, 2024
13c4cf0
test
AsymmetryChou Mar 14, 2024
febcfa8
update density.py device_property.py lead_property.py for ksum
AsymmetryChou Mar 15, 2024
3d3386a
update negf_hamiltonian_init.py for ksum
AsymmetryChou Mar 15, 2024
72bfd7e
update unit tests for ksum and poisson-dev
AsymmetryChou Mar 16, 2024
9ae78d4
update for ksum in poisson_dev
AsymmetryChou Mar 16, 2024
8595628
add atom_cor and gird_cor consistency check
AsymmetryChou Mar 20, 2024
892e345
add loginfo for k-point in NEGF.py
AsymmetryChou Apr 1, 2024
6916c69
Merge branch 'main' into poisson-dev
AsymmetryChou Apr 1, 2024
c3a5fdc
add structure for tbtrans
AsymmetryChou Apr 1, 2024
e57453e
copy some test files from v1
AsymmetryChou Apr 1, 2024
a599a67
update NEGF.py init
AsymmetryChou Apr 1, 2024
0566f15
move AtomicData creator to negf_hamiltonian_init.py
AsymmetryChou Apr 1, 2024
3880128
modify init of negf_hamiltonian_init.py
AsymmetryChou Apr 1, 2024
519285f
add self.e3H in negf_hamiltonian_init.py
AsymmetryChou Apr 2, 2024
73ac9be
add notes
AsymmetryChou Apr 3, 2024
7b36d50
add atom_norb in hr2hk
AsymmetryChou Apr 4, 2024
0e9595b
update NEGFHamiltonianInit initialize part for new api
AsymmetryChou Apr 4, 2024
006c097
add pbc_negf in NEGFHamiltonianInit init
AsymmetryChou Apr 4, 2024
b56b6f6
modify pbc setting in device/lead
AsymmetryChou Apr 8, 2024
491ecb0
add dptb/data/try_test.ipynb to gitignore
AsymmetryChou Apr 8, 2024
a38a658
Merge branch 'main' into poisson-dev
AsymmetryChou Apr 9, 2024
8d4a33d
add test data for negf
AsymmetryChou Apr 11, 2024
00848ec
fix api for device_property and density_Ozaki
AsymmetryChou Apr 11, 2024
c6d4533
fix hamilotonian_init temporarily
AsymmetryChou Apr 11, 2024
c37c533
Merge branch 'main' into poisson-dev
AsymmetryChou Apr 11, 2024
5a5acfa
add pyamg() and scipy() in argcheck
AsymmetryChou Apr 11, 2024
516e527
add soc in test_negf input
AsymmetryChou Apr 11, 2024
81a1b84
add new model update to test_tbtrans_init.py temporarily
AsymmetryChou Apr 11, 2024
d98b591
comment import from tbtrans_init temporarily
AsymmetryChou Apr 11, 2024
560031f
modify test_tbtrans files for v2
AsymmetryChou Apr 11, 2024
78eb02a
update test_negf_hamiltonian_init.py
AsymmetryChou Apr 11, 2024
5fd133a
modify test_negf_device_property
AsymmetryChou Apr 11, 2024
b3c7da9
add h_device compare
AsymmetryChou Apr 11, 2024
b7b2659
update negf_hamiltonian_init
AsymmetryChou Apr 11, 2024
dcd6054
add print ldos in test_negf_device_property
AsymmetryChou Apr 13, 2024
5546799
add eta_lead option in density_integrate_Fiori
AsymmetryChou Apr 13, 2024
0466ba0
modify pbc and add dtype float 64 in negf_hamiltonian_init.py
AsymmetryChou Apr 13, 2024
2458130
add TODO comment in negf_hamitonian_init
AsymmetryChou Apr 13, 2024
732453a
add some comments
AsymmetryChou Apr 13, 2024
e0ad0d1
rename path
AsymmetryChou Apr 13, 2024
03e3750
force test for negf in float64
AsymmetryChou Apr 13, 2024
b83a1bd
add test files for negf
AsymmetryChou Apr 13, 2024
de8f9b9
Merge branch 'main' into poisson-dev
AsymmetryChou Apr 13, 2024
e0afd0c
add task negf option in run.py
AsymmetryChou Apr 15, 2024
34e7812
set torch default float32 after extract H and S
AsymmetryChou Apr 15, 2024
c4a9f6b
update test_negf_run.py for v2
AsymmetryChou Apr 15, 2024
5d71a83
add sort_btd.py and split_btd.py
AsymmetryChou Apr 15, 2024
826cb98
add tbtrans_init in run.py
AsymmetryChou Apr 15, 2024
654ac7c
Merge branch 'main' into poisson-dev
AsymmetryChou Apr 15, 2024
b0eff44
add tbtrans_init in run.py and modify tbtrans_init.py
AsymmetryChou Apr 16, 2024
5067295
add unit test for tbtrans
AsymmetryChou Apr 16, 2024
db076ee
add btd term in test_negf*
AsymmetryChou Apr 16, 2024
dc737c8
fix pyamg import error
AsymmetryChou Apr 16, 2024
6d2ef8f
update docstring in tbtrans_init
AsymmetryChou Apr 16, 2024
e48fa82
rename some variables
AsymmetryChou Apr 21, 2024
5490bed
add BTD
AsymmetryChou Apr 22, 2024
abff5e5
fix gitignore
AsymmetryChou Apr 22, 2024
07186d6
Merge branch 'main' into poisson-dev
AsymmetryChou Apr 22, 2024
9bbe6d7
fix pyinstrument import probelm in pytest
AsymmetryChou Apr 22, 2024
031c441
fix pyinstrument import in pytest
AsymmetryChou Apr 23, 2024
cdfbba0
write code in negf_hamiltonian_init in compact form
AsymmetryChou Apr 23, 2024
7854c93
fix overlap Bool input probelm
AsymmetryChou Apr 23, 2024
dd52834
fix ldos and dos bug for BTD form
AsymmetryChou Apr 23, 2024
4fff7e4
add list for pbc setting in AtomicData_options
AsymmetryChou Apr 24, 2024
bb89909
fix ldos and dos when length of up and down blocklist equals 0
AsymmetryChou Apr 24, 2024
2659506
remove unnecessary n_proj_atom_pre variables
AsymmetryChou Apr 24, 2024
2049d18
fix energy setting problem in selfenergy calculation
AsymmetryChou Apr 24, 2024
e205662
add test files for negf with overlap
AsymmetryChou Apr 24, 2024
c1e09a4
add test_negf_hamiltonian_init file
AsymmetryChou Apr 24, 2024
1268160
remove unnecssary band.json
AsymmetryChou Apr 24, 2024
a5a7998
add .gitkeep in directory
AsymmetryChou Apr 24, 2024
f45a112
Merge branch 'main' into poisson-dev
AsymmetryChou Apr 24, 2024
8664b19
add poisson options in argcheck
AsymmetryChou Apr 26, 2024
533df92
small fix
AsymmetryChou Apr 28, 2024
232b7dd
fix Vbias setting caused in sorting when using BTD
AsymmetryChou Apr 29, 2024
d0bc15e
update uni_test
AsymmetryChou Apr 29, 2024
fb39b19
fix bugs and keep dptb-Poisson SCF same as that in NanoTCAD restrictly.
AsymmetryChou Apr 30, 2024
1f4f4f5
update density calculation with BTD and non-BTD consistent with NanoTCAD
AsymmetryChou Apr 30, 2024
829903e
Merge branch 'main' into poisson-dev
AsymmetryChou Apr 30, 2024
b81c6c0
update test files
AsymmetryChou Apr 30, 2024
476c91e
Merge branch 'main' into poisson-dev
AsymmetryChou May 1, 2024
f02fd27
add show_blocks in BTD mode
AsymmetryChou May 1, 2024
e7a9350
Merge branch 'main' into poisson-dev
AsymmetryChou May 7, 2024
156968b
fix complex warning
AsymmetryChou May 7, 2024
b25ff1f
Merge branch 'main' into poisson-dev
AsymmetryChou May 8, 2024
b8d3745
add DFTB+ band plot tool
AsymmetryChou May 10, 2024
062b1f1
fix Fiori import error when integrate way is direct
AsymmetryChou May 14, 2024
2232c19
fix kpoints as nested_tensor form
AsymmetryChou May 28, 2024
2488d9f
Merge branch 'main' into poisson-dev
AsymmetryChou May 28, 2024
954debb
fix Fiori n_gauss import bug
AsymmetryChou May 28, 2024
d909a4e
recover NEGF related files
AsymmetryChou Jun 13, 2024
46a43fc
Merge branch 'main' into poisson-dev
AsymmetryChou Jun 13, 2024
87a2929
Merge branch 'poisson-dev' of https://github.com/AsymmetryChou/DeePTB…
AsymmetryChou Jun 13, 2024
f902f18
update try_bloch.ipynb
AsymmetryChou Jun 13, 2024
3d221db
Merge branch 'main' into poisson-dev
AsymmetryChou Jun 16, 2024
3d5bbcb
Merge branch 'main' into poisson-dev
AsymmetryChou Jun 20, 2024
ae7d878
add Bloch theorem in NEGF module to accelarate self-energy calculation
AsymmetryChou Jun 24, 2024
aab1706
fix bloch-fold self energy calculation bug and run successfully
AsymmetryChou Jun 26, 2024
4212602
set dtype as float64 for unittest
AsymmetryChou Jun 26, 2024
9795811
update try_bloch.ipynb
AsymmetryChou Jun 26, 2024
3157cbd
support useBloch and bloch_factor in json format
AsymmetryChou Jun 26, 2024
4395019
add onsite_shift in loss.py HamilLossAnalysis
AsymmetryChou Jun 27, 2024
b124a93
fix useBloch bug in NEGF.py
AsymmetryChou Jun 27, 2024
174f0a2
fix sort_indices bug in get_lead_structure
AsymmetryChou Jun 28, 2024
d9c707b
Merge branch 'main' into poisson-dev
AsymmetryChou Aug 27, 2024
ac3f2ef
update files for bloch-self-energy in unittest
AsymmetryChou Aug 27, 2024
3ecc157
update unittest files for hamiltonian.initialize's update
AsymmetryChou Aug 27, 2024
dd4acfb
use rmse as check standard in comparing HK_lead
AsymmetryChou Aug 28, 2024
482e7e1
remove self energy saver temporarily
AsymmetryChou Aug 28, 2024
06d5443
fix pbc bug to accomdate the removing of pbc in AtomicData_options
AsymmetryChou Aug 28, 2024
8748b24
remove pbc output
AsymmetryChou Aug 28, 2024
1dbdbec
add overlap output in feature_to_block
AsymmetryChou Aug 28, 2024
633d540
set rmse_l_HK/SK as 0 when using Block
AsymmetryChou Aug 29, 2024
566d02f
Merge branch 'main' into poisson-dev
AsymmetryChou Sep 21, 2024
cdc7fd5
add block_tridiagonal in compute_density_Ozaki
AsymmetryChou Sep 28, 2024
6cf54c2
add block_tri in deviceprop.cal_green_function
AsymmetryChou Oct 11, 2024
c55db1b
Merge branch 'main' into poisson-dev
AsymmetryChou Oct 11, 2024
24b6f87
update NEGF.py for poisson-NEGF SCF
AsymmetryChou Oct 20, 2024
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
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ dptb/tests/data/test_all/checkpoint/best_nnsk_b5.000_c6.615_w0.265.json
dptb/tests/data/test_all/checkpoint/best_nnsk_b4.000_c4.000_w0.300.json
dptb/tests/data/test_all/fancy_ones/checkpoint/best_nnsk_b4.000_c4.000_w0.300.json
dptb/tests/data/test_negf/test_negf_run/out_negf/run_config.json
dptb/data/try_test.ipynb
dptb/negf/check.ipynb
dptb/tests/data/test_negf/show.ipynb
dptb/tests/data/test_tbtrans/show.ipynb
run_config.json
dptb/nnet/__pycache__/
dptb/sktb/__pycache__/
Expand Down Expand Up @@ -172,3 +176,6 @@ dmypy.json
_date.py
_version.py
/.idea/



49 changes: 48 additions & 1 deletion dptb/entrypoints/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,15 @@
from dptb.utils.argcheck import normalize_run
from dptb.utils.tools import j_loader
from dptb.utils.tools import j_must_have
from dptb.postprocess.NEGF import NEGF
from dptb.postprocess.tbtrans_init import TBTransInputSet,sisl_installed

# from dptb.postprocess.write_ham import write_ham
from dptb.postprocess.write_block import write_block
import torch
import h5py


log = logging.getLogger(__name__)

def run(
Expand Down Expand Up @@ -87,6 +92,48 @@ def run(
emax=jdata["task_options"].get("emax", None))
log.info(msg='band calculation successfully completed.')

elif task=='negf':

# try:
# from pyinstrument import Profiler
# except ImportWarning:
# log.warning(msg="pyinstrument is not installed, no profiling will be done.")
# Profiler = None
# if Profiler is not None:
# profiler = Profiler()
# profiler.start()

negf = NEGF(
model=model,
AtomicData_options=jdata['AtomicData_options'],
structure=structure,
results_path=results_path,
**task_options
)

negf.compute()
log.info(msg='negf calculation successfully completed.')

# if Profiler is not None:
# profiler.stop()
# with open(results_path+'/profile_report.html', 'w') as report_file:
# report_file.write(profiler.output_html())

elif task == 'tbtrans_negf':
if not(sisl_installed):
log.error(msg="sisl is required to perform tbtrans calculation !")
raise RuntimeError
basis_dict = json.load(open(init_model))['common_options']['basis']
tbtrans_init = TBTransInputSet(
model=model,
AtomicData_options=jdata['AtomicData_options'],
structure=structure,
basis_dict=basis_dict,
results_path=results_path,
**task_options)
tbtrans_init.hamil_get_write(write_nc=True)
log.info(msg='TBtrans input files are successfully generated.')

elif task=='write_block':
task = torch.load(init_model, map_location="cpu")["task"]
block = write_block(data=struct_file, AtomicData_options=jdata['AtomicData_options'], model=model, device=jdata["device"])
Expand All @@ -95,4 +142,4 @@ def run(
default_group = fid.create_group("0")
for key_str, value in block.items():
default_group[key_str] = value.detach().cpu().numpy()
log.info(msg='write block successfully completed.')
log.info(msg='write block successfully completed.')
26 changes: 26 additions & 0 deletions dptb/negf/bloch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

import numpy as np


class Bloch(object):
def __init__(self,bloch_factor) -> None:

if isinstance(bloch_factor,list):
bloch_factor = np.array(bloch_factor)

assert bloch_factor.shape[0] == 3, "kpoint should be a 3D vector"
self.bloch_factor = bloch_factor


def unfold_points(self,k):


# Create expansion points
B = self.bloch_factor
unfold = np.empty([B[2], B[1], B[0], 3])
# Use B-casting rules (much simpler)
unfold[:, :, :, 0] = (np.arange(B[0]).reshape(1, 1, -1) + k[0]) / B[0]
unfold[:, :, :, 1] = (np.arange(B[1]).reshape(1, -1, 1) + k[1]) / B[1]
unfold[:, :, :, 2] = (np.arange(B[2]).reshape(-1, 1, 1) + k[2]) / B[2]
# Back-transform shape
return unfold.reshape(-1, 3)
209 changes: 204 additions & 5 deletions dptb/negf/density.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def __init__(self, R, M_cut, n_gauss):
self.R = R
self.n_gauss = n_gauss

def integrate(self, deviceprop, kpoint, eta_lead=1e-5, eta_device=0.):
def integrate(self, deviceprop, kpoint, eta_lead=1e-5, eta_device=0.,Vbias=None,block_tridiagonal=False):
'''calculates the equilibrium and non-equilibrium density matrices for a given k-point.

Parameters
Expand All @@ -166,13 +166,15 @@ def integrate(self, deviceprop, kpoint, eta_lead=1e-5, eta_device=0.):
poles = 1j* self.poles * kBT + deviceprop.lead_L.mu - deviceprop.mu # left lead expression for rho_eq
deviceprop.lead_L.self_energy(kpoint=kpoint, energy=1j*self.R-deviceprop.mu)
deviceprop.lead_R.self_energy(kpoint=kpoint, energy=1j*self.R-deviceprop.mu)
deviceprop.cal_green_function(energy=1j*self.R-deviceprop.mu, kpoint=kpoint, block_tridiagonal=False)
deviceprop.cal_green_function(energy=1j*self.R-deviceprop.mu, kpoint=kpoint, block_tridiagonal=block_tridiagonal,
Vbias = Vbias)
g0 = deviceprop.grd[0]
DM_eq = 1.0j * self.R * g0
for i, e in enumerate(poles):
deviceprop.lead_L.self_energy(kpoint=kpoint, energy=e, eta_lead=eta_lead)
deviceprop.lead_R.self_energy(kpoint=kpoint, energy=e, eta_lead=eta_lead)
deviceprop.cal_green_function(energy=e, kpoint=kpoint, block_tridiagonal=False, eta_device=eta_device)
deviceprop.cal_green_function(energy=e, kpoint=kpoint, block_tridiagonal=block_tridiagonal, eta_device=eta_device,\
Vbias = Vbias)
term = ((-4 * 1j * kBT) * deviceprop.grd[0] * self.residues[i]).imag
DM_eq -= term

Expand All @@ -187,7 +189,7 @@ def integrate(self, deviceprop, kpoint, eta_lead=1e-5, eta_device=0.):
for i, e in enumerate(xs):
deviceprop.lead_L.self_energy(kpoint=kpoint, energy=e, eta_lead=eta_lead)
deviceprop.lead_R.self_energy(kpoint=kpoint, energy=e, eta_lead=eta_lead)
deviceprop.cal_green_function(e=e, kpoint=kpoint, block_tridiagonal=False, eta_device=eta_device)
deviceprop.cal_green_function(energy=e, kpoint=kpoint, block_tridiagonal=block_tridiagonal, eta_device=eta_device)
gr_gamma_ga = torch.mm(torch.mm(deviceprop.grd[0], deviceprop.lead_R.gamma), deviceprop.grd[0].conj().T).real
gr_gamma_ga = gr_gamma_ga * (deviceprop.lead_R.fermi_dirac(e+deviceprop.mu) - deviceprop.lead_L.fermi_dirac(e+deviceprop.mu))
DM_neq = DM_neq + wlg[i] * gr_gamma_ga
Expand Down Expand Up @@ -225,4 +227,201 @@ def get_density_onsite(self, deviceprop, DM):

onsite_density = torch.cat([torch.from_numpy(deviceprop.structure.positions), onsite_density.unsqueeze(-1)], dim=-1)

return onsite_density
return onsite_density



class Fiori(Density):

def __init__(self, n_gauss=None):
super(Fiori, self).__init__()
self.n_gauss = n_gauss
self.xs = None
self.wlg = None
self.e_grid_Fiori = None

def density_integrate_Fiori(self,e_grid,kpoint,Vbias,block_tridiagonal,subblocks,integrate_way,deviceprop,
device_atom_norbs,potential_at_atom,free_charge,
eta_lead=1e-5, eta_device=1e-5):
if integrate_way == "gauss":
assert self.n_gauss is not None, "n_gauss must be set in the Fiori class"
if self.xs is None:
self.xs, self.wlg = gauss_xw(xl=torch.scalar_tensor(e_grid[0]), xu=torch.scalar_tensor(e_grid[-1]), n=self.n_gauss)
# self.xs = self.xs.numpy();self.wlg = self.wlg.numpy()
self.e_grid_Fiori = e_grid
elif self.e_grid_Fiori[0] != e_grid[0] or self.e_grid_Fiori[-1] != e_grid[-1]:
self.xs, self.wlg = gauss_xw(xl=torch.scalar_tensor(e_grid[0]), xu=torch.scalar_tensor(e_grid[-1]), n=self.n_gauss)
# self.xs = self.xs.numpy();self.wlg = self.wlg.numpy()
self.e_grid_Fiori = e_grid
integrate_range = self.xs
pre_factor = self.wlg
elif integrate_way == "direct":
dE = e_grid[1] - e_grid[0]
integrate_range = e_grid
pre_factor = dE * torch.ones(len(e_grid))
else:
raise ValueError("integrate_way only supports gauss and direct in this version")



for eidx, e in enumerate(integrate_range):
deviceprop.lead_L.self_energy(kpoint=kpoint, energy=e, eta_lead=eta_lead)
deviceprop.lead_R.self_energy(kpoint=kpoint, energy=e, eta_lead=eta_lead)
deviceprop.cal_green_function(energy=e, kpoint=kpoint, block_tridiagonal=block_tridiagonal, eta_device=eta_device,Vbias = Vbias)

tx, ty = deviceprop.g_trans.shape
lx, ly = deviceprop.lead_L.se.shape
rx, ry = deviceprop.lead_R.se.shape
x0 = min(lx, tx)
x1 = min(rx, ty)

gammaL = torch.zeros(size=(tx, tx), dtype=torch.complex128)
gammaL[:x0, :x0] += deviceprop.lead_L.gamma[:x0, :x0]
gammaR = torch.zeros(size=(ty, ty), dtype=torch.complex128)
gammaR[-x1:, -x1:] += deviceprop.lead_R.gamma[-x1:, -x1:]

if not block_tridiagonal:
A_Rd = [torch.mm(torch.mm(deviceprop.grd[i],gammaR),deviceprop.grd[i].conj().T) for i in range(len(deviceprop.grd))]
else:
A_Rd = [torch.mm(torch.mm(deviceprop.gr_lc[i],gammaR[-x1:, -x1:]),deviceprop.gr_lc[i].conj().T) for i in range(len(deviceprop.gr_lc))]

A_Ld = [1j*(deviceprop.grd[i]-deviceprop.grd[i].conj().T)-A_Rd[i] for i in range(len(A_Rd))]
gnd = [A_Ld[i]*deviceprop.lead_L.fermi_dirac(e+deviceprop.lead_L.efermi) \
+A_Rd[i]*deviceprop.lead_R.fermi_dirac(e+deviceprop.lead_R.efermi) for i in range(len(A_Ld))]
gpd = [A_Ld[i] + A_Rd[i] - gnd[i] for i in range(len(A_Ld))]


# Vbias = -1 * potential_at_orb
for atom_index, Ei_at_atom in enumerate(-1*potential_at_atom):
pre_orbs = sum(device_atom_norbs[:atom_index])
last_orbs = pre_orbs + device_atom_norbs[atom_index]
# electron density
if e >= Ei_at_atom:
if not block_tridiagonal:
free_charge[str(kpoint)][atom_index] +=\
pre_factor[eidx]*2*(-1)/2/torch.pi*torch.trace(gnd[0][pre_orbs:last_orbs,pre_orbs:last_orbs])
# free_charge[str(kpoint)][atom_index] +=\
# pre_factor[eidx]*2*(-1)/2/torch.pi*torch.trace(deviceprop.gnd[0][pre_orbs:last_orbs,pre_orbs:last_orbs])
else:
block_indexs,orb_start,orb_end = self.get_subblock_index(subblocks,atom_index,device_atom_norbs)
if len(block_indexs) == 1:
free_charge[str(kpoint)][atom_index] += \
pre_factor[eidx]*2*(-1)/2/torch.pi*torch.trace(gnd[block_indexs[0]][orb_start:orb_end,orb_start:orb_end])
else:
for bindex in block_indexs:
if bindex == block_indexs[0]:
free_charge[str(kpoint)][atom_index] += \
pre_factor[eidx]*2*(-1)/2/torch.pi*torch.trace(gnd[bindex][orb_start:,orb_start:])
elif bindex == block_indexs[-1]:
free_charge[str(kpoint)][atom_index] += \
pre_factor[eidx]*2*(-1)/2/torch.pi*torch.trace(gnd[bindex][:orb_end,:orb_end])
else:
free_charge[str(kpoint)][atom_index] += \
pre_factor[eidx]*2*(-1)/2/torch.pi*torch.trace(gnd[bindex])
# hole density
else:
if not block_tridiagonal:
free_charge[str(kpoint)][atom_index] +=\
pre_factor[eidx]*2/2/torch.pi*torch.trace(gpd[0][pre_orbs:last_orbs,pre_orbs:last_orbs])
# free_charge[str(kpoint)][atom_index] += pre_factor[eidx]*2*1/2/torch.pi*torch.trace(gpd[0][pre_orbs:last_orbs,pre_orbs:last_orbs])

else:
block_indexs,orb_start,orb_end = self.get_subblock_index(subblocks,atom_index,device_atom_norbs)
if len(block_indexs) == 1:
free_charge[str(kpoint)][atom_index] += \
pre_factor[eidx]*2*1/2/torch.pi*torch.trace(gpd[block_indexs[0]][orb_start:orb_end,orb_start:orb_end])
else:
for bindex in block_indexs:
if bindex == block_indexs[0]:
free_charge[str(kpoint)][atom_index] += \
pre_factor[eidx]*2*1/2/torch.pi*torch.trace(gpd[bindex][orb_start:,orb_start:])
elif bindex == block_indexs[-1]:
free_charge[str(kpoint)][atom_index] += \
pre_factor[eidx]*2*1/2/torch.pi*torch.trace(gpd[bindex][:orb_end,:orb_end])
else:
free_charge[str(kpoint)][atom_index] += \
pre_factor[eidx]*2*1/2/torch.pi*torch.trace(gpd[bindex])

def get_subblock_index(self,subblocks,atom_index,device_atom_norbs):
# print('atom_index:',atom_index)
# print('subblocks:',subblocks)
subblocks_cumsum = [0]+list(np.cumsum(subblocks))
# print('subblocks_cumsum:',subblocks_cumsum)
pre_orbs = sum(device_atom_norbs[:atom_index])
last_orbs = pre_orbs + device_atom_norbs[atom_index]

# print('pre_orbs:',pre_orbs)
# print('last_orbs:',last_orbs)

block_index = []
for i in range(len(subblocks_cumsum)-1):
if pre_orbs >= subblocks_cumsum[i] and last_orbs <= subblocks_cumsum[i+1]:
block_index.append(i)
orb_start = pre_orbs - subblocks_cumsum[i]
orb_end = last_orbs - subblocks_cumsum[i]
# print('1')
break
elif pre_orbs >= subblocks_cumsum[i] and pre_orbs < subblocks_cumsum[i+1] and last_orbs > subblocks_cumsum[i+1]:
block_index.append(i)
orb_start = pre_orbs - subblocks_cumsum[i]
for j in range(i+1,len(subblocks_cumsum)-1):
block_index.append(j)
if last_orbs <= subblocks_cumsum[j+1]:
orb_end = last_orbs - subblocks_cumsum[j]
# print('2')
break
# print('block_index',block_index)
# print('orb_start',orb_start)
# print('orb_end',orb_end)
return block_index,orb_start,orb_end



# def density_integrate_Fiori_gauss(self,e_grid,kpoint,Vbias,deviceprop,device_atom_norbs,potential_at_atom,free_charge, eta_lead=1e-5, eta_device=1e-5):

# if self.xs is None:
# self.xs, self.wlg = gauss_xw(xl=torch.scalar_tensor(e_grid[0]), xu=torch.scalar_tensor(e_grid[-1]), n=self.n_gauss)
# # self.xs = self.xs.numpy();self.wlg = self.wlg.numpy()
# self.e_grid_Fiori = e_grid
# elif self.e_grid_Fiori[0] != e_grid[0] or self.e_grid_Fiori[-1] != e_grid[-1]:
# self.xs, self.wlg = gauss_xw(xl=torch.scalar_tensor(e_grid[0]), xu=torch.scalar_tensor(e_grid[-1]), n=self.n_gauss)
# # self.xs = self.xs.numpy();self.wlg = self.wlg.numpy()
# self.e_grid_Fiori = e_grid

# for eidx, e in enumerate(self.xs):

# deviceprop.lead_L.self_energy(kpoint=kpoint, energy=e, eta_lead=eta_lead)
# deviceprop.lead_R.self_energy(kpoint=kpoint, energy=e, eta_lead=eta_lead)
# deviceprop.cal_green_function(energy=e, kpoint=kpoint, block_tridiagonal=False, eta_device=eta_device,Vbias = Vbias)

# tx, ty = deviceprop.g_trans.shape
# lx, ly = deviceprop.lead_L.se.shape
# rx, ry = deviceprop.lead_R.se.shape
# x0 = min(lx, tx)
# x1 = min(rx, ty)

# gammaL = torch.zeros(size=(tx, tx), dtype=torch.complex128)
# gammaL[:x0, :x0] += deviceprop.lead_L.gamma[:x0, :x0]
# gammaR = torch.zeros(size=(ty, ty), dtype=torch.complex128)
# gammaR[-x1:, -x1:] += deviceprop.lead_R.gamma[-x1:, -x1:]

# A_L = torch.mm(torch.mm(deviceprop.g_trans,gammaL),deviceprop.g_trans.conj().T)
# A_R = torch.mm(torch.mm(deviceprop.g_trans,gammaR),deviceprop.g_trans.conj().T)

# # Vbias = -1 * potential_at_orb
# for atom_index, Ei_at_atom in enumerate(-1*potential_at_atom):
# pre_orbs = sum(device_atom_norbs[:atom_index])

# # electron density
# if e >= Ei_at_atom:
# for j in range(device_atom_norbs[atom_index]):
# free_charge[str(kpoint)][atom_index] +=\
# self.wlg[eidx]*2*(-1)/2/torch.pi*(A_L[pre_orbs+j,pre_orbs+j]*deviceprop.lead_L.fermi_dirac(e+deviceprop.lead_L.efermi) \
# +A_R[pre_orbs+j,pre_orbs+j]*deviceprop.lead_R.fermi_dirac(e+deviceprop.lead_R.efermi))

# # hole density
# else:
# for j in range(device_atom_norbs[atom_index]):
# free_charge[str(kpoint)][atom_index] +=\
# self.wlg[eidx]*2*1/2/torch.pi*(A_L[pre_orbs+j,pre_orbs+j]*(1-deviceprop.lead_L.fermi_dirac(e+deviceprop.lead_L.efermi)) \
# +A_R[pre_orbs+j,pre_orbs+j]*(1-deviceprop.lead_R.fermi_dirac(e+deviceprop.lead_R.efermi)))
Loading