Commit 7389f941 authored by spiasko's avatar spiasko
Browse files

ex11 gelöst

parent f88897db
......@@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
"execution_count": 16,
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
......@@ -29,7 +29,7 @@
},
{
"cell_type": "code",
"execution_count": 14,
"execution_count": 3,
"metadata": {},
"outputs": [
{
......@@ -64,19 +64,16 @@
"alpha=90\n",
"beta=99.22\n",
"gamma=90\n",
"thespacegroup=14\n",
"thespacegroup='P 21/c'\n",
"print(Spacegroup(thespacegroup))\n",
"\n",
"hfo2 = crystal(symbols=['Hf','O','O'],\n",
" basis=[(0.276,0.04,0.208),(0.074,0.332,0.347),(0.449,0.758,0.480)],\n",
" spacegroup=thespacegroup, \n",
" cellpar=[a, b, c, alpha, beta, gamma])\n",
"#hfo2.write('hfo2.xyz')"
"hfo2 = crystal(['Hf','O','O'],basis=[(0.276,0.04,0.208),(0.074,0.332,0.347),(0.449,0.758,0.480)], \n",
" spacegroup=thespacegroup, cellpar=[a, b, c, alpha, beta, gamma])"
]
},
{
"cell_type": "code",
"execution_count": 12,
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
......@@ -92,13 +89,13 @@
},
{
"cell_type": "code",
"execution_count": 17,
"execution_count": 5,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "173ee9fd9ff14be7a76bdd69a69afbe2",
"model_id": "f9c3ef4efca74690a7d6ac1e4a8d450a",
"version_major": 2,
"version_minor": 0
},
......@@ -133,7 +130,7 @@
},
{
"cell_type": "code",
"execution_count": 18,
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
......@@ -152,7 +149,7 @@
},
{
"cell_type": "code",
"execution_count": 19,
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
......@@ -208,13 +205,13 @@
},
{
"cell_type": "code",
"execution_count": 25,
"execution_count": 9,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "7261855ebc41485c8822834f33016a8d",
"model_id": "7ee7ec2cab1844de870258a5a5674dfc",
"version_major": 2,
"version_minor": 0
},
......@@ -237,29 +234,28 @@
"metadata": {},
"outputs": [],
"source": [
"cell = ase_to_spgcell(ase_atoms=atoms)\n",
"lattice, scaled_positions, numbers = spglib.find_primitive(cell, symprec=1e-5)\n",
"reduced = ase_to_spgcell(cell=(lattice, scaled_positions, numbers),inverse=True)"
"''' \n",
"\n",
" ..TO DO..\n",
"\n",
"'''"
]
},
{
"cell_type": "code",
"execution_count": 28,
"execution_count": 10,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "c0b014720e3d4c09b7430432c38b0056",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"NGLWidget()"
"ename": "NameError",
"evalue": "name 'reduced' is not defined",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-10-e82cf4dbf780>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mnglview\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mshow_ase\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mreduced\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
"\u001b[0;31mNameError\u001b[0m: name 'reduced' is not defined"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
......@@ -279,12 +275,11 @@
"metadata": {},
"outputs": [],
"source": [
"versions = [read(atoms) for atoms in glob('./quartz_alpha*')]\n",
"''' \n",
"\n",
" ..TO DO..\n",
"\n",
"for outer in range(len(versions)-1):\n",
" for inner in range(outer+1,len(versions)):\n",
" print('Comparing: ',outer,inner)\n",
" print('Equivalent: ',a_equiv_b(versions[outer],versions[inner]))"
"'''"
]
}
],
......@@ -304,7 +299,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.1"
"version": "3.6.7"
}
},
"nbformat": 4,
......
%% Cell type:code id: tags:
``` python
import itertools
import numpy as np
from numpy.linalg import norm
import spglib
from glob import glob
from ase import Atoms
from ase.io import read
from ase.spacegroup import crystal
from ase.spacegroup import Spacegroup
from ase.data import atomic_numbers, atomic_names
import nglview
```
%% Cell type:markdown id: tags:
## Crystallographic point groups
%% Cell type:code id: tags:
``` python
a=5.117
b=5.175
c=5.291
alpha=90
beta=99.22
gamma=90
thespacegroup=14
thespacegroup='P 21/c'
print(Spacegroup(thespacegroup))
hfo2 = crystal(symbols=['Hf','O','O'],
basis=[(0.276,0.04,0.208),(0.074,0.332,0.347),(0.449,0.758,0.480)],
spacegroup=thespacegroup,
cellpar=[a, b, c, alpha, beta, gamma])
#hfo2.write('hfo2.xyz')
hfo2 = crystal(['Hf','O','O'],basis=[(0.276,0.04,0.208),(0.074,0.332,0.347),(0.449,0.758,0.480)],
spacegroup=thespacegroup, cellpar=[a, b, c, alpha, beta, gamma])
```
%%%% Output: stream
14 P 21/c
setting 1
centrosymmetric 1
primitive vectors
1.0000000000 0.0000000000 0.0000000000
0.0000000000 1.0000000000 0.0000000000
0.0000000000 0.0000000000 1.0000000000
reciprocal vectors
1 0 0
0 1 0
0 0 1
1 subtranslations
0.0000000000 0.0000000000 0.0000000000
2 symmetry operations (rot+trans)
1 0 0 0 1 0 0 0 1 0.0000000000 0.0000000000 0.0000000000
-1 0 0 0 1 0 0 0 -1 0.0000000000 0.5000000000 0.5000000000
%% Cell type:code id: tags:
``` python
bondatoms = []
symbols = hfo2.get_chemical_symbols()
for i in range(len(hfo2)):
for j in range(i):
if (symbols[i] == 'Hf' and symbols[j] == 'O' and hfo2.get_distance(i, j) < 2.6):
bondatoms.append((i, j))
elif (symbols[i] == 'O' and symbols[j] == 'Hf' and hfo2.get_distance(i, j) < 2.6):
bondatoms.append((i, j))
```
%% Cell type:code id: tags:
``` python
nglview.show_ase(hfo2)
```
%%%% Output: display_data
%% Cell type:markdown id: tags:
Questions:
-how many atoms are contained in the unit cell?
-compute the volume of the unit cell
%% Cell type:markdown id: tags:
##
%% Cell type:code id: tags:
``` python
def ase_to_spgcell(ase_atoms=None, cell=None, inverse=False):
if not inverse:
assert ase_atoms is not None
return (ase_atoms.get_cell(),
ase_atoms.get_scaled_positions(),
ase_atoms.get_atomic_numbers())
else:
assert cell is not None
return Atoms(cell=cell[0],
scaled_positions=cell[1],
numbers=cell[2])
```
%% Cell type:code id: tags:
``` python
def a_equiv_b(a,b):
"""Function that identifies whether two crystals are equivalent"""
# getting symmetry datasets for both crystals
cryst_a = spglib.get_symmetry_dataset(ase_to_spgcell(ase_atoms=a), symprec=1e-5, angle_tolerance=-1.0, hall_number=0)
cryst_b = spglib.get_symmetry_dataset(ase_to_spgcell(ase_atoms=b), symprec=1e-5, angle_tolerance=-1.0, hall_number=0)
samecell = np.allclose(cryst_a['std_lattice'], cryst_b['std_lattice'], atol=1e-5)
samenatoms = len(cryst_a['std_positions']) == len(cryst_b['std_positions'])
samespg = cryst_a['number'] == cryst_b['number']
def test_rotations_translations(cryst_a, cryst_b, repeat):
cell = cryst_a['std_lattice']
pristine = crystal('Mg', [(0, 0., 0.)],
spacegroup=int(cryst_a['number']),
cellpar=[cell[0]/repeat[0], cell[1]/repeat[1], cell[2]/repeat[2]]).repeat(repeat)
sym_set_p = spglib.get_symmetry_dataset(ase_to_spgcell(ase_atoms=pristine), symprec=1e-5,
angle_tolerance=-1.0, hall_number=0)
for _,trans in enumerate(zip(sym_set_p['rotations'], sym_set_p['translations'])):
pnew=(np.matmul(trans[0],cryst_a['std_positions'].T).T + trans[1]) % 1.0
fulln = np.concatenate([cryst_a['std_types'][:, None], pnew], axis=1)
fullb = np.concatenate([cryst_b['std_types'][:, None], cryst_b['std_positions']], axis=1)
sorted_n = np.array(sorted([ list(row) for row in list(fulln) ]))
sorted_b = np.array(sorted([ list(row) for row in list(fullb) ]))
if np.allclose(sorted_n, sorted_b, atol=1e-5):
return True
return False
if samecell and samenatoms and samespg:
cell = cryst_a['std_lattice']
rng1 = range(1, int(norm(cell[0])/2.))
rng2 = range(1, int(norm(cell[1])/2.))
rng3 = range(1, int(norm(cell[2])/2.))
for repeat in itertools.product(rng1, rng2, rng3):
if test_rotations_translations(cryst_a, cryst_b, repeat):
return True
return False
```
%% Cell type:markdown id: tags:
## Task 1
%% Cell type:code id: tags:
``` python
atoms = read('./quartz_alpha.xyz')
nglview.show_ase(atoms)
```
%%%% Output: display_data
%% Cell type:code id: tags:
``` python
cell = ase_to_spgcell(ase_atoms=atoms)
lattice, scaled_positions, numbers = spglib.find_primitive(cell, symprec=1e-5)
reduced = ase_to_spgcell(cell=(lattice, scaled_positions, numbers),inverse=True)
'''
..TO DO..
'''
```
%% Cell type:code id: tags:
``` python
nglview.show_ase(reduced)
```
%%%% Output: display_data
%%%% Output: error
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-10-e82cf4dbf780> in <module>
----> 1 nglview.show_ase(reduced)
NameError: name 'reduced' is not defined
%% Cell type:markdown id: tags:
## Task 2
%% Cell type:code id: tags:
``` python
versions = [read(atoms) for atoms in glob('./quartz_alpha*')]
'''
..TO DO..
for outer in range(len(versions)-1):
for inner in range(outer+1,len(versions)):
print('Comparing: ',outer,inner)
print('Equivalent: ',a_equiv_b(versions[outer],versions[inner]))
'''
```
......
......@@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
"execution_count": 16,
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
......@@ -29,7 +29,7 @@
},
{
"cell_type": "code",
"execution_count": 14,
"execution_count": 3,
"metadata": {},
"outputs": [
{
......@@ -58,22 +58,22 @@
}
],
"source": [
"a=...\n",
"b=...\n",
"c=...\n",
"alpha=...\n",
"beta=...\n",
"gamma=...\n",
"thespacegroup=...\n",
"a=5.117\n",
"b=5.175\n",
"c=5.291\n",
"alpha=90\n",
"beta=99.22\n",
"gamma=90\n",
"thespacegroup='P 21/c'\n",
"print(Spacegroup(thespacegroup))\n",
"\n",
"hfo2 = crystal(['...','...','...'],basis=[(...,...,...),(...,...,...),(...,...,...)], \n",
"hfo2 = crystal(['Hf','O','O'],basis=[(0.276,0.04,0.208),(0.074,0.332,0.347),(0.449,0.758,0.480)], \n",
" spacegroup=thespacegroup, cellpar=[a, b, c, alpha, beta, gamma])"
]
},
{
"cell_type": "code",
"execution_count": 12,
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
......@@ -89,13 +89,13 @@
},
{
"cell_type": "code",
"execution_count": 17,
"execution_count": 5,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "173ee9fd9ff14be7a76bdd69a69afbe2",
"model_id": "f9c3ef4efca74690a7d6ac1e4a8d450a",
"version_major": 2,
"version_minor": 0
},
......@@ -130,7 +130,7 @@
},
{
"cell_type": "code",
"execution_count": 18,
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
......@@ -149,7 +149,7 @@
},
{
"cell_type": "code",
"execution_count": 19,
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
......@@ -205,13 +205,13 @@
},
{
"cell_type": "code",
"execution_count": 25,
"execution_count": 9,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "7261855ebc41485c8822834f33016a8d",
"model_id": "7ee7ec2cab1844de870258a5a5674dfc",
"version_major": 2,
"version_minor": 0
},
......@@ -243,22 +243,19 @@
},
{
"cell_type": "code",
"execution_count": 28,
"execution_count": 10,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "c0b014720e3d4c09b7430432c38b0056",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"NGLWidget()"
"ename": "NameError",
"evalue": "name 'reduced' is not defined",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-10-e82cf4dbf780>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mnglview\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mshow_ase\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mreduced\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
"\u001b[0;31mNameError\u001b[0m: name 'reduced' is not defined"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
......@@ -302,7 +299,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.1"
"version": "3.6.7"
}
},
"nbformat": 4,
......
%% Cell type:code id: tags:
``` python
import itertools
import numpy as np
from numpy.linalg import norm
import spglib
from glob import glob
from ase import Atoms
from ase.io import read
from ase.spacegroup import crystal
from ase.spacegroup import Spacegroup
from ase.data import atomic_numbers, atomic_names
import nglview
```
%% Cell type:markdown id: tags:
## Crystallographic point groups
%% Cell type:code id: tags:
``` python
a=...
b=...
c=...
alpha=...
beta=...
gamma=...
thespacegroup=...
a=5.117
b=5.175
c=5.291
alpha=90
beta=99.22
gamma=90
thespacegroup='P 21/c'
print(Spacegroup(thespacegroup))
hfo2 = crystal(['...','...','...'],basis=[(...,...,...),(...,...,...),(...,...,...)],
hfo2 = crystal(['Hf','O','O'],basis=[(0.276,0.04,0.208),(0.074,0.332,0.347),(0.449,0.758,0.480)],
spacegroup=thespacegroup, cellpar=[a, b, c, alpha, beta, gamma])
```
%%%% Output: stream
14 P 21/c
setting 1
centrosymmetric 1
primitive vectors
1.0000000000 0.0000000000 0.0000000000
0.0000000000 1.0000000000 0.0000000000
0.0000000000 0.0000000000 1.0000000000
reciprocal vectors
1 0 0
0 1 0
0 0 1
1 subtranslations
0.0000000000 0.0000000000 0.0000000000
2 symmetry operations (rot+trans)
1 0 0 0 1 0 0 0 1 0.0000000000 0.0000000000 0.0000000000
-1 0 0 0 1 0 0 0 -1 0.0000000000 0.5000000000 0.5000000000
%% Cell type:code id: tags:
``` python
bondatoms = []
symbols = hfo2.get_chemical_symbols()
for i in range(len(hfo2)):
for j in range(i):
if (symbols[i] == 'Hf' and symbols[j] == 'O' and hfo2.get_distance(i, j) < 2.6):
bondatoms.append((i, j))
elif (symbols[i] == 'O' and symbols[j] == 'Hf' and hfo2.get_distance(i, j) < 2.6):
bondatoms.append((i, j))
```
%% Cell type:code id: tags:
``` python
nglview.show_ase(hfo2)
```
%%%% Output: display_data
%% Cell type:markdown id: tags:
Questions:
-how many atoms are contained in the unit cell?
-compute the volume of the unit cell
%% Cell type:markdown id: tags:
##
%% Cell type:code id: tags:
``` python
def ase_to_spgcell(ase_atoms=None, cell=None, inverse=False):
if not inverse:
assert ase_atoms is not None
return (ase_atoms.get_cell(),
ase_atoms.get_scaled_positions(),
ase_atoms.get_atomic_numbers())
else:
assert cell is not None
return Atoms(cell=cell[0],
scaled_positions=cell[1],
numbers=cell[2])
```
%% Cell type:code id: tags:
``` python
def a_equiv_b(a,b):
"""Function that identifies whether two crystals are equivalent"""
# getting symmetry datasets for both crystals
cryst_a = spglib.get_symmetry_dataset(ase_to_spgcell(ase_atoms=a), symprec=1e-5, angle_tolerance=-1.0, hall_number=0)
cryst_b = spglib.get_symmetry_dataset(ase_to_spgcell(ase_atoms=b), symprec=1e-5, angle_tolerance=-1.0, hall_number=0)
samecell = np.allclose(cryst_a['std_lattice'], cryst_b['std_lattice'], atol=1e-5)
samenatoms = len(cryst_a['std_positions']) == len(cryst_b['std_positions'])
samespg = cryst_a['number'] == cryst_b['number']
def test_rotations_translations(cryst_a, cryst_b, repeat):
cell = cryst_a['std_lattice']
pristine = crystal('Mg', [(0, 0., 0.)],
spacegroup=int(cryst_a['number']),
cellpar=[cell[0]/repeat[0], cell[1]/repeat[1], cell[2]/repeat[2]]).repeat(repeat)
sym_set_p = spglib.get_symmetry_dataset(ase_to_spgcell(ase_atoms=pristine), symprec=1e-5,
angle_tolerance=-1.0, hall_number=0)
for _,trans in enumerate(zip(sym_set_p['rotations'], sym_set_p['translations'])):
pnew=(np.matmul(trans[0],cryst_a['std_positions'].T).T + trans[1]) % 1.0
fulln = np.concatenate([cryst_a['std_types'][:, None], pnew], axis=1)
fullb = np.concatenate([cryst_b['std_types'][:, None], cryst_b['std_positions']], axis=1)
sorted_n = np.array(sorted([ list(row) for row in list(fulln) ]))
sorted_b = np.array(sorted([ list(row) for row in list(fullb) ]))
if np.allclose(sorted_n, sorted_b, atol=1e-5):
return True
return False
if samecell and samenatoms and samespg:
cell = cryst_a['std_lattice']
rng1 = range(1, int(norm(cell[0])/2.))
rng2 = range(1, int(norm(cell[1])/2.))
rng3 = range(1, int(norm(cell[2])/2.))
for repeat in itertools.product(rng1, rng2, rng3):
if test_rotations_translations(cryst_a, cryst_b, repeat):
return True
return False
```
%% Cell type:markdown id: tags:
## Task 1
%% Cell type:code id: tags:
``` python
atoms = read('./quartz_alpha.xyz')
nglview.show_ase(atoms)
```
%%%% Output: display_data
%% Cell type:code id: tags:
``` python
'''
..TO DO..
'''
```
%% Cell type:code id: tags:
``` python
nglview.show_ase(reduced)
```
%%%% Output: display_data
%%%% Output: error
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-10-e82cf4dbf780> in <module>
----> 1 nglview.show_ase(reduced)
NameError: name 'reduced' is not defined
%% Cell type:markdown id: tags:
## Task 2
%% Cell type:code id: tags:
``` python
'''
..TO DO..
'''
```
......
{
"cells": [
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"from matplotlib.patches import Rectangle\n",
"import matplotlib.pyplot as plt"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Theoretical background\n",
"\n",
"$\\Psi_k = \\frac{1}{\\sqrt{N}} \\sum_j e^{(j\\,k\\cdot r_j)} \\, \\phi_j = \\frac{1}{\\sqrt{N}} \\sum_j c_k(r_j) \\, \\phi_j$\n",
"\n",
"Notation:\n",
"$[\\,]_{nm}$ = matrix of dimensions $n\\times m$\n",
"\n",
"- h = $[\\phi_0]_{nn}$\n",
"- t = $[\\phi_{+1}]_{mnn}, \\ m=1$ for first nn hopping\n",
"\n",
"For first nn:\n",
"\n",
"- $c(k) = e^{(j\\,k\\cdot R)} \\, ,k=(0,0,0)...(2\\pi,0,0) \\, , R=(1,0,0) $\n",
"\n",
"- $[h(k)]_{nn} = [h]_{nn} + c(k) \\cdot [t]_{0nn} + (c(k) \\cdot [t]_{0nn})^H$\n",
"\n",
"- $E(k)_n=eigvalsh([h(k)]_{nn})$"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [],
"source": [
"def bands(h,t,K):\n",
" '''\n",
" input:\n",
" h = [\\phi_0]_nn\n",
" t = [\\phi_1]_mnn \n",
" variables:\n",
" \n",
" '''\n",
" kpts = np.linspace(0,K,300)\n",
" E = np.zeros((len(kpts),len(h)))\n",
" R = [1,0,0]\n",
" for k, kpt in enumerate(kpts):\n",
" c_k = np.exp(1j*2*np.pi*np.dot(R,[kpt,0,0]))\n",
" h_k = h + np.sum(c_k*t,axis=0) + np.conj(np.sum(c_k*t,axis=0))\n",
" E[k] = np.linalg.eigvalsh(h_k)\n",
" return kpts,E"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"def make_ht(e,tau):\n",
" dim = e.ndim\n",
" if dim>0:\n",
" dim = len(e)\n",
" h = np.zeros((dim,dim),complex)\n",
" t = np.zeros((dim,dim),complex)\n",
" h.flat[::dim+1]=e\n",
" h.flat[1::dim+1]=tau[0]\n",
" h.flat[dim::dim+1]=np.conj(tau[0])\n",
" t[-1,0]=tau[1]\n",
" else:\n",
" h = np.array(e).reshape(1,1)\n",
" t = np.array(tau).reshape(1,1)\n",
" return h,np.expand_dims(t,0)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"def visulize(ax,h,t,replica=5):\n",
" \n",
" import matplotlib.cm as cm\n",
" colors = cm.hot(np.diag(h).real)\n",
" colors = np.tile(colors,(replica,1))\n",
" \n",
" dim = len(h)\n",
" if dim>1:\n",
" uc = np.arange(dim)*1/abs(h[0,1].real)\n",
" colors = cm.hot(np.diag(h).real)\n",
" colors = np.tile(colors,(replica,1))\n",
" a = 1/abs(t[0,-1,0].real)+1/abs(h[0,1].real)\n",
" atoms = [uc[i]+(j*a) for j in range(replica) for i in range(dim)]\n",
" else:\n",
" uc = 0\n",
" a = 1/abs(t[0,-1,0].real)\n",
" atoms = [uc+(j*a) for j in range(replica)]\n",
" rect = Rectangle((-1/abs(2*t[0,-1,0].real),-0.25),a,0.5,\n",
" linewidth=1,edgecolor='r',facecolor='none')\n",
" ax.add_patch(rect)\n",
" ax.set_ylim((-1,1))\n",
" ax.scatter(atoms,np.zeros(dim*5),100,c=colors)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Do not run\n",
"\n",
"example 0:\n",
"\n",
" 0.1 0.1 \n",
"... | x | x | x | ...\n",
" \n",
"tau=np.array((0.2)), 0.2 = inter-cell hopping term <br>\n",
"e=np.array((0.1)), 0.1 = energy of atom <br>\n",
"\n",
"example 1:\n",
"\n",
" 0.2 0.1 0.2 0.1 0.2 \n",
"... | x x | x x | x x |...\n",