# Toggle Function IUPAC 2009/2013 data (data.py NATURAL\_ABUNDANCE)

**URL:** <https://openmc.discourse.group/t/toggle-function-iupac-2009-2013-data-data-py-natural-abundance/3100>\
**Category:** Development\
**Created:** [June 15, 2023, 12:00am UTC](https://openmc.discourse.group/t/toggle-function-iupac-2009-2013-data-data-py-natural-abundance/3100 "2023-06-15T00:00:32Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jmau](https://avatars.discourse-cdn.com/v4/letter/j/ba9def/32.png) [@jmau](https://openmc.discourse.group/u/jmau)\
**Post date:** [June 15, 2023, 12:00am UTC](https://openmc.discourse.group/t/toggle-function-iupac-2009-2013-data-data-py-natural-abundance/3100/1 "2023-06-15T00:00:32Z")

</div>

Hi everyone,

My desired PR correction is to toggled changing the default Isotopic compositions between IUPAC-2009 and IUPAC-2013. This toggle should be selectable in the API interface and then steer the API to which abundance data to use.

The IUPAC-2013 data should use IUPAC-2013 column 9 and when column 9 is an interval it should use the mean of the given interval _NOT_ the value from IUPAC-2013 column 6. This data differs from what is currently in OpenMC main.

I am sure that IUPAC-2013 will be the default data.

Here is what I have so far with my brain storming on how to accomplish this and want a second opinion on it.

Explanation of my code: I am trying to make a python api function for the material.xml creation of Material.version(). I then place this into the material.xml file. Then this is read by the C++ code materials.cpp and materials.h . My dilemma is how to get the version material.cpp object variable to the data.py and what is the order by which the code is read. I don’t want just to cython a variable over if the data.py is already compiled without the version variable not implemented yet.

**openmc/openmc/data/data.py**

Insert following at line 114  
NATURAL\_ABUNDANCE\_2009 = {…} //Hard coded data like for NATURAL\_ABUNDANCE

**openmc/openmc/material.py**

Replace the following at line 113

def **init** (self, material\_id=None, name=‘’, temperature=None, **version=2013** ):

Insert the following at line 127  
self.\_version = version

Instert following at line 236

@property  
def version(self) → Optional[int]:  
return self.\_version

Insert following at line 269

@version.setter  
def version(self, version: Optional[int]):  
if version is 2009:  
cv.check\_type(‘version for Material ID=“{}”’.format(self.\_id), version, int)  
self.\_version = version  
else:  
self.\_version = 2013

Insert following at line 1337

```
if self.version is 2013:
    element.set("version", str(self.version))

```

**openmc/include/ompenmc/material.h**

Insert the following at line 164

//! Get the version of the abundance data  
//! \return version of the abundance data  
int version() const { return version\_; }

//! Set the version of the abundance data  
//! \param[in] version version of the abundance data  
void set\_version(int version) { version\_ = version; }

Insert the following at line 212

//verions for abundance data  
int version\_;

**openmc/src/material.cpp**

Insert the following at line 119

if (check\_for\_node(material\_node, “version”)) {  
this-\>set\_version(std::stoi(get\_node\_value(material\_node, “version”)));  
}

Insert the following at line 375

mat-\>version\_ = version\_;

**Your suggestions and thoughts are most appreciated.**

---

<div class="post-metadata">

**Author:** ![yrrepy](https://yyz2.discourse-cdn.com/free1/user_avatar/openmc.discourse.group/yrrepy/32/2365_2.png) [@yrrepy](https://openmc.discourse.group/u/yrrepy)\
**Post date:** [June 16, 2023, 1:25am UTC](https://openmc.discourse.group/t/toggle-function-iupac-2009-2013-data-data-py-natural-abundance/3100/2 "2023-06-16T01:25:13Z")

</div>

FYI for others, please read the background to this development in issue:

> <https://github.com/openmc-dev/openmc/issues/2423>
>
> Hello,
> 
> I believe the approach adopted for natural isotopic abundance in Data.…py in the link below was incorrect.
> https://github.com/openmc-dev/openmc/pull/785
> 
> That is, selecting column 6 of IUPAC 2013 when an interval is present in column 9. 
> Column 6 gives you a number that is considered an outstanding measurement for a particular material. But is not necessarily representative of what will be encountered terrestrially for any given element. I guess ideally this would be some sort of mode or median.
> 
> I believe a better approach would be either:
> 1. revert to IUPAC 2009 and use it's column 9
> 2. continue with IUPAC 2013 but when an interval is present in column 9, use the average (mean) over the interval.
> 
> I suppose as another alternative, we could make this file (approach) user selectable.
> 
>  
> 
> Below, is the approach adopted elsewhere.
> 
> \-------------------------------
> \### 1. IUPAC 2009 column 9 (D2=0.0115% of H)
> 
> \- NIST; https://physics.nist.gov/cgi-bin/Compositions/stand\_alone.pl?ele=
> \- RSC Periodic Table; https://www.rsc.org/periodic-table/
> \- JAEA 2014; https://wwwndc.jaea.go.jp/CN14/index.html, https://wwwndc.jaea.go.jp/cgi-bin/nucltab14?01
> \- Brookhaven/NuDat 3.0; https://www.nndc.bnl.gov/nudat3/
> \- OECD/NEA JANIS; https://www.oecd-nea.org/jcms/pl\_39910/janis
> \- PNNL Materials Compendium 3; https://www.osti.gov/servlets/purl/1782721
> \- Nubase2016; https://www-nds.iaea.org/amdc/ame2016/nubase2016.txt
> \- pyne; https://github.com/pyne/pyne/blob/develop/pyne/dbgen/abundances.txt
> \- FISPACT-II v5.0; https://fispact.ukaea.uk/wp-content/uploads/2021/05/api\_manual.pdf
> 
> \-------------------------------
> \### 2. IUPAC 2013 column 9, w/Interval mean (D2=0.0145% of H)
> 
> \- IAEA; https://www-nds.iaea.org/relnsd/vcharthtml/VChartHTML.html
> \- Atomic Massa Data Center/AME2020/Nubase2020; https://www.anl.gov/sites/www/files/2022-11/nubase\_4.mas20.txt
> 
> \-------------------------------
> 
> I have not seen any source that uses IUPAC 2013 column 6 (D2=0.0156% of H)
> Please see attached my correspondence with the primary author of IUPAC 2013, which doesn't really give any specific recommendations (they would probably prefer that we all used some sort of interval, I presume).
> \[RE\_ IUPAC Isotopic Compositions Column 9.zip\](https://github.com/openmc-dev/openmc/files/10972005/RE\_.IUPAC.Isotopic.Compositions.Column.9.zip)
> 
> 
> 
> \#### IUPAC Technical Reports/References
> IUPAC 2009:
> https://www.degruyter.com/document/doi/10.1351/PAC-REP-10-06-02/pdf
> \[IUPAC-2009.pdf\](https://github.com/openmc-dev/openmc/files/11338036/IUPAC-2009.pdf)
> 
> IUPAC 2013:
> https://www.degruyter.com/document/doi/10.1515/pac-2015-0503/pdf
> \[IUPAC-2013.pdf\](https://github.com/openmc-dev/openmc/files/11338037/IUPAC-2013.pdf)

Perry

---

<div class="post-metadata">

**Author:** ![jmau](https://avatars.discourse-cdn.com/v4/letter/j/ba9def/32.png) [@jmau](https://openmc.discourse.group/u/jmau)\
**Post date:** [June 27, 2023, 6:42pm UTC](https://openmc.discourse.group/t/toggle-function-iupac-2009-2013-data-data-py-natural-abundance/3100/3 "2023-06-27T18:42:16Z")

</div>

Here is the update to what I have concluded to do to fix my original code:

**openmc/data/data.py**

…

version\_value = os.getenv(“IUPAC\_VERSION”)  
if not version\_value:  
version\_value = ‘2013’

if version\_value == ‘2009’:  
NATURAL\_ABUNDANCE.update(NATURAL\_ABUNDANCE\_2009)  
elif version\_value == ‘2013’:  
NATURAL\_ABUNDANCE.update(NATURAL\_ABUNDANCE\_2013)  
else:  
NATURAL\_ABUNDANCE.update(NATURAL\_ABUNDANCE\_2013)  
print(“The value you entered is not either IUPAC 2013 or 2009, defaulted to IUPAC 2013”)

…

**Python API**

import os  
**Set the environment variable**  
os.environ[“IUPAC\_VERSION”] = “2009” # or “2013”, whatever you want

import sys  
import subprocess  
sys.path.append(‘/home/jmau/Codes/OpenMC-jmau/build/bin’)  
import openmc  
import os  
import csv  
import matplotlib.pyplot as plt  
import numpy as np

**Create materials**  
materials = openmc.Materials()

**Create concrete material**  
water = openmc.Material()  
water.add\_element(‘H’, 2)  
water.add\_element(‘O’, 1)  
water.set\_density(‘g/cm3’, 0.9998395)  
water.add\_s\_alpha\_beta(‘c\_H\_in\_H2O’)

…

I have found that trying to make a xml input is counter productive due to the data.py file being compiled during the import openmc portion. In order to pass a variable to the data.py before import openmc, I made an environment variable.

---

<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:** [June 29, 2023, 12:56pm UTC](https://openmc.discourse.group/t/toggle-function-iupac-2009-2013-data-data-py-natural-abundance/3100/4 "2023-06-29T12:56:17Z")

</div>

Thanks @jmau for this proposal. For anyone that missed it, there is now a pull request open:

> <https://github.com/openmc-dev/openmc/pull/2581>
>
> \<!--
> If you are a first-time contributor to OpenMC, please have a look at our
> …contributing guidelines:
> https://github.com/openmc-dev/openmc/blob/develop/CONTRIBUTING.md
> \--\>
> 
> \# Description
> 
> Perry and I suggest that the current approach, which selects column 6 of IUPAC 2013 when an interval is present in column 9, is incorrect. We propose two alternating approaches: reverting to IUPAC 2009 and using its column 9 or continuing with IUPAC 2013 but using the average (mean) when an interval is present in column 9. 
> 
> Reference: https://github.com/openmc-dev/openmc/issues/2423
> 
> Fixes # (issue)
> 
> I made the adjustments by taking the intervals onto an excel sheet and averaged the appropriate intervals in IUPAC 2013. 
> 
> I then updated the adjusted numbers with the current data in openmc.
> 
> I took the previous data for IUPAC 2009 from previous openmc versions 
> 
> I made an environment variable that can be set in the python api before import openmc
> 
> examples:
> 
> !\[Togglepy\](https://github.com/openmc-dev/openmc/assets/95399182/76864f90-0967-4f83-9275-e5e52f75f4ad)
> 
> !\[Toggledata\](https://github.com/openmc-dev/openmc/assets/95399182/6cbe78ee-5171-4f55-af5b-f6a5d39cbb18)
> 
> 
> \# Checklist
> 
> \- \[yes\] I have performed a self-review of my own code
> \- \[\] I have run \[clang-format\](https://docs.openmc.org/en/latest/devguide/styleguide.html#automatic-formatting) on any C++ source files (if applicable)
> \- \[yes \] I have followed the \[style guidelines\](https://docs.openmc.org/en/latest/devguide/styleguide.html#python) for Python source files (if applicable)
> \- \[\] I have made corresponding changes to the documentation (if applicable)
> \- \[\] I have added tests that prove my fix is effective or that my feature works (if applicable)
> \<!--
> While tests will automatically be checked by CI, it is good practice to
> ensure that they pass locally first. See instructions here:
> https://docs.openmc.org/en/latest/devguide/tests.html
> \--\>
