Pymatgen File Extension Issue

Hello everyone! I am trying to use pymatgen to import a structure to be used for coordinates for rdfpy. I am getting the following error:

in from_file
raise ValueError(f"Unrecognized extension in {filename=}")
ValueError: Unrecognized extension in filename=‘C:\Users\bnzmi\OneDrive - Northeastern University\Lustig Lab\RDF Attempts\’

I am just a little confused because xyz is one of the accepted formats for “from_file”. Thank you kindly for your help!

My code is the following:

structure = Structure.from_file(r’C:\Users\bnzmi\OneDrive - Northeastern University\Lustig Lab\RDF Attempts\’)
coords = structure.cart_coords
noise = np.random.normal(loc=0.0, scale=0.05, size=(coords.shape))
coords = coords + noise

Note: if I try to remove the “r” before the directory path, it just gives me a unicode error.

EDIT: I made it a “Molecule.from_file” and I am not getting the error anymore. However, I am still struggling because I need to make it a Structure for rdfpy.

Hi @mcb19, xyz files aren’t typically used to represent materials with periodic boundary conditions because they lack information about the crystal lattice (direct lattice vectors). They’re more-often used to represent molecules. Pymatgen’s Structure won’t parse xyz files, but its Molecule will.

To make a structure, you’d need to do something like the following:

from pymatgen.core import Structure, Molecule, Lattice

mol = Molecule.from_file("C:/Users/bnzmi/OneDrive\ -\ Northeastern University/Lustig Lab/RDF Attempts/")

a = 15
b = 15.1
c = 15.2
structure = Structure(
    Lattice([[a, 0., 0.], [0., b, 0.], [0., 0., c]]),

In that example, the molecule is placed into a large orthorhombic box to reduce the influence of periodic images of the molecule when calculating things like the RDF or electronic structure.

The unicode errors are probably because of issues with parsing space and hyphen characters in the path. If you cd into that local directory and run the same python script without any of the leading path, it might work OK.

thank you, @Aaron_Kaplan !!