{"id":674,"date":"2022-10-17T07:01:09","date_gmt":"2022-10-17T07:01:09","guid":{"rendered":"https:\/\/doublelayer.eu\/vilab\/?p=674"},"modified":"2023-04-12T14:16:20","modified_gmt":"2023-04-12T14:16:20","slug":"matching-positions-to-grid-in-gpaw","status":"publish","type":"post","link":"https:\/\/doublelayer.eu\/vilab\/2022\/10\/17\/matching-positions-to-grid-in-gpaw\/","title":{"rendered":"Matching positions to grid in GPAW"},"content":{"rendered":"\n<p>Slab (2D) geometry.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>from ase.build import fcc111\nfrom gpaw import GPAW, PW\nfrom gpaw.utilities import h2gpts\nimport numpy as np\n\n# Set variables\ndiv   = 4.0    # number of grid points is divisible by div\ngrid  = 0.16   # desired grid spacing\nleft  = 6.0    # vacuum at the left border of the slab\nvacuum= 8.0    # vacuum at the right border above the slab\/adsorbate\ncutoff= 400    # PW cut-off\nname  ='slab'  # output file name\nfunc  ='RPBE'  # functional name; with libvdwxc you can use:\n               # {'name':'BEEF-vdW', 'backend':'libvdwxc'}\nkpts  = 4      # number of k-points\n\n# Define a slab with fixed grid and atoms positions\natoms = fcc111('Pt', size=(4,4,4), vacuum=left)\n# add adsorbate here\nzmax  = np.max(&#91;i&#91;2] for i in atoms.get_positions()])\ncell  = atoms.get_cell()\ncell&#91;2]&#91;2]= grid*div*round((zmax+vacuum)\/grid\/div)\natoms.set_cell(cell)\n\n# Set the default calculator\ncalc = GPAW(poissonsolver={'dipolelayer':'xy'},\n            mode=PW(cutoff),\n            xc=func,\n            gpts=h2gpts(grid, atoms.get_cell(), idiv=div),\n            kpts=(kpt,kpt,1),\n            parallel={'augment_grids':True,'sl_auto':True},\n            txt=f'{name}.txt',\n           )\n\n# Run calculation\natoms.calc = calc\natoms.get_potential_energy()<\/code><\/pre>\n\n\n\n<p>When choosing the number of k-points, consider using<\/p>\n\n\n\n<pre id=\"block-67615d31-fd87-4d76-b1b2-f02b46efc63a\" class=\"wp-block-code\"><code>kpts = {'density': 2.5,'gamma':True,'even':True}<\/code><\/pre>\n\n\n\n<p>Read <br><a href=\"https:\/\/wiki.fysik.dtu.dk\/gpaw\/documentation\/basic.html#manual-kpts\">wiki.fysik.dtu.dk\/gpaw\/documentation\/basic.html#manual-kpts<\/a><br>and<br><a href=\"https:\/\/wiki.fysik.dtu.dk\/gpaw\/tutorialsexercises\/structureoptimization\/surface\/surface.html\">wiki.fysik.dtu.dk\/gpaw\/tutorialsexercises\/structureoptimization\/surface\/surface.html<\/a><\/p>\n\n\n\n<p>Molecular (0D) geometry<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>from ase.io import read, write\nfrom ase.build import molecule\nfrom ase.optimize import QuasiNewton\nfrom gpaw import GPAW, PW\nfrom gpaw.cluster import *\nfrom gpaw.utilities import h2gpts\n\n# Set variables\ndiv   = 4.0    # number of grid points is divisible by div\ngrid  = 0.16   # desired grid spacing\nvacuum= 8.0    # vacuum around the molecule\ncutoff= 400    # PW cut-off\nname  ='H2O'   # molecule name from ase.build\nfunc  ='RPBE'  # functional name; with libvdwxc you can use:\n               # {'name':'BEEF-vdW', 'backend':'libvdwxc'}\nfmax  = 0.05   # maximum force in optimization\nsmax  = 11     # maximum steps in optimization\n\n# Define a box with fixed grid and atoms positions\natoms = Cluster(molecule(name))\natoms.minimal_box(border=vacuum, h=grid, multiple=div)\n# atoms.translate(&#91;0.01,0.02,0.03]) # probably not needed\n\n# Set calculator\ncalc = GPAW(mode=PW(cutoff),\n            xc = func,\n            gpts=h2gpts(grid, atoms.get_cell(), idiv=div),\n            parallel={'augment_grids':True,'sl_auto':True},\n            txt=f'{name}.txt',\n           )\n\n# Run optimization\natoms.calc = calc\nopt = QuasiNewton(atoms, trajectory=f'{name}.traj', logfile=f'{name}.log')\nopt.run(fmax=fmax, steps=smax)<\/code><\/pre>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Slab (2D) geometry. When choosing the number of k-points, consider using Read wiki.fysik.dtu.dk\/gpaw\/documentation\/basic.html#manual-kptsandwiki.fysik.dtu.dk\/gpaw\/tutorialsexercises\/structureoptimization\/surface\/surface.html Molecular (0D) geometry<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-674","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/doublelayer.eu\/vilab\/wp-json\/wp\/v2\/posts\/674","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=674"}],"version-history":[{"count":5,"href":"https:\/\/doublelayer.eu\/vilab\/wp-json\/wp\/v2\/posts\/674\/revisions"}],"predecessor-version":[{"id":797,"href":"https:\/\/doublelayer.eu\/vilab\/wp-json\/wp\/v2\/posts\/674\/revisions\/797"}],"wp:attachment":[{"href":"https:\/\/doublelayer.eu\/vilab\/wp-json\/wp\/v2\/media?parent=674"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/doublelayer.eu\/vilab\/wp-json\/wp\/v2\/categories?post=674"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/doublelayer.eu\/vilab\/wp-json\/wp\/v2\/tags?post=674"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}