function T = isotopes(varargin)
%ISOTOPES Returns NMR properties of the isotopes
% T = isotopes(i1, i2, ...)
%
% EXAMPLE
%     H = isotopes('1H'), T = isotopes('3H'), or if the atomic mass is not
%     specified, i.e. I = isotopes('H'), the function returns array of
%     structures with data for all isotopes of the specified element.
%     isotopes('n') returns NMR properties for neutron. Isotopes called
%     without arguments returns the whole table.
%
% The output structure has the following fields:
%     .name - element name;
%     .isotope - element symbol and mass number, i.e. 19F;
%     .Z - atomic number;
%     .mass - mass number; 
%     .I - nuclear spin;
%     .gamma - magnetogyric ratio in rad/(T s) calculated from the resonant
%              frequency: 2*pi*F(@1T);
%     .ResFreq - resonant frequency in Hertz for an applied field B0 of 1 tesla
%                (in cgs units, 10 kilogauss);
%     .RelSensB - sensitivity relative to 1H (=1) assuming an equal number
%                 of nuclei, constant temperature, and constant B0:
%                 0.0076508(mu/mu_N)^3(I + 1)/I^2;
%     .RelSensF - sensitivity relative to 1H (=1) assuming an equal number
%                 of nuclei, constant temperature, and constant resonance
%                 frequency: O.23871(mu/mu_N)(I + 1);
%     .u - nuclear magnetic moment in units of the nuclear magneton, (mu/mu_N);
%     .Q - nuclear quadrupole moment in units of femtometers squared
%          (1 fm2 = 10^-2 barn) 
%
%
% REFERENCES 
% 1. "Nuclear spins, moments, and other data related to NMR spectroscopy" (9-93)
%    CRC Handbook of Chemistry and Physics, 83th Ed., CRC Press, Boca Raton, FL, 
%    2002. 
% 2. Stone, N. J., <www.nndc.bnl.gov/nndc/stone_moments/>
% 3. http://www.hbcpnetbase.com/

% Copyright (c) 2002 by Peter L. Volegov (volegov@unm.edu)   
% All Rights Reserved.                                       


%% Table of the Isotopes
% Element, Name, Z, AtomicMass, Spin, F@1T/MHz, RelSens(H), RelSens(F), mu/mu_N, Q/fm2
TheTable = {
'n', 'neutron', 1, 1, 1/2, 29.1647, 0.32139, 0.6850, -1.913042720, 0.0000; ...
'H', 'Hydrogen', 1, 1, 1/2, 42.5775, 1.00000, 1.0000, 2.792847337, 0.0000; ...
'H', 'Deuterium', 1, 2, 1, 6.5359, 0.00965, 0.4093, 0.857438228, 0.2860; ...
'H', 'Tritium', 1, 3, 1/2, 45.4148, 1.21354, 1.0666, 2.978962500, 0.0000; ...
'He', 'Helium', 2, 3, 1/2, 32.4360, 0.44212, 0.7618, -2.127624800, 0.0000; ...
'Li', 'Lithium', 3, 6, 1, 6.2661, 0.00850, 0.3925, 0.822046700, -0.0808; ...
'Li', 'Lithium', 3, 7, 3/2, 16.5483, 0.29356, 1.9433, 3.256440000, -4.0100; ...
'Be', 'Beryllium', 4, 9, 3/2, 5.9842, 0.01388, 0.7027, -1.177600000, 5.2880; ...
'B', 'Boron', 5, 10, 3, 4.5752, 0.01985, 1.7193, 1.800645000, 8.4590; ...
'B', 'Boron', 5, 11, 3/2, 13.6630, 0.16522, 1.6045, 2.688649000, 4.0590; ...
'C', 'Carbon', 6, 13, 1/2, 10.7084, 0.01591, 0.2515, 0.702411800, 0.0000; ...
'N', 'Nitrogen', 7, 14, 1, 3.0777, 0.00101, 0.1928, 0.403761000, 2.0440; ...
'N', 'Nitrogen', 7, 15, 1/2, 4.3173, 0.00104, 0.1014, -0.283188800, 0.0000; ...
'O', 'Oxygen', 8, 17, 5/2, 5.7742, 0.02910, 1.5822, -1.893790000, -2.5580; ...
'F', 'Fluorine', 9, 19, 1/2, 40.0776, 0.83400, 0.9413, 2.628868000, 0.0000; ...
'Ne', 'Neon', 10, 21, 3/2, 3.3631, 0.00246, 0.3949, -0.661797000, 10.1550; ...
'Na', 'Sodium', 11, 23, 3/2, 11.2688, 0.09270, 1.3233, 2.217522000, 10.4000; ...
'Mg', 'Magnesium', 12, 25, 5/2, 2.6083, 0.00268, 0.7147, -0.855450000, 19.9400; ...
'Al', 'Aluminum', 13, 27, 5/2, 11.1031, 0.20689, 3.0424, 3.641507000, 14.6600; ...
'Si', 'Silicon', 14, 29, 1/2, 8.4655, 0.00786, 0.1988, -0.555290000, 0.0000; ...
'P', 'Phosphorus', 15, 31, 1/2, 17.2515, 0.06652, 0.4052, 1.131600000, 0.0000; ...
'S', 'Sulfur', 16, 33, 3/2, 3.2717, 0.00227, 0.3842, 0.643821200, -6.7800; ...
'Cl', 'Chlorine', 17, 35, 3/2, 4.1765, 0.00472, 0.4905, 0.821874300, -8.1650; ...
'Cl', 'Chlorine', 17, 37, 3/2, 3.4765, 0.00272, 0.4083, 0.684123600, -6.4350; ...
'Ar', 'Argone', 18, 37, 3/2, 5.8190, 0.01276, 0.6833, 1.145000000, 0.0000; ...
'Ar', 'Argone', 18, 39, 7/2, 3.4600, 0.01130, 1.7079, -1.590000000, 0.0000; ...
'K', 'Potassium', 19, 39, 3/2, 1.9893, 0.00051, 0.2336, 0.391466200, 5.8500; ...
'K', 'Potassium', 19, 40, 4, 2.4737, 0.00523, 1.5493, -1.298100000, -7.3000; ...
'K', 'Potassium', 19, 41, 3/2, 1.0919, 8.00000, 0.1282, 0.214870100, 7.1100; ...
'Ca', 'Calcium', 20, 43, 7/2, 2.8688, 0.00642, 1.4150, -1.317260000, -4.0800; ...
'Sc', 'Scandium', 21, 45, 7/2, 10.3591, 0.30244, 5.1093, 4.756487000, -22.0000; ...
'Ti', 'Titanium', 22, 47, 5/2, 2.4041, 0.00210, 0.6587, -0.788480000, 30.2000; ...
'Ti', 'Titanium', 22, 49, 7/2, 2.4048, 0.00378, 1.1861, -1.104170000, 24.7000; ...
'V', 'Vanadium', 23, 50, 6, 4.2505, 0.05571, 5.5904, 3.345689000, 21.0000; ...
'V', 'Vanadium', 23, 51, 7/2, 11.2133, 0.38360, 5.5306, 5.148705700, -5.2000; ...
'Cr', 'Chromium', 24, 53, 3/2, 2.4115, 0.00091, 0.2832, -0.474540000, -15.0000; ...
'Mn', 'Manganese', 25, 55, 5/2, 10.5763, 0.17881, 2.8980, 3.468720000, 33.0000; ...
'Fe', 'Iron', 26, 57, 1/2, 1.3816, 0.00003, 0.0324, 0.090623000, 0.0000; ...
'Co', 'Cobalt', 27, 59, 7/2, 10.0770, 0.27841, 4.9702, 4.627000000, 42.0000; ...
'Ni', 'Nickel', 28, 61, 3/2, 3.8114, 0.00359, 0.4476, -0.750020000, 16.2000; ...
'Cu', 'Copper', 29, 63, 3/2, 11.2982, 0.09342, 1.3268, 2.223290000, -22.0000; ...
'Cu', 'Copper', 29, 65, 3/2, 12.1030, 0.11484, 1.4213, 2.381670000, -20.4000; ...
'Zn', 'Zinc', 30, 67, 5/2, 2.6694, 0.00287, 0.7314, 0.875479000, 15.0000; ...
'Ga', 'Gallium', 31, 69, 3/2, 10.2478, 0.06971, 1.2034, 2.016590000, 17.1000; ...
'Ga', 'Gallium', 31, 71, 3/2, 13.0208, 0.14300, 1.5291, 2.562270000, 10.7000; ...
'Ge', 'Germanium', 32, 73, 9/2, 1.4897, 0.00141, 1.1546, -0.879467700, -19.6000; ...
'As', 'Arsenic', 33, 75, 3/2, 7.3150, 0.02536, 0.8590, 1.439475000, 31.4000; ...
'Se', 'Selenium', 34, 77, 1/2, 8.1571, 0.00703, 0.1916, 0.535060000, 0.0000; ...
'Br', 'Bromine', 35, 79, 3/2, 10.7042, 0.07945, 1.2570, 2.106400000, 31.3000; ...
'Br', 'Bromine', 35, 81, 3/2, 11.5384, 0.09951, 1.3550, 2.270562000, 26.2000; ...
'Kr', 'Krypton', 36, 83, 9/2, 1.6442, 0.00190, 1.2744, -0.970669000, 25.9000; ...
'Rb', 'Rubidium', 37, 85, 5/2, 4.1254, 0.01061, 1.1304, 1.353030000, 27.6000; ...
'Rb', 'Rubidium', 37, 87, 3/2, 13.9811, 0.17703, 1.6418, 2.751240000, 13.3500; ...
'Sr', 'Strontium', 38, 87, 9/2, 1.8525, 0.00272, 1.4358, -1.093603000, 33.5000; ...
'Y', 'Yttrium', 39, 89, 1/2, 2.0949, 0.00012, 0.0492, -0.137415400, 0.0000; ...
'Zr', 'Zirconium', 40, 91, 5/2, 3.9748, 0.00949, 1.0891, -1.303620000, -17.6000; ...
'Nb', 'Niobium', 41, 93, 9/2, 10.4523, 0.48821, 8.1011, 6.170500000, -32.0000; ...
'Mo', 'Molybdenum', 42, 95, 5/2, 2.7874, 0.00327, 0.7638, -0.914200000, -2.2000; ...
'Mo', 'Molybdenum', 42, 97, 5/2, 2.8463, 0.00349, 0.7799, -0.933500000, 25.5000; ...
'Tc', 'Technetium', 43, 99, 9/2, 9.6294, 0.38174, 7.4633, 5.684700000, -12.9000; ...
'Ru', 'Ruthenium', 44, 99, 5/2, 1.9553, 0.00113, 0.5358, -0.641300000, 7.9000; ...
'Ru', 'Ruthenium', 44, 101, 5/2, 2.1916, 0.00159, 0.6005, -0.718800000, 45.7000; ...
'Rh', 'Rhodium', 45, 103, 1/2, 1.3477, 0.00003, 0.0317, -0.088400000, 0.0000; ...
'Pd', 'Palladium', 46, 105, 5/2, 1.9570, 0.00113, 0.5364, -0.642000000, 66.0000; ...
'Ag', 'Silver', 47, 107, 1/2, 1.7331, 0.00007, 0.0407, -0.113679600, 0.0000; ...
'Ag', 'Silver', 47, 109, 1/2, 1.9924, 0.00010, 0.0468, -0.130690600, 0.0000; ...
'Cd', 'Cadmium', 48, 111, 1/2, 9.0692, 0.00966, 0.2130, -0.594886100, 0.0000; ...
'Cd', 'Cadmium', 48, 113, 1/2, 9.4871, 0.01106, 0.2228, -0.622300900, 0.0000; ...
'In', 'Indium', 49, 113, 9/2, 9.3655, 0.35121, 7.2588, 5.528900000, 79.9000; ...
'In', 'Indium', 49, 115, 9/2, 9.3856, 0.35348, 7.2744, 5.540800000, 81.0000; ...
'Sn', 'Tin', 50, 115, 1/2, 14.0077, 0.03561, 0.3290, -0.918830000, 0.0000; ...
'Sn', 'Tin', 50, 117, 1/2, 15.2610, 0.04605, 0.3584, -1.001040000, 0.0000; ...
'Sn', 'Tin', 50, 119, 1/2, 15.9660, 0.05273, 0.3750, -1.047280000, 0.0000; ...
'Sb', 'Antimony', 51, 121, 5/2, 10.2551, 0.16302, 2.8100, 3.363400000, -36.0000; ...
'Sb', 'Antimony', 51, 123, 7/2, 5.5532, 0.04659, 2.7389, 2.549800000, -49.0000; ...
'Te', 'Tellurium', 52, 123, 1/2, 11.2349, 0.01837, 0.2639, -0.736947800, 0.0000; ...
'Te', 'Tellurium', 52, 125, 1/2, 13.5454, 0.03220, 0.3181, -0.888505100, 0.0000; ...
'I', 'Iodine', 53, 127, 5/2, 8.5778, 0.09540, 2.3504, 2.813273000, -71.0000; ...
'Xe', 'Xenon', 54, 129, 1/2, 11.8604, 0.02162, 0.2786, -0.777976300, 0.0000; ...
'Xe', 'Xenon', 54, 131, 3/2, 3.5159, 0.00282, 0.4129, 0.691861900, -11.4000; ...
'Cs', 'Cesium', 55, 133, 7/2, 5.6234, 0.04838, 2.7735, 2.582025000, -0.3430; ...
'Ba', 'Barium', 56, 135, 3/2, 4.2582, 0.00500, 0.5001, 0.837943000, 16.0000; ...
'Ba', 'Barium', 56, 137, 3/2, 4.7634, 0.00700, 0.5594, 0.937365000, 24.5000; ...
'La', 'Lanthanum', 57, 138, 5, 5.6615, 0.09404, 5.3188, 3.713646000, 45.0000; ...
'La', 'Lanthanum', 57, 139, 7/2, 6.0612, 0.06058, 2.9895, 2.783045500, 20.0000; ...
'Ce', 'Cerium', 58, 137, 3/2, 4.8800, 0.00752, 0.5729, 0.960000000, 0.0000; ...
'Ce', 'Cerium', 58, 139, 3/2, 5.3900, 0.01012, 0.6326, 1.060000000, 0.0000; ...
'Ce', 'Cerium', 58, 141, 7/2, 2.3700, 0.00364, 1.1708, 1.090000000, 0.0000; ...
'Pr', 'Praseodymium', 59, 141, 5/2, 13.0359, 0.33483, 3.5720, 4.275400000, -5.9000; ...
'Nd', 'Neodymium', 60, 143, 7/2, 2.3190, 0.00339, 1.1440, -1.065000000, -63.0000; ...
'Nd', 'Neodymium', 60, 145, 7/2, 1.4290, 0.00079, 0.7047, -0.656000000, -33.0000; ...
'Pm', 'Promethium', 61, 143, 5/2, 11.5900, 0.23510, 3.1748, 3.800000000, 0.0000; ...
'Pm', 'Promethium', 61, 147, 7/2, 5.6200, 0.04827, 2.7714, 2.580000000, 74.0000; ...
'Sm', 'Samarium', 62, 147, 7/2, 1.7748, 0.00152, 0.8753, -0.814900000, -26.0000; ...
'Sm', 'Samarium', 62, 149, 7/2, 14631.0000, 0.00085, 0.7216, -0.671800000, 7.4000; ...
'Eu', 'Europium', 63, 151, 5/2, 10.5856, 0.17929, 2.9006, 3.471800000, 90.3000; ...
'Eu', 'Europium', 63, 153, 5/2, 4.6745, 0.01544, 1.2809, 1.533100000, 241.0000; ...
'Gd', 'Gadolinium', 64, 155, 3/2, 1.3120, 0.00015, 0.1541, -0.258200000, 127.0000; ...
'Gd', 'Gadolinium', 64, 157, 3/2, 1.7200, 0.00033, 0.2020, -0.338500000, 135.0000; ...
'Tb', 'Terbium', 65, 159, 3/2, 10.2300, 0.06945, 1.2019, 2.014000000, 143.2000; ...
'Dy', 'Dysprosium', 66, 161, 5/2, 1.4654, 0.00048, 0.4015, -0.480600000, 250.7000; ...
'Dy', 'Dysprosium', 66, 163, 5/2, 2.0508, 0.00130, 0.5619, 0.672600000, 265.0000; ...
'Ho', 'Holmium', 67, 165, 7/2, 9.0883, 0.20423, 4.4825, 4.173000000, 358.0000; ...
'Er', 'Erbium', 68, 167, 7/2, 1.2281, 0.00050, 0.6057, -0.563900000, 356.5000; ...
'Tm', 'Thulium', 69, 169, 1/2, 3.5310, 0.00057, 0.0829, -0.231600000, 0.0000; ...
'Yb', 'Ytterbium', 70, 171, 1/2, 7.5261, 0.00552, 0.1768, 0.493670000, 0.0000; ...
'Yb', 'Ytterbium', 70, 173, 5/2, 2.0730, 0.00135, 0.5680, -0.679890000, 280.0000; ...
'Lu', 'Lutetium', 71, 175, 7/2, 4.8626, 0.03128, 2.3983, 2.232700000, 349.0000; ...
'Lu', 'Lutetium', 71, 176, 7, 3.4510, 0.03975, 6.0516, 3.169000000, 497.0000; ...
'Hf', 'Hafnium', 72, 177, 7/2, 1.7282, 0.00140, 0.8524, 0.793500000, 336.5000; ...
'Hf', 'Hafnium', 72, 179, 9/2, 1.0856, 0.00055, 0.8414, -0.640900000, 379.3000; ...
'Ta', 'Tantalum', 73, 180, 9, 4.0870, 0.10610, 11.5175, 4.825000000, 0.0000; ...
'Ta', 'Tantalum', 73, 181, 7/2, 5.1627, 0.03744, 2.5463, 2.370500000, 317.0000; ...
'W', 'Tungsten', 74, 183, 1/2, 1.7957, 0.00008, 0.0422, 0.117784800, 0.0000; ...
'Re', 'Rhenium', 75, 185, 5/2, 9.7176, 0.13870, 2.6627, 3.187100000, 218.0000; ...
'Re', 'Rhenium', 75, 187, 5/2, 9.8170, 0.14300, 2.6900, 3.219700000, 207.0000; ...
'Os', 'Osmium', 76, 187, 1/2, 0.9856, 0.00001, 0.0231, 0.064651890, 0.0000; ...
'Os', 'Osmium', 76, 189, 3/2, 3.3536, 0.00244, 0.3938, 0.659933000, 85.6000; ...
'Ir', 'Iridium', 77, 191, 3/2, 0.7658, 0.00003, 0.0899, 0.150700000, 81.6000; ...
'Ir', 'Iridium', 77, 191, 3/2, 0.8319, 0.00004, 0.0977, 0.163700000, 75.1000; ...
'Pt', 'Platinum', 78, 195, 1/2, 9.2922, 0.01039, 0.2182, 0.609520000, 0.0000; ...
'Au', 'Gold', 79, 197, 3/2, 0.7406, 0.00003, 0.0870, 0.145746000, 54.7000; ...
'Hg', 'Mercury', 80, 199, 1/2, 7.7123, 0.00594, 0.1811, 0.505885500, 0.0000; ...
'Hg', 'Mercury', 80, 201, 3/2, 2.8469, 0.00149, 0.3343, -0.560225700, 38.6000; ...
'Tl', 'Thallium', 81, 203, 1/2, 24.7316, 0.19598, 0.5809, 1.622257900, 0.0000; ...
'Tl', 'Thallium', 81, 205, 1/2, 24.9749, 0.20182, 0.5866, 1.638214600, 0.0000; ...
'Pb', 'Lead', 82, 207, 1/2, 9.0340, 0.00955, 0.2122, 0.592580000, 0.0000; ...
'Bi', 'Bismuth', 83, 209, 9/2, 6.9630, 0.14433, 5.3967, 4.110600000, 51.6000; ...
'Po', 'Polonium', 84, 209, 1/2, 11.7000, 0.02096, 0.2757, 0.770000000, 0.0000; ...
'Rn', 'Radon', 86, 211, 1/2, 9.1600, 0.00997, 0.2152, 0.601000000, 0.0000; ...
'Fr', 'Francium', 87, 223, 3/2, 5.9500, 0.01362, 0.6982, 1.170000000, 117.0000; ...
'Ra', 'Radium', 88, 223, 3/2, 1.3746, 0.00017, 0.1614, 0.270500000, 125.0000; ...
'Ra', 'Radium', 88, 225, 1/2, 11.1870, 0.01814, 0.2627, -0.733800000, 0.0000; ...
'Ac', 'Actinium', 89, 227, 3/2, 5.6000, 0.01131, 0.6564, 1.100000000, 170.0000; ...
'Th', 'Thorium', 90, 229, 5/2, 1.4000, 0.00042, 0.3843, 0.460000000, 430.0000; ...
'Pa', 'Protactinium', 91, 231, 3/2, 10.2000, 0.06903, 1.1995, 2.010000000, -172.0000; ...
'U', 'Uranium', 92, 235, 7/2, 0.8300, 0.00015, 0.4082, -0.380000000, 493.6000; ...
'Np', 'Neptunium', 93, 237, 5/2, 9.5700, 0.13264, 2.6234, 3.140000000, 388.6000; ...
'Pu', 'Plutonium', 94, 239, 1/2, 3.0900, 0.00038, 0.0727, 0.203000000, 0.0000; ...
'Am', 'Americium', 95, 243, 5/2, 4.6000, 0.01446, 1.2532, 1.500000000, 421.0000; ...
};


%% Find isotopes
if nargin == 0
    % Return the whole table
    T = GetDataFromTheTable(TheTable);
    
 else
    T = [];
    for j = 1:nargin
        curIn = varargin{j};
        if ischar(curIn)
            nn = isstrprop(curIn, 'alpha');            
            curElem = curIn(nn);
           
            % Find the element symbol
            ie = strmatch(curElem, {TheTable{:, 1}}, 'exact');
            
            % Isotope mass number
            nn = isstrprop(curIn,  'digit');
            curMass = curIn;
            curMass(~nn) = ' ';
            curMass = strtok(curMass);
            if ~isempty(curMass)
                curMass = str2double(curMass);
                if ~isnan(curMass)
                    im = find(curMass == [TheTable{:, 4}]);
                    ie = intersect(ie, im);
                end
            end
            
            % Get the isotop(s) properties
            if isempty(ie)
                warning('MATLAB:isotopes:CanNotFindTheElement', ...
                        ['Can not find the element: ' curIn]);
                curT = GetDataFromTheTable;
                curT.name = '<< not found >>';
                curT.isotop = curIn;
                curT.mass = curMass;
                T = [T; curT(:)];
            else
                curT = GetDataFromTheTable(TheTable, ie);
                T = [T; curT(:)];
            end

        else
            error('Input argument(s) should be char, i.e. ''19F''');
        end
    end    
end

%
function T = GetDataFromTheTable(TheTable, TblInd)
%Returns data in a structure

% Factor to Hz
fctHz = 1e6;        

% Create the output structure template
StructTmpl = struct('name', '', 'isotop', '', 'Z', 0, 'mass', 0, 'I', 0, ...
                    'gamma', 0, 'ResFreq', 0, 'RelSensB', 0, ...
                    'RelSensF', 0, 'u', 0, 'Q', 0);
if nargin < 1
    T = StructTmpl;
    return;
    
elseif (nargin < 2)
    TblInd = (1:size(TheTable, 1));
    
elseif isempty(TblInd)
    T = StructTmpl;
    return;
    
end

nIndNum = length(TblInd);
T = repmat(StructTmpl, nIndNum, 1);
for i = 1:nIndNum
    j = TblInd(i);
    T(i).name = TheTable{j, 2};
    T(i).isotop = sprintf('%.0d%s', TheTable{j, 4}, TheTable{j, 1});
    T(i).Z = TheTable{j, 3};
    T(i).mass = TheTable{j, 4};
    T(i).I = TheTable{j, 5};
    T(i).gamma = 2*pi*fctHz*TheTable{j, 6};
    T(i).ResFreq = TheTable{j, 6}*fctHz;
    T(i).RelSensB = TheTable{j, 7};
    T(i).RelSensF = TheTable{j, 8};
    T(i).u = TheTable{j, 9};
    T(i).Q = TheTable{j, 10};
end
