gemmi
gemmi copied to clipboard
[FEATURE REQUEST] make gemmi.cif.Block object picklable
I am currently using gemmi.cif.Block object as an attribute of one of my python classes, and I would like to store this class using pickle. But currently I am not able to do so, because gemmi.cif.Block is not picklable.
It would be convenient if gemmi.cif.Block object can be pickled.
cif.Block is usually read from a file and/or written to a file, so I think it's rarely useful to additionally serialize it. It could have getstate that returns JSON or CIF string, but maybe it's better to save it explicitly as JSON or CIF.
I don't see much point in pickling a Block or Document myself, since they can just be written to JSON or CIF. I would find it useful to pickle a Structure though, since there is a nonzero amount of overhead in serializing a Structure to mmCIF or mmJSON.
Other areas of computational science have found that pickles are about the most energy-efficient serialization there is, generally about 3X higher than alternatives like Arrow (which is hundreds of times more efficient than CIF or JSON). If one accepts the caveat that the pickle will change when the library changes enough to affect the binary constructor, a Structure pickle can also be viewed as an extremely efficient and simple structure file format for gemmi.
We plan a serialization format for Structure in C++. Once we have it, I'll add __setstate__ and __getstate__.