UCSD NANO 266 Quantum Mechanical Modelling of Materials and Nanostructures is a graduate class that provides students with a highly practical introduction to the application of first principles quantum mechanical simulations to model, understand and predict the properties of materials and nano-structures. The syllabus includes: a brief introduction to quantum mechanics and the Hartree-Fock and density functional theory (DFT) formulations; practical simulation considerations such as convergence, selection of the appropriate functional and parameters; interpretation of the results from simulations, including the limits of accuracy of each method. Several lab sessions provide students with hands-on experience in the conduct of simulations. A key aspect of the course is in the use of programming to facilitate calculations and analysis.
3. The four levels of attainment
NANO266
3
Jedi
Master
Jedi Knight
Padawan
Youngling
Does things “manually”.
Lots of mistakes (e.g., typos,
calculations that need to be
repeated, etc. Takes months to
do a basic project.
Knows way around the command line.
Use some basic shell scripting. Maybe
even a little programming to make
some tasks easier.
Mastered most of the tools of the trade.
Can write sophisticated shell/programming
scripts to automate calculations, plot results,
etc. Most PhDs get to this level (hopefully).
Conceptualizes entire software frameworks that
are reusable and extendable by other users.
4. The most important command in Unix
• man sed
• man awk
• man find
• man grep
• man head
• man tail
• man less
• man …
NANO266
4
“man” is short
for manual
5. Some common Unix commands (other than your
typical cp,mv,cd,ls)
grep Searches any given input files,
selecting lines that match one or
more patterns.
cat Reads files sequentially, writing them
to the standard output
sed Reads the specified files, modifying
the input as specified by a list of
commands.
tail Displays last part of a file
head Displays start of a file
find Recursively descends the directory
tree, evaluating an expression in
terms of each file in the tree.
less View file in terminal
NANO266
5
6. Unix shells
Many types of Unix shell available, but broadly
falls into
• Bourne shell – de facto standard
• C shell – uses C-like syntax
Pick one that suits you and just set all your
resources to go into that shell by default.
NANO266
6
7. Shell scripts
Next level beyond just typing commands in the terminal
Writing scripts to execute sequence of commands, with
some control flow where necessary
NANO266
7
# Descending into a directory structure
# and running some commands in each directory
cwd=`pwd`
for dir in `find . –type d`
do
cd $dir
<execute some other commands>
cd $cwd
done
8. Control flow
Specification of the order in which the individual
statements, instructions or function calls of an
imperative program are executed or evaluated.
Two broad-types:
• Conditional: if-else, case-switch, etc.
• Loops: for, while, etc.
NANO266
8
9. Pros and Cons of Shell Scripts
Pros
• Ubiquitous
• Quick and dirty
• Useful for short programs / scripts with
a little bit of control flow
Cons
• Very error-prone, especially with more
complex programs
• Doing even simple math is ugly (don’t
even bother trying to do matrix math or
anything more complex)
• Difficult to extend and build on
NANO266
9
11. Pros and Cons of Programming Languages
Pros
• Far more powerful than shell
• Popular ones come with extensive libraries that makes complex math
and plotting etc. easier
• Usually comes with support tools (compilers, debuggers, IDEs, etc.)
that helps reduce bugs, or at the very least, make them easier to find.
• Proper use allows the development of extensible packages and
libraries
Cons
• Compiled languages require an additional compilation step
• Additional learning curve
• Not all languages are supported on all systems (though this is usually
not an issue with the popular ones)
NANO266
11
12. Which programming language should I choose?
Short answer – Whichever one you are most
comfortable with.
Long answer – Depends on what you need it for.
• If performance is critical (e.g., a DFT code), you probably have to
go with compiled languages like C and Fortran.
• If speed of development and prototyping outweighs raw
performance, interpreted / scripting languages like Python and
Perl are generally easier to get into.
For this class, we will exclusively use Python.
NANO266
12
14. What is ?
General-purpose, high-level programming language
Design emphasizes code readability
Supports multiple programming paradigms (OOP,
imperative, functional, procedural)
Dynamically typed, automatic memory management
and large standard library
Available on almost all platforms
NANO266
14
15. NANO266
15
public class Hello {
public static void main(String[] args) {
System.out.println("Hello World!");
}
}
#include <iostream>
int main()
{
std::cout << "Hello World!" << std::endl;
return 0;
}
Java
C++
print("Hello World!”)
Python
16. Scientific computing with Python
NANO266
16
User-friendly and efficient numerical
routines such as routines for numerical
integration and optimization.
Fundamental package for numerical
computation. Defines array and matrix
types and basic operations on them.
High-performance, easy to use
data structures.
Publication-quality 2D plotting as
well as rudimentary 3D plotting
Rich interactive interface, letting
you quickly process data and
test ideas.
19. Python Materials Genomics (pymatgen)
Core materials analysis powering the
Materials Project
• Defines core extensible Python objects for materials
data representation.
• Provides a robust and well-documented set of
structure and thermodynamic analysis tools relevant to
many applications.
• Establishes an open platform for researchers to
collaboratively develop sophisticated analyses of
materials data.
NANO266
19
22. Final word on Programming
A little investment in learning a programming
language can yield big dividends in your
efficiency as a materials modeler.
NANO266
22
23. Prep for Lab2
In Lab2, you will come face-to-face with a practical
example of how using a programming language can
make performing a sizable number of calculations
much easier.
The scripts are relatively simple and makes use of
only Python’s standard library. They offer but a small
glimpse of what is possible.
Start your journey by going through the simple
Python tutorial at http://www.python.org.
NANO266
23