materialsproject / pymatgen

Python Materials Genomics (pymatgen) is a robust materials analysis code that defines classes for structures and molecules with support for many electronic structure codes. It powers the Materials Project.
https://pymatgen.org
Other
1.52k stars 867 forks source link

A few functions use unrounded `float` as `dict` keys #4162

Open DanielYang59 opened 2 weeks ago

DanielYang59 commented 2 weeks ago

Using float as dict keys can be prone to precision issues (especially when float is not rounded), a few functions operate on such dict[float, Any] (could be more not annotated):

core.bonds.obtain_all_bond_lengths

https://github.com/materialsproject/pymatgen/blob/bd9fba9ec62437b5b62fbd0b2c2c723216cc5a2c/src/pymatgen/core/bonds.py#L122-L137

core.lattice.Lattie

https://github.com/materialsproject/pymatgen/blob/bd9fba9ec62437b5b62fbd0b2c2c723216cc5a2c/src/pymatgen/core/lattice.py#L545-L557

diffraction patterns

https://github.com/materialsproject/pymatgen/blob/bd9fba9ec62437b5b62fbd0b2c2c723216cc5a2c/src/pymatgen/analysis/diffraction/neutron.py#L135 https://github.com/materialsproject/pymatgen/blob/bd9fba9ec62437b5b62fbd0b2c2c723216cc5a2c/src/pymatgen/analysis/diffraction/xrd.py#L199