Você está na página 1de 18

Programming in Python

and Applications in Materials Science


Ján Minár
University of West Bohemia, New Technologies-Research Center, Pilsen, Czech Republic

Email: jmminar@gmail.com
(evtl. jan.minar@hm.edu)
Outline 1: Necessary (maybe boring)

Python
Introduction
Installation

Shells, Scripts IDEs, Jupyter

– components
– simple input&output
Python Intro – variables, mathematical operators
– basic types
– strings
– import libraries
– while, if, for etc…
– files i/o
– lists, tuples, dictionaries
– functions
– objects
– mathematics in python

lecture 1
Outline 2: Useful for data science

Mathematica

NumPy

SciPy
Matlab

Alternative
Matplotlib

SymPy

ASE:
Material science
Simulation package

Vpython PyGame Pandas

lecture 1
Instalation

Instalation of interpreter

Direct Install distribution

Windows Linux Miniconda: conda.pydata.org/miniconda.html


Anaconda: www.continuum.io/downloads
Download the latest Use your favorit package
version of Python: manager:
http://www.python.org Apt, YUM ….

lecture 1
How to run python?

Interpreter

Interactively: “shell” Code

– idle (included in python installation – Write code with your favorite text
from python.org) Editor (not word!)

– command line: call python – run python script.py

– command line: call ipython – coding can be done also in


various IDEs
– notebook like web page: jupyter (very usefull!!) (integrated development enviroment)
e.g. spyder
lecture 1
Too many options: our course

Computers: Here in this seminar room with preinstalled anaconda (2.7)

Own notebooks: Yes, no problem, please install anaconda

(I can help you with Linux without problem, maybe I can help you with Windows,
I can not help you with macOs)

We will use:

Interpreter: ipython mostly

WWW notebook: jupyter

IDE: spyder

Libraries and packages: Standard python libraries, numpy, scipy, matplotlib …

lecture 1
ipython

lecture 1
Ipython: I need help! help(), ? and ??

lecture 1
Ipython: I need help! ? and ??

lecture 1
TAB-autocomplete, Wildcards

lecture 1
ipython

Usefull: %paste of blocks of codes


%cd, %ls, %pdw, %cp ….
%run external code
_ , __, ___ access previous output

lecture 1
Ipython qtconsole : enhanced terminal

lecture 1
Jupyter: interactive notebook

lecture 1
jupyter

lecture 1
How to start

lecture 1
lecture 1
IDE: spyder

● Spyder is a MATLAB-like IDE for scientific computing with python. It has the many
advantages of a traditional IDE environment, for example that everything from code
editing, execution and debugging is carried out in a single environment, and work on
different calculations can be organized as projects in the IDE environment.

● Some advantages of Spyder:


● Powerful code editor, with syntax high-lighting, dynamic code introspection and integration with the python
debugger.
● Variable explorer, IPython command prompt.
● Integrated documentation and help.

How to run: spyder

lecture 1
Homework

● Install anaconda (Version 2.7) on your favorite operating system


● Run ipython shell and get used to it
● Read intro and quickref under ipython:
?
%quickref
● Get version of python you use
● Write your first “Hello World” Program
print(“Hello World”)
● Interactively in ipython
● Create code hello.py using IDE spyder
● Run ipython using hello.py
● Write your first jupyter notebook including notes ans steps from your homework

lecture 1

Você também pode gostar