Debian Codegraph @

bin/atoms

raw
1 #!/usr/bin/perl -w
2 ######################################################################
3 my $ts = "Time-stamp: <2009-06-08 17:24:46 bruce>";
4 ######################################################################
5 ## Atoms version 3.0.1
6 ## copyright (c) 1998-2009 Bruce Ravel
7 ## [email protected]
8 ## http://feff.phys.washington.edu/~ravel/
9 ##
10 ## The latest version of Atoms can always be found at
11 ## http://feff.phys.washington.edu/~ravel/software/atoms/
12 ##
13 ## -------------------------------------------------------------------
14 ## All rights reserved. This program is free software; you can
15 ## redistribute it and/or modify it under the same terms as Perl
16 ## itself.
17 ##
18 ## This program is distributed in the hope that it will be useful,
19 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ## Artistic License for more details.
22 ## -------------------------------------------------------------------
23 ######################################################################
24 ## This file is the main program for Atoms (command line).
25 ##
26 ## This version of atoms is intended for running from the command
27 ## line. It requires an input file that closely resembles the sort of
28 ## input file that was used with the Fortran versions of this program.
29 ## In fact, most old input will be processed correctly and produce the
30 ## desired output. There are some semantic differences between this
31 ## version and the Fortran version. The most important difference is
32 ## the semantic convention for specifying types and names of output
33 ## files. Please read the documentation for details. Also note that
34 ## several keywords recognized by the Fortran version are not used by
35 ## this version. This includes all keywords used for anomalous
36 ## scattering features of the old code.
37 ######################################################################
38 ## Code:
39
40 ## =============================== load methods
41 require 5.004;
42 use strict;
43 use Carp;
44 use Xray::Xtal;
45 $Xray::Xtal::run_level = 0;
46 use Xray::Atoms qw(build_cluster rcfile_name);
47 use Xray::ATP; # qw(parse_atp);
48 use File::Basename;
49 use File::Spec;
50 use Cwd;
51 ##use diagnostics;
52
53 ## =============================== process command line switches
54 use Getopt::Std;
55 use vars qw(%opt);
56 $opt{o} = "";
57 getopts('f678pguaxsbTFDOvqhAr:t:o:c:', \%opt);
58
59 my ($file, $inputdir);
60 if ($ARGV[0] and ($ARGV[0] eq '-')) { # read from STDIN
61 $file = '____stdin'; # an unlikely string (I hope)
62 $inputdir = cwd;
63 } elsif ($opt{A}) {
64 my $inp = $ARGV[0];
65 unless ($inp =~ /\.inp$/) {
66 $inp .= ($inp =~ /\.$/) ? 'inp' : '.inp';
67 };
68 $file = $Xray::Atoms::meta{ADB_location} . $inp;
69 $inputdir = cwd;
70 } else {
71 unless ($^O eq 'MacOS') {
72 INPUT: {
73 $file = "atoms.inp", last INPUT if (not $ARGV[0]);
74 $file = $ARGV[0], last INPUT if (-e $ARGV[0]);
75 $file = $ARGV[0] . ".inp", last INPUT if (-e "$ARGV[0].inp");
76 $file = $ARGV[0] . "inp", last INPUT if (-e "$ARGV[0]inp");
77 die $ARGV[0] . ": " . $$Xray::Atoms::messages{'invalid_input'} . $/;
78 }
79 } else {
80 require Mac::StandardFile;
81 $file = Mac::StandardFile::StandardGetFile(0, 'TEXTclpt');
82 if ($file -> sfGood()) {
83 $file = $file->sfFile();
84 } else {
85 die "File opening canceled. Atoms quitting.$/";
86 };
87 };
88 $inputdir = dirname($file); # if write_to_pwd is false...
89 }
90
91 my @sites = (); # list of sites
92 my @cluster = (); # spherical cluster
93 my @neutral = (); # charge neutral rhomboidal cluster
94
95 ## =============================== run time screen messages
96 use vars (qw($VERSION));
97 $VERSION = '3.0.1';
98 my $v = $VERSION;
99 my $date = substr((split(" ", $ts))[1], 1);
100 my $scriptv = $VERSION; #(split(" ", $cvs_info))[2];
101 my $screen_line = "=" x 71;
102
103 if ($opt{h}) {
104 require Pod::Text;
105 $^W=0;
106 if ($Pod::Text::VERSION < 2.0) {
107 Pod::Text::pod2text($0, *STDOUT);
108 } elsif ($Pod::Text::VERSION >= 2.0) {
109 my $parser = Pod::Text->new;
110 open STDIN, $0;
111 $parser->parse_from_filehandle;
112 };
113 exit;
114 };
115
116 print STDOUT <<EOH
117 $screen_line
118 Atoms $v ($^O) $date
119 $screen_line
120 EOH
121 unless ($opt{'q'});
122
123 my $absorption_resource = Xray::Absorption -> current_resource;
124 print STDOUT <<EOH
125 by Bruce Ravel copyright (c) 1998-2005
126 <bravel\@anl.gov>
127
128 atoms.pl $scriptv
129 using Atoms.pm $Xray::Atoms::module_version, ATP.pm $Xray::ATP::module_version
130 Xtal.pm $Xray::Xtal::VERSION, space groups database $Xray::Xtal::sg_version
131 Absorption.pm $Xray::Absorption::VERSION
132 $absorption_resource
133 with perl $] on $^O.
134
135 EOH
136 and exit if ($opt{v});
137
138 ## =============================== define a cell, parse the input file,
139 my $cell = Xray::Xtal::Cell -> new();
140 my $keywords = Xray::Atoms -> new();
141 $keywords -> make('identity'=>"Atoms $v", die=>0);
142 $opt{'q'} && $keywords->make('quiet'=>1);
143 $keywords -> parse_input($file, 0);
144 die "\n" if $keywords->{cli_warn};
145 ($opt{c}) && $keywords->make(core=>$opt{c});
146
147 ## =============================== fill up the cell and the sites
148 $cell -> make( Space_group=>$keywords->{'space'} );
149 foreach my $param ('a', 'b', 'c', 'alpha', 'beta', 'gamma') {
150 $cell -> make( $param=>$keywords->{$param} );
151 };
152 ($file eq '____stdin') and $file = 'the input data';
153 ( @{$keywords->{'sites'}} ) or
154 croak "$$Xray::Atoms::messages{no_sites} $file$/";
155
156 my $nsites = 0;
157 foreach my $this (@{$keywords->{'sites'}}) {
158 $sites[$nsites] = Xray::Xtal::Site -> new($nsites);
159 $sites[$nsites] -> make(Element=>$$this[0],
160 X=>$$this[1]+$ {$keywords->{"shift"}}[0],
161 Y=>$$this[2]+$ {$keywords->{"shift"}}[1],
162 Z=>$$this[3]+$ {$keywords->{"shift"}}[2] );
163 ($$this[4]) && ( $sites[$nsites] -> make(Tag=>$$this[4]) );
164 ($$this[5]) && ( $sites[$nsites] -> make(Occupancy=>$$this[5]) );
165 ++$nsites;
166 };
167
168 ## =============================== error check, populate the cell, set rmax
169 #$cell -> make( Occupancy=>0 );
170 #($atp =~ /(p1|unit)/) and $cell -> make( Occupancy=>1 );
171 $cell -> verify_cell();
172 $cell -> populate(\@sites);
173 $keywords -> verify_keywords($cell, \@sites, 0);
174
175 ## =============================== override some stuff from the command line
176 $keywords->{"rmax"} = $opt{r} || $keywords->{"rmax"};
177 (($opt{f}) or ($opt{6}) or ($opt{7})) && $keywords -> make('atp'=>'feff');
178 ($opt{8}) && $keywords -> make('atp'=>'feff8');
179 ($opt{g}) && $keywords -> make('atp'=>'geom');
180 ($opt{p}) && $keywords -> make('atp'=>'p1');
181 ($opt{u}) && $keywords -> make('atp'=>'unit');
182 ($opt{a}) && $keywords -> make('atp'=>'alchemy');
183 ($opt{'x'}) && $keywords -> make('atp'=>'xyz');
184 ($opt{'s'}) && $keywords -> make('atp'=>'symmetry');
185 ($opt{b}) && $keywords -> make('atp'=>'pdb');
186 ($opt{T}) && $keywords -> make('atp'=>'test');
187 ($opt{t}) && do {
188 $keywords -> make('atp' => $opt{t});
189 $keywords -> make('files' => $opt{t}, $opt{o});
190 $keywords->{"found_output"} ||= 1;
191 $opt{o} = "";
192 };
193 $keywords->{"found_output"} ||= ($opt{f} or $opt{8} or $opt{g} or $opt{p} or
194 $opt{u} or $opt{a} or $opt{'x'} or $opt{'s'} or
195 $opt{T} or $opt{6} or $opt{7} or $opt{b});
196 ## this is the closest thing to backwards compatibity that I want to
197 ## do with regard to writing the feff6 file.
198 if ((not $keywords->{"found_output"}) || ($keywords->{always_feff})) {
199 if ($keywords->{"prefer_feff_8"}) {
200 $keywords->make('atp'=>'feff8');
201 } else {
202 $keywords->make('atp'=>'feff');
203 };
204 };
205
206 ## =============================== some error checking
207 ($opt{'q'}) or print $cell -> warn_shift(), $cell -> cell_check();
208
209 ## =============================== make spherical and rhomboidal clusters
210 build_cluster($cell, $keywords, \@cluster, \@neutral);
211 if ($opt{D}) {
212 use Data::Dumper;
213 print Data::Dumper->Dump([$keywords, $cell], [qw/*keywords *cell/]);
214 exit;
215 };
216
217 ## =============================== write out all of the output files
218 my $noutput = 0;
219 foreach my $atp (keys %{$keywords->{'atp'}}) {
220 if ($keywords->{'atp'}{$atp}) {
221 next if (($atp eq "feff") && $opt{F});
222 next if ($atp =~ /dafs/);
223 ++$noutput;
224 my $contents = "";
225 my ($default_name, $is_feff) =
226 &parse_atp($atp, $cell, $keywords, \@cluster, \@neutral, \$contents);
227 next unless ($default_name);
228 my $outfile = defined($keywords->{'files'}{$atp}) ?
229 $keywords->{'files'}{$atp} : $default_name;
230 (($opt{o}) and ($noutput == 1)) and ($outfile = $opt{o});
231 if ($keywords->{'write_to_pwd'}) {
232 $outfile = $outfile;
233 } else { # e.g. on Mac or Windows
234 $outfile = File::Spec -> catfile($inputdir, $outfile);
235 };
236 ($keywords->{"quiet"}) or
237 print STDOUT " $atp: ",
238 $$Xray::Atoms::messages{'writing'}, " ", $outfile, $/;
239 if ($opt{O}) {
240 print STDOUT $contents;
241 } else {
242 no warnings;
243 open OUTFILE, ">".$outfile || die $$Xray::Atoms::messages{cannot_write} . " " . $outfile . $/;
244 print OUTFILE $contents;
245 close OUTFILE;
246 };
247 };
248 };
249
250 ## =============================== finish up
251 ($opt{'q'}) or print STDOUT $screen_line, $/, $/;
252 1;
253 ##exit;
254
255 ######################################################################
256 ## End of main program atoms
257
258 =head1 NAME
259
260 Atoms - Make lists of atomic coordinates from crystallographic data
261
262 =head1 SYNOPSIS
263
264 atoms [-fu8gpsbaxF] [-r#] [-qvh] [-t atptype -o file] input_file
265
266 =head1 DESCRIPTION
267
268 Take crystallographic data from the input file given on the command
269 line and write output as indicated by their contents. If no input
270 file is given, F<atoms.inp> is used. If the input file specified at
271 the command line is '-', then input is read from STDIN. If no output
272 format is specified, an input file for feff will be written. Several
273 command line switches can be used to override the contents of the
274 input files.
275
276 output file flags
277 -f feff6 input file -u unit cell file
278 -8 feff8 input file -g geometry file
279 -p P1 input file -s symmetry file
280 -a alchemy atoms list -x xyz atoms list
281 -b Protein Databank list
282 -F do not write feff file -O write to STDOUT
283 -t s user supplied template -o f output file name
284
285 operational flags
286 -r # override the value of rmax with the given value
287 -A use a named file from the Atoms Database
288 -q suppress screen messages
289 -v write version information and exit
290 -h write this message and exit
291
292 # = number f = file s = string
293
294 For complete information about Atoms, consult the documentation at
295 http://leonardo.phys.washington.edu/~ravel/software/doc/Atoms/
296
297 =head1 AUTHOR
298
299 Atoms is copyright (c) 1998-2005 Bruce Ravel
300 [email protected]
301 http://feff.phys.washington.edu/~ravel
302
303 =cut