This directory contains example scripts demonstrating PyMultiWFN usage.
Purpose: Fundamental PyMultiWFN operations
Demonstrates:
- Loading wavefunction files
- Accessing molecular properties
- Calculating electron density
- Computing bond orders
Usage:
python basic_usage.py molecule.wfnOutput:
- Molecular information (atoms, electrons, basis)
- Density at atomic positions
- Bond order analysis
Purpose: Electron density analysis and visualization
Demonstrates:
- Calculating density on 3D grids
- Finding density maxima/minima
- Radial density profiles
- Approximate electron counting
Usage:
python density_analysis.py molecule.wfnOutput:
- Density statistics on grid
- Top density maxima
- Radial density profile
- Integrated electron count
Purpose: Comprehensive bond order analysis
Demonstrates:
- Mayer and Wiberg bond orders
- Bond type classification
- Connectivity analysis
- Bond order matrix visualization
Usage:
python bond_analysis.py molecule.wfnOutput:
- Bond order list with classification
- Mayer vs Wiberg comparison
- Connectivity map
- Bond order statistics
These examples require wavefunction files (.wfn or .fch). You can:
-
Generate from Gaussian:
# Add output=wfn to Gaussian input # Or use formchk to convert .chk to .fch formchk molecule.chk molecule.fch
-
Use provided test data:
# Test files in tests/test_data/ python basic_usage.py ../tests/test_data/H2_CCSD.wfn -
Download from databases:
============================================================
PyMultiWFN Basic Usage Example
============================================================
1. Loading Wavefunction
------------------------------------------------------------
✓ Successfully loaded: molecule.wfn
Title: Water molecule
Method: B3LYP
Basis: 6-31G*
2. Molecular Properties
------------------------------------------------------------
Number of atoms: 3
Number of electrons: 10.0
Charge: 0
Multiplicity: 1
Basis functions: 13
Atoms:
0. O ( 0.0000, 0.0000, 0.1173)
1. H ( 0.0000, 0.7572, -0.4692)
2. H ( 0.0000, -0.7572, -0.4692)
...
from pymultiwfn.io.loader import load_wavefunction
from pymultiwfn.analysis.bonding.bondorder import calculate_mayer_bond_order
# Load and analyze
wfn = load_wavefunction("molecule.wfn")
bonds = calculate_mayer_bond_order(wfn)
# Print bonds
for i in range(wfn.num_atoms):
for j in range(i+1, wfn.num_atoms):
if bonds['total'][i, j] > 0.5:
print(f"Bond {i}-{j}: {bonds['total'][i, j]:.4f}")from pymultiwfn.io.loader import load_wavefunction
from pymultiwfn.math.density import calc_density
import numpy as np
wfn = load_wavefunction("molecule.wfn")
# Create grid
x = np.linspace(-5, 5, 50)
y = np.linspace(-5, 5, 50)
z = np.zeros(1)
coords = np.array([[xi, yi, 0.0] for xi in x for yi in y])
density = calc_density(wfn, coords)
# Reshape for visualization
density_grid = density.reshape(50, 50)from pymultiwfn.io.loader import load_wavefunction
from pymultiwfn.analysis.bonding.bondorder import (
calculate_mayer_bond_order,
calculate_wiberg_bond_order
)
wfn = load_wavefunction("molecule.wfn")
mayer = calculate_mayer_bond_order(wfn)
wiberg = calculate_wiberg_bond_order(wfn)
# Compare
for i in range(wfn.num_atoms):
for j in range(i+1, wfn.num_atoms):
m = mayer['total'][i, j]
w = wiberg['total'][i, j]
if max(m, w) > 0.5:
print(f"Bond {i}-{j}: Mayer={m:.4f}, Wiberg={w:.4f}")- Performance: Use
use_cache=True(default) for repeated calculations - Memory: For large systems, process in chunks
- Visualization: Export density grids to cube files for molecular viewers
- Validation: Compare with Multiwfn for consistency
- Read the User Guide for detailed API documentation
- Check tests/ for more usage examples
- See benchmark_performance.py for performance optimization
Questions? See User Guide or open an issue on GitHub.