Git Product home page Git Product logo

cliptoe's Introduction

Go HTML5 JavaScript Perl Python TeleBASIC

CLI

cliptoe

Command Line Periodic Table of Elements

example_gif

What is it?

  • Highlight elements on Periodic Table
  • Parse chemical formulas
  • Calculate atomic mass of compounds

Web-UI also available here.

Usage

$ 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

Examples

Screenshot

Screenshot

Screenshot


Concept

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'
          ]
        ];
$

Caveats / Disclaimer

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.

Thanks

@telnet23 @kelturio

cliptoe's People

Contributors

thunderpoot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.