csp_train_42k_charges_30Dec2025 / concat_dft_total.py
lollcat's picture
Add files using upload-large-folder tool
efb7845 verified
import numpy as np
from ase import Atoms
from ase.io import read, write
from pathlib import Path
# Location of data downloaded from https://huggingface.co/datasets/AngstromAI/csp_raw_dft.
hf_raw_data_dir = Path("/home/ubuntu/efs/ajc/csp/csp_raw_dft")
output_filename = Path(__file__).parent / "B86bPBEXDM_total_45k_30Dec2025.extxyz"
index = ":" # Useful for debugging.
######### FIRST CONCAT TOTAL DFT DATA #########
files_third_8_to_16k_part1 = list((hf_raw_data_dir / "total_B86bPBEXDM/third_8_to_16k_part1").rglob("*b86bpbexdm.extxyz")) + list((hf_raw_data_dir / "total_B86bPBEXDM/third_8_to_16k_part2").rglob("*b86bpbexdm.extxyz"))
fhi_aims_total_atoms_third_8_to_16k = [read(file, index=index) for file in files_third_8_to_16k_part1]
fhi_aims_total_atoms_third_8_to_16k = [item for sublist in fhi_aims_total_atoms_third_8_to_16k for item in sublist] # Single list.
fhi_aims_total_atoms_first_4k = read(hf_raw_data_dir / "total_B86bPBEXDM/first_4k/traj_total_b86bpbexdm.extxyz", index=index)
fhi_aims_total_atoms_first_4k_check = read(hf_raw_data_dir / "total_B86bPBEXDM/first_4k/batch_0_1000/traj_total_b86bpbexdm.extxyz", index=index)
# Check the first atom is the same.
assert fhi_aims_total_atoms_first_4k_check[0].info["identifier"] == fhi_aims_total_atoms_first_4k[0].info["identifier"]
assert fhi_aims_total_atoms_first_4k_check[0].get_potential_energy() == fhi_aims_total_atoms_first_4k[0].get_potential_energy()
fhi_aims_total_atoms_second_4_to_8k = read(hf_raw_data_dir / "total_B86bPBEXDM/second_4_to_8k/traj_total_b86bpbexdm.extxyz", index=index)
files_fourth_16_to_32k = list((hf_raw_data_dir / "total_B86bPBEXDM/fourth_16_to_32k").rglob("*b86bpbexdm.extxyz"))
fhi_aims_total_atoms_fourth_16_to_32k = [read(file, index=index) for file in files_fourth_16_to_32k]
fhi_aims_total_atoms_fourth_16_to_32k = [item for sublist in fhi_aims_total_atoms_fourth_16_to_32k for item in sublist] # Single list.
# Fifth.
files_fifth_32_to_42k = list((hf_raw_data_dir / "total_B86bPBEXDM/fifth_32_to_64k").rglob("*b86bpbexdm.extxyz"))
fhi_aims_total_atoms_fifth_32_to_42k = [read(file, index=index) for file in files_fifth_32_to_42k]
fhi_aims_total_atoms_fifth_32_to_42k = [item for sublist in fhi_aims_total_atoms_fifth_32_to_42k for item in sublist] # Single list.
fhi_total_atoms = fhi_aims_total_atoms_first_4k + fhi_aims_total_atoms_second_4_to_8k + fhi_aims_total_atoms_third_8_to_16k + fhi_aims_total_atoms_fourth_16_to_32k + fhi_aims_total_atoms_fifth_32_to_42k
print(f"Length of first 4k: {len(fhi_aims_total_atoms_first_4k)}")
print(f"Length of second 4 to 8k: {len(fhi_aims_total_atoms_second_4_to_8k)}")
print(f"Length of third 8 to 16k: {len(fhi_aims_total_atoms_third_8_to_16k)}")
print(f"Length of fourth 16 to 32k: {len(fhi_aims_total_atoms_fourth_16_to_32k)}")
print(f"Length of fifth 32 to 42k: {len(fhi_aims_total_atoms_fifth_32_to_42k)}")
print(f"Length of total total: {len(fhi_total_atoms)}")
######### Complete processing and save. #########
identifiers = [atom.info["identifier"] for atom in fhi_total_atoms]
print(len(identifiers))
write(images=fhi_total_atoms, format="extxyz", filename=output_filename, append=True)