-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAPP_9.8_Qt5.15.6.py
1994 lines (1800 loc) · 100 KB
/
APP_9.8_Qt5.15.6.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# -*- coding: utf-8 -*-
"""
Created on Fri May 19 19:06:57 2023
@author: xiety
"""
# -*- coding: utf-8 -*-
#!!! pip install PyQt5
from PyQt5.QtWidgets import QApplication, QWidget, QHBoxLayout, QVBoxLayout, QTableWidget, QTableWidgetItem, QPushButton,QComboBox, QLabel, QTextEdit, QMainWindow, QCheckBox, QLineEdit, QScrollArea, QSizePolicy, QFileDialog, QMessageBox
from PyQt5.QtGui import QPixmap
from PyQt5.QtGui import QFont
#from PyQt5.QtCore import Qt
#import matplotlib.pyplot as plt
#from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
import numpy as np
import pickle
import csv
import sys
import os
import subprocess
import time
import re
dir_file=(os.popen("pwd").read())
Current_dir=max(dir_file.split('\n'))
root_dir = os.path.expandvars('$HOME')
#code_path="%s/bin/QE-batch/"%root_dir
code_path=sys.path[0]
if os.path.exists("%s/flat.save"%code_path)==0:
os.system("mkdir %s/flat.save"%code_path)
if os.path.isfile("%s/flat.save/FLAT_INFO"%code_path)==0:
#print("AAA")
os.mknod("%s/flat.save/FLAT_INFO"%code_path)
f_initializing=open("%s/flat.save/FLAT_INFO"%code_path,"w")
f_initializing.writelines("flat_number=1 # 1 for\"zf_normal\",2 for \"spst_pub\",3 for \"dm_pub_cpu\"\n")
f_initializing.writelines("node_num=1\n")
f_initializing.writelines("ppn_num=0 # 0 for default\n")
f_initializing.writelines("wall_time=\"116:00:00\"\n")
f_initializing.close()
if os.path.exists("data.save")==0:
os.system("mkdir data.save")
def read_flat_state():
flat_info=open("%s/flat.save/FLAT_INFO"%code_path).readlines()
for lines in flat_info:
if lines.find("flat_number=")!=-1:
flat_number=int(lines.split("flat_number=")[-1].split("#")[0])
if lines.find("node_num=")!=-1:
node_num=int(lines.split("node_num=")[-1].split("#")[0])
if lines.find("ppn_num")!=-1:
ppn_num=int(lines.split("ppn_num=")[-1].split("#")[0])
if lines.find("wall_time=")!=-1:
wall_time=lines.split("wall_time=")[-1].split("#")[0].strip("\n").strip("\"")
if flat_number==1:
type_flat="zf_normal"
if flat_number==2:
type_flat="spst_pub"
if flat_number==3:
type_flat="dm_pub_cpu"
return flat_number,node_num,ppn_num,wall_time,type_flat
#initialize some variables
flat_number,node_num,ppn_num,wall_time,type_flat=read_flat_state()
show_y_l_bands=4
show_y_r_bands=4
#show the available orbital for input element,used in pdos simple mode and detailed mode
def atomic_orbit(element_in,str_name):
common_str_in_output_file="BTO.pdos_atm#"
common_str_in_output_file2=element_in
#print(common_str_in_output_file2)
output_file="accumulated_pdos_file"+common_str_in_output_file2
dir_file=(os.popen("pwd").read())
dir_current=max(dir_file.split('\n'))+'/'+str_name
file_list=[]
for root,dirs,files in os.walk(dir_current):
for file in files:
if common_str_in_output_file in file:
if common_str_in_output_file2 in file.split('#')[1]:
file_list.append(file)
file_dic=[]
for i,files in enumerate(file_list):
file_tail_tick=files.split("#")[-1].strip("\n").strip(")").split("(")
file_tail="-"+file_tail_tick[0]+"-"+file_tail_tick[1]
if file_tail not in file_dic:
file_dic.append(file_tail)
def sort_orbit_num(orbit):
return ''.join([i for i in orbit if i.isdigit()])
file_dic.sort(key=sort_orbit_num)
for i,v in enumerate(file_dic):
file_dic[i]=f"{element_in}{v}"
#print(file_dic)
return file_dic
#show the atomic number range and available orbital under this psp,used in pdos manual mode
def show_pdos_detail(str_name):
common_str_in_output_file="BTO.pdos_atm#"
dir_file=(os.popen("pwd").read())
dir_current=max(dir_file.split('\n'))+'/'+str_name
file_list_tot=[]
for root,dirs,files in os.walk(dir_current):
for file in files:
if common_str_in_output_file in file:
file_list_tot.append(file)
file_dic=[]
for i,files in enumerate(file_list_tot): #read all the pdos files in the dir and store them in [atomic_number,atomic_element,orbital_number,orbital_type]
atomic_nb_i=int(files.split("#")[1].split("(")[0])
atomic_ele_i=files.split("#")[1].split("(")[1].split(")")[0]
orbit_nb_i=int(files.split("#")[-1].split("(")[0])
orbit_tp_i=files.split("#")[-1].split("(")[1].split(")")[0]
file_dic.append([atomic_nb_i,atomic_ele_i,orbit_nb_i,orbit_tp_i])
file_dic.sort(key=lambda x:(x[0],x[2]))
orbit_proj=[['s',['s'],[4]],['p',['p','pz','px','py'],[2,4,6,8]],['d',['d','dz2','dzx','dzy','dx2_y2','dxy'],[2,4,6,8,10,12]]]
ele_type=list(set([x[1] for x in file_dic]))
ele_range_buffer=[]
for i,v in enumerate(file_dic):
if v[1] not in [x[0] for x in ele_range_buffer]:
ele_range_buffer.append([v[1],[v[0]]])
elif v[1] in [x[0] for x in ele_range_buffer]:
if v[0] not in ele_range_buffer[[x[0] for x in ele_range_buffer].index(v[1])][1]:
ele_range_buffer[[x[0] for x in ele_range_buffer].index(v[1])][1].append(v[0])
ele_range=[]
for i in ele_range_buffer:
ele_range.append([i[0],min(i[1]),max(i[1])])
ele_orbit=[]# this list stores the info like [['Ni1', ['-1-s', '-2-p', '-3-s', '-4-d']], ['Li', ['-1-s', '-2-s']], ['O', ['-1-s', '-2-p']], ['Co', ['-1-s', '-2-p', '-3-s', '-4-d']], ['Ni2', ['-1-s', '-2-p', '-3-s', '-4-d']]]
for i,v in enumerate(file_dic):
v_orb='-'+str(v[2])+'-'+v[3]
if v[1] not in [x[0] for x in ele_orbit]:
ele_orbit.append([v[1],[v_orb]])
elif v[1] in [x[0] for x in ele_orbit]:
if v_orb not in ele_orbit[[x[0] for x in ele_orbit].index(v[1])][1]:
ele_orbit[[x[0] for x in ele_orbit].index(v[1])][1].append(v_orb)
show_results=[]
for i in range(len(ele_range)):
ele_i_in_orb=ele_orbit[[x[0] for x in ele_orbit].index(ele_range[i][0])][1]
ele_str_orb=",".join(ele_i_in_orb)
show_results.append(f"{ele_range[i][0]}:({ele_range[i][1]},{ele_range[i][2]})[{ele_str_orb}]")
return "\n".join(show_results)
def load_stylesheet():
with open("styles.qss", "r") as f:
return f.read()
# Define the main window class
class MainWindow(QWidget):
def __init__(self):
super().__init__()
# Load and apply QSS
#stylesheet = load_stylesheet()
#self.setStyleSheet(stylesheet)
# 设置全局字体大小
font = QFont()
font.setPointSize(14) # 设置字体大小为 14 点
app.setFont(font)
self.resize(600, 400)
self.setWindowTitle('QE-batch_V-9.2')
self.move(100, 100)
label = QLabel("开发版",self)
label.move(0,0)
button = QPushButton('上传文件', self)
button.move(50, 100)
#label1 = QLabel("\"一键计算\"会计算当前目录下的\n所有vasp文件并建立文件夹",self)
#label1.setGeometry(30,260,180,100)
button_mode = QPushButton('一键计算', self)
button_mode.move(50, 250)
# Add a new button named "new_be"
button_new_be = QPushButton("查看计算进度", self)
button_new_be.move(50, 300)
# Connect the other buttons' clicked signals to your existing methods
button.clicked.connect(lambda:os.system("rz"))
label_mode_chose = QLabel("选择模式",self)
label_mode_chose.setGeometry(50,170,100,30)
self.combo_box = QComboBox(self)
self.combo_box.setGeometry(50, 200, 100, 30)
# Add items to the QComboBox widget
self.combo_box.addItem("scf")
self.combo_box.addItem("relax")
self.combo_box.addItem("bands")
self.combo_box.addItem("pdos")
self.combo_box.addItem("BaderCharge")
# Set the default item to "mode"
self.combo_box.setCurrentText("relax")
self.mode = self.combo_box.currentText()
self.combo_box.activated.connect(self.on_activated)
#flat_chosen combo
label_flat_chose = QLabel("选择计算平台",self)
label_flat_chose.setGeometry(300,70,100,30)
self.combo_flat = QComboBox(self)
self.combo_flat.setGeometry(300, 100, 100, 30)
self.combo_flat.addItem("zf_normal")
self.combo_flat.addItem("spst_pub")
self.combo_flat.addItem("dm_pub_cpu")
self.combo_flat.setCurrentText(type_flat)
self.flat = self.combo_flat.currentText()
self.combo_flat.activated.connect(self.on_activated_flat)
ppn_lineedit=QLineEdit(str(ppn_num), self)
node_lineedit=QLineEdit(str(node_num), self)
wallT_lineedit=QLineEdit(wall_time, self)
label_node = QLabel("node number",self)
label_node.setGeometry(300,125,100,30)
node_lineedit.setGeometry(300,150,100,30)
label_ppn = QLabel("ppn number (0 for default)",self)
label_ppn.setGeometry(300,175,180,30)
ppn_lineedit.setGeometry(300,200,100,30)
label_wallT = QLabel("Wall Time [format 116:00:00]",self)
label_wallT.setGeometry(300,225,220,30)
wallT_lineedit.setGeometry(300,250,180,30)
button_flat_save = QPushButton('保存', self)
button_flat_save.move(300, 300)
button_flat_save.clicked.connect(lambda:self.flat_save(ppn_lineedit,node_lineedit,wallT_lineedit))
# Connect the activated signal to a function
#button_mode.clicked.connect(lambda:os.system("cp /hpc/data/home/spst/zhengfan/open/replace/in_%s ."%self.mode))
button_mode.clicked.connect(lambda:os.system("python %s/run-all.py %s"%(code_path,self.mode)))
# Connect the button's clicked signal to a method that will open the new window
button_new_be.clicked.connect(lambda:self.read_relax(self.mode))
def flat_save(self,ppn_lineedit,node_lineedit,wallT_lineedit):
type_flat_new = self.combo_flat.currentText()
ppn_num_new=ppn_lineedit.text()
node_num_new=node_lineedit.text()
wallT_new=wallT_lineedit.text()
#flat_number,node_num,ppn_num,wall_time,type_flat=read_flat_state()
print(type_flat_new,node_num_new,ppn_num_new,wallT_new)
if type_flat_new=="zf_normal":
flat_number_new=1
if type_flat_new=="spst_pub":
flat_number_new=2
if type_flat_new=="dm_pub_cpu":
flat_number_new=3
f_flat_change=open("%s/flat.save/FLAT_INFO_1"%code_path,"w")
f_flat_change.writelines("flat_number=%d # 1 for\"zf_normal\",2 for \"spst_pub\",3 for \"dm_pub_cpu\"\n"%flat_number_new)
f_flat_change.writelines("node_num=%s\n"%node_num_new)
f_flat_change.writelines("ppn_num=%s # 0 for default\n"%ppn_num_new)
f_flat_change.writelines("wall_time=\"%s\"\n"%wallT_new)
f_flat_change.close()
os.system("mv %s/flat.save/FLAT_INFO_1 %s/flat.save/FLAT_INFO"%(code_path,code_path))
# Define a function that will be executed when an item is selected
def on_activated(self):
# Get the selected item
self.mode = self.combo_box.currentText()
# Print the selected item
print ("inner",self.mode)
#return self.mode
def on_activated_flat(self):
# Get the selected item
self.flat = self.combo_box.currentText()
# Print the selected item
print ("inner",self.mode)
def read_relax(self,mode):
read_back=os.popen("python %s/read_relax_E_for_UI.py %s"%(code_path,mode)).readlines()
for i in read_back:
if i.find("pv_result_out generated!")!=-1:
self.show_data(mode)
# Define a method that will open the new window and close the current one (optional)
def show_data(self,mode):
self.data_show = DataShow(mode)
self.data_show.show()
# Uncomment the next line if you want to close the current window
# self.close()
class DataShow(QWidget):
def __init__(self,mode):
super().__init__()
self.title = "%s results"%mode
self.mode=mode
self.initUI()
def initUI(self):
self.setWindowTitle(self.title)
self.setGeometry(100, 100, 900, 500)
layout = QVBoxLayout()
if (self.mode=="pdos")|(self.mode=="relax")|(self.mode=="scf"):
colomnout=QHBoxLayout()
colomnout.addStretch()
label_x_rg = QLabel("X range:")
label_y_rg = QLabel("Y range:")
label_space =QLabel(" ")
label_con_x = QLabel(" ~ ")
label_con_y = QLabel(" ~ ")
lineEdit_x_l = QLineEdit()
lineEdit_x_r = QLineEdit()
lineEdit_y_l = QLineEdit()
lineEdit_y_r = QLineEdit()
colomnout.addWidget(label_x_rg)
colomnout.addWidget(lineEdit_x_l)
colomnout.addWidget(label_con_x)
colomnout.addWidget(lineEdit_x_r)
colomnout.addWidget(label_space)
colomnout.addWidget(label_y_rg)
colomnout.addWidget(lineEdit_y_l)
colomnout.addWidget(label_con_y)
colomnout.addWidget(lineEdit_y_r)
if self.mode=='pdos':
linepara = QLineEdit("2;1;0;1")
paralabel = QLabel("Line width;Fill VB;Show Ef;Fill pattern")
colomnout.addWidget(paralabel)
colomnout.addWidget(linepara)
# Add new text_line editer
hidden_col=QHBoxLayout()
hidden_col.addStretch()
hidden_edit=QLineEdit("(1-2)-1-s")
hidden_label=QLabel("Input text:")
hidden_col.addWidget(hidden_label)
hidden_col.addWidget(hidden_edit)
hidden_col.addStretch()
hidden_edit.hide()
hidden_label.hide()
# Add items to the QComboBox widget
self.pdos_combo_box = QComboBox(self)
self.pdos_combo_box.setGeometry(50, 200, 100, 30)
self.pdos_combo_box.addItem("simple mode")
self.pdos_combo_box.addItem("detailed orbital mode")
self.pdos_combo_box.addItem("manual mode")
# Set the default item to "simple mode"
self.pdos_combo_box.setCurrentText("simple mode")
self.pdos_mode = self.pdos_combo_box.currentText()
#self.pdos_combo_box.activated.connect(self.pdos_on_active)
layout.addWidget(self.pdos_combo_box)
layout.addLayout(colomnout)
if self.mode=="pdos":
layout.addLayout(hidden_col)
elif self.mode=="bands":
colomnout=QHBoxLayout()
colomnout.addStretch()
label_y_rg = QLabel("Y range:")
label_minus_y = QLabel(" - ")
label_con_y = QLabel(" ~ ")
lineEdit_y_l = QLineEdit("4")
lineEdit_y_r = QLineEdit("4")
colomnout.addWidget(label_y_rg)
colomnout.addWidget(label_minus_y)
colomnout.addWidget(lineEdit_y_l)
colomnout.addWidget(label_con_y)
colomnout.addWidget(lineEdit_y_r)
layout.addLayout(colomnout)
elif self.mode=="BaderCharge":
pass
table = QTableWidget()
layout.addWidget(table)
self.setLayout(layout)
with open('pv_result_out', 'r') as file:
reader = csv.reader(file, delimiter='\t')
data = list(reader)
table.setRowCount(len(data))
max_column=max([len(i) for i in data])
#print(max_column)
table.setColumnCount(max_column+1)
button_clicked = [False] * len(data) # initialize list of boolean flags
#print(button_clicked)
#for i in range(table.rowCount()):
#for j in range(table.columnCount()-1):
for i in range(len(data)):
for j in range(len(data[i])):
table.setItem(i, j, QTableWidgetItem(str(data[i][j])))
#print(data[i][-2])
if self.mode=='pdos':
self.table_1 = QTableWidget(table.rowCount(),table.columnCount())
self.table_2 = QTableWidget(table.rowCount(),table.columnCount())
self.table_3 = QTableWidget(table.rowCount(),table.columnCount())
for ii in range(table.rowCount()):
for jj in range(table.columnCount()):
self.table_1.setItem(ii, jj, QTableWidgetItem(table.item(ii,jj)))
self.table_2.setItem(ii, jj, QTableWidgetItem(table.item(ii,jj)))
self.table_3.setItem(ii, jj, QTableWidgetItem(table.item(ii,jj)))
self.table_1.setGeometry(table.geometry())
self.table_2.setGeometry(table.geometry())
self.table_3.setGeometry(table.geometry())
layout.addWidget(self.table_1,layout.indexOf(table))
layout.addWidget(self.table_2,layout.indexOf(table))
layout.addWidget(self.table_3,layout.indexOf(table))
self.table_1.hide()
self.table_2.hide()
self.table_3.hide()
for i in range(table.rowCount()):
self.checkBox_1=locals()
self.checkBox_2=locals()
self.hbox_pdos_1=locals()
self.hbox_pdos_2=locals()
self.hbox_pdos_layer_2=locals()
self.widget_pdos_1=locals()
self.widget_pdos_2=locals()
self.elements_1=locals()
self.elements_2=locals()
#continue calculation
if (data[i][-2].find("out of timing")!=-1)|(data[i][-2].find("ERROR")!=-1)|(data[i][-2].find("not converged")!=-1):
button = QPushButton("续算")
button.clicked.connect(lambda state,x=i:self.button_click_error(button,table,button_clicked,x))
button_check_error = QPushButton("查看错误")
button_check_error.clicked.connect(lambda state,x=i:self.button_click_check_error(button_check_error,table,self.mode,x))
button_force = QPushButton("应力")
button_Energy = QPushButton("能量")
button_force.clicked.connect(lambda state,x=i:self.button_click_curve(button_force,table,"force",x,lineEdit_x_l,lineEdit_x_r,lineEdit_y_l,lineEdit_y_r))
button_Energy.clicked.connect(lambda state,x=i:self.button_click_curve(button_Energy,table,"Energy",x,lineEdit_x_l,lineEdit_x_r,lineEdit_y_l,lineEdit_y_r))
layout_Button_relax = QHBoxLayout()
layout_Button_relax.addWidget(button_force)
layout_Button_relax.addWidget(button_Energy)
widget_Button_relax = QWidget()
widget_Button_relax.setLayout(layout_Button_relax)
layout_Button_err = QHBoxLayout()
layout_Button_err.addWidget(button)
layout_Button_err.addWidget(button_check_error)
widget_Button_err = QWidget()
widget_Button_err.setLayout(layout_Button_err)
table.setCellWidget(i, table.columnCount()-1, widget_Button_relax)
table.setCellWidget(i, table.columnCount()-2, widget_Button_err)
table.resizeRowsToContents()
table.resizeColumnsToContents()
#Initial Calculation
if (data[i][-2].find("No Calculation")!=-1):
button = QPushButton("计算")
button.clicked.connect(lambda state,x=i:self.button_click_init(button,table,button_clicked,x))
button_pdos1 = QPushButton("计算")
button_pdos1.clicked.connect(lambda state,x=i:self.button_click_init(button_pdos1,table,button_clicked,x))
button_pdos2 = QPushButton("计算")
button_pdos2.clicked.connect(lambda state,x=i:self.button_click_init(button_pdos2,table,button_clicked,x))
table.setCellWidget(i, table.columnCount()-1, button)
table.resizeRowsToContents()
table.resizeColumnsToContents()
if self.mode=='pdos':
self.table_1.setCellWidget(i, self.table_1.columnCount()-1, button_pdos1)
self.table_2.setCellWidget(i, self.table_2.columnCount()-1, button_pdos2)
self.table_1.resizeRowsToContents()
self.table_2.resizeRowsToContents()
self.table_1.resizeColumnsToContents()
self.table_2.resizeColumnsToContents()
#relax process check
if (self.mode=="relax")&((data[i][-2].find("DONE")!=-1)|(data[i][-2].find("running")!=-1)):
button_force = QPushButton("应力")
button_Energy = QPushButton("能量")
button_force.clicked.connect(lambda state,x=i:self.button_click_curve(button_force,table,"force",x,lineEdit_x_l,lineEdit_x_r,lineEdit_y_l,lineEdit_y_r))
button_Energy.clicked.connect(lambda state,x=i:self.button_click_curve(button_Energy,table,"Energy",x,lineEdit_x_l,lineEdit_x_r,lineEdit_y_l,lineEdit_y_r))
layout_Button_relax = QHBoxLayout()
layout_Button_relax.addWidget(button_force)
layout_Button_relax.addWidget(button_Energy)
widget_Button_relax = QWidget()
widget_Button_relax.setLayout(layout_Button_relax)
table.setCellWidget(i, table.columnCount()-1,widget_Button_relax)
table.resizeRowsToContents()
table.resizeColumnsToContents()
#scf process check
if (self.mode=="scf")&((data[i][-2].find("DONE")!=-1)|(data[i][-2].find("running")!=-1)):
button_E_er = QPushButton("E误差")
button_E_er.clicked.connect(lambda state,x=i:self.button_click_curve(button_E_er,table,"scf-estima",x,lineEdit_x_l,lineEdit_x_r,lineEdit_y_l,lineEdit_y_r))
table.setCellWidget(i, table.columnCount()-1, button_E_er)
table.resizeRowsToContents()
table.resizeColumnsToContents()
#bands draw
if (self.mode=="bands")&(data[i][-2].find("DONE")!=-1):
button = QPushButton("计算能带")
#button = QPushButton("画能带")
#button.clicked.connect(lambda state,x=i:self.button_click_bands(button,table,button_clicked,x,lineEdit_y_l,lineEdit_y_r,show_y_l_bands,show_y_r_bands))
button.clicked.connect(lambda state,x=i:self.button_click_bands(button,table,button_clicked,x,lineEdit_y_l,lineEdit_y_r))
table.setCellWidget(i, table.columnCount()-1, button)
table.resizeRowsToContents()
table.resizeColumnsToContents()
#badercharge show
if (self.mode=="BaderCharge")&(data[i][-2].find("DONE")!=-1):
infile=table.item(i, 0).text().strip()
#judge spin mode
file_input_tag=[]
for root,dirs,files in os.walk(Current_dir+"/"+infile):
for file in files:
if "in_scf" in file or "in_relax" in file:
file_input_tag.append(file)
if len(file_input_tag)==0:
raise ValueError("No input found!The input shall be named with \'in_scf\' or '\in_relax\'!")
spin_mode=0
input_tag=open(infile+"/"+file_input_tag[0]).readlines()
for lines in input_tag:
if "nspin" in lines and "2" in lines and "!" not in lines:
spin_mode=1
if (os.path.isfile(f"data.save/bader_charge_of_{infile}.data")==1)&(((os.path.isfile(f"data.save/Mag_of_{infile}.txt")==1)&(spin_mode==1))|(spin_mode==0)):
button_bader = QPushButton("计算电荷")
button_analyze = QPushButton("分析数据")
button_bader.clicked.connect(lambda state,x=i:self.button_click_badercharge(button_bader,table,button_clicked,x))
button_analyze.clicked.connect(lambda state,x=i:self.button_click_analyze(button_analyze,table,button_clicked,x))
layout_Button_bader = QHBoxLayout()
layout_Button_bader.addWidget(button_bader)
layout_Button_bader.addWidget(button_analyze)
widget_Button_bader = QWidget()
widget_Button_bader.setLayout(layout_Button_bader)
table.setCellWidget(i, table.columnCount()-1,widget_Button_bader)
else:
button_bader = QPushButton("计算电荷")
button_bader.clicked.connect(lambda state,x=i:self.button_click_badercharge(button_bader,table,button_clicked,x))
table.setCellWidget(i, table.columnCount()-1, button_bader)
table.resizeRowsToContents()
table.resizeColumnsToContents()
#pdos draw
if (self.mode=="pdos")&(data[i][-2].find("DONE")!=-1):
#reading elemental species from in_pdos
start_reading=0
ele_spe_li=[]
self.elements_1["el_a"+str(i)]=["total"]
self.elements_2["el_b"+str(i)]=[["total"]]
str_name=table.item(i, 0).text().strip()
if os.path.isfile("%s/in_scf_%s"%(str_name,str_name))==1:
f_read_ele=open("%s/in_scf_%s"%(str_name,str_name)).readlines()
elif os.path.isfile("%s/in_relax_%s"%(str_name,str_name))==1:
f_read_ele=open("%s/in_relax_%s"%(str_name,str_name)).readlines()
for read_ele_lines in f_read_ele:
if read_ele_lines.find("ATOMIC_SPECIES")!=-1:
start_reading=1
continue
elif read_ele_lines.find("K_POINTS")!=-1:
start_reading=0
if start_reading==1:
ele_spe_new=[x for x in read_ele_lines.split() if len(x)>0][0]
if ele_spe_new not in ele_spe_li:
ele_spe_li.append(ele_spe_new)
for ele_spe in ele_spe_li:
ele_2_buffer=[]
self.elements_1["el_a"+str(i)].append(ele_spe)
ele_2_buffer.append(ele_spe)
ele_2_buffer.extend(atomic_orbit(ele_spe,str_name))
self.elements_2["el_b"+str(i)].append(ele_2_buffer)
#self.elements_2["el_b"+str(i)].append(ele_spe)
#self.elements_2["el_b"+str(i)].extend(atomic_orbit(ele_spe,str_name))
self.hbox_pdos_1["hbx_a"+str(i)] = QHBoxLayout()
self.hbox_pdos_1["hbx_a"+str(i)].addStretch()
self.button_1 = QPushButton("计算PDOS")
table.setCellWidget(i, table.columnCount()-1, self.button_1)
for ele in range(len(self.elements_1["el_a"+str(i)])):
self.checkBox_1["chbx_a"+str(i)]=QCheckBox(self.elements_1["el_a"+str(i)][ele])
self.hbox_pdos_1["hbx_a"+str(i)].addWidget(self.checkBox_1["chbx_a"+str(i)])
self.widget_pdos_1["wg_a"+str(i)] = QWidget()
self.widget_pdos_1["wg_a"+str(i)].setLayout(self.hbox_pdos_1["hbx_a"+str(i)])
created_elements = set()
self.button_2 = QPushButton("计算PDOS")
#for ele_symbol in [x.split("-")[0] for x in self.elements_2["el_b"+str(i)]]:
# if ele_symbol not in created_elements:
# checkbox = QCheckBox(ele_symbol)
# self.hbox_pdos_2["hbx_b"+str(i)].addWidget(checkbox)
# created_elements.add(ele_symbol)
#self.widget_pdos_2["wg_b"+str(i)] = QWidget()
#self.widget_pdos_2["wg_b"+str(i)].setLayout(self.hbox_pdos_2["hbx_b"+str(i)])
#self.widget_pdos_2["wg_b"+str(i)] = QWidget()
#self.hbox_pdos_layer_2["hbx_lo_b"+str(i)] = QVBoxLayout()
#for ele in range(len(self.elements_2["el_b"+str(i)])):
# self.hbox_pdos_2["hbx_b"+str(i)+"-"+str(ele)] = QHBoxLayout()
# self.hbox_pdos_2["hbx_b"+str(i)+"-"+str(ele)].addStretch()
# for ele_2 in range(len(self.elements_2["el_b"+str(i)][ele])):
# self.checkBox_2["chbx_b"+str(i)+"-"+str(ele)+"-"+str(ele_2)]=QCheckBox(self.elements_2["el_b"+str(i)][ele][ele_2])
# self.hbox_pdos_2["hbx_b"+str(i)+"-"+str(ele)].addWidget(self.checkBox_2["chbx_b"+str(i)+"-"+str(ele)+"-"+str(ele_2)])
# self.hbox_pdos_layer_2["hbx_lo_b"+str(i)].addLayout(self.hbox_pdos_2["hbx_b"+str(i)+"-"+str(ele)])
#self.widget_pdos_2["wg_b"+str(i)].setLayout(self.hbox_pdos_layer_2["hbx_lo_b"+str(i)])
self.widget_pdos_2["wg_b"+str(i)] = QWidget()
self.hbox_pdos_layer_2["hbx_lo_b"+str(i)] = QVBoxLayout()
for ele in range(len(self.elements_2["el_b"+str(i)])):
self.hbox_pdos_2["hbx_b"+str(i)+"-"+str(ele)] = QHBoxLayout()
self.hbox_pdos_2["hbx_b"+str(i)+"-"+str(ele)].addStretch()
for ele_2 in range(len(self.elements_2["el_b"+str(i)][ele])):
self.checkBox_2["chbx_b"+str(i)+"-"+str(ele)+"-"+str(ele_2)]=QCheckBox(self.elements_2["el_b"+str(i)][ele][ele_2])
self.hbox_pdos_2["hbx_b"+str(i)+"-"+str(ele)].addWidget(self.checkBox_2["chbx_b"+str(i)+"-"+str(ele)+"-"+str(ele_2)])
#self.hbox_pdos_2["hbx_b"+str(i)+"-"+str(ele)].setAlignment(Qt.AlignLeft)
self.hbox_pdos_2["hbx_b"+str(i)+"-"+str(ele)].addStretch()
self.hbox_pdos_layer_2["hbx_lo_b"+str(i)].addLayout(self.hbox_pdos_2["hbx_b"+str(i)+"-"+str(ele)])
#self.hbox_pdos_layer_2["hbx_lo_b"+str(i)].setAlignment(Qt.AlignLeft)
self.widget_pdos_2["wg_b"+str(i)].setLayout(self.hbox_pdos_layer_2["hbx_lo_b"+str(i)])
self.table_2.setCellWidget(i, table.columnCount()-2, self.widget_pdos_2["wg_b"+str(i)])
self.button_2.clicked.connect(lambda state,x=i:self.button_click_pdos_detail(self.button_2,self.table_2,button_clicked,x,self.elements_2["el_b"+str(x)],self.hbox_pdos_2,self.checkBox_2,lineEdit_x_l,lineEdit_x_r,lineEdit_y_l,lineEdit_y_r,linepara))
#self.button_2.clicked.connect(lambda state,x=i:self.button_click_pdos(self.button_2,self.table_2,button_clicked,x,self.elements_2["el_b"+str(x)],self.hbox_pdos_2["hbx_b"+str(x)],self.checkBox_2["chbx_b"+str(x)],lineEdit_x_l,lineEdit_x_r,lineEdit_y_l,lineEdit_y_r,linepara))
self.table_2.setCellWidget(i, table.columnCount()-1, self.button_2)
self.table_2.resizeRowsToContents()
self.table_2.resizeColumnsToContents()
self.table_1.setCellWidget(i, table.columnCount()-2, self.widget_pdos_1["wg_a"+str(i)])
self.button_1.clicked.connect(lambda state,x=i:self.button_click_pdos(self.button_1,self.table_1,button_clicked,x,self.elements_1["el_a"+str(x)],self.hbox_pdos_1["hbx_a"+str(x)],self.checkBox_1["chbx_a"+str(x)],lineEdit_x_l,lineEdit_x_r,lineEdit_y_l,lineEdit_y_r,linepara))
self.table_1.setCellWidget(i, table.columnCount()-1, self.button_1)
#uncommand the followings when use PyQy5.15.9 or higher version, but for 5.15.2 its the best
self.table_1.resizeColumnsToContents()
self.table_1.resizeRowsToContents()
self.button_3 = QPushButton("计算PDOS")
self.table_3.setItem(i, table.columnCount()-2, QTableWidgetItem(show_pdos_detail(table.item(i, 0).text().strip())))
self.button_3.clicked.connect(lambda state,x=i:self.button_click_pdos_diy(self.button_3,self.table_3,button_clicked,x,lineEdit_x_l,lineEdit_x_r,lineEdit_y_l,lineEdit_y_r,linepara,hidden_edit,hidden_label))
self.table_3.setCellWidget(i, table.columnCount()-1, self.button_3)
self.table_3.resizeRowsToContents()
self.table_3.resizeColumnsToContents()
table.hide()
self.table_1.show()
self.pdos_combo_box.activated.connect(lambda state,x=i:self.pdos_on_active(table,button_clicked,x,lineEdit_x_l,lineEdit_x_r,lineEdit_y_l,lineEdit_y_r,linepara,hidden_edit,hidden_label))
def pdos_on_active(self,table,button_clicked,i,lineEdit_x_l,lineEdit_x_r,lineEdit_y_l,lineEdit_y_r,linepara,hidden_edit,hidden_label):
# Get the selected item
self.pdos_mode = self.pdos_combo_box.currentText()
# Print the selected item
print ("Pdos mode:",self.pdos_mode)
if self.pdos_mode=="simple mode":
self.table_1.show()
self.table_2.hide()
self.table_3.hide()
hidden_edit.hide()
hidden_label.hide()
#self.button_2.hide()
#self.button_1.show()
#self.widget_pdos_2["wg_b"+str(i)].hide()
#self.widget_pdos_1["wg_a"+str(i)].show()
#table.setCellWidget(i, table.columnCount()-2, self.widget_pdos_1["wg_a"+str(i)])
#self.button_1.clicked.connect(lambda state,x=i:self.button_click_pdos(self.button_1,table,button_clicked,x,self.elements_1["el_a"+str(x)],self.hbox_pdos_1["hbx_a"+str(x)],self.checkBox_1["chbx_a"+str(x)],lineEdit_x_l,lineEdit_x_r,lineEdit_y_l,lineEdit_y_r,linepara))
#table.setCellWidget(i, table.columnCount()-1, self.button_1)
elif self.pdos_mode=="detailed orbital mode":
self.table_1.hide()
self.table_2.show()
self.table_3.hide()
hidden_edit.hide()
hidden_label.hide()
#self.button_1.hide()
#self.button_2.show()
#self.widget_pdos_1["wg_a"+str(i)].hide()
#self.widget_pdos_2["wg_b"+str(i)].show()
#table.setCellWidget(i, table.columnCount()-2, self.widget_pdos_2["wg_b"+str(i)])
#self.button_2.clicked.connect(lambda state,x=i:self.button_click_pdos(self.button_2,table,button_clicked,x,self.elements_2["el_b"+str(x)],self.hbox_pdos_2["hbx_b"+str(x)],self.checkBox_2["chbx_b"+str(x)],lineEdit_x_l,lineEdit_x_r,lineEdit_y_l,lineEdit_y_r,linepara))
#table.setCellWidget(i, table.columnCount()-1, self.button_2)
elif self.pdos_mode=="manual mode":
self.table_1.hide()
self.table_2.hide()
self.table_3.show()
hidden_edit.show()
hidden_label.show()
def button_click_check_error(self,button_check_error,table,mode,x):
str_name=table.item(x, 0).text().strip()
#button= self.sender()#To change the button's name when it is clicked, you can use the sender() method to get the button that was clicked and then use the setText() method to change its name
#button.setText("已续算")
print("%s/out_%s_%s"%(str_name,mode,str_name))
self.showtext=TextShow("%s/out_%s_%s"%(str_name,mode,str_name))
self.showtext.show()
def button_click_error(self,button,table,button_clicked,x):
#nonlocal button_clicked # use nonlocal to access the list of boolean flags
if button_clicked[x]==False:
os.system("python %s/continue_cal.py %s %s"%(code_path,table.item(x, 0).text(),self.mode))
print(table.item(x, 0).text())
button= self.sender()#To change the button's name when it is clicked, you can use the sender() method to get the button that was clicked and then use the setText() method to change its name
#button.setText("已续算")
button.hide()
button_clicked[x] = True
#table.setItem(x, table.columnCount()-1, QTableWidgetItem("已续算")) # set text of corresponding cell
def button_click_init(self,button,table,button_clicked,x):
#nonlocal button_clicked # use nonlocal to access the list of boolean flags
if button_clicked[x]==False:
os.system("python %s/replace.py %s.vasp %s 0 0"%(code_path,table.item(x, 0).text(),self.mode))
print(table.item(x, 0).text())
button= self.sender()#To change the button's name when it is clicked, you can use the sender() method to get the button that was clicked and then use the setText() method to change its name
button.hide()
button_clicked[x] = True
table.setItem(x, table.columnCount()-1, QTableWidgetItem("已计算")) # set text of corresponding cell
#def button_click_bands(self,button,table,button_clicked,x,lineEdit_y_l,lineEdit_y_r,show_y_l_bands,show_y_r_bands):
def button_click_bands(self,button,table,button_clicked,x,lineEdit_y_l,lineEdit_y_r):
global show_y_l_bands
global show_y_r_bands
str_name=table.item(x, 0).text().strip()
if (str(show_y_l_bands)!=lineEdit_y_l.text().strip())|(str(show_y_r_bands)!=lineEdit_y_r.text().strip()):
for i in range(table.rowCount()):
button_clicked[i]=False
show_y_l_bands,show_y_r_bands=lineEdit_y_l.text().strip(),lineEdit_y_r.text().strip()
if button_clicked[x]==False:
vb_num=bands_read("%s/out_scf_"%str_name+str_name)
print("python %s/titledbandstrv5.1.py out_bands_%s %d %s %s"%(code_path,str_name,vb_num,show_y_l_bands,show_y_r_bands))
os.chdir(str_name)
if (show_y_l_bands==0)|(show_y_r_bands==0):
show_y_l_bands=4
show_y_r_bands=4
print("No data,plz input a range!")
data_bands=os.popen("python %s/titledbandstrv5.1.py out_bands_%s %d %s %s"%(code_path,str_name,vb_num,show_y_l_bands,show_y_r_bands)).readlines()
os.chdir(Current_dir)
for j_i in data_bands:
if j_i.find("Fermi energy =")!=-1:
Fermi_E=float(j_i.split("\n")[0].split("Fermi energy = ")[-1].strip())
elif j_i.find("Band gap =")!=-1:
Band_gap=float(j_i.split("\n")[0].split("Band gap =")[-1].strip())
button=self.sender()
button.setText("查看能带")
button_clicked[x] = True
table.setItem(x, table.columnCount()-2, QTableWidgetItem("Band_Gap=%.2f Fermi_E=%.2f"%(Band_gap,Fermi_E)))
if button_clicked[x]==True:
self.bands_show = BandsShow(str_name)
self.bands_show.show()
def button_click_badercharge(self,button,table,button_clicked,x):
str_name=table.item(x, 0).text().strip()
if button_clicked[x]==False:
original_charge=self.bader_process(str_name)
button=self.sender()
button.setText("查看电荷")
button_clicked[x] = True
table.setItem(x, table.columnCount()-2, QTableWidgetItem(original_charge))
if button_clicked[x]==True:
self.bader_show = BaderShow(str_name)
self.bader_show.show()
def button_click_analyze(self,button,table,button_clicked,x):
str_name=table.item(x, 0).text().strip()
self.analyze_show = AnalyzeShow(str_name)
self.analyze_show.show()
def bader_process(self,str_name):
file_input_tag=[]
for root,dirs,files in os.walk(Current_dir+"/"+str_name):
for file in files:
if "in_scf" in file or "in_relax" in file:
file_input_tag.append(file)
if len(file_input_tag)==0:
raise ValueError("No input found!The input shall be named with \'in_scf\' or '\in_relax\'!")
spin_mode=0
input_tag=open(str_name+"/"+file_input_tag[0]).readlines()
for lines in input_tag:
if "nspin" in lines and "2" in lines and "!" not in lines:
spin_mode=1
infile=str_name
if (os.path.isfile(f"data.save/bader_charge_of_{infile}.data")==1)&(os.path.isfile(f"data.save/Lowdin_of_{infile}.txt")==1):
if ((spin_mode==1)&(os.path.isfile(f"data.save/Mag_of_{infile}.txt")==1))|(spin_mode==0):
print(f"Quick read charge of {infile}")
bader_file=f"{str_name}/Bader_{infile}"
in_bader=open(bader_file).readlines()
valence_charge=[]
for i,v in enumerate(in_bader):
#print(v)
pattern=r'^\s+\d+\s+[A-Za-z0-9]+\s+\d+(?:\.\d*)?\s*\n?$'
if re.match(pattern,v):
valence_line=[x for x in v.strip("\n").split() if len(x)>0]
#print(valence_line)
valence_charge.append([valence_line[1],float(valence_line[2])])
outshit=''
for i in valence_charge:
outshit+=f"{i[0]}-{[i[1]]}\n"
return outshit
os.chdir(str_name)
jj=os.popen(f"bader Bader_{str_name}.cube").readlines()
os.chdir(Current_dir)
magfile=f"data.save/Mag_of_{str_name}.txt"
lowdin_file=f"data.save/Lowdin_of_{str_name}.txt"
if os.path.isfile(f"{str_name}/in_scf_{infile}"):
print("scf done in {str_name}")
atomic_file=f"{str_name}/in_scf_{infile}"
if not os.path.isfile(magfile) and (spin_mode==1):
read_mag=os.popen(f"python {code_path}/read_mag.py {str_name} scf").readlines()
os.system(f"mv Mag_of_{str_name}.txt data.save")
if not os.path.isfile(lowdin_file):
if os.path.isfile(f"{str_name}/out_pdos_{str_name}"):
read_mag=os.popen(f"python {code_path}/read_lowdin.py {str_name} scf").readlines()
os.system(f"mv Lowdin_of_{str_name}.txt data.save")
else:
raise ValueError("PDOS has not been calculated in {str_name}!")
elif os.path.isfile(f"{str_name}/in_relax_{infile}"):
print("relax done in {str_name}")
atomic_file=f"{str_name}/in_relax_{infile}"
if not os.path.isfile(magfile) and (spin_mode==1):
read_mag=os.popen(f"python {code_path}/read_mag.py {str_name} relax").readlines()
os.system(f"mv Mag_of_{str_name}.txt data.save")
if not os.path.isfile(lowdin_file):
if os.path.isfile(f"{str_name}/out_pdos_{str_name}"):
read_mag=os.popen(f"python {code_path}/read_lowdin.py {str_name} relax").readlines()
os.system(f"mv Lowdin_of_{str_name}.txt data.save")
else:
raise ValueError("PDOS has not been calculated in {str_name}!")
else:
raise ValueError("No scf or relaxation found!")
bader_file=f"{str_name}/Bader_{infile}"
acf=f"{str_name}/ACF.dat"
if spin_mode==1:
in_mag=open(magfile).readlines() #Magnetic file get by read_mag.py
in_lowdin=open(lowdin_file).readlines()
in_spe=open(atomic_file).readlines()
in_charge=open(acf).readlines() #bader charge file get by bader
in_bader=open(bader_file).readlines() #bader charge file get by pp.x calculation
atomic_number=0
element_number=0
for i,v in enumerate(in_spe):
if 'nat' in v and '!' not in v:
atomic_number=int(v.split("=")[-1].strip("\n").strip().strip(",").strip())
if 'ntyp' in v and '!' not in v:
element_number=int(v.split("=")[-1].strip("\n").strip().strip(",").strip())
if (atomic_number==0)|(element_number==0):
raise ValueError(f"No \'nat\' or \'ntyp\' found in {atomic_file}")
elements=[] #read elements from in_scf/in_relax it is elements related to EACH atomic number
start_read_in_spe=0
read_count_in_spe=0
for i,v in enumerate(in_spe):
if "ATOMIC_POSITIONS" in v:
start_read_in_spe=1
continue
if (start_read_in_spe==1)&(read_count_in_spe<atomic_number):
elements.append([x for x in v.split() if len(x)>0][0])
element_type=[] #read element_type from in_scf/in_relax it is element with no duplicates
start_read_ele=0
read_count_ele=0
for i,v in enumerate(in_spe):
if "ATOMIC_SPECIES" in v:
start_read_ele=1
continue
if (start_read_ele==1)&(read_count_ele<element_number):
element_type.append([x for x in v.split() if len(x)>0][0])
element_type_number=[]
for i in elements:
if i in [x[0] for x in element_type_number]:
element_type_number[[x[0] for x in element_type_number].index(i)][1]+=1
else:
element_type_number.append([i,1])
start_read_in_bader=0
bader_charge_lst=[] #bader charge of each atomic number
for i,v in enumerate(in_charge):
if "#" in v:
continue
if (start_read_in_bader==0)&(v.find("-------------")!=-1):
start_read_in_bader=1
continue
if (start_read_in_bader==1)&(v.find("-------------")!=-1):
start_read_in_bader=0
continue
if start_read_in_bader==1:
bader_charge_lst.append(float([x for x in v.strip("\n").split() if len(x)>0][4]))
valence_charge=[] #total charge read from Bader_{str_name} which gets from pesuedo potentials
for i,v in enumerate(in_bader):
#print(v)
pattern=r'^\s+\d+\s+[A-Za-z0-9]+\s+\d+(?:\.\d*)?\s*\n?$'
if re.match(pattern,v):
valence_line=[x for x in v.strip("\n").split() if len(x)>0]
#print(valence_line)
valence_charge.append([valence_line[1],float(valence_line[2])])
for i,v in enumerate(valence_charge): #replace the element incase the spin up and spin down is not required by Bader_{infile} file
v[0]=element_type[i]
total_charge=0
for i in valence_charge:
print(i[0],i[1],element_type_number[[x[0] for x in element_type_number].index(i[0])][0],element_type_number[[x[0] for x in element_type_number].index(i[0])][1])
total_charge+=i[1]*element_type_number[[x[0] for x in element_type_number].index(i[0])][1]
print("Calculated total charge:",total_charge)
lowdin_charge=[] #lowdin charge read from out_pdos
for i,v in enumerate(in_lowdin):
if "#" in v:
continue
else:
lowdin_line=[x for x in v.strip("\n").split("\t") if len(x)>0]
lowdin_charge.append([float(lowdin_line[1])])
lowdin_sum=0
for i in lowdin_charge:
lowdin_sum+=i[0]
for i in lowdin_charge:
i[0]=float("%.6f"%(i[0]*total_charge/lowdin_sum))
if spin_mode==1:
magnetics=[] #magnetics read from out_scf/out_relax
for i,v in enumerate(in_mag):
mag_line=[x for x in v.strip("\n").split(" ") if len(x)>0]
magnetics.append([float(mag_line[-1])])
ionic_charge=[] #calculated by valence_charge-bader/lowdin charge
#print(valence_charge,lowdin_charge)
for i,v in enumerate(elements):
if v in [x[0] for x in valence_charge]:
ionic_charge.append(["%.6f"%(valence_charge[[x[0] for x in valence_charge].index(v)][1]-bader_charge_lst[i]),
"%.6f"%(valence_charge[[x[0] for x in valence_charge].index(v)][1]-lowdin_charge[i][0]) ] )
out_filenm=f"bader_charge_of_{infile}.data"
f_out=open(out_filenm,"w")
for i in range(len(ionic_charge)):
if spin_mode==1:
f_out.writelines(f"{elements[i]}-{i+1} {lowdin_charge[i][0]} {bader_charge_lst[i]} {ionic_charge[i][1]} {ionic_charge[i][0]} {magnetics[i][0]}\n")
elif spin_mode==0:
f_out.writelines(f"{elements[i]}-{i+1} {lowdin_charge[i][0]} {bader_charge_lst[i]} {ionic_charge[i][1]} {ionic_charge[i][0]}\n")
#print(f"{elements[i]} {bader_charge_lst[i]} {ionic_charge[i]}")
f_out.close()
os.system(f"mv {out_filenm} data.save")
outshit=''
for i in valence_charge:
outshit+=f"{i[0]}-{[i[1]]}\n"
return outshit
def get_selected_element_detail(self,elements,hbox_pdos,i,checkBox):
selectedChoices = []
for ele in range(len(self.elements_2["el_b"+str(i)])):
for ele_2 in range(len(self.elements_2["el_b"+str(i)][ele])):
checkBox = self.checkBox_2["chbx_b"+str(i)+"-"+str(ele)+"-"+str(ele_2)]
if (checkBox is not None and checkBox.isChecked()):
selectedChoices.append(self.elements_2["el_b"+str(i)][ele][ele_2])
#element_i=[]
#hbox_pdos_i=[]
#for ele in range(len(elements)):
# element_i.extend(elements[ele])
# hbox_pdos_i.extend(hbox_pdos[ele])
#print("total",elements)
#print(checkBox)
#for ele in range(len(elements_i)):
# checkBox = hbox_pdos_i.itemAt(ele+1).widget()
# if (checkBox is not None and checkBox.isChecked()):
# selectedChoices.append(elements_i[ele])
#print("sele",selectedChoices)
return selectedChoices
def button_click_pdos_detail(self,button,table,button_clicked,x,elements,hbox_pdos,checkBox,lineEdit_x_l,lineEdit_x_r,lineEdit_y_l,lineEdit_y_r,linepara):
str_name=table.item(x, 0).text().strip()
#print("in button clicked",elements)
if button_clicked[x]==False:
button=self.sender()
button.setText("查看PDOS")
button_clicked[x] = True
self.pdos_show(str_name,self.get_selected_element_detail(elements,hbox_pdos,x,checkBox),lineEdit_x_l,lineEdit_x_r,lineEdit_y_l,lineEdit_y_r,linepara)
elif button_clicked[x]==True:
self.pdos_show(str_name,self.get_selected_element_detail(elements,hbox_pdos,x,checkBox),lineEdit_x_l,lineEdit_x_r,lineEdit_y_l,lineEdit_y_r,linepara)
def get_selected_element(self,elements,hbox_pdos,i,checkBox):
selectedChoices = []
#print("total",elements)
#print(checkBox)
for ele in range(len(elements)):
checkBox = hbox_pdos.itemAt(ele+1).widget()
if (checkBox is not None and checkBox.isChecked()):
selectedChoices.append(elements[ele])
#print("sele",selectedChoices)
return selectedChoices
def button_click_pdos(self,button,table,button_clicked,x,elements,hbox_pdos,checkBox,lineEdit_x_l,lineEdit_x_r,lineEdit_y_l,lineEdit_y_r,linepara):
str_name=table.item(x, 0).text().strip()
#print("in button clicked",elements)
if button_clicked[x]==False:
button=self.sender()
button.setText("查看PDOS")
button_clicked[x] = True
self.pdos_show(str_name,self.get_selected_element(elements,hbox_pdos,x,checkBox),lineEdit_x_l,lineEdit_x_r,lineEdit_y_l,lineEdit_y_r,linepara)
elif button_clicked[x]==True:
self.pdos_show(str_name,self.get_selected_element(elements,hbox_pdos,x,checkBox),lineEdit_x_l,lineEdit_x_r,lineEdit_y_l,lineEdit_y_r,linepara)
def button_click_pdos_diy(self,button,table,button_clicked,x,lineEdit_x_l,lineEdit_x_r,lineEdit_y_l,lineEdit_y_r,linepara,hidden_edit,hidden_label):
str_name=table.item(x, 0).text().strip()
#print("in button clicked",elements)
if button_clicked[x]==False:
button=self.sender()
button.setText("查看PDOS")
button_clicked[x] = True