Command Line Periodic Table of Elements
- Highlight elements on Periodic Table
- Parse chemical formulas
- Calculate atomic mass of compounds
Web-UI also available here.
$ cliptoe -h
Command Line Interactive Periodic Table of Elements
Usage:
cliptoe [atom] show details for element by atomic symbol or number
cliptoe [compound] list elements in compound
Options:
cliptoe --animate=<n> scroll through colours, speed is <n>
cliptoe --var=<n> set colour variation
cliptoe --ind=<n> set colour start index
cliptoe --label show period and group labels
cliptoe --compounds show list of example compounds
cliptoe --key show colour key
cliptoe --table show table / highlight elements on table
cliptoe --mono disable colours
The idea was originally a TeleBASIC code-golf exercise, then was ported to Perl. The example screenshots are from the Perl version.
Recreating this program in whatever language has been helpful for me in familiarising myself with syntax, using the same (fairly naïve) approaches. I plan to add more 'translations' eventually.
In Perl, the ptoe_parse_input
function turns a chemical formula into its component items:
sub ptoe_parse_input
{
my ( $query ) = @_;
# Parse chemical formula, input a string and get an array
# e.g 'H2O' => $VAR1 = [ 'H', '2' ]; $VAR2 = [ 'O', '1' ];
my @elem;
while ( $query =~ /([A-Z][a-z]?)([0-9]+)?/g )
{
my $element = $1;
my $many = $2;
$many = '1' if !$many;
push @elem, [ $element, $many ];
}
return @elem;
}
$ cliptoe -d C21H30O2
$VAR1 = [
[
'C',
'21'
],
[
'H',
'30'
],
[
'O',
'2'
]
];
$ cliptoe -d NaHCO3
$VAR1 = [
[
'Na',
'1'
],
[
'H',
'1'
],
[
'C',
'1'
],
[
'O',
'3'
]
];
$
These programs are only able to handle formulas like C15H31N3O13P2
, formulas like Fe2(SO4)3
are not supported (yet).
I'm not a chemist, and there are probably all kinds of bugs / problems that I'm not aware of.
I plan to address any such issues to the best of my ability, but cannot make any promises.