Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pyright fixes #3777

Merged
merged 33 commits into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
2075587
enable pyright
DanielYang59 Apr 21, 2024
7fbf88b
fix electronic_structure.plotters
DanielYang59 Apr 21, 2024
13810cb
update pre-commit
DanielYang59 Apr 21, 2024
313f895
finish `electronic_structure`
DanielYang59 Apr 21, 2024
77f26a4
fix `core.surface/tensors/tracjectory`
DanielYang59 Apr 21, 2024
e58df83
fix unit test
DanielYang59 Apr 22, 2024
20a83b1
fix core.surface
DanielYang59 Apr 22, 2024
06a05e8
add DEBUG tag
DanielYang59 Apr 22, 2024
d6adec2
fix core.interface
DanielYang59 Apr 22, 2024
c34e716
fix command_line
DanielYang59 Apr 22, 2024
6034ac7
fix some analysis
DanielYang59 Apr 22, 2024
464077f
fix some analysis
DanielYang59 Apr 22, 2024
54a5a2d
fix more analysis
DanielYang59 Apr 22, 2024
83cb871
fix np.empty
DanielYang59 Apr 22, 2024
c21d454
fix more analysis
DanielYang59 Apr 22, 2024
d7cfa9f
fix chemenv.utils
DanielYang59 Apr 22, 2024
6e2b326
finish chemenv
DanielYang59 Apr 22, 2024
de34eda
revert changes that break tests
DanielYang59 Apr 22, 2024
65e6ca4
Revert "revert changes that break tests"
DanielYang59 Apr 22, 2024
48f87f5
fix unit test
DanielYang59 Apr 22, 2024
b2e86ac
remove tag
DanielYang59 Apr 22, 2024
54818d1
remove TODO tag
DanielYang59 Apr 22, 2024
079ebca
try downgrade pyright
DanielYang59 Apr 22, 2024
2bf9dbb
Revert "try downgrade pyright"
DanielYang59 Apr 22, 2024
f9a3aeb
add venv path for pyright
DanielYang59 Apr 22, 2024
5c08729
Revert "add venv path for pyright"
DanielYang59 Apr 22, 2024
e15186c
Merge branch 'master' into pyright
DanielYang59 Apr 23, 2024
381f430
skip pyright in pre-commit
DanielYang59 Apr 23, 2024
34be0ff
increase `requests` timeout from 60s to 600s
DanielYang59 Apr 23, 2024
bca91fe
skip tests/ext/test_cod.py in CI
janosh Apr 23, 2024
556e897
fix plot_slab weird way to calc zorder
janosh Apr 23, 2024
34aaa2c
internal types
janosh Apr 23, 2024
a297ef8
Merge branch 'master' into pyright
DanielYang59 Apr 23, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:

- name: Install dependencies
run: |
pip install --upgrade ruff mypy
pip install --upgrade ruff mypy pyright

- name: ruff
run: |
Expand All @@ -35,3 +35,7 @@ jobs:
mypy --version
rm -rf .mypy_cache
mypy ${{ github.event.repository.name }}

- name: pyright
run: |
pyright
9 changes: 7 additions & 2 deletions .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.3.7
rev: v0.4.1
hooks:
- id: ruff
args: [--fix, --unsafe-fixes]
Expand All @@ -35,7 +35,7 @@ repos:
additional_dependencies: [tomli] # needed to read pyproject.toml below py3.11

- repo: https://github.com/MarcoGorelli/cython-lint
rev: v0.16.0
rev: v0.16.2
hooks:
- id: cython-lint
args: [--no-pycodestyle]
Expand All @@ -62,3 +62,8 @@ repos:
hooks:
- id: nbstripout
args: [--drop-empty-cells, --keep-output]

- repo: https://github.com/RobertCraigie/pyright-python
rev: v1.1.359
hooks:
- id: pyright
1 change: 1 addition & 0 deletions pymatgen/analysis/adsorption.py
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,7 @@ def plot_slab(
sites = list(reversed(sites))
coords = np.array(reversed(coords))
# Draw circles at sites and stack them accordingly
n = None
for n, coord in enumerate(coords):
radius = sites[n].species.elements[0].atomic_radius * scale
ax.add_patch(patches.Circle(coord[:2] - lattice_sum * (repeat // 2), radius, color="w", zorder=2 * n))
Expand Down
11 changes: 7 additions & 4 deletions pymatgen/analysis/graphs.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from itertools import combinations
from operator import itemgetter
from shutil import which
from typing import TYPE_CHECKING, Any, Callable, cast
from typing import TYPE_CHECKING, cast

import networkx as nx
import networkx.algorithms.isomorphism as iso
Expand All @@ -35,6 +35,7 @@

if TYPE_CHECKING:
from collections.abc import Sequence
from typing import Any, Callable

from igraph import Graph
from numpy.typing import ArrayLike
Expand Down Expand Up @@ -571,9 +572,8 @@ def alter_edge(
f"Edge between {from_index} and {to_index} cannot be altered; no edge exists between those sites."
)

if to_jimage is None:
edge_index = 0
else:
edge_index = 0
if to_jimage is not None:
for idx, properties in existing_edges.items():
if properties["to_jimage"] == to_jimage:
edge_index = idx
Expand Down Expand Up @@ -606,6 +606,7 @@ def break_edge(
if to_jimage is None:
raise ValueError("Image must be supplied, to avoid ambiguity.")

edge_index = 0
if existing_edges:
for idx, props in existing_edges.items():
if props["to_jimage"] == to_jimage:
Expand Down Expand Up @@ -1489,6 +1490,8 @@ def get_subgraphs_as_molecules(self, use_weights: bool = False) -> list[Molecule
# without adding extra logic
if getattr(self, "_supercell_sg", None) is None:
self._supercell_sg = supercell_sg = self * (3, 3, 3)
else: # TODO: need double check
raise RuntimeError("Supercell spacegroup is not None.")
DanielYang59 marked this conversation as resolved.
Show resolved Hide resolved

# make undirected to find connected subgraphs
supercell_sg.graph = nx.Graph(supercell_sg.graph)
Expand Down
62 changes: 37 additions & 25 deletions pymatgen/analysis/local_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -1631,13 +1631,15 @@ def get_nn_info(self, structure: Structure, n: int):
siw = []

for bond in bonds:
capture_bond = False
if bond.site1 == structure[n]:
site = bond.site2
capture_bond = True
elif bond.site2 == structure[n]:
site = bond.site1
capture_bond = True
else:
site = None
capture_bond = False

if capture_bond:
index = structure.index(site)
Expand Down Expand Up @@ -2927,6 +2929,7 @@ def get_order_parameters(
# norms = [[[] for j in range(nneigh)] for t in self._types]

# First, coordination number and distance-based OPs.
typ = ""
for idx, typ in enumerate(self._types):
if typ == "cn":
ops[idx] = n_neighbors / self._params[idx]["norm"]
Expand Down Expand Up @@ -2978,16 +2981,17 @@ def get_order_parameters(
# (Peters, J. Chem. Phys., 131, 244103, 2009;
# Zimmermann et al., J. Am. Chem. Soc., under revision, 2015).
if self._geomops:
gaussthetak: list[float] = [0 for t in self._types] # not used by all OPs
qsp_theta = [[[] for j in range(n_neighbors)] for t in self._types] # type: ignore
norms = [[[] for j in range(n_neighbors)] for t in self._types] # type: ignore
gaussthetak: list[float] = [0 for _t in self._types] # not used by all OPs
qsp_theta = [[[] for _j in range(n_neighbors)] for _t in self._types] # type: ignore
norms = [[[] for _j in range(n_neighbors)] for _t in self._types] # type: ignore
ipi = 1 / pi
piover2 = pi / 2.0
onethird = 1 / 3
twothird = 2 / 3.0
for j in range(n_neighbors): # Neighbor j is put to the North pole.
zaxis = rij_norm[j]
kc = 0
idx = 0
for k in range(n_neighbors): # From neighbor k, we construct
if j != k: # the prime meridian.
for idx in range(len(self._types)):
Expand All @@ -3001,42 +3005,46 @@ def get_order_parameters(
else:
xaxis = xaxis / np.linalg.norm(xaxis)
flag_xaxis = False

if self._comp_azi:
flag_yaxis = True
yaxis = np.cross(zaxis, xaxis)
if np.linalg.norm(yaxis) > very_small:
yaxis = yaxis / np.linalg.norm(yaxis)
flag_yaxis = False
else:
yaxis = None
flag_yaxis = False

# Contributions of j-i-k angles, where i represents the
# central atom and j and k two of the neighbors.
for idx, typ in enumerate(self._types):
if typ in ["bent", "sq_pyr_legacy"]:
if typ in {"bent", "sq_pyr_legacy"}:
tmp = self._params[idx]["IGW_TA"] * (thetak * ipi - self._params[idx]["TA"])
qsp_theta[idx][j][kc] += exp(-0.5 * tmp * tmp)
norms[idx][j][kc] += 1
elif typ in ["tri_plan", "tri_plan_max", "tet", "tet_max"]:
elif typ in {"tri_plan", "tri_plan_max", "tet", "tet_max"}:
tmp = self._params[idx]["IGW_TA"] * (thetak * ipi - self._params[idx]["TA"])
gaussthetak[idx] = exp(-0.5 * tmp * tmp)
if typ in ["tri_plan_max", "tet_max"]:
qsp_theta[idx][j][kc] += gaussthetak[idx]
norms[idx][j][kc] += 1
elif typ in ["T", "tri_pyr", "sq_pyr", "pent_pyr", "hex_pyr"]:
elif typ in {"T", "tri_pyr", "sq_pyr", "pent_pyr", "hex_pyr"}:
tmp = self._params[idx]["IGW_EP"] * (thetak * ipi - 0.5)
qsp_theta[idx][j][kc] += exp(-0.5 * tmp * tmp)
norms[idx][j][kc] += 1
elif typ in [
elif typ in {
"sq_plan",
"oct",
"oct_legacy",
"cuboct",
"cuboct_max",
]:
}:
if thetak >= self._params[idx]["min_SPP"]:
tmp = self._params[idx]["IGW_SPP"] * (thetak * ipi - 1.0)
qsp_theta[idx][j][kc] += self._params[idx]["w_SPP"] * exp(-0.5 * tmp * tmp)
norms[idx][j][kc] += self._params[idx]["w_SPP"]
elif typ in [
elif typ in {
"see_saw_rect",
"tri_bipyr",
"sq_bipyr",
Expand All @@ -3045,7 +3053,7 @@ def get_order_parameters(
"oct_max",
"sq_plan_max",
"hex_plan_max",
]:
}:
if thetak < self._params[idx]["min_SPP"]:
tmp = (
self._params[idx]["IGW_EP"] * (thetak * ipi - 0.5)
Expand Down Expand Up @@ -3078,8 +3086,10 @@ def get_order_parameters(
thetam = acos(tmp)
x_two_axis_tmp = gramschmidt(rij_norm[m], zaxis)
norm = np.linalg.norm(x_two_axis_tmp)
phi2 = 0.0
if norm < very_small:
flag_xtwoaxis = True
phi = 0.0
else:
xtwoaxis = x_two_axis_tmp / norm
phi = acos(max(-1.0, min(np.inner(xtwoaxis, xaxis), 1.0)))
Expand All @@ -3092,7 +3102,7 @@ def get_order_parameters(
# South pole contributions of m.
if (
typ
in [
in {
"tri_bipyr",
"sq_bipyr",
"pent_bipyr",
Expand All @@ -3101,7 +3111,7 @@ def get_order_parameters(
"sq_plan_max",
"hex_plan_max",
"see_saw_rect",
]
}
and thetam >= self._params[idx]["min_SPP"]
):
tmp = self._params[idx]["IGW_SPP"] * (thetam * ipi - 1.0)
Expand All @@ -3112,12 +3122,12 @@ def get_order_parameters(
# angles between plane j-i-k and i-m vector.
if not flag_xaxis and not flag_xtwoaxis:
for idx, typ in enumerate(self._types):
if typ in [
if typ in {
"tri_plan",
"tri_plan_max",
"tet",
"tet_max",
]:
}:
tmp = self._params[idx]["IGW_TA"] * (thetam * ipi - self._params[idx]["TA"])
tmp2 = (
cos(self._params[idx]["fac_AA"] * phi)
Expand All @@ -3133,13 +3143,13 @@ def get_order_parameters(
tmp4 = 1 if typ == "pent_plan_max" else gaussthetak[idx]
qsp_theta[idx][j][kc] += tmp4 * exp(-0.5 * tmp2 * tmp2) * tmp3 * tmp3
norms[idx][j][kc] += 1
elif typ in [
elif typ in {
"T",
"tri_pyr",
"sq_pyr",
"pent_pyr",
"hex_pyr",
]:
}:
tmp = (
cos(self._params[idx]["fac_AA"] * phi)
** self._params[idx]["exp_cos_AA"]
Expand All @@ -3163,15 +3173,15 @@ def get_order_parameters(
tmp * self._params[idx][6] * self._params[idx][7]
)
norms[idx][j][kc] += 1
elif typ in [
elif typ in {
"tri_bipyr",
"sq_bipyr",
"pent_bipyr",
"hex_bipyr",
"oct_max",
"sq_plan_max",
"hex_plan_max",
]:
}:
if (
thetam < self._params[idx]["min_SPP"]
and thetak < self._params[idx]["min_SPP"]
Expand Down Expand Up @@ -3265,7 +3275,7 @@ def get_order_parameters(

# Normalize Peters-style OPs.
for idx, typ in enumerate(self._types):
if typ in [
if typ in {
"tri_plan",
"tet",
"bent",
Expand All @@ -3274,13 +3284,13 @@ def get_order_parameters(
"oct_legacy",
"cuboct",
"pent_plan",
]:
}:
ops[idx] = tmp_norm = 0.0
for j in range(n_neighbors):
ops[idx] += sum(qsp_theta[idx][j])
tmp_norm += float(sum(norms[idx][j]))
ops[idx] = ops[idx] / tmp_norm if tmp_norm > 1.0e-12 else None # type: ignore
elif typ in [
elif typ in {
"T",
"tri_pyr",
"see_saw_rect",
Expand All @@ -3299,7 +3309,7 @@ def get_order_parameters(
"cuboct_max",
"hex_plan_max",
"sq_face_cap_trig_pris",
]:
}:
ops[idx] = None # type: ignore[call-overload]
if n_neighbors > 1:
for j in range(n_neighbors):
Expand Down Expand Up @@ -3353,17 +3363,19 @@ def get_order_parameters(
dhalf = max(distjk_unique) / 2 if len(distjk_unique) > 0 else 0

for idx, typ in enumerate(self._types):
if typ in ("reg_tri", "sq"):
if typ in {"reg_tri", "sq"}:
if n_neighbors < 3:
ops[idx] = None # type: ignore[call-overload]
else:
ops[idx] = 1.0
if typ == "reg_tri":
a = 2 * asin(b / (2 * sqrt(h * h + (b / (2 * cos(3 * pi / 18))) ** 2))) # type: ignore
nmax = 3
elif typ == "sq":

else:
a = 2 * asin(b / (2 * sqrt(h * h + dhalf * dhalf))) # type: ignore
nmax = 4

for j in range(min([n_neighbors, nmax])):
ops[idx] = ops[idx] * exp(-0.5 * ((aijs[j] - a) * self._params[idx][0]) ** 2)

Expand Down
7 changes: 6 additions & 1 deletion pymatgen/analysis/molecule_matcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

from pymatgen.io.babel import BabelMolAdaptor
except ImportError:
openbabel = None
openbabel = BabelMolAdaptor = None # type: ignore[misc]

if TYPE_CHECKING:
from typing_extensions import Self
Expand Down Expand Up @@ -894,6 +894,8 @@ def match(self, mol: Molecule, ignore_warning: bool = False) -> tuple[np.ndarray
rmsd = np.inf

# Generate all permutation grouped/sorted by the elements
p_inds = []
U = np.empty()
for p_inds_test in self.permutations(p_atoms):
p_centroid_test = p_centroid[p_inds_test]
U_test = self.kabsch(p_centroid_test, q_centroid)
Expand Down Expand Up @@ -991,6 +993,8 @@ def match(self, p: Molecule):
rmsd = np.inf

# Generate all permutation grouped/sorted by the elements
inds = []
U = np.empty()
for p_inds_test in self.permutations(p_atoms, p_centroid, p_weights, q_atoms, q_centroid, q_weights):
p_centroid_test = p_centroid[p_inds_test]
U_test = self.kabsch(p_centroid_test, q_centroid)
Expand Down Expand Up @@ -1262,6 +1266,7 @@ def permutations(self, p: Molecule):

# starting matches (only based on element)
partial_matches = [[j] for j in range(self.N) if p_atoms[j] == q_atoms[0]]
matches: list = []

for idx in range(1, self.N):
# extending the target fragment with then next atom
Expand Down
Loading
Loading