Skip to content

Commit

Permalink
refactor: Improve code readability and reducing code duplications (#127)
Browse files Browse the repository at this point in the history
* refactor: Improve code readability and  reducing code duplications

- Using tuples to reperesent the non-diagonal elements via dictionary

* feat: Update poetry-core version and add pytest configuration with new tests for LigandFieldTheory

* test: Mark eigensolver_invalid_input test as expected failure due to unimplemented functionality

* chore: 🗃️ Moving test file

* chore: Clean up configuration files and update changelog formatting

* refactor: Improve test readability by formatting and organizing parameterized tests

* style: Format code for improved readability by adjusting line breaks and spacing

* fix: Correct comment from 'd3' to 'd2' for clarity in batch processing logic

* chore: Update pyproject.toml for improved dependency formatting and linting rules

* refactor: Enhance type hinting and improve code readability in tools and test files

* style: Improve docstring formatting and add missing method descriptions in matrices.py
  • Loading branch information
Anselmoo authored Nov 16, 2024
1 parent a6d958c commit 6a2dae6
Show file tree
Hide file tree
Showing 13 changed files with 983 additions and 1,229 deletions.
1 change: 0 additions & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,3 @@ updates:
directory: "/" # Location of package manifests
schedule:
interval: "weekly"

2 changes: 1 addition & 1 deletion .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ jobs:
steps:
- uses: actions/checkout@v2
- name: Build the Docker image
run: docker build . --file Dockerfile --tag tanabesugano:$(date +%s)
run: docker build . --file Dockerfile --tag tanabesugano:$(date +%s)
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
* Add `poetry` for dependecy mangament
* `setup.py` depends now on the `project.toml`
* Modified the `GitHub-Actions`
* Introduced `TanabeSugano` batch for extending analysis of correlation matrices
* Introduced `TanabeSugano` batch for extending analysis of correlation matrices
162 changes: 82 additions & 80 deletions poetry.lock

Large diffs are not rendered by default.

56 changes: 33 additions & 23 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,31 +38,31 @@ classifiers = [
include = ["LICENSE"]
exclude = ["test/**/*.py", "example/**", "ts-diagrams/**"]

[tool.poetry.dependencies]
python = ">=3.9,<4.0"
pandas = ">=1.2.4,<4.0.0"
numpy = [
{ version = "^1.24.4", python = ">=3.8,<3.9" },
{ version = "^1.26.4", python = ">=3.9,<3.10" },
{ version = "^2.0.2", python = ">=3.10,<3.13" },
]
matplotlib = "^3.4.2"
prettytable = ">=2.1,<4.0"
plotly = { version = "^5.13.1", optional = true }
update = "^0.0.1"
[tool.poetry.dependencies]
python = ">=3.9,<4.0"
pandas = ">=1.2.4,<4.0.0"
numpy = [
{ version = "^1.24.4", python = ">=3.8,<3.9" },
{ version = "^1.26.4", python = ">=3.9,<3.10" },
{ version = "^2.0.2", python = ">=3.10,<3.13" },
]
matplotlib = "^3.4.2"
prettytable = ">=2.1,<4.0"
plotly = { version = "^5.13.1", optional = true }
update = "^0.0.1"

[tool.poetry.group.dev.dependencies]
pytest = ">=7.2,<9.0"
pytest-clarity = "^1.0.1"
pytest-cov = ">=4,<6"
flake8 = ">=6,<8"
black = ">=22.12,<25.0"
isort = "^5.11.4"
pytest-console-scripts = "^1.3.1"
ruff = "^0.7.0"
[tool.poetry.group.dev.dependencies]
pytest = ">=7.2,<9.0"
pytest-clarity = "^1.0.1"
pytest-cov = ">=4,<6"
flake8 = ">=6,<8"
black = ">=22.12,<25.0"
isort = "^5.11.4"
pytest-console-scripts = "^1.3.1"
ruff = "^0.7.0"

[build-system]
requires = ["poetry-core>=1.0.0"]
requires = ["poetry-core>=1.1.0"]
build-backend = "poetry.core.masonry.api"

[tool.poetry.scripts]
Expand All @@ -73,14 +73,24 @@ plotly = ["plotly"]

[tool.ruff]
lint.select = ["ALL"]
lint.ignore = ["N806"]
lint.ignore = ["UP006", "UP007", "N801", "N802", "N803", "N806"]
target-version = "py38"
src = ["tanabesugano"]

[tool.ruff.lint.per-file-ignores]
"tanabesugano/test/*" = ["PT006", "ANN001", "ANN201", "D103", "PLR2004", "S101"]

[tool.ruff.lint.isort]
known-first-party = ["umf"]
force-single-line = true
lines-between-types = 1
lines-after-imports = 2
known-third-party = ["poetry.core"]
required-imports = ["from __future__ import annotations"]

[tool.pytest.ini_options]
markers = """
xfail: mark test as expecting to fail
skip: mark test as skipped
"""
addopts = "-v --cov=tanabesugano"
1 change: 1 addition & 0 deletions tanabesugano/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""tanabesugano: A Python package for Tanabe-Sugano diagrams."""

from __future__ import annotations


Expand Down
10 changes: 7 additions & 3 deletions tanabesugano/batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,18 @@ def __init__(
"The range of `B` is based on the three values: start, stop, steps!",
)
self.B = np.linspace(
B[0], B[1], int(B[2]),
B[0],
B[1],
int(B[2]),
) # Racah-Parameter B in wavenumbers
if len(C) != 3:
raise KeyError(
"The range of `C` is based on the three values: start, stop, steps!",
)
self.C = np.linspace(
C[0], C[1], int(C[2]),
C[0],
C[1],
int(C[2]),
) # Racah-Parameter C in wavenumbers

if slater:
Expand All @@ -63,7 +67,7 @@ def calculation(self) -> None:
for _Dq in self.Dq:
for _B in self.B:
for _C in self.C:
if self.d_count == 2: # d3
if self.d_count == 2: # d2
states = matrices.d2(Dq=_Dq, B=_B, C=_C).solver()
self.result.append(
{
Expand Down
20 changes: 13 additions & 7 deletions tanabesugano/cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,9 @@ def plot(self) -> None:
ls="--",
)
self.label_plot(
"DD excitations -Diagram", r"$dd-state-energy\,(1/cm)$", r"$10Dq\,(1/cm)$",
"DD excitations -Diagram",
r"$dd-state-energy\,(1/cm)$",
r"$10Dq\,(1/cm)$",
)
plt.show()

Expand All @@ -128,8 +130,7 @@ def savetxt(self) -> None:
).to_csv(Path(f"{self.title_DD}.csv"), index=False)

def calculation(self) -> None:
"""Is filling the self.result with the iTS states of over-iterated energy range
"""
"""Is filling the self.result with the iTS states of over-iterated energy range"""
result = []
for dq in self.df["Energy"]:
if self.d_count == 2: # d2
Expand Down Expand Up @@ -197,8 +198,7 @@ def subsplit_states(states: dict) -> dict:
return rearranged_states

def ci_cut(self, dq_ci: float = None) -> None:
"""Extracting the atomic-termsymbols for a specific dq depending on the oxidation state
"""
"""Extracting the atomic-termsymbols for a specific dq depending on the oxidation state"""
if self.d_count == 2: # d2
states = matrices.d2(Dq=dq_ci / 10.0, B=self.B, C=self.C).solver()
self.ts_print(states, dq_ci=dq_ci)
Expand Down Expand Up @@ -366,7 +366,10 @@ def cmd_line() -> None:

parser = argparse.ArgumentParser(description=description)
parser.add_argument(
"-d", type=int, default=6, help="Number of unpaired electrons (default d5)",
"-d",
type=int,
default=6,
help="Number of unpaired electrons (default d5)",
)
parser.add_argument(
"-Dq",
Expand Down Expand Up @@ -398,7 +401,10 @@ def cmd_line() -> None:
"1.)",
)
parser.add_argument(
"-n", type=int, default=500, help="Number of roots (default nroots = 500)",
"-n",
type=int,
default=500,
help="Number of roots (default nroots = 500)",
)
parser.add_argument(
"-ndisp",
Expand Down
Loading

0 comments on commit 6a2dae6

Please sign in to comment.