Skip to content

Commit 6973b7a

Browse files
committed
try to use chargemol precompiled binary
1 parent 43b2385 commit 6973b7a

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

tests/command_line/test_chargemol_caller.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,37 @@
11
from __future__ import annotations
22

3+
import os
4+
import subprocess
5+
import zipfile
36
from unittest.mock import patch
7+
from urllib.request import urlretrieve
48

59
import pytest
610

711
from pymatgen.command_line.chargemol_caller import ChargemolAnalysis
812
from pymatgen.core import Element, Structure
913
from pymatgen.util.testing import TEST_FILES_DIR
1014

15+
ddec_url = "https://sourceforge.net/projects/ddec/files/latest/download"
16+
download_path = TEST_FILES_DIR / "command_line" / "chargemol" / "ddec-latest.gz"
17+
extract_path = TEST_FILES_DIR / "command_line" / "chargemol"
18+
19+
if not os.path.exists(download_path):
20+
urlretrieve(ddec_url, download_path)
21+
22+
if not os.path.exists(extract_path / "chargemol_09_26_2017"):
23+
with zipfile.ZipFile(download_path, "r") as zip_ref:
24+
zip_ref.extractall(extract_path)
25+
26+
exe_path = extract_path / "chargemol_09_26_2017/chargemol_FORTRAN_09_26_2017/compiled_binaries/linux"
27+
28+
current_path = os.environ.get("PATH", "")
29+
if str(exe_path) not in current_path:
30+
os.environ["PATH"] = str(exe_path) + os.pathsep + current_path
31+
32+
subprocess.call(["chmod", "+x", str(exe_path / "Chargemol_09_26_2017_linux_serial")])
33+
subprocess.call(["chmod", "+x", str(exe_path / "Chargemol_09_26_2017_linux_parallel")])
34+
1135

1236
class TestChargemolAnalysis:
1337
def test_parse_chargemol(self):
@@ -72,3 +96,11 @@ def test_missing_exe_error(self):
7296
OSError, match="ChargemolAnalysis requires the Chargemol executable to be in PATH. Please download"
7397
):
7498
ChargemolAnalysis(path=test_dir, run_chargemol=True)
99+
100+
def test_chargemol_custom_path(self):
101+
chg_mol = ChargemolAnalysis(
102+
path=TEST_FILES_DIR / "command_line" / "bader",
103+
atomic_densities_path=extract_path / "chargemol_09_26_2017" / "atomic_densities",
104+
run_chargemol=True,
105+
)
106+
print(chg_mol.ddec_charges)

0 commit comments

Comments
 (0)