-
Notifications
You must be signed in to change notification settings - Fork 30
/
tselecs.sh
executable file
·657 lines (592 loc) · 16.1 KB
/
tselecs.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
#!/bin/bash
# Script to create output for multiple electrodes
# and/or multiple chemical potentials
_this=$(basename $0)
function error {
echo "ERROR: something went wrong... Please see the following output:"
while [ $# -gt 0 ]; do
echo "$1"
shift
done
exit 1
}
# We must require to be able to use the hash-able arrays
# This allows us to reuse the same input twice more easily
help=0
def=2
tbt=0
# Options about what to print
print_mu=0
print_el=0
print_c=0
declare -a opts
_N=0
volt=0
while [ $# -gt 0 ]; do
opt=$1
case $opt in
--*)
opt=${1:1} ;;
esac
case $opt in
-def|-orig|-original)
# Will produce output for standard TS
def=2 ; shift
;;
-V|-bias)
volt=$1 ; shift ; shift
;;
-1|-2|-3|-4|-5|-6|-7|-8|-9)
# Will produce output for standard TS
def=${opt:1} ; shift
;;
-only-el|-only-elec|-only-electrode)
print_el=1 ; shift
;;
-only-mu|-only-chem|-only-chemical)
print_mu=1 ; shift
;;
-only-c|-only-contour)
print_c=1 ; shift
;;
-T|-tbtrans)
# Prefix with TBT instead of TS
tbt=1 ; shift
;;
-help|-h)
# We need to print help
help=1 ; shift
;;
*)
break
esac
done
# Correct what to print (if the user)
# has not specified anything
if [ $print_el -eq 0 ] && [ $print_mu -eq 0 ] && [ $print_c -eq 0 ]; then
print_el=1
print_mu=1
print_c=1
fi
if [ $help -eq 1 ]; then
fmt=" %20s : %s\n"
echo "Usage:"
echo " $_this <options>"
echo ""
echo "For intrinsic transiesta runs call this:"
echo " $_this -2 -V <bias>"
echo ""
echo "If one wishes to divide it in several files do:"
echo " $_this -only-el > ELECS.fdf"
echo " $_this -only-mu > CHEMPOTS.fdf"
echo " $_this -only-c > CONTOURS.fdf"
echo ""
echo "Only print out tbtrans related options:"
echo " $_this -T|--tbtrans"
echo ""
echo "For specifying the contour energy levels you can use these options:"
printf "$fmt" "-Emin <val>" "band bottom energy in eV (-40. eV)"
printf "$fmt" "-dE <val>" "real-axis distance between integration points (0.01 eV)"
echo ""
echo "There are preset creations of 2,3 and 4 electrodes, call:"
echo " $_this -[2-9]"
echo "to create the equivalent systems, note that these options can be accompanied by further setup."
echo ""
echo "Available options for the chemical potentials:"
echo " -mu<idx>-X where X is one of the following:"
printf "$fmt" "mu <val>" "the chemical potential value in eV, or in fractions of V (V/2, |V|/3, etc.)"
printf "$fmt" "name <name>" "the name of the chemical potential (to be referenced by the electrodes)"
echo ""
echo "A shorthand notation for supplying the options is:"
echo " -mu<idx> Y=<val>,Z=<val> where Y,Z is one of X above"
echo ""
echo ""
echo "Available options for the electrodes:"
echo " -el<idx>-X where X is one of the following:"
printf "$fmt" "mu <name>" "the chemical potential name as given by -mu-name"
printf "$fmt" "name <name>" "the name of the electrode"
printf "$fmt" "tshs <file>" "the electrode TSHS-file"
printf "$fmt" "semi-inf <val>" "the semi-infinite direction [-+][a-c|a[1-3]]"
printf "$fmt" "pos <val>" "the first atom of the electrode in the structure"
printf "$fmt" "end-pos <val>" "the last atom of the electrode in the structure"
printf "$fmt" "used-atoms|ua <val>" "number of atoms used in the electrode (all)"
printf "$fmt" "bloch-a[1-3] <val>" "the Bloch expansion in the equivalent direction (1)"
printf "$fmt" "bulk <T|F>" "whether the electrode is a bulk electrode (true)"
printf "$fmt" "gf <file>" "name of the Greens function file (TSGF[el<idx>-name])"
echo ""
echo "A shorthand notation for supplying the options is:"
echo " -el<idx> Y=<val>,Z=<val> where Y,Z is one of X above"
echo ""
echo "You can combine -2 with additional electrode options to easily generate different schemes"
echo "To generate 3 electrodes and 2 chemical potentials you can do this:"
echo " $_this -2 -el3 name=Top,mu=Left,inf-dir=+a2,end-pos=-1"
exit 1
fi
prefix=TS
# If we are doing tbtrans output
# we should not print the contour information
if [ $tbt -eq 1 ]; then
prefix=TBT
print_c=0
fi
# Add an option to the option array, enables easy creations
function add_opt {
local rem=0
[ "x$1" == "x-r" ] && rem=1 && shift
local opt=$1 ; shift
local val=$1 ; shift
if [ $rem -eq 1 ]; then
rem_opt $opt
fi
# array indices are zero-based
local tmp=$(get_opt $opt 1)
[ ${#tmp} -gt 0 ] && return 0
opts+=($opt)
opts+=($val)
let _N++
let _N++
}
# Removes an option from the option array, enables customization of the options in-code
function rem_opt {
local opt
local i
while [ $# -gt 0 ]; do
opt=$1 ; shift
i=0
while [ $i -le $_N ]; do
local val=${opts[$i]}
if [ "x$val" == "x$opt" ]; then
#echo "Removing ($val|$opt: ${opts[$i]}"
unset opts[$i]
let i++
#echo "Removing: ${opts[$i]}"
unset opts[$i]
break
fi
let i++
done
done
opts=( "${opts[@]}" )
_N=${#opts[@]}
}
# Lower-case function
function lc { printf "%b" "$@" | tr '[A-Z]' '[a-z]' ; }
function get_opt {
# Returns the option from the array input
# get_opt <opt-name (with ONE dash)> [number of arguments gobbled]
# If [...] is 0:
# 0) will return 0 or 1 whether or not the option exists
# 1-9) will return the consecutive [...] number of elements
local opt="$1" ; shift
local count=0
if [ $# -gt 0 ]; then
count=$1 ; shift
fi
local i=0 ; local j=0
local ret=""
while [ $i -le $_N ]; do
local oo=$(lc ${opts[$i]})
#echo "searching for: $opt in $oo" 1>&2
if [ "x$opt" == "x$oo" ]; then
if [ $count -gt 0 ]; then
ret=""
for j in `seq 1 $count` ; do
let i++
ret="$ret ${opts[$i]}"
done
else
ret=1
fi
break
fi
let i++
done
[ ${#ret} -eq 0 ] && [ $count -eq 0 ] && ret=0
# trim white-space
ret=${ret%% }
ret=${ret## }
printf "%b" "$ret"
}
# Expands the "short-hand" keywords to their full equivalents
function expand_key {
local nm="$1" ; shift
local i=1
local reg_opt
local opt
local val
while : ; do
reg_opt=$(get_opt -$nm$i 1)
# If the option does not exist, we simply return
[ ${#reg_opt} -eq 0 ] && [ $i -gt 6 ] && break
# Delete, so that we only keep the wanted options (not necessary, but)
rem_opt -$nm$i
reg_opt="${reg_opt//,/ }"
reg_opt="${reg_opt//;/ }"
# Loop over comma/semi-colon separated entries
for reg in $reg_opt ; do
# Add to the option list
# Retrive the option and value
opt=${reg%=*}
val=${reg#*=}
add_opt -r "-$nm$i-$opt" "$val"
done
let i++
done
}
function reduce {
local -a tmp
local i=0
local j=0
while [ $j -le $_N ]; do
if [ ${#opts[$j]} -gt 0 ]; then
tmp[$i]=${opts[$j]}
let i++
fi
let j++
done
opts=( "${tmp[@]}" )
_N=$i
}
for i in `seq 1 $def` ; do
# The user has requested a default setting for some electrodes
# We add them to the option stack
add_opt "-mu$i-name" "mu-$i"
add_opt "-mu$i-mu" "<mu-mu$i>"
add_opt "-el$i-name" "el-$i"
add_opt "-el$i-mu" "mu-$i"
add_opt "-el$i-pos" "<input-value>"
add_opt "-el$i-semi-inf" "+a3"
done
# In case of only two electrodes we have
# the particular case of the traditional transiesta code
case $def in
1)
add_opt -r "-mu1-name" "single"
add_opt -r "-mu1-mu" "0."
add_opt -r "-el1-name" "single"
add_opt -r "-el1-mu" "single"
rem_opt -el1-pos -el1-end-pos -el1-semi-inf
add_opt "-el1-pos" "1"
add_opt "-el1-semi-inf" "-a3"
;;
2)
add_opt -r "-mu1-name" "Left"
add_opt -r "-mu1-mu" "V/2"
add_opt -r "-el1-name" "Left"
add_opt -r "-el1-mu" "Left"
rem_opt -el1-pos -el1-end-pos -el1-semi-inf
add_opt "-el1-pos" "1"
add_opt "-el1-semi-inf" "-a3"
add_opt -r "-mu2-name" "Right"
add_opt -r "-mu2-mu" "-V/2"
add_opt -r "-el2-name" "Right"
add_opt -r "-el2-mu" "Right"
rem_opt -el2-pos -el2-end-pos -el2-semi-inf
add_opt "-el2-end-pos" "-1"
add_opt "-el2-semi-inf" "+a3"
;;
esac
# Add the user options
while [ $# -gt 0 ]; do
opt=$1 ; shift
case $opt in
--*)
opt=${1:1}
rem_opt $opt ;;
-el*|-mu*)
rem_opt $opt ;;
esac
let _N++
opts[$_N]="$opt"
done
# Expand again after the user things
expand_key mu
expand_key el
reduce
function count {
local nm=$1 ; shift
local n=0
local i=
local oldn=-1
local opt=
local j=
while [ $oldn -ne $n ]; do
oldn=$n
i=$n
let i++
j=0
while [ $j -lt $_N ]; do
opt=${opts[$j]}
case $opt in
-${nm}${i}*)
n=$i ;;
esac
let j++
done
done
printf "%b" "$n"
}
# Save the options
old_opts=( "${opts[@]}" )
i=0
while [ $i -lt $_N ]; do
case ${opts[$i]} in
-el*)
unset opts[$i]
let i++
unset opts[$i]
;;
esac
let i++
done
# Remove empty array elements
reduce
# Energy for the contour
emin=$(get_opt -emin 1)
[ ${#emin} -eq 0 ] && emin=-40.
emin="$emin eV"
de=$(get_opt -de 1)
[ ${#de} -eq 0 ] && de=0.01
# The chemical potentials should be denoted like this option:
# -mu1 <options for the chemical potential in comma separated list>
# Another way of supplying information regarding the chemical potentials
# -mu1-name <name>
# -mu1-mu <the value of the chemical potential>
_mus=$(count mu)
# First we need to figure out the number of chemical potentials:
# I don't suspect ANY user will go above 10 chemical potentials
[ $_mus -eq 0 ] && \
error "You have zero chemical potentials." "Please supply at least one..."
# Create the chemical potential array
_mu_names=()
j=0
for i in `seq 1 $_mus` ; do
_mu_names+=( "$(get_opt -mu$i-name 1)" )
let j++
done
function mu_e_correct {
local mu=$1 ; shift
if [ "x${mu:0:1}" == "x-" ]; then
# we have a negative sign
if [ "x${mu:1:2}" != "x|V" ] && [ "x${mu:1:1}" != "xV" ]; then
mu="$mu eV"
fi
else
if [ "x${mu:0:2}" != "x|V" ] && [ "x${mu:0:1}" != "xV" ]; then
mu="$mu eV"
fi
fi
printf "%b" "$mu"
}
if [ $print_mu -eq 1 ]; then
# Print out chemical potential block:
echo "$prefix.Voltage $volt eV"
echo "%block $prefix.ChemPots"
for mu in ${_mu_names[@]} ; do
echo " $mu"
done
echo "%endblock $prefix.ChemPots"
echo ""
function create_mu {
local mu=$1 ; shift
local name=$(get_opt -mu$mu-name 1)
if [ ${#name} -eq 0 ]; then
error "Chemical potential: $mu" "Has not received a name (-mu$mu-name)"
fi
local chem=$(get_opt -mu$mu-mu 1)
if [ ${#chem} -eq 0 ]; then
error "Chemical potential: $mu" "Has not received a chemical potential value (-mu$mu-mu)"
fi
chem=$(mu_e_correct $chem)
echo "%block $prefix.ChemPot.$name"
echo " mu $chem"
if [ $tbt -eq 0 ]; then
echo " contour.eq"
echo " begin"
echo " C-$name"
echo " T-$name"
echo " end"
fi
echo "%endblock $prefix.ChemPot.$name"
}
for i in `seq 1 $_mus` ; do
create_mu $i
done
fi
# Create all the contours
if [ $print_c -eq 1 ]; then
echo ""
echo "TS.Contours.Eq.Pole 2.5 eV"
for i in `seq 1 $_mus` ; do
mu=$(get_opt -mu$i-name 1)
# Create the contours
echo "%block TS.Contour.C-$mu"
echo " part circle"
e=$(get_opt -mu$i-mu 1)
e=$(mu_e_correct $e)
[ ${e:0:1} != "-" ] && e="+ $e"
echo " from $emin $e to -10 kT $e"
echo " points 25"
echo " method g-legendre"
echo " opt right"
echo "%endblock TS.Contour.C-$mu"
# Create the contours
echo "%block TS.Contour.T-$mu"
echo " part tail"
echo " from prev to inf"
echo " points 10"
echo " method g-fermi"
echo "%endblock TS.Contour.T-$mu"
done
echo ""
echo "MSG: You may need to correct the TS.Contours.nEq for signs of bias" >&2
echo "MSG: The energies must be in increasing order (you may use |V|/2 to designate absolute values)" >&2
if [ $_mus -gt 1 ]; then
# Create the non-equilbrium contour
echo "%block TS.Contours.nEq"
for i in `seq 1 $_mus` ; do
[ $i -eq $_mus ] && continue
echo " neq-$i"
done
echo "%endblock TS.Contours.nEq"
fi
# Create array of chemical potentials sorted
mus=()
j=1
for i in `seq $_mus -1 1` ; do
tmp="$(get_opt -mu$i-mu 1)"
tmp=${tmp//\|V\|/V}
tmp=${tmp//V/\|V\|}
mus[$j]=$(mu_e_correct $tmp)
let j++
done
# Create the contours
if [ $_mus -gt 2 ]; then
echo "MSG: You can do with a single contour line in the bias window" >&2
echo "MSG: Use the lowest bias to the highest bias." >&2
echo "MSG: Here we supply as many different parts as there are chemical potentials" >&2
fi
if [ $_mus -gt 1 ]; then
i=1
echo "%block TS.Contour.nEq.neq-$i"
echo " part line"
j=$((i+1))
if [ $j -eq $_mus ]; then
echo " from ${mus[$i]} - 5 kT to ${mus[$j]} + 5 kT"
else
echo " from ${mus[$i]} - 5 kT to ${mus[$j]}"
fi
echo " delta $de eV"
echo " method mid-rule"
echo "%endblock TS.Contour.nEq.neq-$i"
# Sort all chemical potentials
for i in `seq 3 $((_mus))` ; do
# Create the contours
echo "%block TS.Contour.nEq.neq-$((i-1))"
echo " part line"
if [ $i -eq $_mus ]; then
echo " from prev to ${mus[$i]} + 5 kT"
else
echo " from prev to ${mus[$i]}"
fi
echo " delta $de eV"
echo " method mid-rule"
echo "%endblock TS.Contour.nEq.neq-$((i-1))"
done
fi
fi
# Recreate the old
opts=( "${old_opts[@]}" )
_N=${#opts[@]}
# remove all mu
i=0
while [ $i -lt $_N ]; do
case ${opts[$i]} in
-mu*)
unset opts[$i]
let i++
unset opts[$i] ;;
esac
let i++
done
# Remove empty things
reduce
# Now we will concentrate on the electrodes
# First we need to figure out the number of electrode
# I don't suspect ANY user will go above 10 electrodes
_els=$(count el)
[ $_els -eq 0 ] && \
error "You have zero electrodes." "Please supply at least one..."
[ $_els -lt $_mus ] && \
error "You have fewer electrodes than chemical potentials." "Please correct your input..."
if [ $print_el -eq 1 ]; then
# Print out electrodes block:
echo ""
echo "%block $prefix.Elecs"
for i in `seq 1 $_els` ; do
echo " $(get_opt -el$i-name 1)"
done
echo "%endblock $prefix.Elecs"
echo ""
# Get whether or not we should print everything
_all=$(get_opt -print-all)
[ $_all -eq 0 ] && _all=$(get_opt -el-all)
function create_el {
local el=$1 ; shift
local name=$(get_opt -el$el-name 1)
[ ${#name} -eq 0 ] && error "Electrode: $el" "Has not received a name (-el$el-name)"
local chem=$(get_opt -el$el-mu 1)
[ ${#chem} -eq 0 ] && error "Electrode: $el" "Has not received a chemical potential reference (-el$el-mu)"
# Currently we don't check for the existance of
# the chemical potential.
local found=0
local i=$_mus
let i--
for j in `seq 0 $i` ; do
if [ "x${_mu_names[$j]}" == "x$chem" ]; then
found=1
fi
done
[ $found -ne 1 ] && error "Electrode: $el could not be associated with a matching chemical potential: $chem"
echo "%block $prefix.Elec.$name"
local tshs=$(get_opt -el$el-tshs 1)
if [ ${#tshs} -ne 0 ]; then
echo " HS $tshs"
else
echo " HS <input file>"
fi
echo " chemical-potential $chem"
echo " semi-inf-direction $(get_opt -el$el-semi-inf 1)"
local pos=$(get_opt -el$el-pos 1)
if [ ${#pos} -eq 0 ]; then
pos=$(get_opt -el$el-end-pos 1)
[ ${#pos} -ne 0 ] && pos="end $pos"
fi
[ ${#pos} -eq 0 ] && pos="<set value>"
echo " electrode-position $pos"
# Now we can set all the other things (non-important)
function print_if {
local opt=
for opt in ${1//:/ } ; do
local val=$(get_opt -el$el-$opt 1)
if [ ${#val} -gt 0 ]; then
echo " $2 $val"
break
fi
done
}
print_if used-atoms:ua "used-atoms"
print_if bloch-a:bloch-a1 "bloch-a1"
print_if bloch-b:bloch-a2 "bloch-a2"
print_if bloch-c:bloch-a3 "bloch-a3"
print_if bulk "bulk"
print_if gf "GF"
echo "%endblock $prefix.Elec.$name"
}
for i in `seq 1 $_els` ; do
create_el $i
done
fi
# Recreate the options
opts=( "${old_opts[@]}" )
_N=${#opts[@]}