Computer Lab: Difference between revisions
From phys824
Jump to navigationJump to search
| (28 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
==Installing Python and course related packages== | ==Installing Python and course related packages== | ||
*Install [https://www.anaconda.com/products/individual Anaconda] | *Install [https://www.anaconda.com/products/individual Anaconda] | ||
*Install [https://kwant-project.org/install KWANT package]: | *Install [https://kwant-project.org/install KWANT package]: | ||
<pre> | <pre> | ||
| Line 18: | Line 14: | ||
python -m ase test | python -m ase test | ||
</pre> | </pre> | ||
* | *[https://wiki.fysik.dtu.dk/gpaw/ GPAW] package can be easily installed using Anaconda on [https://anaconda.org/conda-forge/gpaw Linux] or [https://wiki.fysik.dtu.dk/gpaw/platforms/MacOSX/anaconda.html#anaconda MacOS] | ||
*If you want to add [https://rise.readthedocs.io/en/stable/ RISE] package for Jupyter notebooks, execute: | |||
<pre> | |||
conda install -c conda-forge rise | |||
</pre> | |||
==JUPYTER notebooks for hands-on practice== | ==JUPYTER notebooks for hands-on practice== | ||
* [[Media:Getting_started_python.ipynb | * [[Media:Getting_started_python.ipynb|Getting started with Python]] | ||
* [[Media:Getting_started_numpy_scipy.ipynb.txt|Getting started with NumPy and SciPy]] | * [[Media:Getting_started_numpy_scipy.ipynb.txt|Getting started with NumPy and SciPy]] | ||
* [[Media:Getting_started_matplotlib.ipynb.txt|Getting started with Matplotlib]] | * [[Media:Getting_started_matplotlib.ipynb.txt|Getting started with Matplotlib]] | ||
* [[Media:Equilibrium_nanophysics_python.ipynb|Nanostructures in equilibrium with Python]] | * [[Media:Equilibrium_nanophysics_python.ipynb|Nanostructures in equilibrium with Python]] | ||
* [[Media:getting_started_pythtb.ipynb.txt|Nanostructures in equilibrium with PythTB]] | |||
* [[Media:Nanostructures_out_of_equilibrium_with_python.ipynb.txt|Nanostructures out of equilibrium with Python]] | * [[Media:Nanostructures_out_of_equilibrium_with_python.ipynb.txt|Nanostructures out of equilibrium with Python]] | ||
* [[Media:Nanostructures_in_equilibrium_with_kwant.ipynb.txt|Nanostructures in equilibrium with KWANT]] | * [[Media:Nanostructures_in_equilibrium_with_kwant.ipynb.txt|Nanostructures in equilibrium with KWANT]] | ||
* [[Media:Nanostructures_out_of_equilibrium_with_kwant.ipynb | * [[Media:Nanostructures_out_of_equilibrium_with_kwant.ipynb|Nanostructures out of equilibrium with KWANT]] | ||
* [[Media:superconducting_junctions_with_kwant.ipynb|Superconducting nanostructures with KWANT]] | |||
==JUPYTER notebooks tips and tricks== | |||
*Force Jupyter notebook to display all outputs of a give cell (and not just the last one as default): | |||
<pre> | |||
from IPython.core.interactiveshell import InteractiveShell | |||
InteractiveShell.ast_node_interactivity = "all" | |||
</pre> | |||
*How do you know that Jupyter notebook is running: | |||
**'''Cell Number Indicator:''' When a cell is actively executing, the input prompt on the left side of the cell will display an asterisk In [*] instead of a number. Once the execution is complete, the asterisk will be replaced by a sequential number In [1], In [2], etc. | |||
**'''Kernel Status Indicator:''' In the top-right corner of the Jupyter Notebook interface, there is a small circle. This circle indicates the kernel's status: | |||
***Solid/Grey: The kernel is busy, meaning a cell is currently executing. | |||
***Empty/White: The kernel is idle, meaning no cells are currently executing. | |||
**'''Executing''' this command will display a list of all running Jupyter Notebook servers, including their URLs and the ports they are using. | |||
<pre> | |||
jupyter notebook list | |||
</pre> | |||
==Python references== | ==Python references== | ||
* [ | * J. M. Stewart and M. Mommert, ''Python for Scientists'' (Cambridge University Press, Cambridge, 2023). [https://www.cambridge.org/core/books/python-for-scientists/F3921BF92798B4EE46A9E904741EFB91 [PDF]] + [https://www.cambridge.org/rs/universitypress/subjects/mathematics/computational-science/python-scientists-3rd-edition?format=PB#resources Jupyter notebooks for each Chapter] | ||
* [https://lectures.scientific-python.org/ Scipy lecture notes] | |||
* [https://numpy.org/doc/1.19/user/absolute_beginners.html NumPy: Absolute Beginners Tutorial] | * [https://numpy.org/doc/1.19/user/absolute_beginners.html NumPy: Absolute Beginners Tutorial] | ||
* [https://numpy.org/doc/1.19/user/quickstart.html NumPy: Quickstart tutorial] | * [https://numpy.org/doc/1.19/user/quickstart.html NumPy: Quickstart tutorial] | ||
* [https://docs.scipy.org/doc/numpy/user/numpy-for-matlab-users.html NumPy for Matlab users] | * [https://docs.scipy.org/doc/numpy/user/numpy-for-matlab-users.html NumPy for Matlab users] | ||
* | * Timing Python script performance: | ||
<pre> | |||
def fibonacci(n): | |||
"""Calculate the n-th Fibonacci number using recursion.""" | |||
if n <= 0: | |||
return 0 | |||
elif n == 1: | |||
return 1 | |||
else: | |||
return fibonacci(n - 1) + fibonacci(n - 2) | |||
import time | |||
start = time.perf_counter() | |||
result = fibonacci(40) | |||
end = time.perf_counter() | |||
elapsed = end - start | |||
print(f'Time taken: {elapsed:.6f} seconds') | |||
</pre> | |||
==KWANT references== | ==KWANT references== | ||
| Line 56: | Line 89: | ||
=== Getting started with GPAW === | === Getting started with GPAW === | ||
* [https://www.youtube.com/watch?v=4P7ukme5f84 VIDEO Tutorial: Electronic structure calculations with GPAW] | * [https://www.youtube.com/watch?v=4P7ukme5f84 VIDEO Tutorial: Electronic structure calculations with GPAW] | ||
* [http://www.youtube.com/watch?v=guXoS3Ojd8Q VIDEO Tutorial: | * [http://www.youtube.com/watch?v=guXoS3Ojd8Q VIDEO Tutorial: Short overview of GPAW] | ||
* [https://youtu.be/-z2M3g-o_sA VIDEO Longer overview of GPAW] | |||
* [http://www.youtube.com/watch?v=hUVu7Kcs7Tc VIDEO Tutorial: CO molecule] | * [http://www.youtube.com/watch?v=hUVu7Kcs7Tc VIDEO Tutorial: CO molecule] | ||
** [https://wiki.fysik.dtu.dk/gpaw/tutorials/plotting/plot_wave_functions.html Plotting CO wavefunction] | ** [https://wiki.fysik.dtu.dk/gpaw/tutorials/plotting/plot_wave_functions.html Plotting CO wavefunction] | ||
Latest revision as of 13:10, 3 December 2025
Installing Python and course related packages
- Install Anaconda
- Install KWANT package:
conda install -c conda-forge kwant
- Install PythTB package:
pip install pythtb --upgrade
- Install and test ASE package:
pip install --upgrade --user ase python -m ase test
- GPAW package can be easily installed using Anaconda on Linux or MacOS
- If you want to add RISE package for Jupyter notebooks, execute:
conda install -c conda-forge rise
JUPYTER notebooks for hands-on practice
- Getting started with Python
- Getting started with NumPy and SciPy
- Getting started with Matplotlib
- Nanostructures in equilibrium with Python
- Nanostructures in equilibrium with PythTB
- Nanostructures out of equilibrium with Python
- Nanostructures in equilibrium with KWANT
- Nanostructures out of equilibrium with KWANT
- Superconducting nanostructures with KWANT
JUPYTER notebooks tips and tricks
- Force Jupyter notebook to display all outputs of a give cell (and not just the last one as default):
from IPython.core.interactiveshell import InteractiveShell InteractiveShell.ast_node_interactivity = "all"
- How do you know that Jupyter notebook is running:
- Cell Number Indicator: When a cell is actively executing, the input prompt on the left side of the cell will display an asterisk In [*] instead of a number. Once the execution is complete, the asterisk will be replaced by a sequential number In [1], In [2], etc.
- Kernel Status Indicator: In the top-right corner of the Jupyter Notebook interface, there is a small circle. This circle indicates the kernel's status:
- Solid/Grey: The kernel is busy, meaning a cell is currently executing.
- Empty/White: The kernel is idle, meaning no cells are currently executing.
- Executing this command will display a list of all running Jupyter Notebook servers, including their URLs and the ports they are using.
jupyter notebook list
Python references
- J. M. Stewart and M. Mommert, Python for Scientists (Cambridge University Press, Cambridge, 2023). [PDF] + Jupyter notebooks for each Chapter
- Scipy lecture notes
- NumPy: Absolute Beginners Tutorial
- NumPy: Quickstart tutorial
- NumPy for Matlab users
- Timing Python script performance:
def fibonacci(n):
"""Calculate the n-th Fibonacci number using recursion."""
if n <= 0:
return 0
elif n == 1:
return 1
else:
return fibonacci(n - 1) + fibonacci(n - 2)
import time
start = time.perf_counter()
result = fibonacci(40)
end = time.perf_counter()
elapsed = end - start
print(f'Time taken: {elapsed:.6f} seconds')
KWANT references
- KWANT documentation
- VIDEO: Introduction to KWANT
- Learning KWANT through examples
- Selecting matrix solvers in KWANT
- KWANT tools
Density functional theory with GPAW package
How to run GPAW on ulam
GPAW has been installed on ulam with the OS installed python 2.6.
- in order to use the serial version of GPAW type:
python your_gpaw_program.py
- in order to use the parallel version of gpaw use the following syntax (replace 8 with the number of cores you want to use):
mpirun -np 8 gpaw-python_openmpi your_gpaw_program.py
Getting started with GPAW
- VIDEO Tutorial: Electronic structure calculations with GPAW
- VIDEO Tutorial: Short overview of GPAW
- VIDEO Longer overview of GPAW
- VIDEO Tutorial: CO molecule
- Plotting CO wavefunction
- relax.py used in VIDEO Tutorial:
from ase import Atoms
from ase.io import write
from ase.optimize import QuasiNewton
from gpaw import GPAW
d = 1.10 # Starting guess for the bond length
atoms = Atoms('CO', positions=((0, 0, 0),
(0, 0, d)), pbc=False)
atoms.center(vacuum=4.0)
write('CO.cif', atoms)
calc = GPAW(h=0.20, xc='PBE', txt='CO_relax.txt')
atoms.set_calculator(calc)
relax = QuasiNewton(atoms, trajectory='CO.traj', logfile='qn.log')
relax.run(fmax=0.05)
- ASE tutorials
- Basics of GPAW calculations
- Band structure of Ni plotted in three steps
- Lattice constant, DOS, and band structure of Si
- STM simulations
GPAW Exercises Related to Midterm Project
- Band structure of bulk graphene
- Subband structure of graphene nanoribbons
- Subband structure of carbon nanotubes
References
- Electronic structure calculations with GPAW: a real-space implementation of the projector augmented-wave method, J. Phys.: Condens. Matter 22, 253202 (2010). [PDF]
- Parameters selection in GPAW scripts
- LCAO basis set in GPAW
- Parameters selection in ASE to define atomic coordinates
- Density of States in GPAW
- About k-point sampling
First-principles quantum transport calculations using NEGF+DFT within GPAW package
Theory Background
- Crash course on NEGF+DFT codes
- NEGF+DFT within GPAW - see also J. Chen, K. S. Thygesen, and K. W. Jacobsen, Ab initio nonequilibrium quantum transport and forces with the real-space projector augmented wave method, Phys. Rev. B 85, 155140 (2012). [PDF]
- M. Strange, I. S. Kristensen, K. S. Thygesen, and K. W. Jacobsen, Benchmark density functional theory calculations for nanoscale conductance, J. Chem. Phys. 128, 114714 (2008). [PDF]
- D. A. Areshkin and B. K. Nikolić, Electron density and transport in top-gated graphene nanoribbon devices: First-principles Green function algorithms for systems containing a large number of atoms, Phys. Rev. B 81, 155450 (2010). [PDF]