| 1 |
|
| 2 |
## =========================================================================== |
| 3 |
## This is the anomolous scattering portion of hephaestus |
| 4 |
|
| 5 |
|
| 6 |
sub f1f2 { |
| 7 |
$periodic_table -> pack(-side=>'top', -padx=>4, -pady=>4, -fill=>'x') |
| 8 |
if $current !~ /$uses_periodic_regex/; |
| 9 |
switch({page=>"f1f2", text=>'Periodic Table of Complex Scattering Factors'}); |
| 10 |
$data{pt_resource} -> gridForget; |
| 11 |
}; |
| 12 |
|
| 13 |
sub setup_f1f2 { |
| 14 |
my $frame = $_[0] -> Frame(-borderwidth=>2, -relief=>'flat'); |
| 15 |
|
| 16 |
$data{f1f2_emin} ||= 3000; |
| 17 |
$data{f1f2_emax} ||= 7000; |
| 18 |
$data{f1f2_egrid} ||= 5; |
| 19 |
$data{f1f2_width} = 0; |
| 20 |
$data{f1f2_plot} = 'new'; |
| 21 |
$data{f1f2_function} = 'both'; |
| 22 |
$data{f1f2_naturalwidth} = 1; |
| 23 |
|
| 24 |
my $fr = $frame -> Frame() -> pack(-side=>'top', -pady=>3); |
| 25 |
$fr -> Label(-text=>'Starting energy', @label_args,) |
| 26 |
-> pack(-side=>'left'); |
| 27 |
$fr -> Entry(-width=>12, |
| 28 |
-textvariable=>\$data{f1f2_emin}, |
| 29 |
-validate=>'key', -validatecommand=>\&set_variable) |
| 30 |
-> pack(-side=>'left', -padx=>4); |
| 31 |
$fr -> Label(-text=>'Ending energy', @label_args,) |
| 32 |
-> pack(-side=>'left'); |
| 33 |
$fr -> Entry(-width=>12, |
| 34 |
-textvariable=>\$data{f1f2_emax}, |
| 35 |
-validate=>'key', -validatecommand=>\&set_variable) |
| 36 |
-> pack(-side=>'left', -padx=>4); |
| 37 |
$fr -> Label(-text=>'Energy grid', @label_args,) |
| 38 |
-> pack(-side=>'left'); |
| 39 |
$fr -> Entry(-width=>12, |
| 40 |
-textvariable=>\$data{f1f2_egrid}, |
| 41 |
-validate=>'key', -validatecommand=>\&set_variable) |
| 42 |
-> pack(-side=>'left', -padx=>4); |
| 43 |
|
| 44 |
$fr = $frame -> Frame() -> pack(-side=>'top', -pady=>3); |
| 45 |
my $w_label = $fr -> Label(-text=>'Convolution with', |
| 46 |
-font=>$config{fonts}{small}, |
| 47 |
-foreground=>'grey50',) |
| 48 |
-> pack(-side=>'left'); |
| 49 |
my $w_entry = $fr -> Entry(-width=>12, |
| 50 |
-foreground=>'grey50', |
| 51 |
-textvariable=>\$data{f1f2_width}, |
| 52 |
(($Tk::VERSION > 804) ? (-disabledbackground=>$bgcolor) : ()), |
| 53 |
-validate=>'key', |
| 54 |
-validatecommand=>[\&set_variable, 'width'], |
| 55 |
-state=>'disabled') |
| 56 |
-> pack(-side=>'left', -padx=>4); |
| 57 |
$fr -> Checkbutton(-text=>'Convolute by the natural core-level width', |
| 58 |
-font=>$config{fonts}{small}, |
| 59 |
-variable=>\$data{f1f2_naturalwidth}, |
| 60 |
-command=>sub{$w_label->configure(-foreground => ($data{f1f2_naturalwidth}) ? 'grey50' : 'blue4'); |
| 61 |
$w_entry->configure(-state => ($data{f1f2_naturalwidth}) ? 'disabled' : 'normal', |
| 62 |
-foreground => ($data{f1f2_naturalwidth}) ? 'grey50' : 'black' ); |
| 63 |
}) |
| 64 |
-> pack(-side=>'left'); |
| 65 |
|
| 66 |
$fr = $frame -> Frame() -> pack(-side=>'top', -pady=>3); |
| 67 |
$fr -> Radiobutton(-text=>'New plot', |
| 68 |
-font=>$config{fonts}{small}, |
| 69 |
-variable=>\$data{f1f2_plot}, |
| 70 |
-value=>'new') |
| 71 |
-> grid(-column=>0, -row=>0, -sticky=>'w'); |
| 72 |
$fr -> Radiobutton(-text=>'Overplot', |
| 73 |
-font=>$config{fonts}{small}, |
| 74 |
-variable=>\$data{f1f2_plot}, |
| 75 |
-value=>'over') |
| 76 |
-> grid(-column=>0, -row=>1, -sticky=>'w'); |
| 77 |
|
| 78 |
$fr -> Label(-width=>5) |
| 79 |
-> grid(-column=>1, -row=>1); |
| 80 |
|
| 81 |
$fr -> Radiobutton(-text=>"Plot just f\'", |
| 82 |
-font=>$config{fonts}{small}, |
| 83 |
-variable=>\$data{f1f2_function}, |
| 84 |
-value=>'f1') |
| 85 |
-> grid(-column=>2, -row=>0, -sticky=>'w'); |
| 86 |
$fr -> Radiobutton(-text=>"Plot just f\"", |
| 87 |
-font=>$config{fonts}{small}, |
| 88 |
-variable=>\$data{f1f2_function}, |
| 89 |
-value=>'f2') |
| 90 |
-> grid(-column=>2, -row=>1, -sticky=>'w'); |
| 91 |
$fr -> Radiobutton(-text=>"Plot both f' and f\"", |
| 92 |
-font=>$config{fonts}{small}, |
| 93 |
-variable=>\$data{f1f2_function}, |
| 94 |
-value=>'both') |
| 95 |
-> grid(-column=>2, -row=>2, -sticky=>'w'); |
| 96 |
|
| 97 |
$fr = $frame -> Frame() -> pack(-side=>'top', -pady=>3); |
| 98 |
$data{f1f2_save} = $fr -> Button(-text=>"Save data", @button_args, |
| 99 |
-width=>20, |
| 100 |
-state=>'disabled') |
| 101 |
-> pack(); |
| 102 |
|
| 103 |
return $frame; |
| 104 |
}; |
| 105 |
|
| 106 |
|
| 107 |
sub get_f1f2_data { |
| 108 |
my $z = get_Z($_[0]); |
| 109 |
my $w = ($data{f1f2_naturalwidth}) ? '-2' : $data{f1f2_width}; |
| 110 |
Ifeffit::ifeffit("f1f2.energy = range($data{f1f2_emin},$data{f1f2_emax},$data{f1f2_egrid})\n"); |
| 111 |
Ifeffit::ifeffit("f1f2(energy=f1f2.energy, z=$z, width=$w)\n"); |
| 112 |
my $plot = ($data{f1f2_plot} eq 'new') ? "newplot" : "plot"; |
| 113 |
if ($data{f1f2_function} eq 'f1') { |
| 114 |
my $key = "$_[0] f1"; |
| 115 |
Ifeffit::ifeffit("$plot(f1f2.energy, f1f2.f1, xmin=$data{f1f2_emin}, xmax=$data{f1f2_emax}, xlabel=\"Energy (eV)\", ylabel=f1, key=\"$key\")\n"); |
| 116 |
Ifeffit::ifeffit("plot(title=\"Complex scattering factors\")\n"); |
| 117 |
} elsif ($data{f1f2_function} eq 'f2') { |
| 118 |
my $key = "$_[0] f2"; |
| 119 |
Ifeffit::ifeffit("$plot(f1f2.energy, f1f2.f2, xmin=$data{f1f2_emin}, xmax=$data{f1f2_emax}, xlabel=\"Energy (eV)\", ylabel=f2, key=\"$key\")\n"); |
| 120 |
Ifeffit::ifeffit("plot(title=\"Complex scattering factors\")\n"); |
| 121 |
} else { |
| 122 |
my $key = "$_[0] f1"; |
| 123 |
Ifeffit::ifeffit("$plot(f1f2.energy, f1f2.f1, xmin=$data{f1f2_emin}, xmax=$data{f1f2_emax}, xlabel=\"Energy (eV)\", ylabel=\"f1 and f2\", key=\"$key\")\n"); |
| 124 |
$key = "$_[0] f2"; |
| 125 |
Ifeffit::ifeffit( "plot(f1f2.energy, f1f2.f2, xmin=$data{f1f2_emin}, xmax=$data{f1f2_emax}, xlabel=\"Energy (eV)\", ylabel=\"f1 and f2\", key=\"$key\")\n"); |
| 126 |
Ifeffit::ifeffit("plot(title=\"Complex scattering factors\")\n"); |
| 127 |
}; |
| 128 |
my $sym = get_symbol($z); |
| 129 |
$data{f1f2_save} -> configure(-text=>"Save data for $sym", |
| 130 |
-command=>[\&save_f1f2, $sym, $data{f1f2_function}, |
| 131 |
$data{f1f2_emin}, $data{f1f2_emax}, |
| 132 |
$data{f1f2_egrid}], |
| 133 |
-state=>'normal'); |
| 134 |
}; |
| 135 |
|
| 136 |
sub save_f1f2 { |
| 137 |
my ($sym, $which, $emin, $emax, $egrid) = @_; |
| 138 |
my $types = [['Scattering factor files', '*.f1f2'], ['All Files', '*'],]; |
| 139 |
my $file = $top -> getSaveFile(-filetypes=>$types, |
| 140 |
##(not $is_windows) ? |
| 141 |
## (-sortcmd=>sub{$Tk::FBox::a cmp $Tk::FBox::b}) : () , |
| 142 |
-initialfile=>lc($sym).".f1f2", |
| 143 |
-initialdir=>$save_dir, |
| 144 |
-title => "Hephaestus: Save f1f2 data"); |
| 145 |
return unless ($file); |
| 146 |
|
| 147 |
$save_dir = dirname($file); |
| 148 |
my $command; |
| 149 |
my $ifeffit_version = (split(" ", Ifeffit::get_string("\$&build")))[0]; |
| 150 |
Ifeffit::put_string("f1f2_title1","Hephaestus $VERSION, Ifeffit $ifeffit_version"); |
| 151 |
if ($which eq 'f1') { |
| 152 |
Ifeffit::put_string("f1f2_title2","f1 data for $sym"); |
| 153 |
$command = "write_data(file=$file, \$f1f2_title*, f1f2.energy, f1f2.f1)"; |
| 154 |
} elsif ($which eq 'f2') { |
| 155 |
Ifeffit::put_string("f1f2_title2","f2 data for $sym"); |
| 156 |
$command = "write_data(file=$file, \$f1f2_title*, f1f2.energy, f1f2.f2)"; |
| 157 |
} else { |
| 158 |
Ifeffit::put_string("f1f2_title2","f1 and f2 data for $sym"); |
| 159 |
$command = "write_data(file=$file, \$f1f2_title*, f1f2.energy, f1f2.f1, f1f2.f2)"; |
| 160 |
}; |
| 161 |
Ifeffit::put_string("f1f2_title3","computed between $emin and $emax on a $egrid eV grid"); |
| 162 |
Ifeffit::ifeffit($command); |
| 163 |
}; |