Skip to content

Commit

Permalink
remove single-arg os.path.join('path') calls
Browse files Browse the repository at this point in the history
  • Loading branch information
janosh committed Oct 2, 2023
1 parent 1110551 commit 7cc629d
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 40 deletions.
10 changes: 2 additions & 8 deletions pymatgen/analysis/hhi.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,14 @@ def __init__(self):
for line in f:
if line[0] != "#":
symbol, hhi_production, hhi_reserve = line.split(",")
self.symbol_hhip_hhir[symbol] = (
float(hhi_production),
float(hhi_reserve),
)
self.symbol_hhip_hhir[symbol] = float(hhi_production), float(hhi_reserve)

def _get_hhi_el(self, el_or_symbol):
"""Returns the tuple of HHI_production, HHI reserve for a single element only."""
if isinstance(el_or_symbol, Element):
el_or_symbol = el_or_symbol.symbol

return (
self.symbol_hhip_hhir[el_or_symbol][0],
self.symbol_hhip_hhir[el_or_symbol][1],
)
return self.symbol_hhip_hhir[el_or_symbol][0], self.symbol_hhip_hhir[el_or_symbol][1]

def get_hhi(self, comp_or_form):
"""
Expand Down
8 changes: 4 additions & 4 deletions pymatgen/analysis/transition_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,10 +234,10 @@ def from_dir(cls, root_dir, relaxation_dirs=None, **kwargs):
"""
neb_dirs = []

for d in os.listdir(root_dir):
pth = os.path.join(root_dir, d)
if os.path.isdir(pth) and d.isdigit():
i = int(d)
for digit in os.listdir(root_dir):
pth = os.path.join(root_dir, digit)
if os.path.isdir(pth) and digit.isdigit():
i = int(digit)
neb_dirs.append((i, pth))
neb_dirs = sorted(neb_dirs, key=lambda d: d[0])
outcars = []
Expand Down
6 changes: 3 additions & 3 deletions pymatgen/io/lammps/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,9 +305,9 @@ def run(self, site_property=None):
self._write_input(input_dir=scratch_dir)
with open(os.path.join(scratch_dir, self.input_file)) as packmol_input, Popen(
self.packmol_bin, stdin=packmol_input, stdout=PIPE, stderr=PIPE
) as p:
(stdout, stderr) = p.communicate()
output_file = os.path.join(self.control_params["output"])
) as proc:
stdout, stderr = proc.communicate()
output_file = self.control_params["output"]
if os.path.isfile(output_file):
packed_mol = BabelMolAdaptor.from_file(output_file, self.control_params["filetype"])
packed_mol = packed_mol.pymatgen_mol
Expand Down
8 changes: 4 additions & 4 deletions tests/electronic_structure/test_plotter.py
Original file line number Diff line number Diff line change
Expand Up @@ -432,11 +432,11 @@ def test_plot_zt_temp(self):
class TestCohpPlotter(PymatgenTest):
def setUp(self):
path = f"{TEST_FILES_DIR}/cohp/complete_cohp_lobster.json"
with open(os.path.join(path)) as f:
self.cohp = CompleteCohp.from_dict(json.load(f))
with open(path) as file:
self.cohp = CompleteCohp.from_dict(json.load(file))
path = f"{TEST_FILES_DIR}/cohp/complete_coop_lobster.json"
with open(os.path.join(path)) as f:
self.coop = CompleteCohp.from_dict(json.load(f))
with open(path) as file:
self.coop = CompleteCohp.from_dict(json.load(file))
self.cohp_plot = CohpPlotter(zero_at_efermi=False)
self.coop_plot = CohpPlotter(are_coops=True)

Expand Down
18 changes: 5 additions & 13 deletions tests/io/lobster/test_inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2368,32 +2368,24 @@ def test_get_volumetricdata_imaginary(self):

def test_get_volumetricdata_density(self):
wave1 = Wavefunction(
filename=os.path.join(
TEST_FILES_DIR,
"cohp",
"LCAOWaveFunctionAfterLSO1PlotOfSpin1Kpoint1band1.gz",
),
filename=os.path.join(TEST_FILES_DIR, "cohp", "LCAOWaveFunctionAfterLSO1PlotOfSpin1Kpoint1band1.gz"),
structure=Structure.from_file(f"{TEST_FILES_DIR}/cohp/POSCAR_O.gz"),
)
volumetricdata_density = wave1.get_volumetricdata_density()
assert volumetricdata_density.data["total"][0, 0, 0] == approx((-3.0966 * -3.0966) + (-6.45895 * -6.45895))

def test_write_file(self):
wave1 = Wavefunction(
filename=os.path.join(
TEST_FILES_DIR,
"cohp",
"LCAOWaveFunctionAfterLSO1PlotOfSpin1Kpoint1band1.gz",
),
filename=f"{TEST_FILES_DIR}/cohp/LCAOWaveFunctionAfterLSO1PlotOfSpin1Kpoint1band1.gz",
structure=Structure.from_file(f"{TEST_FILES_DIR}/cohp/POSCAR_O.gz"),
)
wave1.write_file(filename=os.path.join("wavecar_test.vasp"), part="real")
wave1.write_file(filename="wavecar_test.vasp", part="real")
assert os.path.isfile("wavecar_test.vasp")

wave1.write_file(filename=os.path.join("wavecar_test.vasp"), part="imaginary")
wave1.write_file(filename="wavecar_test.vasp", part="imaginary")
assert os.path.isfile("wavecar_test.vasp")
os.remove("wavecar_test.vasp")
wave1.write_file(filename=os.path.join("density.vasp"), part="density")
wave1.write_file(filename="density.vasp", part="density")
assert os.path.isfile("density.vasp")
os.remove("density.vasp")

Expand Down
14 changes: 6 additions & 8 deletions tests/io/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
from pymatgen.io.core import InputFile, InputSet
from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest

test_dir = os.path.join(TEST_FILES_DIR)


class StructInputFile(InputFile):
"""Test implementation of an InputFile object for CIF."""
Expand Down Expand Up @@ -53,14 +51,14 @@ def test_file_io(self):
with pytest.raises(FileNotFoundError, match="No such file or directory: 'fakepath.cif'"):
StructInputFile.from_file("fakepath.cif")

sif = StructInputFile.from_file(f"{test_dir}/Li.cif")
sif = StructInputFile.from_file(f"{TEST_FILES_DIR}/Li.cif")
assert isinstance(sif.structure, Structure)

sif.write_file("newLi.cif")
assert os.path.exists("newLi.cif")

def test_msonable(self):
sif = StructInputFile.from_file(f"{test_dir}/Li.cif")
sif = StructInputFile.from_file(f"{TEST_FILES_DIR}/Li.cif")
sif_dict = sif.as_dict()
decoder = MontyDecoder()
temp_sif = decoder.process_decoded(sif_dict)
Expand All @@ -71,9 +69,9 @@ def test_msonable(self):
class TestInputSet(PymatgenTest):
@classmethod
def setUpClass(cls):
cls.sif1 = StructInputFile.from_file(f"{test_dir}/Li.cif")
cls.sif2 = StructInputFile.from_file(f"{test_dir}/LiFePO4.cif")
cls.sif3 = StructInputFile.from_file(f"{test_dir}/Li2O.cif")
cls.sif1 = StructInputFile.from_file(f"{TEST_FILES_DIR}/Li.cif")
cls.sif2 = StructInputFile.from_file(f"{TEST_FILES_DIR}/LiFePO4.cif")
cls.sif3 = StructInputFile.from_file(f"{TEST_FILES_DIR}/Li2O.cif")

def test_mapping(self):
sif1, sif2, sif3 = self.sif1, self.sif2, self.sif3
Expand All @@ -94,7 +92,7 @@ def test_mapping(self):
with pytest.raises(KeyError, match="'kwarg1'"):
inp_set["kwarg1"]

sif4 = StructInputFile.from_file(f"{test_dir}/CuCl.cif")
sif4 = StructInputFile.from_file(f"{TEST_FILES_DIR}/CuCl.cif")
inp_set["cif4"] = sif4
assert inp_set.inputs["cif4"] is sif4
assert len(inp_set) == 4
Expand Down

0 comments on commit 7cc629d

Please sign in to comment.