XRD data conversion

64 Views Asked by At

does anyone know how to convert xrd data in .str format to .cif format?

from pymatgen.core import Structure
from pymatgen.io.cif import CifWriter
import os

# Define the directory containing your .str files and the directory where you want to save the .cif files
input_directory = 'file path'
output_directory = 'file path'

# Loop through each .str file and convert it to a .cif file
for filename in os.listdir(input_directory):
    if filename.endswith(".str"):
        str_file_path = os.path.join(input_directory, filename)
        structure = Structure.from_str(open(str_file_path).read(), fmt="str")
        cif_file_path = os.path.join(output_directory, filename.replace(".str", ".cif"))
        CifWriter(structure).write_file(cif_file_path)

I am getting the following error:

ValueError                                Traceback (most recent call last)
~\AppData\Local\Temp\ipykernel_34392\2071889891.py in <module>
     11     if filename.endswith(".str"):
     12         str_file_path = os.path.join(input_directory, filename)
---> 13         structure = Structure.from_str(open(str_file_path).read(), fmt="str")
     14         cif_file_path = os.path.join(output_directory, filename.replace(".str", ".cif"))
     15         CifWriter(structure).write_file(cif_file_path)

~\Anaconda3\lib\site-packages\pymatgen\core\structure.py in from_str(cls, input_string, fmt, primitive, sort, merge_tol, **kwargs)
   2803             struct = ResIO.structure_from_str(input_string, **kwargs)
   2804         else:
-> 2805             raise ValueError(f"Unrecognized format `{fmt}`!")
   2806 
   2807         if sort:

ValueError: Unrecognized format `str`!

Every other approach is given the same error.

0

There are 0 best solutions below