forked from gjeschke/MMM
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathENDOR_window.m
More file actions
1404 lines (1180 loc) · 45.4 KB
/
ENDOR_window.m
File metadata and controls
1404 lines (1180 loc) · 45.4 KB
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
function varargout = ENDOR_window(varargin)
% ENDOR_WINDOW M-file for ENDOR_window.fig
% ENDOR_WINDOW, by itself, creates a new ENDOR_WINDOW or raises the existing
% singleton*.
%
% H = ENDOR_WINDOW returns the handle to a new ENDOR_WINDOW or the handle to
% the existing singleton*.
%
% ENDOR_WINDOW('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in ENDOR_WINDOW.M with the given input arguments.
%
% ENDOR_WINDOW('Property','Value',...) creates a new ENDOR_WINDOW or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before ENDOR_window_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to ENDOR_window_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help ENDOR_window
% Last Modified by GUIDE v2.5 14-Dec-2010 16:21:56
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @ENDOR_window_OpeningFcn, ...
'gui_OutputFcn', @ENDOR_window_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before ENDOR_window is made visible.
function ENDOR_window_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to ENDOR_window (see VARARGIN)
% Choose default command line output for ENDOR_window
handles.output = hObject;
% global MMM_icon
% Old version with MMM figure icon, blocked because of warning
% j = get(hObject,'javaframe');
% j.setFigureIcon(javax.swing.ImageIcon(im2java(MMM_icon))); %create a java image and set the figure icon
handles.libration=0.5; % libration broadening of spin label position
handles.updated=0;
handles.efficiency=1.0;
handles.center_frq=6000;
handles.center_frq_orig=6000;
handles.tau=600;
set(handles.edit_center_frq,'String',sprintf('%5i',handles.center_frq));
handles.range=[0.5,80];
handles.diamagnetic=[];
handles.labels={};
handles.expanded=false;
handles.structure=1;
handles.bsl_poly=0;
handles.trf=10;
set(handles.text_mean,'String','no distribution');
set(handles.text_stddev,'String',' ');
set(handles.text_coor,'String',' ');
handles.Pcoor=[];
handles.Pcoor_bilayer=[];
handles.Scoor=[];
handles.new_molecule=true;
handles.new_bilayer=true;
% Experimental data set defaults
handles.frq_orig=[];
handles.v_orig=[];
handles.dfrq=10;
handles.bas_name='';
handles.frq_corr=[];
handles.vexp=[];
handles.vb={};
handles.rexp=1.5:0.05:10;
handles.dsim=[];
handles.spcsim=[];
handles.frqsim=[];
handles.rmsd=[];
handles.rmean=[];
handles.stddev=[];
% kernel for fast Deer simulations
load('pake_base40_MMM.mat');
kernel=base-ones(size(base)); % kernel format for pcf2deer
handles.Pake_kernel=kernel;
handles.Pake_t=t;
handles.Pake_r=r;
handles.Pake_wd=wd;
handles.texp=t';
handles.tdip=t';
% copy control flags
handles.copy_ENDOR=0;
handles.copy_distr=0;
% experimental data names
handles.project_dir='';
handles.bas_name='';
[handles,success]=mk_label_list(handles);
load helpicon
set(handles.pushbutton_help,'CData',cdata);
if ~success,
msgbox('Model must feature at least one spin label or selected atom','Mims ENDOR simulation impossible','error');
ENDOR_CloseRequestFcn(handles.ENDOR, eventdata, handles);
else
set(handles.uipanel_diamagnetic,'SelectionChangeFcn',@radiobutton_SelectionChangeFcn);
handles=update(handles);
% Update handles structure
guidata(hObject, handles);
end;
% UIWAIT makes ENDOR_window wait for user response (see UIRESUME)
% uiwait(handles.ENDOR);
% --- Outputs from this function are returned to the command line.
function varargout = ENDOR_window_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
% varargout{1} = handles.output;
% --- Executes on button press in pushbutton_Xepr.
function pushbutton_Xepr_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton_Xepr (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global general
my_path=pwd;
cd(general.exp_files);
ext='*.DTA;';
[fname,pname]=uigetfile(ext,'Load experimental dataset (Xepr)');
if isequal(fname,0)||isequal(pname,0),
return;
end;
reset_user_paths(pname);
general.exp_files=pname;
cd(pname);
% separate filename from extension
dots=findstr('.',fname);
ext_pos=length(fname);
if ~isempty(dots), ext_pos=dots(length(dots))-1; end;
bas_name=fname(1:ext_pos); % name without extension
figname=['P-31 Mims ENDOR simulation - ' fname]; % tell user, which file is current
set(handles.ENDOR,'Name',figname);
handles.project_dir=pname;
handles.bas_name=bas_name;
handles.source_file=[pname fname];
[x,y,z,vb]=get_elexsys_MMM(bas_name);
B0=get_vb2_MMM(vb,'B0VL'); % the magnetic field value is extracted from the parameter file
if ~isempty(B0),
handles.field_known=true;
mun=5.0507831720e-27; % nuclear magneton in SI units
gnP31=2.26320; % nuclear g value of P-31
h=6.6260687652e-34; % Planck's quantum of action in SI units
Hz2kHz=1.0e-3; % conversion factor from Hz to kHz
ny31P=Hz2kHz*B0*mun*gnP31/h; % P-31 nuclear Zeeman frequency at the given magnetic field
else
handles.field_known=false;
ny31P=1000*(x(1)+x(end))/2;
end;
handles.center_frq=ny31P;
handles.center_frq_orig=ny31P;
set(handles.edit_center_frq,'String',sprintf('%5.0f',ny31P));
handles.frq_orig=1000*x;
handles.v_orig=real(z);
handles.dfrq=1000*(x(2)-x(1));
handles.vb=vb;
cd(my_path);
handles=update(handles);
guidata(hObject,handles);
% --- Executes on button press in pushbutton_load_ASCII.
function pushbutton_load_ASCII_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton_load_ASCII (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global general
my_path=pwd;
cd(general.exp_files);
ext='*.dat;';
[fname,pname]=uigetfile(ext,'Load experimental dataset (ASCII)');
if isequal(fname,0)||isequal(pname,0),
return;
end;
reset_user_paths(pname);
general.exp_files=pname;
cd(pname);
% separate filename from extension
dots=findstr('.',fname);
ext_pos=length(fname);
if ~isempty(dots), ext_pos=dots(length(dots))-1; end;
bas_name=fname(1:ext_pos); % name without extension
figname=['P-31 Mims ENDOR simulation - ' fname]; % tell user, which file is current
set(handles.ENDOR,'Name',figname);
handles.project_dir=pname;
handles.bas_name=bas_name;
handles.source_file=[pname fname];
data=load(fname);
x=1000*data(:,1);
z=data(:,2);
ny31P=(x(1)+x(end))/2;
handles.field_known=false;
handles.center_frq=ny31P;
handles.center_frq_orig=ny31P;
set(handles.edit_center_frq,'String',sprintf('%5.0f',ny31P));
handles.frq_orig=x';
handles.v_orig=real(z)';
handles.dfrq=x(2)-x(1);
cd(my_path);
handles=update(handles);
guidata(hObject,handles);
% --- Executes on button press in pushbutton_save.
function pushbutton_save_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton_save (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global general
my_path=pwd;
cd(general.reports);
if get(handles.radiobutton_both,'Value'),
mode='molecule_and_bilayer';
end;
if get(handles.radiobutton_molecule,'Value'),
mode='molecule';
end;
if get(handles.radiobutton_bilayer,'Value'),
mode='bilayer';
end;
name=get(handles.text_paramagnetic,'String');
labstring=sprintf('P31_Mims_%s_%s',name,mode);
suggestion=[labstring '_res.txt'];
[fname,pname]=uiputfile('*.txt','Save results',suggestion);
if isequal(fname,0) || isequal(pname,0),
add_msg_board('Saving of distance distribution and Mims ENDOR simulation canceled by user.');
return;
end;
reset_user_paths(pname);
general.reports=pname;
% Remove (last) extension, if any
s=strfind(fname,'.');
if ~isempty(s),
fname=fname(1:s(length(s))-1);
end;
% Remove suffix '_res', if present
s=strfind(fname,'_res');
if ~isempty(s),
fname=fname(1:s(length(s))-1);
end;
fname_res=[fname '_res.txt'];
wfile=fopen(fullfile(pname,fname_res),'w+');
fprintf(wfile,'%s%s%s\n','>>> MMM 31P Mims ENDOR rotamer simulation of data set: ',handles.bas_name,' <<<');
fprintf(wfile,'%s%s%s\n\n','- ',mode,' -');
if ~isempty(handles.bas_name),
fprintf(wfile,'%s\n','### Description of data set ###');
fprintf(wfile,'%s\n%s\n','Source file:',handles.source_file);
fprintf(wfile,'\n%s\n','### Pre-processing ###');
fprintf(wfile,'%s%i\n','Background correction polynomial order: ',handles.bsl_poly);
if get(handles.checkbox_fit,'Value'),
fprintf(wfile,'%s\n','Center frequency fitted.');
elseif handles.field_known && ~handles.center_edited,
fprintf(wfile,'%s\n','Center frequency from known magnetic field.');
elseif ~handles.center_edited
fprintf(wfile,'%s\n','Original center frequency.');
else
fprintf(wfile,'%s\n','Center frequency manually edited.');
end;
end;
fprintf(wfile,'\n%s\n','### Simulation ###');
fprintf(wfile,'%s%5.0f ns\n','Interpulse delay (manual input): ',handles.tau);
fprintf(wfile,'%s%5.0f us\n','Radiofrequency pulse length (manual input): ',handles.trf);
if ~isempty(handles.rmean),
fprintf(wfile,'%s%4.1f ?\n','mean distance: ',handles.rmean);
end;
if ~isempty(handles.stddev),
fprintf(wfile,'%s%4.1f ?\n','std. deviation: ',handles.stddev);
end;
if ~isempty(handles.rmsd),
fprintf(wfile,'%s%9.6f\n','r.m.s. error of fit: ',handles.rmsd);
end;
fclose(wfile);
data=[handles.rsim',handles.dsim'];
fname_distr=[fname '_distr.dat'];
save(fullfile(pname,fname_distr),'data','-ascii');
data=[handles.frqsim',handles.spcsim'];
fname_spc=[fname '_spc.dat'];
save(fullfile(pname,fname_spc),'data','-ascii');
if ~isempty(handles.vexp),
add_msg_board('Simulation and fit to experimental data saved');
data=[handles.frq_corr',handles.vexp',handles.vsim'];
fname_fit=[fname '_fit.dat'];
save(fullfile(pname,fname_fit),'data','-ascii');
end;
cd(my_path);
guidata(hObject,handles);
% --- Executes on button press in pushbutton_close.
function pushbutton_close_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton_close (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
ENDOR_CloseRequestFcn(handles.ENDOR, eventdata, handles);
% --- Executes on selection change in listbox_label.
function listbox_label_Callback(hObject, eventdata, handles)
% hObject handle to listbox_label (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = cellstr(get(hObject,'String')) returns listbox_label contents as cell array
% contents{get(hObject,'Value')} returns selected item from listbox_label
global model
sel=get(hObject,'Value');
if isfield(model,'labels') && sel<=length(model.labels),
NOpos=model.labels(sel).NOpos;
pop=NOpos(:,4);
pop=pop/sum(pop);
x=sum(NOpos(:,1).*pop);
y=sum(NOpos(:,2).*pop);
z=sum(NOpos(:,3).*pop);
name=model.labels(sel).adr;
indices=resolve_address(name);
position=sprintf('at [%6.2f,%6.2f,%6.2f] ?',x,y,z);
handles.Scoor=[NOpos(:,1:3),pop];
else
if isfield(model,'labels'),
asel=sel-length(model.labels);
else
asel=sel;
end;
indices=handles.atoms(asel,:);
[msg0,xyz]=get_atom(indices,'xyz');
[msg0,pop]=get_atom(indices,'populations');
handles.Scoor=[xyz,pop];
pop=pop/sum(pop);
xyz=pop'*xyz;
adr=mk_address(indices);
name=adr;
position=sprintf('at [%6.2f,%6.2f,%6.2f] ?',xyz(1),xyz(2),xyz(3));
end;
set(handles.text_coor,'String',position);
set(handles.text_paramagnetic,'String',name);
old_snum=handles.structure;
handles.structure=indices(1);
if indices(1)~=old_snum,
bilayer_hole(indices(1));
end;
handles=get_phosphorous(handles);
handles.new_molecule=true;
handles.new_bilayer=true;
handles=update(handles);
guidata(hObject,handles);
% --- Executes during object creation, after setting all properties.
function listbox_label_CreateFcn(hObject, eventdata, handles)
% hObject handle to listbox_label (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: listbox controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in pushbutton_help.
function pushbutton_help_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton_help (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global help_files
entry=strcat(help_files,'ENDOR_window.html');
webcall(entry,'-helpbrowser');
% --- Executes on button press in checkbox2.
function checkbox2_Callback(hObject, eventdata, handles)
% hObject handle to checkbox2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of checkbox2
function edit4_Callback(hObject, eventdata, handles)
% hObject handle to edit4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit4 as text
% str2double(get(hObject,'String')) returns contents of edit4 as a double
% --- Executes during object creation, after setting all properties.
function edit4_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on selection change in popupmenu1.
function popupmenu1_Callback(hObject, eventdata, handles)
% hObject handle to popupmenu1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = cellstr(get(hObject,'String')) returns popupmenu1 contents as cell array
% contents{get(hObject,'Value')} returns selected item from popupmenu1
% --- Executes during object creation, after setting all properties.
function popupmenu1_CreateFcn(hObject, eventdata, handles)
% hObject handle to popupmenu1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: popupmenu controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in pushbutton8.
function pushbutton8_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton8 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
function edit_tau_Callback(hObject, eventdata, handles)
% hObject handle to edit_tau (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit_tau as text
% str2double(get(hObject,'String')) returns contents of edit_tau as a double
[v,handles]=edit_update_MMM(handles,hObject,0,20000,600,'%4.0f',0);
handles.tau=v;
handles=update(handles);
% Update handles structure
guidata(hObject, handles);
% --- Executes during object creation, after setting all properties.
function edit_tau_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit_tau (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in checkbox_fit.
function checkbox_fit_Callback(hObject, eventdata, handles)
% hObject handle to checkbox_fit (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of checkbox_fit
if ~get(hObject,'Value'),
handles.center_frq=handles.center_frq_orig;
set(handles.edit_center_frq,'String',sprintf('%5.0f',handles.center_frq));
end;
handles=update(handles);
% Update handles structure
guidata(hObject, handles);
% --- Executes on button press in pushbutton_detach_ENDOR.
function pushbutton_detach_ENDOR_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton_detach_ENDOR (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
handles.copy_ENDOR=1;
handles=update(handles);
% Update handles structure
guidata(hObject, handles);
% --- Executes on button press in pushbutton_detach.
function pushbutton_detach_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton_detach (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
handles.copy_distr=1;
handles=update(handles);
% Update handles structure
guidata(hObject, handles);
% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in pushbutton3.
function pushbutton3_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
function edit_lower_Callback(hObject, eventdata, handles)
% hObject handle to edit_lower (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit_lower as text
% str2double(get(hObject,'String')) returns contents of edit_lower as a double
if isempty(handles.rsim),
add_msg_board('Error: Range can be updated only if distribution is available.');
else
[v,handles]=edit_update_MMM(handles,hObject,min(handles.rsim),handles.range(2)-0.1,handles.range(1),'%4.1f',0);
handles.range=[v,handles.range(2)];
handles=range_update(handles);
% Update handles structure
guidata(hObject, handles);
end;
% --- Executes during object creation, after setting all properties.
function edit_lower_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit_lower (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in pushbutton_lower_left.
function pushbutton_lower_left_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton_lower_left (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
if isempty(handles.rsim),
add_msg_board('Error: Range can be updated only if distribution is available.');
elseif handles.range(1)-0.1>=min(handles.rsim)
handles.range(1)=handles.range(1)-0.1;
handles=range_update(handles);
% Update handles structure
guidata(hObject, handles);
end;
% --- Executes on button press in pushbutton_lower_right.
function pushbutton_lower_right_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton_lower_right (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
if isempty(handles.rsim),
add_msg_board('Error: Range can be updated only if distribution is available.');
elseif handles.range(1)+0.1<=handles.range(2)-0.1,
handles.range(1)=handles.range(1)+0.1;
handles=range_update(handles);
% Update handles structure
guidata(hObject, handles);
end;
function edit_upper_Callback(hObject, eventdata, handles)
% hObject handle to edit_upper (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit_upper as text
% str2double(get(hObject,'String')) returns contents of edit_upper as a double
if isempty(handles.rsim),
add_msg_board('Error: Range can be updated only if distribution is available.');
else
[v,handles]=edit_update_MMM(handles,hObject,handles.range(1)+0.1,max(handles.rsim),handles.range(2),'%4.1f',0);
handles.range=[handles.range(1),v];
handles=range_update(handles);
% Update handles structure
guidata(hObject, handles);
end;
% --- Executes during object creation, after setting all properties.
function edit_upper_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit_upper (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in pushbutton_upper_left.
function pushbutton_upper_left_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton_upper_left (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
if isempty(handles.rsim),
add_msg_board('Error: Range can be updated only if distribution is available.');
elseif handles.range(2)-0.1>=handles.range(1)+0.1
handles.range(2)=handles.range(2)-0.1;
handles=range_update(handles);
% Update handles structure
guidata(hObject, handles);
end;
% --- Executes on button press in pushbutton_upper_right.
function pushbutton_upper_right_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton_upper_right (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
if isempty(handles.rsim),
add_msg_board('Error: Range can be updated only if distribution is available.');
elseif handles.range(2)+0.1<=max(handles.rsim)
handles.range(2)=handles.range(2)+0.1;
handles=range_update(handles);
% Update handles structure
guidata(hObject, handles);
end;
function handles=range_update(handles)
if isfield(handles,'left_crsr'),
set(handles.left_crsr,'XData',[handles.range(1) handles.range(1)]);
else
axes(handles.axes_distr);
handles.left_crsr=plot([handles.range(1) handles.range(1)],[min(handles.dsim),max(handles.dsim)],'b','LineWidth',0.5);
end;
set(handles.edit_lower,'String',sprintf('%4.1f',handles.range(1)));
if isfield(handles,'right_crsr'),
set(handles.right_crsr,'XData',[handles.range(2) handles.range(2)]);
else
axes(handles.axes_distr);
handles.right_crsr=plot([handles.range(2) handles.range(2)],[min(handles.dsim),max(handles.dsim)],'m','LineWidth',0.5);
end;
set(handles.edit_upper,'String',sprintf('%4.1f',handles.range(2)));
% --- Executes on button press in togglebutton_expand.
function togglebutton_expand_Callback(hObject, eventdata, handles)
% hObject handle to togglebutton_expand (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of togglebutton_expand
state=get(hObject,'Value');
handles.expanded=state;
if state,
set(hObject,'TooltipString','Return to full view');
set(hObject,'String','Full view');
else
set(hObject,'TooltipString','Expand or shrink view to selected range');
set(hObject,'String','Expand');
end;
handles=update(handles);
% Update handles structure
guidata(hObject, handles);
function edit_center_frq_Callback(hObject, eventdata, handles)
% hObject handle to edit_center_frq (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit_center_frq as text
% str2double(get(hObject,'String')) returns contents of edit_center_frq as a double
[v,handles]=edit_update_MMM(handles,hObject,1000,100000,6000,'%5.0f',0);
handles.center_frq=v;
handles.center_frq_orig=v;
handles.center_edited=true;
handles=update(handles);
% Update handles structure
guidata(hObject, handles);
% --- Executes during object creation, after setting all properties.
function edit_center_frq_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit_center_frq (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes when user attempts to close ENDOR.
function ENDOR_CloseRequestFcn(hObject, eventdata, handles)
% hObject handle to ENDOR (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: delete(hObject) closes the figure
delete(hObject);
function [handles,success]=mk_label_list(handles)
% Fills listbox_label with the list of available labels
% returns a success flag success=1 if there are at least two labels,
% success=0 otherwise
global model
success=0;
indices=resolve_address('*');
if ~isfield(model,'labels')
labels=0;
if isempty(indices),
return
end;
end;
sites=0;
if isfield(model,'labels') && ~isempty(model.labels),
sites=length(model.labels);
labels=sites;
for k=1:length(model.labels),
label_list{k}=model.labels(k).adr;
end;
end;
% make list of selected atoms
if ~isempty(indices),
[m,n]=size(indices);
poi=0;
handles.atoms=zeros(m,5);
for ko=1:m, % loop over all objects
idepth=length(find(indices(ko,:)>0)); % determine type of current object
if idepth==5,
poi=poi+1;
cindices=indices(ko,1:idepth);
address=mk_address(cindices,true);
label_list{poi+sites}=address;
handles.atoms(poi,:)=cindices;
handles.atom_adr{poi}=address;
end;
end;
if poi>0,
handles.atoms=handles.atoms(1:poi,:);
sites=sites+poi;
else
handles.atoms=[];
end;
end;
if sites>=1,
success=1;
else
set(handles.listbox_label,'String',' ');
set(handles.listbox_label,'Value',1);
return;
end;
set(handles.listbox_label,'String',label_list);
set(handles.listbox_label,'Value',1);
if labels>0,
NOpos=model.labels(1).NOpos;
pop=NOpos(:,4);
pop=pop/sum(pop);
handles.Scoor=[NOpos(:,1:3),pop];
x=sum(NOpos(:,1).*pop);
y=sum(NOpos(:,2).*pop);
z=sum(NOpos(:,3).*pop);
name=model.labels(1).adr;
indices=resolve_address(name);
position=sprintf('at [%6.2f,%6.2f,%6.2f] ?',x,y,z);
else
indices=handles.atoms(1,:);
[msg0,xyz]=get_atom(indices,'xyz');
[msg0,pop]=get_atom(indices,'populations');
pop=pop/sum(pop);
handles.Scoor=[xyz,pop];
xyz=pop'*xyz;
adr=mk_address(indices);
name=adr;
position=sprintf('at [%6.2f,%6.2f,%6.2f] ?',xyz(1),xyz(2),xyz(3));
end;
set(handles.text_coor,'String',position);
set(handles.text_paramagnetic,'String',name);
handles.structure=indices(1);
bilayer_hole(indices(1));
handles=get_phosphorous(handles);
function handles=get_phosphorous(handles)
global model
grid=0.5;
h=gcf;
set(h,'Pointer','watch');
drawnow;
% get structural phosphorous from molecule
adr=mk_address(handles.structure);
adr=sprintf('%s(:)."P"',adr);
indices=resolve_address(adr);
[m,n]=size(indices);
Pcoor=zeros(4*m,4);
poi=0;
for k=1:m,
cindices=indices(k,:);
cindices=cindices(cindices>0);
[mess,xyz]=get_object(cindices,'xyz');
[ml,n]=size(xyz);
[mess,pop]=get_object(cindices,'populations');
Pcoor(poi+1:poi+ml,1:3)=xyz;
Pcoor(poi+1:poi+ml,4)=pop;
poi=poi+ml;
end;
handles.Pcoor=Pcoor(1:poi,:);
msg{1}=sprintf('%i phosphorous nuclei in this structure',m);
snum=handles.structure;
if ~isfield(model.info{snum},'bilayer') || isempty(model.info{snum}.bilayer),
msg{2}='No lipid bilayer present.';
handles.Pcoor_bilayer=[];
else
xax=model.info{snum}.bilayer.xax;
nxm=length(xax)-1;
xmin=min(xax);
xmax=max(xax);
dx=nxm/(xmax-xmin);
yax=model.info{snum}.bilayer.yax;
nym=length(yax)-1;
ymin=min(yax);
ymax=max(yax);
dy=nym/(ymax-ymin);
upper_layer=model.info{snum}.bilayer.upper_layer;
lower_layer=model.info{snum}.bilayer.lower_layer;
Scoor=handles.Scoor;
xyz=Scoor(:,1:3);
pop=Scoor(:,4);
center=pop'*xyz;
xax1=-25:grid:25;
yax1=-25:grid:25;
zax1=-25:grid:25;
poi=0;
Pcoor_bilayer=zeros(250000,4);
[zax,profile,A_per_lipid]=bilayer_P_profile;
totpop=sum(profile); % normalization of z profile of 31P distribution
pixel_area=grid^2; % pixel size (area of grid square)
pixel_per_lipid=pixel_area/A_per_lipid; % number of pixels in area per lipid
popscale=pixel_per_lipid/totpop; % normalization to one 31P per lipid area integrated over z
thickness=model.info{snum}.bilayer.thickness;
zax=zax*thickness/35;
nzm=length(zax)-1;
zmin=min(zax);
zmax=max(zax);
dz=nzm/(zmax-zmin);
for kx=1:length(xax1),
x=xax1(kx);
for ky=1:length(yax1),
y=yax1(ky);
if norm([x,y])<=25,
for kz=1:length(zax1),
z=zax1(kz);
if norm([x,y,z])<=25,
xyz=[x,y,z]+center;
if xyz(1)>xmin && xyz(1)<xmax && xyz(2)>ymin && xyz(2)<ymax,
poix=1+round(dx*(xyz(1)-xmin));
poiy=1+round(dy*(xyz(2)-ymin));
upop=upper_layer(poix,poiy);
lpop=lower_layer(poix,poiy);
else
upop=1;
lpop=1;
end;
if abs(xyz(3))<zmax,
poiz=1+round(dz*(abs(xyz(3))-zmin));
if xyz(3)>0,
pop=upop*profile(poiz);
else
pop=lpop*profile(poiz);
end;
else
pop=0;
end;
if pop>0.01,
poi=poi+1;
Pcoor_bilayer(poi,1:3)=xyz;
Pcoor_bilayer(poi,4)=pop*popscale;
end;
end;
end;
end;
end;
end;
handles.Pcoor_bilayer=Pcoor_bilayer(1:poi,:);
msg{2}=sprintf('%i phosphorous positions for lipid bilayer',poi);
end;
set(handles.text_phosphorous,'String',msg);
set(h,'Pointer','arrow');
function handles=update(handles)