Skip to content

Commit 45c51ec

Browse files
esoteric-ephemerajanosh
authored andcommitted
move file transfer from write_input method of VaspInputSet to VaspInput
1 parent c9117f2 commit 45c51ec

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

pymatgen/io/vasp/inputs.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
from enum import Enum, unique
2020
from glob import glob
2121
from hashlib import sha256
22+
from pathlib import Path
23+
from shutil import copyfileobj
2224
from typing import TYPE_CHECKING, NamedTuple, cast
2325
from zipfile import ZipFile
2426

@@ -39,7 +41,6 @@
3941

4042
if TYPE_CHECKING:
4143
from collections.abc import Iterator
42-
from pathlib import Path
4344
from typing import Any, ClassVar, Literal
4445

4546
from numpy.typing import ArrayLike
@@ -2801,6 +2802,7 @@ def write_input(
28012802
make_dir_if_not_present: bool = True,
28022803
cif_name: str | None = None,
28032804
zip_name: str | None = None,
2805+
files_to_transfer: dict | None = None,
28042806
) -> None:
28052807
"""
28062808
Write VASP inputs to a directory.
@@ -2813,7 +2815,11 @@ def write_input(
28132815
cif_name (str or None): If a str, the name of the CIF file
28142816
to write the POSCAR to (the POSCAR will also be written).
28152817
zip_name (str or None): If a str, the name of the zip to
2816-
archive the vasp input set to.
2818+
archive the VASP input set to.
2819+
files_to_transfer (dict) : A dictionary of
2820+
{ < input filename >: < output filepath >}.
2821+
This allows the transfer of < input filename > files from
2822+
a previous calculation to < output filepath >.
28172823
"""
28182824
if not os.path.isdir(output_dir) and make_dir_if_not_present:
28192825
os.makedirs(output_dir)
@@ -2840,6 +2846,11 @@ def write_input(
28402846
except (FileNotFoundError, PermissionError, IsADirectoryError):
28412847
pass
28422848

2849+
files_to_transfer = files_to_transfer or {}
2850+
for key, val in files_to_transfer.items():
2851+
with zopen(val, "rb") as fin, zopen(str(Path(output_dir) / key), "wb") as fout:
2852+
copyfileobj(fin, fout)
2853+
28432854
@classmethod
28442855
def from_directory(
28452856
cls,

pymatgen/io/vasp/sets.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,7 @@ def write_input(
360360
make_dir_if_not_present=make_dir_if_not_present,
361361
cif_name=cif_name,
362362
zip_name=f"{type(self).__name__}.zip" if zip_output else None,
363+
files_to_transfer=self.files_to_transfer,
363364
)
364365

365366
def as_dict(self, verbosity=2):

0 commit comments

Comments
 (0)