New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Standardize test names: e.g. LatticeTestCase
-> TestLattice
#3693
Conversation
int
and float
in Species
and Composition
constructorint
and zero-decimal float
in Species
and Composition
constructor
tests/core/test_composition.py
Outdated
# test from int/float | ||
assert Composition(1) == Composition("H") | ||
assert Composition(2.0) == Composition("He") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
curious if anyone has thoughts on if we really want this behavior and if so, can you think of more edge cases to test. @JaGeo @Andrew-S-Rosen @shyuep @DanielYang59
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mh. I feel like in the composition case, this might be a bit too much as a composition would also include floats and ints to specify the exact composition. This could get really messy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For species, I agree that this would be useful but I am not so sure about composition.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JaGeo thanks for chiming in!
i should have mentioned the initial motivation for this change came from me noticing (and being surprised) that Structure
already handles int
(e.g. si = 14
below):
pymatgen/tests/io/vasp/test_inputs.py
Lines 383 to 392 in 48af038
si = 14 | |
coords = [[0, 0, 0], [0.75, 0.5, 0.75]] | |
# Silicon structure for testing. | |
latt = [ | |
[3.8401979337, 0.00, 0.00], | |
[1.9200989668, 3.3257101909, 0.00], | |
[0.00, -2.2171384943, 3.1355090603], | |
] | |
struct = Structure(latt, [si, si], coords) |
at that point it seems natural to expect as a user that other core classes like Composition
should do the same. at least that's the first thing i tried when i noticed Structure(species=[14])
is supported
i'm not so much worried about the code getting messy. a single int
/float
was easy to handle in the Composition
constructor. i'm more worried user expectations for what Composition(1)
should return could be inconsistent? but then i can't see what other behavior one might expect
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. If this is only implemented for single ints or floats, I think the intention should be quite clear. Thus, I agree. This should both be fine.
Thanks for pinging me here 😄 . But for me personally I think initialize a Also init a Species/Composition might be limited to single-atom Species/Composition, and this might be a very limited use case.(How to init a Species/Composition like "H2O" from I assume a helper func to convert |
I vote no on this change. I don't even understand why this is needed. |
it's easy to imagine use cases where people have integers and want to create
@shyuep given your question i have a counter question: why do we need atomic number support in |
@janosh Given that no one has ever complained about Composition supporting int/float to my knowledge, I would imagine the use case is theoretical and not practical. Composition(1) is ambiguous and for sure, this will not be something I agree to. Species(1) is slightly more justifiable but given that the pseudo-parent class Element does not support Element(1), this is again extremely bad behavior. Structure supporting int has good reasons. There are some electronic structure codes where the sites are specified in terms of atomic numbers. Also, for ordered structures, the int specification has a 1:1 link with an atom, this is not ambiguous. I would ask that we solve actual problems that people faced, not imagine problems and add complexity to the code to handle a theoretical use case that no one has ever raised. |
@shyuep please stop closing this PR. it contains other changes that should be merged regardless of whether we go ahead with the
the grand total of added complexity are 2 lines. this is all it takes to support if len(args) == 1 and isinstance(args[0], (int, float)):
# treat single integer/float as atomic number
elem_map = {get_el_sp(args[0]): 1} and then 2 more lines to test it, i.e. negligible
that is a shortcoming of |
There is a good reason why Element does from_Z and not Element(1). It is an Enum and was done for backward compatibility. A PR should contain the changes that it is supposed to have - no more, no less. If you want to keep the PR open, by all means but the title should be changed to reflect the actual changes that this PR is supposed to do. But supporting int in Species and Composition is not necessary and adds ambiguity. Like I said - find me someone who has ever complained about the lack of this "feature" and we can discuss it. |
yeah i saw the comment. though i don't understand what would break by supporting
will do
myself actually. i'm not making this up. the first time i used |
It has always been that an Element is initialized by Element("H"). While you can obviously use an "isinstance" to support int, it is not really necessary. |
rename variables for readability
…ith spin, ValueError for None
a630aed
to
1eec25d
Compare
int
and zero-decimal float
in Species
and Composition
constructorLatticeTestCase
-> TestLattice
1eec25d
to
82f40b5
Compare
PR was completely changed after discussion below. now just minor stuff like formatting and better variable names