The brand new Neutron Reflectivity Simulator in Eclipse ICE and what it took to make it

I’m really excited about one of the newest capabilities that we have added to Eclipse ICE: a neutron reflectivity simulator!

ICE's new Neutron Reflectivity Calculator showing the material table and the output plots.
ICE’s new Neutron Reflectivity Calculator showing the material table and the output plots.

About a year ago a colleague of mine, Bobby Sumpter, got in touch with me and told me that some of our other colleagues needed a hand porting an Excel-based neutron reflectivity calculator to ICE. The author of that code, John Ankner, and I sat down with the rest of our colleagues sometime later and then the real truth came out. Not only was their code implemented in Excel, but it was using a fair amount of Visual Basic on the back end!

Challenge accepted, which in retrospect was not the best idea when also running six other projects and working on a PhD, but it was pretty awesome. It just looked so cool and I really wanted to see how “Excel-like” we could make Eclipse ICE while keeping our cross-platform mandate (read: no cheating by hooking up COM in the Workbench).

I am going to walk you through this new capability and provide you with some links for more information. Let me take a step back first and give you a brief description of neutron reflectivity and why we care about it. Wikipedia can provide you more of the gory details, but essentially neutron reflectivity, (or sometimes neutron reflectometry), is the practice of bouncing neutrons off of thin films of materials and measuring how they scatter. The pattern that results tells you about the structure of the thin films. It is the materials science equivalent of subatomic bowling (although the bowling ball is actually a wave) and in practice requires massive facilities like ORNL’s Spallation Neutron Source.

ORNL's Spallation Neutron Source
ORNL’s Spallation Neutron Source

Such big facilities are required because the amount of neutrons required is a “the more the merrier” type thing: the more neutrons you have, the quicker you can get the reflectivity information you need. Neutrons are rather ideal for this work because they are electrically neutral and will not be deflected by electromagnetic properties of the thin films.

In addition to a worksheet to calculate the reflectivity, the spreadsheet also had a dedicated materials database, a stoichiometry calculator and other capabilities built into it. Our goal when doing the port was to make sure we brought all of these capabilities to the workbench, but to do it in a way that also took advantage of the workbench. Here’s what we had to do:

  • Port the reflectivity calculator from Visual Basic in Excel to Java.
  • Create a new materials database, built right into the Eclipse Platform, that is universally accessible.
  • Create a stoichiometry calculator.
  • Embed plots in Eclipse Forms, right next to the tables.

At the same time, there were several requirements of Eclipse ICE that we needed to maintain:

  • ICE must be cross-platform (so again, no COM)
  • New data structures, UI widgets and other pieces in ICE must be as reusable as possible.

I decided that the best way to merge both sets of requirements was to bring in some extra pieces of the Eclipse ecosystem to help out. The biggest challenge was actually figuring out how we could have a materials database that could accommodate one set of materials properties and instances of those materials used by the reflectivity calculator that had both the original properties and a secondary set of thin-film specific quantities. This means that the properties that show up in the materials database are a different set of properties, in whole or part, than those that show up in the reflectivity calculator. Under the hood this can be accommodated by a map that contains the union of both sets, but the big question was how to display different sets without explicitly marking the properties?

I turned to the GlazedLists library and Nattable to pull this off. GlazedLists provides several different types of lists against which listeners can be registered as well as Table Formatters that show different properties in different scenarios. Nattable can draw GlazedLists with a very small amount of code and additional layers can be added for sorting and searching. The combination of these libraries work so well that we have started reimplementing some of ICE’s older data structures to take advantage of the new code, which is smaller, generic, better tested and easier to maintain.

We extended ICE’s workbench to better support SWT-XY-Graph to get the embedded plots. Instead of putting the plots in a separate tab of the FormEditor, or even separate views, we used a SashForm and embedded them directly under the table. This is very “Excel-ish” when you’re using it and works great. If I could have my cake and eat it too, I would really like to figure out a way to make it possible to move the plots around with dynamic resizing instead of only being able to manipulate them within the SashForm.

The final piece of the puzzle was figuring out how we could make it possible to edit entries in the Reflectivity Calculator’s Layer Table programmatically. Imagine that you want to apply a formula to the thickness of the top layer of the materials such that its total thickness is X and the total thickness of all the layers is Y. This places a constraint that the thickness of all the layers under the top layer to to have a total thickness Z = Y – X. Alternatively you might say that a middle layer has a thickness equal to the average of the layer above it and the layer below it. These types of operations are easily done in Excel, but there is currently no way to click on the cells of a Nattable and apply formulas. In lieu of writing such a layer we decided to provide a scripting terminal with the Eclipse Advanced Scripting Environment (EASE) so that users could just write Javascript or Python to do whatever they wanted. This also makes it possible to do really cool things like generate and execute ensembles of calculations.

And… that’s about it. Everything works pretty amazing, considering the rather small amount of time that we spent on this. We have had an Eclipse Con Europe presentation accepted as an Early Bird Talk and ICE will be part of its first SNS User Tutorial in October. These make for very exciting times on the project and this new capability is so slick that I can’t help looking forward to what comes next!

You can check out our YouTube channel in the next few weeks for a video tutorial or our project page for more information. There is also a dedicated tutorial on our wiki. Of course, if you happen to be at EclipseCon Europe you can come by our talk too!

Leave a comment