/ Published in: ASP
URL: http://reusablecode.blogspot.com/2009/05/chemistry-library.html
A collection of chemistry-related functions: lookup element symbol by atomic number, lookup element name by atomic number, determine electron configuration by atomic number. Requires my proper case function
Expand |
Embed | Plain Text
<% ' ASP Chemistry Library ' ' Copyright (c) 2009, reusablecode.blogspot.com; some rights reserved. ' ' This work is licensed under the Creative Commons Attribution License. To view ' a copy of this license, visit http://creativecommons.org/licenses/by/3.0/ or ' send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California ' 94305, USA. ' Elements by name ElementNames = Array(null, _ "Hydrogen", "Helium", "Lithium", "Beryllium", "Boron", "Carbon", "Nitrogen", "Oxygen", "Fluorine", "Neon", _ "Sodium", "Magnesium", "Aluminium", "Silicon", "Phosphorus", "Sulfur", "Chlorine", "Argon", "Potassium", "Calcium", _ "Scandium", "Titanium", "Vanadium", "Chromium", "Manganese", "Iron", "Cobalt", "Nickel", "Copper", "Zinc", _ "Gallium", "Germanium", "Arsenic", "Selenium", "Bromine", "Krypton", "Rubidium", "Strontium", "Yttrium", "Zirconium", _ "Niobium", "Molybdenum", "Technetium", "Ruthenium", "Rhodium", "Palladium", "Silver", "Cadmium", "Indium", "Tin", _ "Antimony", "Tellurium", "Iodine", "Xenon", "Caesium", "Barium", "Lanthanum", "Cerium", "Praseodymium", "Neodymium", _ "Promethium", "Samarium", "Europium", "Gadolinium", "Terbium", "Dysprosium", "Holmium", "Erbium", "Thulium", "Ytterbium", _ "Lutetium", "Hafnium", "Tantalum", "Tungsten", "Rhenium", "Osmium", "Iridium", "Platinum", "Gold", "Mercury", _ "Thallium", "Lead", "Bismuth", "Polonium", "Astatine", "Radon", "Francium", "Radium", "Actinium", "Thorium", _ "Protactinium", "Uranium", "Neptunium", "Plutonium", "Americium", "Curium", "Berkelium", "Californium", "Einsteinium", "Fermium", _ "Mendelevium", "Nobelium", "Lawrencium", "Rutherfordium", "Dubnium", "Seaborgium", "Bohrium", "Hassium", "Meitnerium", "Darmstadtium", _ "Roentgenium" _ ) ' Elements by symbol ElementSymbols = Array(null, _ "H", "He", "Li", "Be", "B", "C", "N", "O", "F", "Ne", _ "Na", "Mg", "Al", "Si", "P", "S", "Cl", "Ar", "K", "Ca", _ "Sc", "Ti", "V", "Cr", "Mn", "Fe", "Co", "Ni", "Cu", "Zn", _ "Ga", "Ge", "As", "Se", "Br", "Kr", "Rb", "Sr", "Y", "Zr", _ "Nb", "Mo", "Tc", "Ru", "Rh", "Pd", "Ag", "Cd", "In", "Sn", _ "Sb", "Te", "I", "Xe", "Cs", "Ba", "La", "Ce", "Pr", "Nd", _ "Pm", "Sm", "Eu", "Gd", "Tb", "Dy", "Ho", "Er", "Tm", "Yb", _ "Lu", "Hf", "Ta", "W", "Re", "Os", "Ir", "Pt", "Au", "Hg", _ "Tl", "Pb", "Bi", "Po", "At", "Rn", "Fr", "Ra", "Ac", "Th", _ "Pa", "U", "Np", "Pu", "Am", "Cm", "Bk", "Cf", "Es", "Fm", _ "Md", "No", "Lr", "Rf", "Db", "Sg", "Bh", "Hs", "Mt", "Ds", _ "Rg" _ ) ' List of subshell names in order of filling. Subshells = Array("1s", "2s", "2p", "3s", "3p", "4s", "3d", "4p", "5s", "4d", "5p", "6s", "4f", "5d", "6p", "7s", "5f", "6d", "7p", "8s", "5g", "6f", "7d", "8p", "9s", "6g", "7f", "8d", "9p", "10s", "6h", "7g", "8f", "9d", "10p", "11s", "7h", "8g", "9f", "10d", "11p", "12s", "7i", "8h", "9g", "10f", "11d", "12p", "13s", "8i", "9h", "10g", "11f", "12d", "13p", "14s") ' Retrieve element name, with support for elements that don't have names yet. ' REQUIRES: PCase() function getElementName(atomicNumber) dim result dim roots result = "" roots = Array("nil", "un", "bi", "tri", "quad", "pent", "hex", "sept", "oct", "enn") if atomicNumber <= UBound(ElementNames) then result = ElementNames(atomicNumber) else for i = 1 to len(cStr(atomicNumber)) result = result & roots(mid(cStr(atomicNumber), i, 1)) next result = pcase(result) & "ium" ' If bi or tri is followed by the ending ium (i.e. the last digit is 2 or 3), the result is '-bium' or -'trium', not '-biium' or '-triium'. result = replace(result, "ii", "i") ' If enn is followed by nil (i.e. the sequence -90- occurs), the result is '-ennil-', not '-ennnil-'. result = replace(result, "nnn", "nn") end if getElementName = result end function ' Retrieve element symbol, with support for elements that don't have symbols yet. ' REQUIRES: PCase() function getElementSymbol(atomicNumber) dim result result = "" symbols = Array("n", "u", "b", "t", "q", "p", "h", "s", "o", "e") if atomicNumber <= UBound(ElementSymbols) then result = ElementSymbols(atomicNumber) else for i = 1 to len(cStr(atomicNumber)) result = result & symbols(mid(cStr(atomicNumber), i, 1)) next result = pcase(result) end if getElementSymbol = result end function ' Returns the maximum number of electrons allowed in the specified subshell. function maxElectrons(subshell) select case lcase(right(subshell, 1)) case "s" maxElectrons = 2 case "p" maxElectrons = 6 case "d" maxElectrons = 10 case "f" maxElectrons = 14 case "g" maxElectrons = 18 case "h" maxElectrons = 23 case "i" maxElectrons = 26 end select end function ' Calculate the electron configuration for a given atom. function electronConfiguration(atomicNumber) dim electrons dim configuration electrons = atomicNumber configuration = "" for each subshell in Subshells if electrons > maxElectrons(subshell) then ' A d subshell that is half-filled or full (ie 5 or 10 electrons) is more stable than the s subshell of the next shell. if (subshell = "4s" and (atomicNumber = 24 or atomicNumber = 29)) or (subshell = "5s" and (atomicNumber = 41 or atomicNumber = 42 or atomicNumber = 44 or atomicNumber = 45 or atomicNumber = 47)) or (subshell = "6s" and (atomicNumber = 78 or atomicNumber = 79)) then configuration = configuration & " " & subshell & "^1" electrons = electrons - 1 ' Special exception for palladium. elseif subshell = "5s" and atomicNumber = 46 then ' do nothing; this subshell gets no electrons else configuration = configuration & " " & subshell & "^" & maxElectrons(subshell) electrons = electrons - maxElectrons(subshell) end if else configuration = configuration & " " & subshell & "^" & electrons electrons = 0 exit for end if next electronConfiguration = trim(configuration) end function %>
You need to login to post a comment.
