\documentclass{beamer}
%\usepackage{beamerarticle}
% For handout, or use article/usepackage{beamerarticle}
%\documentclass[handout]{beamer} 

\usepackage{amsmath,amssymb}
\usepackage{graphicx}
\usepackage{hyperref}
\usepackage{multimedia}
%\usepackage{tabularx}
%\usepackage{algorithm, algorithmic}
\usepackage{algorithm2e}
\usepackage{algorithmic}
%\usepackage{deluxetable}
%\usepackage{natbib}
\setbeamercolor{exampleblock}{fg=red!80!black,bg=black!10!white}
\newcommand{\green}{\textcolor{green!50!black}}
\newcommand{\myblue}{\only{\color{blue}}}
%\newcommand{\dred}{\textbf{\color{darkred}}} 

\mode<presentation>
{
  \usetheme{CambridgeUS} %default, CambridgeUS, Warsaw
  % \usecolortheme{beaver} % seahorse, rose, beaver
  \useoutertheme{infolines}
%  \usefonttheme[onlysmall]{structurebold}
%  %\usefonttheme[onlylarge]{structuresmallcapsserif}
%  \setbeamerfont{title}{shap*={\textsc}}
%  \setbeamerfont{frametitle}{size=\large,series=\bfseries}
%  \setbeamertemplate{navigation symbols}{}
  \setbeamertemplate{title page}[default][rounded=true,shadow=beamer@themerounded@shadow]
  \setbeamercovered{transparent}
  \setbeamercolor{frametitle}{bg=white, fg=black}
%  %\setbeamertemplate{headline}[default]{}
  \setbeamertemplate{headline}
  {
    \hbox{
      \begin{beamercolorbox}[wd=\textwidth,ht=2.25ex,dp=1ex]{}
        \usebeamerfont{section in head/foot}
        \hfill\insertsection%\insertnavigation{\paperwidth}
        \hspace*{2em}
      \end{beamercolorbox}
    }
    \hbox{
      \begin{beamercolorbox}[ht=0.5ex]{section in head/foot}
      \end{beamercolorbox}
    }
    \vskip2pt
  }
  %% From beamerouterthemeinfolines.sty
  \setbeamertemplate{footline} {
    \hbox{%
      \begin{beamercolorbox}[wd=\paperwidth,ht=2.25ex,dp=1ex]{date in head/foot}%
        \hspace*{2em}\insertshorttitle
        \hfill
        \usebeamerfont{author in head/foot}
        \insertshortauthor~~
        %(\insertshortinstitute)  
        \hspace*{2em}
        \usebeamerfont{date in head/foot}\insertshortdate{}\hspace*{2em}
        \insertframenumber{} / \inserttotalframenumber\hspace*{2ex}
      \end{beamercolorbox}}%
    \vskip0pt%
  }
}

\usepackage[english]{babel}
\usepackage{times}
\usepackage[T1]{fontenc}

\pgfdeclaremask{tu}{iusealredonwhite-mask}
\pgfdeclareimage[mask=tu,height=.8cm]{logo}{iusealredonwhite}
\logo{\pgfuseimage{logo}}

\title{Python Tutorial}
\author[B. Zaitlen]{Benjamin L. Zaitlen %{\tt bzaitlen@indiana.edu}
}

\institute{Biocomplexity Institute, Indiana University}
%\date{}

%\author[Author, Another] % (optional, use only with lots of authors)
%\author{Lingyun Yang\inst{1} \and S.~Y.~Lee\inst{2}}
% - Give the names in the same order as the appear in the paper.
% - Use the \inst{?} command only if the authors have different
%   affiliation.

%\institute[Indiana Universities] % (optional, but mostly needed)
%{
%  \inst{1}%
%  Department of Physics\\
%  Indiana University
%  \and
%  \inst{2}%
%  IUCF\\
%  Indiana University}
% - Use the \inst command only if there are several affiliations.
% - Keep it simple, no one is interested in your street address.


\begin{document}

\begin{frame}[plain]
  \setbeamercolor{title}{fg=red!80!black,bg=black!10!white}
  %\setbeamerfont{title}{shape=\itshape,family=\rmfamily}
 \titlepage
\end{frame}

\section[Outline]{}

\begin{frame}[label=toc]
\tableofcontents
\end{frame}

\section{Introduction}
\begin{frame}
  \frametitle{Introduction}
   \begin{itemize}[<+->]
   \item Created Guido van Rossum in 1991
   \item Human-readable
   \item Fast creation and debugging
   \item See http://www.python.org/doc and Python Essential Reference by David Beazley 
  \end{itemize}
\end{frame}

\begin{frame}[fragile]
  \frametitle{Comments and Quirks}
   \begin{itemize}[<+->]
   \item \# A comment
   \item Python is space senstive.  Lines after a : must be indented. 
    \onslide+<3->
      \begin{exampleblock}{Indentation Example}
      \begin{verbatim}
for i in (1,2,3,4):
    print i,

1 2 3 4
        \end{verbatim}
      \end{exampleblock}
  \end{itemize}
\end{frame}

%\section{The Terminal and The Editor}
%\begin{frame}
%    \frametitle{Open Two Terminals and Xcode}
%    \begin{itemize}[<+->]
%        \item Start terminal Finder->Applications->Utilities->Terminal (Double Click)
%        \item Start Xcode  Finder->Developer->Applications->Xcode
%            \begin{itemize}
%                \item File->New File->Python Tool->Name file strings.py
%            \end{itemize}
%    \end{itemize}
%    \includegraphics[width=6cm]{setup.png}
%\end{frame}

\section{Interactive Shell}
\begin{frame}[fragile]
    \frametitle{The Shell}
    \begin{itemize}[<+->]
        \item Invoke the shell from the command line using the keyword python 
        \item Useful for basic math, testing ideas
        \item Do not build programs in interpreter
    \end{itemize}
    \onslide+<4->
    \begin{block}{Interpreter}
    \begin{verbatim}
        >>>print "Hello, World!"
        Hello, World!
        >>>var = 9+2
        >>>var*11
        121
    \end{verbatim}
    \end{block}
\end{frame}

\section{Strings and Numbers}
\begin{frame}
    \frametitle{Strings}
    \begin{itemize}[<+->]
        \item{A simple string "hello world"}
        \item{Concatenation: "hello"+" world" $\to$ "hello world"}
        \item{Repetition: "hello"*3 $\to$ "hellohellohello"}
        \item{Indexing: "world"[3] $\to$ "l"}
        \begin{itemize}
            \item{Note: python lists are zero-offset}
        \end{itemize}
        \item{Searching: "o" in "hello" $\to$ True}
    \end{itemize}
\end{frame}

\begin{frame}
    \frametitle{Numbers}
    \begin{itemize}[<+->]
        \item{Basic math notation: 1.4, 2+2, 2**10,1e10}
        \begin{itemize}
            \item{Note: Integer division floors values: 2/3 $\to$ 0, 2./3 $\to$ .6667}
        \end{itemize}
        \item{Math functions require import of math}
         \begin{itemize}
            \item{import math}
            \item{math.sqrt(4) $\to$ 2.0}
        \end{itemize}
         \begin{itemize}
            \item{from math import *}
            \item{sqrt(4) $\to$ 2.0}
        \end{itemize}

    \end{itemize}
\end{frame}

\section{Storing Data}
\begin{frame}
    \frametitle{Variables and List}
    \begin{block}{Dynamically-Typed Variables}
    \begin{itemize}
        \item x = 5
        \item x = 3.14
        \item x = 'text'
        \item x = '3.14'
    \end{itemize}
    \end{block}

    \begin{block}{Dynamically-Typed Lists}
    \begin{itemize}
        \item numbers = [0,1,2,3,4,5]
        \item words = ['compucell','workshop']
        \item combo = [12,23,['text','knot']]+words
    \end{itemize}
    \end{block}
\end{frame}

\begin{frame}
    \frametitle{List Operations} 
    \begin{itemize}
        \item words.append('almond') $\to$ ['compucell','workshop','almond']
        \item words.insert(1,'water')$\to$ ['compucell','water', 'workshop','almond']
        \item words.reverse() $\to$ ['almond','workshop','water','compucell']
        \item words.remove('water') $\to$ ['almond','workshop','compucell']
    \end{itemize}
\end{frame}

\begin{frame}
    \frametitle{Dictionaries \small{aka Hash Tables, Associative Arrays, Lookup Tables}}
    \begin{itemize}
        \item dictionary = \{'indefatigable':'untiring',
        'intrepid':'fearlessness','dissemble':'simulate'\}
        \item constants = \{'pi':3.1415, 'e':2.7182, 'phi':1.6180\}
        \item com\_dict = \{1:[1,2,3],2:[1,0,3],3:[0,4,5]\}
    \end{itemize}
\end{frame}

\begin{frame}
    \frametitle{Dictionaries Operations}
    \begin{itemize}
        \item com\_dict.keys() $\to$ [1,2,3] 
        \item com\_dict.values() $\to$ [[1, 2, 3], [1, 0, 3], [0, 4, 5]]
    \end{itemize}
    \begin{block}{Accessing Members}
    \begin{itemize}
        \item com\_dict[3] $\to$ [0,4,5] 
        \item constants['phi'] $\to$ 1.6180
        \end{itemize}
    \end{block}
\end{frame}

\section{Control Structures}

\begin{frame}[fragile]
  \frametitle{If, While, and For}
  \begin{columns}[t]
    \column{.5\textwidth}
      \begin{block}{The If...}
      \begin{verbatim}
if condition:
    statements
elif condition:
    statements
else condition:
    statements
        \end{verbatim}
      \end{block}
\alert{\textbf{Note:}Beware of Python's requirement for indentation}

    \column{.45\textwidth}
      \begin{block}{The While...}
       \begin{verbatim}
while condition:
    statements
        \end{verbatim}
      \end{block}
  \begin{block}{The For...}
\begin{verbatim}
for var in sequence:
    statements
    \end{verbatim}
      \end{block}

      \end{columns}
      \begin{columns}
      \column{.45\textwidth}
      \end{columns}
\end{frame}

\begin{frame}[fragile]
  \frametitle{Control Structure Examples}
  \begin{columns}[t]
    \column{.4\textwidth}
      \begin{exampleblock}{The If...}
      \begin{verbatim}
if (x > 0):
    print "Positive"
elif (x < 0):
    print "Negative"
else:
    Print "Zero"
        \end{verbatim}
      \end{exampleblock}
    \column{.44\textwidth}
      \begin{exampleblock}{The While...}
       \begin{verbatim}
while (1):
    print "Always true"
        \end{verbatim}
      \end{exampleblock}

  \end{columns}
      \begin{columns}
      \column{.5\textwidth}
      \begin{exampleblock}{The For...}
      \begin{verbatim}
for i in range(5):
    print i
    \end{verbatim}
      \end{exampleblock}
      \end{columns}
\end{frame}

\section{Functions}
\begin{frame}[fragile]
  \frametitle{Defining Functions}
  \begin{columns}[t]
      \column{.5\textwidth}
      {\myblue{No Arguments}}
      \begin{semiverbatim}
\textcolor{green!50!black}{def} Hello\_World():
    \green{print} 'Hello World' 
\textcolor{green!50!black}{def} return\_5():
    \green{return} 5
      \end{semiverbatim}

      {\myblue{With Arguments}}
      \begin{semiverbatim}
\alert{You can pass a single variable:}
\textcolor{green!50!black}{def} one\_var(x):
    print 'You passed the variable: \%s' \%(x) 

\alert{You can also pass a list:}
\textcolor{green!50!black}{def} list\_func(list):
    \green{for} i \green{in} list:
        \green{print} i,
      \end{semiverbatim}
      \column{.5\textwidth}
      \alert{\textbf{Note:}Python passes all agruments by reference.  This means changing the value in
      the function will change the value when the program exits the function}
      \end{columns}
\end{frame}

\begin{frame}[fragile]
  \frametitle{Calling Functions}
  \begin{columns}[t]
      \column{.5\textwidth}
      {\myblue{No Arguments}}
      \begin{verbatim}
>>>Hello_World()
Hello World
>>>return_5()
5
      \end{verbatim}
{\myblue{With Arguments}}\\
\alert{Passing a single variable:}
\begin{verbatim}
>>>x = 'my variable'
>>>one_var(x)
my variable
\end{verbatim}
      \column{.5\textwidth}
\alert{Passing a list:}
\begin{verbatim}
list = [0,1,2,3,4]
>>>list_func(list):
0 1 2 3 4
      \end{verbatim}

{\myblue{In General}}\\
      \begin{semiverbatim}
\textcolor{green!50!black}{def} name(arg1,arg2,...):
    statements
    \green{return} expression 
    \end{semiverbatim}
      \end{columns}
\end{frame}

\section{Classes}
\begin{frame}
    \frametitle{The Container for Everything}
    \begin{block}{What is a Class ?} 
    \begin{itemize}
    \item Classes contain stuff.  What kind of stuff ? \\
    \textbf{Anything!}
    \item What are the good for ? 
    \textbf{Almost everything}
    \end{itemize}
    \end{block}
    \begin{block}{What can they store ?}
    Classes can store everything: variables, lists, dictionaries, functions,
    other lists, etc
    \end{block}
\end{frame}

\begin{frame}[fragile]
\frametitle{Typical Python Class}
    \begin{block}{Defining}
\begin{semiverbatim}
\green{class} Complex:
    var\_every = 0      {\alert{#class variable}}
    \green{def} {\myblue{\_\_init\_\_}}(self,var = 0):
        self.instance = var     #instance variable
    \green{def} {\myblue{class\_print}}(self):
        \green{print} \alert{"My Value is: %s"} %(self.instance)
\end{semiverbatim}
\end{block}
\end{frame}



\begin{frame}[fragile]
\frametitle{Classes Continued...}
    \begin{block}{General Class}
\begin{semiverbatim}
\green{class} name(baseclass1, baseclass2,...):
    statements
    \green{def} name(self, arg1, arg2,...):
        more statements
\end{semiverbatim}
\end{block}
    \begin{block}{Example: The Complex Variables}
    One object contains both the real and imaginary parts of a complex
    variable.  Can be achieved with a list, dictionary, or class.  Class seems to make
    the most sense...\\
    \end{block}
\end{frame}



\begin{frame}[fragile]
\frametitle{The Complex Class}
    \begin{block}{Defining}
\begin{semiverbatim}
\green{class} Complex:
    \green{def} {\myblue{\_\_init\_\_}}(self,real,imag):
        self.r = real
        self.i = imag
    \green{def} {\myblue{cprint}}(self):
        \green{if}(self.i < 0):
            \green{print} \alert{"%.3f%.3f*i"} %(self.r, self.i)
        \green{else}:
            \green{print} \alert{"%.3f+%.3f*i"} %(self.r, self.i)
\end{semiverbatim}
\end{block}
\begin{itemize}
    \item \textbf{self} is like \textbf{this} and must be passed to member functions
\end{itemize}
\end{frame}

\begin{frame}[fragile]
\frametitle{Complex Class Continued...}
    \onslide+<1->
    \begin{block}{Initializing}
    \begin{itemize}
    \item Let's initalize 1-\textit{i}
    \onslide+<2->
    \item Complex(1,-1)
    \onslide+<3->
    \item We need to store the class.  Simple:\\
    comp = Complex(1,-1).  Now we have access to the variables \alert{r} and \alert{i}
    and the member function cprint()
    \end{itemize}
    \end{block}

    \onslide+<4->
    \begin{block}{Accessing Members}
    \begin{itemize}
    \item Use the . operator to access variables\\ comp.r comp.i
    \onslide+<5->
    \item Use the . operator to access functions\\ comp.cprint()
    \end{itemize}
    \end{block}
\end{frame}

\section{CompuCell Classes}
\begin{frame}[fragile]
\frametitle{The Cell}
    \begin{block}{What are the attributes of a cell ?}
    \begin{itemize}
    \onslide+<1->
    \item Type
    \onslide+<2->
    \item Volume 
    \onslide+<3->
    \item Center of Mass
    \end{itemize}
    \end{block}
    These are a few of the variables inside the cell class built for CompuCell.  We can
    interface with this class through Python
\end{frame}






%\section{Ising Model}

%\section{Monte Carlo Simulation and Metropolis Algorithm}

%\begin{frame}[t]
%  \frametitle{Monte Carlo Simulation and Metropolis Algorithm} %
%  \begin{itemize}
%    \item Randomly move from one state to another.
%    \item Probability at state $S$:
%      \begin{equation}
%        \label{eq:probability}
%        %P(S)=\frac{e^{\displaystyle -\frac{E(S)}{kT}}}{\sum_{A}e^{\displaystyle -\frac{E(A)}{kT}}}
%        P(S)=\frac{e^{-E(S)/kT}}{\sum_{A}e^{-E(A)/kT}}
%      \end{equation}
%    \item Probability of moving to next state:
%      \begin{equation}
%        \label{eq:probability:move}
%        \frac{P(S_{\textrm{after}})}{P(S_{\textrm{before}})}
%         = e^{-\Delta E/kT}
%      \end{equation}
%      where $\Delta E=E_{\textrm{after}}-E_{\textrm{before}}$
%      \item Accept one step with probability:
%        \begin{equation}
%          \label{eq:metropolis}
%          P_{\textrm{accept}}=\min\{1, \frac{P(S_{\textrm{after}})}{P(S_{\textrm{before}})}\}
%        \end{equation}
%  \end{itemize}
%\end{frame}



%\begin{frame}[t]
%\frametitle{Metropolis Algorithm}
  %\vskip-1cm
  %\begin{algorithm}
 %  % \caption{Metropolis Algorithm}
 %   \begin{algorithmic}[1]
 %     \STATE Initialization, Sweep.
 %     \STATE Compute $E_0$.
 %     \STATE Randomly flip one site.
 %     \STATE Compute $E_1$ and $\Delta E=E_1-E_0$.
 %     \IF{$E_1<E_0$ (i.e. $e^{-(E_1-E_0)/kT}>1$)}
 %     \STATE Keep $E_1$
 %     \ELSE
 %     \STATE Keep $E_1$ with probability $\textrm{rand}()<e^{-(E_1-E_0)/kT}$
 %     \ENDIF
 %   \end{algorithmic}
  %\end{algorithm}
%    \hrule
%    5\vskip.5cm
%    \[
%    E=-\sum_{\textrm{neighbor }i,j}S_iS_j
%    \]
    
%\end{frame}

%\section{Physics Result}


% \section{Reference}
%
% \begin{frame}[t]
%   \frametitle{Reference}
%   \begin{thebibliography}{10}
%   \bibitem{Lee04}[S.\ Y.\ Lee, 2004]
%     S.\ Y.\ Lee.
%     \newblock Accelerator Physics, 2nd, 
%     \newblock \emph{World Scientific}, 2004
%   \end{thebibliography}
% \end{frame}

\end{document}
