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
|
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
|
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
create a monoisotopic carbon consisting only of C14
exchanges all carbon in formula with monoIsotopic C14