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

Add Entry.(formula|reduced_formula) #3611

Merged
merged 5 commits into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 5 additions & 5 deletions pymatgen/analysis/bond_valence.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ def _recurse(assigned=None):
for _ in valences[idx]:
tmp.append(n_site)
attrib.append(idx)
new_nsites = np.array(tmp)
new_n_sites = np.array(tmp)
fractions = []
elements = []
for sites in equi_sites:
Expand All @@ -340,8 +340,8 @@ def _recurse(assigned=None):
fractions.append(occu)
fractions = np.array(fractions, float) # type: ignore[assignment]
new_valences = [val for vals in valences for val in vals]
valence_min = np.array([min(i) for i in new_valences], float)
valence_max = np.array([max(i) for i in new_valences], float)
valence_min = np.array([min(val) for val in new_valences], float)
valence_max = np.array([max(val) for val in new_valences], float)

self._n = 0
self._best_score = 0
Expand Down Expand Up @@ -377,13 +377,13 @@ def _recurse(assigned=None):
i = len(assigned)
highest = valence_max.copy()
highest[:i] = assigned
highest *= new_nsites
highest *= new_n_sites
highest *= fractions
highest = np.sum(highest)

lowest = valence_min.copy()
lowest[:i] = assigned
lowest *= new_nsites
lowest *= new_n_sites
lowest *= fractions
lowest = np.sum(lowest)

Expand Down
18 changes: 9 additions & 9 deletions pymatgen/analysis/chempot_diagram.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def __init__(
self.elements = sorted({els for e in self.entries for els in e.elements})
self.dim = len(self.elements)
self._min_entries, self._el_refs = self._get_min_entries_and_el_refs(self.entries)
self._entry_dict = {e.composition.reduced_formula: e for e in self._min_entries}
self._entry_dict = {e.reduced_formula: e for e in self._min_entries}
self._border_hyperplanes = self._get_border_hyperplanes()
self._hyperplanes, self._hyperplane_entries = self._get_hyperplanes_and_entries()

Expand Down Expand Up @@ -211,13 +211,13 @@ def _get_domains(self) -> dict[str, np.ndarray]:
interior_point = np.min(self.lims, axis=1) + 1e-1
hs_int = HalfspaceIntersection(hs_hyperplanes, interior_point)

domains = {entry.composition.reduced_formula: [] for entry in entries} # type: ignore
domains = {entry.reduced_formula: [] for entry in entries} # type: ignore

for intersection, facet in zip(hs_int.intersections, hs_int.dual_facets):
for v in facet:
if v < len(entries):
this_entry = entries[v]
formula = this_entry.composition.reduced_formula
formula = this_entry.reduced_formula
domains[formula].append(intersection)

return {k: np.array(v) for k, v in domains.items() if v}
Expand All @@ -241,8 +241,8 @@ def _get_hyperplanes_and_entries(self) -> tuple[np.ndarray, list[PDEntry]]:
"""
data = np.array(
[
[e.composition.get_atomic_fraction(el) for el in self.elements] + [e.energy_per_atom]
for e in self._min_entries
[entry.composition.get_atomic_fraction(el) for el in self.elements] + [entry.energy_per_atom]
for entry in self._min_entries
]
)
vec = [self.el_refs[el].energy_per_atom for el in self.elements] + [-1]
Expand All @@ -254,7 +254,7 @@ def _get_hyperplanes_and_entries(self) -> tuple[np.ndarray, list[PDEntry]]:

hyperplanes = data[inds]
hyperplanes[:, -1] = hyperplanes[:, -1] * -1
hyperplane_entries = [self._min_entries[i] for i in inds]
hyperplane_entries = [self._min_entries[idx] for idx in inds]

return hyperplanes, hyperplane_entries

Expand Down Expand Up @@ -283,7 +283,7 @@ def _get_2d_plot(self, elements: list[Element], label_stable: bool | None, eleme
entry = self.entry_dict[formula]
anno_formula = formula
if hasattr(entry, "original_entry"):
anno_formula = entry.original_entry.composition.reduced_formula
anno_formula = entry.original_entry.reduced_formula

center = pts_2d.mean(axis=0)
normal = get_2d_orthonormal_vector(pts_2d)
Expand Down Expand Up @@ -355,7 +355,7 @@ def _get_3d_plot(

anno_formula = formula
if hasattr(entry, "original_entry"):
anno_formula = entry.original_entry.composition.reduced_formula
anno_formula = entry.original_entry.reduced_formula

annotation = self._get_annotation(ann_loc, anno_formula)
annotations.append(annotation)
Expand Down Expand Up @@ -548,7 +548,7 @@ def _get_min_entries_and_el_refs(
el_refs = {}
min_entries = []

for formula, group in groupby(entries, key=lambda e: e.composition.reduced_formula):
for formula, group in groupby(entries, key=lambda e: e.reduced_formula):
comp = Composition(formula)
min_entry = min(group, key=lambda e: e.energy_per_atom)
if comp.is_element:
Expand Down
12 changes: 6 additions & 6 deletions pymatgen/analysis/ewald.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,9 +372,9 @@ def _calc_real_and_point(self):

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

for i in range(n_sites):
for idx in range(n_sites):
nf_coords, rij, js, _ = self._struct.lattice.get_points_in_sphere(
frac_coords, coords[i], self._rmax, zip_results=False
frac_coords, coords[idx], self._rmax, zip_results=False
)

# remove the rii term
Expand All @@ -383,22 +383,22 @@ def _calc_real_and_point(self):
rij = rij[inds]
nf_coords = nf_coords[inds]

qi = qs[i]
qi = qs[idx]
qj = qs[js]

erfc_val = erfc(self._sqrt_eta * rij)
new_ereals = erfc_val * qi * qj / rij

# insert new_ereals
for key in range(n_sites):
e_real[key, i] = np.sum(new_ereals[js == key])
e_real[key, idx] = np.sum(new_ereals[js == key])

if self._compute_forces:
nc_coords = self._struct.lattice.get_cartesian_coords(nf_coords)

fijpf = qj / rij**3 * (erfc_val + force_pf * rij * np.exp(-self._eta * rij**2))
forces[i] += np.sum(
np.expand_dims(fijpf, 1) * (np.array([coords[i]]) - nc_coords) * qi * EwaldSummation.CONV_FACT,
forces[idx] += np.sum(
np.expand_dims(fijpf, 1) * (np.array([coords[idx]]) - nc_coords) * qi * EwaldSummation.CONV_FACT,
axis=0,
)

Expand Down
80 changes: 40 additions & 40 deletions pymatgen/analysis/local_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -2450,36 +2450,36 @@ def get_q2(self, thetas=None, phis=None):

# Y_2_-2
real = imag = 0.0
for i in nnn_range:
real += pre_y_2_2[i] * self._cos_n_p[2][i]
imag -= pre_y_2_2[i] * self._sin_n_p[2][i]
for idx in nnn_range:
real += pre_y_2_2[idx] * self._cos_n_p[2][idx]
imag -= pre_y_2_2[idx] * self._sin_n_p[2][idx]
acc += real * real + imag * imag

# Y_2_-1
real = imag = 0.0
for i in nnn_range:
real += pre_y_2_1[i] * self._cos_n_p[1][i]
imag -= pre_y_2_1[i] * self._sin_n_p[1][i]
for idx in nnn_range:
real += pre_y_2_1[idx] * self._cos_n_p[1][idx]
imag -= pre_y_2_1[idx] * self._sin_n_p[1][idx]
acc += real * real + imag * imag

# Y_2_0
real = imag = 0.0
for i in nnn_range:
real += 0.25 * sqrt_5_pi * (3 * self._pow_cos_t[2][i] - 1.0)
for idx in nnn_range:
real += 0.25 * sqrt_5_pi * (3 * self._pow_cos_t[2][idx] - 1.0)
acc += real * real

# Y_2_1
real = imag = 0.0
for i in nnn_range:
real -= pre_y_2_1[i] * self._cos_n_p[1][i]
imag -= pre_y_2_1[i] * self._sin_n_p[1][i]
for idx in nnn_range:
real -= pre_y_2_1[idx] * self._cos_n_p[1][idx]
imag -= pre_y_2_1[idx] * self._sin_n_p[1][idx]
acc += real * real + imag * imag

# Y_2_2
real = imag = 0.0
for i in nnn_range:
real += pre_y_2_2[i] * self._cos_n_p[2][i]
imag += pre_y_2_2[i] * self._sin_n_p[2][i]
for idx in nnn_range:
real += pre_y_2_2[idx] * self._cos_n_p[2][idx]
imag += pre_y_2_2[idx] * self._sin_n_p[2][idx]
acc += real * real + imag * imag

return sqrt(4 * pi * acc / (5 * float(nnn * nnn)))
Expand Down Expand Up @@ -2528,64 +2528,64 @@ def get_q4(self, thetas=None, phis=None):

# Y_4_-4
real = imag = 0.0
for i in nnn_range:
real += pre_y_4_4[i] * self._cos_n_p[4][i]
imag -= pre_y_4_4[i] * self._sin_n_p[4][i]
for idx in nnn_range:
real += pre_y_4_4[idx] * self._cos_n_p[4][idx]
imag -= pre_y_4_4[idx] * self._sin_n_p[4][idx]
acc += real * real + imag * imag

# Y_4_-3
real = imag = 0.0
for i in nnn_range:
real += pre_y_4_3[i] * self._cos_n_p[3][i]
imag -= pre_y_4_3[i] * self._sin_n_p[3][i]
for idx in nnn_range:
real += pre_y_4_3[idx] * self._cos_n_p[3][idx]
imag -= pre_y_4_3[idx] * self._sin_n_p[3][idx]
acc += real * real + imag * imag

# Y_4_-2
real = imag = 0.0
for i in nnn_range:
real += pre_y_4_2[i] * self._cos_n_p[2][i]
imag -= pre_y_4_2[i] * self._sin_n_p[2][i]
for idx in nnn_range:
real += pre_y_4_2[idx] * self._cos_n_p[2][idx]
imag -= pre_y_4_2[idx] * self._sin_n_p[2][idx]
acc += real * real + imag * imag

# Y_4_-1
real = imag = 0.0
for i in nnn_range:
real += pre_y_4_1[i] * self._cos_n_p[1][i]
imag -= pre_y_4_1[i] * self._sin_n_p[1][i]
for idx in nnn_range:
real += pre_y_4_1[idx] * self._cos_n_p[1][idx]
imag -= pre_y_4_1[idx] * self._sin_n_p[1][idx]
acc += real * real + imag * imag

# Y_4_0
real = imag = 0.0
for i in nnn_range:
real += i16_3 * sqrt_1_pi * (35 * self._pow_cos_t[4][i] - 30 * self._pow_cos_t[2][i] + 3.0)
for idx in nnn_range:
real += i16_3 * sqrt_1_pi * (35 * self._pow_cos_t[4][idx] - 30 * self._pow_cos_t[2][idx] + 3.0)
acc += real * real

# Y_4_1
real = imag = 0.0
for i in nnn_range:
real -= pre_y_4_1[i] * self._cos_n_p[1][i]
imag -= pre_y_4_1[i] * self._sin_n_p[1][i]
for idx in nnn_range:
real -= pre_y_4_1[idx] * self._cos_n_p[1][idx]
imag -= pre_y_4_1[idx] * self._sin_n_p[1][idx]
acc += real * real + imag * imag

# Y_4_2
real = imag = 0.0
for i in nnn_range:
real += pre_y_4_2[i] * self._cos_n_p[2][i]
imag += pre_y_4_2[i] * self._sin_n_p[2][i]
for idx in nnn_range:
real += pre_y_4_2[idx] * self._cos_n_p[2][idx]
imag += pre_y_4_2[idx] * self._sin_n_p[2][idx]
acc += real * real + imag * imag

# Y_4_3
real = imag = 0.0
for i in nnn_range:
real -= pre_y_4_3[i] * self._cos_n_p[3][i]
imag -= pre_y_4_3[i] * self._sin_n_p[3][i]
for idx in nnn_range:
real -= pre_y_4_3[idx] * self._cos_n_p[3][idx]
imag -= pre_y_4_3[idx] * self._sin_n_p[3][idx]
acc += real * real + imag * imag

# Y_4_4
real = imag = 0.0
for i in nnn_range:
real += pre_y_4_4[i] * self._cos_n_p[4][i]
imag += pre_y_4_4[i] * self._sin_n_p[4][i]
for idx in nnn_range:
real += pre_y_4_4[idx] * self._cos_n_p[4][idx]
imag += pre_y_4_4[idx] * self._sin_n_p[4][idx]
acc += real * real + imag * imag

return sqrt(4 * pi * acc / (9 * float(nnn * nnn)))
Expand Down
2 changes: 1 addition & 1 deletion pymatgen/analysis/magnetism/heisenberg.py
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,7 @@ def get_heisenberg_model(self):
HeisenbergModel: MSONable object.
"""
# Original formula unit with nonmagnetic ions
hm_formula = str(self.ordered_structures_[0].composition.reduced_formula)
hm_formula = str(self.ordered_structures_[0].reduced_formula)

hm_structures = self.ordered_structures
hm_energies = self.energies
Expand Down
Loading
Loading