Wednesday, June 29, 2016

GSoC Midterm Update for Avogadro2




        Recently, those of us in the Google Summer of Code 2016 had our midterm evaluations. Good news: I passed! This summer, I've been working on adding materials science features to Avogadro2, a project of Open Chemistry. A link to Avogadro2 can be found here:


         And a link to the full description of my project can be found here:


    Being a member of a materials science Ph. D. research group, I've used many of the crystallography features that were present in Avogadro1, and I'm aware of their importance. For the first part of this summer, I've been adding features that were present in Avogadro1, but are not yet present in Avogadro2. I've been able to add several features so far. Below is an image showing some of these new features as seen in the drop-down menu of the GUI:

Figure 1: New crystal features in Avogadro2. Left is before the summer began, and the right is current.

       For the examples in this article, I'm going to be using corundum, an aluminum oxide (Al4O6) compound that makes up several common gems including ruby and sapphire.

        "Import Crystal from Clipboard" is a feature that was present in Avogadro1. It is convenient to have for crystal files that are not usually identified with a file extension such as the VASP POSCAR file. It allows for an easy import of files like these. Below is an example:

Figure 2: "Import Crystal from Clipboard" Example

        In Avogadro1, the authors intended to eventually add "Import Crystal from Clipboard" support for other formats as well (such as GULP, pwscf, CASTEP). I was able to add support for all of these (and more) by adding the extra feature at the top line of the dialog box where the user can put in an extension. If the user chooses to do so, he can put in a file extension, and it will use Open Babel to try to read the file. If it succeeds, it will load the crystal. If not, it just prints an error message.

       A supercell builder is a commonly used feature in crystallography groups. Building a supercell can sometimes help with visualizing a crystal. In addition, supercells can needed for computations such as phonon calculations. Below is the primitive form of corundum:

Figure 3: Primitive Corundum (Al4O6)

      After building a supercell by doubling one of the vectors (a "2x1x1" supercell), you get this:

Figure 4: 2x1x1 Supercell of Primitive Corundum

       Another tool that I've added to Avogadro2 is spglib ("spacegroup library"). Spglib is a very useful library developed by Atsushi Togo. It was used in Avogadro1, and it has been used in several other programs as well. Spglib can be found on the web here:


        Since it is written in C and published under a 3-clause BSD license, we are able compile and link to spglib within Avogadro2. Spglib allows for many symmetry-related features involving crystals. One of the most common features is to simply identify ("perceive") the space group of a crystal. Corundum, for example, has an R-3c space group (number 167), and we can now run the spglib algorithms in Avogadro2 in order to discover this. An example is shown below:

Figure 5: Example of "Perceive Space Group" for Corundum

      As we would expect, spglib has to receive a tolerance to use its features. The user is able to set that with the "Set Tolerance" menu item that is found near "Perceive Space Group". The default is 1e-5 Angstroms. In "noisy" crystals, this tolerance can become very important - an increase or decrease in tolerance can affect which space group is identified, and it can have an effect on other spglib operations as well. 

     A couple of other functions that have been added from spglib are "Reduce to Primitive" and "Conventionalize Cell." A primitive reduction takes the crystal and reduces it to its most primitive form. Simple enough, right? A primitive cell can be thought of as a representation of the cell that has the fewest number of atoms in it. A more official definition of a primitive cell is "A unit cell that contains only one lattice point."

      A supercell is larger and has more atoms in it than needed for a full representation because it has been fully duplicated along at least one of the vectors. Therefore, it also has more than one lattice point. So, performing a primitive reduction of a supercell should bring it back down to its primitive form, right? Indeed. If a primitive reduction is performed on the crystal in Figure 4, it will reduce back to the crystal in Figure 3.

        A cell conventionalization is a little bit different. This feature can go by many different names. "Refine cell" is how spglib puts it because atom positions are "idealized" (meaning, they are moved around a tad bit so that they are in their ideal locations for that space group). "Symmetrize cell" is another way to put it for those same reasons. I used the term "conventionalize" to emphasize the fact that our result is going to be a cell in its conventional form. A conventional cell may not always be the same as a primitive cell. This is true for our corundum case. Below is an image of a conventional cell of corundum:

Figure 6: Conventional Corundum (Al12O18)

Notice that there are 3x as many atoms in conventional corundum than there are in primitive corundum! Space group R-3c (number 167) is a member of the trigonal crystal system. Trigonal crystal systems may be represented with rhombohedral or hexagonal axes. In our case, conventionalizing the cell results in a crystal with hexagonal axes. Crystal lattices with hexagonal axes have a = c, α = β = 90°, and γ = 120°. After conventionalizing corundum, that is what we get: a = b = 4.761 Å, c = 12.994 Å, α = β = 90°, and γ = 120°. This results in the cell becoming larger than it was in its primitive form. It also results in the atoms being placed in their "conventional" Wyckoff positions for that space group.

      Since primitive reductions and cell conventionalizations are highly dependent on the identified space group, the tolerance can play a big factor in their results. Because of this, I set up the program to pop up the following dialog box every time a primitive reduction or cell conventionalization is about to be performed:

Figure 7: Confirm Tolerance
Of course, if the user says no, they are able to change the tolerance before proceeding. This helps to ensure that they know what tolerance they are using before performing those actions.

      That's it! Those features are what I've been able to accomplish so far with my project for Avogadro2. I recently started working on adding undo/redo capabilities to the crystal features. Other additions that will come in the future include: filling a unit cell that has a specific space group, reducing a cell to its asymmetric form (the opposite of filling a unit cell), and more!

Thanks for reading! Hope you enjoyed it.
Patrick Avery