Skip to content

Commit ece36a4

Browse files
committed
I do not remember
1 parent bca68d7 commit ece36a4

3 files changed

Lines changed: 58 additions & 3 deletions

File tree

Modules/Ensemble.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,9 @@ def __init__(self, dyn0, T0, supercell = None):
172172
self.force_computed = None
173173
self.stress_computed = None
174174

175+
# Get the extra quantities
176+
self.extra_quantities = {}
177+
175178
def convert_units(self, new_units):
176179
"""
177180
CONVERT ALL THE VARIABLE IN A COHERENT UNIT OF MEASUREMENTS

Modules/SchaMinimizer.py

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@
9898
__SCHA_T__]
9999

100100
__MAX_DIAG_ERROR_COUNTER__ = 5
101+
__MAX_IMAG_ERROR_COUNTER__ = 50
101102

102103
class SSCHA_Minimizer(object):
103104

@@ -161,6 +162,7 @@ def __init__(self, ensemble = None, root_representation = "normal",
161162
self.minimizer = None#
162163

163164
self.max_diag_error_counter = __MAX_DIAG_ERROR_COUNTER__
165+
self.max_imag_freq_counter = __MAX_IMAG_ERROR_COUNTER__
164166

165167
# Projection. This is chosen to fix some constraint on the minimization
166168
self.projector_dyn = None
@@ -263,6 +265,17 @@ def __setattr__(self, name, value):
263265
raise ValueError("Error, the step attribute {} must be positive ({} given)".format(name, value))
264266

265267

268+
def set_minimization_step(self, step):
269+
"""
270+
Set an uniform minimization step for both the dynamical matrix and the structure minimization.
271+
272+
Try to always use this function unless you specifically want two difference speed between the structure and the dynamical matrix minimization.
273+
"""
274+
275+
self.min_step_dyn = step
276+
self.min_step_struc = step
277+
278+
266279
def set_ensemble(self, ensemble):
267280
"""Provide an ensemble to the minimizer object"""
268281

@@ -445,6 +458,7 @@ def minimization_step(self, custom_function_gradient = None):
445458
# Here a cycle to avoid diagonalization issues
446459
is_diag_ok = False
447460
diag_error_counter = 0
461+
imag_freq_counter = 0
448462
while not is_diag_ok:
449463
is_diag_ok = True
450464
self.minimizer.update_dyn(new_kl_ratio, dyn_grad, struct_grad)
@@ -476,7 +490,7 @@ def minimization_step(self, custom_function_gradient = None):
476490
print("Immaginary frequencies found! Redoing the step.")
477491
new_kl_ratio = 0
478492
is_diag_ok = False
479-
diag_error_counter += 1
493+
imag_freq_counter += 1
480494
else:
481495
# Update the ensemble
482496
try:
@@ -491,18 +505,34 @@ def minimization_step(self, custom_function_gradient = None):
491505

492506
if diag_error_counter >= self.max_diag_error_counter:
493507
ERROR_MSG = """
494-
Error, exceeded the maximum number of diagonalization error. (or imaginary steps)
508+
Error, exceeded the maximum number of diagonalization error.
495509
496510
you can get rid of this error by increasing max_diag_error_counter variable.
497511
498-
Something is very wrong with the dynamical matrix.
512+
Something is very wrong with the dynamical matrix.self.minimizer
499513
I'm saving the dynamical matrix as error_dyn,
500514
if you want to check it or restart the calculation from there.
501515
"""
502516
print(ERROR_MSG)
503517
sys.stdout.flush()
504518
self.dyn.save_qe("error_dyn")
505519
raise ValueError(ERROR_MSG)
520+
elif imag_freq_counter >= self.max_imag_freq_counter:
521+
ERROR_MSG = """
522+
Error, exceeded the maximum number of step with an imaginary frequency ({}).
523+
it is possible that something wrong is happening with the original dynamical matrix.
524+
This error may be caused by a wrong imposition of acoustic sum rule or
525+
the presence of 0 frequency modes.
526+
527+
Final dynamical matrix saved into error_dyn.
528+
529+
If you believe this is not a problem, you can try to increase max_imag_freq_counter
530+
from the '{}' object or reduce the 'min_step_dyn'
531+
""".format(self.max_imag_freq_counter, self.__class__.__name__)
532+
print(ERROR_MSG)
533+
sys.stdout.flush()
534+
self.dyn.save_qe("error_dyn")
535+
raise ValueError(ERROR_MSG)
506536

507537

508538
# Save the ensemble [TODO: IT IS DEBUG]

Modules/Utilities.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,10 @@ def __init__(self):
450450

451451
self.total_freqs = []
452452
self.__save_fname = None
453+
self.__save_atoms_fname = None
454+
self.save_atomic_positions = False
453455
self.__save_each_step = False
456+
self.current_struct = None
454457

455458
def Reset(self):
456459
"""
@@ -473,6 +476,16 @@ def SetupWeights(self, fname, save_each_step = True):
473476
self.save_weights = True
474477
self.__save_each_step = save_each_step
475478

479+
def SetupAtomicPositions(self, fname, save_each_step = True):
480+
"""
481+
Setup the saving of the data on atomic position along with the minimization
482+
"""
483+
484+
self.__save_atoms_fname = fname
485+
self.save_atomic_positions = True
486+
self.__save_each_step = save_each_step
487+
488+
476489
def SetupSaving(self, fname, save_each_step = True):
477490
"""
478491
Setup the system to save the data each time the function is called.
@@ -513,6 +526,12 @@ def Save(self, fname= None):
513526

514527
if self.save_weights:
515528
np.savetxt(self.weights_file, np.transpose(self.weights), header = "Each row is a step containing all the weights of the configurations")
529+
530+
if self.save_atomic_positions:
531+
text = self.current_struct.save_scf(filename = None, get_text = True)
532+
with open(self.__save_atoms_fname, "a") as fp:
533+
fp.write(text)
534+
516535

517536

518537
def CFP_SaveAll(self, minim):
@@ -532,6 +551,9 @@ def CFP_SaveAll(self, minim):
532551

533552
if self.save_dynmats:
534553
minim.dyn.save_qe(self.save_dyn_prefix + "_ka%05d_" % self.ka)
554+
555+
if self.save_atomic_positions:
556+
self.current_struct = minim.dyn.structure.copy()
535557

536558
# This perform also the saving
537559
self.CFP_SaveFrequencies(minim)

0 commit comments

Comments
 (0)