CASTEP Binary File Readers

0.3.1 · active · verified Fri Apr 17

castepxbin is a collection of Python readers for various binary output files generated by CASTEP, a first-principles quantum mechanics code. It enables parsing of data like projected density of states (.pdos_bin), checkpoint files (.castep_bin), optical matrix elements (.ome_bin, .ome_cst), and wave functions (.check). The current version is 0.3.1, with releases occurring irregularly, primarily driven by new feature additions and compatibility fixes.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to instantiate a `PdosBinReader` to read a CASTEP `.pdos_bin` file and access common data such as eigenvalues and projected density of states (PDOS) weights. Remember to replace 'path_to_your_castep.pdos_bin' with the actual path to your CASTEP output file. Similar patterns apply to `CastepBinReader`, `OmeBinReader`, and `CheckReader` for their respective file types.

import numpy as np
from castepxbin.pdos_bin import PdosBinReader

# Assuming you have a castep.pdos_bin file generated by CASTEP
# For demonstration, we'll create a dummy file. In a real scenario,
# this path would point to your actual CASTEP output.

dummy_pdos_data = {
    'kpoints': np.random.rand(5, 3), # Dummy k-points
    'num_spins': 1,
    'num_bands': 10,
    'num_species': 2,
    'num_proj_per_species': 9, # s, p_x, p_y, p_z, d_xy, d_yz, d_zx, d_x2y2, d_z2
    'eigenvalues': np.random.rand(1, 5, 10), # spin, kpoint, band
    'weights': np.random.rand(1, 5, 10, 2, 9), # spin, kpoint, band, species, projection
    'efermi': 0.0
}

# In a real scenario, you'd have a pdos_bin file.
# The library is for reading existing files, not creating them.
# This part is just to make the example runnable without an actual file.
# For a true quickstart, you'd replace 'path_to_your_file.pdos_bin' 
# with an actual file path.

# Example usage with a placeholder path:
file_path = 'path_to_your_castep.pdos_bin'

try:
    reader = PdosBinReader(file_path)
    # Access data, e.g., eigenvalues, weights
    eigenvalues = reader.get_eigenvalues()
    pdos_weights = reader.get_total_weights()

    print(f"Successfully read {file_path}")
    print(f"Eigenvalues shape: {eigenvalues.shape}")
    print(f"PDOS weights shape: {pdos_weights.shape}")

except FileNotFoundError:
    print(f"Error: The file '{file_path}' was not found. Please provide a valid CASTEP .pdos_bin file.")
except Exception as e:
    print(f"An error occurred: {e}")

view raw JSON →