Debian Codegraph @

lib/Xray/ATP.pm

raw
1 package Xray::ATP;
2 ######################################################################
3 ## This is the Xray::ATP.pm module. It exports a single function,
4 ## parse_atp, which is the output engine for Atoms.
5 ##
6 ## This program is copyright (c) 1998-2006 Bruce Ravel
7 ## <[email protected]>
8 ## http://cars9.uchicago.edu/~ravel/software/
9 ##
10 ## -------------------------------------------------------------------
11 ## All rights reserved. This program is free software; you can
12 ## redistribute it and/or modify it under the same terms as Perl
13 ## itself.
14 ##
15 ## This program is distributed in the hope that it will be useful,
16 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ## Artistic License for more details.
19 ## -------------------------------------------------------------------
20 ##
21 ######################################################################
22 ## Time-stamp: <1999/12/03 09:05:33 bruce>
23 ######################################################################
24 ## Code:
25
26 =head1 NAME
27
28 Xray::ATP - Output engine for Atoms
29
30 =head1 SYNOPSIS
31
32 use Xray::ATP;
33 ($output, $is_feff) =
34 parse_atp($atp, $cell, $keywords, \@cluster,
35 \@neutral, \$contents);
36
37 See L<Xray::Atoms> for a discussion of the arguments to C<parse_atp>.
38
39 =head1 DESCRIPTION
40
41 This module exports the C<parse_atp> function, which is the output
42 engine used by Atoms. It takes an atp file type a
43 cell object, a keywords object, references to two lists, and a
44 reference to a scalar as its input. On return, it fills the scalar
45 with the text string output and returns a two element array. The two
46 elements are the default filename taken from the atp file and a flag
47 indicating whether the output is intended for Feff.
48
49 This module must be used in conjunction with <Xray::Atoms>. It exists
50 as a separate module because about half the length of the Atoms module
51 was the C<parse_atp> function and its utilities. It seemed more
52 efficient from a maintenance viewpoint to make two modules.
53
54 =cut
55
56
57
58 use strict;
59 use vars qw($VERSION $cvs_info $module_version @ISA @EXPORT @EXPORT_OK);
60
61 require Exporter;
62
63 @ISA = qw(Exporter AutoLoader);
64 # Items to export into callers namespace by default. Note: do not export
65 # names by default without a very good reason. Use EXPORT_OK instead.
66 # Do not simply export all your public functions/methods/constants.
67 @EXPORT = qw(parse_atp);
68 #@EXPORT_OK = ;
69
70 $cvs_info = '$Id: ATP.pm,v 1.4 2000/11/21 01:09:32 bruce Exp $ ';
71 $module_version = 1.41; #(split(' ', $cvs_info))[2] || "pre_release";
72 $VERSION = $module_version;
73
74 use Carp;
75 use Xray::Atoms qw(rcdirectory absorption mcmaster i_zero self);
76 use Xray::Xtal;
77 use Xray::Absorption;
78 use Chemistry::Elements qw(get_Z);
79 use Text::ParseWords;
80 use constant EV2RYD => 13.605698;
81 use constant PI => 3.14159265358979323844;
82 use constant EPSILON => 0.00001;
83
84
85 ## -------------------------------------------------------------------
86 ## This beast handles the atoms template (atp) files
87
88 ## the arguments are
89 ## 1. atp type
90 ## 2. reference to a cell
91 ## 3. reference to the keyword data
92 ## 4. reference to a cluster (or the calculation for dafs)
93 ## 5. reference to an array, (not used -- a placeholder)
94 ## 6. reference to a scalar (filled with the output data on return)
95 sub parse_atp {
96 my ($atptype, $cell, $keywords, $r_cluster, $r_neutral, $r_contents) = @_;
97 my %ipots = ();
98 my $ipot_style = "species";
99 my @overfull = ();
100 my ($central, $xcenter, $ycenter, $zcenter, $is_host) =
101 $cell -> central($keywords->{"core"});
102 ($is_host) or $keywords->{"dopant_core"} = $central;
103
104 ## meta variables
105 my %meta_data = ("precision" => "%9.5f",
106 "filetype" => "file",
107 "inc_begin" => 0,
108 "list_type" => "",
109 "is_feff" => 0,
110 "is_gnxas" => 0,
111 "occupancy" => 1,
112 "small_sphere" => 2.2,
113 "output_file" => "");
114
115 ## find and fetch the chosen atp file
116 ## search in the user's .atoms directory, then in the system atp directory
117 $meta_data{output_file} = $atptype . ".out";
118 ($atptype eq "test") and $meta_data{output_file} = $^O . ".dat";
119 my ($atpbase, $rcdir) = ($atptype.".atp", &rcdirectory);
120 my $atpfile = File::Spec->catfile($rcdir, "atp", $atpbase);
121 (-e $atpfile) or
122 $atpfile = File::Spec->catfile($Xray::Atoms::atp_dir, $atpbase);
123 (-e $atpfile) or do {
124 warn "No such atp file \"$atptype\"\n";
125 return 0;
126 };
127 open (ATP, $atpfile) || die "Could not open atp file \"$atptype\"\n";
128 my @atp = <ATP>; # slurp in the atp file
129 close ATP;
130
131 ## set up piles of useful variables
132 my %edges = (
133 "no" => 0, "k" => 1, "l1" => 2, "l2" => 3, "l3" => 4,
134 "m1" => 5, "m2" => 6, "m3" => 7, "m4" => 8, "m5" => 9,
135 "n1" => 10, "n2" => 11, "n3" => 12, "n4" => 13, "n5" => 14,
136 "n6" => 15, "n7" => 16, "o1" => 17, "o2" => 18, "o3" => 19,
137 "o4" => 20, "o5" => 21, "o6" => 22, "o7" => 23, "p1" => 24,
138 "p2" => 25, "p3" => 26
139 );
140 my %gnxas_class = ( "triclinic" => "T",
141 "cubic" => "C",
142 "hexagonal" => "H",
143 "monoclinic" => "M",
144 "orthorhombic" => "O",
145 "trigonal" => "R",
146 "tetragonal" => "E");
147
148 ## simple substitutions
149 my ($aa, $bb, $cc, $aalpha, $bbeta, $ggamma, $space, $given,
150 $setting, $bravais) =
151 $cell -> attributes("A", "B", "C", "Alpha", "Beta", "Gamma",
152 "Space_group", "Given_group", "Setting", "Bravais");
153 ##@bravais ||= ("none");
154 ##my @bravais = defined($bravais) ? @$bravais : ("none");
155 my $r1 = $$r_cluster[1][4] || 0;
156 ($atptype =~ /powder/) and $r1 = 0;
157 my $qvec = $keywords->{"qvec"} || [0, 0, 0];
158 my $shift_vec = $keywords->{"shift"} || [0, 0, 0];
159 my $edge_energy =
160 Xray::Absorption -> get_energy($central, $keywords->{"edge"});
161 my $abslist =
162 join(",", &get_abs_list($cell, $keywords, $central, \%meta_data));
163 my $gnid = (@{$keywords->{"title"}}) ?
164 (split(" ", $ {$keywords->{"title"}}[0]))[0] : "abc";
165 $gnid ||= "abc"; # the bizarre case of "title = "
166 my %match_words =
167 (
168 # central atom tokens
169 "central" => ucfirst($central),
170 "ctag" => $keywords->{"core"},
171 "fxc" => $keywords->{"cformulas"}->[0],
172 "fyc" => $keywords->{"cformulas"}->[1],
173 "fzc" => $keywords->{"cformulas"}->[2],
174 # edge tokens
175 "edge" => ucfirst($keywords->{"edge"}),
176 "iedge" => $edges{lc($keywords->{"edge"})},
177 "eedge" => sprintf($meta_data{precision}, $edge_energy),
178 "redge" => sprintf($meta_data{precision}, $edge_energy/EV2RYD),
179 # distance tokens
180 "nclus" => $#{$r_cluster}+1,
181 "rmax" => sprintf($meta_data{precision}, $keywords->{"rmax"}),
182 "rnn" => sprintf($meta_data{precision}, sqrt($r1)),
183 "rss" => sprintf($meta_data{precision},
184 $meta_data{small_sphere}*sqrt($r1)+0.00001),
185 # unit cell tokens
186 "a" => sprintf($meta_data{precision}, $aa),
187 "b" => sprintf($meta_data{precision}, $bb),
188 "c" => sprintf($meta_data{precision}, $cc),
189 "alpha" => sprintf($meta_data{precision}, $aalpha),
190 "beta" => sprintf($meta_data{precision}, $bbeta),
191 "gamma" => sprintf($meta_data{precision}, $ggamma),
192 "space" => ucfirst($space),
193 "given" => $given,
194 "group" => $$Xray::Xtal::r_space_groups{$space}->{number},
195 "class" => $cell -> crystal_class(),
196 "bravais" => Xray::Atoms::bravais_string($bravais,$meta_data{is_gnxas}),
197 "setting" => $setting,
198 # non-data tokens
199 "os" => $^O,
200 "n" => $/,
201 # gnxas tokens
202 "gnclass" => $gnxas_class{$cell -> crystal_class()},
203 "gnid" => $gnid,
204 "nabs" => &get_nabs($cell, $central),
205 "abslist" => $abslist,
206 # dafs tokens
207 "emin" => sprintf($meta_data{precision}, $keywords->{"emin"} || 0),
208 "emax" => sprintf($meta_data{precision}, $keywords->{"emax"} || 0),
209 "estep" => sprintf($meta_data{precision}, $keywords->{"estep"} || 0),
210 "reflection" => "(" . join(" ", map {sprintf "%d", $_} @$qvec) . ")",
211 "dspacing" => sprintf($meta_data{precision}, $cell -> d_spacing(@$qvec)),
212 "thickness" => sprintf($meta_data{precision}, $keywords->{"thickness"} || 0),
213 # powder tokens
214 "energy" => sprintf($meta_data{precision}, $keywords->{"energy"} || 0),
215 "lambda" => sprintf($meta_data{precision}, $keywords->{"lambda"} || 0),
216 );
217 my @numeric =
218 qw(eedge redge rmax rnn rss a b c alpha beta gamma emin emax estep dspacing);
219 map { $match_words{$_} =~ s/0{2,}$/0/ } @numeric;
220 $match_words{'redge'} =~ s/ //g;
221 $match_words{'gnid'} =~ s/\W//g;
222
223 while (@atp) {
224 ## the game is to interpret $line and modify it as appropriate then,
225 ## outside the switch, print out the modified $line
226 my $line = shift @atp;
227 (my $trimmed_line = $line) =~ s/^\s+//; # trim leading blanks
228 ATP_SWITCH: {
229
230 ## ========================== this is an atp <com>ment
231 ($trimmed_line =~ /^\<com/) && do {
232 $line = "";
233 last ATP_SWITCH;
234 };
235
236 ## ========================== this is file(1) magic
237 ($trimmed_line =~ /^\<atp/) && do {
238 $line = "";
239 last ATP_SWITCH;
240 };
241
242 ## ========================== meta data line
243 ($trimmed_line =~ /^\<meta/) && do {
244 chomp $line;
245 $line =~ tr/\<>/ /; # this precludes having < or > in the meta data
246 my @words = &quotewords('\s+', 0, $line);
247 shift @words; # shift off <meta
248 while (@words) {
249 my $word = shift @words;
250 next unless $word;
251 META: {
252 ($word eq ":precision") && do {
253 $meta_data{precision} = shift @words;
254 $meta_data{precision} = "%" . $meta_data{precision} . "f";
255 map { ($match_words{$_} =
256 sprintf($meta_data{precision}, $match_words{$_}))
257 =~ s/0{2,}$/0/
258 } @numeric;
259 last META;
260 };
261 ($word eq ":file") && do {
262 $meta_data{filetype} = shift @words;
263 last META;
264 };
265 ($word eq ":output") && do {
266 $meta_data{output_file} = shift @words;
267 last META;
268 };
269 ($word eq ":incbegin") && do {
270 $meta_data{inc_begin} = shift @words;
271 last META;
272 };
273 ($word eq ":list") && do {
274 $meta_data{list_type} = shift @words;
275 last META;
276 };
277 ($word eq ":feff") && do {
278 $meta_data{is_feff} = shift @words;
279 ($meta_data{is_feff}) and $meta_data{occupancy} = 0;
280 last META;
281 };
282 ($word eq ":gnxas") && do {
283 $meta_data{is_gnxas} = shift @words;
284 $match_words{"bravais"} =
285 Xray::Atoms::bravais_string($bravais,$meta_data{is_gnxas}),
286 ($meta_data{is_gnxas}) and $meta_data{occupancy} = 0;
287 ($meta_data{is_gnxas}) and
288 map { $match_words{$_} =~ s/^ +// } qw(rmax rnn rss);
289 last META;
290 };
291 ($word eq ":occupancy") && do {
292 $meta_data{occupancy} = shift @words;
293 last META;
294 };
295 ($word eq ":margin") && do {
296 $meta_data{margin} = shift @words;
297 $keywords->make(overfull_margin=>$meta_data{margin});
298 last META;
299 };
300 ($word eq ":sphere") && do {
301 $meta_data{small_sphere} = shift @words;
302 if (@$r_cluster) {
303 ($match_words{"rss"} =
304 sprintf($meta_data{precision},
305 $meta_data{small_sphere}*
306 sqrt($$r_cluster[1][4])+0.00001))
307 =~ s/0{2,}$/0/;
308 };
309 last META;
310 };
311 };
312 };
313 ## fix up the value for nclus
314 #($list_type eq "feff8") &&
315 # ($match_words{"nclus"} = $#{$r_neutral}+1);
316 LIST: {
317 ($meta_data{list_type} eq "symmetry") && do {
318 my $p = $cell -> get_symmetry_table();
319 $match_words{"nclus"} = $#{$p} + 1;
320 last LIST;
321 };
322 ($meta_data{list_type} eq "atoms") && do {
323 my $p = $keywords->{'sites'};
324 $match_words{"nclus"} = $#{$p} + 1;
325 $match_words{abslist} =
326 join(",", &get_abs_list($cell, $keywords,
327 $central, \%meta_data));
328 last LIST;
329 };
330 ($meta_data{list_type} eq "unit") && do {
331 my ($contents) = $cell -> attributes("Contents");
332 $match_words{"nclus"} = $#{$contents} + 1;
333 last LIST;
334 };
335 ($meta_data{list_type} eq "overfull") && do {
336 @overfull = $cell->overfull($meta_data{margin});
337 $match_words{"nclus"} = $#overfull + 1;
338 last LIST;
339 };
340 ($meta_data{list_type} eq "cluster") && do {
341 my $nc = 0;
342 map { my ($h) = $ {$$_[3]} -> attributes("Host");
343 ($h eq 1) and ++$nc } @$r_cluster;
344 $match_words{"nclus"} = $nc;
345 last LIST;
346 };
347 };
348 $line = "";
349 last ATP_SWITCH;
350 };
351
352
353 ## ========================== id line
354 ($trimmed_line =~ /^\<id/) && do {
355 &ATP_id(\$line, $r_contents, $keywords, \%meta_data);
356 last ATP_SWITCH;
357 };
358
359 ## ========================== ease line
360 (($trimmed_line =~ /^\<ease/) or ($trimmed_line =~ /^\<fuse/)) && do {
361 &ATP_ease(\$line, $r_contents);
362 last ATP_SWITCH;
363 };
364
365 ## ========================== absorption data resource
366 ($trimmed_line =~ /^\<resource/) && do {
367 &ATP_resource(\$line, $r_contents);
368 last ATP_SWITCH;
369 };
370
371 ## ========================== shift vector
372 ($trimmed_line =~ /^\<shift/) && do {
373 &ATP_shift(\$line, $r_contents, $shift_vec, \%meta_data);
374 last ATP_SWITCH;
375 };
376
377 ## ========================== GNXAS cell lines
378 ($trimmed_line =~ /^\<gncell/) && do {
379 &ATP_gncell(\$line, $r_contents, $cell, \%match_words, \%meta_data);
380 last ATP_SWITCH;
381 };
382
383 ## ========================== corrections
384 ($trimmed_line =~ /^\<corrections/) && do {
385 unless (Xray::Absorption ->
386 data_available($central,$keywords->{"edge"})) {
387 $line = "";
388 last ATP_SWITCH;
389 };
390 if ($keywords->{"edge"} =~ /^[mnop]/i) {
391 $line = "";
392 last ATP_SWITCH;
393 };
394 &ATP_corrections(\$line, $r_contents, $cell, $keywords, \$central);
395 last ATP_SWITCH;
396 };
397
398 ## ========================== print title lines
399 ($trimmed_line =~ /^\<title/) && do {
400 &ATP_title(\$line, $r_contents, $keywords);
401 last ATP_SWITCH;
402 };
403
404 ## ========================== potentials list
405 ($trimmed_line =~ /^\<potentials/) && do {
406 if ($meta_data{list_type} eq "dafs") {
407 $line = shift @atp;
408 $line = "";
409 last ATP_SWITCH;
410 };
411 my $ref = &ATP_potentials(\$line, $r_contents, $cell, $keywords, $r_cluster,
412 \@atp, \$ipot_style, \%ipots, $central);
413 %ipots = %$ref;
414 ##print "after ATP_potentials: ", join("|",%ipots), $/;
415 last ATP_SWITCH;
416 };
417
418 ## ========================== atoms list
419 ($trimmed_line =~ /^\<list/) && do {
420 ##print "before ATP_atoms: ", join("|",%ipots), $/;
421 &ATP_atoms(\$line, $r_contents, $cell, $keywords, $r_cluster,
422 $r_neutral, \%match_words, \@atp, \@overfull,
423 \$ipot_style, \%ipots, \%meta_data);
424 last ATP_SWITCH;
425 };
426
427 ## ========================== dafs list
428 ($trimmed_line =~ /^\<dafs/) && do {
429 unless ($meta_data{list_type} eq "dafs") {
430 $line = shift @atp;
431 $line = "";
432 last ATP_SWITCH;
433 };
434 &ATP_dafs(\$line, $r_contents, $r_cluster, \@atp, \%meta_data);
435 last ATP_SWITCH;
436 };
437
438 ## ========================== powder list
439 ($trimmed_line =~ /^\<powder/) && do {
440 unless ($meta_data{list_type} eq "powder") {
441 $line = shift @atp;
442 $line = "";
443 last ATP_SWITCH;
444 };
445 &ATP_powder(\$line, $cell, $r_contents, $r_cluster, \@atp, \%meta_data);
446 last ATP_SWITCH;
447 };
448
449 ## ========================== any other line
450 do {
451 my $matchstring = join("|", keys %match_words);
452 $line =~ s/\<($matchstring)>/$match_words{$1}/go;
453 last ATP_SWITCH;
454 };
455
456 };
457
458 $$r_contents .= $line;
459 };
460 return ($meta_data{output_file}, $meta_data{is_feff});
461 };
462
463
464
465
466 ## subroutines for type 4 tokens (block structures) -----------
467
468 sub ATP_id {
469 my ($line, $r_contents, $keywords, $meta) = @_;
470 chomp $$line;
471 $$line =~ tr/\<>/ /; # this precludes having < or > in the prefix
472 my @words = &quotewords('\s+', 0, $$line);
473 my $prefix = "";
474 shift @words; # shift off <id
475 while (@words) {
476 my $word = shift @words;
477 next unless $word;
478 ID: {
479 ($word eq ":prefix") && do {
480 $prefix = shift @words;
481 last ID;
482 };
483 };
484 };
485 my $identity = $keywords->{'identity'} || $VERSION;
486 $$r_contents .= $prefix .
487 "This $$meta{filetype} was generated by $identity$/";
488 $$r_contents .= $prefix .
489 "Atoms written by and copyright (c) Bruce Ravel, 1998-2001$/";
490 $$line ="";
491 };
492
493 sub ATP_ease {
494 my ($line, $r_contents) = @_;
495 chomp $$line;
496 $$line =~ tr/\<>/ /; # this precludes having < or > in the prefix
497 my @words = &quotewords('\s+', 0, $$line);
498 my ($filetype, $prefix) = ("feff", "");
499 shift @words; # shift off <ease or <fuse
500 while (@words) {
501 my $word = shift @words;
502 next unless $word;
503 ID: {
504 ($word eq ":file") && do {
505 $filetype = shift @words;
506 last ID;
507 };
508 ($word eq ":prefix") && do {
509 $filetype = shift @words;
510 last ID;
511 };
512 };
513 };
514 $prefix ||= ($filetype eq "feff") ? " *!!&& " : "!!&& ";
515 $$line = "$/${prefix}Local Variables:$/";
516 $$line .= "${prefix}input-program-name: \"$filetype\"$/";
517 $$line .= "${prefix}End:$/";
518 };
519
520 sub ATP_resource {
521 my ($line, $r_contents) = @_;
522 chomp $$line;
523 $$line =~ tr/\<>/ /; # this precludes having < or > in the prefix
524 my $prefix = "";
525 my @words = &quotewords('\s+', 0, $$line);
526 shift @words; # shift off <reflection
527 while (@words) {
528 my $word = shift @words;
529 next unless $word;
530 ID: {
531 ($word eq ":prefix") && do {
532 $prefix = shift @words;
533 last ID;
534 };
535 };
536 };
537 $$r_contents .= $prefix . Xray::Absorption -> current_resource . $/;
538 $$line = "";
539 }
540
541
542 sub ATP_shift {
543 my ($line, $r_contents, $shift_vec, $meta) = @_;
544 chomp $$line;
545 $$line =~ tr/\<>/ /; # this precludes having < or > in the prefix
546 my $prefix = "";
547 my @words = &quotewords('\s+', 0, $$line);
548 shift @words; # shift off <shift
549 while (@words) {
550 my $word = shift @words;
551 next unless $word;
552 ID: {
553 ($word eq ":prefix") && do {
554 $prefix = shift @words;
555 last ID;
556 };
557 };
558 };
559 if ($$shift_vec[0] or $$shift_vec[1] or $$shift_vec[2]) {
560 $$r_contents .= $prefix . 'shift ' .
561 join(" ", map {sprintf $$meta{precision}, $_} @$shift_vec) . $/;
562 };
563 $$line = "";
564 };
565
566 sub ATP_gncell {
567 my ($line, $r_contents, $cell, $match_words, $meta) = @_;
568 my $comma = ',';
569 my $this_line .= sprintf($$meta{precision}, $$match_words{'a'});
570 my $this_class = $cell -> crystal_class();
571 CLASS_SWITCH: {
572 ($this_class eq "triclinic") && do {
573 $this_line .= join("", $comma, $$match_words{'b'}, $comma,
574 $$match_words{'c'}, $/,
575 $$match_words{'alpha'}, $comma,
576 $$match_words{'beta'}, $comma,
577 $$match_words{'gamma'});
578
579 last CLASS_SWITCH;
580 };
581 ($this_class eq "monoclinic") && do {
582 $this_line .= join("", $comma, $$match_words{'b'}, $comma,
583 $$match_words{'c'}, $/,
584 $$match_words{'beta'});
585
586 last CLASS_SWITCH;
587 };
588 ($this_class eq "orthorhombic") && do {
589 $this_line .= join("", $comma, $$match_words{'b'}, $comma,
590 $$match_words{'c'});
591 last CLASS_SWITCH;
592 };
593 (($this_class eq "tetragonal") or ($this_class eq "hexagonal")) && do {
594 $this_line .= join("", $comma, $$match_words{'c'});
595 last CLASS_SWITCH;
596 };
597 ($this_class eq "trigonal") && do {
598 $this_line .= join("", $comma,, $$match_words{'c'}, $/,
599 $$match_words{'beta'});
600 last CLASS_SWITCH;
601 };
602 };
603 $this_line .= $/;
604 $this_line =~ s/ //g;
605 $$r_contents .= $this_line;
606 $$line = "";
607 }
608
609 sub ATP_corrections {
610 my ($line, $r_contents, $cell, $keywords, $central) = @_;
611 chomp $$line;
612 $$line =~ tr/\<>/ /; # this precludes having < or > in the prefix
613 my @words = &quotewords('\s+', 0, $$line);
614 my $prefix = "";
615 my $write_line = 1;
616 my $units = "cm-1";
617 shift @words; # shift off <corrections
618 while (@words) {
619 my $word = shift @words;
620 next unless $word;
621 CORR: {
622 ($word eq ":prefix") && do {
623 $prefix = shift @words;
624 last CORR;
625 };
626 ($word eq ":prettyline") && do {
627 $write_line = shift @words;
628 last CORR;
629 };
630 ($word eq ":units") && do {
631 $units = shift @words;
632 last CORR;
633 };
634 };
635 };
636 my ($fluorescence) =
637 ($keywords->{"nitrogen"} > 0.001) ||
638 ($keywords->{"argon"} > 0.001) ||
639 ($keywords->{"krypton"} > 0.001);
640 my $prettyline = sprintf "%s%s$/", $prefix, "-- * " x 13;
641 my ($xsec, $delta, $density) =
642 absorption($cell, $$central, $keywords->{"edge"});
643 ($write_line) && ($$r_contents .= $prettyline);
644 if ($units eq 'microns') {
645 ## need to deal gracefully with the situation that $xsec or $delta
646 ## are 0, this will cause 0's to be written out
647 my $xx = $xsec || 10e10;
648 my $dd = $delta || 10e10;
649 $$r_contents .=
650 sprintf "%s total mu*x=1: %8.2f microns, unit edge step: %8.2f microns$/",
651 $prefix, 10000/$xx, 10000/$dd;
652 } else {
653 $$r_contents .=
654 sprintf "%s total mu = %8.2f cm^-1, delta_mu = %8.2f cm^-1$/",
655 $prefix, $xsec, $delta;
656 };
657 $$r_contents .=
658 sprintf "%s specific gravity = %6.3f$/", $prefix, $density;
659 my $sigmm = mcmaster($$central, $keywords->{"edge"});
660 ($write_line) && ($$r_contents .= $prettyline);
661 $units = "ang^2";
662 $$r_contents .=
663 sprintf "%s Normalization correction: %8.5f %s$/",
664 $prefix, $sigmm, $units;
665 if ($fluorescence) {
666 my $sigi0 = i_zero($$central, $keywords->{"edge"},
667 $keywords->{"nitrogen"},
668 $keywords->{"argon"},
669 $keywords->{"krypton"});
670 $$r_contents .=
671 sprintf "%s I0 correction: %8.5f %s$/",
672 $prefix, $sigi0, $units;
673 my ($ampsa, $sigsa) = self($$central, $keywords->{"edge"}, $cell);
674 $$r_contents .=
675 sprintf "%s self absorption correction: %8.5f %s$/",
676 $prefix, $sigsa, $units;
677 $$r_contents .=
678 sprintf "%s amplitude factor: %6.3f$/",
679 $prefix, $ampsa;
680 ($write_line) && ($$r_contents .= $prettyline);
681 $$r_contents .=
682 sprintf "%s net correction: %8.5f %s$/",
683 $prefix, $sigmm + $sigi0 + $sigsa, $units;
684 };
685 ($write_line) && ($$r_contents .= $prettyline);
686 $$line = "";
687 }
688
689 sub ATP_title {
690 my ($line, $r_contents, $keywords) = @_;
691 chomp $$line;
692 $$line =~ tr/\<>/ /; # this precludes having < or > in the prefix
693 my @words = &quotewords('\s+', 0, $$line);
694 my ($prefix, $lines) = ("",0);
695 shift @words; # shift off <titles
696 while (@words) {
697 my $word = shift @words;
698 next unless $word;
699 TITLES: {
700 ($word eq ":prefix") && do {
701 $prefix = shift @words;
702 last TITLES;
703 };
704 ($word eq ":lines") && do {
705 $lines = shift @words;
706 ($lines < 1) and $lines = 1;
707 last TITLES;
708 };
709 };
710 };
711 my $count = 0;
712 foreach my $title (@{$keywords->{"title"}}) {
713 ++$count;
714 ($lines) and ($count > $lines) and last;
715 $$r_contents .= $prefix . $title . $/;
716 };
717 if ($count == 0) {
718 $$r_contents .= $prefix . "..." . $/;
719 $count = 1;
720 };
721 if ($count < $lines) {
722 my $n = $lines - $count;
723 $$r_contents .= ($prefix.$/) x $n;
724 };
725 $$line = "";
726 };
727
728 ## subroutines for type 2 tokens (list structures) ------------
729
730 sub ATP_potentials {
731 my ($line, $r_contents, $cell, $keywords, $r_cluster, $atp, $ipot_style, $ipots, $central) = @_;
732 chomp $$line;
733 $$line =~ tr/\<>/ /;
734 my @words = &quotewords('\s+', 0, $$line);
735 $$ipot_style = "species"; # species, tags, sites
736 my ($gcd, $is_mol, $display) = (0, 0, 1);
737 shift @words; # shift off <potentials
738 while (@words) {
739 my $word = shift @words;
740 next unless $word;
741 POTS: {
742 ($word eq ":ipots") && do {
743 $$ipot_style = shift @words;
744 last POTS;
745 };
746 ($word eq ":gcd") && do {
747 $gcd = shift @words;
748 last POTS;
749 };
750 ($word eq ":mol") && do {
751 $is_mol = shift @words;
752 last POTS;
753 };
754 ($word eq ":display") && do {
755 $display = shift @words;
756 last POTS;
757 };
758 };
759 };
760 unless (($$ipot_style eq "tags") or ($$ipot_style eq "sites")) {
761 $$ipot_style = "species";
762 };
763 ##print "Potentials style is $$ipot_style\n";
764 ($display) and $$line = shift @$atp;
765 ## central atom information
766 my $thisline = $$line;
767 my %matches = ("ipot" => 0,
768 "stoi" => 0.001,
769 "znum" => sprintf("%2d",&get_Z($central)),
770 "elem" => sprintf("%-10s",ucfirst($central)),
771 "l" => Xray::Absorption -> get_l($central) );
772 my $matchstring = join("|", keys %matches);
773 $thisline =~ s/(\<($matchstring)>)/$matches{$2}/go;
774 ($display) and $$r_contents .= $thisline;
775 ## and now all the rest ...
776 %$ipots =
777 $cell -> set_ipots($$ipot_style, $is_mol, $keywords->{"core"});
778 unless ($display) {
779 $$line = "";
780 last ATP_SWITCH;
781 };
782
783 #print join("|",%$ipots), $/;
784 $ipots = fix_ipots($ipots, $r_cluster, $$ipot_style);
785 #print join("|",%$ipots), $/;
786
787 my @keys = sort {$$ipots{$a} <=> $$ipots{$b}} (keys %$ipots);
788 my %stoi = &get_stoi($cell, \@keys, $$ipot_style, $gcd);
789 foreach my $key (@keys) {
790 my $thisline = $$line;
791 my $elem;
792 my $pot_label; # get the element symbol and the potential
793 if ($$ipot_style eq "species") { # label for the current
794 $elem = $key; # ipot scheme
795 $pot_label = sprintf("%-2s", ucfirst($elem));
796 } elsif ($$ipot_style eq "tags") {
797 TAG: foreach my $site (@{$cell->{Contents}}) {
798 if ($ {$$site[3]}->{Tag} eq $key) {
799 $elem = $ {$$site[3]}->{Element};
800 $pot_label = sprintf("%-10s", $key);
801 last TAG;
802 };
803 };
804 } elsif ($$ipot_style eq "sites") {
805 ID: foreach my $site (@{$cell->{Contents}}) {
806 if ($ {$$site[3]}->{Id} eq $key) {
807 $elem = $ {$$site[3]}->{Element};
808 my $tag = $ {$$site[3]}->{Tag};
809 $pot_label = sprintf("%-10s", $tag);
810 last ID;
811 };
812 };
813 };
814 my ($ip, $zn, $l, $stoi) =
815 ($$ipots{$key},
816 sprintf("%2d",&get_Z($elem)||0),
817 Xray::Absorption -> get_l($elem),
818 $stoi{$key});
819 $elem = sprintf("%-2s",ucfirst($elem));
820 my %matches = ("ipot" => $ip,
821 "znum" => $zn,
822 "elem" => sprintf("%-10s", $pot_label),
823 "l" => $l,
824 "stoi" => $stoi,);
825 my $matchstring = join("|", keys %matches);
826 $thisline =~ s/(\<($matchstring)>)/$matches{$2}/go;
827 $$r_contents .= $thisline;
828 };
829 $$line = "";
830 return $ipots;
831 };
832
833 ## this ain't pretty...
834 sub ATP_atoms {
835 my ($line, $r_contents, $cell, $keywords, $r_cluster,
836 $r_neutral, $match_words, $atp, $overfull,
837 $ipot_style, $ipots, $meta) = @_;
838 chomp $$line;
839 $$line =~ tr/\<>/ /;
840 my @words = &quotewords('\s+', 0, $$line);
841 my $style = "cluster"; # unit, overfull
842 shift @words; # shift off <list
843 while (@words) {
844 my $word = shift @words;
845 next unless $word;
846 ATOMS: {
847 ($word eq ":style") && do {
848 $style = shift @words;
849 last ATOMS;
850 };
851 ($word eq ":margin") && do {
852 $keywords->{"overfull_margin"} = shift @words;
853 last ATOMS;
854 };
855 };
856 };
857
858 $$line = shift @$atp;
859
860 my $inc = $$meta{inc_begin};
861 my $r_atom_list;
862 my $bigger = ($#{$r_cluster} > $#{$r_neutral}) ?
863 $#{$r_cluster} : $#{$r_neutral};
864 my @indeces = map {""} (0..$bigger+1);
865 my @bounce = map {1} (0..$bigger+1);
866 LISTTYPE: {
867 ($style eq "cluster") && do {
868 $r_atom_list = $r_cluster;
869 ($$line =~ /\<itag>/) && (@indeces = fetch_indeces($r_cluster));
870 ($$line =~ /\<1bou>/) && (@bounce = one_bounce($r_cluster));
871 last LISTTYPE;
872 };
873 ($style eq "neutral") && do {
874 $r_atom_list = $r_neutral;
875 ($$line =~ /\<itag>/) && (@indeces = fetch_indeces($r_neutral));
876 $$match_words{"nclus"} = $#{$r_neutral}+1;
877 last LISTTYPE;
878 };
879 ($style eq "unit") && do {
880 my ($contents) = $cell -> attributes("Contents");
881 $r_atom_list = \@{$contents};
882 ($$line =~ /\<itag>/) && (@indeces = count_sites($r_atom_list));
883 last LISTTYPE;
884 };
885 ($style eq "atoms") && do {
886 $r_atom_list = $keywords->{'sites'};
887 last LISTTYPE;
888 };
889 ($style eq "overfull") && do {
890 # (@$overfull) or
891 @$overfull = $cell->overfull($keywords->{"overfull_margin"});
892 $r_atom_list = $overfull;
893 last LISTTYPE;
894 };
895 ## this one's a bit different...
896 ($style eq "symmetry") && do {
897 &symmetry_table($cell, $$line, $r_contents, $$meta{is_gnxas});
898 $$line = "";
899 return;
900 #last ATP_SWITCH;
901 };
902 };
903 if (($$meta{list_type} eq "dafs") and ($style !~ /atoms|unit|overfull/)) {
904 $$line = shift @$atp;
905 $$line = "";
906 ## an error message would be good ...
907 #last ATP_SWITCH;
908 return;
909 };
910
911 my $atoms_cnt = 0;
912 my %atoms_seen;
913 ATOMS: foreach my $atom (@$r_atom_list) {
914 my $thisline = $$line;
915 my ($el, $tag, $thisipot, $x, $y, $z, $occ, $host);
916 my ($file, $b, $bx, $by, $bz, $color, $valence) = ("", "", "", "", "", "");
917 my ($fx, $fy, $fz, $utag) = ("", "", "", "");
918 if ($style eq 'atoms') {
919 ($el, $x, $y, $z, $tag, $occ) = @$atom;
920 # next unless $occ;
921 ++$atoms_cnt;
922 $utag = $tag||ucfirst($el); #) =~ s/\s*$//;
923 if ( $atoms_seen{$utag}++ ) {
924 $utag .= '_' . $atoms_cnt;
925 };
926 $tag = sprintf("%-10s", $tag);
927 $occ = sprintf($$meta{precision}, $occ);
928 $thisipot = "";
929 } else {
930 ($el) = $ {$$atom[3]} -> attributes("Element");
931 $el = lc($el);
932 my $label; # get the correct hash key for the
933 if ($$ipot_style eq "species") { # current ipot scheme
934 $label = $el;
935 } elsif ($$ipot_style eq "tags") {
936 ($label) = $ {$$atom[3]} -> attributes("Tag");
937 } elsif ($$ipot_style eq "sites") {
938 ($label) = $ {$$atom[3]} -> attributes("Id");
939 };
940 ($tag) = $ {$$atom[3]} -> attributes("Tag");
941 $tag = sprintf("%-10s", $tag);
942 ($utag) = $ {$$atom[3]} -> attributes("Utag");
943 $utag = sprintf("%-13s", $utag);
944 $thisipot = $inc ? $$ipots{$label} : 0;
945 defined ($thisipot) or $thisipot = '?';
946 ($thisipot =~ /\d/) or $thisipot = '?';
947 ($host, $occ) = $ {$$atom[3]} -> attributes("Host", "Occupancy");
948 unless ($inc) { # check for dopant central atom
949 if ($keywords->{dopant_core} and (not $$meta{occupancy})) {
950 $el = $keywords->{dopant_core};
951 $tag = sprintf("%-10s", ucfirst($el));
952 $indeces[0] = sprintf("%-10s", $tag);
953 };
954 };
955 ## next unless $ {$$atom[3]} -> attributes("Occupancy");
956 if ((not $host) and (not $$meta{occupancy})) {
957 ## remove dopants from these lists
958 splice @indeces, $inc, 1;
959 splice @bounce, $inc, 1;
960 next ATOMS;
961 };
962 ($x, $y, $z) = # make sure coords are never -0.00000
963 map { $_ = (abs($_) > EPSILON) ? $_ : 0; }
964 ($$atom[0], $$atom[1], $$atom[2]);
965 ($fx, $fy, $fz) = @$atom[8..10];
966 };
967 my $znum = &get_Z($el);
968 ## $die = 4 because I presume this warning has already been
969 ## flagged at an earlier point in the execution of the program
970 $x = Xray::Atoms::number($x, 4); #$keywords->{die});
971 $y = Xray::Atoms::number($y, 4); #$keywords->{die});
972 $z = Xray::Atoms::number($z, 4); #$keywords->{die});
973 my $r = sprintf($$meta{precision}, sqrt($x**2 + $y**2 + $z**2));
974 ($x, $y, $z) = map { sprintf($$meta{precision}, $_); } ($x, $y, $z);
975
976 ## grab and format the remaining site attributes
977 unless ($style eq 'atoms') {
978 ($style eq 'cluster') and
979 ($fx, $fy, $fz) = map {sprintf "%s", $_} ($fx, $fy, $fz);
980 ($file, $b, $bx, $by, $bz, $color, $valence) =
981 $ {$$atom[3]} ->
982 attributes("File", "B", "Bx", "By", "Bz", "Color", "Valence");
983 ($b, $bx, $by, $bz) =
984 map { sprintf($$meta{precision}, $_); } ($b, $bx, $by, $bz);
985 };
986
987
988 ## it is possible for an overfilled list to be longer than a
989 ## cluster, so...
990 defined $indeces[$inc] or $indeces[$inc] = "";
991 defined $bounce[$inc] or $bounce[$inc] = 1;
992 my %matches = ("x" => $x,
993 "y" => $y,
994 "z" => $z,
995 "r" => $r,
996 "fx" => $fx,
997 "fy" => $fy,
998 "fz" => $fz,
999 "occ" => $occ,
1000 "ipot" => $thisipot,
1001 "znum" => $znum,
1002 "tag" => $tag,
1003 "utag" => $utag,
1004 "elem" => sprintf("%-2s", ucfirst($el)),
1005 "itag" => sprintf("%-13s", $indeces[$inc]),
1006 "1bou" => $bounce[$inc],
1007 "inc" => sprintf("%4d", $inc),
1008 "file" => $file,
1009 "b" => $b,
1010 "bx" => $bx,
1011 "by" => $by,
1012 "bz" => $bz,
1013 "color" => $color,
1014 "valence" => $valence,
1015 "n" => $/);
1016 ($$meta{is_gnxas}) and $matches{elem} = sprintf("%2s",ucfirst($el));
1017 my $matchstring = join("|", keys %matches);
1018 $thisline =~ s/\<($matchstring)>/$matches{$1}/g;
1019 $$r_contents .= $thisline;
1020 ++$inc;
1021 };
1022 $$line = "";
1023 };
1024
1025 sub ATP_dafs {
1026 my ($line, $r_contents, $r_cluster, $atp, $meta) = @_;
1027 chomp $$line;
1028 my $inc = $$meta{inc_begin};
1029
1030 $$line = shift @$atp;
1031 foreach my $point (@$r_cluster) { # data stored in $r_cluster
1032 my $thisline = $$line;
1033 my ($e, $r, $i, $la) = # make sure coords are never -0.00000
1034 ($$point[0], $$point[1], $$point[2], $$point[3]);
1035 my $asqr = $r**2 + $i**2;
1036 my $a = sqrt($asqr);
1037 my $p = atan2($i, $r);
1038 $e = sprintf("%10.3f", $e);
1039 ($r, $i, $a, $asqr, $p, $la) =
1040 map { sprintf($$meta{precision}, $_) } ($r, $i, $a, $asqr, $p, $la);
1041 my %matches = ("e" => $e,
1042 "a" => $a,
1043 "asqr" => $asqr,
1044 "r" => $r,
1045 "i" => $i,
1046 "la" => $la,
1047 "p" => $p,
1048 "n" => $/,
1049 "inc" => sprintf("%5d", $inc++) );
1050 my $matchstring = join("|", keys %matches);
1051 $thisline =~ s/\<($matchstring)>/$matches{$1}/go;
1052 $$r_contents .= $thisline;
1053 };
1054 $$line = "";
1055 };
1056
1057
1058 sub ATP_powder {
1059 my ($line, $cell, $r_contents, $r_cluster, $atp, $meta) = @_;
1060 chomp $$line;
1061 my $inc = $$meta{inc_begin};
1062
1063 my $biggest = 0;
1064 $$line = shift @$atp;
1065 ## fetch the normalization constant
1066 foreach my $point (@$r_cluster) { # data stored in $r_cluster
1067 my ($tth, $h, $k, $l, $r, $i, $m) = @$point;
1068 my $p = $cell -> multiplicity($h, $k, $l);
1069 my $amp = ($r**2 + $i**2) * $p;
1070 my $th = PI*$tth/360;
1071 $amp *= (1 + cos(2*$th)**2) / (sin($th)**2 * cos($th));
1072 $amp *= exp(-2*$m);
1073 ($amp > $biggest) and $biggest = $amp;
1074 };
1075 foreach my $point (@$r_cluster) { # data stored in $r_cluster
1076 my $thisline = $$line;
1077 my ($tth, $h, $k, $l, $r, $i, $m) = @$point;
1078
1079 my $p = $cell -> multiplicity($h, $k, $l);
1080 my $a = ($r**2 + $i**2);
1081 my $amp = $a * $p;
1082 my $th = PI*$tth/360;
1083 my $lp = (1 + cos(2*$th)**2) / (sin($th)**2 * cos($th));
1084 $amp *= $lp*exp(-2*$m);
1085 $amp *= 100/$biggest;
1086 my $ph = atan2($i, $r);
1087 $th = $tth/2;
1088
1089 ($r, $i, $a, $amp, $ph, $tth, $th, $lp) =
1090 map { sprintf($$meta{precision}, $_) } ($r, $i, $a, $amp, $ph, $tth, $th, $lp);
1091 my %matches = ("tth" => $tth,
1092 "th" => $th,,
1093 "a" => $a,
1094 "asqr" => $amp,
1095 "amp" => $amp,
1096 "r" => $r,
1097 "i" => $i,
1098 "p" => $ph,
1099 "lp" => $lp,
1100 "m" => $m,
1101 "h" => sprintf("%2d", $h),
1102 "k" => sprintf("%2d", $k),
1103 "l" => sprintf("%2d", $l),
1104 "n" => $/,
1105 "mult" => sprintf("%2d", $p),
1106 "inc" => sprintf("%5d", $inc++) );
1107 my $matchstring = join("|", keys %matches);
1108 $thisline =~ s/\<($matchstring)>/$matches{$1}/go;
1109 $$r_contents .= $thisline;
1110 };
1111 $$line = "";
1112 };
1113
1114 ## utility subroutines ----------------------------------------------
1115
1116 ## return a count of the number of unique sites populated
1117 sub get_nabs {
1118 my ($cell, $central) = @_;
1119 my ($sites) = $cell -> attributes("Contents");
1120 return 0 unless ($sites);
1121 my $count = 0;
1122 my %seen;
1123 foreach my $site (@{$sites}) {
1124 my ($elem) = $ {$$site[3]} -> attributes("Element");
1125 my ($id) = $ {$$site[3]} -> attributes("Id");
1126 unless ( $seen{$id}++ ) {
1127 (lc($central) eq lc($elem)) and ++$count;
1128 };
1129 };
1130 return $count;
1131 };
1132
1133 ## return a list of the indeces of the atoms in the cell contents list
1134 ## which are of the same species as the central atom but which are
1135 ## different unique sites (as needed for GNXAS CRYMOL file)
1136 sub get_abs_list {
1137 my ($cell, $keywords, $central, $meta) = @_;
1138 my ($sites) = $cell -> attributes("Contents");
1139 my $is_atoms = ($$meta{list_type} eq "atoms");
1140 ($is_atoms) and $sites = $keywords->{'sites'};
1141 my $count = 0;
1142 my @list = ();
1143 return @list unless ($sites);
1144 my %seen;
1145 foreach my $site (@{$sites}) {
1146 ++$count;
1147 if ($is_atoms) { # must be a gnxas SYM file
1148 my $elem = $site -> [0];
1149 (lc($central) eq lc($elem)) and push @list, $count;
1150 } else { # must be a gnxas CRY file
1151 my ($elem) = $ {$$site[3]} -> attributes("Element");
1152 my ($id) = $ {$$site[3]} -> attributes("Id");
1153 unless ( $seen{$id}++ ) {
1154 (lc($central) eq lc($elem)) and push @list, $count;
1155 };
1156 };
1157 };
1158 return @list;
1159 };
1160
1161 ## this is a bit repetitive, but I might want to change it later
1162 sub get_stoi {
1163 my ($cell, $keys, $type, $gcd) = @_;
1164 my @count = ();
1165 my ($sites) = $cell -> attributes("Contents");
1166 my $smallest = 1000000;
1167 foreach my $key (@$keys) {
1168 my $count = 0;
1169 STYLES: {
1170 ($type eq "species") && do {
1171 foreach my $site (@{$sites}) {
1172 my ($tag) = $ {$$site[3]} -> attributes("Element");
1173 (lc($key) eq lc($tag)) and ++$count;
1174 };
1175 last STYLES;
1176 };
1177 ($type eq "tags") && do {
1178 foreach my $site (@{$sites}) {
1179 my ($tag) = $ {$$site[3]} -> attributes("Tag");
1180 ($key eq $tag) and ++$count;
1181 };
1182 last STYLES;
1183 };
1184 ($type eq "sites") && do {
1185 foreach my $site (@{$sites}) {
1186 my ($tag) = $ {$$site[3]} -> attributes("Id");
1187 ($key == $tag) and ++$count;
1188 };
1189 last STYLES;
1190 };
1191 };
1192 push @count, $key, $count;
1193 $smallest = ($count < $smallest) ? $count : $smallest;
1194 };
1195 if ($gcd) { # gcd flag is set so...
1196 GCD: foreach my $i (reverse (1 .. $smallest)) { # step backwards from
1197 my $not_ok = 0; # smallest stoi value
1198 foreach my $s (0 .. $#{$keys}) { # a denom. has mod 0 for
1199 $not_ok ||= ($count[2*$s+1] % $i); # each value of stoi.
1200 };
1201 unless ($not_ok) {
1202 foreach my $s (0 .. $#{$keys}) {
1203 $count[2*$s+1] /= $i;
1204 };
1205 last GCD;
1206 };
1207 };
1208 };
1209 return @count; # return stoi hash
1210 };
1211
1212
1213 sub fix_ipots {
1214 my ($ipots, $r_cluster, $ipot_style) = @_;
1215 my @keys = sort {$$ipots{$a} <=> $$ipots{$b}} (keys %$ipots);
1216 my @found = ();
1217 my $index = -1;
1218 foreach my $k (@keys) {
1219 ++$index;
1220 $found[$index] = 0;
1221 ## search through the cluster of atoms looking for at least one
1222 ## example of each unique potential.
1223 ATOMS: foreach my $atom (@$r_cluster) {
1224 my ($el, $tag, $id) = ($ {$$atom[3]} -> attributes("Element"),
1225 $ {$$atom[3]} -> attributes("Tag"),
1226 $ {$$atom[3]} -> attributes("Id"));
1227 #print join("~", $el, $tag, $id), $/;
1228 if ($ipot_style eq "species") {
1229 ++$found[$index], last ATOMS if (lc($k) eq lc($el));
1230 } elsif ($ipot_style eq "tags") {
1231 ++$found[$index], last ATOMS if (lc($k) eq lc($tag));
1232 } elsif ($ipot_style eq "sites") {
1233 ++$found[$index], last ATOMS if (lc($k) eq lc($id));
1234 };
1235 };
1236 };
1237 ## weed out each ipot that is not represented in the cluster
1238 foreach my $i (reverse(0..$#found)) {
1239 splice(@keys, $i, 1) unless $found[$i];
1240 };
1241 ## renumber the ipots with the missing one weeded out
1242 my %fixed = ();
1243 foreach my $i (0..$#keys) {
1244 $fixed{$keys[$i]} = $i+1;
1245 };
1246 return \%fixed;
1247 };
1248
1249
1250 sub symmetry_table {
1251 my ($cell, $line, $r_contents, $is_gnxas) = @_;
1252 my ($group, $given, $setting) =
1253 $cell->attributes("Space_group", "Given_group", "Setting");
1254 #-------------------------- handle different settings as needed
1255 my $positions = "positions";
1256 my $do_ortho =
1257 ($cell -> crystal_class() eq "orthorhombic" ) &&
1258 ($setting);
1259 my $do_tetr =
1260 ($cell -> crystal_class() eq "tetragonal" ) &&
1261 ($setting);
1262 ($cell -> crystal_class() eq "monoclinic") && do {
1263 $positions = $setting;
1264 # bravais vector for the //given// symbol
1265 ##@bravais = Xray::Xtal::Cell::bravais($given, 0);
1266 };
1267 (($group =~ /^r/i) && ($setting eq "rhombohedral"))
1268 && ($positions = "rhombohedral");
1269 ($positions) || do {
1270 my $this = (caller(0))[3];
1271 die "Invalid positions specifier in " . $this . "(Bruce's error)";
1272 return;
1273 };
1274 my $list = $cell -> get_symmetry_table();
1275 my ($xx, $yy, $zz, $rx, $ry, $rz);
1276 my $inc = 1;
1277 foreach my $position (@{$list}) {
1278 my $thisline = $line;
1279 ($xx = $$position[0]) =~ s/\$//g;
1280 ($xx =~ /^-/) || ($xx = " ".$xx);
1281 ($yy = $$position[1]) =~ s/\$//g;
1282 ($yy =~ /^-/) || ($yy = " ".$yy);
1283 ($zz = $$position[2]) =~ s/\$//g;
1284 ($zz =~ /^-/) || ($zz = " ".$zz);
1285 ($rx, $ry, $rz) = (0, 0, 0);
1286 if ($is_gnxas) { # could this be more annoying?
1287 my ($gx, $gy, $gz);
1288 $gx = ($xx =~ /([- ]x)/ ) ? $1 : " ";
1289 $gx .= ($xx =~ /([-+ ]y)/) ? $1 : " ";
1290 $gx .= ($xx =~ /([-+ ]z)/) ? $1 : " ";
1291 $gy = ($yy =~ /([- ]x)/ ) ? $1 : " ";
1292 $gy .= ($yy =~ /([-+ ]y)/) ? $1 : " ";
1293 $gy .= ($yy =~ /([-+ ]z)/) ? $1 : " ";
1294 $gz = ($zz =~ /([- ]x)/ ) ? $1 : " ";
1295 $gz .= ($zz =~ /([-+ ]y)/) ? $1 : " ";
1296 $gz .= ($zz =~ /([-+ ]z)/) ? $1 : " ";
1297 map { $_ =~ s/\+/ /g } ($gx, $gy, $gz);
1298 ($xx, $yy, $zz) = ($gx, $gy, $gz);
1299 $rx = ($xx =~ /x([-+]\d\/\d)/) ? eval($1) : 0;
1300 $ry = ($yy =~ /y([-+]\d\/\d)/) ? eval($1) : 0;
1301 $rz = ($zz =~ /z([-+]\d\/\d)/) ? eval($1) : 0;
1302 };
1303 my %matches = ("x" => $xx,
1304 "y" => $yy,
1305 "z" => $zz,
1306 "rx" => $rx,
1307 "ry" => $ry,
1308 "rz" => $rz,
1309 "inc" => sprintf("%4d", $inc++));
1310 my $matchstring = join("|", keys %matches);
1311 $thisline =~ s/\<($matchstring)>/$matches{$1}/go;
1312 $$r_contents .= $thisline;
1313 };
1314 };
1315
1316 ## this is a scheme for numbering shells and subshells to provide a
1317 ## visual cue for which atoms in a cluster are symmetry related about
1318 ## the central atom
1319 sub fetch_indeces {
1320 my $r_cluster = $_[0];
1321 my @list = $ {$$r_cluster[0][3]} -> attributes("Tag");
1322 my %seen = ();
1323 my %count = ();
1324 my %shell = ();
1325 my $this = "";
1326 ## should this be user configurable? atp configurable?
1327 my ($open, $close) = ("_", ""); # ("/", "/"); # ("<", ">"); ("_", "");
1328 foreach my $i (1..$#{$r_cluster}) {
1329 my ($x, $y, $z) =
1330 ($$r_cluster[$i][0], $$r_cluster[$i][1], $$r_cluster[$i][2]);
1331 my $r = ($x**2 + $y**2 + $z**2);
1332 #next if ($r < EPSILON);
1333 $r = sprintf("%8.4f", $r);
1334 my ($tag) = $ {$$r_cluster[$i][3]} -> attributes("Tag");
1335 $tag =~ s/\s+$//;
1336 $this = $tag.$r;
1337 exists($seen{$this}) or ++$count{$tag};
1338 ++$seen{$this};
1339 push @list, join("", $tag, $open, $count{$tag}, $close );
1340 };
1341 return @list;
1342 };
1343
1344 ## this provides a list of itags suitable for distinguishing sites in
1345 ## a P1 file
1346 sub count_sites {
1347 my $r_cluster = $_[0];
1348 my @list;
1349 my %seen = ();
1350 foreach my $i (0..$#{$r_cluster}) {
1351 my ($tag) = $ {$$r_cluster[$i][3]} -> attributes("Tag");
1352 ++$seen{$tag};
1353 push @list, $tag."_".$seen{$tag};
1354 };
1355 return @list;
1356 };
1357
1358 #### THIS IS BROKEN IN ALPHA21 (and earlier)
1359 ## this computes the one bounce flags needed for a feff6 geom.dat file
1360 ## this has to be a two pass filter
1361 ## this does not work in some situations ... for example perfect hcp.
1362 sub one_bounce {
1363 my $r_cluster = $_[0];
1364 my @list = (1);
1365 my @descri = ("");
1366 my %seen = ();
1367 foreach my $i (1..$#{$r_cluster}) {
1368 my ($x, $y, $z) = map { int(1000*$_) }
1369 (abs($$r_cluster[$i][0]),
1370 abs($$r_cluster[$i][1]),
1371 abs($$r_cluster[$i][2]));
1372 ($x, $y, $z) = sort($x, $y, $z);
1373 my ($tag) = $ {$$r_cluster[$i][3]} -> attributes("Tag");
1374 push @descri, sprintf("%s%s%s%-10s", $x, $y, $z, $tag);
1375 };
1376 foreach my $i (1..$#{$r_cluster}) {
1377 unless ($seen{$descri[$i]}++) {
1378 my @count = grep /$descri[$i]/, @descri;
1379 push @list, $#count+1;
1380 } else {
1381 push @list, 0;
1382 };
1383 };
1384 return @list;
1385 };
1386
1387 1;
1388 __END__
1389
1390
1391 =head1 MORE INFORMATION
1392
1393 There is more information available in the Atoms document. There you
1394 will find complete descriptions of atp files, calculations using the
1395 Xray::Absorption package, keywords in atoms input files and lots of
1396 other topics.
1397
1398
1399 =head1 AUTHOR
1400
1401 Bruce Ravel <[email protected]>
1402 Atoms URL: http://feff.phys.washington.edu/~ravel/software/atoms/
1403
1404
1405 =cut