Lobsterpy
Lobsterpy is a Python package designed for automatic bonding analysis derived from LOBSTER calculations, which themselves process VASP output. It helps researchers analyze chemical bonding in materials efficiently. The current version is 0.6.0, and the project is under active development with irregular but consistent releases.
Common errors
-
ModuleNotFoundError: No module named 'lobsterpy.analysis'
cause The `analysis` submodule was moved or renamed in recent versions.fixChange your import statement from `from lobsterpy.analysis import LobsterpyAnalysis` to `from lobsterpy.cohp.analyze import LobsterpyAnalysis`. -
FileNotFoundError: [Errno 2] No such file or directory: 'path/to/your/lobster/calculation/COHPCAR.lobster'
cause The specified calculation directory either does not exist, or essential LOBSTER/VASP output files are missing within it.fixEnsure the `path_to_lobster_calc` variable points to a valid directory containing all expected LOBSTER and VASP output files. Check for typos in the path and file names. -
TypeError: __init__ got an unexpected keyword argument 'path'
cause The `LobsterpyAnalysis` constructor parameter for the calculation path changed from `path` to `path_to_lobster_calc` in version 0.5.0.fixUpdate your constructor call from `LobsterpyAnalysis(path=...)` to `LobsterpyAnalysis(path_to_lobster_calc=...)`.
Warnings
- breaking Major refactoring in versions >=0.5.0 moved key classes and changed method signatures. `LobsterpyAnalysis` and `LobsterpyData` are now in `lobsterpy.cohp.analyze` and `lobsterpy.cohp.data` respectively.
- gotcha The `LobsterpyAnalysis` constructor requires a complete LOBSTER/VASP calculation directory. Missing essential files (e.g., `COHPCAR.lobster`, `vasprun.xml`, `POSCAR`) will lead to `FileNotFoundError` or parsing errors.
- deprecated Direct plotting functions within `LobsterpyAnalysis` have been largely deprecated or moved. For plotting, use the dedicated `lobsterpy.plotting` module introduced in version 0.6.0.
Install
-
pip install lobsterpy
Imports
- LobsterpyAnalysis
from lobsterpy.analysis import LobsterpyAnalysis
from lobsterpy.cohp.analyze import LobsterpyAnalysis
- LobsterpyData
from lobsterpy.data import LobsterpyData
from lobsterpy.cohp.data import LobsterpyData
Quickstart
from pathlib import Path
from lobsterpy.cohp.analyze import LobsterpyAnalysis
# NOTE: Replace with the actual path to your LOBSTER/VASP calculation directory.
# This directory should contain files like COHPCAR.lobster, vasprun.xml, POSCAR etc.
# For a runnable example, you would need to set up such a directory locally.
path_to_lobster_calc = Path('/path/to/your/lobster_calculation_output')
# Create an instance of LobsterpyAnalysis
try:
analyzer = LobsterpyAnalysis(
path_to_lobster_calc=path_to_lobster_calc,
gaussian_smearing_width=0.05,
spin_type='none' # or 'up', 'down' for spin-polarized calculations
)
# Access bonding analysis results
bond_data = analyzer.bond_analysis
print("Bond Analysis:\n", bond_data)
# You can also get population data
population_data = analyzer.get_population_data()
print("Population Data:\n", population_data)
except FileNotFoundError as e:
print(f"Error: Calculation path not found or missing files. {e}")
print("Please ensure 'path_to_lobster_calc' points to a valid LOBSTER/VASP calculation directory.")
except Exception as e:
print(f"An error occurred during analysis: {e}")