Biobabel Core Documentation

This gives a brief description of how to use some of the classes defined in this core module.


This class allows one to parse a String Chemical Formula into its elements and counts how many elements in the class. The String must conform to certain conventions i.e. it must use only valid elements as defined in the ChemicalDataValidator. Lets see some examples:

Count Atoms
TreeBag bag = new TreeBag();
// call method set text searches to false
ChemicalDataUtil.countAtoms("C10H5.5H2O2", bag, 0, false);
assertEquals(10, bag.getCount("C"));
assertEquals(15, bag.getCount("H"));
assertEquals(10, bag.getCount("O"));
assertEquals(3, bag.uniqueSet().size());
// Note that the elements are always ordered alphabetically as its a SortedBag.

Count Atoms with wildcard searches
TreeBag bag = new TreeBag();
// Wildcard search inserted as prefix
ChemicalDataUtil.countAtoms("Cr2H2(Cl2H2P)*", bag, 0, true);
assertEquals(2, bag.getCount("Cr"));
// Note you must use the method to check whether you have a wildcard in your bag
assertEquals(4, bag.uniqueSet().size());

Count Atoms with coefficients
TreeBag bag = new TreeBag();
ChemicalDataUtil.countAtoms("H O4 P.*H2O.Ca", bag, 2, true);
assertEquals(2, bag.getCount("Ca"));
assertEquals(2, bag.getCount("P"));
assertEquals(4, bag.uniqueSet().size());

All old documentation not moved can be found on the Archive page .