Skip to content

Standardize Molden output and add Multiwfn-specific interface#7424

Open
Stardust0831 wants to merge 14 commits into
deepmodeling:developfrom
Stardust0831:develop
Open

Standardize Molden output and add Multiwfn-specific interface#7424
Stardust0831 wants to merge 14 commits into
deepmodeling:developfrom
Stardust0831:develop

Conversation

@Stardust0831
Copy link
Copy Markdown

Summary

This PR updates the ABACUS Molden conversion workflow to make the core tools/molden/molden.py output closer to the Molden format conventions, while moving Multiwfn-specific metadata handling into a dedicated interface.

Changes

  • Add Molden format references at the beginning of tools/molden/molden.py.
  • Replace the previous optional [Nval] output in tools/molden/molden.py with default [Pseudo] output.
  • Remove the --write-nval option from the core Molden generator.
  • Add interfaces/Multiwfn_interface/molden_nval.py, which calls tools/molden/molden.py via importlib and writes [Nval] metadata for Multiwfn-specific usage.

Rationale

[Nval] is useful for Multiwfn analysis, but it is not part of the standard Molden format. Keeping it in the core Molden generator couples tools/molden/molden.py to one downstream analysis program.

This PR decouples the two use cases:

  • tools/molden/molden.py now generates a more standard Molden file with [Pseudo] metadata by default.
  • interfaces/Multiwfn_interface provides the Multiwfn-specific [Nval] behavior separately.

Title: Improve ABACUS Molden output for wavefunction analysis

Summary:
This PR fixes several Molden conversion issues in tools/molden/molden.py while keeping the default workflow unchanged as much as possible.

Changes:
- Correct the primitive Gaussian coefficient convention when writing Molden GTO data. The NAO-to-GTO fit uses unnormalized radial primitives, while Molden readers usually normalize primitive Gaussian functions internally.
- Fix Cartesian_angstrom coordinate conversion. Coordinates in Angstrom are now converted to Bohr for the Molden [Atoms] AU section by dividing by 0.529177210903.
- Add optional multi-start NAO-to-GTO fitting. A single -r value keeps the old single-start behavior; comma-separated -r values enable multi-start fitting and keep the fit with the lowest nonlinear error.
- Add optional Molden [Nval] output via --write-nval. The values are read from UPF z_valence. This option is disabled by default.

Notes:
- The changes are limited to the Molden converter.

Validation:
- Ran the existing molden.py unit tests successfully.
- Checked that default output does not contain [Nval].
- Checked that --write-nval writes C/O/H valence charges for the PhenolDimer test case.
- Checked that Cartesian_angstrom coordinates are written at the correct Bohr scale.
Refactor Molden file writing functions to handle effective nuclear charges instead of valence charges. Update command line arguments and main function to remove Nval section.

 - Write [Pseudo] metadata by default in tools/molden/molden.py
 - Remove the [Nval] command-line option from the core Molden generator
This change modifies the molden_nval.py script to write [Nval] metadata by default instead of [Pseudo] when generating Molden files for Multiwfn.
@Stardust0831
Copy link
Copy Markdown
Author

@kirk0830

In this update, I separated the Multiwfn-specific behavior from the core Molden converter.

The main changes are:

  • Added a dedicated interfaces/Multiwfn_interface/molden.py wrapper for Multiwfn-oriented Molden generation.
  • Kept the [Nval] handling inside the Multiwfn interface only, instead of adding it to tools/molden/molden.py.
  • Kept tools/molden/molden.py focused on generating a more standard Molden file.
  • Made optional non-standard or auxiliary sections configurable:
    • tools/molden/molden.py: [Cell] and [Pseudo] are optional and disabled by default.
    • interfaces/Multiwfn_interface/molden.py: [Cell] and [Nval] are enabled by default for Multiwfn usage, while [Pseudo] remains optional and disabled by default.
  • Added Molden format references to clarify the intended output convention.

The purpose is to make the core tools/molden/molden.py output closer to the standard Molden format, while keeping program-specific compatibility logic, such as Multiwfn [Nval], in the interface layer.

@kirk0830 kirk0830 self-requested a review June 3, 2026 10:52
Copy link
Copy Markdown
Collaborator

@kirk0830 kirk0830 left a comment

Choose a reason for hiding this comment

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

This PR is submitted after a long discussion with @Stardust0831, @QuantumMisaka, and @Growl1234, during which several general ideas were developed on how to appropriately implement an interface with other software.

Generally speaking, the interface is where data is reorganized and postprocessed. It would be the best case in which the software interface accepts some common file formats such as Gaussian cube, xyz (extxyz), Protein Data Bank (pdb), Crystallographic Information File (cif), etc, and in this case, it is only needed to add a function/module to dump such a file, and due to there are always not only one softwares accept those formats, it is better to place such codes into tools/ instead of the interfaces/, due to it is a "one (ABACUS)-to-many" case.

Molden is a standard format for organizing wavefunction information and has been widely used in the quantum chemistry community for decades. Its standard regulating a correct format has also been published online. The implementation in the folder tools/ was designed to convert the wavefunction of ABACUS-LCAO into a compatible format that can be stored in the Molden file.

However, there are software programs that may also suggest or accept some customized sections in Molden such as [Nval], [Cell], etc, say, a non-standard Molden format. In this case, the adaptation of the Molden file should not be implemented in the code supporting a standard Molden file generation. Instead, the code to modify the Molden so that it supports software like Multiwfn would be better placed in the folder interfaces/ instead of tools/, as an example of a "one (ABACUS)-to-one (Multiwfn)" case.

This design concept can help ABACUS maintain better code integrity and functionality, to be decoupled from any changes in other software (or, say, avoid any unnecessary dependency). In the future, when the software ABACUS interfaces updates, it is only needed to update the code in interfaces/, avoiding any risks of the spoilage of the functionality of ABACUS's main body.

Image

cc. @mohanchen

Comment thread tools/molden/molden.py Outdated
@mohanchen mohanchen added Feature Discussed The features will be discussed first but will not be implemented soon Interfaces Interfaces with other packages labels Jun 3, 2026
Updated regex pattern for reading ABACUS lowf files to support new naming conventions. Added functions to handle multiple k points and modified the moldengen function to accept ikpoint parameter.
Copy link
Copy Markdown

@Growl1234 Growl1234 left a comment

Choose a reason for hiding this comment

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

Thank you so much, it worked!

Just some minor comments, otherwise looks good.
It's also suggested to run chmod +x to those scripts (with #!/usr/bin/env python3 header).

Comment thread interfaces/Multiwfn_interface/molden.py
Comment thread tools/molden/molden.py
@Stardust0831 Stardust0831 requested a review from Growl1234 June 3, 2026 19:10
Removed ikpoint parameter from moldengen function and adjusted related logic.
Refactor find_abacus_lowf_files function to remove ikpoint parameter and update related logic. Remove unused append_molden_filename_suffix and find_abacus_lowf_file_groups functions.
@Stardust0831 Stardust0831 requested a review from Growl1234 June 3, 2026 20:32
Copy link
Copy Markdown

@Growl1234 Growl1234 left a comment

Choose a reason for hiding this comment

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

I don't quite see the point of the follow-up refactoring, but I think that the discussion of post-processing regarding k-points might be too much for this PR...

@kirk0830
Copy link
Copy Markdown
Collaborator

kirk0830 commented Jun 3, 2026

I don't quite see the point of the follow-up refactoring, but I think that the discussion of post-processing regarding k-points might be too much for this PR...

I agree, multiple k points support seems a complicated topic and there is no Molden file standard regarding k points.

@Stardust0831
Copy link
Copy Markdown
Author

Stardust0831 commented Jun 4, 2026

I don't quite see the point of the follow-up refactoring, but I think that the discussion of post-processing regarding k-points might be too much for this PR...

I agree, multiple k points support seems a complicated topic and there is no Molden file standard regarding k points.

Thanks, I agree. I have removed the k-point-related changes from this PR, including the --ikpoint option, selected/all k-point conversion, and k-point-based output naming.

The converter now keeps the original behavior: only gamma-only single-k calculations are accepted, and non-gamma-only k-point calculations are rejected.

So the remaining scope of this PR is limited to the wavefunction filename compatibility issue in the current ABACUS development branch, while keeping the Multiwfn-specific handling separated in the interface script.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Feature Discussed The features will be discussed first but will not be implemented soon Interfaces Interfaces with other packages

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants