<?xml version="1.0" encoding="UTF-8"?>

<rss version="2.0"
     xmlns:content="http://purl.org/rss/1.0/modules/content/"
     xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
     xmlns:atom="http://www.w3.org/2005/Atom"
     xmlns:dc="http://purl.org/dc/elements/1.1/"
     xmlns:wfw="http://wellformedweb.org/CommentAPI/"
     >
  <channel>
    <atom:link href="http://kitchingroup.cheme.cmu.edu/blog/feed/index.xml" rel="self" type="application/rss+xml" />
    <title>The Kitchin Research Group</title>
    <link>https://kitchingroup.cheme.cmu.edu/blog</link>
    <description>Chemical Engineering at Carnegie Mellon University</description>
    <pubDate>Sat, 01 Nov 2025 13:47:46 GMT</pubDate>
    <generator>Blogofile</generator>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
    
    <item>
      <title>yasnippets for jasp, ase and python</title>
      <link>https://kitchingroup.cheme.cmu.edu/blog/2014/02/17/yasnippets-for-jasp-ase-and-python</link>
      <pubDate>Mon, 17 Feb 2014 09:03:50 EST</pubDate>
      <category><![CDATA[jasp]]></category>
      <category><![CDATA[emacs]]></category>
      <category><![CDATA[ase]]></category>
      <guid isPermaLink="false">5IQtbu_TyyiAG1EcGdlxi4IDXtc=</guid>
      <description>yasnippets for jasp, ase and python</description>
      <content:encoded><![CDATA[


&lt;div id="table-of-contents"&gt;
&lt;h2&gt;Table of Contents&lt;/h2&gt;
&lt;div id="text-table-of-contents"&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="#sec-1"&gt;1. Tangle the snippets, and add them to yasnippet&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#sec-2"&gt;2. Using the snippets&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#sec-3"&gt;3. Appendix&lt;/a&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="#sec-3-1"&gt;3.1. jasp snippets&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#sec-3-2"&gt;3.2. ase snippets&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#sec-3-3"&gt;3.3. python snippets&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;
In using [[&lt;a href="http://github.com/jkitchin/jasp"&gt;http://github.com/jkitchin/jasp&lt;/a&gt; for calculations, I find there are lots of small python phrases I use over and over. Today I will examine using &lt;a href="http://capitaomorte.github.io/yasnippet/index.html"&gt;yasnippet&lt;/a&gt; to save time and keystrokes. yasnippet is a template expansion module, where you type a small set of characters, press &lt;code&gt;Tab&lt;/code&gt;, and the
characters "expand" to the full text. It is pretty sophisticated, and allows you to define "tab-stops" which you interactively fill in, and tab between like filling in a form.
&lt;/p&gt;

&lt;p&gt;
All the snippets are defined in the &lt;pre&gt;*Appendix&lt;/pre&gt; .
&lt;/p&gt;

&lt;div id="outline-container-sec-1" class="outline-2"&gt;
&lt;h2 id="sec-1"&gt;&lt;span class="section-number-2"&gt;1&lt;/span&gt; Tangle the snippets, and add them to yasnippet&lt;/h2&gt;
&lt;div class="outline-text-2" id="text-1"&gt;
&lt;p&gt;
Each snippet definition belongs in a file in a directory. The main directory is called "snippets". Since I anticipate using these snippets in org-mode, each snippet is defined in a directory within snippets called "org-mode". First, we make the directory here. I also want to use the snippets in python mode, so we also create a python-mode directory here. We do not have to duplicate the snippets. We can create a file called &lt;a href="http://capitaomorte.github.io/yasnippet/snippet-organization.html"&gt;.yas-parents&lt;/a&gt; , with one line in it containing "org-mode".
&lt;/p&gt;

&lt;div class="org-src-container"&gt;

&lt;pre class="src src-sh"&gt;mkdir -p snippets/org-mode
mkdir -p snippets/python-mode
&lt;span style="color: #cd0000;"&gt;echo&lt;/span&gt; &lt;span style="color: #228b22;"&gt;"org-mode"&lt;/span&gt; &amp;gt; snippets/python-mode/.yas-parents
&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;
Each snippet is defined in a src block with  a &lt;code&gt;:tangle&lt;/code&gt; header. So, we can extract them all in one command here.
&lt;/p&gt;

&lt;div class="org-src-container"&gt;

&lt;pre class="src src-emacs-lisp"&gt;(org-babel-tangle)
&lt;/pre&gt;
&lt;/div&gt;

&lt;table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides"&gt;


&lt;colgroup&gt;
&lt;col  class="left" /&gt;

&lt;col  class="left" /&gt;

&lt;col  class="left" /&gt;

&lt;col  class="left" /&gt;

&lt;col  class="left" /&gt;

&lt;col  class="left" /&gt;

&lt;col  class="left" /&gt;

&lt;col  class="left" /&gt;

&lt;col  class="left" /&gt;

&lt;col  class="left" /&gt;

&lt;col  class="left" /&gt;

&lt;col  class="left" /&gt;

&lt;col  class="left" /&gt;

&lt;col  class="left" /&gt;

&lt;col  class="left" /&gt;

&lt;col  class="left" /&gt;

&lt;col  class="left" /&gt;

&lt;col  class="left" /&gt;

&lt;col  class="left" /&gt;
&lt;/colgroup&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td class="left"&gt;snippets/org-mode/iase&lt;/td&gt;
&lt;td class="left"&gt;snippets/org-mode/imp&lt;/td&gt;
&lt;td class="left"&gt;snippets/org-mode/inp&lt;/td&gt;
&lt;td class="left"&gt;snippets/org-mode/ij&lt;/td&gt;
&lt;td class="left"&gt;snippets/org-mode/pl&lt;/td&gt;
&lt;td class="left"&gt;snippets/org-mode/pyl&lt;/td&gt;
&lt;td class="left"&gt;snippets/org-mode/pxl&lt;/td&gt;
&lt;td class="left"&gt;snippets/org-mode/pp&lt;/td&gt;
&lt;td class="left"&gt;snippets/org-mode/npa&lt;/td&gt;
&lt;td class="left"&gt;snippets/org-mode/awt&lt;/td&gt;
&lt;td class="left"&gt;snippets/org-mode/avw&lt;/td&gt;
&lt;td class="left"&gt;snippets/org-mode/agf&lt;/td&gt;
&lt;td class="left"&gt;snippets/org-mode/ape&lt;/td&gt;
&lt;td class="left"&gt;snippets/org-mode/atms&lt;/td&gt;
&lt;td class="left"&gt;snippets/org-mode/atm&lt;/td&gt;
&lt;td class="left"&gt;snippets/org-mode/cga&lt;/td&gt;
&lt;td class="left"&gt;snippets/org-mode/cc&lt;/td&gt;
&lt;td class="left"&gt;snippets/org-mode/wjn&lt;/td&gt;
&lt;td class="left"&gt;snippets/org-mode/wjl&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;
We also need to add our new directory to yasnippets. This is done by adding the directory to the &lt;code&gt;yas-snippet-dirs&lt;/code&gt; variable. You could add this to your init.el file to permanently add these snippets.
&lt;/p&gt;

&lt;div class="org-src-container"&gt;

&lt;pre class="src src-emacs-lisp"&gt;(add-to-list 'yas-snippet-dirs &lt;span style="color: #228b22;"&gt;"c:/Users/jkitchin/Dropbox/blogofile-jkitchin.github.com/_blog/snippets"&lt;/span&gt;)
&lt;/pre&gt;
&lt;/div&gt;
&lt;table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides"&gt;


&lt;colgroup&gt;
&lt;col  class="left" /&gt;

&lt;col  class="left" /&gt;

&lt;col  class="left" /&gt;
&lt;/colgroup&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td class="left"&gt;c:/Users/jkitchin/Dropbox/blogofile-jkitchin.github.com/&lt;sub&gt;blog&lt;/sub&gt;/snippets&lt;/td&gt;
&lt;td class="left"&gt;~/.emacs.d/snippets&lt;/td&gt;
&lt;td class="left"&gt;c:/users/jkitchin/Dropbox/kitchingroup/jmax/elpa/yasnippet-20140106.1009/snippets&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;
Finally, we reload all the snippet definitions, so our new definitions are ready to use.
&lt;/p&gt;
&lt;div class="org-src-container"&gt;

&lt;pre class="src src-emacs-lisp"&gt;(yas-reload-all)
&lt;/pre&gt;
&lt;/div&gt;

&lt;pre class="example"&gt;
[yas] Reloaded everything (snippets will load just-in-time)... (some errors, check *Messages*).
&lt;/pre&gt;

&lt;p&gt;
Alternatively, you might just load this directory.
&lt;/p&gt;
&lt;div class="org-src-container"&gt;

&lt;pre class="src src-emacs-lisp"&gt;(yas-load-directory &lt;span style="color: #228b22;"&gt;"./snippets"&lt;/span&gt;)
&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div id="outline-container-sec-2" class="outline-2"&gt;
&lt;h2 id="sec-2"&gt;&lt;span class="section-number-2"&gt;2&lt;/span&gt; Using the snippets&lt;/h2&gt;
&lt;div class="outline-text-2" id="text-2"&gt;
&lt;p&gt;
Each of these snippets is for a python phrase, but I usually write my python blocks in org-mode. You would use these by typing the shortcut name, and then pressing tab. Below I show what each shortcut expands to.
&lt;/p&gt;

&lt;p&gt;
wjl &amp;rarr; &lt;code&gt;with jasp('') as calc:&lt;/code&gt;
&lt;/p&gt;

&lt;p&gt;
wjn &amp;rarr; &lt;code&gt;with jasp('',) as calc:&lt;/code&gt;
    &lt;code&gt;calc.calculate(atoms)&lt;/code&gt;
&lt;/p&gt;

&lt;p&gt;
cc  &amp;rarr; &lt;code&gt;calc.calculate(atoms)&lt;/code&gt;
&lt;/p&gt;

&lt;p&gt;
cga &amp;rarr; &lt;code&gt;atoms = calc.get_atoms()&lt;/code&gt;
&lt;/p&gt;

&lt;p&gt;
atm &amp;rarr; &lt;code&gt;Atom('', )&lt;/code&gt;
&lt;/p&gt;

&lt;p&gt;
atms &amp;rarr; &lt;code&gt;atoms = Atoms([], cell&lt;/code&gt;)=
&lt;/p&gt;

&lt;p&gt;
ape &amp;rarr; &lt;code&gt;atoms.get_potential_energy()&lt;/code&gt;
&lt;/p&gt;

&lt;p&gt;
agf &amp;rarr; &lt;code&gt;atoms.get_forces()&lt;/code&gt;
&lt;/p&gt;

&lt;p&gt;
avw &amp;rarr; &lt;code&gt;from ase.visualize import view&lt;/code&gt;
&lt;code&gt;view(atoms)&lt;/code&gt;
&lt;/p&gt;

&lt;p&gt;
awt &amp;rarr; &lt;code&gt;from ase.io import write&lt;/code&gt;
&lt;code&gt;write('.png', atoms, show_unit_cell=2)&lt;/code&gt;
&lt;/p&gt;

&lt;p&gt;
npa &amp;rarr; &lt;code&gt;np.array()&lt;/code&gt;
&lt;/p&gt;

&lt;p&gt;
pp &amp;rarr; &lt;code&gt;plt.plot(, )&lt;/code&gt;
&lt;/p&gt;

&lt;p&gt;
pxl &amp;rarr; &lt;code&gt;plt.xlabel()&lt;/code&gt;
&lt;/p&gt;

&lt;p&gt;
pyl &amp;rarr; &lt;code&gt;plt.ylabel()&lt;/code&gt;
&lt;/p&gt;

&lt;p&gt;
pl &amp;rarr; &lt;code&gt;plt.legend()&lt;/code&gt;
&lt;/p&gt;

&lt;p&gt;
ij &amp;rarr; &lt;code&gt;from jasp import *&lt;/code&gt;
&lt;/p&gt;

&lt;p&gt;
inp &amp;rarr; &lt;code&gt;import numpy as np&lt;/code&gt;
&lt;/p&gt;

&lt;p&gt;
imp &amp;rarr; &lt;code&gt;import matplotlib.pyplot as plt&lt;/code&gt;
&lt;/p&gt;

&lt;p&gt;
iase &amp;rarr; &lt;code&gt;from ase import Atom, Atoms&lt;/code&gt;
&lt;/p&gt;

&lt;p&gt;
What other snippets would be handy?
&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div id="outline-container-sec-3" class="outline-2"&gt;
&lt;h2 id="sec-3"&gt;&lt;span class="section-number-2"&gt;3&lt;/span&gt; Appendix&lt;/h2&gt;
&lt;div class="outline-text-2" id="text-3"&gt;
&lt;/div&gt;&lt;div id="outline-container-sec-3-1" class="outline-3"&gt;
&lt;h3 id="sec-3-1"&gt;&lt;span class="section-number-3"&gt;3.1&lt;/span&gt; jasp snippets&lt;/h3&gt;
&lt;div class="outline-text-3" id="text-3-1"&gt;
&lt;div class="org-src-container"&gt;

&lt;pre class="src src-snippet"&gt;# -*- mode: snippet -*-
# --
with jasp('$1') as calc:
    $0
&lt;/pre&gt;
&lt;/div&gt;

&lt;div class="org-src-container"&gt;

&lt;pre class="src src-snippet"&gt;# -*- mode: snippet -*-
# --
with jasp('$1',$0) as calc:
    calc.calculate(atoms)
&lt;/pre&gt;
&lt;/div&gt;


&lt;div class="org-src-container"&gt;

&lt;pre class="src src-snippet"&gt;# -*- mode: snippet -*-
# --
calc.calculate(atoms)
&lt;/pre&gt;
&lt;/div&gt;

&lt;div class="org-src-container"&gt;

&lt;pre class="src src-snippet"&gt;# -*- mode: snippet -*-
# --
atoms = calc.get_atoms()
&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div id="outline-container-sec-3-2" class="outline-3"&gt;
&lt;h3 id="sec-3-2"&gt;&lt;span class="section-number-3"&gt;3.2&lt;/span&gt; ase snippets&lt;/h3&gt;
&lt;div class="outline-text-3" id="text-3-2"&gt;
&lt;p&gt;
Template for an ase.Atom
&lt;/p&gt;

&lt;div class="org-src-container"&gt;

&lt;pre class="src src-snippet"&gt;# -*- mode: snippet -*-
# --
Atom('$1', $2)
&lt;/pre&gt;
&lt;/div&gt;

&lt;div class="org-src-container"&gt;

&lt;pre class="src src-snippet"&gt;# -*- mode: snippet -*-
# --
atoms = Atoms([$1], cell=$2)
&lt;/pre&gt;
&lt;/div&gt;


&lt;div class="org-src-container"&gt;

&lt;pre class="src src-snippet"&gt;# -*- mode: snippet -*-
# --
atoms.get_potential_energy()
&lt;/pre&gt;
&lt;/div&gt;


&lt;div class="org-src-container"&gt;

&lt;pre class="src src-snippet"&gt;# -*- mode: snippet -*-
# --
atoms.get_forces()
&lt;/pre&gt;
&lt;/div&gt;


&lt;div class="org-src-container"&gt;

&lt;pre class="src src-snippet"&gt;# -*- mode: snippet -*-
# --
from ase.visualize import view
view(${1:atoms})
&lt;/pre&gt;
&lt;/div&gt;


&lt;div class="org-src-container"&gt;

&lt;pre class="src src-snippet"&gt;# -*- mode: snippet -*-
# --
from ase.io import write
write('$1.png', ${2:atoms}, show_unit_cell=${3:2})
&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div id="outline-container-sec-3-3" class="outline-3"&gt;
&lt;h3 id="sec-3-3"&gt;&lt;span class="section-number-3"&gt;3.3&lt;/span&gt; python snippets&lt;/h3&gt;
&lt;div class="outline-text-3" id="text-3-3"&gt;
&lt;div class="org-src-container"&gt;

&lt;pre class="src src-snippet"&gt;# -*- mode: snippet -*-
# --
import numpy as np
&lt;/pre&gt;
&lt;/div&gt;

&lt;div class="org-src-container"&gt;

&lt;pre class="src src-snippet"&gt;# -*- mode: snippet -*-
# --
import matplotlib.pyplot as plt
&lt;/pre&gt;
&lt;/div&gt;

&lt;div class="org-src-container"&gt;

&lt;pre class="src src-snippet"&gt;# -*- mode: snippet -*-
# --
from ase import Atom, Atoms
&lt;/pre&gt;
&lt;/div&gt;


&lt;div class="org-src-container"&gt;

&lt;pre class="src src-snippet"&gt;# -*- mode: snippet -*-
# --
np.array($0)
&lt;/pre&gt;
&lt;/div&gt;

&lt;div class="org-src-container"&gt;

&lt;pre class="src src-snippet"&gt;# -*- mode: snippet -*-
# --
plt.plot($1, $2)
&lt;/pre&gt;
&lt;/div&gt;

&lt;div class="org-src-container"&gt;

&lt;pre class="src src-snippet"&gt;# -*- mode: snippet -*-
# --
plt.xlabel($1)
&lt;/pre&gt;
&lt;/div&gt;

&lt;div class="org-src-container"&gt;

&lt;pre class="src src-snippet"&gt;# -*- mode: snippet -*-
# --
plt.ylabel($1)
&lt;/pre&gt;
&lt;/div&gt;

&lt;div class="org-src-container"&gt;

&lt;pre class="src src-snippet"&gt;# -*- mode: snippet -*-
# --
plt.legend($1)
&lt;/pre&gt;
&lt;/div&gt;


&lt;div class="org-src-container"&gt;

&lt;pre class="src src-snippet"&gt;# -*- mode: snippet -*-
# --
from jasp import *
&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Copyright (C) 2014 by John Kitchin. See the &lt;a href="/copying.html"&gt;License&lt;/a&gt; for information about copying.&lt;p&gt;&lt;p&gt;&lt;a href="/org/2014/02/17/yasnippets-for-jasp,-ase-and-python.org"&gt;org-mode source&lt;/a&gt;&lt;p&gt;&lt;p&gt;Org-mode version = 8.2.5h&lt;/p&gt;]]></content:encoded>
    </item>
    <item>
      <title>Serializing jasp calculations as json data</title>
      <link>https://kitchingroup.cheme.cmu.edu/blog/2013/10/19/Serializing-jasp-calculations-as-json-data</link>
      <pubDate>Sat, 19 Oct 2013 14:33:51 EDT</pubDate>
      <category><![CDATA[jasp]]></category>
      <category><![CDATA[ase]]></category>
      <category><![CDATA[vasp]]></category>
      <guid isPermaLink="false">7Iyi5XdH1nYlzbMyfxMdYcLjqEg=</guid>
      <description>Serializing jasp calculations as json data</description>
      <content:encoded><![CDATA[


&lt;div id="table-of-contents"&gt;
&lt;h2&gt;Table of Contents&lt;/h2&gt;
&lt;div id="text-table-of-contents"&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="#sec-1"&gt;1. The simplest case of a simple calculation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#sec-2"&gt;2. Including extra information in the JSON file&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#sec-3"&gt;3. Limitations?&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;
We use &lt;a href="http://www.vasp.at/"&gt;VASP&lt;/a&gt;to calculate materials properties in our research We use the &lt;a href="https://github.com/jkitchin/jasp/tree/dev"&gt;jasp&lt;/a&gt;python module we have developed to setup, run and analyze those calculations. One of the things we have worked on developing recently is to more transparently share how do this kind of work by using org-mode supporting information files. Doing this should make our research more reproducible, and allow others to build off of it more easily.
&lt;/p&gt;

&lt;p&gt;
We have run into the following problem trying to share VASP results however. The VASP license prohibits us from sharing the POTCAR files that are used to run the calculations. That is unfortunate, but since these files are also what give VASP some competitive advantage, they are protected, and we agreed to that when we bought the license. The problem is that the &lt;code&gt;jasp&lt;/code&gt; module requires the POTCAR files to work, so without them, our scripts are not reproducible by researchers without a VASP license. 
&lt;/p&gt;

&lt;p&gt;
So, we have been looking at new ways to share the data from our calculations. In this post, we consider representing the calculation as a JSON file. We will look at a couple of new features built into the development branch of &lt;code&gt;jasp&lt;/code&gt;
&lt;/p&gt;

&lt;div id="outline-container-sec-1" class="outline-2"&gt;
&lt;h2 id="sec-1"&gt;&lt;span class="section-number-2"&gt;1&lt;/span&gt; The simplest case of a simple calculation&lt;/h2&gt;
&lt;div class="outline-text-2" id="text-1"&gt;
&lt;p&gt;
Here we setup and run a simple calculation, and output the JSON file.
&lt;/p&gt;

&lt;div class="org-src-container"&gt;

&lt;pre class="src src-python"&gt;&lt;span style="color: #8b0000;"&gt;from&lt;/span&gt; ase &lt;span style="color: #8b0000;"&gt;import&lt;/span&gt; Atoms, Atom
&lt;span style="color: #8b0000;"&gt;from&lt;/span&gt; jasp &lt;span style="color: #8b0000;"&gt;import&lt;/span&gt; *
&lt;span style="color: #8b0000;"&gt;import&lt;/span&gt; numpy &lt;span style="color: #8b0000;"&gt;as&lt;/span&gt; np
np.set_printoptions(precision=3, suppress=&lt;span style="color: #cd0000;"&gt;True&lt;/span&gt;)

&lt;span style="color: #8b008b;"&gt;co&lt;/span&gt; = Atoms([Atom(&lt;span style="color: #228b22;"&gt;'C'&lt;/span&gt;,[0,   0, 0]),
            Atom(&lt;span style="color: #228b22;"&gt;'O'&lt;/span&gt;,[1.2, 0, 0])],
            cell=(6., 6., 6.))

&lt;span style="color: #8b0000;"&gt;with&lt;/span&gt; jasp(&lt;span style="color: #228b22;"&gt;'molecules/simple-co'&lt;/span&gt;, &lt;span style="color: #ff0000; font-weight: bold;"&gt;#&lt;/span&gt;&lt;span style="color: #ff0000; font-weight: bold;"&gt;output dir&lt;/span&gt;
          xc=&lt;span style="color: #228b22;"&gt;'PBE'&lt;/span&gt;,  &lt;span style="color: #ff0000; font-weight: bold;"&gt;# &lt;/span&gt;&lt;span style="color: #ff0000; font-weight: bold;"&gt;the exchange-correlation functional&lt;/span&gt;
          nbands=6,  &lt;span style="color: #ff0000; font-weight: bold;"&gt;# &lt;/span&gt;&lt;span style="color: #ff0000; font-weight: bold;"&gt;number of bands&lt;/span&gt;
          encut=350, &lt;span style="color: #ff0000; font-weight: bold;"&gt;# &lt;/span&gt;&lt;span style="color: #ff0000; font-weight: bold;"&gt;planewave cutoff&lt;/span&gt;
          ismear=1,  &lt;span style="color: #ff0000; font-weight: bold;"&gt;# &lt;/span&gt;&lt;span style="color: #ff0000; font-weight: bold;"&gt;Methfessel-Paxton smearing&lt;/span&gt;
          sigma=0.01,&lt;span style="color: #ff0000; font-weight: bold;"&gt;# &lt;/span&gt;&lt;span style="color: #ff0000; font-weight: bold;"&gt;very small smearing factor for a molecule&lt;/span&gt;
          atoms=co) &lt;span style="color: #8b0000;"&gt;as&lt;/span&gt; calc:
    &lt;span style="color: #8b0000;"&gt;print&lt;/span&gt; &lt;span style="color: #228b22;"&gt;'energy = {0} eV'&lt;/span&gt;.&lt;span style="color: #cd0000;"&gt;format&lt;/span&gt;(co.get_potential_energy())
    &lt;span style="color: #8b0000;"&gt;print&lt;/span&gt; co.get_forces()
    &lt;span style="color: #8b0000;"&gt;with&lt;/span&gt; &lt;span style="color: #cd0000;"&gt;open&lt;/span&gt;(&lt;span style="color: #228b22;"&gt;'JSON'&lt;/span&gt;, &lt;span style="color: #228b22;"&gt;'w'&lt;/span&gt;) &lt;span style="color: #8b0000;"&gt;as&lt;/span&gt; f:
        f.write(calc.json)
&lt;/pre&gt;
&lt;/div&gt;

&lt;pre class="example"&gt;
energy = -14.687906 eV
[[ 5.095  0.     0.   ]
 [-5.095  0.     0.   ]]
&lt;/pre&gt;

&lt;p&gt;
Now, we can analyze the JSON file independently of jasp. The json data contains all the inputs we used for the VASP calculation, the atomic geometry, and many of the outputs of the calculation. Here is the &lt;a href="/media/2013-10-19-Serializing-jasp-calculations-as-json-data/JSON"&gt;JSON&lt;/a&gt;file.
&lt;/p&gt;

&lt;div class="org-src-container"&gt;

&lt;pre class="src src-python"&gt;&lt;span style="color: #8b0000;"&gt;import&lt;/span&gt; json
&lt;span style="color: #8b0000;"&gt;with&lt;/span&gt; &lt;span style="color: #cd0000;"&gt;open&lt;/span&gt;(&lt;span style="color: #228b22;"&gt;'molecules/simple-co/JSON'&lt;/span&gt;, &lt;span style="color: #228b22;"&gt;'rb'&lt;/span&gt;) &lt;span style="color: #8b0000;"&gt;as&lt;/span&gt; f:
    &lt;span style="color: #8b008b;"&gt;d&lt;/span&gt; = json.loads(f.read())

&lt;span style="color: #8b0000;"&gt;print&lt;/span&gt;(&lt;span style="color: #228b22;"&gt;'The energy is {0}'&lt;/span&gt;.&lt;span style="color: #cd0000;"&gt;format&lt;/span&gt;(d[&lt;span style="color: #228b22;"&gt;'data'&lt;/span&gt;][&lt;span style="color: #228b22;"&gt;'total_energy'&lt;/span&gt;]))
&lt;span style="color: #8b0000;"&gt;print&lt;/span&gt;(&lt;span style="color: #228b22;"&gt;'The forces are {0}'&lt;/span&gt;.&lt;span style="color: #cd0000;"&gt;format&lt;/span&gt;(d[&lt;span style="color: #228b22;"&gt;'data'&lt;/span&gt;][&lt;span style="color: #228b22;"&gt;'forces'&lt;/span&gt;]))
&lt;/pre&gt;
&lt;/div&gt;

&lt;pre class="example"&gt;
The energy is -14.687906
The forces are [[5.095488, 0.0, 0.0], [-5.095488, 0.0, 0.0]]
&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div id="outline-container-sec-2" class="outline-2"&gt;
&lt;h2 id="sec-2"&gt;&lt;span class="section-number-2"&gt;2&lt;/span&gt; Including extra information in the JSON file&lt;/h2&gt;
&lt;div class="outline-text-2" id="text-2"&gt;
&lt;p&gt;
If we use a slightly different syntax, we can also include the total DOS in the JSON file.
&lt;/p&gt;
&lt;div class="org-src-container"&gt;

&lt;pre class="src src-python"&gt;&lt;span style="color: #8b0000;"&gt;from&lt;/span&gt; jasp &lt;span style="color: #8b0000;"&gt;import&lt;/span&gt; *

&lt;span style="color: #8b0000;"&gt;with&lt;/span&gt; jasp(&lt;span style="color: #228b22;"&gt;'molecules/simple-co'&lt;/span&gt;) &lt;span style="color: #8b0000;"&gt;as&lt;/span&gt; calc:
    &lt;span style="color: #8b0000;"&gt;with&lt;/span&gt; &lt;span style="color: #cd0000;"&gt;open&lt;/span&gt;(&lt;span style="color: #228b22;"&gt;'JSON-DOS'&lt;/span&gt;, &lt;span style="color: #228b22;"&gt;'w'&lt;/span&gt;) &lt;span style="color: #8b0000;"&gt;as&lt;/span&gt; f:
        f.write(calc_to_json(calc, dos=&lt;span style="color: #cd0000;"&gt;True&lt;/span&gt;))
&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;
To illustrate that we have done that, let us plot the DOS without using &lt;code&gt;jasp&lt;/code&gt; from the &lt;a href="/media/2013-10-19-Serializing-jasp-calculations-as-json-data/JSON-DOS"&gt;JSON-DOS&lt;/a&gt;file.
&lt;/p&gt;

&lt;div class="org-src-container"&gt;

&lt;pre class="src src-python"&gt;&lt;span style="color: #8b0000;"&gt;import&lt;/span&gt; json
&lt;span style="color: #8b0000;"&gt;import&lt;/span&gt; matplotlib.pyplot &lt;span style="color: #8b0000;"&gt;as&lt;/span&gt; plt

&lt;span style="color: #8b0000;"&gt;with&lt;/span&gt; &lt;span style="color: #cd0000;"&gt;open&lt;/span&gt;(&lt;span style="color: #228b22;"&gt;'molecules/simple-co/JSON-DOS'&lt;/span&gt;, &lt;span style="color: #228b22;"&gt;'rb'&lt;/span&gt;) &lt;span style="color: #8b0000;"&gt;as&lt;/span&gt; f:
    &lt;span style="color: #8b008b;"&gt;d&lt;/span&gt; = json.loads(f.read())

&lt;span style="color: #8b008b;"&gt;energies&lt;/span&gt; = d[&lt;span style="color: #228b22;"&gt;'data'&lt;/span&gt;][&lt;span style="color: #228b22;"&gt;'dos'&lt;/span&gt;][&lt;span style="color: #228b22;"&gt;'e'&lt;/span&gt;]
&lt;span style="color: #8b008b;"&gt;dos&lt;/span&gt; = d[&lt;span style="color: #228b22;"&gt;'data'&lt;/span&gt;][&lt;span style="color: #228b22;"&gt;'dos'&lt;/span&gt;][&lt;span style="color: #228b22;"&gt;'dos'&lt;/span&gt;]
plt.plot(energies, dos)
plt.savefig(&lt;span style="color: #228b22;"&gt;'molecules/simple-co/dos.png'&lt;/span&gt;)
&lt;/pre&gt;
&lt;/div&gt;


&lt;div class="figure"&gt;
&lt;p&gt;&lt;img src="/media/2013-10-19-Serializing-jasp-calculations-as-json-data/dos.png"&gt;
&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;
We are still working on getting atom-projected DOS into the json file, and ensuring that all the spin cases are handled (e.g. the spin-up and spin-down DOS).
&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div id="outline-container-sec-3" class="outline-2"&gt;
&lt;h2 id="sec-3"&gt;&lt;span class="section-number-2"&gt;3&lt;/span&gt; Limitations?&lt;/h2&gt;
&lt;div class="outline-text-2" id="text-3"&gt;
&lt;p&gt;
JSON is flexible, and can store text and numeric data. It does not store numpy arrays, but rather it is limited to storing lists of data. You would have to convert them back to arrays if you want to do array math. You probably wouldn't want to store a 3d array of electron density in this format, although it probably isn't worse than a CUBE file format. We haven't tested these files very significantly yet at a large scale to see how fast it is to read from lots of them.
&lt;/p&gt;

&lt;p&gt;
Nonetheless, this looks like a reasonable format to share data in human and machine readable form, without violating the VASP licence conditions.
&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Copyright (C) 2013 by John Kitchin. See the &lt;a href="/copying.html"&gt;License&lt;/a&gt; for information about copying.&lt;p&gt;&lt;p&gt;&lt;a href="/org/2013/10/19/Serializing-jasp-calculations-as-json-data.org"&gt;org-mode source&lt;/a&gt;&lt;p&gt;]]></content:encoded>
    </item>
  </channel>
</rss>
