Skip to content
This repository has been archived by the owner on Apr 27, 2023. It is now read-only.

could you please provide an example to predict disordered structure? #317

Open
liuxiaotong15 opened this issue Dec 20, 2021 · 12 comments
Open

Comments

@liuxiaotong15
Copy link

hi, I am trying to predict band gap of some disordered structures, but i didn't find any examples of that.

I use:

cg = CrystalGraphDisordered()
graph = cg.convert(test_structures[i])
model_output = model.predict_graph(graph).ravel()

I read some of your code and found that you change the atom number to a dict but I get an error finally:
ValueError: Failed to convert a NumPy array to a Tensor (Unsupported object type collections.defaultdict)

so could you provide an example of that?

thanks

@liuxiaotong15
Copy link
Author

liuxiaotong15 commented Dec 21, 2021

Even I load your model like this, it does not work...

model = MEGNetModel.from_file('/home/ubuntu/code/megnet/mvl_models/mf_2020/pbe_gllb_hse_exp_disorder/0/best_model.hdf5')
model_output = model.predict_structure(test_structures[i]).ravel()

Error stack

  File "/home/ubuntu/code/.../python3.8/site-packages/megnet/models/base.py", line 318, in predict_structure
    return self.predict_graph(graph)
  File "/home/ubuntu/code/.../python3.8/site-packages/megnet/models/base.py", line 344, in predict_graph
    inp = self.graph_converter.graph_to_input(graph)
  File "/home/ubuntu/code/.../python3.8/site-packages/megnet/data/graph.py", line 160, in graph_to_input
    expand_1st(self.atom_converter.convert(graph["atom"])),
  File "/home/ubuntu/code/.../python3.8/site-packages/megnet/data/crystal.py", line 130, in convert
    emb += np.array(self.embedding_dict[k]) * v
KeyError: 'Cu+'

Ordered structure work well...

@chc273
Copy link
Contributor

chc273 commented Dec 21, 2021

@liuxiaotong15 can you remove the oxidation state and try again?

@liuxiaotong15
Copy link
Author

@liuxiaotong15 can you remove the oxidation state and try again?

Thanks. It works on the disordered model you submitted after I add a remove_oxidation_states() to all structure. But still not work for all ordered models.

Can I test disordered structure on previous trained ordered model?
thanks

@liuxiaotong15
Copy link
Author

@chc273 I think you use a dict to express an specie in disordered model, so the disorder structure can not be handled by previous trained model?

@liuxiaotong15
Copy link
Author

I guess you change the atom in graph from
something like array([[71, 71, 71, 71, 15, 15, 15, 15]])
to something like

array([[defaultdict(<class 'float'>, {'Lu3+': 1.0}),
        defaultdict(<class 'float'>, {'Lu3+': 1.0}),
        defaultdict(<class 'float'>, {'Lu3+': 1.0}),
        defaultdict(<class 'float'>, {'Lu3+': 1.0}),
        defaultdict(<class 'float'>, {'P3-': 1.0}),
        defaultdict(<class 'float'>, {'P3-': 1.0}),
        defaultdict(<class 'float'>, {'P3-': 1.0}),
        defaultdict(<class 'float'>, {'P3-': 1.0})]], dtype=object)

so old model can't handle disordered structure?
Thanks

@chc273
Copy link
Contributor

chc273 commented Dec 21, 2021

@liuxiaotong15 again please try remove the oxidation state in ordered structures too

@liuxiaotong15
Copy link
Author

@chc273 I think you misunderstanding my point. I have a lot of trained model (by ordered structures). I want to test their performance on disordered structures? Is it possible to do that? thanks.

@liuxiaotong15
Copy link
Author

@chc273 sorry for post so many msg. And now I think I have a more easy way to ask my question:
is it possible to replace the graph_converter from CrystalGraph() to CrystalGraphDisordered().
My old model trained by CrystalGraph(), but CrystalGraph() can't handle disordered structure I think. So I need to replace it to CrystalGraphDisordered() I guess.

@chc273
Copy link
Contributor

chc273 commented Dec 23, 2021

@liuxiaotong15 you can construct a new model without the elemental embedding layer, but compute the elemental embedding yourself via linear combinations, e.g., what CrystalGraphDisordered does.

Some simple, but exactly the same example is here

https://github.com/materialsvirtuallab/megnet/blob/master/notebooks/model_reconstruct.ipynb

@liuxiaotong15
Copy link
Author

@chc273 Yes, it is a good way. thanks.

By the way, I also tested training from graph generated by CrystalGraphDisordered.
It looks a converter should be added, I have submit a PR. The training process runs ok now.
Maybe you have some better place to add the converter.
#321

Merry Christmas and thank for a great MEGNet.

@liuxiaotong15
Copy link
Author

@chc273 hi, today I dive into https://github.com/materialsvirtuallab/megnet/blob/master/notebooks/model_reconstruct.ipynb and find it is still not easy to handle the disordered structure. The 'CrystalGraphDisordered' bring in so many troubles...
I still advice you to provide some example on training and inference with 'CrystalGraphDisordered', many thanks...

@liuxiaotong15
Copy link
Author

oh, my previous model is created by
MEGNetModel(nfeat_edge=10, nfeat_global=2, graph_converter=CrystalGraph(bond_converter=GaussianDistance(np.linspace(0, 5, 10), 0.5)))
no atom embedding layer in it.... default of nfeat_node is None....
That's why it is really hard for me to modify the model.........

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants