Computer Lab: Difference between revisions

From phys824
Jump to navigationJump to search
 
(124 intermediate revisions by 3 users not shown)
Line 1: Line 1:
== Unix Training==
==Installing Python and course related packages==
*[http://www.ee.surrey.ac.uk/Teaching/Unix/ UNIX tutorials for beginners]
*Install [https://www.anaconda.com/products/individual Anaconda]
 
*Install [https://kwant-project.org/install KWANT package]:
== MATLAB Training ==
<pre>
 
conda install -c conda-forge kwant
=== Hands-on tutorials by Instructor ===
</pre>
*[https://wiki.physics.udel.edu/wiki_phys660/images/1/14/Matlab_tutorial_phys660.m Getting started with MATLAB]
*Install [http://www.physics.rutgers.edu/pythtb/ PythTB package]:
*[https://wiki.physics.udel.edu/wiki_phys660/images/2/26/Sparse_matrices.m Sparse matrices]
<pre>
*[https://wiki.physics.udel.edu/wiki_phys660/images/e/e0/Gpu_speedup.m GPU accelerated computing with MATLAB]
pip install pythtb --upgrade
*How to run MATLAB in background on Unix:
</pre>
*Install and test [https://wiki.fysik.dtu.dk/ase/ ASE package]:
<pre>
pip install --upgrade --user ase
python -m ase test
</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>
<pre>
nohup matlab -nojvm < your_script.m > output_messages &
conda install -c conda-forge rise
</pre>
</pre>


=== Hands-on tutorials by MathWorks ===
==JUPYTER notebooks for hands-on practice==
*[http://www.mathworks.com/videos/getting-started-with-matlab-101684.html VIDEO: Getting Started]
* [[Media:Getting_started_python.ipynb|Getting started with Python]]
*[http://www.mathworks.com/videos/working-in-the-development-environment-101632.html VIDEO: Working with MATLAB Desktop]
* [[Media:Getting_started_numpy_scipy.ipynb.txt|Getting started with NumPy and SciPy]]
*[http://www.mathworks.com/products/matlab/examples.html# Code Examples]
* [[Media:Getting_started_matplotlib.ipynb.txt|Getting started with Matplotlib]]
*[http://www.mathworks.com/academia/student_center/tutorials/launchpad.html MATLAB Student Center]
* [[Media:Equilibrium_nanophysics_python.ipynb|Nanostructures in equilibrium with Python]]
*[http://www.mathworks.com/help/matlab/matlab_prog/run-sections-of-programs.html How to run code sections]
* [[Media:Nanostructures_out_of_equilibrium_with_python.ipynb.txt|Nanostructures out of equilibrium with Python]]
*[http://www.mathworks.com/discovery/matlab-gpu.html GPU computing in MATLAB]
* [[Media:getting_started_pythtb.ipynb.txt|Nanostructures in equilibrium with PythTB]]
*[http://blogs.mathworks.com/loren/2012/02/06/using-gpus-in-matlab/ Using GPUs with MATLAB]
* [[Media:Nanostructures_in_equilibrium_with_kwant.ipynb.txt|Nanostructures in equilibrium with KWANT]]
 
* [[Media:Nanostructures_out_of_equilibrium_with_kwant.ipynb.txt|Nanostructures out of equilibrium with KWANT]]
=== Reference ===
*[[MATLAB Brief List of Commands]]
*[http://www.mathworks.com/access/helpdesk/help/helpdesk.html MATLAB Documentation]
* [[Media:matlab_pitfals.pdf | Some Common MATLAB Programming Pitfalls and How to Avoid Them]]
 
=== Books ===
* T. A. Driscoll, [http://epubs.siam.org/doi/book/10.1137/1.9780898717662 Learning MATLAB] (SIAM, Philadelphia, 2009).
* C. Moler, [http://www.mathworks.com/moler/chapters.html Numerical Computing with MATLAB] (SIAM, Philadelphia, 2004).
* C. Moler, [http://www.mathworks.com/moler/exm/chapters.html Experiments with MATLAB] (MathWorks, Natick, 2011).


==Python training==
==Python references==
* [https://wiki.fysik.dtu.dk/ase/python.html Crash course on Python]
* [http://www.scipy-lectures.org/ Scipy lecture notes]
* [[Media:python3handson.pdf|Hands-on Python: A tutorial introduction for beginners]]  
* [https://numpy.org/doc/1.19/user/absolute_beginners.html NumPy: Absolute Beginners Tutorial]
* [http://www-personal.umich.edu/~mejn/computational-physics/ Python programming for physicists]
* [https://numpy.org/doc/1.19/user/quickstart.html NumPy: Quickstart tutorial]
* [https://python.g-node.org/wiki/introductory_material  NumPy: Creating and manipulating numerical data]
* [https://docs.scipy.org/doc/numpy/user/numpy-for-matlab-users.html NumPy for Matlab users]
* [http://www.huyng.com/posts/python-performance-analysis/ Timing Python script performance]
* [http://www.huyng.com/posts/python-performance-analysis/ Timing Python script performance]
* J. M. Stewart, ''Python for Scientists'' (Cambridge University Press, Cambridge, 2014). [https://delcat.worldcat.org/title/python-for-scientists/oclc/885338129&referer=brief_results [PDF]]


=== Using Anaconda Python on ulam===
==KWANT references==
* in order to enable the python environment provided by Anaconda you need to add the following to your <code>~/.bashrc</code>:
*[https://kwant-project.org/doc/1/ KWANT documentation]  
export PATH="/opt/anaconda/1.9.2/bin:$PATH"
*[http://kwant-project.org/doc/kwant-screencast-2014 VIDEO: Introduction to KWANT]
* if you want to use the MKL and NumbaPro add-ons you'll need to request a free academic license from [https://store.continuum.io/cshop/accelerate/ here] and once you receive the license put it in the <code>~/.continuum</code> directory in your home directory
*[https://kwant-project.org/doc/1/tutorial/ Learning KWANT through examples]
* [[Media:speedup_mkl_ulam.png|Speed-up using Anaconda Python + MKL over 1 to 8 cores on ulam]]
*[https://kwant-project.org/doc/1/reference/kwant.solvers Selecting matrix solvers in KWANT]
 
*[https://github.com/jbweston/kwant_tools KWANT tools]
== MATLAB Scripts ==
 
===Matrix representation of single-particle Hamiltonians===
*[[Discretization of 1D Hamiltonian]]
*[[How to put magnetic field into tight-binding Hamiltonian]]
 
===Electron density in nanowires using equilibrium density matrix===
*[http://www.physics.udel.edu/~bnikolic/teaching/phys824/MATLAB/electron_density.m electron_density.m]
 
===DOS of 1D disordered nanowire using eigenvalues + visualization of Anderson localization of eigenfunctions===
*[http://www.physics.udel.edu/~bnikolic/teaching/phys824/MATLAB/disordered_nanowire.m disordered_nanowire.m]
 
===Density of states using equilibrium retarded Green function===
*[[Media:dos_negf_closed.m|dos_negf_closed.m]] computes DOS for finite 1D wire
*[[Media:dos_negf_open.m|dos_negf_open.m]] computes DOS for finite 1D wire attached to one or two macroscopic reservoirs
*[[Media:graphene_dos.m|graphene_dos.m]] computes DOS for a supercell of graphene with periodic boundary conditions
 
===Subband structure of graphene nanoribbons using tight-binding models===
*[http://www.physics.udel.edu/~bnikolic/teaching/phys824/MATLAB/8zgnr.m 8zgnr.m] (poor man's script follows literally the  [http://www.physics.udel.edu/~bnikolic/teaching/phys824/lectures/gnr_and_cnt.pdf lecture slide], so it works only for 8-ZGNR)
 
===Quantum transport in 1D nanowires using NEGF===
*[[Media:negf_formulas_in_pictures.pdf|How to use NEGF matrix formulas: Step-by-step in pictures]]
*[http://www.physics.udel.edu/~bnikolic/teaching/phys824/MATLAB/qt_1d.m qt_1d.m] (computes conductance, as well as total and local density of states for 1D nanowire modeled as tight-binding chain, with possible potential barriers or impurities, attached to two semi-infinite leads)
 
===Tunneling magnetoresistance in tight-binding models of magnetic tunnel junctions using NEGF===
* [[Media:mtj_1d.m|mtj_1d.m]] (computes TMR of F/I/F MTJs modeled using 1D tight-binding chain)
* [[Media:mtj_3d.m|mtj_3d.m]] (computes TMR of F/I/F MTJs modeled using mixed real space and k-space tight-binding model of 3D junctions
 
===Quantum transport in graphene nanostructures using NEGF===
*[[Media:gnr_cond_recursive.m|gnr_cond_recursive.m]],[http://www.physics.udel.edu/~bnikolic/teaching/phys824/MATLAB/bstruct.m bstruct.m], [http://www.physics.udel.edu/~bnikolic/teaching/phys824/MATLAB/blocktosparse.m blocktosparse.m], [http://www.physics.udel.edu/~bnikolic/teaching/phys824/MATLAB/sparsetoblock.m sparsetoblock.m], [http://www.physics.udel.edu/~bnikolic/teaching/phys824/MATLAB/h_zigzag.m h_zigzag.m], [http://www.physics.udel.edu/~bnikolic/teaching/phys824/MATLAB/invnn.m invnn.m], [[Media:Invb.m|Invb.m]]
[http://www.physics.udel.edu/~bnikolic/teaching/phys824/MATLAB/Self.m Self.m], (code to compute the conductance of a finite graphene nanoribbon attached to two semi-infinite graphene electrodes)
 
== MATLAB functions ==
* [http://www.physics.udel.edu/~bnikolic/teaching/phys824/MATLAB/matrix_exp.m matrix_exp.m] (Exponential, or any other function with small changed in the code, of a Hermitian  matrix)
* [http://www.physics.udel.edu/~bnikolic/teaching/phys824/MATLAB/visual_graphene_H.m visual_graphene_H.m] (For a given tight-binding Hamiltonian on the honeycomb lattice, function plots position of carbon atoms and draws blue lines to represent hoppings between them; red circles to represent on-site potential  between them; and cyan lines to represent the periodic boundary conditions; it can be used to test if the tight-binding Hamiltonian of graphene is set correctly); This function calls another three function which should be placed in the same directory (or in the path): [http://www.physics.udel.edu/~bnikolic/teaching/phys824/MATLAB/atomCoord.m atomCoord.m], [http://www.physics.udel.edu/~bnikolic/teaching/phys824/MATLAB/atomPosition.m atomPosition.m], and [http://www.physics.udel.edu/~bnikolic/teaching/phys824/MATLAB/constrainView.m constrainView.m]
* [http://www.physics.udel.edu/~bnikolic/teaching/phys824/MATLAB/self_energy.m self_energy.m] (Self-energy of the semi-infinite ideal metallic lead modeled on the square tight-binding lattice - the code shows how to convert analytical formulas of the lead surface Green function into a working program)
* [[Media:transmission.m|transmission.m]] (Transmission function for 1D tight-binding chain with spin-dependent terms)
 
==Band structure calculations using PythTB package==
*[http://www.physics.rutgers.edu/pythtb/ PythTB Website]
 
==Quantum transport simulations using KWANT package==
* [http://kwant-project.org/ Kwant Website]
* [http://kwant-project.org/doc/kwant-screencast-2014 VIDEO: Introduction to KWANT]
* [http://kwant-project.org/doc/1.0/reference/kwant.solvers#module-kwant.solvers.default Selecting matrix solvers in KWANT]
* [[Conductance of ZGNR]]
* [[Conductance of ZGNR+adatoms=2D topological insulator]]
 
== First-principles electronic structure calculations using DFT within GPAW package==


* [https://molmod.ugent.be/deltacodesdft Delta benchmark of DFT codes]
== Density functional theory with GPAW package==


=== How to run GPAW on ulam===
=== How to run GPAW on ulam===
Line 105: Line 55:


=== Getting started with GPAW ===
=== Getting started with GPAW ===
* [http://www.youtube.com/watch?v=guXoS3Ojd8Q VIDEO Tutorial: Overview of GPAW]
* [https://www.youtube.com/watch?v=4P7ukme5f84 VIDEO Tutorial: Electronic structure calculations with GPAW]
* [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]
Line 146: Line 98:
* [[About k-point sampling]]
* [[About k-point sampling]]


== First-principles electronic transport calculations using NEGF+DFT within GPAW package==
== First-principles quantum transport calculations using NEGF+DFT within GPAW package==


==Theory Background==
===Theory Background===
* [[Media:negf_dft_slide.pdf|Crash course on NEGF+DFT codes]]
* [[Media:negf_dft_slide.pdf|Crash course on NEGF+DFT codes]]
* [https://wiki.fysik.dtu.dk/gpaw/documentation/transport/negftransport.html 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). [http://link.aps.org/doi/10.1103/PhysRevB.85.155140 [PDF]]
* [https://wiki.fysik.dtu.dk/gpaw/documentation/transport/negftransport.html 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). [http://link.aps.org/doi/10.1103/PhysRevB.85.155140 [PDF]]
Line 154: Line 106:
* 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). [https://wiki.physics.udel.edu/wiki_qttg/images/d/dc/Negf_dft_gnr.pdf [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). [https://wiki.physics.udel.edu/wiki_qttg/images/d/dc/Negf_dft_gnr.pdf [PDF]]


==GPAW Exercises==
===GPAW Exercises===
* [[PtH2Pt nanojunction|Pt-<math> \mathrm{H}_2 </math>-Pt nanojunction]].
* [[PtH2Pt nanojunction|Pt-<math> \mathrm{H}_2 </math>-Pt nanojunction]].
* [[Annulene molecule between two graphene nanoribbon electrodes nanojunction]]
* [[Annulene molecule between two graphene nanoribbon electrodes nanojunction]]

Latest revision as of 13:14, 7 September 2022

Installing Python and course related packages

conda install -c conda-forge kwant
pip install pythtb --upgrade
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

Python references

KWANT references

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

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)

GPAW Exercises Related to Midterm Project

References

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]

GPAW Exercises