#!/usr/bin/env python """ parse_ml_data.py — Inject ML EPC brakets into EPW for HPRO/DeepH-E3 comparison. For a given ML source (fd, hpro, e3): 1. If source != 'fd': run julia run_hpro_brakets_epw.jl (generates displacements/epw/braket_list_rotated_* from ao_brackets npz) 2. Restore original DFPT EPB: diamond_dft.save/diamond.epb1 → tmp/diamond.epb1 3. Inject ML brakets from displacements/epw/ into tmp/diamond.epb1 4. Patch NSCF eigenvalues in diamond.save/ from Julia's scf_0 save Usage: python parse_ml_data.py [--source {fd,hpro,e3}] python parse_ml_data.py --source hpro python parse_ml_data.py --source e3 Then run EPW2: mpirun -n 1 epw.x -npool 1 -in epw2.in > epw2_.out And compare: python $ELEPHANY_PATH/epw/compare_epw.py ./ """ import argparse import os import re import shutil import subprocess import xml.etree.ElementTree as ET import numpy as np from scipy.io import FortranFile from ase.io import read as ase_read SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) def _determine_q_point_cart(nscf_out, iq): """Extract Cartesian k-point iq (1-based) from nscf.out.""" count = 0 with open(nscf_out) as f: for line in f: if " k(" in line: count += 1 if count == iq: parts = line.split() coords = [p.rstrip(',)') for p in parts[4:7]] return [float(c) for c in coords] return [0.0, 0.0, 0.0] def inject_brakets(path_to_epw, path_to_frozen, nbnd, nbndep, nks, nqs, nat, epb_name): """Inject FD/HPRO/E3 brakets from displacements/epw/ into the EPB binary.""" nmodes = 3 * nat dtypes = [ ' epw2_{args.source}.out") print(f" python $ELEPHANY_PATH/epw/compare_epw.py ./") if __name__ == "__main__": main()