{"id":711,"date":"2022-12-13T10:31:18","date_gmt":"2022-12-13T10:31:18","guid":{"rendered":"https:\/\/doublelayer.eu\/vilab\/?p=711"},"modified":"2023-04-12T11:28:00","modified_gmt":"2023-04-12T11:28:00","slug":"k-points-kplib","status":"publish","type":"post","link":"https:\/\/doublelayer.eu\/vilab\/2022\/12\/13\/k-points-kplib\/","title":{"rendered":"k-points with kplib and gpaw"},"content":{"rendered":"\n<p>Choosing optimal k-points is a tricky task. In GPAW, one can set them <a href=\"https:\/\/wiki.fysik.dtu.dk\/gpaw\/documentation\/basic.html#manual-kpts\">manually<\/a>, using size or density and following a rule of thumb: <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>calc = GPAW(kpts={'size': (4, 4, 4), 'gamma': True})\n# or\ncalc = GPAW(kpts={'density': 2.5, 'gamma': True})<\/code><\/pre>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>A rule of thumb for choosing the initial <strong>k<\/strong>-point sampling is, that the product, <em>ka<\/em>, between the number of <strong>k<\/strong>-points, <em>k<\/em>, in any direction, and the length of the basis vector in this direction, <em>a<\/em>, should be:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><em>ka<\/em> ~ 30 \u00c5, for <em>d<\/em> band metals<\/li>\n\n\n\n<li><em>ka<\/em> ~ 25 \u00c5, for simple metals<\/li>\n\n\n\n<li><em>ka<\/em> ~ 20 \u00c5, for semiconductors<\/li>\n\n\n\n<li><em>ka<\/em> ~ 15 \u00c5, for insulators<\/li>\n<\/ul>\n\n\n\n<p>Remember that convergence in this parameter should always be checked.<\/p>\n<cite>https:\/\/wiki.fysik.dtu.dk\/gpaw\/tutorialsexercises\/structureoptimization\/surface\/surface.html<\/cite><\/blockquote>\n\n\n\n<p>The corresponding densities (<em>ka<\/em>\/2\u03c0) are:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><em>ka<\/em>\/2\u03c0 ~ 4.8 \u00c5, for <em>d<\/em> band metals<\/li>\n\n\n\n<li><em>ka<\/em>\/2\u03c0 ~ 4.0 \u00c5, for simple metals<\/li>\n\n\n\n<li><em>ka<\/em>\/2\u03c0 ~ 3.2 \u00c5, for semiconductors<\/li>\n\n\n\n<li><em>ka<\/em>\/2\u03c0 ~ 2.4 \u00c5, for insulators<\/li>\n<\/ul>\n\n\n\n<p>With the recent update, I can start using <a href=\"https:\/\/gitlab.com\/muellergroup\/kplib\/\">kplib<\/a> (see <a href=\"https:\/\/www.sciencedirect.com\/science\/article\/pii\/S0927025620305917#f0005\">paper<\/a>) to choose the optimal generalized k-point grids. The main variable in kplib is min_distance, which is analogous to the density\u00d72\u03c0. Read more about the min_distance at <a href=\"https:\/\/muellergroup.jhu.edu\/K-Points.html\">muellergroup.jhu.edu\/K-Points.html<\/a>.<\/p>\n\n\n\n<p>Here is an example of my conda environment<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>conda create -n gpaw23 python=3.9\nconda activate gpaw23\nconda install -c conda-forge cxx-compiler\npip install kplib # from pypi.org\/project\/kpLib\nconda install -c conda-forge gpaw<\/code><\/pre>\n\n\n\n<p>Here is a working example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>from ase import Atoms\nfrom ase.parallel import parprint\nfrom gpaw import GPAW, PW\nfrom kpLib import get_kpoints\nfrom pymatgen.io.ase import AseAtomsAdaptor\n\natoms = Atoms(cell=&#91;&#91;1.608145, -2.785389, 0.0], &#91;1.608145, 2.785389, 0.0], &#91;0.0, 0.0, 5.239962]],\n              symbols=&#91;'Ga', 'Ga', 'N', 'N'],\n              positions=&#91;&#91; 1.608145  , -0.92846486,  2.61536983],\n                         &#91; 1.608145  ,  0.92846486,  5.23535083],\n                         &#91; 1.608145  , -0.92846486,  4.58957792],\n                         &#91; 1.608145  ,  0.92846486,  1.96959692]],\n              pbc=True)\nstructure = AseAtomsAdaptor.get_structure(atoms)\nkpts_data = get_kpoints(structure, minDistance=30, include_gamma=False)\n    \nparprint(\"Found lattice with kplib: \")\nparprint(f\"Nominal kpts: {kpts_data&#91;'num_total_kpts']}\")\nparprint(f\"Distinct kpts: {kpts_data&#91;'num_distinct_kpts']}\")\n\natoms.calc = GPAW(xc='PBE',\n                  mode=PW(400),\n                  kpts=kpts_data&#91;'coords'],\n                  symmetry={'point_group': True,\n                            'time_reversal': True,\n                            'symmorphic': False,\n                            'tolerance': 1e-4},\n                  txt='gpaw-out.txt')\nenergy = atoms.get_total_energy()\n\nparprint(f\"Total energy: {energy}\")\nparprint(f\"kpts passed to GPAW: {len(atoms.calc.get_bz_k_points())}\")\nparprint(f\"kpts in GPAW IBZ: {len(atoms.calc.get_ibz_k_points())}\")<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Choosing optimal k-points is a tricky task. In GPAW, one can set them manually, using size or density and following a rule of thumb: The corresponding densities (ka\/2\u03c0) are: With the recent update, I can start using kplib (see paper) to choose the optimal generalized k-point grids. The main variable in kplib is min_distance, which&hellip; <a class=\"read-more\" href=\"https:\/\/doublelayer.eu\/vilab\/2022\/12\/13\/k-points-kplib\/\">Read More<\/a><\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[31,34],"class_list":["post-711","post","type-post","status-publish","format-standard","hentry","category-know-how","tag-hpc","tag-software"],"_links":{"self":[{"href":"https:\/\/doublelayer.eu\/vilab\/wp-json\/wp\/v2\/posts\/711","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/doublelayer.eu\/vilab\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/doublelayer.eu\/vilab\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/doublelayer.eu\/vilab\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/doublelayer.eu\/vilab\/wp-json\/wp\/v2\/comments?post=711"}],"version-history":[{"count":9,"href":"https:\/\/doublelayer.eu\/vilab\/wp-json\/wp\/v2\/posts\/711\/revisions"}],"predecessor-version":[{"id":796,"href":"https:\/\/doublelayer.eu\/vilab\/wp-json\/wp\/v2\/posts\/711\/revisions\/796"}],"wp:attachment":[{"href":"https:\/\/doublelayer.eu\/vilab\/wp-json\/wp\/v2\/media?parent=711"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/doublelayer.eu\/vilab\/wp-json\/wp\/v2\/categories?post=711"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/doublelayer.eu\/vilab\/wp-json\/wp\/v2\/tags?post=711"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}