20. Is there no molecular weight calculator in the Debian repos?

The best molecular weight calculator which I've encountered is Matthew Monroe's Molecular Weight Calculator, which can be found at http://ncrr.pnnl.gov/software/

It does everything. Molecular weights. Isotopic patterns. And so, so, so much more.

It has one major drawback though - it's written for Windows. Luckily, it sort of works under Wine after you've done a bit of wine-trick-ery.

As great as the calculator is, sometimes you only need to calculate the molecular weight of something, and nothing else. Searching the debian repos I can' t find a single dedicated molecular weight calculator. In particular, a command-line driven calculator would be nice.

Seriously - it's a crying shame that the distribution with the largest repos, i.e. Debian, does not have a single passable molecular weight calculator. It is even more surprising given the number of chemistry-related packages which are present.

A little bit of editing gave the code below, which was saved as molcalc, copied to /usr/bin, followed by sudo chmod +x /usr/bin/molcalc. It can now be called using
molcalc "(Co(CO)5)2"
and returns
The mass of (Co(CO)5)2 is 257.916890.

Here's the code, which is 99.9% the original and 0.1% my modification. All credit thus due to Lee, Freitas and Tucker.

#!/usr/bin/python2.6
#########################################################################
# Author: Toni Lee with the help of Guilherme Freitas and Becky Tucker. Minor changes by Lindqvist
# Copyright: This module has been placed in the public domain
#########################################################################

8 comments:

I wrote qmol, derived from Tomislav Gountchev's KMol. At the moment, it does not do command line calculations, but it's on my TODO list. It does evaluate expressions like (Al(NO3)3)2 correctly (thanks to Tomislav's flexible formula parser).

There's a package for debian 6.0 at:http://download.opensuse.org/repositories/home:/lineinthesand/Debian_6.0/Source code is located here:http://sourceforge.net/projects/qmol/files/

I wrote an isotopic pattern calculator last year and rewrote the parser so that it can handle (almost) anything you throw at it: http://verahill.blogspot.com.au/2012/10/isotopic-pattern-caculator-in-python.html

qmol: I couldn't install the .deb file (amd64) on wheezy (there's no libqt4 package -- maybe replaced by libqt4-core?), but compiling was straightforward. It looks like a nice piece of software. I'll make a post about it next week.

Thanks for the feedback. I had that package made by the open build service and I assumed the package would be ok if the build on their virtual debian machines was successful. So you say the package's name is libqt4-core? I'll try to research what the problem is about (I'm using an rpm-based distribution myself, so I'll have to rely on any feedback).

Correction: that should probably be libqt4core, without the hyphen (there are both libqt4-core and libqt4core, but the former is a dummy package which pulls in the latter, and more). I'll build in a chroot next week which should tell me for sure -- but for now:

Unfortunately, I don't know enough about Debian, but Wheezy seems to be 7.0 (which is testing). The package at the open build service is for Squeeze, which is version 6.0 (stable). Maybe obs will offer to build packages for 7.0 when it becomes stable.

Your isotopic pattern calculator looks very interesting. Actually I had in mind incorporating one into qmol (possibly on a separate tab). I'll have a look at your code/the algorithm for doing this. Let's see if I'm able to do it (will surely take quite some time). (o;

As for isotopic pattern calculator, the science is easy (get the cartesian product), and since you already have a formula parser half the work is done. The trick is to avoid the product matrix from ballooning out of control by continuously sorting, removing duplicates and trimming the isotopic data as your generating it. I did that in python by using the dictionary data type -- not sure about c++.

Thanks for that write-up! I'd just write qmol in lower case, but it's not so important. Could you possibly mention that KMol (which you were trying to compile; btw. I still have the latest KMol version installed on my system with its kde3 dependencies) was written by Tomislav Gountchev (http://gountchev.net/ although he took the source code off his page)?

I will look into that 0 coefficient handling.

As for the upper/lower case handling: yes, that's because of disabiguities that might occur (you may define an all-lowercase group, but as you stated, no mixed-case). Tomislav wrote that up in the KMol handbook, which I based the qmol handbook (Help > qmol Handbook) on.

Did you notice you can configure what is output in command-line mode? You can read about that in the handbook, or, for a short sum-up just hover the text field for the 'Command line output format' in the GUI preferences dialog.

@isotopic pattern calculator: as soon as I have the time, I'll analyze your source. Thanks for the short explanation (I still have a paper lying around which deals with isotopic patterns, C. Hsu 1984, but I haven't yet had the time to read through it). I guess with C++/Qt there's a type QMap for sorted entries (I'm already quite curious if there'll be speed/memory issues).