Skip to content

Commit

Permalink
fix type for species
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielYang59 committed Aug 8, 2024
1 parent 61061ba commit 5bcde4e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def __init__(self, lambda_table=None, alpha=-5):

# create Z and px
self.Z = 0
self._px: dict[Species, float] = defaultdict(float)
self._px: dict[SpeciesLike, float] = defaultdict(float)
for s1, s2 in itertools.product(self.species, repeat=2):
value = math.exp(self.get_lambda(s1, s2))
self._px[s1] += value / 2
Expand Down
14 changes: 12 additions & 2 deletions src/pymatgen/core/periodic_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from enum import Enum, unique
from itertools import combinations, product
from pathlib import Path
from typing import TYPE_CHECKING
from typing import TYPE_CHECKING, overload

import numpy as np
from monty.dev import deprecated
Expand Down Expand Up @@ -1597,11 +1597,21 @@ class DummySpecie(DummySpecies):
"""


@overload
def get_el_sp(obj: int) -> Element:
pass


@overload
def get_el_sp(obj: SpeciesLike) -> Element | Species | DummySpecies:
pass


@functools.lru_cache
def get_el_sp(obj: int | SpeciesLike) -> Element | Species | DummySpecies:
"""Utility method to get an Element, Species or DummySpecies from any input.
If obj is in itself an element or a specie, it is returned automatically.
If obj is in itself an Element or a Species, it is returned automatically.
If obj is an int or a string representing an integer, the Element with the
atomic number obj is returned.
If obj is a string, Species parsing will be attempted (e.g. Mn2+). Failing that
Expand Down

0 comments on commit 5bcde4e

Please sign in to comment.