OpenMC/openmc/nuclide.py

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

38 lines
826 B
Python
Raw Permalink Normal View History

import warnings
class Nuclide(str):
"""A nuclide that can be used in a material.
Parameters
----------
name : str
2017-07-31 08:18:55 -05:00
Name of the nuclide, e.g. 'U235'
Attributes
----------
name : str
2017-07-31 08:18:55 -05:00
Name of the nuclide, e.g. 'U235'
"""
def __new__(cls, name):
# Initialize class attributes
orig_name = name
if '-' in name:
name = name.replace('-', '')
name = name.replace('Nat', '0')
if name.endswith('m'):
name = name[:-1] + '_m1'
msg = ('OpenMC nuclides follow the GNDS naming convention. '
2021-07-31 22:33:45 +01:00
f'Nuclide "{orig_name}" is being renamed as "{name}".')
warnings.warn(msg)
2017-12-24 16:34:25 +07:00
return super().__new__(cls, name)
@property
def name(self):
return self