Mercurial > repos > deepakjadmin > r_caret_test
comparison mayachemtool/mayachemtools/bin/InfoPeriodicTableElements.pl @ 0:68300206e90d draft default tip
Uploaded
author | deepakjadmin |
---|---|
date | Thu, 05 Nov 2015 02:41:30 -0500 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:68300206e90d |
---|---|
1 #!/usr/bin/perl -w | |
2 # | |
3 # $RCSfile: InfoPeriodicTableElements.pl,v $ | |
4 # $Date: 2015/02/28 20:46:20 $ | |
5 # $Revision: 1.28 $ | |
6 # | |
7 # Author: Manish Sud <msud@san.rr.com> | |
8 # | |
9 # Copyright (C) 2015 Manish Sud. All rights reserved. | |
10 # | |
11 # This file is part of MayaChemTools. | |
12 # | |
13 # MayaChemTools is free software; you can redistribute it and/or modify it under | |
14 # the terms of the GNU Lesser General Public License as published by the Free | |
15 # Software Foundation; either version 3 of the License, or (at your option) any | |
16 # later version. | |
17 # | |
18 # MayaChemTools is distributed in the hope that it will be useful, but without | |
19 # any warranty; without even the implied warranty of merchantability of fitness | |
20 # for a particular purpose. See the GNU Lesser General Public License for more | |
21 # details. | |
22 # | |
23 # You should have received a copy of the GNU Lesser General Public License | |
24 # along with MayaChemTools; if not, see <http://www.gnu.org/licenses/> or | |
25 # write to the Free Software Foundation Inc., 59 Temple Place, Suite 330, | |
26 # Boston, MA, 02111-1307, USA. | |
27 # | |
28 | |
29 use strict; | |
30 use FindBin; use lib "$FindBin::Bin/../lib"; | |
31 use Getopt::Long; | |
32 use File::Basename; | |
33 use Text::ParseWords; | |
34 use Benchmark; | |
35 use FileUtil; | |
36 use TextUtil; | |
37 use PeriodicTable; | |
38 | |
39 my($ScriptName, %Options, $StartTime, $EndTime, $TotalTime); | |
40 | |
41 # Autoflush STDOUT | |
42 $| = 1; | |
43 | |
44 # Starting message... | |
45 $ScriptName = basename($0); | |
46 print "\n$ScriptName: Starting...\n\n"; | |
47 $StartTime = new Benchmark; | |
48 | |
49 # Get the options and setup script... | |
50 SetupScriptUsage(); | |
51 if ($Options{help}) { | |
52 die GetUsageFromPod("$FindBin::Bin/$ScriptName"); | |
53 } | |
54 | |
55 print "Processing options...\n"; | |
56 my(%OptionsInfo); | |
57 ProcessOptions(); | |
58 | |
59 ListElementProperties(); | |
60 print "\n$ScriptName:Done...\n\n"; | |
61 | |
62 $EndTime = new Benchmark; | |
63 $TotalTime = timediff ($EndTime, $StartTime); | |
64 print "Total time: ", timestr($TotalTime), "\n"; | |
65 | |
66 ############################################################################### | |
67 | |
68 # List atomic properties for elements... | |
69 sub ListElementProperties { | |
70 my($ElementID, $ElementDataRef, $PropertyName, $PropertyValue, $PropertyUnits, $PropertyUnitsRef, @PropertyLabels, @PropertyValues); | |
71 | |
72 print "Listing information for periodic table element(s)...\n"; | |
73 | |
74 if ($OptionsInfo{FileOutput}) { | |
75 print "Generating file $OptionsInfo{OutFileName}...\n"; | |
76 open OUTFILE, ">$OptionsInfo{OutFileName}" or die "Couldn't open $OptionsInfo{OutFileName}: $!\n"; | |
77 } | |
78 | |
79 # Setup property labels... | |
80 @PropertyLabels = (); | |
81 $PropertyUnitsRef = PeriodicTable::GetElementPropertiesNamesAndUnits(); | |
82 for $PropertyName (@{$OptionsInfo{SpecifiedProperies}}) { | |
83 $PropertyUnits = (exists $PropertyUnitsRef->{$PropertyName}) ? $PropertyUnitsRef->{$PropertyName} : ''; | |
84 if ($PropertyName =~ /^NaturalIsotopeData$/i) { | |
85 push @PropertyLabels, qw(MassNumber: RelativeAtomicMass: NaturalAbundance:); | |
86 } | |
87 else { | |
88 push @PropertyLabels, ($PropertyUnits ? "$PropertyName ($PropertyUnits):" : "$PropertyName:"); | |
89 } | |
90 } | |
91 | |
92 if ($OptionsInfo{ElementRowsOutput}) { | |
93 ListHeaderRowData(\@PropertyLabels); | |
94 } | |
95 | |
96 # Go over specified properties... | |
97 for $ElementID (@{$OptionsInfo{SpecifiedElementIDs}}) { | |
98 $ElementDataRef = PeriodicTable::GetElementPropertiesData($ElementID); | |
99 | |
100 if (!$OptionsInfo{ElementRowsOutput}) { | |
101 if ($OptionsInfo{FileOutput}) { | |
102 print OUTFILE "\nListing atomic properties for element $ElementID...\n\n"; | |
103 } | |
104 else { | |
105 print "\nListing atomic properties for element $ElementID...\n\n"; | |
106 } | |
107 } | |
108 | |
109 # Collect data.. | |
110 @PropertyValues = (); | |
111 for $PropertyName (@{$OptionsInfo{SpecifiedProperies}}) { | |
112 if ($PropertyName =~ /^NaturalIsotopeData$/i) { | |
113 push @PropertyValues, SetupIsotopeData($ElementID); | |
114 } | |
115 else { | |
116 $PropertyValue = $ElementDataRef->{$PropertyName}; | |
117 if (IsFloat($PropertyValue)) { | |
118 $PropertyValue = sprintf("%.$OptionsInfo{Precision}f", $PropertyValue) + 0; | |
119 } | |
120 push @PropertyValues, $PropertyValue; | |
121 } | |
122 } | |
123 # List data... | |
124 ListElementData(\@PropertyLabels, \@PropertyValues); | |
125 } | |
126 if ($OptionsInfo{FileOutput}) { | |
127 close OUTFILE; | |
128 } | |
129 print "\n"; | |
130 } | |
131 | |
132 # List data for an element... | |
133 sub ListElementData { | |
134 my($DataLabelRef, $DataValueRef) = @_; | |
135 my($Index, $Line, $Value); | |
136 | |
137 if ($OptionsInfo{ElementRowsOutput}) { | |
138 $Line = ''; | |
139 # Format data... | |
140 if ($OptionsInfo{OutQuote} || $Options{outdelim} !~ /^comma$/i) { | |
141 $Line = JoinWords($DataValueRef, $OptionsInfo{OutDelim}, $OptionsInfo{OutQuote}); | |
142 } | |
143 else { | |
144 # Always quote values containing commas... | |
145 $Line = ($DataValueRef->[0] =~ /\,/) ? qq("$DataValueRef->[0]") : $DataValueRef->[0]; | |
146 for $Index (1 .. $#{$DataValueRef} ) { | |
147 $Value = $DataValueRef->[$Index]; | |
148 if ($Value =~ /\,/) { | |
149 $Value = qq("$Value"); | |
150 } | |
151 $Line .= $OptionsInfo{OutDelim} . $Value; | |
152 } | |
153 } | |
154 if ($OptionsInfo{FileOutput}) { | |
155 print OUTFILE "$Line\n"; | |
156 } | |
157 else { | |
158 print "$Line\n"; | |
159 } | |
160 } | |
161 else { | |
162 # Format and list data... | |
163 $Line = ''; | |
164 for $Index (0 .. $#{$DataLabelRef} ) { | |
165 $Line = $DataLabelRef->[$Index] . ' ' . $DataValueRef->[$Index]; | |
166 if ($OptionsInfo{FileOutput}) { | |
167 print OUTFILE "$Line\n"; | |
168 } | |
169 else { | |
170 print "$Line\n"; | |
171 } | |
172 } | |
173 } | |
174 } | |
175 | |
176 # List data for an element... | |
177 sub ListHeaderRowData { | |
178 my($DataLabelRef) = @_; | |
179 my($Line); | |
180 | |
181 # Format data... | |
182 $Line = JoinWords($DataLabelRef, $OptionsInfo{OutDelim}, $OptionsInfo{OutQuote}); | |
183 $Line =~ s/\://g; | |
184 # List data... | |
185 if ($OptionsInfo{FileOutput}) { | |
186 print OUTFILE "$Line\n"; | |
187 } | |
188 else { | |
189 print "$Line\n"; | |
190 } | |
191 } | |
192 | |
193 # Setup isotope data strings... | |
194 sub SetupIsotopeData { | |
195 my($ElementID) = @_; | |
196 my($MassNumber, $RelativeAtomicMass, $NaturalAbundance, $NaturalIsotopeDataRef, @MassNumbers, @RelativeAtomicMasses, @NaturalAbundances); | |
197 | |
198 # Get natural isotope data: MassNumber, RelativeAtomicMass and NaturalAbundance | |
199 @MassNumbers = (); @RelativeAtomicMasses = (); @NaturalAbundances = (); | |
200 $NaturalIsotopeDataRef = PeriodicTable::GetElementNaturalIsotopesData($ElementID); | |
201 for $MassNumber (sort {$a <=> $b} keys %{$NaturalIsotopeDataRef}) { | |
202 $RelativeAtomicMass = $NaturalIsotopeDataRef->{$MassNumber}{RelativeAtomicMass}; | |
203 $NaturalAbundance = $NaturalIsotopeDataRef->{$MassNumber}{NaturalAbundance}; | |
204 push @MassNumbers, $MassNumber; | |
205 $RelativeAtomicMass = ($RelativeAtomicMass > 0) ? (sprintf("%.$OptionsInfo{Precision}f", $RelativeAtomicMass) + 0) : ''; | |
206 push @RelativeAtomicMasses, $RelativeAtomicMass; | |
207 $NaturalAbundance = ($NaturalAbundance > 0) ? (sprintf("%.$OptionsInfo{Precision}f", $NaturalAbundance) + 0) : ''; | |
208 push @NaturalAbundances, $NaturalAbundance; | |
209 } | |
210 $MassNumber = JoinWords(\@MassNumbers, ",", 0); | |
211 $RelativeAtomicMass = JoinWords(\@RelativeAtomicMasses, ",", 0); | |
212 $NaturalAbundance = JoinWords(\@NaturalAbundances, ",", 0); | |
213 return ($MassNumber, $RelativeAtomicMass, $NaturalAbundance); | |
214 } | |
215 | |
216 # Get propery names from categories... | |
217 sub GetPropertyNamesFromCategories { | |
218 my($CategoryName) = @_; | |
219 my(@PropertyNames); | |
220 | |
221 @PropertyNames = (); | |
222 if ($CategoryName =~ /^Basic$/i) { | |
223 @PropertyNames = ('AtomicNumber', 'ElementSymbol', 'ElementName', 'AtomicWeight', 'GroundStateConfiguration', 'GroupNumber', 'PeriodNumber', 'FirstIonizationEnergy'); | |
224 } elsif ($CategoryName =~ /^BasicAndNaturalIsotope$/i) { | |
225 # Natural isotope data includes: 'MassNumber', 'RelativeAtomicMass', 'NaturalAbundance' | |
226 @PropertyNames = ('AtomicNumber', 'ElementSymbol', 'ElementName', 'AtomicWeight', 'GroundStateConfiguration', 'GroupNumber', 'PeriodNumber', 'FirstIonizationEnergy', 'NaturalIsotopeData'); | |
227 } elsif ($CategoryName =~ /^NaturalIsotope$/i) { | |
228 @PropertyNames = ('AtomicNumber', 'ElementSymbol', 'ElementName', 'NaturalIsotopeData'); | |
229 } | |
230 | |
231 return @PropertyNames; | |
232 } | |
233 | |
234 # Process option values... | |
235 sub ProcessOptions { | |
236 %OptionsInfo = (); | |
237 | |
238 $OptionsInfo{Mode} = $Options{mode}; | |
239 | |
240 $OptionsInfo{OutDelim} = ($Options{outdelim} =~ /^tab$/i ) ? "\t" : (($Options{outdelim} =~ /^semicolon$/i) ? "\;" : "\,"); | |
241 $OptionsInfo{OutQuote} = ($Options{quote} =~ /^yes$/i) ? 1 : 0; | |
242 | |
243 $OptionsInfo{Overwrite} = defined $Options{overwrite} ? $Options{overwrite} : undef; | |
244 $OptionsInfo{OutFileRoot} = defined $Options{root} ? $Options{root} : undef; | |
245 | |
246 $OptionsInfo{Output} = $Options{output}; | |
247 $OptionsInfo{OutputStyle} = $Options{outputstyle}; | |
248 | |
249 $OptionsInfo{ElementRowsOutput} = ($Options{outputstyle} =~ /^ElementRows$/i) ? 1 : 0; | |
250 $OptionsInfo{FileOutput} = ($Options{output} =~ /^File$/i) ? 1 : 0; | |
251 | |
252 $OptionsInfo{Precision} = $Options{precision}; | |
253 | |
254 my($ElementID, @ElementIDs, @GroupElements, @PeriodElements, %GroupNamesMap); | |
255 | |
256 @{$OptionsInfo{SpecifiedElementIDs}} = (); | |
257 if (@ARGV >=1 && ($Options{mode} =~ /^All$/i) ) { | |
258 warn "Warning: Ignoring comman line element IDs: Not valid for All value of \"-m --mode\" option...\n"; | |
259 } | |
260 | |
261 # Set up element IDs except for All mode... | |
262 @ElementIDs = (); | |
263 %GroupNamesMap = (); | |
264 | |
265 if (@ARGV >=1 ) { | |
266 if ($Options{mode} !~ /^All$/i) { | |
267 push @ElementIDs, @ARGV; | |
268 } | |
269 } | |
270 else { | |
271 # Setup mode specified default values... | |
272 my($Nothing); | |
273 MODE: { | |
274 if ($Options{mode} =~ /^ElementID$/i) { push @ElementIDs, 'H'; last MODE; }; | |
275 if ($Options{mode} =~ /^AmericanGroupLabel$/i) { push @ElementIDs, 'IA'; last MODE; }; | |
276 if ($Options{mode} =~ /^EuropeanGroupLabel$/i) { push @ElementIDs, 'IA'; last MODE; }; | |
277 if ($Options{mode} =~ /^GroupNumber$/i) { push @ElementIDs, '1'; last MODE; }; | |
278 if ($Options{mode} =~ /^GroupName$/i) { push @ElementIDs, 'AlkaliMetals'; last MODE; }; | |
279 if ($Options{mode} =~ /^PeriodNumber$/i) { push @ElementIDs, '1'; last MODE; }; | |
280 $Nothing = 1; | |
281 } | |
282 } | |
283 if ($Options{mode} =~ /^GroupName$/i) { | |
284 # Map group names to what's stored in Perioidic table data file... | |
285 %GroupNamesMap = ('alkalimetals', 'Alkali metal', 'alkalineearthmetals', 'Alkaline earth metal', 'chalcogens', 'Chalcogen', 'coinagemetals', 'Coinage metal', 'halogens', 'Halogen', 'noblegases', 'Noble gas', 'pnictogens', 'Pnictogen', 'lanthanides', 'Lanthanoid', 'lanthanoids', 'Lanthanoid', 'actinides', 'Actinoid', 'actinoids', 'Actinoid' ); | |
286 } | |
287 | |
288 # Generate list of elements... | |
289 if ($Options{mode} =~ /^All$/i) { | |
290 push @{$OptionsInfo{SpecifiedElementIDs}}, PeriodicTable::GetElements(); | |
291 } | |
292 else { | |
293 ELEMENTID: for $ElementID (@ElementIDs) { | |
294 if ($Options{mode} =~ /^ElementID$/i) { | |
295 if (PeriodicTable::IsElement($ElementID)) { | |
296 push @{$OptionsInfo{SpecifiedElementIDs}}, $ElementID; | |
297 } | |
298 else { | |
299 warn "Ignoring element ID, $ElementID, specified using command line parameter: Unknown element ID...\n"; | |
300 next ELEMENTID; | |
301 } | |
302 } | |
303 elsif ($Options{mode} =~ /^AmericanGroupLabel$/i) { | |
304 if (@GroupElements = PeriodicTable::GetElementsByAmericanStyleGroupLabel($ElementID)) { | |
305 push @{$OptionsInfo{SpecifiedElementIDs}}, @GroupElements; | |
306 } | |
307 else { | |
308 warn "Ignoring American style group label, $ElementID, specified using command line parameter: Unknown group label...\n"; | |
309 next ELEMENTID; | |
310 } | |
311 } | |
312 elsif ($Options{mode} =~ /^EuropeanGroupLabel$/i) { | |
313 if (@GroupElements = PeriodicTable::GetElementsByEuropeanStyleGroupLabel($ElementID)) { | |
314 push @{$OptionsInfo{SpecifiedElementIDs}}, @GroupElements; | |
315 } | |
316 else { | |
317 warn "Ignoring American style group label, $ElementID, specified using command line parameter: Unknown group label...\n"; | |
318 next ELEMENTID; | |
319 } | |
320 } | |
321 elsif ($Options{mode} =~ /^GroupNumber$/i) { | |
322 if (@GroupElements = PeriodicTable::GetElementsByGroupNumber($ElementID)) { | |
323 push @{$OptionsInfo{SpecifiedElementIDs}}, @GroupElements; | |
324 } | |
325 else { | |
326 warn "Ignoring group number, $ElementID, specified using command line parameter: Unknown group number...\n"; | |
327 next ELEMENTID; | |
328 } | |
329 } | |
330 elsif ($Options{mode} =~ /^GroupName$/i) { | |
331 if (exists $GroupNamesMap{lc($ElementID)}) { | |
332 @GroupElements = PeriodicTable::GetElementsByGroupName($GroupNamesMap{lc($ElementID)}); | |
333 push @{$OptionsInfo{SpecifiedElementIDs}}, @GroupElements; | |
334 } | |
335 else { | |
336 warn "Ignoring group name, $ElementID, specified using command line parameter: Unknown group name...\n"; | |
337 next ELEMENTID; | |
338 } | |
339 } | |
340 elsif ($Options{mode} =~ /^PeriodNumber$/i) { | |
341 if (@GroupElements = PeriodicTable::GetElementsByPeriodNumber($ElementID)) { | |
342 push @{$OptionsInfo{SpecifiedElementIDs}}, @GroupElements; | |
343 } | |
344 else { | |
345 warn "Ignoring period number, $ElementID, specified using command line parameter: Unknown period number...\n"; | |
346 next ELEMENTID; | |
347 } | |
348 } | |
349 } | |
350 } | |
351 SetupSpecifiedProperties(); | |
352 | |
353 # Setup output file name... | |
354 $OptionsInfo{OutFileName} = ''; | |
355 if ($OptionsInfo{FileOutput}) { | |
356 my($OutFileRoot, $OutFileExt); | |
357 | |
358 $OutFileRoot = ''; | |
359 $OutFileExt = "csv"; | |
360 if ($Options{outdelim} =~ /^tab$/i) { | |
361 $OutFileExt = "tsv"; | |
362 } | |
363 if ($Options{root}) { | |
364 my ($RootFileDir, $RootFileName, $RootFileExt) = ParseFileName($Options{root}); | |
365 if ($RootFileName && $RootFileExt) { | |
366 $OutFileRoot = $RootFileName; | |
367 } | |
368 else { | |
369 $OutFileRoot = $Options{root}; | |
370 } | |
371 } | |
372 else { | |
373 $OutFileRoot = 'PeriodicTableElementsInfo' . $Options{mode}; | |
374 } | |
375 $OptionsInfo{OutFileName} = $OutFileRoot . '.' . $OutFileExt; | |
376 if (!$Options{overwrite}) { | |
377 if (-e $OptionsInfo{OutFileName}) { | |
378 die "Error: Output file, $OptionsInfo{OutFileName}, already exists.\nUse \-o --overwrite\ option or specify a different name using \"-r --root\" option.\n"; | |
379 } | |
380 } | |
381 } | |
382 } | |
383 | |
384 # Setup properties to list... | |
385 sub SetupSpecifiedProperties { | |
386 $OptionsInfo{Properties} = defined $Options{properties} ? $Options{properties} : undef; | |
387 | |
388 $OptionsInfo{PropertiesMode} = $Options{propertiesmode}; | |
389 $OptionsInfo{PropertiesListing} = $Options{propertieslisting}; | |
390 | |
391 # Make sure atomic appropriate properties/category names are specified... | |
392 @{$OptionsInfo{SpecifiedProperies}} = (); | |
393 if ($Options{properties} && ($Options{propertiesmode} =~ /^All$/i) ) { | |
394 warn "Warning: Ignoring values specifed by \"-p --properties\" option: Not valid for All value of \"--propertiesmode\" option...\n"; | |
395 } | |
396 if ($Options{propertiesmode} =~ /^All$/i) { | |
397 if ($Options{propertieslisting} =~ /^Alphabetical$/i) { | |
398 push @{$OptionsInfo{SpecifiedProperies}}, PeriodicTable::GetElementPropertiesNames('Alphabetical'); | |
399 } | |
400 else { | |
401 push @{$OptionsInfo{SpecifiedProperies}}, PeriodicTable::GetElementPropertiesNames(); | |
402 } | |
403 push @{$OptionsInfo{SpecifiedProperies}}, 'NaturalIsotopeData'; | |
404 } | |
405 else { | |
406 if ($Options{properties}) { | |
407 if ($Options{propertiesmode} =~ /^Categories$/i) { | |
408 # Check category name... | |
409 if ($Options{properties} !~ /^(Basic|BasicAndNaturalIsotope|NaturalIsotope)$/i) { | |
410 die "Error: The value specified, $Options{properties}, for option \"-p --properties\" in conjunction with \"Categories\" value for option \"--propertiesmode\" is not valid. Allowed values: Basic, BasicAndNaturalIsotope, NaturalIsotope\n"; | |
411 } | |
412 # Set propertynames... | |
413 push @{$OptionsInfo{SpecifiedProperies}}, GetPropertyNamesFromCategories($Options{properties}); | |
414 } | |
415 else { | |
416 # Check property names.. | |
417 my($Name, $PropertyName, @Names); | |
418 @Names = split /\,/, $Options{properties}; | |
419 NAME: for $Name (@Names) { | |
420 $PropertyName = RemoveLeadingAndTrailingWhiteSpaces($Name); | |
421 if ($PropertyName =~ /^NaturalIsotopeData$/i) { | |
422 push @{$OptionsInfo{SpecifiedProperies}}, $PropertyName; | |
423 next NAME; | |
424 } | |
425 if (PeriodicTable::IsElementProperty($PropertyName)) { | |
426 push @{$OptionsInfo{SpecifiedProperies}}, $PropertyName; | |
427 } | |
428 else { | |
429 warn "Warning: Ignoring value, $Name, specifed by \"-p --properties\" option: Unknown property name...\n"; | |
430 } | |
431 } | |
432 if ($Options{propertieslisting} =~ /^Alphabetical$/i) { | |
433 # AtomicNumber, ElementSymbol and ElementName are always listed first and | |
434 # NaturalIsotopeData in the end... | |
435 my($AtomicNumberPresent, $ElementSymbolPresent, $ElementNamePresent, $NaturalIsotopeDataPresent, @AlphabeticalProperties, %PropertiesMap); | |
436 %PropertiesMap = (); | |
437 @AlphabeticalProperties = (); | |
438 $AtomicNumberPresent = 0; $ElementSymbolPresent = 0; $ElementNamePresent = 0; $NaturalIsotopeDataPresent = 0; | |
439 NAME: for $Name (@{$OptionsInfo{SpecifiedProperies}}) { | |
440 if ($Name =~ /^AtomicNumber$/i) { | |
441 $AtomicNumberPresent = 1; | |
442 next NAME; | |
443 } | |
444 if ($Name =~ /^ElementSymbol$/i) { | |
445 $ElementSymbolPresent = 1; | |
446 next NAME; | |
447 } | |
448 if ($Name =~ /^ElementName$/i) { | |
449 $ElementNamePresent = 1; | |
450 next NAME; | |
451 } | |
452 if ($Name =~ /^NaturalIsotopeData$/i) { | |
453 $NaturalIsotopeDataPresent = 1; | |
454 next NAME; | |
455 } | |
456 $PropertiesMap{$Name} = $Name; | |
457 } | |
458 # Setup the alphabetical list... | |
459 if ($AtomicNumberPresent) { | |
460 push @AlphabeticalProperties, 'AtomicNumber'; | |
461 } | |
462 if ($ElementSymbolPresent) { | |
463 push @AlphabeticalProperties, 'ElementSymbol'; | |
464 } | |
465 if ($ElementNamePresent) { | |
466 push @AlphabeticalProperties, 'ElementName'; | |
467 } | |
468 for $Name (sort keys %PropertiesMap) { | |
469 push @AlphabeticalProperties, $Name; | |
470 } | |
471 if ($NaturalIsotopeDataPresent) { | |
472 push @AlphabeticalProperties, 'NaturalIsotopeData'; | |
473 } | |
474 @{$OptionsInfo{SpecifiedProperies}} = (); | |
475 push @{$OptionsInfo{SpecifiedProperies}}, @AlphabeticalProperties; | |
476 } | |
477 } | |
478 } | |
479 else { | |
480 # Set default value... | |
481 push @{$OptionsInfo{SpecifiedProperies}}, GetPropertyNamesFromCategories('Basic'); | |
482 } | |
483 } | |
484 } | |
485 | |
486 # Setup script usage and retrieve command line arguments specified using various options... | |
487 sub SetupScriptUsage { | |
488 | |
489 # Retrieve all the options... | |
490 %Options = (); | |
491 $Options{mode} = "ElementID"; | |
492 $Options{outdelim} = "comma"; | |
493 $Options{output} = "STDOUT"; | |
494 $Options{outputstyle} = "ElementBlock"; | |
495 $Options{precision} = 4; | |
496 $Options{propertiesmode} = "Categories"; | |
497 $Options{propertieslisting} = "ByGroup"; | |
498 $Options{quote} = "yes"; | |
499 | |
500 if (!GetOptions(\%Options, "help|h", "mode|m=s", "outdelim=s", "output=s", "outputstyle=s", "overwrite|o", "precision=i", "properties|p=s", "propertieslisting=s", "propertiesmode=s", "quote|q=s", "root|r=s", "workingdir|w=s")) { | |
501 die "\nTo get a list of valid options and their values, use \"$ScriptName -h\" or\n\"perl -S $ScriptName -h\" command and try again...\n"; | |
502 } | |
503 if ($Options{workingdir}) { | |
504 if (! -d $Options{workingdir}) { | |
505 die "Error: The value specified, $Options{workingdir}, for option \"-w --workingdir\" is not a directory name.\n"; | |
506 } | |
507 chdir $Options{workingdir} or die "Error: Couldn't chdir $Options{workingdir}: $! \n"; | |
508 } | |
509 if ($Options{mode} !~ /^(ElementID|AmericanGroupLabel|EuropeanGroupLabel|GroupNumber|GroupName|PeriodNumber|All)$/i) { | |
510 die "Error: The value specified, $Options{mode}, for option \"-m --mode\" is not valid. Allowed values: ElementID, AmericanGroupLabel, EuropeanGroupLabel, GroupNumber, GroupName, PeriodNumber, or All\n"; | |
511 } | |
512 if ($Options{outdelim} !~ /^(comma|semicolon|tab)$/i) { | |
513 die "Error: The value specified, $Options{outdelim}, for option \"--outdelim\" is not valid. Allowed values: comma, tab, or semicolon\n"; | |
514 } | |
515 if ($Options{output} !~ /^(STDOUT|File)$/i) { | |
516 die "Error: The value specified, $Options{output}, for option \"--output\" is not valid. Allowed values: STDOUT or File\n"; | |
517 } | |
518 if ($Options{outputstyle} !~ /^(ElementBlock|ElementRows)$/i) { | |
519 die "Error: The value specified, $Options{outputstyle}, for option \"--outputstyle\" is not valid. Allowed values: ElementBlock or ElementRows\n"; | |
520 } | |
521 if (!IsPositiveInteger($Options{precision})) { | |
522 die "Error: The value specified, $Options{precision}, for option \"-p --precision\" is not valid. Allowed values: > 0 \n"; | |
523 } | |
524 if ($Options{propertiesmode} !~ /^(Categories|Names|All)$/i) { | |
525 die "Error: The value specified, $Options{propertiesmode}, for option \"--propertiesmode\" is not valid. Allowed values: Categories, Names, or All\n"; | |
526 } | |
527 if ($Options{propertieslisting} !~ /^(ByGroup|Alphabetical)$/i) { | |
528 die "Error: The value specified, $Options{propertieslisting}, for option \"--propertieslisting\" is not valid. Allowed values: ByGroup, or Alphabetical\n"; | |
529 } | |
530 if ($Options{quote} !~ /^(yes|no)$/i) { | |
531 die "Error: The value specified, $Options{quote}, for option \"-q --quote\" is not valid. Allowed values: yes or no\n"; | |
532 } | |
533 } | |
534 | |
535 __END__ | |
536 | |
537 =head1 NAME | |
538 | |
539 InfoPeriodicTableElements.pl - List atomic properties of elements | |
540 | |
541 =head1 SYNOPSIS | |
542 | |
543 InfoPeriodicTableElements.pl ElementID(s)... | |
544 | |
545 InfoPeriodicTableElements.pl [B<-h, --help>] | |
546 [B<-m, --mode> ElementID | AmericanGroupLabel | EuropeanGroupLabel | GroupNumber | GroupName | PeriodNumber | All] | |
547 [B<--outdelim> comma | tab | semicolon] [B<--output> STDOUT | File] [B<--outputstyle> ElementBlock | ElementRows] | |
548 [B<-o, --overwrite>] [B<--precision> number] [B<--propertiesmode> Categories | Names | All] | |
549 [B<-p, --properties> CategoryName,[CategoryName,...] | PropertyName,[PropertyName,...]] | |
550 [B<--propertieslinting> ByGroup | Alphabetical] [B<-q, --quote> yes | no] [B<-r, --root> rootname] | |
551 [B<-w, --workingdir> dirname] ElementID(s)... | |
552 | |
553 =head1 DESCRIPTION | |
554 | |
555 List atomic properties of elements in the periodic table. A variety of methods are available to | |
556 specify elements of interest: atomic numbers, element symbols, American or European style group | |
557 labels, IUPAC group numbers, period numbers, and group names. | |
558 | |
559 Atomic properties data, in addition to basic information about the periodic table elements, is | |
560 also available for these categories: atomic radii, bulk properties, common valences, electronegativities, | |
561 electron affinities, historical data, ionization energies, natural isotopes, oxidation states, | |
562 and thermal properties. | |
563 | |
564 Natural isotopes data include mass number, relative atomic mass and percent natural | |
565 abundance for each isotope of an element. | |
566 | |
567 =head1 PARAMETERS | |
568 | |
569 =over 4 | |
570 | |
571 =item B<ElementIDs> I<ElementSymbol [AtomicNumber...] | GroupLabel [GroupLabel...] | GroupNumbel [GroupNumber...] | PeriodNumber [PeriodNumbe...]> | |
572 | |
573 Command line specification of elements is mode specific. In general, it's a space delimited list of values to identify | |
574 elements. All element IDs must correspond to a specific mode; mixed specifications is not supported. | |
575 | |
576 For I<ElementID> mode, input value format is: I<AtomicNumber [ElementSymbol ...]>. Default: I<H>. | |
577 Examples: | |
578 | |
579 C | |
580 6 | |
581 C N O P S Cl | |
582 6 7 8 15 16 17 | |
583 C 7 8 15 S 17 | |
584 | |
585 For I<AmericanGroupLabel> mode, input value format is: I<GroupLabel [GroupLabel ...]>. Default: I<IA>. Possible | |
586 group label values are: I<IA IIA IIIB IVB VB VIB VIIB VIII or VIIIB IB IIB IIIA IVA VA, | |
587 VIA, VIIA, VIIA>. Examples: | |
588 | |
589 IA | |
590 IA IVA IIB | |
591 | |
592 For I<EuropeanGroupLabel> mode, input value format is: I<GroupLabel [GroupLabel ...]>. Default: I<IA>. Possible | |
593 group label values are: I<IA IIA IIIA IVA VA VIA VIIA VIII or VIIIA IB IIB IIIB IVB VB, | |
594 VIB VIIB VIIB>. Examples: | |
595 | |
596 IA | |
597 IA IVB IIB | |
598 | |
599 For IUPAC I<GroupNumber> mode, input value format is: I<GroupNumber [GroupNumber...]>. Default: I<1>. Possible | |
600 group label values are: I<1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18>. Examples: | |
601 | |
602 1 | |
603 1 14 12 | |
604 | |
605 For I<GroupName> mode, input value format is: I<GroupName [GroupName...]>. Default: I<AlkaliMetals>. Possible | |
606 group name values are: I<AlkaliMetals AlkalineEarthMetals Chalcogens CoinageMetals Halogens | |
607 NobleGases Pnictogens Lanthanides or Lanthanoids, Actinides or Actinoids>. Examples: | |
608 | |
609 AlkaliMetals | |
610 AlkaliMetals Halogens NobleGases | |
611 | |
612 For I<PeriodNumber> mode, input value format is: I<PeriodNumber [PeriodNumber,...]>. Default: I<1>. Possible | |
613 group label values are: I<1 2 3 4 5 6 7>. Examples: | |
614 | |
615 1 | |
616 1 2 3 | |
617 | |
618 For I<All> mode, no input value is needed and atomic properties information is listed for all the | |
619 elements. | |
620 | |
621 =back | |
622 | |
623 =head1 OPTIONS | |
624 | |
625 =over 4 | |
626 | |
627 =item B<-h, --help> | |
628 | |
629 Print this help message. | |
630 | |
631 =item B<-m, --mode> I<ElementID | AmericanGroupLabel | EuropeanGroupLabel | GroupNumber | GroupName | PeriodNumber | All> | |
632 | |
633 Specify elements for listing atomic properties using one of these methods: atomic numbers | |
634 and/or element symbols list, American style group labels, European style group labels, IUPAC | |
635 group number, group names, period numbers, or all elements. | |
636 | |
637 Possible values: I<ElementID, AmericanGroupLabel, EuropeanGroupLabel, GroupNumber, | |
638 GroupName, PeriodNumber, All>. Default: I<ElementID>. | |
639 | |
640 =item B<--outdelim> I<comma | tab | semicolon> | |
641 | |
642 Output text file delimiter. Possible values: I<comma, tab, or semicolon> | |
643 Default value: I<comma>. | |
644 | |
645 =item B<--output> I<STDOUT | File> | |
646 | |
647 List information at STDOUT or write it to a file. Possible values: I<STDOUT or File>. Default: | |
648 I<STDOUT>. B<-r, --root> option is used to generate output file name. | |
649 | |
650 =item B<--outputstyle> I<ElementBlock | ElementRows> | |
651 | |
652 Specify how to list element information: add a new line for each property and present it as a block | |
653 for each element; or include all properties in one line and show it as a single line. | |
654 | |
655 Possible values: I<ElementBlock | ElementRows>. Default: I<ElementBlock> | |
656 | |
657 An example for I<ElementBlock> output style: | |
658 | |
659 Atomic number: 1 | |
660 Element symbol: H | |
661 Element name: Hydrogen | |
662 Atomic weight: 1.00794 | |
663 ... ... | |
664 ... ... | |
665 | |
666 Atomic number: 6 | |
667 Element symbol: C | |
668 Element name: Carbon | |
669 Atomic weight: 12.0107 | |
670 ... ... | |
671 ... ... | |
672 | |
673 An example for I<ElementRows> output style: | |
674 | |
675 Atomic number, Element symbol, Elemenet name, Atomic weight, ... | |
676 1,H,Hydrogen,1.00794,.. | |
677 6,C,Carbon,12.0107,.. | |
678 | |
679 =item B<-o, --overwrite> | |
680 | |
681 Overwrite existing files. | |
682 | |
683 =item B<--precision> I<number> | |
684 | |
685 Precision for listing numerical values. Default: up to I<4> decimal places. | |
686 Valid values: positive integers. | |
687 | |
688 =item B<--propertiesmode> I<Categories | Names | All> | |
689 | |
690 Specify how property names are specified: use category names; explicit list of property names; or | |
691 use all available properties. Possible values: I<Categories, Names, or All>. Default: I<Categories>. | |
692 | |
693 This option is used in conjunction with B<-p, --properties> option to specify properties of | |
694 interest. | |
695 | |
696 =item B<-p, --properties> I<CategoryName,[CategoryName,...] | PropertyName,[PropertyName,...]> | |
697 | |
698 This option is B<--propertiesmode> specific. In general, it's a list of comma separated category or | |
699 property names. | |
700 | |
701 Specify which atomic properties information to list for the elements specified using command line | |
702 parameters: list basic and/or isotope information; list all available information; or specify a comma | |
703 separated list of atomic property names. | |
704 | |
705 Possible values: I<Basic| BasicAndNaturalIsotope | NaturalIsotope | PropertyName,[PropertyName,...]>. | |
706 Default: I<Basic>. | |
707 | |
708 I<Basic> includes: I<AtomicNumber, ElementSymbol, ElementName, AtomicWeight, GroundStateConfiguration, | |
709 GroupNumber, PeriodNumber, FirstIonizationEnergy>. | |
710 | |
711 I<NaturalIsotope> includes: I<AtomicNumber, ElementSymbol, ElementName, MassNumber, | |
712 RelativeAtomicMass, NaturalAbundance>. | |
713 | |
714 Here is a complete list of available properties: AllenElectronegativity, AllredRochowElectronegativity, AtomicNumber, | |
715 AtomicRadiusCalculated, AtomicRadiusEmpirical, AtomicWeight, Block, BoilingPoint, BondLength, | |
716 BrinellHardness, BulkModulus, Classification, CoefficientOfLinearExpansion, Color, | |
717 CommonValences, LowestCommonValence, HighestCommonValence, | |
718 CommonOxidationNumbers, LowestCommonOxidationNumber, HighestCommonOxidationNumber, | |
719 CovalentRadiusEmpirical, CriticalTemperature, DensityOfSolid, DiscoveredAt, DiscoveredBy, | |
720 DiscoveredWhen, ElectricalResistivity, ElectronAffinity, ElementName, ElementSymbol, EnthalpyOfAtmization, | |
721 EnthalpyOfFusion, EnthalpyOfVaporization, FirstIonizationEnergy, GroundStateConfiguration, GroundStateLevel, | |
722 GroupName, GroupNumber, NaturalIsotopeData, MeltingPoint, MineralHardness, MolarVolume, | |
723 MullikenJaffeElectronegativity, OriginOfName, PaulingElectronegativity, PeriodNumber, PoissonsRatio, | |
724 Reflectivity, RefractiveIndex, RigidityModulus, SandersonElectronegativity, StandardState, | |
725 SuperconductionTemperature, ThermalConductivity, VanderWaalsRadius, VelocityOfSound, VickersHardness, | |
726 YoungsModulus. | |
727 | |
728 =item B<--propertieslisting> I<ByGroup | Alphabetical> | |
729 | |
730 Specify how to list properties for elements: group by category or an alphabetical by | |
731 property names. Possible values: I<ByGroup or Alphabetical>. Default: I<ByGroup>. | |
732 During I<Alphabetical> listing, element identification data - I<AtomicNumber, ElementSymbol, | |
733 ElementName> - is show first, and natural isotope data - I<MassNumber, RelativeAtomicMass, | |
734 NaturalAbundance> - is listed in the end. | |
735 | |
736 =item B<-q, --quote> I<yes | no> | |
737 | |
738 Put quotes around column values in output text file. Possible values: I<yes or | |
739 no>. Default value: I<yes>. | |
740 | |
741 =item B<-r, --root> I<rootname> | |
742 | |
743 New text file name is generated using the root: <Root>.<Ext>. File name is only | |
744 used during I<File> value of B<-o, --output> option. | |
745 | |
746 Default file name: PeriodicTableElementsInfo<mode>.<Ext>. The csv, and tsv | |
747 <Ext> values are used for comma/semicolon, and tab delimited text files respectively. | |
748 | |
749 =item B<-w, --workingdir> I<dirname> | |
750 | |
751 Location of working directory. Default: current directory. | |
752 | |
753 =back | |
754 | |
755 =head1 EXAMPLES | |
756 | |
757 To list basic atomic properties information for element H, type: | |
758 | |
759 % InfoPeriodicTableElements.pl | |
760 | |
761 To list basic atomic properties information for elements C,N,O and F, type: | |
762 | |
763 % InfoPeriodicTableElements.pl C N O F | |
764 | |
765 To list all available atomic properties information for elements C,N,O and F, type: | |
766 | |
767 % InfoPeriodicTableElements.pl --propertiesmode all 6 N O 9 | |
768 | |
769 To list basic and natural isotope information for elements C,N,O and F, type: | |
770 | |
771 % InfoPeriodicTableElements.pl --propertiesmode Categories | |
772 --properties BasicAndNaturalIsotope C N O F | |
773 | |
774 To list AtomicNumber, ElementName, AtomicWeight and CommonValences information | |
775 for elements C,N,O and F, type: | |
776 | |
777 % InfoPeriodicTableElements.pl --propertiesmode Names | |
778 --properties AtomicNumber,ElementName,AtomicWeight,CommonValences | |
779 C N O F | |
780 | |
781 To alphabetically list basic and natural isotope information for elements C,N,O and F in rows instead of | |
782 element blocks with quotes around the values, type: | |
783 | |
784 % InfoPeriodicTableElements.pl --propertiesmode Categories | |
785 --properties BasicAndNaturalIsotope --propertieslisting alphabetical | |
786 --outdelim comma --outputstyle ElementRows --quote yes C N O F | |
787 | |
788 To alphabetically list all available atomic information for elements C,N,O and F in rows instead of | |
789 element blocks with quotes around the values and write them into a file ElementProperties.csv, type: | |
790 | |
791 % InfoPeriodicTableElements.pl --propertiesmode Categories | |
792 --properties BasicAndNaturalIsotope --propertieslisting alphabetical | |
793 --outdelim comma --outputstyle ElementRows --quote yes | |
794 --output File -r ElementsProperties -o -m All | |
795 | |
796 To list basic atomic properties information for elements in groups IA and VIA using American | |
797 style group labels, type: | |
798 | |
799 % InfoPeriodicTableElements.pl -m AmericanGroupLabel IA VIA | |
800 | |
801 To list basic atomic properties information for elements in groups IA and VB using European | |
802 style group labels, type: | |
803 | |
804 % InfoPeriodicTableElements.pl -m AmericanGroupLabel IA VB | |
805 | |
806 To list basic atomic properties information for elements in groups Halogens and NobleGases, type: | |
807 | |
808 % InfoPeriodicTableElements.pl -m GroupName Halogens NobleGases | |
809 | |
810 =head1 AUTHOR | |
811 | |
812 Manish Sud <msud@san.rr.com> | |
813 | |
814 =head1 SEE ALSO | |
815 | |
816 InfoAminoAcids.pl InfoNucleicAcids.pl | |
817 | |
818 =head1 COPYRIGHT | |
819 | |
820 Copyright (C) 2015 Manish Sud. All rights reserved. | |
821 | |
822 This file is part of MayaChemTools. | |
823 | |
824 MayaChemTools is free software; you can redistribute it and/or modify it under | |
825 the terms of the GNU Lesser General Public License as published by the Free | |
826 Software Foundation; either version 3 of the License, or (at your option) | |
827 any later version. | |
828 | |
829 =cut |