CederGroupHub / chgnet

Pretrained universal neural network potential for charge-informed atomistic modeling https://chgnet.lbl.gov
https://doi.org/10.1038/s42256-023-00716-3
Other
220 stars 60 forks source link

`IndexError` on `predict_structure` #85

Closed Yong-Q closed 10 months ago

Yong-Q commented 10 months ago

Which OS(es) are you using?

What happened?

The following code snippet fails:

from chgnet.model.model import CHGNet
from pymatgen.core import Structure

chgnet = CHGNet.load()
structure = Structure.from_file('example/mp-2878.cif')
prediction = chgnet.predict_structure(structure)

for key, unit in [
    ("energy", "eV/atom"),
    ("forces", "eV/A"),
    ("stress", "GPa"),
    ("magmom", "mu_B"),
]:
    print(f"CHGNet-predicted {key} ({unit}):\n{prediction[key[0]]}\n")

Error Message

CHGNet initialized with 400,438 parameters
Traceback (most recent call last):
  File "<script>", line 6, in <module>
    prediction = chgnet.predict_structure(structure)
  File "/path/to/chgnet/model/model.py", line 551, in predict_structure
    return self.predict_graph(...)
  File "/path/to/chgnet/model/model.py", line 340, in forward
    batched_graph = BatchedGraph.from_graphs(...)
  File "/path/to/chgnet/model/model.py", line 754, in from_graphs
    center=atom_cart_coords[graph.atom_graph[:, 0]],
IndexError: tensors used as indices must be long, byte or bool tensors
BowenD-UCB commented 10 months ago

I can't reproduce this error

janosh commented 10 months ago

Me neither.

Yong-Q commented 10 months ago

Why is this, I installed it via pip, this problem occurs in both cpu and gpu 1.txt

Yong-Q commented 10 months ago

Me neither.

structure = Structure.from_file(f"{ROOT}/examples/mp-18767-LiMnO2.cif")

structure = Structure.from_file("./mp-18767-LiMnO2.cif")
I only changed this one item, but looking at the output shouldn't be the problem

BowenD-UCB commented 10 months ago

I suppose it's a version issue of pymatgen and CHGNet. Can you try upgrade pymatgen and CHGNet? @Yong-Q

Yong-Q commented 10 months ago

ok,i will try

---Original--- From: "Bowen @.> Date: Mon, Oct 23, 2023 11:42 AM To: @.>; Cc: @.**@.>; Subject: Re: [CederGroupHub/chgnet] IndexError on predict_structure (Issue#85)

I suppose it's a version issue of pymatgen and CHGNet. Can you try upgrade pymatgen and CHGNet? @Yong-Q

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.Message ID: @.***>

Yong-Q commented 10 months ago

good

Yong-Q commented 10 months ago

我想这是pymatgen和CHGNet的版本问题。你能尝试升级pymatgen和CHGNet吗?

I would like to ask how the prediction of energy etc. can be improved by constructing the Angle relationship on the GNN structure