Skip to content

Commit d069185

Browse files
authored
Merge pull request #760 from janosh/main
Fix `ModuleNotFoundError`: No module named 'pymatgen.transformations.defect_transformations'
2 parents 3b5da4e + be615b7 commit d069185

29 files changed

+181
-148
lines changed

.github/workflows/test.yml

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,15 @@ jobs:
1818

1919
steps:
2020
- name: Checkout repo
21-
uses: actions/checkout@v2
21+
uses: actions/checkout@v3
2222

2323
- name: Setup Python
24-
uses: actions/setup-python@v2
24+
uses: actions/setup-python@v4
2525
with:
26+
cache: pip
27+
cache-dependency-path: |
28+
setup.py
29+
requirements-ci.txt
2630
python-version: 3.8
2731

2832
- name: Install OpenBabel
@@ -32,14 +36,6 @@ jobs:
3236
# https://github.com/openbabel/openbabel/issues/2408#issuecomment-1014466193
3337
sudo ln -s /usr/include/openbabel3 /usr/local/include/openbabel3
3438
35-
- name: Cache pip
36-
uses: actions/cache@v2
37-
with:
38-
path: ~/.cache/pip
39-
key: ${{ runner.os }}-pip-${{ hashFiles('requirements-ci.txt', 'setup.py') }}
40-
restore-keys: |
41-
${{ runner.os }}-pip-
42-
4339
- name: Install dependencies
4440
run: |
4541
pip install -r requirements-ci.txt

.pre-commit-config.yaml

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,64 @@
1+
ci:
2+
autoupdate_schedule: quarterly
3+
skip: [mypy]
4+
5+
default_stages: [commit]
6+
7+
default_install_hook_types: [pre-commit, commit-msg]
8+
19
exclude: ^(docs/|.*test_files/|.*tests/)
210

311
repos:
412
- repo: https://github.com/myint/autoflake
513
rev: v1.4
614
hooks:
715
- id: autoflake
8-
args: [--in-place, --remove-all-unused-imports, --remove-unused-variable, --ignore-init-module-imports]
16+
args:
17+
- --in-place
18+
- --remove-unused-variables
19+
- --remove-all-unused-imports
20+
- --expand-star-imports
21+
- --ignore-init-module-imports
922

1023
- repo: https://github.com/psf/black
11-
rev: 22.1.0
24+
rev: 22.6.0
1225
hooks:
1326
- id: black
1427

15-
- repo: https://github.com/pycqa/flake8
16-
rev: 4.0.1
28+
- repo: https://github.com/PyCQA/flake8
29+
rev: 5.0.4
1730
hooks:
1831
- id: flake8
19-
args: [--max-line-length=125]
32+
33+
- repo: https://github.com/pre-commit/mirrors-mypy
34+
rev: v0.971
35+
hooks:
36+
- id: mypy
37+
additional_dependencies: [types-requests]
2038

2139
- repo: https://github.com/pre-commit/pre-commit-hooks
22-
rev: v4.1.0
40+
rev: v4.3.0
2341
hooks:
42+
- id: check-case-conflict
43+
- id: check-symlinks
2444
- id: check-yaml
45+
- id: destroyed-symlinks
2546
- id: end-of-file-fixer
47+
- id: mixed-line-ending
2648
- id: trailing-whitespace
2749

2850
- repo: https://github.com/asottile/pyupgrade
29-
rev: v2.31.0
51+
rev: v2.37.3
3052
hooks:
3153
- id: pyupgrade
3254
args: [--py38-plus]
3355

56+
- repo: https://github.com/codespell-project/codespell
57+
rev: v2.2.1
58+
hooks:
59+
- id: codespell
60+
stages: [commit, commit-msg]
61+
3462
- repo: https://github.com/PyCQA/isort
3563
rev: 5.10.1
3664
hooks:

atomate/feff/workflows/tests/test_eels_workflows.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@
1414

1515
module_dir = os.path.dirname(os.path.abspath(__file__))
1616
db_dir = os.path.join(module_dir, "..", "..", "..", "common", "test_files")
17-
DEBUG_MODE = (
18-
False # If true, retains the database and output dirs at the end of the test
19-
)
17+
# If DEBUG_MODE = true, retains the database and output dirs at the end of the test
18+
DEBUG_MODE = False
2019

2120

2221
class TestEELSWorkflow(AtomateTest):

atomate/feff/workflows/tests/test_exafs_scattering_paths.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ def test_feff_input_sets(self):
4141
"nkpts": 1000,
4242
"radius": 10.0,
4343
"user_tag_settings": {},
44-
"structure": self.struct.as_dict(),
4544
}
4645
ans_fis_fw2 = {
4746
"@class": "MPEXAFSSet",
@@ -51,13 +50,14 @@ def test_feff_input_sets(self):
5150
"nkpts": 1000,
5251
"radius": 10.0,
5352
"user_tag_settings": {"CONTROL": "0 0 0 0 1 1", "PRINT": "0 0 0 1 0 3"},
54-
"structure": self.struct.as_dict(),
5553
}
5654
fis_fw1 = self.fw1_dict["spec"]["_tasks"][0]["feff_input_set"]
5755
fis_fw2 = self.fw2_dict["spec"]["_tasks"][1]["feff_input_set"]
5856

5957
fis_fw1.pop("@version")
6058
fis_fw2.pop("@version")
59+
fis_fw1.pop("structure")
60+
fis_fw2.pop("structure")
6161

6262
self.assertDictEqual(fis_fw1, ans_fis_fw1)
6363
self.assertDictEqual(fis_fw2, ans_fis_fw2)

atomate/feff/workflows/tests/test_xas_workflows.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,8 @@
1616
module_dir = os.path.dirname(os.path.abspath(__file__))
1717
db_dir = os.path.join(module_dir, "..", "..", "..", "common", "test_files")
1818

19-
DEBUG_MODE = (
20-
False # If true, retains the database and output dirs at the end of the test
21-
)
19+
# If DEBUG_MODE = true, retains the database and output dirs at the end of the test
20+
DEBUG_MODE = False
2221
FEFF_CMD = None # "feff"
2322

2423

atomate/utils/testing.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,10 @@
1414
MODULE_DIR = os.path.dirname(os.path.abspath(__file__))
1515
DB_DIR = os.path.join(MODULE_DIR, "..", "common", "test_files")
1616

17-
DEBUG_MODE = (
18-
False # If true, retains the database and output dirs at the end of the test
19-
)
20-
VASP_CMD = (
21-
None # If None, runs a "fake" VASP. Otherwise, runs VASP with this command...
22-
)
17+
# If DEBUG_MODE = true, retains the database and output dirs at the end of the test
18+
DEBUG_MODE = False
19+
# If None, runs a "fake" VASP. Otherwise, runs VASP with this command...
20+
VASP_CMD = None
2321

2422

2523
class AtomateTest(unittest.TestCase):

atomate/vasp/analysis/linear_response.py

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -253,29 +253,32 @@ def det_deriv(matrix, i, j):
253253
jacobians = [[] for i in range(m)]
254254

255255
det = np.linalg.det(matrix)
256-
for i in range(m):
257-
for j in range(n):
258-
mji = np.delete(np.delete(matrix, j, 0), i, 1)
259-
minor = (-1) ** (i + j) * np.linalg.det(mji)
256+
for idx in range(m):
257+
for jdx in range(n):
258+
mji = np.delete(np.delete(matrix, jdx, 0), idx, 1)
259+
minor = (-1) ** (idx + jdx) * np.linalg.det(mji)
260260

261261
j_matrix = np.zeros([m, n])
262-
for k in range(m):
263-
for l in range(n):
264-
det_p = det_deriv(matrix, k, l)
262+
for kdx in range(m):
263+
for ldx in range(n):
264+
det_p = det_deriv(matrix, kdx, ldx)
265265

266-
if k == j or l == i:
266+
if kdx == jdx or ldx == idx:
267267
minor_p = 0.0
268268
else:
269-
kk, ll = k - 1 if k > j else k, l - 1 if l > i else l
270-
minor_p = (-1) ** (i + j) * det_deriv(mji, kk, ll)
269+
kk, ll = (
270+
kdx - 1 if kdx > jdx else kdx,
271+
ldx - 1 if ldx > idx else ldx,
272+
)
273+
minor_p = (-1) ** (idx + jdx) * det_deriv(mji, kk, ll)
271274

272-
j_matrix[k, l] = (minor_p * det - minor * det_p) / det**2
275+
j_matrix[kdx, ldx] = (minor_p * det - minor * det_p) / det**2
273276

274-
jacobians[i].append(j_matrix)
277+
jacobians[idx].append(j_matrix)
275278

276279
j_vec = np.reshape(j_matrix, [m * n, 1])
277280
sigma_f = np.sum(np.dot(np.transpose(j_vec), np.dot(matrix_covar, j_vec)))
278-
matrixinv_var[i, j] = sigma_f
281+
matrixinv_var[idx, jdx] = sigma_f
279282

280283
return matrixinv, matrixinv_var, jacobians
281284

atomate/vasp/firetasks/electrode_tasks.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import math
22

33
from fireworks import FiretaskBase, Firework, FWAction, Workflow, explicit_serialize
4-
from pymatgen.analysis.defects.utils import ChargeInsertionAnalyzer
54
from pymatgen.analysis.structure_matcher import StructureMatcher
65
from pymatgen.core import Structure
76

@@ -12,6 +11,15 @@
1211
from atomate.vasp.firetasks import pass_vasp_result
1312
from atomate.vasp.fireworks.core import OptimizeFW, StaticFW
1413

14+
try:
15+
from pymatgen.analysis.defects import ChargeInsertionAnalyzer
16+
except ImportError:
17+
print(
18+
"Failed to import ChargeInsertionAnalyzer. This is likely due to converting the pymatgen defects module "
19+
"to a namespace package. See https://github.com/materialsproject/pymatgen/pull/2582#issuecomment-1198318101 "
20+
"for updates."
21+
)
22+
1523
__author__ = "Jimmy Shen"
1624
__email__ = "[email protected]"
1725

@@ -21,7 +29,7 @@
2129
2230
Note:
2331
The workflow passes data to fw_spec extensively and requires specific fields in the spec to be updated.
24-
Example, the base_taks_id must be stored and the spec and updated as the workflow runs so you have to set
32+
Example, the base_task_id must be stored and the spec and updated as the workflow runs so you have to set
2533
```
2634
{
2735
"store_volumetric_data": vasptodb_kwargs_vol_data[volumetric_data_type],

atomate/vasp/firetasks/tests/test_polarization_to_db.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,8 @@
1515
DEBUG_MODE = (
1616
True # If true, retains the database and output dirs at the end of the test
1717
)
18-
VASP_CMD = (
19-
None # If None, runs a "fake" VASP. Otherwise, runs VASP with this command...
20-
)
18+
# If None, runs a "fake" VASP. Otherwise, runs VASP with this command...
19+
VASP_CMD = None
2120

2221

2322
class TestFerroelectricWorkflow(AtomateTest):

atomate/vasp/firetasks/tests/test_write_vasp.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ def setUpClass(cls):
3636

3737
def setUp(self):
3838
super().setUp(lpad=False)
39+
self.maxDiff = None
3940

4041
def tearDown(self):
4142
for x in ["INCAR", "POSCAR", "POTCAR", "KPOINTS", "POTCAR.spec"]:
@@ -50,7 +51,10 @@ def _verify_files(
5051
self.assertEqual(Incar.from_file("INCAR"), self.ref_incar)
5152

5253
poscar = Poscar.from_file("POSCAR")
53-
self.assertEqual(str(poscar), str(self.ref_poscar))
54+
self.assertEqual(
55+
poscar.get_string(significant_figures=4),
56+
self.ref_poscar.get_string(significant_figures=4),
57+
)
5458

5559
if potcar_spec:
5660
symbols = Path("POTCAR.spec").read_text().split()

0 commit comments

Comments
 (0)