Computer Lab: Difference between revisions

From phys824
Jump to navigationJump to search
No edit summary
Line 15: Line 15:
</pre>
</pre>


== MATLAB Training ==
==JUPYTER notebooks for hands-on computer lab sessions==


=== Hands-on tutorials by Instructor ===
*[[Media:Matlab_first_tutorial_bkn.m|First steps with MATLAB]]
*[https://wiki.physics.udel.edu/wiki_phys660/images/2/26/Sparse_matrices.m Sparse matrices]
*[https://wiki.physics.udel.edu/wiki_phys660/images/e/e0/Gpu_speedup.m GPU accelerated computing with MATLAB]
*How to run MATLAB in background on Unix:
<pre>
nohup matlab -nojvm < your_script.m > output_messages &
</pre>


=== Hands-on tutorials by MathWorks ===
==Python references==
*[http://www.mathworks.com/videos/getting-started-with-matlab-101684.html VIDEO: Getting Started]
* 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 from UD library])
*[http://www.mathworks.com/videos/working-in-the-development-environment-101632.html VIDEO: Working with MATLAB Desktop]
*[http://www.mathworks.com/products/matlab/examples.html# Code Examples]
*[http://www.mathworks.com/help/matlab/matlab_prog/run-sections-of-programs.html How to run code sections]
*[http://www.mathworks.com/discovery/matlab-gpu.html GPU computing in MATLAB]
*[http://blogs.mathworks.com/loren/2012/02/06/using-gpus-in-matlab/ GPU computing benchmarks with MATLAB]
 
=== 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).
 
=== Reference ===
*[[MATLAB Brief List of Commands]]
*[http://www.mathworks.com/access/helpdesk/help/helpdesk.html Official MATLAB Documentation]
* [[Media:matlab_pitfals.pdf | Common MATLAB programming pitfalls and how to avoid them]]
 
==Python training==
 
===Hands-on tutorials by the Instructor (Dr. Marko D. Petrovic)===
* [[Media:01 introduction.ipynb|Jupyter Notebook: First steps with Python]]
* [https://drive.google.com/file/d/1dACmfS5hkeeP0TDSQLcauA_EnA3dTBau/view?usp=sharing Jupyter Notebook: Functions and Objects in Python]
* [https://drive.google.com/file/d/1eLcGXrEnorozG6A9PdG73wM2yG0wZFxM/view?usp=sharing Jupyter Notebook: Kwant Introduction]
* [https://drive.google.com/file/d/1AXFtI5gr4ZmebGdNCJFWt7IMOyrb2c69/view?usp=sharing PDF: Kwant Introduction]
* [https://drive.google.com/file/d/1Qas3CFQbfnsXx01Z4T9ACMo65ROOGMoK/view?usp=sharing Jupyter Notebook: Kwant Honeycomb Lattice]
* [https://drive.google.com/file/d/1n0d1eclD70Q0QOGhw1avMQg8xkKuk0yp/view?usp=sharing PDF: Kwant Honeycomb Lattice]
* [https://drive.google.com/file/d/1jQ_wA4yacLi-1qDS6zAxLXV7jMQ2Vkoo/view?usp=sharing Jupyter Notebook: Kwant Solvers]
* [https://drive.google.com/file/d/13nQ4odWtBHoxbnLxhqxX45SuZ3nK71MT/view?usp=sharing PDF: Kwant Solvers]
 
===Other tutorials===
* [http://www.scipy-lectures.org/ Scipy lecture notes]
* [http://www.scipy-lectures.org/ Scipy lecture notes]
* [https://www.labri.fr/perso/nrougier/from-python-to-numpy From Python to NumPy]
* [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]
* [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 from UD library])


=== Using Anaconda Python===
==KWANT references==
* [https://www.continuum.io/downloads Installation of Anaconda Python]
*[https://kwant-project.org/doc/1/ KWANT documentation]  
* [https://www.mail-archive.com/kwant-discuss@kwant-project.org/msg00755.html Conda packages for KWANT]
*[https://kwant-project.org/doc/1/reference/kwant.solvers Selecting matrix solvers in KWANT]
* in order to enable the Python environment on ulam provided by Anaconda you need to add the following to your <code>~/.bashrc</code>:
*[https://github.com/jbweston/kwant_tools KWANT tools]
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/mm16 Interactive tutorials using Jupyter Notebooks]
 
*[https://kwant-project.org/doc/1/tutorial/discretize Discretization of continuous Hamiltonians]
== MATLAB Scripts ==
*[[Conductance of graphene nanoribbons]]
*[[Conductance of topological insulators built from graphene nanoribbons]]
*[[Spin Hall effect in four terminal devices]]
*[[Topological Hall effect in four terminal devices]]


===Charge and spin densities in quantum dots via equilibrium density matrix===
===Charge and spin densities in quantum dots via equilibrium density matrix===
Line 106: Line 70:
* [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)
* [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)
* [[Media:transmission.m|transmission.m]] (Transmission function for 1D tight-binding chain with spin-dependent terms)
==Quantum transport simulations using KWANT package==
===Tutorials===
*[http://kwant-project.org/doc/kwant-screencast-2014 VIDEO: Introduction to KWANT]
*[https://kwant-project.org/doc/1/tutorial/ Learning KWANT through examples]
*[https://kwant-project.org/mm16 Interactive tutorials using Jupyter Notebooks]
*[https://kwant-project.org/doc/1/tutorial/discretize Discretization of continuous Hamiltonians]
*[[Conductance of graphene nanoribbons]]
*[[Conductance of topological insulators built from graphene nanoribbons]]
*[[Spin Hall effect in four terminal devices]]
*[[Topological Hall effect in four terminal devices]]
===Manuals===
*[https://kwant-project.org/doc/1/ KWANT documentation]
*[https://kwant-project.org/doc/1/reference/kwant.solvers Selecting matrix solvers in KWANT]
*[https://github.com/jbweston/kwant_tools KWANT tools]
==Band structure calculations for tight-binding models using PythTB package==
*[http://www.physics.rutgers.edu/pythtb/ PythTB Website]


== Density functional theory with GPAW package==
== Density functional theory with GPAW package==

Revision as of 06:33, 29 August 2020

Python and package installation

conda install -c conda-forge kwant
pip install pythtb --upgrade
pip install --upgrade --user ase
python -m ase test

JUPYTER notebooks for hands-on computer lab sessions

Python references

KWANT references

Charge and spin densities in quantum dots via equilibrium density matrix

DOS of 1D disordered nanowire using eigenvalues + visualization of Anderson localization of eigenfunctions

Density of states using equilibrium Green functions

  • dos_negf_closed.m computes DOS for finite 1D wire
  • dos_negf_open.m computes DOS for finite 1D wire attached to one or two macroscopic reservoirs
  • graphene_dos.m computes DOS for a supercell of graphene with periodic boundary conditions

Subband structure of graphene nanoribbons using tight-binding models

Quantum transport in 1D nanowires using NEGF

Tunneling magnetoresistance in tight-binding models of magnetic tunnel junctions using NEGF

  • mtj_1d.m (computes TMR of F/I/F MTJs modeled using 1D tight-binding chain)
  • 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 via NEGF

Self.m, (code to compute the conductance of a finite graphene nanoribbon attached to two semi-infinite graphene electrodes)

MATLAB functions

  • matrix_exp.m (Exponential, or any other function with small changed in the code, of a Hermitian matrix)
  • 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): atomCoord.m, atomPosition.m, and constrainView.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)
  • transmission.m (Transmission function for 1D tight-binding chain with spin-dependent terms)

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