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

Fix `apply_operation(fractional=True)` #4057

Closed kavanase closed 2 months ago

kavanase commented 2 months ago

Summary

Structure.apply_operation() fails when using the fractional=True operation. The issue is that the SymmOp is applied to the site frac coords (in the original lattice), but then these new frac coords (in the old basis) are used directly with the new (transformed) lattice, giving a 'doubled' transformation and messing with the output.

Fix added here, matching the implementation in doped (which also has a couple more options and a cleaner implementation).

MWE:

image image

(Notebook and structure being used attached too as always 😉 , with more examples)

Pymatgen_SymmOp_Fix_PR.zip

kavanase commented 2 months ago

This fixed implementation is tested and shown to be working in the attached notebook as well

kavanase commented 2 months ago

Done! Also checked that this test fails with the old code (for fractional=True), but works all fine with the new code.