Skip to content

Commit 00a25ee

Browse files
move file transfer from write_input method of VaspInputSet to VaspInput
1 parent 5f6c8f9 commit 00a25ee

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
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/base.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
from __future__ import annotations
3030

3131
import abc
32-
import shutil
3332
import warnings
3433
from copy import deepcopy
3534
from dataclasses import dataclass, field
@@ -39,7 +38,6 @@
3938

4039
import numpy as np
4140
from monty.dev import deprecated
42-
from monty.io import zopen
4341
from monty.json import MSONable
4442
from monty.serialization import loadfn
4543

@@ -368,12 +366,9 @@ def write_input(
368366
make_dir_if_not_present=make_dir_if_not_present,
369367
cif_name=cif_name,
370368
zip_name=f"{type(self).__name__}.zip" if zip_output else None,
369+
files_to_transfer=self.files_to_transfer,
371370
)
372371

373-
for key, val in self.files_to_transfer.items():
374-
with zopen(val, "rb") as fin, zopen(str(Path(output_dir) / key), "wb") as fout:
375-
shutil.copyfileobj(fin, fout)
376-
377372
def as_dict(self, verbosity=2):
378373
"""
379374
Args:

0 commit comments

Comments
 (0)