Saturday 10 April 2010

Plug cclib into Avogadro

cclib is an open source Python library for parsing and analysing computational chemistry log files.

Avogadro is a cross-platform molecular visualiser with a lot of functionality geared towards setting up and analysing computational chemistry calculations. It is an open source project led by Marcus Hanwell and is built on top of OpenBabel.

Although Avogadro has increasing support for parsing comp chem log files from a variety of packages, there may be times when it chokes on a file. If this happens, it's nice to have a backup option. This is where cclib can come in handy.

If you're on Windows, have Avogadro 1.0.0, cclib 1.0, OpenBabel 2.2.3 and its Python bindings (these latter shouldn't be necessary in a future version of Avogadro), just copy the following code into a .py file and save it in C:\Program Files\Avogadro\bin\extensionScripts.

When you next start Avogadro, it will have an "Open with cclib" Option in the Scripts menu.

from PyQt4.QtCore import *
from PyQt4.QtGui import *

import sys
sys.path.append("C:\\Python26\\Lib\\site-packages")
sys.path.append("C:\\Python26\\lib")

import cclib

import numpy
import Avogadro as avo
import openbabel as ob

class Extension(QObject):
def __init__(self):
QObject.__init__(self)

def name(self): # Recommended
return "Open with cclib"

def description(self): # Recommended
return "Open comp chem files with cclib"

def actions(self): # Required
actions = []

# Actions are just instances of the QAction class from PyQt4
action = QAction(self)
action.setText("Open with cclib")
actions.append(action)

return actions

def performAction(self, action, glwidget): # Required
# Only one action so need to check its identity

filename = str(QFileDialog.getOpenFileName())
if not filename: # You hit cancel
return None

logfile = cclib.parser.ccopen(filename)
data = logfile.parse()

obmol = ob.OBMol()
avomol = avo.molecules.addMolecule()
avoatoms = []
for atomcoord, atomno in zip(data.atomcoords[-1], data.atomnos):
coord = atomcoord.tolist()
obatom = ob.OBAtom()
obatom.SetAtomicNum(int(atomno))
obatom.SetVector(*coord)
obmol.AddAtom(obatom)

newatom = avomol.addAtom()
newatom.atomicNumber = int(atomno)
newatom.pos = atomcoord
avoatoms.append(newatom)

obmol.ConnectTheDots()
obmol.PerceiveBondOrders()
obmol.SetTotalSpinMultiplicity(data.mult)
obmol.SetTotalCharge(data.charge)

for bond in ob.OBMolBondIter(obmol):
newbond = avomol.addBond()
newbond.setBegin(avomol.atom(bond.GetBeginAtomIdx() - 1))
newbond.setEnd(avomol.atom(bond.GetEndAtomIdx() - 1))
newbond.order = bond.GetBO()

avo.GLWidget.current().molecule = avomol

return None

Notes:
  • There should be no need to have the OpenBabel Python bindings installed separately, but there is no way to access the OpenBabel library in Avogadro (at least on Windows). This prevents me, for example, from calling ConnectTheDots (I had to use my own installation of OpenBabel) or to add Conformers (which was what I wanted to do).
  • There are two Script menus after installing this plugin!
  • How do I emit a debug message?
  • The Python prompt in Avogadro requires you to "print" everything to see its value. This should not be necessary.
  • Cutting and pasting multiple lines into the Python prompt works fine, but it looks pretty weird as the prompt (>>>) is missing.

Friday 9 April 2010

ANN: Cinfony 1.0 released

Cinfony presents a common API to several cheminformatics toolkits. It uses the Python programming language, and builds on top of OpenBabel, RDKit, the CDK, and cheminformatics webservices.

Cinfony 1.0 is now available for download.

The two major additions in this release are support for using OpenBabel from IronPython (the ironable module), and webel - a cheminformatics toolkit that uses webservices (read more about this here).

As usual, Cinfony has been updated to use the latest stable releases of each toolkit: OpenBabel 2.2.3, CDK 1.2.5 and RDKit Q4_2009.

Thanks to Fredrik Wallner, Tom Sheldon and Cedric Moretti for reporting bugs.

Feedback, both positive and negative, is very much appreciated - I want to make Cinfony a useful toolkit for the community. That means you.

Tuesday 6 April 2010

How to organise a symposium for an ACS National Meeting

At the recent ACS in San Francisco I co-organised a Visual Analysis of Chemical Data symposium with Jean-Claude Bradley and Andy Lang (see summary here). The original idea for the symposium was as a sort of follow-up to ChemToolsMeet ([1], [2]), a really excellent workshop organised by Daresbury Labs in the UK. I mentioned this idea to Rajarshi (the CINF Program Chair) and he volunteered me to organise it, but suggested tailoring the topic towards the more general area of Chemical Data Viz rather than Molecular Viz as this was being covered by the preceding ACS Meeting (i.e. last Fall). As this was my first time organising a session, I thought it best to have some help and so Jean-Claude and Andy were invited on board.

What went well:
  • Great talks, and good participation from the audience in questions.
  • We had a couple of first-time ACS speakers. I thought about standing up at the start and trying to settle their nerves by telling them I was a first-time organiser, but that might have made things worse. :-)
  • Having a keynote speaker was a great idea. I especially liked the idea of having a keynote speaker with broader experience outside the main topic of the symposium, the reason being that this is sometimes one of the best ways of bringing new ideas into a field. Elizabeth Dorland (Washington Uni) kicked things off to a great start with a look at Chemistry Visualization in Education.
  • High attendance. This is a reflection on the quality of the speakers of course.
  • I think the symposium was reasonably well advertised on the CCL, my blog, and CHMINF-L. Apart from the keynote, none of the speakers were invited and yet we received quite a number of talks.

What could have been done better:
  • The talks were 20min + 5min for questions. At the 15min mark, we indicated that 5 mins were left. Afterwards, one of the presenters told us that he understood that the signal indicated the 20min mark and so brought things to a premature end. Given that all the talks ended with plenty of time for questions, he may not have been the only person we confused. Next time, we should explain the hand signals in advance.
  • Bring a functioning timepiece and a pointer next time. Apparently, my phone charger doesn't work in the US and my watch is broken. A pointer was provided by the ACS on Day Two, but we lacked one on Day One (I should have asked the meeting technicians).
  • We also had some problems following up on sponsorship which I won't discuss further here.

What was unexpected:
  • Exactly how the recording worked. Many talks were recorded, in which case the desktop PC provided needed to be used to enable the powerpoint timing to be captured.
  • The inability to log into the PACS system after the symposium was finalised. This made it difficult to get the speakers email addresses and abstracts. Fortunately, I had printed out (as PDF) some of the details earlier.
  • The fact that apart from one or two exceptions, almost everyone submits their abstracts in the last week before the deadline. This is somewhat understandable as it's still 6 months before the conference at that stage.
  • The time required for the ACS to communicate to authors that their papers were accepted.

Notes:
  • Some of these talks were recorded and will be up on the web soon. In the meanwhile, you can find some on Slideshare, such as that by Jean-Claude and Andy.
  • If you have an idea for a symposium or are simply interested in helping to organise one (good for CV, etc.), I know that Rajarshi is very happy to hear from you..

Finally, I'd like to thank Rajarshi publicly for all of his help in organising this symposium. Considering that this was only one of several symposia in the CINF division he really does a huge amount behind the scenes keeping things going.