Debian Codegraph @

artemis_parts/path.pl

raw
1 # -*- cperl -*-
2 ## This file is part of Artemis, copyright (c) 2002-2008 Bruce Ravel
3 ##
4 ## THE PATH PAGE
5
6
7 sub make_path {
8 my $parent = $_[0];
9 my $x_bitmap = '#define noname_width 13
10 #define noname_height 13
11 static char noname_bits[] = {
12 0x00,0x00,0x0c,0x1c,0x18,0x0e,0x30,0x07,0xe0,0x03,0xc0,0x01,0xe0,0x01,0x70,
13 0x03,0x38,0x06,0x1c,0x0c,0x0c,0x18,0x00,0x00,0x00,0x00};
14 ';
15 my $x_X = $top -> Bitmap('x', -data=>$x_bitmap,
16 -foreground=>$config{colors}{activehighlightcolor});
17 my @x=(-image=>$x_X);
18
19 my $c = $parent -> Frame(-relief=>'flat',
20 -borderwidth=>0,
21 #@window_size,
22 -highlightcolor=>$config{colors}{background},
23 );
24
25 my $t = ""; # used for clicky help
26 my @start = (-foreground=>$config{colors}{activehighlightcolor},
27 -font=>$config{fonts}{med});
28 my @bold = (-foreground => $config{colors}{mbutton},
29 -background => $config{colors}{activebackground},
30 -cursor => $mouse_over_cursor,
31 -font => $config{fonts}{med});
32 my @normal = (-foreground => $config{colors}{activehighlightcolor},
33 -background => $config{colors}{background},
34 -font => $config{fonts}{med});
35 ## header
36 ##$header{current} = $c -> Label(@title2, -text=>"Path Description",)
37 ## -> pack(-side=>'top', -anchor=>'w', -padx=>6);
38
39
40 #my $fr = $c -> Frame()
41 # -> pack(-side=>'top', -anchor=>'w', -fill=>'x', -padx=>6);
42 $widgets{path_label} = $c -> Label(-font => $config{fonts}{bold},
43 -foreground => $config{colors}{button},
44 -background => $config{colors}{background2},
45 -borderwidth => 2,
46 -relief => 'groove',
47 -anchor => 'w',
48 )
49 -> pack(-side=>'top', -anchor=>'w', -pady=>0, -fill=>'x');
50
51 my $fr = $c -> Frame()
52 -> pack(-side=>'top', -anchor=>'e', -fill=>'x', -padx=>6);
53 $widgets{path_include} = $fr -> Checkbutton(-text => "Include in the fit",
54 -font => $config{fonts}{med},
55 -foreground => $config{colors}{activehighlightcolor},
56 -activeforeground => $config{colors}{activehighlightcolor},
57 -selectcolor => $config{colors}{check},
58 -command => \&toggle_include,
59 )
60 -> pack(-side=>'right', -anchor=>'w');
61 $widgets{path_plotpath} = $fr -> Checkbutton(-text => "Plot after the fit",
62 -font => $config{fonts}{med},
63 -foreground => $config{colors}{activehighlightcolor},
64 -activeforeground => $config{colors}{activehighlightcolor},
65 -selectcolor => $config{colors}{check},
66 -command => \&toggle_plotpath,
67 )
68 -> pack(-side=>'left', -anchor=>'e');
69 $fr = $c -> Frame()
70 -> pack(-side=>'top', -anchor=>'e', -fill=>'x', -padx=>6);
71 $widgets{path_setpath} = $fr -> Checkbutton(-text => "Make this path the default after the fit",
72 -font => $config{fonts}{med},
73 -foreground => $config{colors}{activehighlightcolor},
74 -activeforeground => $config{colors}{activehighlightcolor},
75 -selectcolor => $config{colors}{check},
76 -command => sub{&set_path_index($current)},
77 )
78 -> pack(-side=>'left', -anchor=>'e');
79
80 $widgets{path_header_box} =
81 $c-> LabFrame(-label => '',
82 -font => $config{fonts}{med},
83 -foreground => $config{colors}{activehighlightcolor},
84 -labelside => 'acrosstop')
85 -> pack(-side=>'top', -pady=>3, -padx=>6, -fill=>'x');
86 $widgets{path_header} = $widgets{path_header_box}
87 -> ROText(-width=>49, -height=>10, relief=>'flat',
88 -wrap=>'none', -font=>$config{fonts}{fixed})
89 -> pack();
90 &disable_mouse3($widgets{path_header});
91 my ($font, $red, $grey) = ($config{fonts}{fixedit}, $config{colors}{button}, $config{colors}{disabledforeground});
92 $widgets{path_header} -> tagConfigure('absorber', -foreground=>$red);
93 $widgets{path_header} -> tagConfigure('angles', -font=>$font, -foreground=>$grey);
94 #$widgets{path_header} -> insert('end', 'This box will contain the feffNNNN.dat header');
95
96 ## Entry widgets for path parameters
97 ##my $one_page = 1; # 0=use NoteBook, 1=all on one page
98 my ($fr2, $frind);
99 ##if ($one_page) {
100 my $labframe = $c -> LabFrame(-label => 'Path parameter math expressions',
101 -font => $config{fonts}{med},
102 -foreground => $config{colors}{activehighlightcolor},
103 -labelside => 'acrosstop')
104 -> pack(-side=>'top', -pady=>3, -padx=>6, -fill=>'both', -expand=>1);
105 $fr = $labframe -> Scrolled('Pane', -relief=>'flat', -borderwidth=>2,
106 -scrollbars=>'oe', -height=>1)
107 -> pack(-expand=>1, -fill=>'both');
108 $fr->Subwidget("yscrollbar")->configure(-background=>$config{colors}{background},
109 ($is_windows) ? () : (-width=>8));
110 my $i = 0;
111 ## feff
112 foreach my $pp (qw(label S02 E0 delR sigma^2 Ei 3rd 4th dphase k_array phase_array amp_array)) {
113 my $tn;
114 if ($pp eq 'S02') { # insert degen box
115 $tn = $fr -> ROText()
116 -> grid(-column=>0, -row=>$i, -sticky=>'e');
117 $widgets{'path_me_N'} = $fr -> PathparamEntry(-width=>3, -validate=>'key',
118 -validatecommand=>[\&set_pathparam, 'N'])
119 -> grid(-column=>1, -row=>$i, -sticky=>'w');
120 $fr -> Label(@x)
121 -> grid(-column=>2, -row=>$i);
122 $t = $fr -> ROText()
123 -> grid(-column=>3, -row=>$i, -sticky=>'w');
124 $widgets{'path_me_'.$pp} = $fr -> PathparamEntry(-width=>30,
125 -validate=>'key',
126 -validatecommand=>[\&set_pathparam, $pp])
127 -> grid(-column=>4, -row=>$i, -sticky=>'ew');
128 } else {
129 $t = $fr -> ROText()
130 -> grid(-column=>0, -row=>$i, -sticky=>'e');
131 $widgets{'path_me_'.$pp} = $fr -> PathparamEntry(-validate=>'key',
132 -validatecommand=>[\&set_pathparam, $pp])
133 -> grid(-column=>1, -row=>$i, -sticky=>'ew', -columnspan=>4);
134 };
135 foreach my $tt ($tn, $t) {
136 next unless $tt;
137 $tt -> configure(-relief => 'flat',
138 -height => 1,
139 -width => ($pp eq 'S02') ? 4 : 11,
140 -highlightcolor => $config{colors}{background},
141 -selectbackground => $config{colors}{background},
142 -selectforeground => $config{colors}{activehighlightcolor},
143 -selectborderwidth => 0,
144 -foreground => $config{colors}{activehighlightcolor},
145 -font => $config{fonts}{med});
146 my @t_bindtags = $tt -> bindtags;
147 $tt -> bindtags([$t_bindtags[1]]); ## bindtags([@t_bindtags[1,0,2,3]]);
148 $tt -> tagConfigure('label', -justify=>'right');
149 $tt -> tagBind('label', "<Any-Enter>", sub {shift->configure(@bold)});
150 $tt -> tagBind('label', "<Any-Leave>", sub {shift->configure(@normal)});
151 ## button one echos a little help message unless a fit has been
152 ## run and this path parameter has been evaluated, in which case
153 ## the evaluation is echoed
154 $tt -> tagBind('label', "<Button-1>", sub {my $tt = shift->get(qw(1.0 end));
155 chomp $tt;
156 my $ttt = $click_help{$tt} || "$tt ???";
157 my $pp = substr($tt,0,-1);
158 my $p = ($pp eq 'delE0') ? 'E0' : $pp;
159 $ttt = join(" ",
160 $paths{$current}->descriptor() ,
161 "---",
162 $pp,
163 "evaluated to",
164 $paths{$current}->get("value_".lc($p)),
165 "in the last fit."
166 )
167 if ($paths{$current}->get("value_".lc($p)));
168 Echo($ttt); });
169 $t -> tagBind('label', "<Button-3>", [\&post_pathparam_menu, $pp, Ev('X'), Ev('Y')]);
170 $widgets{'path_lab_'.$pp} = $tt;
171 ## button three to raise a menu for setting other pathparams
172 };
173
174 $widgets{'path_me_'.$pp} -> bind("<Button-3>", [\&snarf_variable, $pp,
175 Ev('x'), Ev('y'),
176 Ev('X'), Ev('Y')]);
177
178
179 $tn and $tn -> insert('end', 'N:', 'label');
180 $tn and $tn -> configure(-width=>10);
181 my $ppp = $pp;
182 $ppp = "delE0" if ($pp eq 'E0');
183 $t -> insert('end', $ppp.':', 'label');
184 ++$i;
185 };
186 #$fr -> gridColumnconfigure(1, -weight=>1);
187 #$fr -> gridColumnconfigure(4, -weight=>1);
188
189 &manage_extended_params;
190 $c -> Frame()
191 -> pack(-side=>'top', -pady=>3, -padx=>6, -fill=>'both', -expand=>1);
192 $widgets{help_path} =
193 $c-> Button(-text => "Document: Paths and path parameters", @button2_list,
194 -command=>sub{pod_display("artemis_path.pod")},
195 )
196 -> pack(-side=>'top', -pady=>3, -padx=>1, -fill=>'x',);
197
198
199 return $c;
200 };
201
202
203 ## this is the call-back for the checkbutton in the paths menu for
204 ## showing the "extended path parameters". These are the odd ones,
205 ## dphase + (k|amp|phase)_array, which only the experts should be
206 ## using. This sub hides them by gridForget-ing or replaces them by
207 ## gridding them back onto the paths view.
208 sub manage_extended_params {
209 my $row = 9;
210 foreach my $p (qw(dphase k_array amp_array phase_array)) {
211 if (($config{paths}{extpp}) and (not $widgets{'path_me_'.$p} -> gridInfo)) {
212 $widgets{'path_lab_'.$p} ->
213 grid(-column=>0, -row=>$row, -sticky=>'w', -columnspan=>4);
214 $widgets{'path_me_'.$p} ->
215 grid(-column=>1, -row=>$row++, -sticky=>'ew', -columnspan=>4);
216 } elsif ((not $config{paths}{extpp}) and ($widgets{'path_me_'.$p} -> gridInfo)) {
217 $widgets{'path_lab_'.$p} -> gridForget();
218 $widgets{'path_me_'.$p} -> gridForget();
219 };
220 };
221 };
222
223
224 ## this is the callback to a mouse-3 click in the entry box for math
225 ## expressions on the path page
226 sub snarf_variable {
227 my ($t, $p, $x, $y, $xm, $ym) = @_;
228 return if (($p eq 'feff') or ($p eq 'label'));
229 #$widgets{'path_me_'.$p}
230 $t -> eventGenerate("<Button-1>", '-x'=>$x, '-y'=>$y);
231 $t -> eventGenerate("<ButtonRelease-1>", '-x'=>$x, '-y'=>$y);
232 $t -> MouseSelect($x,'word','sel.first');
233 return unless $t -> selectionPresent;
234 my $this = $t -> SelectionGet;
235 $t -> selectionClear, return if ($this =~ /[- \t\n\r\f(),+*\/]/);
236 $t -> selectionClear, return if ($this eq 'reff');
237 $t -> selectionClear, return if ($this =~ /^(\d+\.?\d*|\.\d+)$/);
238 $t -> selectionClear, return if ($this =~ /^($function_regex)$/);
239 $top ->
240 Menu(-tearoff=>0,
241 -menuitems=>[
242 ['command' => "Make \`$this\' a guess and jump",
243 -command => sub{&jump_to_variable($this, 'guess', 0)}],
244 ['command' => "Make \`$this\' a guess and stay",
245 -command => sub{&jump_to_variable($this, 'guess', 1)}],
246 "-",
247 ['command' => "Make \`$this\' a def and jump",
248 -command => sub{&jump_to_variable($this, 'def', 0)}],
249 ['command' => "Make \`$this\' a def and stay",
250 -command => sub{&jump_to_variable($this, 'def', 1)}],
251 "-",
252 ['command' => "Make \`$this\' a set and jump",
253 -command => sub{&jump_to_variable($this, 'set', 0)}],
254 ['command' => "Make \`$this\' a set and stay",
255 -command => sub{&jump_to_variable($this, 'set', 1)}],
256 "-",
257 ['command' => "Make \`$this\' a skip and jump",
258 -command => sub{&jump_to_variable($this, 'skip', 0)}],
259 ['command' => "Make \`$this\' a skip and stay",
260 -command => sub{&jump_to_variable($this, 'skip', 1)}],
261 ]
262 ) ->Post($xm,$ym);
263 $t -> break;
264 };
265
266
267 ## and this disposes of the snarfed variable
268 sub jump_to_variable {
269 my ($this, $gds, $stay, $value) = @_;
270 my $which = -1;
271 ## search for this variable ...
272 my $see = 0;
273 foreach (@gds) {
274 ++$see;
275 $which = $_, last if ($_->name =~ /^$this$/i);
276 };
277 ## or for the end of the list
278 if ($which == -1) {
279 push @gds, Ifeffit::Parameter->new(type=>$gds,
280 name=>$this,
281 mathexp=>'0',
282 bestfit=>0,
283 modified=>1,
284 note=>"$this: ",
285 autonote=>1,
286 );
287 $see = $#gds;
288 $which = $gds[$see];
289 ++$see;
290 };
291 $which->make(type=>$gds,
292 modified=>1);
293 Echo("Made \"$this\" a $gds parameter");
294 if (defined $value) {
295 $which->make(mathexp=>$value);
296 } elsif ($stay) {
297 $which->make(mathexp=>'0');
298 };
299 $which->make(note=>$which->name.": ") if ($which->note =~ /^\s*$/);
300 repopulate_gds2();
301 gds2_display($see);
302 return if $stay;
303 &display_page("gsd");
304 project_state(0);
305 $parameters_changed = 1;
306 };
307
308
309 ## This sub posts the menu of path parameter operations when the path
310 ## parameter label is mouse-3 clicked.
311 sub post_pathparam_menu {
312 my ($t, $p, $X, $Y) = @_;
313 #$p = $t->get(qw(1.0 end));
314 #$p = substr($p, 0, index($p, ':'));
315 my $pp = uc $p;
316 if (@_ < 3) {
317 my $e = $t->XEvent;
318 ($X, $Y) = ($e->X, $e->Y);
319 };
320
321 my $d = $paths{$current}->data;
322 my $f = $paths{$current}->get('parent');
323 my @all = &all_data;
324 my $ndata = $#all;
325 @all = &all_feff;
326 my $nfeff = $#all;
327 @all = grep /^$d\.feff\d+$/, (keys %paths);
328 my $this_nfeff = $#all;
329
330
331 my $pathparam_menu = $top ->
332 Menu(-tearoff=>0,
333 -menuitems=>[#(($p eq 'feff') ?
334 # (['command' => "Read a feffNNNN.dat file",
335 # -command => [\&Echo, "Read a feffNNNN.dat file"]],"-" ) : ()),
336 ['command' => "Edit $pp for many paths",
337 -command => [\&add_mathexp, $p]],
338 ['command' => "Clear $pp for this path",
339 -command => sub{$paths{$current}->get($p) = "";
340 $widgets{'path_me_'.$p} -> delete(qw(0 end));
341 project_state(0);}],
342 "-",
343 ['command' =>
344 "Export this $pp to every path in THIS feff calculation",
345 -command =>
346 [\&add_to_paths, $pp, $widgets{'path_me_'.$p}->get(), 'this']],
347 ['command' =>
348 "Export this $pp to every path in EACH feff with THIS data set",
349 -state => ($this_nfeff) ? 'normal' : 'disabled',
350 -command =>
351 [\&add_to_paths, $pp, $widgets{'path_me_'.$p}->get(), 'data']],
352 ['command' =>
353 "Export this $pp to every path in EACH feff calculation",
354 -state => ($nfeff) ? 'normal' : 'disabled',
355 -command =>
356 [\&add_to_paths, $pp, $widgets{'path_me_'.$p}->get(), 'each']],
357 ['command' =>
358 "Export this $pp to SELECTED paths",
359 -command =>
360 [\&add_to_paths, $pp, $widgets{'path_me_'.$p}->get(), 'sel']],
361 "-",
362 ['command' => "Grab $pp from the previous path",
363 -command => [\&grab_from_path, $p, 'prev']],
364 ['command' => "Grab $pp from the next path",
365 -command => [\&grab_from_path, $p, 'next']],
366 (($p eq 'sigma^2') ?
367 ("-",
368 ['command' => "Insert Einstein function",
369 -command => sub{sigsqr_model('eins') }],
370 ['command' => "Insert Debye function",
371 -command => sub{sigsqr_model('debye')}],
372 ) : ())
373 ] );
374 $pathparam_menu->Post($X,$Y);
375 $t -> break;
376 };
377
378
379 sub populate_path {
380 my $this = $_[0];
381 my $parent = $paths{$this}->get('parent');
382 $widgets{path_header} -> delete(qw(1.0 end));
383 my $i = 0;
384 foreach my $l (split(/\n/, $paths{$this}->get('header'))) {
385 ## the look-ahead assertion is required because it is easy to mix
386 ## up the letter O and the number 0 in a feff potentials list
387 if ($l =~ / 0 +(?=\w)/) {
388 $widgets{path_header} -> insert('end', $l, 'absorber');
389 } elsif ($l =~ /beta/) {
390 $widgets{path_header} -> insert('end', $l, 'angles');
391 } else {
392 $widgets{path_header} -> insert('end', $l);
393 };
394 $widgets{path_header} -> insert('end', "\n");
395 ++$i;
396 };
397 $widgets{path_header} -> configure(-height=>$i);
398 my $label = $paths{$this}->get('intrpline');
399 $widgets{path_header_box} -> configure(-label=>substr($label, index($label, ':')+1));
400
401 $widgets{path_include} -> deselect();
402 $widgets{path_include} -> select() if ($paths{$this}->get('include'));
403 ##my $thislab = $paths{$this}->get('lab');
404 ##($thislab = substr($thislab, 0, 15) . " ... ") if (length($thislab) > 16);
405 ##$widgets{path_include} -> configure(-text=>"Include \`$thislab\' in the fit");
406
407 $widgets{path_setpath} -> deselect();
408 $widgets{path_setpath} -> select() if ($paths{$this}->get('setpath'));
409
410 $widgets{path_plotpath} -> deselect();
411 $widgets{path_plotpath} -> select() if ($paths{$this}->get('plotpath'));
412
413 $widgets{path_label} -> configure(-text=>" ".$paths{$this}->descriptor());
414
415 ##feff
416 foreach (qw(label N S02 E0 delR sigma^2 Ei 3rd 4th dphase k_array phase_array amp_array)) {
417 my $key = "path_me_".$_;
418 $widgets{$key} -> configure(-validate=>'none');
419 $widgets{$key} -> delete(qw(0 end));
420 $widgets{$key} -> insert(0, ($_ eq 'N') ?
421 $paths{$this}->get('deg') :
422 $paths{$this}->get(lc($_)));
423 $widgets{$key} -> configure(-validate=>'key');
424 };
425 };
426
427
428 sub set_pathparam {
429 my ($k, $entry, $prop) = (shift, shift, shift);
430 # print "$current $k $entry\n";
431 (lc($k) eq 'n') and ($entry !~ /^(|\d+\.?\d*|\.\d+)$/) and return 0;
432 $paths{$current} -> make(lc($k)=>$entry);
433 (lc($k) eq 'feff') and $paths{$current} -> make(file=>$entry);
434 (lc($k) eq 'n') and $paths{$current} -> make(deg =>$entry);
435 unless (($entry eq 'label') or ($entry eq 'header')) {
436 $paths{$current} -> make(do_k=>1);
437 };
438 project_state(0);
439 return 1;
440 ## need to flag that fit needs to be redone and that project needs
441 ## to be saved
442 };
443
444
445 sub add_a_path {
446 my $data = $paths{$current}->data;
447 ##local $Tk::FBox::a;
448 ##local $Tk::FBox::b;
449 my $path = $current_data_dir || cwd;
450 my $types = [['feffNNNN.dat files', 'feff*.dat'],
451 ['All Files', '*'],];
452 my $file = $_[0];
453 my $noanchor = $_[1];
454 my $force_new = $_[2];
455 ($file and (-e $file)) or
456 ($file = $top -> getOpenFile(-filetypes=>$types,
457 ##(not $is_windows) ?
458 ## (-sortcmd=>sub{$Tk::FBox::a cmp $Tk::FBox::b}) : () ,
459 -initialdir=>$path,
460 -title => "Artemis: Open a feffNNNN.dat file"));
461 return unless ($file);
462 Error("\"$file\" is not a feffNNNN.dat file"), return unless Ifeffit::Files->is_feffnnnn($file);
463 my ($name, $feff_path, $suffix) = fileparse($file);
464 ($current_data_dir = $feff_path) unless sub_directory($feff_path, $project_folder);
465
466 my $id = '';
467 ## need to figure out if this path is from a calculation that has
468 ## already been used with this data set
469 foreach my $k (keys %paths) {
470 next unless (ref($paths{$k}) =~ /Ifeffit/);
471 next unless ($paths{$k}->type eq 'feff');
472 next unless same_directory($paths{$k}->get('path'), $feff_path);
473 next unless ($paths{$k}->data eq $data);
474 $id = $paths{$k}->get('id');
475 last;
476 };
477
478 if ($force_new or (not $id)) {
479 $id = $data . '.feff' . $n_feff;
480
481 ## ## import this feff calc into the project by copying all files
482 ## ## &initialize_project(0);
483 ## my $project_feff_dir = &initialize_feff($id);
484 ## ## copy all these feff files to the project feff folder
485 ## opendir F, $feff_path;
486 ## my @list = grep { (-f File::Spec->catfile($feff_path,$_)) and
487 ## (lc($_) =~ /\.(bin|dat|inp|log|run)$/) } readdir F;
488 ## closedir F;
489 ## map { copy(File::Spec->catfile($feff_path,$_), $project_feff_dir) } @list;
490 ## ## make sure that the feff.inp file is "feff.inp"
491 ## copy($file, File::Spec->catfile($project_feff_dir, 'feff.inp'));
492
493 ## instantiate and list a new feff object
494 $paths{$id} = Ifeffit::Path -> new(id => $id,
495 lab => 'FEFF'.$n_feff,
496 type => 'feff',
497 path => $feff_path,
498 data => $data,
499 family => \%paths);
500 $paths{$id}->make(mode=>2) if (-e $paths{$id}->get('feff.inp'));
501 my @autoparams;
502 $#autoparams = 6;
503 (@autoparams = autoparams_define($id, $n_feff, 0, 0)) if $config{autoparams}{do_autoparams};
504 $paths{$id} -> make(autoparams=>[@autoparams]);
505 $list -> add($id, -text=>'FEFF'.$n_feff, -style=>$list_styles{noplot});
506 $list -> setmode($id, 'close');
507 $list -> setmode($data, 'close') if ($list->getmode($data) eq 'none');
508 my $intrp_ok = &do_intrp($id);
509 $paths{$id} -> make(mode=>$paths{$id}->get('mode')+4) if $intrp_ok;
510 ++$n_feff;
511 };
512
513 my $descr = $paths{$id}->descriptor();
514 Echo("Adding $descr ...");
515 #my $kid = $list -> addchild($id); #, -after=>$current);
516 my $kid = fetch_nnnn($id, $feff_path, $name);
517 $list -> entryconfigure($kid,
518 -style => $list_styles{$paths{$kid}->pathstate("enabled")},
519 -text => $paths{$kid}->get('lab'));
520 display_page($kid) unless $noanchor;
521 Echo("Adding $descr ... done!");
522 return $kid;
523 };
524
525
526
527 sub rename_path {
528 Error("This isn't a path."), return unless ($paths{$current}->type eq 'path');
529 my $this = $paths{$current}->get('lab');
530 my $newname = $this;
531 my $label = "New name for path \"".$paths{$paths{$current}->get('parent')}->get('lab').": $this\": ";
532 my $dialog = get_string($dmode, $label, \$newname, \@rename_buffer);
533 $dialog -> waitWindow; # the get_string dialog will be
534 # destroyed once the user hits ok,
535 # then we can move on...
536 Echo("Not renaming ". $this), return if ($this eq $newname);
537 $newname =~ s{[\"\']}{}g;
538 push @rename_buffer, $newname;
539 project_state(0);
540 $paths{$current} -> make(lab=>$newname);
541 $list -> itemConfigure($current, 0, -text=>$newname);
542 $widgets{path_label} -> configure(-text=>" ".$paths{$current}->descriptor());
543 };
544
545
546 sub clone_this_path {
547 my $old = $paths{$current}->get('lab');
548 my $parent = $paths{$current}->get('parent');
549 my $this = $list -> addchild($parent, -after=>$current);
550 $paths{$this} = Ifeffit::Path -> new(id => $this,
551 type => 'path',
552 family => \%paths,
553 plotpath => 0);
554 foreach my $k (keys %{$paths{$current}}) {
555 next if ($k =~ /(id|type|group|file)/);
556 $paths{$this}->make($k=>$paths{$current}->get($k));
557 };
558
559 my $lab = $paths{$this}->pathlabel($old);
560 #$paths{$this}->make(lab=>$lab);
561
562 ## halve the degeneracy of the current and the clone
563 $paths{$this}->make(deg=>$paths{$current}->get('deg')/2);
564 $paths{$current}->make(deg=>$paths{$this}->get('deg'));
565
566 $list -> entryconfigure($this,
567 -style => $list_styles{$paths{$this}->pathstate("enabled")},
568 -text => $lab);
569 $paths{$this} -> pathgroup(\%paths);
570 display_page($this);
571 Echo("Cloned $old and called it \"$lab\"");
572 };
573
574
575
576
577 sub toggle_include {
578 $paths{$current}->make(include=> not $paths{$current}->get('include'));
579 project_state(0);
580 my $this = $paths{$current}->data;
581 return unless $paths{$this}->{include};
582 my $style = $list_styles{$paths{$current}->pathstate};
583 $list -> entryconfigure($current, -style => $style);
584 $paths{$current}->get('include') ?
585 Echo("Include " . $paths{$current}->descriptor() . " in the fit.") :
586 Echo("Exclude " . $paths{$current}->descriptor() . " from the fit.");
587 };
588
589 sub toggle_plotpath {
590 $paths{$current}->make(plotpath=> not $paths{$current}->get('plotpath'));
591 project_state(0);
592 };
593 sub set_plotpath {
594 my ($which, $val) = @_;
595 $paths{$which}->make(plotpath=>$val);
596 project_state(0);
597 };
598
599
600 sub set_path_index {
601 my $which = $_[0];
602 foreach my $k (keys %paths) {
603 next unless (ref($paths{$k}) =~ /Ifeffit/);
604 next unless ($paths{$k}->type eq "path");
605 $paths{$k}->make(setpath => 0);
606 };
607 $paths{$which}->make(setpath => 1);
608 Echo($paths{$which}->descriptor() . " marked as Ifeffit's current path");
609 };
610
611 ## return the one marked as the default or the first included path if
612 ## the default is not included
613 sub which_set_path {
614 foreach my $k (keys %paths) {
615 next unless (ref($paths{$k}) =~ /Ifeffit/);
616 next unless ($paths{$k}->type eq "path");
617 return $k if (($paths{$k}->get('setpath')) and $paths{$k}->get('include'));
618 };
619 foreach my $k (sort (keys %paths)) {
620 next unless (ref($paths{$k}) =~ /Ifeffit/);
621 next unless ($paths{$k}->type eq "path");
622 return $k if $paths{$k}->get('include');
623 };
624 };
625
626
627 ###===================================================================
628 ### math expression utilities
629 ###===================================================================
630
631 sub add_mathexp {
632 my $which = $_[0];
633 my $red = $config{colors}{check};
634 my $calcs = 'this';
635 my $ren = $top -> Toplevel(-title=>'Artemis: read math expression', -class=>'horae');
636 $ren -> protocol(WM_DELETE_WINDOW => sub{$ren->destroy;});
637 #$ren -> iconbitmap('@'.$iconbitmap);
638 $ren -> iconimage($iconimage);
639 $ren -> Label(-text=>"Math expression for $which",
640 -foreground=>$config{colors}{activehighlightcolor})
641 -> pack(-side=>'top');
642 my $entry = $ren -> Entry(-justify=>'left',-width=>50)
643 -> pack(-side=>'top', -expand=>1, -fill=>'x', -padx=>10);
644 $entry -> insert('end', $widgets{'path_me_'.$which}->get) if ($paths{$current}->type eq 'path');
645 $entry -> selectionRange(qw(0 end));
646 $entry -> bind("<KeyPress-Return>",
647 sub{&add_to_paths($which, $entry->get(), $calcs); $ren->destroy;});
648
649 # buttons at the bottom
650 my @props = (-selectcolor=>$red,
651 -foreground=>$config{colors}{activehighlightcolor});
652 my $fr = $ren -> Frame(-relief=>'flat')
653 -> pack(-side=>'bottom', -expand=>1, -fill=>'x');
654 $fr -> Button(-text=>'Document: edit math expression', @button2_list,
655 -command=>sub{pod_display("artemis_editme.pod")})
656 -> pack(-side=>'right', -expand=>1, -fill=>'x');
657 $fr = $ren -> Frame(-relief=>'flat')
658 -> pack(-side=>'bottom', -expand=>1, -fill=>'x');
659 $fr -> Button(-text=>'OK', @button2_list,
660 -command=>sub{&add_to_paths($which, $entry->get(), $calcs); $ren->destroy;})
661 -> pack(-side=>'left', -expand=>1, -fill=>'x');
662 $fr -> Button(-text=>'Cancel', @button2_list,
663 -command=>sub{$ren->destroy;})
664 -> pack(-side=>'right', -expand=>1, -fill=>'x');
665 ## this radio above the buttons
666 $fr = $ren -> Frame(-relief=>'flat')
667 -> pack(-side=>'bottom', -expand=>1, -fill=>'x');
668 my $data = $fr -> Radiobutton(-text=>'Add to EACH feff in THIS data set', @props,
669 -activeforeground=>$config{colors}{activehighlightcolor},
670 -value=>'data', -variable=>\$calcs)
671 -> pack(-side=>'left');
672 my $sel = $fr -> Radiobutton(-text=>'Add to all selected paths', @props,
673 -activeforeground=>$config{colors}{activehighlightcolor},
674 -value=>'sel', -variable=>\$calcs)
675 -> pack(-side=>'right');
676 ## and these radios underneath entry box
677 $fr = $ren -> Frame(-relief=>'flat')
678 -> pack(-side=>'bottom', -expand=>1, -fill=>'x');
679 my $this = $fr -> Radiobutton(-text=>'Add to THIS feff calculation only', @props,
680 -activeforeground=>$config{colors}{activehighlightcolor},
681 -value=>'this', -variable=>\$calcs)
682 -> pack(-side=>'left');
683 my $each = $fr -> Radiobutton(-text=>'Add to EACH feff calculation', @props,
684 -activeforeground=>$config{colors}{activehighlightcolor},
685 -value=>'each', -variable=>\$calcs)
686 -> pack(-side=>'right');
687
688 ## disable the radiobuttons as appropriate
689 my $d = $paths{$current}->data;
690 my $f = $paths{$current}->get('parent');
691 my @all = &all_data;
692 ($#all) or ($data -> configure(-state=>'disabled'));
693 @all = &all_feff;
694 ($#all) or ($each -> configure(-state=>'disabled'));
695 @all = grep /^$d\.feff\d+$/, (keys %paths);
696 ($#all) or ($data -> configure(-state=>'disabled'));
697
698 $entry -> focus;
699 my $str = sprintf("+%d+%d", 0.35*$top->screenwidth(), 0.4*$top->screenheight());
700 $ren -> geometry($str);
701 $ren -> raise;
702 $ren -> grab;
703 };
704
705 ## this data each sel
706 sub add_to_paths {
707 my ($which, $mathexp, $calcs) = @_;
708 my ($dt, $f, $curr) = split(/\./,$current);
709 my $data = $paths{$current}->data;
710 my $feff = $paths{$current}->feff; #get('parent');
711 my $message = "";
712 if ($mathexp eq '^^clear^^') {
713 $mathexp = "";
714 $message = "Cleared \`$which\' for all paths.";
715 };
716 foreach my $p (keys %paths) {
717 next unless (ref($paths{$p}) =~ /Ifeffit/);
718 next unless ($paths{$p}->type eq "path");
719 my %tokens = (i => $paths{$p}->get('feff_index'),
720 I => sprintf("%4.4d", $paths{$p}->get('feff_index')),
721 r => $paths{$p}->get('reff'),
722 d => $paths{$p}->get('deg'),
723 D => "debye(temp, thetad)",
724 E => "eins(temp, thetae)",
725 );
726 (my $mesub = $mathexp) =~ s/\%([iIrdDE])/$tokens{$1}/g;
727 SWITCH: {
728 ($calcs eq 'this') and do { # this feff calculation
729 last SWITCH unless ($paths{$p}->get('parent') eq $feff); # this or each?
730 $paths{$p} -> make($which, $mesub);
731 $message = "Set \`$which\' to \`$mathexp\' in all paths in this feff calculation.";
732 last SWITCH;
733 };
734 ($calcs eq 'data') and do { # all feff calcs with this data set
735 last SWITCH unless ($paths{$p}->data eq $data);
736 $paths{$p} -> make($which, $mesub);
737 $message = "Set \`$which\' to \`$mathexp\' in all paths for this data set.";
738 last SWITCH;
739 };
740 ($calcs eq 'each') and do { # all feff calcs used
741 $paths{$p} -> make($which, $mesub);
742 $message = "Set \`$which\' to \`$mathexp\' in all paths in each feff calculation.";
743 last SWITCH;
744 };
745 ($calcs eq 'sel') and do { # selected paths
746 last SWITCH unless grep {$p eq $_} $list->info('selection');
747 $paths{$p} -> make($which, $mesub);
748 $message = "Set \`$which\' to \`$mathexp\' in the selected paths.";
749 last SWITCH;
750 };
751 };
752 };
753 display_properties;
754 project_state(0);
755 Echo($message);
756 };
757
758 ## copy all path parameters from current to others
759 sub copy_pps {
760 my $how = $_[0];
761 my $data = $paths{$current}->data;
762 my $feff = $paths{$current}->feff;
763
764 foreach my $p (keys %paths) {
765 next unless (ref($paths{$p}) =~ /Ifeffit/);
766 next unless ($paths{$p}->type eq "path");
767
768 next if (($how eq 'this') and ($paths{$p}->feff ne $feff));
769 next if (($how eq 'data') and ($paths{$p}->data ne $data));
770 next if (($how eq 'sel') and not (grep {$p eq $_} $list->info('selection')));
771
772 foreach (qw(label S02 E0 delR sigma^2 Ei 3rd 4th dphase k_array phase_array amp_array)) {
773 my $exp = $widgets{'path_me_'.$_}->get();
774 $paths{$p} -> make($_, $exp);
775 };
776
777 };
778 my $which = "paths in this Feff calculation";
779 ($which = "paths for this data set") if ($how eq 'data');
780 ($which = "all paths") if ($how eq 'each');
781 ($which = "selected paths") if ($how eq 'sel');
782 Echo("Set all parameters for $which to the values of the current path");
783 };
784
785
786 sub grab_from_path {
787 my ($p, $which) = @_;
788 my $from = $list->info($which, $current);
789 ## exception handling
790 Echo("This is the last path"), return if (not $from and ($which eq 'next'));
791 Echo("This is the last path in this feff calculation"), return
792 if (($from =~ /^feff\d+$/) and ($which eq 'next'));
793 Echo("This is the first path in this feff calculation"), return
794 if (($from =~ /^feff\d+$/) and ($which eq 'previous'));
795 ## insert the value
796 my $value = $paths{$from} -> get(lc($p));
797 ($which eq 'prev') and ($which = 'previous');
798 Echo("The $which value of $p is blank"), return unless (defined $value);
799 Echo("The $which value of $p is blank"), return if ($value =~ /^\s*$/);
800 $paths{$current} -> make($p => $value);
801 $widgets{'path_me_'.$p} -> delete(0, 'end');
802 $widgets{'path_me_'.$p} -> insert('end', $value);
803 $widgets{'path_me_'.$p} -> icursor('end');
804 $widgets{'path_me_'.$p} -> focus();
805 project_state(0);
806 my $pp = uc $p;
807 Echo("Grabbed \`$value\' for $pp from the $which path");
808 };
809
810
811 sub select_paths {
812 my ($how, $crit, $nodisplay) = @_;
813 my ($data, $feff, $curr) = split(/\./,$current);
814 $feff = ($current =~ /(feff\d+)/) ? $1 : "";
815 my $parent;
816 my $this = $current;
817
818 ## get the list of paths that follow the current one in the list,
819 ## but which are still of the same feff calculation. this is done
820 ## for the sake of "exclude after current". This way cloned
821 ## paths, which have a higher X as in dataN.feffM.X are considered
822 ## in their place in the list
823 my @following = ();
824 if ($paths{$current}->type eq 'path') {
825 my $pth = $current;
826 while ($list->infoNext($pth)) {
827 $pth = $list->infoNext($pth);
828 push(@following, $pth)
829 if (($paths{$pth}->type eq 'path') and
830 ($paths{$pth}->get('parent') eq $paths{$current}->get('parent')));
831 };
832 };
833
834 $parent = $paths{$current}->feff;
835 return unless $parent;
836
837 my $message;
838 if (($how eq 'nlegs') and (not $crit)) {
839 $crit = &get_nlegs;
840 Echo("Canceling path selection"), return if ($crit eq 'Cancel');
841 Echo("Selecting all paths of $crit legs and fewer");
842 } elsif (($how eq 'r') and (not $crit)) {
843 $crit = &get_r;
844 Echo("Canceling path selection"), return if ($crit eq 'Cancel');
845 Echo("Selecting all paths of distance $crit and shorter");
846 } elsif (($how eq 'amp') and (not $crit)) {
847 $crit = &get_zcwif;
848 Echo("Canceling path selection"), return if ($crit eq 'Cancel');
849 Echo("Selecting all paths of amplitude $crit and higher");
850 };
851
852 ## check the data this path is associated with to see if it is
853 ## included in the fit
854
855 if ($how eq 'toggle') {
856 my $data = $paths{$crit}->data;
857 $paths{$crit}->make(include => not $paths{$crit}->get('include'));
858 if ($paths{$data}->get('include')) {
859 $list -> entryconfigure($paths{$crit}->get('id'),
860 -style=>$list_styles{$paths{$crit}->pathstate});
861 };
862 my $onoff = ($paths{$crit}->get('include')) ? 'on' : 'off';
863 $message = "Toggled $onoff \"" . $paths{$crit}->descriptor() .
864 "\" for fitting.";
865 } elsif ($how eq 'on') {
866 my $data = $paths{$crit}->data;
867 $paths{$crit}->make(include => 1);
868 if ($paths{$data}->get('include')) {
869 $list -> entryconfigure($paths{$crit}->get('id'),
870 -style=>$list_styles{$paths{$crit}->pathstate("enabled")});
871 };
872 $message = "Toggled on \"" . $paths{$crit}->descriptor() . "\" for fitting.";
873 } elsif ($how eq 'off') {
874 my $data = $paths{$crit}->data;
875 $paths{$crit}->make(include => 0);
876 if ($paths{$data}->get('include')) {
877 $list -> entryconfigure($paths{$crit}->get('id'),
878 -style=>$list_styles{$paths{$crit}->pathstate("disabled")});
879 };
880 $message = "Toggled off \"" . $paths{$crit}->descriptor() . "\" for fitting.";
881 } else {
882 foreach my $p (keys %paths) {
883 next unless (ref($paths{$p}) =~ /Ifeffit/);
884 next unless ($paths{$p}->type eq 'path');
885 SWITCH: {
886 ($how =~ /^all/) and do {
887 last SWITCH if (($how =~ /this/) and ($p !~ /$parent/));
888 $paths{$p} -> make(include=>1);
889 my $data = $paths{$p}->data;
890 if ($paths{$data}->get('include')) {
891 $list -> entryconfigure($paths{$p}->get('id'),
892 -style => $list_styles{$paths{$p}->pathstate("enabled")});
893 };
894 $message = "Included all paths for fitting.";
895 last SWITCH;
896 };
897 ($how =~ /^none/) and do {
898 last SWITCH if (($how =~ /this/) and ($p !~ /$parent/));
899 $paths{$p} -> make(include=>0);
900 $list -> entryconfigure($paths{$p}->get('id'),
901 -style => $list_styles{$paths{$p}->pathstate("disabled")});
902 $message = "Excluded all paths from fitting.";
903 last SWITCH;
904 };
905 ($how =~ /^invert/) and do {
906 last SWITCH if (($how =~ /this/) and ($p !~ /$parent/));
907 $paths{$p} -> make(include=>($paths{$p}->get('include')) ? 0 : 1);
908 my $data = $paths{$p}->data;
909 if ($paths{$data}->get('include')) {
910 $list -> entryconfigure($paths{$p}->get('id'),
911 -style=>$list_styles{$paths{$p}->pathstate});
912 };
913 $message = "Inverted the included paths.";
914 last SWITCH;
915 };
916 ($how eq 'current') and do {
917 last SWITCH if ($paths{$p}->get('parent') ne $parent);
918 $paths{$p} -> make(include=>(grep /^$p$/, @following) ? 0 : 1);
919 my $data = $paths{$p}->data;
920 if ($paths{$data}->get('include')) {
921 $list -> entryconfigure($paths{$p}->get('id'),
922 -style=>$list_styles{$paths{$p}->pathstate});
923 };
924 $message = "Excluded all paths after \"" .
925 $paths{$current}->descriptor() . "\" from fitting.";
926 last SWITCH;
927 };
928 ($how eq 'nlegs') and do {
929 last SWITCH if ($paths{$p}->get('parent') ne $parent);
930 $paths{$p} -> make(include=>($paths{$p}->get('nleg') > $crit) ? 0 : 1);
931 my $data = $paths{$p}->data;
932 if ($paths{$data}->get('include')) {
933 $list -> entryconfigure($paths{$p}->get('id'),
934 -style=>$list_styles{$paths{$p}->pathstate});
935 };
936 $message = "Excluded all paths with more than $crit legs from fitting.";
937 last SWITCH;
938 };
939 ($how eq 'r') and do {
940 last SWITCH if ($paths{$p}->get('parent') ne $parent);
941 $paths{$p} -> make(include=>($paths{$p}->get('reff')>$crit) ? 0 : 1);
942 my $data = $paths{$p}->data;
943 if ($paths{$data}->get('include')) {
944 $list -> entryconfigure($paths{$p}->get('id'),
945 -style=>$list_styles{$paths{$p}->pathstate});
946 };
947 $message = "Excluded all paths longer than $crit from fitting.";
948 last SWITCH;
949 };
950 ($how eq 'amp') and do {
951 last SWITCH if ($paths{$p}->get('parent') ne $parent);
952 $paths{$p} -> make(include=>($paths{$p}->get('zcwif')<$crit) ? 0 : 1);
953 my $data = $paths{$p}->data;
954 if ($paths{$data}->get('include')) {
955 $list -> entryconfigure($paths{$p}->get('id'),
956 -style=>$list_styles{$paths{$p}->pathstate});
957 };
958 $message = "Excluded all paths with amplitude smaller than $crit from fitting.";
959 last SWITCH;
960 };
961 ($how eq 'selon') and do {
962 my $selected = grep {$p eq $_} $list->info('selection');
963 last SWITCH unless ($selected);
964 $paths{$p} -> make(include=>1);
965 my $data = $paths{$p}->data;
966 if ($paths{$data}->get('include')) {
967 $list -> entryconfigure($paths{$p}->get('id'),
968 -style=>$list_styles{$paths{$p}->pathstate("enabled")});
969 };
970 $message = "Included selected paths for fitting.";
971 last SWITCH;
972 };
973 ($how eq 'seloff') and do {
974 my $selected = grep {$p eq $_} $list->info('selection');
975 last SWITCH unless ($selected);
976 $paths{$p} -> make(include=>0);
977 $list -> entryconfigure($paths{$p}->get('id'),
978 -style=>$list_styles{$paths{$p}->pathstate("disabled")});
979 $message = "Excluded selected paths from fitting.";
980 last SWITCH;
981 };
982 }; # end of SWITCH
983 }; # end of loop over paths
984 }; # end of if/else
985 display_properties unless $nodisplay;
986 project_state(0);
987 Echo($message);
988 };
989
990
991 sub plot_path {
992 my $these = $_[0];
993 my $space = $_[1];
994 my $data = $paths{$these->[0]}->data;
995 $list->selectionClear;
996 $list->selectionSet($data);
997 foreach my $p (@$these) {
998 $list->selectionSet($p);
999 };
1000 &plot($space, 0);
1001 };
1002
1003 sub set_degeneracy {
1004 my $how = $_[0];
1005 my $this = ($paths{$current}->type eq 'feff') ? $current : $paths{$current}->get('parent');
1006 SWITCH: {
1007 ($how eq '1') and do {
1008 foreach my $p (keys %paths) {
1009 next unless (ref($paths{$p}) =~ /Ifeffit/);
1010 next unless ($paths{$p}->type eq 'path');
1011 next unless ($paths{$p}->get('parent') eq $this);
1012 $paths{$p} -> make(deg=>1);
1013 };
1014 Echo('All degeneracies were set to 1 for "' . $paths{$this}->descriptor . '"');
1015 last SWITCH;
1016 };
1017 ($how eq 'feff') and do {
1018 my $pathto = $paths{$this}->get('path');
1019 Echo("You need to reset the path to FEFF"), return unless (-d $pathto);
1020 $top -> Busy;
1021 foreach my $p (keys %paths) {
1022 next unless (ref($paths{$p}) =~ /Ifeffit/);
1023 next unless ($paths{$p}->type eq 'path');
1024 next unless ($paths{$p}->get('parent') eq $this);
1025 my $file = File::Spec->catfile($pathto, $paths{$p}->get('feff'));
1026 next unless (-e $file);
1027 my $degen;
1028 open F, $file or die "could not open feffNNNN.dat file $file for reading\n";
1029 while (<F>) {
1030 next unless (/nleg, deg, reff/);
1031 $degen = (split(" ", $_))[1];
1032 last;
1033 };
1034 close F;
1035 $paths{$p} -> make(deg=>int($degen));
1036 };
1037 $top -> Unbusy;
1038 Echo('All degeneracies were reset to their values from FEFF');
1039 last SWITCH;
1040 };
1041 };
1042 display_properties;
1043 project_state(0);
1044 };
1045
1046
1047 sub sigsqr_model {
1048 my $name = ($_[0] eq 'eins') ? "Einstein" : "Debye";
1049 my $which = ($_[0] eq 'eins') ? "bond" : "material";
1050
1051 ## use the autoparameter suffix for this feff calc
1052 my $parent = $paths{$current}->get('parent');
1053 my $suffix = "";
1054 ($suffix = $1) if ($paths{$parent}->{autoparams}->[0] =~ /(_.+)/);
1055 my $theta = ($_[0] eq 'eins') ? "thetae" : "thetad";
1056 my $value = $_[0] . "(temp$suffix, $theta$suffix)";
1057
1058 ## define the guess and set parameters if needed
1059 my $found = 0;
1060 map { ++$found if (lc($_->name) eq "temp$suffix") } (@gds);
1061 unless ($found) {
1062 push @gds, Ifeffit::Parameter->new(type=>"set",
1063 name=>"temp$suffix",
1064 mathexp=>"300",
1065 bestfit=>"300",
1066 modified=>1,
1067 note=>"The temperature of the measurement",
1068 autonote=>0,
1069 );
1070 my $row = $#gds+1;
1071 $widgets{gds2list} -> add($row);
1072 $widgets{gds2list} -> itemCreate($row, 0, -text=>$row, -style=>$gds_styles{set});
1073 $widgets{gds2list} -> itemCreate($row, 1, -text=>"s:", -style=>$gds_styles{set});
1074 $widgets{gds2list} -> itemCreate($row, 2, -text=>"temp$suffix", -style=>$gds_styles{set});
1075 $widgets{gds2list} -> itemCreate($row, 3, -text=>"300", -style=>$gds_styles{set});
1076 };
1077 $found = 0;
1078 map { ++$found if (lc($_->name) eq "$theta$suffix") } (@gds);
1079 unless ($found) {
1080 push @gds, Ifeffit::Parameter->new(type=>"guess",
1081 name=>"$theta$suffix",
1082 mathexp=>"350",
1083 bestfit=>"350",
1084 modified=>1,
1085 note=>"The $name temperature of the $which",
1086 autonote=>0,
1087 );
1088 my $row = $#gds+1;
1089 $widgets{gds2list} -> add($row);
1090 $widgets{gds2list} -> itemCreate($row, 0, -text=>$row, -style=>$gds_styles{guess});
1091 $widgets{gds2list} -> itemCreate($row, 1, -text=>"g:", -style=>$gds_styles{guess});
1092 $widgets{gds2list} -> itemCreate($row, 2, -text=>"$theta$suffix", -style=>$gds_styles{guess});
1093 $widgets{gds2list} -> itemCreate($row, 3, -text=>"350", -style=>$gds_styles{guess});
1094 };
1095
1096 ## define the path parameter
1097 $paths{$current} -> make('sigma^2' => $value);
1098 $widgets{'path_me_sigma^2'} -> delete(0, 'end');
1099 $widgets{'path_me_sigma^2'} -> insert('end', $value);
1100
1101 Echo("Using the $name model for this path.");
1102 };
1103
1104
1105 ###===================================================================
1106 ### deletion of project parts
1107 ###===================================================================
1108
1109 sub delete_path {
1110 #Echo("Want to delete paths -- $_[0].");
1111
1112 my ($how, $crit) = @_;
1113 my $redisplay = 1;
1114 my ($data, $feff, $curr) = split(/\./,$current);
1115 $feff = ($current =~ /feff(\d+)/) ? $1 : "";
1116 my $message = "No paths were deleted!";
1117 if ($how eq 'nlegs') {
1118 $crit = &get_nlegs;
1119 return if ($crit eq 'Cancel');
1120 } elsif ($how eq 'r') {
1121 $crit = &get_r;
1122 return if ($crit eq 'Cancel');
1123 } elsif ($how eq 'amp') {
1124 $crit = &get_zcwif;
1125 return if ($crit eq 'Cancel');
1126 };
1127
1128 ## get the list of paths that follow the current one in the list,
1129 ## but which are still of the same feff calculation. this is done
1130 ## for the sake of "discard after current". This way cloned
1131 ## paths, which have a higher X as in dataN.feffM.X are considered
1132 ## in their place in the list
1133 my @following = ();
1134 if ($paths{$current}->type eq 'path') {
1135 my $pth = $current;
1136 while ($list->info("next",$pth)) {
1137 $pth = $list->info("next",$pth);
1138 push(@following, $pth)
1139 if (($paths{$pth}->type eq 'path') and
1140 ($paths{$pth}->get('parent') eq $paths{$current}->get('parent')));
1141 };
1142 };
1143
1144 my $new = ($paths{$current}->type eq 'feff') ? $current : $paths{$current}->get('parent');
1145 #($how eq 'nlegs') and ($new = $paths{$current}->feff.".0");
1146 ($how eq 'current') and ($new = $current); # not strictly correct
1147 my @delete_them;
1148 foreach my $p (keys %paths) {
1149 next unless (ref($paths{$p}) =~ /Ifeffit/);
1150 next unless ($paths{$p}->type eq 'path');
1151 SWITCH: {
1152 ($how eq 'all') and do {
1153 push @delete_them, $p;
1154 $message = "Discarded all paths";
1155 last SWITCH;
1156 };
1157 ($how eq 'this') and do {
1158 next unless ($p eq $current);
1159 $new = $list->info('next', $p);
1160 $new ||= $list->info('prev', $p);
1161 push @delete_them, $p;
1162 $message = "Discarded path \"" . $paths{$current}->descriptor() . "\"";
1163 last SWITCH;
1164 };
1165 ($how eq 'r') and do {
1166 if ($paths{$p}->get('reff') < $crit) {
1167 $new = $p;
1168 } else {
1169 push @delete_them, $p;
1170 };
1171 $message = "Discarded all paths with more than $crit legs";
1172 last SWITCH;
1173 };
1174 ($how eq 'amp') and do {
1175 if ($paths{$p}->get('zcwif') > $crit) {
1176 $new = $p;
1177 } else {
1178 push @delete_them, $p;
1179 };
1180 $message = "Discarded all paths with amplitude less than $crit";
1181 last SWITCH;
1182 };
1183 ($how eq 'nlegs') and do {
1184 next unless ($paths{$p}->get('nleg') > $crit);
1185 push @delete_them, $p;
1186 $message = "Discarded all paths longer than $crit";
1187 last SWITCH;
1188 };
1189 ($how eq 'current') and do {
1190 ## my $this = (split(/\./,$p))[2];
1191 ## next if ($this<=$curr);
1192 push @delete_them, $p if (grep /^$p$/, @following);
1193 $message = "Discarded all paths after \"" . $paths{$current}->descriptor() . "\"";
1194 last SWITCH;
1195 };
1196 ($how eq 'sel') and do {
1197 my $selected = grep {$p eq $_} $list->info('selection');
1198 next unless $selected;
1199 push @delete_them, $p;
1200 $message = "Discarded all selected paths.";
1201 last SWITCH;
1202 };
1203 (exists $paths{$how}) and do {
1204 $redisplay = 0;
1205 next unless ($p eq $how);
1206 push @delete_them, $p;
1207 $message = "Discarded path \"" . $paths{$current}->descriptor() . "\"";
1208 last SWITCH;
1209 };
1210 };
1211 };
1212 ## clean up evidence of deleted paths
1213 foreach my $p (@delete_them) {
1214 $list->delete('entry',$p);
1215 ##($paths{$p}->get('group')) and
1216 $paths{$p}->dispose("erase \@group ".$paths{$p}->get('group'), $dmode) if $paths{$p}->get('group');
1217 $paths{$p}->drop; # release it's index
1218 delete $paths{$p};
1219 project_state(0);
1220 };
1221 if ($redisplay) {
1222 $current = $new;
1223 $list->focus();
1224 display_page($new);
1225 };
1226 Echo($message);
1227 return;
1228 };
1229
1230
1231
1232 sub show_path {
1233 if ($paths{$current}->type eq "path") {
1234 my $error = "";
1235 $error .= &verify_parens;
1236 if ($error) {
1237 post_message($error, "Error Messages");
1238 Error("cannot show path due to errors in parameters and math expressions");
1239 return;
1240 };
1241 ##&read_gds2(1);
1242 my $command = "";
1243 if ($parameters_changed) {
1244 map { $command .= $_ -> write_gsd } (@gds);
1245 $parameters_changed = 0;
1246 };
1247
1248 #my $n = $1 + 1;
1249 my $ii = $paths{$current}->index;
1250 my $pathto = $paths{$current}->get('path');
1251 $command .= $paths{$current} -> write_path($ii, $pathto, $config{paths}{extpp}, $stash_dir);
1252 $paths{$current} -> dispose($command, $dmode);
1253 &show_things('path '.$ii);
1254 $paths{$current} ->dispose("get_path($ii, t___emp)", 1);
1255 my $r = sprintf ("%.6f", Ifeffit::get_scalar("t___emp_reff") +
1256 Ifeffit::get_scalar("t___emp_delr"));
1257 $paths{$current} ->
1258 dispose("### ifeffit group for path $ii = ".$paths{$current}->get('group'), $dmode)
1259 if ($paths{$current}->get('group'));
1260 foreach (qw(s02 e0 ei delr sigma2 third fourth degen reff)) {
1261 $paths{$current} ->dispose("erase t___emp_$_", 1);
1262 };
1263 Echo("Showing path \"" . $paths{$current}->descriptor() . "\"");
1264 }
1265 };
1266
1267
1268 sub display_path_header {
1269 my $this = $_[0];
1270 $notes{messages} -> delete(qw(1.0 end));
1271 $notes{messages} -> insert('end', $paths{$this}->descriptor(), "bold");
1272 $notes{messages} -> insert('end', "\n\n");
1273 foreach my $l (split(/\n/, $paths{$this}->get('header'))) {
1274 if ($l =~ / 0 /) {
1275 #print "abs\n";
1276 $notes{messages} -> insert('end', $l, 'absorber');
1277 } elsif ($l =~ /beta/) {
1278 #print "angle\n";
1279 $notes{messages} -> insert('end', $l, 'angles');
1280 } else {
1281 #print "nothing\n";
1282 $notes{messages} -> insert('end', $l);
1283 };
1284 $notes{messages} -> insert('end', "\n");
1285 };
1286 $top -> update;
1287 raise_palette('messages');
1288 Echo("Showing header for \"" . $paths{$this}->descriptor() . "\"");
1289 };
1290
1291 sub verify_number_of_paths {
1292 my $message = "";
1293 my $total = 0;
1294 my %seen;
1295 foreach my $d (&all_data) {
1296 my $n = 0;
1297 foreach my $k (keys %paths) {
1298 next unless (ref($paths{$k}) =~ /Ifeffit/);
1299 next unless ($paths{$k}->type eq "path"); # not a path
1300 next unless ($paths{$k}->data eq $d); # not from this data set
1301 next unless $paths{$k}->get('include'); # not included in the fit
1302 ++$n;
1303 ++$total;
1304 };
1305 if ($n > $limits{paths_per_set}) {
1306 $message .= "You have exceeded the per-path limit of $limits{paths_per_set} paths in data set\n";
1307 $message .= "\t" . $paths{$d}->descriptor();
1308 };
1309 };
1310 if ($total > $limits{total_paths}) {
1311 $message .= "You have used $total paths, exceeding Ifeffit's total-fit limit of $limits{total_paths} paths.\n";
1312 };
1313 };
1314
1315
1316 ## this returns the list of paths in the order that they are
1317 ## displayed.
1318 sub path_list {
1319 my $this = 'gsd';
1320 my @foo = ($this);
1321 while ($list->infoNext($this)) {
1322 $this = $list->infoNext($this);
1323 push @foo, $this;
1324 };
1325 return @foo;
1326 };
1327
1328
1329 ## this returns a list of the first 5 paths in each feff calculation
1330 ## for a data set
1331 sub pcpath_list {
1332 my $data = $_[0];
1333 my $this = 'gsd';
1334 my $count = 0;
1335 my @foo = ($this);
1336 while ($list->infoNext($this)) {
1337 $this = $list->infoNext($this);
1338 next unless (ref($paths{$this}) =~ /Ifeffit/);
1339 ($count = 0) if ($paths{$this}->type eq 'feff');
1340 next unless ($paths{$this}->type eq 'path');
1341 next unless ($paths{$this}->data eq $data);
1342 ++$count;
1343 next if ($count > 5);
1344 push @foo, $this;
1345 };
1346 return @foo;
1347 };
1348
1349 sub path_used {
1350 my ($path, $file) = @_;
1351 foreach my $p (keys %paths) {
1352 next unless ($paths{$p}->type eq 'path');
1353 my $thispath = File::Spec->catfile($project_folder, $paths{$p}->get('parent'));
1354 next unless same_directory($thispath, $path);
1355 next unless ($file eq $paths{$p}->get('feff'));
1356 return 1;
1357 };
1358 return 0;
1359 };
1360
1361
1362 ## END OF THE SECTION ON THE PATH PAGE
1363