what is the best way to save and load a psi4 molecule? I tried pickle/dill but they both failed. I see a feature to save as xyz, but I'm not seeing a function to load as xyz and I'm not sure if save xyz also saves the energy and charges etc.
import psi4
# Define the molecular geometry using a string
h2_geometry = """
H 0.0 0.0 0.0
H 0.0 0.0 0.74
"""
# Create the molecule object
h2_molecule = psi4.geometry(h2_geometry)
pickle_file_path = "psi4_mol.pkl"
with open(pickle_file_path, 'wb') as file:
pickle.dump(h2_molecule, file)
Traceback (most recent call last):
File "<stdin>", line 2, in <module>
TypeError: cannot pickle 'psi4.core.Molecule' object
I also tried dill:
with open(pickle_file_path, 'wb') as file:
dill.dump(h2_molecule, file)
Traceback (most recent call last):
File "<stdin>", line 2, in <module>
File "lib/python3.11/site-packages/dill/_dill.py", line 250, in dump
Pickler(file, protocol, **_kwds).dump(obj)
File "lib/python3.11/site-packages/dill/_dill.py", line 418, in dump
StockPickler.dump(self, obj)
File "lib/python3.11/pickle.py", line 487, in dump
self.save(obj)
File "lib/python3.11/site-packages/dill/_dill.py", line 412, in save
StockPickler.save(self, obj, save_persistent_id)
File "lib/python3.11/pickle.py", line 560, in save
f(self, obj) # Call unbound method with explicit self
^^^^^^^^^^^^
File "lib/python3.11/pickle.py", line 887, in save_tuple
save(element)
File "lib/python3.11/site-packages/dill/_dill.py", line 412, in save
StockPickler.save(self, obj, save_persistent_id)
File "lib/python3.11/pickle.py", line 578, in save
rv = reduce(self.proto)
^^^^^^^^^^^^^^^^^^
TypeError: cannot pickle 'psi4.core.Molecule' object
```