Search Blogs

Thursday, March 7, 2024

A Multiphase Polycrystalline Utility

During graduate school, I had to write several utility scripts to prepare the structures used for simulations. One such script [1] generated polycrystalline samples of SiC using Voronoi tessellation. The script worked, but was brute-force and slow.

Fortunately, after my time in this space, several other fast and feature-full codes/packages continued to grow. Two of them in particular: atomsk and ASE [2-3]. I've recently been writing about ASE in several post; it's a great tool! So is atomsk.

A Refresh

About two year's ago I worked on a script that leveraged these two packages to generate polycrystalline samples in a similar fashion that I had done. I forgot about it and recently stumbled back on it. I decided to refresh it a bit and use Linux AppImage to make it portable for others (just download the AppImage and run in command line, no setup 🤞).

The Bash Script

The refreshed script, called PolyCrysGen.sh, is a bash script and basically contains the workflow to connect atomsk and ASE to generate multiphase polycrystalline LAMMPS data files. Of course one could do this manually using these tools, but the value added by this script is that the logic is in place to make the use syntax very friendly and convenient. All one has to do is type:

chmod +x ./PolyCrysGen.sh ./PolyCrysGen.sh --size "150 150 150" --phases "Fe:6 Mg:2 Cr:2 "

And this will generate a polycrystalline simulation cell with 6 Iron, 2 Magnesium, and 2 Chromium grains using the ground-state crystal structure. It looks like the following LAMMPS data file:

Multiphase Fe-Mg-Cr polycrystal LAMMPS data configuration

The particular logic that is included is to handle the template for the multi-phase polycrystal. This requires randomly generating the node locations for the grains, assigning the grains to each phase (i.e., element/compounds), and then removing and combining grains based on the assignment using the -select prop, -rmatom, and --merge flags in atomsk.

One thing I really appreciate is how fast2 atomsk is at doing this. You can easily do 10's of grains and have millions of atoms in your simulation cell.

Improving portability 🤞

On thing with workflows that leverage pre-built or configured tools is that not every computer (linux specifically) will be the same. Environmental paths and variables could be totally different. Additionally the tools might not be installed/available or the user isn't entirely sure how to compile and configure. For this specific instance both atomsk and ASE are easy to setup, however, I want to try and make this bash script a bit more portable and decided to investigate the use of containers, specifically the AppImage setup.

For the most part I think I was successful, and now anyone with a linux system should be able to download the latest release AppImage, change the permissions to run, and then utilize the scrip without having to setup atomsk or ASE. The only caveat seems to be that the Filesystem in Userspace has to be installed1, 😢.

Remarks

I haven't exhaustively tested every case, for example, with four phases it seems the alphabetic ordering matters, in that should be from a to z. I'm not sure though, as the logic I have seems to be 👌.

The other features I need to eventually add is the ability to place the grain center/nodes in predefined superlattice, like placing the grains in FCC patter with the phases alternating in a desired fashion. I also need to add the ability to generate amorphous grains. This may require actually using some kind of Monte carlo algorithm where I just specify min and max distances between pairs of atoms. In other words, I won't try to minimize the distance based on minimizing the interaction energy.

Feel free to test the utility out and open up an issue or pull request if you see bugs or add new features to the script.

Footnotes


  1. This is kind-of annoying in my opinion. Someone needs to find a way to make it so you can bundle a linux environment, package it, and then deploy for execution on any x86-64 Linux box. Probably exist, but I don't know about it and it would need to be as easy as the AppImage approach. 

  2. I believe this is because it is using OpenMP to speed things up but I'm not entirely sure. If you want you can try to test by setting OMP_NUM_THREADS=1 and then OMP_NUM_THREADS=4 and see what happens. 

References

[1] S. Bringuier, NaivePolyCrys, (2020). https://doi.org/10.5281/ZENODO.3925791.

[2] P. Hirel, Atomsk: A tool for manipulating and converting atomic data files, Computer Physics Communications 197 (2015) 212–219. https://doi.org/10.1016/j.cpc.2015.07.012.

[3] A. Hjorth Larsen, et al., The atomic simulation environment—a Python library for working with atoms, J. Phys.: Condens. Matter 29 (2017) 273002. https://doi.org/10.1088/1361-648X/aa680e.


Reuse and Attribution

No comments:

Post a Comment

Please refrain from using ad hominem attacks, profanity, slander, or any similar sentiment in your comments. Let's keep the discussion respectful and constructive.