Repository: materialsproject/custodian
Pull request #189 (2021-11-22 22:16:34)

[VASP] Switch from IBRION = 1 --> 2 if the BRIONS error occurs more than once
Currently, the `brions` error handler works by sequentially increasing POTIM by increments of 0.1. There are a few improvements that can be made here:

1. There was no test for this error handler. I have now added a test.
2. As noted [in the VASP manual](https://www.vasp.at/wiki/index.php/POTIM): "The POTIM tag serves as a scaling constant for the step widths. Especially the quasi-Newton algorithm [IBRION = 1] is sensitive to the choice of this parameter." With this in mind, after 1 failed attempt of increasing POTIM by 0.1, my PR has a switch to IBRION = 2 if it was previously IBRION = 1, which often resolves this issue because conjugate gradient is less sensitive to the value of POTIM. Personally, I would change this to IBRION = 2 right away instead of bothering with POTIM, but I didn't want to break backwards compatibility in case this check helps others.
3. It makes sense to copy CONTCAR to POSCAR here, which has now been implemented. This closes #159.



Patch:
diff --git a/custodian/vasp/handlers.py b/custodian/vasp/handlers.py
index 547f8ccf..fbef2f6d 100644
--- a/custodian/vasp/handlers.py
+++ b/custodian/vasp/handlers.py
@@ -355,8 +355,16 @@ class VaspErrorHandler(ErrorHandler):
             actions.append({"dict": "INCAR", "action": {"_set": {"SYMPREC": 1e-8, "ISYM": 0}}})
 
         if "brions" in self.errors:
+            # Increase POTIM but switch to IBRION = 2 (CG) if IBRION = 1 simply isn't working out
+            # IBRION = 2 is less sensitive to POTIM
             potim = float(vi["INCAR"].get("POTIM", 0.5)) + 0.1
             actions.append({"dict": "INCAR", "action": {"_set": {"POTIM": potim}}})
+            actions.append({"file": "CONTCAR", "action": {"_file_copy": {"dest": "POSCAR"}}})
+            if self.error_count["brions"] == 1 and vi["INCAR"].get("IBRION", 0) == 1:
+                # Reset POTIM to original value and switch to IBRION = 2
+                potim -= 0.2
+                actions.append({"dict": "INCAR", "action": {"_set": {"IBRION": 2, "POTIM": potim}}})
+            self.error_count["brions"] += 1
 
         if "zbrent" in self.errors:
             actions.append({"dict": "INCAR", "action": {"_set": {"IBRION": 1}}})


Test patch:
diff --git a/custodian/vasp/tests/test_handlers.py b/custodian/vasp/tests/test_handlers.py
index ac175c67..4c4cf071 100644
--- a/custodian/vasp/tests/test_handlers.py
+++ b/custodian/vasp/tests/test_handlers.py
@@ -131,6 +131,30 @@ class VaspErrorHandlerTest(unittest.TestCase):
             [{"action": {"_set": {"kpoints": [[4, 4, 4]]}}, "dict": "KPOINTS"}],
         )
 
+    def test_brions(self):
+        shutil.copy("INCAR.ibrion", "INCAR")
+        h = VaspErrorHandler("vasp.brions")
+        h.check()
+        d = h.correct()
+        self.assertEqual(d["errors"], ["brions"])
+        i = Incar.from_file("INCAR")
+        self.assertEqual(i["IBRION"], 1)
+        self.assertAlmostEqual(i["POTIM"], 1.5)
+
+        h.check()
+        d = h.correct()
+        self.assertEqual(d["errors"], ["brions"])
+        i = Incar.from_file("INCAR")
+        self.assertEqual(i["IBRION"], 2)
+        self.assertAlmostEqual(i["POTIM"], 1.4)
+
+        h.check()
+        d = h.correct()
+        self.assertEqual(d["errors"], ["brions"])
+        i = Incar.from_file("INCAR")
+        self.assertEqual(i["IBRION"], 2)
+        self.assertAlmostEqual(i["POTIM"], 1.5)
+
     def test_dentet(self):
         h = VaspErrorHandler("vasp.dentet")
         h.check()
diff --git a/test_files/CONTCAR b/test_files/CONTCAR
new file mode 100644
index 00000000..40191e1d
--- /dev/null
+++ b/test_files/CONTCAR
@@ -0,0 +1,16 @@
+Na2 Fe1 Ni1 O4
+1.0
+-2.816100 0.000000 0.000000
+-0.000000 -4.877628 0.000000
+-1.408050 0.812938 4.684533
+Na Fe Ni O
+2 1 1 4
+direct
+0.000000 0.000000 0.000000 Na
+0.500000 0.500000 0.000000 Na
+0.250000 0.250000 0.500000 Fe
+0.750000 0.750000 0.500000 Ni
+0.859265 0.380245 0.281470 O
+0.359265 0.880245 0.281470 O
+0.640735 0.119755 0.718530 O
+0.140735 0.619755 0.718530 O
diff --git a/test_files/INCAR.ibrion b/test_files/INCAR.ibrion
new file mode 100644
index 00000000..3ff2eba9
--- /dev/null
+++ b/test_files/INCAR.ibrion
@@ -0,0 +1,33 @@
+ALGO = Fast
+AMIN = 0.01
+AMIX = 0.2
+BMIX = 0.001
+EDIFF = 1e-05
+EDIFFG = -0.02
+ENAUG = 4000
+ENCUT = 400
+GGA = Pe
+IBRION = 1
+IDIPOL = 3
+ISIF = 2
+ISMEAR = 1
+ISPIN = 2
+ISYM = 0
+IVDW = 0
+KPAR = 16
+LASPH = True
+LDAU = False
+LDIPOL = True
+LMAXMIX = 4
+LORBIT = 11
+LREAL = Auto
+LVTOT = True
+LWAVE = False
+MAGMOM = 48*0.0
+NCORE = 4
+NELM = 100
+NELMIN = 8
+NSW = 99
+POTIM = 1.400
+PREC = Accurate
+SIGMA = 0.15
diff --git a/test_files/vasp.brions b/test_files/vasp.brions
new file mode 100644
index 00000000..06898e66
--- /dev/null
+++ b/test_files/vasp.brions
@@ -0,0 +1,128 @@
+ ----------------------------------------------------
+    OOO  PPPP  EEEEE N   N M   M PPPP
+   O   O P   P E     NN  N MM MM P   P
+   O   O PPPP  EEEEE N N N M M M PPPP   -- VERSION
+   O   O P     E     N  NN M   M P
+    OOO  P     EEEEE N   N M   M P
+ ----------------------------------------------------
+ running  128 mpi-ranks, with    1 threads/rank
+ distrk:  each k-point on    8 cores,   16 groups
+ distr:  one band on    4 cores,    2 groups
+ vasp.6.2.1 16May21 (build Jul 28 2021 23:24:15) complex                        
+  
+ POSCAR found type information on POSCAR NaPd
+ POSCAR found :  2 types and      48 ions
+ scaLAPACK will be used
+ LDA part: xc-table for Pade appr. of Perdew
+ POSCAR, INCAR and KPOINTS ok, starting setup
+ FFT: planning ...
+ WAVECAR not read
+ WARNING: random wavefunctions but no delay for mixing, default for NELMDL
+ entering main loop
+       N       E                     dE             d eps       ncg     rms          rms(c)
+DAV:   1     0.259055125689E+04    0.25906E+04   -0.16206E+05 14616   0.116E+03
+DAV:   2     0.103107001085E+03   -0.24874E+04   -0.23892E+04 12824   0.366E+02
+DAV:   3    -0.105189937336E+03   -0.20830E+03   -0.19766E+03 13224   0.111E+02
+DAV:   4    -0.112580098164E+03   -0.73902E+01   -0.73565E+01 13296   0.209E+01
+DAV:   5    -0.112904391648E+03   -0.32429E+00   -0.32425E+00 18952   0.354E+00    0.839E+00
+RMM:   6    -0.148517521639E+03   -0.35613E+02   -0.98053E+01 14356   0.746E+00    0.439E+01
+RMM:   7    -0.110332207642E+03    0.38185E+02   -0.12318E+01 12659   0.489E+00    0.844E+00
+RMM:   8    -0.106664042444E+03    0.36682E+01   -0.48493E+00 11998   0.293E+00    0.598E+00
+RMM:   9    -0.104643696045E+03    0.20203E+01   -0.10147E+00 13543   0.131E+00    0.514E+00
+RMM:  10    -0.104048278353E+03    0.59542E+00   -0.14678E+00 14422   0.169E+00    0.346E+00
+RMM:  11    -0.102964854905E+03    0.10834E+01   -0.87664E-01 13106   0.140E+00    0.115E+00
+RMM:  12    -0.102940032088E+03    0.24823E-01   -0.18891E-01 13019   0.701E-01    0.700E-01
+RMM:  13    -0.102940241863E+03   -0.20977E-03   -0.42376E-02 14938   0.338E-01    0.380E-01
+RMM:  14    -0.102931719898E+03    0.85220E-02   -0.13292E-02 14208   0.221E-01    0.222E-01
+RMM:  15    -0.102933391371E+03   -0.16715E-02   -0.84351E-03 13773   0.178E-01    0.190E-01
+RMM:  16    -0.102935183535E+03   -0.17922E-02   -0.28242E-03 14846   0.877E-02    0.210E-01
+RMM:  17    -0.102932600362E+03    0.25832E-02   -0.15400E-03 15212   0.526E-02    0.118E-01
+RMM:  18    -0.102932044171E+03    0.55619E-03   -0.10001E-03 13062   0.406E-02    0.570E-02
+RMM:  19    -0.102931980507E+03    0.63664E-04   -0.46192E-04 12448   0.226E-02    0.370E-02
+RMM:  20    -0.102931972342E+03    0.81648E-05   -0.18480E-04 11436   0.139E-02    0.307E-02
+RMM:  21    -0.102931888343E+03    0.84000E-04   -0.10503E-04  9862   0.115E-02    0.211E-02
+RMM:  22    -0.102931827616E+03    0.60727E-04   -0.65112E-05  8545   0.896E-03    0.125E-02
+RMM:  23    -0.102931813487E+03    0.14129E-04   -0.40516E-05  7547   0.700E-03    0.688E-03
+RMM:  24    -0.102931811977E+03    0.15096E-05   -0.23161E-05  6823   0.598E-03
+   1 F= -.10293181E+03 E0= -.10292786E+03  d E =-.102932E+03  mag=     0.0000
+ BRION: g(F)=  0.345E-01 g(S)=  0.000E+00
+ bond charge predicted
+       N       E                     dE             d eps       ncg     rms          rms(c)
+DAV:   1    -0.102899636845E+03    0.32177E-01   -0.15620E+01 12832   0.438E+00    0.704E-01
+RMM:   2    -0.102937053172E+03   -0.37416E-01   -0.43446E-01 11856   0.837E-01    0.364E-01
+RMM:   3    -0.103023627522E+03   -0.86574E-01   -0.27301E-01 12782   0.496E-01    0.514E-01
+RMM:   4    -0.102965331214E+03    0.58296E-01   -0.21515E-02 12452   0.229E-01    0.308E-01
+RMM:   5    -0.102965004682E+03    0.32653E-03   -0.22573E-03 13291   0.797E-02    0.274E-01
+RMM:   6    -0.102964462169E+03    0.54251E-03   -0.30661E-04 12986   0.323E-02    0.238E-01
+RMM:   7    -0.102963772008E+03    0.69016E-03   -0.38430E-04 11823   0.236E-02    0.159E-01
+RMM:   8    -0.102963224529E+03    0.54748E-03   -0.13659E-03 11440   0.361E-02    0.183E-02
+RMM:   9    -0.102963096009E+03    0.12852E-03   -0.13331E-04  9410   0.150E-02    0.340E-02
+RMM:  10    -0.102963055487E+03    0.40521E-04   -0.28043E-05  7189   0.912E-03    0.213E-02
+RMM:  11    -0.102963041225E+03    0.14263E-04   -0.22262E-05  6251   0.628E-03    0.737E-03
+RMM:  12    -0.102963024193E+03    0.17031E-04   -0.90867E-06  5465   0.483E-03    0.263E-03
+RMM:  13    -0.102962996773E+03    0.27420E-04   -0.32324E-06  4933   0.361E-03    0.933E-04
+RMM:  14    -0.102962996980E+03   -0.20679E-06   -0.18719E-06  4247   0.272E-03
+   2 F= -.10296300E+03 E0= -.10295913E+03  d E =-.311850E-01  mag=    -0.0000
+ BRION: g(F)=  0.266E-01 g(S)=  0.000E+00 retain N=  1 mean eig= 7.96
+ eig:   7.961
+ bond charge predicted
+       N       E                     dE             d eps       ncg     rms          rms(c)
+DAV:   1    -0.994701690334E+02    0.34928E+01   -0.10021E+03 14840   0.468E+01    0.342E+00
+RMM:   2    -0.102111364016E+03   -0.26412E+01   -0.27072E+01 12555   0.796E+00    0.197E+00
+RMM:   3    -0.105012737756E+03   -0.29014E+01   -0.98692E+00 13058   0.451E+00    0.278E+00
+RMM:   4    -0.103108466143E+03    0.19043E+01   -0.88538E-01 12291   0.176E+00    0.152E+00
+RMM:   5    -0.103100276279E+03    0.81899E-02   -0.17322E-01 14285   0.757E-01    0.124E+00
+RMM:   6    -0.103088428079E+03    0.11848E-01   -0.19343E-02 16431   0.236E-01    0.112E+00
+RMM:   7    -0.103080627639E+03    0.78004E-02   -0.58199E-03 15923   0.113E-01    0.943E-01
+RMM:   8    -0.103068433445E+03    0.12194E-01   -0.23762E-02 14068   0.189E-01    0.334E-01
+RMM:   9    -0.103067013361E+03    0.14201E-02   -0.23575E-02 15078   0.180E-01    0.340E-01
+RMM:  10    -0.103066647687E+03    0.36567E-03   -0.29334E-03 13086   0.974E-02    0.189E-01
+RMM:  11    -0.103065852547E+03    0.79514E-03   -0.15767E-03 13955   0.559E-02    0.943E-02
+RMM:  12    -0.103066142116E+03   -0.28957E-03   -0.77897E-04 13176   0.318E-02    0.437E-02
+RMM:  13    -0.103065725374E+03    0.41674E-03   -0.44892E-04 12673   0.269E-02    0.243E-02
+RMM:  14    -0.103065601189E+03    0.12419E-03   -0.17993E-04 10001   0.149E-02    0.822E-03
+RMM:  15    -0.103065628085E+03   -0.26896E-04   -0.78806E-05  7456   0.886E-03    0.900E-03
+RMM:  16    -0.103065589527E+03    0.38558E-04   -0.56294E-05  6575   0.826E-03    0.165E-03
+RMM:  17    -0.103065600434E+03   -0.10906E-04   -0.40249E-05  5705   0.599E-03    0.167E-03
+RMM:  18    -0.103065605072E+03   -0.46380E-05   -0.22501E-05  5362   0.488E-03
+   3 F= -.10306561E+03 E0= -.10306259E+03  d E =-.102608E+00  mag=    -0.0000
+ BRION: g(F)=  0.893E-03 g(S)=  0.000E+00 retain N=  1 mean eig= 7.58
+ eig:   7.581
+ bond charge predicted
+       N       E                     dE             d eps       ncg     rms          rms(c)
+DAV:   1    -0.103051852801E+03    0.13748E-01   -0.36420E+00 13088   0.202E+00    0.331E-01
+RMM:   2    -0.103061313695E+03   -0.94609E-02   -0.91641E-02 11308   0.375E-01    0.191E-01
+RMM:   3    -0.103075014448E+03   -0.13701E-01   -0.70317E-02 12535   0.238E-01    0.314E-01
+RMM:   4    -0.103067963942E+03    0.70505E-02   -0.40583E-03 12272   0.116E-01    0.172E-01
+RMM:   5    -0.103066994283E+03    0.96966E-03   -0.48514E-04 11156   0.408E-02    0.145E-01
+RMM:   6    -0.103066880284E+03    0.11400E-03   -0.12565E-04 11776   0.184E-02    0.120E-01
+RMM:   7    -0.103066861635E+03    0.18649E-04   -0.54305E-05  7021   0.104E-02    0.956E-02
+RMM:   8    -0.103066835740E+03    0.25895E-04   -0.16637E-04  8255   0.131E-02    0.460E-02
+RMM:   9    -0.103066882138E+03   -0.46398E-04   -0.99208E-05  7372   0.105E-02    0.740E-03
+RMM:  10    -0.103066935738E+03   -0.53600E-04   -0.19741E-05  6020   0.620E-03    0.849E-03
+RMM:  11    -0.103066922194E+03    0.13544E-04   -0.38862E-06  5234   0.411E-03    0.784E-03
+RMM:  12    -0.103066922609E+03   -0.41535E-06   -0.30265E-06  4769   0.313E-03
+   4 F= -.10306692E+03 E0= -.10306385E+03  d E =-.131754E-02  mag=    -0.0000
+ BRION: g(F)=  0.593E-03 g(S)=  0.000E+00 retain N=  1 mean eig= 5.69
+ eig:   5.691
+ bond charge predicted
+       N       E                     dE             d eps       ncg     rms          rms(c)
+DAV:   1    -0.103066226425E+03    0.69577E-03   -0.31317E-01 12712   0.619E-01    0.967E-02
+RMM:   2    -0.103067217849E+03   -0.99142E-03   -0.80205E-03  9944   0.116E-01    0.548E-02
+RMM:   3    -0.103066772148E+03    0.44570E-03   -0.60800E-03 10588   0.684E-02    0.632E-02
+RMM:   4    -0.103068094344E+03   -0.13222E-02   -0.22655E-04  9764   0.272E-02    0.534E-02
+RMM:   5    -0.103067543842E+03    0.55050E-03   -0.31373E-05  8208   0.105E-02    0.434E-02
+RMM:   6    -0.103067545144E+03   -0.13020E-05   -0.88685E-06  5782   0.570E-03    0.362E-02
+RMM:   7    -0.103067541195E+03    0.39490E-05   -0.29841E-06  4914   0.370E-03    0.340E-02
+RMM:   8    -0.103067534653E+03    0.65423E-05   -0.19398E-06  4649   0.314E-03
+   5 F= -.10306753E+03 E0= -.10306447E+03  d E =-.612044E-03  mag=    -0.0000
+ BRION: g(F)=  0.530E-03 g(S)=  0.000E+00
+ BRIONS problems: POTIM should be increased
+ retain N=  1 mean eig=11.24
+ eig:  11.242
+ bond charge predicted
+       N       E                     dE             d eps       ncg     rms          rms(c)
+DAV:   1    -0.102942393423E+03    0.12515E+00   -0.31507E+01 12736   0.632E+00    0.956E-01
+RMM:   2    -0.103018338176E+03   -0.75945E-01   -0.82319E-01 12492   0.118E+00    0.546E-01
+RMM:   3    -0.103091385214E+03   -0.73047E-01   -0.60869E-01 12856   0.705E-01    0.602E-01
+RMM:   4    -0.103091203211E+03    0.18200E-03   -0.23542E-02 12444   0.272E-01    0.536E-01