Skip to content

Commit

Permalink
Merge branch 'master' into fix-position-check-in-get-slabs
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielYang59 committed May 15, 2024
2 parents 72e36c3 + 40b0165 commit b1c8f42
Show file tree
Hide file tree
Showing 81 changed files with 1,114 additions and 911 deletions.
3 changes: 2 additions & 1 deletion pymatgen/alchemy/materials.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import datetime
import json
import re
from typing import TYPE_CHECKING, Any
from typing import TYPE_CHECKING
from warnings import warn

from monty.json import MSONable, jsanitize
Expand All @@ -22,6 +22,7 @@

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

from typing_extensions import Self

Expand Down
3 changes: 2 additions & 1 deletion pymatgen/alchemy/transmuters.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@
import os
import re
from multiprocessing import Pool
from typing import TYPE_CHECKING, Callable
from typing import TYPE_CHECKING

from pymatgen.alchemy.materials import TransformedStructure
from pymatgen.io.vasp.sets import MPRelaxSet, VaspInputSet

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

from typing_extensions import Self

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@
import itertools
import json
import os
from typing import TYPE_CHECKING, Any
from typing import TYPE_CHECKING

import numpy as np
from monty.json import MontyDecoder, MSONable
from scipy.special import factorial

if TYPE_CHECKING:
from typing import Any

from typing_extensions import Self

__author__ = "David Waroquiers"
Expand Down
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
10 changes: 6 additions & 4 deletions pymatgen/analysis/chemenv/utils/coordination_geometry_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from __future__ import annotations

import math
from typing import TYPE_CHECKING, Callable
from typing import TYPE_CHECKING

import numpy as np
from numpy.linalg import norm
Expand All @@ -14,6 +14,8 @@
from pymatgen.analysis.chemenv.utils.chemenv_errors import SolidAngleError

if TYPE_CHECKING:
from typing import Callable

from numpy.typing import ArrayLike
from typing_extensions import Self

Expand Down Expand Up @@ -901,7 +903,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 +912,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 +962,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
3 changes: 2 additions & 1 deletion pymatgen/analysis/elasticity/elastic.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import itertools
import math
import warnings
from typing import TYPE_CHECKING, Literal
from typing import TYPE_CHECKING

import numpy as np
import sympy as sp
Expand All @@ -25,6 +25,7 @@

if TYPE_CHECKING:
from collections.abc import Sequence
from typing import Literal

from numpy.typing import ArrayLike
from typing_extensions import Self
Expand Down
3 changes: 2 additions & 1 deletion pymatgen/analysis/elasticity/strain.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import collections
import itertools
from typing import TYPE_CHECKING, Literal
from typing import TYPE_CHECKING

import numpy as np
import scipy
Expand All @@ -18,6 +18,7 @@

if TYPE_CHECKING:
from collections.abc import Sequence
from typing import Literal

from numpy.typing import ArrayLike
from typing_extensions import Self
Expand Down
22 changes: 12 additions & 10 deletions pymatgen/analysis/ewald.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
from __future__ import annotations

import bisect
import math
from copy import copy, deepcopy
from datetime import datetime
from math import log, pi, sqrt
from typing import TYPE_CHECKING, Any
from typing import TYPE_CHECKING
from warnings import warn

import numpy as np
Expand All @@ -18,6 +18,8 @@
from pymatgen.util.due import Doi, due

if TYPE_CHECKING:
from typing import Any

from typing_extensions import Self

__author__ = "Shyue Ping Ong, William Davidson Richard"
Expand Down Expand Up @@ -55,7 +57,7 @@ class EwaldSummation(MSONable):
"""

# Converts unit of q*q/r into eV
CONV_FACT = 1e10 * constants.e / (4 * pi * constants.epsilon_0)
CONV_FACT = 1e10 * constants.e / (4 * math.pi * constants.epsilon_0)

def __init__(
self,
Expand Down Expand Up @@ -102,12 +104,12 @@ def __init__(

self._acc_factor = acc_factor
# set screening length
self._eta = eta or (len(structure) * w / (self._vol**2)) ** (1 / 3) * pi
self._sqrt_eta = sqrt(self._eta)
self._eta = eta or (len(structure) * w / (self._vol**2)) ** (1 / 3) * math.pi
self._sqrt_eta = math.sqrt(self._eta)

# acc factor used to automatically determine the optimal real and
# reciprocal space cutoff radii
self._accf = sqrt(log(10**acc_factor))
self._accf = math.sqrt(math.log(10**acc_factor))

self._rmax = real_space_cut or self._accf / self._sqrt_eta
self._gmax = recip_space_cut or 2 * self._sqrt_eta * self._accf
Expand Down Expand Up @@ -307,7 +309,7 @@ def _calc_recip(self):
This method is heavily vectorized to utilize numpy's C backend for speed.
"""
n_sites = len(self._struct)
prefactor = 2 * pi / self._vol
prefactor = 2 * math.pi / self._vol
e_recip = np.zeros((n_sites, n_sites), dtype=np.float64)
forces = np.zeros((n_sites, 3), dtype=np.float64)
coords = self._coords
Expand All @@ -332,7 +334,7 @@ def _calc_recip(self):

for g, g2, gr, exp_val, s_real, s_imag in zip(gs, g2s, grs, exp_vals, s_reals, s_imags):
# Uses the identity sin(x)+cos(x) = 2**0.5 sin(x + pi/4)
m = np.sin((gr[None, :] + pi / 4) - gr[:, None])
m = np.sin((gr[None, :] + math.pi / 4) - gr[:, None])
m *= exp_val / g2

e_recip += m
Expand All @@ -350,7 +352,7 @@ def _calc_recip(self):
def _calc_real_and_point(self):
"""Determine the self energy -(eta/pi)**(1/2) * sum_{i=1}^{N} q_i**2."""
frac_coords = self._struct.frac_coords
force_pf = 2 * self._sqrt_eta / sqrt(pi)
force_pf = 2 * self._sqrt_eta / math.sqrt(math.pi)
coords = self._coords
n_sites = len(self._struct)
e_real = np.empty((n_sites, n_sites), dtype=np.float64)
Expand All @@ -359,7 +361,7 @@ def _calc_real_and_point(self):

qs = np.array(self._oxi_states)

e_point = -(qs**2) * sqrt(self._eta / pi)
e_point = -(qs**2) * math.sqrt(self._eta / math.pi)

for idx in range(n_sites):
nf_coords, rij, js, _ = self._struct.lattice.get_points_in_sphere(
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
5 changes: 4 additions & 1 deletion pymatgen/analysis/interface_reactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import json
import os
import warnings
from typing import Literal
from typing import TYPE_CHECKING

import matplotlib.pyplot as plt
import numpy as np
Expand All @@ -23,6 +23,9 @@
from pymatgen.util.plotting import pretty_plot
from pymatgen.util.string import htmlify, latexify

if TYPE_CHECKING:
from typing import Literal

__author__ = "Yihan Xiao, Matthew McDermott"
__maintainer__ = "Matthew McDermott"
__email__ = "mcdermott@lbl.gov"
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
4 changes: 3 additions & 1 deletion pymatgen/analysis/magnetism/jahnteller.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import os
import warnings
from typing import TYPE_CHECKING, Any, Literal, cast
from typing import TYPE_CHECKING, Literal, cast

import numpy as np

Expand All @@ -14,6 +14,8 @@
from pymatgen.symmetry.analyzer import SpacegroupAnalyzer

if TYPE_CHECKING:
from typing import Any

from pymatgen.core import Structure

MODULE_DIR = os.path.dirname(os.path.abspath(__file__))
Expand Down
3 changes: 2 additions & 1 deletion pymatgen/analysis/phase_diagram.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import warnings
from collections import defaultdict
from functools import lru_cache
from typing import TYPE_CHECKING, Any, Literal, no_type_check
from typing import TYPE_CHECKING, no_type_check

import matplotlib.pyplot as plt
import numpy as np
Expand All @@ -38,6 +38,7 @@
if TYPE_CHECKING:
from collections.abc import Collection, Iterator, Sequence
from io import StringIO
from typing import Any, Literal

from numpy.typing import ArrayLike
from typing_extensions import Self
Expand Down
4 changes: 3 additions & 1 deletion pymatgen/analysis/pourbaix_diagram.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from copy import deepcopy
from functools import cmp_to_key, partial
from multiprocessing import Pool
from typing import TYPE_CHECKING, Any, no_type_check
from typing import TYPE_CHECKING, no_type_check

import numpy as np
from monty.json import MontyDecoder, MSONable
Expand All @@ -31,6 +31,8 @@
from pymatgen.util.string import Stringify

if TYPE_CHECKING:
from typing import Any

import matplotlib.pyplot as plt
from typing_extensions import Self

Expand Down
3 changes: 2 additions & 1 deletion pymatgen/analysis/structure_matcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import abc
import itertools
from typing import TYPE_CHECKING, Literal
from typing import TYPE_CHECKING

import numpy as np
from monty.json import MSONable
Expand All @@ -16,6 +16,7 @@

if TYPE_CHECKING:
from collections.abc import Mapping, Sequence
from typing import Literal

from typing_extensions import Self

Expand Down
3 changes: 2 additions & 1 deletion pymatgen/cli/pmg_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import shutil
import subprocess
from glob import glob
from typing import TYPE_CHECKING, Literal
from typing import TYPE_CHECKING
from urllib.request import urlretrieve

from monty.json import jsanitize
Expand All @@ -21,6 +21,7 @@

if TYPE_CHECKING:
from argparse import Namespace
from typing import Literal


def setup_cp2k_data(cp2k_data_dirs: list[str]) -> None:
Expand Down
4 changes: 3 additions & 1 deletion pymatgen/command_line/bader_caller.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from pathlib import Path
from shutil import which
from tempfile import TemporaryDirectory
from typing import TYPE_CHECKING, Any
from typing import TYPE_CHECKING

import numpy as np
from monty.dev import deprecated
Expand All @@ -34,6 +34,8 @@
from pymatgen.io.vasp.outputs import Chgcar

if TYPE_CHECKING:
from typing import Any

from typing_extensions import Self

from pymatgen.core import Structure
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 b1c8f42

Please sign in to comment.