Skip to content

Commit 0b68c9d

Browse files
committed
A GOOD PRINTING
=============== This commit introduces the good printing of everything after the line minimization has been introduced. Now it only stores the steps found good by the algorithm. Moreover it also corrects the stress sign when the ensemble is loaded with load_from_calculator_output
1 parent 7210924 commit 0b68c9d

3 files changed

Lines changed: 40 additions & 31 deletions

File tree

Modules/Ensemble.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,7 @@ def load_from_calculator_output(self, directory, out_ext = ".pwo"):
618618

619619
# Get the stress if any
620620
try:
621-
stress = ase_struct.get_stress(voigt=False)
621+
stress = - ase_struct.get_stress(voigt=False)
622622
# eV/A^3 -> Ry/bohr^3
623623
stress /= Rydberg / Bohr**3
624624
count_stress += 1

Modules/SchaMinimizer.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ def __init__(self, ensemble = None, root_representation = "normal",
231231
self.__gw__ = []
232232
self.__gw_err__ = []
233233
self.__KL__ = []
234+
self.__good_kasteps__ = []
234235

235236

236237

@@ -554,6 +555,10 @@ def minimization_step(self, custom_function_gradient = None):
554555

555556
# Update the previous gradient
556557
self.prev_grad = dyn_grad
558+
559+
# If the step is good, pass chose it
560+
if self.minimizer.new_direction:
561+
self.__good_kasteps__.append(len(self.__fe__) - 1)
557562

558563
def setup_from_namelist(self, input_file):
559564
"""
@@ -1483,18 +1488,18 @@ def plot_results(self, save_filename = None, plot = True):
14831488

14841489
self.__gc__.append(self.__gc__[-1])
14851490
self.__gc_err__.append(self.__gc_err__[-1])
1491+
1492+
fe = np.array(self.__fe__)[self.__good_kasteps__] * __RyTomev__
1493+
fe_err = np.array(self.__fe_err__)[self.__good_kasteps__] * __RyTomev__
14861494

1487-
# Convert the data in numpy arrays
1488-
fe = np.array(self.__fe__) * __RyTomev__
1489-
fe_err = np.array(self.__fe_err__) * __RyTomev__
14901495

1491-
gc = np.array(self.__gc__) * __RyTomev__
1492-
gc_err = np.array(self.__gc_err__) * __RyTomev__
1496+
gc = np.array(self.__gc__)[self.__good_kasteps__] * __RyTomev__
1497+
gc_err = np.array(self.__gc_err__)[self.__good_kasteps__] * __RyTomev__
14931498

1494-
gw = np.array(self.__gw__) * __RyTomev__
1495-
gw_err = np.array(self.__gw_err__) * __RyTomev__
1499+
gw = np.array(self.__gw__)[self.__good_kasteps__] * __RyTomev__
1500+
gw_err = np.array(self.__gw_err__)[self.__good_kasteps__] * __RyTomev__
14961501

1497-
kl = np.array(self.__KL__, dtype = np.float64)
1502+
kl = np.array(self.__KL__, dtype = np.float64)[self.__good_kasteps__]
14981503

14991504
steps = np.arange(len(fe))
15001505

@@ -1507,6 +1512,7 @@ def plot_results(self, save_filename = None, plot = True):
15071512
np.savetxt(save_filename, np.real(np.transpose(save_data)),
15081513
header = "Steps; Free energy +- error [meV]; FC gradient +- error [bohr^2]; Structure gradient +- error [meV / A]; Kong-Liu N_eff")
15091514
print ("Minimization data saved in %s." % save_filename)
1515+
print('Good steps at {}'.format(self.__good_kasteps__))
15101516

15111517

15121518
# Plot

Modules/Utilities.py

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -546,39 +546,42 @@ def CFP_SaveAll(self, minim):
546546

547547
if not sscha.Parallel.am_i_the_master():
548548
return
549-
550-
# Get the weights if required
551-
if self.save_weights:
552-
self.weights.append(minim.ensemble.rho[:])
549+
550+
if minim.minimizer.new_direction:
553551

554-
if self.save_dynmats:
555-
minim.dyn.save_qe(self.save_dyn_prefix + "_ka%05d_" % self.ka)
556-
557-
if self.save_atomic_positions:
558-
self.current_struct = minim.dyn.structure.copy()
552+
# Get the weights if required
553+
if self.save_weights:
554+
self.weights.append(minim.ensemble.rho[:])
555+
556+
if self.save_dynmats:
557+
minim.dyn.save_qe(self.save_dyn_prefix + "_ka%05d_" % self.ka)
559558

560-
# This perform also the saving
561-
self.CFP_SaveFrequencies(minim)
562-
563-
# Update the step
564-
self.ka += 1
559+
if self.save_atomic_positions:
560+
self.current_struct = minim.dyn.structure.copy()
561+
562+
# This perform also the saving
563+
self.CFP_SaveFrequencies(minim)
564+
565+
# Update the step
566+
self.ka += 1
565567

566568

567569
def CFP_SaveFrequencies(self, minim):
568570
"""
569571
This custom method stores the total frequencies updating an exeternal file
570572
"""
571573

572-
# Generate the supercell in real space
573-
dyn_sc = minim.dyn.GenerateSupercellDyn( minim.ensemble.supercell )
574+
# Generate the supercell in real space (Do it only if the frequency changes)
575+
if minim.minimizer.new_direction:
576+
dyn_sc = minim.dyn.GenerateSupercellDyn( minim.ensemble.supercell )
574577

575-
# Dyagonalize
576-
w, pols = dyn_sc.DyagDinQ(0)
577-
self.total_freqs.append(w)
578-
578+
# Dyagonalize
579+
w, pols = dyn_sc.DyagDinQ(0)
580+
self.total_freqs.append(w)
581+
579582

580-
if self.__save_each_step:
581-
self.Save()
583+
if self.__save_each_step:
584+
self.Save()
582585

583586

584587

0 commit comments

Comments
 (0)