Skip to content

Conversation

@shimwell
Copy link
Member

@shimwell shimwell commented Nov 21, 2025

Description

It have just added a minimal set of extra options to the Material constructor to allow a material to made from the constructor.

This is useful to myself as I have a json representation of the material and going to a material object is easier with this addition. It also follows on some work @eepeterson and myself were doing trying to allow more classes to be construct-able from the constructor.

Fixes # (issue)

Checklist

  • I have performed a self-review of my own code
  • I have followed the style guidelines 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)

@shimwell
Copy link
Member Author

shimwell commented Nov 24, 2025

edited this PR
I had originally added nuclides to the constructor but have now removed that as there are a few ways go about the addition of elements/nuclides and I would now like to do that in a follow up PR to keep this one as minimal as possible. I think this makes it easier to consider for merging.

Copy link
Contributor

@paulromano paulromano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having objects be in a fully valid state after calling __init__ is a good idea 👍 So, I'm supportive of the change here, but wondering if there was a reason that you didn't also add a components argument that gets passed to add_components while you were at it? That would make it truly complete.

Comment on lines 160 to 168
# Set density if provided
if (density is not None and density_units is None) or (
density is None and density_units is not None
):
raise ValueError(
"Both density and density_units must be provided together."
)
elif density is not None and density_units is not None:
self.set_density(density_units, density)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do you feel about having density_units default to "g/cm3"? In that case, the first branch of the if could just be removed.

Copy link
Member Author

@shimwell shimwell Nov 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would be happy with that density of 'g/cm3'.

If we make 'g/cm3' the default should we also make the the default units when using material.set_density() which I see defaults to None currently?

@shimwell
Copy link
Member Author

wondering if there was a reason that you didn't also add a components argument that gets passed to add_components while you were at it? That would make it truly complete.

I wasn't sure if that would be acceptable so I didn't want it blocking the PR.

I was not sure if it would be acceptable as adding_components currently needs two additional arguments, one for the dict of components and one for the percent_type. The percent_type is a bigger step as it is not a class attribute currently.

So I had a go at reducing components to a single dictionary argument with #3654 but now that PR not going ahead I the way to add components to the init is clearer but it would require adding percent_type as a class attribute.

@shimwell
Copy link
Member Author

shimwell commented Dec 1, 2025

ok tests are failing, it looks like many tests assumed the density_units were defaulting to sum so I have opted for this as the default as it was previously the default.

Wondering of we should keep density_units to sum or change them to g/cm3 and update tests accordingly?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants