### Set Up Development Environment (Git & Python) Source: https://github.com/python-periodictable/periodictable/blob/master/doc/sphinx/guide/contributing.rst Clone the repository, navigate to the project directory, and install the package in development mode. The `develop` keyword ensures that changes to the package files are immediately reflected without needing reinstallation. ```bash git clone https://github.com/GITNAME/periodictable.git cd periodictable python setup.py develop ``` -------------------------------- ### Install periodictable and Dependencies Source: https://github.com/python-periodictable/periodictable/blob/master/doc/sphinx/guide/using.rst Installs the periodictable library and its dependencies, pyparsing and numpy. Ensure numpy is already installed. ```shell easy_install periodictable ``` -------------------------------- ### Build Documentation with Sphinx Source: https://github.com/python-periodictable/periodictable/blob/master/doc/sphinx/guide/contributing.rst Install Sphinx and then use make commands within the documentation directory to clean previous builds and generate HTML and PDF versions of the documentation. The output can be viewed in the specified build directories. ```bash pip install sphinx (cd doc/sphinx && PYTHONPATH=../.. make clean html pdf) ``` -------------------------------- ### Run Tests with Pytest Source: https://github.com/python-periodictable/periodictable/blob/master/doc/sphinx/guide/contributing.rst Install the necessary testing packages, pytest and pytest-cov, and then execute all tests using the pytest command. This ensures that your changes do not break existing functionality. ```bash pip install pytest pytest-cov pytest ``` -------------------------------- ### Aggregate package data for multiple packages in py2exe bundle Source: https://github.com/python-periodictable/periodictable/blob/master/doc/sphinx/guide/bundle.rst This snippet shows how to aggregate package data from multiple sources, including 'periodictable' and its extensions, for inclusion in a py2exe bundle. It initializes an empty dictionary, updates it with 'periodictable.package_data', and then passes the aggregated dictionary to the 'package_data' argument in the 'setup' function. ```python import periodictable package_data = {} ... package_data.update(periodictable.package_data) ... setup(..., package_data=package_data, ...) ``` -------------------------------- ### Include periodictable data in py2exe bundle Source: https://github.com/python-periodictable/periodictable/blob/master/doc/sphinx/guide/bundle.rst This code snippet demonstrates how to include the 'periodictable' package data when using py2exe. It involves adding the 'periodictable.package_data' to the 'package_data' argument in your distutils 'setup' function. This ensures that the necessary data files are bundled with your application. ```python import periodictable ... setup(..., package_data=periodictable.package_data, ...) ``` -------------------------------- ### Support Ions with Magnetic Form Factors and X-ray Scattering Factors in Python Source: https://github.com/python-periodictable/periodictable/blob/master/ChangeLog.rst The library now supports ions, including their magnetic form factors and X-ray f0 scattering factors. This extends the capabilities for calculating scattering properties of charged species. ```python from periodictable import formula # Example: # fe_ion = formula('Fe2+') # magnetic_form_factor = fe_ion.magnetic_form_factor(q=0.1) # Hypothetical method # xray_f0 = fe_ion.xray_f0(wavelength=1.54) # Hypothetical method ``` -------------------------------- ### Get Formula Charge Source: https://github.com/python-periodictable/periodictable/blob/master/doc/sphinx/guide/formula_grammar.rst Retrieves the net charge of a formula object, calculated from the charges of its constituent ions. ```python from periodictable import formula # Example: Get the charge of a formula with ions print(formula("P{5+}O{2-}4").charge) ``` -------------------------------- ### Mix by Weight and Volume Formula Constructors in Python Source: https://github.com/python-periodictable/periodictable/blob/master/ChangeLog.rst Introduces `mix_by_weight` and `mix_by_volume` constructors for the `formula` object. These facilitate the creation of formulas representing mixtures based on mass or volume proportions. ```python from periodictable import formula # Mix by weight: # mixture_w = formula.mix_by_weight([('NaCl', 5), ('H2O', 50)]) # Mix by volume: # mixture_v = formula.mix_by_volume([('NaCl', 5), ('H2O', 50)]) ``` -------------------------------- ### Support Neutron Activation Calculations in Python Source: https://github.com/python-periodictable/periodictable/blob/master/ChangeLog.rst The library now includes dedicated support for neutron activation calculations. This enables users to simulate and analyze the production of radioactive isotopes resulting from neutron bombardment. ```python from periodictable import neutron_activation # Example usage (hypothetical): # activation_yield = neutron_activation('U235', neutron_flux=1e15, irradiation_time=600) ``` -------------------------------- ### Create and Populate Custom Periodic Table (Python) Source: https://github.com/python-periodictable/periodictable/blob/master/doc/sphinx/guide/customizing.rst Demonstrates creating a custom PeriodicTable instance, initializing properties like mass and density, and scaling values based on a specific isotope. This allows for private tables with user-defined values. ```python import periodictable from periodictable import core, mass, density, elements, formula mytable = core.PeriodicTable(table="H=1") mass.init(mytable) density.init(mytable) # Reset mass to H=1 rather than C=12 scale = elements.H[1].mass for el in mytable: el._mass /= scale if hasattr(el,'_density') and el._density is not None: el._density /= scale for iso in el: iso._mass /= scale print("%.10f %.10f"%(mytable.H[1].mass, mytable.C[12].mass)) print("%.10f %.10f"%(periodictable.H[1].mass, periodictable.C[12].mass)) print("%.10f"%formula('2H[1]', table=mytable).mass) ``` -------------------------------- ### Support X-ray Refraction Index and Mirror Reflectivity in Python Source: https://github.com/python-periodictable/periodictable/blob/master/ChangeLog.rst Added functionality to calculate X-ray refraction indices and mirror reflectivity. This is useful for applications involving X-ray optics and material analysis. ```python from periodictable import xray_refractive_index, xray_reflectivity # Example usage (hypothetical): # refractive_index = xray_refractive_index('Si', wavelength=1.54) # reflectivity = xray_reflectivity('Au', angle=0.1, wavelength=1.54) ``` -------------------------------- ### Formulas Report Charge and Mass Fraction in Python Source: https://github.com/python-periodictable/periodictable/blob/master/ChangeLog.rst Formula objects now provide direct access to the calculated charge and mass fraction of the compound. This simplifies the retrieval of these fundamental chemical properties. ```python from periodictable import formula # Example: # f = formula('NaCl') # print(f.charge) # Output: 0 # print(f.mass_fraction('Na')) # Output: 0.3934... ``` -------------------------------- ### Allow Density Calculation from Structure in Python Source: https://github.com/python-periodictable/periodictable/blob/master/ChangeLog.rst Density can now be calculated directly from crystal structure information (bcc, fcc, hcp, cubic, diamond). This allows for density determination when only structural parameters are known. ```python from periodictable import elements # Example (hypothetical): # iron = elements.Element('Fe') # bcc_density = iron.density_from_structure('bcc', lattice_constant=2.87) # print(bcc_density) ``` -------------------------------- ### Access Ion Properties (Ni) Source: https://github.com/python-periodictable/periodictable/blob/master/doc/sphinx/guide/using.rst Shows how to create specific ion handles (e.g., Ni[58].ion[2] and Ni.ion[2]) and access their properties like mass and charge. ```python import periodictable Ni58_2 = periodictable.Ni[58].ion[2] Ni_2 = periodictable.Ni.ion[2] print("charge for Ni2+ is %d"%Ni_2.charge) print("mass for Ni[58] and for natural abundance: %.4f %.4f"%(Ni58_2.mass, Ni_2.mass)) ``` -------------------------------- ### Formula Parser with Density and Mixture Support in Python Source: https://github.com/python-periodictable/periodictable/blob/master/ChangeLog.rst The formula parser has been updated to support density specifications and mixture calculations by weight or volume. This allows for more complex material definitions within the library. ```python from periodictable import formula # Mixture by mass: # mixture_mass = formula('5 g NaCl // 50 g H2O') # Mixture by volume: # mixture_volume = formula('5 g NaCl // 50 mL H2O@1') # Density specification: # dense_water = formula('H2O', density=1.0) # dense_water_iso = formula('H2O', density=1.0, isotopes='D') ``` -------------------------------- ### Creating and Using Custom Periodic Tables in Periodictable Source: https://context7.com/python-periodictable/periodictable/llms.txt Explains how to create custom periodic tables with modified element properties for specialized calculations. It demonstrates modifying properties and using the custom table in formula parsing, highlighting its isolation from the default table. ```python from periodictable.core import PeriodicTable from periodictable import formula, elements # Create a custom table custom_table = PeriodicTable("my_custom_table") # Modify properties on the custom table custom_table.Fe.density = 7.0 # Custom density # Use custom table in calculations custom_compound = formula("Fe2O3", table=custom_table) # Custom table isolates changes from the default table print(elements.Fe.density) # Still 7.874 (default) print(custom_table.Fe.density) # 7.0 (custom) # Type checking utilities from periodictable.core import isatom, iselement, isisotope, ision print(isatom(elements.Fe)) # True print(iselement(elements.Fe)) # True print(isisotope(elements.Fe[56])) # True print(ision(elements.Fe.ion[2])) # True ``` -------------------------------- ### Estimate Density using Molecular Mass and Lattice Parameters Source: https://github.com/python-periodictable/periodictable/blob/master/doc/sphinx/guide/formula_grammar.rst Shows a more accurate method for estimating density by using the molecular mass and explicitly providing the lattice parameters of the crystal structure. This method yields results closer to experimental values. ```python Fe.density = Fe.molecular_mass/Fe.volume(a=2.8664) print(f"{Fe.density:.3g}") ``` -------------------------------- ### Support Private Tables with Value Replacement in Python Source: https://github.com/python-periodictable/periodictable/blob/master/ChangeLog.rst The library allows the use of private tables where specific values can be replaced. This enables customization and the use of proprietary data within the periodic table framework. ```python from periodictable import elements # Example (hypothetical): # private_data = {'H': {'density': 0.08988}} # custom_elements = elements.Table(private_data=private_data) # hydrogen = custom_elements.H # print(hydrogen.density) ``` -------------------------------- ### Create Mixture by Weight Source: https://github.com/python-periodictable/periodictable/blob/master/doc/sphinx/guide/formula_grammar.rst Demonstrates creating a mixture of substances based on weight ratios using the `mix_by_weight` function. The density of the resulting mixture is computed automatically, potentially differing from volume-based mixtures. ```python mix = mix_by_weight(H2O,2,D2O,1) print(f"{mix} {mix.density:.4g}") ``` -------------------------------- ### Access Ion Magnetic Form Factor (Fe) Source: https://github.com/python-periodictable/periodictable/blob/master/doc/sphinx/guide/using.rst Demonstrates accessing ion-specific properties, specifically the magnetic form factor for Fe2+ ions, and calculating it for a given Q range. ```python import periodictable Fe_2 = periodictable.Fe.ion[2] print("[%.5f, %.5f, %.5f]"\ % tuple(Fe_2.magnetic_ff[Fe_2.charge].M_Q([0,0.1,0.2]))) ``` -------------------------------- ### Import All Elements and Access Properties Source: https://github.com/python-periodictable/periodictable/blob/master/doc/sphinx/guide/using.rst Imports all elements from the periodictable library and demonstrates accessing Hydrogen (H) by its symbol and then its mass. ```python from periodictable import * print(periodictable.H) print(periodictable.H.mass) ``` -------------------------------- ### Estimate Molecular Volume in Python Source: https://github.com/python-periodictable/periodictable/blob/master/ChangeLog.rst A feature to estimate the molecular volume of compounds has been added. This calculation is useful in various physical chemistry and material science applications. ```python from periodictable import formula # Example: # water_volume = formula('H2O').molecular_volume() # print(water_volume) ``` -------------------------------- ### Estimate Density using Molecular Mass and Volume (Packing Factor) Source: https://github.com/python-periodictable/periodictable/blob/master/doc/sphinx/guide/formula_grammar.rst Demonstrates estimating the density of a substance using its molecular mass and the volume of its unit cell, calculated using standard packing factors for crystal structures. This method provides an approximation. ```python from periodictable import elements, formula Fe = formula("2Fe") # bcc lattice has 2 atoms per unit cell Fe.density = Fe.molecular_mass/Fe.volume('bcc') print(f"{Fe.density:.3g}") ``` -------------------------------- ### Add neutron_scattering Function in Python Source: https://github.com/python-periodictable/periodictable/blob/master/ChangeLog.rst A new function `neutron_scattering()` has been added. It returns the total cross section (xs), scattering length density (sld), and penetration depth for a given material, providing comprehensive neutron interaction data. ```python from periodictable import neutron_scattering # Example: # xs, sld, penetration_depth = neutron_scattering('H2O') # print(f"Cross Section: {xs}") # print(f"SLD: {sld}") # print(f"Penetration Depth: {penetration_depth}") ``` -------------------------------- ### Create Mixture by Volume Source: https://github.com/python-periodictable/periodictable/blob/master/doc/sphinx/guide/formula_grammar.rst Illustrates creating a mixture of substances based on volume ratios using the `mix_by_volume` function. The density of the resulting mixture is computed automatically. ```python from periodictable import formula, mix_by_volume, mix_by_weight H2O = formula('H2O',natural_density=1) D2O = formula('D2O',natural_density=1) mix = mix_by_volume(H2O,2,D2O,1) print(f"{mix} {mix.density:.4g}") ``` -------------------------------- ### Create Formula using Formula Math Source: https://github.com/python-periodictable/periodictable/blob/master/doc/sphinx/guide/formula_grammar.rst Illustrates building formulas by combining existing formula objects using arithmetic operations. This simplifies the creation of complex formulas by leveraging previously defined structures. ```python print(formula("CaCO3") + 6*formula("H2O")) ``` -------------------------------- ### X-ray Scattering Calculations for Elements and Compounds Source: https://context7.com/python-periodictable/periodictable/llms.txt Calculates X-ray scattering factors, scattering length density (SLD), and related properties for elements and compounds using the periodictable.xsf module. Requires NumPy for Q-dependent calculations. Outputs scattering factors (f1, f2) and SLD (real, imag) in appropriate units. ```python import periodictable from periodictable import formula from periodictable.xsf import xray_sld, xray_wavelength, xray_energy # Element X-ray properties si = periodictable.Si # Scattering factors at specific energy f1, f2 = si.xray.scattering_factors(energy=8.05) # Cu K-alpha ~8.05 keV print(f"Si f1={f1:.3f}, f2={f2:.3f}") # Or by wavelength f1, f2 = si.xray.scattering_factors(wavelength=1.5418) # Cu K-alpha # Full scattering factor table energy_table, f1_table, f2_table = si.xray.sftable() # Atomic form factor f0(Q) import numpy as np Q = np.linspace(0, 10, 100) # Q in 1/Angstrom f0 = si.xray.f0(Q) # Element SLD at specific energy sld = si.xray.sld(energy=8.05) # Returns (real, imag) in 1e-6/A^2 # Compound X-ray SLD (requires density) sld = xray_sld("SiO2", density=2.2, energy=8.05) print(f"SiO2 SLD at 8.05 keV: ({sld[0]:.2f}, {sld[1]:.2f}) x 10^-6 A^-2") # By wavelength sld = xray_sld("Fe2O3", density=5.24, wavelength=1.5418) # K-alpha emission lines (available for elements beyond Ne) cu = periodictable.Cu print(f"Cu K_alpha: {cu.K_alpha} Angstrom") print(f"Cu K_beta1: {cu.K_beta1} Angstrom") # Energy/wavelength conversion wavelength = xray_wavelength(8.05) # keV to Angstrom energy = xray_energy(1.5418) # Angstrom to keV ``` -------------------------------- ### D2O Contrast Matching for Neutron Scattering Source: https://context7.com/python-periodictable/periodictable/llms.txt Calculates contrast match points and SLD for samples in D2O/H2O mixtures, essential for neutron scattering experiments. Handles molecules with and without labile hydrogen. Uses functions from periodictable.nsf. ```python from periodictable.nsf import D2O_sld, D2O_match # Find contrast match point for a molecule # Returns (D2O_fraction, SLD_at_match) match_fraction, match_sld = D2O_match("C6H12O6", density=1.54) print(f"Glucose matches at {match_fraction*100:.1f}% D2O") print(f"Match SLD: {match_sld:.4f} x 10^-6 A^-2") # Calculate SLD at specific D2O concentration # With volume fraction of solute in solution sld = D2O_sld("C6H12O6@1.54", volume_fraction=0.1, D2O_fraction=0.4) print(f"SLD at 40% D2O: {sld}") # For proteins with labile hydrogen (use H[1] notation) # Labile H exchanges with solvent D protein_formula = "C100H150N25O30S2H[1]20" # H[1] = labile hydrogen match_frac, sld = D2O_match(protein_formula, density=1.35) ``` -------------------------------- ### Pass Table to Neutron SLD Calculators in Python Source: https://github.com/python-periodictable/periodictable/blob/master/ChangeLog.rst Enhances neutron scattering calculators (`neutron_sld`, `neutron_scattering`) to accept a `table` argument. This allows users to provide a custom periodic table or isotope information source when parsing chemical formulas. ```python from periodictable import neutron_sld, elements # Custom table (example) custom_table = elements.Element('H') # Using the custom table: # sld = neutron_sld('H2O', table=custom_table) ``` -------------------------------- ### List Element Properties in Table Format Source: https://github.com/python-periodictable/periodictable/blob/master/doc/sphinx/guide/using.rst Shows how to use the 'list' method on the elements object to retrieve specific properties (symbol, K_alpha) for all elements in a formatted string. ```python from periodictable import elements elements.list('symbol','K_alpha',format="%s K-alpha = %s") ``` -------------------------------- ### Access Elements by Symbol (H, B, Cu, Ni) Source: https://github.com/python-periodictable/periodictable/blob/master/doc/sphinx/guide/using.rst Shows how to access elements using their chemical symbols (H, B, Cu, Ni). It retrieves and prints the neutron absorption for Boron and X-ray scattering factors for Nickel. ```python from periodictable import H,B,Cu,Ni print("B absorption %s"%B.neutron.absorption) print("Ni f1/f2 for Cu K-alpha X-rays f'=%.5f f''=%.5f" % Ni.xray.scattering_factors(wavelength=Cu.K_alpha)) ``` -------------------------------- ### Mixture and Composite Calculations Source: https://context7.com/python-periodictable/periodictable/llms.txt Creates mixtures by weight or volume and calculates composite scattering properties for alloys, solutions, and layered structures. Supports various notations for defining mixtures, including weight/volume percentages and absolute masses. Uses functions from the periodictable module. ```python from periodictable import formula, mix_by_weight, mix_by_volume # Mix by weight percentage # 70% Fe, 30% Ni alloy alloy = mix_by_weight('Fe', 70, 'Ni', 30, name='FeNi') print(f"Alloy mass: {alloy.mass}") print(f"Alloy density: {alloy.density}") # Computed from components # Mix by volume percentage # 60% ethanol, 40% water solution solution = mix_by_volume('C2H5OH@0.789', 60, 'H2O@1.0', 40) print(f"Solution density: {solution.density}") # With explicit density override polymer = mix_by_weight('C2H4', 80, 'C3H6', 20, density=0.92, name='PE-PP') # Parse mixture formulas directly # Weight percent notation m1 = formula("50wt%ite // 50%ite") # 50% TiO2, 50% SiO2 # Volume percent notation m2 = formula("30vol% H2O@1.0 // 70% D2O@1.1") # Layer thickness notation (for thin films) film = formula("10nm SiO2@2.2 // 5nm Ti@4.5") # Absolute mass notation sample = formula("5mg NaCl // 10mg KCl") # Composite SLD calculator for variable compositions from periodictable.nsf import neutron_composite_sld materials = [formula("H2O@1.0"), formula("D2O@1.1")] calc = neutron_composite_sld(materials, wavelength=1.798) # Calculate SLD for different H2O/D2O ratios weights = [0.5, 0.5] # 50/50 mixture density = 1.05 sld = calc(weights, density=density) print(f"50/50 H2O/D2O SLD: {sld}") ``` -------------------------------- ### Access Isotopes by Mass Number (Ni) Source: https://github.com/python-periodictable/periodictable/blob/master/doc/sphinx/guide/using.rst Illustrates accessing specific isotopes of an element (Nickel) using mass number subscripts. It compares the coherent neutron scattering of 58-Ni and 62-Ni. ```python from periodictable import Ni print("58-Ni vs 62-Ni scattering %s:%s"%(Ni[58].neutron.coherent, Ni[62].neutron.coherent)) ``` -------------------------------- ### Parse and Manipulate Chemical Formulas in Python Source: https://context7.com/python-periodictable/periodictable/llms.txt Illustrates chemical formula parsing and manipulation using the periodictable Python package. It supports string parsing, dictionary construction, isotope notation, density specifications, and mathematical operations on formulas. Outputs include molar mass, density, and composition. ```python from periodictable import formula, elements # Parse string formulas water = formula("H2O") print(water.mass) # 18.015 u print(water.atoms) # {H: 2, O: 1} # Complex formulas with groups calcite_hydrate = formula("CaCO3+6H2O") gypsum = formula("CaSO4(H2O)2") # Isotope notation using brackets heavy_water = formula("D2O") labeled = formula("C[13]O2") # Carbon-13 dioxide # Specify density with @ notation water_with_density = formula("H2O@1.0") d2o = formula("D2O@1.11") # Use 'n' suffix for natural density (adjusts for isotope mass) d2o_natural = formula("D2O@1.0n") # Build from dictionary compound = formula({elements.Ca: 1, elements.C: 1, elements.O: 3}) # Mathematical operations on formulas ethanol = formula("C2H5OH") glucose = 6 * formula("CH2O") # Multiply by count mixture = formula("NaCl") + formula("H2O") # Combine formulas # Access composition print(water.mass) # Molar mass in u print(water.molecular_mass) # Mass in grams print(water.density) # Density in g/cm^3 print(water.mass_fraction) # {H: 0.1119, O: 0.8881} print(water.hill) # Hill notation formula # Volume estimation vol = formula("NaCl@2.16").volume(packing_factor='fcc') vol = formula("NaCl@2.16").volume(a=5.64) # From lattice constant ``` -------------------------------- ### Restructure Package and Separate Tests in Python Source: https://github.com/python-periodictable/periodictable/blob/master/ChangeLog.rst The internal structure of the `periodictable` package has been reorganized. Tests are now located in a separate directory, improving code organization and maintainability. ```python # Project structure change: # - # periodictable/ # core.py # elements.py # nsf.py # ... # tests/ # test_core.py # test_elements.py # ... ``` -------------------------------- ### Reload Base Table Properties (Python) Source: https://github.com/python-periodictable/periodictable/blob/master/doc/sphinx/guide/customizing.rst Illustrates how to replace a dataset in the base table with custom values using the 'reload=True' option. This method has a global effect and is generally discouraged due to potential conflicts with other packages. ```python from periodictable import elements # Assuming 'custom_mass' is a module with your custom values # custom_mass.init(elements, reload = True) ``` -------------------------------- ### Define Custom Formula Parser (Python) Source: https://github.com/python-periodictable/periodictable/blob/master/doc/sphinx/guide/customizing.rst Shows how to define a custom parser for chemical formulas when using custom tables. This is necessary to correctly interpret formulas within the context of your specific table configuration. ```python from periodictable.formulas import formula_grammar parser = formula_grammar(table=elements) ``` -------------------------------- ### Calculate Neutron Scattering Properties in Python Source: https://context7.com/python-periodictable/periodictable/llms.txt Shows how to compute neutron scattering length density (SLD), cross sections, and penetration depth for elements, isotopes, and compounds using the periodictable Python package. Supports calculations based on natural abundance, specific isotopes, and includes options for wavelength and energy dependence. ```python import periodictable from periodictable import formula, neutron_sld, neutron_scattering # Element neutron properties ni = periodictable.Ni print(ni.neutron.b_c) # Bound coherent scattering length: 10.3 fm print(ni.neutron.absorption) # Absorption cross section: 4.49 barn print(ni.neutron.total) # Total scattering cross section # SLD for element at natural abundance and density sld = ni.neutron.sld() # Returns (real, imag, incoh) in 1e-6/A^2 print(f"Ni SLD: {sld[0]:.4f} x 10^-6 A^-2") # Isotope-specific neutron data ni58 = periodictable.Ni[58] print(ni58.neutron.b_c) # 14.4 fm print(ni58.neutron.abundance) # 67.88% # SLD table for isotopes for iso in periodictable.Ni: if iso.neutron.has_sld(): sld = iso.neutron.sld() print(f"{iso}: {sld[0]:.4f}") # Compound SLD calculation (requires density) sld = neutron_sld("H2O", density=1.0) print(f"H2O SLD: {sld}") # (real, imag, incoh) # Full scattering calculation sld, xs, penetration = neutron_scattering("SiO2", density=2.2) print(f"SLD: {sld}") # (real, imag, incoh) 1e-6/A^2 print(f"Cross sections: {xs}") # (coherent, absorption, incoherent) 1/cm print(f"1/e penetration: {penetration} cm") # Wavelength-dependent calculations sld, xs, pen = neutron_scattering("B4C", density=2.52, wavelength=4.75) # Energy-dependent calculations sld, xs, pen = neutron_scattering("Gd2O3", density=7.4, energy=25) # meV ``` -------------------------------- ### Create Formula from Atoms Source: https://github.com/python-periodictable/periodictable/blob/master/doc/sphinx/guide/formula_grammar.rst Demonstrates creating a chemical formula object from individual atoms using the `formula` function. This is a basic way to represent simple compounds. ```python from periodictable import Ca, C, O, H print(formula(Ca)) ``` -------------------------------- ### Access Element and Isotope Data in Python Source: https://context7.com/python-periodictable/periodictable/llms.txt Demonstrates how to access element and isotope data using the periodictable Python package. It covers lookup by symbol, name, atomic number, and specific isotopes, along with iterating through isotopes of an element. No external dependencies are required beyond the package itself. ```python import periodictable # Access elements by symbol (attribute access) ni = periodictable.Ni print(ni.symbol) # 'Ni' print(ni.name) # 'nickel' print(ni.number) # 28 print(ni.mass) # 58.6934 u print(ni.density) # 8.908 g/cm^3 # Access by atomic number iron = periodictable.elements[26] print(iron.symbol) # 'Fe' # Access by name or symbol lookup fe = periodictable.elements.symbol('Fe') fe = periodictable.elements.name('iron') # Access specific isotopes ni58 = periodictable.Ni[58] print(ni58.isotope) # 58 print(ni58.mass) # 57.9353 u # Special isotopes: deuterium and tritium D = periodictable.D # 2-H T = periodictable.T # 3-H # Iterate over all isotopes of an element for iso in periodictable.Ni: print(f"{iso}: mass={iso.mass}") ``` -------------------------------- ### Add Activation Decay Time to Neutron Activation Calculator in Python Source: https://github.com/python-periodictable/periodictable/blob/master/ChangeLog.rst The neutron activation calculator now includes support for specifying activation decay time. This allows for more accurate calculations of radioactive decay products after neutron irradiation. ```python from periodictable import neutron_activation # Example usage (hypothetical): # activation_data = neutron_activation('Fe56', flux=1e14, time=3600, decay_time=7200) ``` -------------------------------- ### Handle Missing Properties (Radon Density) Source: https://github.com/python-periodictable/periodictable/blob/master/doc/sphinx/guide/using.rst Illustrates that missing properties for an element, such as the density of Radon (Rn), will evaluate to None. ```python import periodictable print("Radon density %s"%periodictable.Rn.density) ``` -------------------------------- ### Define Table Extensions in Python Source: https://github.com/python-periodictable/periodictable/blob/master/ChangeLog.rst When extending the periodic table, the import statement has changed. Users should now import `periodic_table`, `Element`, and `Isotope` from `elements.core`. ```python # Old way: # from elements import periodic_table # from elements.elements import Element, Isotope # New way: from periodictable.core import periodic_table, Element, Isotope ``` -------------------------------- ### Support Pickle for Elements in Python Source: https://github.com/python-periodictable/periodictable/blob/master/ChangeLog.rst Elements and their associated data can now be pickled and unpickled, ensuring that object identity is preserved across serialization. This is useful for caching and inter-process communication. ```python import pickle from periodictable import H # Serialize and deserialize serialized_H = pickle.dumps(H) unpickled_H = pickle.loads(serialized_H) # Check identity print(id(H) == id(unpickled_H)) # Output: True ``` -------------------------------- ### Add nsf.D2O_match() and nsf.D2O_sld() Functions in Python Source: https://github.com/python-periodictable/periodictable/blob/master/ChangeLog.rst This snippet details the addition of two new functions, `nsf.D2O_match()` and `nsf.D2O_sld()`, within the `nsf` module. These functions likely relate to calculating properties or matching conditions involving Deuterium Oxide (D2O). ```python from periodictable import nsf # Example usage (hypothetical): # biomolecule = 'some_protein' # d2o_contrast = nsf.D2O_match(biomolecule) # d2o_scattering_length_density = nsf.D2O_sld() ``` -------------------------------- ### Rename Package and Table in Python Source: https://github.com/python-periodictable/periodictable/blob/master/ChangeLog.rst The main package has been renamed from `elements` to `periodictable`. Consequently, the `table` object has also been renamed to `periodictable.elements` for clarity and consistency. ```python # Old import: # from elements import periodic_table # from elements.elements import Element, Isotope # New import: from periodictable import elements from periodictable.core import Element, Isotope # Accessing elements: # periodic_table = elements.periodic_table ``` -------------------------------- ### Parse Biological and Chemical Formulas with Periodictable Source: https://context7.com/python-periodictable/periodictable/llms.txt Demonstrates parsing biological sequences (RNA) and chemical formulas using FASTA notation directly with the periodictable library. This is useful for initial data input and validation. ```python from periodictable import Sequence, formula # Parse RNA sequence rna = Sequence( name="myrna", sequence="AUGCGAUCGAUCG", type="rna" ) # Parse formulas with FASTA notation directly protein_formula = formula("aa:MKFLILLFNILC") dna_formula = formula("dna:ATGCGATC") rna_formula = formula("rna:AUGCGAUC") ``` -------------------------------- ### Access Element by Name (Hydrogen) Source: https://github.com/python-periodictable/periodictable/blob/master/doc/sphinx/guide/using.rst Demonstrates accessing a specific element, Hydrogen, by its full name and printing its mass and mass units. ```python from periodictable import hydrogen print("H mass %s %s"%(hydrogen.mass, hydrogen.mass_units)) ``` -------------------------------- ### Formula Parser Accepts Ions in Python Source: https://github.com/python-periodictable/periodictable/blob/master/ChangeLog.rst The formula parser has been extended to recognize and parse ionic species using specific notations like `Yy{#+}` or `Yy[#]{#+}`. This improves the representation of charged chemical entities. ```python from periodictable import formula # Example: # ion_formula = formula('Fe[2+]') # isotope_ion_formula = formula('Cl[35]{-1}') # print(ion_formula.charge) # Output: 2 ``` -------------------------------- ### Biomolecule Support (FASTA) for Scattering Calculations Source: https://context7.com/python-periodictable/periodictable/llms.txt Enables working with amino acid sequences, DNA, and RNA from FASTA format for scattering calculations. Supports defining molecules with labile hydrogen and parsing biological sequences. Uses classes from periodictable.fasta. ```python from periodictable.fasta import Molecule, Sequence # Define a molecule with labile hydrogen # Use H[1] for exchangeable hydrogen positions lysine = Molecule( name="lysine", formula="C6H14N2O2H[1]3", # 3 labile H cell_volume=168.6, charge=1 ) print(f"Lysine SLD: {lysine.sld}") print(f"Lysine D2O match: {lysine.D2Omatch}%") print(f"Lysine mass: {lysine.mass}") # SLD in deuterated solvent sld = lysine.D2Osld(volume_fraction=1.0, D2O_fraction=0.5) # Parse amino acid sequence protein = Sequence( name="myprotein", sequence="MKFLILLFNILCLFPVLAADNHGVGPLNC", type="aa" # amino acid ) print(f"Protein formula: {protein.natural_formula}") print(f"Protein SLD: {protein.sld}") print(f"D2O match point: {protein.D2Omatch:.1f}%") # Parse DNA sequence dna = Sequence( name="mydna", sequence="ATGCGATCGATCG", type="dna" ) ``` -------------------------------- ### Use Natural Density for Isotope Specific Formulas in Python Source: https://github.com/python-periodictable/periodictable/blob/master/ChangeLog.rst When defining isotope-specific formulas, the library now defaults to using the natural density of the element. This provides a more physically relevant default density for isotopic compositions. ```python from periodictable import formula # Example: # deuterium_oxide = formula('D2O') # The density will now default to a value related to natural water density. ``` -------------------------------- ### Add replace() Method to Formula in Python Source: https://github.com/python-periodictable/periodictable/blob/master/ChangeLog.rst Introduces the `replace()` method for formula objects, enabling isotope substitution. This allows for dynamic modification of chemical formulas to represent specific isotopic compositions. ```python from periodictable import formula # Example usage: # f = formula('H2O') # f_deuterated = f.replace({'H': 'D'}) # print(f_deuterated) # Output: D2O ``` -------------------------------- ### Access Deuterium (D) and Tritium (T) Masses Source: https://github.com/python-periodictable/periodictable/blob/master/doc/sphinx/guide/using.rst Shows how to access the special isotopes Deuterium (D) and Tritium (T) by their symbols and print their masses. ```python from periodictable import D print("D mass %s"%D.mass) ``` -------------------------------- ### Accessing Element Properties with Periodictable Source: https://context7.com/python-periodictable/periodictable/llms.txt Retrieves various physical and chemical properties of elements, such as covalent radius, crystal structure, density, mass, and ion properties. It also demonstrates accessing magnetic form factors and listing elements by specific criteria. ```python import periodictable import numpy as np # Covalent radius fe = periodictable.Fe print(f"Fe covalent radius: {fe.covalent_radius} {fe.covalent_radius_units}") print(f"Uncertainty: {fe.covalent_radius_uncertainty}") # Crystal structure print(f"Fe crystal structure: {fe.crystal_structure}") # Density and mass print(f"Fe density: {fe.density} g/cm^3") print(f"Fe mass: {fe.mass} u") print(f"Fe number density: {fe.number_density} atoms/cm^3") # Ion properties fe2 = periodictable.Fe.ion[2] # Fe2+ fe3 = periodictable.Fe.ion[3] # Fe3+ print(f"Fe2+ charge: {fe2.charge}") print(f"Fe2+ mass: {fe2.mass}") # Accounts for electron mass # Magnetic form factors (for neutron magnetic scattering) Q = np.linspace(0, 10, 50) ff = fe.magnetic_ff[0].j0(Q) # j0 form factor print(f"Fe j0(Q=0): {ff[0]}") # List elements with specific properties periodictable.elements.list('symbol', 'mass', 'density', format="%-2s: %6.2f u %6.2f g/cm^3") # Iterate over all elements for el in periodictable.elements: if el.density and el.density > 10: print(f"{el.symbol}: {el.density} g/cm^3") ``` -------------------------------- ### Iterate Through Isotopes of an Element (Hydrogen) Source: https://github.com/python-periodictable/periodictable/blob/master/doc/sphinx/guide/using.rst Demonstrates iterating through all isotopes of Hydrogen (H) and printing the isotope symbol and its mass. ```python import periodictable for iso in periodictable.H: print("%s %s"%(iso,iso.mass)) ``` -------------------------------- ### Clone Formula Object Source: https://github.com/python-periodictable/periodictable/blob/master/doc/sphinx/guide/formula_grammar.rst Demonstrates the ability to clone a formula object, creating an independent copy. This is useful for modifying or using a formula without affecting the original. ```python print(formula(formula("CaCO3+6H2O"))) ``` -------------------------------- ### Calculate X-ray Scattering Length Density Source: https://github.com/python-periodictable/periodictable/blob/master/doc/sphinx/guide/formula_grammar.rst Demonstrates the calculation of X-ray scattering length density (SLD) for a given chemical formula. This calculation requires the formula object, density, and wavelength, often using characteristic X-ray sources like Copper K-alpha. ```python rho,mu = periodictable.xray_sld(hydrated,density=1.5, wavelength=periodictable.Cu.K_alpha) print(f"{hydrated} X-ray sld {rho:.3g}") ``` -------------------------------- ### Specify Volume Fractions in Formula Source: https://github.com/python-periodictable/periodictable/blob/master/doc/sphinx/guide/formula_grammar.rst Defines mixtures based on volume fractions using 'vol%' or '%'. Requires densities for individual components to calculate mixture density accurately. ```python from periodictable import formula # Example: Mixture with volume fractions print(formula("10vol% Fe // Ni")) ``` -------------------------------- ### Specify Natural Density for Formula Source: https://github.com/python-periodictable/periodictable/blob/master/doc/sphinx/guide/formula_grammar.rst Shows how to specify the natural density of a formula when it is created. This is particularly useful for compounds like heavy water where density is a key property. ```python D2O = formula("D2O", natural_density=1) print(f"{D2O} {D2O.density:.4g}") ``` -------------------------------- ### Iterate Through All Elements (Symbol and Name) Source: https://github.com/python-periodictable/periodictable/blob/master/doc/sphinx/guide/using.rst Iterates through all elements in the periodictable library and prints the symbol and name of each element. ```python import periodictable for el in periodictable.elements: print("%s %s"%(el.symbol,el.name)) ``` -------------------------------- ### Calculate Molar Mass and Neutron Scattering Length Density Source: https://github.com/python-periodictable/periodictable/blob/master/doc/sphinx/guide/formula_grammar.rst Shows how to compute derived properties of a chemical formula, such as molar mass and neutron scattering length density (SLD). This involves combining formulas and providing density and wavelength parameters. ```python import periodictable SiO2 = periodictable.formula('SiO2') hydrated = SiO2 + periodictable.formula('3H2O') print(f"{hydrated} mass {hydrated.mass:.3f}") rho,mu,inc = periodictable.neutron_sld('SiO2+3H2O',density=1.5,wavelength=4.75) print(f"{hydrated} neutron sld {rho:.3g}") ``` -------------------------------- ### Specify Mass Fractions in Formula Source: https://github.com/python-periodictable/periodictable/blob/master/doc/sphinx/guide/formula_grammar.rst Defines mixtures based on mass fractions using 'wt%' or '%'. The sum of fractions should ideally approach 100%. Requires density for non-elemental components if used in volume calculations. ```python from periodictable import formula # Example: Mixture with mass fractions print(formula("10wt% Fe // 15% Co // Ni")) ``` -------------------------------- ### Neutron Activation Analysis with Periodictable Source: https://context7.com/python-periodictable/periodictable/llms.txt Calculates neutron activation for samples exposed to neutron beams, including decay calculations. It defines neutron environments, sample compositions, and exposure/rest times to estimate activity. ```python from periodictable import activation # Define the neutron environment env = activation.ActivationEnvironment( fluence=1e10, # neutrons/cm^2/s thermal flux Cd_ratio=70, # Thermal to epithermal ratio fast_ratio=50, # Thermal to fast ratio location="NCNR" ) # Define sample by formula and mass (grams) sample = activation.Sample("Co30Fe70", mass=10.0) # 10g sample # Calculate activation for given exposure and rest times sample.calculate_activation( env, exposure=10, # hours of exposure rest_times=[0, 1, 24, 360] # hours after removal ) # Display activation table sample.show_table() # Output shows isotope, product, reaction, half-life, and activity at each rest time # Find time to reach a specific activity level hours = sample.decay_time(0.001) # Time to reach 1 nCi print(f"Time to reach 1 nCi: {hours:.2f} hours") # Detailed access to activation products for p in sample.products: print(f"{p.isotope} -> {p.product}: {p.activity[0]:.4f} uCi at t=0") ``` -------------------------------- ### Access Element Indirectly (Cadmium) Source: https://github.com/python-periodictable/periodictable/blob/master/doc/sphinx/guide/using.rst Demonstrates accessing an element, Cadmium (Cd), indirectly through the periodictable module and printing its density. ```python import periodictable print("Cd density %.2f %s"%(periodictable.Cd.density, periodictable.Cd.density_units)) ``` -------------------------------- ### Iterate Through All Elements (Symbol and Number) Source: https://github.com/python-periodictable/periodictable/blob/master/doc/sphinx/guide/using.rst Iterates through all elements using the imported 'elements' object and prints the symbol and atomic number of each element. ```python from periodictable import elements for el in elements: print("%s %s"%(el.symbol,el.number)) ``` -------------------------------- ### Specify Specific Mass in Formula Source: https://github.com/python-periodictable/periodictable/blob/master/doc/sphinx/guide/formula_grammar.rst Allows specifying components by mass (e.g., '5g NaCl') or volume (e.g., '50mL H2O@1'). Density is required for volume specifications. The total mass is stored in the `total_mass` attribute. ```python from periodictable import formula # Example: Mixture with specific mass and volume print(formula("5g NaCl // 50mL H2O@1")) ``` -------------------------------- ### Create Formula from Nested Structures Source: https://github.com/python-periodictable/periodictable/blob/master/doc/sphinx/guide/formula_grammar.rst Shows how to construct complex chemical formulas using nested lists of counts and fragments. This allows for representing hydrated compounds or other complex molecular structures. ```python print(formula( [ (1,Ca), (1,C), (3,O), (6,[(2,H),(1,O)]) ] )) ``` -------------------------------- ### Default Neutron Wavelength in Python Source: https://github.com/python-periodictable/periodictable/blob/master/ChangeLog.rst Modifies the default behavior of `neutron_sld()` and `neutron_scattering()` functions. When both wavelength and energy are unspecified, a default neutron wavelength of 1.798 Å is now used, preventing assertion errors. ```python from periodictable import neutron_sld, neutron_scattering # Previously, this would raise an error: # result = neutron_sld('H2O') # Now, it uses a default wavelength: # result = neutron_sld('H2O') # Uses default wavelength if none provided ```