Announcements of available shared folders


Postby oliver » Thu Oct 14, 2010 6:17 am

This is an extension to ND1, which provides a new data type, "chem", for chemical formulas.

Type "H2O" and you'll see it nicely formatted, with a badge to indicate the type:
H2O.png (2.3 KiB) Viewed 6668 times

Evaluate it to obtain the relative molar mass.
18.png (2.26 KiB) Viewed 6668 times

The calculation is based on current relative atomic mass IUPAC 2007 data, and has been double-checked for accuracy.

There's beta support for addition and multiplication of the chem type with scalar values and other chem types.
Site Admin
Posts: 433
Joined: Sat May 01, 2010 2:11 pm

Note to programmers

Postby oliver » Thu Oct 14, 2010 7:09 am

You're more than welcome to add functionality to this type and/or help complete work on making operators work in all cases.

The gist of the relative molar mass computation is this handful of lines of code:
Code: Select all
      var atomicWeights = { // relative atomic mass, IUPAC 2007 data
         "H": 1.00794, "He": 4.002602, ..., "Uut": 284, "Uuq": 289, "Uup": 288, "Uuh": 293, "Uuo": 294
      calculator.vars.local = atomicWeights; // make atomicWeight our new set of local vars
      var atomicWeight = calculator.eval(obj.stringValue.replace(/[[]/g, "(").replace(/[]]/g, ")").replace(/([A-Z][a-z]?)([0-9]+)/g, "$1*$2").replace(/([A-Z][a-z]?)|([(])/g, "+$&").replace(/([)])([0-9]+)/g, "$1*$2"));
      calculator.vars.local = {}; // reset local vars
      return atomicWeight;

Regular expressions are used to reshape the type's string into simple math which is then evaluated.
Only 10 or so lines of glue code are needed to make the object a 1st class citizen in ND1. See the discussion about custom data types, and this one specifically as one example, at, if you're interested.
Site Admin
Posts: 433
Joined: Sat May 01, 2010 2:11 pm

Re: Chem

Postby oliver » Sat Mar 12, 2011 8:11 am

This folder has been updated to version 1.1.

The new version contains bug fixes (please install again, if you installed it before), as well as two additions:
- a new info command, which displays the WolframAlpha info for a given compound
- two example compounds: water and alunite

The way to enter a compound has been changed: it's now necessary to precede the formula with a special prefix character "/".
For example, to enter water, type /H2O.
This change was necessary to keep Chem from grabbing names, such as "S2", that are meant to be normal variable names.
Site Admin
Posts: 433
Joined: Sat May 01, 2010 2:11 pm

Updated to v1.2

Postby oliver » Tue Jul 03, 2012 12:18 am

Updated to version 1.2.

Functions added:
what: returns name of a compound; for example /NH3 what will return "ammonia"
melt: returns the melting point; example /NaCl melt will return 58.7 '°C'
boil: returns the boiling point; example /NaCl boil will return 1413 '°C'

These functions work through Wolfram|Alpha integration and will require the CAS download.

More information for programmers who want to extend this type in this fashion can be found here:

Also added are a couple more example compounds.
Site Admin
Posts: 433
Joined: Sat May 01, 2010 2:11 pm

Return to Downloadable Folders / Shared Data

Who is online

Users browsing this forum: No registered users and 1 guest