-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGUI.py
931 lines (758 loc) · 38.8 KB
/
GUI.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
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5.QtGui import *
import re
import sys
import os
import matplotlib
import numpy as np
matplotlib.use('Qt5Agg')
import matplotlib.pyplot as plt
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg
from matplotlib.figure import Figure
from pyPPSTM.guiMethods import newPPSTM_simple, conv2float, importData
import pyPPSTM.basUtils as Bu
import pyPPSTM.elements as elements
######################### Canvas classes for plotting ####################
class SampleCanvas(FigureCanvasQTAgg):
def __init__(self, parentWiget=None, parentApp=None, width=5, height=4, dpi=100 ):
self.fig = Figure( figsize=(width, height), dpi=dpi )
self.axes = self.fig.add_subplot(111)
#super(self.__class__, self).__init__( self.fig )
FigureCanvasQTAgg.__init__(self, self.fig )
self.parent = parentApp
self.setParent(parentWiget)
FigureCanvasQTAgg.setSizePolicy(self,QSizePolicy.Expanding, QSizePolicy.Expanding)
FigureCanvasQTAgg.updateGeometry(self)
class MplCanvas(FigureCanvasQTAgg):
def __init__(self, parentApp=None, parentWidget=None, width=20, height=8, dpi=150):
self.fig = plt.gcf()
self.axes = self.fig.gca()
super(MplCanvas, self).__init__(self.fig)
self.parent = parentApp
self.setParent(parentWidget)
def correct_ext(self, fname, ext):
_, fext = os.path.splitext(fname)
if fext.capitalize() != ext.capitalize():
fname += ext
return fname
def saveData(self):
mapType = self.parent.map
vv = self.parent.Vindx
k = self.parent.Hindx
namez = self.parent.plotData['namez']
tip_type = self.parent.plotData['tip_type']
WorkFunction = self.parent.plotData['WorkFunction']
Voltages = self.parent.plotData['Voltages']
WF_decay = self.parent.plotData['WF_decay']
eta = self.parent.myDict['etaValue']
if mapType == 'dIdV':
fileName, fext = QFileDialog.getSaveFileName(self,"QFileDialog.getSaveFileName()",'didv_'+namez[vv]+"_tip_"+tip_type+"-"+"_WF_"+str(WorkFunction-Voltages[vv]*WF_decay)+"_eta_"+str(eta)+'_%03d' %k, "WSxM Files (*.xyz);;XSF Files (*.xsf);;NPY Files (*.npy)")
else:
fileName, fext = QFileDialog.getSaveFileName(self,"QFileDialog.getSaveFileName()",'STM_'+namez[vv]+"_tip_"+tip_type+"-"+"_WF_"+str(WorkFunction)+"_WF_decay_"+str(round(WF_decay,1))+"_eta_"+str(eta)+'_%03d' %k, "WSxM Files (*.xyz);;XSF Files (*.xsf);;NPY Files (*.npy)")
if fileName:
if fext == '(*.xsf)':
print("For XSF or NPY outputs or tip_type = relaxed you have to have installed PPAFM in your PPSTM directory ")
import pyPPSTM.GridUtils as GU
print("writing XSF files")
geom_plot = self.parent.plotData['geom_plot']
lvec = self.parent.plotData['lvec']
xsf_head = Bu.At2XSF(geom_plot) #if plot_atoms else GU.XSF_HEAD_DEFAULT
if mapType == 'dIdV':
didv = self.parent.plotData['didv']
GU.saveXSF(fileName, didv[vv], lvec, head=xsf_head )
elif mapType == 'STM':
current = self.parent.plotData['current']
GU.saveXSF(fileName, current[vv], lvec, head=xsf_head )
print("XSF files written")
elif fext == '(*.npy)':
print("For XSF or NPY outputs or tip_type = relaxed you have to have installed PPAFM in your PPSTM directory ")
import pyPPSTM.GridUtils as GU
print("writing npy binary files")
lvec = self.parent.plotData['lvec']
if mapType == 'dIdV':
didv = self.parent.plotData['didv']
GU.saveNpy(fileName, didv[vv], lvec)#, head=XSF_HEAD_DEFAULT )
elif mapType == 'STM':
current = self.parent.plotData['current']
GU.saveNpy(fileName, current[vv], lvec)#, head=XSF_HEAD_DEFAULT )
print("npy files written")
else:
# default write in WSxM
print("writing WSxM files")
tip_r0 = self.parent.plotData['tip_r0']
if mapType == 'dIdV':
didv = self.parent.plotData['didv']
tmp_curr=didv[vv,k,:,:].flatten()
out_curr=np.zeros((len(tmp_curr),3))
out_curr[:,0]=tip_r0[k,:,:,0].flatten()
out_curr[:,1]=tip_r0[k,:,:,1].flatten()
out_curr[:,2]=tmp_curr.copy()
f=open(fileName,'w')
print("WSxM file copyright Nanotec Electronica", file=f)
print("WSxM ASCII XYZ file; obtained from dIdV code by Krejci et al.", file=f)
print("X[A] Y[A] Z[A]", file=f)
print("", file=f)
np.savetxt(f, out_curr)
f.close()
elif mapType == 'STM':
current = self.parent.plotData['current']
tmp_curr=current[vv,k,:,:].flatten()
out_curr=np.zeros((len(tmp_curr),3))
out_curr[:,0]=tip_r0[k,:,:,0].flatten()
out_curr[:,1]=tip_r0[k,:,:,1].flatten()
out_curr[:,2]=tmp_curr.copy()
f=open(fileName,'w')
print("WSxM file copyright Nanotec Electronica", file=f)
print("WSxM ASCII XYZ file; obtained from dIdV code by Krejci et al.", file=f)
print("X[A] Y[A] Z[A]", file=f)
print("", file=f)
np.savetxt(f, out_curr)
f.close()
print("WSxM files written")
print ("Data saved")
def saveFigure(self):
plotData = self.parent.plotData
vv = self.parent.Vindx
eta = self.parent.myDict['etaValue']
k = self.parent.Hindx
mapType = self.parent.map
if mapType == 'dIdV':
fileName, _ = QFileDialog.getSaveFileName(self,"QFileDialog.getSaveFileName()",'didv_'+plotData['namez'][vv]+"_tip_"+plotData['tip_type']+"-"+"_WF_"+str(plotData['WorkFunction']-plotData['Voltages'][vv]*plotData['WF_decay'])+"_eta_"+str(eta)+'_%03d.png' %k,"Image files (*.png)")
if fileName:
fileName = self.correct_ext(fileName, ".png")
print(("saving image to :", fileName))
plt.fig = plt.gcf()
plt.fig.savefig(fileName)
else:
fileName, _ = QFileDialog.getSaveFileName(self,"QFileDialog.getSaveFileName()",'STM_'+plotData['namez'][vv]+"_tip_"+plotData['tip_type']+"-"+"_WF_"+str(plotData['WorkFunction'])+"_WF_decay_"+str(round(plotData['WF_decay'],1))+"_eta_"+str(eta)+'_%03d.png' %k,"Image files (*.png)")
if fileName:
fileName = self.correct_ext(fileName, ".png")
print(("saving image to :", fileName))
plt.savefig(fileName)
######################## Application Window Class ########################
class Window(QMainWindow):
def __init__(self):
super(Window, self).__init__()
# Following are the variables from inputs. Kind of like private
# Putting all the self variables to a dictionary
# List of needed parameters:
self.myDict = {'dft_code': 'fireball',
'sample_orbs': 'sp',
'spin': None,
'pbc': '00',
'lvs': '[[100,0],[0,100]',
'cut_atoms': -1,
'lower_atoms': None,
'lower_coefs': None,
'data_format': 'xsf',
'kValue': 0.24,
'qValue': 0.0,
'x': [0.0,20.0,0.1],
'y': [0.0,20.0,0.1],
'z': [5.0,6.0,1.0],
'scan_type': 'dIdV',
'etaValue': 0.1,
'wf_decay': 0.0,
'V': -2.0,
'Vmax': 2.0,
'dV': 0.1,
'tipOrbS': 0.13,
'tipOrbPxy': 0.87,
'OMP_NUM_THREADS': 1,
'tip_type': 'fixed',}
self.importData = None
self.plotData = None
self.string_widgets = {}
self.num_widgets = {}
self.paramList = ['dft_code', 'sample_orbs', 'spin', 'pbc', 'lvs', 'cut_atoms', 'lower_atoms', 'lower_coefs', 'data_format', 'kValue', 'qValue', 'x', 'y', 'z', 'scan_type', 'etaValue', 'wf_decay', 'V', 'Vmax', 'dV', 'tipOrbS', 'tipOrbPxy', 'OMP_NUM_THREADS', 'tip_type', 'paths']
self.runClicked = False
self.paths = None
self.map = 'dIdV'
self.Hindx = 0
self.Vindx = 0
# App settings
self.setAttribute(Qt.WA_DeleteOnClose)
self.setWindowTitle("Application Window")
# 'Dummy' widget to hold the whole layout
self.mainWidget = QWidget(self)
# Main layout. Horizontal box. Graphics on the left, functionality on the right.
self.layout = QHBoxLayout(self.mainWidget)
# Create a dummy widget for the plot
canvLayout = QVBoxLayout()
self.layout.addLayout(canvLayout)
self.myCanvas = SampleCanvas(parentWiget=self.mainWidget, parentApp=self, width=5, height=4, dpi=100)
canvLayout.addWidget(self.myCanvas)
# Control Part on the right. Vertical Box Layout.
controlLayout = QVBoxLayout()
self.layout.addLayout(controlLayout)
#################################### INPUT PART ##############################################
# Input part 1 - HBox. First top region of the control part.
inputLayout1 = QHBoxLayout()
controlLayout.addLayout(inputLayout1)
# Adding codes to layout
codesBox = QVBoxLayout(); inputLayout1.addLayout(codesBox)
codesBox.addWidget(QLabel("codes"))
# codes scroll bar
self.codes = QComboBox(); codesBox.addWidget(self.codes)
self.codes.addItems(['fireball', 'gpaw', 'aims', 'cp2k'])
self.codes.currentIndexChanged[str].connect(self.selectCode)
self.string_widgets['dft_code'] = self.codes
# Adding orbitals to layout
orbitalBox = QVBoxLayout(); inputLayout1.addLayout(orbitalBox)
orbitalBox.addWidget(QLabel("sample orbital"))
# oribital scroll bar
self.orbitals = QComboBox(); orbitalBox.addWidget(self.orbitals)
self.orbitals.addItems(['sp', 'spd'])
self.orbitals.currentIndexChanged[str].connect(self.selectOrbital)
self.string_widgets['sample_orbs'] = self.orbitals
# Adding spin to Layout
spinBox = QVBoxLayout(); inputLayout1.addLayout(spinBox)
spinBox.addWidget(QLabel("spin"))
# Spin scroll bar
self.spin = QComboBox(); spinBox.addWidget(self.spin)
self.spin.addItems(['None', 'both', 'alpha', 'beta'])
self.spin.currentIndexChanged[str].connect(self.selectSpin)
self.string_widgets['spin'] = self.spin
# Adding pbc to layout
pbcBox = QVBoxLayout(); inputLayout1.addLayout(pbcBox)
pbcBox.addWidget(QLabel("pbc"))
# pbc scroll bar
self.pbc = QComboBox(); pbcBox.addWidget(self.pbc)
self.pbc.addItems(['00', '11', '22'])
self.pbc.currentIndexChanged[str].connect(self.selectPbc)
self.string_widgets['pbc'] = self.pbc
# Input part 2 - HBox. Second top region of the control part.
inputLayout2 = QHBoxLayout()
controlLayout.addLayout(inputLayout2)
# Adding path text box to the layout
pathBox = QVBoxLayout(); inputLayout2.addLayout(pathBox)
pathBox.addWidget(QLabel("Input files path"))
# Creating input files path text box
# In this case self is needed in order to reference later to the written text inside.
self.path_inputFiles = QLineEdit(); pathBox.addWidget(self.path_inputFiles)
self.path_inputFiles.setText('./')
# Adding geometry_file text box to the layout
geometryBox = QVBoxLayout(); inputLayout2.addLayout(geometryBox)
geometryBox.addWidget(QLabel("Geometry file name"))
# Creating geometry file path text box
self.geometryFile = QLineEdit(); geometryBox.addWidget(self.geometryFile)
self.geometryFile.setText('input.xyz')
# Adding CP2K/GPAW name text box to the layout
nameBox = QVBoxLayout(); inputLayout2.addLayout(nameBox)
nameBox.addWidget(QLabel("CP2K/GPAW name"))
# Creating name text box
self.name = QLineEdit(); nameBox.addWidget(self.name)
self.name.setText('None')
# Adding lvs text box to the layout
lvsBox = QVBoxLayout(); inputLayout2.addLayout(lvsBox)
lvsBox.addWidget(QLabel("lvs"))
# Creating lvs text box
self.lvs = QLineEdit(); lvsBox.addWidget(self.lvs)
self.lvs.setText('[[100,0],[0,100]]')
# Input part 3 - HBox. Third top region of the control part.
inputLayout3 = QHBoxLayout()
controlLayout.addLayout(inputLayout3)
# Cut at box
cutAtBox = QHBoxLayout(); inputLayout3.addLayout(cutAtBox)
cutAtBox.addWidget(QLabel('cut atoms:'))
# Adding cut_at
self.cutAtoms = QSpinBox(); cutAtBox.addWidget(self.cutAtoms);
self.cutAtoms.setRange(-2, 1000); self.cutAtoms.setSingleStep(1)
self.cutAtoms.setValue(-1)
self.cutAtoms.valueChanged.connect(self.selectCutAtoms)
self.num_widgets['cut_atoms'] = self.cutAtoms
# Lower atoms box
lowAtomBox = QHBoxLayout(); inputLayout3.addLayout(lowAtomBox)
lowAtomBox.addWidget(QLabel("lower_atoms:"))
# Creating lower atoms text box
self.lowAtoms = QLineEdit(); lowAtomBox.addWidget(self.lowAtoms)
self.lowAtoms.setText('None')
lowAtomBox.setAlignment(Qt.AlignLeft)
# Lower coefficients box
lowcoeffsBox = QHBoxLayout(); inputLayout3.addLayout(lowcoeffsBox)
lowcoeffsBox.addWidget(QLabel("lower_coeffs:"))
# Creating lower atoms text box
self.lowcoeffs = QLineEdit(); lowcoeffsBox.addWidget(self.lowcoeffs)
self.lowcoeffs.setText('None')
lowcoeffsBox.setAlignment(Qt.AlignLeft)
# Button importing packages and everything
importBox = QHBoxLayout(); inputLayout3.addLayout(importBox)
importButton = QPushButton("Import"); importBox.addWidget(importButton)
importButton.clicked.connect(self.imported)
#### Seperating line
line = QFrame(); controlLayout.addWidget(line); line.setFrameShape(QFrame.HLine); line.setFrameShadow(QFrame.Sunken)
############################## GRID AND RUNNING OPTIONS ####################################
############# grl1 - grid running layout 1 - Format, K, Q ############################
grl1 = QHBoxLayout(); controlLayout.addLayout(grl1);
# Adding format to layout
grl1.addWidget(QLabel(" Format"))
# Creating format scroll bar
self.formatBar = QComboBox(); grl1.addWidget(self.formatBar);
self.formatBar.addItems(['xsf', 'npy'])
self.formatBar.currentIndexChanged[str].connect(self.selectFormat)
self.string_widgets['data_format'] = self.formatBar
# Adding K number range
grl1.addWidget(QLabel(' K: '))
self.k = QDoubleSpinBox(); grl1.addWidget(self.k);
self.k.setRange(0.0, 2.0); self.k.setSingleStep(0.05)
self.k.valueChanged.connect(self.selectK)
self.k.setValue(0.24)
self.num_widgets['kValue'] = self.k
# Adding Q number range
grl1.addWidget(QLabel(' Q: '))
self.q = QDoubleSpinBox(); grl1.addWidget(self.q);
self.q.setRange(-2.0, 2.0); self.q.setSingleStep(0.05)
self.q.valueChanged.connect(self.selectQ)
self.num_widgets['qValue'] = self.q
############# grl2 - grid running layout 2 - Xmin, Xmax, dX #######################
grl2 = QHBoxLayout(); controlLayout.addLayout(grl2);
# Adding Xmin number range
grl2.addWidget(QLabel(' Xmin: '))
self.xMin = QDoubleSpinBox(self); grl2.addWidget(self.xMin);
self.xMin.setRange(-50.0, 20.0); self.xMin.setSingleStep(0.05)
self.xMin.valueChanged.connect(self.selectX)
# Adding Xmax number range
grl2.addWidget(QLabel(' Xmax: '))
self.xMax = QDoubleSpinBox(); grl2.addWidget(self.xMax);
self.xMax.setRange(0.0, 50.0); self.xMax.setSingleStep(0.05)
self.xMax.setValue(20.0)
self.xMax.valueChanged.connect(self.selectX)
# Adding dX number range
grl2.addWidget(QLabel(' dX: '))
self.dx = QDoubleSpinBox(); grl2.addWidget(self.dx);
self.dx.setRange(0.0, 20.0); self.dx.setSingleStep(0.05)
self.dx.setValue(0.1)
self.dx.valueChanged.connect(self.selectX)
############# grl3 - grid running layout 3 - Ymin, Ymax, dY ########################
grl3 = QHBoxLayout(); controlLayout.addLayout(grl3);
# Adding Ymin number range
grl3.addWidget(QLabel(' Ymin: '))
self.yMin = QDoubleSpinBox(); grl3.addWidget(self.yMin);
self.yMin.setRange(-50.0, 20.0); self.yMin.setSingleStep(0.05)
self.yMin.valueChanged.connect(self.selectY)
# Adding Ymax number range
grl3.addWidget(QLabel(' Ymax: '))
self.yMax = QDoubleSpinBox(); grl3.addWidget(self.yMax);
self.yMax.setRange(0.0, 50.0); self.yMax.setSingleStep(0.05)
self.yMax.setValue(20.0)
self.yMax.valueChanged.connect(self.selectY)
# Adding dY number range
grl3.addWidget(QLabel(' dY: '))
self.dy = QDoubleSpinBox(); grl3.addWidget(self.dy);
self.dy.setRange(0.0, 20.0); self.dy.setSingleStep(0.05)
self.dy.setValue(0.1)
self.dy.valueChanged.connect(self.selectY)
############# grl4 - grid running layout 4 - Zmin, Zmax, dZ #########################
grl4 = QHBoxLayout(); controlLayout.addLayout(grl4);
# Adding Zmin number range
grl4.addWidget(QLabel(' Zmin: '))
self.zMin = QDoubleSpinBox(); grl4.addWidget(self.zMin);
self.zMin.setRange(-50.0, 20.0); self.zMin.setSingleStep(0.05)
self.zMin.setValue(5.0)
self.zMin.valueChanged.connect(self.selectZ)
# Adding Zmax number range
grl4.addWidget(QLabel(' Zmax: '))
self.zMax = QDoubleSpinBox(); grl4.addWidget(self.zMax);
self.zMax.setRange(0.0, 50.0); self.zMax.setSingleStep(0.05)
self.zMax.setValue(6.0)
self.zMax.valueChanged.connect(self.selectZ)
# Adding dZ number range
grl4.addWidget(QLabel(' dZ: '))
self.dz = QDoubleSpinBox(); grl4.addWidget(self.dz);
self.dz.setRange(0.0, 20.0); self.dz.setSingleStep(0.05)
self.dz.setValue(1.0)
self.dz.valueChanged.connect(self.selectZ)
############# grl5 - grid running layout 5 - Scan Type, Eta, WF_decay ##################
grl5 = QHBoxLayout(); controlLayout.addLayout(grl5);
# Adding scan type to layout
grl5.addWidget(QLabel(" Scan type"))
# Creating scan type scroll bar
self.scan = QComboBox(); grl5.addWidget(self.scan);
self.scan.addItems(['dIdV', 'v-scan', 'states'])
self.scan.currentIndexChanged[str].connect(self.selectScanType)
self.string_widgets['scan_type'] = self.scan
# Adding Eta number range
grl5.addWidget(QLabel(' Eta: '))
self.eta = QDoubleSpinBox(); grl5.addWidget(self.eta);
self.eta.setRange(0.0, 20.0); self.eta.setSingleStep(0.05)
self.eta.valueChanged.connect(self.selectEta)
self.eta.setValue(0.1)
self.num_widgets['etaValue'] = self.eta
# Adding WF_decay number range (wfd)
grl5.addWidget(QLabel(' WF_decay: '))
self.wfd = QDoubleSpinBox(); grl5.addWidget(self.wfd);
self.wfd.setRange(0.0, 2.0); self.wfd.setSingleStep(0.05)
self.wfd.valueChanged.connect(self.selectWF_decay)
self.num_widgets['wf_decay'] = self.wfd
############# grl6 - grid running layout 6 - V(min), Vmax, dV ###########################
grl6 = QHBoxLayout(); controlLayout.addLayout(grl6);
# Adding V(min) number range
grl6.addWidget(QLabel(' V(min): '))
self.vMin = QDoubleSpinBox(); grl6.addWidget(self.vMin);
self.vMin.setRange(-2.0, 2.0); self.vMin.setSingleStep(0.05)
self.vMin.setValue(-2.0)
self.num_widgets['V'] = self.vMin
# Adding Vmax number range
grl6.addWidget(QLabel(' Vmax: '))
self.vMax = QDoubleSpinBox(); grl6.addWidget(self.vMax);
self.vMax.setRange(0.0, 20.0); self.vMax.setSingleStep(0.05)
self.vMax.setValue(2.0)
self.num_widgets['Vmax'] = self.vMax
# Adding dV number range
grl6.addWidget(QLabel(' dV: '))
self.dv = QDoubleSpinBox(); grl6.addWidget(self.dv);
self.dv.setRange(0.0, 20.0); self.dv.setSingleStep(0.05)
self.dv.setValue(0.1)
self.num_widgets['dV'] = self.dv
self.vMin.valueChanged.connect(self.selectV)
self.dv.valueChanged.connect(self.selectV)
self.vMax.valueChanged.connect(self.selectV)
############# grl7 - grid running layout 7 - Tip orb. s, Tip orb. pxy, OMP_NUM_THREADS ###########
grl7 = QHBoxLayout(); controlLayout.addLayout(grl7);
# Adding Tip orb s number range
grl7.addWidget(QLabel(' Tip orb. s: '))
self.orbS = QDoubleSpinBox(); grl7.addWidget(self.orbS);
self.orbS.setRange(-2.0, 2.0); self.orbS.setSingleStep(0.05)
self.orbS.valueChanged.connect(self.selectTipOrbS)
self.orbS.setValue(0.13)
self.num_widgets['tipOrbS'] = self.orbS
# Adding Vmax number range
grl7.addWidget(QLabel(' Tip orb. pxy: '))
self.orbPxy = QDoubleSpinBox(); grl7.addWidget(self.orbPxy);
self.orbPxy.setRange(-2.0, 20.0); self.orbPxy.setSingleStep(0.05)
self.orbPxy.valueChanged.connect(self.selectTipOrbPxy)
self.orbPxy.setValue(0.87)
self.num_widgets['tipOrbPxy'] = self.orbPxy
# Adding dV number range
grl7.addWidget(QLabel(' OMP_NUM_THREADS: '))
self.ont = QSpinBox(); grl7.addWidget(self.ont);
self.ont.setRange(0, 20); self.ont.setSingleStep(1)
self.ont.valueChanged.connect(self.selectONT)
self.ont.setValue(1)
self.num_widgets['OMP_NUM_THREADS'] = self.ont
############# grl8 - grid running layout 8 - Tip Orb. , Tip type, Run button ###############
grl8 = QHBoxLayout(); controlLayout.addLayout(grl8)
l1 = QHBoxLayout(); grl8.addLayout(l1)
# Tip type
label2 = QLabel(" Tip type:")
label2.setAlignment(Qt.AlignRight)
l1.addWidget(label2)
# Creating tip type scroll bar
self.tip_type = QComboBox(); l1.addWidget(self.tip_type);
self.tip_type.addItems(['fixed', 'relaxed'])
self.tip_type.currentIndexChanged[str].connect(self.selectTipType)
l1.setAlignment(Qt.AlignLeft)
self.string_widgets['tip_type'] = self.tip_type
# Buttons
l2 = QHBoxLayout(); grl8.addLayout(l2)
run = QPushButton("Run"); l2.addWidget(run)
run.clicked.connect(self.running)
#### Seperating line
line = QFrame(); controlLayout.addWidget(line); line.setFrameShape(QFrame.HLine); line.setFrameShadow(QFrame.Sunken)
############################# VISUALIZING OPTIONS PART ####################################
####### vo1 - visualizing options part 1, row 1 - Map type, Voltage, Height, Show button ############
vo1 = QHBoxLayout(); controlLayout.addLayout(vo1)
l3 = QHBoxLayout(); vo1.addLayout(l3)
# Map type scroll bar
label3 = QLabel("Map type")
label3.setAlignment(Qt.AlignRight)
l3.addWidget(label3)
mapType = QComboBox(); l3.addWidget(mapType)
mapType.addItems(['dIdV', 'STM'])
mapType.currentIndexChanged[str].connect(self.selectMapType)
# Adding Voltage Index number range
label4 = QLabel("Voltage Index:")
label4.setAlignment(Qt.AlignRight)
l3.addWidget(label4)
self.vIndx = QSpinBox(); l3.addWidget(self.vIndx);
self.vIndx.setRange(0, 10000); self.vIndx.setSingleStep(1)
self.vIndx.valueChanged.connect(self.selectVindx)
# Adding Height Index number range
label5 = QLabel("Height Index:")
label5.setAlignment(Qt.AlignRight)
l3.addWidget(label5)
self.hIndx = QSpinBox(); l3.addWidget(self.hIndx);
self.hIndx.setRange(0, 10000); self.hIndx.setSingleStep(1)
self.hIndx.valueChanged.connect(self.selectHindx)
l3.setAlignment(Qt.AlignLeft)
l4 = QHBoxLayout(); vo1.addLayout(l4)
self.plotatoms_box = QCheckBox("Plot atoms"); l4.addWidget(self.plotatoms_box)
self.plotatoms_box.setChecked(True)
l5 = QHBoxLayout(); vo1.addLayout(l5)
show = QPushButton("Show"); l5.addWidget(show)
show.clicked.connect(self.showImage)
####### vo2 - visualizing options part 2, row 2 - save image, save data, save options, load options (buttons) #################
vo2 = QHBoxLayout(); controlLayout.addLayout(vo2)
# Buttons
saveImg = QPushButton("Save image"); vo2.addWidget(saveImg)
saveImg.clicked.connect(self.saveFigure)
saveData = QPushButton("Save data"); vo2.addWidget(saveData)
saveData.clicked.connect(self.saveData)
saveOptions = QPushButton("Save options"); vo2.addWidget(saveOptions)
saveOptions.clicked.connect(self.saveOptions)
loadOptions = QPushButton("Load options"); vo2.addWidget(loadOptions)
loadOptions.clicked.connect(self.load)
# Adding layout to the main widget
self.mainWidget.setFocus()
self.setCentralWidget(self.mainWidget)
####################### Saving methods (figure, data, options) ####################################
def saveFigure(self):
if self.runClicked:
self.myCanvas.saveFigure()
else:
print('Error, no plot exists. Run first.')
def saveData(self):
if self.runClicked:
self.myCanvas.saveData()
else:
print('Error. Run first.')
def saveOptions(self):
fileName, fext = QFileDialog.getSaveFileName(self, "QFileDialog.getSaveFileName()", "", "ASCII File (*.txt)")
if fileName:
data = self.myDict
paths = self.paths
f = open(fileName, 'w')
f.write("# comment can be written by hash and space afterwards \n")
for d in data:
f.write(d+': ')
f.write(str(data[d]))
f.write('\n')
if paths:
f.write('paths: ')
f.write(str(paths))
f.close()
############################# Select methods (selecting values for all vars) ####################################
def selectCode(self, code):
self.myDict['dft_code'] = code
def selectOrbital(self, orbital):
self.myDict['sample_orbs'] = orbital
def selectSpin(self, spin):
self.myDict['spin'] = spin
def selectPbc(self, pbc):
self.myDict['pbc'] = pbc
def selectCutAtoms(self):
self.myDict['cut_atoms'] = self.cutAtoms.value()
def selectFormat(self, myFormat):
self.myDict['data_format'] = myFormat
def selectK(self):
self.myDict['kValue'] = self.k.value()
def selectQ(self):
self.myDict['qValue'] = self.q.value()
def selectX(self):
self.myDict['x'][0] = self.xMin.value()
self.myDict['x'][1] = self.xMax.value()
self.myDict['x'][2] = self.dx.value()
def selectY(self):
self.myDict['y'][0] = self.yMin.value()
self.myDict['y'][1] = self.yMax.value()
self.myDict['y'][2] = self.dy.value()
def selectZ(self):
self.myDict['z'][0] = self.zMin.value()
self.myDict['z'][1] = self.zMax.value()
self.myDict['z'][2] = self.dz.value()
def selectScanType(self, scanType):
self.myDict['scan_type'] = scanType
def selectEta(self):
self.myDict['etaValue'] = self.eta.value()
def selectWF_decay(self):
self.myDict['wf_decay'] = self.wfd.value()
def selectV(self):
self.myDict['V'] = self.vMin.value()
self.myDict['Vmax'] = self.vMax.value()
self.myDict['dV'] = self.dv.value()
def selectTipOrbS(self):
self.myDict['tipOrbS'] = self.orbS.value()
def selectTipOrbPxy(self):
self.myDict['tipOrbPxy'] = self.orbPxy.value()
def selectONT(self):
self.myDict['OMP_NUM_THREADS'] = self.ont.value()
def selectTipType(self, tip_type):
self.myDict['tip_type'] = tip_type
def selectMapType(self, chosenMap):
self.map = chosenMap
def selectVindx(self):
self.Vindx = self.vIndx.value()
def selectHindx(self):
self.Hindx = self.hIndx.value()
############################# Button methods (import, load, run, show) ####################################
def imported(self):
# check if path to input files is given, if not give error and do not let to run
inputPath = self.path_inputFiles.text()
geometry_file = self.geometryFile.text()
cp2kName = self.name.text()
if len(inputPath) == 0 or len(cp2kName) == 0 or len(geometry_file) == 0:
print ('Path/name/file not given')
return
lower_coefs = self.lowcoeffs.text()
lower_atoms = self.lowAtoms.text()
lvs = self.lvs.text()
self.myDict['lower_coefs'] = lower_coefs
self.myDict['lower_atoms'] = lower_atoms
self.myDict['lvs'] = lvs
self.paths = {'inputPath': inputPath,
'geometry_file': geometry_file,
'cp2kName': cp2kName,}
self.importData = importData(self.myDict, self.paths)
if self.importData:
print("energies prepared, coeffecients read")
def load(self):
filePath, ext = QFileDialog.getOpenFileName(self,"QFileDialog.getOpenFileName()", "", "ASCII File (*.txt)")
if filePath:
print (" >> OVERWRITING SETTINGS by "+ filePath)
fin = open(filePath, 'r')
for line in fin:
copiedLine = re.sub('\[|\]|\:|\,|\)|\(|\'|\}|\{', '', line)
words = copiedLine.split()
if len(words) == 0 : continue
if words[0][0] == '#': continue
if words[0] in ['x', 'y', 'z']:
sampleList = [float(words[1]), float(words[2]), float(words[3])]
self.myDict[words[0]] = sampleList
self.paramList.remove(words[0])
continue
if words[0] == 'lvs':
splittedLine = line.split(':')
self.myDict['lvs'] = ''.join(splittedLine[1].split())
self.lvs.setText(''.join(splittedLine[1].split()))
self.paramList.remove('lvs')
continue
if words[0] == 'lower_atoms' or words[0] == 'lower_coefs':
splittedLine = line.split(':')
self.myDict[words[0]] = ''.join(splittedLine[1].split())
if words[0] == 'lower_atoms':
self.lowAtoms.setText(''.join(splittedLine[1].split()))
else:
self.lowcoeffs.setText(''.join(splittedLine[1].split()))
self.paramList.remove(words[0])
continue
if words[0] == 'paths':
self.paths = {}
# inputPath
self.paths[words[1]] = words[2]
self.path_inputFiles.setText(words[2])
# geometry_file
self.paths[words[3]] = words[4]
self.geometryFile.setText(words[4])
# cp2kName
self.paths[words[5]] = words[6]
self.name.setText(words[6])
self.paramList.remove('paths')
continue
if words[0] == 'pbc':
self.myDict[words[0]] = words[1]
self.paramList.remove(words[0])
continue
# All the other cases. Assigning values to the keys of self.myDict and trying to convert them to float. If they are not a number conv2float will just return string
self.myDict[words[0]] = conv2float(words[1])
self.paramList.remove(words[0])
self.updateWidgets()
if len(self.paramList) != 0:
print('Following parameters where not changed and remained default:')
for p in self.paramList:
if p == 'paths':
print (p + '(input files path, geometry file name, CP2K/GPAW) = ' + str(self.paths))
else:
print(p + ' = ' + self.myDict[p])
self.paramList = []
self.paramList = list(self.myDict.keys())
self.paramList.append('paths')
fin.close()
def updateWidgets(self):
self.xMin.blockSignals(True); self.xMin.setValue(self.myDict['x'][0]); self.xMin.blockSignals(False)
self.xMax.blockSignals(True); self.xMax.setValue(self.myDict['x'][1]); self.xMax.blockSignals(False)
self.dx.blockSignals(True); self.dx.setValue(self.myDict['x'][2]); self.dx.blockSignals(False)
self.yMin.blockSignals(True); self.yMin.setValue(self.myDict['y'][0]); self.yMin.blockSignals(False)
self.yMax.blockSignals(True); self.yMax.setValue(self.myDict['y'][1]); self.yMax.blockSignals(False)
self.dy.blockSignals(True); self.dy.setValue(self.myDict['y'][2]); self.dy.blockSignals(False)
self.zMin.blockSignals(True); self.zMin.setValue(self.myDict['z'][0]); self.zMin.blockSignals(False)
self.zMax.blockSignals(True); self.zMax.setValue(self.myDict['z'][1]); self.zMax.blockSignals(False)
self.dz.blockSignals(True); self.dz.setValue(self.myDict['z'][2]); self.dz.blockSignals(False)
for ws, wn in zip(self.string_widgets, self.num_widgets):
self.string_widgets[ws].blockSignals(True)
self.string_widgets[ws].setCurrentIndex(self.string_widgets[ws].findText(self.myDict[ws]))
self.string_widgets[ws].blockSignals(False)
self.num_widgets[wn].blockSignals(True)
self.num_widgets[wn].setValue(float(self.myDict[wn]))
self.num_widgets[wn].blockSignals(False)
def running(self):
# run PPSTM_simple with either grid data from 'relaxed' tip or from 'fixed'
if self.paths and self.importData:
self.plotData = newPPSTM_simple(self.myDict, self.paths, self.importData)
else:
print ('Error. Not all the parameters were given (paths - click import button).')
return
if self.plotData:
# Update plot
self.runClicked = True
if self.plotImage(self.plotData, self.Hindx, self.Vindx, self.map):
canvas = MplCanvas(parentApp=self, parentWidget=self.mainWidget, width=20, height=8, dpi=150,)
self.layout.replaceWidget(self.myCanvas, canvas)
self.myCanvas = canvas
def showImage(self):
if self.runClicked:
if self.plotImage(self.plotData, self.Hindx, self.Vindx, self.map):
canvas = MplCanvas(parentApp=self, parentWidget=self.mainWidget, width=20, height=8, dpi=150,)
self.layout.replaceWidget(self.myCanvas, canvas)
self.myCanvas = canvas
else:
print('Error. Run first.')
def plotGeom(self, atomSize=0.1, edge=True, ec='k'):
atoms, tmp1, tmp2 = Bu.loadAtoms(os.path.join(self.paths['inputPath'], 'input_plot.xyz')); del tmp1, tmp2;
self.plotData['geom_plot'] = atoms
plt.fig = plt.gcf()
es = atoms[0]; xs = atoms[1]; ys = atoms[2]
for i in range(len(xs)):
fc = '#%02x%02x%02x' % elements.ELEMENT_DICT[es[i]][7] #; print "DEBUG: fc", fc ; ##fc = '#FFFFFF' ##
if not edge:
ec=fc
circle=plt.Circle( ( xs[i], ys[i] ), atomSize, fc=fc, ec=ec )
plt.fig.gca().axes.add_artist(circle)
def plotImage(self, plotData, height, voltage, mapType):
if mapType == 'dIdV':
if plotData['didv'] is None:
print('Error. didv does not exist.')
return None
if height >= plotData['NoH_didv']:
print ('Error. Height out of index')
return None
elif voltage >= plotData['NoV_didv']:
print ('Error. Voltage out of index')
return None
elif mapType == 'STM':
if plotData['current'] is None:
print('Error. current does not exist.')
return None
if height >= plotData['NoH_STM']:
print ('Error. Height out of index')
return None
elif voltage >= plotData['NoV_STM']:
print ('Error. Voltage out of index')
return None
print("We go to plotting ")
# print "DEBUG: long name:::", namez[vv],';height:%03d;tip:' %k,tip_type,';',tip_orb
#name_plot=namez[voltage]+';height:'+str(height)+';tip:'+tip_type+';'+tip_orb
plt.close()
name_plot=plotData['namez'][voltage]+';height:'+str(height)+';tip:'+plotData['tip_type']
if mapType == 'dIdV':
# ploting part here:
plt.figure( figsize=(0.5 * plotData['lvec'][1,0] , 0.5 * plotData['lvec'][2,1] ) )
plt.imshow(plotData['didv'][voltage,height,:,:], origin='lower', extent=plotData['extent'] , cmap='gray')
if self.plotatoms_box.isChecked(): self.plotGeom()
plt.xlabel(r' Tip_x $\AA$')
plt.ylabel(r' Tip_y $\AA$')
plt.title("dIdV:"+name_plot)
else:
# ploting part here:
plt.figure( figsize=(0.5 * plotData['lvec'][1,0] , 0.5 * plotData['lvec'][2,1] ) )
plt.imshow(plotData['current'][voltage,height,:,:], origin='lower', extent=plotData['extent'] , cmap='gray')
if self.plotatoms_box.isChecked(): self.plotGeom()
plt.xlabel(r' Tip_x $\AA$')
plt.ylabel(r' Tip_y $\AA$')
plt.title("STM:"+name_plot)
return True
if __name__ == "__main__":
app = QApplication(sys.argv)
window = Window()
window.show()
sys.exit(app.exec_())