.. _mat-python: Python ====== Use the native object model from ``scinumtools3.mat``. Basic examples -------------- Calculate a formula's composition with the native Python objects: .. code-block:: python from scinumtools3.mat import Substance water = Substance("H2O") print(water.data_composite().sum.mass) # 18.0153*u Calculate a mixture's total mass through the command facade: .. code-block:: python from scinumtools3.api.mat import MATMaterial, quantity_value from scinumtools3.puq import Quantity command = MATMaterial("0.965 0.035 ") command.argument_normalization("mass_fraction") command.argument_mass_density(Quantity(1.02, "g/cm3")) command.argument_volume(Quantity(1, "L")) brine = command.execute() print(quantity_value(brine.matter.mass, "g")) # approximately 1020 Common workflows ---------------- .. list-table:: :header-rows: 1 * - Task - Call chain - Result * - Evaluate a formula - ``Substance(expression)``; ``data_composite()`` - ``Substance``; ``CompositeData`` * - Derive matter values - ``MatterSpec``; ``Substance(..., matter=...)``; ``mass()`` - ``Quantity`` or ``None`` * - Build a normalized mixture - ``Material(..., normalization=Norm.MASS_FRACTION, ...)`` - ``Material`` * - Modify or extend a composition - ``add(expression, proportion)``; ``data_components()`` - Updated object; component records * - Use the command facade - ``MATSubstance(...).execute()`` - ``SubstanceResult`` .. code-block:: python from scinumtools3.mat import Material, MatterSpec, Norm, Substance from scinumtools3.puq import Quantity matter = MatterSpec() matter.mass_density = Quantity(1.02, "g/cm3") matter.volume = Quantity(1.0, "L") water = Substance("H2O", matter=matter) # Substance print(water.mass()) # Quantity print(water.data_composite().sum.mass) # Quantity mixture = Material("0.965 0.035 ", normalization=Norm.MASS_FRACTION) # Material print(mixture.reference_count) The command-oriented ``scinumtools3.api.mat`` facade returns the same typed records used by the CLI and REST server and follows the same command-object lifecycle as the PUQ and DIP API modules. See the :doc:`Python binding guide <../../../integrations/python>`, :doc:`native Python API reference <../../../api/python_mat>`, and :doc:`application command reference <../../../api/python_api>`. Current limitations and differences ----------------------------------- Compared with the canonical C++ implementation: - Python exposes the native Element, Substance, and Material objects and the command facade. Optional quantities use ``None`` instead of ``std::optional``; returned record fields are read-only Python attributes. ``MatterSpec`` inputs remain writable. - Direct ionization-table lookup and the C++ expression-solver extension interfaces are not wrapped. - The isotope choices, normalization, matter consistency checks, and physical limits are the same as in C++; the binding adds no separate physics model. Binding reference ----------------- This is a lookup index, not a sequence to read from top to bottom. Use `Common workflows` above to choose a task, then find the exact Python names for that task below. Properties are shown without parentheses; callable names include their arguments. The linked API reference documents complete signatures and result fields. Construction and matter inputs ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - ``Element(expression, proportion=1, natural=True, matter=MatterSpec())``. - ``Substance(expression, proportion=1.0, natural=True, matter=MatterSpec())``, ``Substance()``, ``Substance(number)``, and ``Substance(elements, ...)``. - ``Material(expression, normalization=Norm.NUMBER_FRACTION, natural=True, matter=MatterSpec())``, ``Material()``, and ``Material(substances, ...)``. - ``MatterSpec()`` with writable fields ``number_density``, ``mass_density``, ``volume``, and ``mass``. Element calls ~~~~~~~~~~~~~ - Properties ``expression``, ``symbol``, ``isotope``, ``charge``, ``natural``, ``selection``, ``effective_isotope_number``, ``natural_abundance_sum``, ``proportion``, and ``component_mass``. - Methods ``mass()``, ``mass_density()``, ``number_density()``, ``total_number_density()``, ``volume()``, ``matter_spec()``, ``set_matter()``, ``data()``, ``data_matter()``, and ``to_string()``. Substance and material calls ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - Properties ``expression``, ``natural``, ``normalization``, ``reference_count``, ``proportion`` (substance), ``formula`` (substance), and ``component_mass`` (substance). - Methods ``add(expression, proportion=1)``, ``composite_mass()``, ``mass()``, ``mass_density()``, ``number_density()``, ``total_number_density()``, ``volume()``, ``matter_spec()``, ``set_matter()``, ``data_components()``, ``data_composite()``, ``data_matter()``, and ``to_string()``. Enums and result records ~~~~~~~~~~~~~~~~~~~~~~~~ - ``Norm.NUMBER``, ``Norm.NUMBER_FRACTION``, ``Norm.MASS_FRACTION``. - ``IsotopeSelection.EXPLICIT``, ``NATURAL``, ``DEFAULT``, and ``PARTICLE``. - ``ElementData``, ``ComponentData``, ``CompositeRow``, ``CompositeData``, ``MatterSpecies``, ``MatterRow``, and ``MatterData``. Application command facade ~~~~~~~~~~~~~~~~~~~~~~~~~~ - ``scinumtools3.api.mat.MATElement(expression)``, ``MATSubstance(expression)``, and ``MATMaterial(expression)``. - ``argument_natural()``, ``argument_matter()``, ``argument_normalization()``, ``argument_number_density()``, ``argument_mass_density()``, ``argument_volume()``, ``argument_mass()``, and ``execute()``. - ``quantity_value(value, units)`` and ``normalization_name(normalization)``.