From 267601a198c28a14bfa0ab455462cb861f3d414e Mon Sep 17 00:00:00 2001 From: Janosh Riebesell Date: Mon, 3 Apr 2023 18:30:13 -0700 Subject: [PATCH] replace calls to df.append() with pd.concat() and df.iteritems() with df.items() --- pymatgen/analysis/magnetism/heisenberg.py | 8 ++++---- pymatgen/io/lammps/data.py | 2 +- pymatgen/io/qchem/outputs.py | 20 ++++++-------------- 3 files changed, 11 insertions(+), 19 deletions(-) diff --git a/pymatgen/analysis/magnetism/heisenberg.py b/pymatgen/analysis/magnetism/heisenberg.py index dcfac25ef58..2d3eb12bd88 100644 --- a/pymatgen/analysis/magnetism/heisenberg.py +++ b/pymatgen/analysis/magnetism/heisenberg.py @@ -327,13 +327,13 @@ def _get_exchange_df(self): ex_row.at[sgraph_index, j_ji] -= s_i * s_j # Ignore the row if it is a duplicate to avoid singular matrix - if ex_mat.append(ex_row)[j_columns].equals( - ex_mat.append(ex_row)[j_columns].drop_duplicates(keep="first") - ): + # Create a temporary DataFrame with the new row + temp_df = pd.concat([ex_mat, ex_row], ignore_index=True) + if temp_df[j_columns].equals(temp_df[j_columns].drop_duplicates(keep="first")): e_index = self.ordered_structures.index(sgraph.structure) ex_row.at[sgraph_index, "E"] = self.energies[e_index] sgraph_index += 1 - ex_mat = ex_mat.append(ex_row) + ex_mat = pd.concat([ex_mat, ex_row], ignore_index=True) # if sgraph_index == num_nn_j: # check for zero columns # zeros = [b for b in (ex_mat[j_columns] == 0).all(axis=0)] # if True in zeros: diff --git a/pymatgen/io/lammps/data.py b/pymatgen/io/lammps/data.py index 7f8636f4363..41968038e14 100644 --- a/pymatgen/io/lammps/data.py +++ b/pymatgen/io/lammps/data.py @@ -552,7 +552,7 @@ def disassemble(self, atom_labels=None, guess_element=True, ff_label="ff_map"): for um, s in zip(unique_masses, symbols): masses.loc[masses["mass"] == um, "element"] = s if atom_labels is None: # add unique labels based on elements - for el, vc in masses["element"].value_counts().iteritems(): + for el, vc in masses["element"].value_counts().items(): masses.loc[masses["element"] == el, "label"] = [f"{el}{c}" for c in range(1, vc + 1)] assert masses["label"].nunique(dropna=False) == len(masses), "Expecting unique atom label for each type" mass_info = [(row.label, row.mass) for row in masses.itertuples()] diff --git a/pymatgen/io/qchem/outputs.py b/pymatgen/io/qchem/outputs.py index dc0e934b125..1e75b43877a 100644 --- a/pymatgen/io/qchem/outputs.py +++ b/pymatgen/io/qchem/outputs.py @@ -1368,13 +1368,7 @@ def _read_optimization_data(self): self.data["energy_trajectory"] = [] if read_pattern(self.text, {"key": r"Error in back_transform"}, terminate_on_match=True).get("key") == [[]]: self.data["errors"] += ["back_transform_error"] - elif read_pattern( - self.text, - {"key": r"pinv\(\)\: svd failed"}, - terminate_on_match=True, - ).get( - "key" - ) == [[]]: + elif read_pattern(self.text, {"key": r"pinv\(\)\: svd failed"}, terminate_on_match=True).get("key") == [[]]: self.data["errors"] += ["svd_failed"] else: real_energy_trajectory = np.zeros(len(temp_energy_trajectory)) @@ -2668,13 +2662,13 @@ def parse_perturbation_energy(lines: list[str]) -> list[pd.DataFrame]: Parse the perturbation energy section of NBO output. Args: - lines: QChem output lines. + lines: QChem output lines. Returns: - Data frame of formatted output. + Data frame of formatted output. Raises: - RuntimeError + RuntimeError """ no_failures = True e2_dfs = [] @@ -2682,10 +2676,8 @@ def parse_perturbation_energy(lines: list[str]) -> list[pd.DataFrame]: while no_failures: # 2nd order perturbation theory analysis try: - lines = jump_to_header( - lines, - "SECOND ORDER PERTURBATION THEORY ANALYSIS OF FOCK MATRIX IN NBO BASIS", - ) + header_str = "SECOND ORDER PERTURBATION THEORY ANALYSIS OF FOCK MATRIX IN NBO BASIS" + lines = jump_to_header(lines, header_str) except RuntimeError: no_failures = False