pymatgen.util.serialization module

class PmgPickler[source]

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)[source]

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

class PmgUnpickler[source]

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)[source]

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

class SlotPickleMixin[source]

Bases: object

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

json_pretty_dump(obj, filename)[source]

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

pmg_pickle_dump(obj, filobj, **kwargs)[source]

Dump an object to a pickle file using PmgPickler.

Parameters:
  • obj (object) – Object to dump.
  • fileobj – File-like object
  • **kwargs – Any of the keyword arguments supported by PmgPickler
pmg_pickle_load(filobj, **kwargs)[source]

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)[source]

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