pymatgen
                                
                                 pymatgen copied to clipboard
                                
                                    pymatgen copied to clipboard
                            
                            
                            
                        Bug in `core.composition` comparison
Bug in core.composition comparison
Open this in case it got forgotten.
As found out by @janosh in https://github.com/materialsproject/pymatgen/pull/3792#discussion_r1584003750, there is an obvious bug with Composition comparison where True is returned too early:
https://github.com/materialsproject/pymatgen/blob/6c696cdb327621d5d16c675478f4ed0e024feea1/pymatgen/core/composition.py#L195-L212
On top of this obvious bug, there are a few questions:
- The docstring adds to ambiguity: (Should ONLY be used for defining a sort order (the behavior is probably not what you'd expect).).
- It appears that we don't need to sort this union set?
- How should we define the behavior when a Elementis only in one of theCompositionand thisCompositionis not a superset of another? For example:- Composition({"O": 1, "S": 1})>- Composition({"O": 1})# This makes sense
- Composition({"S": 1})>- Composition({"O": 1})# This feels a bit weird though the atomic number is indeed greater
- Composition({"O": 2, "N": 1})>- Composition({"O": 2, "C": 1})# This doesn't seem to make sense? But this could be inferred by previous case (so should we prevent atom different Element from being compared altogether?).
 
https://github.com/materialsproject/pymatgen/blob/6c696cdb327621d5d16c675478f4ed0e024feea1/tests/core/test_composition.py#L504-L516