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

Does `CHGNetCalculator` work with ASE #48

Closed Asif-Iqbal-Bhatti closed 1 year ago

Asif-Iqbal-Bhatti commented 1 year ago

Does the CHGNetCalculator work with ASE? As I try to run the code using

chgnet = CHGNet.load()
pot = CHGNetCalculator(
        potential=chgnet, 
        properties = 'energy',
        compute_stress = True, 
        compute_hessian = False, 
        stress_weight=0.01)

atoms = read_vasp("POSCAR")
atoms.calc = pot
print(atoms)
qn = BFGS(atoms, trajectory='initial.traj')
qn.run(fmax=0.5)

It gives me this error:

return json.JSONEncoder.default(self, obj)
  File "/home/*****/miniconda3/lib/python3.9/json/encoder.py", line 179, in default
    raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type CHGNet is not JSON serializable
janosh commented 1 year ago

@Asif-Iqbal-Bhatti This will be fixed in #49. Until that is released, you can workaround the TypeError by adding this line

chgnet = CHGNet.load()

+ chgnet.todict = lambda: {"model_name": "CHGNet", "model_args": chgnet.model_args}