@@ -407,18 +407,27 @@ def run(self, geom_num_list, B_g, pre_B_g=[], pre_geom=[], B_e=0.0, pre_B_e=0.0,
407407 # More efficient projection matrix construction for multiple roots
408408 P = np .eye (gradient .size )
409409 root_num = 0
410- i = 0
411- while root_num < len (self .roots ):
412- if np .abs (eigvals [i ]) > 1e-10 :
413- # Extract the eigenvector once
414- trans_vec = eigvecs [:, i ]
415- # Use inplace operation to update P (avoid new allocation)
416- if self .NEB_mode :
417- P -= np .outer (trans_vec , trans_vec )
418- else :
419- P -= 2 * np .outer (trans_vec , trans_vec )
420- root_num += 1
421- i += 1
410+
411+ try :
412+ for i in range (len (eigvals )):
413+ if root_num >= len (self .roots ):
414+ break
415+ if np .abs (eigvals [i ]) > 1e-10 :
416+ trans_vec = eigvecs [:, i ]
417+ if self .NEB_mode :
418+ P -= np .outer (trans_vec , trans_vec )
419+ else :
420+ P -= 2 * np .outer (trans_vec , trans_vec )
421+ root_num += 1
422+
423+ if root_num < len (self .roots ):
424+ raise ValueError ("Not enough valid eigenvectors." )
425+
426+ except (ValueError , IndexError ) as e :
427+ self .log (f"Projection Error: { str (e )} " , force = True )
428+ self .log ("Falling back to identity projection (Steepest Descent)." , force = True )
429+ P = np .eye (gradient .size )
430+
422431 # Create the image Hessian H_star and image gradient grad_star
423432 H_star = np .dot (P , H )
424433 H_star = 0.5 * (H_star + H_star .T ) # Symmetrize the Hessian
0 commit comments