Brownian Motion and Avogadro's Number


Overview

This project may include a data collection component as well as computer programming and data analysis. In that respect, it is a good representation of how computation and programming are used in physics research.

The goal is to track the motion of particles immersed in a liquid undergoing Brownian motion. The data can be fit to Einstein's statistical model of molecular motion to estimate Avogadro's number.

The experiment involves the following five components:

  1. Data collection. Using a USB microscope and diluted milk, we can capture images of milkfat globules undergoing Brownian motion. For writing and testing the code, you will be supplied with a set of raw data as sequences of 200 JPEG images. Once you have a working analysis chain, you will collect and analyze your own data.
  2. Image segmentation. Read in an image and use thresholding to separate the image into foreground and background pixels.
  3. Particle identification. Find maximal blobs of connected foreground pixels using depth-first search.
  4. Particle tracking. Determine how far each particle moves between observations via a simple nearest neighbor calculation.
  5. Data analysis. Estimate Avogadro's number by averaging a sequence of displacements and plugging the results into Einstein's equations.

Historical perspective.

The atom played a central role in 20th century physics and chemistry, but prior to 1908 the reality of atoms and molecules was not universally accepted. In 1827, the botanist Robert Brown observed the random erratic motion of particles found in wildflower pollen grains immersed in water using a microscope. This motion would later become known as Brownian motion. Einstein hypothesized that this Brownian motion was the result of millions of tiny water molecules colliding with the larger pollen grain particles.

In one of his "miraculous year" (1905) papers, Einstein formulated a quantitative theory of Brownian motion in an attempt to justify the "existence of atoms of definite finite size." His theory provided experimentalists with a method to count molecules with an ordinary microscope by observing their collective effect on a larger immersed particle. In 1908 Jean Baptiste Perrin used the recently invented ultramicroscope to experimentally validate Einstein's kinetic theory of Brownian motion, thereby providing the first direct evidence supporting the atomic nature of matter. His experiment also provided one of the earliest estimates of Avogadro's number. For this work, Perrin won the 1926 Nobel Prize in physics.

The problem.

For this project, you will redo a version of Perrin's experiment. Your job is greatly simplified because with modern video and computer technology (in conjunction with your programming skills), it is possible to accurately measure and track the motion of an immersed particle undergoing Brownian motion. For testing and code development, you will have a set of video microscopy data of polystyrene spheres ("beads") suspended in water, undergoing Brownian motion. Your task is to write a program to analyze this data, determine how much each bead moves between observations, fit this data to Einstein's model, and estimate Avogadro's number.

The data.

For starters, you will use this supplied data to develop and validate your code. Once you are done, you will have the opportunity to collect your own data on fat globules suspended in dilute milk using a USB microscope. The test data was obtained by William Ryu using fluorescent imaging. Each run contains a sequence of two hundred 640-by-480 color JPEG images, frame00000.jpg through frame00199.jpg and is stored in a subdirectory run0 through run9.

Each image shows a two-dimensional cross section of a microscope slide. The beads move in and out of the microscope's field of view (the x- and y-directions). Beads also move in the z-direction, so they can move in and out of the microscope's depth of focus; this results in halos, and it can also result in beads completely disappearing from the image.

Particle identification.

The first challenge is to identify the beads amidst the noisy data. Each image is 640-by-480 pixels, and each pixel is represented by a Color object which needs to be converted to a luminance value ranging from 0.0 (black) to 255.0 (white). Whiter pixels correspond to beads (foreground) and blacker pixels to water (background). Break the problem into three pieces:

  • (i) read in the picture
  • (ii) classify the pixels as foreground or background by using a variable threshold luminance value (180.0 works well for the test data
  • (iii) find the disc-shaped clumps of foreground pixels that constitute each bead.

A polystyrene bead is typically represented by a disc-like shape of at least some minimum number, $P$, (typically 25) of connected foreground pixels. A blob or connected component is a maximal set of connected foreground pixels, regardless of its shape or size. Refer to any blob containing at least $P$ pixels as a bead. The center-of-mass of a blob (or bead) is the average of the x- and y-coordinates of its constituent pixels.

Suggested code structure:

Create a python module called Blobfinder.py that includes a class Blob() with the following methods:

__init__         # construct an empty blob
add(i,j)         # add a pixel (i, j) to the blob
mass()           # return number of pixels added = its mass
distanceTo(blob) # return distance between centers of masses of this blob and b
centerOfMass()   # return tuple of (x,y) values for this blob's center of mass
                 # format center-of-mass coordinates with 4 digits to right
                 # of decimal point

Include in the module the following additional functions:

def BlobFinder(picture, tau):
    '''find all blobs in the picture using the luminance threshold tau'''

def countBeads(P):
    '''return the number of beads with >= P pixels'''

def getBeads(P):
    '''return all beads with >= P pixels'''

Write a function that takes an integer $P$, a float $\tau$, and the name of a JPEG file. It should create a BlobFinder object using a luminance threshold of $\tau$ and print out the mass and center-of-mass of all of the beads with at least $P$ pixels, then finally, it should print out the mass and center-of-mass of all of the blobs (beads with at least 1 pixel).

Note: The Counting Stars lesson and exercises are exactly like the image manipulation you need to use for this part of the project. Review your code from Counting Stars to help you get started.

Particle tracking.

The next step is to determine how far a bead moved from one time step $t$ to the next $t + \Delta t$. For the test data, $\Delta t$ = 0.5 seconds per frame. Assume the data is such that each bead moves a relatively small amount, and that two beads do not collide. (However, you must account for the possibility that the bead disappears from the frame, either by departing the microscope's field of view in the x- or y- direction, or moving out of the microscope's depth of focus in the z-direction.) Thus, for each bead at time $t + \Delta t$, calculate the closest bead at time $t$ (in Euclidean distance) and identify these two as the same beads. However, if the distance is too large (greater than $\Delta p$ pixels) assume that one of the beads has either just begun or ended its journey. Record the displacement that each bead travels in the $\Delta t$ units of time.

Write a function that takes an integer $P$, a floating point value $\tau$, a floating point value $\Delta p$, and a sequence of JPEG filenames as arguments, identifies the beads (using the specified values of $P$ and $\tau$) in each JPEG image (using BlobFinder), and writes to a file (one per line, formatted with 4 decimal places to the right of decimal point) the radial displacement that each bead moves from one frame to the next (assuming it is no more than $\Delta p$). Note that it is not necessary to explicitly track a bead through a sequence of frames—you only need to worry about identifying the same bead in two consecutive frames.

Data analysis.

Einstein's theory of Brownian motion connects microscopic properties (e.g., radius, diffusivity) of the beads to macroscopic properties (e.g., temperature, viscosity) of the fluid in which the beads are immersed. This amazing theory enables us to estimate Avogadro's number with an ordinary microscope by observing the collective effect of millions of water molecules on the beads.

Estimating the self-diffusion constant.

The self-diffusion constant $D$ characterizes the stochastic movement of a molecule (bead) through a homogeneous medium (the water molecules) as a result of random thermal energy. The Einstein-Smoluchowski equation states that the random displacement of a bead in one dimension has a Gaussian distribution with mean zero and variance $\sigma^2 = 2 D \Delta t$, where $\Delta t$ is the time interval between position measurements. That is, a molecule's mean displacement is zero and its mean square displacement is proportional to the elapsed time between measurements, with the constant of proportionality $2D$. We estimate $\sigma^2$ by computing the variance of all observed bead displacements in the x and y directions. Let ($\Delta x_1$, $\Delta x_2$), ..., ($\Delta x_n$, $\Delta y_n$) be the $n$ bead displacements, and let $r_1$, ..., $r_n$ denote the radial displacements. Then

$$ \langle \sigma^2 \rangle = \frac{(\Delta x^2_1 + ... + \Delta x^2_n) + (\Delta y^2_1 + ... + \Delta y^2_n)}{2n} = \frac{r^2_1 + ... r^2_n}{2n}$$

For the test data, $\Delta t$ = 0.5 so this is an estimate for $D$ as well. The radial displacements $r_i$ are measured in pixels: to convert to meters, multiply by 0.175$\times$10$^{-6}$ (meters per pixel).

Estimating the Boltzmann constant.

The Stokes-Einstein relation asserts that the self-diffusion constant of a spherical particle immersed in a fluid is given by

$$ D = \frac{kT}{6\pi\eta\rho}$$

where, for the test data,

$T$ = absolute temperature = 297 degrees Kelvin (room temperature)
$\eta$ = viscosity of water = 9.135$\times$10$^{-4}$ N$\cdot$s/m$^2$ (at room temperature)
$\rho$ = radius of bead = 0.5$\times$10$^{-6}$ meters

and $k$ is the Boltzmann constant. All parameters are given in SI units. The Boltzmann constant is a fundamental physical constant that relates the average kinetic energy of a molecule to its temperature. We estimate $k$ by measuring all of the parameters in the Stokes-Einstein equation, and solving for $k$.

Estimating Avogadro's number.

Avogadro's number $N_A$ is defined to be the number of particles in a mole. By definition, $k = R / N_A$, where the universal gas constant $R$ is approximately 8.31457 J/K$\cdot$mol. Use $R / k$ as an estimate of Avogadro's number.

Write a function that reads in the displacements from the data file and computes an estimate of Boltzmann's constant and Avogadro's number using the formulas described above.

Output formats. Use four digits to the right of the decimal place for all of your floating point outputs whether they are in floating point format or exponential format.


Once you have this working, you can come see me to collect your own data. I will provide a set of specific questions for you to answer regarding your data. These will form the basis for your demo presentation during the final exam.

Test data

Here are the data files for testing. You will be assigned a specific set of test data to use for your project.


All content is under a modified MIT License, and can be freely used and adapted. See the full license text here.