Skip to content

Commit

Permalink
Update methods requiring scm.libbase SCMSUITE-8674 SO--
Browse files Browse the repository at this point in the history
  • Loading branch information
dormrod committed Sep 24, 2024
1 parent 0cb6cdd commit 10e344a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
5 changes: 2 additions & 3 deletions interfaces/adfsuite/ams.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import numpy as np
from scm.plams.core.basejob import SingleJob
from scm.plams.core.errors import FileError, JobError, PlamsError, PTError, ResultsError
from scm.plams.core.functions import config, log, parse_heredoc
from scm.plams.core.functions import config, log, parse_heredoc, requires_optional_package
from scm.plams.core.private import sha256
from scm.plams.core.results import Results
from scm.plams.core.settings import Settings
Expand Down Expand Up @@ -209,6 +209,7 @@ def get_molecule(self, section: str, file: str = "ams") -> Molecule:
if sectiondict:
return Molecule._mol_from_rkf_section(sectiondict)

@requires_optional_package("scm.libbase")
def get_system(self, section: str, file: str = "ams") -> "ChemicalSystem":
"""Return a ``ChemicalSystem`` instance stored in a given *section* of a chosen ``.rkf`` file.
Expand All @@ -218,8 +219,6 @@ def get_system(self, section: str, file: str = "ams") -> "ChemicalSystem":
Note that ``ChemicalSystem`` is only available within AMS python. If unavailable, the call will raise an error.
"""
if not _has_scm_chemsys:
raise PlamsError("'ChemicalSystem' not available outside of AMS python.")
return ChemicalSystem.from_kf(self.rkfpath(file), section)

def get_ase_atoms(self, section: str, file: str = "ams") -> "AseAtoms":
Expand Down
8 changes: 4 additions & 4 deletions unit_tests/test_amsresults.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from scm.plams.interfaces.adfsuite.ams import AMSJob, AMSResults
from scm.plams.tools.kftools import KFFile
from scm.plams.core.errors import FileError, PlamsError
from scm.plams.core.errors import FileError, MissingOptionalPackageError
from scm.plams.mol.molecule import Molecule
from scm.plams.unit_tests.test_helpers import skip_if_no_ams_installation

Expand Down Expand Up @@ -245,7 +245,7 @@ def test_get_system_returns_requested_section_chemical_system_with_libbase_other
self.assert_water_molecule(molecule, expected_coords, ChemicalSystem)
except ImportError:
# Otherwise errors
with pytest.raises(PlamsError):
with pytest.raises(MissingOptionalPackageError):
water_opt_results.get_system(section, file)

@pytest.mark.parametrize(
Expand Down Expand Up @@ -286,7 +286,7 @@ def test_get_input_system_as_expected_with_libbase_otherwise_errors(self, water_
self.assert_water_molecule(molecule, "input", ChemicalSystem)
except ImportError:
# Otherwise errors
with pytest.raises(PlamsError):
with pytest.raises(MissingOptionalPackageError):
water_opt_results.get_input_system()

def test_get_input_molecules_has_initial_molecule_under_empty_key(self, water_opt_results):
Expand Down Expand Up @@ -321,7 +321,7 @@ def test_get_main_system_as_expected(self, water_opt_results):
self.assert_water_molecule(molecule, "main", ChemicalSystem)
except ImportError:
# Otherwise errors
with pytest.raises(PlamsError):
with pytest.raises(MissingOptionalPackageError):
water_opt_results.get_main_system()

@pytest.mark.parametrize("get_results", [False, True])
Expand Down

0 comments on commit 10e344a

Please sign in to comment.