periodictable

repository·master·Indexed 41 days ago

https://github.com/python-periodictable/periodictable

An extensible periodic table library for Python providing detailed elemental data, including mass, density, and specialized scattering information for X-ray and neutron physics. It features a chemical formula parser supporting isotopes, ions, and mixtures, as well as the ability to create custom PeriodicTable instances and extend the table with third-party property packages.

Tokens
21.8K
Snippets
88
Records
108
Agent score
51%

What's inside periodictable

  1. Overview of the periodictable package

    master

    The periodictable package provides an extensible periodic table containing various properties of the elements, such as name, symbol, mass, and density. It is specifically designed to provide data important to neutron and X-ray scattering experiments, allowing users to compute the scattering potential of a compound at a given wavelength using the elements package.

    Because the table is extensible, third-party packages can add new properties to the existing structure without modifying the core package.

  2. Introduction to the periodictable package

    master
    The periodictable package is an extensible periodic table of the elements implemented entirely in Python. It is designed for use in scientific contexts, specifically pre-populated with data relevant to neutron and X-ray scattering experiments. The package has no external library dependencies, making it easy to integrate into existing Python environments.
  3. Overview of periodictable capabilities

    master

    The periodictable package is an extensible periodic table that supports several scientific calculation domains:

    • Mass and Density: Standard elemental properties.
    • Neutron Scattering: Uses values from the neutron data booklet (Atomic Institute of the Austrian Universities), including energy-dependent scattering for rare earth elements (Lynn and Seeger, 1990).
    • X-ray Scattering: Uses a combination of empirical and theoretical values from the LBL Center for X-ray Optics.
    • Neutron Activation: Provides gross estimates of expected activation for a sample in a beam based on Shleien (1998), focusing on isotopes important to health physics. Note that this is a gross estimate and not a full activation analysis.
  4. License and usage terms for periodictable

    master

    The periodictable package is in the public domain. However, users should check individual file headers, as specific files may contain separate copyright and licensing terms.

    Disclaimer: The data provided by this package is compiled from various sources for convenience and does not constitute a critical evaluation. While efforts are made to verify values against published data, the values are based on measurements that may differ from specific experimental conditions.

  5. Use `delayed_load` for efficient property extension

    master

    For large datasets, instead of loading all data immediately upon import, use periodictable.core.delayed_load. This prevents slow import times by deferring data loading until the attribute is actually accessed.

    delayed_load takes two arguments:

    1. A list of attribute names that will be defined.
    2. A loading function. The docstring of this function will be used as the attribute description.

    When using delayed_load for isotope-specific data, you must set isotope=True in the call to ensure the magic delegation works correctly.

    # discoverer/__init__.py
    import periodictable
    from periodictable.core import delayed_load
    
    def load_discoverer(table):
        """Description of the discoverer attribute"""
        # Logic to populate discoverer
        pass
    
    delayed_load(['discoverer'], load_discoverer)
  6. Key features of periodictable

    master

    The package includes several core abstractions for chemical and physical modeling:

    • Standard Properties: Built-in support for element name, symbol, mass, and density.
    • Chemical Formulas: Use periodictable.formulas.Formula to parse chemical formulas and compute properties like molar mass.
    • Isotopes: Use periodictable.core.Isotope to access mass and relative abundance for known isotopes. Formulas can include isotope composition.
    • Ions: Use periodictable.core.Ion to access magnetic form factors and ionic radii.
    • Scattering Factors: Use periodictable.nsf (Neutron) and periodictable.xsf (X-ray Scattering Factors) to get wavelength-dependent scattering factors for elements, isotopes, and formulas.
    • Extensibility: New properties can be added to the periodictable.core.PeriodicTable from external packages, allowing for specialized tables with alternative values.
  7. Add ion-specific data to elements

    master

    To add properties that depend on the ion's state, use the ion=True keyword when calling delayed_load.

    Note that ion-dependent properties can interact complexly with isotopes (e.g., Ni[58].ion[3]). While the library supports ion-specific data, some existing modules (like magnetic_ff) may require users to access properties via specific patterns like ion.magnetic_ff[ion.charge] rather than direct attribute access.

  8. Add new properties to the periodic table

    master

    The periodic table is extensible via third-party packages. You can add attributes to all elements by defining a Python package that implements an init(table) function. This function attaches information to the periodic table so it is available on demand.

    To add a simple attribute (like discoverer) to every element, create a module containing the init(table) function and call it with the default table instance.

    # discoverer/discoverer.py
    def init(table):
        for el in table:
            el.discoverer = "J. Black" # Example value
    
    import periodictable
    init(periodictable.core.default_table())
  9. Specify density in formulas using the '@' tag

    master

    You can specify the density of a formula directly within the string using the @ tag. This is useful for isotopic density or natural density.

    • Isotopic density: formula("D2O@1.112")
    • Natural density: Use the n suffix, e.g., formula("D2O@1n"). This assumes isotope substitution does not change the unit cell volume.
    • Mixtures: Density applies to the entire formula. For a mixture, specify the density of the resulting compound or the components.

    Note: For volume-based mixtures, density must be known for individual components.

    # Specify isotopic density
    print(formula("D2O@1.112").density)
    
    # Specify natural density
    print(formula("D2O@1n").density)
    
    # Mixture with density
    print(formula("2D2O + H2O@1n").density)
  10. Access isotopes and special isotopes

    master

    Isotopes can be accessed using mass number subscripts on the element object (e.g., Ni[58]). Additionally, certain isotopes have special names, such as D for Deuterium and T for Tritium.

    from periodictable import Ni, D, T
    
    # Access specific isotope by mass number
    print(Ni[58].neutron.coherent)
    
    # Access special isotopes
    print(D.mass)
    print(T.mass)