materialsproject / atomate2

atomate2 is a library of computational materials science workflows
https://materialsproject.github.io/atomate2/
Other
136 stars 76 forks source link

BUG: Optimization of NaCl #159

Closed JaGeo closed 1 year ago

JaGeo commented 1 year ago

Describe the bug ISMEAR=2 is set for non-metals.

I try to optimize the structure of NaCl with the following script (atomate development version):

from atomate2.vasp.jobs.core import RelaxMaker
from jobflow import run_locally
from pymatgen.core import Structure

from atomate2.vasp.powerups import update_user_incar_settings

structure = Structure.from_file("POSCAR.NaCl.vasp")
relax_job = RelaxMaker().make(structure)
relax_job = update_user_incar_settings(relax_job, {"NPAR": 4}, class_filter=RelaxMaker)

run_locally(relax_job, create_folders=True)

POSCAR.NaCl.vasp

Na4 Cl4
1.0
5.691694 0.000000 0.000000
0.000000 5.691694 0.000000
0.000000 0.000000 5.691694
Na Cl
4 4
direct
0.000000 0.000000 0.000000 Na+
0.000000 0.500000 0.500000 Na+
0.500000 0.000000 0.500000 Na+
0.500000 0.500000 0.000000 Na+
0.500000 0.000000 0.000000 Cl-
0.500000 0.500000 0.500000 Cl-
0.000000 0.000000 0.500000 Cl-
0.000000 0.500000 0.000000 Cl-

I end up with this INCAR:

ALGO = Fast
EDIFF = 1e-05
EDIFFG = -0.02
ENAUG = 1360
ENCUT = 680
GGA = Ps
IBRION = 2
ISIF = 3
ISMEAR = 2
ISPIN = 2
KSPACING = 0.22
LAECHG = True
LASPH = True
LCHARG = False
LELF = False
LMIXTAU = True
LORBIT = 11
LREAL = Auto
LVTOT = True
LWAVE = False
MAGMOM = 8*0.6
NELM = 200
NPAR = 4
NSW = 99
PREC = Accurate
SIGMA = 0.2

I think it is due the combination of this line here https://github.com/materialsproject/atomate2/blob/73b9b3e71be8addc237c9d6cfce3dd1c09aa2ca8/src/atomate2/vasp/sets/core.py#L43

And this one here: https://github.com/materialsproject/atomate2/blob/73b9b3e71be8addc237c9d6cfce3dd1c09aa2ca8/src/atomate2/vasp/sets/base.py#L976

I would maybe suggest to switch to a default value of "None" to avoid such errors. Happy to hear what other people are thinking.

(I can of course try to fix it but I suspect it might concern many parts of the code ...)

utf commented 1 year ago

This is tricky, the current default of atomate2 is to assume a material is metallic, in terms of the density of k-points and the smearing parameters. The idea is that if you use a double relax maker on an insulator, the first relaxation will have metallic parameters and the second relax with have insulating parameters.

In practice, I've found that this is unnecessarily expensive when screening lots of insulators/semiconductors. One way to get around this problem then would be to switch the behaviour and assume insulating for the first relaxation. This would get around the issue identified here.

Another issue I have is the automatic setting of KSPACING based on the band gap. It results in weird behaviour when going from a GGA calculation to a HSE calculation, as the band gap increases so the kspacing decreases, but you'd really expect the kspacing to stay the same.

Therefore, I'm thinking to:

  1. Assume a material is insulating by default rather than metallic.
  2. Remove the continuous setting of KSPACING based on band gap, and instead have 3 KSPACING settings: Metallic, small band gap (< 0.5 eV), and larger band gap.
JaGeo commented 1 year ago

Thanks for explaining the reasoning.

An alternative could be: setting ISMEAR=0 in the first optimization. This would have the advantage that it would work for optimizations of metals and insulators. The other options (kpoints) could be kept.

But I think switching to a less strict setting might have some advantages. Thus, I do like your suggestion of making the insulating material default. I found the run times for my NaCl tests too long.

What would be your approach to optimize structures that haven't been preoptimized before with the current Makers? If I run VASP without automation for a structure optimization, I would typically use a larger kspacing first to pre-optimize and then refine with a very small kspacing for the last 10-15 ionic steps. Is there currently a predefined maker for this or would I need to customize? I think this could save a lot of computing time for optimizations. For metals, one might however think about if two optimization runs are then still enough to reach a well-converged structure or if one needs to do three.

JaGeo commented 1 year ago

Coming back to this again: I very much like the idea of introducing 3 band gap settings. I think people would like to have consistent kspacings for all of their runs for a similar compound.

utf commented 1 year ago

@JaGeo, do you think you'd be able to submit a PR with this feature? If not, I can try and look into it but might take a some time due to other commitments.

JaGeo commented 1 year ago

@utf I am currently also not sure how fast I/we can proceed here. We are not actively working on it at the moment.

mkhorton commented 1 year ago

Joining this thread, wondering if it is worth having more discussion on any of the following:

  1. Workflow stability issues aside, if it's theoretically better to scale density with k-points? I think the original motivation came via https://journals.aps.org/prb/abstract/10.1103/PhysRevB.93.155109
    • If yes, would an alternative interpolation be preferred, or a separate fix for the PBE->HSE issue?
  2. Why ditch KSPACING; is this not an orthogonal question and unrelated to above?
  3. Is it worth exploring or using a generalized k-point grid generator? Several options are available to run locally now (via Tim Mueller or BYU), and should be strictly better than M-P grids?
mkhorton commented 1 year ago

Not sure if this is the best place for discussion, or if a new issue would be better.