1
1
from __future__ import annotations
2
2
3
- import os
4
3
import unittest
5
4
from shutil import which
6
5
21
20
@unittest .skipIf (not which ("critic2" ), "critic2 executable not present" )
22
21
class TestCritic2Caller (unittest .TestCase ):
23
22
def test_from_path (self ):
24
- # uses chgcars
25
- test_dir = f"{ TEST_FILES_DIR } /bader"
26
-
27
- c2c = Critic2Caller .from_path (test_dir )
23
+ # uses CHGCARs
24
+ c2c = Critic2Caller .from_path (f"{ TEST_FILES_DIR } /bader" )
28
25
29
26
# check we have some results!
30
27
assert len (c2c ._stdout ) >= 500
@@ -51,36 +48,39 @@ def test_from_path(self):
51
48
52
49
# alternatively, can also set when we do the analysis, but note that this will change
53
50
# the analysis performed since augmentation charges are added in core regions
54
- c2c = Critic2Caller .from_path (test_dir , zpsp = {"Fe" : 8.0 , "O" : 6.0 })
51
+ c2c = Critic2Caller .from_path (f" { TEST_FILES_DIR } /bader" , zpsp = {"Fe" : 8.0 , "O" : 6.0 })
55
52
56
53
# check yt integration
57
54
assert c2o .structure .site_properties ["bader_volume" ][0 ] == approx (66.0148355 )
58
55
assert c2o .structure .site_properties ["bader_charge" ][0 ] == approx (12.2229131 )
59
56
assert c2o .structure .site_properties ["bader_charge_transfer" ][0 ] == approx (4.2229131 )
60
57
61
58
def test_from_structure (self ):
62
- # uses promolecular density
63
- structure = Structure .from_file (
64
- os .path .join (
65
- TEST_FILES_DIR ,
66
- "critic2/MoS2.cif" ,
67
- )
68
- )
59
+ # uses pro-molecular density
60
+ structure = Structure .from_file (f"{ TEST_FILES_DIR } /critic2/MoS2.cif" )
69
61
70
62
c2c = Critic2Caller .from_chgcar (structure )
71
63
72
64
# check we have some results!
73
65
assert len (c2c ._stdout ) >= 500
74
66
67
+ # test with chgcar and zpsp to ensure zval is formatted as int
68
+ # https://github.com/materialsproject/pymatgen/issues/3501
69
+ c2c = Critic2Caller .from_chgcar (
70
+ structure , zpsp = {"Mo" : 6.0 , "S" : 6.0 }, chgcar = f"{ TEST_FILES_DIR } /bader/CHGCAR.gz"
71
+ )
72
+
73
+ assert "ERROR : load int.CHGCAR id chg_int zpsp Mo 6 S 6" in c2c ._input_script
74
+
75
75
76
76
class TestCritic2Analysis (unittest .TestCase ):
77
77
def setUp (self ):
78
78
stdout_file = f"{ TEST_FILES_DIR } /critic2/MoS2_critic2_stdout.txt"
79
79
stdout_file_new_format = f"{ TEST_FILES_DIR } /critic2/MoS2_critic2_stdout_new_format.txt"
80
- with open (stdout_file ) as f :
81
- reference_stdout = f .read ()
82
- with open (stdout_file_new_format ) as f :
83
- reference_stdout_new_format = f .read ()
80
+ with open (stdout_file ) as file :
81
+ reference_stdout = file .read ()
82
+ with open (stdout_file_new_format ) as file :
83
+ reference_stdout_new_format = file .read ()
84
84
85
85
structure = Structure .from_file (f"{ TEST_FILES_DIR } /critic2/MoS2.cif" )
86
86
0 commit comments