Commit a939ee4
Fix incorrect spin-element mapping in make_unlabeled_stru() for ABACUS STRU generation (#852)
This patch resolves a bug in dpdata/abacus/stru.py where the spin values
were misaligned with their corresponding elements when generating an
unlabeled STRU file.
Root cause:
In make_unlabeled_stru(), the code correctly identifies the global atom
index (iatomtype) for each element type, but then mistakenly uses a
separate running counter (natom_tot) to index every property except
atomic coordinates. As a result, spins (and any other per-atom
attributes) are pulled from the wrong positions in the input array,
breaking the element–spin correspondence.
Fix:
Replace all usages of natom_tot with iatomtype when accessing per-atom
data (spins, velocities, etc.). Coordinates were already using the
correct index; the change makes the remaining properties consistent.
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
* **Bug Fixes**
* Improved accuracy in assigning per-atom properties when generating
atomic position data, ensuring correct values are used for each atom.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
---------
Signed-off-by: SuperBing <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>1 parent 6b57f35 commit a939ee4
1 file changed
+30
-28
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
751 | 751 | | |
752 | 752 | | |
753 | 753 | | |
754 | | - | |
| 754 | + | |
| 755 | + | |
| 756 | + | |
755 | 757 | | |
756 | 758 | | |
757 | 759 | | |
758 | 760 | | |
759 | | - | |
760 | | - | |
| 761 | + | |
| 762 | + | |
761 | 763 | | |
762 | 764 | | |
763 | | - | |
| 765 | + | |
764 | 766 | | |
765 | | - | |
766 | | - | |
| 767 | + | |
| 768 | + | |
767 | 769 | | |
768 | 770 | | |
769 | 771 | | |
770 | 772 | | |
771 | 773 | | |
772 | | - | |
773 | | - | |
| 774 | + | |
| 775 | + | |
774 | 776 | | |
775 | | - | |
| 777 | + | |
776 | 778 | | |
777 | 779 | | |
778 | | - | |
779 | | - | |
| 780 | + | |
| 781 | + | |
780 | 782 | | |
781 | | - | |
782 | | - | |
783 | | - | |
| 783 | + | |
| 784 | + | |
| 785 | + | |
784 | 786 | | |
785 | 787 | | |
786 | | - | |
| 788 | + | |
787 | 789 | | |
788 | | - | |
| 790 | + | |
789 | 791 | | |
790 | 792 | | |
791 | | - | |
| 793 | + | |
792 | 794 | | |
793 | | - | |
| 795 | + | |
794 | 796 | | |
795 | 797 | | |
796 | | - | |
797 | | - | |
| 798 | + | |
| 799 | + | |
798 | 800 | | |
799 | 801 | | |
800 | | - | |
| 802 | + | |
801 | 803 | | |
802 | | - | |
803 | | - | |
| 804 | + | |
| 805 | + | |
804 | 806 | | |
805 | 807 | | |
806 | | - | |
807 | | - | |
| 808 | + | |
| 809 | + | |
808 | 810 | | |
809 | 811 | | |
810 | | - | |
| 812 | + | |
811 | 813 | | |
812 | | - | |
813 | | - | |
| 814 | + | |
| 815 | + | |
814 | 816 | | |
815 | 817 | | |
816 | 818 | | |
| |||
0 commit comments