Skip to content

Commit dc5f895

Browse files
author
Shyue Ping Ong
committed
Merge branch 'master' of github.com:materialsproject/pymatgen
2 parents ba7e121 + c764dc9 commit dc5f895

File tree

7 files changed

+46
-58
lines changed

7 files changed

+46
-58
lines changed

pymatgen/core/structure.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1271,7 +1271,7 @@ def __eq__(self, other: object) -> bool:
12711271
# return NotImplemented as in https://docs.python.org/3/library/functools.html#functools.total_ordering
12721272
return NotImplemented
12731273

1274-
other = cast(Structure, other) # to make mypy happy
1274+
other = cast(Structure, other) # make mypy happy
12751275

12761276
if other is self:
12771277
return True

pymatgen/electronic_structure/plotter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ def get_plot(
233233
# Remove duplicate labels with a dictionary
234234
handles, labels = ax.get_legend_handles_labels()
235235
label_dict = dict(zip(labels, handles))
236-
ax.legend(label_dict.values(), label_dict.keys())
236+
ax.legend(label_dict.values(), label_dict)
237237
legend_text = ax.get_legend().get_texts() # all the text.Text instance in the legend
238238
plt.setp(legend_text, fontsize=30)
239239
plt.tight_layout()

pymatgen/io/lammps/inputs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,7 @@ def _initialize_stage(self, stage_name: str | None = None, stage_index: int | No
669669

670670
@staticmethod
671671
def _check_stage_format(stage: dict):
672-
if list(stage.keys()) != ["stage_name", "commands"]:
672+
if list(stage) != ["stage_name", "commands"]:
673673
raise KeyError(
674674
"The provided stage does not have the correct keys. It should be 'stage_name' and 'commands'."
675675
)

pymatgen/io/vasp/sets.py

Lines changed: 26 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -932,28 +932,30 @@ class MPScanRelaxSet(DictSet):
932932
CONFIG = _load_yaml_config("MPSCANRelaxSet")
933933
_valid_potcars = ("PBE_52", "PBE_54")
934934

935-
def __init__(self, structure: Structure, bandgap=0, **kwargs):
935+
def __init__(self, structure: Structure, bandgap: float = 0, bandgap_tol: float = 1e-4, **kwargs) -> None:
936936
"""
937937
Args:
938938
structure (Structure): Input structure.
939-
bandgap (int): Bandgap of the structure in eV. The bandgap is used to
940-
compute the appropriate k-point density and determine the
941-
smearing settings.
942-
943-
Metallic systems (default, bandgap = 0) use a KSPACING value of 0.22
944-
and Methfessel-Paxton order 2 smearing (ISMEAR=2, SIGMA=0.2).
945-
946-
Non-metallic systems (bandgap > 0) use the tetrahedron smearing
947-
method (ISMEAR=-5, SIGMA=0.05). The KSPACING value is
948-
calculated from the bandgap via Eqs. 25 and 29 of Wisesa, McGill,
949-
and Mueller [1] (see References). Note that if 'user_incar_settings'
950-
or 'user_kpoints_settings' override KSPACING, the calculation from
951-
bandgap is not performed.
952-
939+
bandgap (float): Bandgap of the structure in eV. The bandgap is used to
940+
compute the appropriate k-point density and determine the
941+
smearing settings.
942+
943+
Metallic systems (default, bandgap = 0) use a KSPACING value of 0.22
944+
and Methfessel-Paxton order 2 smearing (ISMEAR=2, SIGMA=0.2).
945+
946+
Non-metallic systems (bandgap > 0) use the tetrahedron smearing
947+
method (ISMEAR=-5, SIGMA=0.05). The KSPACING value is
948+
calculated from the bandgap via Eqs. 25 and 29 of Wisesa, McGill,
949+
and Mueller [1] (see References). Note that if 'user_incar_settings'
950+
or 'user_kpoints_settings' override KSPACING, the calculation from
951+
bandgap is not performed.
952+
bandgap_tol (float): Tolerance for determining if a system is metallic.
953+
If the bandgap is less than this value, the system is considered
954+
metallic. Defaults to 1e-4 (eV).
953955
vdw (str): set "rVV10" to enable SCAN+rVV10, which is a versatile
954-
van der Waals density functional by combing the SCAN functional
955-
with the rVV10 non-local correlation functional. rvv10 is the only
956-
dispersion correction available for SCAN at this time.
956+
van der Waals density functional by combing the SCAN functional
957+
with the rVV10 non-local correlation functional. rvv10 is the only
958+
dispersion correction available for SCAN at this time.
957959
**kwargs: Same as those supported by DictSet.
958960
959961
References:
@@ -966,33 +968,21 @@ def __init__(self, structure: Structure, bandgap=0, **kwargs):
966968
super().__init__(structure, MPScanRelaxSet.CONFIG, **kwargs)
967969
self.bandgap = bandgap
968970
self.kwargs = kwargs
971+
self.bandgap_tol = bandgap_tol
969972

970-
updates = {}
973+
updates: dict[str, float] = {}
971974
# select the KSPACING and smearing parameters based on the bandgap
972975
if self.bandgap < 1e-4:
973-
updates["KSPACING"] = 0.22
974-
updates["SIGMA"] = 0.2
975-
updates["ISMEAR"] = 2
976+
updates.update(KSPACING=0.22, SIGMA=0.2, ISMEAR=2)
976977
else:
977978
rmin = 25.22 - 2.87 * bandgap # Eq. 25
978979
kspacing = 2 * np.pi * 1.0265 / (rmin - 1.0183) # Eq. 29
979980
# cap the KSPACING at a max of 0.44, per internal benchmarking
980-
if 0.22 < kspacing < 0.44:
981-
updates["KSPACING"] = kspacing
982-
else:
983-
updates["KSPACING"] = 0.44
984-
updates["ISMEAR"] = -5
985-
updates["SIGMA"] = 0.05
981+
updates.update(KSPACING=kspacing if 0.22 < kspacing < 0.44 else 0.44, SIGMA=0.05, ISMEAR=-5)
986982

987983
# Don't overwrite things the user has supplied
988-
if self.user_incar_settings.get("KSPACING"):
989-
del updates["KSPACING"]
990-
991-
if self.user_incar_settings.get("ISMEAR"):
992-
del updates["ISMEAR"]
993-
994-
if self.user_incar_settings.get("SIGMA"):
995-
del updates["SIGMA"]
984+
for key in self.user_incar_settings:
985+
updates.pop(key, None)
996986

997987
if self.vdw and self.vdw != "rvv10":
998988
warnings.warn("Use of van der waals functionals other than rVV10 with SCAN is not supported at this time. ")

tests/electronic_structure/test_plotter.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import matplotlib.pyplot as plt
99
import numpy as np
1010
import scipy
11+
from matplotlib import rc
1112
from numpy.testing import assert_allclose
1213
from pytest import approx
1314

@@ -54,8 +55,6 @@ def test_get_dos_dict(self):
5455
# it can actually execute.
5556
def test_get_plot(self):
5657
# Disabling latex is needed for this test to work.
57-
from matplotlib import rc
58-
5958
rc("text", usetex=False)
6059
self.plotter.add_dos_dict(self.dos.get_element_dos(), key_sort_func=lambda x: x.X)
6160
ax = self.plotter.get_plot()

tests/io/qchem/test_outputs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ def test_cmirs_water(self):
468468

469469
def test_NBO_hyperbonds(self):
470470
data = QCOutput(f"{TEST_FILES_DIR}/molecules/new_qchem_files/hyper.qout").data
471-
assert len(data["nbo_data"]["hyperbonds"][0]["hyperbond index"].keys()) == 2
471+
assert len(data["nbo_data"]["hyperbonds"][0]["hyperbond index"]) == 2
472472
assert data["nbo_data"]["hyperbonds"][0]["BD(A-B)"][1] == 106
473473
assert data["nbo_data"]["hyperbonds"][0]["bond atom 2 symbol"][0] == "C"
474474
assert data["nbo_data"]["hyperbonds"][0]["occ"][1] == 3.0802

tests/io/vasp/test_sets.py

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1483,25 +1483,24 @@ def test_scan_substitute(self):
14831483
incar = mp_scan_sub.incar
14841484
assert incar["METAGGA"] == "Scan"
14851485

1486-
def test_nonmetal(self):
1487-
# Test that KSPACING and ISMEAR change with a nonmetal structure
1488-
file_path = f"{TEST_FILES_DIR}/POSCAR.O2"
1489-
struct = Poscar.from_file(file_path, check_for_POTCAR=False).structure
1490-
scan_nonmetal_set = MPScanRelaxSet(struct, bandgap=1.1)
1491-
incar = scan_nonmetal_set.incar
1492-
assert incar["KSPACING"] == approx(0.3064757, abs=1e-5)
1493-
assert incar["ISMEAR"] == -5
1494-
assert incar["SIGMA"] == 0.05
1495-
1496-
def test_kspacing_cap(self):
1486+
def test_bandgap_tol(self):
1487+
# Test that the bandgap tolerance is applied correctly
1488+
bandgap = 0.01
1489+
for bandgap_tol, expected_kspacing in ((0.001, 0.2668137888), (0.02, 0.26681378884)):
1490+
incar = MPScanRelaxSet(self.struct, bandgap=0.01, bandgap_tol=bandgap_tol).incar
1491+
assert incar["KSPACING"] == approx(expected_kspacing, abs=1e-5), f"{bandgap_tol=}, {bandgap=}"
1492+
assert incar["ISMEAR"] == -5
1493+
assert incar["SIGMA"] == 0.05
1494+
1495+
def test_kspacing(self):
14971496
# Test that KSPACING is capped at 0.44 for insulators
14981497
file_path = f"{TEST_FILES_DIR}/POSCAR.O2"
14991498
struct = Poscar.from_file(file_path, check_for_POTCAR=False).structure
1500-
scan_nonmetal_set = MPScanRelaxSet(struct, bandgap=10)
1501-
incar = scan_nonmetal_set.incar
1502-
assert incar["KSPACING"] == approx(0.44, abs=1e-5)
1503-
assert incar["ISMEAR"] == -5
1504-
assert incar["SIGMA"] == 0.05
1499+
for bandgap, expected in ((10, 0.44), (3, 0.4136617), (1.1, 0.3064757)):
1500+
incar = MPScanRelaxSet(struct, bandgap=bandgap).incar
1501+
assert incar["KSPACING"] == approx(expected, abs=1e-5)
1502+
assert incar["ISMEAR"] == -5
1503+
assert incar["SIGMA"] == 0.05
15051504

15061505
def test_incar_overrides(self):
15071506
# use 'user_incar_settings' to override the KSPACING, ISMEAR, and SIGMA

0 commit comments

Comments
 (0)