Skip to content

Commit

Permalink
Pre-commit fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
AntObi committed Aug 30, 2024
1 parent 8a80bbb commit 2369591
Show file tree
Hide file tree
Showing 11 changed files with 26 additions and 44 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ This is a quick guide on how to follow best practice and contribute smoothly to

## Workflow

We follow the [GitHub flow](<https://docs.github.com/en/get-started/using-github/github-flow>), using
We follow the [GitHub flow](https://docs.github.com/en/get-started/using-github/github-flow), using
branches for new work and pull requests for verifying the work.

The steps for a new piece of work can be summarised as follows:
Expand Down
2 changes: 1 addition & 1 deletion docs/smact.utils.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
SMACT Utilities module
===========================

The utilities module provides some utilty functions to support the core functionalities of SMACT
The utilities module provides some utility functions to support the core functionalities of SMACT

Submodules
----------
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -269,5 +269,6 @@ ignore-words-list = [
"Cm",
"Bk",
"eles",
"assertIn"
"assertIn",
"Mater",
]
3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
__author__ = "The SMACT Developers"
__author_email__ = "[email protected]"
__copyright__ = "Copyright Daniel W. Davies, Adam J. Jackson, Keith T. Butler (2019)"
__version__ = "2.6"
__version__ = "2.7"
__maintainer__ = "Anthony O. Onwuli"
__maintainer_email__ = "[email protected]"
__date__ = "August 30 2024"
Expand All @@ -33,7 +33,6 @@
author_email=__author_email__,
maintainer=__maintainer__,
maintainer_email=__maintainer_email__,
maintainer_email=__maintainer_email__,
license="MIT",
packages=[
"smact",
Expand Down
4 changes: 1 addition & 3 deletions smact/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,7 @@ def __init__(self, symbol: str, oxi_states_custom_filepath: str | None = None):
num_valence = None

valence_data = data_loader.lookup_element_valence_data(symbol)
num_valence_modified = (
valence_data["NValence"] if valence_data else None
)
num_valence_modified = valence_data["NValence"] if valence_data else None

for attribute, value in (
("coord_envs", coord_envs),
Expand Down
16 changes: 3 additions & 13 deletions smact/data_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -825,7 +825,6 @@ def lookup_element_magpie_data(symbol: str, copy: bool = True):
"""

global _element_magpie_data

if _element_magpie_data is None:
Expand Down Expand Up @@ -865,10 +864,7 @@ def lookup_element_magpie_data(symbol: str, copy: bool = True):
return _element_magpie_data[symbol]
else:
if _print_warnings:
print(
"WARNING: Magpie data for element {} not "
"found.".format(symbol)
)
print(f"WARNING: Magpie data for element {symbol} not " "found.")

return None

Expand Down Expand Up @@ -897,15 +893,12 @@ def lookup_element_valence_data(symbol: str, copy: bool = True):
Returns None if the element was not found among the external
data.
"""

global _element_valence_data

if _element_valence_data is None:
_element_valence_data = {}

df = pd.read_csv(
os.path.join(data_directory, "element_valence_modified.csv")
)
df = pd.read_csv(os.path.join(data_directory, "element_valence_modified.csv"))
for _index, row in df.iterrows():
key = row.iloc[0]

Expand All @@ -916,9 +909,6 @@ def lookup_element_valence_data(symbol: str, copy: bool = True):
return _element_valence_data[symbol]
else:
if _print_warnings:
print(
"WARNING: Valence data for element {} not "
"found.".format(symbol)
)
print(f"WARNING: Valence data for element {symbol} not " "found.")

return None
7 changes: 2 additions & 5 deletions smact/properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,7 @@ def get_element_valence(element: str) -> int:
try:
return smact.Element(element).num_valence_modified
except NameError:
raise ValueError(
f"Valence data not found for element: {element}"
) from None
raise ValueError(f"Valence data not found for element: {element}") from None

element_stoich = parse_formula(compound)

Expand All @@ -203,5 +201,4 @@ def get_element_valence(element: str) -> int:
if total_stoich == 0:
return 0.0

vec = total_valence / total_stoich
return vec
return total_valence / total_stoich
9 changes: 5 additions & 4 deletions smact/screening.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,13 +337,13 @@ def smact_filter(
species_unique: bool = True,
oxidation_states_set: str = "smact14",
comp_tuple: bool = False,
) -> Union[List[Tuple[str, int, int]], List[Tuple[str, int]]]:
) -> list[tuple[str, int, int]] | list[tuple[str, int]]:
"""Function that applies the charge neutrality and electronegativity
tests in one go for simple application in external scripts that
wish to apply the general 'smact test'.
.. warning::
For backwards compatability in SMACT >=2.7, expllicitly set oxidation_states_set to 'smact14' if you wish to use the 2014 SMACT default oxidation states.
For backwards compatibility in SMACT >=2.7, expllicitly set oxidation_states_set to 'smact14' if you wish to use the 2014 SMACT default oxidation states.
In SMACT 3.0, the smact_filter function will be set to use a new default oxidation states set.
Args:
Expand All @@ -354,6 +354,7 @@ def smact_filter(
species_unique (bool): Whether or not to consider elements in different oxidation states as unique in the results.
oxidation_states_set (string): A string to choose which set of oxidation states should be chosen. Options are 'smact14', 'icsd', 'pymatgen' and 'wiki' for the 2014 SMACT default, 2016 ICSD, pymatgen structure predictor and Wikipedia (https://en.wikipedia.org/wiki/Template:List_of_oxidation_states_of_the_elements) oxidation states respectively. A filepath to an oxidation states text file can also be supplied as well.
comp_tuple (bool): Whether or not to return the results as a named tuple of elements and stoichiometries (True) or as a normal tuple of elements and stoichiometries (False).
Returns:
-------
allowed_comps (list): Allowed compositions for that chemical system
Expand Down Expand Up @@ -436,15 +437,15 @@ def smact_validity(
composition: pymatgen.core.Composition | str,
use_pauling_test: bool = True,
include_alloys: bool = True,
oxidation_states_set: Union[str, bytes, os.PathLike] = "smact14",
oxidation_states_set: str | bytes | os.PathLike = "smact14",
) -> bool:
"""
Check if a composition is valid according to the SMACT rules.
Composition is considered valid if it passes the charge neutrality test and the Pauling electronegativity test.
.. warning::
For backwards compatability in SMACT >=2.7, expllicitly set oxidation_states_set to 'smact14' if you wish to use the 2014 SMACT default oxidation states.
For backwards compatibility in SMACT >=2.7, expllicitly set oxidation_states_set to 'smact14' if you wish to use the 2014 SMACT default oxidation states.
In SMACT 3.0, the smact_filter function will be set to use a new default oxidation states set.
Args:
Expand Down
5 changes: 3 additions & 2 deletions smact/tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import os
import unittest

import pytest
from pymatgen.core import Structure
from pymatgen.core.periodic_table import Specie

Expand Down Expand Up @@ -96,10 +97,10 @@ def test_valence_electron_count(self):
self.assertEqual(valence_electron_count(""), 0.0)

# Test invalid elements and formats
with self.assertRaises(ValueError):
with pytest.raises(ValueError):
valence_electron_count("Xx2O3") # Xx is not a real element

with self.assertRaises(ValueError):
with pytest.raises(ValueError):
valence_electron_count("LrO")

# ---------------- BUILDER ----------------
Expand Down
6 changes: 3 additions & 3 deletions smact/tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import unittest

from pymatgen.core import Composition
Expand Down Expand Up @@ -59,9 +61,7 @@ def test_comp_maker(self):
self.assertEqual(Composition("FeO"), comp2)
self.assertEqual(Composition({"Fe2+": 1, "O2-": 1}), comp1)
self.assertEqual(Composition({"Fe2+": 1, "Fe3+": 2, "O2-": 4}), comp3)
self.assertEqual(
Composition({"Li+": 10, "Ge4+": 1, "P5+": 2, "S2-": 12}), comp4
)
self.assertEqual(Composition({"Li+": 10, "Ge4+": 1, "P5+": 2, "S2-": 12}), comp4)

def test_formula_maker(self):
"""Test the formula_maker function"""
Expand Down
13 changes: 4 additions & 9 deletions smact/utils/composition.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Utility functioms for handling elements, species, formulas and composition"""

from __future__ import annotations

import re
Expand Down Expand Up @@ -27,9 +28,7 @@ def parse_formula(formula: str) -> dict[str, float]:
if m.group(2) != "":
factor = float(m.group(2))
unit_sym_dict = _get_sym_dict(m.group(1), factor)
expanded_sym = "".join(
[f"{el}{amt}" for el, amt in unit_sym_dict.items()]
)
expanded_sym = "".join([f"{el}{amt}" for el, amt in unit_sym_dict.items()])
expanded_formula = formula.replace(m.group(), expanded_sym)
return parse_formula(expanded_formula)
return _get_sym_dict(formula, 1)
Expand All @@ -53,9 +52,7 @@ def _get_sym_dict(formula: str, factor: float) -> dict[str, float]:
return sym_dict


def comp_maker(
smact_filter_output: tuple[str, int, int] | tuple[str, int]
) -> Composition:
def comp_maker(smact_filter_output: tuple[str, int, int] | tuple[str, int]) -> Composition:
"""Convert an item in the output of smact.screening.smact_filer into a Pymatgen Composition.
Args:
Expand All @@ -82,9 +79,7 @@ def comp_maker(
return Composition(form)


def formula_maker(
smact_filter_output: tuple[str, int, int] | tuple[str, int]
) -> str:
def formula_maker(smact_filter_output: tuple[str, int, int] | tuple[str, int]) -> str:
"""Convert an item in the output of smact.screening.smact_filter into a chemical formula.
Args:
Expand Down

0 comments on commit 2369591

Please sign in to comment.