Generating a supercell from a material's structure data

Hello,

My name is Kenjiro, I’m a senior undergrad Chemistry student from the University of Puerto Rico. I’m currently working on an implementation of machine learning to a materials science project related to batteries (I’m not an expert in computer science but I know Python). I’ve coded a program that can calculate some abstract characteristics of the materials mostly based on the distances between particular atoms. The reason I’m asking here is that I need a 3x3x3 supercell to be able to calculate one of the characteristics, but I’m not sure how to obtain that from the Materials Project Database; I only get unit cell information.

I can create a program that obtains unit cell information and duplicates the cell in all dimensions, generating a kind of supercell, but that would cost a lot of time and resources with the idea I came up with (since I don’t know any other). Right now I’m only working with a few materials and I can do this manually for all of them, but if I want to implement this to say, for example, all Lithium containing materials, it would be physically impossible for me to do it. So I want to automate this, but I need a better way to generate or obtain supercell information. Is there a pymatgen tool, or really anything else I can use that can generate these supercells for me? I have seen some tools like VESTA, but I have to download the CIF file first, open it, and manually convert them to supercells, so this isn’t practical. It would be better to use the MAPI or something on the server side.

Thank you!

Kenjiro, you can do this with Pymatgen, which is one of the Python libraries that undergirds the Materials Project. Below is an example of how to use pymatgen to retrieve a structure (Si in the example) from Materials Project and create a supercell.

from pymatgen.ext.matproj import MPRester

with MPRester() as mp:
    structure = mp.get_structure_by_material_id('mp-149')

structure.make_supercell((3,3,3))

If you have a CIF file already, and would like to use that instead of the MPRester you can do:

from pymatgen.core.structure import Structure

structure = Structure.from_file('my_cif_file.cif') 
structure.make_supercell(3)
2 Likes

Thank you very much!

My way of setting up MPRester is a bit different but I think it should work the same. I tried the code you provided and printed the result but it returns none.

My code is:

from pymatgen.ext.matproj import MPRester

m = MPRester(“API_KEY”)
structure = m.get_structure_by_material_id(‘mp-149’)
print(structure.make_supercell((3,3,3)))


I restarted the kernel, pasted your code exactly, typed my API Key, and it returned the same thing.
I did:

from pymatgen.ext.matproj import MPRester

with MPRester(“API_Key”) as mp:
structure = mp.get_structure_by_material_id(‘mp-149’)

print(structure.make_supercell((3,3,3)))


I tried to print it to know how I’m receiving the information. I also wanted to know what type of data it was and it says <class ‘NoneType’>. I think I’m doing something wrong but I’m not sure what. Thanks in advance!

make_supercell works inline. That means it mutates the structure you run it on:

structure = mp.get_structure_by_material_id(‘mp-149’)
structure.make_supercell((3,3,3))
print(structure)
1 Like

Oh, that makes sense. It works! Thank you!

Thank you both!