Open science with figshare and object orientated-programming

Update: I’m pleased to say that I was awarded Imperial’s Bradley-Mason Prize for Open Chemistry — see Professor Rzepa’s blog post for more info.

From 1st May 2015, the EPSRC requires that all publications include a statement saying how the underlying research data can be accessed. Technically, you can simply include an email address to contact for the data, but I think that’s hardly in the spirit of open science. In this post, I want to describe how I used object-orientated programming (OOP) and figshare to meet this requirement for my latest paper in Lab on a Chip. You can download the data and MATLAB code to reproduce the graphs at figshare.

Graphical abstract for Microscale extraction and phase separation using a porous capillary.
Graphical abstract for my paper.

In OOP, you create classes that define objects and their properties. For example, if you had a class Animal, instances of this class could be cat and dog. For the Animal class the properties might be legs (an integer) or dateofbirth (a date). The class also defines methods, which are functions that operate on instances of a class. For example, Animal.age() might use the dateofbirth property to return the age of the animal.

For my paper I defined a class called sepexp (short for separation experiment, the subject of the paper) with properties corresponding to the independent and dependent variables. My class definition also included a method runall to run the experiments (which were, thankfully, automated—one of the joys of flow chemistry) and plot[^overloading] to plot the data.

To start an experiment, I would create an instance of my sepexp class. For example, let’s call it exp1, and during its creation I specify the independent variables. Executing exp1.runall() runs all the experiments defined by my properties. The details aren’t relevant here—see the paper if you’re interested—but the key thing is that it saves the results in the properties mass_initial and mass_final.

Now I’ve got an object that defines the experiment and contains the results I can save it, e.g. using save in MATLAB or pickle in Python.[^binary]

The next step is to plot it, so I execute exp1.plot(), which does a straightforward calculation on the data collected to get the volumetric collection rate at the outlet and plots it. I then repeated this for each experiment.

What does this approach give you? You end up with a class definition and series of objects that contain the parameters of each experiment, how it was carried out, the results, and a means to reproduce the analyses. You can zip this up, upload it to figshare, and you’ve got a publicly accessible link to your data with a DOI.

An OOP approach saves time when analysing data, because you define how the data is analysed once in class definition, and apply it repeatedly to every object/experiment. It’s easy to iterate through all your objects (see the scripts in the /plotting_scripts folder). Distributing the class definition ands the objects together means others can reproduce your analysis. I think that’s pretty cool. If you’ve got MATLAB, download my archive and give it a go.

Or even better, try it out with your next project. There are lots of resources for learning OOP in your language of choice online. The MATLAB OOP documentation is good (although I think MATLAB’s OOP syntax is horrible). I personally like books and learnt about OOP for the first time in the excellent book Learning Python by Mark Lutz.

[^overloading]: This is an example of operator overloading.

[^binary]: The main disadvantage of these methods are that they save the data as binary objects. There are also security issues around opening pickle objects from untrusted sources. Therefore I recommend that when you come to publishing your data you also export it as ASCII, which is straightforward. See the export_mat2csv.m script in the figshare archive.

Light- and power-making things

Inspired by xkcd’s Up Goer Five comic Theo Sanderson created the Up Goer Five Text Editor. It challenges you to explain a hard idea using only the thousand ten hundred most commonly used words in the English language. Lots of scientists on Twitter have been using it to try and describe their work. It’s a lot harder than it sounds! Here’s my attempt:

Many years ago a few people were doing some work and, to their surprise, they managed to make light come out of something that had never had light come out of it before. People were very excited about it and now lots of groups of people spend their time trying to answer questions like “how does it work?” and “how can we make it work better?”. Everyone was interested because they thought it could be used to make new things like better TVs, very small computers and different kinds of lighting. But the perhaps the most important thing it could maybe do was give us all a new way to turn light from the sun into power for not very much money.

At the moment only a few people get to see them because they are hard to make. They are hard to make for lots of reasons, but perhaps the biggest reason is that the parts you need are themselves hard to make. Everyone struggles to make enough of them exactly as they need them to be. If the parts aren’t good enough, sometimes not very much light comes out, or for only a little while, or the ones that turn light from the sun into power don’t do it very well. No one wants any of those.

It doesn’t help that the normal ways of making the parts are often only good enough for making a little at a time. If you try to make more in the same way it stops working so well. I’m part of a group of people trying to make the parts in a new way that can make lots and lots and it still be good enough. In fact, our stuff is usually better than the best stuff you can buy.

I try lots of different ways to make things. I look in books to read how other people did things to get new ideas that no one else has had before. Sometimes they don’t work, but sometimes they do and when that happens it makes me very excited and happy. Sometimes we tell everyone but sometimes we only tell a few people. We can use my new way to make the light-making and power-making things work better and for less money than ever before so everyone can have them.

What do you think?

MSci Project Part 1: Quantum Dots

I don’t start my PhD until October so I won’t be posting much about it for a couple of months. In the mean time, I thought it would be nice to talk about what I did for my final year research project as part of my MSci degree.

The aim was to synthesis quantum dots[^1] using microfluidic reactors. It sounds complicated, but really it’s quite straight forward! An explanation of it all in one post would be rather long so I’m going to break it down into two posts, starting with quantum dots and then moving on to microfluidic reactors.

What are Quantum Dots?

Quantum dots are nanoparticles—particles only a few billionths of a metre in size—made from semiconductors. Semiconductors are materials whose electrical conductivity is midway between that of insulators and conductors. They are the foundation of modern electronics and without them we wouldn’t have components like transistors and diodes which are essential building blocks of the technology we use every day.

All materials have particular physical properties—such as the melting point or density—that are independent of how much of the material you have. For example, if you measured the melting point of a material, cut it in half, then remeasured the melting point, the melting point would not change. Properties like these are called intensive properties.

Imagine you had a piece of semiconductor and repeatedly measured an intensive property, such as melting point, then cut it in half. You would expect intensive properties to stay the same, regardless of the amount of material. However, if you carried on doing this for quite some time—so that your semiconductor was just a few billionths of a metre across—you would find that its properties would start to change: properties which were intensive become extensive and dependent on how much of the material you have. Chemists take can advantage of this phenomenon to tune the properties of semiconductors for particular applications by controlling the particle size.[^2]

Making Quantum Dots

Rather than breaking down macro- or microscopic bits of semiconductor to make nanoparticles (“top-down”), chemists usually make quantum dots from individual atoms (“bottom-up”). This is most commonly achieved by injecting the appropriate reagents into a hot solvent. The quantum dots spontaneously form in the hot solvent and are left to grow to the desired size.

The photo below is of some cadmium selenide quantum dots that I made last year. I think it’s a wonderful example of their size-dependent properties.

CdSe Quantum Dots
CdSe quantum dots fluorescing under UV light.

Each vial contains quantum dots that were removed from the reaction vessel at regular intervals. The vial on the far left hand side contains quantum dots grown for 30 seconds and the vial on the far right hand side contains quantum dots grown for 3 hours. The mean size of the particles grown for 30 seconds and 3 hours was 2.8 nm and 4.2 nm respectively, so the nanoparticle size increases from left to right.[^3]

The colour arises from a process called fluorescence. The vials are sat on top of an ultraviolet lamp which causes the quantum dots to fluoresce and emit light, the wavelength of which is dependent on the size of the quantum dots.

These unique optical properties make quantum dots very attractive for use in solar cells, displays and even in medical imaging. The trouble is that high-quality quantum dots are quite tricky to make, especially on an industrial scale. In part 2, I’ll talk a bit more about the applications of quantum dots, what microfluidics is and why it’s great for making quantum dots. If anyone has any questions, please don’t hesitate to ask!

[^1]: For the chemists/physicists: I was working on core-shell and ternary quantum dots rather than regular binary quantum dots.

[^2]: This behaviour isn’t unique to semiconductors—it’s just that the change occurs at a much larger particle size for semiconductors than for metals because of differences in the arrangement of electron energy levels in metals and semiconductors. See this very frequently cited paper in Science if you want the details.

[^3]: Analysis was performed using a technique called transmission electron microscopy, if you were wondering. It’s very cool.