forked from quantum-kite/kite
/
kite.py
1863 lines (1534 loc) · 84.8 KB
/
kite.py
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
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
"""
##############################################################################
# KITE | Release 1.0 #
# #
# Kite home: quantum-kite.com #
# #
# Developed by: Simao M. Joao, Joao V. Lopes, Tatiana G. Rappoport, #
# Misa Andelkovic, Lucian Covaci, Aires Ferreira, 2018-2019 #
# #
##############################################################################
"""
import numpy as np
import h5py as hp
import pybinding as pb
from scipy.sparse import coo_matrix
from scipy.spatial import cKDTree
# Class that introduces Structural Disorder into the initially built lattice.
# The exported dataset StructuralDisorder has the following groups:
# - Concentration: concentration of disorder,
# - Position: If instead of concentration one want's to select an exact position of disorder,
# - NumBondDisorder: number of bond changes,
# - NumOnsiteDisorder: number of onsite energy,
# The disorder is represented through nodes, where each node represents and maps a single orbital.
# - NumNodes: total number of orbitals included in the disorded,
# - NodePosition: orbital associated with the node,
# - NodeFrom, and NodeTo: bond from and to with 2 columns and NumBondDisorder rows, where the second column is complex
# conjugated hopping,
# - Hopping: values of the new hopping, with 2 columns and NumBondDisorder rows where the hoppings in different
# columns are conjugated values,
# - NodeOnsite: array of nodes that have onsite disorder,
# - U0: value of the onsite disorder.
class StructuralDisorder:
def __init__(self, lattice, concentration=0, position=None):
if (concentration != 0 and not(position is None)) or (position is None and concentration == 0):
SystemExit('Either select concentration which results in random distribution or '
'the exact position of the defect!')
self._lattice = lattice
vectors = np.asarray(self._lattice.vectors)
self._space_size = vectors.shape[0]
if position is None:
position = np.zeros(self._space_size)
self._exact_position = False
else:
self._exact_position = True
self._concentration = concentration
self._position = np.asmatrix(position)
self._num_bond_disorder_per_type = 0
self._num_onsite_disorder_per_type = 0
self._orbital_from = []
self._orbital_to = []
self._orbital_onsite = []
self._idx_node = 0
self._disorder_hopping = []
self._disorder_onsite = []
self._nodes_from = []
self._nodes_to = []
self._nodes_onsite = []
# only used for scaling
self._sub_from = []
self._sub_to = []
self._sub_onsite = []
self._rel_idx_onsite = []
self._rel_idx_to = []
self._rel_idx_from = []
self._onsite = []
self._hopping = []
self._orbital_vacancy = []
self._orbital_vacancy_cell = []
self._vacancy_sub = []
self._num_nodes = 0
self._nodes_map = dict()
self._node_orbital = []
num_orbitals = np.zeros(lattice.nsub, dtype=np.uint64)
for name, sub in lattice.sublattices.items():
# num of orbitals at each sublattice is equal to size of onsite energy
num_energies = np.asarray(sub.energy).shape[0]
num_orbitals[sub.alias_id] = num_energies
self._num_orbitals_total = np.sum(np.asarray(num_orbitals))
self._num_orbitals = np.asarray(num_orbitals)
self._num_orbitals_before = np.cumsum(np.asarray(num_orbitals)) - num_orbitals
self._lattice = lattice
vectors = np.asarray(self._lattice.vectors)
self._space_size = vectors.shape[0]
def add_vacancy(self, *disorder):
num_vacancy_disorder = 0
for dis in disorder:
if len(disorder) == 1:
relative_index = [0, 0]
dis =[relative_index, dis]
# check if it's just concentration or sublatt
num_vacancy_disorder += 1
self.add_local_vacancy_disorder(*dis)
if len(disorder) > 2:
raise SystemExit('Vacancy disorder should be added in a form:'
'\n sublattice name,'
'\n sublattice name, [rel. unit cell],'
'\n or in a form of disorder onsite energy:'
'\n ([rel. unit cell], sublattice_name, '
'onsite energy)')
def add_structural_disorder(self, *disorder):
self._nodes_map = dict()
num_bond_disorder_per_type = 0
num_onsite_disorder_per_type = 0
for dis in disorder:
if len(dis) == 5:
num_bond_disorder_per_type += 1
self.add_local_bond_disorder(*dis)
else:
if len(dis) == 3:
num_onsite_disorder_per_type += 1
self.add_local_onsite_disorder(*dis)
else:
raise SystemExit('Disorder should be added in a form of bond disorder:'
'\n([rel. unit cell from], sublattice_from, [rel. unit cell to], sublattice_to, '
'value),'
'\n or in a form of disorder onsite energy:'
'\n ([rel. unit cell], sublattice_name, '
'onsite energy)')
self._num_bond_disorder_per_type = num_bond_disorder_per_type
self._num_onsite_disorder_per_type = num_onsite_disorder_per_type
sorted_node_orb = sorted(self._nodes_map, key=lambda x: self._nodes_map[x])
sorted_nodes = [self._nodes_map[x] for x in sorted_node_orb]
sorted_dict = dict(zip(sorted_node_orb, sorted_nodes))
self._nodes_map = sorted_dict
self._node_orbital = sorted_node_orb
def map_the_orbital(self, orb, nodes_map):
idx_node = len(nodes_map)
if not (orb in nodes_map):
nodes_map[orb] = idx_node
idx_node += 1
self._nodes_map = nodes_map
return idx_node
def add_local_vacancy_disorder(self, relative_index, sub):
orbital_vacancy = []
orbital_vacancy_cell = []
names, sublattices = zip(*self._lattice.sublattices.items())
if sub not in names:
raise SystemExit('Desired initial sublattice doesn\'t exist in the chosen lattice! ')
indx = names.index(sub)
lattice_sub = sublattices[indx]
sub_id = lattice_sub.alias_id
it = np.nditer(lattice_sub.energy, flags=['multi_index'])
while not it.finished:
orbit = int(self._num_orbitals_before[sub_id] + it.multi_index[0])
if orbit not in orbital_vacancy:
orbital_vacancy.append(orbit)
it.iternext()
self._orbital_vacancy.extend(orbital_vacancy)
self._vacancy_sub.extend(sub)
def add_local_bond_disorder(self, relative_index_from, from_sub, relative_index_to, to_sub, hoppings):
# save the info used for manual scaling
self._sub_from.append(from_sub)
self._sub_to.append(to_sub)
self._rel_idx_to.append(relative_index_to)
self._rel_idx_from.append(relative_index_from)
self._hopping.append(np.atleast_1d(hoppings))
orbital_from = []
orbital_to = []
orbital_hop = []
if not (np.all(np.abs(np.asarray(relative_index_from)) < 2) and
np.all(np.abs(np.asarray(relative_index_to)) < 2)):
raise SystemExit('When using structural disorder, only the distance between nearest unit cells are '
'supported, make the bond in the bond disorder shorter! ')
names, sublattices = zip(*self._lattice.sublattices.items())
if from_sub not in names:
raise SystemExit('Desired initial sublattice doesnt exist in the chosen lattice! ')
if to_sub not in names:
raise SystemExit('Desired final sublattice doesnt exist in the chosen lattice! ')
indx_from = names.index(from_sub)
lattice_sub_from = sublattices[indx_from]
indx_to = names.index(to_sub)
lattice_sub_to = sublattices[indx_to]
from_sub_id = lattice_sub_from.alias_id
to_sub_id = lattice_sub_to.alias_id
nodes_map = self._nodes_map
nodes_from = []
nodes_to = []
h = np.nditer(hoppings, flags=['multi_index'])
while not h.finished:
relative_move_from = np.dot(np.asarray(relative_index_from) + 1,
3 ** np.linspace(0, self._space_size - 1, self._space_size, dtype=np.int32))
relative_move_to = np.dot(np.asarray(relative_index_to) + 1,
3 ** np.linspace(0, self._space_size - 1, self._space_size, dtype=np.int32))
if isinstance(hoppings, np.ndarray):
orb_from = int(relative_move_from +
(self._num_orbitals_before[from_sub_id] + h.multi_index[0]) * 3 ** self._space_size)
orb_to = int(relative_move_to +
(self._num_orbitals_before[to_sub_id] + h.multi_index[1]) * 3 ** self._space_size)
self.map_the_orbital(orb_from, nodes_map)
self.map_the_orbital(orb_to, nodes_map)
orbital_from.append(orb_from)
orbital_to.append(orb_to)
nodes_from.append(nodes_map[orb_from])
nodes_to.append(nodes_map[orb_to])
# conjugate
orbital_from.append(orb_to)
orbital_to.append(orb_from)
nodes_from.append(nodes_map[orb_to])
nodes_to.append(nodes_map[orb_from])
orbital_hop.append(h[0])
orbital_hop.append(np.conj(np.transpose(h[0])))
else:
orb_from = int(relative_move_from + self._num_orbitals_before[from_sub_id] * 3 ** self._space_size)
orb_to = int(relative_move_to + self._num_orbitals_before[to_sub_id] * 3 ** self._space_size)
self.map_the_orbital(orb_from, nodes_map)
self.map_the_orbital(orb_to, nodes_map)
orbital_from.append(orb_from)
orbital_to.append(orb_to)
nodes_from.append(nodes_map[orb_from])
nodes_to.append(nodes_map[orb_to])
# conjugate
orbital_from.append(orb_to)
orbital_to.append(orb_from)
nodes_from.append(nodes_map[orb_to])
nodes_to.append(nodes_map[orb_from])
orbital_hop.append(h[0])
orbital_hop.append((h[0].conjugate()))
h.iternext()
self._orbital_from.append(orbital_from)
self._orbital_to.append(orbital_to)
self._disorder_hopping.append(orbital_hop)
self._nodes_from.append(nodes_from)
self._nodes_to.append(nodes_to)
if len(nodes_map) > self._num_nodes:
self._num_nodes = len(nodes_map)
def add_local_onsite_disorder(self, relative_index, sub, value):
# save the info used for manual scaling
self._sub_onsite.append(sub)
self._rel_idx_onsite.append(relative_index)
self._onsite.append(np.atleast_1d(value))
orbital_onsite = []
orbital_onsite_en = []
nodes_map = self._nodes_map
names, sublattices = zip(*self._lattice.sublattices.items())
if sub not in names:
raise SystemExit('Desired initial sublattice doesnt exist in the chosen lattice! ')
indx_sub = names.index(sub)
lattice_sub = sublattices[indx_sub]
sub_id = lattice_sub.alias_id
nodes_onsite = []
h = np.nditer(value, flags=['multi_index'])
while not h.finished:
relative_move = np.dot(np.asarray(relative_index) + 1,
3 ** np.linspace(0, self._space_size - 1, self._space_size, dtype=np.int32))
if isinstance(value, np.ndarray):
orb = int(relative_move + (self._num_orbitals_before[sub_id] + h.multi_index[0]) * 3 ** self._space_size)
self.map_the_orbital(orb, nodes_map)
orbital_onsite_en.append(h[0])
nodes_onsite.append(nodes_map[orb])
orbital_onsite.append(orb)
else:
orb = int(relative_move + self._num_orbitals_before[sub_id] * 3 ** self._space_size)
self.map_the_orbital(orb, nodes_map)
orbital_onsite_en.append(h[0])
nodes_onsite.append(nodes_map[orb])
orbital_onsite.append(orb)
h.iternext()
self._orbital_onsite.append(orbital_onsite)
self._disorder_onsite.append(orbital_onsite_en)
self._nodes_onsite.append(nodes_onsite)
if len(nodes_map) > self._num_nodes:
self._num_nodes = len(nodes_map)
# Class that introduces Disorder into the initially built lattice.
# The informations about the disorder are the type, mean value, and standard deviation. The function that you could use
# in the bulding of the lattice is add_disorder. The class method takes care of the shape of the disorder chosen (it
# needs to be same as the number of orbitals at a given atom), and takes care of the conversion to the c++ orbital-only
# format.
class Disorder:
def __init__(self, lattice):
# type of the disorder, can be 'Gaussian', 'Uniform' and 'Deterministic'.
self._type = []
# type_id of the disorder, can be 'Gaussian': 1, 'Uniform': 2 and 'Deterministic': 3.
self._type_id = []
# mean value of the disorder.
self._mean = []
# standard deviation of the disorder.
self._stdv = []
# orbital that has the chosen disorder.
self._orbital = []
# sublattice that has the chosen disorder.
self._sub_name = []
num_orbitals = np.zeros(lattice.nsub, dtype=np.uint64)
for name, sub in lattice.sublattices.items():
# num of orbitals at each sublattice is equal to size of onsite energy
num_energies = np.asarray(sub.energy).shape[0]
num_orbitals[sub.alias_id] = num_energies
self._num_orbitals_total = np.sum(np.asarray(num_orbitals))
self._num_orbitals = np.asarray(num_orbitals)
self._num_orbitals_before = np.cumsum(np.asarray(num_orbitals)) - num_orbitals
self._lattice = lattice
# class method that introduces the disorder to the lattice
def add_disorder(self, sublattice, dis_type, mean_value, standard_deviation=0.):
# make lists
if not (isinstance(sublattice, list)):
sublattice = [sublattice]
if not (isinstance(dis_type, list)):
dis_type = [dis_type]
mean_value = [mean_value]
standard_deviation = [standard_deviation]
self.add_local_disorder(sublattice, dis_type, mean_value, standard_deviation)
def add_local_disorder(self, sublattice_name, dis_type, mean_value, standard_deviation):
vectors = np.asarray(self._lattice.vectors)
space_size = vectors.shape[0]
names, sublattices = zip(*self._lattice.sublattices.items())
chosen_orbitals_single = -1 * np.ones((self._num_orbitals_total, len(dis_type))) # automatically set to -1
orbital_dis_mean = []
orbital_dis_stdv = []
orbital_dis_type_id = []
for idx_sub, sub_name in enumerate(sublattice_name):
if sub_name not in names:
raise SystemExit('Desired sublattice doesnt exist in the chosen lattice! ')
indx = names.index(sub_name)
lattice_sub = sublattices[indx]
size_orb = self._num_orbitals[lattice_sub.alias_id]
hopping = {'relative_index': np.zeros(space_size, dtype=np.int32), 'from_id': lattice_sub.alias_id,
'to_id': lattice_sub.alias_id, 'mean_value': lattice_sub.energy}
# number of orbitals before i-th sublattice, where is is the array index
orbitals_before = self._num_orbitals_before
orbital_from = []
orbital_dis_mean = []
orbital_dis_stdv = []
orbital_dis_type_id = []
dis_number = {'Gaussian': 1, 'Uniform': 2, 'Deterministic': 3, 'gaussian': 1, 'uniform': 2,
'deterministic': 3}
for index, it in enumerate(mean_value):
if len(mean_value) > 1:
chosen_orbitals_single[idx_sub, index] = orbitals_before[hopping['from_id']] + index
else:
chosen_orbitals_single[idx_sub, index] = hopping['from_id']
orbital_dis_mean.append(it)
orbital_dis_stdv.append(standard_deviation[index])
if dis_type[index] in dis_number:
orbital_dis_type_id.append(dis_number[dis_type[index]])
if dis_type[index] == 'Deterministic' or dis_type[index] == 'deterministic':
if standard_deviation[index] != 0:
raise SystemExit(
'Standard deviation of deterministic disorder must be 0.')
else:
raise SystemExit(
'Disorder not present! Try between Gaussian, Deterministic, and Uniform case insensitive ')
if not (all(np.asarray(i).shape == size_orb for i in [dis_type, mean_value, standard_deviation])):
print('Shape of disorder', len(dis_type), len(mean_value), len(standard_deviation),
'is different than the number of orbitals at sublattice ', sublattice_name, 'which is', size_orb,
'\n')
raise SystemExit('All parameters should have the same length! ')
self._type_id.extend(orbital_dis_type_id)
self._mean.extend(orbital_dis_mean)
self._stdv.extend(orbital_dis_stdv)
if len(self._orbital) == 0:
self._orbital = chosen_orbitals_single
else:
self._orbital = np.column_stack((self._orbital, chosen_orbitals_single))
class Modification:
def __init__(self, **kwargs):
self._magnetic_field = kwargs.get('magnetic_field', None)
self._flux = kwargs.get('flux', None)
@property
def magnetic_field(self): # magnetic_field:
"""Returns true if magnetic field is on, else False."""
return self._magnetic_field
@property
def flux(self): # flux:
"""Returns the number of multiples of flux quantum."""
return self._flux
class Calculation:
@property
def get_dos(self):
"""Returns the requested DOS functions."""
return self._dos
@property
def get_ldos(self):
"""Returns the requested LDOS functions."""
return self._ldos
@property
def get_arpes(self):
"""Returns the requested ARPES functions."""
return self._arpes
@property
def get_gaussian_wave_packet(self):
"""Returns the requested wave packet time evolution function, with a gaussian wavepacket mutiplied with different
plane waves."""
return self._gaussian_wave_packet
@property
def get_conductivity_dc(self):
"""Returns the requested DC conductivity functions."""
return self._conductivity_dc
@property
def get_conductivity_optical(self):
"""Returns the requested optical conductivity functions."""
return self._conductivity_optical
@property
def get_conductivity_optical_nonlinear(self):
"""Returns the requested nonlinear optical conductivity functions."""
return self._conductivity_optical_nonlinear
@property
def get_singleshot_conductivity_dc(self):
"""Returns the requested singleshot DC conductivity functions."""
return self._singleshot_conductivity_dc
def __init__(self, configuration=None):
if configuration is not None and not isinstance(configuration, Configuration):
raise TypeError("You're forwarding a wrong type!")
self._scaling_factor = configuration.energy_scale
self._energy_shift = configuration.energy_shift
self._dos = []
self._ldos = []
self._arpes = []
self._conductivity_dc = []
self._conductivity_optical = []
self._conductivity_optical_nonlinear = []
self._gaussian_wave_packet = []
self._singleshot_conductivity_dc = []
self._avail_dir_full = {'xx': 0, 'yy': 1, 'zz': 2, 'xy': 3, 'xz': 4, 'yx': 5, 'yz': 6, 'zx': 7, 'zy': 8}
self._avail_dir_nonl = {'xxx': 0, 'xxy': 1, 'xxz': 2, 'xyx': 3, 'xyy': 4, 'xyz': 5, 'xzx': 6, 'xzy': 7,
'xzz': 8, 'yxx': 9, 'yxy': 10, 'yxz': 11, 'yyx': 12, 'yyy': 13, 'yyz': 14, 'yzx': 15,
'yzy': 16, 'yzz': 17, 'zxx': 18, 'zxy': 19, 'zxz': 20, 'zyx': 21, 'zyy': 22, 'zyz': 23,
'zzx': 24, 'zzy': 25, 'zzz': 26}
self._avail_dir_sngl = {'xx': 0, 'yy': 1, 'zz': 2}
def dos(self, num_points, num_moments, num_random, num_disorder=1):
"""Calculate the density of states as a function of energy
Parameters
----------
num_points : int
Number of energy point inside the spectrum at which the DOS will be calculated.
num_moments : int
Number of polynomials in the Chebyshev expansion.
num_random : int
Number of random vectors to use for the stochastic evaluation of trace.
num_disorder : int
Number of different disorder realisations.
"""
self._dos.append({'num_points': num_points, 'num_moments': num_moments, 'num_random': num_random,
'num_disorder': num_disorder})
def ldos(self, energy, num_moments, position, sublattice, num_disorder=1):
"""Calculate the density of states as a function of energy
Parameters
----------
energy : list or np.array
List of energy points at which the LDOS will be calculated.
num_moments : int
Number of polynomials in the Chebyshev expansion.
num_disorder : int
Number of different disorder realisations.
position : list
Relative index of the unit cell where the LDOS will be calculated.
sublattice : str or list
Name of the sublattice at which the LDOS will be calculated.
"""
self._ldos.append({'energy': energy, 'num_moments': num_moments, 'position': np.asmatrix(position),
'sublattice': sublattice, 'num_disorder': num_disorder})
def arpes(self, k_vector, weight, num_moments, num_disorder=1):
"""Calculate the density of states as a function of energy
Parameters
----------
k_vector : List
List of K points with respect to reciprocal vectors b0 and b1 at which the band structure will be calculated.
weight : List
List of orbital weights used for ARPES.
num_moments : int
Number of polynomials in the Chebyshev expansion.
num_disorder : int
Number of different disorder realisations.
"""
self._arpes.append({'k_vector': k_vector, 'weight': weight, 'num_moments': num_moments, 'num_disorder': num_disorder})
def gaussian_wave_packet(self, num_points, num_moments, timestep, k_vector, spinor, width, mean_value,
num_disorder=1, **kwargs):
"""Calculate the density of states as a function of energy
Parameters
----------
num_points : int
Number of time points for the time evolution.
num_moments : int
Number of polynomials in the Chebyshev expansion.
timestep : float
Timestep for calculation of time evolution.
k_vector : np.array
Different wave vectors, components corresponding to vectors b0 and b1.
spinor : np.array
Spinors for each of the k vectors.
width : float
Width of the gaussian.
mean_value : [float, float]
Mean value of the gaussian envelope.
num_disorder : int
Number of different disorder realisations.
Optional parameters, forward probing point, defined with x, y coordinate were the wavepacket will be checked
at different timesteps.
"""
probing_point = kwargs.get('probing_point', 0)
self._gaussian_wave_packet.append(
{'num_points': num_points, 'num_moments': num_moments,
'timestep': timestep, 'num_disorder': num_disorder, 'spinor': spinor, 'width': width, 'k_vector': k_vector,
'mean_value': mean_value, 'probing_point': probing_point})
def conductivity_dc(self, direction, num_points, num_moments, num_random, num_disorder=1, temperature=0):
"""Calculate the density of states as a function of energy
Parameters
----------
direction : string
direction in xyz coordinates along which the conductivity is calculated.
Supports 'xx', 'yy', 'zz', 'xy', 'xz', 'yx', 'yz', 'zx', 'zy'.
num_points : int
Number of energy point inside the spectrum at which the DOS will be calculated.
num_moments : int
Number of polynomials in the Chebyshev expansion.
num_random : int
Number of random vectors to use for the stochastic evaluation of trace.
num_disorder : int
Number of different disorder realisations.
temperature : float
Value of the temperature at which we calculate the response.
"""
if direction not in self._avail_dir_full:
print('The desired direction is not available. Choose from a following set: \n',
self._avail_dir_full.keys())
raise SystemExit('Invalid direction!')
else:
self._conductivity_dc.append(
{'direction': self._avail_dir_full[direction], 'num_points': num_points, 'num_moments': num_moments,
'num_random': num_random, 'num_disorder': num_disorder,
'temperature': temperature})
def conductivity_optical(self, direction, num_points, num_moments, num_random, num_disorder=1, temperature=0):
"""Calculate the density of states as a function of energy
Parameters
----------
direction : string
direction in xyz coordinates along which the conductivity is calculated.
Supports 'xx', 'yy', 'zz', 'xy', 'xz', 'yx', 'yz', 'zx', 'zy'.
num_points : int
Number of energy point inside the spectrum at which the DOS will be calculated.
num_moments : int
Number of polynomials in the Chebyshev expansion.
num_random : int
Number of random vectors to use for the stochastic evaluation of trace.
num_disorder : int
Number of different disorder realisations.
temperature : float
Value of the temperature at which we calculate the response.
"""
if direction not in self._avail_dir_full:
print('The desired direction is not available. Choose from a following set: \n',
self._avail_dir_full.keys())
raise SystemExit('Invalid direction!')
else:
self._conductivity_optical.append(
{'direction': self._avail_dir_full[direction], 'num_points': num_points, 'num_moments': num_moments,
'num_random': num_random, 'num_disorder': num_disorder,
'temperature': temperature})
def conductivity_optical_nonlinear(self, direction, num_points, num_moments, num_random, num_disorder=1,
temperature=0, **kwargs):
"""Calculate the density of states as a function of energy
Parameters
----------
direction : string
direction in xyz coordinates along which the conductivity is calculated.
Supports all the combinations of the direction x, y and z with length 3 like 'xxx','zzz', 'xxy', 'xxz' etc.
num_points : int
Number of energy point inside the spectrum at which the DOS will be calculated.
num_moments : int
Number of polynomials in the Chebyshev expansion.
num_random : int
Number of random vectors to use for the stochastic evaluation of trace.
num_disorder : int
Number of different disorder realisations.
temperature : float
Value of the temperature at which we calculate the response.
Optional parameters, forward special, a parameter that can simplify the calculation for some materials.
"""
if direction not in self._avail_dir_nonl:
print('The desired direction is not available. Choose from a following set: \n',
self._avail_dir_nonl.keys())
raise SystemExit('Invalid direction!')
else:
special = kwargs.get('special', 0)
self._conductivity_optical_nonlinear.append(
{'direction': self._avail_dir_nonl[direction], 'num_points': num_points,
'num_moments': num_moments, 'num_random': num_random, 'num_disorder': num_disorder,
'temperature': temperature, 'special': special})
def singleshot_conductivity_dc(self, energy, direction, eta, num_moments, num_random, num_disorder=1, **kwargs):
"""Calculate the density of states as a function of energy
Parameters
----------
energy : ndarray or float
Array or a single value of energies at which singleshot_conductivity_dc will be calculated.
direction : string
direction in xyz coordinates along which the conductivity is calculated.
Supports 'xx', 'yy', 'zz'.
eta : Float
Parameter that affects the broadening of the kernel function.
num_moments : int
Number of polynomials in the Chebyshev expansion.
num_random : int
Number of random vectors to use for the stochastic evaluation of trace.
num_disorder : int
Number of different disorder realisations.
**kwargs: Optional arguments preserve_disorder.
"""
preserve_disorder = kwargs.get('preserve_disorder', False)
if direction not in self._avail_dir_sngl:
print('The desired direction is not available. Choose from a following set: \n',
self._avail_dir_sngl.keys())
raise SystemExit('Invalid direction!')
else:
self._singleshot_conductivity_dc.append(
{'energy': (np.atleast_1d(energy)),
'direction': self._avail_dir_sngl[direction],
'eta': np.atleast_1d(eta), 'num_moments': np.atleast_1d(num_moments),
'num_random': num_random, 'num_disorder': num_disorder,
'preserve_disorder': np.atleast_1d(preserve_disorder)})
class Configuration:
def __init__(self, divisions=(1, 1, 1), length=(1, 1, 1), boundaries=(False, False, False),
is_complex=False, precision=1, spectrum_range=None):
"""Define basic parameters used in the calculation
Parameters
----------
divisions : int, tuple(int, int), tuple(int, int, int)
Number of decomposition parts of the system.
length : int, tuple(int, int), tuple(int, int, int)
Number of unit cells in each direction.
boundaries : int, tuple(int, int), tuple(int, int, int)
Periodic boundary conditions each direction.
is_complex : bool
Boolean that reflects whether the type of Hamiltonian is complex or not.
precision : int
Integer which defines the precision of the number used in the calculation. Float - 0, double - 1,
long double - 2.
spectrum_range : Optional[Tuple[float, float]]
Energy scale which defines the scaling factor of all the energy related parameters. The scaling is done
automatically in the background after this definition. If the term is not specified, a rough estimate of the
bounds is found.
"""
if spectrum_range:
self._energy_scale = (spectrum_range[1] - spectrum_range[0]) / 2
self._energy_shift = (spectrum_range[1] + spectrum_range[0]) / 2
else:
self._energy_scale = None
self._energy_shift = None
# promote to lists
if not (isinstance(length, list)):
length = [length]
if not (isinstance(divisions, list)):
divisions = [divisions]
if not (isinstance(boundaries, list)):
boundaries = [boundaries]
self._is_complex = int(is_complex)
self._precision = precision
self._divisions = divisions
self._boundaries = np.asarray(boundaries).astype(int)
self._length = length
self._htype = np.float32
self.set_type()
def set_type(self, ):
if self._is_complex == 0:
if self._precision == 0:
self._htype = np.float32
elif self._precision == 1:
self._htype = np.float64
elif self._precision == 2:
self._htype = np.float128
else:
raise SystemExit('Precision should be 0, 1 or 2')
else:
if self._precision == 0:
self._htype = np.complex64
elif self._precision == 1:
self._htype = np.complex128
elif self._precision == 2:
self._htype = np.complex256
@property
def energy_scale(self):
"""Returns the energy scale of the hopping parameters."""
return self._energy_scale
@property
def energy_shift(self):
"""Returns the energy shift of the hopping parameters around which the spectrum is centered."""
return self._energy_shift
@property
def comp(self): # -> is_complex:
"""Returns 0 if hamiltonian is real and 1 elsewise."""
return self._is_complex
@property
def prec(self): # -> precision:
"""Returns 0, 1, 2 if precision if float, double, and long double respectively."""
return self._precision
@property
def div(self): # -> divisions:
"""Returns the number of decomposed elements of matrix in x, y and/or z direction. Their product gives the total
number of threads spawn."""
return self._divisions
@property
def bound(self): # -> boundaries:
"""Returns the boundary conditions in each direction, 0 - no boundary condtions, 1 - peridoc bc. """
return self._boundaries
@property
def leng(self): # -> length:
"""Return the number of unit cell repetitions in each direction. """
return self._length
@property
def type(self): # -> type:
"""Return the type of the Hamiltonian complex or real, and float, double or long double. """
return self._htype
def make_pybinding_model(lattice, disorder=None, disorder_structural=None, **kwargs):
"""Build a Pybinding model with disorder used in Kite. Bond disorder or magnetic field are not currently supported.
Parameters
----------
lattice : pb.Lattice
Pybinding lattice object that carries the info about the unit cell vectors, unit cell cites, hopping terms and
onsite energies.
disorder : Disorder
Class that introduces Disorder into the initially built lattice. For more info check the Disorder class.
disorder_structural : StructuralDisorder
Class that introduces StructuralDisorder into the initially built lattice. For more info check the
StructuralDisorder class.
**kwargs: Optional arguments like shape .
"""
shape = kwargs.get('shape', None)
if disorder_structural:
# check if there's a bond disorder term
# return an error if so
disorder_struc_list = disorder_structural
if not isinstance(disorder_structural, list):
disorder_struc_list = [disorder_structural]
for idx_struc, dis_struc in enumerate(disorder_struc_list):
if len(dis_struc._sub_from):
raise SystemExit(
'Automatic scaling is not supported when bond disorder is specified. Please select the scaling '
'bounds manually.')
def gaussian_disorder(sub, mean_value, stdv):
"""Add gaussian disorder with selected mean value and standard deviation to the pybinding model.
Parameters
----------
sub : str
Select a sublattice where disorder should be added.
mean_value : float
Select a mean value of the disorder.
stdv : float
Select standard deviation of the disorder.
"""
@pb.onsite_energy_modifier
def modify_energy(energy, sub_id):
rand_onsite = np.random.normal(loc=mean_value, scale=stdv, size=len(energy[sub_id == sub]))
energy[sub_id == sub] += rand_onsite
return energy
return modify_energy
def deterministic_disorder(sub, mean_value):
"""Add deterministic disorder with selected mean value to the Pybinding model.
Parameters
----------
sub : str
Select a sublattice where disorder should be added.
mean_value : float
Select a mean value of the disorder.
"""
@pb.onsite_energy_modifier
def modify_energy(energy, sub_id):
onsite = mean_value * np.ones(len(energy[sub_id == sub]))
energy[sub_id == sub] += onsite
return energy
return modify_energy
def uniform_disorder(sub, mean_value, stdv):
"""Add uniform disorder with selected mean value and standard deviation to the Pybinding model.
Parameters
----------
sub : str
Select a sublattice where disorder should be added.
mean_value : float
Select a mean value of the disorder.
stdv : float
Select standard deviation of the disorder.
"""
@pb.onsite_energy_modifier
def modify_energy(energy, sub_id):
a = mean_value - stdv * np.sqrt(3)
b = mean_value + stdv * np.sqrt(3)
rand_onsite = np.random.uniform(low=a, high=b, size=len(energy[sub_id == sub]))
energy[sub_id == sub] += rand_onsite
return energy
return modify_energy
def vacancy_disorder(sub, concentration):
"""Add vacancy disorder with selected concentration to the Pybinding model.
Parameters
----------
sub : str
Select a sublattice where disorder should be added.
concentration : float
Concentration of the vacancy disorder.
"""
@pb.site_state_modifier(min_neighbors=2)
def modifier(state, sub_id):
rand_vec = np.random.rand(len(state))
vacant_sublattice = np.logical_and(sub_id == sub, rand_vec < concentration)
state[vacant_sublattice] = False
return state
return modifier
def local_onsite_disorder(positions, value):
"""Add onsite disorder as a part of StructuralDisorder class to the Pybinding model.
Parameters
----------
positions : np.ndarray
Select positions where disorder should appear
value : np.ndarray
Value of the disordered onsite term.
"""
space_size = np.array(positions).shape[1]
@pb.onsite_energy_modifier
def modify_energy(x, y, z, energy):
# all_positions = np.column_stack((x, y, z))[0:space_size, :]
all_positions = np.stack([x, y, z], axis=1)[:, 0:space_size]
kdtree1 = cKDTree(positions)