Make phase symmetry and structure immutable
In https://github.com/pyxem/orix/issues/543#issuecomment-3031781380, I suggest to set ensure a lattice compatible with the crystal system of a phase in the constructor. If the user later on changes the symmetry of a phase, this lattice may not be valid anymore. Should we then check the lattice and give an error if it is not? I say no, and instead suggest to make some attributes of a phase, such as its symmetry, immutable.
Phase attributes I mean should be immutable:
- point group
- space group
- structure
Pros:
- All validation can be done in the constructor
- User and developer knows that a phase's symmetry and lattice are consistent throughout its lifetime
Cons:
- Someone may rely on setting these attributes of a phase. Their code will break
Do anyone set any of these attributes after creation? If so, I'd say this is an antipattern, they should instead create a new phase.
Do anyone set any of these attributes after creation? If so, I'd say this is an antipattern, they should instead create a new phase.
I agree.
Glad to hear it! @CSSFrancis, do you know if set the symmetry or structure of crystal phases in pyxem or diffsims after creation?
Hmmm.
I'm not sure. Maybe if someone wanted to strain some crystal they might adjust the lattice. But that would keep the symmetry constant.
I'm not really sure of a good case. Probably better to make sure people don't accidentally break things
Yes, but they should do so by creating a new phase with a slightly different lattice. The structure attribute of the phase class was really only meant to be a storage of data given upon creation, not something you change after the phase was created.
We can make a release candidate and ask downstream packages to test against it.
I think as long as PG and SG are immutable, I could go either way on the lattice.
If you make the lattice immutable, coding up the checks becomes way easier, and you have considerably less edge cases to consider. It also makes it easier to reuse Phase objects without concern.
Exactly. Then I'll make the change.