Skip to content

Commit

Permalink
Merge pull request #755 from janosh/from-monty-to-shutil-which
Browse files Browse the repository at this point in the history
From `monty` to `shutil` `which`
  • Loading branch information
Zhuoying authored May 18, 2022
2 parents 5b84933 + a3efc15 commit 0e4547f
Show file tree
Hide file tree
Showing 10 changed files with 118 additions and 109 deletions.
17 changes: 12 additions & 5 deletions atomate/common/firetasks/glue_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,13 @@ class CopyFilesFromCalcLoc(FiretaskBase):
"""

required_params = ["calc_loc"]
optional_params = ["filenames", "name_prepend",
"name_append", "exclude_files",
"decompress"]
optional_params = [
"filenames",
"name_prepend",
"name_append",
"exclude_files",
"decompress",
]

def run_task(self, fw_spec=None):
calc_loc = get_calc_loc(self["calc_loc"], fw_spec["calc_locs"])
Expand Down Expand Up @@ -146,13 +150,16 @@ def run_task(self, fw_spec=None):
for f in files_to_copy:
prev_path_full = os.path.join(calc_dir, f)
f, ext = os.path.splitext(f)
dest_fname = self.get("name_prepend", "") + f + self.get("name_append", "") + ext
dest_fname = (
self.get("name_prepend", "") + f + self.get("name_append", "") + ext
)
dest_path = os.path.join(os.getcwd(), dest_fname)

fileclient.copy(prev_path_full, dest_path)
if self.get("decompress",False):
if self.get("decompress", False):
monty.shutil.decompress_file(dest_path)


@explicit_serialize
class DeleteFiles(FiretaskBase):
"""
Expand Down
2 changes: 1 addition & 1 deletion atomate/qchem/firetasks/tests/test_critic2.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
import os
import shutil
import unittest
from shutil import which

from monty.os.path import which
from pymatgen.io.qchem.outputs import QCOutput

from atomate.qchem.firetasks.critic2 import ProcessCritic2, RunCritic2
Expand Down
2 changes: 1 addition & 1 deletion atomate/vasp/analysis/phonopy.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,6 @@ def get_phonopy_thermal_expansion(

# thermal expansion coefficient and temperature
max_t_index = phonopy_qha._qha._len
alpha = phonopy_qha.get_thermal_expansion()[: max_t_index]
alpha = phonopy_qha.get_thermal_expansion()[:max_t_index]
T = phonopy_qha._qha._temperatures[:max_t_index]
return alpha, T
6 changes: 3 additions & 3 deletions atomate/vasp/drones.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
import traceback
import warnings
from fnmatch import fnmatch
from shutil import which

import numpy as np
from monty.io import zopen
from monty.json import jsanitize
from monty.os.path import which
from pymatgen.apps.borg.hive import AbstractDrone
from pymatgen.command_line.bader_caller import bader_analysis_from_path
from pymatgen.core.composition import Composition
Expand Down Expand Up @@ -420,7 +420,7 @@ def generate_doc(self, dir_name, vasprun_files, outcar_files):
d["output"][k] = d_calc_final["output"][k]

# store optical data, overwrites the LOPTICS data
if d["input"]["incar"].get("ALGO") == 'CHI':
if d["input"]["incar"].get("ALGO") == "CHI":
for k in ["optical_absorption_coeff", "dielectric"]:
d["output"][k] = d_calc_final["output"][k]

Expand Down Expand Up @@ -588,7 +588,7 @@ def process_vasprun(self, dir_name, taskname, filename):
d["output"]["optical_absorption_coeff"] = vrun.optical_absorption_coeff

# parse output from response function
if vrun.incar.get("ALGO") == 'CHI':
if vrun.incar.get("ALGO") == "CHI":
dielectric = vrun.dielectric
d["output"]["dielectric"] = dict(
energy=dielectric[0], real=dielectric[1], imag=dielectric[2]
Expand Down
15 changes: 3 additions & 12 deletions atomate/vasp/firetasks/absorption_tasks.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,6 @@
import os
from importlib import import_module

import numpy as np

from monty.serialization import dumpfn
from fireworks import FiretaskBase, explicit_serialize
from fireworks.utilities.dict_mods import apply_mod
from pymatgen.core.structure import Structure
from pymatgen.io.vasp import Incar, Poscar, Potcar, PotcarSingle, Kpoints
from pymatgen.io.vasp.sets import MPAbsorptionSet
from pymatgen.io.vasp.outputs import Vasprun
from atomate.utils.utils import env_chk, load_class


@explicit_serialize
class WriteVaspAbsorptionFromPrev(FiretaskBase):
Expand All @@ -25,6 +15,7 @@ class WriteVaspAbsorptionFromPrev(FiretaskBase):
"potcar_spec"
"""

optional_params = [
"prev_calc_dir",
"structure",
Expand All @@ -37,7 +28,7 @@ class WriteVaspAbsorptionFromPrev(FiretaskBase):
"ncores",
"nedos",
"potcar_spec",
"other_params"
"other_params",
]

def run_task(self, fw_spec):
Expand Down
4 changes: 2 additions & 2 deletions atomate/vasp/firetasks/glue_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,14 +290,14 @@ def interpolate_poscar(self, fw_spec):
# use CopyFilesFromCalcLoc to get files from previous locations.
CopyFilesFromCalcLoc(
calc_loc=self["start"],
filenames=["CONTCAR","CONTCAR.gz"],
filenames=["CONTCAR", "CONTCAR.gz"],
name_prepend=interpolate_folder + os.sep,
name_append="_0",
decompress=True,
).run_task(fw_spec=fw_spec)
CopyFilesFromCalcLoc(
calc_loc=self["end"],
filenames=["CONTCAR","CONTCAR.gz"],
filenames=["CONTCAR", "CONTCAR.gz"],
name_prepend=interpolate_folder + os.sep,
name_append="_1",
decompress=True,
Expand Down
2 changes: 1 addition & 1 deletion atomate/vasp/firetasks/tests/test_exchange.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import os
import unittest
from shutil import which

import pandas as pd
from monty.os.path import which
from pymatgen.core import Structure

from atomate.utils.testing import AtomateTest
Expand Down
Loading

0 comments on commit 0e4547f

Please sign in to comment.