diff --git a/pyiron_atomistics/atomistics/job/potentials.py b/pyiron_atomistics/atomistics/job/potentials.py index e947a65f1..8892ce419 100644 --- a/pyiron_atomistics/atomistics/job/potentials.py +++ b/pyiron_atomistics/atomistics/job/potentials.py @@ -172,14 +172,12 @@ def _get_potential_default_df( except ResourceNotFound: raise ValueError("Was not able to locate the potential files.") from None - def find_potential_file_base(path, resource_path_lst, rel_path): try: return ResourceResolver( resource_path_lst, rel_path, - name=path - ).first() + ).first(path) except ResourceNotFound: raise ValueError( "Either the filename or the functional has to be defined.", diff --git a/pyiron_atomistics/lammps/potential.py b/pyiron_atomistics/lammps/potential.py index 7022c539f..c0ac36e44 100644 --- a/pyiron_atomistics/lammps/potential.py +++ b/pyiron_atomistics/lammps/potential.py @@ -10,7 +10,7 @@ from pyiron_base import GenericParameters, state from pyiron_atomistics.atomistics.job.potentials import ( - PotentialAbstract, + PotentialAbstract ) from pyiron_atomistics.atomistics.structure.atoms import Atoms from pyiron_snippets.resources import ResourceResolver, ResourceNotFound @@ -26,7 +26,6 @@ __status__ = "production" __date__ = "Sep 1, 2017" - class LammpsPotential(GenericParameters): """ This module helps write commands which help in the control of parameters related to the potential used in LAMMPS @@ -66,6 +65,16 @@ def remove_structure_block(self): @property def files(self): + env = os.environ + resolver = ResourceResolver( + state.settings.resource_paths, + "lammps", "potentials", + ).chain( + ResourceResolver( + [env[var] for var in ("CONDA_PREFIX", "CONDA_DIR") if var in env], + "share", "iprpy", + ) + ) if len(self._df["Filename"].values[0]) > 0 and self._df["Filename"].values[ 0 ] != [""]: @@ -78,20 +87,10 @@ def files(self): if not os.path.isabs(files) ] for path in relative_file_paths: - resolver = ResourceResolver( - state.settings.resource_paths, - "lammps", "potentials", - ).chain( - # support iprpy-data package; data paths in the iprpy are of a different form than in - # pyiron resources, so we cannot add it as an additional path to the resolver above. - # Instead make a new resolver and chain it after the first one. - ResourceResolver( - [env[var] for var in ("CONDA_PREFIX", "CONDA_DIR") if var in env], - "share", "iprpy", - ), - ) try: - absolute_file_paths.append(resolver.first(path)) + absolute_file_paths.append( + resolver.first(path) + ) except ResourceNotFound: raise ValueError("Was not able to locate the potentials.") from None return absolute_file_paths diff --git a/pyiron_atomistics/sphinx/potential.py b/pyiron_atomistics/sphinx/potential.py index 8e58ff123..ab1c93d2f 100644 --- a/pyiron_atomistics/sphinx/potential.py +++ b/pyiron_atomistics/sphinx/potential.py @@ -6,11 +6,8 @@ import pandas from pyiron_base import state - -from pyiron_atomistics.vasp.potential import ( - VaspPotentialAbstract, - find_potential_file_base, -) +from pyiron_atomistics.vasp.potential import VaspPotentialAbstract +from pyiron_snippets.resources import ResourceResolver, ResourceNotFound __author__ = "Osamu Waseda" __copyright__ = ( @@ -80,14 +77,12 @@ def add_new_element(self, parent_element, new_element): def find_potential_file(path): env = os.environ - resource_path_lst = state.settings.resource_paths - for conda_var in ["CONDA_PREFIX", "CONDA_DIR"]: - if conda_var in env.keys(): # support sphinx-data package - path_to_add = os.path.join(env[conda_var], "share", "sphinxdft") - if path_to_add not in resource_path_lst: - resource_path_lst += [path_to_add] - return find_potential_file_base( - path=path, - resource_path_lst=resource_path_lst, - rel_path=os.path.join("sphinx", "potentials"), - ) + return ResourceResolver( + state.settings.resource_paths, + "sphinx", "potentials" + ).chain( + ResourceResolver( + [env[var] for var in ("CONDA_PREFIX", "CONDA_DIR") if var in env], + "share", "sphinxdft", + ) + ).first(path) diff --git a/pyiron_atomistics/vasp/potential.py b/pyiron_atomistics/vasp/potential.py index fcef76809..12b56abdf 100644 --- a/pyiron_atomistics/vasp/potential.py +++ b/pyiron_atomistics/vasp/potential.py @@ -9,6 +9,7 @@ import pandas from pyiron_base import GenericParameters, state from pyiron_snippets.deprecate import deprecate +from pyiron_snippets.resources import ResourceResolver, ResourceNotFound from pyiron_atomistics.atomistics.job.potentials import ( PotentialAbstract, @@ -120,16 +121,6 @@ def list_potential_names(self): else: return [] - @staticmethod - def _return_potential_file(file_name): - for resource_path in state.settings.resource_paths: - resource_path_potcar = os.path.join( - resource_path, "vasp", "potentials", file_name - ) - if os.path.exists(resource_path_potcar): - return resource_path_potcar - return None - def __dir__(self): return [val.replace("-", "_") for val in self.list_potential_names()] @@ -137,7 +128,7 @@ def __getitem__(self, item): item_replace = item.replace("_gga_pbe", "-gga-pbe").replace("_lda", "-lda") if item_replace in self.list_potential_names(): df = self.list() - return self._return_potential_file( + return return_potential_file( file_name=list(df[df["Name"] == item_replace]["Filename"])[0][0] ) selected_atoms = self._selected_atoms + [item] @@ -267,10 +258,13 @@ def __repr__(self): def find_potential_file(path): - return ResourceResolver( - state.settings.resource_paths, - "vasp", "potentials", - ).first(path) + try: + return ResourceResolver( + state.settings.resource_paths, + "vasp", "potentials", + ).first(path) + except ResourceNotFound: + return None @deprecate(