Skip to content

Commit

Permalink
remove unnecessary dict.keys()
Browse files Browse the repository at this point in the history
  • Loading branch information
janosh committed Jan 30, 2023
1 parent 3e6ae36 commit 35ffd5e
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 23 deletions.
3 changes: 1 addition & 2 deletions pymatgen/analysis/diffraction/tem.py
Expand Up @@ -271,10 +271,9 @@ def cell_intensity(
dict of hkl plane to cell intensity
"""
csf = self.cell_scattering_factors(structure, bragg_angles)
plane = bragg_angles.keys()
csf_val = np.array(list(csf.values()))
cell_intensity_val = (csf_val * csf_val.conjugate()).real
cell_intensity = dict(zip(plane, cell_intensity_val))
cell_intensity = dict(zip(bragg_angles, cell_intensity_val))
return cell_intensity

def get_pattern(
Expand Down
2 changes: 1 addition & 1 deletion pymatgen/analysis/disorder.py
Expand Up @@ -32,7 +32,7 @@ def get_warren_cowley_parameters(structure: Structure, r: float, dr: float) -> d
n_neighbors[site.specie] += 1

alpha_ij = {} # type: ignore
for sp1, sp2 in itertools.product(comp.keys(), comp.keys()):
for sp1, sp2 in itertools.product(comp, comp):
pij = n_ij.get((sp1, sp2), 0) / n_neighbors[sp1]
conc2 = comp.get_atomic_fraction(sp2)
alpha_ij[(sp1, sp2)] = (pij - conc2) / ((1 if sp1 == sp2 else 0) - conc2)
Expand Down
18 changes: 9 additions & 9 deletions pymatgen/analysis/phase_diagram.py
Expand Up @@ -1099,23 +1099,23 @@ def get_element_profile(self, element, comp, comp_tol=1e-5):
if element not in self.elements:
raise ValueError("get_transition_chempots can only be called with elements in the phase diagram.")

gccomp = Composition({el: amt for el, amt in comp.items() if el != element})
elref = self.el_refs[element]
elcomp = Composition(element.symbol)
gc_comp = Composition({el: amt for el, amt in comp.items() if el != element})
el_ref = self.el_refs[element]
el_comp = Composition(element.symbol)
evolution = []

for cc in self.get_critical_compositions(elcomp, gccomp)[1:]:
decomp_entries = list(self.get_decomposition(cc).keys())
for cc in self.get_critical_compositions(el_comp, gc_comp)[1:]:
decomp_entries = list(self.get_decomposition(cc))
decomp = [k.composition for k in decomp_entries]
rxn = Reaction([comp], decomp + [elcomp])
rxn = Reaction([comp], decomp + [el_comp])
rxn.normalize_to(comp)
c = self.get_composition_chempots(cc + elcomp * 1e-5)[element]
amt = -rxn.coeffs[rxn.all_comp.index(elcomp)]
c = self.get_composition_chempots(cc + el_comp * 1e-5)[element]
amt = -rxn.coeffs[rxn.all_comp.index(el_comp)]
evolution.append(
{
"chempot": c,
"evolution": amt,
"element_reference": elref,
"element_reference": el_ref,
"reaction": rxn,
"entries": decomp_entries,
"critical_composition": cc,
Expand Down
Expand Up @@ -72,13 +72,13 @@ class SubstitutionPredictorTest(unittest.TestCase):
def test_prediction(self):
sp = SubstitutionPredictor(threshold=8e-3)
result = sp.list_prediction(["Na+", "Cl-"], to_this_composition=True)[5]
cprob = sp.p.cond_prob_list(result["substitutions"].keys(), result["substitutions"].values())
assert result["probability"] == approx(cprob)
cond_prob = sp.p.cond_prob_list(list(result["substitutions"]), result["substitutions"].values())
assert result["probability"] == approx(cond_prob)
assert set(result["substitutions"].values()) == {"Na+", "Cl-"}

result = sp.list_prediction(["Na+", "Cl-"], to_this_composition=False)[5]
cprob = sp.p.cond_prob_list(result["substitutions"].keys(), result["substitutions"].values())
assert result["probability"] == approx(cprob)
cond_prob = sp.p.cond_prob_list(list(result["substitutions"]), result["substitutions"].values())
assert result["probability"] == approx(cond_prob)
assert set(result["substitutions"].values()) != {"Na+", "Cl-"}

c = Composition({"Ag2+": 1, "Cl-": 2})
Expand Down
4 changes: 2 additions & 2 deletions pymatgen/analysis/surface_analysis.py
Expand Up @@ -1296,7 +1296,7 @@ def surface_chempot_range_map(

# Plot the edge along the max x value
pt = v[-1]
delu1, delu2 = pt.keys()
delu1, delu2 = pt
xvals.extend([pt[delu1], pt[delu1]])
yvals.extend(pt[delu2][0])
if not show_unphyiscal_only:
Expand Down Expand Up @@ -1849,7 +1849,7 @@ def scaled_wulff(self, wulffshape, r):
"""
# get the scaling ratio for the energies
r_ratio = r / wulffshape.effective_radius
miller_list = wulffshape.miller_energy_dict.keys()
miller_list = list(wulffshape.miller_energy_dict)
# Normalize the magnitude of the facet normal vectors
# of the Wulff shape by the minimum surface energy.
se_list = np.array(list(wulffshape.miller_energy_dict.values()))
Expand Down
8 changes: 4 additions & 4 deletions pymatgen/io/cp2k/outputs.py
Expand Up @@ -659,9 +659,9 @@ def parse_dft_params(self):

# Functional
if self.input and self.input.check("FORCE_EVAL/DFT/XC/XC_FUNCTIONAL"):
xcfuncs = list(self.input["force_eval"]["dft"]["xc"]["xc_functional"].subsections.keys())
if xcfuncs:
self.data["dft"]["functional"] = xcfuncs
xc_funcs = list(self.input["force_eval"]["dft"]["xc"]["xc_functional"].subsections)
if xc_funcs:
self.data["dft"]["functional"] = xc_funcs
else:
for v in self.input["force_eval"]["dft"]["xc"].subsections.values():
if v.name.upper() == "XC_FUNCTIONAL":
Expand Down Expand Up @@ -1614,7 +1614,7 @@ def read_pattern(self, patterns, reverse=False, terminate_on_match=False, postpr
terminate_on_match=terminate_on_match,
postprocess=postprocess,
)
for k in patterns.keys():
for k in patterns:
self.data[k] = [i[0] for i in matches.get(k, [])]

def read_table_pattern(
Expand Down
2 changes: 1 addition & 1 deletion pymatgen/io/vasp/inputs.py
Expand Up @@ -2014,7 +2014,7 @@ def verify_potcar(self) -> tuple[bool, bool]:
# file with known potcar file hashes.
md5_file_hash = self.file_hash
hash_db = loadfn(os.path.join(cwd, "vasp_potcar_file_hashes.json"))
if md5_file_hash in hash_db.keys():
if md5_file_hash in hash_db:
passed_hash_check = True
else:
passed_hash_check = False
Expand Down

0 comments on commit 35ffd5e

Please sign in to comment.