Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/diffpy/structure/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@

# Interface definitions ------------------------------------------------------

import os

from diffpy.structure.atom import Atom
from diffpy.structure.lattice import Lattice
from diffpy.structure.parsers import getParser
Expand All @@ -55,8 +57,7 @@ def loadStructure(filename, fmt="auto", **kw):

Parameters
----------

filename : str
filename : str or pathlib.Path
Path to the file to be loaded.
fmt : str, Optional
Format of the structure file such as 'cif' or 'xyz'. Must be
Expand All @@ -74,7 +75,7 @@ def loadStructure(filename, fmt="auto", **kw):
Return a more specific PDFFitStructure type for 'pdffit'
and 'discus' formats.
"""

filename = os.fspath(filename) # This handles str, Path, and os.PathLike
p = getParser(fmt, **kw)
rv = p.parseFile(filename)
return rv
Expand Down
11 changes: 11 additions & 0 deletions tests/test_loadstructure.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,17 @@ def test_badkwarg(self):
self.assertRaises(TypeError, loadStructure, f, eps=1e-10)
return

def test_cif_pathlib(self):
"""check loading CIF file using pathlib.Path input"""
from pathlib import Path

f = self.datafile("PbTe.cif")
f_path = Path(f) # Convert to Path object
stru = loadStructure(f_path)
self.assertTrue(isinstance(stru, Structure))
self.assertFalse(isinstance(stru, PDFFitStructure))
return


# End of class TestLoadStructure

Expand Down