Skip to content

Commit

Permalink
Update .pytest-split-durations (#3005)
Browse files Browse the repository at this point in the history
* partially update .pytest-split-durations

* skip StructureTest.test_relax() if tensorflow missing

* MoleculeGraph.find_rings() only sort cycle once

* drop -x (exit on error) from pytest addopts

* rerun pytest --store-durations --durations-path test_files/.pytest-split-durations without -x flag

* fix OptimadeTest.test_get_snls_mp() by making query stricter to reduce returned payload

avoids timeout and speeds up test
  • Loading branch information
janosh authored May 22, 2023
1 parent d621490 commit 13f7f5d
Show file tree
Hide file tree
Showing 9 changed files with 2,565 additions and 2,445 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ jobs:
- name: pytest split ${{ matrix.split }}
# to update the test durations, run
# pytest --store-durations --durations-path test_files/.pytest-split-durations
# and commit the results
# and commit the results (requires pip install pytest-split)
run: |
pytest --cov=pymatgen --splits 10 --group ${{ matrix.split }} --durations-path test_files/.pytest-split-durations
- name: Upload coverage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -724,14 +724,14 @@ def get_csm_and_maps(self, isite, max_csm=8.0, figsize=None, symmetry_measure_ty
ce = self.ce_list[isite][cn][inb_set]
if ce is None:
continue
mingeoms = ce.minimum_geometries(max_csm=max_csm)
if len(mingeoms) == 0:
min_geoms = ce.minimum_geometries(max_csm=max_csm)
if len(min_geoms) == 0:
continue
wds = nb_set.normalized_distances
max_wd = max(max_wd, max(wds))
all_wds.append(wds)
all_was.append(nb_set.normalized_angles)
for mp_symbol, cg_dict in mingeoms:
for mp_symbol, cg_dict in min_geoms:
csm = cg_dict["other_symmetry_measures"][symmetry_measure_type]
subplot.plot(idx, csm, "ob")
subplot.annotate(mp_symbol, xy=(idx, csm))
Expand Down
6 changes: 3 additions & 3 deletions pymatgen/analysis/graphs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2434,15 +2434,15 @@ def find_rings(self, including=None) -> list[list[tuple[int, int]]]:
cycles_edges = []

# Remove all two-edge cycles
all_cycles = [c for c in nx.simple_cycles(directed) if len(c) > 2]
all_cycles = [sorted(cycle) for cycle in nx.simple_cycles(directed) if len(cycle) > 2]

# Using to_directed() will mean that each cycle always appears twice
# So, we must also remove duplicates
unique_sorted = []
unique_cycles = []
for cycle in all_cycles:
if sorted(cycle) not in unique_sorted:
unique_sorted.append(sorted(cycle))
if cycle not in unique_sorted:
unique_sorted.append(cycle)
unique_cycles.append(cycle)

if including is None:
Expand Down
60 changes: 30 additions & 30 deletions pymatgen/analysis/local_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -2991,7 +2991,7 @@ def get_order_parameters(
# Zimmermann et al., J. Am. Chem. Soc., under revision, 2015).
if self._geomops:
gaussthetak: list[float] = [0 for t in self._types] # not used by all OPs
qsptheta = [[[] for j in range(nneigh)] for t in self._types] # type: ignore
qsp_theta = [[[] for j in range(nneigh)] for t in self._types] # type: ignore
norms = [[[] for j in range(nneigh)] for t in self._types] # type: ignore
ipi = 1 / pi
piover2 = pi / 2.0
Expand All @@ -3003,7 +3003,7 @@ def get_order_parameters(
for k in range(nneigh): # From neighbor k, we construct
if j != k: # the prime meridian.
for i in range(len(self._types)):
qsptheta[i][j].append(0.0)
qsp_theta[i][j].append(0.0)
norms[i][j].append(0)
tmp = max(-1.0, min(np.inner(zaxis, rij_norm[k]), 1.0))
thetak = acos(tmp)
Expand All @@ -3025,17 +3025,17 @@ def get_order_parameters(
for i, t in enumerate(self._types):
if t in ["bent", "sq_pyr_legacy"]:
tmp = self._params[i]["IGW_TA"] * (thetak * ipi - self._params[i]["TA"])
qsptheta[i][j][kc] += exp(-0.5 * tmp * tmp)
qsp_theta[i][j][kc] += exp(-0.5 * tmp * tmp)
norms[i][j][kc] += 1
elif t in ["tri_plan", "tri_plan_max", "tet", "tet_max"]:
tmp = self._params[i]["IGW_TA"] * (thetak * ipi - self._params[i]["TA"])
gaussthetak[i] = exp(-0.5 * tmp * tmp)
if t in ["tri_plan_max", "tet_max"]:
qsptheta[i][j][kc] += gaussthetak[i]
qsp_theta[i][j][kc] += gaussthetak[i]
norms[i][j][kc] += 1
elif t in ["T", "tri_pyr", "sq_pyr", "pent_pyr", "hex_pyr"]:
tmp = self._params[i]["IGW_EP"] * (thetak * ipi - 0.5)
qsptheta[i][j][kc] += exp(-0.5 * tmp * tmp)
qsp_theta[i][j][kc] += exp(-0.5 * tmp * tmp)
norms[i][j][kc] += 1
elif t in [
"sq_plan",
Expand All @@ -3046,7 +3046,7 @@ def get_order_parameters(
]:
if thetak >= self._params[i]["min_SPP"]:
tmp = self._params[i]["IGW_SPP"] * (thetak * ipi - 1.0)
qsptheta[i][j][kc] += self._params[i]["w_SPP"] * exp(-0.5 * tmp * tmp)
qsp_theta[i][j][kc] += self._params[i]["w_SPP"] * exp(-0.5 * tmp * tmp)
norms[i][j][kc] += self._params[i]["w_SPP"]
elif t in [
"see_saw_rect",
Expand All @@ -3065,23 +3065,23 @@ def get_order_parameters(
else self._params[i]["IGW_TA"]
* (fabs(thetak * ipi - 0.5) - self._params[i]["TA"])
)
qsptheta[i][j][kc] += exp(-0.5 * tmp * tmp)
qsp_theta[i][j][kc] += exp(-0.5 * tmp * tmp)
norms[i][j][kc] += 1
elif t in ["pent_plan", "pent_plan_max"]:
tmp = 0.4 if thetak <= self._params[i]["TA"] * pi else 0.8
tmp2 = self._params[i]["IGW_TA"] * (thetak * ipi - tmp)
gaussthetak[i] = exp(-0.5 * tmp2 * tmp2)
if t == "pent_plan_max":
qsptheta[i][j][kc] += gaussthetak[i]
qsp_theta[i][j][kc] += gaussthetak[i]
norms[i][j][kc] += 1
elif t == "bcc" and j < k:
if thetak >= self._params[i]["min_SPP"]:
tmp = self._params[i]["IGW_SPP"] * (thetak * ipi - 1.0)
qsptheta[i][j][kc] += self._params[i]["w_SPP"] * exp(-0.5 * tmp * tmp)
qsp_theta[i][j][kc] += self._params[i]["w_SPP"] * exp(-0.5 * tmp * tmp)
norms[i][j][kc] += self._params[i]["w_SPP"]
elif t == "sq_face_cap_trig_pris" and thetak < self._params[i]["TA3"]:
tmp = self._params[i]["IGW_TA1"] * (thetak * ipi - self._params[i]["TA1"])
qsptheta[i][j][kc] += exp(-0.5 * tmp * tmp)
qsp_theta[i][j][kc] += exp(-0.5 * tmp * tmp)
norms[i][j][kc] += 1

for m in range(nneigh):
Expand Down Expand Up @@ -3117,7 +3117,7 @@ def get_order_parameters(
and thetam >= self._params[i]["min_SPP"]
):
tmp = self._params[i]["IGW_SPP"] * (thetam * ipi - 1.0)
qsptheta[i][j][kc] += exp(-0.5 * tmp * tmp)
qsp_theta[i][j][kc] += exp(-0.5 * tmp * tmp)
norms[i][j][kc] += 1

# Contributions of j-i-m angle and
Expand All @@ -3133,14 +3133,14 @@ def get_order_parameters(
tmp = self._params[i]["IGW_TA"] * (thetam * ipi - self._params[i]["TA"])
tmp2 = cos(self._params[i]["fac_AA"] * phi) ** self._params[i]["exp_cos_AA"]
tmp3 = 1 if t in ["tri_plan_max", "tet_max"] else gaussthetak[i]
qsptheta[i][j][kc] += tmp3 * exp(-0.5 * tmp * tmp) * tmp2
qsp_theta[i][j][kc] += tmp3 * exp(-0.5 * tmp * tmp) * tmp2
norms[i][j][kc] += 1
elif t in ["pent_plan", "pent_plan_max"]:
tmp = 0.4 if thetam <= self._params[i]["TA"] * pi else 0.8
tmp2 = self._params[i]["IGW_TA"] * (thetam * ipi - tmp)
tmp3 = cos(phi)
tmp4 = 1 if t == "pent_plan_max" else gaussthetak[i]
qsptheta[i][j][kc] += tmp4 * exp(-0.5 * tmp2 * tmp2) * tmp3 * tmp3
qsp_theta[i][j][kc] += tmp4 * exp(-0.5 * tmp2 * tmp2) * tmp3 * tmp3
norms[i][j][kc] += 1
elif t in [
"T",
Expand All @@ -3151,7 +3151,7 @@ def get_order_parameters(
]:
tmp = cos(self._params[i]["fac_AA"] * phi) ** self._params[i]["exp_cos_AA"]
tmp3 = self._params[i]["IGW_EP"] * (thetam * ipi - 0.5)
qsptheta[i][j][kc] += tmp * exp(-0.5 * tmp3 * tmp3)
qsp_theta[i][j][kc] += tmp * exp(-0.5 * tmp3 * tmp3)
norms[i][j][kc] += 1
elif t in ["sq_plan", "oct", "oct_legacy"]:
if (
Expand All @@ -3163,9 +3163,9 @@ def get_order_parameters(
** self._params[i]["exp_cos_AA"]
)
tmp2 = self._params[i]["IGW_EP"] * (thetam * ipi - 0.5)
qsptheta[i][j][kc] += tmp * exp(-0.5 * tmp2 * tmp2)
qsp_theta[i][j][kc] += tmp * exp(-0.5 * tmp2 * tmp2)
if t == "oct_legacy":
qsptheta[i][j][kc] -= tmp * self._params[i][6] * self._params[i][7]
qsp_theta[i][j][kc] -= tmp * self._params[i][6] * self._params[i][7]
norms[i][j][kc] += 1
elif t in [
"tri_bipyr",
Expand All @@ -3190,13 +3190,13 @@ def get_order_parameters(
else self._params[i]["IGW_TA"]
* (fabs(thetam * ipi - 0.5) - self._params[i]["TA"])
)
qsptheta[i][j][kc] += tmp * exp(-0.5 * tmp2 * tmp2)
qsp_theta[i][j][kc] += tmp * exp(-0.5 * tmp2 * tmp2)
norms[i][j][kc] += 1
elif t == "bcc" and j < k:
if thetak < self._params[i]["min_SPP"]:
fac = 1 if thetak > piover2 else -1
tmp = (thetam - piover2) / asin(1 / 3)
qsptheta[i][j][kc] += (
qsp_theta[i][j][kc] += (
fac * cos(3 * phi) * fac_bcc * tmp * exp(-0.5 * tmp * tmp)
)
norms[i][j][kc] += 1
Expand All @@ -3211,7 +3211,7 @@ def get_order_parameters(
** self._params[i]["exp_cos_AA"]
)
tmp2 = self._params[i]["IGW_EP"] * (thetam * ipi - 0.5)
qsptheta[i][j][kc] += tmp * exp(-0.5 * tmp2 * tmp2)
qsp_theta[i][j][kc] += tmp * exp(-0.5 * tmp2 * tmp2)
norms[i][j][kc] += 1.0
elif t in ["cuboct", "cuboct_max"]:
if (
Expand All @@ -3221,19 +3221,19 @@ def get_order_parameters(
if self._params[i][4] < thetam < self._params[i][2]:
tmp = cos(phi)
tmp2 = self._params[i][5] * (thetam * ipi - 0.5)
qsptheta[i][j][kc] += tmp * tmp * exp(-0.5 * tmp2 * tmp2)
qsp_theta[i][j][kc] += tmp * tmp * exp(-0.5 * tmp2 * tmp2)
norms[i][j][kc] += 1.0
elif thetam < self._params[i][4]:
tmp = 0.0556 * (cos(phi - 0.5 * pi) - 0.81649658)
tmp2 = self._params[i][6] * (thetam * ipi - onethird)
qsptheta[i][j][kc] += exp(-0.5 * tmp * tmp) * exp(
qsp_theta[i][j][kc] += exp(-0.5 * tmp * tmp) * exp(
-0.5 * tmp2 * tmp2
)
norms[i][j][kc] += 1.0
elif thetam > self._params[i][2]:
tmp = 0.0556 * (cos(phi - 0.5 * pi) - 0.81649658)
tmp2 = self._params[i][6] * (thetam * ipi - twothird)
qsptheta[i][j][kc] += exp(-0.5 * tmp * tmp) * exp(
qsp_theta[i][j][kc] += exp(-0.5 * tmp * tmp) * exp(
-0.5 * tmp2 * tmp2
)
norms[i][j][kc] += 1.0
Expand Down Expand Up @@ -3262,7 +3262,7 @@ def get_order_parameters(
thetam * ipi - self._params[i]["TA2"]
)

qsptheta[i][j][kc] += tmp * exp(-0.5 * tmp2 * tmp2)
qsp_theta[i][j][kc] += tmp * exp(-0.5 * tmp2 * tmp2)
norms[i][j][kc] += 1

kc += 1
Expand All @@ -3281,7 +3281,7 @@ def get_order_parameters(
]:
ops[i] = tmp_norm = 0.0
for j in range(nneigh):
ops[i] += sum(qsptheta[i][j])
ops[i] += sum(qsp_theta[i][j])
tmp_norm += float(sum(norms[i][j]))
ops[i] = ops[i] / tmp_norm if tmp_norm > 1.0e-12 else None # type: ignore
elif t in [
Expand All @@ -3307,15 +3307,15 @@ def get_order_parameters(
ops[i] = None # type: ignore
if nneigh > 1:
for j in range(nneigh):
for k in range(len(qsptheta[i][j])):
qsptheta[i][j][k] = (
qsptheta[i][j][k] / norms[i][j][k] if norms[i][j][k] > 1.0e-12 else 0.0
for k in range(len(qsp_theta[i][j])):
qsp_theta[i][j][k] = (
qsp_theta[i][j][k] / norms[i][j][k] if norms[i][j][k] > 1.0e-12 else 0.0
)
ops[i] = max(qsptheta[i][j]) if j == 0 else max(ops[i], max(qsptheta[i][j]))
ops[i] = max(qsp_theta[i][j]) if j == 0 else max(ops[i], max(qsp_theta[i][j]))
elif t == "bcc":
ops[i] = 0.0
for j in range(nneigh):
ops[i] += sum(qsptheta[i][j])
ops[i] += sum(qsp_theta[i][j])
if nneigh > 3:
ops[i] = ops[i] / float(0.5 * float(nneigh * (6 + (nneigh - 2) * (nneigh - 3))))
else:
Expand All @@ -3328,7 +3328,7 @@ def get_order_parameters(
tmp = self._params[i][2] * (d - dmean)
acc = acc + exp(-0.5 * tmp * tmp)
for j in range(nneigh):
ops[i] = max(qsptheta[i][j]) if j == 0 else max(ops[i], max(qsptheta[i][j]))
ops[i] = max(qsp_theta[i][j]) if j == 0 else max(ops[i], max(qsp_theta[i][j]))
ops[i] = acc * ops[i] / float(nneigh)
# nneigh * (nneigh - 1))
else:
Expand Down
8 changes: 2 additions & 6 deletions pymatgen/analysis/tests/test_graphs.py
Original file line number Diff line number Diff line change
Expand Up @@ -840,12 +840,8 @@ def test_find_rings(self):
assert no_rings == []

def test_isomorphic(self):
ethylene = Molecule.from_file(
os.path.join(
PymatgenTest.TEST_FILES_DIR,
"graphs/ethylene.xyz",
)
)
ethyl_xyz_path = os.path.join(PymatgenTest.TEST_FILES_DIR, "graphs/ethylene.xyz")
ethylene = Molecule.from_file(ethyl_xyz_path)
# switch carbons
ethylene[0], ethylene[1] = ethylene[1], ethylene[0]

Expand Down
Loading

0 comments on commit 13f7f5d

Please sign in to comment.