Skip to content

Band Structure

band.py

Band

This class contains all the methods for constructing band structures from the outputs of VASP band structure calculations.

Parameters:

Name Type Description Default
folder str

This is the folder that contains the VASP files

required
projected bool

Determines whether of not to parse the projected eigenvalues from the PROCAR file. Making this true increases the computational time, so only use if a projected band structure is required.

False
spin str

Choose which spin direction to parse. ('up' or 'down')

'up'
kpath str

High symmetry k-point path of band structure calculation Due to the nature of the KPOINTS file for unfolded calculations this information is a required input for proper labeling of the figure for unfolded calculations. This information is extracted from the KPOINTS files for non-unfolded calculations. (G is automaticall converted to \Gamma)

None
n int

Number of points between each high symmetry point. This is also only required for unfolded calculations. This number should be known by the user, as it was used to generate the KPOINTS file.

None
Source code in vaspvis/band.py
  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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
class Band:
    """
    This class contains all the methods for constructing band structures
    from the outputs of VASP band structure calculations.

    Parameters:
        folder (str): This is the folder that contains the VASP files
        projected (bool): Determines whether of not to parse the projected
            eigenvalues from the PROCAR file. Making this true
            increases the computational time, so only use if a projected
            band structure is required.
        spin (str): Choose which spin direction to parse. ('up' or 'down')
        kpath (str): High symmetry k-point path of band structure calculation
            Due to the nature of the KPOINTS file for unfolded calculations this
            information is a required input for proper labeling of the figure
            for unfolded calculations. This information is extracted from the KPOINTS
            files for non-unfolded calculations. (G is automaticall converted to \\Gamma)
        n (int): Number of points between each high symmetry point.
            This is also only required for unfolded calculations. This number should be
            known by the user, as it was used to generate the KPOINTS file.
    """

    def __init__(
        self,
        folder,
        projected=False,
        unfold=False,
        spin="up",
        kpath=None,
        n=None,
        M=None,
        high_symm_points=None,
        # bandgap=False,
        # printbg=True,
        shift_efermi=0,
        interpolate=True,
        new_n=200,
        custom_kpath=None,
        soc_axis=None,
        stretch_factor=1.0,
    ):
        """
        Initialize parameters upon the generation of this class

        Parameters:
            folder (str): This is the folder that contains the VASP files
            projected (bool): Determines whether of not to parse the projected
                eigenvalues from the PROCAR file. Making this true
                increases the computational time, so only use if a projected
                band structure is required.
            unfold (bool): Determines if the band structure should be unfolded or not.
            spin (str): Choose which spin direction to parse. ('up' or 'down')
            kpath (str): High symmetry k-point path of band structure calculation
                Due to the nature of the KPOINTS file for unfolded calculations this
                information is a required input for proper labeling of the figure
                for unfolded calculations. This information is extracted from the KPOINTS
                files for non-unfolded calculations. (G is automatically converted to \\Gamma)
            n (int): Number of points between each high symmetry point.
                This is also only required for unfolded calculations. This number should be
                known by the user, as it was used to generate the KPOINTS file.
            M (list[list]): Transformation matrix for unfolding calculations. Can be found using
                the conver_slab function in the utils module.
            high_symm_points (list[list]): Coordinates of the high symmetry points of the bulk
                Brilloin zone for an unfolded calculation.
            shift_efermi (float): Gives the option to shift the fermi energy by the specified value
            interpolate (bool): Determines is the data between each high symmetry point should be
                interpolated or not.
            new_n (int): New number of k-points in between each high symmetry point.
            custom_kpath (list): Custom kpath that can be selected is the user desires.
                Given a path G-X-W-L-G-K then there are 5 segements to choose from
                [1 -> G-X, 2 -> X-W, 3 -> W-L, 4 -> L-G, 5 -> G-K]. If a user wanted to
                plot only the path G-X-W they can set custom_kpath=[1,2]. If a user wanted
                to flip the k-path of a segment, then the index should be made negative, so
                if the desired path was G-X|L-W then custom_kpath=[1,-3]
            soc_axis (None or str): This parameter can either take the value of None or the
                it can take the value of 'x', 'y', or 'z'. If either 'x', 'y', or 'z' are given
                then spin='up' states will be defined by positive values of this spin-component
                and spin='down' states will be defined by negative values of this spin-component.
                This will only be used for showing a pseudo-spin-polarized plot for calculations
                that have SOC enabled.
            stretch_factor (float): Used to scale the eigenvalues by a certain constant. Useful for comparing to ARPES data.
                Default is scale_factor = 1.0 (i.e. no scaling)
        """
        self.interpolate = interpolate
        self.soc_axis = soc_axis
        self.new_n = new_n
        self.stretch_factor = stretch_factor
        # self.bandgap = bandgap
        # self.printbg = printbg
        self.eigenval = Eigenval(os.path.join(folder, "EIGENVAL"))
        self.efermi = (
            float(
                os.popen(f'grep E-fermi {os.path.join(folder, "OUTCAR")}')
                .read()
                .split()[2]
            )
            + shift_efermi
        )
        self.poscar = Poscar.from_file(
            os.path.join(folder, "POSCAR"),
            check_for_POTCAR=False,
            read_velocities=False,
        )
        self.incar = Incar.from_file(os.path.join(folder, "INCAR"))
        if "LSORBIT" in self.incar:
            if self.incar["LSORBIT"]:
                self.lsorbit = True
            else:
                self.lsorbit = False
        else:
            self.lsorbit = False

        if "ISPIN" in self.incar:
            if self.incar["ISPIN"] == 2:
                self.ispin = True
            else:
                self.ispin = False
        else:
            self.ispin = False

        if "LHFCALC" in self.incar:
            if self.incar["LHFCALC"]:
                self.hse = True
            else:
                self.hse = False
        else:
            self.hse = False

        self.kpoints_file = Kpoints.from_file(os.path.join(folder, "KPOINTS"))

        self.wavecar = os.path.join(folder, "WAVECAR")
        self.projected = projected

        self.forbitals = self._check_f_orb()
        self.unfold = unfold

        if self.hse and self.unfold:
            self.hse = False

        self.kpath = kpath
        self.n = n
        self.M = M
        self.high_symm_points = high_symm_points
        self.folder = folder
        self.spin = spin
        self.spin_dict = {"up": Spin.up, "down": Spin.down}
        if not self.unfold:
            self.pre_loaded_bands = os.path.isfile(
                os.path.join(folder, "eigenvalues.npy")
            )
            self.eigenvalues, self.kpoints = self._load_bands()
        else:
            self.pre_loaded_bands = os.path.isfile(
                os.path.join(folder, "unfolded_eigenvalues.npy")
            )
            (
                self.eigenvalues,
                self.spectral_weights,
                self.K_indices,
                self.kpoints,
            ) = self._load_bands_unfold()

        if self.stretch_factor != 1.0:
            self.eigenvalues *= self.stretch_factor

        self.color_dict = {
            0: "#FF0000",
            1: "#0000FF",
            2: "#008000",
            3: "#800080",
            4: "#E09200",
            5: "#FF5C77",
            6: "#778392",
            7: "#07C589",
            8: "#40BAF2",
            9: "#FF0000",
            10: "#0000FF",
            11: "#008000",
            12: "#800080",
            13: "#E09200",
            14: "#FF5C77",
            15: "#778392",
        }
        self.orbital_labels = {
            0: "s",
            1: "p_{y}",
            2: "p_{z}",
            3: "p_{x}",
            4: "d_{xy}",
            5: "d_{yz}",
            6: "d_{z^{2}}",
            7: "d_{xz}",
            8: "d_{x^{2}-y^{2}}",
            9: "f_{y^{3}x^{2}}",
            10: "f_{xyz}",
            11: "f_{yz^{2}}",
            12: "f_{z^{3}}",
            13: "f_{xz^{2}}",
            14: "f_{zx^{3}}",
            15: "f_{x^{3}}",
        }
        self.spd_relations = {
            "s": 0,
            "p": 1,
            "d": 2,
            "f": 3,
        }
        # if self.bandgap:
        #     self.bg = self._get_bandgap()
        # else:
        #     self.bg = None

        self.custom_kpath = custom_kpath
        if self.custom_kpath is not None:
            (
                self.custom_kpath_inds,
                self.custom_kpath_flip,
            ) = self._get_custom_kpath()
        #  else:
        #  self.custom_kpath_inds, self.custom_kpath_flip = None, None

        if projected:
            self.pre_loaded_projections = os.path.isfile(
                os.path.join(folder, "projected_eigenvalues.npy")
            )
            self.projected_eigenvalues = self._load_projected_bands()

        if soc_axis is not None and self.lsorbit:
            self.pre_loaded_spin_projections = os.path.isfile(
                os.path.join(folder, "spin_projections.npy")
            )
            self.spin_projections = self._load_soc_spin_projection()

    def _get_custom_kpath(self):
        flip = (-np.sign(self.custom_kpath) + 1).astype(bool)
        inds = (np.abs(self.custom_kpath) - 1).astype(int)

        return inds, flip

    # def _get_bandgap(self):
    #     from vaspvis.utils import BandGap
    #     self.bg = BandGap(
    #         folder=self.folder,
    #         printbg=self.printbg,
    #     )

    def _check_f_orb(self):
        f_elements = [
            "La",
            "Ac",
            "Ce",
            "Tb",
            "Th",
            "Pr",
            "Dy",
            "Pa",
            "Nd",
            "Ho",
            "U",
            "Pm",
            "Er",
            "Np",
            "Sm",
            "Tm",
            "Pu",
            "Eu",
            "Yb",
            "Am",
            "Gd",
            "Lu",
        ]
        f = False
        for element in self.poscar.site_symbols:
            if element in f_elements:
                f = True

        return f

    def _load_bands(self):
        """
        This function is used to load eigenvalues from the vasprun.xml
        file and into a dictionary which is in the form of
        band index --> eigenvalues

        Returns:
            bands_dict (dict[str][np.ndarray]): Dictionary which contains
                the eigenvalues for each band
        """

        if self.spin == "up":
            spin = 0
        if self.spin == "down":
            spin = 1

        if self.pre_loaded_bands:
            with open(
                os.path.join(self.folder, "eigenvalues.npy"), "rb"
            ) as eigenvals:
                band_data = np.load(eigenvals)

            if self.ispin and not self.lsorbit:
                eigenvalues = band_data[:, :, [0, 2]]
                kpoints = band_data[0, :, 4:]
            else:
                eigenvalues = band_data[:, :, 0]
                kpoints = band_data[0, :, 2:]
        else:
            if len(self.eigenval.eigenvalues.keys()) > 1:
                eigenvalues_up = np.transpose(
                    self.eigenval.eigenvalues[Spin.up], axes=(1, 0, 2)
                )
                eigenvalues_down = np.transpose(
                    self.eigenval.eigenvalues[Spin.down], axes=(1, 0, 2)
                )
                eigenvalues_up[:, :, 0] = eigenvalues_up[:, :, 0] - self.efermi
                eigenvalues_down[:, :, 0] = (
                    eigenvalues_down[:, :, 0] - self.efermi
                )
                eigenvalues = np.concatenate(
                    [eigenvalues_up, eigenvalues_down], axis=2
                )
            else:
                eigenvalues = np.transpose(
                    self.eigenval.eigenvalues[Spin.up], axes=(1, 0, 2)
                )
                eigenvalues[:, :, 0] = eigenvalues[:, :, 0] - self.efermi

            kpoints = np.array(self.eigenval.kpoints)

            if self.hse:
                kpoint_weights = np.array(self.eigenval.kpoints_weights)
                zero_weight = np.where(kpoint_weights == 0)[0]
                eigenvalues = eigenvalues[:, zero_weight]
                kpoints = kpoints[zero_weight]

            band_data = np.append(
                eigenvalues,
                np.tile(kpoints, (eigenvalues.shape[0], 1, 1)),
                axis=2,
            )

            np.save(os.path.join(self.folder, "eigenvalues.npy"), band_data)

            if len(self.eigenval.eigenvalues.keys()) > 1:
                eigenvalues = eigenvalues[:, :, [0, 2]]
            else:
                eigenvalues = eigenvalues[:, :, 0]

        if len(self.eigenval.eigenvalues.keys()) > 1:
            eigenvalues = eigenvalues[:, :, spin]

        return eigenvalues, kpoints

    def _load_bands_unfold(self):
        if self.spin == "up":
            spin = 0
        if self.spin == "down":
            if self.lsorbit:
                spin = 0
            else:
                spin = 1

        kpath = make_kpath(self.high_symm_points, nseg=self.n)

        if self.pre_loaded_bands:
            with open(
                os.path.join(self.folder, "unfolded_eigenvalues.npy"), "rb"
            ) as eigenvals:
                band_data = np.load(eigenvals)
        else:
            wavecar_data = unfold(
                M=self.M,
                wavecar=self.wavecar,
                lsorbit=self.lsorbit,
            )
            band_data = wavecar_data.spectral_weight(kpath)
            np.save(
                os.path.join(self.folder, "unfolded_eigenvalues.npy"),
                band_data,
            )

        band_data = np.transpose(band_data[spin], axes=(2, 1, 0))
        eigenvalues, spectral_weights, K_indices = band_data
        eigenvalues = eigenvalues - self.efermi
        kpath = np.array(kpath)

        path_len = len(self.kpath)
        n = self.n
        inserts = [n * (i + 1) for i in range(path_len - 1)]
        inds = list(range(n * path_len + 1))
        for i in reversed(inserts):
            inds.insert(i, i)

        kpath = kpath[inds]
        spectral_weights = spectral_weights[:, inds]
        K_indices = K_indices[:, inds]
        eigenvalues = eigenvalues[:, inds]

        return eigenvalues, spectral_weights, K_indices, kpath

    def _load_projected_bands(self):
        """
        This function loads the project weights of the orbitals in each band
        from vasprun.xml into a dictionary of the form:
        band index --> atom index --> weights of orbitals

        Returns:
            projected_dict (dict([str][int][pd.DataFrame])): Dictionary containing the projected weights of all orbitals on each atom for each band.
        """

        if self.lsorbit:
            if self.soc_axis is None:
                spin = 0
            elif self.soc_axis == "x":
                spin = 1
            elif self.soc_axis == "y":
                spin = 2
            elif self.soc_axis == "z":
                spin = 3
        else:
            if self.spin == "up":
                spin = 0
            elif self.spin == "down":
                spin = 1

        if not os.path.isfile(os.path.join(self.folder, "PROCAR_repaired")):
            UtilsProcar().ProcarRepair(
                os.path.join(self.folder, "PROCAR"),
                os.path.join(self.folder, "PROCAR_repaired"),
            )

        if self.pre_loaded_projections:
            with open(
                os.path.join(self.folder, "projected_eigenvalues.npy"), "rb"
            ) as projected_eigenvals:
                projected_eigenvalues = np.load(projected_eigenvals)
        else:
            parser = ProcarParser()
            parser.readFile(os.path.join(self.folder, "PROCAR_repaired"))
            if (
                self.ispin
                and not self.lsorbit
                and np.sum(self.poscar.natoms) == 1
            ):
                shape = int(parser.spd.shape[1] / 2)
                projected_eigenvalues_up = np.transpose(
                    parser.spd[:, :shape, 0, :, 1:-1], axes=(1, 0, 2, 3)
                )
                projected_eigenvalues_down = np.transpose(
                    parser.spd[:, shape:, 0, :, 1:-1], axes=(1, 0, 2, 3)
                )
                projected_eigenvalues = np.concatenate(
                    [
                        projected_eigenvalues_up[:, :, :, :, np.newaxis],
                        projected_eigenvalues_down[:, :, :, :, np.newaxis],
                    ],
                    axis=4,
                )
                projected_eigenvalues = np.transpose(
                    projected_eigenvalues, axes=(0, 1, 4, 2, 3)
                )
            elif (
                self.ispin
                and not self.lsorbit
                and np.sum(self.poscar.natoms) != 1
            ):
                shape = int(parser.spd.shape[1] / 2)
                projected_eigenvalues_up = np.transpose(
                    parser.spd[:, :shape, 0, :-1, 1:-1], axes=(1, 0, 2, 3)
                )
                projected_eigenvalues_down = np.transpose(
                    parser.spd[:, shape:, 0, :-1, 1:-1], axes=(1, 0, 2, 3)
                )
                projected_eigenvalues = np.concatenate(
                    [
                        projected_eigenvalues_up[:, :, :, :, np.newaxis],
                        projected_eigenvalues_down[:, :, :, :, np.newaxis],
                    ],
                    axis=4,
                )
                projected_eigenvalues = np.transpose(
                    projected_eigenvalues, axes=(0, 1, 4, 2, 3)
                )
            else:
                if np.sum(self.poscar.natoms) == 1:
                    projected_eigenvalues = np.transpose(
                        parser.spd[:, :, :, :, 1:-1], axes=(1, 0, 2, 3, 4)
                    )
                else:
                    projected_eigenvalues = np.transpose(
                        parser.spd[:, :, :, :-1, 1:-1], axes=(1, 0, 2, 3, 4)
                    )

            np.save(
                os.path.join(self.folder, "projected_eigenvalues.npy"),
                projected_eigenvalues,
            )

        projected_eigenvalues = projected_eigenvalues[:, :, spin, :, :]

        if self.lsorbit and self.soc_axis is not None:
            separated_projections = np.zeros(
                projected_eigenvalues.shape + (2,)
            )
            separated_projections[
                projected_eigenvalues > 0, 0
            ] = projected_eigenvalues[projected_eigenvalues > 0]
            separated_projections[
                projected_eigenvalues < 0, 1
            ] = -projected_eigenvalues[projected_eigenvalues < 0]

            if self.spin == "up":
                soc_spin = 0
            elif self.spin == "down":
                soc_spin = 1

            projected_eigenvalues = separated_projections[..., soc_spin]

        if self.hse:
            kpoint_weights = np.array(self.eigenval.kpoints_weights)
            zero_weight = np.where(kpoint_weights == 0)[0]
            projected_eigenvalues = projected_eigenvalues[:, zero_weight]

        projected_eigenvalues = np.square(projected_eigenvalues)

        return projected_eigenvalues

    def _load_soc_spin_projection(self):
        """
        This function loads the project weights of the orbitals in each band
        from vasprun.xml into a dictionary of the form:
        band index --> atom index --> weights of orbitals

        Returns:
            projected_dict (dict([str][int][pd.DataFrame])): Dictionary containing the projected weights of all orbitals on each atom for each band.
        """

        if not self.lsorbit:
            raise BaseException(
                f"You selected soc_axis='{self.soc_axis}' for a non-soc axis calculation, please set soc_axis=None"
            )
        if self.lsorbit and self.soc_axis == "x":
            spin = 1
        if self.lsorbit and self.soc_axis == "y":
            spin = 2
        if self.lsorbit and self.soc_axis == "z":
            spin = 3

        if not os.path.isfile(os.path.join(self.folder, "PROCAR_repaired")):
            UtilsProcar().ProcarRepair(
                os.path.join(self.folder, "PROCAR"),
                os.path.join(self.folder, "PROCAR_repaired"),
            )

        if self.pre_loaded_spin_projections:
            with open(
                os.path.join(self.folder, "spin_projections.npy"), "rb"
            ) as spin_projs:
                spin_projections = np.load(spin_projs)
        else:
            parser = ProcarParser()
            parser.readFile(os.path.join(self.folder, "PROCAR_repaired"))
            spin_projections = np.transpose(
                parser.spd[:, :, :, -1, -1], axes=(1, 0, 2)
            )

            np.save(
                os.path.join(self.folder, "spin_projections.npy"),
                spin_projections,
            )

        spin_projections = spin_projections[:, :, spin]

        if self.hse:
            kpoint_weights = np.array(self.eigenval.kpoints_weights)
            zero_weight = np.where(kpoint_weights == 0)[0]
            spin_projections = spin_projections[:, zero_weight]

        separated_projections = np.zeros(
            (spin_projections.shape[0], spin_projections.shape[1], 2)
        )
        separated_projections[spin_projections > 0, 0] = spin_projections[
            spin_projections > 0
        ]
        separated_projections[spin_projections < 0, 1] = -spin_projections[
            spin_projections < 0
        ]

        separated_projections = (
            separated_projections / separated_projections.max()
        )

        if self.spin == "up":
            separated_projections = separated_projections[:, :, 0]
        elif self.spin == "down":
            separated_projections = separated_projections[:, :, 1]
        else:
            raise BaseException(
                "The soc_axis feature does not work with spin='both'"
            )

        return separated_projections

    def _sum_spd(self, spd):
        """
        This function sums the weights of the s, p, and d orbitals for each atom
        and creates a dictionary of the form:
        band index --> s,p,d orbital weights

        Returns:
            spd_dict (dict([str][pd.DataFrame])): Dictionary that contains the summed weights for the s, p, and d orbitals for each band
        """

        if not self.forbitals:
            spd_indices = [
                np.array([False for _ in range(9)]) for i in range(3)
            ]
            spd_indices[0][0] = True
            spd_indices[1][1:4] = True
            spd_indices[2][4:] = True
        else:
            spd_indices = [
                np.array([False for _ in range(16)]) for i in range(4)
            ]
            spd_indices[0][0] = True
            spd_indices[1][1:4] = True
            spd_indices[2][4:9] = True
            spd_indices[3][9:] = True

        orbital_contributions = np.sum(self.projected_eigenvalues, axis=2)

        spd_contributions = np.transpose(
            np.array(
                [
                    np.sum(orbital_contributions[:, :, ind], axis=2)
                    for ind in spd_indices
                ]
            ),
            axes=[1, 2, 0],
        )

        #  norm_term = np.sum(spd_contributions, axis=2)[:,:,np.newaxis]
        #  spd_contributions = np.divide(spd_contributions, norm_term, out=np.zeros_like(spd_contributions), where=norm_term!=0)

        spd_contributions = spd_contributions[
            :, :, [self.spd_relations[orb] for orb in spd]
        ]

        return spd_contributions

    def _sum_orbitals(self, orbitals):
        """
        This function finds the weights of desired orbitals for all atoms and
            returns a dictionary of the form:
            band index --> orbital index

        Parameters:
            orbitals (list): List of desired orbitals.
                0 = s
                1 = py
                2 = pz
                3 = px
                4 = dxy
                5 = dyz
                6 = dz2
                7 = dxz
                8 = dx2-y2
                9 = fy3x2
                10 = fxyz
                11 = fyz2
                12 = fz3
                13 = fxz2
                14 = fzx3
                15 = fx3

        Returns:
            orbital_dict (dict[str][pd.DataFrame]): Dictionary that contains the projected weights of the selected orbitals.
        """
        orbital_contributions = self.projected_eigenvalues.sum(axis=2)
        #  norm_term =  np.sum(orbital_contributions, axis=2)[:,:,np.newaxis]
        #  orbital_contributions = np.divide(orbital_contributions, norm_term, out=np.zeros_like(orbital_contributions), where=norm_term!=0)
        orbital_contributions = orbital_contributions[:, :, [orbitals]]

        return orbital_contributions

    def _sum_atoms(self, atoms, spd=False):
        """
        This function finds the weights of desired atoms for all orbitals and
            returns a dictionary of the form:
            band index --> atom index

        Parameters:
            atoms (list): List of desired atoms where atom 0 is the first atom in
                the POSCAR file.

        Returns:
            atom_dict (dict[str][pd.DataFrame]): Dictionary that contains the projected
                weights of the selected atoms.
        """

        if spd:
            if not self.forbitals:
                spd_indices = [
                    np.array([False for _ in range(9)]) for i in range(3)
                ]
                spd_indices[0][0] = True
                spd_indices[1][1:4] = True
                spd_indices[2][4:] = True
            else:
                spd_indices = [
                    np.array([False for _ in range(16)]) for i in range(4)
                ]
                spd_indices[0][0] = True
                spd_indices[1][1:4] = True
                spd_indices[2][4:9] = True
                spd_indices[3][9:] = True

            atoms_spd = np.transpose(
                np.array(
                    [
                        np.sum(
                            self.projected_eigenvalues[:, :, :, ind], axis=3
                        )
                        for ind in spd_indices
                    ]
                ),
                axes=(1, 2, 3, 0),
            )

            #  atoms_spd = atoms_spd[:,:,[atoms], :]

            #  norm_term = np.sum(atoms_spd_to_norm, axis=(2,3))[:,:, np.newaxis]
            #  atoms_spd = np.divide(atoms_spd, norm_term, out=np.zeros_like(atoms_spd), where=norm_term!=0)

            return atoms_spd
        else:
            atoms_array = self.projected_eigenvalues.sum(axis=3)
            #  norm_term = np.sum(atoms_array, axis=2)[:,:,np.newaxis]
            #  atoms_array = np.divide(atoms_array, norm_term, out=np.zeros_like(atoms_array), where=norm_term!=0)
            atoms_array = atoms_array[:, :, [atoms]]

            return atoms_array

    def _sum_elements(
        self, elements, orbitals=False, spd=False, spd_options=None
    ):
        """
        This function sums the weights of the orbitals of specific elements within the
        calculated structure and returns a dictionary of the form:
        band index --> element label --> orbital weights for orbitals = True
        band index --> element label for orbitals = False
        This is useful for structures with many elements because manually entering indicies is
        not practical for large structures.

        Parameters:
            elements (list): List of element symbols to sum the weights of.
            orbitals (bool): Determines whether or not to inclue orbitals or not
                (True = keep orbitals, False = sum orbitals together )
            spd (bool): Determines whether or not to sum the s, p, and d orbitals


        Returns:
            element_dict (dict([str][str][pd.DataFrame])): Dictionary that contains the summed weights for each orbital for a given element in the structure.
        """

        poscar = self.poscar
        natoms = poscar.natoms
        symbols = poscar.site_symbols
        projected_eigenvalues = self.projected_eigenvalues

        element_list = np.hstack(
            [
                [symbols[i] for j in range(natoms[i])]
                for i in range(len(symbols))
            ]
        )

        element_indices = [
            np.where(np.isin(element_list, element))[0] for element in elements
        ]

        element_orbitals = np.transpose(
            np.array(
                [
                    np.sum(projected_eigenvalues[:, :, ind, :], axis=2)
                    for ind in element_indices
                ]
            ),
            axes=(1, 2, 0, 3),
        )

        if orbitals:
            return element_orbitals
        elif spd:
            if not self.forbitals:
                spd_indices = [
                    np.array([False for _ in range(9)]) for i in range(3)
                ]
                spd_indices[0][0] = True
                spd_indices[1][1:4] = True
                spd_indices[2][4:] = True
            else:
                spd_indices = [
                    np.array([False for _ in range(16)]) for i in range(4)
                ]
                spd_indices[0][0] = True
                spd_indices[1][1:4] = True
                spd_indices[2][4:9] = True
                spd_indices[3][9:] = True

            element_spd = np.transpose(
                np.array(
                    [
                        np.sum(element_orbitals[:, :, :, ind], axis=3)
                        for ind in spd_indices
                    ]
                ),
                axes=(1, 2, 3, 0),
            )

            #  norm_term = np.sum(element_spd, axis=(2,3))[:,:,np.newaxis, np.newaxis]
            #  element_spd = np.divide(element_spd, norm_term, out=np.zeros_like(element_spd), where=norm_term!=0)

            return element_spd
        else:
            element_array = np.sum(element_orbitals, axis=3)
            #  norm_term = np.sum(element_array, axis=2)[:,:,np.newaxis]
            #  element_array = np.divide(element_array, norm_term, out=np.zeros_like(element_array), where=norm_term!=0)

            return element_array

    def _get_k_distance_old(self):
        cell = self.poscar.structure.lattice.matrix
        kpt_c = np.dot(self.kpoints, np.linalg.inv(cell).T)
        kdist = np.r_[
            0, np.cumsum(np.linalg.norm(np.diff(kpt_c, axis=0), axis=1))
        ]

        return kdist

    def _get_k_distance(self):
        slices = self._get_slices(unfold=self.unfold, hse=self.hse)
        kdists = []

        if self.custom_kpath is not None:
            #  if self.custom_kpath is None:
            index = self.custom_kpath_inds
        else:
            index = range(len(slices))

        for j, i in enumerate(index):
            inv_cell = deepcopy(self.poscar.structure.lattice.inv_matrix)
            inv_cell_norms = np.linalg.norm(inv_cell, axis=1)
            inv_cell /= inv_cell_norms.min()

            # If you want to be able to compare only identical relative cell lengths
            kpt_c = np.dot(self.kpoints[slices[i]], inv_cell.T)

            # If you want to be able to compare any cell length. Maybe straining an orthorhombic cell or something like that
            # This will mess up relative distances though
            # kpt_c = self.kpoints[slices[i]]
            kdist = np.r_[
                0, np.cumsum(np.linalg.norm(np.diff(kpt_c, axis=0), axis=1))
            ]
            if j == 0:
                kdists.append(kdist)
            else:
                kdists.append(kdist + kdists[-1][-1])

        # kdists = np.array(kdists)

        return kdists

    def _get_kticks(self, ax, wave_vectors, vlinecolor):
        """
        This function extracts the kpoint labels and index locations for a regular
        band structure calculation (non unfolded).

        Parameters:
            ax (matplotlib.pyplot.axis): Axis to append the tick labels
        """

        high_sym_points = self.kpoints_file.kpts

        segements = []
        for i in range(0, len(high_sym_points) - 1):
            if not i % 2:
                segements.append([i, i + 1])

        if self.custom_kpath is not None:
            high_sym_points_inds = []
            for i, b in zip(self.custom_kpath_inds, self.custom_kpath_flip):
                if b:
                    seg = list(reversed(segements[i]))
                else:
                    seg = segements[i]

                high_sym_points_inds.extend(seg)
        else:
            high_sym_points_inds = list(range(len(high_sym_points)))

        num_kpts = self.kpoints_file.num_kpts
        kpts_labels = np.array(
            [
                f"${k}$" if k != "G" else "$\\Gamma$"
                for k in self.kpoints_file.labels
            ]
        )
        all_kpoints = self.kpoints

        group_index = []
        for i, j in enumerate(high_sym_points_inds):
            if i == 0:
                group_index.append([j])
            if i % 2 and not i == len(high_sym_points_inds) - 1:
                group_index.append([j, high_sym_points_inds[i + 1]])
            if i == len(high_sym_points_inds) - 1:
                group_index.append([j])

        labels = []
        index = []

        for i in group_index:
            if len(i) == 1:
                labels.append(kpts_labels[i[0]])
                index.append(i[0])
            else:
                if kpts_labels[i[0]] == kpts_labels[i[1]]:
                    labels.append(kpts_labels[i[0]])
                    index.append(i[0])
                else:
                    merged_label = "|".join(
                        [
                            kpts_labels[i[0]],
                            kpts_labels[i[1]],
                        ]
                    ).replace("$|$", "|")
                    labels.append(merged_label)
                    index.append(i[0])

        kpoints_index = [0] + [
            (i + 1) * num_kpts - 1
            for i in range(int((len(high_sym_points_inds) + 1) / 2))
        ]

        for k in kpoints_index:
            ax.axvline(
                x=wave_vectors[k], color=vlinecolor, alpha=0.7, linewidth=0.5
            )

        ax.set_xticks([wave_vectors[k] for k in kpoints_index])
        ax.set_xticklabels(labels)

    def _get_kticks_hse(self, wave_vectors, ax, kpath, vlinecolor):
        structure = self.poscar.structure
        kpath_obj = HighSymmKpath(structure)
        kpath_labels = np.array(list(kpath_obj._kpath["kpoints"].keys()))
        kpath_coords = np.array(list(kpath_obj._kpath["kpoints"].values()))
        index = np.where(
            np.isclose(
                self.kpoints[:, None],
                kpath_coords,
            )
            .all(-1)
            .any(-1)
            == True
        )[0]

        segements = []
        for i in range(0, len(index) - 1):
            if not i % 2:
                segements.append([index[i], index[i + 1]])

        if self.custom_kpath is not None:
            high_sym_points_inds = []
            for i, b in zip(self.custom_kpath_inds, self.custom_kpath_flip):
                if b:
                    seg = list(reversed(segements[i]))
                else:
                    seg = segements[i]

                high_sym_points_inds.extend(seg)
        else:
            high_sym_points_inds = list(np.concatenate(segements))

        full_segments = []
        for i in range(0, len(high_sym_points_inds) - 1):
            if not i % 2:
                full_segments.append(
                    [high_sym_points_inds[i], high_sym_points_inds[i + 1]]
                )

        segment_lengths = [np.abs(i[1] - i[0]) + 1 for i in full_segments]
        kpoints_index = [0] + [
            np.sum(segment_lengths[:i])
            for i in range(1, len(segment_lengths) + 1)
        ]
        kpoints_index[-1] -= 1

        group_index = []
        for i, j in enumerate(high_sym_points_inds):
            if i == 0:
                group_index.append([j])
            if i % 2 and not i == len(high_sym_points_inds) - 1:
                group_index.append([j, high_sym_points_inds[i + 1]])
            if i == len(high_sym_points_inds) - 1:
                group_index.append([j])

        kpoints_in_band = []
        for group in group_index:
            g = [self.kpoints[g] for g in group]
            kpoints_in_band.append(g)

        group_labels = []
        for kpoints in kpoints_in_band:
            group = []
            for k in kpoints:
                for i, coords in enumerate(kpath_coords):
                    if (np.round(k, 5) == np.round(coords, 5)).all():
                        group.append(kpath_labels[i])
            group_labels.append(group)

        labels = []
        index = []

        for label in group_labels:
            if len(label) == 1:
                labels.append(label[0])
            else:
                if label[0] == label[1]:
                    labels.append(label[0])
                else:
                    merged_label = "|".join(
                        [
                            label[0],
                            label[1],
                        ]
                    ).replace("$|$", "|")
                    labels.append(merged_label)

        kpath = [f"${k}$" if k != "G" else "$\\Gamma$" for k in labels]

        for k in kpoints_index:
            ax.axvline(
                x=wave_vectors[k], color=vlinecolor, alpha=0.7, linewidth=0.5
            )

        ax.set_xticks([wave_vectors[k] for k in kpoints_index], kpath)

    def _get_kticks_unfold(self, ax, wave_vectors, vlinecolor):
        if self.custom_kpath is not None:
            kpath = []
            for i, b in zip(self.custom_kpath_inds, self.custom_kpath_flip):
                if b:
                    seg = list(reversed(self.kpath[i]))
                else:
                    seg = self.kpath[i]

                kpath.extend(seg)
        else:
            kpath = []
            for seg in self.kpath:
                kpath.extend(seg)

        kpath = [
            f"${k.strip()}$" if k.strip() != "G" else "$\\Gamma$"
            for k in kpath
        ]

        group_kpath = []
        for i, j in enumerate(kpath):
            if i == 0:
                group_kpath.append([j])
            if i % 2 and not i == len(kpath) - 1:
                group_kpath.append([j, kpath[i + 1]])
            if i == len(kpath) - 1:
                group_kpath.append([j])

        labels = []

        for k in group_kpath:
            if len(k) == 1:
                labels.append(k[0])
            else:
                if k[0] == k[1]:
                    labels.append(k[0])
                else:
                    merged_label = "|".join([k[0], k[1]]).replace("$|$", "|")
                    labels.append(merged_label)

        n = int(len(self.kpoints) / len(self.kpath))
        kpoints_index = [0] + [(n * i) for i in range(1, len(labels))]
        kpoints_index[-1] -= 1

        for k in kpoints_index:
            ax.axvline(
                x=wave_vectors[k], color=vlinecolor, alpha=0.7, linewidth=0.5
            )

        ax.set_xticks(wave_vectors[kpoints_index])
        ax.set_xticklabels(labels)
        #  plt.xticks(np.array(kpoints)[kpoints_index], kpath)

    def _get_kticks_unfold_old(self, ax, wave_vectors, vlinecolor):
        if type(self.kpath) == str:
            kpath = [
                f"${k}$" if k != "G" else "$\\Gamma$"
                for k in self.kpath.upper().strip()
            ]
        elif type(self.kpath) == list:
            kpath = self.kpath

        kpoints_index = [0] + [(self.n * i) for i in range(1, len(self.kpath))]
        kpoints_index[-1] -= 1

        for k in kpoints_index:
            ax.axvline(
                x=wave_vectors[k], color=vlinecolor, alpha=0.7, linewidth=0.5
            )

        ax.set_xticks(wave_vectors[kpoints_index])
        ax.set_xticklabels(kpath)
        #  plt.xticks(np.array(kpoints)[kpoints_index], kpath)

    def _get_kticks_old(self, ax, wave_vectors, vlinecolor):
        """
        This function extracts the kpoint labels and index locations for a regular
        band structure calculation (non unfolded).

        Parameters:
            ax (matplotlib.pyplot.axis): Axis to append the tick labels
        """

        high_sym_points = self.kpoints_file.kpts
        kpts_labels = np.array(
            [
                f"${k}$" if k != "G" else "$\\Gamma$"
                for k in self.kpoints_file.labels
            ]
        )
        all_kpoints = self.kpoints

        index = [0]
        for i in range(len(high_sym_points) - 2):
            if high_sym_points[i + 2] != high_sym_points[i + 1]:
                index.append(i)
        index.append(len(high_sym_points) - 1)

        kpts_loc = np.isin(
            np.round(all_kpoints, 3), np.round(high_sym_points, 3)
        ).all(1)
        kpoints_index = np.where(kpts_loc == True)[0]

        kpts_labels = kpts_labels[index]
        kpoints_index = list(kpoints_index[index])
        #  kpoints_index = ax.lines[0].get_xdata()[kpoints_index]

        for k in kpoints_index:
            ax.axvline(
                x=wave_vectors[k], color=vlinecolor, alpha=0.7, linewidth=0.5
            )

        ax.set_xticks([wave_vectors[k] for k in kpoints_index])
        ax.set_xticklabels(kpts_labels)

    def _get_kticks_hse_old(self, wave_vectors, ax, kpath, vlinecolor):
        structure = self.poscar.structure
        kpath_obj = HighSymmKpath(structure)
        kpath_labels = np.array(list(kpath_obj._kpath["kpoints"].keys()))
        kpath_coords = np.array(list(kpath_obj._kpath["kpoints"].values()))
        index = np.where(
            np.isclose(
                self.kpoints[:, None],
                kpath_coords,
            )
            .all(-1)
            .any(-1)
            == True
        )[0]
        #  index = np.where(np.isclose(self.kpoints[:, None], kpath_coords).all(-1).any(-1) == True)[0]
        #  index = np.where((self.kpoints[:, None] == kpath_coords).all(-1).any(-1) == True)[0]
        index = (
            [index[0]]
            + [index[i] for i in range(1, len(index) - 1) if i % 2]
            + [index[-1]]
        )
        kpoints_in_band = self.kpoints[index]

        label_index = []
        for i in range(kpoints_in_band.shape[0]):
            for j in range(kpath_coords.shape[0]):
                if (
                    np.round(kpoints_in_band[i], 5)
                    == np.round(kpath_coords[j], 5)
                ).all():
                    label_index.append(j)

        kpoints_index = index
        kpath = kpath_labels[label_index]
        #  kpoints_index = ax.lines[0].get_xdata()[kpoints_index]

        kpath = [f"${k}$" if k != "G" else "$\\Gamma$" for k in kpath]

        for k in kpoints_index:
            ax.axvline(
                x=wave_vectors[k], color=vlinecolor, alpha=0.7, linewidth=0.5
            )

        plt.xticks([wave_vectors[k] for k in kpoints_index], kpath)

    def _get_slices(self, unfold=False, hse=False):
        if not unfold and not hse:
            high_sym_points = self.kpoints_file.kpts
            all_kpoints = self.kpoints
            num_kpts = self.kpoints_file.num_kpts
            num_slices = int(len(high_sym_points) / 2)
            slices = [
                slice(i * num_kpts, (i + 1) * num_kpts, None)
                for i in range(num_slices)
            ]

        if hse and not unfold:
            structure = self.poscar.structure
            kpath_obj = HighSymmKpath(structure)
            kpath_coords = np.array(list(kpath_obj._kpath["kpoints"].values()))
            index = np.where(
                np.isclose(
                    self.kpoints[:, None],
                    kpath_coords,
                )
                .all(-1)
                .any(-1)
                == True
            )[0]

            segements = []
            for i in range(0, len(index) - 1):
                if not i % 2:
                    segements.append([index[i], index[i + 1]])

            # print(segements)

            num_kpts = int(len(self.kpoints) / (len(index) / 2))
            slices = [
                slice(i * num_kpts, (i + 1) * num_kpts, None)
                for i in range(int(len(index) / 2))
            ]
            # print(slices)
            slices = [slice(i[0], i[1] + 1, None) for i in segements]
            # print(slices)

        if unfold and not hse:
            n = int(len(self.kpoints) / len(self.kpath))
            slices = [
                slice(i * n, (i + 1) * n, None)
                for i in range(int(len(self.kpath)))
            ]

        return slices

    def _get_slices_old(self, unfold=False, hse=False):
        if not unfold and not hse:
            high_sym_points = self.kpoints_file.kpts
            all_kpoints = self.kpoints
            num_kpts = self.kpoints_file.num_kpts

            if self.custom_kpath is not None:
                num_slices = len(self.custom_kpath_inds)
            else:
                num_slices = int(len(high_sym_points) / 2)

            slices = [
                slice(i * num_kpts, (i + 1) * num_kpts, None)
                for i in range(num_slices)
            ]

        if hse and not unfold:
            structure = self.poscar.structure
            kpath_obj = HighSymmKpath(structure)
            kpath_coords = np.array(list(kpath_obj._kpath["kpoints"].values()))
            index = np.where(
                np.isclose(
                    self.kpoints[:, None],
                    kpath_coords,
                )
                .all(-1)
                .any(-1)
                == True
            )[0]

            num_kpts = int(len(self.kpoints) / (len(index) / 2))
            slices = [
                slice(i * num_kpts, (i + 1) * num_kpts, None)
                for i in range(int(len(index) / 2))
            ]

        if unfold and not hse:
            n = int(len(self.kpoints) / len(self.kpath))
            print(n)
            slices = [
                slice(i * n, (i + 1) * n, None)
                for i in range(int(len(self.kpath) - 1))
            ]
            print(slices)

        return slices

    def _get_interpolated_data_segment(
        self, wave_vectors, data, crop_zero=False, kind="cubic"
    ):
        data_shape = data.shape

        if len(data_shape) == 1:
            fs = interp1d(wave_vectors, data, kind=kind, axis=0)
        else:
            fs = interp1d(wave_vectors, data, kind=kind, axis=1)

        new_wave_vectors = np.linspace(
            wave_vectors.min(), wave_vectors.max(), self.new_n
        )
        data = fs(new_wave_vectors)

        if crop_zero:
            data[np.where(data < 0)] = 0

        return new_wave_vectors, data

    def _get_interpolated_data(
        self, wave_vectors, data, crop_zero=False, kind="cubic"
    ):
        slices = self._get_slices(unfold=self.unfold, hse=self.hse)
        data_shape = data.shape
        if len(data_shape) == 1:
            data = [data[i] for i in slices]
        else:
            data = [data[:, i] for i in slices]

        wave_vectors = [wave_vectors[i] for i in slices]

        if len(data_shape) == 1:
            fs = [
                interp1d(i, j, kind=kind, axis=0)
                for (i, j) in zip(wave_vectors, data)
            ]
        else:
            fs = [
                interp1d(i, j, kind=kind, axis=1)
                for (i, j) in zip(wave_vectors, data)
            ]

        new_wave_vectors = [
            np.linspace(wv.min(), wv.max(), self.new_n) for wv in wave_vectors
        ]
        data = np.hstack([f(wv) for (f, wv) in zip(fs, new_wave_vectors)])
        wave_vectors = np.hstack(new_wave_vectors)

        if crop_zero:
            data[np.where(data < 0)] = 0

        return wave_vectors, data

    def _filter_bands(self, erange):
        eigenvalues = self.eigenvalues
        where = (eigenvalues >= np.min(erange) - 1) & (
            eigenvalues <= np.max(erange) + 1
        )
        is_true = np.sum(np.isin(where, True), axis=1)
        bands_in_plot = is_true > 0

        return bands_in_plot

    def _add_legend(self, ax, names, colors, fontsize=10, markersize=4):
        legend_lines = []
        legend_labels = []
        for name, color in zip(names, colors):
            legend_lines.append(
                plt.Line2D(
                    [0],
                    [0],
                    marker="o",
                    markersize=markersize,
                    linestyle="",
                    color=color,
                )
            )
            legend_labels.append(f"${name}$")

        leg = ax.get_legend()

        if leg is None:
            handles = legend_lines
            labels = legend_labels
        else:
            handles = [l._legmarker for l in leg.legendHandles]
            labels = [text._text for text in leg.texts]
            handles.extend(legend_lines)
            labels.extend(legend_labels)

        ax.legend(
            handles,
            labels,
            ncol=1,
            loc="upper left",
            fontsize=fontsize,
            bbox_to_anchor=(1, 1),
            borderaxespad=0,
            frameon=False,
            handletextpad=0.1,
        )

    def _heatmap(
        self,
        ax,
        wave_vectors,
        eigenvalues,
        weights,
        sigma,
        cmap,
        bins,
        projection=None,
        powernorm=True,
        gamma=0.5,
    ):
        eigenvalues_ravel = np.ravel(eigenvalues)
        wave_vectors_tile = np.tile(wave_vectors, eigenvalues.shape[0])

        if projection is not None:
            if len(np.squeeze(projection).shape) == 2:
                weights *= np.squeeze(projection)
            else:
                weights *= np.sum(np.squeeze(projection), axis=2)

        weights_ravel = np.ravel(weights)

        data = np.histogram2d(
            wave_vectors_tile,
            eigenvalues_ravel,
            bins=bins,
            weights=weights_ravel,
        )[0]

        data = gaussian_filter(data, sigma=sigma)
        if powernorm:
            norm = colors.PowerNorm(
                gamma=gamma, vmin=np.min(data), vmax=np.max(data)
            )
        else:
            norm = colors.Normalize(vmin=np.min(data), vmax=np.max(data))

        ax.pcolormesh(
            np.linspace(np.min(wave_vectors), np.max(wave_vectors), bins),
            np.linspace(np.min(eigenvalues), np.max(eigenvalues), bins),
            data.T,
            shading="gouraud",
            cmap=cmap,
            norm=norm,
        )

    def _alpha_cmap(self, color, repeats=3):
        cmap = LinearSegmentedColormap.from_list(
            "custom_cmap",
            [to_rgb(color) + (0,)] + [to_rgba(color) for _ in range(repeats)],
            N=10000,
        )
        return cmap

    def plot_plain(
        self,
        ax,
        color="black",
        erange=[-6, 6],
        linewidth=1.25,
        scale_factor=20,
        linestyle="-",
        heatmap=False,
        bins=400,
        sigma=3,
        cmap="hot",
        vlinecolor="black",
        powernorm=False,
        gamma=0.5,
        projection=None,
        highlight_band=False,
        highlight_band_color="red",
        band_index=None,
        sp_color="red",
        sp_scale_factor=5,
    ):
        """
        This function plots a plain band structure.

        Parameters:
            ax (matplotlib.pyplot.axis): Axis to plot the data on
            color (str): Color of the band structure lines
            linewidth (float): Line width of the band structure lines
            linestyle (str): Line style of the bands
        """
        bands_in_plot = self._filter_bands(erange=erange)
        slices = self._get_slices(unfold=self.unfold, hse=self.hse)
        wave_vector_segments = self._get_k_distance()

        # if self.soc_axis is not None and self.lsorbit:
        #     color = "black"
        #     linestyle = "-"

        if self.soc_axis is not None and self.lsorbit:
            if self.unfold:
                K_indices = np.array(self.K_indices[0], dtype=int)
                spin_projection_full_k = self.spin_projections[:, K_indices]
            else:
                spin_projection_full_k = self.spin_projections

        if self.custom_kpath is not None:
            kpath_inds = self.custom_kpath_inds
            kpath_flip = self.custom_kpath_flip
        else:
            kpath_inds = range(len(slices))
            kpath_flip = [False for _ in range(len(slices))]

        for i, f, wave_vectors in zip(
            kpath_inds, kpath_flip, wave_vector_segments
        ):
            if f:
                eigenvalues = np.flip(
                    self.eigenvalues[bands_in_plot, slices[i]], axis=1
                )
                if self.soc_axis is not None and self.lsorbit:
                    spin_projections = np.flip(
                        spin_projection_full_k[bands_in_plot, slices[i]],
                        axis=1,
                    )
            else:
                eigenvalues = self.eigenvalues[bands_in_plot, slices[i]]
                if self.soc_axis is not None and self.lsorbit:
                    spin_projections = spin_projection_full_k[
                        bands_in_plot, slices[i]
                    ]

            if highlight_band:
                if band_index is not None:
                    if type(band_index) == int:
                        highlight_eigenvalues = self.eigenvalues[
                            int(band_index), slices[i]
                        ]
                    else:
                        highlight_eigenvalues = self.eigenvalues[
                            band_index, slices[i]
                        ]

            wave_vectors_for_kpoints = wave_vectors

            if self.interpolate:
                (
                    wave_vectors,
                    eigenvalues,
                ) = self._get_interpolated_data_segment(
                    wave_vectors_for_kpoints,
                    eigenvalues,
                )
                if self.soc_axis is not None and self.lsorbit:
                    _, spin_projections = self._get_interpolated_data_segment(
                        wave_vectors_for_kpoints,
                        spin_projections,
                        crop_zero=True,
                        kind="linear",
                    )

                if highlight_band:
                    if band_index is not None:
                        (
                            _,
                            highlight_eigenvalues,
                        ) = self._get_interpolated_data_segment(
                            wave_vectors_for_kpoints,
                            highlight_eigenvalues,
                        )

            eigenvalues_ravel = np.ravel(
                np.c_[eigenvalues, np.empty(eigenvalues.shape[0]) * np.nan]
            )
            wave_vectors_tile = np.tile(
                np.append(wave_vectors, np.nan), eigenvalues.shape[0]
            )

            if self.soc_axis is not None and self.lsorbit:
                #  spin_cmap = self._alpha_cmap(color=spin_projection_color, repeats=1)
                spin_projections_ravel = np.ravel(
                    np.c_[
                        spin_projections,
                        np.empty(spin_projections.shape[0]) * np.nan,
                    ]
                )
                #  spin_colors = [spin_cmap(s) for s in spin_projections_ravel]

            if self.unfold:
                spectral_weights = self.spectral_weights[
                    bands_in_plot, slices[i]
                ]
                if f:
                    spectral_weights = np.flip(spectral_weights, axis=1)
                #  spectral_weights = spectral_weights / np.max(spectral_weights)

                if highlight_band:
                    if band_index is not None:
                        highlight_spectral_weights = self.spectral_weights[
                            int(band_index), slices[i]
                        ]

                if self.interpolate:
                    _, spectral_weights = self._get_interpolated_data_segment(
                        wave_vectors_for_kpoints,
                        spectral_weights,
                        crop_zero=True,
                        kind="linear",
                    )

                    if highlight_band:
                        if band_index is not None:
                            (
                                _,
                                highlight_spectral_weights,
                            ) = self._get_interpolated_data_segment(
                                wave_vectors_for_kpoints,
                                highlight_spectral_weights,
                                crop_zero=True,
                                kind="linear",
                            )

                spectral_weights_ravel = np.ravel(
                    np.c_[
                        spectral_weights,
                        np.empty(spectral_weights.shape[0]) * np.nan,
                    ]
                )

                if heatmap:
                    self._heatmap(
                        ax=ax,
                        wave_vectors=wave_vectors,
                        eigenvalues=eigenvalues,
                        weights=spectral_weights,
                        sigma=sigma,
                        cmap=cmap,
                        bins=bins,
                        projection=projection,
                        powernorm=powernorm,
                        gamma=gamma,
                    )
                else:
                    ax.scatter(
                        wave_vectors_tile,
                        eigenvalues_ravel,
                        c=color,
                        ec=None,
                        s=scale_factor * spectral_weights_ravel,
                        zorder=0,
                    )
                    if highlight_band:
                        if band_index is not None:
                            if type(band_index) == int:
                                ax.scatter(
                                    wave_vectors,
                                    highlight_eigenvalues,
                                    c=highlight_band_color,
                                    ec=None,
                                    s=scale_factor
                                    * highlight_spectral_weights,
                                    zorder=100,
                                )
                            else:
                                ax.scatter(
                                    np.tile(
                                        np.append(wave_vectors, np.nan),
                                        highlight_eigenvalues.shape[0],
                                    ),
                                    np.ravel(
                                        np.c_[
                                            highlight_eigenvalues,
                                            np.empty(
                                                highlight_eigenvalues.shape[0]
                                            )
                                            * np.nan,
                                        ]
                                    ),
                                    c=highlight_band_color,
                                    ec=None,
                                    s=scale_factor
                                    * np.ravel(highlight_spectral_weights),
                                    zorder=100,
                                )
                    if self.soc_axis is not None and self.lsorbit:
                        ax.scatter(
                            wave_vectors_tile,
                            eigenvalues_ravel,
                            s=spectral_weights_ravel
                            * sp_scale_factor
                            * spin_projections_ravel,
                            c=sp_color,
                            zorder=100,
                        )
            else:
                if heatmap:
                    self._heatmap(
                        ax=ax,
                        wave_vectors=wave_vectors,
                        eigenvalues=eigenvalues,
                        weights=np.ones(eigenvalues.shape),
                        sigma=sigma,
                        cmap=cmap,
                        bins=bins,
                        projection=projection,
                        powernorm=powernorm,
                        gamma=gamma,
                    )
                else:
                    ax.plot(
                        wave_vectors_tile,
                        eigenvalues_ravel,
                        color=color,
                        linewidth=linewidth,
                        linestyle=linestyle,
                        zorder=0,
                    )
                    if highlight_band:
                        if band_index is not None:
                            if type(band_index) == int:
                                ax.plot(
                                    wave_vectors,
                                    highlight_eigenvalues,
                                    color=highlight_band_color,
                                    linewidth=linewidth,
                                    linestyle=linestyle,
                                    zorder=100,
                                )
                            else:
                                ax.plot(
                                    np.tile(
                                        np.append(wave_vectors, np.nan),
                                        highlight_eigenvalues.shape[0],
                                    ),
                                    np.ravel(
                                        np.c_[
                                            highlight_eigenvalues,
                                            np.empty(
                                                highlight_eigenvalues.shape[0]
                                            )
                                            * np.nan,
                                        ]
                                    ),
                                    color=highlight_band_color,
                                    linewidth=linewidth,
                                    linestyle=linestyle,
                                    zorder=100,
                                )
                    if self.soc_axis is not None and self.lsorbit:
                        ax.scatter(
                            wave_vectors_tile,
                            eigenvalues_ravel,
                            s=sp_scale_factor * spin_projections_ravel,
                            c=sp_color,
                            zorder=100,
                        )

        if self.hse:
            self._get_kticks_hse(
                ax=ax,
                wave_vectors=np.concatenate(self._get_k_distance()),
                kpath=self.kpath,
                vlinecolor=vlinecolor,
            )
        elif self.unfold:
            self._get_kticks_unfold(
                ax=ax,
                wave_vectors=np.concatenate(self._get_k_distance()),
                vlinecolor=vlinecolor,
            )
        else:
            self._get_kticks(
                ax=ax,
                wave_vectors=np.concatenate(self._get_k_distance()),
                vlinecolor=vlinecolor,
            )

        ax.set_xlim(0, np.concatenate(self._get_k_distance()).max())

    def _plot_projected_general(
        self,
        ax,
        projected_data,
        colors,
        scale_factor=5,
        erange=[-6, 6],
        display_order=None,
        linewidth=0.75,
        band_color="black",
        heatmap=False,
        bins=400,
        sigma=3,
        cmap="hot",
        vlinecolor="black",
        powernorm=False,
        gamma=0.5,
        plain_scale_factor=10,
    ):
        """
        This is a general method for plotting projected data

        Parameters:
            scale_factor (float): Factor to scale weights. This changes the size of the
                points in the scatter plot
            color_dict (dict[str][str]): This option allow the colors of each orbital
                specified. Should be in the form of:
                {'orbital index': <color>, 'orbital index': <color>, ...}
            legend (bool): Determines if the legend should be included or not.
            linewidth (float): Line width of the plain band structure plotted in the background
            band_color (string): Color of the plain band structure
        """
        if self.unfold:
            if band_color == "black":
                band_color = "darkgrey"
            scale_factor = scale_factor * 4

        bands_in_plot = self._filter_bands(erange=erange)
        slices = self._get_slices(unfold=self.unfold, hse=self.hse)

        if self.unfold:
            K_indices = np.array(self.K_indices[0], dtype=int)
            projected_data = projected_data[:, K_indices, :]

        self.plot_plain(
            ax=ax,
            linewidth=linewidth,
            color=band_color,
            erange=erange,
            heatmap=heatmap,
            sigma=sigma,
            cmap=cmap,
            bins=bins,
            vlinecolor=vlinecolor,
            projection=projected_data,
            scale_factor=plain_scale_factor,
            sp_scale_factor=0,
        )

        wave_vector_segments = self._get_k_distance()

        if self.custom_kpath is not None:
            kpath_inds = self.custom_kpath_inds
            kpath_flip = self.custom_kpath_flip
        else:
            kpath_inds = range(len(slices))
            kpath_flip = [False for _ in range(len(slices))]

        for i, f, wave_vectors in zip(
            kpath_inds, kpath_flip, wave_vector_segments
        ):
            projected_data_slice = projected_data[bands_in_plot, slices[i]]
            if f:
                eigenvalues = np.flip(
                    self.eigenvalues[bands_in_plot, slices[i]], axis=1
                )
                projected_data_slice = np.flip(projected_data_slice, axis=1)
            else:
                eigenvalues = self.eigenvalues[bands_in_plot, slices[i]]

            unique_colors = np.unique(colors)
            shapes = (
                projected_data_slice.shape[0],
                projected_data_slice.shape[1],
                projected_data_slice.shape[-1],
            )
            projected_data_slice = projected_data_slice.reshape(shapes)

            if len(unique_colors) == len(colors):
                plot_colors = colors
            else:
                unique_inds = [np.isin(colors, c) for c in unique_colors]
                projected_data_slice = np.squeeze(projected_data_slice)
                projected_data_slice = np.c_[
                    [
                        np.sum(projected_data_slice[..., u], axis=2)
                        for u in unique_inds
                    ]
                ].transpose((1, 2, 0))
                plot_colors = unique_colors

            wave_vectors_old = wave_vectors

            if self.interpolate:
                (
                    wave_vectors,
                    eigenvalues,
                ) = self._get_interpolated_data_segment(
                    wave_vectors_old, eigenvalues
                )
                _, projected_data_slice = self._get_interpolated_data_segment(
                    wave_vectors_old,
                    projected_data_slice,
                    crop_zero=True,
                    kind="linear",
                )

            if not heatmap:
                if self.unfold:
                    spectral_weights = self.spectral_weights[
                        bands_in_plot, slices[i]
                    ]
                    if f:
                        spectral_weights = np.flip(spectral_weights, axis=1)
                    #  spectral_weights = spectral_weights / np.max(spectral_weights)

                    if self.interpolate:
                        (
                            _,
                            spectral_weights,
                        ) = self._get_interpolated_data_segment(
                            wave_vectors_old,
                            spectral_weights,
                            crop_zero=True,
                            kind="linear",
                        )

                    spectral_weights_ravel = np.repeat(
                        np.ravel(spectral_weights),
                        projected_data_slice.shape[-1],
                    )

                projected_data_ravel = np.ravel(projected_data_slice)
                wave_vectors_tile = np.tile(
                    np.repeat(wave_vectors, projected_data_slice.shape[-1]),
                    projected_data_slice.shape[0],
                )
                eigenvalues_tile = np.repeat(
                    np.ravel(eigenvalues), projected_data_slice.shape[-1]
                )
                colors_tile = np.tile(
                    plot_colors, np.prod(projected_data_slice.shape[:-1])
                )

                if display_order is None:
                    pass
                else:
                    sort_index = np.argsort(projected_data_ravel)

                    if display_order == "all":
                        sort_index = sort_index[::-1]

                    wave_vectors_tile = wave_vectors_tile[sort_index]
                    eigenvalues_tile = eigenvalues_tile[sort_index]
                    colors_tile = colors_tile[sort_index]
                    projected_data_ravel = projected_data_ravel[sort_index]

                    if self.unfold:
                        spectral_weights_ravel = spectral_weights_ravel[
                            sort_index
                        ]

                if self.unfold:
                    s = (
                        scale_factor
                        * projected_data_ravel
                        * spectral_weights_ravel
                    )
                    ec = None
                else:
                    s = scale_factor * projected_data_ravel
                    ec = colors_tile

                ax.scatter(
                    wave_vectors_tile,
                    eigenvalues_tile,
                    c=colors_tile,
                    ec=ec,
                    s=s,
                    zorder=100,
                )

    def plot_plain_old(
        self,
        ax,
        color="black",
        erange=[-6, 6],
        linewidth=1.25,
        scale_factor=20,
        linestyle="-",
        heatmap=False,
        bins=400,
        sigma=3,
        cmap="hot",
        vlinecolor="black",
        powernorm=False,
        gamma=0.5,
        projection=None,
        highlight_band=False,
        highlight_band_color="red",
        band_index=None,
    ):
        """
        This function plots a plain band structure.

        Parameters:
            ax (matplotlib.pyplot.axis): Axis to plot the data on
            color (str): Color of the band structure lines
            linewidth (float): Line width of the band structure lines
            linestyle (str): Line style of the bands
        """
        bands_in_plot = self._filter_bands(erange=erange)
        eigenvalues = self.eigenvalues[bands_in_plot]

        if highlight_band:
            if band_index is not None:
                highlight_eigenvalues = self.eigenvalues[int(band_index)]

        wave_vectors = self._get_k_distance()
        wave_vectors_for_kpoints = wave_vectors

        if self.interpolate:
            wave_vectors, eigenvalues = self._get_interpolated_data_segment(
                wave_vectors_for_kpoints, eigenvalues
            )

            if highlight_band:
                if band_index is not None:
                    (
                        _,
                        highlight_eigenvalues,
                    ) = self._get_interpolated_data_segment(
                        wave_vectors_for_kpoints,
                        highlight_eigenvalues,
                    )

        eigenvalues_ravel = np.ravel(
            np.c_[eigenvalues, np.empty(eigenvalues.shape[0]) * np.nan]
        )
        wave_vectors_tile = np.tile(
            np.append(wave_vectors, np.nan), eigenvalues.shape[0]
        )

        if self.unfold:
            spectral_weights = self.spectral_weights[bands_in_plot]
            #  spectral_weights = spectral_weights / np.max(spectral_weights)

            if highlight_band:
                if band_index is not None:
                    highlight_spectral_weights = self.spectral_weights[
                        int(band_index)
                    ]

            if self.interpolate:
                _, spectral_weights = self._get_interpolated_data_segment(
                    wave_vectors_for_kpoints,
                    spectral_weights,
                    crop_zero=True,
                    kind="linear",
                )

                if highlight_band:
                    if band_index is not None:
                        (
                            _,
                            highlight_spectral_weights,
                        ) = self._get_interpolated_data_segment(
                            wave_vectors_for_kpoints,
                            highlight_spectral_weights,
                            crop_zero=True,
                            kind="linear",
                        )

            spectral_weights_ravel = np.ravel(
                np.c_[
                    spectral_weights,
                    np.empty(spectral_weights.shape[0]) * np.nan,
                ]
            )

            if heatmap:
                self._heatmap(
                    ax=ax,
                    wave_vectors=wave_vectors,
                    eigenvalues=eigenvalues,
                    weights=spectral_weights,
                    sigma=sigma,
                    cmap=cmap,
                    bins=bins,
                    projection=projection,
                    powernorm=powernorm,
                    gamma=gamma,
                )
            else:
                ax.scatter(
                    wave_vectors_tile,
                    eigenvalues_ravel,
                    c=color,
                    ec=None,
                    s=scale_factor * spectral_weights_ravel,
                    zorder=0,
                )
                if highlight_band:
                    if band_index is not None:
                        ax.scatter(
                            wave_vectors,
                            highlight_eigenvalues,
                            c=highlight_band_color,
                            ec=None,
                            s=scale_factor * highlight_spectral_weights,
                            zorder=100,
                        )
        else:
            if heatmap:
                self._heatmap(
                    ax=ax,
                    wave_vectors=wave_vectors,
                    eigenvalues=eigenvalues,
                    weights=np.ones(eigenvalues.shape),
                    sigma=sigma,
                    cmap=cmap,
                    bins=bins,
                    projection=projection,
                    powernorm=powernorm,
                    gamma=gamma,
                )
            else:
                ax.plot(
                    wave_vectors_tile,
                    eigenvalues_ravel,
                    color=color,
                    linewidth=linewidth,
                    linestyle=linestyle,
                    zorder=0,
                )
                if highlight_band:
                    if band_index is not None:
                        ax.plot(
                            wave_vectors,
                            highlight_eigenvalues,
                            color=highlight_band_color,
                            linewidth=linewidth,
                            linestyle=linestyle,
                            zorder=100,
                        )

        if self.hse:
            self._get_kticks_hse(
                ax=ax,
                wave_vectors=wave_vectors_for_kpoints,
                kpath=self.kpath,
                vlinecolor=vlinecolor,
            )
        elif self.unfold:
            self._get_kticks_unfold(
                ax=ax,
                wave_vectors=wave_vectors_for_kpoints,
                vlinecolor=vlinecolor,
            )
        else:
            self._get_kticks(
                ax=ax,
                wave_vectors=wave_vectors_for_kpoints,
                vlinecolor=vlinecolor,
            )

        ax.set_xlim(0, np.max(wave_vectors))

    def _plot_projected_general_old(
        self,
        ax,
        projected_data,
        colors,
        scale_factor=5,
        erange=[-6, 6],
        display_order=None,
        linewidth=0.75,
        band_color="black",
        heatmap=False,
        bins=400,
        sigma=3,
        cmap="hot",
        vlinecolor="black",
        powernorm=False,
        gamma=0.5,
        plain_scale_factor=10,
    ):
        """
        This is a general method for plotting projected data

        Parameters:
            scale_factor (float): Factor to scale weights. This changes the size of the
                points in the scatter plot
            color_dict (dict[str][str]): This option allow the colors of each orbital
                specified. Should be in the form of:
                {'orbital index': <color>, 'orbital index': <color>, ...}
            legend (bool): Determines if the legend should be included or not.
            linewidth (float): Line width of the plain band structure plotted in the background
            band_color (string): Color of the plain band structure
        """
        if self.unfold:
            if band_color == "black":
                band_color = "darkgrey"
            scale_factor = scale_factor * 4

        bands_in_plot = self._filter_bands(erange=erange)
        projected_data = projected_data[bands_in_plot]
        unique_colors = np.unique(colors)
        shapes = (
            projected_data.shape[0],
            projected_data.shape[1],
            projected_data.shape[-1],
        )
        projected_data = projected_data.reshape(shapes)

        if len(unique_colors) == len(colors):
            pass
        else:
            unique_inds = [np.isin(colors, c) for c in unique_colors]
            projected_data = np.squeeze(projected_data)
            projected_data = np.c_[
                [np.sum(projected_data[..., i], axis=2) for i in unique_inds]
            ].transpose((1, 2, 0))
            colors = unique_colors

        #  projected_data = projected_data / np.max(projected_data)
        wave_vectors = self._get_k_distance()
        wave_vectors_old = wave_vectors
        eigenvalues = self.eigenvalues[bands_in_plot]

        if self.unfold:
            K_indices = np.array(self.K_indices[0], dtype=int)
            projected_data = projected_data[:, K_indices, :]

        if self.interpolate:
            wave_vectors, eigenvalues = self._get_interpolated_data(
                wave_vectors_old, eigenvalues
            )
            _, projected_data = self._get_interpolated_data(
                wave_vectors_old,
                projected_data,
                crop_zero=True,
                kind="linear",
            )

        self.plot_plain(
            ax=ax,
            linewidth=linewidth,
            color=band_color,
            erange=erange,
            heatmap=heatmap,
            sigma=sigma,
            cmap=cmap,
            bins=bins,
            vlinecolor=vlinecolor,
            projection=projected_data,
            scale_factor=plain_scale_factor,
        )

        if not heatmap:
            if self.unfold:
                spectral_weights = self.spectral_weights[bands_in_plot]
                spectral_weights = spectral_weights / np.max(spectral_weights)

                if self.interpolate:
                    _, spectral_weights = self._get_interpolated_data(
                        wave_vectors_old,
                        spectral_weights,
                        crop_zero=True,
                        kind="linear",
                    )

                spectral_weights_ravel = np.repeat(
                    np.ravel(spectral_weights), projected_data.shape[-1]
                )

            projected_data_ravel = np.ravel(projected_data)
            wave_vectors_tile = np.tile(
                np.repeat(wave_vectors, projected_data.shape[-1]),
                projected_data.shape[0],
            )
            eigenvalues_tile = np.repeat(
                np.ravel(eigenvalues), projected_data.shape[-1]
            )
            colors_tile = np.tile(colors, np.prod(projected_data.shape[:-1]))

            if display_order is None:
                pass
            else:
                sort_index = np.argsort(projected_data_ravel)

                if display_order == "all":
                    sort_index = sort_index[::-1]

                wave_vectors_tile = wave_vectors_tile[sort_index]
                eigenvalues_tile = eigenvalues_tile[sort_index]
                colors_tile = colors_tile[sort_index]
                projected_data_ravel = projected_data_ravel[sort_index]

                if self.unfold:
                    spectral_weights_ravel = spectral_weights_ravel[sort_index]

            if self.unfold:
                s = (
                    scale_factor
                    * projected_data_ravel
                    * spectral_weights_ravel
                )
                ec = None
            else:
                s = scale_factor * projected_data_ravel
                ec = colors_tile

            ax.scatter(
                wave_vectors_tile,
                eigenvalues_tile,
                c=colors_tile,
                ec=ec,
                s=s,
                zorder=100,
            )

    def plot_orbitals(
        self,
        ax,
        orbitals,
        scale_factor=5,
        erange=[-6, 6],
        display_order=None,
        color_list=None,
        legend=True,
        linewidth=0.75,
        band_color="black",
        heatmap=False,
        bins=400,
        sigma=3,
        cmap="hot",
        vlinecolor="black",
        powernorm=False,
        gamma=0.5,
    ):
        """
        This function plots the projected band structure of given orbitals summed across all atoms on a given axis.

        Parameters:
            ax (matplotlib.pyplot.axis): Axis to plot the data on
            orbitals (list): List of orbits to compare

                | 0 = s
                | 1 = py
                | 2 = pz
                | 3 = px
                | 4 = dxy
                | 5 = dyz
                | 6 = dz2
                | 7 = dxz
                | 8 = dx2-y2
                | 9 = fy3x2
                | 10 = fxyz
                | 11 = fyz2
                | 12 = fz3
                | 13 = fxz2
                | 14 = fzx3
                | 15 = fx3

            scale_factor (float): Factor to scale weights. This changes the size of the
                points in the scatter plot
            color_dict (dict[str][str]): This option allow the colors of each orbital
                specified. Should be in the form of:
                {'orbital index': <color>, 'orbital index': <color>, ...}
            legend (bool): Determines if the legend should be included or not.
            linewidth (float): Line width of the plain band structure plotted in the background
            band_color (string): Color of the plain band structure
        """

        if color_list is None:
            colors = np.array([self.color_dict[i] for i in orbitals])
        else:
            colors = color_list

        projected_data = self._sum_orbitals(orbitals=orbitals)

        self._plot_projected_general(
            ax=ax,
            projected_data=projected_data,
            colors=colors,
            scale_factor=scale_factor,
            erange=erange,
            display_order=display_order,
            linewidth=linewidth,
            band_color=band_color,
            heatmap=heatmap,
            bins=bins,
            sigma=sigma,
            cmap=cmap,
            vlinecolor=vlinecolor,
        )

        if legend:
            self._add_legend(
                ax,
                names=[self.orbital_labels[i] for i in orbitals],
                colors=colors,
            )

    def plot_spd(
        self,
        ax,
        scale_factor=5,
        orbitals="spd",
        erange=[-6, 6],
        display_order=None,
        color_list=None,
        legend=True,
        linewidth=0.75,
        band_color="black",
        heatmap=False,
        bins=400,
        sigma=3,
        cmap="hot",
        vlinecolor="black",
        powernorm=False,
        gamma=0.5,
    ):
        """
        This function plots the s, p, d projected band structure onto a given axis

        Parameters:
            ax (matplotlib.pyplot.axis): Axis to plot the data on
            scale_factor (float): Factor to scale weights. This changes the size of the
                points in the scatter plot
            order (list): This determines the order in which the points are plotted on the
                graph. This is an option because sometimes certain orbitals can be hidden
                under others because they have a larger weight. For example, if the
                weights of the d orbitals are greater than that of the s orbitals, it
                might be smart to choose ['d', 'p', 's'] as the order so the s orbitals are
                plotted over the d orbitals.
            color_dict (dict[str][str]): This option allow the colors of the s, p, and d
                orbitals to be specified. Should be in the form of:
                {'s': <s color>, 'p': <p color>, 'd': <d color>}
            legend (bool): Determines if the legend should be included or not.
            linewidth (float): Line width of the plain band structure plotted in the background
            band_color (string): Color of the plain band structure
        """
        if color_list is None:
            color_list = [
                self.color_dict[0],
                self.color_dict[1],
                self.color_dict[2],
                self.color_dict[4],
            ]
            colors = np.array([color_list[i] for i in range(len(orbitals))])
        else:
            colors = color_list

        projected_data = self._sum_spd(spd=orbitals)

        self._plot_projected_general(
            ax=ax,
            projected_data=projected_data,
            colors=colors,
            scale_factor=scale_factor,
            erange=erange,
            display_order=display_order,
            linewidth=linewidth,
            band_color=band_color,
            heatmap=heatmap,
            bins=bins,
            sigma=sigma,
            cmap=cmap,
            vlinecolor=vlinecolor,
        )

        if legend:
            self._add_legend(ax, names=[i for i in orbitals], colors=colors)

    def plot_atoms(
        self,
        ax,
        atoms,
        scale_factor=5,
        erange=[-6, 6],
        display_order=None,
        color_list=None,
        legend=True,
        linewidth=0.75,
        band_color="black",
        heatmap=False,
        bins=400,
        sigma=3,
        cmap="hot",
        vlinecolor="black",
        powernorm=False,
        gamma=0.5,
    ):
        """
        This function plots the projected band structure of given atoms summed across all orbitals on a given axis.

        Parameters:
            ax (matplotlib.pyplot.axis): Axis to plot the data on
            atoms (list): List of atoms to project onto
            scale_factor (float): Factor to scale weights. This changes the size of the
                points in the scatter plot
            color_list (list): List of colors of the same length as the atoms list
            legend (bool): Determines if the legend should be included or not.
            linewidth (float): Line width of the plain band structure plotted in the background
            band_color (string): Color of the plain band structure
        """
        if color_list is None:
            colors = np.array([self.color_dict[i] for i in range(len(atoms))])
        else:
            colors = color_list

        projected_data = self._sum_atoms(atoms=atoms)

        self._plot_projected_general(
            ax=ax,
            projected_data=projected_data,
            colors=colors,
            scale_factor=scale_factor,
            erange=erange,
            display_order=display_order,
            linewidth=linewidth,
            band_color=band_color,
            heatmap=heatmap,
            bins=bins,
            sigma=sigma,
            cmap=cmap,
            vlinecolor=vlinecolor,
        )

        if legend:
            self._add_legend(ax, names=atoms, colors=colors)

    def plot_atom_orbitals(
        self,
        ax,
        atom_orbital_dict,
        scale_factor=5,
        erange=[-6, 6],
        display_order=None,
        color_list=None,
        legend=True,
        linewidth=0.75,
        band_color="black",
        heatmap=False,
        bins=400,
        sigma=3,
        cmap="hot",
        vlinecolor="black",
        powernorm=False,
        gamma=0.5,
    ):
        """
        This function plots the projected band structure of individual orbitals on a given axis.

        Parameters:
            ax (matplotlib.pyplot.axis): Axis to plot the data on
            atom_orbital_pairs (list[list]): Selected orbitals on selected atoms to plot.
                This should take the form of [[atom index, orbital_index], ...].
                To plot the px orbital of the 1st atom and the pz orbital of the 2nd atom
                in the POSCAR file, the input would be [[0, 3], [1, 2]]
            scale_factor (float): Factor to scale weights. This changes the size of the
                points in the scatter plot
            color_list (list): List of colors of the same length as the atom_orbital_pairs
            legend (bool): Determines if the legend should be included or not.
            linewidth (float): Line width of the plain band structure plotted in the background
            band_color (string): Color of the plain band structure
        """

        atom_indices = list(atom_orbital_dict.keys())
        orbital_indices = list(atom_orbital_dict.values())
        number_orbitals = [len(i) for i in orbital_indices]
        atom_indices = np.repeat(atom_indices, number_orbitals)
        orbital_symbols_long = np.hstack(
            [[self.orbital_labels[o] for o in orb] for orb in orbital_indices]
        )
        orbital_indices_long = np.hstack(orbital_indices)
        indices = np.vstack([atom_indices, orbital_indices_long]).T

        projected_data = self.projected_eigenvalues
        projected_data = np.transpose(
            np.array(
                [projected_data[:, :, ind[0], ind[1]] for ind in indices]
            ),
            axes=(1, 2, 0),
        )

        if color_list is None:
            colors = np.array(
                [self.color_dict[i] for i in range(len(orbital_indices_long))]
            )
        else:
            colors = color_list

        self._plot_projected_general(
            ax=ax,
            projected_data=projected_data,
            colors=colors,
            scale_factor=scale_factor,
            erange=erange,
            display_order=display_order,
            linewidth=linewidth,
            band_color=band_color,
            heatmap=heatmap,
            bins=bins,
            sigma=sigma,
            cmap=cmap,
            vlinecolor=vlinecolor,
        )

        if legend:
            self._add_legend(
                ax,
                names=[
                    f"{i[0]}({i[1]})"
                    for i in zip(atom_indices, orbital_symbols_long)
                ],
                colors=colors,
            )

    def plot_atom_spd(
        self,
        ax,
        atom_spd_dict,
        scale_factor=5,
        erange=[-6, 6],
        display_order=None,
        color_list=None,
        legend=True,
        linewidth=0.75,
        band_color="black",
        heatmap=False,
        bins=400,
        sigma=3,
        cmap="hot",
        vlinecolor="black",
        powernorm=False,
        gamma=0.5,
    ):
        """
        This function plots the projected band structure on the s, p, and d orbitals for each specified atom in the calculated structure.

        Parameters:
            ax (matplotlib.pyplot.axis): Axis to plot the data on
            atom_spd_dict (dict): Dictionary to determine the atom and spd orbitals to project onto
                Format: {0: 'spd', 1: 'sp', 2: 's'} where 0,1,2 are atom indicies in the POSCAR
            display_order (None or str): The available options are None, 'all', 'dominant' where None
                plots the scatter points in the order presented in the atom_spd_dict, 'all' plots the
                scatter points largest --> smallest to all points are visable, and 'dominant' plots
                the scatter points smallest --> largest so only the dominant color is visable.
            scale_factor (float): Factor to scale weights. This changes the size of the
                points in the scatter plot
            color_dict (dict[str][str]): This option allow the colors of the s, p, and d
                orbitals to be specified. Should be in the form of:
                {'s': <s color>, 'p': <p color>, 'd': <d color>}
            legend (bool): Determines if the legend should be included or not.
            linewidth (float): Line width of the plain band structure plotted in the background
            band_color (string): Color of the plain band structure
        """
        atom_indices = list(atom_spd_dict.keys())
        orbital_symbols = list(atom_spd_dict.values())
        number_orbitals = [len(i) for i in orbital_symbols]
        atom_indices = np.repeat(atom_indices, number_orbitals)
        orbital_symbols_long = np.hstack(
            [[o for o in orb] for orb in orbital_symbols]
        )
        orbital_indices = np.hstack(
            [[self.spd_relations[o] for o in orb] for orb in orbital_symbols]
        )
        indices = np.vstack([atom_indices, orbital_indices]).T

        projected_data = self._sum_atoms(atoms=atom_indices, spd=True)
        projected_data = np.transpose(
            np.array(
                [projected_data[:, :, ind[0], ind[1]] for ind in indices]
            ),
            axes=(1, 2, 0),
        )

        if color_list is None:
            colors = np.array(
                [self.color_dict[i] for i in range(len(orbital_symbols_long))]
            )
        else:
            colors = color_list

        self._plot_projected_general(
            ax=ax,
            projected_data=projected_data,
            colors=colors,
            scale_factor=scale_factor,
            erange=erange,
            display_order=display_order,
            linewidth=linewidth,
            band_color=band_color,
            heatmap=heatmap,
            bins=bins,
            sigma=sigma,
            cmap=cmap,
            vlinecolor=vlinecolor,
        )

        if legend:
            self._add_legend(
                ax,
                names=[
                    f"{i[0]}({i[1]})"
                    for i in zip(atom_indices, orbital_symbols_long)
                ],
                colors=colors,
            )

    def plot_elements(
        self,
        ax,
        elements,
        scale_factor=5,
        erange=[-6, 6],
        display_order=None,
        color_list=None,
        legend=True,
        linewidth=0.75,
        band_color="black",
        heatmap=False,
        bins=400,
        sigma=3,
        cmap="hot",
        vlinecolor="black",
        powernorm=False,
        gamma=0.5,
    ):
        """
        This function plots the projected band structure on specified elements in the calculated structure

        Parameters:
            ax (matplotlib.pyplot.axis): Axis to plot the data on
            elements (list): List of element symbols to project onto
            scale_factor (float): Factor to scale weights. This changes the size of the
                points in the scatter plot
            color_list (list): List of colors of the same length as the elements list
            legend (bool): Determines if the legend should be included or not.
            linewidth (float): Line width of the plain band structure plotted in the background
            band_color (string): Color of the plain band structure
        """
        if color_list is None:
            colors = np.array(
                [self.color_dict[i] for i in range(len(elements))]
            )
        else:
            colors = color_list

        projected_data = self._sum_elements(elements=elements)

        self._plot_projected_general(
            ax=ax,
            projected_data=projected_data,
            colors=colors,
            scale_factor=scale_factor,
            erange=erange,
            display_order=display_order,
            linewidth=linewidth,
            band_color=band_color,
            heatmap=heatmap,
            bins=bins,
            sigma=sigma,
            cmap=cmap,
            vlinecolor=vlinecolor,
        )

        if legend:
            self._add_legend(ax, names=elements, colors=colors)

    def plot_element_orbitals(
        self,
        ax,
        element_orbital_dict,
        scale_factor=5,
        erange=[-6, 6],
        display_order=None,
        color_list=None,
        legend=True,
        linewidth=0.75,
        band_color="black",
        heatmap=False,
        bins=400,
        sigma=3,
        cmap="hot",
        vlinecolor="black",
        powernorm=False,
        gamma=0.5,
    ):
        """
        this function plots the projected band structure on chosen orbitals for each specified element in the calculated structure.

        Parameters:
            ax (matplotlib.pyplot.axis): axis to plot the data on
            element_orbital_pairs (list[list]): List of list in the form of
                [[element symbol, orbital index], [element symbol, orbital_index], ...]
            scale_factor (float): factor to scale weights. this changes the size of the
                points in the scatter plot
            color_list (list): List of colors of the same length as the element_orbital_pairs
            legend (bool): determines if the legend should be included or not.
            linewidth (float): line width of the plain band structure plotted in the background
            band_color (string): color of the plain band structure
        """
        element_symbols = list(element_orbital_dict.keys())
        orbital_indices = list(element_orbital_dict.values())
        number_orbitals = [len(i) for i in orbital_indices]
        element_symbols_long = np.repeat(element_symbols, number_orbitals)
        element_indices = np.repeat(
            range(len(element_symbols)), number_orbitals
        )
        orbital_symbols_long = np.hstack(
            [[self.orbital_labels[o] for o in orb] for orb in orbital_indices]
        )
        orbital_indices_long = np.hstack(orbital_indices)
        indices = np.vstack([element_indices, orbital_indices_long]).T

        projected_data = self._sum_elements(
            elements=element_symbols, orbitals=True
        )
        projected_data = np.transpose(
            np.array(
                [projected_data[:, :, ind[0], ind[1]] for ind in indices]
            ),
            axes=(1, 2, 0),
        )

        if color_list is None:
            colors = np.array(
                [self.color_dict[i] for i in range(len(orbital_indices_long))]
            )
        else:
            colors = color_list

        self._plot_projected_general(
            ax=ax,
            projected_data=projected_data,
            colors=colors,
            scale_factor=scale_factor,
            erange=erange,
            display_order=display_order,
            linewidth=linewidth,
            band_color=band_color,
            heatmap=heatmap,
            bins=bins,
            sigma=sigma,
            cmap=cmap,
            vlinecolor=vlinecolor,
        )

        if legend:
            self._add_legend(
                ax,
                names=[
                    f"{i[0]}({i[1]})"
                    for i in zip(element_symbols_long, orbital_symbols_long)
                ],
                colors=colors,
            )

    def plot_element_spd(
        self,
        ax,
        element_spd_dict,
        scale_factor=5,
        erange=[-6, 6],
        display_order=None,
        color_list=None,
        legend=True,
        linewidth=0.75,
        band_color="black",
        heatmap=False,
        bins=400,
        sigma=3,
        cmap="hot",
        vlinecolor="black",
        powernorm=False,
        gamma=0.5,
    ):
        """
        This function plots the projected band structure on the s, p, and d orbitals for each specified element in the calculated structure.

        Parameters:
            ax (matplotlib.pyplot.axis): Axis to plot the data on
            elements (list): List of element symbols to project onto
            order (list): This determines the order in which the points are plotted on the
                graph. This is an option because sometimes certain orbitals can be hidden
                under other orbitals because they have a larger weight. For example, if the
                signitures of the d orbitals are greater than that of the s orbitals, it
                might be smart to choose ['d', 'p', 's'] as the order so the s orbitals are
                plotted over the d orbitals.
            scale_factor (float): Factor to scale weights. This changes the size of the
                points in the scatter plot
            color_dict (dict[str][str]): This option allow the colors of the s, p, and d
                orbitals to be specified. Should be in the form of:
                {'s': <s color>, 'p': <p color>, 'd': <d color>}
            legend (bool): Determines if the legend should be included or not.
            linewidth (float):12 Line width of the plain band structure plotted in the background
            band_color (string): Color of the plain band structure
        """
        element_symbols = list(element_spd_dict.keys())
        orbital_symbols = list(element_spd_dict.values())
        number_orbitals = [len(i) for i in orbital_symbols]
        element_symbols_long = np.repeat(element_symbols, number_orbitals)
        element_indices = np.repeat(
            range(len(element_symbols)), number_orbitals
        )
        orbital_symbols_long = np.hstack(
            [[o for o in orb] for orb in orbital_symbols]
        )
        orbital_indices = np.hstack(
            [[self.spd_relations[o] for o in orb] for orb in orbital_symbols]
        )
        indices = np.vstack([element_indices, orbital_indices]).T

        projected_data = self._sum_elements(elements=element_symbols, spd=True)
        projected_data = np.transpose(
            np.array(
                [projected_data[:, :, ind[0], ind[1]] for ind in indices]
            ),
            axes=(1, 2, 0),
        )

        if color_list is None:
            colors = np.array(
                [self.color_dict[i] for i in range(len(orbital_symbols_long))]
            )
        else:
            colors = color_list

        self._plot_projected_general(
            ax=ax,
            projected_data=projected_data,
            colors=colors,
            scale_factor=scale_factor,
            erange=erange,
            display_order=display_order,
            linewidth=linewidth,
            band_color=band_color,
            heatmap=heatmap,
            bins=bins,
            sigma=sigma,
            cmap=cmap,
            vlinecolor=vlinecolor,
        )

        if legend:
            self._add_legend(
                ax,
                names=[
                    f"{i[0]}({i[1]})"
                    for i in zip(element_symbols_long, orbital_symbols_long)
                ],
                colors=colors,
            )

__init__(folder, projected=False, unfold=False, spin='up', kpath=None, n=None, M=None, high_symm_points=None, shift_efermi=0, interpolate=True, new_n=200, custom_kpath=None, soc_axis=None, stretch_factor=1.0)

Initialize parameters upon the generation of this class

Parameters:

Name Type Description Default
folder str

This is the folder that contains the VASP files

required
projected bool

Determines whether of not to parse the projected eigenvalues from the PROCAR file. Making this true increases the computational time, so only use if a projected band structure is required.

False
unfold bool

Determines if the band structure should be unfolded or not.

False
spin str

Choose which spin direction to parse. ('up' or 'down')

'up'
kpath str

High symmetry k-point path of band structure calculation Due to the nature of the KPOINTS file for unfolded calculations this information is a required input for proper labeling of the figure for unfolded calculations. This information is extracted from the KPOINTS files for non-unfolded calculations. (G is automatically converted to \Gamma)

None
n int

Number of points between each high symmetry point. This is also only required for unfolded calculations. This number should be known by the user, as it was used to generate the KPOINTS file.

None
M list[list]

Transformation matrix for unfolding calculations. Can be found using the conver_slab function in the utils module.

None
high_symm_points list[list]

Coordinates of the high symmetry points of the bulk Brilloin zone for an unfolded calculation.

None
shift_efermi float

Gives the option to shift the fermi energy by the specified value

0
interpolate bool

Determines is the data between each high symmetry point should be interpolated or not.

True
new_n int

New number of k-points in between each high symmetry point.

200
custom_kpath list

Custom kpath that can be selected is the user desires. Given a path G-X-W-L-G-K then there are 5 segements to choose from [1 -> G-X, 2 -> X-W, 3 -> W-L, 4 -> L-G, 5 -> G-K]. If a user wanted to plot only the path G-X-W they can set custom_kpath=[1,2]. If a user wanted to flip the k-path of a segment, then the index should be made negative, so if the desired path was G-X|L-W then custom_kpath=[1,-3]

None
soc_axis None or str

This parameter can either take the value of None or the it can take the value of 'x', 'y', or 'z'. If either 'x', 'y', or 'z' are given then spin='up' states will be defined by positive values of this spin-component and spin='down' states will be defined by negative values of this spin-component. This will only be used for showing a pseudo-spin-polarized plot for calculations that have SOC enabled.

None
stretch_factor float

Used to scale the eigenvalues by a certain constant. Useful for comparing to ARPES data. Default is scale_factor = 1.0 (i.e. no scaling)

1.0
Source code in vaspvis/band.py
 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
def __init__(
    self,
    folder,
    projected=False,
    unfold=False,
    spin="up",
    kpath=None,
    n=None,
    M=None,
    high_symm_points=None,
    # bandgap=False,
    # printbg=True,
    shift_efermi=0,
    interpolate=True,
    new_n=200,
    custom_kpath=None,
    soc_axis=None,
    stretch_factor=1.0,
):
    """
    Initialize parameters upon the generation of this class

    Parameters:
        folder (str): This is the folder that contains the VASP files
        projected (bool): Determines whether of not to parse the projected
            eigenvalues from the PROCAR file. Making this true
            increases the computational time, so only use if a projected
            band structure is required.
        unfold (bool): Determines if the band structure should be unfolded or not.
        spin (str): Choose which spin direction to parse. ('up' or 'down')
        kpath (str): High symmetry k-point path of band structure calculation
            Due to the nature of the KPOINTS file for unfolded calculations this
            information is a required input for proper labeling of the figure
            for unfolded calculations. This information is extracted from the KPOINTS
            files for non-unfolded calculations. (G is automatically converted to \\Gamma)
        n (int): Number of points between each high symmetry point.
            This is also only required for unfolded calculations. This number should be
            known by the user, as it was used to generate the KPOINTS file.
        M (list[list]): Transformation matrix for unfolding calculations. Can be found using
            the conver_slab function in the utils module.
        high_symm_points (list[list]): Coordinates of the high symmetry points of the bulk
            Brilloin zone for an unfolded calculation.
        shift_efermi (float): Gives the option to shift the fermi energy by the specified value
        interpolate (bool): Determines is the data between each high symmetry point should be
            interpolated or not.
        new_n (int): New number of k-points in between each high symmetry point.
        custom_kpath (list): Custom kpath that can be selected is the user desires.
            Given a path G-X-W-L-G-K then there are 5 segements to choose from
            [1 -> G-X, 2 -> X-W, 3 -> W-L, 4 -> L-G, 5 -> G-K]. If a user wanted to
            plot only the path G-X-W they can set custom_kpath=[1,2]. If a user wanted
            to flip the k-path of a segment, then the index should be made negative, so
            if the desired path was G-X|L-W then custom_kpath=[1,-3]
        soc_axis (None or str): This parameter can either take the value of None or the
            it can take the value of 'x', 'y', or 'z'. If either 'x', 'y', or 'z' are given
            then spin='up' states will be defined by positive values of this spin-component
            and spin='down' states will be defined by negative values of this spin-component.
            This will only be used for showing a pseudo-spin-polarized plot for calculations
            that have SOC enabled.
        stretch_factor (float): Used to scale the eigenvalues by a certain constant. Useful for comparing to ARPES data.
            Default is scale_factor = 1.0 (i.e. no scaling)
    """
    self.interpolate = interpolate
    self.soc_axis = soc_axis
    self.new_n = new_n
    self.stretch_factor = stretch_factor
    # self.bandgap = bandgap
    # self.printbg = printbg
    self.eigenval = Eigenval(os.path.join(folder, "EIGENVAL"))
    self.efermi = (
        float(
            os.popen(f'grep E-fermi {os.path.join(folder, "OUTCAR")}')
            .read()
            .split()[2]
        )
        + shift_efermi
    )
    self.poscar = Poscar.from_file(
        os.path.join(folder, "POSCAR"),
        check_for_POTCAR=False,
        read_velocities=False,
    )
    self.incar = Incar.from_file(os.path.join(folder, "INCAR"))
    if "LSORBIT" in self.incar:
        if self.incar["LSORBIT"]:
            self.lsorbit = True
        else:
            self.lsorbit = False
    else:
        self.lsorbit = False

    if "ISPIN" in self.incar:
        if self.incar["ISPIN"] == 2:
            self.ispin = True
        else:
            self.ispin = False
    else:
        self.ispin = False

    if "LHFCALC" in self.incar:
        if self.incar["LHFCALC"]:
            self.hse = True
        else:
            self.hse = False
    else:
        self.hse = False

    self.kpoints_file = Kpoints.from_file(os.path.join(folder, "KPOINTS"))

    self.wavecar = os.path.join(folder, "WAVECAR")
    self.projected = projected

    self.forbitals = self._check_f_orb()
    self.unfold = unfold

    if self.hse and self.unfold:
        self.hse = False

    self.kpath = kpath
    self.n = n
    self.M = M
    self.high_symm_points = high_symm_points
    self.folder = folder
    self.spin = spin
    self.spin_dict = {"up": Spin.up, "down": Spin.down}
    if not self.unfold:
        self.pre_loaded_bands = os.path.isfile(
            os.path.join(folder, "eigenvalues.npy")
        )
        self.eigenvalues, self.kpoints = self._load_bands()
    else:
        self.pre_loaded_bands = os.path.isfile(
            os.path.join(folder, "unfolded_eigenvalues.npy")
        )
        (
            self.eigenvalues,
            self.spectral_weights,
            self.K_indices,
            self.kpoints,
        ) = self._load_bands_unfold()

    if self.stretch_factor != 1.0:
        self.eigenvalues *= self.stretch_factor

    self.color_dict = {
        0: "#FF0000",
        1: "#0000FF",
        2: "#008000",
        3: "#800080",
        4: "#E09200",
        5: "#FF5C77",
        6: "#778392",
        7: "#07C589",
        8: "#40BAF2",
        9: "#FF0000",
        10: "#0000FF",
        11: "#008000",
        12: "#800080",
        13: "#E09200",
        14: "#FF5C77",
        15: "#778392",
    }
    self.orbital_labels = {
        0: "s",
        1: "p_{y}",
        2: "p_{z}",
        3: "p_{x}",
        4: "d_{xy}",
        5: "d_{yz}",
        6: "d_{z^{2}}",
        7: "d_{xz}",
        8: "d_{x^{2}-y^{2}}",
        9: "f_{y^{3}x^{2}}",
        10: "f_{xyz}",
        11: "f_{yz^{2}}",
        12: "f_{z^{3}}",
        13: "f_{xz^{2}}",
        14: "f_{zx^{3}}",
        15: "f_{x^{3}}",
    }
    self.spd_relations = {
        "s": 0,
        "p": 1,
        "d": 2,
        "f": 3,
    }
    # if self.bandgap:
    #     self.bg = self._get_bandgap()
    # else:
    #     self.bg = None

    self.custom_kpath = custom_kpath
    if self.custom_kpath is not None:
        (
            self.custom_kpath_inds,
            self.custom_kpath_flip,
        ) = self._get_custom_kpath()
    #  else:
    #  self.custom_kpath_inds, self.custom_kpath_flip = None, None

    if projected:
        self.pre_loaded_projections = os.path.isfile(
            os.path.join(folder, "projected_eigenvalues.npy")
        )
        self.projected_eigenvalues = self._load_projected_bands()

    if soc_axis is not None and self.lsorbit:
        self.pre_loaded_spin_projections = os.path.isfile(
            os.path.join(folder, "spin_projections.npy")
        )
        self.spin_projections = self._load_soc_spin_projection()

plot_atom_orbitals(ax, atom_orbital_dict, scale_factor=5, erange=[-6, 6], display_order=None, color_list=None, legend=True, linewidth=0.75, band_color='black', heatmap=False, bins=400, sigma=3, cmap='hot', vlinecolor='black', powernorm=False, gamma=0.5)

This function plots the projected band structure of individual orbitals on a given axis.

Parameters:

Name Type Description Default
ax axis

Axis to plot the data on

required
atom_orbital_pairs list[list]

Selected orbitals on selected atoms to plot. This should take the form of [[atom index, orbital_index], ...]. To plot the px orbital of the 1st atom and the pz orbital of the 2nd atom in the POSCAR file, the input would be [[0, 3], [1, 2]]

required
scale_factor float

Factor to scale weights. This changes the size of the points in the scatter plot

5
color_list list

List of colors of the same length as the atom_orbital_pairs

None
legend bool

Determines if the legend should be included or not.

True
linewidth float

Line width of the plain band structure plotted in the background

0.75
band_color string

Color of the plain band structure

'black'
Source code in vaspvis/band.py
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
def plot_atom_orbitals(
    self,
    ax,
    atom_orbital_dict,
    scale_factor=5,
    erange=[-6, 6],
    display_order=None,
    color_list=None,
    legend=True,
    linewidth=0.75,
    band_color="black",
    heatmap=False,
    bins=400,
    sigma=3,
    cmap="hot",
    vlinecolor="black",
    powernorm=False,
    gamma=0.5,
):
    """
    This function plots the projected band structure of individual orbitals on a given axis.

    Parameters:
        ax (matplotlib.pyplot.axis): Axis to plot the data on
        atom_orbital_pairs (list[list]): Selected orbitals on selected atoms to plot.
            This should take the form of [[atom index, orbital_index], ...].
            To plot the px orbital of the 1st atom and the pz orbital of the 2nd atom
            in the POSCAR file, the input would be [[0, 3], [1, 2]]
        scale_factor (float): Factor to scale weights. This changes the size of the
            points in the scatter plot
        color_list (list): List of colors of the same length as the atom_orbital_pairs
        legend (bool): Determines if the legend should be included or not.
        linewidth (float): Line width of the plain band structure plotted in the background
        band_color (string): Color of the plain band structure
    """

    atom_indices = list(atom_orbital_dict.keys())
    orbital_indices = list(atom_orbital_dict.values())
    number_orbitals = [len(i) for i in orbital_indices]
    atom_indices = np.repeat(atom_indices, number_orbitals)
    orbital_symbols_long = np.hstack(
        [[self.orbital_labels[o] for o in orb] for orb in orbital_indices]
    )
    orbital_indices_long = np.hstack(orbital_indices)
    indices = np.vstack([atom_indices, orbital_indices_long]).T

    projected_data = self.projected_eigenvalues
    projected_data = np.transpose(
        np.array(
            [projected_data[:, :, ind[0], ind[1]] for ind in indices]
        ),
        axes=(1, 2, 0),
    )

    if color_list is None:
        colors = np.array(
            [self.color_dict[i] for i in range(len(orbital_indices_long))]
        )
    else:
        colors = color_list

    self._plot_projected_general(
        ax=ax,
        projected_data=projected_data,
        colors=colors,
        scale_factor=scale_factor,
        erange=erange,
        display_order=display_order,
        linewidth=linewidth,
        band_color=band_color,
        heatmap=heatmap,
        bins=bins,
        sigma=sigma,
        cmap=cmap,
        vlinecolor=vlinecolor,
    )

    if legend:
        self._add_legend(
            ax,
            names=[
                f"{i[0]}({i[1]})"
                for i in zip(atom_indices, orbital_symbols_long)
            ],
            colors=colors,
        )

plot_atom_spd(ax, atom_spd_dict, scale_factor=5, erange=[-6, 6], display_order=None, color_list=None, legend=True, linewidth=0.75, band_color='black', heatmap=False, bins=400, sigma=3, cmap='hot', vlinecolor='black', powernorm=False, gamma=0.5)

This function plots the projected band structure on the s, p, and d orbitals for each specified atom in the calculated structure.

Parameters:

Name Type Description Default
ax axis

Axis to plot the data on

required
atom_spd_dict dict

Dictionary to determine the atom and spd orbitals to project onto Format: {0: 'spd', 1: 'sp', 2: 's'} where 0,1,2 are atom indicies in the POSCAR

required
display_order None or str

The available options are None, 'all', 'dominant' where None plots the scatter points in the order presented in the atom_spd_dict, 'all' plots the scatter points largest --> smallest to all points are visable, and 'dominant' plots the scatter points smallest --> largest so only the dominant color is visable.

None
scale_factor float

Factor to scale weights. This changes the size of the points in the scatter plot

5
color_dict dict[str][str]

This option allow the colors of the s, p, and d orbitals to be specified. Should be in the form of: {'s': , 'p':

, 'd': }

required
legend bool

Determines if the legend should be included or not.

True
linewidth float

Line width of the plain band structure plotted in the background

0.75
band_color string

Color of the plain band structure

'black'
Source code in vaspvis/band.py
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
def plot_atom_spd(
    self,
    ax,
    atom_spd_dict,
    scale_factor=5,
    erange=[-6, 6],
    display_order=None,
    color_list=None,
    legend=True,
    linewidth=0.75,
    band_color="black",
    heatmap=False,
    bins=400,
    sigma=3,
    cmap="hot",
    vlinecolor="black",
    powernorm=False,
    gamma=0.5,
):
    """
    This function plots the projected band structure on the s, p, and d orbitals for each specified atom in the calculated structure.

    Parameters:
        ax (matplotlib.pyplot.axis): Axis to plot the data on
        atom_spd_dict (dict): Dictionary to determine the atom and spd orbitals to project onto
            Format: {0: 'spd', 1: 'sp', 2: 's'} where 0,1,2 are atom indicies in the POSCAR
        display_order (None or str): The available options are None, 'all', 'dominant' where None
            plots the scatter points in the order presented in the atom_spd_dict, 'all' plots the
            scatter points largest --> smallest to all points are visable, and 'dominant' plots
            the scatter points smallest --> largest so only the dominant color is visable.
        scale_factor (float): Factor to scale weights. This changes the size of the
            points in the scatter plot
        color_dict (dict[str][str]): This option allow the colors of the s, p, and d
            orbitals to be specified. Should be in the form of:
            {'s': <s color>, 'p': <p color>, 'd': <d color>}
        legend (bool): Determines if the legend should be included or not.
        linewidth (float): Line width of the plain band structure plotted in the background
        band_color (string): Color of the plain band structure
    """
    atom_indices = list(atom_spd_dict.keys())
    orbital_symbols = list(atom_spd_dict.values())
    number_orbitals = [len(i) for i in orbital_symbols]
    atom_indices = np.repeat(atom_indices, number_orbitals)
    orbital_symbols_long = np.hstack(
        [[o for o in orb] for orb in orbital_symbols]
    )
    orbital_indices = np.hstack(
        [[self.spd_relations[o] for o in orb] for orb in orbital_symbols]
    )
    indices = np.vstack([atom_indices, orbital_indices]).T

    projected_data = self._sum_atoms(atoms=atom_indices, spd=True)
    projected_data = np.transpose(
        np.array(
            [projected_data[:, :, ind[0], ind[1]] for ind in indices]
        ),
        axes=(1, 2, 0),
    )

    if color_list is None:
        colors = np.array(
            [self.color_dict[i] for i in range(len(orbital_symbols_long))]
        )
    else:
        colors = color_list

    self._plot_projected_general(
        ax=ax,
        projected_data=projected_data,
        colors=colors,
        scale_factor=scale_factor,
        erange=erange,
        display_order=display_order,
        linewidth=linewidth,
        band_color=band_color,
        heatmap=heatmap,
        bins=bins,
        sigma=sigma,
        cmap=cmap,
        vlinecolor=vlinecolor,
    )

    if legend:
        self._add_legend(
            ax,
            names=[
                f"{i[0]}({i[1]})"
                for i in zip(atom_indices, orbital_symbols_long)
            ],
            colors=colors,
        )

plot_atoms(ax, atoms, scale_factor=5, erange=[-6, 6], display_order=None, color_list=None, legend=True, linewidth=0.75, band_color='black', heatmap=False, bins=400, sigma=3, cmap='hot', vlinecolor='black', powernorm=False, gamma=0.5)

This function plots the projected band structure of given atoms summed across all orbitals on a given axis.

Parameters:

Name Type Description Default
ax axis

Axis to plot the data on

required
atoms list

List of atoms to project onto

required
scale_factor float

Factor to scale weights. This changes the size of the points in the scatter plot

5
color_list list

List of colors of the same length as the atoms list

None
legend bool

Determines if the legend should be included or not.

True
linewidth float

Line width of the plain band structure plotted in the background

0.75
band_color string

Color of the plain band structure

'black'
Source code in vaspvis/band.py
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
def plot_atoms(
    self,
    ax,
    atoms,
    scale_factor=5,
    erange=[-6, 6],
    display_order=None,
    color_list=None,
    legend=True,
    linewidth=0.75,
    band_color="black",
    heatmap=False,
    bins=400,
    sigma=3,
    cmap="hot",
    vlinecolor="black",
    powernorm=False,
    gamma=0.5,
):
    """
    This function plots the projected band structure of given atoms summed across all orbitals on a given axis.

    Parameters:
        ax (matplotlib.pyplot.axis): Axis to plot the data on
        atoms (list): List of atoms to project onto
        scale_factor (float): Factor to scale weights. This changes the size of the
            points in the scatter plot
        color_list (list): List of colors of the same length as the atoms list
        legend (bool): Determines if the legend should be included or not.
        linewidth (float): Line width of the plain band structure plotted in the background
        band_color (string): Color of the plain band structure
    """
    if color_list is None:
        colors = np.array([self.color_dict[i] for i in range(len(atoms))])
    else:
        colors = color_list

    projected_data = self._sum_atoms(atoms=atoms)

    self._plot_projected_general(
        ax=ax,
        projected_data=projected_data,
        colors=colors,
        scale_factor=scale_factor,
        erange=erange,
        display_order=display_order,
        linewidth=linewidth,
        band_color=band_color,
        heatmap=heatmap,
        bins=bins,
        sigma=sigma,
        cmap=cmap,
        vlinecolor=vlinecolor,
    )

    if legend:
        self._add_legend(ax, names=atoms, colors=colors)

plot_element_orbitals(ax, element_orbital_dict, scale_factor=5, erange=[-6, 6], display_order=None, color_list=None, legend=True, linewidth=0.75, band_color='black', heatmap=False, bins=400, sigma=3, cmap='hot', vlinecolor='black', powernorm=False, gamma=0.5)

this function plots the projected band structure on chosen orbitals for each specified element in the calculated structure.

Parameters:

Name Type Description Default
ax axis

axis to plot the data on

required
element_orbital_pairs list[list]

List of list in the form of [[element symbol, orbital index], [element symbol, orbital_index], ...]

required
scale_factor float

factor to scale weights. this changes the size of the points in the scatter plot

5
color_list list

List of colors of the same length as the element_orbital_pairs

None
legend bool

determines if the legend should be included or not.

True
linewidth float

line width of the plain band structure plotted in the background

0.75
band_color string

color of the plain band structure

'black'
Source code in vaspvis/band.py
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
def plot_element_orbitals(
    self,
    ax,
    element_orbital_dict,
    scale_factor=5,
    erange=[-6, 6],
    display_order=None,
    color_list=None,
    legend=True,
    linewidth=0.75,
    band_color="black",
    heatmap=False,
    bins=400,
    sigma=3,
    cmap="hot",
    vlinecolor="black",
    powernorm=False,
    gamma=0.5,
):
    """
    this function plots the projected band structure on chosen orbitals for each specified element in the calculated structure.

    Parameters:
        ax (matplotlib.pyplot.axis): axis to plot the data on
        element_orbital_pairs (list[list]): List of list in the form of
            [[element symbol, orbital index], [element symbol, orbital_index], ...]
        scale_factor (float): factor to scale weights. this changes the size of the
            points in the scatter plot
        color_list (list): List of colors of the same length as the element_orbital_pairs
        legend (bool): determines if the legend should be included or not.
        linewidth (float): line width of the plain band structure plotted in the background
        band_color (string): color of the plain band structure
    """
    element_symbols = list(element_orbital_dict.keys())
    orbital_indices = list(element_orbital_dict.values())
    number_orbitals = [len(i) for i in orbital_indices]
    element_symbols_long = np.repeat(element_symbols, number_orbitals)
    element_indices = np.repeat(
        range(len(element_symbols)), number_orbitals
    )
    orbital_symbols_long = np.hstack(
        [[self.orbital_labels[o] for o in orb] for orb in orbital_indices]
    )
    orbital_indices_long = np.hstack(orbital_indices)
    indices = np.vstack([element_indices, orbital_indices_long]).T

    projected_data = self._sum_elements(
        elements=element_symbols, orbitals=True
    )
    projected_data = np.transpose(
        np.array(
            [projected_data[:, :, ind[0], ind[1]] for ind in indices]
        ),
        axes=(1, 2, 0),
    )

    if color_list is None:
        colors = np.array(
            [self.color_dict[i] for i in range(len(orbital_indices_long))]
        )
    else:
        colors = color_list

    self._plot_projected_general(
        ax=ax,
        projected_data=projected_data,
        colors=colors,
        scale_factor=scale_factor,
        erange=erange,
        display_order=display_order,
        linewidth=linewidth,
        band_color=band_color,
        heatmap=heatmap,
        bins=bins,
        sigma=sigma,
        cmap=cmap,
        vlinecolor=vlinecolor,
    )

    if legend:
        self._add_legend(
            ax,
            names=[
                f"{i[0]}({i[1]})"
                for i in zip(element_symbols_long, orbital_symbols_long)
            ],
            colors=colors,
        )

plot_element_spd(ax, element_spd_dict, scale_factor=5, erange=[-6, 6], display_order=None, color_list=None, legend=True, linewidth=0.75, band_color='black', heatmap=False, bins=400, sigma=3, cmap='hot', vlinecolor='black', powernorm=False, gamma=0.5)

This function plots the projected band structure on the s, p, and d orbitals for each specified element in the calculated structure.

Parameters:

Name Type Description Default
ax axis

Axis to plot the data on

required
elements list

List of element symbols to project onto

required
order list

This determines the order in which the points are plotted on the graph. This is an option because sometimes certain orbitals can be hidden under other orbitals because they have a larger weight. For example, if the signitures of the d orbitals are greater than that of the s orbitals, it might be smart to choose ['d', 'p', 's'] as the order so the s orbitals are plotted over the d orbitals.

required
scale_factor float

Factor to scale weights. This changes the size of the points in the scatter plot

5
color_dict dict[str][str]

This option allow the colors of the s, p, and d orbitals to be specified. Should be in the form of: {'s': , 'p':

, 'd': }

required
legend bool

Determines if the legend should be included or not.

True
linewidth float

12 Line width of the plain band structure plotted in the background

0.75
band_color string

Color of the plain band structure

'black'
Source code in vaspvis/band.py
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
def plot_element_spd(
    self,
    ax,
    element_spd_dict,
    scale_factor=5,
    erange=[-6, 6],
    display_order=None,
    color_list=None,
    legend=True,
    linewidth=0.75,
    band_color="black",
    heatmap=False,
    bins=400,
    sigma=3,
    cmap="hot",
    vlinecolor="black",
    powernorm=False,
    gamma=0.5,
):
    """
    This function plots the projected band structure on the s, p, and d orbitals for each specified element in the calculated structure.

    Parameters:
        ax (matplotlib.pyplot.axis): Axis to plot the data on
        elements (list): List of element symbols to project onto
        order (list): This determines the order in which the points are plotted on the
            graph. This is an option because sometimes certain orbitals can be hidden
            under other orbitals because they have a larger weight. For example, if the
            signitures of the d orbitals are greater than that of the s orbitals, it
            might be smart to choose ['d', 'p', 's'] as the order so the s orbitals are
            plotted over the d orbitals.
        scale_factor (float): Factor to scale weights. This changes the size of the
            points in the scatter plot
        color_dict (dict[str][str]): This option allow the colors of the s, p, and d
            orbitals to be specified. Should be in the form of:
            {'s': <s color>, 'p': <p color>, 'd': <d color>}
        legend (bool): Determines if the legend should be included or not.
        linewidth (float):12 Line width of the plain band structure plotted in the background
        band_color (string): Color of the plain band structure
    """
    element_symbols = list(element_spd_dict.keys())
    orbital_symbols = list(element_spd_dict.values())
    number_orbitals = [len(i) for i in orbital_symbols]
    element_symbols_long = np.repeat(element_symbols, number_orbitals)
    element_indices = np.repeat(
        range(len(element_symbols)), number_orbitals
    )
    orbital_symbols_long = np.hstack(
        [[o for o in orb] for orb in orbital_symbols]
    )
    orbital_indices = np.hstack(
        [[self.spd_relations[o] for o in orb] for orb in orbital_symbols]
    )
    indices = np.vstack([element_indices, orbital_indices]).T

    projected_data = self._sum_elements(elements=element_symbols, spd=True)
    projected_data = np.transpose(
        np.array(
            [projected_data[:, :, ind[0], ind[1]] for ind in indices]
        ),
        axes=(1, 2, 0),
    )

    if color_list is None:
        colors = np.array(
            [self.color_dict[i] for i in range(len(orbital_symbols_long))]
        )
    else:
        colors = color_list

    self._plot_projected_general(
        ax=ax,
        projected_data=projected_data,
        colors=colors,
        scale_factor=scale_factor,
        erange=erange,
        display_order=display_order,
        linewidth=linewidth,
        band_color=band_color,
        heatmap=heatmap,
        bins=bins,
        sigma=sigma,
        cmap=cmap,
        vlinecolor=vlinecolor,
    )

    if legend:
        self._add_legend(
            ax,
            names=[
                f"{i[0]}({i[1]})"
                for i in zip(element_symbols_long, orbital_symbols_long)
            ],
            colors=colors,
        )

plot_elements(ax, elements, scale_factor=5, erange=[-6, 6], display_order=None, color_list=None, legend=True, linewidth=0.75, band_color='black', heatmap=False, bins=400, sigma=3, cmap='hot', vlinecolor='black', powernorm=False, gamma=0.5)

This function plots the projected band structure on specified elements in the calculated structure

Parameters:

Name Type Description Default
ax axis

Axis to plot the data on

required
elements list

List of element symbols to project onto

required
scale_factor float

Factor to scale weights. This changes the size of the points in the scatter plot

5
color_list list

List of colors of the same length as the elements list

None
legend bool

Determines if the legend should be included or not.

True
linewidth float

Line width of the plain band structure plotted in the background

0.75
band_color string

Color of the plain band structure

'black'
Source code in vaspvis/band.py
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
def plot_elements(
    self,
    ax,
    elements,
    scale_factor=5,
    erange=[-6, 6],
    display_order=None,
    color_list=None,
    legend=True,
    linewidth=0.75,
    band_color="black",
    heatmap=False,
    bins=400,
    sigma=3,
    cmap="hot",
    vlinecolor="black",
    powernorm=False,
    gamma=0.5,
):
    """
    This function plots the projected band structure on specified elements in the calculated structure

    Parameters:
        ax (matplotlib.pyplot.axis): Axis to plot the data on
        elements (list): List of element symbols to project onto
        scale_factor (float): Factor to scale weights. This changes the size of the
            points in the scatter plot
        color_list (list): List of colors of the same length as the elements list
        legend (bool): Determines if the legend should be included or not.
        linewidth (float): Line width of the plain band structure plotted in the background
        band_color (string): Color of the plain band structure
    """
    if color_list is None:
        colors = np.array(
            [self.color_dict[i] for i in range(len(elements))]
        )
    else:
        colors = color_list

    projected_data = self._sum_elements(elements=elements)

    self._plot_projected_general(
        ax=ax,
        projected_data=projected_data,
        colors=colors,
        scale_factor=scale_factor,
        erange=erange,
        display_order=display_order,
        linewidth=linewidth,
        band_color=band_color,
        heatmap=heatmap,
        bins=bins,
        sigma=sigma,
        cmap=cmap,
        vlinecolor=vlinecolor,
    )

    if legend:
        self._add_legend(ax, names=elements, colors=colors)

plot_orbitals(ax, orbitals, scale_factor=5, erange=[-6, 6], display_order=None, color_list=None, legend=True, linewidth=0.75, band_color='black', heatmap=False, bins=400, sigma=3, cmap='hot', vlinecolor='black', powernorm=False, gamma=0.5)

This function plots the projected band structure of given orbitals summed across all atoms on a given axis.

Parameters:

Name Type Description Default
ax axis

Axis to plot the data on

required
orbitals list

List of orbits to compare

| 0 = s | 1 = py | 2 = pz | 3 = px | 4 = dxy | 5 = dyz | 6 = dz2 | 7 = dxz | 8 = dx2-y2 | 9 = fy3x2 | 10 = fxyz | 11 = fyz2 | 12 = fz3 | 13 = fxz2 | 14 = fzx3 | 15 = fx3

required
scale_factor float

Factor to scale weights. This changes the size of the points in the scatter plot

5
color_dict dict[str][str]

This option allow the colors of each orbital specified. Should be in the form of: {'orbital index': , 'orbital index': , ...}

required
legend bool

Determines if the legend should be included or not.

True
linewidth float

Line width of the plain band structure plotted in the background

0.75
band_color string

Color of the plain band structure

'black'
Source code in vaspvis/band.py
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
def plot_orbitals(
    self,
    ax,
    orbitals,
    scale_factor=5,
    erange=[-6, 6],
    display_order=None,
    color_list=None,
    legend=True,
    linewidth=0.75,
    band_color="black",
    heatmap=False,
    bins=400,
    sigma=3,
    cmap="hot",
    vlinecolor="black",
    powernorm=False,
    gamma=0.5,
):
    """
    This function plots the projected band structure of given orbitals summed across all atoms on a given axis.

    Parameters:
        ax (matplotlib.pyplot.axis): Axis to plot the data on
        orbitals (list): List of orbits to compare

            | 0 = s
            | 1 = py
            | 2 = pz
            | 3 = px
            | 4 = dxy
            | 5 = dyz
            | 6 = dz2
            | 7 = dxz
            | 8 = dx2-y2
            | 9 = fy3x2
            | 10 = fxyz
            | 11 = fyz2
            | 12 = fz3
            | 13 = fxz2
            | 14 = fzx3
            | 15 = fx3

        scale_factor (float): Factor to scale weights. This changes the size of the
            points in the scatter plot
        color_dict (dict[str][str]): This option allow the colors of each orbital
            specified. Should be in the form of:
            {'orbital index': <color>, 'orbital index': <color>, ...}
        legend (bool): Determines if the legend should be included or not.
        linewidth (float): Line width of the plain band structure plotted in the background
        band_color (string): Color of the plain band structure
    """

    if color_list is None:
        colors = np.array([self.color_dict[i] for i in orbitals])
    else:
        colors = color_list

    projected_data = self._sum_orbitals(orbitals=orbitals)

    self._plot_projected_general(
        ax=ax,
        projected_data=projected_data,
        colors=colors,
        scale_factor=scale_factor,
        erange=erange,
        display_order=display_order,
        linewidth=linewidth,
        band_color=band_color,
        heatmap=heatmap,
        bins=bins,
        sigma=sigma,
        cmap=cmap,
        vlinecolor=vlinecolor,
    )

    if legend:
        self._add_legend(
            ax,
            names=[self.orbital_labels[i] for i in orbitals],
            colors=colors,
        )

plot_plain(ax, color='black', erange=[-6, 6], linewidth=1.25, scale_factor=20, linestyle='-', heatmap=False, bins=400, sigma=3, cmap='hot', vlinecolor='black', powernorm=False, gamma=0.5, projection=None, highlight_band=False, highlight_band_color='red', band_index=None, sp_color='red', sp_scale_factor=5)

This function plots a plain band structure.

Parameters:

Name Type Description Default
ax axis

Axis to plot the data on

required
color str

Color of the band structure lines

'black'
linewidth float

Line width of the band structure lines

1.25
linestyle str

Line style of the bands

'-'
Source code in vaspvis/band.py
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
def plot_plain(
    self,
    ax,
    color="black",
    erange=[-6, 6],
    linewidth=1.25,
    scale_factor=20,
    linestyle="-",
    heatmap=False,
    bins=400,
    sigma=3,
    cmap="hot",
    vlinecolor="black",
    powernorm=False,
    gamma=0.5,
    projection=None,
    highlight_band=False,
    highlight_band_color="red",
    band_index=None,
    sp_color="red",
    sp_scale_factor=5,
):
    """
    This function plots a plain band structure.

    Parameters:
        ax (matplotlib.pyplot.axis): Axis to plot the data on
        color (str): Color of the band structure lines
        linewidth (float): Line width of the band structure lines
        linestyle (str): Line style of the bands
    """
    bands_in_plot = self._filter_bands(erange=erange)
    slices = self._get_slices(unfold=self.unfold, hse=self.hse)
    wave_vector_segments = self._get_k_distance()

    # if self.soc_axis is not None and self.lsorbit:
    #     color = "black"
    #     linestyle = "-"

    if self.soc_axis is not None and self.lsorbit:
        if self.unfold:
            K_indices = np.array(self.K_indices[0], dtype=int)
            spin_projection_full_k = self.spin_projections[:, K_indices]
        else:
            spin_projection_full_k = self.spin_projections

    if self.custom_kpath is not None:
        kpath_inds = self.custom_kpath_inds
        kpath_flip = self.custom_kpath_flip
    else:
        kpath_inds = range(len(slices))
        kpath_flip = [False for _ in range(len(slices))]

    for i, f, wave_vectors in zip(
        kpath_inds, kpath_flip, wave_vector_segments
    ):
        if f:
            eigenvalues = np.flip(
                self.eigenvalues[bands_in_plot, slices[i]], axis=1
            )
            if self.soc_axis is not None and self.lsorbit:
                spin_projections = np.flip(
                    spin_projection_full_k[bands_in_plot, slices[i]],
                    axis=1,
                )
        else:
            eigenvalues = self.eigenvalues[bands_in_plot, slices[i]]
            if self.soc_axis is not None and self.lsorbit:
                spin_projections = spin_projection_full_k[
                    bands_in_plot, slices[i]
                ]

        if highlight_band:
            if band_index is not None:
                if type(band_index) == int:
                    highlight_eigenvalues = self.eigenvalues[
                        int(band_index), slices[i]
                    ]
                else:
                    highlight_eigenvalues = self.eigenvalues[
                        band_index, slices[i]
                    ]

        wave_vectors_for_kpoints = wave_vectors

        if self.interpolate:
            (
                wave_vectors,
                eigenvalues,
            ) = self._get_interpolated_data_segment(
                wave_vectors_for_kpoints,
                eigenvalues,
            )
            if self.soc_axis is not None and self.lsorbit:
                _, spin_projections = self._get_interpolated_data_segment(
                    wave_vectors_for_kpoints,
                    spin_projections,
                    crop_zero=True,
                    kind="linear",
                )

            if highlight_band:
                if band_index is not None:
                    (
                        _,
                        highlight_eigenvalues,
                    ) = self._get_interpolated_data_segment(
                        wave_vectors_for_kpoints,
                        highlight_eigenvalues,
                    )

        eigenvalues_ravel = np.ravel(
            np.c_[eigenvalues, np.empty(eigenvalues.shape[0]) * np.nan]
        )
        wave_vectors_tile = np.tile(
            np.append(wave_vectors, np.nan), eigenvalues.shape[0]
        )

        if self.soc_axis is not None and self.lsorbit:
            #  spin_cmap = self._alpha_cmap(color=spin_projection_color, repeats=1)
            spin_projections_ravel = np.ravel(
                np.c_[
                    spin_projections,
                    np.empty(spin_projections.shape[0]) * np.nan,
                ]
            )
            #  spin_colors = [spin_cmap(s) for s in spin_projections_ravel]

        if self.unfold:
            spectral_weights = self.spectral_weights[
                bands_in_plot, slices[i]
            ]
            if f:
                spectral_weights = np.flip(spectral_weights, axis=1)
            #  spectral_weights = spectral_weights / np.max(spectral_weights)

            if highlight_band:
                if band_index is not None:
                    highlight_spectral_weights = self.spectral_weights[
                        int(band_index), slices[i]
                    ]

            if self.interpolate:
                _, spectral_weights = self._get_interpolated_data_segment(
                    wave_vectors_for_kpoints,
                    spectral_weights,
                    crop_zero=True,
                    kind="linear",
                )

                if highlight_band:
                    if band_index is not None:
                        (
                            _,
                            highlight_spectral_weights,
                        ) = self._get_interpolated_data_segment(
                            wave_vectors_for_kpoints,
                            highlight_spectral_weights,
                            crop_zero=True,
                            kind="linear",
                        )

            spectral_weights_ravel = np.ravel(
                np.c_[
                    spectral_weights,
                    np.empty(spectral_weights.shape[0]) * np.nan,
                ]
            )

            if heatmap:
                self._heatmap(
                    ax=ax,
                    wave_vectors=wave_vectors,
                    eigenvalues=eigenvalues,
                    weights=spectral_weights,
                    sigma=sigma,
                    cmap=cmap,
                    bins=bins,
                    projection=projection,
                    powernorm=powernorm,
                    gamma=gamma,
                )
            else:
                ax.scatter(
                    wave_vectors_tile,
                    eigenvalues_ravel,
                    c=color,
                    ec=None,
                    s=scale_factor * spectral_weights_ravel,
                    zorder=0,
                )
                if highlight_band:
                    if band_index is not None:
                        if type(band_index) == int:
                            ax.scatter(
                                wave_vectors,
                                highlight_eigenvalues,
                                c=highlight_band_color,
                                ec=None,
                                s=scale_factor
                                * highlight_spectral_weights,
                                zorder=100,
                            )
                        else:
                            ax.scatter(
                                np.tile(
                                    np.append(wave_vectors, np.nan),
                                    highlight_eigenvalues.shape[0],
                                ),
                                np.ravel(
                                    np.c_[
                                        highlight_eigenvalues,
                                        np.empty(
                                            highlight_eigenvalues.shape[0]
                                        )
                                        * np.nan,
                                    ]
                                ),
                                c=highlight_band_color,
                                ec=None,
                                s=scale_factor
                                * np.ravel(highlight_spectral_weights),
                                zorder=100,
                            )
                if self.soc_axis is not None and self.lsorbit:
                    ax.scatter(
                        wave_vectors_tile,
                        eigenvalues_ravel,
                        s=spectral_weights_ravel
                        * sp_scale_factor
                        * spin_projections_ravel,
                        c=sp_color,
                        zorder=100,
                    )
        else:
            if heatmap:
                self._heatmap(
                    ax=ax,
                    wave_vectors=wave_vectors,
                    eigenvalues=eigenvalues,
                    weights=np.ones(eigenvalues.shape),
                    sigma=sigma,
                    cmap=cmap,
                    bins=bins,
                    projection=projection,
                    powernorm=powernorm,
                    gamma=gamma,
                )
            else:
                ax.plot(
                    wave_vectors_tile,
                    eigenvalues_ravel,
                    color=color,
                    linewidth=linewidth,
                    linestyle=linestyle,
                    zorder=0,
                )
                if highlight_band:
                    if band_index is not None:
                        if type(band_index) == int:
                            ax.plot(
                                wave_vectors,
                                highlight_eigenvalues,
                                color=highlight_band_color,
                                linewidth=linewidth,
                                linestyle=linestyle,
                                zorder=100,
                            )
                        else:
                            ax.plot(
                                np.tile(
                                    np.append(wave_vectors, np.nan),
                                    highlight_eigenvalues.shape[0],
                                ),
                                np.ravel(
                                    np.c_[
                                        highlight_eigenvalues,
                                        np.empty(
                                            highlight_eigenvalues.shape[0]
                                        )
                                        * np.nan,
                                    ]
                                ),
                                color=highlight_band_color,
                                linewidth=linewidth,
                                linestyle=linestyle,
                                zorder=100,
                            )
                if self.soc_axis is not None and self.lsorbit:
                    ax.scatter(
                        wave_vectors_tile,
                        eigenvalues_ravel,
                        s=sp_scale_factor * spin_projections_ravel,
                        c=sp_color,
                        zorder=100,
                    )

    if self.hse:
        self._get_kticks_hse(
            ax=ax,
            wave_vectors=np.concatenate(self._get_k_distance()),
            kpath=self.kpath,
            vlinecolor=vlinecolor,
        )
    elif self.unfold:
        self._get_kticks_unfold(
            ax=ax,
            wave_vectors=np.concatenate(self._get_k_distance()),
            vlinecolor=vlinecolor,
        )
    else:
        self._get_kticks(
            ax=ax,
            wave_vectors=np.concatenate(self._get_k_distance()),
            vlinecolor=vlinecolor,
        )

    ax.set_xlim(0, np.concatenate(self._get_k_distance()).max())

plot_plain_old(ax, color='black', erange=[-6, 6], linewidth=1.25, scale_factor=20, linestyle='-', heatmap=False, bins=400, sigma=3, cmap='hot', vlinecolor='black', powernorm=False, gamma=0.5, projection=None, highlight_band=False, highlight_band_color='red', band_index=None)

This function plots a plain band structure.

Parameters:

Name Type Description Default
ax axis

Axis to plot the data on

required
color str

Color of the band structure lines

'black'
linewidth float

Line width of the band structure lines

1.25
linestyle str

Line style of the bands

'-'
Source code in vaspvis/band.py
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
def plot_plain_old(
    self,
    ax,
    color="black",
    erange=[-6, 6],
    linewidth=1.25,
    scale_factor=20,
    linestyle="-",
    heatmap=False,
    bins=400,
    sigma=3,
    cmap="hot",
    vlinecolor="black",
    powernorm=False,
    gamma=0.5,
    projection=None,
    highlight_band=False,
    highlight_band_color="red",
    band_index=None,
):
    """
    This function plots a plain band structure.

    Parameters:
        ax (matplotlib.pyplot.axis): Axis to plot the data on
        color (str): Color of the band structure lines
        linewidth (float): Line width of the band structure lines
        linestyle (str): Line style of the bands
    """
    bands_in_plot = self._filter_bands(erange=erange)
    eigenvalues = self.eigenvalues[bands_in_plot]

    if highlight_band:
        if band_index is not None:
            highlight_eigenvalues = self.eigenvalues[int(band_index)]

    wave_vectors = self._get_k_distance()
    wave_vectors_for_kpoints = wave_vectors

    if self.interpolate:
        wave_vectors, eigenvalues = self._get_interpolated_data_segment(
            wave_vectors_for_kpoints, eigenvalues
        )

        if highlight_band:
            if band_index is not None:
                (
                    _,
                    highlight_eigenvalues,
                ) = self._get_interpolated_data_segment(
                    wave_vectors_for_kpoints,
                    highlight_eigenvalues,
                )

    eigenvalues_ravel = np.ravel(
        np.c_[eigenvalues, np.empty(eigenvalues.shape[0]) * np.nan]
    )
    wave_vectors_tile = np.tile(
        np.append(wave_vectors, np.nan), eigenvalues.shape[0]
    )

    if self.unfold:
        spectral_weights = self.spectral_weights[bands_in_plot]
        #  spectral_weights = spectral_weights / np.max(spectral_weights)

        if highlight_band:
            if band_index is not None:
                highlight_spectral_weights = self.spectral_weights[
                    int(band_index)
                ]

        if self.interpolate:
            _, spectral_weights = self._get_interpolated_data_segment(
                wave_vectors_for_kpoints,
                spectral_weights,
                crop_zero=True,
                kind="linear",
            )

            if highlight_band:
                if band_index is not None:
                    (
                        _,
                        highlight_spectral_weights,
                    ) = self._get_interpolated_data_segment(
                        wave_vectors_for_kpoints,
                        highlight_spectral_weights,
                        crop_zero=True,
                        kind="linear",
                    )

        spectral_weights_ravel = np.ravel(
            np.c_[
                spectral_weights,
                np.empty(spectral_weights.shape[0]) * np.nan,
            ]
        )

        if heatmap:
            self._heatmap(
                ax=ax,
                wave_vectors=wave_vectors,
                eigenvalues=eigenvalues,
                weights=spectral_weights,
                sigma=sigma,
                cmap=cmap,
                bins=bins,
                projection=projection,
                powernorm=powernorm,
                gamma=gamma,
            )
        else:
            ax.scatter(
                wave_vectors_tile,
                eigenvalues_ravel,
                c=color,
                ec=None,
                s=scale_factor * spectral_weights_ravel,
                zorder=0,
            )
            if highlight_band:
                if band_index is not None:
                    ax.scatter(
                        wave_vectors,
                        highlight_eigenvalues,
                        c=highlight_band_color,
                        ec=None,
                        s=scale_factor * highlight_spectral_weights,
                        zorder=100,
                    )
    else:
        if heatmap:
            self._heatmap(
                ax=ax,
                wave_vectors=wave_vectors,
                eigenvalues=eigenvalues,
                weights=np.ones(eigenvalues.shape),
                sigma=sigma,
                cmap=cmap,
                bins=bins,
                projection=projection,
                powernorm=powernorm,
                gamma=gamma,
            )
        else:
            ax.plot(
                wave_vectors_tile,
                eigenvalues_ravel,
                color=color,
                linewidth=linewidth,
                linestyle=linestyle,
                zorder=0,
            )
            if highlight_band:
                if band_index is not None:
                    ax.plot(
                        wave_vectors,
                        highlight_eigenvalues,
                        color=highlight_band_color,
                        linewidth=linewidth,
                        linestyle=linestyle,
                        zorder=100,
                    )

    if self.hse:
        self._get_kticks_hse(
            ax=ax,
            wave_vectors=wave_vectors_for_kpoints,
            kpath=self.kpath,
            vlinecolor=vlinecolor,
        )
    elif self.unfold:
        self._get_kticks_unfold(
            ax=ax,
            wave_vectors=wave_vectors_for_kpoints,
            vlinecolor=vlinecolor,
        )
    else:
        self._get_kticks(
            ax=ax,
            wave_vectors=wave_vectors_for_kpoints,
            vlinecolor=vlinecolor,
        )

    ax.set_xlim(0, np.max(wave_vectors))

plot_spd(ax, scale_factor=5, orbitals='spd', erange=[-6, 6], display_order=None, color_list=None, legend=True, linewidth=0.75, band_color='black', heatmap=False, bins=400, sigma=3, cmap='hot', vlinecolor='black', powernorm=False, gamma=0.5)

This function plots the s, p, d projected band structure onto a given axis

Parameters:

Name Type Description Default
ax axis

Axis to plot the data on

required
scale_factor float

Factor to scale weights. This changes the size of the points in the scatter plot

5
order list

This determines the order in which the points are plotted on the graph. This is an option because sometimes certain orbitals can be hidden under others because they have a larger weight. For example, if the weights of the d orbitals are greater than that of the s orbitals, it might be smart to choose ['d', 'p', 's'] as the order so the s orbitals are plotted over the d orbitals.

required
color_dict dict[str][str]

This option allow the colors of the s, p, and d orbitals to be specified. Should be in the form of: {'s': , 'p':

, 'd': }

required
legend bool

Determines if the legend should be included or not.

True
linewidth float

Line width of the plain band structure plotted in the background

0.75
band_color string

Color of the plain band structure

'black'
Source code in vaspvis/band.py
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
def plot_spd(
    self,
    ax,
    scale_factor=5,
    orbitals="spd",
    erange=[-6, 6],
    display_order=None,
    color_list=None,
    legend=True,
    linewidth=0.75,
    band_color="black",
    heatmap=False,
    bins=400,
    sigma=3,
    cmap="hot",
    vlinecolor="black",
    powernorm=False,
    gamma=0.5,
):
    """
    This function plots the s, p, d projected band structure onto a given axis

    Parameters:
        ax (matplotlib.pyplot.axis): Axis to plot the data on
        scale_factor (float): Factor to scale weights. This changes the size of the
            points in the scatter plot
        order (list): This determines the order in which the points are plotted on the
            graph. This is an option because sometimes certain orbitals can be hidden
            under others because they have a larger weight. For example, if the
            weights of the d orbitals are greater than that of the s orbitals, it
            might be smart to choose ['d', 'p', 's'] as the order so the s orbitals are
            plotted over the d orbitals.
        color_dict (dict[str][str]): This option allow the colors of the s, p, and d
            orbitals to be specified. Should be in the form of:
            {'s': <s color>, 'p': <p color>, 'd': <d color>}
        legend (bool): Determines if the legend should be included or not.
        linewidth (float): Line width of the plain band structure plotted in the background
        band_color (string): Color of the plain band structure
    """
    if color_list is None:
        color_list = [
            self.color_dict[0],
            self.color_dict[1],
            self.color_dict[2],
            self.color_dict[4],
        ]
        colors = np.array([color_list[i] for i in range(len(orbitals))])
    else:
        colors = color_list

    projected_data = self._sum_spd(spd=orbitals)

    self._plot_projected_general(
        ax=ax,
        projected_data=projected_data,
        colors=colors,
        scale_factor=scale_factor,
        erange=erange,
        display_order=display_order,
        linewidth=linewidth,
        band_color=band_color,
        heatmap=heatmap,
        bins=bins,
        sigma=sigma,
        cmap=cmap,
        vlinecolor=vlinecolor,
    )

    if legend:
        self._add_legend(ax, names=[i for i in orbitals], colors=colors)