JaGeo / LobsterPy

Package to perform automatic bonding analysis with the program Lobster in the field of computational materials science and quantum chemistry
https://jageo.github.io/LobsterPy/
BSD 3-Clause "New" or "Revised" License
74 stars 27 forks source link

Do we really need very large kpoint grid density to do the vasp computation in order to do the further lobster computation? #303

Closed hongyi-zhao closed 2 months ago

hongyi-zhao commented 2 months ago

Hi there,

In the example here, I noticed the following Warning:

The ‘KPOINTS’ file is not adapted; the user must select the appropriate grid density before starting VASP computations. Usually, a factor of 50 x reciprocal lattice vectors is sufficient for reliable bonding analysis results.

So, I regenerated the ‘KPOINTS’ file as follows using the corresponding 'POSCAR' file:

In [23]: from pymatgen.io.vasp.inputs import Kpoints
    ...: from pymatgen.core import Structure
    ...: import numpy as np
    ...:
    ...: # Read the structure file (e.g., POSCAR file)
    ...: structure = Structure.from_file("POSCAR")
    ...:
    ...: # Define the factor (commonly 50)
    ...: factor = 50
    ...:
    ...: # Calculate the magnitudes of the reciprocal lattice vectors
    ...: reciprocal_lattice = structure.lattice.reciprocal_lattice
    ...: reciprocal_lengths = [np.linalg.norm(vector) for vector in
reciprocal_lattice.matrix]
    ...:
    ...: # Calculate the k-point grid density
    ...: kpoint_density = [int(round(factor * length)) for length in
reciprocal_lengths]
    ...:
    ...: # Create Kpoints object
    ...: kpoints = Kpoints(comment="Automatic mesh",
    ...:                   num_kpts=0,
    ...:                   style=Kpoints.supported_modes.Gamma,
    ...:                   kpts=[kpoint_density],
    ...:                   kpts_shift=[0, 0, 0])
    ...:
    ...: # Write to KPOINTS file
    ...: kpoints.write_file("KPOINTS")
    ...:
    ...: print(f"KPOINTS file generated with grid density: {kpoint_density}")
KPOINTS file generated with grid density: [99, 99, 99]

The generated KPOINTS file is shown below:

$ cat KPOINTS
Automatic mesh
0
Gamma
99 99 99

As you can see, this will result in a very dense k-point grid, which will require very intensive computational resources. So, I want to know do we really need a very large k-point grid density to do the VASP computation in order to do the further LOBSTER computation?

Regards, Zhao

JaGeo commented 2 months ago

Hi there,

In the example here, I noticed the following Warning:

The ‘KPOINTS’ file is not adapted; the user must select the appropriate grid density before starting VASP computations. Usually, a factor of 50 x reciprocal lattice vectors is sufficient for reliable bonding analysis results.

So, I regenerated the ‘KPOINTS’ file as follows using the corresponding 'POSCAR' file:

In [23]: from pymatgen.io.vasp.inputs import Kpoints
    ...: from pymatgen.core import Structure
    ...: import numpy as np
    ...:
    ...: # Read the structure file (e.g., POSCAR file)
    ...: structure = Structure.from_file("POSCAR")
    ...:
    ...: # Define the factor (commonly 50)
    ...: factor = 50
    ...:
    ...: # Calculate the magnitudes of the reciprocal lattice vectors
    ...: reciprocal_lattice = structure.lattice.reciprocal_lattice
    ...: reciprocal_lengths = [np.linalg.norm(vector) for vector in
reciprocal_lattice.matrix]
    ...:
    ...: # Calculate the k-point grid density
    ...: kpoint_density = [int(round(factor * length)) for length in
reciprocal_lengths]
    ...:
    ...: # Create Kpoints object
    ...: kpoints = Kpoints(comment="Automatic mesh",
    ...:                   num_kpts=0,
    ...:                   style=Kpoints.supported_modes.Gamma,
    ...:                   kpts=[kpoint_density],
    ...:                   kpts_shift=[0, 0, 0])
    ...:
    ...: # Write to KPOINTS file
    ...: kpoints.write_file("KPOINTS")
    ...:
    ...: print(f"KPOINTS file generated with grid density: {kpoint_density}")
KPOINTS file generated with grid density: [99, 99, 99]

The generated KPOINTS file is shown below:

$ cat KPOINTS
Automatic mesh
0
Gamma
99 99 99

As you can see, this will result in a very dense k-point grid, which will require very intensive computational resources. So, I want to know do we really need a very large k-point grid density to do the VASP computation in order to do the further LOBSTER computation?

Regards, Zhao Thank you for raising the issue.

Surely, this is not what we referring to. It's not possible to use this many kpoints in VASP.

@naik-aakash could you add a few more details. Confusing might come from 2pi added or not to the definition.

naik-aakash commented 2 months ago

Hi @hongyi-zhao, thanks for reaching out to us.

We refer to structure.lattice.reciprocal_lattice_crystallographic lattice vectors (which do not have an additional 2pi factor, as @JaGeo mentioned). Then, you should be able to get the required k-point grid density for reliable LOBSTER computations.

Below is the slightly tweaked code snippet, which should get the desired results

reciprocal_lattice = structure.lattice.reciprocal_lattice_crystallographic
factor = 50
reciprocal_lengths = [np.linalg.norm(vector) for vector in
reciprocal_lattice.matrix]
kpoint_density = [int(round(factor * length)) for length in
reciprocal_lengths]

kpoints = Kpoints(comment="Automatic mesh",
                  num_kpts=0,
                  style=Kpoints.supported_modes.Gamma,
                  kpts=[kpoint_density],
                  kpts_shift=[0, 0, 0])

See here for the pymatgen definition.

We will update the documentation to make this clearer in the next release 😄

hongyi-zhao commented 2 months ago

@naik-aakash This time, the code and the result are as follows:

from pymatgen.io.vasp.inputs import Kpoints
from pymatgen.core import Structure
import numpy as np

# Read the structure file (e.g., POSCAR file)
structure = Structure.from_file("POSCAR")

# Define the factor (commonly 50)
factor = 50

# Calculate the magnitudes of the reciprocal lattice vectors
reciprocal_lattice = structure.lattice.reciprocal_lattice_crystallographic
reciprocal_lengths = [np.linalg.norm(vector) for vector in reciprocal_lattice.matrix]

# Calculate the k-point grid density
kpoint_density = [int(round(factor * length)) for length in reciprocal_lengths]

# Create Kpoints object
kpoints = Kpoints(comment="Automatic mesh",
                  num_kpts=0,
                  style=Kpoints.supported_modes.Gamma,
                  kpts=[kpoint_density],
                  kpts_shift=[0, 0, 0])

# Write to KPOINTS file
kpoints.write_file("KPOINTS")

print(f"KPOINTS file generated with grid density: {kpoint_density}")

# Check it as follows:
In [1]: from pymatgen.io.vasp.inputs import Kpoints
   ...: from pymatgen.core import Structure
   ...: import numpy as np
   ...: 
   ...: # Read the structure file (e.g., POSCAR file)
   ...: structure = Structure.from_file("POSCAR")
   ...: 
   ...: # Define the factor (commonly 50)
   ...: factor = 50
   ...: 
   ...: # Calculate the magnitudes of the reciprocal lattice vectors
   ...: reciprocal_lattice = structure.lattice.reciprocal_lattice_crystallographic
   ...: reciprocal_lengths = [np.linalg.norm(vector) for vector in reciprocal_lattice.matrix]
   ...: 
   ...: # Calculate the k-point grid density
   ...: kpoint_density = [int(round(factor * length)) for length in reciprocal_lengths]
   ...: 
   ...: # Create Kpoints object
   ...: kpoints = Kpoints(comment="Automatic mesh",
   ...:                   num_kpts=0,
   ...:                   style=Kpoints.supported_modes.Gamma,
   ...:                   kpts=[kpoint_density],
   ...:                   kpts_shift=[0, 0, 0])
   ...: 
   ...: # Write to KPOINTS file
   ...: kpoints.write_file("KPOINTS")
   ...: 
   ...: print(f"KPOINTS file generated with grid density: {kpoint_density}")
KPOINTS file generated with grid density: [16, 16, 16]

The generated KPOINTS file:

$ cat KPOINTS 
Automatic mesh
0
Gamma
16 16 16
naik-aakash commented 2 months ago

@hongyi-zhao , Yes, this should be enough 😃

hongyi-zhao commented 1 month ago

See https://github.com/materialsproject/pymatgen/discussions/3709 for the related discussion.