[CP2K-user] [CP2K:22368] MOLECULAR_MOMENTS localization with DFT+U and UKS - CP2K 2026.1

Thomas Kühne tkuehne at gmail.com
Wed Aug 5 19:17:13 UTC 2026


Dear Matthew,

I found a bug in the MOLECULAR_MOMENTS code path that explains this behavior. It is not caused by UKS, DFT+U, the SCF, or the Jacobi localization itself. 
The finite Wannier centers are consistent with this diagnosis.

After forming the moment matrix product, CP2K summed the entire local allocation of a distributed matrix. This allocation can contain unused padding rows or 
columns that are not initialized or written by the matrix operation. Depending on the MPI distribution and memory contents, a NaN in this padding can therefore 
contaminate all molecular moments.

I have opened a fix:
https://github.com/cp2k/cp2k/pull/5680

The fix restricts the sum to the actual local matrix dimensions. It also extends the existing UKS molecular-moments regression test and makes the numerical test 
matcher reject NaN and Inf explicitly.

I tested the UKS case with 1, 2, and 4 MPI ranks. All runs produced identical finite molecular moments.

Your post-processing of the finite Wannier centers is a reasonable temporary workaround for first moments. Running with a different MPI layout or a single MPI 
rank may also happen to avoid the NaNs, but that is not a reliable fix.

Best regards,
Thomas

> Am 04.08.2026 um 16:41 schrieb 'Matthew Emerson' via cp2k <cp2k at googlegroups.com>:
> 
> Dear CP2K developers and users,
> I'm running into an issue with MOLECULAR_MOMENTS after Wannier localization and was wondering if anyone has seen something similar.
> 
> I'm using UKS (also reproduced with DFT+U enabled) together with:
> 
> &LOCALIZE 
>  METHOD JACOBI 
>  USE_HISTORY F 
>  &PRINT &MOLECULAR_MOMENTS LOW 
>     ORDER 1 
>  &END MOLECULAR_MOMENTS 
>    &WANNIER_CENTERS 
>      IONS+CENTERS 
>    &END WANNIER_CENTERS 
>  &END PRINT &END LOCALIZE
> The SCF converges normally, the Jacobi localization converges, and the printed Wannier centers for both spin channels are finite and appear reasonable. However, the MOLECULAR_MOMENTS output consists entirely of NaN values for every atom/molecule.
> 
> As a sanity check, I wrote a small post-processing script that assigns the printed Wannier centers to the nearest atom (using minimum-image PBC) and reconstructs per-atom electronic dipoles which are all reasonable.
> 
> Has anyone encountered this before, or is there a known issue with MOLECULAR_MOMENTS for localized UKS wavefunctions? 
> 
> 
> -- 
> You received this message because you are subscribed to the Google Groups "cp2k" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to cp2k+unsubscribe at googlegroups.com <mailto:cp2k+unsubscribe at googlegroups.com>.
> To view this discussion visit https://groups.google.com/d/msgid/cp2k/92857f51-b8d0-4551-8467-e45d87cd39can%40googlegroups.com <https://groups.google.com/d/msgid/cp2k/92857f51-b8d0-4551-8467-e45d87cd39can%40googlegroups.com?utm_medium=email&utm_source=footer>.

-- 
You received this message because you are subscribed to the Google Groups "cp2k" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cp2k+unsubscribe at googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/cp2k/D1864E0A-EF08-44F2-9985-49E51305C01B%40gmail.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.cp2k.org/archives/cp2k-user/attachments/20260805/c50880cd/attachment.htm>


More information about the CP2K-user mailing list