packages/miew/src/chem/Element.js

Summary

Maintainability
A
0 mins
Test Coverage
class Element {
  constructor(number, name, fullName, weight, radius, radiusBonding, hValency) {
    this.number = number
    this.name = name
    this.fullName = fullName
    this.weight = weight
    this.radius = radius
    this.radiusBonding = radiusBonding
    this.hydrogenValency = hValency
  }

  static Constants = {
    /* eslint-disable no-magic-numbers */
    U1: 1,
    Lead: 2,
    U2: 3,
    Wing: 4,
    U18: 18
    /* eslint-enable no-magic-numbers */
  }

  static Role = {
    /* eslint-disable no-magic-numbers */
    N: Element.Constants.U1,
    CA: Element.Constants.Lead,
    C: Element.Constants.U2,
    O: Element.Constants.Wing,
    SG: Element.Constants.U18
    /* eslint-enable no-magic-numbers */
  }

  // DO NOT EDIT MANUALLY! Autogenerated from atom_types.csv by atom_types.py.
  static ByAtomicNumber = [
    /* eslint-disable no-magic-numbers */
    null,
    new Element(1, 'H', 'Hydrogen', 1.008, 1.2, 0.23, [1]),
    new Element(2, 'HE', 'Helium', 4.003, 1.4, 0.93, [0]),
    new Element(3, 'LI', 'Lithium', 6.941, 1.82, 0.68, [1]),
    new Element(4, 'BE', 'Beryllium', 9.012, 1.7, 0.35, [2]),
    new Element(5, 'B', 'Boron', 10.81, 2.08, 0.83, [3]),
    new Element(6, 'C', 'Carbon', 12.011, 1.95, 0.68, [4]),
    new Element(7, 'N', 'Nitrogen', 14.007, 1.85, 0.68, [3, 5]),
    new Element(8, 'O', 'Oxygen', 15.999, 1.7, 0.68, [2, 4]),
    new Element(9, 'F', 'Fluorine', 18.998, 1.73, 0.64, [1]),
    new Element(10, 'NE', 'Neon', 20.18, 1.54, 1.12, [0]),
    new Element(11, 'NA', 'Sodium', 22.99, 2.27, 0.97, [1]),
    new Element(12, 'MG', 'Magnesium', 24.305, 1.73, 1.1, [2]),
    new Element(13, 'AL', 'Aluminum', 26.981, 2.05, 1.35, [3]),
    new Element(14, 'SI', 'Silicon', 28.086, 2.1, 1.2, [4]),
    new Element(15, 'P', 'Phosphorus', 30.974, 2.08, 0.75, [3, 5]),
    new Element(16, 'S', 'Sulfur', 32.07, 2, 1.02, [2, 4, 6]),
    new Element(17, 'CL', 'Chlorine', 35.453, 1.97, 0.99, [1, 3, 5, 7]),
    new Element(18, 'AR', 'Argon', 39.948, 1.88, 1.57, [0]),
    new Element(19, 'K', 'Potassium', 39.1, 2.75, 1.33, [1]),
    new Element(20, 'CA', 'Calcium', 40.08, 1.973, 0.99, [2]),
    new Element(21, 'SC', 'Scandium', 44.956, 1.7, 1.44, [0]),
    new Element(22, 'TI', 'Titanium', 47.88, 1.7, 1.47, [0]),
    new Element(23, 'V', 'Vanadium', 50.941, 1.7, 1.33, [0]),
    new Element(24, 'CR', 'Chromium', 52, 1.7, 1.35, [0]),
    new Element(25, 'MN', 'Manganese', 54.938, 1.7, 1.35, [0]),
    new Element(26, 'FE', 'Iron', 55.847, 1.7, 1.34, [0]),
    new Element(27, 'CO', 'Cobalt', 58.93, 1.7, 1.33, [0]),
    new Element(28, 'NI', 'Nickel', 58.69, 1.63, 1.5, [0]),
    new Element(29, 'CU', 'Copper', 63.55, 1.4, 1.52, [0]),
    new Element(30, 'ZN', 'Zinc', 65.39, 1.39, 1.45, [0]),
    new Element(31, 'GA', 'Gallium', 69.72, 1.87, 1.22, [3]),
    new Element(32, 'GE', 'Germanium', 72.61, 1.7, 1.17, [4]),
    new Element(33, 'AS', 'Arsenic', 74.92, 1.85, 1.21, [3, 5]),
    new Element(34, 'SE', 'Selenium', 78.96, 1.9, 1.22, [2, 4, 6]),
    new Element(35, 'BR', 'Bromine', 79.9, 2.1, 1.21, [1, 3, 5, 7]),
    new Element(36, 'KR', 'Krypton', 83.8, 2.02, 1.91, [0]),
    new Element(37, 'RB', 'Rubidium', 85.47, 1.7, 1.47, [1]),
    new Element(38, 'SR', 'Strontium', 87.62, 1.7, 1.12, [2]),
    new Element(39, 'Y', 'Yttrium', 88.91, 1.7, 1.78, [0]),
    new Element(40, 'ZR', 'Zirconium', 91.22, 1.7, 1.56, [0]),
    new Element(41, 'NB', 'Niobium', 92.91, 1.7, 1.48, [0]),
    new Element(42, 'MO', 'Molybdenum', 95.94, 1.7, 1.47, [0]),
    new Element(43, 'TC', 'Technetium', 98.91, 1.7, 1.35, [0]),
    new Element(44, 'RU', 'Ruthenium', 101.07, 1.7, 1.4, [0]),
    new Element(45, 'RH', 'Rhodium', 102.91, 1.7, 1.45, [0]),
    new Element(46, 'PD', 'Palladium', 106.42, 1.63, 1.5, [0]),
    new Element(47, 'AG', 'Silver', 107.87, 1.72, 1.59, [0]),
    new Element(48, 'CD', 'Cadmium', 112.41, 1.58, 1.69, [0]),
    new Element(49, 'IN', 'Indium', 114.82, 1.93, 1.63, [3]),
    new Element(50, 'SN', 'Tin', 118.71, 2.17, 1.46, [2, 4]),
    new Element(51, 'SB', 'Antimony', 121.75, 2.2, 1.46, [3, 5]),
    new Element(52, 'TE', 'Tellurium', 127.6, 2.06, 1.47, [2, 4, 6]),
    new Element(53, 'I', 'Iodine', 126.91, 2.15, 1.4, [1, 3, 5, 7]),
    new Element(54, 'XE', 'Xenon', 131.29, 2.16, 1.98, [0]),
    new Element(55, 'CS', 'Cesium', 132.91, 1.7, 1.67, [1]),
    new Element(56, 'BA', 'Barium', 137.33, 1.7, 1.34, [2]),
    new Element(57, 'LA', 'Lanthanum', 138.91, 1.7, 1.87, [0]),
    new Element(58, 'CE', 'Cerium', 140.12, 1.7, 1.83, [0]),
    new Element(59, 'PR', 'Praseodymium', 140.91, 1.7, 1.82, [0]),
    new Element(60, 'ND', 'Neodymium', 144.24, 1.7, 1.81, [0]),
    new Element(61, 'PM', 'Promethium', 144.9, 1.7, 1.8, [0]),
    new Element(62, 'SM', 'Samarium', 150.36, 1.7, 1.8, [0]),
    new Element(63, 'EU', 'Europium', 151.96, 1.7, 1.99, [0]),
    new Element(64, 'GD', 'Gadolinium', 157.25, 1.7, 1.79, [0]),
    new Element(65, 'TB', 'Terbium', 158.93, 1.7, 1.76, [0]),
    new Element(66, 'DY', 'Dysprosium', 162.5, 1.7, 1.75, [0]),
    new Element(67, 'HO', 'Holmium', 164.93, 1.7, 1.74, [0]),
    new Element(68, 'ER', 'Erbium', 167.26, 1.7, 1.73, [0]),
    new Element(69, 'TM', 'Thulium', 168.93, 1.7, 1.72, [0]),
    new Element(70, 'YB', 'Ytterbium', 173.04, 1.7, 1.94, [0]),
    new Element(71, 'LU', 'Lutetium', 174.97, 1.7, 1.72, [0]),
    new Element(72, 'HF', 'Hafnium', 178.49, 1.7, 1.57, [0]),
    new Element(73, 'TA', 'Tantalum', 180.95, 1.7, 1.43, [0]),
    new Element(74, 'W', 'Tungsten', 183.85, 1.7, 1.37, [0]),
    new Element(75, 'RE', 'Rhenium', 186.21, 1.7, 1.35, [0]),
    new Element(76, 'OS', 'Osmium', 190.2, 1.7, 1.37, [0]),
    new Element(77, 'IR', 'Iridium', 192.22, 1.7, 1.32, [0]),
    new Element(78, 'PT', 'Platinum', 195.08, 1.72, 1.5, [0]),
    new Element(79, 'AU', 'Gold', 196.97, 1.66, 1.5, [0]),
    new Element(80, 'HG', 'Mercury', 200.59, 1.55, 1.7, [0]),
    new Element(81, 'TL', 'Thallium', 204.38, 1.96, 1.55, [1, 3]),
    new Element(82, 'PB', 'Lead', 207.2, 2.02, 1.54, [2, 4]),
    new Element(83, 'BI', 'Bismuth', 208.98, 1.7, 1.54, [3, 5]),
    new Element(84, 'PO', 'Polonium', 210, 1.7, 1.68, [2, 4, 6]),
    new Element(85, 'AT', 'Astatine', 210, 1.7, 1.7, [1, 3, 5, 7]),
    new Element(86, 'RN', 'Radon', 222, 1.7, 2.4, [0]),
    new Element(87, 'FR', 'Francium', 223, 1.7, 2, [1]),
    new Element(88, 'RA', 'Radium', 226.03, 1.7, 1.9, [2]),
    new Element(89, 'AC', 'Actinium', 227.03, 1.7, 1.88, [0]),
    new Element(90, 'TH', 'Thorium', 232.04, 1.7, 1.79, [0]),
    new Element(91, 'PA', 'Protactinium', 231.04, 1.7, 1.61, [0]),
    new Element(92, 'U', 'Uranium', 238.03, 1.86, 1.58, [0]),
    new Element(93, 'NP', 'Neptunium', 237.05, 1.7, 1.55, [0]),
    new Element(94, 'PU', 'Plutonium', 239.1, 1.7, 1.53, [0]),
    new Element(95, 'AM', 'Americium', 243.1, 1.7, 1.51, [0]),
    new Element(96, 'CM', 'Curium', 247.1, 1.7, 1.5, [0]),
    new Element(97, 'BK', 'Berkelium', 247.1, 1.7, 1.5, [0]),
    new Element(98, 'CF', 'Californium', 252.1, 1.7, 1.5, [0]),
    new Element(99, 'ES', 'Einsteinium', 252.1, 1.7, 1.5, [0]),
    new Element(100, 'FM', 'Fermium', 257.1, 1.7, 1.5, [0]),
    new Element(101, 'MD', 'Mendelevium', 256.1, 1.7, 1.5, [0]),
    new Element(102, 'NO', 'Nobelium', 259.1, 1.7, 1.5, [0]),
    new Element(103, 'LR', 'Lawrencium', 260.1, 1.7, 1.5, [0]),
    new Element(104, 'RF', 'Rutherfordium', 261, 1.7, 1.6, [0]),
    new Element(105, 'DB', 'Dubnium', 262, 1.7, 1.6, [0]),
    new Element(106, 'SG', 'Seaborgium', 263, 1.7, 1.6, [0]),
    new Element(107, 'BH', 'Bohrium', 262, 1.7, 1.6, [0]),
    new Element(108, 'HS', 'Hassium', 265, 1.7, 1.6, [0]),
    new Element(109, 'MT', 'Meitnerium', 268, 1.7, 1.6, [0])
    /* eslint-enable no-magic-numbers */
  ]

  // DO NOT EDIT MANUALLY! Autogenerated from atom_types.csv by atom_types.py.
  static ByName = {
    // Duplicate atomic numbers (isotopes)
    /* eslint-disable no-magic-numbers */
    D: new Element(1, 'D', 'Deuterium', 2.014, 1.2, 0.23, [1]),
    T: new Element(1, 'T', 'Tritium', 3.016, 1.2, 0.23, [1])
    /* eslint-enable no-magic-numbers */

    // All regular elements will be added later, automatically
  }
}

;(function () {
  const byAtomicNumber = Element.ByAtomicNumber
  const byName = Element.ByName
  for (let i = 0, n = byAtomicNumber.length; i < n; ++i) {
    const element = byAtomicNumber[i]
    if (element) {
      byName[element.name] = element
    }
  }
})()

// find atom type by chemical element (or create if missing)
Element.getByName = function (element) {
  let type = Element.ByName[element]
  if (!type) {
    type = Element.ByName[element] = new Element(
      0,
      element,
      'Unknown',
      0,
      1.0,
      0.01,
      [0]
    )
  }
  return type
}

export default Element