Skip to content

Commit

Permalink
fixed import statements in tutorials
Browse files Browse the repository at this point in the history
Signed-off-by: Nick Papior <[email protected]>
  • Loading branch information
zerothi committed Jun 28, 2024
1 parent 4157a1c commit 6a1c670
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 57 deletions.
2 changes: 1 addition & 1 deletion docs/tutorials/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ sisl is shipped with these tutorials which introduce the basics.
All examples are assumed to have this in the header::

import numpy as np
from sisl import *
import sisl as si

to enable `numpy`_ and sisl.

Expand Down
20 changes: 10 additions & 10 deletions docs/tutorials/tutorial_es_1.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"outputs": [],
"source": [
"import numpy as np\n",
"from sisl import *\n",
"import sisl as si\n",
"from sisl.viz import merge_plots\n",
"from sisl.viz.processors.math import normalize\n",
"import matplotlib.pyplot as plt\n",
Expand Down Expand Up @@ -35,7 +35,7 @@
"metadata": {},
"outputs": [],
"source": [
"graphene = geom.graphene().tile(6, 0).tile(6, 1)"
"graphene = si.geom.graphene().tile(6, 0).tile(6, 1)"
]
},
{
Expand All @@ -44,7 +44,7 @@
"source": [
"This does *a lot* of things behind the scenes:\n",
"\n",
"1. `geom.graphene`:\n",
"1. `si.geom.graphene`:\n",
" - create atomic coordinates of pristine graphene with a default bond-length of $1.42\\,\\mathrm{Å}$.\n",
" - create pristine graphene unit cell, by default this will create a supercell\n",
" with a size `3x3`, i.e. a nearest neighbour unit-cell.\n",
Expand Down Expand Up @@ -156,7 +156,7 @@
"metadata": {},
"outputs": [],
"source": [
"H = Hamiltonian(system)\n",
"H = si.Hamiltonian(system)\n",
"print(H)"
]
},
Expand Down Expand Up @@ -291,7 +291,7 @@
"metadata": {},
"outputs": [],
"source": [
"band = BandStructure(\n",
"band = si.BandStructure(\n",
" H,\n",
" [[0, 0, 0], [0, 0.5, 0], [1 / 3, 2 / 3, 0], [0, 0, 0]],\n",
" 400,\n",
Expand Down Expand Up @@ -349,7 +349,7 @@
"metadata": {},
"outputs": [],
"source": [
"bz = MonkhorstPack(H, [35, 35, 1])\n",
"bz = si.MonkhorstPack(H, [35, 35, 1])\n",
"bz_average = (\n",
" bz.apply.average\n",
"); # specify the Brillouin zone to perform an average of subsequent method calls"
Expand Down Expand Up @@ -416,7 +416,7 @@
"print(\"Normalization: {}\".format(f.sum() * (r[1] - r[0])))\n",
"plt.plot(r, f)\n",
"plt.ylim([0, None])\n",
"orb = SphericalOrbital(1, (r, f));"
"orb = si.SphericalOrbital(1, (r, f));"
]
},
{
Expand Down Expand Up @@ -460,7 +460,7 @@
"metadata": {},
"outputs": [],
"source": [
"C = Atom(6, orb)\n",
"C = si.Atom(6, orb)\n",
"print(system.atoms)\n",
"system.atoms.replace(system.atoms[0], C)\n",
"print(system.atoms)"
Expand All @@ -482,7 +482,7 @@
"outputs": [],
"source": [
"es = H.eigenstate(dtype=np.float64).sub([len(H) // 2 + 1])\n",
"grid = Grid(0.075, lattice=H.lattice)\n",
"grid = si.Grid(0.075, lattice=H.lattice)\n",
"es.wavefunction(grid)"
]
},
Expand Down Expand Up @@ -540,7 +540,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.15"
"version": "3.11.7"
}
},
"nbformat": 4,
Expand Down
49 changes: 21 additions & 28 deletions docs/tutorials/tutorial_es_2.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"outputs": [],
"source": [
"import numpy as np\n",
"from sisl import *\n",
"import sisl as si\n",
"from sisl.physics.electron import berry_phase\n",
"import matplotlib.pyplot as plt\n",
"\n",
"%matplotlib inline"
Expand All @@ -32,8 +33,8 @@
"metadata": {},
"outputs": [],
"source": [
"graphene = geom.graphene()\n",
"H = Hamiltonian(graphene)\n",
"graphene = si.geom.graphene()\n",
"H = si.Hamiltonian(graphene)\n",
"H.construct([(0.1, 1.44), (0, -2.7)])"
]
},
Expand Down Expand Up @@ -70,7 +71,7 @@
"metadata": {},
"outputs": [],
"source": [
"band = BandStructure(\n",
"band = si.BandStructure(\n",
" H, [[0, 0.5, 0], [1 / 3, 2 / 3, 0], [0.5, 0.5, 0]], 400, [r\"$M$\", r\"$K$\", r\"$M'$\"]\n",
")"
]
Expand Down Expand Up @@ -100,7 +101,7 @@
"metadata": {},
"outputs": [],
"source": [
"bz = MonkhorstPack(\n",
"bz = si.MonkhorstPack(\n",
" H, [41, 41, 1], displacement=[1 / 3, 2 / 3, 0], size=[0.125, 0.125, 1]\n",
")\n",
"bz_average = bz.apply.average # specify the Brillouin zone to perform an average"
Expand Down Expand Up @@ -139,7 +140,7 @@
"outputs": [],
"source": [
"E = np.linspace(-0.5, 0.5, 1000)\n",
"dist = get_distribution(\"gaussian\", 0.03)\n",
"dist = si.get_distribution(\"gaussian\", 0.03)\n",
"bz.set_parent(H)\n",
"plt.plot(\n",
" E,\n",
Expand Down Expand Up @@ -181,7 +182,7 @@
"normal = [0, 0, 1]\n",
"# Origo (in units of reciprocal lattice vectors)\n",
"origin = [1 / 3, 2 / 3, 0]\n",
"circle = BrillouinZone.param_circle(H, N, kR, normal, origin)\n",
"circle = si.BrillouinZone.param_circle(H, N, kR, normal, origin)\n",
"plt.plot(circle.k[:, 0], circle.k[:, 1])\n",
"plt.xlabel(r\"$k_x$ [$b_x$]\")\n",
"plt.ylabel(r\"$k_y$ [$b_y$]\")\n",
Expand Down Expand Up @@ -224,21 +225,13 @@
"outputs": [],
"source": [
"circle.set_parent(H)\n",
"print(\"Pristine graphene (0): {:.5f} rad\".format(electron.berry_phase(circle, sub=0)))\n",
"print(\"Pristine graphene (1): {:.5f} rad\".format(electron.berry_phase(circle, sub=1)))\n",
"print(\"Pristine graphene (:): {:.5f} rad\".format(electron.berry_phase(circle)))\n",
"print(\"Pristine graphene (0): {:.5f} rad\".format(berry_phase(circle, sub=0)))\n",
"print(\"Pristine graphene (1): {:.5f} rad\".format(berry_phase(circle, sub=1)))\n",
"print(\"Pristine graphene (:): {:.5f} rad\".format(berry_phase(circle)))\n",
"circle.set_parent(H_bp)\n",
"print(\n",
" \"Anti-symmetric graphene (0): {:.5f} rad\".format(\n",
" electron.berry_phase(circle, sub=0)\n",
" )\n",
")\n",
"print(\n",
" \"Anti-symmetric graphene (1): {:.5f} rad\".format(\n",
" electron.berry_phase(circle, sub=1)\n",
" )\n",
")\n",
"print(\"Anti-symmetric graphene (:): {:.5f} rad\".format(electron.berry_phase(circle)))"
"print(\"Anti-symmetric graphene (0): {:.5f} rad\".format(berry_phase(circle, sub=0)))\n",
"print(\"Anti-symmetric graphene (1): {:.5f} rad\".format(berry_phase(circle, sub=1)))\n",
"print(\"Anti-symmetric graphene (:): {:.5f} rad\".format(berry_phase(circle)))"
]
},
{
Expand All @@ -258,13 +251,13 @@
"dk = 0.0001\n",
"bp = np.empty([4, len(kRs)])\n",
"for i, kR in enumerate(kRs):\n",
" circle = BrillouinZone.param_circle(H_bp, dk, kR, normal, origin)\n",
" bp[0, i] = electron.berry_phase(circle, sub=0)\n",
" circle_other = BrillouinZone.param_circle(\n",
" utils.mathematics.fnorm(H_bp.rcell), dk, kR, normal, origin\n",
" circle = si.BrillouinZone.param_circle(H_bp, dk, kR, normal, origin)\n",
" bp[0, i] = berry_phase(circle, sub=0)\n",
" circle_other = si.BrillouinZone.param_circle(\n",
" si.utils.mathematics.fnorm(H_bp.rcell), dk, kR, normal, origin\n",
" )\n",
" circle.k[:, :] = circle_other.k[:, :]\n",
" bp[1, i] = electron.berry_phase(circle, sub=0)\n",
" bp[1, i] = berry_phase(circle, sub=0)\n",
"plt.plot(kRs, bp[0, :] / np.pi, label=r\"1/Ang\")\n",
"plt.plot(kRs, bp[1, :] / np.pi, label=r\"$b_i$\")\n",
"plt.legend()\n",
Expand Down Expand Up @@ -296,9 +289,9 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.9"
"version": "3.11.7"
}
},
"nbformat": 4,
"nbformat_minor": 2
"nbformat_minor": 4
}
16 changes: 8 additions & 8 deletions docs/tutorials/tutorial_siesta_1.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"\n",
"os.chdir(\"siesta_1\")\n",
"import numpy as np\n",
"from sisl import *\n",
"import sisl as si\n",
"from sisl.viz import merge_plots\n",
"from sisl.viz.processors.math import normalize\n",
"from functools import partial\n",
Expand Down Expand Up @@ -39,10 +39,10 @@
"metadata": {},
"outputs": [],
"source": [
"h2o = Geometry(\n",
"h2o = si.Geometry(\n",
" [[0, 0, 0], [0.8, 0.6, 0], [-0.8, 0.6, 0.0]],\n",
" [Atom(\"O\"), Atom(\"H\"), Atom(\"H\")],\n",
" lattice=Lattice(10, origin=[-5] * 3),\n",
" [si.Atom(\"O\"), si.Atom(\"H\"), si.Atom(\"H\")],\n",
" lattice=si.Lattice(10, origin=[-5] * 3),\n",
")"
]
},
Expand Down Expand Up @@ -144,7 +144,7 @@
"metadata": {},
"outputs": [],
"source": [
"fdf = get_sile(\"RUN.fdf\")\n",
"fdf = si.get_sile(\"RUN.fdf\")\n",
"H = fdf.read_hamiltonian()\n",
"# Create a short-hand to handle the geometry\n",
"h2o = H.geometry\n",
Expand Down Expand Up @@ -285,7 +285,7 @@
" )\n",
"\n",
"\n",
"g = Grid(0.2, lattice=h2o.lattice)\n",
"g = si.Grid(0.2, lattice=h2o.lattice)\n",
"es.sub(0).wavefunction(g)\n",
"integrate(g)\n",
"# g.write('HOMO.cube')\n",
Expand Down Expand Up @@ -314,7 +314,7 @@
"outputs": [],
"source": [
"DM = fdf.read_density_matrix()\n",
"rho = get_sile(\"siesta_1.nc\").read_grid(\"Rho\")"
"rho = si.get_sile(\"siesta_1.nc\").read_grid(\"Rho\")"
]
},
{
Expand Down Expand Up @@ -363,7 +363,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.15"
"version": "3.11.7"
}
},
"nbformat": 4,
Expand Down
16 changes: 8 additions & 8 deletions docs/tutorials/tutorial_siesta_2.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"\n",
"os.chdir(\"siesta_2\")\n",
"import numpy as np\n",
"from sisl import *\n",
"import sisl as si\n",
"import matplotlib.pyplot as plt\n",
"\n",
"%matplotlib inline"
Expand All @@ -37,7 +37,7 @@
"metadata": {},
"outputs": [],
"source": [
"graphene = geom.graphene(1.44)"
"graphene = si.geom.graphene(1.44)"
]
},
{
Expand Down Expand Up @@ -106,7 +106,7 @@
"metadata": {},
"outputs": [],
"source": [
"fdf = get_sile(\"RUN.fdf\")\n",
"fdf = si.get_sile(\"RUN.fdf\")\n",
"H = fdf.read_hamiltonian()\n",
"print(H)"
]
Expand All @@ -128,7 +128,7 @@
"source": [
"E = np.linspace(-6, 4, 500)\n",
"for nk in [21, 41, 61, 81]:\n",
" bz = MonkhorstPack(H, [nk, nk, 1])\n",
" bz = si.MonkhorstPack(H, [nk, nk, 1])\n",
" plt.plot(\n",
" E,\n",
" bz.apply.average.eigenvalue(wrap=lambda ev: ev.DOS(E)),\n",
Expand Down Expand Up @@ -189,7 +189,7 @@
"outputs": [],
"source": [
"# Define the band-structure\n",
"bz = BandStructure(\n",
"bz = si.BandStructure(\n",
" H,\n",
" [[0] * 3, [2.0 / 3, 1.0 / 3, 0], [0.5, 0.5, 0], [1] * 3],\n",
" 400,\n",
Expand Down Expand Up @@ -239,7 +239,7 @@
"es = es.sub(idx_valence)\n",
"\n",
"# Generate a grid encompassing a 2x2 graphene unit-cell\n",
"g = Grid(0.2, lattice=H.geometry.lattice.tile(2, 0).tile(2, 1))\n",
"g = si.Grid(0.2, lattice=H.geometry.lattice.tile(2, 0).tile(2, 1))\n",
"# Calculate the real-space wavefunctions\n",
"es.wavefunction(g)\n",
"\n",
Expand Down Expand Up @@ -275,7 +275,7 @@
"es = H.eigenstate([1.0 / 2, 0, 0])\n",
"idx_valence = (es.eig > 0).nonzero()[0][0] - 1\n",
"es = es.sub(idx_valence)\n",
"g = Grid(0.2, dtype=np.complex128, lattice=H.geometry.lattice.tile(4, 0).tile(4, 1))\n",
"g = si.Grid(0.2, dtype=np.complex128, lattice=H.geometry.lattice.tile(4, 0).tile(4, 1))\n",
"es.wavefunction(g)\n",
"x, y = np.mgrid[: g.shape[0], : g.shape[1]]\n",
"x, y = x * g.dcell[0, 0] + y * g.dcell[1, 0], x * g.dcell[0, 1] + y * g.dcell[1, 1]\n",
Expand Down Expand Up @@ -312,7 +312,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.15"
"version": "3.11.7"
}
},
"nbformat": 4,
Expand Down
4 changes: 2 additions & 2 deletions docs/tutorials/tutorial_siesta_2_ahc.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"outputs": [],
"source": [
"import numpy as np\n",
"from sisl import *\n",
"import sisl as si\n",
"import matplotlib.pyplot as plt\n",
"\n",
"%matplotlib inline"
Expand All @@ -32,7 +32,7 @@
"metadata": {},
"outputs": [],
"source": [
"H = get_sile(\"siesta_2/RUN.fdf\").read_hamiltonian()"
"H = si.get_sile(\"siesta_2/RUN.fdf\").read_hamiltonian()"
]
},
{
Expand Down

0 comments on commit 6a1c670

Please sign in to comment.