# Path: auxi/core/objects.py
# class Object(object):
#     """
#     Base class for all auxi classes.
#     """
# 
#     def __str__(self):
#         o = json.loads(jsonpickle.encode(self))
#         result = json.dumps(o, sort_keys=True, indent=4,
#                             separators=(',', ': '))
#         return result
# 
#     def __hash__(self):
#         return hash(str(self))
# 
#     def _validate_params_(self):
#         pass
# 
#     def _init(self):
#         pass
# 
#     def write(self, path):
#         with open(path, 'w') as file:
#             file.write(str(self))
# 
#     @staticmethod
#     def read(path):
#         with open(path, 'r') as file:
#             s = file.read()
#         result = jsonpickle.decode(s)
#         result._init()
#         return result
# 
# class NamedObject(Object):
#     """
#     Base class for all auxi classes requiring a name and description.
# 
#     :param name: the object's name
#     :param description: the object's description
#     """
# 
#     def __init__(self, name, description=None):
#         self.name = name
#         self.description = description
# 
#     def _validate_params_(self, name, description):
#         # TODO: Enforce name format.
#         pass
# 
# Path: auxi/tools/chemistry/stoichiometry.py
# def element_mass_fractions(compound, elements):
#     """
#     Determine the mass fractions of a list of elements in a chemical compound.
# 
#     :param compound: Formula and phase of a chemical compound, e.g.
#       'Fe2O3[S1]'.
#     :param elements: List of elements, ['Si', 'O', 'Fe'].
# 
#     :returns: Mass fractions.
#     """
# 
#     return [element_mass_fraction(compound, element)
#             for element in elements]
# 
# Path: auxi/tools/chemistry/stoichiometry.py
# class Element(Object):
# class Group:
# class Compound:
# class CompoundVisitor(parsimonious.NodeVisitor):
#     def __init__(self, period, group, atomic_number, symbol, molar_mass):
#     def count(self):
#     def _validate_(self):
#     def __repr__(self):
# def count_with_multiplier(groups, multiplier):
#     def __init__(self, group, multiplier=1, dotted=False):
#     def count(self):
#     def __repr__(self):
#     def __init__(self, group, dottedgroup=None, phase=None):
#     def count(self):
#     def molar_mass(self):
#     def __repr__(self):
#     def visit_compound(self, _, compound):
#     def visit_group(self, _, group):
#     def visit_phase(self, node, _):
#     def visit_dottedgroup(self, _, dottedgroup):
#     def visit_subscriptedgroup(self, _, subscriptedgroup):
#     def visit_subscriptedelement(self, _, subscriptedelement):
#     def visit_element(self, node, _):
#     def visit_number(self, node, _):
#     def generic_visit(self, node, other):
# def parse_compound(string):
# def amount(compound, mass):
# def amounts(masses):
# def amount_fractions(masses):
# def mass(compound, amount):
# def masses(amounts):
# def mass_fractions(amounts):
# def convert_compound(mass, source, target, element):
# def element_mass_fraction(compound, element):
# def element_mass_fractions(compound, elements):
# def elements(compounds):
# def molar_mass(compound=''):
# def stoichiometry_coefficient(compound, element):
# def stoichiometry_coefficients(compound, elements):


import copy
    import unittest
from os.path import isfile
from auxi.core.objects import Object, NamedObject
from auxi.tools.chemistry.stoichiometry import element_mass_fractions as emf
from auxi.tools.chemistry import stoichiometry as stoich
    from auxi.modelling.process.materials.chem_test \
        import ChemMaterialUnitTester, ChemMaterialPackageUnitTester

    def get_element_mass_dictionary(self):
        """
        Determine the masses of elements in the package and return as a
        dictionary.

        :returns: [kg] A dictionary of element symbols and masses.
        """

        element_symbols = self.material.elements
        element_masses = self.get_element_masses()

        result = {}
        for s, m in zip(element_symbols, element_masses):
            result[s] = m

        return result

    def get_element_mass(self, element):
        """
        Determine the masses of elements in the package.

        :returns: [kg] An array of element masses. The sequence of the elements
          in the result corresponds with the sequence of elements in the
          element list of the material.
        """

        result = [0]
        for compound in self.material.compounds:
            c = self.get_compound_mass(compound)

# Path: auxi/core/objects.py
# class Object(object):
#     """
#     Base class for all auxi classes.
#     """
# 
#     def __str__(self):
#         o = json.loads(jsonpickle.encode(self))
#         result = json.dumps(o, sort_keys=True, indent=4,
#                             separators=(',', ': '))
#         return result
# 
#     def __hash__(self):
#         return hash(str(self))
# 
#     def _validate_params_(self):
#         pass
# 
#     def _init(self):
#         pass
# 
#     def write(self, path):
#         with open(path, 'w') as file:
#             file.write(str(self))
# 
#     @staticmethod
#     def read(path):
#         with open(path, 'r') as file:
#             s = file.read()
#         result = jsonpickle.decode(s)
#         result._init()
#         return result
# 
# class NamedObject(Object):
#     """
#     Base class for all auxi classes requiring a name and description.
# 
#     :param name: the object's name
#     :param description: the object's description
#     """
# 
#     def __init__(self, name, description=None):
#         self.name = name
#         self.description = description
# 
#     def _validate_params_(self, name, description):
#         # TODO: Enforce name format.
#         pass
# 
# Path: auxi/tools/chemistry/stoichiometry.py
# def element_mass_fractions(compound, elements):
#     """
#     Determine the mass fractions of a list of elements in a chemical compound.
# 
#     :param compound: Formula and phase of a chemical compound, e.g.
#       'Fe2O3[S1]'.
#     :param elements: List of elements, ['Si', 'O', 'Fe'].
# 
#     :returns: Mass fractions.
#     """
# 
#     return [element_mass_fraction(compound, element)
#             for element in elements]
# 
# Path: auxi/tools/chemistry/stoichiometry.py
# class Element(Object):
# class Group:
# class Compound:
# class CompoundVisitor(parsimonious.NodeVisitor):
#     def __init__(self, period, group, atomic_number, symbol, molar_mass):
#     def count(self):
#     def _validate_(self):
#     def __repr__(self):
# def count_with_multiplier(groups, multiplier):
#     def __init__(self, group, multiplier=1, dotted=False):
#     def count(self):
#     def __repr__(self):
#     def __init__(self, group, dottedgroup=None, phase=None):
#     def count(self):
#     def molar_mass(self):
#     def __repr__(self):
#     def visit_compound(self, _, compound):
#     def visit_group(self, _, group):
#     def visit_phase(self, node, _):
#     def visit_dottedgroup(self, _, dottedgroup):
#     def visit_subscriptedgroup(self, _, subscriptedgroup):
#     def visit_subscriptedelement(self, _, subscriptedelement):
#     def visit_element(self, node, _):
#     def visit_number(self, node, _):
#     def generic_visit(self, node, other):
# def parse_compound(string):
# def amount(compound, mass):
# def amounts(masses):
# def amount_fractions(masses):
# def mass(compound, amount):
# def masses(amounts):
# def mass_fractions(amounts):
# def convert_compound(mass, source, target, element):
# def element_mass_fraction(compound, element):
# def element_mass_fractions(compound, elements):
# def elements(compounds):
# def molar_mass(compound=''):
# def stoichiometry_coefficient(compound, element):
# def stoichiometry_coefficients(compound, elements):


# Path: auxi/modelling/process/materials/chem.py
import copy
    import unittest
from os.path import isfile
from auxi.core.objects import Object, NamedObject
from auxi.tools.chemistry.stoichiometry import element_mass_fractions as emf
from auxi.tools.chemistry import stoichiometry as stoich
    from auxi.modelling.process.materials.chem_test \
        import ChemMaterialUnitTester, ChemMaterialPackageUnitTester


    def get_element_mass_dictionary(self):
        """
        Determine the masses of elements in the package and return as a
        dictionary.

        :returns: [kg] A dictionary of element symbols and masses.
        """

        element_symbols = self.material.elements
        element_masses = self.get_element_masses()

        result = {}
        for s, m in zip(element_symbols, element_masses):
            result[s] = m

        return result

    def get_element_mass(self, element):
        """
        Determine the masses of elements in the package.

        :returns: [kg] An array of element masses. The sequence of the elements
          in the result corresponds with the sequence of elements in the
          element list of the material.
        """

        result = [0]
        for compound in self.material.compounds:
            c = self.get_compound_mass(compound)

            f = [c * x for x in emf(compound, [element])]