Header menu logo BioFSharp

Formula

Summary: This example shows how to use chemical formulas in BioFSharp

BioFSharp offers a great bunch of functionality for working with molecules. All elements are represented as the composition of their stable isotopes. A Formula is a collection of those Elements with the given count. Creating and altering formulas is quite easy. Also functions for obtaining a mass of a molecule, which becomes quite handy especially for mass spectrometry, can be used straightforwardly.

To create formulas, no direct fiddling around with the data type is necessary. You can just use the stringparser:

open BioFSharp

let CO2 = Formula.parseFormulaString "CO2"
Formula.toString CO2
C1.00 O2.00

We just created some Carbon Dioxide. Luckily there is no in silico climate change. But let's get rid of it anyways, by making some Sprudel (german term for sprinkly water)

let sprudel = Formula.add CO2 (Formula.Table.H2O)
Formula.toString sprudel
C1.00 H2.00 O3.00

Quite refreshing, but boring nevertheless. Let's make some radioactive sprudel.

/// create a monoisotopic carbon consisting only of C14
let monoC14 = 
    Elements.createMono "C14" (Isotopes.Table.C14,1.)
    |> Elements.Mono 

/// exchanges all carbon in formula with monoIsotopic C14
let lableWithC14 molecule = Formula.replaceElement molecule Elements.Table.C monoC14

let radioactiveSprudel = lableWithC14 sprudel

As you can see converting a refreshing drink to a refreshing, radioactive drink is quickly done. As a check up, let's compare the masses:

Formula.monoisoMass sprudel,
Formula.monoisoMass radioactiveSprudel

(62.00039392114, 64.00363591054)
Item1
62.00039392114
Item2
64.00363591054

val CO2: obj
val sprudel: obj
val monoC14: obj
 create a monoisotopic carbon consisting only of C14
val lableWithC14: molecule: 'a -> 'b
 exchanges all carbon in formula with monoIsotopic C14
val molecule: 'a
val radioactiveSprudel: obj

Type something to start searching.