Closed zdcao121 closed 1 month ago
Hi @zdcao121, I am unable to reproduce your error. I used the following code to test it:
import matgl from matgl.ext.ase import Relaxer from pymatgen.core import Structure, Lattice
pot = matgl.load_model("pretrained_models/CHGNet-MPtrj-2023.12.1-PES-2.7M/") relaxer = Relaxer(pot) struct = Structure(Lattice.cubic(4.0), ["Mo", "S"], [[0.0, 0.0, 0.0], [0.5, 0.5, 0.5]]) out = relaxer.relax(struct) o_dict = out['final_structure'].as_dict() print(Structure.from_dict(o_dict))
I don't understand why you are using "literal_eval(s)" but not just "s" in your code. I hope it helps
Thanks for your reply! @kenko911
Because I saved the Structure.as_dict()
in a csv file, I need to convert it from a string to a dictionary format when reloading it. The following code can reproduce the error.
pot = matgl.load_model("pretrained_models/CHGNet-MPtrj-2023.12.1-PES-2.7M/")
relaxer = Relaxer(pot)
struct = Structure(Lattice.cubic(4.0), ["Mo", "S"], [[0.0, 0.0, 0.0], [0.5, 0.5, 0.5]])
out = relaxer.relax(struct)
o_dict = str(out['final_structure'].as_dict())
print(Structure.from_dict(literal_eval(o_dict)))
Hi @zdcao121, I would recommend using json instead of csv since we have monty to handle numpy arrays in json. Please read the documentation carefully (https://pymatgen.org/usage.html) and figure it out by yourself. It should be very easy to follow.
Thanks for the suggestion. I will check out the documentation.
Email (Optional)
zdcao@iphy.ac.cn
Version
v1.1.3
Which OS(es) are you using?
What happened?
If the structure is relaxed by the
CHGNet
, thefinal_magmom
will be added to the site properties like'final_magmom': array([-0.1934694], dtype=float32)
. It will cause problems when reloading it from string of the dictionary format.Code snippet
Log output
Code of Conduct