File Coverage

blib/lib/Chemistry/Isotope.pm
Criterion Covered Total %
statement 25 25 100.0
branch 7 8 87.5
condition n/a
subroutine 6 6 100.0
pod 2 3 66.6
total 40 42 95.2


line stmt bran cond sub pod time code
1             package Chemistry::Isotope;
2              
3             $VERSION = '0.11';
4             # $Id: Isotope.pm,v 1.3 2005/05/18 23:14:04 itubert Exp $
5              
6 1     1   35817 use strict;
  1         3  
  1         35  
7 1     1   5 use warnings;
  1         1  
  1         29  
8 1     1   4 use base qw(Exporter);
  1         5  
  1         383  
9             our @EXPORT_OK = qw(isotope_mass isotope_abundance);
10             our %EXPORT_TAGS = (all => \@EXPORT_OK);
11              
12             my @masses;
13             my %abundances;
14              
15             sub isotope_mass {
16 3     3 1 896 my ($A, $Z) = @_;
17 3 100       13 read_data() unless @masses;
18 3         23 $masses[$A]{$Z};
19             }
20              
21             sub read_data {
22 1     1 0 2 local $_;
23 1         7 while () {
24 2932 100       5936 last if /^$/;
25 2931         7040 my ($A, $Z, $m) = split;
26 2931         10081 $masses[$A]{$Z} = $m;
27             }
28 1         12 while () {
29 288         614 my ($symbol, $A, $abundance) = split;
30 288         923 $abundances{$symbol}{$A} = $abundance;
31             }
32             }
33              
34             sub isotope_abundance {
35 2     2 1 818 my ($symbol) = shift;
36 2 50       8 read_data() unless @masses;
37 2 100       4 my %ret = %{$abundances{$symbol} || {}};
  2         18  
38 2         8 \%ret;
39             }
40              
41             1;
42              
43             =head1 NAME
44              
45             Chemistry::Isotope - Table of the isotopes exact mass data
46              
47             =head1 SYNOPSIS
48              
49             use Chemistry::Isotope ':all';
50              
51             # get the exact atomic mass for an isotope
52             my $m = isotope_mass(235, 92); # 235.043923094753
53              
54             my $ab_table = isotope_abundance('C');
55             while (my ($A, $percent_ab) = each %$ab_table) {
56             print "$A\t$percent_ab\n";
57             }
58             # this should print (the order may vary):
59             # 12 98.93
60             # 13 1.07
61              
62             =head1 DESCRIPTION
63              
64             This module contains the exact mass data from the table of the isotopes.
65             It has an exportable function, isotope_mass, which returns the mass
66             of an atom in mass units given its mass number (A) and atomic number (Z); and
67             a function isotope_abundance which returns a table with the natural abundance
68             of the isotopes given an element symbol.
69              
70             The table of the masses includes 2931 nuclides and is taken from
71             L (G. Audi and A.H. Wapstra, Nucl. Phys. A595,
72             409, 1995)
73              
74             The table of natural abundances includes 288 nuclides and is taken from
75             the Commission on Atomic Weights and Isotopic Abundances report for the
76             International Union of Pure and Applied Chemistry in Isotopic Compositions of
77             the Elements 1989, Pure and Applied Chemistry, 1998, 70, 217.
78             L
79              
80             =head1 FUNCTIONS
81              
82             =head2 isotope_mass($A, $Z)
83              
84             Return the mass for the atom with the given mass number and atomic number,
85             or undef if the nuclide is not in the data table.
86              
87             =head2 isotope_abundance($symbol)
88              
89             Returns a hash reference with the natural abundance information for the
90             isotopes of a given element. The hash keys are the mass numbers, and the
91             values are the abundance percentages. For example, isotope_abundance('C')
92             returns the following structure:
93              
94             {
95             '13' => '1.07',
96             '12' => '98.93'
97             };
98              
99              
100             =head1 VERSION
101              
102             0.11
103              
104             =head1 SEE ALSO
105              
106             L
107              
108             The PerlMol website L
109              
110             =head1 AUTHOR
111              
112             Ivan Tubert-Brohman Eitub@cpan.orgE
113              
114             =head1 COPYRIGHT
115              
116             Copyright (c) 2005 Ivan Tubert-Brohman. All rights reserved. This program is
117             free software; you can redistribute it and/or modify it under the same terms as
118             Perl itself.
119              
120             =cut
121              
122             __DATA__