Skip to content

Commit

Permalink
Merge branch master into kpoints-tuple-type
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielYang59 committed Apr 15, 2024
2 parents ca7cbfc + 0e57abf commit 05c715d
Show file tree
Hide file tree
Showing 75 changed files with 1,139 additions and 1,129 deletions.
2 changes: 2 additions & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
pymatgen/io/ase.py @Andrew-S-Rosen
pymatgen/io/abinit/* @gmatteo
pymatgen/io/lobster/* @JaGeo
pymatgen/ext/* @ml-evs
tests/ext/* @ml-evs
2 changes: 1 addition & 1 deletion .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.5
rev: v0.3.7
hooks:
- id: ruff
args: [--fix, --unsafe-fixes]
Expand Down
8 changes: 6 additions & 2 deletions dev_scripts/chemenv/equivalent_indices.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@
# 0. any point
for i0 in range(8):
# 1. point opposite to point 0. in the square face
if i0 in [0, 2]:
if i0 in {0, 2}:
i1 = i0 + 1
elif i0 in [1, 3]:
elif i0 in {1, 3}:
i1 = i0 - 1
elif i0 == 4:
i1 = 7
Expand All @@ -111,10 +111,14 @@
i1 = 5
elif i0 == 7:
i1 = 4
else:
raise RuntimeError("Cannot determine point.")

# 2. one of the two last points in the square face
sfleft = list(sf1) if i0 in sf1 else list(sf2)
sfleft.remove(i0)
sfleft.remove(i1)
i2 = 0
for i2 in sfleft:
sfleft2 = list(sfleft)
sfleft2.remove(i2)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,17 +151,18 @@ def get_structure(self, morphing_factor):

coords = copy.deepcopy(self.abstract_geometry.points_wcs_ctwcc())
bare_points = self.abstract_geometry.bare_points_with_centre
origin = None

for morphing in self.morphing_description:
if morphing["site_type"] == "neighbor":
i_site = morphing["ineighbor"] + 1
if morphing["expansion_origin"] == "central_site":
origin = bare_points[0]
vector = bare_points[i_site] - origin
coords[i_site] += vector * (morphing_factor - 1.0)
else:
if morphing["site_type"] != "neighbor":
raise ValueError(f"Key \"site_type\" is {morphing['site_type']} while it can only be neighbor")

i_site = morphing["ineighbor"] + 1
if morphing["expansion_origin"] == "central_site":
origin = bare_points[0]
vector = bare_points[i_site] - origin
coords[i_site] += vector * (morphing_factor - 1.0)

return Structure(lattice=lattice, species=species, coords=coords, coords_are_cartesian=True)

def estimate_parameters(self, dist_factor_min, dist_factor_max, symmetry_measure_type="csm_wcs_ctwcc"):
Expand Down Expand Up @@ -269,7 +270,7 @@ def get_weights(self, weights_options):
"+-------------------------------------------------------------+\n"
)

with open("ce_pairs.json") as file:
with open("ce_pairs.json", encoding="utf-8") as file:
ce_pairs = json.load(file)
self_weight_max_csms: dict[str, list[float]] = {}
self_weight_max_csms_per_cn: dict[str, list[float]] = {}
Expand Down
1 change: 1 addition & 0 deletions dev_scripts/chemenv/view_environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
print()
# Visualize the separation plane of a given algorithm
sep_plane = False
algo = None
if any(algo.algorithm_type == SEPARATION_PLANE for algo in cg.algorithms):
test = input("Enter index of the algorithm for which you want to visualize the plane : ")
if test != "":
Expand Down
5 changes: 4 additions & 1 deletion dev_scripts/update_pt_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,10 @@ def parse_shannon_radii():
from openpyxl import load_workbook

wb = load_workbook("Shannon Radii.xlsx")
print(wb.get_sheet_names())
print(wb.sheetnames())
sheet = wb["Sheet1"]
i = 2
el = charge = cn = None
radii = collections.defaultdict(dict)
while sheet[f"E{i}"].value:
if sheet[f"A{i}"].value:
Expand Down Expand Up @@ -235,6 +236,7 @@ def add_electron_affinities():

req = requests.get("https://wikipedia.org/wiki/Electron_affinity_(data_page)")
soup = BeautifulSoup(req.text, "html.parser")
table = None
for table in soup.find_all("table"):
if "Hydrogen" in table.text:
break
Expand Down Expand Up @@ -271,6 +273,7 @@ def add_ionization_energies():

with open("NIST Atomic Ionization Energies Output.html") as file:
soup = BeautifulSoup(file.read(), "html.parser")
table = None
for table in soup.find_all("table"):
if "Hydrogen" in table.text:
break
Expand Down
16 changes: 16 additions & 0 deletions docs/CHANGES.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 9 additions & 10 deletions pymatgen/analysis/chemenv/connectivity/connected_components.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,17 +241,16 @@ def __init__(
if links_data is None:
edge_data = None

elif (env_node1, env_node2, key) in links_data:
edge_data = links_data[(env_node1, env_node2, key)]
elif (env_node2, env_node1, key) in links_data:
edge_data = links_data[(env_node2, env_node1, key)]
elif (env_node1, env_node2) in links_data:
edge_data = links_data[(env_node1, env_node2)]
elif (env_node2, env_node1) in links_data:
edge_data = links_data[(env_node2, env_node1)]
else:
if (env_node1, env_node2, key) in links_data:
edge_data = links_data[(env_node1, env_node2, key)]
elif (env_node2, env_node1, key) in links_data:
edge_data = links_data[(env_node2, env_node1, key)]
elif (env_node1, env_node2) in links_data:
edge_data = links_data[(env_node1, env_node2)]
elif (env_node2, env_node1) in links_data:
edge_data = links_data[(env_node2, env_node1)]
else:
edge_data = None
edge_data = None

if edge_data:
self._connected_subgraph.add_edge(env_node1, env_node2, key, **edge_data)
Expand Down
5 changes: 4 additions & 1 deletion pymatgen/analysis/elasticity/stress.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@
from __future__ import annotations

import math
from typing import TYPE_CHECKING

import numpy as np
from typing_extensions import Self

from pymatgen.core.tensors import SquareTensor

if TYPE_CHECKING:
from typing_extensions import Self

__author__ = "Joseph Montoya"
__copyright__ = "Copyright 2012, The Materials Project"
__credits__ = "Maarten de Jong, Mark Asta, Anubhav Jain"
Expand Down
3 changes: 1 addition & 2 deletions pymatgen/analysis/ewald.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,8 +344,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 = (gr[None, :] + pi / 4) - gr[:, None]
np.sin(m, m)
m = np.sin((gr[None, :] + pi / 4) - gr[:, None])
m *= exp_val / g2

e_recip += m
Expand Down
8 changes: 4 additions & 4 deletions pymatgen/analysis/local_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -4164,10 +4164,10 @@ def _get_radius(site):
return el.ionic_radii[oxi]

# e.g., oxi = 2.667, average together 2+ and 3+ radii
if int(math.floor(oxi)) in el.ionic_radii and int(math.ceil(oxi)) in el.ionic_radii:
oxi_low = el.ionic_radii[int(math.floor(oxi))]
oxi_high = el.ionic_radii[int(math.ceil(oxi))]
x = oxi - int(math.floor(oxi))
if math.floor(oxi) in el.ionic_radii and math.ceil(oxi) in el.ionic_radii:
oxi_low = el.ionic_radii[math.floor(oxi)]
oxi_high = el.ionic_radii[math.ceil(oxi)]
x = oxi - math.floor(oxi)
return (1 - x) * oxi_low + x * oxi_high

if oxi > 0 and el.average_cationic_radius > 0:
Expand Down
4 changes: 2 additions & 2 deletions pymatgen/command_line/enumlib_caller.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ def get_sg_info(ss):
# enumeration. See Cu7Te5.cif test file.
base *= 10

# base = n_disordered # 10 ** int(math.ceil(math.log10(n_disordered)))
# base = n_disordered # 10 ** math.ceil(math.log10(n_disordered))
# To get a reasonable number of structures, we fix concentrations to the
# range expected in the original structure.
total_amounts = sum(index_amounts)
Expand All @@ -266,7 +266,7 @@ def get_sg_info(ss):
if abs(conc * base - round(conc * base)) < 1e-5:
output.append(f"{int(round(conc * base))} {int(round(conc * base))} {base}")
else:
min_conc = int(math.floor(conc * base))
min_conc = math.floor(conc * base)
output.append(f"{min_conc - 1} {min_conc + 1} {base}")
output.append("")
logger.debug("Generated input file:\n" + "\n".join(output))
Expand Down
54 changes: 26 additions & 28 deletions pymatgen/command_line/vampire_caller.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,9 @@ def __init__(
stdout: str = _stdout.decode()

if stderr:
vanhelsing = stderr.decode()
if len(vanhelsing) > 27: # Suppress blank warning msg
logging.warning(vanhelsing)
van_helsing = stderr.decode()
if len(van_helsing) > 27: # Suppress blank warning msg
logging.warning(van_helsing)

if process.returncode != 0:
raise RuntimeError(f"Vampire exited with return code {process.returncode}.")
Expand All @@ -146,9 +146,9 @@ def __init__(
self._stderr = stderr

# Process output
nmats = max(self.mat_id_dict.values())
parsed_out, critical_temp = VampireCaller.parse_stdout("output", nmats)
self.output = VampireOutput(parsed_out, nmats, critical_temp)
n_mats = max(self.mat_id_dict.values())
parsed_out, critical_temp = VampireCaller.parse_stdout("output", n_mats)
self.output = VampireOutput(parsed_out, n_mats, critical_temp)

def _create_mat(self):
structure = self.structure
Expand All @@ -158,43 +158,41 @@ def _create_mat(self):
# Maps sites to material id for vampire inputs
mat_id_dict = {}

nmats = 0
n_mats = 0
for key in self.unique_site_ids:
spin_up, spin_down = False, False
nmats += 1 # at least 1 mat for each unique site
n_mats += 1 # at least 1 mat for each unique site

# Check which spin sublattices exist for this site id
for site in key:
m = magmoms[site]
if m > 0:
if magmoms[site] > 0:
spin_up = True
if m < 0:
if magmoms[site] < 0:
spin_down = True

# Assign material id for each site
for site in key:
m = magmoms[site]
if spin_up and not spin_down:
mat_id_dict[site] = nmats
mat_id_dict[site] = n_mats
if spin_down and not spin_up:
mat_id_dict[site] = nmats
mat_id_dict[site] = n_mats
if spin_up and spin_down:
# Check if spin up or down shows up first
m0 = magmoms[key[0]]
if m > 0 and m0 > 0:
mat_id_dict[site] = nmats
if m < 0 and m0 < 0:
mat_id_dict[site] = nmats
if m > 0 > m0:
mat_id_dict[site] = nmats + 1
if m < 0 < m0:
mat_id_dict[site] = nmats + 1
if magmoms[site] > 0 and m0 > 0:
mat_id_dict[site] = n_mats
if magmoms[site] < 0 and m0 < 0:
mat_id_dict[site] = n_mats
if magmoms[site] > 0 > m0:
mat_id_dict[site] = n_mats + 1
if magmoms[site] < 0 < m0:
mat_id_dict[site] = n_mats + 1

# Increment index if two sublattices
if spin_up and spin_down:
nmats += 1
n_mats += 1

mat_file = [f"material:num-materials={nmats}"]
mat_file = [f"material:num-materials={n_mats}"]

for key in self.unique_site_ids:
i = self.unique_site_ids[key] # unique site id
Expand Down Expand Up @@ -230,7 +228,7 @@ def _create_mat(self):

def _create_input(self):
structure = self.structure
mcbs = self.mc_box_size
mc_box_size = self.mc_box_size
equil_timesteps = self.equil_timesteps
mc_timesteps = self.mc_timesteps
mat_name = self.mat_name
Expand All @@ -255,9 +253,9 @@ def _create_input(self):

# System size in nm
input_script += [
f"dimensions:system-size-x = {mcbs:.1f} !nm",
f"dimensions:system-size-y = {mcbs:.1f} !nm",
f"dimensions:system-size-z = {mcbs:.1f} !nm",
f"dimensions:system-size-x = {mc_box_size:.1f} !nm",
f"dimensions:system-size-y = {mc_box_size:.1f} !nm",
f"dimensions:system-size-z = {mc_box_size:.1f} !nm",
]

# Critical temperature Monte Carlo calculation
Expand Down
27 changes: 7 additions & 20 deletions pymatgen/core/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# ruff: noqa: PLC0414
"""This package contains core modules and classes for representing structures and operations on them."""

from __future__ import annotations
Expand All @@ -10,25 +9,13 @@

from ruamel.yaml import YAML

from pymatgen.core.composition import Composition as Composition
from pymatgen.core.lattice import Lattice as Lattice
from pymatgen.core.operations import SymmOp as SymmOp
from pymatgen.core.periodic_table import DummySpecie as DummySpecie
from pymatgen.core.periodic_table import DummySpecies as DummySpecies
from pymatgen.core.periodic_table import Element as Element
from pymatgen.core.periodic_table import Species as Species
from pymatgen.core.periodic_table import get_el_sp as get_el_sp
from pymatgen.core.sites import PeriodicSite as PeriodicSite
from pymatgen.core.sites import Site as Site
from pymatgen.core.structure import IMolecule as IMolecule
from pymatgen.core.structure import IStructure as IStructure
from pymatgen.core.structure import Molecule as Molecule
from pymatgen.core.structure import PeriodicNeighbor as PeriodicNeighbor
from pymatgen.core.structure import SiteCollection as SiteCollection
from pymatgen.core.structure import Structure as Structure
from pymatgen.core.units import ArrayWithUnit as ArrayWithUnit
from pymatgen.core.units import FloatWithUnit as FloatWithUnit
from pymatgen.core.units import Unit as Unit
from pymatgen.core.composition import Composition
from pymatgen.core.lattice import Lattice
from pymatgen.core.operations import SymmOp
from pymatgen.core.periodic_table import DummySpecie, DummySpecies, Element, Species, get_el_sp
from pymatgen.core.sites import PeriodicSite, Site
from pymatgen.core.structure import IMolecule, IStructure, Molecule, PeriodicNeighbor, SiteCollection, Structure
from pymatgen.core.units import ArrayWithUnit, FloatWithUnit, Unit

__author__ = "Pymatgen Development Team"
__email__ = "pymatgen@googlegroups.com"
Expand Down
Loading

0 comments on commit 05c715d

Please sign in to comment.