m3gnet icon indicating copy to clipboard operation
m3gnet copied to clipboard

could u provide a simple code example how to call the pretrained model to prediction formation energy?

Open usccolumbia opened this issue 2 years ago • 3 comments

and other properties?

usccolumbia avatar Sep 13 '22 01:09 usccolumbia

The notebooks here show how to relax a strucutre. The notebooks in the megnet repo (see https://github.com/materialsvirtuallab/megnet) provide an example code of how to predict formation energies and other properties. You simply need to relax the structure with m3gnet and then use the models from MEGNet to predict the properties.

shyuep avatar Sep 13 '22 02:09 shyuep

Thanks for the quick update with the hint. i tried this: from m3gnet.utils.models import load_model, AVAILABLE_MODELS gives error:

Traceback (most recent call last): File "", line 1, in ModuleNotFoundError: No module named 'm3gnet.utils.models'

I still recommend providing a jupyter notebook here with an example code of how to predict formation energies and other properties using this m3gnet models to make this package self-contained -:).

usccolumbia avatar Sep 13 '22 03:09 usccolumbia

@usccolumbia For those m3gnet property models, as described in the pretrained folder (https://github.com/materialsvirtuallab/m3gnet/blob/main/pretrained/matbench_properties.md), you need to first download them from figshare. Then loading and using them can be done with the below three lines of code:

from m3gnet.models import M3GNet
m3gnet_e_form = M3GNet.from_dir(e_form_folder)
e_form_predict = m3gnet_e_form.predict_structure(a_structure)

The a_structure should be a pymatgen structure. If you haven't worked with it, you can follow this example to get a pymatgen structure of LiFePO4: notebook

The e_form_folder is the path to the folder containing parameter files of the m3gnet property model. For example, I downloaded the pretained models into ./m3gnet_models folder, which is at same folder with my working jupyter notebook running the above three lines of codes. Then, the e_form_folder can be m3gnet_models/matbench_mp_e_form/0/m3gnet/.

You should be able to load and use those property models with the above.

JiQi535 avatar Sep 13 '22 17:09 JiQi535