5
5
import warnings
6
6
from typing import TYPE_CHECKING
7
7
8
- from monty .io import reverse_readfile
8
+ from monty .io import zopen
9
9
from monty .os .path import zpath
10
10
from pymatgen .io .vasp .outputs import Oszicar , Vasprun
11
11
@@ -58,13 +58,11 @@ def parse_vasp_dir(
58
58
exception_on_bad_xml = False ,
59
59
)
60
60
61
- charge , mag_x , mag_y , mag_z , header , all_lines = [], [], [], [], [], []
61
+ charge , mag_x , mag_y , mag_z , header = [], [], [], [], []
62
62
63
- for line in reverse_readfile (outcar_path ):
64
- clean = line .strip ()
65
- all_lines .append (clean )
63
+ with zopen (outcar_path , encoding = "utf-8" ) as file :
64
+ all_lines = [line .strip () for line in file .readlines ()]
66
65
67
- all_lines .reverse ()
68
66
# For single atom systems, VASP doesn't print a total line, so
69
67
# reverse parsing is very difficult
70
68
# for SOC calculations only
@@ -79,23 +77,21 @@ def parse_vasp_dir(
79
77
if clean .startswith ("# of ion" ):
80
78
header = re .split (r"\s{2,}" , clean .strip ())
81
79
header .pop (0 )
82
- else :
83
- m = re .match (r"\s*(\d+)\s+(([\d\.\-]+)\s+)+" , clean )
84
- if m :
85
- tokens = [float (token ) for token in re .findall (r"[\d\.\-]+" , clean )]
86
- tokens .pop (0 )
87
- if read_charge :
88
- charge .append (dict (zip (header , tokens )))
89
- elif read_mag_x :
90
- mag_x .append (dict (zip (header , tokens )))
91
- elif read_mag_y :
92
- mag_y .append (dict (zip (header , tokens )))
93
- elif read_mag_z :
94
- mag_z .append (dict (zip (header , tokens )))
95
- elif clean .startswith ("tot" ):
96
- if ion_step_count == (len (mag_x_all ) + 1 ):
97
- mag_x_all .append (mag_x )
98
- read_charge = read_mag_x = read_mag_y = read_mag_z = False
80
+ elif re .match (r"\s*(\d+)\s+(([\d\.\-]+)\s+)+" , clean ):
81
+ tokens = [float (token ) for token in re .findall (r"[\d\.\-]+" , clean )]
82
+ tokens .pop (0 )
83
+ if read_charge :
84
+ charge .append (dict (zip (header , tokens , strict = True )))
85
+ elif read_mag_x :
86
+ mag_x .append (dict (zip (header , tokens , strict = True )))
87
+ elif read_mag_y :
88
+ mag_y .append (dict (zip (header , tokens , strict = True )))
89
+ elif read_mag_z :
90
+ mag_z .append (dict (zip (header , tokens , strict = True )))
91
+ elif clean .startswith ("tot" ):
92
+ if ion_step_count == (len (mag_x_all ) + 1 ):
93
+ mag_x_all .append (mag_x )
94
+ read_charge = read_mag_x = read_mag_y = read_mag_z = False
99
95
if clean == "total charge" :
100
96
read_charge = True
101
97
read_mag_x = read_mag_y = read_mag_z = False
0 commit comments