diff --git a/pymatgen/core/structure.py b/pymatgen/core/structure.py index 54ba5d5a657..6a04ae24628 100644 --- a/pymatgen/core/structure.py +++ b/pymatgen/core/structure.py @@ -18,7 +18,7 @@ import warnings from abc import ABCMeta, abstractmethod from fnmatch import fnmatch -from typing import Any, Dict, Iterable, Iterator, List, Optional, Sequence, Set, Tuple, Union, Callable, Literal +from typing import Any, Callable, Dict, Iterable, Iterator, List, Literal, Optional, Sequence, Set, Tuple, Union import numpy as np from monty.dev import deprecated @@ -2358,19 +2358,20 @@ def from_str( Returns: IStructure / Structure """ - from pymatgen.io.atat import Mcsqs - from pymatgen.io.cif import CifParser - from pymatgen.io.cssr import Cssr - from pymatgen.io.vasp import Poscar - from pymatgen.io.xcrysden import XSF fmt_low = fmt.lower() if fmt_low == "cif": + from pymatgen.io.cif import CifParser + parser = CifParser.from_string(input_string) s = parser.get_structures(primitive=primitive)[0] elif fmt_low == "poscar": + from pymatgen.io.vasp import Poscar + s = Poscar.from_string(input_string, False, read_velocities=False).structure elif fmt_low == "cssr": + from pymatgen.io.cssr import Cssr + cssr = Cssr.from_string(input_string) s = cssr.structure elif fmt_low == "json": @@ -2380,8 +2381,12 @@ def from_str( d = yaml.safe_load(input_string) s = Structure.from_dict(d) elif fmt_low == "xsf": + from pymatgen.io.xcrysden import XSF + s = XSF.from_string(input_string).structure elif fmt_low == "mcsqs": + from pymatgen.io.atat import Mcsqs + s = Mcsqs.structure_from_string(input_string) else: raise ValueError(f"Unrecognized format `{fmt}`!")