Skip to content

Commit

Permalink
Fix _get_dipole_info for DDEC6 ChargemolAnalysis and add test case (
Browse files Browse the repository at this point in the history
#3801)

* fix _get_dipole_info for ddec6 and add test case

* refactor

---------

Co-authored-by: Janosh Riebesell <janosh.riebesell@gmail.com>
  • Loading branch information
JonathanSchmidt1 and janosh authored May 2, 2024
1 parent 87c92e6 commit 4e7a68d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
18 changes: 9 additions & 9 deletions pymatgen/command_line/chargemol_caller.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,16 +416,16 @@ def _get_dipole_info(filepath):
idx = 0
start = False
dipoles = []
with open(filepath) as r:
for line in r:
with open(filepath) as file:
for line in file:
if "The following XYZ" in line:
start = True
idx += 1
continue
if start and line.strip() == "":
break
if idx >= 2:
dipoles.append([float(d) for d in line.strip().split()[7:10]])
dipoles.append(list(map(float, line.strip().split()[6:9])))
if start:
idx += 1

Expand All @@ -441,9 +441,9 @@ def _get_bond_order_info(filename):
# Get where relevant info for each atom starts
bond_order_info = {}

with open(filename, encoding="utf-8") as r:
with open(filename, encoding="utf-8") as file:
start_idx = 0
for line in r:
for line in file:
split = line.strip().split()
if "Printing BOs" in line:
start_idx = int(split[5]) - 1
Expand Down Expand Up @@ -543,8 +543,8 @@ def _get_data_from_xyz(xyz_path) -> list[float]:
"""
props = []
if os.path.isfile(xyz_path):
with open(xyz_path) as r:
for idx, line in enumerate(r):
with open(xyz_path) as file:
for idx, line in enumerate(file):
if idx <= 1:
continue
if line.strip() == "":
Expand All @@ -568,8 +568,8 @@ def _get_cm5_data_from_output(ddec_analysis_path) -> list[float]:
props = []
if os.path.isfile(ddec_analysis_path):
start = False
with open(ddec_analysis_path) as r:
for line in r:
with open(ddec_analysis_path) as file:
for line in file:
if "computed CM5" in line:
start = True
continue
Expand Down
1 change: 1 addition & 0 deletions tests/command_line/test_chargemol_caller.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ def test_parse_chargemol2(self):
test_dir = f"{TEST_DIR}/spin_polarized"
ca = ChargemolAnalysis(path=test_dir, run_chargemol=False)
assert ca.ddec_spin_moments == [0.201595, 0.399203, 0.399203]
assert ca.dipoles == [[-0.0, 0.0, -0.127251], [0.0, -0.027857, -0.010944], [0.0, 0.027857, -0.010944]]
assert ca.summary["ddec"]["bond_order_dict"][0]["bonded_to"][0]["spin_polarization"] == 0.0490
assert ca.summary["ddec"]["spin_moments"] == ca.ddec_spin_moments
assert ca.natoms is None
Expand Down

0 comments on commit 4e7a68d

Please sign in to comment.