# pymatgen.util.serialization module

Most features of this module has been moved to monty. Please refer to monty.json and monty.serialization documentation.

class PmgPickler(file, protocol=None, fix_imports=True, buffer_callback=None)

  Bases: `_pickle.Pickler`

  Persistence of External Objects as described in section 12.1.5.1 of https://docs.python.org/3/library/pickle.html

  persistent_id(obj)

    Instead of pickling as a regular class instance, we emit a persistent ID.

class PmgUnpickler(file, *, fix_imports=True, encoding='ASCII', errors='strict', buffers=())

  Bases: `_pickle.Unpickler`

  Persistence of External Objects as described in section 12.1.5.1 of https://docs.python.org/3/library/pickle.html

  persistent_load(pid)

    This method is invoked whenever a persistent ID is encountered. Here, pid is the tuple returned by PmgPickler.

class SlotPickleMixin

  Bases: `object`

  This mixin makes it possible to pickle/unpickle objects with __slots__ defined.

json_pretty_dump(obj, filename)

  Serialize obj as a JSON formatted stream to the given filename ( pretty printing version)

pmg_pickle_dump(obj, filobj, **kwargs)

  Dump an object to a pickle file using PmgPickler.

  Parameters

    - obj – Object to dump.

    - fileobj – File-like object

    - **kwargs – Any of the keyword arguments supported by PmgPickler

pmg_pickle_load(filobj, **kwargs)

  Loads a pickle file and deserialize it with PmgUnpickler.

  Parameters

    - filobj – File-like object

    - **kwargs – Any of the keyword arguments supported by PmgUnpickler

  Returns

    Deserialized object.

pmg_serialize(method)

  Decorator for methods that add MSON serializations keys to the dictionary. See documentation of MSON for more details