pyef.multiwfn_interface

Multiwfn Interface Module

This module provides a clean interface to the Multiwfn external quantum chemistry analysis program for charge partitioning and multipole moment calculations.

Classes

MultiwfnInterface

Main interface class for running Multiwfn calculations

Functions

getmultipoles

Static function to parse multipole moment output files

Module Contents

Classes

MoldenObject

Helper class for parsing molden files to count basis functions.

MultiwfnInterface

Interface class for Multiwfn charge partitioning and multipole calculations.

class MoldenObject(file_path_xyz, molden_filename)[source]

Helper class for parsing molden files to count basis functions.

countBasis()[source]

Count the number of basis functions in the molden file.

class MultiwfnInterface(config=None)[source]

Interface class for Multiwfn charge partitioning and multipole calculations.

This class encapsulates all interactions with the Multiwfn external program, providing methods for charge partitioning, multipole moment calculations, and parsing of Multiwfn output files.

dict_of_calcs

Mapping of charge scheme names to Multiwfn command codes

Type:

dict

dict_of_multipole

Mapping of multipole schemes to Multiwfn command sequences

Type:

dict

config

Configuration dictionary with Multiwfn settings

Type:

dict

CHARGE_SCHEMES
MULTIPOLE_SCHEMES
static get_monopole_commands(charge_type)[source]

Get the Multiwfn command sequence for a given charge type.

This is the single source of truth for all Multiwfn monopole charge calculation commands. Different charge types require different menu navigation sequences in Multiwfn.

Parameters:

charge_type (str) – The charge partitioning scheme name

Returns:

Command sequence to send to Multiwfn stdin

Return type:

list of str

Raises:

ValueError – If charge_type is ‘AIM’ (not supported in menu 7)

run_multiwfn(command, input_commands, output_file=None, description='Multiwfn calculation', capture_output=True)[source]

Centralized Multiwfn runner with proper error handling and output display.

Parameters:
  • command (str) – The shell command to run Multiwfn (e.g., “multiwfn file.molden”)

  • input_commands (list of str) – List of commands to send to Multiwfn’s stdin

  • output_file (str, optional) – Path to redirect stdout to a file

  • description (str, optional) – Description of the calculation for error messages

  • capture_output (bool, optional) – If True, capture and display output. If False, let it stream to terminal

Returns:

(stdout, stderr, returncode) from the Multiwfn process

Return type:

tuple

Raises:

RuntimeError – If Multiwfn fails with non-zero exit code

partitionCharge(multipole_bool, f, multiwfn_path, charge_type, owd, molden_filename=None, xyz_filename=None)[source]

Partition electron density using Multiwfn to generate partial charges or multipole moments.

This is the centralized interface for all charge partitioning schemes (Hirshfeld, CHELPG, etc.). Checks if calculation was previously completed and reuses results unless rerun=True.

Parameters:
  • multipole_bool (bool) – True to compute multipole moments, False for monopoles only

  • f (str) – Complete path to folder containing the calculation

  • multiwfn_path (str) – Path to Multiwfn executable

  • charge_type (str) – Partitioning scheme (e.g., ‘Hirshfeld’, ‘CHELPG’, ‘Hirshfeld_I’)

  • owd (str) – Original working directory

  • molden_filename (str, optional) – Name of the molden file (not full path, just filename). If None, uses self.config[‘molden_filename’]

  • xyz_filename (str, optional) – Name of the xyz file (not full path, just filename). If None, uses self.config[‘xyzfilename’]

Returns:

Computation time in seconds, 0 if calculation was previously completed (skipped), or -1 if calculation failed

Return type:

float

Notes

For Hirshfeld-I calculations, atmrad files are automatically loaded from pyef.resources.atmrad (bundled with the package).

static count_atoms(xyz_filename)[source]

Count number of atoms in XYZ file (mapcount replacement).

static getmultipoles(multipole_name)[source]

Parse multipole moments from Multiwfn output file.

Parameters:

multipole_name (str) – Path to multipole moment output file from Multiwfn.

Returns:

List of dictionaries containing multipole data for each atom: - ‘Index’: atom index (str) - ‘Element’: element symbol (str) - ‘Atom_Charge’: atomic charge (float) - ‘Dipole_Moment’: dipole moment vector [x, y, z] (list of float) - ‘Quadrupole_Moment’: 3x3 quadrupole tensor (np.ndarray)

Return type:

list of dict

Notes

Parses Multiwfn output format with sections separated by asterisks. Extracts monopole (charge), dipole, and quadrupole moments for each atom.