Monday, December 5, 2011

How to run MOPAC6 on a modern Linux machine

Ahum, so we were trying to test the differences between AM1 and PM3 in GAMESS and MOPAC2009 and surprisingly we found a not insignificant difference in the total energies. The energies are shifted by a constant factor of roughly ~1.000014.

However, going back to the MOPAC manual ( we see that the implementation of physical constants were changed in 1993. The GAMESS implementation of semi-empirical methods is basically the MOPAC6 Fock-formation code with some GAMESS routines to diagonalize the whole shebang (for at least as far as single-point energies goes - I haven't been looking at derivatives yet).

Most likely this difference is due to conversion factors between kcal/mol (what MOPAC will give you) and hartrees (GAMESS). For instance, this table I randomly found on the Internet, which is "taken from and old book by Karplus and Porter", says that 1 Hartree = 27.2107 eV, while Jimmy Stewart (Mr. MOPAC) says it's more like 27.2113961 eV. I guess the hartree must recently have been increased in energy along with the speed of light and neutrinos ...

Anyways, I wanted to go back and try MOPAC6 and see if the problem was in the code there. Compiling the MOPAC6 source code, however, proved very difficult, since the source syntax in certain places is not compatible with a newer gfortran, and not even my fall-back f77 compiler would eat it. However, Intel's trusty old Ifort compiler was willing to eat MOPAC6 code, albeit with a couple of warnings. 
However, then the second problem arised. The Makefile was seemingly buggy and refused to work out-of-the-box on my Ubuntu 10.10 machine. So I decided to make a Makefile that would actually run. The script can be found at the bottom of this page, and compiles like a charm, if you have Ifort. Ifort is free for non-commercial use, and usually also quite a bit faster than gfortran.

However, a possibly more simple (and possibly more fun) option is to install Wine (a Windows compatible environment for Linux) and use Wine to execute Mopac. Jimmy Stewart has a Windows compatible binary version of MOPAC6 available for download. Now, lemme show you how to install Wine and fire up MOPAC! On Ubuntu this is as simple as (let's say you have a file named methan.mop):

$ sudo apt-get install wine   # This installs WINE

$ wine mopac6.exe methan      # This runs MOPAC6 via wine with methan.mop

And that's it! Either get Ifort (free for non-commercial use) or use Wine to run MOPAC6 via the binary. I honestly found the last method to be hilarious, but I guess I'm not too different from the guy below.

The newest MOPAC and GAMESS are available for free for personal and academic use.

UPDATE: Just a short note on how to run the compiled version of MOPAC6. First, rename mopac.exe to MOPAC. Next, set the mopac directory in mopac.csh. Now open a cshell and use the mopac.csh script to envoke MOPAC6:

$ csh                     # Start a cshell
% source mopac.csh        # A script necessary to run MOPAC6
% mopac methan            # To actually run MOPAC6 with the file methan.mop

$ indicates bash shell, and % indicates a cshell.

MOPAC6 Makefile for Intel Ifort: (put it in the source code directory and type 'make')

Saturday, December 3, 2011

Fixing disabled wireless on Lenovo Z360 running Ubuntu 10.10

Ok, this post isn't about chemistry at all. However, I'm going to defend it under the category of free software. Here is a short introduction to my problem. I have a Lenovo Z360 laptop running Ubuntu 10.10. It came with some Windows distribution (are they even called distributions? I haven't had a windows computer since 2004) which I never used. <sarcasm> Thanks to Lenovo, the laptop was set up with some proprietary driver software for my wireless network interface card (NIC). </sarcasm>

After installing Ubuntu 10.10 (AKA the perfect 10) everything was working fine ... until I one day pressed the "turn off wireless" buttons (Fn+F5) to save a tiny amount of battery power. This apparently bypasses the hardware "disable wireless switch" and switches off wireless via some built-in firmware. And since I wasn't using the proprietary drivers in Windows, there was no way to switch wireless back on. 

The tedious solution to my problem was to replace the solid-state drive I had put in myself for the original drive, and boot up in windows, switch on wireless using the proprietary driver software. 
Long story short, I have up until this day always been carrying the original harddive and a small screwdriver with me, in case I should accidentally turn off wifi, so I could perform the wireless-enabling surgical procedure.

However, today I stubled up a more permanent solution. I turns out, that the signal to turn off the wireless NIC is transmitted via pin #20. So to avoid ever turning off wireless you just have to tape over that particular pin - see the picture below. After five minutes of fiddling with tape, tweezers and scissors I managed cut a piece of tape small enough and put it precisely over the pin. 
And lo and behold - it's now impossible to disable the wireless NIC via switches or accidental key-presses!

Thanks to the guys over at for pointing this out! And thanks to Lenovo for this post possible by making hardware that just works out-of-the-box-until-it-doesn't-and-there's-no-way-to-switch-it-back-on-besides-software-only-written-for-one-particular-operating-system.

Code snippets on blogs

I had a brief discussion with Casper Steinmann about how to present code snippets in blog-posts. We both agreed that nice formatting is really important. We also agreed that our previous attempts to do so were (and still are) crummy.

One of the (easy) ways to set up nice formatting can be found over at CraftyFella:

Just put some stuff in your blogger template and all you have to do is wrap your code examples in HTML <pre>  tags. "Pre tags" denote a pre-defined format, and are often used to wrap around code examples, with the color coding pertaining to that particular code-language and an equispaced font, which makes it possible to use indentations properly.

Most popular programming languages are supported in this method. C, C++ C#, python, and probably many others. Hoever, no support for FORTRAN - quantum chemists beware. If you know of a user-friendly syntax highlighter that does FORTRAN, do leave a comment! Everybody loves FORTRAN.

Here is a simple example of how a dumb python script looks after using CraftyFella's guide to set things up:


def print_string(string):
    print string

hello_world = "Hello world, look at my fancy code formatting!"

for i in range(10):

... and a little bit of C++:

//! Return size of collection
//! \return size of collection
unsigned int size() const {
     return data_vector.size();