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
238 stars 61 forks source link

segmentation issue with energy calculation for some structures #40

Closed usccolumbia closed 2 years ago

usccolumbia commented 2 years ago

I used the code to predict the energy for the following cif structure and got a deadly segmentation error. it seems it is caused by there is no bond in the structure. Is anyway for your code to detect this and raise an exception instead of segmentation error?
this seems to be a limitation for the model. I cannot avoid this even using try-except. It crashes my code. the code works with other regular structures with bonds.

generated using pymatgen

data_CaS _symmetry_space_group_name_H-M 'P 1' _cell_length_a 5.77562248 _cell_length_b 5.77562248 _cell_length_c 11.50881363 _cell_angle_alpha 90.00000000 _cell_angle_beta 90.00000000 _cell_angle_gamma 90.00000000 _symmetry_Int_Tables_number 1 _chemical_formula_structural CaS _chemical_formula_sum 'Ca4 S4' _cell_volume 383.90887645 _cell_formula_unitsZ 4 loop _symmetry_equiv_pos_site_id _symmetry_equiv_pos_asxyz 1 'x, y, z' loop _atom_site_type_symbol _atom_site_label _atom_site_symmetry_multiplicity _atom_site_fract_x _atom_site_fract_y _atom_site_fract_z _atom_site_occupancy Ca Ca0 1 0.00000000 0.50000000 0.25000000 1 Ca Ca1 1 0.50000000 0.00000000 0.25000000 1 Ca Ca2 1 0.50000000 1.00000000 0.75000000 1 Ca Ca3 1 1.00000000 0.50000000 0.75000000 1 S S4 1 0.00000000 0.00000000 0.00000000 1 S S5 1 0.50000000 0.50000000 0.50000000 1 S S6 1 0.00000000 0.00000000 0.50000000 1 S S7 1 0.50000000 0.50000000 1.00000000 1

here is my code: parser = CifParser('74.cif') struct = parser.get_structures()[0] e_form_folder = 'm3gnet_models/MP-2021.2.8-EFS' m3gnet_e_form = M3GNet.from_dir(e_form_folder) e_form_predict = m3gnet_e_form.predict_structure(struct) eform=e_form_predict.numpy()[0][0] print('formation energy:',eform)

shyuep commented 2 years ago

I can't actually reproduce this error.

from pymatgen.core import Structure
s = Structure.from_file("74.cif")
from m3gnet.models import M3GNet
model = M3GNet.load()
model.predict_structure(s)
model.predict_structure(s)[0][0]

gives me

 <tf.Tensor: shape=(), dtype=float32, numpy=-20.25159>

which seems correct to me. Pls try and confirm if it is an issue with your installation and make sure you have the latest pymatgen and m3gnet. Also, do a few different structures.

usccolumbia commented 2 years ago

Thanks for clarification. Shyue.

I double checked and found that the issue is caused by the installation on my Macbook pro with ARM chip.. I reinstall the packages and it works well as you did. I also find the following two ways to read cif structure file got different energy results. Method 2) only reads primitive cell?. 1) s = Structure.from_file("temp.cif") 2) parser = CifParser('temp.cif') s = parser.get_structures()[0]

shyuep commented 2 years ago

By default the second method reads primitive cells. But you can set it such that it reads the conventional cell too. You can set whether it is primitive or not with the primitive=True/False kwarg in both methods.