Skip to content

Commit 287663d

Browse files
add TBtrans Interface tbtrans_init.py and its test files (#50)
* add tbtrans_init and related files for Shell command * rename load_dptb_model as load_model * add or modify some docstring * add test files for tbtrans_init.py * modify test_tbtrans_init.py * add some comments * change test_hBN_struct to orthogonal unit cell * remove unnecessary sisl import * add warning for input structure file in vasp format. * add docstring to class * fix some small problems * rewrite orbitals_get function * hamil_get to hamil_get_write * add runtime error for .vasp and change R_vec assert * add comments to sort([2,1,0]) * add TODO for double leads and notes on Z-direction trans. * move set_nsc to hamiltonian_get * add notes on Hamil_sisl.set_nsc * add import properties in __init__ * remove unnecessary print * rewrite load_model in for * fix load_model docstring problem * delete load_model and merge its function to hamil_get_write * delete load_model * fix bugs in chemical_symbol determination * check _orbital_name_get
1 parent 2569acd commit 287663d

File tree

8 files changed

+1070
-1
lines changed

8 files changed

+1070
-1
lines changed

dptb/entrypoints/run.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
from dptb.postprocess.bandstructure.ifermi_api import ifermiapi, ifermi_installed, pymatgen_installed
2424
from dptb.postprocess.write_skparam import WriteNNSKParam
2525
from dptb.postprocess.NEGF import NEGF
26+
from dptb.postprocess.tbtrans_init import TBTransInputSet,sisl_installed
2627

2728
__all__ = ["run"]
2829

@@ -215,6 +216,14 @@ def run(
215216
negf.compute()
216217
log.info(msg='NEGF calculation successfully completed.')
217218

219+
if task == 'tbtrans_negf':
220+
if not(sisl_installed):
221+
log.error(msg="sisl is required to perform tbtrans calculation !")
222+
raise RuntimeError
223+
224+
tbtrans_init = TBTransInputSet(apiHrk, run_opt, task_options)
225+
tbtrans_init.hamil_get_write(write_nc=True)
226+
log.info(msg='TBtrans input files are successfully generated.')
218227

219228
if output:
220229
with open(os.path.join(output, "run_config.json"), "w") as fp:

dptb/postprocess/tbtrans_init.py

Lines changed: 664 additions & 0 deletions
Large diffs are not rendered by default.
60.1 KB
Binary file not shown.
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
{
2+
"onsite": {
3+
"N-N-2s-2s-0": [
4+
0.02462027035653591,
5+
0.007205560803413391
6+
],
7+
"N-N-2s-2p-0": [
8+
0.008309782482683659,
9+
-0.007032226305454969
10+
],
11+
"N-N-2p-2p-0": [
12+
0.012606431730091572,
13+
0.010783562436699867
14+
],
15+
"N-N-2p-2p-1": [
16+
0.0068643586710095406,
17+
-0.011892829090356827
18+
],
19+
"N-B-2s-2s-0": [
20+
0.041020166128873825,
21+
-0.007834071293473244
22+
],
23+
"N-B-2s-2p-0": [
24+
26.214815139770508,
25+
-28.22139549255371
26+
],
27+
"N-B-2p-2p-0": [
28+
0.2541739046573639,
29+
0.3701082468032837
30+
],
31+
"N-B-2p-2p-1": [
32+
-0.052932459861040115,
33+
0.03325718641281128
34+
],
35+
"B-N-2s-2s-0": [
36+
-0.10863762348890305,
37+
-0.10621777176856995
38+
],
39+
"B-N-2s-2p-0": [
40+
24.486974716186523,
41+
26.85447883605957
42+
],
43+
"B-N-2p-2p-0": [
44+
0.13345032930374146,
45+
-0.3127709925174713
46+
],
47+
"B-N-2p-2p-1": [
48+
-0.03844165802001953,
49+
0.00011800970969488844
50+
],
51+
"B-B-2s-2s-0": [
52+
-0.007172069512307644,
53+
0.007495054975152016
54+
],
55+
"B-B-2s-2p-0": [
56+
0.004442985635250807,
57+
0.0030813836492598057
58+
],
59+
"B-B-2p-2p-0": [
60+
-0.0013882589992135763,
61+
-6.591381679754704e-05
62+
],
63+
"B-B-2p-2p-1": [
64+
-0.009361814707517624,
65+
-0.017272837460041046
66+
]
67+
},
68+
"hopping": {
69+
"N-N-2s-2s-0": [
70+
0.05967297405004501,
71+
-0.21457917988300323
72+
],
73+
"N-N-2s-2p-0": [
74+
0.042178086936473846,
75+
0.5767796635627747
76+
],
77+
"N-N-2p-2p-0": [
78+
0.1008036881685257,
79+
0.5027011632919312
80+
],
81+
"N-N-2p-2p-1": [
82+
-0.005753065925091505,
83+
-1.0040007829666138
84+
],
85+
"N-B-2s-2s-0": [
86+
0.06605493277311325,
87+
2.485130786895752
88+
],
89+
"N-B-2s-2p-0": [
90+
-0.19711704552173615,
91+
-1.884203314781189
92+
],
93+
"N-B-2p-2s-0": [
94+
-0.06678403168916702,
95+
-2.8326284885406494
96+
],
97+
"N-B-2p-2p-0": [
98+
-0.2129121571779251,
99+
3.601222276687622
100+
],
101+
"N-B-2p-2p-1": [
102+
0.034046269953250885,
103+
-4.79115104675293
104+
],
105+
"B-B-2s-2s-0": [
106+
-0.061647042632102966,
107+
-0.4071168601512909
108+
],
109+
"B-B-2s-2p-0": [
110+
0.048091448843479156,
111+
0.8385105729103088
112+
],
113+
"B-B-2p-2p-0": [
114+
-0.11344866454601288,
115+
0.5754562020301819
116+
],
117+
"B-B-2p-2p-1": [
118+
0.007624409161508083,
119+
-0.7790966033935547
120+
]
121+
}
122+
}
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
{
2+
"common_options": {
3+
"onsitemode": "strain",
4+
"onsite_cutoff": 1.6,
5+
"bond_cutoff": 3.6,
6+
"env_cutoff": 3.5,
7+
"atomtype": [
8+
"N",
9+
"B"
10+
],
11+
"proj_atom_neles": {
12+
"N": 5,
13+
"B": 3
14+
},
15+
"proj_atom_anglr_m": {
16+
"N": [
17+
"2s",
18+
"2p"
19+
],
20+
"B": [
21+
"2s",
22+
"2p"
23+
]
24+
}
25+
},
26+
"model_options": {
27+
"sknetwork": {
28+
"sk_hop_nhidden": 1,
29+
"sk_onsite_nhidden": 1
30+
},
31+
"skfunction": {
32+
"sk_cutoff": 3.6,
33+
"sk_decay_w": 0.3
34+
}
35+
},
36+
"structure":"./test_hBN_zigzag_struct.xyz",
37+
"task_options":
38+
{
39+
"task": "tbtrans_negf",
40+
"scf": true,
41+
"block_tridiagonal": false,
42+
"ele_T": 500,
43+
"unit": "Hartree",
44+
"scf_options":{
45+
"mode": "PDIIS",
46+
"mixing_period": 3,
47+
"step_size": 0.05,
48+
"n_history": 6,
49+
"abs_err": 1e-6,
50+
"rel_err": 1e-4,
51+
"max_iter": 100
52+
},
53+
"stru_options":{
54+
"pbc":[false, true, false],
55+
"kmesh":[1,1,1],
56+
"device":{
57+
"id":"8-12",
58+
"sort": true
59+
},
60+
"lead_L":{
61+
"id":"0-8",
62+
"voltage":0.0
63+
},
64+
"lead_R":{
65+
"id":"12-20",
66+
"voltage":0.0
67+
}
68+
},
69+
"poisson_options": {
70+
"solver": "fmm",
71+
"err": 1e-5
72+
},
73+
"sgf_solver": "Sancho-Rubio",
74+
"espacing": 0.1,
75+
"emin": -2,
76+
"emax": 2,
77+
"e_fermi": -9.874357223510742,
78+
"density_options":{
79+
"method": "Ozaki"
80+
},
81+
"eta_lead":1e-5,
82+
"eta_device":0.0,
83+
"out_dos": true,
84+
"out_tc": true,
85+
"out_ldos": true,
86+
"out_current_nscf": true,
87+
"out_density": true,
88+
"out_lcurrent": true
89+
}
90+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
20
2+
Lattice="30.0 0.0 0.0 0.0 4.337055133 0.0 0.0 0.0 12.519999742500001" Properties=species:S:1:pos:R:3 pbc="T T T"
3+
N 15.00000000 3.97563387 0.62599999
4+
B 15.00000000 2.52994883 0.62599999
5+
N 15.00000000 1.80710631 1.87799996
6+
B 15.00000000 0.36142126 1.87799996
7+
N 15.00000000 3.97563387 3.12999994
8+
B 15.00000000 2.52994883 3.12999994
9+
N 15.00000000 1.80710631 4.38199991
10+
B 15.00000000 0.36142126 4.38199991
11+
N 15.00000000 3.97563387 5.63399988
12+
B 15.00000000 2.52994883 5.63399988
13+
N 15.00000000 1.80710631 6.88599986
14+
B 15.00000000 0.36142126 6.88599986
15+
N 15.00000000 3.97563387 8.13799983
16+
B 15.00000000 2.52994883 8.13799983
17+
N 15.00000000 1.80710631 9.38999981
18+
B 15.00000000 0.36142126 9.38999981
19+
N 15.00000000 3.97563387 10.64199978
20+
B 15.00000000 2.52994883 10.64199978
21+
N 15.00000000 1.80710631 11.89399976
22+
B 15.00000000 0.36142126 11.89399976

dptb/tests/test_tbtrans_init.py

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
import pytest
2+
from dptb.nnops.apihost import NNSKHost
3+
from dptb.plugins.init_nnsk import InitSKModel
4+
from dptb.nnops.NN2HRK import NN2HRK
5+
from dptb.postprocess.tbtrans_init import TBTransInputSet
6+
from dptb.utils.tools import j_loader
7+
import numpy as np
8+
9+
@pytest.fixture(scope='session', autouse=True)
10+
def root_directory(request):
11+
return str(request.config.rootdir)
12+
13+
14+
def test_tbtrans_init(root_directory):
15+
16+
# check whether sisl is installed: if not, skip this test
17+
try:
18+
import sisl
19+
except:
20+
pytest.skip('sisl is not installed which is necessary for TBtrans Input Generation. Therefore, skipping test_tbtrans_init.')
21+
22+
model_ckpt = f'{root_directory}/dptb/tests/data/test_tbtrans/best_nnsk_b3.600_c3.600_w0.300.json'
23+
config = f'{root_directory}/dptb/tests/data/test_tbtrans/negf_tbtrans.json'
24+
apihost = NNSKHost(checkpoint=model_ckpt, config=config)
25+
apihost.register_plugin(InitSKModel())
26+
apihost.build()
27+
apiHrk = NN2HRK(apihost=apihost, mode='nnsk')
28+
29+
run_opt = {
30+
"run_sk": True,
31+
"init_model":model_ckpt,
32+
"results_path":f'{root_directory}/dptb/tests/data/test_tbtrans/',
33+
"structure":f'{root_directory}/dptb/tests/data/test_tbtrans/test_hBN_zigzag_struct.xyz',
34+
"log_path": '/data/DeepTB/dptb_Zjj/DeePTB/dptb/tests/data/test_tbtrans/output',
35+
"log_level": 5,
36+
"use_correction":False
37+
}
38+
39+
jdata = j_loader(config)
40+
jdata = jdata['task_options']
41+
tbtrans_hBN = TBTransInputSet(apiHrk=apiHrk,run_opt=run_opt, jdata=jdata)
42+
43+
# check _orbitals_name_get
44+
element_orbital_name = tbtrans_hBN._orbitals_name_get(['2s', '2p'])
45+
assert element_orbital_name == ['2s', '2py', '2pz', '2px']
46+
element_orbital_name = tbtrans_hBN._orbitals_name_get(['3s', '3p', 'd*'])
47+
assert element_orbital_name == ['3s', '3py', '3pz', '3px', 'dxy*', 'dyz*', 'dz2*', 'dxz*', 'dx2-y2*']
48+
49+
50+
51+
tbtrans_hBN.hamil_get_write(write_nc=False)
52+
assert (tbtrans_hBN.allbonds_all[0].detach().numpy()-np.array([5, 0, 5, 0, 0, 0, 0])).max()<1e-5
53+
assert (tbtrans_hBN.allbonds_all[50].detach().numpy()-np.array([ 5, 2, 5, 18, 0, 0, -1])).max()<1e-5
54+
assert (tbtrans_hBN.hamil_block_all[0].detach().numpy()- np.array([[-0.73303634, 0. , 0. , 0. ],
55+
[ 0. , 0.04233637, 0. , 0. ],
56+
[ 0. , 0. , 0.04233636, 0. ],
57+
[ 0. , 0. , 0. , -0.27156556]])).max()<1e-5
58+
assert (tbtrans_hBN.hamil_block_all[50].detach().numpy()-np.array([[-0.03164609, -0. , 0.02028139, -0. ],
59+
[ 0. , 0.00330366, 0. , 0. ],
60+
[-0.02028139, 0. , -0.05393751, 0. ],
61+
[ 0. , 0. , 0. , 0.00330366]])).max()<1e-5
62+
assert (tbtrans_hBN.allbonds_lead_L[0].detach().numpy()-np.array([5, 0, 5, 0, 0, 0, 0])).max()<1e-5
63+
assert (tbtrans_hBN.allbonds_lead_L[50].detach().numpy()-np.array([5, 4, 7, 7, 0, 0, 0])).max()<1e-5
64+
assert (tbtrans_hBN.hamil_block_lead_L[0].detach().numpy()-np.array([[-0.73303634, 0. , 0. , 0. ],
65+
[ 0. , 0.04233637, 0. , 0. ],
66+
[ 0. , 0. , 0.04233636, 0. ],
67+
[ 0. , 0. , 0. , -0.27156556]])).max()<1e-5
68+
assert (tbtrans_hBN.hamil_block_lead_L[50].detach().numpy()-np.array([[ 0.1145315 , -0.06116847, 0.10594689, 0. ],
69+
[ 0.15539739, -0.04634972, 0.22751862, 0. ],
70+
[-0.26915616, 0.22751862, -0.30906558, 0. ],
71+
[-0. , 0. , 0. , 0.08500822]])).max()<1e-5
72+
73+
74+
# tbtrans_hBN.hamil_write()
75+
# check the hamiltonian through Hk at Gamma and M
76+
H_lead = tbtrans_hBN.H_lead_L
77+
G_eigs = sisl.BandStructure(H_lead, [[0., 0.,0.]], 1, ["G"])
78+
M_eigs = sisl.BandStructure(H_lead, [[0, 0.5 ,0 ]], 1, ["M"])
79+
Ef = -9.874358177185059
80+
G_eigs = G_eigs.apply.array.eigh() -Ef
81+
M_eigs = M_eigs.apply.array.eigh() -Ef
82+
83+
G_eigs_right = np.array([[-19.95362763, -17.10774579, -17.10774579, -16.9118761 ,
84+
-11.20609829, -10.01050689, -10.01050689, -8.11443067,
85+
-8.11443067, -7.60442045, -6.6550603 , -3.79211664,
86+
-3.79211663, -3.22863532, -3.22863532, -3.17535758,
87+
3.18703263, 3.24031037, 3.24031037, 6.45306332,
88+
7.70583557, 7.91107113, 10.91058699, 10.91058699,
89+
23.64785516, 23.64785516, 28.30755414, 28.30755428,
90+
28.65719263, 30.78452851, 33.25399887, 33.25399887]])
91+
92+
M_eigs_right = np.array([[-18.69653568, -18.69653568, -16.91187582, -16.91187582,
93+
-11.20609828, -11.20609828, -7.44726991, -7.44726991,
94+
-6.65506047, -6.65506047, -5.79252308, -5.79252308,
95+
-5.2193769 , -5.2193769 , -3.17535758, -3.17535758,
96+
3.18703263, 3.18703263, 5.84906816, 5.84906816,
97+
7.74726616, 7.74726616, 7.91107121, 7.91107121,
98+
28.12912079, 28.12912079, 28.65719227, 28.65719227,
99+
29.54182975, 29.54182975, 30.78452877, 30.78452877]])
100+
101+
assert (G_eigs[0]-G_eigs_right[0]).max()<1e-5
102+
assert (M_eigs[0]-M_eigs_right[0]).max()<1e-5
103+
104+
105+
106+

0 commit comments

Comments
 (0)