|
15 | 15 | energy_convert = EnergyConversion("hartree", "eV").value() |
16 | 16 | force_convert = ForceConversion("hartree/bohr", "eV/angstrom").value() |
17 | 17 |
|
| 18 | +import warnings |
18 | 19 | from collections import OrderedDict |
19 | 20 |
|
20 | 21 | ### iterout.c from OpenMX soure code: column numbers and physical quantities ### |
|
28 | 29 | # /* 12: magnetic moment (muB) */ |
29 | 30 | # /* 13,14: angles of spin */ |
30 | 31 |
|
| 32 | +# 15: scf_convergence_flag (optional) |
| 33 | +# |
| 34 | +# 1. Move the declaration of `scf_convergence_flag` in `DFT.c` to `openmx_common.h`. |
| 35 | +# 2. Add `scf_convergence_flag` output to the end of `iterout.c` where `*.md` is written. |
| 36 | +# 3. Recompile OpenMX. |
| 37 | + |
31 | 38 |
|
32 | 39 | def load_atom(lines): |
33 | 40 | atom_names = [] |
@@ -70,9 +77,18 @@ def load_cells(lines): |
70 | 77 | for index, line in enumerate(lines): |
71 | 78 | if "Cell_Vectors=" in line: |
72 | 79 | parts = line.split() |
73 | | - cell.append([float(parts[12]), float(parts[13]), float(parts[14])]) |
74 | | - cell.append([float(parts[15]), float(parts[16]), float(parts[17])]) |
75 | | - cell.append([float(parts[18]), float(parts[19]), float(parts[20])]) |
| 80 | + if len(parts) == 21: # MD.Type is NVT_NH |
| 81 | + cell.append([float(parts[12]), float(parts[13]), float(parts[14])]) |
| 82 | + cell.append([float(parts[15]), float(parts[16]), float(parts[17])]) |
| 83 | + cell.append([float(parts[18]), float(parts[19]), float(parts[20])]) |
| 84 | + elif len(parts) == 16: # MD.Type is Opt |
| 85 | + cell.append([float(parts[7]), float(parts[8]), float(parts[9])]) |
| 86 | + cell.append([float(parts[10]), float(parts[11]), float(parts[12])]) |
| 87 | + cell.append([float(parts[13]), float(parts[14]), float(parts[15])]) |
| 88 | + else: |
| 89 | + raise RuntimeError( |
| 90 | + "Does the file System.Name.md contain unsupported calculation results?" |
| 91 | + ) |
76 | 92 | cells.append(cell) |
77 | 93 | cell = [] |
78 | 94 | cells = np.array(cells) |
@@ -104,6 +120,9 @@ def load_coords(lines, atom_names, natoms): |
104 | 120 | parts = line.split() |
105 | 121 | for_line = [float(parts[1]), float(parts[2]), float(parts[3])] |
106 | 122 | coord.append(for_line) |
| 123 | + # It may be necessary to recompile OpenMX to make scf convergence determination. |
| 124 | + if len(parts) == 15 and parts[14] == "0": |
| 125 | + warnings.warn("SCF in System.Name.md has not converged!") |
107 | 126 | if cnt == natoms: |
108 | 127 | coords.append(coord) |
109 | 128 | cnt = 0 |
|
0 commit comments