Sunday, 25 August 2013

Code for TrA animation

As promised the code for the animation I did previously which shows how transient absorption data is collected.
So I import the libraries and generate the mock data. I then play around with the plot so it looks right.

import numpy as np
import matplotlib.pyplot as plt
from scipy import special
from mpl_toolkits.mplot3d import axes3d
import numpy.ma as ma

#Generate some mock data
t1 = np.linspace(-10,-2,num=9)
t = np.append(t1,np.linspace(-1,1,num=9))
t = np.append(t,np.linspace(2,10,num=9))
T = np.append(t,np.linspace(20,100,num=9))
L = np.linspace(400,800)

l,t = np.meshgrid(L,T)

#Spectra
A = np.exp(-(l-650)**2/(2*50**2))+0.3*np.exp(-(l-550)**2/(2*50**2))

A1 = 0.01
T1 = 20.0
mu = 0.0
w = 0.2
y0 = 0

d = (w/(2*np.sqrt(2*np.log(2))))
#Kinetics
K = A1*1/2*np.exp(-t/T1)*np.exp((mu+(d**2)/(2*T1))/T1)*(1+special.erf((t-(mu+(d**2)/T1))/(np.sqrt(2)*d))) + y0

#Masking matrix
mask = np.ones(l.shape)

#2D spectrum
Psi = K*A

#Forming the initial plot
fig = plt.figure(figsize=(13,8))
ax = fig.add_subplot(221, projection='3d')
ax.plot_wireframe(l, t, Psi, linewidth=0.5)
ax.view_init(35, 340)
ax.set_zlim(0.0,0.012)

plt.subplot(222)
plt.contourf(L,T,Psi,500)
plt.colorbar()
plt.title("Contour plot")
plt.xlabel("Wavelength (nm)")
plt.ylabel("Time (ps)")

plt.subplot(223)
plt.plot(T,Psi)
plt.title("Kinetic")
plt.xlabel("Time (ps)")
plt.ylabel("Abs.")

plt.subplot(224)
plt.plot(L,Psi.T)
plt.title("Spectra")
plt.xlabel("Wavelength (nm)")
plt.ylabel("Abs.")

plt.subplots_adjust(left=0.06, bottom=0.06, right=0.99, top=0.96, wspace=0.15, hspace=0.22)
plt.savefig("animation.png")
plt.show()

Then I loop through the masking matrix and save each plot successively.

for i in range(10,L.shape[0]):
    mask_i = mask.copy()
    mask_i[i:,:] = 0.0
    Psi_i = Psi.copy()*mask_i
    
    fig = plt.figure(figsize=(13,8))
    ax = fig.add_subplot(221, projection='3d')
    ax.plot_wireframe(l, t, Psi_i,linewidth=0.5)
    ax.view_init(35, 340)
    ax.set_zlim(0.0,0.012)
    
    plt.subplot(222)
    plt.contourf(L,T,Psi_i,200)
    plt.colorbar()
    plt.title("Contour plot")
    plt.xlabel("Wavelength (nm)")
    plt.ylabel("Time (ps)")

    plt.subplot(223)
    plt.plot(T,Psi_i)
    plt.title("Kinetic")
    plt.xlabel("Time (ps)")
    plt.ylabel("Abs.")
    plt.ylim(0.0,0.012)

    plt.subplot(224)
    plt.plot(L,Psi_i.T)
    plt.title("Spectra")
    plt.xlabel("Wavelength (nm)")
    plt.ylabel("Abs.")
    plt.ylim(0.0,0.012)

    plt.subplots_adjust(left=0.06, bottom=0.06, right=0.99, top=0.96, wspace=0.15, hspace=0.22)
    plt.savefig("animation_%s.png"%(i))

I used ImageJ to put the pictures into a gif and set the time between the frames.

Sunday, 11 August 2013

Seeing quantum

When you first learn about quantum mechanics there are two simple examples that can be solved exactly and help give some quantum intuition. Particle in a box and the harmonic oscillator. Recently two experiments have used a scanning tunneling microscope to somewhat let us see these text book examples happening in real systems.

I will do a post on how a scanning tunneling microscope uses tunneling of electrons to image electrons. For now you can think of a STM as a sharp tip that when bought near to the surface can allow electrons to jump onto the tip and let a very small electric current to flow. The voltage of the tip can be used to excite different energy electrons onto the tip. By scanning the tip over the same you can measure the electron density (not position but density more like a localized wave then a particle in this case).


The really cool thing is that you get to image the electron density directly which is quantum mechanics is as close as we get to working out where the electron is.

Particle-in-a-box
The particle in a box is the solution to a quantum particle contained with an energy well. In other words the electron cannot get out of some region of space. The potential energy function is usually drawn as:


The solutions for a quantum particle are
$\psi = \sqrt{\dfrac{2}{L}}sin{\dfrac{n\pi}{L}}x $
Check out how to find the solution at this link

I always found it difficult to think of a physical analogy to this. One system that is often used is a hydrocarbon chain with a conjugated backbone. Electrons are confined along the whole length of the chain and it can be thought of as a analogy to the particle in a box.

A while back I saw a great experiment that seeks to replicate this particle in a box. Using a STM they picked up Palladium atoms and lined up 20 of them. As the electrons were spread out over the whole length and was constrained within the length of the atoms it can be thought of as a analogy to the particle in a box.

STM image of the Palladium atoms lined up 

Using different voltages of the STM tip they were able to excite different energy modes which were found to approximate the solutions for the particle in a box.


(Image from Princples of Modern Chemistry, Oxtoby et al.)

Nilius, N., Wallis, T. M., & Ho, W. (2005). Realization of a particle-in-a-box: electron in an atomic Pd chain. The journal of physical chemistry. B, 109(44), 20657–60. doi:10.1021/jp053496l

Harmonic oscillator

The second system that can be easily solved is a quantum particle in a harmonic (parabolic) potential. The potential for this looks something like this and look a bit like the potential energy of a bond between two atoms.

The harmonic potential (dotted line) approximates the potential energy between two bonding atoms which is shown (solid line) (Image reference)

Think of this as the atoms are vibrating but because everything is quantum you can't vibrate at any frequency you can only vibrate at discrete values. The wave functions can be calculated

By squaring the wave function (left) we get the density or probability (right) of the position of the atoms in this case.

Recently I saw another awesome experiment using the STM and electrons stuck in bits of semiconductor.

By changing the bias voltage on this small quantum dot they were able to excite different vibrational modes of the electron stuck inside of this harmonic potential.

The solid lines are the probability densities and the circles are the current/V as they scan across the dot showing the electrons density.

By scanning the bias voltage they made this nice plot that shows the different vibrational modes being excited as they come to the voltage that matches the energy of the mode.



Teichmann, K., Wenderoth, M., Prüser, H., Pierz, K., Schumacher, H. W., & Ulbrich, R. G. (2013). Harmonic Oscillator Wave Functions of a Self-Assembled InAs Quantum Dot Measured by Scanning Tunneling Microscopy. Nano letters. doi:10.1021/nl401217q

Friday, 2 August 2013

Fourier Transforms at the speed of light

The Fourier transform is a way of decomposing a signal into different frequencies' components. From the wave picture of photons that we developed earlier we can now think about how to take the Fourier transform of a mask that we put in front of a laser beam.

Double slit
The path difference can be found by considering how the spherical waves from two slits will interfere. 

We found that for the case of constructive interference we got the equation:
$dsin\theta = n\lambda$
This holds true with n being an integer. Let's rearrange the equation for $\theta$:
$sin(\theta) = \frac{n\lambda}{d}$
For small angles the small angle approximation applies
$sin(\theta)=\theta$
$\theta = \frac{n\lambda}{d}$
This shows that the angle is dependent on the reciprocal of the distance between the two slits.
$\theta \propto \frac{1}{d}$
You can think of the spatial frequency of these two points as being the reciprocal of the distance between the points.
$f_{x}\propto\frac{1}{d}$

Multiple slits
If you had multiple slits you would end up with wavefronts that constructively interfered with each other. This can be seen in the figure below. We will consider Fraunhofer diffraction where the features are relatively small compared with the wavelength of the light and we are looking far from features. This allows us to approximate the wavelets as spherical waves and consider their long range interference. You can see that far away from the source you will find approximate plane waves traveling in different directions.

Picture of approximate plane waves from a source of spherical waves (Image from Hecht Optics 2nd edition)

Fourier Transform
What is a Fourier transform? Put simply, the transform is a way to describe a function as a sum or integral of waves (sine and cosines). Let's look at the different frequency waves you need to put together to make a square wave.

The fourier transform is given as 
$F(f_{x})=\int_{-\infty}^{+\infty}f(x)e^{-2\pi i x f_{x}}df_{x}$
We define our square function as


$f(x)=A$ 
from -L/2 to L/2 where L is the length of the square wave 
 $F(f_{x})=\int_{-L/2}^{+L/2}Ae^{-2\pi i x f_{x}}df_{x}$
$F(f_{x})=\frac{A}{-2\pi i f_{x}}[e^{-2\pi i x f_{x}}]^{L/2}_{-L/2}$
$F(f_{x})=\frac{A}{-2\pi i f_{x}}[e^{-\pi i L f_{x}}-e^{\pi i L f_{x}}]$
$F(f_{x})=\frac{AL}{-\pi f_{x}L}[\frac{e^{-\pi i L f_{x}}-e^{\pi i L f_{x}}}{2i}]$
$F(f_{x})=\frac{AL}{-\pi f_{x}L}sin(\pi f_{x}L)$ 
We then define the sinc function which is sin(x)/x
 $F(f_{x})=AL[sinc(f_{x}L)]$

I found a great animation of this by Lucas.

File:Continuous Fourier transform of rect and sinc functions.gif 
How does a lens take the Fourier transform?
To see how the lens takes the Fourier transform it is helpful to look at transfer matrices where we describe a ray of light going into a lens with the position from the centre and the angle it makes to the optical axis. As it goes through different optical elements it will change its direction and position. Have a look at some of the matrices on wikipedia.

If we have a lens and then let the ray propagate by a length d we can mutliply these two matrices together to give the resulting matrix. This is called the ABCD matrix. We can then use matrix multiplication to work out what the angle and position of the ray is after these optical elements.

 {x_2 \choose \theta_2} = \begin{pmatrix} A & B \\ C & D \end{pmatrix}{x_1 \choose \theta_1},
Here is a picture of the ray (black arrow) in and the resulting ray out.


The important thing to note is that the position of the ray at the focal length is the angle of that ray in, multiplied by the focal length.


By putting the plane waves from the interference pattern through a lens we get the Fraunhofer diffraction pattern from the plane waves.
Franhofer diffraction from a small aperture at a large distance (Image from Hecht Optics 2nd edition)

You end up with the angle being dependent on the reciprocal of the size of the features. The lens then turns these plane waves into a dot on a screen and this is how a grating and lens can take the Fourier transform of a mask.

The classical device in Fourier optics is the 4f correlator, 4f because there are four focal lengths in the design.
File:4F Correlator.svg 
The input plane can be a mask that creates plane waves due to the interference of all of the spherical waves that come from the grating. The first lens takes the Fourier transform and at the focal length is the Fourier transform pattern. As the lower frequencies will be at the middle (as they diffract the light less and are least deflected) and the higher frequencies will be around the outside (as they diffract the light the most and are most deflected) you can use a pin hole to filter out the high frequency components. These were the first image filters that were used. Similar filters are used in image software and do the same thing - take the Fourier transform of the image and then mask off the parts that are to be filtered.

Fun example
We recently had a primary school teaching fellow, Cristina Cochrane, come into the lab and do a project on laser cutting of tissue in the body. This used our ultra-fast lasers which do not burn the tissue but simply remove it.

We decided to make her a certificate of appreciation when she left, so we plated chrome onto a glass plate and machined away the certificate. It was only 1 mm by 1 mm.

We put together a beam expander to make the beam large enough to cover the whole pattern. This is a diagram of the optics.


This is the image we project onto the wall. 
It is not completely obvious how we can reform the image using only one lens when you normally need at least two in the 4f correlator and this is due to the fact that the plane waves are coming out from almost the same point, so you can think of it as a spherical source of plane waves. Here are two different ways of looking at this:
The picture of the left shows how the spherical waves are collimated and focused to a point on the screen and the right picture shows how the plane waves are recollimated to reform the pattern on the screen. (Images from  Hecht Optics 2nd edition)

The picture below sums up the whole process, where you see the fourier transform and then what you see projected onto the screen.
(Image from Hecht Optics 2nd edition)