Skip to content

Commit

Permalink
run black
Browse files Browse the repository at this point in the history
  • Loading branch information
mattmcdermott committed Aug 16, 2021
1 parent 48b84a5 commit 886ed3f
Showing 1 changed file with 28 additions and 32 deletions.
60 changes: 28 additions & 32 deletions pymatgen/analysis/chempot_diagram.py
Expand Up @@ -69,17 +69,15 @@ def __init__(
self.limits = limits
self.default_limit = default_limit

self.elements = list(sorted({els for e in self.entries for els in
e.composition.elements}))
self.elements = list(sorted({els for e in self.entries for els in e.composition.elements}))
self.dim = len(self.elements)
self._min_entries, self.el_refs = self._get_min_entries_and_el_refs(entries)
self._entry_dict = {e.composition.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()

if self.dim < 3:
raise ValueError("ChemicalPotentialDiagram currently requires phase diagrams "
"with 3 or more elements!")
raise ValueError("ChemicalPotentialDiagram currently requires phase diagrams " "with 3 or more elements!")

if len(self.el_refs) != self.dim:
missing = set(self.elements).difference(self.el_refs.keys())
Expand Down Expand Up @@ -117,8 +115,7 @@ def get_plot(

domains = self.domains.copy()
draw_domains = {}
draw_comps = [Composition(formula).reduced_composition for formula in
formulas_to_draw]
draw_comps = [Composition(formula).reduced_composition for formula in formulas_to_draw]
annotations = []

for formula, points in domains.items():
Expand Down Expand Up @@ -202,8 +199,10 @@ def _get_border_hyperplanes(self):

def _get_hyperplanes_and_entries(self):
data = np.array(
[[e.composition.get_atomic_fraction(el) for el in self.elements] + [
e.energy_per_atom] for e in self._min_entries]
[
[e.composition.get_atomic_fraction(el) for el in self.elements] + [e.energy_per_atom]
for e in self._min_entries
]
)
vec = [self.el_refs[el].energy_per_atom for el in self.elements] + [-1]
form_e = -np.dot(data, vec)
Expand Down Expand Up @@ -239,8 +238,7 @@ def _get_domain_simplices_and_ann_loc(points_3d):
points_2d, v, w = simple_pca(points_3d, k=2)
domain = ConvexHull(points_2d)
centroid_2d = get_centroid_2d(points_2d[domain.vertices])
ann_loc = centroid_2d @ w.T + np.mean(points_3d.T,
axis=1) # recover orig 3D coords from eigenvectors
ann_loc = centroid_2d @ w.T + np.mean(points_3d.T, axis=1) # recover orig 3D coords from eigenvectors

simplices = [Simplex(points_3d[indices]) for indices in domain.simplices]

Expand All @@ -252,16 +250,16 @@ def _get_formula_meshes(draw_domains, formula_colors) -> List[Mesh3d]:
for idx, (formula, coords) in enumerate(draw_domains.items()):
points_3d = coords[:, :3]
mesh = Mesh3d(
x=points_3d[:, 0],
y=points_3d[:, 1],
z=points_3d[:, 2],
alphahull=0,
showlegend=True,
lighting=dict(fresnel=1.0),
color=formula_colors[idx],
name=f"{formula} (mesh)",
opacity=0.13,
)
x=points_3d[:, 0],
y=points_3d[:, 1],
z=points_3d[:, 2],
alphahull=0,
showlegend=True,
lighting=dict(fresnel=1.0),
color=formula_colors[idx],
name=f"{formula} (mesh)",
opacity=0.13,
)
meshes.append(mesh)
return meshes

Expand All @@ -280,14 +278,14 @@ def _get_formula_lines(draw_domains, formula_colors) -> List[Scatter3d]:
z.extend(s.coords[:, 2].tolist() + [None])

line = Scatter3d(
x=x,
y=y,
z=z,
mode="lines",
line={"width": 8, "color": formula_colors[idx]},
opacity=1.0,
name=f"{formula} (lines)",
)
x=x,
y=y,
z=z,
mode="lines",
line={"width": 8, "color": formula_colors[idx]},
opacity=1.0,
name=f"{formula} (lines)",
)
lines.append(line)
return lines

Expand Down Expand Up @@ -356,8 +354,7 @@ def chemical_system(self) -> str:

@staticmethod
def _get_chempot_axis_title(element) -> str:
return f"μ<sub>{str(element)}</sub> - μ<sub>" \
f"{str(element)}</sub><sup>o</sup> (eV)"
return f"μ<sub>{str(element)}</sub> - μ<sub>" f"{str(element)}</sub><sup>o</sup> (eV)"

@staticmethod
def _get_annotation(ann_loc, formula) -> Dict[str, Union[str, float]]:
Expand All @@ -384,8 +381,7 @@ def _get_axis_layout_dict(self, elements):
return axes_layout

def __repr__(self):
return f"ChemicalPotentialDiagram for {self.chemical_system} with {len(self.entries)} " \
f"entries"
return f"ChemicalPotentialDiagram for {self.chemical_system} with {len(self.entries)} " f"entries"


def simple_pca(data: np.array, k: int = 2) -> Tuple[np.array, np.array, np.array]:
Expand Down

0 comments on commit 886ed3f

Please sign in to comment.