% !Mode:: "TeX:UTF-8"

\documentclass[11pt, a4paper]{article}
%\usepackage{xltxtra,fontspec,xunicode}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{breqn}
\usepackage{autobreak}
\usepackage{braket,mleftright}
\usepackage{amsfonts}
\usepackage[section]{placeins}
\usepackage{float}
\usepackage{siunitx}
\usepackage{graphicx}
\usepackage{subcaption}
\usepackage{mwe}
\usepackage{indentfirst}
\usepackage{caption}
\usepackage{physics}
\usepackage{geometry}
\usepackage{graphicx}
\usepackage{algorithm}% http://ctan.org/pkg/algorithm
\usepackage{algpseudocode}% http://ctan.org/pkg/algorithmicx

\geometry{top=1in, bottom=1in, left=1in, right=1in}
%\linespread{1.5}

\DeclareMathOperator*{\argmax}{argmax}
\DeclareMathOperator*{\argmin}{argmin}

\newcommand{\degc}{$\,^\circ$C}

\begin{document}

\title{Work Report}
\author{Zhuoran Qiao}
\date{\today}

\maketitle

\section{Introduction}

\paragraph{1} Developed a genetic algorithm based approach to simulate kinetics of co-transcriptional folding.
\paragraph{2} Tested effect of folding rate variation on folding population dynamics and $p_{unbound}$.

\section{Progress}
\subsection{Framework}
Various algorithms or programs have been developed to predict RNA folding pathway ultilizing force-field based simulations and multiple coarse grained energy landscape sampling methods built on Markov state model. Those present methods have succeeded in revealing multiscale dynamic events during RNA folding, however are either designed for only predicting
annealing dynamics or limited to RNA segments with length up to hundred bases. To quantitatively predict folding dynamics coupled with transcription,
we developed a genetic algorithm and chemical Master equation based approach, which is capable of capturing kilobase level kinetics.
 Our method is built on two following assumptions:
\paragraph{1} All populated RNA secondary structures (SS) are linkage of locally optimal or sub-optimal structures at various folding sites;
\paragraph{2} Global structural rearrangement of a partial RNA segment is permitted only if it's folding to the optimal SS on that segment.
\\

Formally, we denote a domain $D_{A,\,B}$ as a segment between base $A$ and $B$ that all contacts on that segment are local. For simplicity, we denote \textbf{foldon}
as domains with optimal secondary structures: $D^{foldon}_{A,\,B} = \text{MFE(sequence[A,B])}$. Note that $'.'$ is a trival example of foldon.
Our assumption 1 can be rewritten as
\begin{equation}
  D_{A,\,B} = D^{foldon}_{A, i_1} \oplus D^{foldon}_{i_1, i_2} \oplus ... \oplus D^{foldon}_{i_n, B}
\end{equation}
Where $\oplus$ represents a link operation. Note that all structural information of $D_{A,\,B}$ is encoded by the sequential representation $[A,\, i_1,\, ...,\, i_n,\, B]$;
 as a foldon is also a linkage of smaller foldons, there could be multiple way to represent $D_{A,\,B}$. Here we introduce \textbf{Irreducible Foldon Representation} (IFR) to be the
 sequential representations for which linkage of every adjacent foldons is not another foldon: $\forall k,\, D^{foldon}_{i_k, i_{k+1}} \oplus D^{foldon}_{i_{k+1}, i_{k+2}} \neq D^{foldon}_{i_{k}, i_{k+2}}$.
 Then the sufficient and necessary condition for structural rearrangement is

\begin{center}
  $\langle D^{u}_{A,\,B} | \hat{\mathbf{T}} | D^{v}_{A,\,B} \rangle \neq 0$ if and only if $\exists\, i,\,j$ satisfies

  $i,\,j \in D^{u}_{A,\,B}$.IFR, $i,\,j \in D^{v}_{A,\,B}$.IFR;

  $D^{u}_{A,\,i} = D^{v}_{A,\,i},\, D^{u}_{j,\,B} = D^{v}_{j,\,B}$;

  $D^{u}_{i,\,j} = D^{foldon}_{i,\,j}$ or $D^{v}_{i,\,j} = D^{foldon}_{i,\,j}$.

  Then $\langle D^{u}_{A,\,B} | \hat{\mathbf{T}} | D^{v}_{A,\,B} \rangle = \langle D^{u}_{i,\,j} | \hat{\mathbf{T}} | D^{v}_{i,\,j} \rangle$.
\end{center}

\subsection{Folding pathway identification \& Rate calculation} \label{section:rate}

Given two domains between which rearrangement is allowed, the task is to compute forward and backward rate constant
linking each other. Multiple methods to rigorously calculate the maximum likelihood during RNA folding have been reported;
here we proposed a computationally feasible approach: the forward free energy barrier is estimated by sum up all free energy associated
with old stacks unzipping and new loop forming; then rate constant $k_{uv} = \langle D^{u}_{A,\,B} | \hat{\mathbf{T}} | D^{v}_{A,\,B} \rangle $ is calculated by Arrhenius approximation $k_{uv} = k_0 \exp[-\frac{1}{RT}(\Delta G^{Stack}_{u}+\Delta G^{Loop}_{v})]$. 'New' and 'old' helices are identified by comparing elementary domains (defined as domains that cannot be decomposed to smaller valid domains) between reactant and product domains; identical elementary domains are excluded.

\subsection{Algorithm procedure}

During every iterative elongation step, an active species pool of strands with unique SS and diffrent population is updated. New candidate strands $D^{Candidate}_{0,\, L+\Delta L}$ with
length $L+\Delta L$ are generated by a recombination
process: for every old strand $D^{Strand}_{0, \text{ L}}$, all indices in its IFR is identified as possible rearrangement site, then its child strands is generated by linking partial domains
$D^{Strand}_{0, \text{ Site}}$ with a foldon $D^{foldon}_{\text{Site}, L+\Delta L}$ that terminated at $L+\Delta L$.

We assume that elongation will not change the inital population distribution
of secondary structures: child strands with the exact parental SS on $[0, L]$ ($D^{child}_{0, L+\Delta L} = D^{strand}_{0, L} \oplus D^{foldon}_{L, L+\Delta L}$) will also inherit the population of their parents.

After structual generation the rate matrix among all candidate strands within the new active species pool is calculated (see part \ref{section:rate}). Then the population
distribution of strands after elongation is computed by propagate the chemical master equation.

For the sake of computational efficiency, we introduce a cutoff $N $ as the size limit of the active species pool. After each elongation step, we impose a selection sweep on all active
strands; species with top $N $ fitness is reserved. In the current edition, we simply used population as the fitness function. Population of remaining strands within
the active pool is renormalized after selection.

Pseudocodes of the whole simulation procedure are as follows (Algorithm \ref{algorithm:1}):

\begin{algorithm}
  \begin{algorithmic}[1]
    \State Initalize ActivePool
    \While{$\text{sequence length} > \text{current length }$}
      \State $\text{OldPool} \gets \text{ActivePool }$
      \State $\text{renew ActivePool }$
      \State $\text{Current length} \gets \text{Current length} + dL$
      \State $\text{dt} \gets dL / k_T$ \Comment{Transcription time}
      \For{$\text{left boundary} \in \text{\{0, dL, 2dL, ..., Current length - dL\}}$}\Comment{Get all new foldons}
        \State $D^{foldon}_{\text{left boundary}, \text{ Current length}} \gets \text{numpy.mfe(sequence[left boundary, Current length]})$
      \EndFor
      \For{$\text{Strand} \in \text{OldPool }$}\Comment{Recombination}
        \For{$\text{Site} \in \text{Strand.IFR }$}
          \State $D^{Candidate}_{0,\text{Current length}} \gets D^{Strand}_{0, \text{ Site}} \oplus D^{foldon}_{\text{Site}, \text{ Current length}}$
          \If {$D^{Candidate}_{0,\text{Current length}} \in \text{ActivePool }$}
            \State $\text{update $D^{Candidate}_{0,\text{Current length}}$.IFR}$
          \Else
            \State $\text{add $D^{Candidate}_{0,\text{Current length}}$ to ActivePool}$
          \EndIf
          \If {$\text{site} = \text{Current length} - dL$}
            \State $\langle \text{ActivePool}.\textbf{population}\,|D^{Candidate}_{0,\text{Current length}}\rangle \gets \langle \text{OldPool}.\textbf{population}\,|D^{Strand}_{0, \text{ Site}}\rangle$
          \EndIf
        \EndFor
      \EndFor
      \For{$D^{\text{u}}_{0,\text{Current length}} \neq D^{\text{v}}_{0,\text{Current length}} \in \text{ActivePool}$}\Comment{Calculate new rate matrix}
        \State $\text{calculate  } D^{u}_{\text{rearrange}} ,\ D^{v}_{\text{rearrange}}$\Comment{Find all helices involved in rearrangement}
        \State $\langle D^{u}_{\text{rearrange}} | \hat{\mathbf{T}} |D^{v}_{\text{rearrange}} \rangle \gets k_0 \exp(-\frac{1}{RT}(\Delta G^{Stack}_{u}+\Delta G^{Loop}_{v}) )$
      \EndFor
      \State $\langle \text{ActivePool}.\textbf{population}\,|\, \gets \langle \text{ActivePool}.\textbf{population}\,|\, \exp(t\times\hat{\mathbf{T}}) $\Comment{Master equation}
      \State $\text{reserve top $N$ populated strands in ActivePool}$\Comment{Selection}
      \State $\text{renormalize }\langle \text{ActivePool}.\textbf{population}\,|$
    \EndWhile
  \end{algorithmic}
\caption{Co-transcriptional folding elongation procedure}\label{algorithm:1}
\end{algorithm}

\subsection{Results}

The only remaining free parameter to be determined is $k_0/k_T$, the ratio of pre-exponential factor in Arrhenius rate formulation and trancription rate ($nt\cdot s^{-1}$). I tuned $k_0/k_T$ from $10^{1}$ to $10^{15}$ and obtained the data for $k_0/k_T=\infty$ by calculate stationary distribution ($\frac{1}{Q}\exp(-G_i)$) after every elongation step for strand i in active pool.

\paragraph{Population analysis} For folA-WT four predominant local folding motifs within SD sequence are identified. Figure \ref{fig:local_foldings} shows exemplary secondary structures containing these motifs; figure \ref{fig:populations} shows evolution of these structure motifs during co-transcriptional folding with different $k_0/k_T$. Identical motifs are marked by the same color as in figure \ref{fig:local_foldings}. Surprisingly we noticed that when $k_0/k_T=\infty$, exchange between dominant motifs is very frequent at early stage of transcription, indicating the sensitivity of local structures on long-range contacts, and dependence of motif predominance on the limited timescale for folding.

\begin{figure*}
    \centering
    \begin{subfigure}[b]{0.475\textwidth}
   		\centering
    	\includegraphics[width=\textwidth]{folding_example_purple}
    	\caption[]%
   		{{\small Motif 1}}
    	\label{fig:mean and std of net14}
    \end{subfigure}
   	\hfill
    \begin{subfigure}[b]{0.475\textwidth}
   		\centering
   		\includegraphics[width=\textwidth]{folding_example_blue}
    	\caption[]%
    	{{\small Motif 2}}
   		\label{fig:mean and std of net24}
   	\end{subfigure}
   	\vskip\baselineskip
   	\begin{subfigure}[b]{0.475\textwidth}
    	\centering
    	\includegraphics[width=\textwidth]{folding_example_red}
   		\caption[]%
   		{{\small Motif 3}}
    	\label{fig:mean and std of net34}
    \end{subfigure}
   	\quad
   	\begin{subfigure}[b]{0.475\textwidth}
   		\centering
    	\includegraphics[width=\textwidth]{folding_example_grey}
    	\caption[]%
   		{{\small Motif 4}}
   		\label{fig:mean and std of net44}
   	\end{subfigure}
    \caption[ Exemplary ss containing folding motifs within folA-WT Shine-Dalgarno sequence ]
   	{\small Exemplary ss containing folding motifs within folA-WT Shine-Dalgarno sequence}
   	\label{fig:local_foldings}
\end{figure*}

\begin{figure*}[tph]
\centering
\includegraphics[width=\textwidth]{RNA_local_population_evolution_summary}
\caption[Population dynamics]{\small Population dynamics of four structrual motifs during co-transcriptional folding.}
\label{fig:populations}
\end{figure*}

\paragraph{$p_{unbound}$ analysis} We calculated $p_{unbound}$ with respect to transcription time and $k_0/k_T$ (Figure \ref{fig:RNA_p_unbound_SD_k_tuning}-\ref{fig:RNA_p_unbound_base[-14]_k_tuning}). Deviation of asymptotic behavior from equilibrium value (calculated by nupack.ppairs) is possiblly due to the limited set of foldons (only used mfe to obtain current results).

\begin{figure}
	\centering
	\includegraphics[width=\linewidth]{p_unbound/RNA_p_unbound_SD_k_tuning}
	\caption{}
	\label{fig:RNA_p_unbound_SD_k_tuning}
\end{figure}
\begin{figure}
\centering
\includegraphics[width=\linewidth]{p_unbound/RNA_p_unbound_base[-8]_k_tuning}
\caption{}
\label{fig:RNA_p_unbound_base[-8]_k_tuning}
\end{figure}
\begin{figure}
\centering
\includegraphics[width=\linewidth]{p_unbound/RNA_p_unbound_base[-9]_k_tuning}
\caption{}
\label{fig:RNA_p_unbound_base[-9]_k_tuning}
\end{figure}
\begin{figure}
\centering
\includegraphics[width=\linewidth]{p_unbound/RNA_p_unbound_base[-10]_k_tuning}
\caption{}
\label{fig:RNA_p_unbound_base[-10]_k_tuning}
\end{figure}
\begin{figure}
\centering
\includegraphics[width=\linewidth]{p_unbound/RNA_p_unbound_base[-11]_k_tuning}
\caption{}
\label{fig:RNA_p_unbound_base[-11]_k_tuning}
\end{figure}
\begin{figure}
\centering
\includegraphics[width=\linewidth]{p_unbound/RNA_p_unbound_base[-12]_k_tuning}
\caption{}
\label{fig:RNA_p_unbound_base[-12]_k_tuning}
\end{figure}
\begin{figure}
\centering
\includegraphics[width=\linewidth]{p_unbound/RNA_p_unbound_base[-13]_k_tuning}
\caption{}
\label{fig:RNA_p_unbound_base[-13]_k_tuning}
\end{figure}
\begin{figure}
\centering
\includegraphics[width=\linewidth]{p_unbound/RNA_p_unbound_base[-14]_k_tuning}
\caption{}
\label{fig:RNA_p_unbound_base[-14]_k_tuning}
\end{figure}

%\paragraph{a.} Using a genetic-algorithm based method and NUPACK to predict populated RNA configurations during cotranscriptional folding (in progress);
%\paragraph{b.} Using master equation method to simulate evolution of folding configurations and SD sequence accessibility.

%In order to examine when the one-dimensional coordinate projection could be recognized as effective reaction coordinate,
%we then examine the probability distribution of committors for transition path trajectories $p(q|TP)$, for which a single peak of probability $p(q|TP)$ have been ultilized as a indicator for 'good' reaction coordinates.
% Firstly, We found that for harmonic toy model, the shape of $p(q|TP)$ is very sensitive to the definition of source/sink region. For illustration, $p(q|TP)$ for two different selection
%  of source/sink regions was compared: in the first case, only two free energy minimum was indentified as source or sink\textbf{(S1)}; in the second case, only the barrier top was
%  defined as the transition path, while other two region of the free energy landscape was calssified as source/sink\textbf{(S2)}.

%\cite{Jacobs2018,Chaudhury2010,Vanden-Eijnden2010,Metzner,Krivov}

\small
%\bibliographystyle{plain}
%\bibliography{0727}

\end{document}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                                                                 %
% GEANT manual in LaTeX form                                      %
%                                                                 %
% Michel Goossens (for translation into LaTeX)                    %
% Version 1.00                                                    %
% Last Mod. Jan 24 1991 1300  MG + IB                             %
%                                                                 %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\Origin{L.Urb\'{a}n}
\Revision{J. Chwastowski}
\Submitted{26.10.84}\Revised{16.12.93}
\Version{GEANT 3.16}\Routid{PHYS231}
\Makehead{Simulation of photoelectric Effect}
\section{Subroutines}
\Shubr{GPHOT}
{\tt GPHOT} simulates the photoelectric effect. It uses the following
input and output:
\begin{DLtt}{MMMMMMM}
\item[Input]{via common \Cind{GCTRAK}}
\item[Output]{via common \Cind{GCKING}}
\end{DLtt}
It calls the functions \Rind{GPHSG1}, \Rind{GPHSGP}, \Rind{GAVRL2}
and \Rind{GAVRL3} for the cross-section and the functions \Rind{GHPHAK},
\Rind{GHPHAL1}, \Rind{GHPHAL2}, \Rind{GPHAL3} for the cosine distribution
of the photoelectron. \Rind{GPHOT} is called by the tracking routine
\Rind{GTGAMA}, if, and when, the photon reaches its interaction point.
\Sfunc{GAVRL2}{VALUE = GAVRL2(GAMAL2,BETAL2,X)}
\Rind{GAVRL2} calculates approximation of the cross-section for the
photoelectric effect from $L_{II}$ shell. {\tt GAMAL2},
{\tt BETAL2} are the Lorentz gamma and beta factors of the emitted
photoelectron and $X = m_e/E_\gamma$ where $m_e$ is
the electron mass and $E_\gamma$ is the incident radiation energy.
\Rind{GAVRL2} is called by \Rind{GHPOT}.
\Sfunc{GAVRL3}{VALUE = GAVRL3(GAMAL3,BETAL3,X)}
\Rind{GAVRL3} calculates approximation of the cross-section for the
photoelectric effect from $L_{III}$ shell.
{\tt GAMAL3}, {\tt BETAL3} are the Lorentz gamma and beta factors of the
emitted photoelectron and $X = m_e/E_\gamma$ where $m_e$ is the electron
mass and $E_\gamma$ is the  incident radiation energy.
{\tt GAVRL3} is called by \Rind{GPHOT}.
\Sfunc{GPHAK}{VALUE = GPHAK(BETAK)}
\Sfunc{GPHAL1}{VALUE = GPHAL1(BETAL1)}
{\tt GPHAK} and its entry point {\tt GPHAL1} poll the cosine distribution
(w.r.t. the incident photon direction) of the photoelectron emitted from
$K$ or $L_{I}$ shell, respectively. They are called by \Rind{GPHOT}.
\Sfunc{GPHAL2}{VALUE = GPHAL2(BETAL2)}
\Rind{GPHAL2} polls the cosine distribution (w.r.t. the incident photon
direction) of the photoelectron emitted from $L_{II}$ shell.
\Sfunc{GPHAL3}{VALUE = GPHAL3(BETAL3)}
{\tt GPHAL3} polls the cosine distribution (w.r.t. the incident photon
direction) of the photoelectron emitted from $L_{III}$ shell.
It is called by \Rind{GPHOT}.
\Sfunc{GPHSGP}{VALUE = GPHSGP(EGAM)}
\Rind{GPHSGP} calculates the photoelectric effect total cross-section for
a particular atom of a mixture taking into account weights. It is called by
\Rind{GPHOT} for ${\tt Z} \leq  100$.

\section{Method}

If the energy of the radiation incident on an atom is $E_{\gamma}$, then
the quanta can be absorbed if $E_{\gamma} > E_{shell}$.
The photoelectron is emitted with total energy:
\begin{equation}
E_{photoelectron} = E_{\gamma}-E_{shell}+m_e.
\end{equation}
In the above equation it is assumed that the atom has infinite mass. One should
note that there exists a correction term (see \cite{bib-BETHE} and
references therein) which becomes more and more important with
increasing $E_{\gamma}$ \cite{bib-HALL} \cite{bib-PRATT} \cite{bib-PRATT1}.

\subsection{Probability of Interaction with an Atom}
Probability of the interaction with an atom is calculated taking into
account partial cross-sections of atoms of a mixture
or a compound.
\subsection{Probability of Interaction with a Shell}
To calculate the probability of the interaction with a particular shell we use
the jump ratios defined as:
\begin{equation}
J_{shell} = \frac{\sigma(E_{shell}+\delta E)}{\sigma(E_{shell}-\delta E)}
\label{eq:jumprat}
\end{equation}
where $\delta E \rightarrow 0$.
In addition we assume that the jump ratio is also valid away from the edges.\\
From (\ref{eq:jumprat}) it follows that the probability $p_{shell}$
to interact with a shell is:
\begin{equation}
p_{shell} = 1-\frac{1}{J_{shell}}
\label{eq:probrat}
\end{equation}
We use the following parametrisation of the jump ratios for $K$ and
$L_{I}$ shells\cite{bib-VEIGELE}:
\begin{equation}
J_K = \frac{125}{Z} + 3.5
\end{equation}
\begin{equation}
J_{L_{I}} = 1.2
\label{eq:jumpl1}
\end{equation}
For the $L_{II}$ and $L_{III}$ shells we adopt approximation of the formulae
calculated by Gavrila \cite{bib-GAVRILA-L}:
\begin{eqnarray}
\sigma_{L_{II}} &=& \gamma \beta \frac{m_e}{E_\gamma}
              \left\{
               \gamma^3-5\gamma^2+24\gamma-16
               -(\gamma^2+3\gamma-8)\frac{\log(\gamma(1+\beta))}{\gamma\beta}
              \right\}
\label{eq:sigmal2}
\end{eqnarray}
and
\begin{eqnarray}
\sigma_{L_{III}} &=& \gamma \beta \frac{m_e}{E_\gamma}
             \left\{
                4\gamma^3-6\gamma^2+5\gamma+3
               -(\gamma^2-3\gamma+4)\frac{\log(\gamma(1+\beta))}{\gamma\beta}
             \right\}
\label{eq:sigmal3}
\end{eqnarray}
where\\

\begin{tabular}[t]{l@{\hspace{1cm}}p{.7\textwidth}}
$ \gamma, \beta $    & are the emitted photoelectron  Lorentz gamma and beta
                       factors;\\
$ E_\gamma      $    & is the incident radiation energy;  \\
$ m_e           $    & is the electron mass.  \\
\end{tabular}\\
Below an example of the shell interaction probability calculations for
$E_\gamma > E_K$ is given.\\
If
\begin{eqnarray*}
   \Sigma_{II,III} & = &  \sigma_{L_{II}}+\sigma_{L_{III}} \\
   r_{L_{II}} & = & \frac{\sigma_{L_{II}}}{\Sigma_{II,III}}  \\
   r_{L_{III}} & = & \frac{\sigma_{L_{III}}}{\Sigma_{II,III}}
\end{eqnarray*}
then from (\ref{eq:probrat}) one can find that
\begin{eqnarray*}
       p_K & = & 1-\frac{1}{J_K} \\
       p_{L_1} & = & (1-p_K)\cdot (1 - \frac{1}{J_{L_1}}) \\
       p_{L_{II}} & = & (1-p_K-p_{L_I})\cdot r_{L_{II}} \\
       p_{L_{III}} & = & (1-p_K-p_{L_I})\cdot r_{L_{III}}
\end{eqnarray*}
After simple calculations one obtains the probability distribution function
which is used to select the shell.
\subsection{Angular distributions of photoelectrons}

The angular distributions of photoelectrons should be calculated using the
partial wave analysis for the outgoing electron. Since this method is very time
consuming we use approximations of the angular distributions calculated by
F. von Sauter \cite{bib-SAUTER1} \cite{bib-SAUTER2} (K shell) and Gavrila
\cite{bib-GAVRILA-K} \cite{bib-GAVRILA-L}
(K and L shells). We use the cross-section
which is correct only to zero order in $\alpha Z$. This approximation foresees
zero scattering amplitude in the direction of incident photon while
experimentally the cross-section at $0$ angle is non-vanishing \cite{bib-NAGEL}.
If
\begin{eqnarray*}
           X &=& 1-\beta\cos\Theta
\end{eqnarray*}
then for $K$ and $L_I$ shells we use:
\begin{eqnarray}
           \frac{d\sigma_{K,L_{I}}}{d(\cos\Theta)}
           &\sim& \frac{\sin^2\Theta}{X^4}
                \left\{1+ \frac{1}{2}\gamma(\gamma-1)(\gamma-2)\right\}
\label{eq:angkl}
\end{eqnarray}
 and for $L_{II}$  and $L_{III}$ shells we have:
\begin{eqnarray}
 \frac{d\sigma_{L_{II}}}{d(\cos\Theta)}
           &\sim & \frac{(\gamma^2-1)^{\frac{1}{2}}}{\gamma^5(\gamma-1)^5}
           \left\{ \frac{\gamma(3\gamma+1)}{2 X^4}
      -\frac{\gamma^2(9\gamma^2+30\gamma-7)}{8 X^3} \right.  \nonumber \\
      \ & \ &      +\frac{\gamma^3(\gamma^3+6\gamma^2+11\gamma-2)}{4 X^2}
            -\frac{\gamma^4(\gamma-1)(\gamma+7)}{8 X} \\
         \ & \ &    +\sin^2\Theta
                  \left.    \left(
                         \frac{(\gamma+1)}{X^5}
                        -\frac{\gamma(\gamma+1)}{X^4}
                        -\frac{\gamma^2(3\gamma+1)(\gamma^2-1)}{X^3}
                      \right)
           \right\} \nonumber
\label{eq:angl2}
\end{eqnarray}

\begin{eqnarray}
           \frac{d\sigma_{L_{III}}}{d(\cos\Theta)}
           &\sim & \frac{(\gamma^2-1)^{\frac{1}{2}}}{\gamma^5(\gamma-1)^5}
           \left\{ -\frac{\gamma(3\gamma-1)}{2 X^4}
                   +\frac{\gamma^2(3\gamma^2-1)}{X^3} \right. \nonumber \\
        \ & \ & \frac{\gamma^3(\gamma^3-3\gamma^2+2\gamma+1)}{X^3}
                   -\frac{\gamma^4(\gamma-2)(\gamma-1)}{2 X} \\
        \ & \ & +\sin^2\Theta
                  \left.    \left(
                   \frac{(\gamma+1)}{X^5}
                  -\frac{\gamma(\gamma+1)(3\gamma-1)}{X^4}
                  +\frac{\gamma^2(\gamma^2-1)}{X^3}
                      \right)
           \right\} \nonumber
\label{eq:angl3}
\end{eqnarray}
The azimuthal angle distribution is uniform.

\subsection{Final State}

After the photoelectron emission the atom is left in excited state.
The excitation energy equal to the binding energy $E_i$ of the shell in which the interaction took place. Subsequently the atom emits a fluorescent photon
or Auger or Coster-Kronig electron. The selection of radiative or
non-radiative transition is based on compilation by Krause \cite{bib-KRAUSE}.\\
The Auger or Coster-Kronig transitions are represented by the most probable
line for a given vacancy \cite{bib-CULLEN}. The emitted electron energy $E_e$ is
\begin{equation}
 E_e = E_i-(E_j+E_k)
\label{eq:augere}
\end{equation}
where
$E_i, E_j, E_k$ are the subshell binding energies and $E_j > E_k$.\\
In case of fluorescence we use transition rates of Scofield \cite{bib-SCOFIELD}.
We use only those transitions for which the occurrence probability is not less
than 1\%. The fluorescent photon is emitted with energy $E_\gamma$
\begin{equation}
E_\gamma = E_i-E_j
\label{eq:fluore}
\end{equation}
for transition between the subshells $i$ and $j$.\\
In addition to the above, to fulfill the energy conservation law,
emission of an additional photon is simulated. For non-radiative transitions
its energy is $E_k$ (see formula \ref{eq:augere}). In case of fluorescent
transition this photon has energy $E_j$ (see equation \ref{eq:fluore}).
The angular distribution of the emitted particle is isotropic.


%%
%% Automatically generated file from DocOnce source
%% (https://github.com/hplgit/doconce/)
%%
%%

%-------------------- begin preamble ----------------------

\documentclass[%
oneside,                 % oneside: electronic viewing, twoside: printing
final,                   % draft: marks overfull hboxes, figures with paths
10pt]{article}

\listfiles               %  print all files needed to compile this document

\usepackage{relsize,makeidx,color,setspace,amsmath,amsfonts,amssymb}
\usepackage[table]{xcolor}
\usepackage{bm,ltablex,microtype}

\usepackage[pdftex]{graphicx}

\usepackage[T1]{fontenc}
%\usepackage[latin1]{inputenc}
\usepackage{ucs}
\usepackage[utf8x]{inputenc}

\usepackage{lmodern}         % Latin Modern fonts derived from Computer Modern

% Hyperlinks in PDF:
\definecolor{linkcolor}{rgb}{0,0,0.4}
\usepackage{hyperref}
\hypersetup{
    breaklinks=true,
    colorlinks=true,
    linkcolor=linkcolor,
    urlcolor=linkcolor,
    citecolor=black,
    filecolor=black,
    %filecolor=blue,
    pdfmenubar=true,
    pdftoolbar=true,
    bookmarksdepth=3   % Uncomment (and tweak) for PDF bookmarks with more levels than the TOC
    }
%\hyperbaseurl{}   % hyperlinks are relative to this root

\setcounter{tocdepth}{2}  % levels in table of contents

% --- fancyhdr package for fancy headers ---
\usepackage{fancyhdr}
\fancyhf{} % sets both header and footer to nothing
\renewcommand{\headrulewidth}{0pt}
\fancyfoot[LE,RO]{\thepage}
% Ensure copyright on titlepage (article style) and chapter pages (book style)
\fancypagestyle{plain}{
  \fancyhf{}
  \fancyfoot[C]{{\footnotesize \copyright\ 1999-2019, "Computational Physics I FYS3150/FYS4150":"http://www.uio.no/studier/emner/matnat/fys/FYS3150/index-eng.html". Released under CC Attribution-NonCommercial 4.0 license}}
%  \renewcommand{\footrulewidth}{0mm}
  \renewcommand{\headrulewidth}{0mm}
}
% Ensure copyright on titlepages with \thispagestyle{empty}
\fancypagestyle{empty}{
  \fancyhf{}
  \fancyfoot[C]{{\footnotesize \copyright\ 1999-2019, "Computational Physics I FYS3150/FYS4150":"http://www.uio.no/studier/emner/matnat/fys/FYS3150/index-eng.html". Released under CC Attribution-NonCommercial 4.0 license}}
  \renewcommand{\footrulewidth}{0mm}
  \renewcommand{\headrulewidth}{0mm}
}

\pagestyle{fancy}

% prevent orhpans and widows
\clubpenalty = 10000
\widowpenalty = 10000

% --- end of standard preamble for documents ---

% insert custom LaTeX commands...

\raggedbottom
\makeindex
\usepackage[totoc]{idxlayout}   % for index in the toc
\usepackage[nottoc]{tocbibind}  % for references/bibliography in the toc

%-------------------- end preamble ----------------------

\begin{document}

% matching end for #ifdef PREAMBLE

\newcommand{\exercisesection}[1]{\subsection*{#1}}

% ------------------- main content ----------------------

% ----------------- title -------------------------

\thispagestyle{empty}

\begin{center}
{\LARGE\bf
\begin{spacing}{1.25}
Project 2, deadline  September 30
\end{spacing}
}
\end{center}

% ----------------- author(s) -------------------------

\begin{center}
{\bf \href{{http://www.uio.no/studier/emner/matnat/fys/FYS3150/index-eng.html}}{Computational Physics I FYS3150/FYS4150}}
\end{center}

    \begin{center}
% List of all institutions:
\centerline{{\small Department of Physics, University of Oslo, Norway}}
\end{center}

% ----------------- end author(s) -------------------------

% --- begin date ---
\begin{center}
Sep 18, 2019
\end{center}
% --- end date ---

\vspace{1cm}

\subsection*{Eigenvalue problems, from the equations of a buckling beam to Schroedinger's equation for two electrons in a three-dimensional harmonic oscillator well}

\paragraph{Introduction.}
The aim of this project is to develop your own code for solving
eigenvalue problems. The matrix to diagonalize is the same as the one
we encountered in project one, a so-called tridiagonal Toeplitz
matrix. This matrix has analytical eigenpairs (eigenvalues and
eigenvectors) and gives us an excellent testing ground for our
algorithms. In this project we will develop an eigenvalue solver based
on Jacobi's method. The project will also introduce you to units tests
and we will compare our results against other eigenvalue solvers (from
LAPACK and/or numpy).

This project aims also at introducing to you the concept of \href{{http://www.springer.com/us/book/9783319327259}}{scaling
of equations}. This
means often either making various variables dimensionless or
introducing units which are more convenient.

We will start with the two-point boundary value problem of a buckling
beam or a spring fastened at both ends. This is one of the problems
which has analytical solutions. Thereafter, by simply adding a new
variable along the diagonal elements, we can study quantum mechanical
problems. In particular, we will study the harmonic oscillator problem
in three dimensions, with one or two electrons. For the latter case we
can study the role of the repulsive Coulomb interaction and extract
interesting physics results. For selected frequencies, this
interacting two-electron problem exhibits analytical solutions, one of the few cases of an interacting system where wecan find analytical solutions. See
\href{{http://prola.aps.org/abstract/PRA/v48/i5/p3561_1}}{M. Taut, Phys. Rev. A 48, 3561
(1993)} for the derivation of analytical expressions for the eigenpairs..

Electrons confined in small areas in semiconductors, so-called quantum
dots, form a hot research area in modern solid-state physics, with
applications spanning from such diverse fields as quantum
nano-medicine to the contruction of quantum gates.
The article on quantum computing with quantum dots by \href{{http://journals.aps.org/pra/abstract/10.1103/PhysRevA.57.120}}{Loss and DiVincenzo} is an excellent read for those interested in this exciting topic.

\paragraph{The buckling beam problem, a classical wave function problem in one dimension.}
We start with the following differential equation, namely
\[
\gamma \frac{d^2 u(x)}{dx^2} = -F u(x),
\]
where $u(x)$ is the vertical displacement of the beam in the $y$ direction.
The beam has length $L$, $x\in [0,L]$ and $F$ is a force applied at $(L,0)$ in the direction towards the origin.
The parameter $\gamma$ is a constant defined by properties like the rigidity of the beam.
We apply again so-called Dirichlet boundary conditions and set $u(0)=u(L)=0$.

In this specific case two of the  parameters $\gamma$, $F$ and $L$ are known. As an example, assume we know $F$ and $L$. Then the eigenvalue problem we set up below will allow us to find $\gamma$.

We define a dimensional variable
\[
 \rho = \frac{x}{L},
\]
meaning that we have $\rho \in [0,1]$.    By reordering the equation as
\[
 \frac{d^2 u(\rho)}{d\rho^2} = -\frac{FL^2}{\gamma} u(\rho)=-\lambda u(\rho),
\]
with $\lambda= FL^2/\gamma$ we have an equation that when discretized, becomes an eigenvalue problem.
We use the same
expression for the second derivative of a function $u$ as we did in project 1, namely
\begin{equation}
    u''=\frac{u(\rho+h) -2u(\rho) +u(\rho-h)}{h^2} +O(h^2),
    \label{eq:diffoperation}
\end{equation}
where $h$ is our step.
Next we define minimum and maximum values for the variable $\rho$,
$\rho_{\mathrm{min}}=0$  and $\rho_{\mathrm{max}}=1$, respectively.
With a given number of mesh points, $N$, we
define the step length $h$ as, with $\rho_{\mathrm{min}}=\rho_0$  and $\rho_{\mathrm{max}}=\rho_N$,
\begin{equation*}
  h=\frac{\rho_N-\rho_0 }{N}.
\end{equation*}
The value of $\rho$ at a point $i$ is then
\[
    \rho_i= \rho_0 + ih \hspace{1cm} i=1,2,\dots , N.
\]
We can rewrite the differential equation for a value $\rho_i$ as
\[
-\frac{u(\rho_i+h) -2u(\rho_i) +u(\rho_i-h)}{h^2}  = \lambda u(\rho_i),
\]
or in  a more compact way as
\[
-\frac{u_{i+1} -2u_i +u_{i-1} }{h^2}  = \lambda u_i.
\]
Following our approach from project 1, we can rewrite this equation in a more a general form, but now
as an eigenvalue problem, that is
\begin{equation}
    \begin{bmatrix} d& a & 0   & 0    & \dots  &0     & 0 \\
                                a & d & a & 0    & \dots  &0     &0 \\
                                0   & a & d & a  &0       &\dots & 0\\
                                \dots  & \dots & \dots & \dots  &\dots      &\dots & \dots\\
                                0   & \dots & \dots & \dots  &a  &d & a\\
                                0   & \dots & \dots & \dots  &\dots       &a & d\end{bmatrix}
                                 \begin{bmatrix} u_1 \\ u_2 \\ u_3 \\ \dots \\ u_{N-2} \\ u_{N-1}\end{bmatrix} = \lambda \begin{bmatrix} u_1 \\ u_2 \\ u_3 \\ \dots \\ u_{N-2} \\ u_{N-1}\end{bmatrix} .
\label{eq:matrixse}
\end{equation}
As in project 1, we have not included the endpoints $u_0$ and $u_N$.
We have defined $d=2/h^2$ and the non-diagonal ones as $a=-1/h^2$. This eigenvalue problem has analytical eigenpairs, with eigenvalues given as
\[
\lambda_j = d+2a\cos{(\frac{j\pi}{N+1})} \hspace{0.1cm} j=1,2,\dots N.
\]

\paragraph{Project 2 a): Mathematical intermezzo.}
A unitary transformation preserves  the orthogonality of the obtained eigenvectors. To see this consider first a basis of vectors $\mathbf{v}_i$,
\[
\mathbf{v}_i = \begin{bmatrix} v_{i1} \\ \dots \\ \dots \\v_{in} \end{bmatrix}
\]
We assume that the basis is orthogonal, that is
\[
\mathbf{v}_j^T\mathbf{v}_i = \delta_{ij}.
\]
Show that an orthogonal or unitary transformation
\[
\mathbf{w}_i=\mathbf{U}\mathbf{v}_i,
\]
preserves the dot product and orthogonality.

\paragraph{Project 2 b): Setting up a code for tridiagonal Toeplitz matrix.}
Your task now is to write a function which implements Jacobi's rotation algorithm (see Lecture notes chapter 7)  in order to solve Eq. (\ref{eq:matrixse}).
However, the first simple check is to set up the matrix to diagonalize for a given $N$ and use either armadillo's or numpy's functions for diagonalizing a matrix. You can then check that you obtain the analytical eigenvalues.

For Jacobi's method,
we define the quantities $\tan\theta = t= s/c$, with $s=\sin\theta$ and $c=\cos\theta$ and
\begin{equation*}\cot 2\theta=\tau = \frac{a_{ll}-a_{kk}}{2a_{kl}}.
\end{equation*}
We can then define the angle $\theta$ so that the non-diagonal matrix elements of the transformed matrix
$a_{kl}$ become non-zero and
we obtain the quadratic equation (using $\cot 2\theta=1/2(\cot \theta-\tan\theta)$

\begin{equation*}
t^2+2\tau t-1= 0,
\end{equation*}
resulting in

\begin{equation*}
  t = -\tau \pm \sqrt{1+\tau^2},
\end{equation*}
and $c$ and $s$ are easily obtained via

\begin{equation*}
   c = \frac{1}{\sqrt{1+t^2}},
\end{equation*}
and $s=tc$.

How many similarity transformations are needed before you reach a
result where all non-diagonal matrix elements are essentially zero?
Try to estimate the number of transformations and extract a behavior as function
of the dimensionality of the matrix. Compare your results with the analytical ones.

You can check your results against the Armadillo function for solving
eigenvalue problems. The armadillo function \emph{eigsys} can be used to find eigenvalues and eigenvectors.
A Python program which solves this part of the project is available under the \href{{http://compphysics.github.io/ComputationalPhysics/doc/pub/projectwriting/html/projectwriting.html}}{project writing slides}.

Comment your results (here you could for example compute the time needed for
both algorithms for a given dimensionality of the matrix).

\paragraph{Project 2 c): Implementing tests in your code.}
In this project (and later ones as well) we will implement so-called
\textbf{unit} tests. Our unit tests are mainly meant to test mathematical
properties of our algorithm. During the development phase of a program
it is useful to devise tests that your program should pass. One of
these is to make sure that for a given simple test matrix (say a
$5\times 5$ matrix) our algorithm for searching for the largest
non-diagonal element always returns the correct answer. Furthermore,
for a known simple matrix, irrespective of changes made, we should
always get the same and correct eigenvalues. Another test is to make
sure that the orthogonality shown in exercise (a) is preserved. Try to
figure out other tests your code should pass, based either on the
mathematical properties of the algorithms or more program specific
tests. Implement at least two unit tests in this project.

\paragraph{Extending our machinery to quantum mechanics.}
Here we will assume that these electrons move in a three-dimensional harmonic
oscillator potential (they are confined by for example quadrupole fields)
and repel  each other via the static Coulomb interaction.
We assume spherical symmetry.  You don't need to think of quantum mechanics when solving this project, look at it as another diagonalization problem.

We are first interested in the solution of the radial part of Schroedinger's equation for one electron. This equation reads

\begin{equation*}
  -\frac{\hbar^2}{2 m} \left ( \frac{1}{r^2} \frac{d}{dr} r^2
  \frac{d}{dr} - \frac{l (l + 1)}{r^2} \right )R(r)
     + V(r) R(r) = E R(r).
\end{equation*}
In our case $V(r)$ is the harmonic oscillator potential $(1/2)kr^2$ with
$k=m\omega^2$ and $E$ is
the energy of the harmonic oscillator in three dimensions.
The oscillator frequency is $\omega$ and the energies are

\begin{equation*}
E_{nl}=  \hbar \omega \left(2n+l+\frac{3}{2}\right),
\end{equation*}
with $n=0,1,2,\dots$ and $l=0,1,2,\dots$.

Since we have made a transformation to spherical coordinates it means that
$r\in [0,\infty)$.
The quantum number
$l$ is the orbital momentum of the electron.
%
Then we substitute $R(r) = (1/r) u(r)$ and obtain
%

\begin{equation*}
  -\frac{\hbar^2}{2 m} \frac{d^2}{dr^2} u(r)
       + \left ( V(r) + \frac{l (l + 1)}{r^2}\frac{\hbar^2}{2 m}
                                    \right ) u(r)  = E u(r) .
\end{equation*}
%
The boundary conditions are $u(0)=0$ and $u(\infty)=0$.

We introduce a dimensionless variable $\rho = (1/\alpha) r$
where $\alpha$ is a constant with dimension length and get
%

\begin{equation*}
  -\frac{\hbar^2}{2 m \alpha^2} \frac{d^2}{d\rho^2} u(\rho)
       + \left ( V(\rho) + \frac{l (l + 1)}{\rho^2}
         \frac{\hbar^2}{2 m\alpha^2} \right ) u(\rho)  = E u(\rho) .
\end{equation*}
%
We will set in this project $l=0$.
Inserting $V(\rho) = (1/2) k \alpha^2\rho^2$ we end up with

\begin{equation*}
  -\frac{\hbar^2}{2 m \alpha^2} \frac{d^2}{d\rho^2} u(\rho)
       + \frac{k}{2} \alpha^2\rho^2u(\rho)  = E u(\rho) .
\end{equation*}
We multiply thereafter with $2m\alpha^2/\hbar^2$ on both sides and obtain

\begin{equation*}
  -\frac{d^2}{d\rho^2} u(\rho)
       + \frac{mk}{\hbar^2} \alpha^4\rho^2u(\rho)  = \frac{2m\alpha^2}{\hbar^2}E u(\rho) .
\end{equation*}
The constant $\alpha$ can now be fixed
so that

\begin{equation*}
\frac{mk}{\hbar^2} \alpha^4 = 1,
\end{equation*}
or

\begin{equation*}
\alpha = \left(\frac{\hbar^2}{mk}\right)^{1/4}.
\end{equation*}
Defining

\begin{equation*}
\lambda = \frac{2m\alpha^2}{\hbar^2}E,
\end{equation*}
we can rewrite Schroedinger's equation as

\begin{equation*}
  -\frac{d^2}{d\rho^2} u(\rho) + \rho^2u(\rho)  = \lambda u(\rho) .
\end{equation*}
This is the first equation to solve numerically. In three dimensions
the eigenvalues for $l=0$ are
$\lambda_0=3,\lambda_1=7,\lambda_2=11,\dots .$

We define minimum and maximum values for the variable $\rho$,
$\rho_{\mathrm{min}}=0$  and $\rho_{\mathrm{max}}$, respectively.
You need to check your results for the energies against different values
$\rho_{\mathrm{max}}$, since we cannot set
$\rho_{\mathrm{max}}=\infty$.

With a given number of mesh points, $N$, we
define the step length $h$ as, with $\rho_{\mathrm{min}}=\rho_0$  and $\rho_{\mathrm{max}}=\rho_N$,

\begin{equation*}
  h=\frac{\rho_N-\rho_0 }{N}.
\end{equation*}
The value of $\rho$ at a point $i$ is then
\[
    \rho_i= \rho_0 + ih \hspace{1cm} i=1,2,\dots , N.
\]
We can rewrite the Schroedinger equation for a value $\rho_i$ as

\[
-\frac{u(\rho_i+h) -2u(\rho_i) +u(\rho_i-h)}{h^2}+\rho_i^2u(\rho_i)  = \lambda u(\rho_i),
\]
or in  a more compact way

\[
-\frac{u_{i+1} -2u_i +u_{i-1}}{h^2}+\rho_i^2u_i=-\frac{u_{i+1} -2u_i +u_{i-1} }{h^2}+V_iu_i  = \lambda u_i,
\]
where $V_i=\rho_i^2$ is the harmonic oscillator potential.

We define first the diagonal matrix element
\begin{equation*}
   d_i=\frac{2}{h^2}+V_i,
\end{equation*}
and the non-diagonal matrix element
\begin{equation*}
   e_i=-\frac{1}{h^2}.
\end{equation*}
In this case the non-diagonal matrix elements are given by a mere constant.
\emph{All non-diagonal matrix elements are equal}.
With these definitions the Schroedinger equation takes the following form

\begin{equation*}
d_iu_i+e_{i}u_{i-1}+e_{i}u_{i+1}  = \lambda u_i,
\end{equation*}
where $u_i$ is unknown. We can write the
latter equation as a matrix eigenvalue problem
\begin{equation}
    \begin{bmatrix}d_1 & e_1 & 0   & 0    & \dots  &0     & 0 \\
                                e_1 & d_2 & e_2 & 0    & \dots  &0     &0 \\
                                0   & e_2 & d_3 & e_3  &0       &\dots & 0\\
                                \dots  & \dots & \dots & \dots  &\dots      &\dots & \dots\\
                                0   & \dots & \dots & \dots  &\dots  e_{N-3}     &d_{N-2} & e_{N-2}\\
                                0   & \dots & \dots & \dots  &\dots       &e_{N-2} & d_{N-1}
             \end{bmatrix}  \begin{bmatrix} u_{1} \\
                                                              u_{2} \\
                                                              \dots\\ \dots\\ \dots\\
                                                              u_{N-1}
             \end{bmatrix}=\lambda \begin{bmatrix} u_{1} \\
                                                              u_{2} \\
                                                              \dots\\ \dots\\ \dots\\
                                                              u_{N-1}
             \end{bmatrix}.
      \label{eq:sematrix}
\end{equation}

Note here that we have not included the endpoints since we assume that they are knowm (as we did in project 1). The matrix is also symmetric in this case.

\paragraph{Project 2 d): Quantum dots in three dimensions, one electron.}
Add the harmonic oscillator potential to your tridiagonal Toeplitz matrix from 2a-2c and diagonalize the matrix.
Study the results as functions of the number of integration points $N$ and your approximation to $\rho_{\mathrm{max}}$.
The analytical results with our scaling for the one-electron energies are $\lambda=3,7,11,15,\dots$. How many integration points do you need in order to reproduce the analytical results with say four leading digits after the decimal point?

You can reuse the code you wrote for part (b),
but you need to add  the potential $\rho^2$ to the diagonal elements.

\paragraph{Project 2 e): Quantum dots in three dimensions, two electrons.}
Note: if you are not interested in the explicit quantum physics case here, you can replace this part with either 2g or 2h below. The latter ones are optional exercises if you do this.

We will now study two electrons in a harmonic oscillator well which
also interact via a repulsive Coulomb interaction.
Let us start with the single-electron equation written as

\begin{equation*}
  -\frac{\hbar^2}{2 m} \frac{d^2}{dr^2} u(r)
       + \frac{1}{2}k r^2u(r)  = E^{(1)} u(r),
\end{equation*}
where $E^{(1)}$ stands for the energy with one electron only.
For two electrons with no repulsive Coulomb interaction, we have the following
Schroedinger equation

\begin{equation*}
\left(  -\frac{\hbar^2}{2 m} \frac{d^2}{dr_1^2} -\frac{\hbar^2}{2 m} \frac{d^2}{dr_2^2}+ \frac{1}{2}k r_1^2+ \frac{1}{2}k r_2^2\right)u(r_1,r_2)  = E^{(2)} u(r_1,r_2) .
\end{equation*}

Note that we deal with a two-electron wave function $u(r_1,r_2)$ and
two-electron energy $E^{(2)}$.

With no interaction this can be written out as the product of two
single-electron wave functions, that is we have a solution on closed form.

We introduce the relative coordinate $\mathbf{r} = \mathbf{r}_1-\mathbf{r}_2$
and the center-of-mass coordinate $\mathbf{R} = 1/2(\mathbf{r}_1+\mathbf{r}_2)$.
With these new coordinates, the radial Schroedinger equation reads

\begin{equation*}
\left(  -\frac{\hbar^2}{m} \frac{d^2}{dr^2} -\frac{\hbar^2}{4 m} \frac{d^2}{dR^2}+ \frac{1}{4} k r^2+  kR^2\right)u(r,R)  = E^{(2)} u(r,R).
\end{equation*}

The equations for $r$ and $R$ can be separated via the ansatz for the
wave function $u(r,R) = \psi(r)\phi(R)$ and the energy is given by the sum
of the relative energy $E_r$ and the center-of-mass energy $E_R$, that
is

\begin{equation*}
E^{(2)}=E_r+E_R.
\end{equation*}

We add then the repulsive Coulomb interaction between two electrons,
namely a term

\begin{equation*}
V(r_1,r_2) = \frac{\beta e^2}{|\mathbf{r}_1-\mathbf{r}_2|}=\frac{\beta e^2}{r},
\end{equation*}
with $\beta e^2=1.44$ eVnm.

Adding this term, the $r$-dependent Schroedinger equation becomes

\begin{equation*}
\left(  -\frac{\hbar^2}{m} \frac{d^2}{dr^2}+ \frac{1}{4}k r^2+\frac{\beta e^2}{r}\right)\psi(r)  = E_r \psi(r).
\end{equation*}
This equation is similar to the one we had previously in (b) and we introduce
again a dimensionless variable $\rho = r/\alpha$. Repeating the same
steps as above, we arrive at

\begin{equation*}
  -\frac{d^2}{d\rho^2} \psi(\rho)
       + \frac{1}{4}\frac{mk}{\hbar^2} \alpha^4\rho^2\psi(\rho)+\frac{m\alpha \beta e^2}{\rho\hbar^2}\psi(\rho)  =
\frac{m\alpha^2}{\hbar^2}E_r \psi(\rho) .
\end{equation*}
We want to manipulate this equation further to make it as similar to that in (a)
as possible. We define a new 'frequency'

\begin{equation*}
\omega_r^2=\frac{1}{4}\frac{mk}{\hbar^2} \alpha^4,
\end{equation*}
and fix the constant $\alpha$ by requiring

\begin{equation*}
\frac{m\alpha \beta e^2}{\hbar^2}=1
\end{equation*}
or

\begin{equation*}
\alpha = \frac{\hbar^2}{m\beta e^2}.
\end{equation*}
Defining

\begin{equation*}
\lambda = \frac{m\alpha^2}{\hbar^2}E,
\end{equation*}
we can rewrite Schroedinger's equation as

\begin{equation*}
  -\frac{d^2}{d\rho^2} \psi(\rho) + \omega_r^2\rho^2\psi(\rho) +\frac{1}{\rho} = \lambda \psi(\rho).
\end{equation*}
We treat $\omega_r$ as a parameter which reflects the strength of the oscillator potential.

Here we will study the cases $\omega_r = 0.01$, $\omega_r = 0.5$, $\omega_r =1$,
and $\omega_r = 5$
for the ground state only, that is the lowest-lying state.

With no repulsive Coulomb interaction
you should get a result which corresponds to
the relative energy of a non-interacting system.
Make sure your results are
stable as functions of $\rho_{\mathrm{max}}$ and the number of steps.

We are only interested in the ground state with $l=0$. We omit the
center-of-mass energy.

You can reuse the code you wrote for part (b),
but you need to add  the potential $\omega_r^2\rho^2+1/\rho$ to the diagonal elements.

Comment the results for the lowest state (ground state) as function of
varying strengths of $\omega_r$.

For specific oscillator frequencies, the above equation has answers in an analytical form,
see the article by \href{{http://prola.aps.org/abstract/PRA/v48/i5/p3561_1}}{M. Taut, Phys. Rev. A 48, 3561 (1993)}.

\paragraph{Project 2 f): First optional exercise: Quantum physics analysis of  the results.}
This exercise is a continuation of the previous and adds more quantum physics to the analysis.
In this exercise we want to plot the wave function
for two electrons as functions of the relative coordinate $r$ and different
values of $\omega_r$.  With no Coulomb interaction you should have a result which corresponds to the non-interacting case.
Plot either the function itself or the probability distribution (the function squared) with and without the repulsion between the two electrons.
Varying $\omega_r$, the shape of the wave function
will change.

We are only interested in the wave function for the ground state with $l=0$ and
omit again the  center-of-mass motion.

The eigenvectors are normalized.
Plot then the normalized wave functions for different  values of $\omega_r$ and comment the results.

\paragraph{Project 2 g): Second optional challenge: Smarter way of finding the eigenvalues.}
This exercise is also optional and is an algorithmic challenge. Your matrix is already tridiagonal.
Can you devise a more efficient way to find the eigenvalues and eigenvectors instead of the brute force application of Jacobi's method?
Hint: Use the bisection method discussed in for example \href{{http://www.maths.ed.ac.uk/~aar/papers/bamawi.pdf}}{Barth, Martin and Wilkinson, Numerische Mathematik 9, 386 (1967)}.

\paragraph{Project 2 h): Third optional challenge: Implementing Lanczos' algorithm.}
This exercise is optional and is meant more as a challenge for those of you with an interest in other algorithms for solving eigenvalue problems.
Implement the iterative Lanczos' algorithm discussed in the lecture notes and compute the lowest eigenvalues
as done in exercise (c) or (d) above. Compare your results and discuss faults and merits of the iterative method versus
direct methods like Jacobi's method.

\subsection*{Introduction to numerical projects}

Here follows a brief recipe and recommendation on how to write a report for each
project.

\begin{itemize}
  \item Give a short description of the nature of the problem and the eventual  numerical methods you have used.

  \item Describe the algorithm you have used and/or developed. Here you may find it convenient to use pseudocoding. In many cases you can describe the algorithm in the program itself.

  \item Include the source code of your program. Comment your program properly.

  \item If possible, try to find analytic solutions, or known limits in order to test your program when developing the code.

  \item Include your results either in figure form or in a table. Remember to        label your results. All tables and figures should have relevant captions        and labels on the axes.

  \item Try to evaluate the reliabilty and numerical stability/precision of your results. If possible, include a qualitative and/or quantitative discussion of the numerical stability, eventual loss of precision etc.

  \item Try to give an interpretation of you results in your answers to  the problems.

  \item Critique: if possible include your comments and reflections about the  exercise, whether you felt you learnt something, ideas for improvements and  other thoughts you've made when solving the exercise. We wish to keep this course at the interactive level and your comments can help us improve it.

  \item Try to establish a practice where you log your work at the  computerlab. You may find such a logbook very handy at later stages in your work, especially when you don't properly remember  what a previous test version  of your program did. Here you could also record  the time spent on solving the exercise, various algorithms you may have tested or other topics which you feel worthy of mentioning.
\end{itemize}

\noindent
\subsection*{Format for electronic delivery of report and programs}

The preferred format for the report is a PDF file. You can also use DOC or postscript formats or as an ipython notebook file.  As programming language we prefer that you choose between C/C++, Fortran2008 or Python. The following prescription should be followed when preparing the report:

\begin{itemize}
  \item Use Devilry to hand in your projects, log in  at  \href{{http://devilry.ifi.uio.no}}{\nolinkurl{http://devilry.ifi.uio.no}} with your normal UiO username and password and choose either 'fys3150' or 'fys4150'. There you can load up the files within the deadline.

  \item Upload \textbf{only} the report file!  For the source code file(s) you have developed please provide us with your link to your github domain.  The report file should include all of your discussions and a list of the codes you have developed.  Do not include library files which are available at the course homepage, unless you have made specific changes to them.

  \item In your git repository, please include a folder which contains selected results. These can be in the form of output from your code for a selected set of runs and input parameters.

  \item In this and all later projects, you should include tests (for example unit tests) of your code(s).

  \item Comments  from us on your projects, approval or not, corrections to be made  etc can be found under your Devilry domain and are only visible to you and the teachers of the course.
\end{itemize}

\noindent
Finally,
we encourage you to work two and two together. Optimal working groups consist of
2-3 students. You can then hand in a common report.

% ------------------- end of main content ---------------

\end{document}