Skip to content

Fix: Bug in pairwise minimum distance calculation#1

Open
jsukpark wants to merge 1 commit into
FourPhonon:mainfrom
jsukpark:main
Open

Fix: Bug in pairwise minimum distance calculation#1
jsukpark wants to merge 1 commit into
FourPhonon:mainfrom
jsukpark:main

Conversation

@jsukpark
Copy link
Copy Markdown

@jsukpark jsukpark commented Apr 30, 2026

This PR fixes a bug reported in FourPhonon/FourPhonon#72.

Changes

  • The variable d2_min2 was being updated at the wrong for-loop level
    • Setting d2_min2 references array car4, whose contents change at each kaux
    • Only the contents of car4 at kaux == n4equi - 1 is currently reflected
    • Changed to update d2_min2 after every update to car4

This causes, for example, quartet (0, 0, 1, 2) of 2x2x2 diamond supercell (up to 2nd nearest neighbor cutoff) to be skipped, even though all 6 pairwise distances are within the interaction cutoff. Its permutation (0, 0, 2, 1) is later considered and accounted for, but the final number of DFT calculations is still affected.

After this fix, using the unit cell input file

! Contents of scf.in
&CONTROL
  ...
/
&SYSTEM
  ...
/
&ELECTRONS
  ...
/

ATOMIC_SPECIES
  C  12.011 C.upf

ATOMIC_POSITIONS crystal
  C  0.00  0.00  0.00
  C  0.25  0.25  0.25

CELL_PARAMETERS angstrom
  0.000  1.785  1.785
  1.785  0.000  1.785
  1.785  1.785  0.000

K_POINTS automatic
  8 8 8 0 0 0

and running sow command for 2x2x2 supercell with considering up to 2nd nearest neighbor cutoff, the total number of DFT calculations needed is reduced from 400 to 360.

This PR also removes an unused local variable d2_min.

- Setting `d2_min2` references array `car4`, whose contents change at each `kaux`
  - Hence must be updated at `kaux` for-loop level
- This prevented, e.g., quartet (0, 0, 1, 2) of 2x2x2 diamond supercell (up to 2nd nearest neighbor cutoff) from being considered
  - Even though all 4 atoms are within the interaction range
  - Its permutation (0, 0, 2, 1) is later considered
    - But transformation arrays still affected
- Also removed unused local variable `d2_min`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant