Latest Blog Posts http://localhost/latest.atom/ 2017-05-28T12:00:00Z http://localhost/ Werkzeug Visualizing ASE structures in Jupyter notebook http://localhost/blog/ase-jupyter-notebook/ 2017-05-28T12:00:00Z 2017-05-28T12:00:00Z <p>Since I first heard about the <a href="http://jupyter.org/">Jupyter notebook</a> (around that time it was called <em>ipython notebook</em>) I instantly adopted it into my work flow for rapid testing, developing and most of all experimenting and playing around with <a href="https://www.python.org/">Python</a> code. I realized quickly how comfortable it is as a working environment and started creating notebooks using more and more of the capabilities. I began integrating plots, images, <a href="https://en.wikipedia.org/wiki/Markdown">markdown</a> notes and even creating slide presentation in <a href="http://jupyter.org/">jupyter</a>.</p> <p>Since I'm a computational chemist I manipulate the chemical structures a lot and the package I've been using a lot lately is the <a href="https://wiki.fysik.dtu.dk/ase/">Atomic Simulation Environment (ASE)</a>. Mostly because it's written in <a href="https://www.python.org/">Python</a> and has a great assortment of methods for running and analyzing DFT calculations. It also provides a set of convenient methods for handling chemical structures including periodic ones. The package comes with it's on GUI, that does a decent job when it comes to displaying and handling structures however when working in a notebook it would be great to have a tool that allows embedding the viewer inside the notebook. Some time ago there was even a <a href="https://listserv.fysik.dtu.dk/pipermail/ase-users/2016-December/003305.html">thread on the ase-users</a> mailing list where a question about embedding <a href="https://wiki.fysik.dtu.dk/ase/">ASE</a> structures in a <a href="http://jupyter.org/">Jupyter notebook</a> was raised.</p> <p>I found a few ways that enable the interactive visualization of chemical structures given as the <code>Atoms</code> objects (internal representation in ASE) in the notebook, that I think are interesting to try out:</p> <ul> <li><a href="#html">html</a> using <a href="https://wiki.fysik.dtu.dk/ase/">ASE</a>'s native <a href="https://wiki.fysik.dtu.dk/ase/ase/io/io.html#module-ase.io">html writer</a></li> <li><a href="#imolecule">imolecule</a></li> <li><a href="#nglview">nglview</a></li> <li><a href="https://chemview.readthedocs.io/en/latest/">chemview</a></li> </ul> <p>The list above is by no means complete and there are probably some other great tools that provide similar functionality, so if you think I skipped some important alternative - let me know.</p> <!-- | Software | Version | |-----------|-------------------------| | Python | 3.6.1 | | IPython | 6.0.0 | | ase | 3.13.0 | | jupyter | 1.0.0 | | OS | Linux 3.16.0 debian 8.8 | --> <h1 id="html">html</h1> <p><a href="https://wiki.fysik.dtu.dk/ase/">ASE</a> has a builtin format <a href="https://wiki.fysik.dtu.dk/ase/ase/io/io.html#module-ase.io">converter</a> (or writer) to html that uses the <a href="https://www.x3dom.org/">x3dom</a> library to create an interactive view of the molecular structure once you open or embed the generated html in a browser. You can interact with your molecule by rotating, translating zooming and panning the view. To embed the view in one of the <a href="http://jupyter.org/">Jupyter</a> output cells we can use the native <code>HTML</code> function from the <code>IPython.display</code> module</p> <div class="codehilite"><pre><span></span><span class="kn">from</span> <span class="nn">IPython.display</span> <span class="kn">import</span> <span class="n">HTML</span> </pre></div> <p>A small hurdle is that we would like to have the html as a string that can be passed to the <code>HTML</code> functions but the ASE html writer needs to write a physical file. One of the ways of fixing this behavior is a to use a <a href="https://docs.python.org/3/library/tempfile.html#tempfile.NamedTemporaryFile">named temporary file</a> from the <a href="https://docs.python.org/3/library/tempfile.html">tempfile</a> package and a custom function that takes the <code>Atoms</code> objects and returns the html string.</p> <div class="codehilite"><pre><span></span><span class="k">def</span> <span class="nf">atoms_to_html</span><span class="p">(</span><span class="n">atoms</span><span class="p">):</span> <span class="s1">&#39;Return the html representation the atoms object as string&#39;</span> <span class="kn">from</span> <span class="nn">tempfile</span> <span class="kn">import</span> <span class="n">NamedTemporaryFile</span> <span class="k">with</span> <span class="n">NamedTemporaryFile</span><span class="p">(</span><span class="s1">&#39;r+&#39;</span><span class="p">,</span> <span class="n">suffix</span><span class="o">=</span><span class="s1">&#39;.html&#39;</span><span class="p">)</span> <span class="k">as</span> <span class="n">ntf</span><span class="p">:</span> <span class="n">atoms</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">ntf</span><span class="o">.</span><span class="n">name</span><span class="p">,</span> <span class="n">format</span><span class="o">=</span><span class="s1">&#39;html&#39;</span><span class="p">)</span> <span class="n">ntf</span><span class="o">.</span><span class="n">seek</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span> <span class="n">html</span> <span class="o">=</span> <span class="n">ntf</span><span class="o">.</span><span class="n">read</span><span class="p">()</span> <span class="k">return</span> <span class="n">html</span> </pre></div> <p>Then to display any structure available as an <code>Atoms</code> instance, we could do</p> <div class="codehilite"><pre><span></span><span class="kn">from</span> <span class="nn">ase.build</span> <span class="kn">import</span> <span class="n">molecule</span> <span class="n">tbut</span> <span class="o">=</span> <span class="n">molecule</span><span class="p">(</span><span class="s1">&#39;trans-butane&#39;</span><span class="p">)</span> <span class="n">tbut_html</span> <span class="o">=</span> <span class="n">atoms_to_html</span><span class="p">(</span><span class="n">tbut</span><span class="p">)</span> <span class="n">HTML</span><span class="p">(</span><span class="n">tbut_html</span><span class="p">)</span> </pre></div> <p>If everything went well you should see a view widget with a trans-butene molecule displayed, similar to the one below. If you want to try it yourself on a couple more examples see, the short <a href="http://nbviewer.jupyter.org/github/lmmentel/ase-jnb/blob/master/ase-html.ipynb">notebook</a> I used to test this code.</p> <p><div> <link rel="stylesheet" type="text/css" href="https://www.x3dom.org/x3dom/release/x3dom.css"> </link> <script type="text/javascript" src="https://www.x3dom.org/x3dom/release/x3dom.js"> </script></p> <p><X3D style="margin:0; padding:0; width:100%; height:100%; border:none;"> <Scene> <Transform translation="0.70 1.82 0.00"> <Shape> <Appearance> <Material diffuseColor="0.565 0.565 0.565" specularColor="0.5 0.5 0.5"> </Material> </Appearance> <Sphere radius="0.76"> </Sphere> </Shape> </Transform> <Transform translation="0.70 0.30 0.00"> <Shape> <Appearance> <Material diffuseColor="0.565 0.565 0.565" specularColor="0.5 0.5 0.5"> </Material> </Appearance> <Sphere radius="0.76"> </Sphere> </Shape> </Transform> <Transform translation="-0.70 -0.30 0.00"> <Shape> <Appearance> <Material diffuseColor="0.565 0.565 0.565" specularColor="0.5 0.5 0.5"> </Material> </Appearance> <Sphere radius="0.76"> </Sphere> </Shape> </Transform> <Transform translation="-0.70 -1.82 0.00"> <Shape> <Appearance> <Material diffuseColor="0.565 0.565 0.565" specularColor="0.5 0.5 0.5"> </Material> </Appearance> <Sphere radius="0.76"> </Sphere> </Shape> </Transform> <Transform translation="1.72 2.22 0.00"> <Shape> <Appearance> <Material diffuseColor="1.000 1.000 1.000" specularColor="0.5 0.5 0.5"> </Material> </Appearance> <Sphere radius="0.31"> </Sphere> </Shape> </Transform> <Transform translation="-1.72 -2.22 0.00"> <Shape> <Appearance> <Material diffuseColor="1.000 1.000 1.000" specularColor="0.5 0.5 0.5"> </Material> </Appearance> <Sphere radius="0.31"> </Sphere> </Shape> </Transform> <Transform translation="0.19 2.21 0.88"> <Shape> <Appearance> <Material diffuseColor="1.000 1.000 1.000" specularColor="0.5 0.5 0.5"> </Material> </Appearance> <Sphere radius="0.31"> </Sphere> </Shape> </Transform> <Transform translation="0.19 2.21 -0.88"> <Shape> <Appearance> <Material diffuseColor="1.000 1.000 1.000" specularColor="0.5 0.5 0.5"> </Material> </Appearance> <Sphere radius="0.31"> </Sphere> </Shape> </Transform> <Transform translation="-0.19 -2.21 0.88"> <Shape> <Appearance> <Material diffuseColor="1.000 1.000 1.000" specularColor="0.5 0.5 0.5"> </Material> </Appearance> <Sphere radius="0.31"> </Sphere> </Shape> </Transform> <Transform translation="-0.19 -2.21 -0.88"> <Shape> <Appearance> <Material diffuseColor="1.000 1.000 1.000" specularColor="0.5 0.5 0.5"> </Material> </Appearance> <Sphere radius="0.31"> </Sphere> </Shape> </Transform> <Transform translation="1.25 -0.07 -0.88"> <Shape> <Appearance> <Material diffuseColor="1.000 1.000 1.000" specularColor="0.5 0.5 0.5"> </Material> </Appearance> <Sphere radius="0.31"> </Sphere> </Shape> </Transform> <Transform translation="1.25 -0.07 0.88"> <Shape> <Appearance> <Material diffuseColor="1.000 1.000 1.000" specularColor="0.5 0.5 0.5"> </Material> </Appearance> <Sphere radius="0.31"> </Sphere> </Shape> </Transform> <Transform translation="-1.25 0.07 -0.88"> <Shape> <Appearance> <Material diffuseColor="1.000 1.000 1.000" specularColor="0.5 0.5 0.5"> </Material> </Appearance> <Sphere radius="0.31"> </Sphere> </Shape> </Transform> <Transform translation="-1.25 0.07 0.88"> <Shape> <Appearance> <Material diffuseColor="1.000 1.000 1.000" specularColor="0.5 0.5 0.5"> </Material> </Appearance> <Sphere radius="0.31"> </Sphere> </Shape> </Transform> </Scene> </X3D> </div> </p> <h1 id="nglview">nglview</h1> <p>The most feature rich option is offered by the <a href="https://github.com/arose/nglview">nglview</a> package that provides a <a href="http://jupyter.org/">Jupyter</a> widget for interactive visualizations of chemical structures and trajectories. It is built on top of the <a href="https://github.com/arose/ngl">NGL Viewer</a> and it supports some of the more popular formats through a number of convenience functions. The supported formats include:</p> <ul> <li><a href="http:www.rcsb.org">RCSB PDB</a>,</li> <li><a href="https://github.com/arose/simpletraj">simpletraj</a>,</li> <li><a href="http://mdtraj.org/">mdtraj</a>,</li> <li><a href="http://amber-md.github.io/pytraj/latest/index.html">pytraj</a>,</li> <li><a href="http://www.mdanalysis.org/">mdanalysis</a>,</li> <li><a href="http://parmed.github.io/ParmEd/">ParmEd</a>,</li> <li><a href="https://github.com/rdkit/rdkit">rdkit</a>,</li> <li><a href="https://github.com/Acellera/htmd">HTMD</a>.</li> </ul> <p>Most importantly it also supports <code>ase.Atoms</code> though <code>nglview.showase</code> function, which displays a single structure and <code>nglview.showasetraj</code> that is capable of showing an animation based on the images in the trajectory file.</p> <p>The installation is pretty straightforward with <a href="https://www.continuum.io/">conda</a>:</p> <div class="codehilite"><pre><span></span>conda install nglview -c bioconda </pre></div> <p>or pip:</p> <div class="codehilite"><pre><span></span>pip install nglview </pre></div> <p>but I found I also need to enable it with</p> <div class="codehilite"><pre><span></span>jupyter-nbextension <span class="nb">enable</span> nglview --py --sys-prefix </pre></div> <p>The feature that I really like, that is not available in other viewers, is displaying trajectories and sequences of structures, which makes it possible to visualize molecular vibrations, structure relaxation steps or reaction paths. As an example consider viewing a vibrational mode from the trajectory file:</p> <div class="codehilite"><pre><span></span><span class="kn">import</span> <span class="nn">ase.io</span> <span class="n">mode30</span> <span class="o">=</span> <span class="n">ase</span><span class="o">.</span><span class="n">io</span><span class="o">.</span><span class="n">read</span><span class="p">(</span><span class="s1">&#39;vib.30.traj&#39;</span><span class="p">,</span> <span class="n">index</span><span class="o">=</span><span class="s1">&#39;:&#39;</span><span class="p">)</span> <span class="n">nglview</span><span class="o">.</span><span class="n">show_asetraj</span><span class="p">(</span><span class="n">mode30</span><span class="p">)</span> </pre></div> <p>Moreover <a href="https://github.com/arose/nglview">nglview</a> let you save the movie as gif file.</p> <p>If you need more control for tweaking the display you can activate the <code>gui</code> mode by passing an additional parameter to the viewer</p> <div class="codehilite"><pre><span></span><span class="n">nglview</span><span class="o">.</span><span class="n">show_asetraj</span><span class="p">(</span><span class="n">mode30</span><span class="p">,</span> <span class="n">gui</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span> </pre></div> <p>that will show a menu with a lot of options to adjust.</p> <h1 id="imolecule">imolecule</h1> <p><a href="https://github.com/patrickfuller/imolecule">imolecule</a> is an embeddable <a href="https://developer.mozilla.org/en-US/docs/Web/API/WebGL_API">WebGL</a> viewer that comes with a convenient chemical format converting features that largely rely on the capabilities on <a href="http://openbabel.org/wiki/Main_Page">openbabel</a>.</p> <p>The embedding capabilities are nicely illustrated on the <a href="http://patrickfuller.github.io/imolecule/examples/mof.html">page provided by the author</a> and the compatibility with <a href="http://jupyter.org/">Jupyter</a> is demonstrated in this <a href="http://patrickfuller.github.io/imolecule/examples/ipython.html">example notebook</a>.</p> <p>The installation is as simple as running:</p> <div class="codehilite"><pre><span></span>pip install imolecule </pre></div> <p>The <a href="https://github.com/patrickfuller/imolecule">imolecule</a> package can handle multiple file formats, and can take string representation of structures as well a read files, however it cannot handle the default <a href="https://wiki.fysik.dtu.dk/ase/">ASE</a> format. It uses it's own molecule representation internally that is based on <a href="https://en.wikipedia.org/wiki/JSON">json</a> so we can write a small function for converting <code>ase.Atoms</code> to json. The are probably a few alternative ways of getting it done but I chose to convert <code>ase.Atoms</code> to <code>OBMol</code> first and then use the converter from <a href="https://github.com/patrickfuller/imolecule">imolecule</a> to do the rest. I chose that solution since by default <code>ase.Atoms</code> has no information about chemical bonds, and we can infer that information by using <a href="http://openbabel.org/wiki/Main_Page">openbabel</a>. The bonding data is then used to correctly render the stick part of the <em>ball and stick</em> representation of structures. The <code>atoms_to_json</code> function does the above conversion, it takes the <code>ase.Atoms</code> objects and returns a json representation compatible with <a href="https://github.com/patrickfuller/imolecule">imolecule</a>.</p> <div class="codehilite"><pre><span></span><span class="k">def</span> <span class="nf">atoms_to_json</span><span class="p">(</span><span class="n">aseatoms</span><span class="p">,</span> <span class="n">infer_bonds</span><span class="o">=</span><span class="bp">True</span><span class="p">):</span> <span class="sd">&#39;&#39;&#39;</span> <span class="sd"> Convert ASE Atoms isntance into the json format compatible with</span> <span class="sd"> Args:</span> <span class="sd"> aseatoms : ase.Atoms</span> <span class="sd"> Instance of Atoms from ase package</span> <span class="sd"> infer_bonds : bool</span> <span class="sd"> If `True` bonds will be inferred using openbabel</span> <span class="sd"> Returns:</span> <span class="sd"> mol : dist</span> <span class="sd"> A dictionary with the json format of the molecule</span> <span class="sd"> &#39;&#39;&#39;</span> <span class="kn">import</span> <span class="nn">pybel</span> <span class="n">ob</span> <span class="o">=</span> <span class="n">pybel</span><span class="o">.</span><span class="n">ob</span> <span class="n">obmol</span> <span class="o">=</span> <span class="n">ob</span><span class="o">.</span><span class="n">OBMol</span><span class="p">()</span> <span class="n">obmol</span><span class="o">.</span><span class="n">BeginModify</span><span class="p">()</span> <span class="k">for</span> <span class="n">atom</span> <span class="ow">in</span> <span class="n">aseatoms</span><span class="p">:</span> <span class="n">obatom</span> <span class="o">=</span> <span class="n">obmol</span><span class="o">.</span><span class="n">NewAtom</span><span class="p">()</span> <span class="n">obatom</span><span class="o">.</span><span class="n">SetAtomicNum</span><span class="p">(</span><span class="nb">int</span><span class="p">(</span><span class="n">atom</span><span class="o">.</span><span class="n">number</span><span class="p">))</span> <span class="n">obatom</span><span class="o">.</span><span class="n">SetVector</span><span class="p">(</span><span class="o">*</span><span class="n">atom</span><span class="o">.</span><span class="n">position</span><span class="o">.</span><span class="n">tolist</span><span class="p">())</span> <span class="c1"># If there is no bond data, try to infer them</span> <span class="k">if</span> <span class="n">infer_bonds</span><span class="p">:</span> <span class="n">obmol</span><span class="o">.</span><span class="n">ConnectTheDots</span><span class="p">()</span> <span class="n">obmol</span><span class="o">.</span><span class="n">PerceiveBondOrders</span><span class="p">()</span> <span class="c1"># Check for unit cell data</span> <span class="k">if</span> <span class="nb">any</span><span class="p">(</span><span class="n">aseatoms</span><span class="o">.</span><span class="n">pbc</span><span class="p">):</span> <span class="n">uc</span> <span class="o">=</span> <span class="n">ob</span><span class="o">.</span><span class="n">OBUnitCell</span><span class="p">()</span> <span class="n">uc</span><span class="o">.</span><span class="n">SetData</span><span class="p">(</span><span class="o">*</span><span class="p">(</span><span class="n">ob</span><span class="o">.</span><span class="n">vector3</span><span class="p">(</span><span class="o">*</span><span class="n">v</span><span class="p">)</span> <span class="k">for</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">aseatoms</span><span class="o">.</span><span class="n">get_cell</span><span class="p">()))</span> <span class="n">uc</span><span class="o">.</span><span class="n">SetSpaceGroup</span><span class="p">(</span><span class="s1">&#39;P1&#39;</span><span class="p">)</span> <span class="n">obmol</span><span class="o">.</span><span class="n">CloneData</span><span class="p">(</span><span class="n">uc</span><span class="p">)</span> <span class="n">obmol</span><span class="o">.</span><span class="n">EndModify</span><span class="p">()</span> <span class="n">mol</span> <span class="o">=</span> <span class="n">pybel</span><span class="o">.</span><span class="n">Molecule</span><span class="p">(</span><span class="n">obmol</span><span class="p">)</span> <span class="k">return</span> <span class="n">imolecule</span><span class="o">.</span><span class="n">format_converter</span><span class="o">.</span><span class="n">pybel_to_json</span><span class="p">(</span><span class="n">mol</span><span class="p">)</span> </pre></div> <h1 id="chemview">chemview</h1> <p><a href="https://chemview.readthedocs.io/en/latest/">chemview</a> is another option which utilizes the <a href="https://developer.mozilla.org/en-US/docs/Web/API/WebGL_API">WebGL</a> and <a href="http://threejs.org/">three.js</a> libraries. It is pretty easy to install since it can be done using <a href="https://www.continuum.io/">conda</a>:</p> <div class="codehilite"><pre><span></span>conda install -c http://conda.binstar.org/gabrielelanaro </pre></div> <p>however I had to clone latest repository and install it through pip</p> <div class="codehilite"><pre><span></span>git clone https://github.com/gabrielelanaro/chemview <span class="nb">cd</span> chemview pip install . </pre></div> <p>due to some dependency conflicts for Python 3.6.1. After installing I had to manually enable the widget with jupyter:</p> <div class="codehilite"><pre><span></span>jupyter nbextension <span class="nb">enable</span> widgetsnbextension --user --py jupyter nbextension install --user --py --symlink chemview jupyter nbextension <span class="nb">enable</span> --user --py chemview </pre></div> <p>The <code>MolecularViewer</code> class that is responsible for creating the visualization accepts the (x, y, z) coordinates and additional <code>topology</code> dictionary that specifies a list of chemical symbols and chemical bonds as a list of connected atom indices. As in the case of <a href="https://github.com/patrickfuller/imolecule">imolecule</a> we can convert the <code>ase.Atoms</code> instance into the required format using the code below.</p> <div class="codehilite"><pre><span></span><span class="k">def</span> <span class="nf">atoms_to_chemview</span><span class="p">(</span><span class="n">atoms</span><span class="p">,</span> <span class="n">infer_bonds</span><span class="o">=</span><span class="bp">True</span><span class="p">):</span> <span class="sd">&#39;&#39;&#39;</span> <span class="sd"> Convert ase.Atoms instance into a dict of kwargs for the chemview.MolecularViewer</span> <span class="sd"> Args:</span> <span class="sd"> atoms : ase.Atoms</span> <span class="sd"> infer_bonds : bool</span> <span class="sd"> Get the list of indices of connected atoms, (requires pybel)</span> <span class="sd"> Returns:</span> <span class="sd"> data : dict</span> <span class="sd"> A dict with kwargs that can be passed to chemview.MolecularViewer</span> <span class="sd"> &#39;&#39;&#39;</span> <span class="n">data</span> <span class="o">=</span> <span class="nb">dict</span><span class="p">()</span> <span class="c1"># convert the coordinates to nanometers</span> <span class="n">data</span><span class="p">[</span><span class="s1">&#39;coordinates&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">atoms</span><span class="o">.</span><span class="n">get_positions</span><span class="p">()</span> <span class="o">/</span> <span class="mf">10.0</span> <span class="n">data</span><span class="p">[</span><span class="s1">&#39;topology&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="nb">dict</span><span class="p">()</span> <span class="n">data</span><span class="p">[</span><span class="s1">&#39;topology&#39;</span><span class="p">][</span><span class="s1">&#39;atom_types&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">atoms</span><span class="o">.</span><span class="n">get_chemical_symbols</span><span class="p">()</span> <span class="k">if</span> <span class="n">infer_bonds</span><span class="p">:</span> <span class="kn">import</span> <span class="nn">pybel</span> <span class="n">ob</span> <span class="o">=</span> <span class="n">pybel</span><span class="o">.</span><span class="n">ob</span> <span class="n">obmol</span> <span class="o">=</span> <span class="n">ob</span><span class="o">.</span><span class="n">OBMol</span><span class="p">()</span> <span class="n">obmol</span><span class="o">.</span><span class="n">BeginModify</span><span class="p">()</span> <span class="k">for</span> <span class="n">atom</span> <span class="ow">in</span> <span class="n">atoms</span><span class="p">:</span> <span class="n">obatom</span> <span class="o">=</span> <span class="n">obmol</span><span class="o">.</span><span class="n">NewAtom</span><span class="p">()</span> <span class="n">obatom</span><span class="o">.</span><span class="n">SetAtomicNum</span><span class="p">(</span><span class="nb">int</span><span class="p">(</span><span class="n">atom</span><span class="o">.</span><span class="n">number</span><span class="p">))</span> <span class="n">obatom</span><span class="o">.</span><span class="n">SetVector</span><span class="p">(</span><span class="o">*</span><span class="n">atom</span><span class="o">.</span><span class="n">position</span><span class="o">.</span><span class="n">tolist</span><span class="p">())</span> <span class="n">obmol</span><span class="o">.</span><span class="n">ConnectTheDots</span><span class="p">()</span> <span class="n">obmol</span><span class="o">.</span><span class="n">PerceiveBondOrders</span><span class="p">()</span> <span class="n">bonds</span> <span class="o">=</span> <span class="p">[[</span><span class="n">b</span><span class="o">.</span><span class="n">GetBeginAtom</span><span class="p">()</span><span class="o">.</span><span class="n">GetIndex</span><span class="p">(),</span> <span class="n">b</span><span class="o">.</span><span class="n">GetEndAtom</span><span class="p">()</span><span class="o">.</span><span class="n">GetIndex</span><span class="p">()]</span> <span class="k">for</span> <span class="n">b</span> <span class="ow">in</span> <span class="n">ob</span><span class="o">.</span><span class="n">OBMolBondIter</span><span class="p">(</span><span class="n">obmol</span><span class="p">)]</span> <span class="n">data</span><span class="p">[</span><span class="s1">&#39;topology&#39;</span><span class="p">][</span><span class="s1">&#39;bonds&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">bonds</span> <span class="k">return</span> <span class="n">data</span> </pre></div> <p>Here I used <a href="https://openbabel.org/docs/dev/UseTheLibrary/Python_Pybel.html">pybel</a> again to get the information about chemical bonds. Notice also that I converted the coordinates to nanometers since it looks a lot nicer, although I didn't found any information in the <a href="https://chemview.readthedocs.io/en/latest/">chemview</a>'s docs that this is the default unit used. </p> <p>If you want to see a working example see <a href="https://github.com/lmmentel/ase-jnb/blob/master/ase-chemview.ipynb">this notebook</a> where the above function is used to display a couple of <a href="https://wiki.fysik.dtu.dk/ase/">ASE</a> structures.</p> Visualizing reactor simulation results http://localhost/blog/coke-profile-animation/ 2017-05-22T12:00:00Z 2017-05-22T12:00:00Z <p>Recently I was involved in a project where I was simulating a chemical reaction network leading to the deactivation of a solid catalyst in a tubular reactor. As a result of those simulations I obtained concentrations of several species involved in the reactions that were defined for a specific point in space (reactor coordinate) and time - usually referred to as time on stream (TOS). Naturally this kind of data fit very well to be stored in a matrix form, and since I wanted to <strong>see</strong> the data to understand it a bit better I started exploring options for visualizing matrix datasets using one of the most powerful python plotting libraries, namely <a href="https://matplotlib.org/">matplotlib</a>.</p> <!-- The same colormap was chosen for all the visualizations for easier visual comparison between the results. --> <h3 id="the-data">The data</h3> <p>Going into a detailed description of the particular model used to produce the data deserves a separate post and therefore I'll just mention a few important points here and probably write a full length post about it some time in the future.</p> <p>First of all the model used in the simulation was designed to closely approximate the actual catalysts deactivation processes that are also studied experimentally.</p> <p>In the simulations the tubular reactor is approximated by the <a href="https://en.wikipedia.org/wiki/Plug_flow_reactor_model">plug flow reactor model</a> to which a mixture of reactant gases are fed at specified flow conditions.</p> <p>In order to solve the model equations the reactor was divided into 200 separate segments and the reactions were evolved for 438 discrete time steps therefore the resulting concentrations profiles are given as arrays of the shape 438 x 200. This means that for a given specie each row of the array holds it's concentration profile along the reactor at a specific time. Analogously each column of the array stores the evolution of the concentration in a discrete reactor segment.</p> <h2 id="heatmap">Heatmap</h2> <p>A <a href="https://en.wikipedia.org/wiki/Heat_map">heat map</a> is probably the most obvious way of graphically representing a 3D dataset on a flat 2D plot. Each value of the matrix is mapped into (or encoded with) a color patch placed at the coordinates specified by the row and column. The color is usually determined from a specially designed palette called a <em>colormap</em>. There are many colormaps available in <a href="https://matplotlib.org/">matplotlib</a> and choosing the right depends on a particular application and probably your sense of aesthetics. I highly recommend reading <a href="https://jakevdp.github.io/blog/2014/10/16/how-bad-is-your-colormap/">this blog post</a> to learn more about avoiding common bad choices.</p> <!-- The heatmap below is a representing the data deactivation data ranging --> <div class="row" style="padding-top: 20px;padding-bottom: 20px;"> <figure> <img class="img-responsive center-block" width=760px src="../../static/img/simulated_coke_profile.png"> </figure> </div> <p>This particular heatmap was generated with <a href="https://seaborn.pydata.org/">seaborn</a> package that provides a lot of convenient, high-level methods for visualizing data with <a href="https://matplotlib.org/">matplotlib</a>. The plot can be generated by a single line (line 9 in the code below) however to have meaningful axis labels and tick values I tweaked some of the respective settings.</p> <script src="https://gist.github.com/lmmentel/688d0c5d4101a2cfdb3bb3913c9aa674.js"></script> <h2 id="3d-plot">3D Plot</h2> <p>Since the data we have is 3-dimensional in a sense that we can assign an <em>x</em>, <em>y</em> and <em>z</em> axes it seems only natural to try and plot it in 3D (more accurately a 2D projection of a 3D plot). Since we can safely assume that the physical quantity being modeled on a discrete grid is in principle continuous therefore the most suitable choice seems to be 3D surface plot.</p> <div class="row" style="padding-top: 20px;padding-bottom: 20px;"> <figure> <img class="img-responsive center-block" width=760px src="../../static/img/simulated_coke_profile_3d.png"> </figure> </div> <p>Creating a surface plot requires a bit more data manipulation since the <code>plot_surface</code> method expects coordinate matrices and not coordinate vectors. Fortunately <a href="http://www.numpy.org/">numpy</a> provides a convenient <a href="https://docs.scipy.org/doc/numpy/reference/generated/numpy.meshgrid.html">meshgrid</a> method to do the work for us. As in the previous case rest of the code is mostly updating some of the display settings of the axes and labels.</p> <script src="https://gist.github.com/lmmentel/5ef001dece7165f71d4b114fbe43c2a9.js"></script> <h2 id="animation">Animation</h2> <p><a href="https://matplotlib.org/">matplotlib</a> also allows making <a href="http://matplotlib.org/examples/animation/">animations</a> and saving them as gifs or one of the video formats. Here I'll animate the deactivation data showing one row of the data matrix at a time, one after another. The plot area below can be thought of as the tubular reactor with the inlet on the left hand side and the outlet on the right hand side. With the flow of gas reactant mixture and passage of time the catalyst will deactivate, which in this particular case can be observed as the gradual change in color from yellowish to black.</p> <div class="row" style="padding-top: 20px;padding-bottom: 20px;"> <figure> <img class="img-responsive center-block" width=760px src="../../static/img/coke_animation_magma.gif"> </figure> </div> <p>For comparison I also made the same animation but using the <code>Greys</code> colormap since it is more realistic compared to the actual deactivation. This is because the fresh catalyst is a white powder and when it gets deactivated it turns black.</p> <div class="row" style="padding-top: 20px;padding-bottom: 20px;"> <figure> <img class="img-responsive center-block" width=760px src="../../static/img/coke_animation_greys.gif"> </figure> </div> <p>The particular method used in this example is <code>FuncAnimation</code> that requires two additional functions to be defined, one that will be responsible for updating the plot values (in our case called <code>update</code>) and an initialization function that sets the values for the first frame of the animation (<code>init_coke</code>). The plotting is done through the <code>pcolormesh</code> function that creates a pseudocolor plot of a 2D array and can be thought of as a low-level function for creating heatmaps.</p> <script src="https://gist.github.com/lmmentel/1154b9289eb4a06e4823ffb38f4f3a7a.js"></script> <h2 id="summary">Summary</h2> <p>Out of the three visualization methods above I think the most intuitive one is the animation since it quickly conveys the message and it's mostly self explanatory. This makes it a preferable choice for slide presentations, web pages and other digital formats, however it would be a poor choice for any printable media.</p> <p>When it comes to creating graphics for articles, books and anything else that is expected to be printable I would recommend the heat map over the 3D surface plot since I find it easier to see the overall trend of the data changes and also to read the value for a specific coordinate pair. The surface plot looks much cooler but it might harder to read the (<em>x</em>, <em>y</em>, <em>z</em>) values having only one projection. Moreover deciding which projection to choose or in other words how to position the axes with respect to the viewer is another issue that has to be decided based on some trials and the features of the dataset. </p> Zeolite Framework Classification II http://localhost/blog/zeolite-classification-ii/ 2017-04-22T12:00:00Z 2017-04-22T12:00:00Z <p>In my <a href="http://lukaszmentel.com/blog/zeolite-classification/index.html">previous post</a> I was exploring the database of of zeolite frameworks using <a href="https://www.python.org/">Python</a>, <a href="http://bokeh.pydata.org/en/latest/">bokeh</a>, <a href="http://pandas.pydata.org/">pandas</a> and my own <a href="https://bitbucket.org/lukaszmentel/zefram">zefram</a> package that provided easy access to the data on zeolite frameworks available from the <a href="http://www.iza-structure.org/databases/">IZA database</a> and <a href="http://helios.princeton.edu/zeomics/">ZEOMICS</a>.</p> <p>To explore the topic further I thought that a grouping of the frameworks into one-dimensional (<em><strong>D</strong></em>=1) and multidimensional (<em><strong>D</strong></em>=2 or <em><strong>D</strong></em>=3) might be useful. Such a distinction is largely related to the applications since multidimensional frameworks have unique topological features such as channel intersections that allow different phenomena to happen.</p> <p>Among the frameworks with multidimensional channel structures there are ones that have multiple channels of the same size, for example <em>AEI</em> having 3 distinct channels each along [100], [110] and [001]. The complementary group would be the frameworks that have at least two intersecting channels that are of different size. The latter group is usually referred to as <em>multipore zeolites</em>.</p> <p>An important phenomenon contributing to the unique properties of multidimensional frameworks is the so called <a href="http://www.sciencedirect.com/science/article/pii/0021951780903280">molecular traffic control</a> which occurs where there are at least two molecules of different size or shape where one of them prefers to travel (diffuse) along one channel system and the other one travels along a different channel system. This fact together with the knowledge of the relationship between the molecule's size and it's preference to choose a channel of specific size can be used to tune catalytic processes occurring over zeolites. A <a href="http://onlinelibrary.wiley.com/doi/10.1002/anie.201406344/abstract">recent review article</a> about multipore zeolites explores their catalytic applications and the role of <em>molecular traffic control</em>.</p> <h2 id="figures">Figures</h2> <p>The figure below presents all the frameworks with the zero- and one-dimensional ones not colored. The multidimensional frameworks can be either two- or three-dimensional which is indicated by the color of the outer ring. The inside of each circle indicates the composition of the channel structure in terms of the distinct channel sizes. If a framework is three-dimensional but only has channels on one size, such as <em>AEI</em> it will be filled with a single color. If there are channels with more than 12 T atoms they are considered extra large (<em>XL</em>). Since extra large channels exhibit very poor selectivity no distinction is made here between them and they are treated as a channel of single (but very large) size.</p> <div class="row" style="padding-top: 20px;padding-bottom: 20px;"> <figure> <img class="img-responsive center-block" width=760px src="../../static/img/2d-and-3d-channels.png"> <figcaption class="text-muted" style="text-align: center;">2D and 3D channels</figcaption> </figure> </div> <p>Finally since I mentioned that multipore zeolites are often teated as a separate category I decided to created a separate figure where only the multidimensional frameworks that have at least two channels with different sizes are highlighted.</p> <div class="row" style="padding-top: 20px;padding-bottom: 20px;"> <figure> <img class="img-responsive center-block" width=760px src="../../static/img/multipore-frameworks.png"> <figcaption class="text-muted" style="text-align: center;">Multipore frameworks</figcaption> </figure> </div> <p>For clarity and easier navigation I also created a graphic where only the multipore frameworks are included with the same color coding as above.</p> <div class="row" style="padding-top: 20px;padding-bottom: 20px;"> <figure> <img class="img-responsive center-block" width=760px src="../../static/img/multipore-frameworks-only.png"> <figcaption class="text-muted" style="text-align: center;">Multipore frameworks only</figcaption> </figure> </div> <p>As in the previous case uploaded a <a href="http://nbviewer.jupyter.org/github/lmmentel/zeolite-classification/blob/master/multipore_zeolites.ipynb">jupyter notebook</a> that I used the generate the plots to a <a href="https://github.com/lmmentel/zeolite-classification">github repo</a>. There are also some additional plots at the bottom of the notebook.</p> Zeolite Framework Classification http://localhost/blog/zeolite-classification/ 2017-03-28T12:00:00Z 2017-03-28T12:00:00Z <h1 id="introduction">Introduction</h1> <p>Zeolites are fascinating materials with quite unique properties. They belong to what is often referred to as microporous materials which means that they contain pores that do not exceed 2 nm (20 &#8491;). That is probably why they earned the name of <em>molecular sieves</em> since the pores match the sizes of small molecules allowing for size based discrimination. Initially they were a curiosity to mineralogists but since their discovery they opened a rich field of scientific activities and fallen under investigation by chemists, mathematicians, physicists, material scientists, biologists and probably some more.</p> <p>From a structural point of view zeolites are built from tetrahedrons that have oxygen atoms at vertices and an atom of valency 4 at their centers. Those tetrahedrons connect with each other by sharing O atoms (vertices) and form intricate networks with repeatable patterns resulting in a variety of periodic crystalline materials.</p> <p>Due to the number of possible ways that the network of interconnected tetrahedra can be arranged in space the number of resulting structures in overwhelmingly large, however not all of the possibilities will be energetically stable and even a smaller fraction is feasible to synthesize or find in nature.</p> <p>As an illustration have a look below at the two possible frameworks that are labeled AFI and MTT. Both are composed of silicon (beige spheres) and oxygen atoms (red spheres) with AFI having 12 Si and 12 O atoms forming channels and MTT 10 Si and O atoms form the channels.</p> <div class="row" style="padding-top: 30px;padding-bottom: 30px;"> <figure> <img class="img-responsive center-block" width=760px src="../../static/img/afi.png"> <figcaption class="text-muted" style="text-align: center;">AFI framework</figcaption> </figure> </div> <div class="row" style="padding-top: 30px;padding-bottom: 30px;"> <figure> <img class="img-responsive center-block" width=492px src="../../static/img/mtt.png"> <figcaption class="text-muted" style="text-align: center;">MTT framework</figcaption> </figure> </div> <p>The list of all the zeolite frameworks that are currently available is curated by the <a href="http://www.iza-structure.org/">International Zeolite Association (IZA)</a> which also makes a catalog with the basic properties of each framework accessible either as the <a href="http://europe.iza-structure.org/IZA-SC/ftc_table.php">Database of Zeolite Frameworks</a> or in a published form as the <a href="http://www.sciencedirect.com/science/book/9780444530646">Atlas of Zeolite Framework Types</a> available from the <a href="http://www.iza-structure.org/IZA-SC_Publications.htm">IZA publications page</a>.</p> <p>There are many parameters that can be used to characterize the frameworks and the empty space that can be found inside. Usually the internal voids are categorized as cages and channels with their sizes given as the number of tetrahedrally coordinated atoms (T atoms) forming the ring or units of length suitable for the atomic scale such as &#8491;ngstrom.</p> <p>Here I would just like to mention two of characteristic variables namely the channel size given as the number of T atoms and channel system dimensionality since those two parameters to a large extent determine the applications of a given framework.</p> <p>The channels present in a given framework are generally classified according to the size of the largest channel into:</p> <ul> <li><em>small</em>, if the largest channel is assembled with 8 T atoms (and the same number of oxygen atoms),</li> <li><em>medium</em>, if the largest channel is assembled with 10 T atoms,</li> <li><em>large</em>, if the largest channel is assembled with 12 T atoms,</li> <li><em>extra large</em> if the number of T atoms is greater than 12.</li> </ul> <p>The channel system dimensionality on the other hand determines the number of dimensions <em><strong>D</strong></em> that a guest molecule can freely travel through the framework once it enters the pores. Frameworks that have only cages or channels composed of 6 and less T atoms are considered inaccessible and therefore their dimensionality is 0 (<em><strong>D</strong></em>=0). Frameworks with channels composed of more than 6 T atoms and running only in one direction have <em><strong>D</strong></em>=1. In the case of frameworks with multiple channels running in more than one direction the pore dimensionality is dependent on how the channels are mutually connected. If a molecule can move between two channel systems <em><strong>D</strong></em>=2, and when it can move between three channel systems <em><strong>D</strong></em>=3.</p> <p>By the current count there are 229 unique topologies recognized by IZA. The complete listing of the channel system details for each framework can be found in the <a href="http://www.sciencedirect.com/science/article/pii/B9780444530646503686">Appendix E – Channel System Dimensions</a> of the <a href="http://www.sciencedirect.com/science/book/9780444530646">Atlas of Zeolite Framework Types</a>.</p> <h1 id="graphs">Graphs</h1> <p>Having a convenient way for accessing the data on zeolite frameworks through the <a href="https://bitbucket.org/lukaszmentel/zefram">zefram package</a> we can explore how certain features are distributed. To perform the basic data analysis and produce the nice visualizations below I chose <a href="http://bokeh.pydata.org/en/latest/">Bokeh</a> package since it's a very handy tool.</p> <h2 id="channel-size-distribution">Channel size distribution</h2> <p>Let us start by looking at a histogram below showing the frequencies of the largest channel size (given as the number of T atoms) with a subdivision into different pore system dimensionalities. </p> <div class="row" style="padding-top: 30px;padding-bottom: 30px;"> <img class="img-responsive center-block" width=760px src="../../static/img/zeolite_histogram.png"> </div> <p>What can be immediately inferred from the graph is that frameworks with even numbered rings dominate over the odd numbered ones. Within the even numbered frameworks there are 74 frameworks with 8 membered ring (MR) channels, 66 with 12 MR and 45 with 10 MR. When it comes to the dimensionality the largest group is composed of three-dimensional frameworks (94), then one-dimensional (63), two-dimensional (51) and zero-dimensional (21).</p> <p>The details about the distribution of different channel sizes for a given pore system dimensionality are visualized in the four figures below. Channels that belong to one of the categories described above as <em>small</em>, <em>medium</em> and <em>large</em> are color coded. Additionally if a given framework is composed solely of even numbered rings it is labeled as AlPO since it would be hypothetically possible to synthesize it as an aluminum phosphate (AlPO). </p> <h2 id="zero-dimensional-frameworks">Zero-dimensional Frameworks</h2> <div style="padding-top: 30px;padding-bottom: 30px;"> <img class="img-responsive center-block" src="../../static/img/zero_dimensional_frameworks.png" alt="Zero dimensional Zeolite Topologies" > </div> <h2 id="one-dimensional-frameworks">One-dimensional Frameworks</h2> <div style="padding-top: 30px;padding-bottom: 30px;"> <img class="img-responsive center-block" style="width:750px;margin: 0 auto;" src="../../static/img/one_dimensional_frameworks.png" alt="Unidirectional Zeolite Topologies"> </div> <h1 id="two-dimensional-frameworks">Two-dimensional Frameworks</h1> <div style="padding-top: 30px;padding-bottom: 30px;"> <img class="img-responsive center-block" src="../../static/img/two_dimensional_frameworks.png" alt="Bidirectional Zeolite Topologies"> </div> <h1 id="three-dimensional-frameworks">Three-dimensional Frameworks</h1> <div style="text-align:right;padding-top: 30px;padding-bottom: 30px;"> <img class="img-responsive center-block" src="../../static/img/three_dimensional_frameworks.png" alt="Tridirectional Zeolite Topologies"> </div> <p>If you are interested how to create similar plots to the ones above I uploaded a <a href="http://nbviewer.jupyter.org/github/lmmentel/zeolite-classification/blob/master/zeolite_categories.ipynb">jupyter notebook</a> that I used the generate the plots to a <a href="https://github.com/lmmentel/zeolite-classification">github repo</a>. There are also additional plots showing some of the other descriptors for the channels and cages size for a given pore system (from <a href="http://helios.princeton.edu/zeomics/">ZEOMICS</a> database), such as largest cavity diameter, pore limiting diameter and maximum diameter of a sphere that can be included.</p> Awesome Python Chemistry http://localhost/blog/awesome-python-chemistry/ 2017-01-28T12:00:00Z 2017-01-28T12:00:00Z <p><a href="https://www.python.org/">Python</a> programming language is becoming the language of choice for large number of scientists and it doesn't take much effort to realize why this is happening. One of the most important reasons is it's simplicity that does not compromise it's power. It has a relatively low entry point since simple python expressions resemble statements in English but at the same time it's a mature language used as an indispensable tool in many operating systems, it powers up web services, and is used in large scale applications. Moreover it has a great documentation system, helpful community and a lot of online resources that offer everything from short tutorials to university programming courses.</p> <p>It is so popular among scientists between a broad range of domains that there is now a meeting called <a href="https://conference.scipy.org/">SciPy conference</a> dedicated to scientific applications of <a href="https://www.python.org/">Python</a>. It is a great initiative that encourages collaboration and blurs the lines between different fields of scientific inquiry like: chemistry, physics, mathematics, computer science and many more, which is crucial for research innovations.</p> <p>The popularity didn't go unnoticed by an even wider audience since one of the most influential scientific journals (Nature) published <a href="http://www.nature.com/news/programming-pick- up-python-1.16833">this article</a> that recommends picking up <a href="https://www.python.org/">Python</a> to work much more efficiently, improve handling of big data sets and create beautiful visualizations. You could also communicate your research results more efficiently through building websites or web applications (also with Python tools). Collaboration and publishing also became more efficient with <a href="http://jupyter.org/">Jupyter notebooks</a> that were highlighted in another <a href="http://www.nature.com/news/interactive-notebooks-sharing-the-code-1.16261">article</a>. If you are curious to see <a href="https://www.python.org/">Python</a> and <a href="http://jupyter.org/">Jupyter</a> working together for various applications (including scientific ones) have a look at the <a href="https://github.com/jupyter/jupyter/wiki/A-gallery-of-interesting-Jupyter-and-IPython-Notebooks">gallery of interesting Jupyter notebooks</a>.</p> <p>There are already a lot of useful tools, packages and libraries written in <a href="https://www.python.org/">Python</a> to help you improve your research and most of them can be found on <a href="https://pypi.python.org/pypi">PyPI</a> or <a href="https://github.com">github</a>. However finding relevant content might be a bit difficult due to to the sheer number of packages on <a href="https://pypi.python.org/pypi">PyPI</a> or repositories on <a href="https://github.com">github</a>, therefore I decided to create a list of packages that are related to chemistry (since I'm a chemist) inspired by the <a href="https://github.com/sindresorhus/awesome">awesome list repo</a>. You can find the list in a <a href="https://github.com/lmmentel/awesome-python-chemistry">repository on github</a> and below in this post. Additionally I included some of the more useful scientific packages from the <a href="https://awesome-python.com">awesome-python</a> list.</p> <p>I am quite sure that the list below is not complete and there are a lot more useful packages that should be included. If you would like to suggest a package that is not mentioned yet, please write an <a href="https://github.com/lmmentel/awesome-python-chemistry/issues">issue on github</a> or submit a <a href="https://github.com/lmmentel/awesome-python-chemistry/pulls">pull request</a>. If both of the above sound difficult you can always write a commend below or drop me an email.</p> <h1 id="awesome-python-chemistry">Awesome Python Chemistry</h1> <p>A curated list of awesome Python frameworks, libraries, software and resources related to Chemistry.</p> <p>Inspired by <a href="https://awesome-python.com">awesome-python</a>.</p> <ul> <li><a href="#awesome-python-chemistry">Awesome Python Chemistry</a><ul> <li><a href="#general-chemistry">General Chemistry</a></li> <li><a href="#simulations">Simulations</a></li> <li><a href="#molecular-visualization">Molecular Visualization</a></li> <li><a href="#general-scientific-packages">General Scientific Packages</a></li> <li><a href="#data-visualization">Data Visualization</a></li> </ul> </li> </ul> <h2 id="general-chemistry">General Chemistry</h2> <p><em>Packages and tools for general chemistry.</em></p> <ul> <li><a href="http://lukaszmentel.com/batchcalculator/">batchcalculator</a> - A GUI app based on wxPython for calculating the correct amount of reactants (batch) for a particular composition given by the molar ratio of its components.</li> <li><a href="http://pythonhosted.org/chempy/">chempy</a> - ChemPy is a package useful for chemistry (mainly physical/inorganic/analytical chemistry).</li> <li><a href="http://lewisamarshall.github.io/ionize/">ionize</a> - Calculates the properties of individual ionic species in aqueous solution, as well as aqueous solutions containing arbitrary sets of ions.</li> <li><a href="http://mendeleev.readthedocs.io/en/stable/">mendeleev</a> - A package that provides a python API for accessing various properties of elements from the periodic table of elements.</li> <li><a href="http://openbabel.org/wiki/Main_Page">Open Babel</a> - A chemical toolbox designed to speak the many languages of chemical data.</li> <li><a href="http://www.reflectometry.org/danse/elements.html">periodictable</a> - This package provides a periodic table of the elements with support for mass, density and xray/neutron scattering information.</li> <li><a href="http://pubchempy.readthedocs.io/en/latest/">pubchempy</a> - PubChemPy provides a way to interact with PubChem in Python.</li> <li><a href="https://openbabel.org/docs/dev/UseTheLibrary/Python_Pybel.html">pybel</a> - Pybel provides convenience functions and classes that make it simpler to use the Open Babel libraries from Python.</li> <li><a href="https://pyeql.readthedocs.io/en/latest/index.html">pyEQL</a> - A set of tools for conventional calculations involving solutions (mixtures) and electrolytes.</li> <li><a href="http://pymatgen.org/">pymatgen</a> - Python Materials Genomics is a robust, open-source library for materials analysis.</li> <li><a href="http://pythonhosted.org/symmetry/">symmetry</a> - Symmetry is a library for materials symmetry analysis.</li> </ul> <h2 id="simulations">Simulations</h2> <p><em>Packages for atomistic simulations and computational chemistry.</em></p> <ul> <li><a href="http://amp.readthedocs.io/en/latest/">amp</a> - Is an open-source package designed to easily bring machine-learning to atomistic calculations.</li> <li><a href="https://wiki.fysik.dtu.dk/ase/index.html">Atomic Silumation Environment (ASE)</a> - Is a set of tools and modules for setting up, manipulating, running, visualizing and analyzing atomistic simulations. </li> <li><a href="https://downloads.ccdc.cam.ac.uk/documentation/API/index.html">ccdc</a> - An API for the Cambridge Structural Database System.</li> <li><a href="https://cclib.github.io/">cclib</a> - A library for parsing output files various quantum chemical programs.</li> <li><a href="http://chemlab.readthedocs.io/en/latest/index.html">chemlab</a> - Is a library that can help the user with chemistry-relevant calculations.</li> <li><a href="http://deepchem.io/">deepchem</a> - Deep-learning models for Drug Discovery and Quantum Chemistry.</li> <li><a href="http://theochem.github.io/horton/2.0.1/index.html">horton</a> - Helpful Open-source Research TOol for N-fermion system, a quantum-chemistry program that can perform computations involving model Hamiltonians.</li> <li><a href="http://mathchem.iam.upr.si/">mathchem</a> - Is a free open source package for calculating topological indices and other invariants of molecular graphs.</li> <li><a href="http://www.mdanalysis.org/">MDAnalysis</a> - Is an object-oriented library to analyze trajectories from molecular dynamics (MD) simulations in many popular formats.</li> <li><a href="http://dirac.cnrs-orleans.fr/MMTK/">MMTK</a> - The Molecular Modeling Toolkit is an Open Source program library for molecular simulation applications.</li> <li><a href="http://molmod.github.io/molmod/index.html">MolMod</a> - A library with many components that are useful to write molecular modeling programs.</li> <li><a href="https://pygauss.readthedocs.io/en/stable/index.html">pygauss</a> - An interactive tool for supporting the lifecycle of a computational molecular chemistry investigations.</li> <li><a href="http://pyquante.sourceforge.net/">PyQuante</a> - Is an open-source suite of programs for developing quantum chemistry methods</li> <li><a href="https://github.com/thynnine/pysic">pysic</a> - A calculator incorporating various empirical pair and many-body potentials.</li> <li><a href="https://github.com/sunqm/pyscf">Pyscf</a> - A quantum chemistry package written in Python.</li> <li><a href="http://www.rdkit.org/">RDKit</a> - Open-Source Cheminformatics Software.</li> <li><a href="http://libatoms.github.io/QUIP/">QUIP</a> - A collection of software tools to carry out molecular dynamics simulations.</li> <li><a href="http://theory.cm.utexas.edu/tsase/">tsase</a> - The library which depends on ASE to tackle transition state calculations.</li> </ul> <h2 id="molecular-visualization">Molecular Visualization</h2> <p><em>Packages for viewing molecular structures.</em></p> <ul> <li><a href="https://wiki.fysik.dtu.dk/ase/ase/gui/gui.html#module-ase.gui">ase-gui</a> - The graphical user-interface allows users to visualize, manipulate, and render molecular systems and atoms objects.</li> <li><a href="http://chemview.readthedocs.io/en/latest/">chemview</a> - An interactive molecular viewer designed for the IPython notebook. </li> <li><a href="http://futurefullers.com/imolecule/">imolecule</a> - An embeddable webGL molecule viewer and file format converter.</li> <li><a href="https://pgi-jcns.fz-juelich.de/portal/pages/pymoldyn-main.html">pymoldyn</a> - A viewer for atomic clusters, crystalline and amorphous materials in a unit cell corresponding to one of the seven 3D Bravais lattices.</li> </ul> <h2 id="general-scientific-packages">General Scientific Packages</h2> <p><em>Packages for scientific computing and data analyzing.</em></p> <ul> <li><a href="https://github.com/blaze/blaze">blaze</a> - NumPy and Pandas interface to Big Data.</li> <li><a href="https://networkx.github.io/">NetworkX</a> - A high-productivity software for complex networks.</li> <li><a href="http://neupy.com/pages/home.html">Neupy</a> - Running and testing different Artificial Neural Networks algorithms.</li> <li><a href="http://numba.pydata.org/">Numba</a> - Python JIT (just in time) complier to LLVM aimed at scientific Python by the developers of Cython and NumPy.</li> <li><a href="http://www.numpy.org/">NumPy</a> - A fundamental package for scientific computing with Python.</li> <li><a href="https://github.com/mining/mining">Open Mining</a> - Business Intelligence (BI) in Python (Pandas web interface)</li> <li><a href="http://orange.biolab.si/">orange</a> - Data mining, data visualization, analysis and machine learning through visual programming or Python scripting.</li> <li><a href="http://pandas.pydata.org/">Pandas</a> - A library providing high-performance, easy-to-use data structures and data analysis tools.</li> <li><a href="http://www.pydy.org/">PyDy</a> - Short for Python Dynamics, used to assist with workflow in the modeling of dynamic motion based around NumPy, SciPy, IPython, and matplotlib.</li> <li><a href="https://github.com/pymc-devs/pymc3">PyMC</a> - Markov Chain Monte Carlo sampling toolkit.</li> <li><a href="https://openbabel.org/docs/dev/UseTheLibrary/Python_Pybel.html">scikit-learn</a> - Very powerful and rich machine learning library, built on NumPy, SciPy, and matplotlib.</li> <li><a href="http://www.scipy.org/">SciPy</a> - A Python-based ecosystem of open-source software for mathematics, science, and engineering.</li> <li><a href="https://github.com/statsmodels/statsmodels">statsmodels</a> - Statistical modeling and econometrics in Python.</li> <li><a href="https://github.com/sympy/sympy">SymPy</a> - A Python library for symbolic mathematics.</li> </ul> <h2 id="data-visualization">Data Visualization</h2> <p><em>Libraries for visualizing data.</em></p> <ul> <li><a href="http://matplotlib.org/">matplotlib</a> - A Python 2D plotting library.</li> <li><a href="https://github.com/bokeh/bokeh">bokeh</a> - Interactive Web Plotting for Python.</li> <li><a href="https://github.com/yhat/ggplot">ggplot</a> - Same API as ggplot2 for R.</li> <li><a href="https://plot.ly/python/">plotly</a> - Collaborative web plotting for Python and matplotlib.</li> <li><a href="http://www.pygal.org/en/latest/">pygal</a> - A Python SVG Charts Creator.</li> <li><a href="https://pypi.python.org/pypi/pygraphviz">pygraphviz</a> - Python interface to <a href="http://www.graphviz.org/">Graphviz</a>.</li> <li><a href="http://www.pyqtgraph.org/">PyQtGraph</a> - Interactive and real time 2D/3D/Image plotting and science/engineering widgets.</li> <li><a href="http://jiffyclub.github.io/snakeviz/">SnakeViz</a> - A browser based graphical viewer for the output of Python's cProfile module.</li> <li><a href="https://github.com/wrobstory/vincent">vincent</a> - A Python to Vega translator.</li> <li><a href="http://vispy.org/">VisPy</a> - High-performance scientific visualization based on OpenGL.</li> </ul>