Giter Club home page Giter Club logo

Comments (5)

hongyi-zhao avatar hongyi-zhao commented on July 21, 2024 2

@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

from lobsterpy.

JaGeo avatar JaGeo commented on July 21, 2024 1

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.

from lobsterpy.

naik-aakash avatar naik-aakash commented on July 21, 2024 1

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 😄

from lobsterpy.

naik-aakash avatar naik-aakash commented on July 21, 2024

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

from lobsterpy.

hongyi-zhao avatar hongyi-zhao commented on July 21, 2024

See materialsproject/pymatgen#3709 for the related discussion.

from lobsterpy.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.