Wednesday, August 17, 2016

GSoC Summary



GSoC is coming to a close! It has been a productive summer working with Avogadro2. I was able to complete all of my primary goals and contribute in a few extra areas as well. 

Work Accomplished
Here is a list of the major contributions that I was able to make towards the project:
  • Added POSCAR (from Vienna Ab Initio Simulation Package) format reader and writer. This is used by a lot of computational materials science groups.
  • Added an "Import Crystal from Clipboard" feature. This was present in Avogadro 1 and allows the user to copy a crystal file to their clipboard and import it from there. It is particularly useful for POSCAR format due to the way files are named.
  • Added a supercell builder. This is helpful for visualization and situations that require a supercell.
  • Added spglib to Avogadro2. Spglib is a library written in C that allows for many useful crystal operations related to symmetry and space groups.
  • Added space group perception using spglib.
  • Added functions using spglib that allow users to primitive reduce a crystal, conventionalize a crystal, and symmetrize a crystal.
  • Added functions to fill a unit cell by using symmetry operations for a space group, and added functions to reduce a unit cell to its asymmetric unit.
All of these features are accessible by the user interface so that users may access them as well. In addition, tests were made for the majority of these features to demonstrate that they work.

Here is a list of minor contributions (that were not in my primary goals) that I was able to make towards the project:
  • Added undo/redo operations for already existing crystal features and newly added crystal features.
  • Added undo/redo text in the user interface to clarify the operation that would be performed.
  • Improved the cmake files so that VTK can be more easily turned on or off.

Here is a list of some bug fixes that were made:
  • Fixed a few bugs in crystal functions (one involving transforming atoms and one involving setting the cell parameters).
  • Improved cmake files so that some options were set at the right time.
  • Fixed GUI bug where the center and radius of a scene were not being updated properly (this resulted in clipping).
  • Fixed a few small memory leaks in an assignment operator.
  • Fixed some bugs in the atomic coordinate editor (and improved it so that the user experience is smoother).

Descriptions and further discussion of the major contributions can be found at the following two links:

Contributions before midterm (June 27):

Contributions after midterm (June 27):

A more detailed look at the code changes that were made can be viewed from the following links. The commits that were a part of the GSoC work are from about May 10, 2016 to August 23, 2016. Links are ordered by decreasing number of commits:


In addition, for Avogadro 1, I was able to assist in creating the new Windows executable for the new release: Avogadro 1.2.

Work Still in Progress
Although I finished my primary goals for Avogadro 2, I started some extra work that I will continue working on after GSoC ends. Probably the most significant is adding YAeHMOP (Yet Another extended Hückel Molecular Orbital Package). This can allow Avogadro to perform quick semi-empirical quantum mechanical calculations using Extended Hückel Theory. I mentioned this in more detail on my blog post containing my contributions after the midterm, but this feature could potentially add many different types of quick semi-empirical quantum mechanical calculations that could be useful when analyzing a molecule or crystal. I've been adding it to Avogadro 1 first, and then I'll be adding it to Avogadro 2 next. My work so far with preparing YAeHMOP for Avogadro can be found here:

https://github.com/greglandrum/yaehmop/commits?author=psavery

I've also been working on improving the undo/redo operations while drawing to make it more user-friendly, and I've been adding more undo/redo operations to different features.


In conclusion, my work this Summer seems to have been fairly successful! I'm glad that Avogadro2 has these new additions, and I hope it does well in the future!

Thanks for reading!
Patrick Avery

Finalizing GSoC


Google Summer of Code 2016 is coming to a close! Fortunately, I've been able to accomplish my primary goals for Avogadro2 and a little more. My blog post after the midterm evaluations was here:

http://avogadro2crystals.blogspot.com/2016/06/recently-those-of-us-in-google-summer.html

I've mostly been adding operations related to crystal space groups for the molecular editor. I'll be discussing a few of the new ones that I have added here.

First of all, I've added two features called "fill unit cell" and "reduce to asymmetric unit." These two features can be thought of as opposites of one another. This will be explained more as we go along.

For an example, let's take post-perovskite (MgSiO3). This material is reportedly common in the mantle of the earth. It is stable under the pressures there, and it has important properties as far as geophysics is concerned. It's space group is Cmcm (number 63). This means the Bravais lattice is of type C, and it has two mirror planes (the m's) and a glide plane (the c). Don't worry about those details too much, though, if you aren't familiar with them...

It's common for papers in journals and databases to give a crystal's information as its asymmetric unit. For post-perovskite, that may look something like this (data from here http://crystallography.net/cod/9009217.html):

a,        b,         c,          alpha, beta, gamma
2.456,  8.042,  6.093,  90,     90,    90

Fractional Coordinates
Mg 0.0  0.25    0.25
Si   0.0  0.0      0.0
O   0.0  0.923  0.25
O   0.0  0.631  0.436

In Avogadro2, this looks like the following:

Figure 1: Asymmetric Unit of Post-Perovskite (MgSiO3)
Magnesium is green, silicon is grey, and oxygen is red.

The cell looks rather empty, doesn't it? That's because only the necessary atoms are included. You find the other atoms by applying symmetry operations for the space group to the existing atoms. This is done with the "Fill Unit Cell" feature. In Avogadro2, you now just need to select it from the dropdown menu as shown in Figure 2:

Figure 2: Fill Unit Cell in Dropdown Menu

Once "Fill Unit Cell" is selected from the dropdown menu, it will ask the user to select a space group. This is necessary because the space group cannot be determined from an asymmetric unit since it does not yet have the correct symmetry. The Select Space Group dialog is a scroll-able table containing all of the space groups - it looks like the following:

Figure 3: Select Space Group Dialog


Once a space group has been chosen, the fill unit cell feature will apply the symmetry operations to every atom in the crystal. The result for post-perovskite is the following:

Figure 4:  Post-Perovskite with a Filled Unit Cell

That is what the filled conventional crystal of post-perovskite actually looks like. Notice that the numbers of atoms for magnesium and silicon went from 1 to 4, but the number of oxygen atoms went from 2 to 12. This is because an atom that lies on a symmetry site may be duplicated a different number of times than an atom on another symmetry site.

So "Fill Unit Cell" is a very useful feature! But what if we want to go the other way? As in, we start out with a filled unit cell, and we want to reduce it to its asymmetric unit to reduce the amount of data? Well, that is done with the "Reduce to Asymmetric Unit" feature. Starting with our filled cell, you can select the "Reduce to Asymmetric Unit" feature via the following dropdown menu:

Figure 5: Reduce to Asymmetric Unit Dropdown Menu

Like "Fill Unit Cell," "Reduce to Asymmetric Unit" needs to know the space group in order to perform its actions. Because the unit cell is probably filled, the program uses space group detection from the other functions I added (see the first blog post linked at the top) to try to determine the space group. In our case, it detects that the space group is Cmcm (number 63) as shown below:

Figure 6: Reduce to Asymmetric Unit Dialog

The user can decide whether or not to proceed with the perceived space group. If the user selects "yes," then the algorithm will proceed. If the user selects "no," then the Select Space Group dialog (Figure 3) appears and allows the user to select a different space group. In our case, when we use the space group 63 (Cmcm), the filled unit cell gets reduced, and it ends up looking just like the crystal Figure 1. "Reduce to Asymmetric Unit" basically works by looking at the results of the symmetry operations when applied to an atom. If there are atoms at the positions that result from the symmetry operations, they get removed. So "Reduce to Asymmetric Unit" does indeed do the opposite of "Fill Unit Cell."

Another recent feature that I added was a "Symmetrize" feature. This uses the space group library, and it is similar to the "Conventionalize Cell" and "Reduce to Primitive" features I added (see my first blog post linked at the top). It can be found in the dropdown menu as shown below:

Figure 7: Symmetrize Dropdown Menu

It's probably best to think of "Symmetrize" as a combination of "Conventionalize Cell" followed by "Reduce to Primitive," although it does it in one operation to save time and memory. "Conventionalize Cell" idealizes the atom positions to match those of the space group, and it changes the unit cell to be in its conventional form (as defined by its Bravais lattice). "Reduce to Primitive" does not do either of these things, but it reduces the crystal to the smallest form in which it can be represented. So "Symmetrize" idealizes atom positions and reduces the crystal to its smallest form. The result of symmetrizing the filled unit cell of post-perovskite is the following: 

Figure 8: Symmetrized Post-Perovskite

Notice that the number of atoms has been reduced, and the unit cell is a lot smaller. So this is similar to a "Reduce to Primitive" feature in that way. The difference, however, is that the positions of the atoms have also been idealized so that they should be in nearly perfect positions for the space group.

As I mentioned at the top of the blog, I've been able to do work on some additional things with Avogadro2 as well. One of them involves undo and redo commands. Before the summer, none of the crystal features in Avogadro were "undo-able" (and consequently, none of them were "redo-able" either). This is an important feature: if you were to make a mistake by performing a crystal feature, you'd have to start over in your editing. In addition, undo and redo features make it easier to review what you have done thus far. Thus, I added in the necessary commands and functions so that "undo" and "redo" operations can be performed on the old crystal features (as well as the new ones). I also changed the program so that it displays text now for the undo and redo commands. They look like so:

Figure 9: Undo and Redo Operations

This is certainly a plus as it makes editing easier.

I've fixed a few other bugs as well including ones in the atomic coordinates editor. These fixed bugs help keep the user experience smooth.

Some final things that I am currently working on but have not yet been added are features involving YAeHMOP (Yet Another extended Hückel Molecular Orbital Package). Extended Hückel Theory has proven to be a fast and successful semi-empirical method for quantum calculations. It was developed by Roald Hoffmann, and its applications were part of the reason he won the Nobel Prize in 1981. YAeHMOP was created by a student, Greg Landrum, who worked in Roald's research group. In order to improve on the versatility of Avogadro, we decided to add YAeHMOP to Avogadro1 and Avogadro2. Its inclusion opens the door to many possibilities, including molecular orbital calculations, band structure calculations (for solids), total and partial density of states calculations (for solids as well), and more.

I've worked mostly on band structure calculations so far in Avogadro1. After the user has created a crystal (or imported one from somewhere else), they can select "Calculate Band Structure" from the dropdown menu. I am using diamond as an example. "Calculate Band Structure" is located here in my branch of Avogadro1:

Figure 10: Yaehmop Calculate Band Structure Dropdown Menu in Avogadro 1

Once that is selected, the following dialog appears:

Figure 11: Yaehmop Band Structure Dialog in Avogadro 1
In this dialog, the user is able to select the number of k points connecting special k points. K points are three dimensional coordinates in reciprocal space. They are locations that are "sampled" during quantum calculations for crystals. The higher the number of k points connecting special k points, the smoother the curves will be, but the calculation will take longer since it must sample at more k point values. The special k points are typically high symmetry points in reciprocal space for a space group. In our case, diamond is of space group 227 (Fd3m), so a few high symmetry points in reciprocal space are Gamma (0,0,0), X (1/2,0,1/2), and L (1/2,1/2,1/2). The lines will begin at the first special k point that is given and traverse through each special k point after it until it reaches the final special k point. So, our order is L, G, X (since that is what was input in Figure 11). When you hit "Ok", Yaehmop calculates the band structure using the information you gave it. Since it is a semi-empirical calculation, it takes less than a second on most computers for it to finish, and the following graph is plotted:

Figure 12: Yaehmop Band Structure for Diamond in Avogadro1

This plot is the band structure of diamond as obtained from YAeHMOP.

The YAeHMOP features are currently being worked on (so they are not yet released to the public). There are still some details and bugs to sort out. In addition, some other features are going to be added as well (like total and partial density of state and molecular orbitals calculations). However, they should be in usable sometime in the near future!

It's exciting to see where Avogadro2 is heading with these new features!

Thanks for reading! Hope you enjoyed it!
Patrick Avery

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