Skip to content

Commit

Permalink
Add types for `core.molecular_orbitals/operations/sites/spectrum/tens…
Browse files Browse the repository at this point in the history
…or/xcfunc` (#3829)

* fix `core.molecular_orbitals`

* fix `core.operations`

* add types for site, mypy errors to fix

* remove no_type_check decorator

* move dunder methods to the top

* fix mypy errors

* remove debug tag

* improve `spectrum`

* finish `core.tensors`

* finish `xcfunc`

* fix hash of `SymmOp`

* add a missing type

* Revert "fix hash of `SymmOp`"

This reverts commit bf2a953.

* fix some types in operations

* "TEST": remove one unused var, relocate another

* final tweak types

* avoid hard-code class name

* format tweaks

* type tweak

* fix unit test

* replace all `[0:x]` with `[:x]`
  • Loading branch information
DanielYang59 authored May 14, 2024
1 parent 51180fc commit 616abc5
Show file tree
Hide file tree
Showing 29 changed files with 813 additions and 668 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ def points_wcs_csc(self, permutation=None):
"""
if permutation is None:
return self._points_wcs_csc
return np.concatenate((self._points_wcs_csc[0:1], self._points_wocs_csc.take(permutation, axis=0)))
return np.concatenate((self._points_wcs_csc[:1], self._points_wocs_csc.take(permutation, axis=0)))

def points_wocs_csc(self, permutation=None):
"""
Expand All @@ -238,7 +238,7 @@ def points_wcs_ctwcc(self, permutation=None):
return self._points_wcs_ctwcc
return np.concatenate(
(
self._points_wcs_ctwcc[0:1],
self._points_wcs_ctwcc[:1],
self._points_wocs_ctwcc.take(permutation, axis=0),
)
)
Expand All @@ -261,7 +261,7 @@ def points_wcs_ctwocc(self, permutation=None):
return self._points_wcs_ctwocc
return np.concatenate(
(
self._points_wcs_ctwocc[0:1],
self._points_wcs_ctwocc[:1],
self._points_wocs_ctwocc.take(permutation, axis=0),
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -901,7 +901,7 @@ def project_and_to2dim(self, pps, plane_center):
xypps = []
for pp in proj:
xyzpp = np.dot(pp, PP)
xypps.append(xyzpp[0:2])
xypps.append(xyzpp[:2])
if str(plane_center) == "mean":
mean = np.zeros(2, float)
for pp in xypps:
Expand All @@ -910,7 +910,7 @@ def project_and_to2dim(self, pps, plane_center):
xypps = [pp - mean for pp in xypps]
elif plane_center is not None:
projected_plane_center = self.projectionpoints([plane_center])[0]
xy_projected_plane_center = np.dot(projected_plane_center, PP)[0:2]
xy_projected_plane_center = np.dot(projected_plane_center, PP)[:2]
xypps = [pp - xy_projected_plane_center for pp in xypps]
return xypps

Expand Down Expand Up @@ -960,7 +960,7 @@ def coefficients(self):
@property
def abcd(self):
"""A tuple with the plane coefficients."""
return tuple(self._coefficients[0:4])
return tuple(self._coefficients[:4])

@property
def a(self):
Expand Down
2 changes: 1 addition & 1 deletion pymatgen/analysis/ferroelectricity/polarization.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def get_nearest_site(struct: Structure, coords: Sequence[float], site: PeriodicS
# Sort by distance to coords
ns.sort(key=lambda x: x[1])
# Return PeriodicSite and distance of closest image
return ns[0][0:2]
return ns[0][:2]


class Polarization:
Expand Down
2 changes: 1 addition & 1 deletion pymatgen/analysis/magnetism/analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1011,7 +1011,7 @@ def _add_structures(ordered_structures, ordered_structures_origins, structures_t

# ...and decide which ones to keep
if len(max_symmetries) > self.truncate_by_symmetry:
max_symmetries = max_symmetries[0:5]
max_symmetries = max_symmetries[:5]
structs_to_keep = [(idx, num) for idx, num in enumerate(num_sym_ops) if num in max_symmetries]

# sort so that highest symmetry structs are first
Expand Down
2 changes: 1 addition & 1 deletion pymatgen/command_line/gulp_caller.py
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,7 @@ def get_relaxed_structure(gout: str):
# read the site coordinates in the following lines
idx += 6
line = output_lines[idx]
while line[0:2] != "--":
while line[:2] != "--":
structure_lines.append(line)
idx += 1
line = output_lines[idx]
Expand Down
2 changes: 1 addition & 1 deletion pymatgen/command_line/mcsqs_caller.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ def _parse_clusters(filename):
for point in range(cluster_dict["num_points_in_cluster"]):
line = cluster[3 + point].split(" ")
point_dict = {}
point_dict["coordinates"] = [float(line) for line in line[0:3]]
point_dict["coordinates"] = [float(line) for line in line[:3]]
point_dict["num_possible_species"] = int(line[3]) + 2 # see ATAT manual for why +2
point_dict["cluster_function"] = float(line[4]) # see ATAT manual for what "function" is
points.append(point_dict)
Expand Down
Loading

0 comments on commit 616abc5

Please sign in to comment.