python3-nist

2024-05-17 22:37 UTC
  • Xyne

Metadata

Description: Modules for accessing and working with data from the National Institute of Standards and Technology (NIST).
Latest Version: 2021
Source Code: src/
Architecture:
  • any
Dependencies:
Build Dependencies:
  • python-setuptools
Optional Dependencies:
Arch Repositories:
  • [xyne-any]
  • [xyne-i686]
  • [xyne-x86_64]
AUR Page: python3-nist
Arch Forum Thread: 151524
Tags:

About

The NIST package provides modules for retrieving and caching scientific data from the National Institute of Standards and Technology (NIST).

Modules

NIST.Isotopes

This module retrieves isotope data from http://www.nist.gov/pml/data/comp.cfm and provides several functions for extracting. The Isotopes object is a wrapper around the underlying caching database and should be used when full access to all of the isotope data is necessary. The Query object is a simplified wrapper around Isotopes for more basic usage.

The module’s main routine provides a fully functional command-line interface for retrieving data. It also provides support for determining the molecular weights of chemicals based on formula or InChi. This function is wrapped by nist-isotopes. See the help message below.

Examples

from NIST.Isotopes import Query
from SciNum import DecimalWithUnits as DwU

q = Query()
n = DwU('8', 'mol')
for formula in ('CH4', 'O2', 'CO2', 'InChI=1S/C4H5As/c1-2-4-5-3-1/h1-5H'):
  mol_mass = q.molecular_weight(formula)
  print(formula, ':', mol_mass, '*', n, '=', mol_mass * n)

CH4 : 16.04246 {±0.00108} g mol^{-1} * 8 mol = 128.33968 {±0.00864} g
O2 : 31.9988 {±0.0006} g mol^{-1} * 8 mol = 255.9904 {±0.0048} g
CO2 : 44.0095 {±0.0014} g mol^{-1} * 8 mol = 352.0760 {±0.0112} g
InChI=1S/C4H5As/c1-2-4-5-3-1/h1-5H : 128.00410 {±0.00357} g mol^{-1} * 8 mol = 1024.03280 {±0.02856} g

NIST.PhysicalConstants

This module provides an interface for retrieving physical constants from http://physics.nist.gov/cuu/Constants/ via the PhysicalConstants object.

The module’s main function provides a complete command-line interface for querying physical constants. See the output below.

Examples

Source Code

#!/usr/bin/env python3

"""
A very simple example of using SciNum and NIST.PhysicalConstants to calculate
the pressure of an ideal gas.

The following are demonstrated:

* retrieval of physical constants
* declaration of physical quantities
* basic arithmetic
* reduction to SI base units
* expression in desired units by substitution
"""

from SciNum import DecimalWithUnits as DwU, MeasuredDecimalWithUnits as MDwU
from SciNum.units import Units, Definition, SI_DERIVED_UNIT_DEFINITIONS
from SciNum.units import reduce_to_base_units, express
from NIST.PhysicalConstants import PhysicalConstants

pc = PhysicalConstants()

# This is just to show unit multiplication.
k_b = pc['Boltzmann constant']
N_A = pc['Avogadro constant']
R = k_b * N_A

# This would work as well
# R = pc['molar gas constant']

# Measured decimals are used here to keep track of significant figures. Each
# number has 3 and so 3 sigfigs will be included in the output. Digits beyond
# those are just placeholders.
n = MDwU('5.00', 'mol')
T = MDwU('300', 'K')
V = MDwU('2.00', 'm^3')

# Calculate the pressure p from the ideal gas law.
p = (n * R * T) / V

# Display some output.
print("Given:")
print('k_b =', k_b)
print('N_A =', N_A)
# Display fewer digits for R.
print('R =', format(R, '.5f'))
print('n =', n)
print('T =', T)
print('V =', V)
print()

print("Rearranging the ideal gas law (pV = nRT) to solve for p")
print("p = (nRT)/V")
print("p = (%s * %s * %s)/(%s)" % (n, format(R, '.5f'), T, V))
print("p = (%s)/(%s)" % (n * R * T, V))

# Express p in default units (whatever the constants and the above values happen
# to be expressed in).
print('p =', format(p, 'f'), "(%d significant figure(s))" % p.precision)

# Express p in SI base units.
p_SI = p.reduce_to_base_units()
print('  =', format(p_SI, 'f'))

# Express p in Pa
# The Definition for Pa could have been created directly instead of manipulating
# SI_DERIVED_UNIT_DEFINITIONS.
Pa_base, Pa_factor = reduce_to_base_units(SI_DERIVED_UNIT_DEFINITIONS['Pa'])
Pa_def = Definition('Pa', Pa_base, Pa_factor)
m_def = express(Pa_def, 'm')
p_Pa = p_SI.substitute_units((m_def,))
print('  =', format(p_Pa, 'f'))

Output

Given:
k_b = 1.3806488e-23 {±0.0000013e-23} J K^{-1}
N_A = 6.02214129e+23 {±0.00000027e+23} mol^{-1}
R = 8.31446 {±0.00001} J K^{-1} mol^{-1}
n = 5.00 mol
T = 300 K
V = 2.00 m^{3}

Rearranging the ideal gas law (pV = nRT) to solve for p
p = (nRT)/V
p = (5.00 mol * 8.31446 {±0.00001} J K^{-1} mol^{-1} * 300 K)/(2.00 m^{3})
p = (1.25E+4 J)/(2.00 m^{3})
p = 6240 J m^{-3} (3 significant figure(s))
  = 6240 kg m^{-1} s^{-2}
  = 6240 Pa

NIST.DB

This module provides the database caching functionality for the other modules.

Scripts

Wrapper scripts are provide for querying data from the command line:

  • nist-isotopes: query isotope data or get molecular weights for formulae
  • nist-phys_const: query physical constants

Note that the scripts provide an option to draw tables using box-drawing characters. This is not shown below because Firefox is unable to draw such characters correctly (it breaks the table). Try the example commands yourself with the --box option.

Contact
echo xyne.archlinux.org | sed 's/\./@/'
Validation
XHTML 1.0 Strict CSS level 3 Atom 1.0