diff --git a/src/quacc/atoms/phonons.py b/src/quacc/atoms/phonons.py index 2f811849a7..83e61092a5 100644 --- a/src/quacc/atoms/phonons.py +++ b/src/quacc/atoms/phonons.py @@ -2,6 +2,7 @@ from __future__ import annotations +from importlib.util import find_spec from typing import TYPE_CHECKING import numpy as np @@ -10,18 +11,15 @@ from pymatgen.io.phonopy import get_phonopy_structure, get_pmg_structure from pymatgen.symmetry.analyzer import SpacegroupAnalyzer -try: - import phonopy +has_phonopy = find_spec("phonopy") - has_phonopy = True -except ImportError: - has_phonopy = False +if has_phonopy: + from phonopy import Phonopy if TYPE_CHECKING: from ase.atoms import Atoms - if phonopy: - from phonopy import Phonopy + if has_phonopy: from phonopy.structure.atoms import PhonopyAtoms @@ -71,7 +69,7 @@ def get_phonopy( np.round(np.ceil(min_lengths / np.array(symmetrized_structure.lattice.abc))) ) - phonon = phonopy.Phonopy( + phonon = Phonopy( get_phonopy_structure(symmetrized_structure), symprec=symprec, supercell_matrix=supercell_matrix,