|
49 | 49 | from ase.io import read, write |
50 | 50 | import shutil |
51 | 51 |
|
52 | | -__version__ = "1.6.0" |
| 52 | +__version__ = "1.6.1" |
53 | 53 |
|
54 | 54 |
|
55 | 55 | def _check_equal(val): |
@@ -759,16 +759,29 @@ def _validate_all(self) -> "Input": |
759 | 759 |
|
760 | 760 | def fix_paths(self, potlist): |
761 | 761 | """ |
762 | | - Fix paths for potential files to complete ones |
| 762 | + Fix paths for potential files to complete ones. |
| 763 | +
|
| 764 | + Also expands environment variables (e.g. ``$USER``, ``${USER}``) and |
| 765 | + the home-directory shortcut ``~`` in potential file paths before |
| 766 | + resolving them to absolute paths. This allows input files to contain |
| 767 | + portable paths such as ``/home/$USER/potentials/Cu.eam``. |
763 | 768 | """ |
764 | 769 | fixedpots = [] |
765 | 770 | for pot in potlist: |
766 | 771 | pcraw = pot.split() |
767 | 772 | if len(pcraw) >= 3: |
768 | | - filename = pcraw[2] |
769 | | - filename = os.path.abspath(filename) |
770 | | - if os.path.exists(filename): |
771 | | - pcnew = " ".join([*pcraw[:2], filename, *pcraw[3:]]) |
| 773 | + raw_filename = pcraw[2] |
| 774 | + # Expand environment variables ($USER, ${USER}, $HOME, …) and ~ |
| 775 | + expanded = os.path.expandvars(os.path.expanduser(raw_filename)) |
| 776 | + abs_filename = os.path.abspath(expanded) |
| 777 | + if os.path.exists(abs_filename): |
| 778 | + pcnew = " ".join([*pcraw[:2], abs_filename, *pcraw[3:]]) |
| 779 | + fixedpots.append(pcnew) |
| 780 | + elif expanded != raw_filename: |
| 781 | + # A variable was expanded even though the file was not found |
| 782 | + # at that location yet – still substitute so LAMMPS receives |
| 783 | + # the resolved path rather than a literal "$USER" string. |
| 784 | + pcnew = " ".join([*pcraw[:2], expanded, *pcraw[3:]]) |
772 | 785 | fixedpots.append(pcnew) |
773 | 786 | else: |
774 | 787 | fixedpots.append(pot) |
|
0 commit comments