NANO266 - Lecture 9 - Tools of the Modeling Trade
-
Upload
shyue-ping-ong -
Category
Education
-
view
357 -
download
2
Transcript of NANO266 - Lecture 9 - Tools of the Modeling Trade
Tools of the Modeling trade (QM, not catwalk)
Shyue Ping Ong
It’s not just about quantum mechanics
NANO266 2
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.
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
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
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
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
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
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
Beyond shell scripts
NANO266 10
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
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
NANO266 13 https://xkcd.com/353/
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
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
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.
Python Resources
Python documentation https://www.python.org/doc/
Numpy docs http://docs.scipy.org/doc/numpy/reference/
NANO266 17
Beyond simple scripts – Libraries for Computational Materials Science
NANO266 18
https://wiki.fysik.dtu.dk/ase/ https://www.pymatgen.org
http://www.aflowlib.org/
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
Overview of Pymatgen
NANO266 20
Example usage
NANO266 21
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
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