9898 __SCHA_T__ ]
9999
100100__MAX_DIAG_ERROR_COUNTER__ = 5
101+ __MAX_IMAG_ERROR_COUNTER__ = 50
101102
102103class 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]
0 commit comments