# Issues Fetching Nuclide Concentration from Depleted Results

**URL:** <https://openmc.discourse.group/t/issues-fetching-nuclide-concentration-from-depleted-results/3367>\
**Category:** User Support\
**Created:** [August 30, 2023, 3:24am UTC](https://openmc.discourse.group/t/issues-fetching-nuclide-concentration-from-depleted-results/3367 "2023-08-30T03:24:16Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Daedalus](https://yyz2.discourse-cdn.com/free1/user_avatar/openmc.discourse.group/daedalus/32/2928_2.png) [@Daedalus](https://openmc.discourse.group/u/Daedalus)\
**Post date:** [August 30, 2023, 3:24am UTC](https://openmc.discourse.group/t/issues-fetching-nuclide-concentration-from-depleted-results/3367/1 "2023-08-30T03:24:16Z")

</div>

I’ve been trying to use the .get\_atoms function from the depletion module, but I haven’t managed to get it working. I’ve tried dozens of versions of the code to fetch the data, but all of them fail. The error changes, but always has to do with the specifications being passed within the parenthesis. It also seems to think something is out of place or simply returns a “KeyError” otherwise. The snippet of the code is included below.

results = openmc.deplete.Results(‘depletion\_results.h5’)

time, u235 = results.get\_atoms(“1”, ‘U235’, nuc\_units=‘atom/b-cm’, time\_units=‘d’)

print(u235)

---

<div class="post-metadata">

**Author:** ![Shimwell](https://yyz2.discourse-cdn.com/free1/user_avatar/openmc.discourse.group/shimwell/32/3876_2.png) [@Shimwell](https://openmc.discourse.group/u/Shimwell)\
**Post date:** [August 30, 2023, 9:23am UTC](https://openmc.discourse.group/t/issues-fetching-nuclide-concentration-from-depleted-results/3367/2 "2023-08-30T09:23:40Z")

</div>

There is a part of the source code where it looks up the mat\_id and nuc in the results object and if not found it would return a key error.

Are you able to post the whole error message so I can check

I suspect it is this line of the source code raises the keyerror, when it does not find the nuc or the material id

> <https://github.com/openmc-dev/openmc/blob/eea52238dac0162a8b7924b81800af4a3c78798e/openmc/deplete/results.py#L201>

---

<div class="post-metadata">

**Author:** ![Daedalus](https://yyz2.discourse-cdn.com/free1/user_avatar/openmc.discourse.group/daedalus/32/2928_2.png) [@Daedalus](https://openmc.discourse.group/u/Daedalus)\
**Post date:** [August 30, 2023, 8:06pm UTC](https://openmc.discourse.group/t/issues-fetching-nuclide-concentration-from-depleted-results/3367/3 "2023-08-30T20:06:20Z")

</div>

File “core.py”, line 3592, in   
time, u235 = results.get\_atoms(“1”, ‘U235’, nuc\_units=‘atom/b-cm’, time\_units=‘d’)  
File “/home/rmclem/miniconda3/envs/openmc-py3.7/lib/python3.7/site-packages/openmc/deplete/results.py”, line 147, in get\_atoms  
concentrations[i] = result[0, mat\_id, nuc]  
File “/home/rmclem/miniconda3/envs/openmc-py3.7/lib/python3.7/site-packages/openmc/deplete/stepresult.py”, line 104, in **getitem**  
mat = self.index\_mat[mat]  
KeyError: ‘1’

---

<div class="post-metadata">

**Author:** ![Daedalus](https://yyz2.discourse-cdn.com/free1/user_avatar/openmc.discourse.group/daedalus/32/2928_2.png) [@Daedalus](https://openmc.discourse.group/u/Daedalus)\
**Post date:** [September 8, 2023, 1:14am UTC](https://openmc.discourse.group/t/issues-fetching-nuclide-concentration-from-depleted-results/3367/4 "2023-09-08T01:14:34Z")

</div>

For anyone reading this in the future, an alternative if you can’t get this to work either is to use the following code:

results = openmc.deplete.Results(‘depletion\_results.h5’)

materials\_dep = results.export\_to\_materials(1) # 1 is for 1 step depletion, 0 would be fresh

materials\_dep.export\_to\_xml()

This generates a new materials.xml file containing the depleted materials which can be used to check compositions. There are some quirks to using this though, primarily the “atomic percents” listed in the compositions don’t add to 1 or anything close to it for the depleted materials. The values are consistently arbitrary.

---

<div class="post-metadata">

**Author:** ![Shimwell](https://yyz2.discourse-cdn.com/free1/user_avatar/openmc.discourse.group/shimwell/32/3876_2.png) [@Shimwell](https://openmc.discourse.group/u/Shimwell)\
**Post date:** [September 9, 2023, 7:30am UTC](https://openmc.discourse.group/t/issues-fetching-nuclide-concentration-from-depleted-results/3367/5 "2023-09-09T07:30:40Z")

</div>

A more helpful error messages merged into openmc. Should help identify the available keys instead of just a keyerror messages

> <https://github.com/openmc-dev/openmc/pull/2674>
>
> \# Description
> 
> Inspired by \[this user story\](https://openmc.discourse.group/t/…issues-fetching-nuclide-concentration-from-depleted-results/3367)
> 
> This PR proposes adding to the error message that a user gets when trying to access a material id in the StepResult.get\_material() that is not present.
> 
> 
> \`\`\`python
> import openmc
> import openmc.deplete
> results = openmc.deplete.Results.from\_hdf5('depletion\_results.h5')
> step=results\[0\]
> step.get\_material('42')
> \`\`\`
> 
> current behaviour
> \`\`\`
> \>\>\> KeyError: '42'
> \`\`\`
> proposed behaviour
> \`\`\`
> KeyError: "mat\_id '42' not found in StepResult. Available mat\_id values are \['1', '2', '3'\]"
> \`\`\`
> 
> \# Checklist
> 
> \- \[x\] I have performed a self-review of my own code
> \<s\> - \[\] I have run \[clang-format\](https://docs.openmc.org/en/latest/devguide/styleguide.html#automatic-formatting) on any C++ source files (if applicable)\</s\>
> \- \[x\] I have followed the \[style guidelines\](https://docs.openmc.org/en/latest/devguide/styleguide.html#python) for Python source files (if applicable)
> \- \[x\] I have made corresponding changes to the documentation (if applicable)\</s\>
> \<s\>- \[\] I have added tests that prove my fix is effective or that my feature works (if applicable)\<\\s\>

---

<div class="post-metadata">

**Author:** ![Daedalus](https://yyz2.discourse-cdn.com/free1/user_avatar/openmc.discourse.group/daedalus/32/2928_2.png) [@Daedalus](https://openmc.discourse.group/u/Daedalus)\
**Post date:** [September 9, 2023, 11:48pm UTC](https://openmc.discourse.group/t/issues-fetching-nuclide-concentration-from-depleted-results/3367/6 "2023-09-09T23:48:07Z")

</div>

Correction: The units in the exported materials.xml file are in units of atoms/barn-cm.
