Skip to content

Commit

Permalink
move parser imports into respective if cases
Browse files Browse the repository at this point in the history
  • Loading branch information
janosh committed Sep 10, 2021
1 parent 474f029 commit 6b80194
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions pymatgen/core/structure.py
Expand Up @@ -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
Expand Down Expand Up @@ -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":
Expand All @@ -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}`!")
Expand Down

0 comments on commit 6b80194

Please sign in to comment.