|
1 | 1 | from __future__ import annotations |
2 | 2 |
|
3 | | -import os, glob |
| 3 | +import glob |
| 4 | +import os |
4 | 5 |
|
5 | 6 | import numpy as np |
6 | 7 |
|
@@ -30,15 +31,17 @@ def get_log_file(fname, inlines): |
30 | 31 | logf = os.path.join(fname, f"OUT.{suffix}/running_{calculation}.log") |
31 | 32 | return logf |
32 | 33 |
|
| 34 | + |
33 | 35 | def get_relax_stru_files(output_dir): |
34 | 36 | """Find the STRU files in the output directory. |
35 | 37 |
|
36 | 38 | Args: |
37 | 39 | output_dir (str): output directory |
38 | | - |
39 | | - returns: |
| 40 | +
|
| 41 | + Returns |
| 42 | + ------- |
40 | 43 | strus: list of STRU files |
41 | | - |
| 44 | +
|
42 | 45 | example: |
43 | 46 | ["STRU_ION1_D", "STRU_ION2_D"] |
44 | 47 | """ |
@@ -120,19 +123,20 @@ def get_coords_from_log(loglines, natoms, stru_files=[]): |
120 | 123 | # we should read cell and coord from STRU_ION*_D files |
121 | 124 | if len(energy) > 1 and len(coords) == 1: |
122 | 125 | # the energies of all structrues are collected, but coords have only the first structure |
123 | | - if len(stru_files) > 1: # if stru_files are not only STRU_ION_D |
| 126 | + if len(stru_files) > 1: # if stru_files are not only STRU_ION_D |
124 | 127 | stru_file_name = [os.path.basename(i) for i in stru_files] |
125 | | - coords = coords[:1] + [np.nan for i in range(len(energy)-1)] |
126 | | - coord_direct = coord_direct[:1] + [False for i in range(len(energy)-1)] |
127 | | - cells = cells[:1] + [np.nan for i in range(len(energy)-1)] |
| 128 | + coords = coords[:1] + [np.nan for i in range(len(energy) - 1)] |
| 129 | + coord_direct = coord_direct[:1] + [False for i in range(len(energy) - 1)] |
| 130 | + cells = cells[:1] + [np.nan for i in range(len(energy) - 1)] |
128 | 131 | for iframe in range(1, len(energy)): |
129 | 132 | if f"STRU_ION{iframe}_D" in stru_file_name: |
130 | 133 | # read the structure from STRU_ION*_D |
131 | | - stru_data = get_frame_from_stru(stru_files[stru_file_name.index(f"STRU_ION{iframe}_D")]) |
| 134 | + stru_data = get_frame_from_stru( |
| 135 | + stru_files[stru_file_name.index(f"STRU_ION{iframe}_D")] |
| 136 | + ) |
132 | 137 | coords[iframe] = stru_data["coords"][0] |
133 | 138 | cells[iframe] = stru_data["cells"][0] |
134 | 139 |
|
135 | | - |
136 | 140 | force = collect_force(loglines) |
137 | 141 | stress = collect_stress(loglines) |
138 | 142 |
|
@@ -165,7 +169,11 @@ def get_coords_from_log(loglines, natoms, stru_files=[]): |
165 | 169 |
|
166 | 170 | # delete structures whose energy is np.nan |
167 | 171 | for i in range(minl): |
168 | | - if np.isnan(energy[i - minl]) or np.any(np.isnan(coords[i - minl])) or np.any(np.isnan(cells[i - minl])): |
| 172 | + if ( |
| 173 | + np.isnan(energy[i - minl]) |
| 174 | + or np.any(np.isnan(coords[i - minl])) |
| 175 | + or np.any(np.isnan(cells[i - minl])) |
| 176 | + ): |
169 | 177 | del energy[i - minl] |
170 | 178 | del coords[i - minl] |
171 | 179 | del cells[i - minl] |
@@ -225,8 +233,9 @@ def get_frame(fname): |
225 | 233 |
|
226 | 234 | relax_stru_files = get_relax_stru_files(os.path.dirname(logf)) |
227 | 235 |
|
228 | | - energy, cells, coords, force, stress, virial = get_coords_from_log(lines, natoms, stru_files=relax_stru_files) |
229 | | - |
| 236 | + energy, cells, coords, force, stress, virial = get_coords_from_log( |
| 237 | + lines, natoms, stru_files=relax_stru_files |
| 238 | + ) |
230 | 239 |
|
231 | 240 | magmom, magforce = get_mag_force(lines) |
232 | 241 |
|
|
0 commit comments