Skip to content

Commit

Permalink
Fix undiscovered tests (#3369)
Browse files Browse the repository at this point in the history
* replace _parse_string with str.strip in PotcarSingle.parse_functions

* use keyword args to dict.update()

* fix ruff

* convert (point_ops|shared_ops).pkl to json.gz in tests/files/site_symmetries

update tests/symmetry/test_site_symmetries.py to use json.gz files

* breaking: ETSF_Reader PascalCase to EtsfReader

typeidx_from_symbol snake_case to type_idx_from_symbol

* fix TestNEBAnalysis.runTest renamed test_run so pytest discovers and actually runs it

* snake_case test method names

* delete get_path helper in test_surface_analysis.py

* fix doc string indent

* no need for os.path.join in tests
  • Loading branch information
janosh authored Oct 2, 2023
1 parent 1749cf8 commit 7fe4f7b
Show file tree
Hide file tree
Showing 30 changed files with 248 additions and 314 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ ci:

repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.0.290
rev: v0.0.292
hooks:
- id: ruff
args: [--fix]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -592,14 +592,12 @@ def compute_structure_environments(
if info is None:
info = {}
info.update(
{
"local_geometry_finder": {
"parameters": {
"centering_type": self.centering_type,
"include_central_site_in_centroid": self.include_central_site_in_centroid,
"structure_refinement": self.structure_refinement,
"spg_analyzer_options": self.spg_analyzer_options,
}
local_geometry_finder={
"parameters": {
"centering_type": self.centering_type,
"include_central_site_in_centroid": self.include_central_site_in_centroid,
"structure_refinement": self.structure_refinement,
"spg_analyzer_options": self.spg_analyzer_options,
}
}
)
Expand All @@ -610,9 +608,9 @@ def compute_structure_environments(
)

if valences == "undefined":
firstsite = self.structure[0]
first_site = self.structure[0]
try:
sp = firstsite.specie
sp = first_site.specie
if isinstance(sp, Species):
self.valences = [int(site.specie.oxi_state) for site in self.structure]
else:
Expand Down
141 changes: 63 additions & 78 deletions pymatgen/analysis/phase_diagram.py
Original file line number Diff line number Diff line change
Expand Up @@ -2939,15 +2939,7 @@ def _create_plotly_element_annotations(self):
z += offset

annotation = plotly_layouts["default_annotation_layout"].copy()
annotation.update(
{
"x": x,
"y": y,
"font": font_dict,
"text": clean_formula,
"opacity": opacity,
}
)
annotation.update(x=x, y=y, font=font_dict, text=clean_formula, opacity=opacity)

if self._dim in (3, 4):
for d in ["xref", "yref"]:
Expand Down Expand Up @@ -3066,44 +3058,41 @@ def get_marker_props(coords, entries):
unstable_markers = plotly_layouts["default_unary_marker_settings"].copy()

stable_markers.update(
{
"x": [0] * len(stable_props["y"]),
"y": list(stable_props["x"]),
"name": "Stable",
"marker": {
"color": "darkgreen",
"size": 20,
"line": {"color": "black", "width": 2},
"symbol": "star",
},
"opacity": 0.9,
"hovertext": stable_props["texts"],
"error_y": {
"array": list(stable_props["uncertainties"]),
"type": "data",
"color": "gray",
"thickness": 2.5,
"width": 5,
},
}
x=[0] * len(stable_props["y"]),
y=list(stable_props["x"]),
name="Stable",
marker={
"color": "darkgreen",
"size": 20,
"line": {"color": "black", "width": 2},
"symbol": "star",
},
opacity=0.9,
hovertext=stable_props["texts"],
error_y={
"array": list(stable_props["uncertainties"]),
"type": "data",
"color": "gray",
"thickness": 2.5,
"width": 5,
},
)
plotly_layouts["unstable_colorscale"].copy()
unstable_markers.update(
{
"x": [0] * len(unstable_props["y"]),
"y": list(unstable_props["x"]),
"name": "Above Hull",
"marker": {
"color": unstable_props["energies"],
"colorscale": plotly_layouts["unstable_colorscale"],
"size": 16,
"symbol": "diamond-wide",
"line": {"color": "black", "width": 2},
},
"hovertext": unstable_props["texts"],
"opacity": 0.9,
}
x=[0] * len(unstable_props["y"]),
y=list(unstable_props["x"]),
name="Above Hull",
marker={
"color": unstable_props["energies"],
"colorscale": plotly_layouts["unstable_colorscale"],
"size": 16,
"symbol": "diamond-wide",
"line": {"color": "black", "width": 2},
},
hovertext=unstable_props["texts"],
opacity=0.9,
)

if highlight_entries:
highlight_markers = plotly_layouts["default_unary_marker_settings"].copy()
highlight_markers.update(
Expand Down Expand Up @@ -3134,21 +3123,19 @@ def get_marker_props(coords, entries):
unstable_markers = plotly_layouts["default_binary_marker_settings"].copy()

stable_markers.update(
{
"x": list(stable_props["x"]),
"y": list(stable_props["y"]),
"name": "Stable",
"marker": {"color": "darkgreen", "size": 16, "line": {"color": "black", "width": 2}},
"opacity": 0.99,
"hovertext": stable_props["texts"],
"error_y": {
"array": list(stable_props["uncertainties"]),
"type": "data",
"color": "gray",
"thickness": 2.5,
"width": 5,
},
}
x=list(stable_props["x"]),
y=list(stable_props["y"]),
name="Stable",
marker={"color": "darkgreen", "size": 16, "line": {"color": "black", "width": 2}},
opacity=0.99,
hovertext=stable_props["texts"],
error_y={
"array": list(stable_props["uncertainties"]),
"type": "data",
"color": "gray",
"thickness": 2.5,
"width": 5,
},
)
unstable_markers.update(
{
Expand All @@ -3169,26 +3156,24 @@ def get_marker_props(coords, entries):
if highlight_entries:
highlight_markers = plotly_layouts["default_binary_marker_settings"].copy()
highlight_markers.update(
{
"x": list(highlight_props["x"]),
"y": list(highlight_props["y"]),
"name": "Highlighted",
"marker": {
"color": "mediumvioletred",
"size": 16,
"line": {"color": "black", "width": 2},
"symbol": "square",
},
"opacity": 0.99,
"hovertext": highlight_props["texts"],
"error_y": {
"array": list(highlight_props["uncertainties"]),
"type": "data",
"color": "gray",
"thickness": 2.5,
"width": 5,
},
}
x=list(highlight_props["x"]),
y=list(highlight_props["y"]),
name="Highlighted",
marker={
"color": "mediumvioletred",
"size": 16,
"line": {"color": "black", "width": 2},
"symbol": "square",
},
opacity=0.99,
hovertext=highlight_props["texts"],
error_y={
"array": list(highlight_props["uncertainties"]),
"type": "data",
"color": "gray",
"thickness": 2.5,
"width": 5,
},
)

elif self._dim == 3 and self.ternary_style == "2d":
Expand Down
12 changes: 5 additions & 7 deletions pymatgen/apps/battery/insertion_battery.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,13 +333,11 @@ def get_summary_dict(self, print_subelectrodes=True) -> dict:
)
if all("decomposition_energy" in itr_ent.data for itr_ent in self.get_all_entries()):
dct.update(
{
"stability_charge": self.fully_charged_entry.data["decomposition_energy"],
"stability_discharge": self.fully_discharged_entry.data["decomposition_energy"],
"stability_data": {
itr_ent.entry_id: itr_ent.data["decomposition_energy"] for itr_ent in self.get_all_entries()
},
}
stability_charge=self.fully_charged_entry.data["decomposition_energy"],
stability_discharge=self.fully_discharged_entry.data["decomposition_energy"],
stability_data={
itr_ent.entry_id: itr_ent.data["decomposition_energy"] for itr_ent in self.get_all_entries()
},
)

if all("muO2" in itr_ent.data for itr_ent in self.get_all_entries()):
Expand Down
2 changes: 1 addition & 1 deletion pymatgen/io/abinit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from .netcdf import (
NO_DEFAULT,
ETSF_Reader,
EtsfReader,
NetcdfReader,
NetcdfReaderError,
as_etsfreader,
Expand Down
8 changes: 4 additions & 4 deletions pymatgen/io/abinit/netcdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ def as_ncreader(file):


def as_etsfreader(file):
"""Return an ETSF_Reader. Accepts filename or ETSF_Reader."""
return _asreader(file, ETSF_Reader)
"""Return an EtsfReader. Accepts filename or EtsfReader."""
return _asreader(file, EtsfReader)


class NetcdfReaderError(Exception):
Expand Down Expand Up @@ -233,7 +233,7 @@ def read_keys(self, keys, dict_cls=AttrDict, path="/"):
return od


class ETSF_Reader(NetcdfReader):
class EtsfReader(NetcdfReader):
"""
This object reads data from a file written according to the ETSF-IO specifications.
Expand All @@ -251,7 +251,7 @@ def chemical_symbols(self):

return symbols

def typeidx_from_symbol(self, symbol):
def type_idx_from_symbol(self, symbol):
"""Returns the type index from the chemical symbol. Note python convention."""
return self.chemical_symbols.index(symbol)

Expand Down
22 changes: 11 additions & 11 deletions pymatgen/io/abinit/variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,38 +149,38 @@ def format_scalar(val, float_decimal=0):
@staticmethod
def format_list2d(values, float_decimal=0):
"""Format a list of lists."""
lvals = flatten(values)
flattened_list = flatten(values)

# Determine the representation
if all(isinstance(v, int) for v in lvals):
if all(isinstance(v, int) for v in flattened_list):
type_all = int
else:
try:
for v in lvals:
for v in flattened_list:
float(v)
type_all = float
except Exception:
type_all = str

# Determine the format
width = max(len(str(s)) for s in lvals)
width = max(len(str(s)) for s in flattened_list)
if type_all == int:
fmt_spec = f">{width}d"
elif type_all == str:
fmt_spec = f">{width}"
else:
# Number of decimal
max_dec = max(len(str(f - int(f))) - 2 for f in lvals)
ndec = min(max(max_dec, float_decimal), 10)
max_dec = max(len(str(f - int(f))) - 2 for f in flattened_list)
n_dec = min(max(max_dec, float_decimal), 10)

if all(f == 0 or (abs(f) > 1e-3 and abs(f) < 1e4) for f in lvals):
fmt_spec = f">{ndec + 5}.{ndec}f"
if all(f == 0 or (abs(f) > 1e-3 and abs(f) < 1e4) for f in flattened_list):
fmt_spec = f">{n_dec + 5}.{n_dec}f"
else:
fmt_spec = f">{ndec + 8}.{ndec}e"
fmt_spec = f">{n_dec + 8}.{n_dec}e" # noqa: F841

line = "\n"
for L in values:
for val in L:
for lst in values:
for val in lst:
line += f" {val:{{fmt_spec}}}"
line += "\n"

Expand Down
18 changes: 9 additions & 9 deletions pymatgen/io/exciting/inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,15 +157,15 @@ def write_etree(self, celltype, cartesian=False, bandstr=False, symprec: float =
Args:
celltype (str): Choice of unit cell. Can be either the unit cell
from self.structure ("unchanged"), the conventional cell
("conventional"), or the primitive unit cell ("primitive").
from self.structure ("unchanged"), the conventional cell
("conventional"), or the primitive unit cell ("primitive").
cartesian (bool): Whether the atomic positions are provided in
Cartesian or unit-cell coordinates. Default is False.
Cartesian or unit-cell coordinates. Default is False.
bandstr (bool): Whether the bandstructure path along the
HighSymmKpath is included in the input file. Only supported if the
celltype is set to "primitive". Default is False.
HighSymmKpath is included in the input file. Only supported if the
celltype is set to "primitive". Default is False.
symprec (float): Tolerance for the symmetry finding. Default is 0.4.
Expand Down Expand Up @@ -207,8 +207,8 @@ def write_etree(self, celltype, cartesian=False, bandstr=False, symprec: float =
# write lattice
basis = new_struct.lattice.matrix
for idx in range(3):
basevect = ET.SubElement(crystal, "basevect")
basevect.text = f"{basis[idx][0]:16.8f} {basis[idx][1]:16.8f} {basis[idx][2]:16.8f}"
base_vec = ET.SubElement(crystal, "basevect")
base_vec.text = f"{basis[idx][0]:16.8f} {basis[idx][1]:16.8f} {basis[idx][2]:16.8f}"
# write atomic positions for each species
index = 0
for elem in sorted(new_struct.types_of_species, key=lambda el: el.X):
Expand Down Expand Up @@ -237,9 +237,9 @@ def write_etree(self, celltype, cartesian=False, bandstr=False, symprec: float =
if bandstr and celltype == "primitive":
kpath = HighSymmKpath(new_struct, symprec=symprec, angle_tolerance=angle_tolerance)
prop = ET.SubElement(root, "properties")
bandstrct = ET.SubElement(prop, "bandstructure")
band_struct = ET.SubElement(prop, "bandstructure")
for idx in range(len(kpath.kpath["path"])):
plot = ET.SubElement(bandstrct, "plot1d")
plot = ET.SubElement(band_struct, "plot1d")
path = ET.SubElement(plot, "path", steps="100")
for j in range(len(kpath.kpath["path"][idx])):
symbol = kpath.kpath["path"][idx][j]
Expand Down
Loading

0 comments on commit 7fe4f7b

Please sign in to comment.