diff --git a/README.md b/README.md index a3afaf1..e2bb265 100644 --- a/README.md +++ b/README.md @@ -4,22 +4,7 @@ ## Installation -`libra-toolbox` relies on Python. You can install it from the official website: [python.org](https://www.python.org/downloads/). - -Install OpenMC: - -If you want to run OpenMC functions, [install OpenMC](https://docs.openmc.org/en/stable/quickinstall.html) with conda: - -``` -conda install -c conda-forge openmc>=0.14.0 -``` - - -To install `libra-toolbox`, use pip: - -```bash -pip install git+https://github.com/LIBRA-project/libra-toolbox -``` +You can find the [installation instructions](https://libra-toolbox.readthedocs.io/en/latest/installation.html#installation) in the documentation. ## Documentation The documentation for `libra-toolbox` is built using Sphinx and is [available online](https://libra-toolbox.readthedocs.io/en/latest/). To build the documentation locally, you can use the provided Makefile or make.bat script. diff --git a/docs/installation.rst b/docs/installation.rst index c7b308d..e0821cc 100644 --- a/docs/installation.rst +++ b/docs/installation.rst @@ -21,6 +21,20 @@ To install a specific version of the code: Here, ``v0.1`` is the version number. You can replace it with the version you want to install. +To install the code in editable mode (i.e. the code is installed in the current directory and any changes to the code are immediately available to the user): + +.. code-block:: bash + + git clone https://github.com/LIBRA-project/libra-toolbox + cd libra-toolbox + pip install -e . + +To install the code alongside with the optional dependencies for the neutronics module, first [install OpenMC](https://docs.openmc.org/en/stable/quickinstall.html) with conda: + +``` +conda install -c conda-forge openmc>=0.14.0 +``` + To uninstall the package: .. code-block:: bash diff --git a/libra_toolbox/neutronics/neutron_source.py b/libra_toolbox/neutronics/neutron_source.py index a7e934d..b66da9a 100644 --- a/libra_toolbox/neutronics/neutron_source.py +++ b/libra_toolbox/neutronics/neutron_source.py @@ -5,11 +5,18 @@ from collections.abc import Iterable import pandas as pd import numpy as np -import h5py -import openmc +try: + import h5py + import openmc + from openmc import IndependentSource +except ModuleNotFoundError: + pass -def A325_generator_diamond(center=(0, 0, 0), reference_uvw=(0, 0, 1)) -> Iterable[openmc.IndependentSource]: + +def A325_generator_diamond( + center=(0, 0, 0), reference_uvw=(0, 0, 1) +) -> "Iterable[IndependentSource]": """ Builds the MIT-VaultLab A-325 neutron generator in OpenMC with data tabulated from John Ball and Shon Mackie characterization @@ -28,15 +35,20 @@ def A325_generator_diamond(center=(0, 0, 0), reference_uvw=(0, 0, 1)) -> Iterabl Returns ------- - list of openmc neutron sources with angular and energy distribution + list of openmc neutron sources with angular and energy distribution and total strength of 1 """ + try: + import h5py + import openmc + except ModuleNotFoundError: + raise ModuleNotFoundError("openmc and h5py are required") filename = "A325_generator_diamond.h5" filename = str(Path(__file__).parent) / Path(filename) with h5py.File(filename, "r") as source: - df = pd.DataFrame(source["values/table"][()]).drop(columns='index') + df = pd.DataFrame(source["values/table"][()]).drop(columns="index") # energy values energies = np.array(df["Energy (MeV)"]) * 1e6 # angle column names @@ -64,7 +76,7 @@ def A325_generator_diamond(center=(0, 0, 0), reference_uvw=(0, 0, 1)) -> Iterabl ) strength = yields[i] - my_source = openmc.Source( + my_source = openmc.IndependentSource( space=space, angle=angle, energy=energy, diff --git a/pyproject.toml b/pyproject.toml index 33f28fe..3a4f85c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -15,9 +15,10 @@ description = "Design and analysis tools for LIBRA project" license = {file = "LICENSE"} requires-python = ">=3.6" dynamic = ["version"] -dependencies = ["numpy", "pint", "scipy", "matplotlib", "sympy", "pandas", "openmc>=0.14.0", "h5py"] +dependencies = ["numpy", "pint", "scipy", "matplotlib", "sympy", "pandas"] [project.optional-dependencies] +neutronics = ["openmc>=0.14.0", "h5py"] tests = ["pytest>=5.4.3", "pytest-cov", "nbconvert", "ipykernel"] [tool.setuptools_scm] diff --git a/test/neutronics/test_neutron_source.py b/test/neutronics/test_neutron_source.py index 843b3d8..68d6f39 100644 --- a/test/neutronics/test_neutron_source.py +++ b/test/neutronics/test_neutron_source.py @@ -1,10 +1,17 @@ -from libra_toolbox.neutronics.neutron_source import * from collections.abc import Iterable +from libra_toolbox.neutronics.neutron_source import A325_generator_diamond + +import pytest + def test_get_avg_neutron_rate(): + try: + import openmc + except ImportError: + pytest.skip("OpenMC is not installed") source = A325_generator_diamond((0, 0, 0), (0, 0, 1)) assert isinstance(source, Iterable) for s in source: - assert isinstance(s, openmc.IndependentSource) \ No newline at end of file + assert isinstance(s, openmc.IndependentSource)