diff --git a/dpdata/plugins/deepmd.py b/dpdata/plugins/deepmd.py index d8ed0aed..1ed79f72 100644 --- a/dpdata/plugins/deepmd.py +++ b/dpdata/plugins/deepmd.py @@ -302,6 +302,8 @@ def to_system( **kwargs : dict other parameters """ + import h5py + if isinstance(file_name, (h5py.Group, h5py.File)): dpdata.deepmd.hdf5.dump( file_name, "", data, set_size=set_size, comp_prec=comp_prec @@ -332,6 +334,8 @@ def from_multi_systems(self, directory: str, **kwargs) -> h5py.Group: h5py.Group a HDF5 group in the HDF5 file """ + import h5py + with h5py.File(directory, "r") as f: for ff in f.keys(): yield f[ff] @@ -355,6 +359,8 @@ def to_multi_systems( h5py.Group a HDF5 group with the name of formula """ + import h5py + with h5py.File(directory, "w") as f: for ff in formulas: yield f.create_group(ff)