## New publication in Calphad

| categories: | tags: | View Comments

Alloys can have rich, complex phase behavior. Cu-Pd alloys for example show an unusual behavior where a BCC lattice forms for some compositions, even though the alloy is made from two metals that are exclusively FCC in structure! Being able to model and predict this kind of behavior is a major challenge. In this work, we use cluster expansions to model the configurational degrees of freedom in the FCC and BCC lattices and show qualitatively that we can predict the region where the B2 phase (the BCC one) forms. The agreement with experiment is not quantitative though, and we show that part this disagreement is due to the lack of vibrational entropy in the cluster expansion. When we include vibrational entropy, the qualitative agreement improves.

@article{geng-2017-first-princ,
author =       "Feiyang Geng and Jacob R. Boes and John R. Kitchin",
title =        {First-Principles Study of the Cu-Pd Phase Diagram},
journal =      "Calphad ",
volume =       56,
pages =        "224 - 229",
year =         2017,
doi =          {10.1016/j.calphad.2017.01.009},
url =
{https://doi.org/http://dx.doi.org/10.1016/j.calphad.2017.01.009},
abstract =     "Abstract The equilibrium phase diagram of a Cu-Pd alloy has
been computed using cluster expansion and Monte Carlo
simulation methods combined with density functional theory.
The computed phase boundaries show basic features that are
consistent with the experimentally reported phase diagram.
Without vibrational free energy contributions, the
order-disorder transition temperature is underestimated by 100
K and the critical point is inconsistent with experimental
result. The addition of vibrational free energy contributions
yields a more qualitatively correct Cu-Pd phase diagram in the
Cu rich region. ",
issn =         "0364-5916",
keywords =     "Density functional theory",
}


Copyright (C) 2017 by John Kitchin. See the License for information about copying.

org-mode source

Org-mode version = 9.0.3

Read and Post Comments

## New publication in Molecular Simulation

| categories: | tags: | View Comments

Molecules interact with each other when they adsorb on surfaces and these interactions are coverage dependent. Modeling these interactions is a challenge though, because there are many configurations of adsorbates on the surface, and the surface changes due to the interactions. To mitigate these challenges, one often simplifies the model, e.g. by using a cluster expansion or lattice gas Hamiltonian. These approaches have their own limitations though, and are not that useful for modeling dynamic processes like diffusion. Using molecular potentials enables the dynamic simulations, but not at the same level of accuracy as density functional theory. In this work we use density functional theory to train a neural network, and then use the neural network to model coverage-dependent adsorption isotherms and the dynamics of oxygen diffusion on a Pd(111) surface. We show the neural network can capture the onset of surface oxidation, and that the simulation results have comparable accuracy to the DFT calculations it was trained from.

@article{boes-2017-neural-networ,
author =       {Jacob R. Boes and John R. Kitchin},
title =        {Neural Network Predictions of Oxygen Interactions on a Dynamic
Pd Surface},
journal =      {Molecular Simulation},
pages =        {1-9},
year =         2017,
doi =          {10.1080/08927022.2016.1274984},
url =          {https://doi.org/10.1080/08927022.2016.1274984},
keywords =     {CBET-1506770},
}


Copyright (C) 2017 by John Kitchin. See the License for information about copying.

org-mode source

Org-mode version = 9.0.3

Read and Post Comments

## New publication in J. Phys. Chem. C

| categories: | tags: | View Comments

The surface composition of an alloy is rarely the same as the bulk composition due to segregation, and it changes with changing reaction conditions. Segregation is a ubiquitous issue in alloy catalysis, and makes modeling alloy surfaces a challenge, because we need to know the surface composition to model them! In this work, we take a first step in using density functional theory to build a neural network potential that we can use with Monte Carlo simulations to predict the temperature dependent surface composition of an Au-Pd bulk alloy in a vacuum. This approach yielded quantitative predictions in good agreement with experimental measurements over the entire bulk composition range.

@article{boes-2017-model-segreg,
author =       {Boes, Jacob Russell and Kitchin, John R.},
title =        {Modeling Segregation on {AuPd}(111) Surfaces With Density
Functional Theory and Monte Carlo Simulations},
journal =      {The Journal of Physical Chemistry C},
volume =       0,
number =       {ja},
pages =        {null},
year =         2017,
doi =          {10.1021/acs.jpcc.6b12752},
url =          {https://doi.org/10.1021/acs.jpcc.6b12752},
eprint =       { http://dx.doi.org/10.1021/acs.jpcc.6b12752 },
}


Copyright (C) 2017 by John Kitchin. See the License for information about copying.

org-mode source

Org-mode version = 9.0.3

Read and Post Comments

## ob-ipython and inline figures in org-mode

| categories: | tags: | View Comments

## Table of Contents

ob-ipython provides some nice support for inline images, but it is a little limited. You can only have one inline plot, and you cannot capture the printed output. I often want both, and use more than one figure in a code block. So, here I look at a way to get that.

When ob-ipython executes a cell, it gets two things internally: the output and a list of result elements. The output is all the stuff that is printed, and the result contains result cells. So, we just have to check these for images, and append them to the output in an appropriate way. I will do that using file links so that org automatically renders them. We will save the images as temp files, since they are regenerated each time you run the cell.

I want output and inline figures. This ipython block should output some text and two figures. Note we do not define file names anywhere! See this section for details on how to get ob-ipython to do this.

%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np

t = np.linspace(0, 20 * np.pi, 350)
x = np.exp(-0.1 * t) * np.sin(t)
y = np.exp(-0.1 * t) * np.cos(t)

plt.plot(x, y)
plt.axis('equal')

plt.figure()
plt.plot(y, x)
plt.axis('equal')

print('Length of t = {}'.format(len(t)))
print('x .dot. y = {}'.format(x @ y))


Length of t = 350 x .dot. y = 1.3598389888491538

Nice, success! Now my code blocks export more cleanly to jupyter notebooks. Speaking of which, if you liked the post on that, there is a new library for it in scimax: https://github.com/jkitchin/scimax/blob/master/ox-ipynb.el. Yes, one day I will put it in its own repo, and probably put it up on MELPA. If it turns out to be useful over the next semester.

## 1 code for getting output and inline figures

I wrote one new function that writes the base64 data out to a temporary file and returns a link to it. Then, I modified the org-babel-execute:ipython function to append these links onto the output. It seems like you need to use a header like this in your ob-ipython block, notably the results need to be in a drawer like this if you want org-mode to render the images. They do not show up in the results that have colons starting them.

#+BEGIN_SRC ipython :session :results output drawer


Here is the code.

(defun ob-ipython-inline-image (b64-string)
"Write the b64-string to a temporary file.
Returns an org-link to the file."
(let* ((tfile (make-temp-file "ob-ipython-" nil ".png"))
(link (format "[[file:%s]]" tfile)))
(ob-ipython--write-base64-string tfile b64-string)
link))

(defun org-babel-execute:ipython (body params)
"Execute a block of IPython code with Babel.
This function is called by org-babel-execute-src-block'."
(let* ((file (cdr (assoc :file params)))
(session (cdr (assoc :session params)))
(result-type (cdr (assoc :result-type params))))
(org-babel-ipython-initiate-session session params)
(-when-let (ret (ob-ipython--eval
(ob-ipython--execute-request
(org-babel-expand-body:generic (encode-coding-string body 'utf-8)
params (org-babel-variable-assignments:python params))
(ob-ipython--normalize-session session))))
(let ((result (cdr (assoc :result ret)))
(output (cdr (assoc :output ret))))
(if (eq result-type 'output)
(concat
output
(format "%s"
(mapconcat 'identity
(loop for res in result
if (eq 'image/png (car res))
collect (ob-ipython-inline-image (cdr res)))
"\n")))
(ob-ipython--create-stdout-buffer output)
(cond ((and file (string= (f-ext file) "png"))
(->> result (assoc 'image/png) cdr (ob-ipython--write-base64-string file)))
((and file (string= (f-ext file) "svg"))
(->> result (assoc 'image/svg+xml) cdr (ob-ipython--write-string-to-file file)))
(file (error "%s is currently an unsupported file extension." (f-ext file)))
(t (->> result (assoc 'text/plain) cdr))))))))

org-babel-execute:ipython


Copyright (C) 2017 by John Kitchin. See the License for information about copying.

org-mode source

Org-mode version = 9.0.3

Read and Post Comments

## Exporting org-mode to Jupyter notebooks

| categories: | tags: | View Comments

## Table of Contents

I am going to use Jupyter notebooks to teach from this semester. I really dislike preparing notebooks though. A browser is a really poor editor, and I really dislike Markdown. Notebooks do not seem to have any real structure in them, e.g. the collapsible outline that I am used to in org-mode, so for long notebooks, it is difficult to get a sense for the structure. I am anticipating spending up to 80 hours preparing notebooks this semester, so today I worked out some code to export org-mode to an ipython notebook!

This will let me use the power tools I am accustomed to for the creation of IPython notebooks for my students, and perhaps others who do not use org-mode.

Jupyter notebooks are just json files, so all we need to do is generate it from an org document. The basic strategy was to build up a lisp data structure that represents the notebook and then just convert that data structure to json. I split the document up into sequential markdown and code cells, and then encode those in the format required for the notebook (json).

So, here is an example of what can be easily written in org-mode, posted to this blog, and exported to an IPython notebook, all from one org-document.

Check out the notebook: exporting-orgmode-to-ipynb.ipynb .

## 1 Solve a nonlinear problem

Consider the equation $$x^2 = 4$$. Find a solution to it in Python using a nonlinear solver.

To do that, we need to define an objective function that will be equal to zero at the solution. Here is the function:

def objective(x):
return x**2 - 4


Next, we use fsolve with an initial guess. We get fsolve from scipy.optimize.

from scipy.optimize import fsolve

ans = fsolve(objective, 3)
print(ans)

[ 2.]


That should have been an obvious answer. The answer is in brackets because fsolve returns an array. In the next block we will unpack the solution into the answer using the comma operator. Also, we can see that using a different guess leads to a different answer. There are, of course, two answers: $$x = \pm 2$$

ans, = fsolve(objective, -3)
print(ans)

-2.0


Now you see we get a float answer!

Here are some other ways to get a float:

ans = fsolve(objective, -3)

print(float(ans))
print(ans[0])

-2.0000000000000084
-2.0


It is worth noting from the first result that fsolve is iterative and stops when it reaches zero within a tolerance. That is why it is not exactly -2.

## 2 Benefits of export to ipynb

1. I can use org-mode
2. And emacs
3. and ipynb for teaching.

The export supports org-markup: bold, italic, underlined, and ~~strike~~.

We can use tables:

Table 1: A table of squares.
x y
1 2
2 4
3 9
4 16

We can make plots.

import numpy as np

t = np.linspace(0, 2 * np.pi)

x = np.cos(t)
y = np.sin(t)

import matplotlib.pyplot as plt
plt.plot(x, y)
plt.axis('equal')
plt.xlabel('x')
plt.ylabel('y')
plt.savefig('circle.png')


Even include HTML: <font color="red">Pay special attention to the axis labels!</font>

## 3 Limitations

• Only supports iPython blocks
• Does not do inline images in results
• Will not support src-block variables
• Currently only supports vanilla output results

## 4 Summary

The code that does this is here: ox-ipynb.el . After I use it a while I will put it in scimax. There are some tricks in it to fix up some markdown export of latex fragments and links with no descriptions.

I just run this command in Emacs to get the notebook. Even it renders reasonably in the notebook.

(export-ipynb-buffer)
`

Overall, this looks extremely promising to develop lecture notes and assignments in org-mode, but export them to Ipython notebooks for the students.

Copyright (C) 2017 by John Kitchin. See the License for information about copying.

org-mode source

Org-mode version = 9.0.3

Read and Post Comments

Next Page »