Fusion4Energy / F4Enix

API for parsing and post-processing many MC simulations related files
Other
12 stars 10 forks source link

[BUG] - creating a Material fails with Typeerror #76

Closed shimwell closed 5 months ago

shimwell commented 5 months ago

Describe the bug Trying to make a F4enix material like this

import f4enix
f4enix_material = Material(zaids=[(3007, -0.1), (3006, -0.9)], elem='Li', name='mat1')

results in this error message

  File "/home/j/miniforge3/envs/f4enix_dev/lib/python3.11/site-packages/f4enix/input/materials.py", line 727, in __init__
    submat = submaterials[0]
             ~~~~~~~~~~~~^^^
TypeError: 'NoneType' object is not subscriptable

To Reproduce run the above code, hopefully I've understood the material class correctly

Expected behavior I was expecting to met a material object returned

Screenshots If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

dodu94 commented 5 months ago

Hello Jonathan, from the doc: image So either you express it with a natural zaid notation (1000) if you want elements, or specific zaids (1001). Do not touch the elements attribute and use mcnp naming convention for materials (like M1).

shimwell commented 5 months ago

I did try expressing it with just the zaid originally but it appears to need the elements and name as well

>>> from f4enix.input.materials import Material
>>> f4enix_material = Material(zaids=[(3007, -0.1), (3006, -0.9)])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: Material.__init__() missing 2 required positional arguments: 'elem' and 'name'

Thanks for taking a look

dodu94 commented 5 months ago

Yeah creating a material from the init is not straightforward due to historical reason. There are a bunch of class constructor method though if you check the doc I am using the Material.from_zaids() method and not the init