materialsvirtuallab / m3gnet

Materials graph network with 3-body interactions featuring a DFT surrogate crystal relaxer and a state-of-the-art property predictor.
BSD 3-Clause "New" or "Revised" License
231 stars 59 forks source link

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

Open usccolumbia opened 2 years ago

usccolumbia commented 2 years ago

and other properties?

shyuep commented 2 years ago

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.

usccolumbia commented 2 years ago

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 -:).

JiQi535 commented 2 years ago

@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.