NAME

Chemistry::File::Formula - Molecular formula reader/formatter

SYNOPSIS

use Chemistry::File::Formula;

my $mol = Chemistry::Mol->parse("H2O");
print $mol->print(format => formula);
print $mol->print(format => formula, 
    formula_format => "%s%d{<sub>%d</sub>});

DESCRIPTION

This module converts a molecule object to a string with the formula. It registers the 'formula' format with Chemistry::Mol. Besides its obvious use, it is included in the Chemistry::Mol distribution because it is a very simple example of a Chemistry::File derived I/O module.

The format can be specified as a printf-like string with the following control sequences, which are specified with the formula_format parameter to $mol->print or $mol->write.

%s symbol
%D number of atoms
%d number of atoms, included only when it is greater than one
%d{substr} substr is only included when number of atoms is greater than one

If no format is specified, the default is "%s%d". Examples:

%s%D Like the default, but include explicit indices for all atoms
%s%d{<sub>%d</sub>} HTML format

Formulas can also be parsed back into Chemistry::Mol objects, but currently this only works for simple formulas with the "%s%d" format.

VERSION

0.20

SEE ALSO

Chemistry::Mol, Chemistry::File

The PerlMol website http://www.perlmol.org/

AUTHOR

Ivan Tubert-Brohman <itub@cpan.org>