March 29, 2019

Water

A chemical reaction combines hydrogen and oxygen to produce water

To make it simple we will assume that the reaction is this: \[2H+O\leftrightarrow H_2O\]

Our system has 3 items:

  • Hydrogen
  • Oxygen
  • Water

The simple system

Reactions are bidirectional

The items of the system

We represent hydrogen by H, oxygen by O, and water by W.

Each vector has the number of atoms or molecules for different times

We will measure the number of atoms and molecules in moles

The initial quantities are:

  • 1 mole oxygen,
  • 1 mole hydrogen, and
  • 0 mole water

The rules are the following:

There are two reactions at the same time:

  1. from hydrogen and oxygen into water
    (that is, left to right),

  2. from water into hydrogen and oxygen
    (that is, right to left).

Simplifying notation

According to our rules, we have two rates:

  • reaction1_rate
  • reaction2_rate

In chemistry, these rates are usually written as

  • k1
  • k2

Shorter and cleaner for this class

We can see that

  • The speed of reaction1 depends on the number of oxygen atoms and the square of the number of hydrogen atoms
k1 *  H * H * O
  • The speed of reaction2 depends on the number of water molecules
k2 *  W
  • actual reaction rates depend on temperature and other conditions

We also see that

  • The number water molecules increase with the first reaction and decreases with the second reaction
  • The number of oxygen atoms reduces with the first reaction and increases with the second
  • The number of hydrogen atoms reduces two times with the first reaction and increases two times with the second

The reactions

Then the main part of the simulation is

for(i in 2:N) {
    d_W[i] <-    k1*H[i-1]*H[i-1]*O[i-1] - k2*W[i-1]
    d_O[i] <-   -k1*H[i-1]*H[i-1]*O[i-1] + k2*W[i-1]
    d_H[i] <- -2*k1*H[i-1]*H[i-1]*O[i-1] + 2*k2*W[i-1]

    W[i] <- W[i-1] + d_W[i]
    O[i] <- O[i-1] + d_O[i]
    H[i] <- H[i-1] + d_H[i]
}

Exercise: finish it

Create a water_formation function.

Inputs are:

  • N: Number of steps in the simulation
  • H_ini: initial amount of hydrogen, default 1
  • O_ini: initial amount of oxygen, default 1
  • W_ini: initial amount of water, default 0
  • k1: reaction 1 rate, default 0.1
  • k2: reaction 2 rate, default 0.1

Exercise 2: conservation of mass

One atom of oxygen has 16 times the mass of one atom of hydrogen

Therefore one molecule of water has mass 18

Show that the total mass never changes

Polymerase Chain Reaction

Polymerase Chain Reaction

The Polymerase Chain Reaction (PCR) is a method used to synthesize millions of copies of a given DNA sequence.

A typical PCR reaction consists of series of cycles:

  • template DNA denaturation,
  • primer annealing, and
  • extension of the annealed primers by DNA polymerase.

This loop is repeated between 25 and 30 times

PCR system

We can represent the PCR reaction as a system with two parts, DNA and primers and one process, the thermal cycle.

Here we simplify the reaction and we forget about the polymerase and the dNTP. They both will be represented by primers.

The system is represented by this diagram:

Simulate several PCR cycles

Please write a function to simulate the PCR reaction.

The function name should be pcr and it must take four inputs:

  • the number of cycles N,
  • the initial DNA concentration dna_ini,
  • the initial primer concentration primer_ini, and
  • the reaction rate rate.

The function must return a data frame with dna and primer.

Simulate several PCR cycles

If all is right, you should see this result

pcr(N=6, dna_ini=1e6)
       dna    primer
1  1000000 100000000
2  2000000  99000000
3  3980000  97020000
4  7841396  93158604
5 15146331  85853669
6 28150012  72849988

Simulate several PCR cycles

conc <- pcr(N=20, dna_ini=1e6)
plot(conc$dna)

PCR depends on initial concentration

The PCR reaction curve depends on the initial concentration of DNA.

We want to understand this dependency for the following values of initial DNA concentration:

initial_dna <- 10**(0:6)
initial_dna
[1] 1e+00 1e+01 1e+02 1e+03 1e+04 1e+05 1e+06

PCR depends on initial concentration

You have to create a data frame a list named conc.

This data frame has seven columns, with the result of pcr() for each of the initial DNA concentrations in initial_dna.

That is, from one DNA molecule per liter up to one million molecules per liter.

Simulate the PCR reaction for 30 cycles, and store only the value of the dna column.

PCR depends on initial concentration

If you did it correctly, you can use this code to create a plot.

plot(x=c(1,30), y=c(0, max(conc)), type="n", 
    xlab="PCR cycle", ylab="DNA Concentration",
    main="Effect of initial DNA on PCR")
legend("topleft", legend=initial_dna, pch=1:7)
for(i in 1:ncol(conc)) {
    points(conc[[i]], pch=i, type="b")
}

PCR depends on initial concentration

Bonus: Quantitative PCR

Please write the code (not a function) to make a vector called CT.

The vector CT contains the half value of each column of the data frame conc.

You can use the function locate_half() from Homework 4.

Bonus: Quantitative PCR

plot(initial_dna ~ CT, log="y")

We conclude that the CT value can be used to predict the initial concentration of DNA.