# How to indicate cross section data

**URL:** <https://openmc.discourse.group/t/how-to-indicate-cross-section-data/489>\
**Category:** User Support\
**Created:** [October 4, 2019, 2:19pm UTC](https://openmc.discourse.group/t/how-to-indicate-cross-section-data/489 "2019-10-04T14:19:02Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Javier\_Gonzalez](https://yyz2.discourse-cdn.com/free1/user_avatar/openmc.discourse.group/javier_gonzalez/32/1095_2.png) [@Javier\_Gonzalez](https://openmc.discourse.group/u/Javier_Gonzalez)\
**Post date:** [October 4, 2019, 2:19pm UTC](https://openmc.discourse.group/t/how-to-indicate-cross-section-data/489/1 "2019-10-04T14:19:02Z")

</div>

Hello guys,

I’m a new user of OpenMC and also I have few experience with Ubuntu. I installed OpenMC via conda-forge.

I’m trying to run the first example “Modeling a Pin Cell”, however, although I read the Cross Section Configuration guide, I do not fully understand how to indicate in the input file where the cross section data can be found. So, I would like to know how to do that. I do not want to set an environment variable.

If useful, the OpenMC’s Python API is in ‘/home/anaconda3/bin/’. The nuclear data, downloaded from [openmc.org](http://openmc.org), is in the directory ‘/home/Documens/OpenMC/NuclearData/’.

I also want to know if it is not a problem to use Spyder to create the input files.

Thanks in advance for your help.

---

<div class="post-metadata">

**Author:** ![paulromano](https://yyz2.discourse-cdn.com/free1/user_avatar/openmc.discourse.group/paulromano/32/486_2.png) [@paulromano](https://openmc.discourse.group/u/paulromano)\
**Post date:** [October 4, 2019, 2:32pm UTC](https://openmc.discourse.group/t/how-to-indicate-cross-section-data/489/2 "2019-10-04T14:32:31Z")

</div>

Hi Javier,

If you don’t want to set the OPENMC\_CROSS\_SECTIONS environment variable, you can use Materials.cross\_sections to achieve same thing. So it would look something like:

mats = openmc.Materials([mat1, mat2, …])  
mats.cross\_sections =   
mats.export\_to\_xml()

One other note to make is that the version that is currently available on conda-forge (0.10) will not work with the data uploaded on [openmc.org](http://openmc.org), which is intended for our next release. You can download an ENDF/B-VII.1 based library that will work with 0.10 here: [https://anl.box.com/s/8uwvqh1fkpsys82n54ks39ou8ji222is](https://anl.box.com/s/8uwvqh1fkpsys82n54ks39ou8ji222is)

Best,  
Paul

---

<div class="post-metadata">

**Author:** ![shimon](https://avatars.discourse-cdn.com/v4/letter/s/59ef9b/32.png) [@shimon](https://openmc.discourse.group/u/shimon)\
**Post date:** [October 7, 2020, 2:21pm UTC](https://openmc.discourse.group/t/how-to-indicate-cross-section-data/489/3 "2020-10-07T14:21:34Z")

</div>

Sorry for digging up this old thread, but I am in need of some clarification…

I have tried to specify the cross sections via openmc.Materials like you said, but it never seemed to work, and the path will not end up in the materials.xml file.

OpenMC complains that the cross sections are not present.

Currently using 0.12

Thanks in advance,  
Simon

---

<div class="post-metadata">

**Author:** ![Javier\_Gonzalez](https://yyz2.discourse-cdn.com/free1/user_avatar/openmc.discourse.group/javier_gonzalez/32/1095_2.png) [@Javier\_Gonzalez](https://openmc.discourse.group/u/Javier_Gonzalez)\
**Post date:** [October 7, 2020, 2:38pm UTC](https://openmc.discourse.group/t/how-to-indicate-cross-section-data/489/4 "2020-10-07T14:38:32Z")

</div>

Hi Simon,

When you specify the path to the cross sections, did you include the “cross\_sections.xml”?. Something like this:

materials = openmc.Materials([mat1, mat2, …])  
materials.cross\_sections = ‘/path/to/nucleardata/cross\_sections.xml’  
materials.export\_to\_xml()

Hope this helps.  
Javier

---

<div class="post-metadata">

**Author:** ![shimon](https://avatars.discourse-cdn.com/v4/letter/s/59ef9b/32.png) [@shimon](https://openmc.discourse.group/u/shimon)\
**Post date:** [October 7, 2020, 3:19pm UTC](https://openmc.discourse.group/t/how-to-indicate-cross-section-data/489/5 "2020-10-07T15:19:51Z")

</div>

Yes, I included the complete path, but it still does not get exported

Thanks for the reminder,  
Simon

---

<div class="post-metadata">

**Author:** ![Javier\_Gonzalez](https://yyz2.discourse-cdn.com/free1/user_avatar/openmc.discourse.group/javier_gonzalez/32/1095_2.png) [@Javier\_Gonzalez](https://openmc.discourse.group/u/Javier_Gonzalez)\
**Post date:** [October 7, 2020, 3:21pm UTC](https://openmc.discourse.group/t/how-to-indicate-cross-section-data/489/6 "2020-10-07T15:21:59Z")

</div>

Okay, could you share a picture of the script and/or the error shown?

---

<div class="post-metadata">

**Author:** ![shimon](https://avatars.discourse-cdn.com/v4/letter/s/59ef9b/32.png) [@shimon](https://openmc.discourse.group/u/shimon)\
**Post date:** [October 7, 2020, 3:33pm UTC](https://openmc.discourse.group/t/how-to-indicate-cross-section-data/489/7 "2020-10-07T15:33:21Z")

</div>

The skript goes like this:

> materials\_file = openmc.Materials([fuel, heavy\_water, cladding,  
> ss316, u\_depleted, lead, cadmium,  
> polyethylene])  
> materials\_file.cross\_sections = ‘path/to/cross\_sections.xml’  
> materials\_file.export\_to\_xml()

The resulting XML file does not contain the path.

Accordingly, I get the following error from OpenMC:

> ERROR: No cross\_sections.xml file was specified in materials.xml or in the  
> OPENMC\_CROSS\_SECTIONS environment variable. OpenMC needs such a file to  
> identify where to find data libraries. Please consult the user’s guide  
> at [https://docs.openmc.org/](https://docs.openmc.org/) for information on how to set up data  
> libraries.

---

<div class="post-metadata">

**Author:** ![Javier\_Gonzalez](https://yyz2.discourse-cdn.com/free1/user_avatar/openmc.discourse.group/javier_gonzalez/32/1095_2.png) [@Javier\_Gonzalez](https://openmc.discourse.group/u/Javier_Gonzalez)\
**Post date:** [October 7, 2020, 3:52pm UTC](https://openmc.discourse.group/t/how-to-indicate-cross-section-data/489/8 "2020-10-07T15:52:20Z")

</div>

Humm, very weird. Well, another option is to include manually the path in the “materials.xml”. If you would like to share the part of your script where you specify the materials, I could check it!

Javier

---

<div class="post-metadata">

**Author:** ![paulromano](https://yyz2.discourse-cdn.com/free1/user_avatar/openmc.discourse.group/paulromano/32/486_2.png) [@paulromano](https://openmc.discourse.group/u/paulromano)\
**Post date:** [October 7, 2020, 8:51pm UTC](https://openmc.discourse.group/t/how-to-indicate-cross-section-data/489/9 "2020-10-07T20:51:05Z")

</div>

@shimon Do you actually see the cross\_sections.xml path inside of the generated `materials.xml` file?

---

<div class="post-metadata">

**Author:** ![shimon](https://avatars.discourse-cdn.com/v4/letter/s/59ef9b/32.png) [@shimon](https://openmc.discourse.group/u/shimon)\
**Post date:** [October 8, 2020, 8:18am UTC](https://openmc.discourse.group/t/how-to-indicate-cross-section-data/489/10 "2020-10-08T08:18:56Z")

</div>

No, the materials.xml does not contain any path.

Also, contrary to what I initially said, element expansion does NOT work without setting the OPENMC\_CROSS\_SECTIONS variable. How would you use element expansion without the environment variable?  
(edit) ok, I think I figured element expansion out. I had set the path using “openmc.Materials.cross\_sections = cross\_sections\_path”, but appearantly there was still an $OPENMC\_CROSS\_SECTIONS in the environment which took precedence. After unsetting OPENMC\_CROSS\_SECTIONS, element expansion works.

Thanks,  
Simon

---

<div class="post-metadata">

**Author:** ![shimon](https://avatars.discourse-cdn.com/v4/letter/s/59ef9b/32.png) [@shimon](https://openmc.discourse.group/u/shimon)\
**Post date:** [October 8, 2020, 11:46am UTC](https://openmc.discourse.group/t/how-to-indicate-cross-section-data/489/11 "2020-10-08T11:46:40Z")

</div>

A curious addition: It seems to work if I put

> `my_materials._cross_sections = 'cross_sections_path'`  
> `my_materials.export_to_xml()`

Then, materials.xml contains the path, and OpenMC runs. I found this out by checking the output of of `my_materials. __dict__ ` which reads:

> ```
> {'expected_type': openmc.material.Material,
> 'name': 'materials collection',
> '_cross_sections': None}
> 
> ```

What is happening here? The cross\_sections attribute is private after instantiation? Is it just me not knowing enough about Python?

(edit)  
For the sake of clarity, let me expand a bit.  
If I put

> `my_materials.cross_sections = 'cross_sections_path'`  
> `my_materials.export_to_xml()`

then `my_materials. __dict__ ` says

> ```
> {'expected_type': openmc.material.Material,
> 'name': 'materials collection',
> '_cross_sections': None,
> 'cross_sections': 'cross_sections_path'}
> 
> ```

and materials.xml does not contain the path.

---

<div class="post-metadata">

**Author:** ![Javier\_Gonzalez](https://yyz2.discourse-cdn.com/free1/user_avatar/openmc.discourse.group/javier_gonzalez/32/1095_2.png) [@Javier\_Gonzalez](https://openmc.discourse.group/u/Javier_Gonzalez)\
**Post date:** [October 8, 2020, 5:38pm UTC](https://openmc.discourse.group/t/how-to-indicate-cross-section-data/489/12 "2020-10-08T17:38:50Z")

</div>

I have never had that issue, @shimon. No idea what to do.

---

<div class="post-metadata">

**Author:** ![paulromano](https://yyz2.discourse-cdn.com/free1/user_avatar/openmc.discourse.group/paulromano/32/486_2.png) [@paulromano](https://openmc.discourse.group/u/paulromano)\
**Post date:** [October 14, 2020, 9:30pm UTC](https://openmc.discourse.group/t/how-to-indicate-cross-section-data/489/13 "2020-10-14T21:30:10Z")

</div>

Yeah, not sure what’s going with the last issue with the `_cross_sections` attribute. Setting `my_materials.cross_sections` is the right way to do this and should work (I wasn’t able to reproduce the behavior you’re seeing).

Regarding element expansion, generally you do need to rely on the `OPENMC_CROSS_SECTIONS` environment variable as opposed to `materials.cross_sections`. The reason is that at the time you call `mat.add_element(...)`, the `mat` object doesn’t know anything about the `cross_sections` attribute you’ve set on another object. One potential way around this is the following:

```auto
zr = openmc.Element('Zr')
expanded = zr.expand(density, 'ao', cross_sections='cross_sections_path')

mat = openmc.Material()
for isotope, percent, percent_type in expanded:
    mat.add_element(isotope, percent, percent_type)

```

As you see, when you directly expand an element, you _can_ pass it a path to a cross sections file. Perhaps we ought to allow a similar specification in `Material.add_element`.

---

<div class="post-metadata">

**Author:** ![shimon](https://avatars.discourse-cdn.com/v4/letter/s/59ef9b/32.png) [@shimon](https://openmc.discourse.group/u/shimon)\
**Post date:** [October 15, 2020, 10:28am UTC](https://openmc.discourse.group/t/how-to-indicate-cross-section-data/489/14 "2020-10-15T10:28:51Z")

</div>

Thanks for the helpful comments!

I think I will give up trying to do this without an environment variable.

Setting an environment variable programatically works, e.g. in Jupyter I can just use  
`%env OPENMC_CROSS_SECTIONS $cross_sections_path`

---

<div class="post-metadata">

**Author:** ![neonnuke](https://yyz2.discourse-cdn.com/free1/user_avatar/openmc.discourse.group/neonnuke/32/1079_2.png) [@neonnuke](https://openmc.discourse.group/u/neonnuke)\
**Post date:** [November 3, 2020, 8:10pm UTC](https://openmc.discourse.group/t/how-to-indicate-cross-section-data/489/15 "2020-11-03T20:10:50Z")

</div>

All, I am having the same issue. I want to specify the path to my cross section library, but it never ends up in the materials.xml file. I can edit the materials.xml file by hand (or write a script to do that) and insert the cross section line, but that sort of defeats the purpose of the python api.

I have tried every which way I can think of to specify the path to the cross sections I want to use. I prefer to not do this with an environment variable so that I could more explicitly run a sensitivity study on different cross section sets.

I am playing with the assembly example file and have the source codes of interest available (being a new user I cannot upload). I have been compiling with the command:

python3 assembly.py --generate

Here is the assembly source code of interest:

# Define materials

fuel = openmc.Material(name=‘Fuel’)  
fuel.set\_density(‘g/cm3’, 10.29769)  
fuel.add\_nuclide(‘U234’, 4.4843e-6)  
fuel.add\_nuclide(‘U235’, 5.5815e-4)  
fuel.add\_nuclide(‘U238’, 2.2408e-2)  
fuel.add\_nuclide(‘O16’, 4.5829e-2)

clad = openmc.Material(name=‘Cladding’)  
clad.set\_density(‘g/cm3’, 6.55)  
clad.add\_nuclide(‘Zr90’, 2.1827e-2)  
clad.add\_nuclide(‘Zr91’, 4.7600e-3)  
clad.add\_nuclide(‘Zr92’, 7.2758e-3)  
clad.add\_nuclide(‘Zr94’, 7.3734e-3)  
clad.add\_nuclide(‘Zr96’, 1.1879e-3)

hot\_water = openmc.Material(name=‘Hot borated water’)  
hot\_water.set\_density(‘g/cm3’, 0.740582)  
hot\_water.add\_nuclide(‘H1’, 4.9457e-2)  
hot\_water.add\_nuclide(‘O16’, 2.4672e-2)  
hot\_water.add\_nuclide(‘B10’, 8.0042e-6)  
hot\_water.add\_nuclide(‘B11’, 3.2218e-5)  
hot\_water.add\_s\_alpha\_beta(‘c\_H\_in\_H2O’)

openmc.Materials.cross\_sections = ‘/home/neonnuke/openmc/xsecs/endfb80\_hdf5/cross\_sections.xml’

And here is the materials.xml file without the line needed:

\<?xml version='1.0' encoding='utf-8'?\> 

… etcetera

And I can get it to run with openmc by inserting the line:

\<cross\_sections\>/home/neonnuke/openmc/xsecs/endfb80\_hdf5/cross\_sections.xml\</cross\_sections\>

right after the materials tag.

---

<div class="post-metadata">

**Author:** ![Javier\_Gonzalez](https://yyz2.discourse-cdn.com/free1/user_avatar/openmc.discourse.group/javier_gonzalez/32/1095_2.png) [@Javier\_Gonzalez](https://openmc.discourse.group/u/Javier_Gonzalez)\
**Post date:** [November 3, 2020, 8:16pm UTC](https://openmc.discourse.group/t/how-to-indicate-cross-section-data/489/16 "2020-11-03T20:16:26Z")

</div>

Hi,

Doing the following is not working?

materials = openmc.Materials([mat1, mat2, …])  
materials.cross\_sections = ‘/path/to/nucleardata/cross\_sections.xml’  
materials.export\_to\_xml()

---

<div class="post-metadata">

**Author:** ![neonnuke](https://yyz2.discourse-cdn.com/free1/user_avatar/openmc.discourse.group/neonnuke/32/1079_2.png) [@neonnuke](https://openmc.discourse.group/u/neonnuke)\
**Post date:** [November 3, 2020, 8:21pm UTC](https://openmc.discourse.group/t/how-to-indicate-cross-section-data/489/17 "2020-11-03T20:21:05Z")

</div>

> [@Javier\_Gonzalez](#):
>
> materials = openmc.Materials([mat1, mat2, …])

I gave it a try with the following lines:

materials = openmc.Materials([fuel, clad, hot\_water])  
#openmc.Materials.cross\_sections = ‘/home/neonnuke/openmc/xsecs/endfb80\_hdf5/cross\_sections.xml’  
materials.cross\_sections = ‘/home/neonnuke/openmc/xsecs/endfb80\_hdf5/cross\_sections.xml’  
materials.export\_to\_xml()

And no cross section path. Now, should I still be using the same python command? The /examples/assembly directory has no export\_to\_xml for the materials list.

---

<div class="post-metadata">

**Author:** ![Javier\_Gonzalez](https://yyz2.discourse-cdn.com/free1/user_avatar/openmc.discourse.group/javier_gonzalez/32/1095_2.png) [@Javier\_Gonzalez](https://openmc.discourse.group/u/Javier_Gonzalez)\
**Post date:** [November 3, 2020, 8:27pm UTC](https://openmc.discourse.group/t/how-to-indicate-cross-section-data/489/18 "2020-11-03T20:27:47Z")

</div>

If you are new with OpenMC, I recommend taking a look at the [Examples](https://docs.openmc.org/en/stable/examples/index.html#examples). There it is very well explained every step to create your input.

If you are using this [Python API](https://docs.openmc.org/en/stable/_modules/openmc/examples.html#pwr_assembly), I guess the way of defining the path to the cross sections should be similar

---

<div class="post-metadata">

**Author:** ![neonnuke](https://yyz2.discourse-cdn.com/free1/user_avatar/openmc.discourse.group/neonnuke/32/1079_2.png) [@neonnuke](https://openmc.discourse.group/u/neonnuke)\
**Post date:** [November 3, 2020, 8:41pm UTC](https://openmc.discourse.group/t/how-to-indicate-cross-section-data/489/19 "2020-11-03T20:41:57Z")

</div>

Thanks for the input Javier. I will continue playing with it and referencing the different example files available.

---

<div class="post-metadata">

**Author:** ![neonnuke](https://yyz2.discourse-cdn.com/free1/user_avatar/openmc.discourse.group/neonnuke/32/1079_2.png) [@neonnuke](https://openmc.discourse.group/u/neonnuke)\
**Post date:** [November 3, 2020, 9:21pm UTC](https://openmc.discourse.group/t/how-to-indicate-cross-section-data/489/20 "2020-11-03T21:21:08Z")

</div>

Ah-Ha!!! I have localized the source of the problem - I still do not have an idea about what is going on, but here is what I have found.

When I insert the lines Javier recommended:

materials = openmc.Materials([fuel, clad, hot\_water])  
#openmc.Materials.cross\_sections = ‘/home/neonnuke/openmc/xsecs/endfb80\_hdf5/cross\_sections.xml’  
materials.cross\_sections = ‘/home/neonnuke/openmc/xsecs/endfb80\_hdf5/cross\_sections.xml’  
materials.export\_to\_xml()

**And** I use the compile **without** --generate **or** --run flags, I get a materials.xml file that includes my cross section path. “python3 input\_file”

Now, if I change **absolutely nothing** about the input, but use either the --generate or --run flags, the cross\_section path is **not included** in the materials.xml file. “python3 input\_file --generate”

So it is something with the generate or run interaction. Or maybe with the looping that occurs if you do not specify export\_to\_xml for the materials explicitly.

Here is the lame work-around, you have to add the materials.export statement and then compile twice then execute openmc standalone:

python3 assembly.py --generate;python3 assembly.py;openmc

[Next page](https://openmc.discourse.group/t/how-to-indicate-cross-section-data/489.md?page=2)
