Skip to content

Improve Isotope Instantiation #505

@tjlaboss

Description

@tjlaboss

Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

"I'm always frustrated when" I want to instantiate an Isotope, but have to remember that it lives at montepy.data_inputs.isotope.Isotope. It should be a top-level object.

Also annoying is that the representation uses the "Element-Z" convention, but instantiation has to use ZAID.

Example

>>> montepy.data_inputs.isotope.Isotope("1001.00c")
Isotope('H-1.00c')

>>> Isotope('H-1.00c')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'Isotope' is not defined

>>> montepy.data_inputs.isotope.Isotope("H-1.00c")
Traceback (most recent call last):
  File "montepy/data_inputs/isotope.py", line 34, in __init__
    int(parts[0])
ValueError: invalid literal for int() with base 10: 'H-1'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "montepy/data_inputs/isotope.py", line 36, in __init__
    raise ValueError(f"ZAID: {ZAID} could not be parsed as a valid isotope")
ValueError: ZAID: H-1.00c could not be parsed as a valid isotope

Describe the solution you'd like

  • Import the Isotope class into the top-level namespace, in montepy/init.py
  • Allow instantiation from, e.g., montepy.Isotope("H-1.00c"), montepy.Isotope("H1.01c"), etc.

Additional context
Someone changed the repr in #473, but didn't bother to update __init__ accordingly.

Metadata

Metadata

Assignees

Labels

feature requestAn issue that improves the user interface.

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions