blib/lib/Chemistry/Isotope.pm

filter: Statementstmt 100% 30 / 30 Branchbran 80.0% 8 / 10 Conditioncond 100% 2 / 2 MC/DCmcdc 100% 1 / 1 Subroutinesub 100% 6 / 6 Podpod 66.6% 2 / 3 totaltotal 94.2% 49 / 52 CC 7 SCAR 9.8
CC
7
Cov
95%
read_data
4.0
isotope_abundance
3.0
isotope_mass
2.0
CRAP 2.7
↑ Summary
1 package Chemistry::Isotope;
2  
3 1 $VERSION = '0.11';
4 # $Id: Isotope.pm,v 1.3 2005/05/18 23:14:04 itubert Exp $
5  
6 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use base qw(Exporter);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 our @EXPORT_OK = qw(isotope_mass isotope_abundance);
10 1 our %EXPORT_TAGS = (all => \@EXPORT_OK);
11  
12 1 my @masses;
13 my %abundances;
14  
15 3 ▶sub isotope_mass {
Subroutine isotope_mass: called CC=2 SCAR=6.9
Pod documented
16 3 my ($A, $Z) = @_;
17 3 ▶ read_data() unless @masses;
Branch: 1 branch
BranchTrueFalseTotal
unless @masses 1 2 3
18 3 $masses[$A]{$Z};
19 }
20  
21 1 ▶sub read_data {
Subroutine read_data: called CC=4 SCAR=13.9
Pod undocumented
22 1 local $_;
23 1 ▶ while (<DATA>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline DATA)) 2932 0 2932
24 2932 ▶ last if /^$/;
Branch: 1 branch
BranchTrueFalseTotal
if /^$/ 1 2931 2932
25 2931 my ($A, $Z, $m) = split;
26 2931 $masses[$A]{$Z} = $m;
27 }
28 1 ▶ while (<DATA>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline DATA)) 288 1 289
29 288 my ($symbol, $A, $abundance) = split;
30 288 $abundances{$symbol}{$A} = $abundance;
31 }
32 }
33  
34 2 ▶sub isotope_abundance {
Subroutine isotope_abundance: called CC=3 SCAR=11.0
Pod documented
35 2 my ($symbol) = shift;
36 2 ▶ read_data() unless @masses;
Branch: 1 branch
BranchTrueFalseTotal
unless @masses 0 2 2
37 2 ▶ my %ret = %{$abundances{$symbol} || {}};
Condition100%2/2
$abundances{$symbol} || {}
l!l
11
MC/DC100%1/1
$abundances{$symbol} || {}
$abundances{$symbol}
Truth table100%2/2
A
A= $abundances{$symbol}
Aresult
11
00
38 2 \%ret;
39 }
40  
41 1 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<http://ie.lbl.gov/txt/awm95.txt> (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<http://www.iupac.org/publications/pac/1998/pdf/7001x0217.pdf>
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<Chemistry::Atom>
107  
108 The PerlMol website L<http://www.perlmol.org/>
109  
110 =head1 AUTHOR
111  
112 Ivan Tubert-Brohman E<lt>itub@cpan.orgE<gt>
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__
↑ Summary