Skip to content

Conversation

@Wentzell
Copy link
Member

@Wentzell Wentzell commented Oct 9, 2025

Summary

This PR replaces the f2py-compiled Fortran module for reading Elk's PMAT.OUT files with a pure Python implementation, eliminating the Fortran compiler dependency for the elktools converter.

Changes:

  • Created python/triqs_dft_tools/converters/elktools/getpmatelk.py - pure Python replacement
  • Updated python/triqs_dft_tools/converters/elk.py to use new module
  • Updated python/triqs_dft_tools/converters/elktools/__init__.py to expose getpmatelk
  • Removed f2py build infrastructure from CMakeLists.txt
  • Deleted python/triqs_dft_tools/converters/elktools/elkwrappers/ directory (Fortran source and build files)

Technical details:

  • Maintains exact functional compatibility with original Fortran implementation
  • Handles Fortran column-major array ordering correctly with order='F'
  • Preserves all validation checks (k-point and nstsv consistency)
  • All existing tests pass

@AlynJ - As the original author of the Fortran implementation, could you please review this translation to ensure it correctly captures all the intended behavior?

Test plan

  • Existing elk converter tests pass
  • Binary file reading produces identical results to Fortran version
  • Array ordering (column-major) handled correctly
  • Validation checks work as expected

The elktools converter previously used an f2py-compiled Fortran module
to read binary PMAT.OUT files. This has been replaced with a pure Python
implementation that provides identical functionality without requiring
a Fortran compiler at build time.

Changes:
- Add python/triqs_dft_tools/converters/elktools/getpmatelk.py
  Pure Python implementation to read Elk's Fortran unformatted binary files
- Update python/triqs_dft_tools/converters/elk.py
  Modified import to use new Python module
- Update python/triqs_dft_tools/converters/elktools/__init__.py
  Export getpmatelk function for direct import
- Remove python/triqs_dft_tools/converters/elktools/elkwrappers/
  Deleted f2py build infrastructure and Fortran source
- Update CMakeLists.txt
  Removed elkwrappers subdirectory from build

Benefits:
- Eliminates Fortran compiler dependency for this component
- Simplifies build process (no f2py compilation needed)
- Easier to maintain and debug
- Better error messages and handling
- Resolves historical f2py compatibility issues on Intel/macOS

Implementation details:
- Correctly handles Fortran direct-access unformatted binary files
- Properly reads column-major array ordering
- Maintains exact compatibility with original Fortran version
- All validation and error checking preserved

Testing:
- All 5 Elk converter tests pass
- Output matches reference files exactly (verified with h5diff)
- Tested with actual Elk PMAT.OUT files (41 states, 10 k-points)

Cc: @AlynJ
@Wentzell Wentzell requested a review from the-hampel October 9, 2025 15:55
@AlynJ
Copy link
Contributor

AlynJ commented Oct 13, 2025

Hi Nils,

I've reviewed the pure Python implementation and it looks good to me (especially with the test passing). I've currently not got the time to run it locally to examine it in more detail, but I'll try to look at it in the near future and let you know if I encounter any issues.

Apologies for the hassle using f2py has been with this. I believe my logic at the time of implementation was that it may be easier to update the Fortran code to mirror how Elk reads/writes the PMAT.OUT Fortran binary file within Elk's future release, but evidently having the implementation within Python is the best way forward.

It may be worth noting the latest version of the Elk-TRIQS repository which this implementation is compatible with (which I believe is 8.4.21) for internal reference.

Let me know if there are any other queries.

Thanks,
Alyn

Copy link
Member

@the-hampel the-hampel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a very nice change. Getting rid of the fortran code here is good. I think the python code looks clean enough to facilitate future changes. Of course the dependency in dmftproj on fortran still remains. But this part is of course now simpler.

Thank you @Wentzell for the improvements.

@the-hampel the-hampel merged commit c4c980d into unstable Oct 14, 2025
5 checks passed
@Wentzell Wentzell deleted the elk-remove-f2py branch October 14, 2025 14:12
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.

4 participants