3535from custodian .utils import backup
3636from custodian .vasp .interpreter import VaspModder
3737from custodian .vasp .io import load_outcar , load_vasprun
38- from custodian .vasp .utils import increase_k_point_density
38+ from custodian .vasp .utils import increase_k_point_density , is_valid_poscar
3939
4040__author__ = (
4141 "Shyue Ping Ong, William Davidson Richards, Anubhav Jain, Wei Chen, Stephen Dacek, Andrew Rosen, Janosh Riebesell"
@@ -226,7 +226,8 @@ def correct(self, directory="./"):
226226 # https://www.vasp.at/forum/viewtopic.php?p=14827
227227 if self .error_count ["fexcf" ] == 0 :
228228 # First see if last ionic configuration is more stable on rerun
229- actions .append ({"file" : "CONTCAR" , "action" : {"_file_copy" : {"dest" : "POSCAR" }}})
229+ if is_valid_poscar ("CONTCAR" , directory ):
230+ actions .append ({"file" : "CONTCAR" , "action" : {"_file_copy" : {"dest" : "POSCAR" }}})
230231 elif self .error_count ["fexcf" ] == 1 and vi ["INCAR" ].get ("IBRION" , - 1 ) == 1 :
231232 # Try more stable geometry optimization method
232233 actions .append ({"dict" : "INCAR" , "action" : {"_set" : {"IBRION" : 2 }}})
@@ -469,7 +470,8 @@ def correct(self, directory="./"):
469470
470471 if "brions" in self .errors :
471472 # Copy CONTCAR to POSCAR so we do not lose our progress.
472- actions .append ({"file" : "CONTCAR" , "action" : {"_file_copy" : {"dest" : "POSCAR" }}})
473+ if is_valid_poscar ("CONTCAR" , directory ):
474+ actions .append ({"file" : "CONTCAR" , "action" : {"_file_copy" : {"dest" : "POSCAR" }}})
473475
474476 # By default, increase POTIM per the VASP error message. But if that does not work,
475477 # we should try IBRION = 2 since it is less sensitive to POTIM.
@@ -499,8 +501,9 @@ def correct(self, directory="./"):
499501
500502 ediff = vi ["INCAR" ].get ("EDIFF" , 1e-4 )
501503
502- # Copy CONTCAR to POSCAR. This should always be done so we don't lose our progress.
503- actions .append ({"file" : "CONTCAR" , "action" : {"_file_copy" : {"dest" : "POSCAR" }}})
504+ # Copy CONTCAR to POSCAR so we don't lose our progress.
505+ if is_valid_poscar ("CONTCAR" , directory ):
506+ actions .append ({"file" : "CONTCAR" , "action" : {"_file_copy" : {"dest" : "POSCAR" }}})
504507
505508 # Tighten EDIFF per the VASP warning message. We tighten it by a factor of 10 unless
506509 # it is > 1e-6 (in which case we set it to 1e-6) or 1e-8 in which case we stop tightening
@@ -548,11 +551,7 @@ def correct(self, directory="./"):
548551 if "eddrmm" in self .errors :
549552 # RMM algorithm is not stable for this calculation
550553 # Copy CONTCAR to POSCAR if CONTCAR has already been populated.
551- try :
552- is_contcar = Poscar .from_file (os .path .join (directory , "CONTCAR" ))
553- except Exception :
554- is_contcar = False
555- if is_contcar :
554+ if is_valid_poscar ("CONTCAR" , directory ):
556555 actions .append ({"file" : "CONTCAR" , "action" : {"_file_copy" : {"dest" : "POSCAR" }}})
557556 if vi ["INCAR" ].get ("ALGO" , "Normal" ).lower () in {"fast" , "veryfast" }:
558557 actions .append ({"dict" : "INCAR" , "action" : {"_set" : {"ALGO" : "Normal" }}})
@@ -570,11 +569,7 @@ def correct(self, directory="./"):
570569
571570 if "edddav" in self .errors :
572571 # Copy CONTCAR to POSCAR if CONTCAR has already been populated.
573- try :
574- is_contcar = Poscar .from_file (os .path .join (directory , "CONTCAR" ))
575- except Exception :
576- is_contcar = False
577- if is_contcar :
572+ if is_valid_poscar ("CONTCAR" , directory ):
578573 actions .append ({"file" : "CONTCAR" , "action" : {"_file_copy" : {"dest" : "POSCAR" }}})
579574 if vi ["INCAR" ].get ("ICHARG" , 0 ) < 10 :
580575 actions .append ({"file" : "CHGCAR" , "action" : {"_file_delete" : {"mode" : "actual" }}})
@@ -619,11 +614,7 @@ def correct(self, directory="./"):
619614
620615 if self .errors & {"zheev" , "eddiag" }:
621616 # Copy CONTCAR to POSCAR if CONTCAR has already been populated.
622- try :
623- is_contcar = Poscar .from_file (os .path .join (directory , "CONTCAR" ))
624- except Exception :
625- is_contcar = False
626- if is_contcar :
617+ if is_valid_poscar ("CONTCAR" , directory ):
627618 actions .append ({"file" : "CONTCAR" , "action" : {"_file_copy" : {"dest" : "POSCAR" }}})
628619 if vi ["INCAR" ].get ("ALGO" , "Normal" ).lower () == "fast" :
629620 actions .append ({"dict" : "INCAR" , "action" : {"_set" : {"ALGO" : "Normal" }}})
@@ -1057,8 +1048,9 @@ def correct(self, directory="./"):
10571048 incar = vi ["INCAR" ]
10581049 outcar = load_outcar (os .path .join (directory , "OUTCAR" ))
10591050
1060- # Move CONTCAR to POSCAR
1061- actions .append ({"file" : "CONTCAR" , "action" : {"_file_copy" : {"dest" : "POSCAR" }}})
1051+ # Move CONTCAR to POSCAR if valid
1052+ if is_valid_poscar ("CONTCAR" , directory ):
1053+ actions .append ({"file" : "CONTCAR" , "action" : {"_file_copy" : {"dest" : "POSCAR" }}})
10621054
10631055 # Set PREC to High so ENAUG can be used to control Augmentation Grid Size
10641056 if incar .get ("PREC" , "Accurate" ).lower () != "high" :
@@ -1239,10 +1231,9 @@ def correct(self, directory="./"):
12391231 elif not v .converged_ionic :
12401232 # Just continue optimizing and let other handlers fix ionic
12411233 # optimizer parameters
1242- actions += [
1243- {"dict" : "INCAR" , "action" : {"_set" : {"IBRION" : 1 }}},
1244- {"file" : "CONTCAR" , "action" : {"_file_copy" : {"dest" : "POSCAR" }}},
1245- ]
1234+ actions .append ({"dict" : "INCAR" , "action" : {"_set" : {"IBRION" : 1 }}})
1235+ if is_valid_poscar ("CONTCAR" , directory ):
1236+ actions .append ({"file" : "CONTCAR" , "action" : {"_file_copy" : {"dest" : "POSCAR" }}})
12461237
12471238 if actions :
12481239 vi = VaspInput .from_directory (directory )
@@ -1927,7 +1918,9 @@ def correct(self, directory="./"):
19271918 i = d ["Index" ]
19281919 name = shutil .make_archive (os .path .join (directory , f"vasp.chk.{ i } " ), "gztar" )
19291920
1930- actions = [{"file" : "CONTCAR" , "action" : {"_file_copy" : {"dest" : "POSCAR" }}}]
1921+ actions = []
1922+ if is_valid_poscar ("CONTCAR" , directory ):
1923+ actions .append ({"file" : "CONTCAR" , "action" : {"_file_copy" : {"dest" : "POSCAR" }}})
19311924
19321925 modder = Modder (actions = [FileActions ], directory = directory )
19331926 for action in actions :
0 commit comments