@@ -197,6 +197,19 @@ def check(self, directory="./"):
197197 # e-density (brmix error)
198198 if err == "brmix" and "NELECT" in incar :
199199 continue
200+
201+ # Treat auto_nbands only as a warning, do not fail a job
202+ if err == "auto_nbands" :
203+ if nbands := self ._get_nbands_from_outcar (directory ):
204+ outcar = load_outcar (os .path .join (directory , "OUTCAR" ))
205+ if (nelect := outcar .nelect ) and (nbands > 2 * nelect ):
206+ warnings .warn (
207+ "NBANDS seems to be too high. The electronic structure may be inaccurate. "
208+ "You may want to rerun this job with a smaller number of cores." ,
209+ UserWarning ,
210+ )
211+ continue
212+
200213 self .errors .add (err )
201214 error_msgs .add (msg )
202215 for msg in error_msgs :
@@ -538,12 +551,11 @@ def correct(self, directory="./"):
538551
539552 self .error_count ["zbrent" ] += 1
540553
541- if "too_few_bands" in self .errors :
542- nbands = None
543- nbands = vi ["INCAR" ]["NBANDS" ] if "NBANDS" in vi ["INCAR" ] else self ._get_nbands_from_outcar (directory )
544- if nbands :
545- new_nbands = max (int (1.1 * nbands ), nbands + 1 ) # This handles the case when nbands is too low (< 8).
546- actions .append ({"dict" : "INCAR" , "action" : {"_set" : {"NBANDS" : new_nbands }}})
554+ if "too_few_bands" in self .errors and (
555+ nbands := vi ["INCAR" ].get ("NBANDS" ) or self ._get_nbands_from_outcar (directory )
556+ ):
557+ new_nbands = max (int (1.1 * nbands ), nbands + 1 ) # This handles the case when nbands is too low (< 8).
558+ actions .append ({"dict" : "INCAR" , "action" : {"_set" : {"NBANDS" : new_nbands }}})
547559
548560 if self .errors & {"pssyevx" , "pdsyevx" } and vi ["INCAR" ].get ("ALGO" , "Normal" ).lower () != "normal" :
549561 actions .append ({"dict" : "INCAR" , "action" : {"_set" : {"ALGO" : "Normal" }}})
@@ -667,23 +679,20 @@ def correct(self, directory="./"):
667679
668680 if self .errors .intersection (["bravais" , "ksymm" ]):
669681 # For bravais: VASP recommends refining the lattice parameters
670- # or changing SYMPREC. See https://www.vasp.at/forum/viewtopic.php?f=3&t=19109
682+ # or changing SYMPREC (default = 1e-5). See
683+ # https://www.vasp.at/forum/viewtopic.php?f=3&t=19109
671684 # Appears to occur when SYMPREC is very low, so we change it to
672685 # the default if it's not already. If it's the default, we x10.
673686 # For ksymm, there's not much information about the issue other than the
674687 # direct and reciprocal meshes being incompatible.
675688 # This is basically the same as bravais
676689 vasp_recommended_symprec = 1e-6
677- symprec = vi ["INCAR" ].get ("SYMPREC" , vasp_recommended_symprec )
678- if symprec < vasp_recommended_symprec :
679- actions .append ({"dict" : "INCAR" , "action" : {"_set" : {"SYMPREC" : vasp_recommended_symprec }}})
680- elif symprec < 1e-4 :
681- # try 10xing symprec twice, then set ISYM=0 to not impose potentially artificial symmetry from
682- # too loose symprec on charge density
683- actions .append ({"dict" : "INCAR" , "action" : {"_set" : {"SYMPREC" : float (f"{ symprec * 10 :.1e} " )}}})
684- else :
690+ if (symprec := vi ["INCAR" ].get ("SYMPREC" , 1e-5 )) > vasp_recommended_symprec :
691+ actions .append (
692+ {"dict" : "INCAR" , "action" : {"_set" : {"SYMPREC" : min (symprec / 10.0 , vasp_recommended_symprec )}}}
693+ )
694+ elif vi ["INCAR" ].get ("ISYM" ) > 0 : # Default ISYM is variable, but never 0
685695 actions .append ({"dict" : "INCAR" , "action" : {"_set" : {"ISYM" : 0 }}})
686- self .error_count ["bravais" ] += 1
687696
688697 if "nbands_not_sufficient" in self .errors :
689698 outcar = load_outcar (os .path .join (directory , "OUTCAR" ))
@@ -749,50 +758,25 @@ def correct(self, directory="./"):
749758 )
750759 self .error_count ["algo_tet" ] += 1
751760
752- if "auto_nbands" in self .errors and (nbands := self ._get_nbands_from_outcar (directory )):
753- outcar = load_outcar (os .path .join (directory , "OUTCAR" ))
754-
755- if (nelect := outcar .nelect ) and (nbands > 2 * nelect ):
756- self .error_count ["auto_nbands" ] += 1
757- warnings .warn (
758- "NBANDS seems to be too high. The electronic structure may be inaccurate. "
759- "You may want to rerun this job with a smaller number of cores." ,
760- UserWarning ,
761- )
762-
763- elif nbands := vi ["INCAR" ].get ("NBANDS" ):
764- kpar = vi ["INCAR" ].get ("KPAR" , 1 )
765- ncore = vi ["INCAR" ].get ("NCORE" , 1 )
766- # If the user set an NBANDS that isn't compatible with parallelization settings,
767- # increase NBANDS to ensure correct task distribution and issue a UserWarning.
768- # The number of ranks per band is (number of MPI ranks) / (KPAR * NCORE)
769- if (ranks := outcar .run_stats .get ("cores" )) and (rem_bands := nbands % (ranks // (kpar * ncore ))) != 0 :
770- actions .append ({"dict" : "INCAR" , "action" : {"_set" : {"NBANDS" : nbands + rem_bands }}})
771- warnings .warn (
772- f"Your NBANDS={ nbands } setting was incompatible with your parallelization "
773- f"settings, KPAR={ kpar } , NCORE={ ncore } , over { ranks } ranks. "
774- f"The number of bands has been decreased accordingly to { nbands + rem_bands } ." ,
775- UserWarning ,
776- )
777-
778761 VaspModder (vi = vi , directory = directory ).apply_actions (actions )
779762 return {"errors" : list (self .errors ), "actions" : actions }
780763
781764 @staticmethod
782765 def _get_nbands_from_outcar (directory : str ) -> int | None :
783766 nbands = None
784- with open (os .path .join (directory , "OUTCAR" )) as file :
785- for line in file :
786- # Have to take the last NBANDS line since sometimes VASP
787- # updates it automatically even if the user specifies it.
788- # The last one is marked by NBANDS= (no space).
789- if "NBANDS=" in line :
790- try :
791- d = line .split ("=" )
792- nbands = int (d [- 1 ].strip ())
793- break
794- except (IndexError , ValueError ):
795- pass
767+ if os .path .isfile (outcar_path := os .path .join (directory , "OUTCAR" )):
768+ with open (outcar_path ) as file :
769+ for line in file :
770+ # Have to take the last NBANDS line since sometimes VASP
771+ # updates it automatically even if the user specifies it.
772+ # The last one is marked by NBANDS= (no space).
773+ if "NBANDS=" in line :
774+ try :
775+ d = line .split ("=" )
776+ nbands = int (d [- 1 ].strip ())
777+ break
778+ except (IndexError , ValueError ):
779+ pass
796780 return nbands
797781
798782
0 commit comments