From 36a5c3ddb070a69a3acb314ced048c6bc2e9f1d3 Mon Sep 17 00:00:00 2001 From: Jonathan Date: Fri, 4 Feb 2022 22:04:51 +0000 Subject: [PATCH 01/18] updated package install method --- .github/workflows/python-publish.yml | 16 ++------------ .gitignore | 4 +++- Dockerfile | 26 +++++----------------- neutronics_material_maker/__init__.py | 14 ++++++++++++ neutronics_material_maker/material.py | 19 ++++++++++------ pyproject.toml | 10 +++++++++ readthedocs.yml | 15 +++++-------- requirments.txt | 3 --- setup.py | 32 --------------------------- 9 files changed, 51 insertions(+), 88 deletions(-) create mode 100644 pyproject.toml delete mode 100644 requirments.txt diff --git a/.github/workflows/python-publish.yml b/.github/workflows/python-publish.yml index c909e16..d187fc5 100644 --- a/.github/workflows/python-publish.yml +++ b/.github/workflows/python-publish.yml @@ -25,27 +25,15 @@ jobs: with: python-version: '3.x' - - name: Autobump version - run: | - # from refs/tags/v1.2.3 get 1.2.3 - VERSION=$(echo $GITHUB_REF | sed 's#.*/v##') - PLACEHOLDER='version="develop"' - VERSION_FILE='setup.py' - # Grep checks that the placeholder is in the file. If grep doesn't find - # the placeholder then it exits with exit code 1 and github actions fails. - grep "$PLACEHOLDER" "$VERSION_FILE" - sed -i "s@$PLACEHOLDER@version=\"${VERSION}\"@g" "$VERSION_FILE" - shell: bash - - name: Install dependencies run: | python -m pip install --upgrade pip - pip install setuptools wheel twine + pip install setuptools wheel build twine - name: Build and publish env: TWINE_USERNAME: __token__ TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }} run: | - python setup.py sdist bdist_wheel + python -m build twine upload dist/* diff --git a/.gitignore b/.gitignore index cddb549..32e3d43 100644 --- a/.gitignore +++ b/.gitignore @@ -49,4 +49,6 @@ new_materials/ .vscode/ -.tox/ \ No newline at end of file +.tox/ + +_version.py diff --git a/Dockerfile b/Dockerfile index 36114f8..c5118ab 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,35 +1,19 @@ # build with the following command # sudo docker build -t neutronics_material_maker . -FROM ubuntu:18.04 +FROM continuumio/miniconda3:4.9.2 -# Updating Ubuntu packages -RUN apt-get update && yes|apt-get upgrade -# Adding wget and bzip2 -RUN apt-get install -y wget bzip2 - -# Anaconda installing -RUN wget https://repo.continuum.io/archive/Anaconda3-2020.02-Linux-x86_64.sh - -RUN bash Anaconda3-2020.02-Linux-x86_64.sh -b - -RUN rm Anaconda3-2020.02-Linux-x86_64.sh - -# Set path to conda -ENV PATH /root/anaconda3/bin:$PATH - -# install openmc from conda involves less sets compared to compiling it from source +# install openmc from conda RUN conda install -c conda-forge openmc - -# install endf nuclear data - -# clone the openmc nuclear data repository RUN apt-get update RUN apt-get install -y git + +# clone the openmc nuclear data repository RUN git clone https://github.com/openmc-dev/data.git +# install endf nuclear data # run script that converts ACE data to hdf5 data RUN python data/convert_nndc71.py --cleanup diff --git a/neutronics_material_maker/__init__.py b/neutronics_material_maker/__init__.py index 3aaddcb..3ec60ad 100644 --- a/neutronics_material_maker/__init__.py +++ b/neutronics_material_maker/__init__.py @@ -1,3 +1,17 @@ + +try: + from importlib.metadata import version, PackageNotFoundError +except (ModuleNotFoundError, ImportError): + from importlib_metadata import version, PackageNotFoundError +try: + __version__ = version("paramak") +except PackageNotFoundError: + from setuptools_scm import get_version + + __version__ = get_version(root="..", relative_to=__file__) + +__all__ = ["__version__"] + from .utils import make_fispact_material from .utils import make_serpent_material from .utils import make_mcnp_material diff --git a/neutronics_material_maker/material.py b/neutronics_material_maker/material.py index 98f3b4d..a301370 100644 --- a/neutronics_material_maker/material.py +++ b/neutronics_material_maker/material.py @@ -9,10 +9,10 @@ import re import warnings from json import JSONEncoder -from typing import Dict, List, Optional, Union +from typing import Dict, List, Optional import asteval -from CoolProp.CoolProp import PropsSI + from neutronics_material_maker import ( NATURAL_ABUNDANCE, @@ -39,10 +39,6 @@ atomic_mass_unit_in_g = 1.660539040e-24 -# Set any custom symbols for use in asteval -asteval_user_symbols = {"PropsSI": PropsSI} - - def _default(self, obj): """monkey-patches json module so that the custom to_json method is used which allows Materials to be json dumped @@ -764,7 +760,16 @@ def _add_density(self, openmc_material): # a density equation is being used elif isinstance(self.density, str): - aeval = asteval.Interpreter(usersyms=asteval_user_symbols) + + if self.density.startswith('PropsSI'): + from CoolProp.CoolProp import PropsSI + + # Set any custom symbols for use in asteval + asteval_user_symbols = {"PropsSI": PropsSI} + + aeval = asteval.Interpreter(usersyms=asteval_user_symbols) + else: + aeval = asteval.Interpreter() if "temperature" in self.density and self.temperature is None: raise ValueError( diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..8135034 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,10 @@ +[build-system] +requires = [ + "setuptools >= 45", + "wheel", + "setuptools_scm[toml] >= 6.2", +] +build-backend = "setuptools.build_meta" + +[tool.setuptools_scm] +write_to = "neutronics_material_maker/_version.py" diff --git a/readthedocs.yml b/readthedocs.yml index 202a672..3cedd87 100644 --- a/readthedocs.yml +++ b/readthedocs.yml @@ -9,21 +9,16 @@ build: python: version: 3.8 + install: + - method: pip + path: . + extra_requirements: + - docs # Build documentation in the docs/ directory with Sphinx sphinx: configuration: docs/source/conf.py -# Optional additional build formats -# formats: -# - pdf - -# this is not needed if using conda environment -# python: -# version: 3.8 -# install: -# - requirements: requirements.txt - # specify conda environment needed for build conda: environment: docs/environment.yml diff --git a/requirments.txt b/requirments.txt deleted file mode 100644 index c1d4e96..0000000 --- a/requirments.txt +++ /dev/null @@ -1,3 +0,0 @@ -asteval==0.9.19 -CoolProp -openmc \ No newline at end of file diff --git a/setup.py b/setup.py index c4c47f9..434e719 100644 --- a/setup.py +++ b/setup.py @@ -1,33 +1 @@ import setuptools - -with open("README.md", "r") as fh: - long_description = fh.read() - -setuptools.setup( - name="neutronics_material_maker", - version="develop", - summary="Package for making material cards for neutronics codes", - author="neutronics_material_maker development team", - author_email="mail@jshimwell.com", - description="A tool for making neutronics material cards for use in OpenMC, MCNP, Serpent, Shift and Fispact", - long_description=long_description, - long_description_content_type="text/markdown", - url="https://github.com/fusion-energy/neutronics_material_maker", - packages=setuptools.find_packages(), - zip_safe=True, - package_dir={"neutronics_material_maker": "neutronics_material_maker"}, - package_data={ - "neutronics_material_maker": [ - "requirements.txt", - "README.md", - "LICENSE.txt", - "data/*.json", - ] - }, - tests_require=["pytest-cov", "pytest-runner"], - install_requires=[ - "coolprop", - "asteval", - # 'openmc' when pip install is available - ], -) From 36f397beb0e9bc3c72232eaf0c3d2bcf3a09e2b3 Mon Sep 17 00:00:00 2001 From: shimwell Date: Fri, 4 Feb 2022 22:05:29 +0000 Subject: [PATCH 02/18] [skip ci] Apply formatting changes --- docs/source/conf.py | 5 +- neutronics_material_maker/__init__.py | 1 - neutronics_material_maker/material.py | 47 +- neutronics_material_maker/utils.py | 611 +++++++++++++++++++------- tests/test_Material.py | 317 +++++-------- tests/test_Material_from_mixture.py | 242 +++++----- tests/test_utils.py | 122 ++--- 7 files changed, 763 insertions(+), 582 deletions(-) diff --git a/docs/source/conf.py b/docs/source/conf.py index d62f974..69d0c81 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -37,10 +37,7 @@ # Add any Sphinx extension module names here, as strings. They can be # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom # ones. -extensions = [ - "sphinx.ext.autodoc", - "sphinx.ext.coverage", - "sphinx.ext.napoleon"] +extensions = ["sphinx.ext.autodoc", "sphinx.ext.coverage", "sphinx.ext.napoleon"] # Add any paths that contain templates here, relative to this directory. templates_path = ["_templates"] diff --git a/neutronics_material_maker/__init__.py b/neutronics_material_maker/__init__.py index 3ec60ad..484fc0b 100644 --- a/neutronics_material_maker/__init__.py +++ b/neutronics_material_maker/__init__.py @@ -1,4 +1,3 @@ - try: from importlib.metadata import version, PackageNotFoundError except (ModuleNotFoundError, ImportError): diff --git a/neutronics_material_maker/material.py b/neutronics_material_maker/material.py index a301370..fb4e7ab 100644 --- a/neutronics_material_maker/material.py +++ b/neutronics_material_maker/material.py @@ -39,6 +39,7 @@ atomic_mass_unit_in_g = 1.660539040e-24 + def _default(self, obj): """monkey-patches json module so that the custom to_json method is used which allows Materials to be json dumped @@ -312,11 +313,9 @@ def packing_fraction(self): @packing_fraction.setter def packing_fraction(self, value): if not isinstance(value, (float, int)): - raise ValueError( - "Material.packing_fraction must be a float or int") + raise ValueError("Material.packing_fraction must be a float or int") if value < 0.0: - raise ValueError( - "Material.packing_fraction must be greater than 0") + raise ValueError("Material.packing_fraction must be greater than 0") if value > 1.0: raise ValueError("Material.packing_fraction must be less than 1.") self._packing_fraction = float(value) @@ -350,8 +349,7 @@ def chemical_equation(self, value): if isinstance(value, str) or value is None: self._chemical_equation = value else: - raise ValueError( - "Material.chemical_equation must be a string e.g. 'H2O'") + raise ValueError("Material.chemical_equation must be a string e.g. 'H2O'") @property def isotopes(self) -> dict: @@ -399,8 +397,7 @@ def percent_type(self, value) -> float: if value in ["ao", "wo", None]: self._percent_type = value else: - raise ValueError( - "Material.percent_type only accepts 'ao' or 'wo' types") + raise ValueError("Material.percent_type only accepts 'ao' or 'wo' types") @property def enrichment_type(self) -> float: @@ -427,8 +424,7 @@ def atoms_per_unit_cell(self): def atoms_per_unit_cell(self, value): if value is not None: if value < 0.0: - raise ValueError( - "Material.atoms_per_unit_cell must be greater than 0") + raise ValueError("Material.atoms_per_unit_cell must be greater than 0") self._atoms_per_unit_cell = value @property @@ -464,8 +460,7 @@ def temperature(self): def temperature(self, value): if value is not None: if value < 0.0: - raise ValueError( - "Material.temperature must be greater than 0 Kelvin") + raise ValueError("Material.temperature must be greater than 0 Kelvin") self._temperature = value @property @@ -486,8 +481,7 @@ def density(self, value): self._density = value elif isinstance(value, (int, float)): if value < 0: - raise ValueError( - f"Material.density should be above 0. Not {value}") + raise ValueError(f"Material.density should be above 0. Not {value}") self._density = float(value) @property @@ -504,8 +498,7 @@ def enrichment(self): def enrichment(self, value): if value is not None: if value < 0 or value > 100: - raise ValueError( - "Material.enrichment must be between 0 and 100") + raise ValueError("Material.enrichment must be between 0 and 100") self._enrichment = value @property @@ -761,7 +754,7 @@ def _add_density(self, openmc_material): # a density equation is being used elif isinstance(self.density, str): - if self.density.startswith('PropsSI'): + if self.density.startswith("PropsSI"): from CoolProp.CoolProp import PropsSI # Set any custom symbols for use in asteval @@ -777,8 +770,7 @@ def _add_density(self, openmc_material): ) if "pressure" in self.density and self.pressure is None: - raise ValueError( - "Material.pressure is needed to calculate the density") + raise ValueError("Material.pressure is needed to calculate the density") # Potentially used in the eval part aeval.symtable["temperature"] = self.temperature @@ -790,10 +782,7 @@ def _add_density(self, openmc_material): raise aeval.error[0].exc(aeval.error[0].msg) if density is None: - raise ValueError( - "Density value of ", - self.name, - " can not be found") + raise ValueError("Density value of ", self.name, " can not be found") else: self.density = density @@ -803,8 +792,8 @@ def _add_density(self, openmc_material): ): molar_mass = ( - self._get_atoms_in_crystal() * - openmc_material.average_molar_mass) + self._get_atoms_in_crystal() * openmc_material.average_molar_mass + ) mass = self.atoms_per_unit_cell * molar_mass * atomic_mass_unit_in_g @@ -826,10 +815,7 @@ def _add_density(self, openmc_material): def _get_atoms_in_crystal(self): """Finds the number of atoms in the crystal lactic""" - tokens = [ - a for a in re.split( - r"([A-Z][a-z]*)", - self.chemical_equation) if a] + tokens = [a for a in re.split(r"([A-Z][a-z]*)", self.chemical_equation) if a] list_of_fractions = [] @@ -864,8 +850,7 @@ def from_library(name: str, **kwargs): # TODO allow discreat libraries to be searched library: List('str') if name not in material_dict.keys(): - closest_match = difflib.get_close_matches( - name, material_dict.keys()) + closest_match = difflib.get_close_matches(name, material_dict.keys()) msg = f"name of {name} was not found in the internal library." if len(closest_match) > 0: msg = msg + f" Did you mean {closest_match}?" diff --git a/neutronics_material_maker/utils.py b/neutronics_material_maker/utils.py index 2aaabb9..7c1e1d8 100644 --- a/neutronics_material_maker/utils.py +++ b/neutronics_material_maker/utils.py @@ -12,132 +12,423 @@ except BaseException: warnings.warn( "OpenMC not found, .openmc_material, .serpent_material," - " .mcnp_material, .fispact_material .shif_materials not avaiable") + " .mcnp_material, .fispact_material .shif_materials not avaiable" + ) # from https://github.com/openmc-dev/openmc/blob/develop/openmc/data/data.py # remove when pip install openmc via PyPi is available NATURAL_ABUNDANCE = { - 'H1': 0.99984426, 'H2': 0.00015574, 'He3': 0.000002, - 'He4': 0.999998, 'Li6': 0.07589, 'Li7': 0.92411, - 'Be9': 1.0, 'B10': 0.1982, 'B11': 0.8018, - 'C12': 0.988922, 'C13': 0.011078, 'N14': 0.996337, - 'N15': 0.003663, 'O16': 0.9976206, 'O17': 0.000379, - 'O18': 0.0020004, 'F19': 1.0, 'Ne20': 0.9048, - 'Ne21': 0.0027, 'Ne22': 0.0925, 'Na23': 1.0, - 'Mg24': 0.78951, 'Mg25': 0.1002, 'Mg26': 0.11029, - 'Al27': 1.0, 'Si28': 0.9222968, 'Si29': 0.0468316, - 'Si30': 0.0308716, 'P31': 1.0, 'S32': 0.9504074, - 'S33': 0.0074869, 'S34': 0.0419599, 'S36': 0.0001458, - 'Cl35': 0.757647, 'Cl37': 0.242353, 'Ar36': 0.003336, - 'Ar38': 0.000629, 'Ar40': 0.996035, 'K39': 0.932581, - 'K40': 0.000117, 'K41': 0.067302, 'Ca40': 0.96941, - 'Ca42': 0.00647, 'Ca43': 0.00135, 'Ca44': 0.02086, - 'Ca46': 0.00004, 'Ca48': 0.00187, 'Sc45': 1.0, - 'Ti46': 0.0825, 'Ti47': 0.0744, 'Ti48': 0.7372, - 'Ti49': 0.0541, 'Ti50': 0.0518, 'V50': 0.0025, - 'V51': 0.9975, 'Cr50': 0.04345, 'Cr52': 0.83789, - 'Cr53': 0.09501, 'Cr54': 0.02365, 'Mn55': 1.0, - 'Fe54': 0.05845, 'Fe56': 0.91754, 'Fe57': 0.02119, - 'Fe58': 0.00282, 'Co59': 1.0, 'Ni58': 0.680769, - 'Ni60': 0.262231, 'Ni61': 0.011399, 'Ni62': 0.036345, - 'Ni64': 0.009256, 'Cu63': 0.6915, 'Cu65': 0.3085, - 'Zn64': 0.4917, 'Zn66': 0.2773, 'Zn67': 0.0404, - 'Zn68': 0.1845, 'Zn70': 0.0061, 'Ga69': 0.60108, - 'Ga71': 0.39892, 'Ge70': 0.2052, 'Ge72': 0.2745, - 'Ge73': 0.0776, 'Ge74': 0.3652, 'Ge76': 0.0775, - 'As75': 1.0, 'Se74': 0.0086, 'Se76': 0.0923, - 'Se77': 0.076, 'Se78': 0.2369, 'Se80': 0.498, - 'Se82': 0.0882, 'Br79': 0.50686, 'Br81': 0.49314, - 'Kr78': 0.00355, 'Kr80': 0.02286, 'Kr82': 0.11593, - 'Kr83': 0.115, 'Kr84': 0.56987, 'Kr86': 0.17279, - 'Rb85': 0.7217, 'Rb87': 0.2783, 'Sr84': 0.0056, - 'Sr86': 0.0986, 'Sr87': 0.07, 'Sr88': 0.8258, - 'Y89': 1.0, 'Zr90': 0.5145, 'Zr91': 0.1122, - 'Zr92': 0.1715, 'Zr94': 0.1738, 'Zr96': 0.028, - 'Nb93': 1.0, 'Mo92': 0.14649, 'Mo94': 0.09187, - 'Mo95': 0.15873, 'Mo96': 0.16673, 'Mo97': 0.09582, - 'Mo98': 0.24292, 'Mo100': 0.09744, 'Ru96': 0.0554, - 'Ru98': 0.0187, 'Ru99': 0.1276, 'Ru100': 0.126, - 'Ru101': 0.1706, 'Ru102': 0.3155, 'Ru104': 0.1862, - 'Rh103': 1.0, 'Pd102': 0.0102, 'Pd104': 0.1114, - 'Pd105': 0.2233, 'Pd106': 0.2733, 'Pd108': 0.2646, - 'Pd110': 0.1172, 'Ag107': 0.51839, 'Ag109': 0.48161, - 'Cd106': 0.01245, 'Cd108': 0.00888, 'Cd110': 0.1247, - 'Cd111': 0.12795, 'Cd112': 0.24109, 'Cd113': 0.12227, - 'Cd114': 0.28754, 'Cd116': 0.07512, 'In113': 0.04281, - 'In115': 0.95719, 'Sn112': 0.0097, 'Sn114': 0.0066, - 'Sn115': 0.0034, 'Sn116': 0.1454, 'Sn117': 0.0768, - 'Sn118': 0.2422, 'Sn119': 0.0859, 'Sn120': 0.3258, - 'Sn122': 0.0463, 'Sn124': 0.0579, 'Sb121': 0.5721, - 'Sb123': 0.4279, 'Te120': 0.0009, 'Te122': 0.0255, - 'Te123': 0.0089, 'Te124': 0.0474, 'Te125': 0.0707, - 'Te126': 0.1884, 'Te128': 0.3174, 'Te130': 0.3408, - 'I127': 1.0, 'Xe124': 0.00095, 'Xe126': 0.00089, - 'Xe128': 0.0191, 'Xe129': 0.26401, 'Xe130': 0.04071, - 'Xe131': 0.21232, 'Xe132': 0.26909, 'Xe134': 0.10436, - 'Xe136': 0.08857, 'Cs133': 1.0, 'Ba130': 0.0011, - 'Ba132': 0.001, 'Ba134': 0.0242, 'Ba135': 0.0659, - 'Ba136': 0.0785, 'Ba137': 0.1123, 'Ba138': 0.717, - 'La138': 0.0008881, 'La139': 0.9991119, 'Ce136': 0.00186, - 'Ce138': 0.00251, 'Ce140': 0.88449, 'Ce142': 0.11114, - 'Pr141': 1.0, 'Nd142': 0.27153, 'Nd143': 0.12173, - 'Nd144': 0.23798, 'Nd145': 0.08293, 'Nd146': 0.17189, - 'Nd148': 0.05756, 'Nd150': 0.05638, 'Sm144': 0.0308, - 'Sm147': 0.15, 'Sm148': 0.1125, 'Sm149': 0.1382, - 'Sm150': 0.0737, 'Sm152': 0.2674, 'Sm154': 0.2274, - 'Eu151': 0.4781, 'Eu153': 0.5219, 'Gd152': 0.002, - 'Gd154': 0.0218, 'Gd155': 0.148, 'Gd156': 0.2047, - 'Gd157': 0.1565, 'Gd158': 0.2484, 'Gd160': 0.2186, - 'Tb159': 1.0, 'Dy156': 0.00056, 'Dy158': 0.00095, - 'Dy160': 0.02329, 'Dy161': 0.18889, 'Dy162': 0.25475, - 'Dy163': 0.24896, 'Dy164': 0.2826, 'Ho165': 1.0, - 'Er162': 0.00139, 'Er164': 0.01601, 'Er166': 0.33503, - 'Er167': 0.22869, 'Er168': 0.26978, 'Er170': 0.1491, - 'Tm169': 1.0, 'Yb168': 0.00123, 'Yb170': 0.02982, - 'Yb171': 0.14086, 'Yb172': 0.21686, 'Yb173': 0.16103, - 'Yb174': 0.32025, 'Yb176': 0.12995, 'Lu175': 0.97401, - 'Lu176': 0.02599, 'Hf174': 0.0016, 'Hf176': 0.0526, - 'Hf177': 0.186, 'Hf178': 0.2728, 'Hf179': 0.1362, - 'Hf180': 0.3508, 'Ta180': 0.0001201, 'Ta181': 0.9998799, - 'W180': 0.0012, 'W182': 0.265, 'W183': 0.1431, - 'W184': 0.3064, 'W186': 0.2843, 'Re185': 0.374, - 'Re187': 0.626, 'Os184': 0.0002, 'Os186': 0.0159, - 'Os187': 0.0196, 'Os188': 0.1324, 'Os189': 0.1615, - 'Os190': 0.2626, 'Os192': 0.4078, 'Ir191': 0.373, - 'Ir193': 0.627, 'Pt190': 0.00012, 'Pt192': 0.00782, - 'Pt194': 0.32864, 'Pt195': 0.33775, 'Pt196': 0.25211, - 'Pt198': 0.07356, 'Au197': 1.0, 'Hg196': 0.0015, - 'Hg198': 0.1004, 'Hg199': 0.1694, 'Hg200': 0.2314, - 'Hg201': 0.1317, 'Hg202': 0.2974, 'Hg204': 0.0682, - 'Tl203': 0.29524, 'Tl205': 0.70476, 'Pb204': 0.014, - 'Pb206': 0.241, 'Pb207': 0.221, 'Pb208': 0.524, - 'Bi209': 1.0, 'Th230': 0.0002, 'Th232': 0.9998, - 'Pa231': 1.0, 'U234': 0.000054, 'U235': 0.007204, - 'U238': 0.992742 + "H1": 0.99984426, + "H2": 0.00015574, + "He3": 0.000002, + "He4": 0.999998, + "Li6": 0.07589, + "Li7": 0.92411, + "Be9": 1.0, + "B10": 0.1982, + "B11": 0.8018, + "C12": 0.988922, + "C13": 0.011078, + "N14": 0.996337, + "N15": 0.003663, + "O16": 0.9976206, + "O17": 0.000379, + "O18": 0.0020004, + "F19": 1.0, + "Ne20": 0.9048, + "Ne21": 0.0027, + "Ne22": 0.0925, + "Na23": 1.0, + "Mg24": 0.78951, + "Mg25": 0.1002, + "Mg26": 0.11029, + "Al27": 1.0, + "Si28": 0.9222968, + "Si29": 0.0468316, + "Si30": 0.0308716, + "P31": 1.0, + "S32": 0.9504074, + "S33": 0.0074869, + "S34": 0.0419599, + "S36": 0.0001458, + "Cl35": 0.757647, + "Cl37": 0.242353, + "Ar36": 0.003336, + "Ar38": 0.000629, + "Ar40": 0.996035, + "K39": 0.932581, + "K40": 0.000117, + "K41": 0.067302, + "Ca40": 0.96941, + "Ca42": 0.00647, + "Ca43": 0.00135, + "Ca44": 0.02086, + "Ca46": 0.00004, + "Ca48": 0.00187, + "Sc45": 1.0, + "Ti46": 0.0825, + "Ti47": 0.0744, + "Ti48": 0.7372, + "Ti49": 0.0541, + "Ti50": 0.0518, + "V50": 0.0025, + "V51": 0.9975, + "Cr50": 0.04345, + "Cr52": 0.83789, + "Cr53": 0.09501, + "Cr54": 0.02365, + "Mn55": 1.0, + "Fe54": 0.05845, + "Fe56": 0.91754, + "Fe57": 0.02119, + "Fe58": 0.00282, + "Co59": 1.0, + "Ni58": 0.680769, + "Ni60": 0.262231, + "Ni61": 0.011399, + "Ni62": 0.036345, + "Ni64": 0.009256, + "Cu63": 0.6915, + "Cu65": 0.3085, + "Zn64": 0.4917, + "Zn66": 0.2773, + "Zn67": 0.0404, + "Zn68": 0.1845, + "Zn70": 0.0061, + "Ga69": 0.60108, + "Ga71": 0.39892, + "Ge70": 0.2052, + "Ge72": 0.2745, + "Ge73": 0.0776, + "Ge74": 0.3652, + "Ge76": 0.0775, + "As75": 1.0, + "Se74": 0.0086, + "Se76": 0.0923, + "Se77": 0.076, + "Se78": 0.2369, + "Se80": 0.498, + "Se82": 0.0882, + "Br79": 0.50686, + "Br81": 0.49314, + "Kr78": 0.00355, + "Kr80": 0.02286, + "Kr82": 0.11593, + "Kr83": 0.115, + "Kr84": 0.56987, + "Kr86": 0.17279, + "Rb85": 0.7217, + "Rb87": 0.2783, + "Sr84": 0.0056, + "Sr86": 0.0986, + "Sr87": 0.07, + "Sr88": 0.8258, + "Y89": 1.0, + "Zr90": 0.5145, + "Zr91": 0.1122, + "Zr92": 0.1715, + "Zr94": 0.1738, + "Zr96": 0.028, + "Nb93": 1.0, + "Mo92": 0.14649, + "Mo94": 0.09187, + "Mo95": 0.15873, + "Mo96": 0.16673, + "Mo97": 0.09582, + "Mo98": 0.24292, + "Mo100": 0.09744, + "Ru96": 0.0554, + "Ru98": 0.0187, + "Ru99": 0.1276, + "Ru100": 0.126, + "Ru101": 0.1706, + "Ru102": 0.3155, + "Ru104": 0.1862, + "Rh103": 1.0, + "Pd102": 0.0102, + "Pd104": 0.1114, + "Pd105": 0.2233, + "Pd106": 0.2733, + "Pd108": 0.2646, + "Pd110": 0.1172, + "Ag107": 0.51839, + "Ag109": 0.48161, + "Cd106": 0.01245, + "Cd108": 0.00888, + "Cd110": 0.1247, + "Cd111": 0.12795, + "Cd112": 0.24109, + "Cd113": 0.12227, + "Cd114": 0.28754, + "Cd116": 0.07512, + "In113": 0.04281, + "In115": 0.95719, + "Sn112": 0.0097, + "Sn114": 0.0066, + "Sn115": 0.0034, + "Sn116": 0.1454, + "Sn117": 0.0768, + "Sn118": 0.2422, + "Sn119": 0.0859, + "Sn120": 0.3258, + "Sn122": 0.0463, + "Sn124": 0.0579, + "Sb121": 0.5721, + "Sb123": 0.4279, + "Te120": 0.0009, + "Te122": 0.0255, + "Te123": 0.0089, + "Te124": 0.0474, + "Te125": 0.0707, + "Te126": 0.1884, + "Te128": 0.3174, + "Te130": 0.3408, + "I127": 1.0, + "Xe124": 0.00095, + "Xe126": 0.00089, + "Xe128": 0.0191, + "Xe129": 0.26401, + "Xe130": 0.04071, + "Xe131": 0.21232, + "Xe132": 0.26909, + "Xe134": 0.10436, + "Xe136": 0.08857, + "Cs133": 1.0, + "Ba130": 0.0011, + "Ba132": 0.001, + "Ba134": 0.0242, + "Ba135": 0.0659, + "Ba136": 0.0785, + "Ba137": 0.1123, + "Ba138": 0.717, + "La138": 0.0008881, + "La139": 0.9991119, + "Ce136": 0.00186, + "Ce138": 0.00251, + "Ce140": 0.88449, + "Ce142": 0.11114, + "Pr141": 1.0, + "Nd142": 0.27153, + "Nd143": 0.12173, + "Nd144": 0.23798, + "Nd145": 0.08293, + "Nd146": 0.17189, + "Nd148": 0.05756, + "Nd150": 0.05638, + "Sm144": 0.0308, + "Sm147": 0.15, + "Sm148": 0.1125, + "Sm149": 0.1382, + "Sm150": 0.0737, + "Sm152": 0.2674, + "Sm154": 0.2274, + "Eu151": 0.4781, + "Eu153": 0.5219, + "Gd152": 0.002, + "Gd154": 0.0218, + "Gd155": 0.148, + "Gd156": 0.2047, + "Gd157": 0.1565, + "Gd158": 0.2484, + "Gd160": 0.2186, + "Tb159": 1.0, + "Dy156": 0.00056, + "Dy158": 0.00095, + "Dy160": 0.02329, + "Dy161": 0.18889, + "Dy162": 0.25475, + "Dy163": 0.24896, + "Dy164": 0.2826, + "Ho165": 1.0, + "Er162": 0.00139, + "Er164": 0.01601, + "Er166": 0.33503, + "Er167": 0.22869, + "Er168": 0.26978, + "Er170": 0.1491, + "Tm169": 1.0, + "Yb168": 0.00123, + "Yb170": 0.02982, + "Yb171": 0.14086, + "Yb172": 0.21686, + "Yb173": 0.16103, + "Yb174": 0.32025, + "Yb176": 0.12995, + "Lu175": 0.97401, + "Lu176": 0.02599, + "Hf174": 0.0016, + "Hf176": 0.0526, + "Hf177": 0.186, + "Hf178": 0.2728, + "Hf179": 0.1362, + "Hf180": 0.3508, + "Ta180": 0.0001201, + "Ta181": 0.9998799, + "W180": 0.0012, + "W182": 0.265, + "W183": 0.1431, + "W184": 0.3064, + "W186": 0.2843, + "Re185": 0.374, + "Re187": 0.626, + "Os184": 0.0002, + "Os186": 0.0159, + "Os187": 0.0196, + "Os188": 0.1324, + "Os189": 0.1615, + "Os190": 0.2626, + "Os192": 0.4078, + "Ir191": 0.373, + "Ir193": 0.627, + "Pt190": 0.00012, + "Pt192": 0.00782, + "Pt194": 0.32864, + "Pt195": 0.33775, + "Pt196": 0.25211, + "Pt198": 0.07356, + "Au197": 1.0, + "Hg196": 0.0015, + "Hg198": 0.1004, + "Hg199": 0.1694, + "Hg200": 0.2314, + "Hg201": 0.1317, + "Hg202": 0.2974, + "Hg204": 0.0682, + "Tl203": 0.29524, + "Tl205": 0.70476, + "Pb204": 0.014, + "Pb206": 0.241, + "Pb207": 0.221, + "Pb208": 0.524, + "Bi209": 1.0, + "Th230": 0.0002, + "Th232": 0.9998, + "Pa231": 1.0, + "U234": 0.000054, + "U235": 0.007204, + "U238": 0.992742, } ATOMIC_SYMBOL = { - 0: 'n', 1: 'H', 2: 'He', 3: 'Li', 4: 'Be', 5: 'B', 6: 'C', - 7: 'N', 8: 'O', 9: 'F', 10: 'Ne', 11: 'Na', 12: 'Mg', 13: 'Al', - 14: 'Si', 15: 'P', 16: 'S', 17: 'Cl', 18: 'Ar', 19: 'K', - 20: 'Ca', 21: 'Sc', 22: 'Ti', 23: 'V', 24: 'Cr', 25: 'Mn', - 26: 'Fe', 27: 'Co', 28: 'Ni', 29: 'Cu', 30: 'Zn', 31: 'Ga', - 32: 'Ge', 33: 'As', 34: 'Se', 35: 'Br', 36: 'Kr', 37: 'Rb', - 38: 'Sr', 39: 'Y', 40: 'Zr', 41: 'Nb', 42: 'Mo', 43: 'Tc', - 44: 'Ru', 45: 'Rh', 46: 'Pd', 47: 'Ag', 48: 'Cd', 49: 'In', - 50: 'Sn', 51: 'Sb', 52: 'Te', 53: 'I', 54: 'Xe', 55: 'Cs', - 56: 'Ba', 57: 'La', 58: 'Ce', 59: 'Pr', 60: 'Nd', 61: 'Pm', - 62: 'Sm', 63: 'Eu', 64: 'Gd', 65: 'Tb', 66: 'Dy', 67: 'Ho', - 68: 'Er', 69: 'Tm', 70: 'Yb', 71: 'Lu', 72: 'Hf', 73: 'Ta', - 74: 'W', 75: 'Re', 76: 'Os', 77: 'Ir', 78: 'Pt', 79: 'Au', - 80: 'Hg', 81: 'Tl', 82: 'Pb', 83: 'Bi', 84: 'Po', 85: 'At', - 86: 'Rn', 87: 'Fr', 88: 'Ra', 89: 'Ac', 90: 'Th', 91: 'Pa', - 92: 'U', 93: 'Np', 94: 'Pu', 95: 'Am', 96: 'Cm', 97: 'Bk', - 98: 'Cf', 99: 'Es', 100: 'Fm', 101: 'Md', 102: 'No', - 103: 'Lr', 104: 'Rf', 105: 'Db', 106: 'Sg', 107: 'Bh', - 108: 'Hs', 109: 'Mt', 110: 'Ds', 111: 'Rg', 112: 'Cn', - 113: 'Nh', 114: 'Fl', 115: 'Mc', 116: 'Lv', 117: 'Ts', - 118: 'Og' + 0: "n", + 1: "H", + 2: "He", + 3: "Li", + 4: "Be", + 5: "B", + 6: "C", + 7: "N", + 8: "O", + 9: "F", + 10: "Ne", + 11: "Na", + 12: "Mg", + 13: "Al", + 14: "Si", + 15: "P", + 16: "S", + 17: "Cl", + 18: "Ar", + 19: "K", + 20: "Ca", + 21: "Sc", + 22: "Ti", + 23: "V", + 24: "Cr", + 25: "Mn", + 26: "Fe", + 27: "Co", + 28: "Ni", + 29: "Cu", + 30: "Zn", + 31: "Ga", + 32: "Ge", + 33: "As", + 34: "Se", + 35: "Br", + 36: "Kr", + 37: "Rb", + 38: "Sr", + 39: "Y", + 40: "Zr", + 41: "Nb", + 42: "Mo", + 43: "Tc", + 44: "Ru", + 45: "Rh", + 46: "Pd", + 47: "Ag", + 48: "Cd", + 49: "In", + 50: "Sn", + 51: "Sb", + 52: "Te", + 53: "I", + 54: "Xe", + 55: "Cs", + 56: "Ba", + 57: "La", + 58: "Ce", + 59: "Pr", + 60: "Nd", + 61: "Pm", + 62: "Sm", + 63: "Eu", + 64: "Gd", + 65: "Tb", + 66: "Dy", + 67: "Ho", + 68: "Er", + 69: "Tm", + 70: "Yb", + 71: "Lu", + 72: "Hf", + 73: "Ta", + 74: "W", + 75: "Re", + 76: "Os", + 77: "Ir", + 78: "Pt", + 79: "Au", + 80: "Hg", + 81: "Tl", + 82: "Pb", + 83: "Bi", + 84: "Po", + 85: "At", + 86: "Rn", + 87: "Fr", + 88: "Ra", + 89: "Ac", + 90: "Th", + 91: "Pa", + 92: "U", + 93: "Np", + 94: "Pu", + 95: "Am", + 96: "Cm", + 97: "Bk", + 98: "Cf", + 99: "Es", + 100: "Fm", + 101: "Md", + 102: "No", + 103: "Lr", + 104: "Rf", + 105: "Db", + 106: "Sg", + 107: "Bh", + 108: "Hs", + 109: "Mt", + 110: "Ds", + 111: "Rg", + 112: "Cn", + 113: "Nh", + 114: "Fl", + 115: "Mc", + 116: "Lv", + 117: "Ts", + 118: "Og", } @@ -146,26 +437,29 @@ def check_add_additional_end_lines(value): classes are correctly formatted""" if value is not None: - string_codes = ['mcnp', 'serpent', 'shift', 'fispact'] + string_codes = ["mcnp", "serpent", "shift", "fispact"] if not isinstance(value, dict): - raise ValueError( - 'Material.additional_end_lines should be a dictionary') + raise ValueError("Material.additional_end_lines should be a dictionary") for key, entries in value.items(): if key not in string_codes: - msg = (f'Material.additional_end_lines should be a dictionary ' - 'where the keys are the name of the neutronics ' - 'code. Acceptable values are {string_codes}') + msg = ( + f"Material.additional_end_lines should be a dictionary " + "where the keys are the name of the neutronics " + "code. Acceptable values are {string_codes}" + ) raise ValueError(msg) if not isinstance(entries, list): raise ValueError( - 'Material.additional_end_lines should be a dictionary ' - 'where the value of each dictionary entry is a list') + "Material.additional_end_lines should be a dictionary " + "where the value of each dictionary entry is a list" + ) for entry in entries: if not isinstance(entry, str): raise ValueError( - 'Material.additional_end_lines should be a dictionary ' - 'where the value of each dictionary entry is a list ' - 'of strings') + "Material.additional_end_lines should be a dictionary " + "where the value of each dictionary entry is a list " + "of strings" + ) return value @@ -207,7 +501,7 @@ def make_fispact_material(mat) -> str: atoms = mat.volume_in_cm3 * atoms_cm3 mat_card.append(isotope + " " + "{:.12E}".format(atoms)) - mat_card = mat_card + add_additional_end_lines('fispact', mat) + mat_card = mat_card + add_additional_end_lines("fispact", mat) return "\n".join(mat_card) @@ -221,14 +515,14 @@ def make_serpent_material(mat) -> str: zaid_suffix = mat.zaid_suffix if mat.name is None: - name = '' + name = "" else: name = mat.name mat_card = [f"mat {name} {mat.openmc_material.get_mass_density()}"] if mat.temperature_to_neutronics_code is True: if mat.temperature is not None: - mat_card[0] = mat_card[0] + f' tmp {mat.temperature}' + mat_card[0] = mat_card[0] + f" tmp {mat.temperature}" # should check if percent type is 'ao' or 'wo' for isotope in mat.openmc_material.nuclides: @@ -244,7 +538,7 @@ def make_serpent_material(mat) -> str: + f"{isotope[1]:.{mat.decimal_places}e}" ) - mat_card = mat_card + add_additional_end_lines('serpent', mat) + mat_card = mat_card + add_additional_end_lines("serpent", mat) return "\n".join(mat_card) @@ -263,7 +557,7 @@ def make_mcnp_material(mat) -> str: zaid_suffix = mat.zaid_suffix if mat.name is None: - name = '' + name = "" else: name = mat.name @@ -295,9 +589,9 @@ def make_mcnp_material(mat) -> str: mat_card.append(start + rest) - mat_card = mat_card + add_additional_end_lines('mcnp', mat) + mat_card = mat_card + add_additional_end_lines("mcnp", mat) - return "\n".join(mat_card) + '\n' + return "\n".join(mat_card) + "\n" def make_shift_material(mat) -> str: @@ -318,17 +612,17 @@ def make_shift_material(mat) -> str: + "matid %s\n" % mat.material_id + "tmp %s" % mat.temperature ] - zaid = 'zaid' - nd_ = 'nd' + zaid = "zaid" + nd_ = "nd" # shift units in atoms / barn-cm for nuclide, atom_dens in mat.openmc_material.get_nuclide_atom_densities().items(): - zaid += ' ' + isotope_to_zaid(nuclide) - nd_ += ' ' + f"{atom_dens[1]:.{mat.decimal_places}e}" + zaid += " " + isotope_to_zaid(nuclide) + nd_ += " " + f"{atom_dens[1]:.{mat.decimal_places}e}" mat_card.extend([zaid, nd_]) - mat_card = mat_card + add_additional_end_lines('shift', mat) + mat_card = mat_card + add_additional_end_lines("shift", mat) return "\n".join(mat_card) @@ -351,14 +645,14 @@ def zaid_to_isotope(zaid: str) -> str: def AddMaterialFromDir(directory: str, verbose: bool = True, recursive=True): """Add materials to the internal library from a directory of json files""" if verbose is True: - print('searching directory', directory) + print("searching directory", directory) if recursive: filelist = Path(directory).rglob("*.json") else: filelist = Path(directory).glob("*.json") for filename in filelist: if verbose is True: - print(f'loading {filename}') + print(f"loading {filename}") AddMaterialFromFile(filename, verbose) @@ -369,7 +663,7 @@ def AddMaterialFromFile(filename: str, verbose: Optional[bool] = True) -> None: with open(filename, "r") as f: new_data = json.load(f) if verbose: - print('Added material', list(new_data.keys())) + print("Added material", list(new_data.keys())) material_dict.update(new_data) @@ -378,7 +672,7 @@ def AvailableMaterials() -> dict: return material_dict -def SaveMaterialsToFile(filename: str, materials: list, format='json') -> str: +def SaveMaterialsToFile(filename: str, materials: list, format="json") -> str: """Saves a list of materials to a json file. Useful for saving as a library for future use. @@ -390,27 +684,30 @@ def SaveMaterialsToFile(filename: str, materials: list, format='json') -> str: str: the filename of the json file """ - if format == 'json': - with open(filename, 'w') as outfile: - json.dump({mat.name: mat.to_json()[mat.name] - for mat in materials}, outfile, indent=4) + if format == "json": + with open(filename, "w") as outfile: + json.dump( + {mat.name: mat.to_json()[mat.name] for mat in materials}, + outfile, + indent=4, + ) return filename - all_materials = '' + all_materials = "" for mat in materials: - if format == 'mcnp': - all_materials += 'c\nc\nc\n' + mat.mcnp_material + if format == "mcnp": + all_materials += "c\nc\nc\n" + mat.mcnp_material - if format == 'serpent': + if format == "serpent": all_materials += mat.serpent_material - if format == 'shift': + if format == "shift": all_materials += mat.shift_material - if format == 'fispact': + if format == "fispact": all_materials += mat.shift_material - with open(filename, 'w') as outfile: + with open(filename, "w") as outfile: outfile.write(all_materials) return filename diff --git a/tests/test_Material.py b/tests/test_Material.py index 5f1026c..1af5298 100644 --- a/tests/test_Material.py +++ b/tests/test_Material.py @@ -11,15 +11,11 @@ class test_object_properties(unittest.TestCase): - def test_error_raised_when_enrichment_and_enrichment_target(self): - def error_raised_correctly(): test_material = nmm.Material.from_library( - name="WC", - enrichment=90, - enrichment_target=None + name="WC", enrichment=90, enrichment_target=None ) test_material.openmc_material @@ -30,8 +26,7 @@ def test_temperature_to_neutronics_code_openmc(self): selectivly propagated to the openmc_material and that the density remains unchanged""" - test_mat = nmm.Material.from_library( - "FLiBe", temperature=80, pressure=1) + test_mat = nmm.Material.from_library("FLiBe", temperature=80, pressure=1) assert test_mat.temperature == 80 assert test_mat.openmc_material.temperature == 80 @@ -40,7 +35,8 @@ def test_temperature_to_neutronics_code_openmc(self): name="FLiBe", temperature=80, pressure=1, - temperature_to_neutronics_code=False) + temperature_to_neutronics_code=False, + ) assert test_mat_2.temperature == 80 assert test_mat_2.openmc_material.temperature is None @@ -51,30 +47,26 @@ def test_temperature_to_neutronics_code_serpent(self): selectivly propagated to the serpent_material and that the density remains unchanged""" - test_mat = nmm.Material.from_library( - name="FLiBe", - temperature=180, - pressure=2) + test_mat = nmm.Material.from_library(name="FLiBe", temperature=180, pressure=2) assert test_mat.temperature == 180 assert test_mat.openmc_material.temperature == 180 - assert test_mat.serpent_material.split('\n')[0].endswith(' tmp 180') + assert test_mat.serpent_material.split("\n")[0].endswith(" tmp 180") test_mat_2 = nmm.Material.from_library( name="FLiBe", temperature=180, pressure=1, - temperature_to_neutronics_code=False) + temperature_to_neutronics_code=False, + ) assert test_mat_2.temperature == 180 assert test_mat_2.openmc_material.temperature is None - assert test_mat_2.serpent_material.split( - '\n')[0].endswith(' tmp 180') is False + assert test_mat_2.serpent_material.split("\n")[0].endswith(" tmp 180") is False assert test_mat.openmc_material.density == test_mat_2.openmc_material.density def test_density_of_material_is_set_from_equation(self): - test_mat = nmm.Material.from_library( - "FLiBe", temperature=80, pressure=1) + test_mat = nmm.Material.from_library("FLiBe", temperature=80, pressure=1) assert test_mat.density is not None def test_density_of_material_is_set_from_crystal(self): @@ -159,20 +151,18 @@ def test_fispact_material(self): dict_of_fispact_mats = {} for entry in line_by_line_material: isotope_and_fraction = entry.split() - dict_of_fispact_mats[isotope_and_fraction[0] - ] = float(isotope_and_fraction[1]) - - assert dict_of_fispact_mats['Li6'] == pytest.approx(3.537400925715E+21) - assert dict_of_fispact_mats['Li7'] == pytest.approx(4.307481314353E+22) - assert dict_of_fispact_mats['Si28'] == pytest.approx( - 1.074757396925E+22) - assert dict_of_fispact_mats['Si29'] == pytest.approx( - 5.457311411014E+20) - assert dict_of_fispact_mats['Si30'] == pytest.approx( - 3.597484069651E+20) - assert dict_of_fispact_mats['O16'] == pytest.approx(4.650130496709E+22) - assert dict_of_fispact_mats['O17'] == pytest.approx(1.766602913225E+19) - assert dict_of_fispact_mats['O18'] == pytest.approx(9.324307302413E+19) + dict_of_fispact_mats[isotope_and_fraction[0]] = float( + isotope_and_fraction[1] + ) + + assert dict_of_fispact_mats["Li6"] == pytest.approx(3.537400925715e21) + assert dict_of_fispact_mats["Li7"] == pytest.approx(4.307481314353e22) + assert dict_of_fispact_mats["Si28"] == pytest.approx(1.074757396925e22) + assert dict_of_fispact_mats["Si29"] == pytest.approx(5.457311411014e20) + assert dict_of_fispact_mats["Si30"] == pytest.approx(3.597484069651e20) + assert dict_of_fispact_mats["O16"] == pytest.approx(4.650130496709e22) + assert dict_of_fispact_mats["O17"] == pytest.approx(1.766602913225e19) + assert dict_of_fispact_mats["O18"] == pytest.approx(9.324307302413e19) def test_fispact_material_with_volume(self): test_mat = nmm.Material.from_library("Li4SiO4", volume_in_cm3=2.0) @@ -185,20 +175,18 @@ def test_fispact_material_with_volume(self): dict_of_fispact_mats = {} for entry in line_by_line_material: isotope_and_fraction = entry.split() - dict_of_fispact_mats[isotope_and_fraction[0] - ] = float(isotope_and_fraction[1]) - - assert dict_of_fispact_mats['Li6'] == pytest.approx(7.074801851431E+21) - assert dict_of_fispact_mats['Li7'] == pytest.approx(8.614962628707E+22) - assert dict_of_fispact_mats['Si28'] == pytest.approx( - 2.149514793849E+22) - assert dict_of_fispact_mats['Si29'] == pytest.approx( - 1.091462282203E+21) - assert dict_of_fispact_mats['Si30'] == pytest.approx( - 7.194968139301E+20) - assert dict_of_fispact_mats['O16'] == pytest.approx(9.300260993419E+22) - assert dict_of_fispact_mats['O17'] == pytest.approx(3.533205826449E+19) - assert dict_of_fispact_mats['O18'] == pytest.approx(1.864861460483E+20) + dict_of_fispact_mats[isotope_and_fraction[0]] = float( + isotope_and_fraction[1] + ) + + assert dict_of_fispact_mats["Li6"] == pytest.approx(7.074801851431e21) + assert dict_of_fispact_mats["Li7"] == pytest.approx(8.614962628707e22) + assert dict_of_fispact_mats["Si28"] == pytest.approx(2.149514793849e22) + assert dict_of_fispact_mats["Si29"] == pytest.approx(1.091462282203e21) + assert dict_of_fispact_mats["Si30"] == pytest.approx(7.194968139301e20) + assert dict_of_fispact_mats["O16"] == pytest.approx(9.300260993419e22) + assert dict_of_fispact_mats["O17"] == pytest.approx(3.533205826449e19) + assert dict_of_fispact_mats["O18"] == pytest.approx(1.864861460483e20) def test_mcnp_material_suffix(self): test_material1 = nmm.Material.from_library( @@ -209,8 +197,7 @@ def test_mcnp_material_suffix(self): name="Nb3Sn", zaid_suffix=".30c", material_id=27 ) mcnp_material2 = test_material2.mcnp_material - test_material3 = nmm.Material.from_library( - name="Nb3Sn", material_id=27) + test_material3 = nmm.Material.from_library(name="Nb3Sn", material_id=27) mcnp_material3 = test_material3.mcnp_material assert len(mcnp_material3) < len(mcnp_material2) @@ -340,12 +327,10 @@ def test_serpent_material_lines_contain_underscore(self): assert "-" in line_by_line_material[11] def test_serpent_material_suffix(self): - test_material1 = nmm.Material.from_library( - name="Nb3Sn", zaid_suffix=".21c") + test_material1 = nmm.Material.from_library(name="Nb3Sn", zaid_suffix=".21c") serpent_material1 = test_material1.serpent_material - test_material2 = nmm.Material.from_library( - name="Nb3Sn", zaid_suffix=".30c") + test_material2 = nmm.Material.from_library(name="Nb3Sn", zaid_suffix=".30c") serpent_material2 = test_material2.serpent_material test_material3 = nmm.Material.from_library(name="Nb3Sn") @@ -389,8 +374,7 @@ def test_serpent_material_lines_with_decimal_places(self): assert len(line_by_line_material) == 12 assert line_by_line_material[0].split()[0] == "mat" assert line_by_line_material[0].split()[1] == "Nb3Sn" - assert float(line_by_line_material[0].split()[ - 2]) == pytest.approx(3.3333) + assert float(line_by_line_material[0].split()[2]) == pytest.approx(3.3333) assert " 041093.30c 7.5000e-01" in line_by_line_material assert " 050120.30c 8.1450e-02" in line_by_line_material assert " 050119.30c 2.1475e-02" in line_by_line_material @@ -409,8 +393,7 @@ def test_material_creation_from_chemical_formula_with_enrichment(self): li_fraction = 7 enrichment = 20 - lithium_lead_elements = "Li" + \ - str(li_fraction) + "Pb" + str(pb_fraction) + lithium_lead_elements = "Li" + str(li_fraction) + "Pb" + str(pb_fraction) test_material = nmm.Material.from_library( "lithium-lead", enrichment=enrichment, @@ -434,10 +417,8 @@ def test_material_creation_from_chemical_formula_with_enrichment(self): if entry[0] == "Li7": li7_atom_count = li7_atom_count + entry[1] print(nucs) - assert pb_atom_count == pytest.approx( - pb_fraction / (pb_fraction + li_fraction)) - assert li_atom_count == pytest.approx( - li_fraction / (pb_fraction + li_fraction)) + assert pb_atom_count == pytest.approx(pb_fraction / (pb_fraction + li_fraction)) + assert li_atom_count == pytest.approx(li_fraction / (pb_fraction + li_fraction)) assert li6_atom_count * 4.0 == pytest.approx(li7_atom_count) assert li6_atom_count == pytest.approx( @@ -445,8 +426,7 @@ def test_material_creation_from_chemical_formula_with_enrichment(self): rel=0.01, ) assert li7_atom_count == pytest.approx( - ((100.0 - enrichment) / 100) * - (li_fraction / (pb_fraction + li_fraction)), + ((100.0 - enrichment) / 100) * (li_fraction / (pb_fraction + li_fraction)), rel=0.01, ) @@ -456,8 +436,7 @@ def test_material_creation_from_chemical_formula_with_enrichment2(self): li_fraction = 7 enrichment = 20 - lithium_lead_elements = "Li" + \ - str(li_fraction) + "Pb" + str(pb_fraction) + lithium_lead_elements = "Li" + str(li_fraction) + "Pb" + str(pb_fraction) test_material = nmm.Material.from_library( "lithium-lead", enrichment=enrichment, @@ -497,44 +476,34 @@ def test_density_of_crystals(self): # however, this could be becuase the density values are rounded to 2 dp test_mat = nmm.Material.from_library(name="Li4SiO4") - assert test_mat.openmc_material.density == pytest.approx( - 2.32, rel=0.01) + assert test_mat.openmc_material.density == pytest.approx(2.32, rel=0.01) test_mat = nmm.Material.from_library(name="Li2SiO3") - assert test_mat.openmc_material.density == pytest.approx( - 2.44, rel=0.01) + assert test_mat.openmc_material.density == pytest.approx(2.44, rel=0.01) test_mat = nmm.Material.from_library(name="Li2ZrO3") - assert test_mat.openmc_material.density == pytest.approx( - 4.03, rel=0.01) + assert test_mat.openmc_material.density == pytest.approx(4.03, rel=0.01) test_mat = nmm.Material.from_library(name="Li2TiO3") - assert test_mat.openmc_material.density == pytest.approx( - 3.34, rel=0.01) + assert test_mat.openmc_material.density == pytest.approx(3.34, rel=0.01) test_mat = nmm.Material.from_library(name="Li8PbO6") - assert test_mat.openmc_material.density == pytest.approx( - 4.14, rel=0.01) + assert test_mat.openmc_material.density == pytest.approx(4.14, rel=0.01) test_mat = nmm.Material.from_library(name="Be") - assert test_mat.openmc_material.density == pytest.approx( - 1.88, rel=0.01) + assert test_mat.openmc_material.density == pytest.approx(1.88, rel=0.01) test_mat = nmm.Material.from_library(name="Be12Ti") - assert test_mat.openmc_material.density == pytest.approx( - 2.28, rel=0.01) + assert test_mat.openmc_material.density == pytest.approx(2.28, rel=0.01) test_mat = nmm.Material.from_library(name="Ba5Pb3") - assert test_mat.openmc_material.density == pytest.approx( - 5.84, rel=0.01) + assert test_mat.openmc_material.density == pytest.approx(5.84, rel=0.01) test_mat = nmm.Material.from_library(name="Nd5Pb4") - assert test_mat.openmc_material.density == pytest.approx( - 8.79, rel=0.01) + assert test_mat.openmc_material.density == pytest.approx(8.79, rel=0.01) test_mat = nmm.Material.from_library(name="Zr5Pb3") - assert test_mat.openmc_material.density == pytest.approx( - 8.23, rel=0.01) + assert test_mat.openmc_material.density == pytest.approx(8.23, rel=0.01) # TODO extra checks for all the crystals needed here @@ -547,15 +516,16 @@ def test_density_of_enriched_crystals(self): enrichment_target="Li6", enrichment_type="ao", ) - assert (test_mat.openmc_material.density > - test_mat_enriched.openmc_material.density) + assert ( + test_mat.openmc_material.density > test_mat_enriched.openmc_material.density + ) def test_density_of_packed_crystals(self): test_mat = nmm.Material.from_library(name="Li4SiO4") test_mat_packed = nmm.Material.from_library( - name="Li4SiO4", - packing_fraction=0.35) + name="Li4SiO4", packing_fraction=0.35 + ) assert ( test_mat.openmc_material.density * 0.35 == test_mat_packed.openmc_material.density @@ -566,8 +536,7 @@ def test_material_creation_from_chemical_formula(self): pb_fraction = 3 li_fraction = 7 - lithium_lead_elements = "Li" + \ - str(li_fraction) + "Pb" + str(pb_fraction) + lithium_lead_elements = "Li" + str(li_fraction) + "Pb" + str(pb_fraction) test_material = nmm.Material.from_library( "lithium-lead", chemical_equation=lithium_lead_elements, @@ -581,13 +550,10 @@ def test_material_creation_from_chemical_formula(self): pb_atom_count = pb_atom_count + entry[1] if entry[0].startswith("Li"): li_atom_count = li_atom_count + entry[1] - assert pb_atom_count == pytest.approx( - pb_fraction / (pb_fraction + li_fraction)) - assert li_atom_count == pytest.approx( - li_fraction / (pb_fraction + li_fraction)) + assert pb_atom_count == pytest.approx(pb_fraction / (pb_fraction + li_fraction)) + assert li_atom_count == pytest.approx(li_fraction / (pb_fraction + li_fraction)) def test_incorrect_settings(self): - def enrichment_too_high(): """checks a ValueError is raised when enrichment is over 100""" @@ -627,16 +593,14 @@ def incorrect_elements_chemical_equation_usage(): """checks a ValueError is raised when the both chemical_equation and elements are used""" nmm.Material.from_library( - name='my_mat', + name="my_mat", enrichment=50.0, chemical_equation="Li4SiO4", - elements={'C': 0.3333, 'O': 0.666}, + elements={"C": 0.3333, "O": 0.666}, enrichment_type="ao", ) - self.assertRaises( - ValueError, - incorrect_elements_chemical_equation_usage) + self.assertRaises(ValueError, incorrect_elements_chemical_equation_usage) def incorrect_enrichment_target(): """checks a ValueError is raised when the enrichment target is not a natural isotope""" @@ -683,9 +647,9 @@ def test_missing_temperature_CO2(): def test_incorrect_name_type(): """checks a ValueError is raised when the temperature is not set""" - test_material = nmm.Material.from_library("H2O", - temperature=283, - pressure=-1e6) + test_material = nmm.Material.from_library( + "H2O", temperature=283, pressure=-1e6 + ) test_material.name = 1 self.assertRaises(ValueError, test_incorrect_name_type) @@ -694,9 +658,8 @@ def test_incorrect_density_unit_type(): """checks a ValueError is raised when the temperature is not set""" nmm.Material.from_library( - "eurofer", - density=1., - density_unit='grams per cm3') + "eurofer", density=1.0, density_unit="grams per cm3" + ) self.assertRaises(ValueError, test_incorrect_density_unit_type) @@ -704,9 +667,8 @@ def test_incorrect_percent_type_type(): """checks a ValueError is raised when the temperature is not set""" nmm.Material.from_library( - "eurofer", - density=1., - percent_type='weight percent') + "eurofer", density=1.0, percent_type="weight percent" + ) self.assertRaises(ValueError, test_incorrect_percent_type_type) @@ -714,45 +676,36 @@ def test_incorrect_enrichment_type_type(): """checks a ValueError is raised when the temperature is not set""" nmm.Material.from_library( - "eurofer", - density=1., - enrichment_type='weight percent') + "eurofer", density=1.0, enrichment_type="weight percent" + ) self.assertRaises(ValueError, test_incorrect_enrichment_type_type) def test_incorrect_atoms_per_unit_cell(): """checks a ValueError is raised when the temperature is not set""" - nmm.Material.from_library( - "eurofer", - atoms_per_unit_cell=-1.) + nmm.Material.from_library("eurofer", atoms_per_unit_cell=-1.0) self.assertRaises(ValueError, test_incorrect_atoms_per_unit_cell) def test_incorrect_volume_of_unit_cell_cm3(): """checks a ValueError is raised when the temperature is not set""" - nmm.Material.from_library( - "eurofer", - volume_of_unit_cell_cm3=-1.) + nmm.Material.from_library("eurofer", volume_of_unit_cell_cm3=-1.0) self.assertRaises(ValueError, test_incorrect_volume_of_unit_cell_cm3) def test_incorrect_temperature(): """checks a ValueError is raised when the temperature is not set""" - nmm.Material.from_library( - "eurofer", - temperature=-1.) + nmm.Material.from_library("eurofer", temperature=-1.0) self.assertRaises(ValueError, test_incorrect_temperature) def test_incorrect_zaid_suffix_type(): """checks a ValueError is raised when the temperature is not set""" - nmm.Material.from_library( - "eurofer", - zaid_suffix=0.80) + nmm.Material.from_library("eurofer", zaid_suffix=0.80) self.assertRaises(ValueError, test_incorrect_zaid_suffix_type) @@ -760,10 +713,7 @@ def test_incorrect_packing_fraction(): """checks a ValueError is raised when the packing_fraction is the wrong type""" - nmm.Material.from_library( - "eurofer", - packing_fraction="1" - ) + nmm.Material.from_library("eurofer", packing_fraction="1") self.assertRaises(ValueError, test_incorrect_packing_fraction) @@ -771,10 +721,7 @@ def test_too_large_packing_fraction(): """checks a ValueError is raised when the packing_fraction is the too large""" - nmm.Material.from_library( - "eurofer", - packing_fraction=1.1 - ) + nmm.Material.from_library("eurofer", packing_fraction=1.1) self.assertRaises(ValueError, test_too_large_packing_fraction) @@ -782,10 +729,7 @@ def test_too_small_packing_fraction(): """checks a ValueError is raised when the packing_fraction is the too large""" - nmm.Material.from_library( - "eurofer", - packing_fraction=-0.1 - ) + nmm.Material.from_library("eurofer", packing_fraction=-0.1) self.assertRaises(ValueError, test_too_small_packing_fraction) @@ -793,10 +737,7 @@ def test_chemical_equation_wrong_type(): """checks a ValueError is raised when the chemical_equation is the not a str""" - nmm.Material.from_library( - "eurofer", - chemical_equation=-0.1 - ) + nmm.Material.from_library("eurofer", chemical_equation=-0.1) self.assertRaises(ValueError, test_chemical_equation_wrong_type) @@ -805,9 +746,7 @@ def test_enrichment_too_high(): too large""" nmm.Material.from_library( - "Li4SiO4", - enrichment=101, - enrichment_target='Li6' + "Li4SiO4", enrichment=101, enrichment_target="Li6" ) self.assertRaises(ValueError, test_enrichment_too_high) @@ -816,11 +755,7 @@ def test_enrichment_too_low(): """checks a ValueError is raised when the enrichment is the too small""" - nmm.Material.from_library( - "Li4SiO4", - enrichment=-1, - enrichment_target='Li6' - ) + nmm.Material.from_library("Li4SiO4", enrichment=-1, enrichment_target="Li6") self.assertRaises(ValueError, test_enrichment_too_low) @@ -828,10 +763,7 @@ def test_pressure_too_low(): """checks a ValueError is raised when the pressure is the too small""" - nmm.Material.from_library( - "Li4SiO4", - pressure=-1 - ) + nmm.Material.from_library("Li4SiO4", pressure=-1) self.assertRaises(ValueError, test_pressure_too_low) @@ -839,10 +771,7 @@ def test_comment_wrong_type(): """checks a ValueError is raised when the comment is the not a string""" - nmm.Material.from_library( - "Li4SiO4", - comment=-1 - ) + nmm.Material.from_library("Li4SiO4", comment=-1) self.assertRaises(ValueError, test_comment_wrong_type) @@ -850,10 +779,7 @@ def test_material_id_wrong_type(): """checks a ValueError is raised when the material_id is the not an int""" - nmm.Material.from_library( - "Li4SiO4", - material_id='one' - ) + nmm.Material.from_library("Li4SiO4", material_id="one") self.assertRaises(ValueError, test_material_id_wrong_type) @@ -970,49 +896,43 @@ def test_setting_for_volume_float(self): def test_json_dump_works(self): test_material = nmm.Material.from_library( - name="H2O", temperature=373, pressure=1e6) + name="H2O", temperature=373, pressure=1e6 + ) assert isinstance(json.dumps(test_material), str) def test_json_dump_contains_correct_keys(self): test_material = nmm.Material.from_library( - name="H2O", temperature=373, pressure=1e6, comment='test') + name="H2O", temperature=373, pressure=1e6, comment="test" + ) test_material_in_json_form = test_material.to_json() - assert "density" in test_material_in_json_form['H2O'].keys() - assert "density_unit" in test_material_in_json_form['H2O'].keys() - assert "chemical_equation" in test_material_in_json_form['H2O'].keys() - assert "packing_fraction" in test_material_in_json_form['H2O'].keys() - assert "percent_type" in test_material_in_json_form['H2O'].keys() - assert "pressure" in test_material_in_json_form['H2O'].keys() - assert "comment" in test_material_in_json_form['H2O'].keys() - assert "temperature" in test_material_in_json_form['H2O'].keys() + assert "density" in test_material_in_json_form["H2O"].keys() + assert "density_unit" in test_material_in_json_form["H2O"].keys() + assert "chemical_equation" in test_material_in_json_form["H2O"].keys() + assert "packing_fraction" in test_material_in_json_form["H2O"].keys() + assert "percent_type" in test_material_in_json_form["H2O"].keys() + assert "pressure" in test_material_in_json_form["H2O"].keys() + assert "comment" in test_material_in_json_form["H2O"].keys() + assert "temperature" in test_material_in_json_form["H2O"].keys() def test_json_dump_contains_correct_keys_2(self): - test_material = nmm.Material.from_library( - name="Li4SiO4", enrichment=90) + test_material = nmm.Material.from_library(name="Li4SiO4", enrichment=90) test_material_in_json_form = test_material.to_json() - assert "atoms_per_unit_cell" in test_material_in_json_form['Li4SiO4'].keys( - ) - assert "density" in test_material_in_json_form['Li4SiO4'].keys() - assert "density_unit" in test_material_in_json_form['Li4SiO4'].keys() - assert "chemical_equation" in test_material_in_json_form['Li4SiO4'].keys( - ) - assert "enrichment_type" in test_material_in_json_form['Li4SiO4'].keys( - ) - assert "packing_fraction" in test_material_in_json_form['Li4SiO4'].keys( - ) - assert "percent_type" in test_material_in_json_form['Li4SiO4'].keys() - assert "comment" in test_material_in_json_form['Li4SiO4'].keys() - assert "enrichment" in test_material_in_json_form['Li4SiO4'].keys() - assert "enrichment_target" in test_material_in_json_form['Li4SiO4'].keys( - ) - assert "volume_of_unit_cell_cm3" in test_material_in_json_form['Li4SiO4'].keys( - ) + assert "atoms_per_unit_cell" in test_material_in_json_form["Li4SiO4"].keys() + assert "density" in test_material_in_json_form["Li4SiO4"].keys() + assert "density_unit" in test_material_in_json_form["Li4SiO4"].keys() + assert "chemical_equation" in test_material_in_json_form["Li4SiO4"].keys() + assert "enrichment_type" in test_material_in_json_form["Li4SiO4"].keys() + assert "packing_fraction" in test_material_in_json_form["Li4SiO4"].keys() + assert "percent_type" in test_material_in_json_form["Li4SiO4"].keys() + assert "comment" in test_material_in_json_form["Li4SiO4"].keys() + assert "enrichment" in test_material_in_json_form["Li4SiO4"].keys() + assert "enrichment_target" in test_material_in_json_form["Li4SiO4"].keys() + assert "volume_of_unit_cell_cm3" in test_material_in_json_form["Li4SiO4"].keys() def test_json_dump_contains_correct_values(self): - test_material = nmm.Material.from_library( - "H2O", temperature=373, pressure=1e6) + test_material = nmm.Material.from_library("H2O", temperature=373, pressure=1e6) test_material_in_json_form = test_material.to_json() assert test_material_in_json_form["H2O"]["pressure"] == 1e6 @@ -1024,9 +944,7 @@ def test_temperature_from_C_in_materials(self): attribute of the openmc materials""" test_material = nmm.Material.from_library( - 'H2O', - temperature=383, - pressure=15.5e6 + "H2O", temperature=383, pressure=15.5e6 ) assert test_material.temperature == 383 @@ -1042,9 +960,7 @@ def test_temperature_from_K_in_materials(self): attribute of the openmc materials""" test_material = nmm.Material.from_library( - 'H2O', - temperature=300, - pressure=15.5e6 + "H2O", temperature=300, pressure=15.5e6 ) assert test_material.temperature == 300 @@ -1059,7 +975,7 @@ def test_temperature_not_in_materials(self): """checks that the temperature set in K ends up in the temperature attribute of the openmc materials""" - test_material = nmm.Material.from_library('WC') + test_material = nmm.Material.from_library("WC") assert test_material.openmc_material.temperature is None line_by_line_material = test_material.serpent_material.split("\n") @@ -1072,10 +988,7 @@ def test_restricted_eval(): """Test that arbitrary commands cannot be injected.""" with pytest.raises(NameError): nmm.Material.from_library( - name="Nb3Sn", - temperature=373, - pressure=1e6, - density="os.system('ls')" + name="Nb3Sn", temperature=373, pressure=1e6, density="os.system('ls')" ) diff --git a/tests/test_Material_from_mixture.py b/tests/test_Material_from_mixture.py index 97adbbc..e071fcc 100644 --- a/tests/test_Material_from_mixture.py +++ b/tests/test_Material_from_mixture.py @@ -18,10 +18,9 @@ def test_serpent_from_mixture_type(self): name="test_material", materials=[ nmm.Material.from_library("Li4SiO4"), - nmm.Material.from_library("Be12Ti")], - fracs=[ - 0.50, - 0.50], + nmm.Material.from_library("Be12Ti"), + ], + fracs=[0.50, 0.50], percent_type="vo", ) @@ -34,10 +33,9 @@ def test_mcnp_from_mixture_type(self): name="test_material", materials=[ nmm.Material.from_library("Li4SiO4"), - nmm.Material.from_library("Be12Ti")], - fracs=[ - 0.50, - 0.50], + nmm.Material.from_library("Be12Ti"), + ], + fracs=[0.50, 0.50], percent_type="vo", material_id=2, ) @@ -51,10 +49,9 @@ def test_shift_from_mixture_type(self): name="test_material", materials=[ nmm.Material.from_library("Li4SiO4"), - nmm.Material.from_library("Be12Ti")], - fracs=[ - 0.50, - 0.50], + nmm.Material.from_library("Be12Ti"), + ], + fracs=[0.50, 0.50], percent_type="vo", temperature=300, material_id=2, @@ -69,10 +66,9 @@ def test_fispact_from_mixture_type(self): name="test_material", materials=[ nmm.Material.from_library("Li4SiO4"), - nmm.Material.from_library("Be12Ti")], - fracs=[ - 0.50, - 0.50], + nmm.Material.from_library("Be12Ti"), + ], + fracs=[0.50, 0.50], percent_type="vo", volume_in_cm3=20, ) @@ -88,10 +84,9 @@ def test_make_from_mixture_from_material_objects(self): name="test_material", materials=[ nmm.Material.from_library("Li4SiO4"), - nmm.Material.from_library("Be12Ti")], - fracs=[ - 0.50, - 0.50], + nmm.Material.from_library("Be12Ti"), + ], + fracs=[0.50, 0.50], percent_type="vo", ) @@ -119,33 +114,34 @@ def test_mutliname_setting(self): test_material = nmm.Material.from_mixture( materials=[ - nmm.Material.from_library('Pb842Li158', temperature=500), - nmm.Material.from_library('SiC') + nmm.Material.from_library("Pb842Li158", temperature=500), + nmm.Material.from_library("SiC"), ], - fracs=[0.5, 0.5]) + fracs=[0.5, 0.5], + ) assert test_material.name is None - test_material.name = 'tag_set_after_creation' - assert test_material.name == 'tag_set_after_creation' + test_material.name = "tag_set_after_creation" + assert test_material.name == "tag_set_after_creation" test_material.openmc_material - assert test_material.openmc_material.name == 'tag_set_after_creation' + assert test_material.openmc_material.name == "tag_set_after_creation" test_material = nmm.Material.from_mixture( materials=[ - nmm.Material.from_library('Pb842Li158', temperature=500), - nmm.Material.from_library('SiC') + nmm.Material.from_library("Pb842Li158", temperature=500), + nmm.Material.from_library("SiC"), ], fracs=[0.5, 0.5], - name='tag_set_on_creation') + name="tag_set_on_creation", + ) - assert test_material.name == 'tag_set_on_creation' + assert test_material.name == "tag_set_on_creation" test_material.openmc_material - assert test_material.openmc_material.name == 'tag_set_on_creation' + assert test_material.openmc_material.name == "tag_set_on_creation" - def test_from_mixture_attributes_from_material_objects_and_openmc_materials( - self): + def test_from_mixture_attributes_from_material_objects_and_openmc_materials(self): # tests that from_mixtures made from material objects and neutronics # materials have the same properties @@ -153,10 +149,9 @@ def test_from_mixture_attributes_from_material_objects_and_openmc_materials( name="test_material_1", materials=[ nmm.Material.from_library("Li4SiO4"), - nmm.Material.from_library("Be12Ti")], - fracs=[ - 0.5, - 0.5], + nmm.Material.from_library("Be12Ti"), + ], + fracs=[0.5, 0.5], percent_type="vo", ).openmc_material @@ -228,11 +223,11 @@ def test_density_of_mixed_two_packed_and_non_packed_crystals(self): def test_density_of_mixed_materials_from_density(self): test_material = nmm.Material.from_library( - "H2O", temperature=300, pressure=100000) + "H2O", temperature=300, pressure=100000 + ) test_mixed_material = nmm.Material.from_mixture( - name="test_mixed_material", - materials=[test_material], - fracs=[1]) + name="test_mixed_material", materials=[test_material], fracs=[1] + ) assert test_material.openmc_material.density == pytest.approx( test_mixed_material.openmc_material.density @@ -269,21 +264,22 @@ def test_packing_fraction_for_single_materials(self): test_material_1 = nmm.Material.from_library("Li4SiO4").openmc_material test_material_2 = nmm.Material.from_library( - "Li4SiO4", packing_fraction=1).openmc_material + "Li4SiO4", packing_fraction=1 + ).openmc_material assert test_material_1.density == test_material_2.density test_material_3 = nmm.Material.from_library( - "Li4SiO4", packing_fraction=0.5).openmc_material + "Li4SiO4", packing_fraction=0.5 + ).openmc_material - assert test_material_3.density == pytest.approx( - test_material_1.density * 0.5) + assert test_material_3.density == pytest.approx(test_material_1.density * 0.5) test_material_4 = nmm.Material.from_library( - "Li4SiO4", packing_fraction=0.75).openmc_material + "Li4SiO4", packing_fraction=0.75 + ).openmc_material - assert test_material_4.density == pytest.approx( - test_material_1.density * 0.75) + assert test_material_4.density == pytest.approx(test_material_1.density * 0.75) def test_packing_fraction_for_from_mixture_function(self): @@ -291,10 +287,9 @@ def test_packing_fraction_for_from_mixture_function(self): name="test_material_5", materials=[ nmm.Material.from_library("tungsten"), - nmm.Material.from_library("eurofer")], - fracs=[ - 0.5, - 0.5], + nmm.Material.from_library("eurofer"), + ], + fracs=[0.5, 0.5], ).openmc_material test_material_6 = nmm.Material.from_mixture( @@ -317,8 +312,7 @@ def test_packing_fraction_for_from_mixture_function(self): fracs=[0.5, 0.5], ).openmc_material - assert test_material_7.density == pytest.approx( - test_material_5.density * 0.5) + assert test_material_7.density == pytest.approx(test_material_5.density * 0.5) def test_packing_fraction_of_a_from_mixture(self): @@ -358,23 +352,36 @@ def test_packing_fraction_for_mix_materials_function(self): ) test_material_9 = openmc.Material.mix_materials( - name="test_material_9", materials=[ + name="test_material_9", + materials=[ nmm.Material.from_library( - "tungsten", packing_fraction=1).openmc_material, nmm.Material.from_library( - "eurofer", packing_fraction=1).openmc_material, ], fracs=[ - 0.5, 0.5], percent_type="vo", ) + "tungsten", packing_fraction=1 + ).openmc_material, + nmm.Material.from_library( + "eurofer", packing_fraction=1 + ).openmc_material, + ], + fracs=[0.5, 0.5], + percent_type="vo", + ) assert test_material_8.density == test_material_9.density test_material_10 = openmc.Material.mix_materials( - name="test_material_10", materials=[ + name="test_material_10", + materials=[ + nmm.Material.from_library( + "tungsten", packing_fraction=0.5 + ).openmc_material, nmm.Material.from_library( - "tungsten", packing_fraction=0.5).openmc_material, nmm.Material.from_library( - "eurofer", packing_fraction=0.5).openmc_material, ], fracs=[ - 0.5, 0.5], percent_type="vo", ) + "eurofer", packing_fraction=0.5 + ).openmc_material, + ], + fracs=[0.5, 0.5], + percent_type="vo", + ) - assert test_material_10.density == pytest.approx( - test_material_8.density * 0.5) + assert test_material_10.density == pytest.approx(test_material_8.density * 0.5) def test_from_mixture_vs_mix_materials(self): @@ -382,10 +389,9 @@ def test_from_mixture_vs_mix_materials(self): name="test_material_11", materials=[ nmm.Material.from_library("tungsten"), - nmm.Material.from_library("eurofer")], - fracs=[ - 0.5, - 0.5], + nmm.Material.from_library("eurofer"), + ], + fracs=[0.5, 0.5], ).openmc_material test_material_12 = openmc.Material.mix_materials( @@ -398,8 +404,7 @@ def test_from_mixture_vs_mix_materials(self): percent_type="vo", ) - assert pytest.approx( - test_material_11.density) == test_material_12.density + assert pytest.approx(test_material_11.density) == test_material_12.density test_material_13 = nmm.Material.from_mixture( name="test_material_13", @@ -411,14 +416,20 @@ def test_from_mixture_vs_mix_materials(self): ).openmc_material test_material_14 = openmc.Material.mix_materials( - name="test_material_14", materials=[ + name="test_material_14", + materials=[ + nmm.Material.from_library( + "tungsten", packing_fraction=0.6 + ).openmc_material, nmm.Material.from_library( - "tungsten", packing_fraction=0.6).openmc_material, nmm.Material.from_library( - "eurofer", packing_fraction=0.8).openmc_material, ], fracs=[ - 0.3, 0.7], percent_type="vo", ) + "eurofer", packing_fraction=0.8 + ).openmc_material, + ], + fracs=[0.3, 0.7], + percent_type="vo", + ) - assert pytest.approx( - test_material_13.density) == test_material_14.density + assert pytest.approx(test_material_13.density) == test_material_14.density def test_json_dump_works(self): test_material = nmm.Material.from_mixture( @@ -443,10 +454,8 @@ def test_json_dump_contains_correct_keys(self): test_material_in_json_form = test_material.to_json() assert "test_material" in list(test_material_in_json_form.keys()) - assert "percent_type" in test_material_in_json_form["test_material"].keys( - ) - assert "packing_fraction" in test_material_in_json_form["test_material"].keys( - ) + assert "percent_type" in test_material_in_json_form["test_material"].keys() + assert "packing_fraction" in test_material_in_json_form["test_material"].keys() def test_json_dump_contains_correct_values(self): test_material = nmm.Material.from_mixture( @@ -468,11 +477,13 @@ def too_large_fracs(): """checks a ValueError is raised when the fracs are above 1""" nmm.Material.from_mixture( - name="test_material", materials=[ - nmm.Material.from_library( - "tungsten", packing_fraction=0.6), nmm.Material.from_library( - "eurofer", packing_fraction=0.8), ], fracs=[ - 0.3, 0.75], ) + name="test_material", + materials=[ + nmm.Material.from_library("tungsten", packing_fraction=0.6), + nmm.Material.from_library("eurofer", packing_fraction=0.8), + ], + fracs=[0.3, 0.75], + ) with warnings.catch_warnings(record=True) as w: # Cause all warnings to always be triggered. @@ -485,17 +496,20 @@ def too_large_fracs(): # the second entry is needed as OpenMC material mixer also raises # and error assert "warning sum of MutliMaterials.fracs do not sum to 1." in str( - w[-2].message) + w[-2].message + ) def too_small_fracs(): """checks a ValueError is raised when the fracs are above 1""" nmm.Material.from_mixture( - name="test_material", materials=[ - nmm.Material.from_library( - "tungsten", packing_fraction=0.6), nmm.Material.from_library( - "eurofer", packing_fraction=0.8), ], fracs=[ - 0.3, 0.65], ) + name="test_material", + materials=[ + nmm.Material.from_library("tungsten", packing_fraction=0.6), + nmm.Material.from_library("eurofer", packing_fraction=0.8), + ], + fracs=[0.3, 0.65], + ) with warnings.catch_warnings(record=True) as w: # Cause all warnings to always be triggered. @@ -508,18 +522,22 @@ def too_small_fracs(): # the second entry is needed as OpenMC material mixer also raises # and error assert "warning sum of MutliMaterials.fracs do not sum to 1." in str( - w[-2].message) + w[-2].message + ) def test_incorrect_packing_fraction(): """checks a ValueError is raised when the packing_fraction is the wrong type""" nmm.Material.from_mixture( - name="test_material", materials=[ - nmm.Material.from_library( - "tungsten", packing_fraction=0.6), nmm.Material.from_library( - "eurofer", packing_fraction=0.8), ], fracs=[ - 0.3, 0.7], packing_fraction="1") + name="test_material", + materials=[ + nmm.Material.from_library("tungsten", packing_fraction=0.6), + nmm.Material.from_library("eurofer", packing_fraction=0.8), + ], + fracs=[0.3, 0.7], + packing_fraction="1", + ) self.assertRaises(ValueError, test_incorrect_packing_fraction) @@ -528,11 +546,14 @@ def test_too_large_packing_fraction(): too large""" nmm.Material.from_mixture( - name="test_material", materials=[ - nmm.Material.from_library( - "tungsten", packing_fraction=0.6), nmm.Material.from_library( - "eurofer", packing_fraction=0.8), ], fracs=[ - 0.3, 0.7], packing_fraction=1.1) + name="test_material", + materials=[ + nmm.Material.from_library("tungsten", packing_fraction=0.6), + nmm.Material.from_library("eurofer", packing_fraction=0.8), + ], + fracs=[0.3, 0.7], + packing_fraction=1.1, + ) self.assertRaises(ValueError, test_too_large_packing_fraction) @@ -541,11 +562,14 @@ def test_too_small_packing_fraction(): too large""" nmm.Material.from_mixture( - name="test_material", materials=[ - nmm.Material.from_library( - "tungsten", packing_fraction=0.6), nmm.Material.from_library( - "eurofer", packing_fraction=0.8), ], fracs=[ - 0.3, 0.7], packing_fraction=-0.1) + name="test_material", + materials=[ + nmm.Material.from_library("tungsten", packing_fraction=0.6), + nmm.Material.from_library("eurofer", packing_fraction=0.8), + ], + fracs=[0.3, 0.7], + packing_fraction=-0.1, + ) self.assertRaises(ValueError, test_too_small_packing_fraction) @@ -560,7 +584,7 @@ def test_temperature_from_C_in_from_mixtures(self): nmm.Material.from_library("eurofer"), ], fracs=[0.3, 0.7], - temperature=283.15 + temperature=283.15, ) assert test_material.temperature == 283.15 @@ -582,7 +606,7 @@ def test_temperature_from_K_in_from_mixtures(self): nmm.Material.from_library("eurofer"), ], fracs=[0.3, 0.7], - temperature=300 + temperature=300, ) assert test_material.temperature == 300 diff --git a/tests/test_utils.py b/tests/test_utils.py index 5429569..676dc9c 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -16,81 +16,76 @@ class test_object_properties(unittest.TestCase): - def test_additional_lines_multimaterial_mcnp(self): test_mat1 = nmm.Material.from_library( - 'Li4SiO4', - additional_end_lines={'mcnp': ['mat1_additional']} + "Li4SiO4", additional_end_lines={"mcnp": ["mat1_additional"]} ) test_mat2 = nmm.Material.from_library( - 'Be12Ti', - additional_end_lines={'mcnp': ['mat2_additional']} + "Be12Ti", additional_end_lines={"mcnp": ["mat2_additional"]} ) test_mat3 = nmm.Material.from_mixture( - name='mixed', + name="mixed", materials=[test_mat1, test_mat2], temperature=500, fracs=[0.5, 0.5], material_id=3, volume_in_cm3=1, additional_end_lines={ - 'mcnp': ['extra_mcnp_lin'], - 'serpent': ['extra_serpent_lin'], - 'fispact': ['extra_fispact_lin'], - 'shift': ['extra_shift_lin'], - } + "mcnp": ["extra_mcnp_lin"], + "serpent": ["extra_serpent_lin"], + "fispact": ["extra_fispact_lin"], + "shift": ["extra_shift_lin"], + }, ) - assert test_mat3.mcnp_material.split('\n')[-2] == 'extra_mcnp_lin' - assert test_mat3.serpent_material.split( - '\n')[-1] == 'extra_serpent_lin' - assert test_mat3.fispact_material.split( - '\n')[-1] == 'extra_fispact_lin' - assert test_mat3.shift_material.split('\n')[-1] == 'extra_shift_lin' + assert test_mat3.mcnp_material.split("\n")[-2] == "extra_mcnp_lin" + assert test_mat3.serpent_material.split("\n")[-1] == "extra_serpent_lin" + assert test_mat3.fispact_material.split("\n")[-1] == "extra_fispact_lin" + assert test_mat3.shift_material.split("\n")[-1] == "extra_shift_lin" def test_additional_lines_mcnp(self): test_mat = nmm.Material.from_library( - 'H2O', + "H2O", pressure=1e6, temperature=393, material_id=1, - additional_end_lines={'mcnp': [' mt24 lwtr.01']} + additional_end_lines={"mcnp": [" mt24 lwtr.01"]}, ) - assert test_mat.mcnp_material.split('\n')[-2] == ' mt24 lwtr.01' + assert test_mat.mcnp_material.split("\n")[-2] == " mt24 lwtr.01" def test_additional_lines_shift(self): test_mat = nmm.Material.from_library( - 'H2O', + "H2O", pressure=1e6, temperature=393, material_id=1, - additional_end_lines={'shift': ['coucou']} + additional_end_lines={"shift": ["coucou"]}, ) - assert test_mat.shift_material.split('\n')[-1] == 'coucou' + assert test_mat.shift_material.split("\n")[-1] == "coucou" def test_additional_lines_fispact(self): test_mat = nmm.Material.from_library( - 'H2O', + "H2O", pressure=1e6, temperature=393, material_id=1, volume_in_cm3=1, - additional_end_lines={'fispact': ['coucou']} + additional_end_lines={"fispact": ["coucou"]}, ) - assert test_mat.fispact_material.split('\n')[-1] == 'coucou' + assert test_mat.fispact_material.split("\n")[-1] == "coucou" def test_additional_lines_serpent(self): test_mat = nmm.Material.from_library( - 'H2O', + "H2O", pressure=1e6, temperature=393, material_id=1, - additional_end_lines={'serpent': ['coucou']} + additional_end_lines={"serpent": ["coucou"]}, ) - assert test_mat.serpent_material.split('\n')[-1] == 'coucou' + assert test_mat.serpent_material.split("\n")[-1] == "coucou" def test_additional_lines_from_json(self): """ @@ -103,7 +98,7 @@ def test_additional_lines_from_json(self): "density": 18.0, "density_unit": "g/cm3", "percent_type": "ao", - "additional_end_lines": {'mcnp': ['coucou1', 'coucou2']} + "additional_end_lines": {"mcnp": ["coucou1", "coucou2"]}, } } @@ -112,92 +107,67 @@ def test_additional_lines_from_json(self): nmm.AddMaterialFromFile("extra_material_1.json") - test_mat = nmm.Material.from_library('mat_with_add_line') - assert test_mat.mcnp_material.split('\n')[-3] == 'coucou1' - assert test_mat.mcnp_material.split('\n')[-2] == 'coucou2' + test_mat = nmm.Material.from_library("mat_with_add_line") + assert test_mat.mcnp_material.split("\n")[-3] == "coucou1" + assert test_mat.mcnp_material.split("\n")[-2] == "coucou2" def test_incorrect_additional_lines_code_name(self): - def incorrect_additional_lines_code_name(): """Set additional_end_lines to not the name of a neutronics code which should raise an error""" nmm.Material.from_library( - 'Li4SiO4', - additional_end_lines={'unknow code': ['coucou']} + "Li4SiO4", additional_end_lines={"unknow code": ["coucou"]} ) - self.assertRaises( - ValueError, - incorrect_additional_lines_code_name - ) + self.assertRaises(ValueError, incorrect_additional_lines_code_name) def test_incorrect_additional_lines_code_value_type(self): - def incorrect_additional_lines_code_value_type(): """Set additional_end_lines value to a string which should raise an error""" nmm.Material.from_library( - 'Li4SiO4', - additional_end_lines={'unknow code': 'serpent'} + "Li4SiO4", additional_end_lines={"unknow code": "serpent"} ) - self.assertRaises( - ValueError, - incorrect_additional_lines_code_value_type - ) + self.assertRaises(ValueError, incorrect_additional_lines_code_value_type) def test_incorrect_additional_lines_code_value_list_type(self): - def incorrect_additional_lines_code_value_list_type(): """Set additional_end_lines value to a list of ints which should raise an error""" nmm.Material.from_library( - 'Li4SiO4', - additional_end_lines={'unknow code': [1]} + "Li4SiO4", additional_end_lines={"unknow code": [1]} ) - self.assertRaises( - ValueError, - incorrect_additional_lines_code_value_list_type - ) + self.assertRaises(ValueError, incorrect_additional_lines_code_value_list_type) def test_check_add_additional_end_lines_error_handeling(self): - def incorrect_type_dict(): """Set additional_end_lines value to a string which should raise an error""" - nmm.utils.check_add_additional_end_lines('mcnp') + nmm.utils.check_add_additional_end_lines("mcnp") - self.assertRaises( - ValueError, - incorrect_type_dict - ) + self.assertRaises(ValueError, incorrect_type_dict) def incorrect_type_dict_value_empty(): """Set additional_end_lines value to a string which should raise an error""" - nmm.utils.check_add_additional_end_lines({'mcnp': 'random string'}) + nmm.utils.check_add_additional_end_lines({"mcnp": "random string"}) - self.assertRaises( - ValueError, - incorrect_type_dict_value_empty - ) + self.assertRaises(ValueError, incorrect_type_dict_value_empty) def incorrect_type_dict_value(): """Set additional_end_lines value to a list of ints which should raise an error""" - nmm.utils.check_add_additional_end_lines({'mcnp': [1, 2, 3]}) + nmm.utils.check_add_additional_end_lines({"mcnp": [1, 2, 3]}) - self.assertRaises( - ValueError, - incorrect_type_dict_value - ) + self.assertRaises(ValueError, incorrect_type_dict_value) def test_zaid_to_isotope(self): assert nmm.utils.zaid_to_isotope("3006") == "Li6" @@ -256,8 +226,7 @@ def test_dictionary_of_materials_makes_openmc_materials(self): for mat in nmm.AvailableMaterials().keys(): print(mat) - test_mat = nmm.Material.from_library( - mat, temperature=300, pressure=5e6) + test_mat = nmm.Material.from_library(mat, temperature=300, pressure=5e6) assert isinstance(test_mat.openmc_material, openmc.Material) @@ -286,10 +255,8 @@ def test_dictionary_of_materials_makes_fispact_materials(self): for mat in nmm.AvailableMaterials().keys(): print(mat) test_mat = nmm.Material.from_library( - mat, - temperature=300, - pressure=5e6, - volume_in_cm3=1.5) + mat, temperature=300, pressure=5e6, volume_in_cm3=1.5 + ) assert isinstance(test_mat.fispact_material, str) @@ -297,8 +264,7 @@ def test_dictionary_of_materials_makes_serpent_materials(self): for mat in nmm.AvailableMaterials().keys(): print(mat) - test_mat = nmm.Material.from_library( - mat, temperature=300, pressure=5e6) + test_mat = nmm.Material.from_library(mat, temperature=300, pressure=5e6) assert isinstance(test_mat.serpent_material, str) From 9e2b0458d413b7935d6acf3b70c4c82240da6268 Mon Sep 17 00:00:00 2001 From: Jonathan Date: Fri, 4 Feb 2022 22:12:34 +0000 Subject: [PATCH 03/18] corrected parackage name --- neutronics_material_maker/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/neutronics_material_maker/__init__.py b/neutronics_material_maker/__init__.py index 484fc0b..c098d65 100644 --- a/neutronics_material_maker/__init__.py +++ b/neutronics_material_maker/__init__.py @@ -3,7 +3,7 @@ except (ModuleNotFoundError, ImportError): from importlib_metadata import version, PackageNotFoundError try: - __version__ = version("paramak") + __version__ = version("neutronics_material_maker") except PackageNotFoundError: from setuptools_scm import get_version From 0960e23a4184866f96903063a31b0bbdf44eabf6 Mon Sep 17 00:00:00 2001 From: Jonathan Date: Fri, 4 Feb 2022 22:23:59 +0000 Subject: [PATCH 04/18] added conda install for openmc --- .circleci/config.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 81a47e5..0e2ff67 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -9,7 +9,7 @@ version: 2.1 jobs: build: docker: - - image: openmc/openmc:develop + - image: continuumio/miniconda3:4.9.2 working_directory: ~/repo @@ -23,7 +23,8 @@ jobs: # run tests! - run: name: run tests - command: + command: | + conda install -c conda-forge pytest tests -v --cov=neutronics_material_maker --cov-report term --cov-report html:htmlcov --cov-report xml --junitxml=test-reports/junit.xml - store_test_results: path: test-reports From 6785f60af085faf402623d468610bf3c895efe89 Mon Sep 17 00:00:00 2001 From: Jonathan Date: Fri, 4 Feb 2022 22:26:38 +0000 Subject: [PATCH 05/18] moved to pip install .[density] --- .circleci/config.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 0e2ff67..f987d25 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -18,13 +18,13 @@ jobs: - run: name: install command: - python setup.py install + pip install .[density] # run tests! - run: name: run tests command: | - conda install -c conda-forge + conda install -c conda-forge openmc pytest tests -v --cov=neutronics_material_maker --cov-report term --cov-report html:htmlcov --cov-report xml --junitxml=test-reports/junit.xml - store_test_results: path: test-reports From a656ea456ea1703659694fae013d217936b86859 Mon Sep 17 00:00:00 2001 From: Jonathan Date: Fri, 4 Feb 2022 22:42:00 +0000 Subject: [PATCH 06/18] added missing setup.cfg file --- .gitignore | 140 +++++++++++++++++++++++++++++++++++++++++------------ setup.cfg | 46 ++++++++++++++++++ 2 files changed, 155 insertions(+), 31 deletions(-) create mode 100644 setup.cfg diff --git a/.gitignore b/.gitignore index 32e3d43..8fe6264 100644 --- a/.gitignore +++ b/.gitignore @@ -1,54 +1,132 @@ -# Compiled python modules. -**.pyc - -.eggs/ - -# Setuptools distribution folder. -/dist/ - -# Python egg metadata, regenerated from source files by setuptools. -/*.egg-info +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class -*.pyo +# C extensions +*.so -__pycache__/ +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +pip-wheel-metadata/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ -.idea/ +# Translations +*.mo +*.pot -.gitignore +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal -.ipynb_checkpoints/ +# Flask stuff: +instance/ +.webassets-cache -.pytest_cache/ +# Scrapy stuff: +.scrapy -*.py[cod] +# Sphinx documentation +docs/_build/ -build/ +# PyBuilder +target/ -neutronics_material_maker.egg-info/ +# Jupyter Notebook +.ipynb_checkpoints -.ipynb_checkpoints/ +# IPython +profile_default/ +ipython_config.py -dist_pac.sh +# pyenv +.python-version -setup.cfg +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock -twine_upload.sh +# PEP 582; used by e.g. github.com/David-OConnor/pyflow +__pypackages__/ -upload.sh +# Celery stuff +celerybeat-schedule +celerybeat.pid -setup.py___jb_old___ +# SageMath parsed files +*.sage.py -setup.py___jb_tmp___ +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ -.coverage +# Spyder project settings +.spyderproject +.spyproject -refs/ +# Rope project settings +.ropeproject -new_materials/ +# mkdocs documentation +/site -.vscode/ +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json -.tox/ +# Pyre type checker +.pyre/ +# file containing version number _version.py diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..be47228 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,46 @@ +[metadata] +name = neutronics_material_maker +author = The neutronics_material_maker Development Team +author_email = mail@jshimwell.com +description = A tool for making reproducible materials and standardizing use across several neutronics codes +long_description = file: README.md +long_description_content_type = text/markdown +url = https://github.com/fusion-energy/neutronics_material_maker +license = MIT +license_file = LICENSE.txt +classifiers = + Natural Language :: English + Topic :: Scientific/Engineering + Programming Language :: Python :: 3 + Programming Language :: Python :: 3.6 + Programming Language :: Python :: 3.7 + Programming Language :: Python :: 3.8 + Programming Language :: Python :: 3.9 + License :: OSI Approved :: MIT License + Operating System :: OS Independent +project_urls = + Source = https://github.com/fusion-energy/neutronics_material_maker + Tracker = https://github.com/fusion-energy/neutronics_material_maker/issues + +[options] +packages = find: +python_requires= >=3.6 +install_requires= + asteval + +[options.package_data] +* = *.json + +[options.extras_require] +density = + coolprop +tests = + pytest >= 5.4.3 + pytest-cov>=2.12.1 + pytest-runner>=5.3.1 +docs = + sphinx >= 4.1.2 + sphinx_autodoc_typehints + +[flake8] +per-file-ignores = __init__.py:F401 From bf1d341349d8a571223b51d8dcb2c7a384602f69 Mon Sep 17 00:00:00 2001 From: Jonathan Date: Fri, 4 Feb 2022 23:02:28 +0000 Subject: [PATCH 07/18] adding density option to CI --- .circleci/config.yml | 2 +- build.sh | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) create mode 100644 build.sh diff --git a/.circleci/config.yml b/.circleci/config.yml index f987d25..edc08b6 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -18,7 +18,7 @@ jobs: - run: name: install command: - pip install .[density] + pip install .[density,tests] # run tests! - run: diff --git a/build.sh b/build.sh new file mode 100644 index 0000000..8c43946 --- /dev/null +++ b/build.sh @@ -0,0 +1,2 @@ +python3 -m pip install --upgrade build +python3 -m build From 3eebdef20bba65c1f3da3a4421c1b3d155be2939 Mon Sep 17 00:00:00 2001 From: Jonathan Shimwell Date: Fri, 4 Feb 2022 23:02:51 +0000 Subject: [PATCH 08/18] added twine check --- .github/workflows/python-publish.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/python-publish.yml b/.github/workflows/python-publish.yml index d187fc5..ac5bbec 100644 --- a/.github/workflows/python-publish.yml +++ b/.github/workflows/python-publish.yml @@ -36,4 +36,5 @@ jobs: TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }} run: | python -m build + twine check dist/* twine upload dist/* From 3894f3e3e18ddb96b8ca88808d5b4c9e8c54eb89 Mon Sep 17 00:00:00 2001 From: Jonathan Date: Fri, 4 Feb 2022 23:22:20 +0000 Subject: [PATCH 09/18] updated install to include [density] --- MANIFEST.in | 4 ---- README.md | 22 +++++++++++++++++----- docs/source/install.rst | 10 +++++++++- setup.cfg | 2 +- 4 files changed, 27 insertions(+), 11 deletions(-) delete mode 100644 MANIFEST.in diff --git a/MANIFEST.in b/MANIFEST.in deleted file mode 100644 index 93a4b11..0000000 --- a/MANIFEST.in +++ /dev/null @@ -1,4 +0,0 @@ -include README.md -include requirements.txt -include neutronics_material_maker/data/*.json -include LICENSE.txt \ No newline at end of file diff --git a/README.md b/README.md index a33f5e6..22dd155 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,8 @@ temperature and pressure. ## Installation +### Conda + To use the code you will need to have OpenMC installed [OpenMC](https://docs.openmc.org/en/latest/quickinstall.html). @@ -33,17 +35,27 @@ The recommended method is to install from [Conda Forge](https://conda-forge.org) which also installs all the dependencies including OpenMC. -``` +```bash +conda create --name new_env python=3.8 +conda activate new_env conda install neutronics_material_maker -c conda-forge ``` +### Pip +Alternatively the code can be easily installed using pip. This method doesn't +currently include OpenMC so that will have to be installed separately using +Conda or compiled. -Alternatively the code can be easily installed using pip (which doesn't -currently include OpenMC) - -``` +```bash pip install neutronics_material_maker ``` +To include the optional capability of calculating the density of coolants +additional packages are needed (CoolProp). A slightly modified pip install +is required in this case. +```bash +pip install "neutronics_material_maker[density]" +``` + ## Features Materials for using in neutronics codes have two main aspects; a list of diff --git a/docs/source/install.rst b/docs/source/install.rst index 374cc1d..e26e6ea 100644 --- a/docs/source/install.rst +++ b/docs/source/install.rst @@ -48,7 +48,7 @@ environment. Install (conda + pip) --------------------- -Create a new environment (Python 3.6, 3.7 or 3.8 are supported). +Create a new environment (Python 3.6, 3.7, 3.8, 3.9 are supported). .. code-block:: bash @@ -76,3 +76,11 @@ Then pip install the package. Now you should be ready to import neutronics-material-maker from your new python environment. + +To include the optional capability of calculating the density of coolants +additional packages are needed (CoolProp). A slightly modified pip install +is required in this case. + +.. code-block:: bash + + pip install "neutronics_material_maker[density]" diff --git a/setup.cfg b/setup.cfg index be47228..5872a89 100644 --- a/setup.cfg +++ b/setup.cfg @@ -26,7 +26,7 @@ project_urls = packages = find: python_requires= >=3.6 install_requires= - asteval + asteval >= 0.9.20 [options.package_data] * = *.json From 31f48f54791a5110855b7526d7b2a42b03d34c6b Mon Sep 17 00:00:00 2001 From: Jonathan Date: Fri, 4 Feb 2022 23:22:33 +0000 Subject: [PATCH 10/18] added missing section --- setup.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/setup.py b/setup.py index 434e719..1abbd06 100644 --- a/setup.py +++ b/setup.py @@ -1 +1,4 @@ import setuptools + +if __name__ == "__main__": + setuptools.setup() From 4698e1de66620417dfd054e72788bfc326683fa3 Mon Sep 17 00:00:00 2001 From: Jonathan Date: Fri, 4 Feb 2022 23:30:26 +0000 Subject: [PATCH 11/18] moved conda install openmc upwards --- .circleci/config.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index edc08b6..ea4ae40 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -17,14 +17,14 @@ jobs: - checkout - run: name: install - command: + command: | + conda install -c conda-forge openmc pip install .[density,tests] # run tests! - run: name: run tests - command: | - conda install -c conda-forge openmc + command: pytest tests -v --cov=neutronics_material_maker --cov-report term --cov-report html:htmlcov --cov-report xml --junitxml=test-reports/junit.xml - store_test_results: path: test-reports From 51388719c28a462b706263bbbe8c4517c3fce207 Mon Sep 17 00:00:00 2001 From: Jonathan Date: Tue, 15 Feb 2022 22:21:16 +0000 Subject: [PATCH 12/18] updated to openmc 0.13 --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index ea4ae40..8fd78e5 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -18,7 +18,7 @@ jobs: - run: name: install command: | - conda install -c conda-forge openmc + conda install -c conda-forge openmc==0.13.0 pip install .[density,tests] # run tests! From 3197eee95ee7cf528ee76224903a0e8d82d0198b Mon Sep 17 00:00:00 2001 From: Jonathan Date: Tue, 15 Feb 2022 22:24:34 +0000 Subject: [PATCH 13/18] updated conda image --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 8fd78e5..d333a4c 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -9,7 +9,7 @@ version: 2.1 jobs: build: docker: - - image: continuumio/miniconda3:4.9.2 + - image: continuumio/miniconda3:4.10.3 working_directory: ~/repo From f1815070005bed4689f0706356cbd04b7b2c9658 Mon Sep 17 00:00:00 2001 From: Jonathan Date: Tue, 15 Feb 2022 22:55:12 +0000 Subject: [PATCH 14/18] created python 3.8 env --- .circleci/config.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index d333a4c..0b9a085 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -18,6 +18,8 @@ jobs: - run: name: install command: | + conda create --name test_env python=3.8 + conda activate test_env conda install -c conda-forge openmc==0.13.0 pip install .[density,tests] From 75227cecb531dd881d697a28c3593d015be3922e Mon Sep 17 00:00:00 2001 From: Jonathan Date: Tue, 15 Feb 2022 23:30:02 +0000 Subject: [PATCH 15/18] removed conda env --- .circleci/config.yml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 0b9a085..fc77878 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -9,8 +9,7 @@ version: 2.1 jobs: build: docker: - - image: continuumio/miniconda3:4.10.3 - + - image: working_directory: ~/repo steps: @@ -18,8 +17,6 @@ jobs: - run: name: install command: | - conda create --name test_env python=3.8 - conda activate test_env conda install -c conda-forge openmc==0.13.0 pip install .[density,tests] From 2c1b49fc67b5fa8d53ac84da5ac52871200ba657 Mon Sep 17 00:00:00 2001 From: Jonathan Date: Tue, 15 Feb 2022 23:32:10 +0000 Subject: [PATCH 16/18] added image --- .circleci/config.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index fc77878..8fd78e5 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -9,7 +9,8 @@ version: 2.1 jobs: build: docker: - - image: + - image: continuumio/miniconda3:4.9.2 + working_directory: ~/repo steps: From 371f435efc30362cd91199b945cfe52c2c47133e Mon Sep 17 00:00:00 2001 From: Jonathan Date: Tue, 15 Feb 2022 23:34:38 +0000 Subject: [PATCH 17/18] added allow update for older debian image --- .circleci/config.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index 8fd78e5..1f177eb 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -34,5 +34,6 @@ jobs: - run: name: install curl command: + apt-get --allow-releaseinfo-change update apt-get update && apt-get -y install curl - run: curl -s https://codecov.io/bash | bash From d535d16d90946f9e80de220b1ffff1f4e4f59c21 Mon Sep 17 00:00:00 2001 From: Jonathan Date: Tue, 15 Feb 2022 23:36:46 +0000 Subject: [PATCH 18/18] added multline cmd --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 1f177eb..8ed3388 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -33,7 +33,7 @@ jobs: path: test-reports - run: name: install curl - command: + command: | apt-get --allow-releaseinfo-change update apt-get update && apt-get -y install curl - run: curl -s https://codecov.io/bash | bash