| 1 |
#!/usr/bin/perl |
| 2 |
###################################################################### |
| 3 |
## CGI version of Atoms version 3.0.1 |
| 4 |
## copyright (c) 1998-2005 Bruce Ravel |
| 5 |
## [email protected] |
| 6 |
## http://cars9.uchicago.edu/~ravel/ |
| 7 |
## |
| 8 |
## The latest version of Atoms can always be found at |
| 9 |
## http://cars9.uchicago.edu/~ravel/software/ |
| 10 |
## |
| 11 |
## ------------------------------------------------------------------- |
| 12 |
## All rights reserved. This program is free software; you can |
| 13 |
## redistribute it and/or modify it under the same terms as Perl |
| 14 |
## itself. |
| 15 |
## |
| 16 |
## This program is distributed in the hope that it will be useful, |
| 17 |
## but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 |
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 |
## Artistic License for more details. |
| 20 |
## ------------------------------------------------------------------- |
| 21 |
###################################################################### |
| 22 |
my $cvs_info = '$Id: atoms.cgi,v 1.5 2000/10/17 18:30:17 bruce Exp $ '; |
| 23 |
## Time-stamp: <06/02/03 13:36:45 bruce> |
| 24 |
###################################################################### |
| 25 |
## Install this some place your web server can find it and then you |
| 26 |
## can serve up Atoms over the Web. Be sure to configure the |
| 27 |
## variables in and just after the BEGIN block. |
| 28 |
###################################################################### |
| 29 |
## To Do: |
| 30 |
## |
| 31 |
## -- called with file, then press clear button, file argument |
| 32 |
## remains in URL |
| 33 |
## -- under lynx, save as name includes query info |
| 34 |
###################################################################### |
| 35 |
## Code: |
| 36 |
|
| 37 |
## ------------------------------------------------------------------- |
| 38 |
## These lines need to be fixed by the web administrator installing |
| 39 |
## WebAtoms. |
| 40 |
BEGIN { |
| 41 |
my $extra_INC = # Set this if you have Atoms installed |
| 42 |
"/home/bruce/perl"; # outside of Perl's normal search path |
| 43 |
($extra_INC) and unshift @INC, $extra_INC; |
| 44 |
} |
| 45 |
my $atoms_help = # the Web-space location of the help file |
| 46 |
"file://localhost/home/bruce/perl/atoms/cgi/WebAtoms_help.html"; |
| 47 |
my $ADB_search = # URL of ADB search form |
| 48 |
"somewhere"; |
| 49 |
my $ADB_directory = # the real-disk location of the ADB files |
| 50 |
"/www/apache/htdocs/cgi-data/atoms/ADB/"; |
| 51 |
## ------------------------------------------------------------------- |
| 52 |
## On millenia: |
| 53 |
## |
| 54 |
## BEGIN { |
| 55 |
## my $extra_INC = ""; # Set this if you have Atoms installed |
| 56 |
## ## "/home/ravel/perl"; # outside of Perl's normal search path |
| 57 |
## ($extra_INC) and unshift @INC, $extra_INC; |
| 58 |
## } |
| 59 |
## my $atoms_help = |
| 60 |
## "http://cars9.uchicago.edu/cgi-data/atoms/WebAtoms_help.html"; |
| 61 |
## my $ADB_search = |
| 62 |
## "http://cars9.uchicago.edu/cgi-bin/atoms/Atoms-Search.cgi"; |
| 63 |
## my $ADB_directory = |
| 64 |
## "/www/htdocs/cgi-data/atoms/ADB/"; |
| 65 |
|
| 66 |
## note that this is the actual location of WebAtoms_help.html on |
| 67 |
## millenia |
| 68 |
## /millenia/www/apache/htdocs/cgi-data/atoms |
| 69 |
## apparently the URL above is mapped to that location. |
| 70 |
|
| 71 |
## the actual location on millenia of the script itself is |
| 72 |
## /millenia/www/apache2/cgi-bin/atoms/ |
| 73 |
|
| 74 |
my $version = "1.8 (Atoms $Xray::Atoms::VERSION)"; # (split(' ', $cvs_info))[2] || "pre_release"; |
| 75 |
my $date = "3 February, 2005"; # (split(' ', $cvs_info))[3] || "Oct 11 1999"; |
| 76 |
|
| 77 |
## =============================== load methods |
| 78 |
require 5.004; |
| 79 |
use strict; |
| 80 |
use Carp; |
| 81 |
|
| 82 |
use Xray::Xtal; |
| 83 |
$Xray::Xtal::run_level = 2; |
| 84 |
use Xray::Atoms qw(build_cluster rcfile_name number); |
| 85 |
use Xray::ATP; # qw(parse_atp); |
| 86 |
use Chemistry::Elements qw(get_Z); |
| 87 |
|
| 88 |
use CGI; # load CGI routines |
| 89 |
use CGI::Carp 'fatalsToBrowser'; |
| 90 |
$CGI::POST_MAX=1024 * 1000; # max 1M posts |
| 91 |
my $q = new CGI; # create new CGI object |
| 92 |
my $inpfile = $q->param('file'); |
| 93 |
$q->delete('file'); |
| 94 |
($ADB_directory =~ /\/$/) or $ADB_directory .= '/'; |
| 95 |
|
| 96 |
my %values = (); # values hash (a few need to be pre-set) |
| 97 |
$values{edge} = ' '; |
| 98 |
$values{central_index} = 1; |
| 99 |
$values{nsites} = 10; |
| 100 |
$values{rmax} = 10; |
| 101 |
$values{atp} = ($Xray::Atoms::prefer_feff_eight) ? 'feff8' : 'feff'; |
| 102 |
$values{debug} = $q->param('debug'); |
| 103 |
my ($atoms,$feff) = ($q->small('ATOMS'), $q->small('FEFF')); |
| 104 |
my $bruce_home = "http://cars9.uchicago.edu/~ravel/"; |
| 105 |
my $atoms_url = $bruce_home . "software/"; |
| 106 |
my $atoms_home = $atoms_url; |
| 107 |
my @edge_names = (" ", qw(K L1 L2 L3 M1 M2 M3 M4 M5)); |
| 108 |
my @elem_names = (" ","H","He","Li","Be","B","C","N","O","F","Ne", |
| 109 |
"Na","Mg","Al","Si","P","S","Cl","Ar","K","Ca", |
| 110 |
"Sc","Ti","V","Cr","Mn","Fe","Co","Ni","Cu","Zn", |
| 111 |
"Ga","Ge","As","Se","Br","Kr","Rb","Sr","Y","Zr", |
| 112 |
"Nb","Mo","Tc","Ru","Rh","Pd","Ag","Cd","In", |
| 113 |
"Sn","Sb","Te","I","Xe","Cs","Ba","La","Ce","Pr", |
| 114 |
"Nd","Pm","Sm","Eu","Gd","Tb","Dy","Ho","Er","Tm", |
| 115 |
"Yb","Lu","Hf","Ta","W","Re","Os","Ir","Pt","Au", |
| 116 |
"Hg","Tl","Pb","Bi","Po","At","Rn","Fr","Ra","Ac", |
| 117 |
"Th","Pa","U","Np","Pu"); |
| 118 |
my $table_params = {qw(border 0 cellspacing 0 cellpadding 2 |
| 119 |
align CENTER bgcolor tan)}; |
| 120 |
my $table_row = {qw(align CENTER valign CENTER)}; |
| 121 |
my @atp_files = qw(feff feff8 atoms absorption xyz alchemy |
| 122 |
unit p1 p1_cartesian symmetry gnxas_cry gnxas_sym); # geom); |
| 123 |
my %atp = ( # labels for atp file popup |
| 124 |
feff => 'feff6.inp', |
| 125 |
feff8 => 'feff8.inp', |
| 126 |
atoms => 'atoms.inp', |
| 127 |
absorption => 'absorption', |
| 128 |
xyz => 'xyz', |
| 129 |
alchemy => 'alchemy', |
| 130 |
unit => 'unit cell', |
| 131 |
p1 => 'p1.inp', |
| 132 |
p1_cartesian => 'cartesian P1 file', |
| 133 |
symmetry => 'symmetry', |
| 134 |
gnxas_cry => 'GNXAS cry', |
| 135 |
gnxas_sym => 'GNXAS sym', |
| 136 |
#geom => 'geom.dat', |
| 137 |
); |
| 138 |
my %output = ( |
| 139 |
feff => 'feff.inp', |
| 140 |
feff8 => 'feff.inp', |
| 141 |
atoms => 'atoms.inp', |
| 142 |
absorption => 'absorption.dat', |
| 143 |
xyz => 'xyz.lis', |
| 144 |
alchemy => 'alchemy.lis', |
| 145 |
unit => 'unit.dat', |
| 146 |
p1 => 'p1.inp', |
| 147 |
p1_cartesian => 'cartesian.dat', |
| 148 |
symmetry => 'symmetry.dat', |
| 149 |
gnxas_cry => 'cluster', |
| 150 |
gnxas_sym => 'cluster', |
| 151 |
#geom => 'geom.dat', |
| 152 |
); |
| 153 |
|
| 154 |
## ----- Installation tool ------------------------------------------- |
| 155 |
## This next bit is only run by the web administrator at install time. |
| 156 |
## It is accessed by running `atoms.cgi -install' at the command line |
| 157 |
## in the installation directory. Normally, this block is ignored by |
| 158 |
## the script. |
| 159 |
if ($ARGV[0] =~ /-{1,2}install/i) { |
| 160 |
my $pwd = `pwd`; |
| 161 |
print <<EOH |
| 162 |
|
| 163 |
Installation tool for atoms.cgi version $version |
| 164 |
Installing $0 in $pwd |
| 165 |
Creating or varifying hard links: |
| 166 |
EOH |
| 167 |
; |
| 168 |
foreach my $k (keys %output) { |
| 169 |
print " $output{$k}$/"; |
| 170 |
(-f $output{$k}) and unlink $output{$k}; |
| 171 |
link($0, $output{$k}); |
| 172 |
}; |
| 173 |
print <<EOH |
| 174 |
|
| 175 |
Please edit the variables in and just after the BEGIN block of |
| 176 |
'$0' to complete the installation on your server. |
| 177 |
These variables are: |
| 178 |
|
| 179 |
\$extra_INC The installation location of the Atoms package |
| 180 |
if you have installed it outside of the normal |
| 181 |
perl search path |
| 182 |
\$atoms_help The Web-space location of the help file |
| 183 |
\$ADB_search The URL of the Atoms Database search form |
| 184 |
\$ADB_directory The real-disk location of the Atoms Database files |
| 185 |
|
| 186 |
EOH |
| 187 |
; |
| 188 |
exit; |
| 189 |
}; |
| 190 |
## ----- end of installation tool ------------------------------------- |
| 191 |
|
| 192 |
my $red_message = ""; # warnings and errors |
| 193 |
my $run_atoms = 1; # flag for atoms or feff display |
| 194 |
my @sites = (); # list of sites |
| 195 |
my @cluster = (); # spherical cluster |
| 196 |
my @neutral = (); # charge neutral rhomboidal cluster |
| 197 |
|
| 198 |
|
| 199 |
## =============================== define a cell and a keyword hash |
| 200 |
my $cell = Xray::Xtal::Cell -> new(); |
| 201 |
my $keywords = Xray::Atoms -> new(); |
| 202 |
$keywords -> make('identity' => "WebAtoms $version", die=>2, |
| 203 |
'quiet' => 1, 'www_warn' => ""); |
| 204 |
($inpfile) and import_data($ADB_directory.$inpfile, $keywords, \%values); |
| 205 |
|
| 206 |
($q->param) or $run_atoms = 0; # this is the first call! |
| 207 |
($q->param('redisplay')) and $run_atoms = 0; |
| 208 |
|
| 209 |
if ($q->param('text_entry')) { |
| 210 |
# $run_atoms = 0; |
| 211 |
$q->param(text_entry=>0); |
| 212 |
}; |
| 213 |
if ($q->param('list_entry')) { |
| 214 |
# $run_atoms = 0; |
| 215 |
$q->param(list_entry=>0); |
| 216 |
}; |
| 217 |
if ($q->param('Clear')) { |
| 218 |
$inpfile = ""; |
| 219 |
$run_atoms = 0; |
| 220 |
$q->delete_all; |
| 221 |
(my $uu = $q->url()) =~ s/\?.*$//; |
| 222 |
$q->redirect($uu); |
| 223 |
}; |
| 224 |
((not $q->param('text_entry')) and (not $q->param('list_entry'))) |
| 225 |
and $q->param(list_entry=>1); |
| 226 |
#$red_message .= "text = " . $q->param('text_entry') . $/; |
| 227 |
#$red_message .= "list = " . $q->param('list_entry') . $/; |
| 228 |
|
| 229 |
|
| 230 |
## cell parameters |
| 231 |
foreach my $key (qw(space_group a b c alpha beta gamma)) { |
| 232 |
last unless $run_atoms; |
| 233 |
my $val = $q->param($key); |
| 234 |
if (($key eq 'space_group') and ($val =~ /^\s*$/)) { |
| 235 |
$red_message .= "$/You have not specified a space group.$/"; |
| 236 |
$run_atoms = 0; |
| 237 |
last; |
| 238 |
}; |
| 239 |
next unless ($val); |
| 240 |
if ( ($val) or ($val =~ /^\s*$/) ) { |
| 241 |
$cell -> make($key => $val); |
| 242 |
## what about non-standard settings...? |
| 243 |
($values{$key}) = $cell->attributes($key); |
| 244 |
if ($Xray::Xtal::xtal_fatals) { |
| 245 |
$red_message .= $Xray::Xtal::xtal_fatals; |
| 246 |
$run_atoms = 0; |
| 247 |
}; |
| 248 |
}; |
| 249 |
}; |
| 250 |
|
| 251 |
|
| 252 |
## operational keywords |
| 253 |
foreach my $key (qw(rmax edge titles)) { |
| 254 |
last unless $run_atoms; |
| 255 |
if (($q->param($key)) and ($q->param($key) !~ /^\s*$/)) { |
| 256 |
if ($key eq 'titles') { |
| 257 |
my $eol = $/ . "+"; # split title text into lines |
| 258 |
my @t = split /$eol/, $q->param('titles'); |
| 259 |
$keywords->{'title'} = []; |
| 260 |
map {$keywords->make('title'=>$_)} @t; |
| 261 |
} else { |
| 262 |
$keywords -> make($key => $q->param($key)); |
| 263 |
}; |
| 264 |
}; |
| 265 |
}; |
| 266 |
## fill up the sites array |
| 267 |
my $i = 0; |
| 268 |
my %map = (); |
| 269 |
($q->param('nsites')) and $values{nsites} = $q->param('nsites'); |
| 270 |
foreach my $s (1 .. ($values{nsites})) { |
| 271 |
last unless $run_atoms; |
| 272 |
my ($e, $x, $y, $z, $t) = ($q->param('elem'.$s), |
| 273 |
$q->param('x'.$s), |
| 274 |
$q->param('y'.$s), |
| 275 |
$q->param('z'.$s), |
| 276 |
$q->param('tag'.$s)); |
| 277 |
next if ($e =~ /^\s*$/); |
| 278 |
unless (($e) and (get_Z($e))) { |
| 279 |
$e =~ s/\s+$//; |
| 280 |
$red_message .= "\"$e\" is not a valid element.$/"; |
| 281 |
$run_atoms = 0; |
| 282 |
next; |
| 283 |
}; |
| 284 |
$map{$s} = $i; |
| 285 |
$sites[$i] = Xray::Xtal::Site -> new($i); |
| 286 |
$x = number($x, 2, $keywords) + number($q->param("shiftx"), 2, $keywords); |
| 287 |
$y = number($y, 2, $keywords) + number($q->param("shifty"), 2, $keywords); |
| 288 |
$z = number($z, 2, $keywords) + number($q->param("shiftz"), 2, $keywords); |
| 289 |
$sites[$i] -> make(Element=>$e, X=>$x, Y=>$y, Z=>$z, Tag=>$t); |
| 290 |
($t) = $sites[$i] -> attributes('Tag'); |
| 291 |
## parse_atp in Atoms.pm uses the $keywords->{'sites'} to generate |
| 292 |
## the <list :style atoms>, so I must load that up as well ... |
| 293 |
$keywords -> make('sites'=> $e, $x, $y, $z, $t, 1); |
| 294 |
++$i; |
| 295 |
}; |
| 296 |
if ($run_atoms and not $i) { |
| 297 |
$run_atoms = 0; |
| 298 |
$red_message .= "$/You have not defined any sites.$/"; |
| 299 |
}; |
| 300 |
|
| 301 |
|
| 302 |
if ($run_atoms) { |
| 303 |
if ($q->param('central_index')) { |
| 304 |
$values{central_index} = $q->param('central_index'); |
| 305 |
$values{core_tag} = $map{$values{central_index}}; |
| 306 |
if ($sites[$values{core_tag}]) { |
| 307 |
$values{core_tag} = $sites[$values{core_tag}] -> {Tag}; |
| 308 |
$keywords -> make('core'=>$values{core_tag}); |
| 309 |
} else { |
| 310 |
$red_message .= |
| 311 |
"$/You have selected an undefined site as the central atom.$/"; |
| 312 |
$run_atoms = 0; |
| 313 |
}; |
| 314 |
}; |
| 315 |
|
| 316 |
if ($run_atoms and $cell -> {Space_group}) { |
| 317 |
$cell -> verify_cell(); |
| 318 |
($Xray::Xtal::xtal_fatals) or $cell -> populate(\@sites); |
| 319 |
$keywords -> verify_keywords($cell, \@sites, 2); |
| 320 |
$red_message .= $Xray::Xtal::xtal_warnings; |
| 321 |
if ($Xray::Xtal::xtal_fatals) { |
| 322 |
$red_message .= $Xray::Xtal::xtal_fatals; |
| 323 |
$run_atoms = 0; |
| 324 |
} |
| 325 |
$red_message .= $keywords -> {www_warn}; |
| 326 |
}; |
| 327 |
|
| 328 |
$red_message .= $cell -> warn_shift(); |
| 329 |
$red_message .= $cell -> cell_check(); |
| 330 |
}; |
| 331 |
|
| 332 |
## foreach my $key (qw(space_group a b c alpha beta gamma)) { |
| 333 |
## $red_message .= $key . " " . $cell->{ucfirst($key)} . "\n"; |
| 334 |
## } |
| 335 |
## $run_atoms = 0; |
| 336 |
|
| 337 |
## generate the appropriate page |
| 338 |
if ($q->param('actual')) { |
| 339 |
my $atp = $q->param('atp') || 'feff'; |
| 340 |
print $q->header('text/plain'); |
| 341 |
my $result = messages($q, \%values, 1); |
| 342 |
## foreach my $key (qw(space_group a b c alpha beta gamma)) { |
| 343 |
## print join(" ", $key, $cell->{ucfirst($key)}, "|", $q->param($key), "\n"); |
| 344 |
## } |
| 345 |
run_atoms($q, $atp, $cell, $keywords, \@cluster, \@neutral, \$result); |
| 346 |
print $result; |
| 347 |
} elsif ($run_atoms) { |
| 348 |
my $atp = $q->param('atp') || 'feff'; |
| 349 |
$q->param(-name=>'actual', -value=>1, text_entry=>0, list_entry=>0); |
| 350 |
my $this = $q->url(); |
| 351 |
(my $redir = $q->url(-query=>1)) =~ s/atoms.cgi/$output{$atp}/; |
| 352 |
print $q -> redirect($redir); |
| 353 |
} else { |
| 354 |
top($q, \%values); |
| 355 |
messages($q, \%values, 0); |
| 356 |
atoms_keywords($q, \%values); |
| 357 |
site_table($q, \%values); |
| 358 |
bottom($q, \%values); |
| 359 |
}; |
| 360 |
|
| 361 |
|
| 362 |
## ---------------------------------------------------------------------- |
| 363 |
## This is the end! |
| 364 |
|
| 365 |
|
| 366 |
######################################################################### |
| 367 |
## subroutines |
| 368 |
|
| 369 |
## gather and print the output file |
| 370 |
sub run_atoms { |
| 371 |
my ($q, $atp, $cell, $keywords, $r_cluster, $r_neutral, $r_result) = @_; |
| 372 |
## foreach my $key (qw(space_group a b c alpha beta gamma)) { |
| 373 |
## print $key . " " . $$r_cell->{ucfirst($key)} . "\n"; |
| 374 |
## } |
| 375 |
## exit; |
| 376 |
build_cluster($cell, $keywords, $r_cluster, $r_neutral); |
| 377 |
my $contents = ""; |
| 378 |
$q->autoEscape(1); |
| 379 |
my ($default_name, $is_feff) = |
| 380 |
&parse_atp($atp, $cell, $keywords, $r_cluster, $r_neutral, \$contents); |
| 381 |
#my %subs = {'<'=>'<', '>'=>'>'}; |
| 382 |
#my $sub_keys = join('', keys(%subs)); |
| 383 |
#$contents =~ s/([$sub_keys])/$subs{$1}/eg; |
| 384 |
$$r_result .= $contents; |
| 385 |
}; |
| 386 |
|
| 387 |
## Header materials for atoms data entry page |
| 388 |
sub top { |
| 389 |
my $q = $_[0]; |
| 390 |
my $r_values = $_[1]; |
| 391 |
print |
| 392 |
$q->header, # create the HTTP header |
| 393 |
$q->start_html(-title=>'ATOMS', |
| 394 |
-bgcolor=>'white', |
| 395 |
-meta=>{'copyright'=>'copyright 1999-2005 Bruce Ravel'} |
| 396 |
), |
| 397 |
$q->h1({align=>'CENTER'}, 'ATOMS on the Web'); |
| 398 |
|
| 399 |
my $paragraph = "$atoms is a program for generating lists of |
| 400 |
atomic coordinates from crystallographic data. The primary use of |
| 401 |
$atoms is to create input files suitable for running the " . |
| 402 |
$q->i("ab initio") . |
| 403 |
" XAFS program $feff, however several other interesting output formats |
| 404 |
are available."; |
| 405 |
print $q->p($paragraph); |
| 406 |
$paragraph = "This web page demonstrates the main features of $atoms. |
| 407 |
It consists of a rather large form which you may fill in with |
| 408 |
data describing your crystal. "; |
| 409 |
($ADB_search) and |
| 410 |
$paragraph .= |
| 411 |
$q->a({href=>$ADB_search}, |
| 412 |
"You may also search a database of input data for $atoms."); |
| 413 |
$paragraph .= " After clicking the \"Run Atoms\" |
| 414 |
button, your browser will display an input file suitable for running |
| 415 |
$feff (or perhaps some other kind of interesting output file). You |
| 416 |
can get help about any of the parameters by following the link |
| 417 |
bound to the parameter name."; |
| 418 |
print $q->p($paragraph); |
| 419 |
$paragraph = "This web page does not offer " . |
| 420 |
$q->a({href=>"$atoms_help#features"}, 'all the features') . |
| 421 |
" available in the version of $atoms which you can run on your |
| 422 |
own computer. Please see the "; |
| 423 |
$paragraph .= $q->a({href=>$atoms_home}, "$atoms homepage"); |
| 424 |
$paragraph .= " for complete details."; |
| 425 |
print $q->p($paragraph), $q->hr(); |
| 426 |
}; |
| 427 |
|
| 428 |
## print out error and warning messages |
| 429 |
sub messages { |
| 430 |
my $q = $_[0]; |
| 431 |
my $r_values = $_[1]; |
| 432 |
my $output = $_[2]; |
| 433 |
return unless (($red_message) or ($q->param('debug')) ); |
| 434 |
if ($q->param('debug')) { |
| 435 |
#foreach my $key ($q->param) { |
| 436 |
# my $start = ($output) ? " * $key -> " : $q->b("$key -> ") ; |
| 437 |
# print $start; |
| 438 |
# my @values = $q->param($key); |
| 439 |
# print join(", ",@values); |
| 440 |
# my $end = ($output) ? $/ : $q->br(); |
| 441 |
# print $end; |
| 442 |
#} |
| 443 |
require Data::Dumper; |
| 444 |
$red_message .= $/; |
| 445 |
$red_message .= Data::Dumper -> |
| 446 |
Dump([$cell, $keywords, $values{core_tag}, $run_atoms], |
| 447 |
[qw(*cell *keywords core_tag, run_atoms)]); |
| 448 |
}; |
| 449 |
if ($output) { |
| 450 |
$red_message =~ s|$/|$/ * |g; |
| 451 |
my $ret_str = " * ", '-' x 70, $/, ' * '; |
| 452 |
$ret_str .= $red_message; |
| 453 |
$ret_str .= $/, " * ", '-' x 70, $/; |
| 454 |
return $ret_str; |
| 455 |
} else { |
| 456 |
print $q->font({color=>'red'}, $q->pre($red_message)); |
| 457 |
print $q->hr(); |
| 458 |
}; |
| 459 |
}; |
| 460 |
|
| 461 |
## Big table of Atoms keywords, including operational and unit cell parameters |
| 462 |
sub atoms_keywords { |
| 463 |
my $q = $_[0]; |
| 464 |
my $r_values = $_[1]; |
| 465 |
## Operational parameters and space group |
| 466 |
print |
| 467 |
$q->startform(), |
| 468 |
#$q->hidden('debug', $values{debug}); |
| 469 |
$q->table($table_params, |
| 470 |
$q->Tr($table_row, |
| 471 |
$q->td({-colspan=>6}, |
| 472 |
$q->submit(-name=>'Run ATOMS', |
| 473 |
-value=>'Run ATOMS'), |
| 474 |
$q->submit(-name=>'Clear', |
| 475 |
-value=>'Clear'), |
| 476 |
$q->reset )), |
| 477 |
$q->Tr($table_row, |
| 478 |
$q->td($q->a({href=>"$atoms_help#title"}, |
| 479 |
$q->b('Titles'))), |
| 480 |
$q->td({-colspan=>5}, |
| 481 |
$q->textarea(-name=>'titles', |
| 482 |
-default=>$$r_values{titles}, |
| 483 |
-rows=>6, -columns=>50))), |
| 484 |
$q->Tr($table_row, |
| 485 |
[ |
| 486 |
$q->td({-colspan=>6}, $q->b('Operational Parameters')), |
| 487 |
$q->td([$q->a({href=>"$atoms_help#space_group"}, |
| 488 |
$q->b('Space', $q->br(), 'Group: ')), |
| 489 |
$q->textfield(-name=>'space_group', |
| 490 |
-default=>$$r_values{space_group}, |
| 491 |
-size=>10, -maxlength=>20), |
| 492 |
$q->a({href=>"$atoms_help#rmax"}, |
| 493 |
$q->b('Rmax: ')), |
| 494 |
$q->textfield(-name=>'rmax', |
| 495 |
-default=>$$r_values{rmax}, |
| 496 |
-size=>10, -maxlength=>20), |
| 497 |
$q->a({href=>"$atoms_help#edge"}, |
| 498 |
$q->b('Edge: ')), |
| 499 |
$q->popup_menu(-name=>'edge', |
| 500 |
-values=>[@edge_names], |
| 501 |
-default=>$$r_values{edge},) |
| 502 |
]), |
| 503 |
]), |
| 504 |
$q->Tr($table_row, |
| 505 |
$q->td($q->a({href=>"$atoms_help#output"}, |
| 506 |
$q->b('Output', $q->br(), 'Type: '))), |
| 507 |
$q->td($q->popup_menu(-name=>'atp', |
| 508 |
-values=>[@atp_files], |
| 509 |
-default=>$$r_values{atp}, |
| 510 |
-labels=>\%atp)), |
| 511 |
$q->td($q->a({href=>"$atoms_help#shift"}, |
| 512 |
$q->b('Shift: '))), |
| 513 |
$q->td($q->textfield(-name=>'shiftx', |
| 514 |
-default=>$$r_values{'shiftx'}, |
| 515 |
-size=>10, -maxlength=>20)), |
| 516 |
$q->td($q->textfield(-name=>'shifty', |
| 517 |
-default=>$$r_values{'shifty'}, |
| 518 |
-size=>10, -maxlength=>20)), |
| 519 |
$q->td($q->textfield(-name=>'shiftz', |
| 520 |
-default=>$$r_values{'shiftz'}, |
| 521 |
-size=>10, -maxlength=>20)), |
| 522 |
), |
| 523 |
$q->Tr($table_row, |
| 524 |
[ |
| 525 |
$q->td({-colspan=>6,}, |
| 526 |
$q->b('Lattice Constants and Angles')), |
| 527 |
$q->td([$q->a({href=>"$atoms_help#abc"}, |
| 528 |
$q->b('A: ')), |
| 529 |
$q->textfield(-name=>'a', |
| 530 |
-default=>$$r_values{'a'}, |
| 531 |
-size=>10, -maxlength=>20), |
| 532 |
$q->a({href=>"$atoms_help#abc"}, |
| 533 |
$q->b('B: ')), |
| 534 |
$q->textfield(-name=>'b', |
| 535 |
-default=>$$r_values{'b'}, |
| 536 |
-size=>10, -maxlength=>20), |
| 537 |
$q->a({href=>"$atoms_help#abc"}, |
| 538 |
$q->b('C: ')), |
| 539 |
$q->textfield(-name=>'c', |
| 540 |
-default=>$$r_values{'c'}, |
| 541 |
-size=>10, -maxlength=>20)]), |
| 542 |
$q->td([$q->a({href=>"$atoms_help#alpha"}, |
| 543 |
$q->b('Alpha: ')), |
| 544 |
$q->textfield(-name=>'alpha', |
| 545 |
-default=>$$r_values{'alpha'}, |
| 546 |
-size=>10, -maxlength=>20), |
| 547 |
$q->a({href=>"$atoms_help#beta"}, |
| 548 |
$q->b('Beta: ')), |
| 549 |
$q->textfield(-name=>'beta', |
| 550 |
-default=>$$r_values{'beta'}, |
| 551 |
-size=>10, -maxlength=>20), |
| 552 |
$q->a({href=>"$atoms_help#gamma"}, |
| 553 |
$q->b('Gamma: ')), |
| 554 |
$q->textfield(-name=>'gamma', |
| 555 |
-default=>$$r_values{'gamma'}, |
| 556 |
-size=>10, -maxlength=>20)]), |
| 557 |
$q->td({-colspan=>6}, |
| 558 |
$q->submit(-name=>'Run ATOMS', |
| 559 |
-value=>'Run ATOMS'), |
| 560 |
$q->submit(-name=>'Clear', |
| 561 |
-value=>'Clear'), |
| 562 |
$q->reset ), |
| 563 |
])); |
| 564 |
print $q -> p(); |
| 565 |
}; |
| 566 |
|
| 567 |
## Big table of site parameters |
| 568 |
sub site_table { |
| 569 |
my $q = $_[0]; |
| 570 |
my $r_values = $_[1]; |
| 571 |
my @sites = &make_n_sites($r_values); |
| 572 |
print $q->table($table_params, |
| 573 |
$q->Tr($table_row, |
| 574 |
[ |
| 575 |
$q->td({-colspan=>6}, |
| 576 |
$q->b('Table of Crystallographic Sites')), |
| 577 |
$q->th([$q->a({href=>"$atoms_help#central"}, 'Cent.'), |
| 578 |
$q->a({href=>"$atoms_help#element"}, 'Element'), |
| 579 |
$q->a({href=>"$atoms_help#xyz"}, 'X'), |
| 580 |
$q->a({href=>"$atoms_help#xyz"}, 'Y'), |
| 581 |
$q->a({href=>"$atoms_help#xyz"}, 'Z'), |
| 582 |
$q->a({href=>"$atoms_help#tag"}, 'Tag')]), |
| 583 |
@sites, |
| 584 |
$q->td({-colspan=>6}, |
| 585 |
$q->submit(-name=>'Run ATOMS', |
| 586 |
-value=>'Run ATOMS'), |
| 587 |
$q->submit(-name=>'Clear', |
| 588 |
-value=>'Clear'), |
| 589 |
$q->reset ), |
| 590 |
$q->td({-colspan=>6}, |
| 591 |
$q->b('Redisplay with this many sites:'), |
| 592 |
$q->textfield(-name=>'nsites', |
| 593 |
-default=>$$r_values{'nsites'}, |
| 594 |
-size=>3, -maxlength=>20), |
| 595 |
$q->submit(-value=> 'Do it!', |
| 596 |
-name=>'redisplay'), |
| 597 |
$q->a({href=>"$atoms_help#overview"}, |
| 598 |
$q->b('Explain')) ), |
| 599 |
##($q->param('list_entry')) ? |
| 600 |
##$q->td({-colspan=>6}, |
| 601 |
## $q->b('Press here to redisplay with ' . |
| 602 |
## 'text entry of element symbols:'), |
| 603 |
## $q->submit(-name=>'text_entry', |
| 604 |
## -value=>'Do it!'), |
| 605 |
## $q->a({href=>"$atoms_help#overview"}, |
| 606 |
## $q->b('Explain')) ) : |
| 607 |
##$q->td({-colspan=>6}, |
| 608 |
## $q->b('Press here to redisplay with ' . |
| 609 |
## 'list entry of element symbols:'), |
| 610 |
## $q->submit(-name=>'list_entry', |
| 611 |
## -value=>'Do it!'), |
| 612 |
## $q->a({href=>"$atoms_help#overview"}, |
| 613 |
## $q->b('Explain')) ), |
| 614 |
])); |
| 615 |
print $q->endform; |
| 616 |
}; |
| 617 |
|
| 618 |
|
| 619 |
## trailing materials for atoms data input page |
| 620 |
sub bottom { |
| 621 |
my $q = $_[0]; |
| 622 |
my $r_values = $_[1]; |
| 623 |
print |
| 624 |
$q->hr(), |
| 625 |
"Web$atoms version $version ($date)", $q->br(), |
| 626 |
"$atoms is copyright © 1998-2005 Bruce Ravel", $q->br(), |
| 627 |
$q->a({href=>$atoms_home}, "$atoms homepage"), $q->br(), |
| 628 |
$q->a({href=>$bruce_home}, "Bruce's homepage"); |
| 629 |
|
| 630 |
print $q->end_html, $/; # end the HTML |
| 631 |
}; |
| 632 |
|
| 633 |
|
| 634 |
## generate a list of table rows for the sites |
| 635 |
sub make_n_sites { |
| 636 |
my $r_values = $_[0]; |
| 637 |
my $ns = $$r_values{nsites}; |
| 638 |
my $total = $ns + 1; |
| 639 |
my @table = (); |
| 640 |
my %labels = (); |
| 641 |
map {$labels{$_} = ' '.$_} (0..$ns); |
| 642 |
my @radio = $q->radio_group(-name=>'central_index', -values=>[(1..$ns)], |
| 643 |
-default=>$$r_values{central_index}, |
| 644 |
-labels=>\%labels); |
| 645 |
while ($ns) { |
| 646 |
my $this = $total - $ns--; |
| 647 |
my $elem = ($q->param('text_entry')) ? |
| 648 |
$q->textfield(-name=>'elem'.$this, |
| 649 |
-default=>$$r_values{'elem'.$this}, |
| 650 |
-size=>3, -maxlength=>20) : |
| 651 |
$q->popup_menu(-name=>'elem'.$this, |
| 652 |
-values=>[@elem_names], |
| 653 |
-default=>$$r_values{'elem'.$this},); |
| 654 |
|
| 655 |
my @site = ( |
| 656 |
$radio[$this-1], |
| 657 |
$elem, |
| 658 |
$q->textfield(-name=>'x'.$this, |
| 659 |
-default=>$$r_values{'x'.$this}, |
| 660 |
-size=>8, -maxlength=>20), |
| 661 |
$q->textfield(-name=>'y'.$this, |
| 662 |
-default=>$$r_values{'y'.$this}, |
| 663 |
-size=>8, -maxlength=>20), |
| 664 |
$q->textfield(-name=>'z'.$this, |
| 665 |
-default=>$$r_values{'z'.$this}, |
| 666 |
-size=>8, -maxlength=>20), |
| 667 |
$q->textfield(-name=>'tag'.$this, |
| 668 |
-default=>$$r_values{'tag'.$this}, |
| 669 |
-size=>10, -maxlength=>20) |
| 670 |
); |
| 671 |
push @table, $q->td([@site]); |
| 672 |
}; |
| 673 |
return @table; |
| 674 |
}; |
| 675 |
|
| 676 |
|
| 677 |
sub import_data { |
| 678 |
my ($fname, $keys, $r_values) = @_; |
| 679 |
unless (-e $fname) { |
| 680 |
$red_message .= $q->pre("Error reading $fname.\n$!"); |
| 681 |
return; |
| 682 |
}; |
| 683 |
$keys -> parse_input($fname, 2); |
| 684 |
foreach my $v (qw(a b c alpha beta gamma rmax)) { |
| 685 |
($keys->{$v}) and $$r_values{$v} = $keys->{$v}; |
| 686 |
}; |
| 687 |
($keys->{space}) and $$r_values{space_group} = $keys->{space}; |
| 688 |
($keys->{title}) and $$r_values{titles} = join($/,@{$keys->{title}}); |
| 689 |
if ($keys->{shift}) { |
| 690 |
$$r_values{shiftx} = $ {$keys->{shift}}[0]; |
| 691 |
$$r_values{shifty} = $ {$keys->{shift}}[1]; |
| 692 |
$$r_values{shiftz} = $ {$keys->{shift}}[2]; |
| 693 |
}; |
| 694 |
if ($keys->{sites}) { |
| 695 |
my $i = 0; |
| 696 |
foreach my $s (@{$keys->{sites}}) { |
| 697 |
++$i; |
| 698 |
$$r_values{"elem".$i} = $$s[0]; |
| 699 |
$$r_values{"x".$i} = $$s[1]; |
| 700 |
$$r_values{"y".$i} = $$s[2]; |
| 701 |
$$r_values{"z".$i} = $$s[3]; |
| 702 |
$$r_values{"tag".$i} = $$s[4]; |
| 703 |
(lc($$s[4]) eq lc($keys->{core})) and $$r_values{central_index} = $i; |
| 704 |
}; |
| 705 |
$$r_values{nsites} = $i; |
| 706 |
}; |
| 707 |
undef($keys->{core}); |
| 708 |
}; |
| 709 |
|
| 710 |
## Local Variables: |
| 711 |
## time-stamp-line-limit: 25 |
| 712 |
## End: |