I am looking for a C or a C++ library that can do crystal generation, that is, multiply unit cells in one or more directions with symmetry information. (in other words, generate supercells). I have been using OpenBabel (also C++) but it doesn't have this function (it is more oriented to molecules).

If the library can read or write CIF or other similar formats that would be even better.

Can you recommend one?

I know that libraries like this exist in Python, e.g. ASE, but I need to generate them on the fly (e.g from CIF files.)

I am not looking in particular to generate random periodic structures, but it is fine as long as the simpler case I mention above can be performed as well.

  • 2
    $\begingroup$ Try SYMLIB and see if that works. $\endgroup$
    – PBH
    Oct 15, 2021 at 5:33
  • $\begingroup$ +1! What a great first question, already 10 upvotes and 3 bookmarks. Thank you for contributing your question here and we hope to see much more of you in the future !!! $\endgroup$ Oct 16, 2021 at 4:43
  • $\begingroup$ @NikeDattani, I think there is a great need for a library like this. Anecdotally, I couldn't find one yet. I think my best option will be to contribute this functionality to OpenBabel, although that code base is quite messy/outdated. $\endgroup$
    – alfC
    Oct 16, 2021 at 4:50
  • 1
    $\begingroup$ @alfC - I won't take offense, but understand that a general-purpose C++ library often can't use the latest standards. As to "messy.." well, contributions are always welcome for even minor cleanups. $\endgroup$ Nov 30, 2021 at 1:18
  • 1
    $\begingroup$ If you’ve found a memory leak, you definitely need to let us know. Your other comment makes it clear you should just be asking on the mailing list - I’d need a clearer example to know what you mean. Generally the OBMol tracks everything, but that’s a better discussion for the list. $\endgroup$ Dec 1, 2021 at 11:57

1 Answer 1


Please feel free to contribute to Open Babel. I'm sure people would use it! Probably the easiest C++ code to adapt would be from Avogadro 1, which directly used the Open Babel API.

For example the "supercell extension"

      // For each atom, we loop through:
      // * convert the coords back to inverse space
      // * apply the transformations
      // * create new atoms
      // * check for atoms in the same spot due to symmetry

There are methods to put all the atoms into the unit cell (not strictly required), and duplicate the unit cell -- which is just a big triple loop over a, b, and c repeats.

If you want more specific pointers, ping me on the Open Babel GitHub or mailing list.

  • $\begingroup$ Yes, this is the way to go. The problem is that this procedure doesn't use existing symmetry information contained in Molecule data structure. Also what is not clear is what do with the symmetry information after applying this multiplication of the cell. Initially I though that the library will handle that but I think I was mistaken. $\endgroup$
    – alfC
    Dec 1, 2021 at 10:22
  • 2
    $\begingroup$ Sure it does. The first thing it does is put all the atoms in the unit cell (fillUC) and ensure it has all the symmetric copies. As to “what does it do afterwards,” if you want to check for remaining symmetry, you’ll need to use spglib. There’s no guarantee of remaining symmetry. $\endgroup$ Dec 1, 2021 at 11:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .