|
import os |
|
from tqdm import tqdm |
|
from ase.io import read, write |
|
from pymatgen.io.cif import CifParser |
|
import warnings |
|
|
|
warnings.filterwarnings("ignore") |
|
|
|
|
|
|
|
input_folder = "/users/PAS2490/marcusshen/cmame/Data/CSD_non_disordered/CSD_non_disordered/" |
|
output_folder_ase = "/users/PAS2490/marcusshen/cmame/Data/CSD_non_disordered/CSD_non_disordered/cleaned_ase/" |
|
output_folder_pymatgen = "/users/PAS2490/marcusshen/cmame/Data/CSD_non_disordered/CSD_non_disordered/cleaned_pymatgen/" |
|
|
|
|
|
|
|
os.makedirs(output_folder_ase, exist_ok=True) |
|
os.makedirs(output_folder_pymatgen, exist_ok=True) |
|
|
|
|
|
cif_files = [f for f in os.listdir(input_folder) if f.endswith(".cif")] |
|
|
|
|
|
for file_name in tqdm(cif_files, desc="Processing CIF files"): |
|
if file_name.endswith(".cif"): |
|
input_path = os.path.join(input_folder, file_name) |
|
ase_output_path = os.path.join(output_folder_ase, file_name) |
|
pymatgen_output_path = os.path.join(output_folder_pymatgen, file_name) |
|
|
|
try: |
|
|
|
structure = read(input_path) |
|
write(ase_output_path, structure) |
|
|
|
|
|
parser = CifParser(ase_output_path) |
|
structure_pymatgen = parser.get_structures()[0] |
|
structure_pymatgen.to(filename=pymatgen_output_path) |
|
except Exception as e: |
|
print(f"Error processing file {file_name}: {e}") |