|
1 | 1 | from __future__ import annotations
|
2 | 2 |
|
| 3 | +import os |
| 4 | +import subprocess |
| 5 | +import zipfile |
3 | 6 | from unittest.mock import patch
|
| 7 | +from urllib.request import urlretrieve |
4 | 8 |
|
5 | 9 | import pytest
|
6 | 10 |
|
7 | 11 | from pymatgen.command_line.chargemol_caller import ChargemolAnalysis
|
8 | 12 | from pymatgen.core import Element, Structure
|
9 | 13 | from pymatgen.util.testing import TEST_FILES_DIR
|
10 | 14 |
|
| 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 | + |
11 | 35 |
|
12 | 36 | class TestChargemolAnalysis:
|
13 | 37 | def test_parse_chargemol(self):
|
@@ -72,3 +96,11 @@ def test_missing_exe_error(self):
|
72 | 96 | OSError, match="ChargemolAnalysis requires the Chargemol executable to be in PATH. Please download"
|
73 | 97 | ):
|
74 | 98 | 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