Serialization

cvpack.serialization.serialize(obj, iostream)[source]

Serializes a cvpack object.

Parameters:
  • obj (Any) – The cvpack object to be serialized

  • iostream (IO) – A text stream in write mode

Example

>>> import cvpack
>>> import io
>>> from cvpack import serialization
>>> radius_of_gyration = cvpack.RadiusOfGyration([0, 1, 2])
>>> iostream = io.StringIO()
>>> serialization.serialize(radius_of_gyration, iostream)
>>> print(iostream.getvalue())
!cvpack.RadiusOfGyration
group:
- 0
- 1
- 2
name: radius_of_gyration
pbc: false
weighByMass: false
cvpack.serialization.deserialize(iostream)[source]

Deserializes a cvpack object.

Parameters:

iostream (IO) – A text stream in read mode containing the object to be deserialized

Returns:

An instance of any cvpack class

Return type:

t.Any

Example

>>> import cvpack
>>> import io
>>> from cvpack import serialization
>>> radius_of_gyration = cvpack.RadiusOfGyration([0, 1, 2])
>>> iostream = io.StringIO()
>>> serialization.serialize(radius_of_gyration, iostream)
>>> iostream.seek(0)
0
>>> new_object = serialization.deserialize(iostream)
>>> type(new_object)
<class 'cvpack.radius_of_gyration.RadiusOfGyration'>