Using cclib


In [1]:
import IPython
url = "https://github.com/cclib/cclib/raw/master/logo.png"
IPython.display.Image(url=url)


Out[1]:

To quote the GitHub page,

cclib is a Python library that provides parsers for output files of computational chemistry packages. It also provides a platform for computational chemists to implement algorithms in a platform-independent way.

What this means is that for many common properties that can be calculated using quantum chemistry packages, cclib can turn them into Python objects for manipulation. This is especially valuable for analysis.

It also means that much of the work we did in the "Reading QM outputs" exercises is no longer necessary. Given a path to an output file, cclib will open it, search for all possible properties it "knows" about, and will extract them into appropriate Python datatypes.

The most common way to use cclib is as follows:


In [2]:
from cclib.parser import ccread

In [3]:
ccdata = ccread("../qm_files/drop_0375_0qm_0mm.out")

In older code, you might see this as well; it should be equivalent to using ccread.


In [4]:
from cclib.parser import ccopen
job = ccopen("../qm_files/drop_0375_0qm_0mm.out")
ccdata2 = job.parse()

Let's see what's available when we open or parse an output file:


In [5]:
print('\n'.join(dir(ccdata)))


__class__
__delattr__
__dict__
__dir__
__doc__
__eq__
__format__
__ge__
__getattribute__
__gt__
__hash__
__init__
__le__
__lt__
__module__
__ne__
__new__
__reduce__
__reduce_ex__
__repr__
__setattr__
__sizeof__
__str__
__subclasshook__
__weakref__
_attrlist
_attrtypes
_dictsofarrays
_intarrays
_listsofarrays
arrayify
atomcharges
atomcoords
atommasses
atomnos
charge
coreelectrons
enthalpy
entropy
freeenergy
getattributes
hessian
homos
listify
moenergies
moments
mult
natom
nbasis
nmo
scfenergies
scftargets
scfvalues
setattributes
temperature
typecheck
vibdisps
vibfreqs
vibirs
write

Aside from the standard double underscore ("dunder") private methods, there are a number of attributes that sound like chemical properties.