cclib: Computational Chemistry Parsers

1.8.1 · active · verified Thu Apr 16

cclib is an open-source Python library designed for parsing and interpreting output files from various computational chemistry packages. It provides a consistent interface to extract data like geometries, energies, orbitals, and vibrational modes, facilitating the implementation of package-independent algorithms. The current stable version is 1.8.1, with a major version 2.0 actively in alpha development, which is expected to introduce significant architectural and API changes.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to use `cclib.io.ccread` to parse a computational chemistry output file. It creates a simple dummy logfile, parses it, and then accesses common attributes like the number of atoms, SCF energy, and atom coordinates from the returned `ccData` object.

import cclib
import os

# Create a dummy logfile for demonstration
dummy_logfile_content = """
 Program: Gaussian
 # hf/sto-3g Opt

 Energy: -76.0357878
 Nuclear Repulsion Energy: 22.1898
 Number of atoms: 3
 Atom 1: H   0.000000   0.000000   0.000000
 Atom 2: O   0.000000   0.000000   0.969000
 Atom 3: H   0.880000   0.000000   1.239000
"""

with open("water.log", "w") as f:
    f.write(dummy_logfile_content)

try:
    # Parse the logfile using ccread
    data = cclib.io.ccread("water.log")

    # Access parsed data attributes
    print(f"Number of atoms: {data.natom}")
    print(f"Electronic energy (eV): {data.scfenergies[-1]:.2f}")
    print(f"Atom coordinates (Angstrom):\n{data.atomcoords[-1]}")

except Exception as e:
    print(f"Error parsing file: {e}")
finally:
    # Clean up the dummy file
    if os.path.exists("water.log"):
        os.remove("water.log")

view raw JSON →