Skip to content

Commit 25fc6c0

Browse files
committed
update print
1 parent c784579 commit 25fc6c0

2 files changed

Lines changed: 40 additions & 26 deletions

File tree

src/mdapy/md_elastic.py

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -125,16 +125,19 @@ def print(self) -> None:
125125
c11, c12, c44 = self.cubic_average()
126126
K, G = (c11 + 2 * c12) / 3.0, (c11 - c12 + 3 * c44) / 5.0
127127
E = 9 * K * G / (3 * K + G) if (3 * K + G) > 0 else 0.0
128-
print(f"MDElastic @ T={self.temperature:.0f} K ({self.ensemble}):")
129-
print(f" V_eq = {self.V_eq:.3f} A^3")
130-
print(f" T_actual = {self.T_actual:.1f} K")
131-
print(f" reference sigma= {np.array2string(self.stress_ref, precision=3)} GPa")
132-
print(f" C11 (cubic avg)= {c11:.2f} GPa")
133-
print(f" C12 (cubic avg)= {c12:.2f} GPa")
134-
print(f" C44 (cubic avg)= {c44:.2f} GPa")
135-
print(f" K (V) = {K:.2f} GPa")
136-
print(f" G (V) = {G:.2f} GPa")
137-
print(f" E = {E:.2f} GPa")
128+
lines = [
129+
f"MDElastic @ T={self.temperature:.0f} K ({self.ensemble}):",
130+
f" V_eq = {self.V_eq:.3f} A^3",
131+
f" T_actual = {self.T_actual:.1f} K",
132+
f" reference sigma= {np.array2string(self.stress_ref, precision=3)} GPa",
133+
f" C11 (cubic avg)= {c11:.2f} GPa",
134+
f" C12 (cubic avg)= {c12:.2f} GPa",
135+
f" C44 (cubic avg)= {c44:.2f} GPa",
136+
f" K (V) = {K:.2f} GPa",
137+
f" G (V) = {G:.2f} GPa",
138+
f" E = {E:.2f} GPa",
139+
]
140+
print("\n".join(lines), flush=True)
138141

139142

140143
# ============================================================
@@ -766,7 +769,8 @@ def scan_parallel(
766769
if not quiet:
767770
print(
768771
f"[MDElastic.scan_parallel] phase 1: {len(ref_tasks)} ref runs "
769-
f"on {n_workers_ref} workers x {n_threads_ref} threads ..."
772+
f"on {n_workers_ref} workers x {n_threads_ref} threads ...",
773+
flush=True,
770774
)
771775
ctx = _mp.get_context("spawn")
772776
with ProcessPoolExecutor(max_workers=n_workers_ref, mp_context=ctx) as ex:
@@ -783,7 +787,8 @@ def scan_parallel(
783787
if not quiet:
784788
print(
785789
f"[MDElastic.scan_parallel] phase 2: {len(deform_tasks)} deformation "
786-
f"runs on {n_workers_def} workers x {n_threads_def} threads ..."
790+
f"runs on {n_workers_def} workers x {n_threads_def} threads ...",
791+
flush=True,
787792
)
788793
with ProcessPoolExecutor(max_workers=n_workers_def, mp_context=ctx) as ex:
789794
def_results = list(ex.map(_run_deform_segment, deform_tasks))
@@ -1074,7 +1079,8 @@ def _execute_single(self) -> MDElasticResult:
10741079
if not self.quiet:
10751080
print(
10761081
f"[MDElastic] T={self.temperature} K reference "
1077-
f"({self.thermostat}, ensemble={self.ensemble}) ..."
1082+
f"({self.thermostat}, ensemble={self.ensemble}) ...",
1083+
flush=True,
10781084
)
10791085
ref = _run_reference_segment(self._build_reference_args())
10801086

@@ -1088,7 +1094,8 @@ def _execute_single(self) -> MDElasticResult:
10881094
if not self.quiet:
10891095
print(
10901096
f"[MDElastic] T={self.temperature} K: "
1091-
f"{len(deform_args)} deformations on {n_w} workers ..."
1097+
f"{len(deform_args)} deformations on {n_w} workers ...",
1098+
flush=True,
10921099
)
10931100
if n_w > 1:
10941101
ctx = _mp.get_context("spawn")

src/mdapy/qha_elastic.py

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,8 @@ def _build_grid(self) -> None:
609609
f"crystal_class={self.crystal_class}, "
610610
f"force_constants={self.force_constants_method}, "
611611
f"supercell={self.supercell}, "
612-
f"V0={self._ref_volume:.3f} A^3"
612+
f"V0={self._ref_volume:.3f} A^3",
613+
flush=True,
613614
)
614615

615616
# ----------------------------------------------------------
@@ -648,7 +649,8 @@ def run(self) -> None:
648649
f"[QHAElastic] run {k + 1}/{len(self.unique_cells)}: "
649650
f"V_strain={uc['V_strain']:+.3f}, "
650651
f"E_static={uc['E_static']:.4f} eV, "
651-
f"n_disp={uc['n_disp']}"
652+
f"n_disp={uc['n_disp']}",
653+
flush=True,
652654
)
653655

654656
# ----------------------------------------------------------
@@ -761,13 +763,15 @@ def export_inputs(self, root: Union[str, os.PathLike]) -> None:
761763
f"[QHAElastic] exported {len(self.unique_cells)} POSCAR files "
762764
f"to {root}/. Run VASP DFPT (IBRION=8) on each, drop "
763765
f"vasprun.xml back into the same directory, then call "
764-
f"qha.import_results({root!r})."
766+
f"qha.import_results({root!r}).",
767+
flush=True,
765768
)
766769
else:
767770
print(
768771
f"[QHAElastic] exported {len(self.unique_cells)} unique unitcells "
769772
f"to {root}/. Run VASP static SCF in each */static and each "
770-
f"*/disp-NNN subdirectory."
773+
f"*/disp-NNN subdirectory.",
774+
flush=True,
771775
)
772776

773777
def import_results(self, root: Union[str, os.PathLike]) -> None:
@@ -840,7 +844,10 @@ def import_results(self, root: Union[str, os.PathLike]) -> None:
840844
uc["phonon"].produce_force_constants(show_drift=False)
841845

842846
if not self.quiet:
843-
print(f"[QHAElastic] imported {len(self.unique_cells)} VASP results.")
847+
print(
848+
f"[QHAElastic] imported {len(self.unique_cells)} VASP results.",
849+
flush=True,
850+
)
844851

845852
# ----------------------------------------------------------
846853
# Post-processing
@@ -1438,20 +1445,20 @@ def _read_dfpt_force_constants(vasprun: Path) -> np.ndarray:
14381445
# unit.calc = nep
14391446
# fy = FIRE(unit, optimize_cell=True, hydrostatic_strain=True)
14401447
# assert fy.run(fmax=1e-4, steps=1000, show_process=False)
1448+
calc = NEP("compare_qha_md/nep_gen400000.txt")
14411449
unit = System("compare_qha_md/Ni.POSCAR")
14421450
qha_dft = QHAElastic(
14431451
unit,
1444-
calc=unit.calc,
14451452
t_min=0,
14461453
t_max=1000,
14471454
t_step=100,
14481455
volume_strains=(-0.06, -0.03, 0.0, 0.03, 0.06),
1449-
strain_values=(-0.02, -0.01, 0.0, 0.01, 0.02),
1456+
strain_values=(-0.02, 0.0, 0.02),
14501457
supercell=(2, 2, 2),
14511458
mesh=(10, 10, 10),
14521459
)
1453-
qha_dft.export_inputs("compare_qha_md/dft_out_new")
1454-
# qha_dft.import_results("compare_qha_md/dft_out")
1455-
# df = qha_dft.compute()
1456-
# qha_dft.plot()
1457-
# plt.show()
1460+
# qha_dft.export_inputs("compare_qha_md/nospin")
1461+
qha_dft.import_results("compare_qha_md/nospin")
1462+
df = qha_dft.compute()
1463+
qha_dft.plot()
1464+
plt.show()

0 commit comments

Comments
 (0)