polymerist.genutils.fileutils.jsonio.serialize

Interfaces for extending what types of objects can be serialized to JSON

Attributes

T

JSONSerializable

Classes

TypeSerializer

Interface for defining how types which are not JSON serializable by default should be encoded and decoded

MultiTypeSerializer

For dynamically merging multiple TypeSerializer encoders and decoders

PathSerializer

For JSON-serializing OpenMM Quantities

QuantitySerializer

For JSON-serializing OpenMM Quantities

NDArraySerializer

For JSON-serializing of numpy n-dimensional arrays

Functions

enum_serializer_factory(→ TypeSerializer)

Factory for generating a TypeSerializer specific to an Enum type

Module Contents

polymerist.genutils.fileutils.jsonio.serialize.T
polymerist.genutils.fileutils.jsonio.serialize.JSONSerializable
class polymerist.genutils.fileutils.jsonio.serialize.TypeSerializer[source]

Bases: abc.ABC

Interface for defining how types which are not JSON serializable by default should be encoded and decoded

python_type: ClassVar[Type[T]]
static encode(python_obj: T) JSONSerializable[source]
Abstractmethod:

static decode(json_obj: JSONSerializable) T[source]
Abstractmethod:

classmethod encoder_default(python_obj: Any) JSONSerializable[source]

Augmented Encoder for encoding registered objects along with type info for decoding

classmethod decoder_hook(json_dict: dict[JSONSerializable, JSONSerializable]) dict | T[source]
class polymerist.genutils.fileutils.jsonio.serialize.MultiTypeSerializer(*type_sers: tuple[Type[TypeSerializer]])[source]

For dynamically merging multiple TypeSerializer encoders and decoders

property type_sers: list[Type[TypeSerializer]]

Read-only wrapper for the internal registry of TypeSerializers

add_type_serializer(obj: TypeSerializer | MultiTypeSerializer) None[source]

For type, instance, and uniqueness checking of Type

encoder_default(python_obj: Any) JSONSerializable[source]
decoder_hook(json_dict: dict[JSONSerializable, JSONSerializable]) Any[source]
class polymerist.genutils.fileutils.jsonio.serialize.PathSerializer[source]

Bases: TypeSerializer

For JSON-serializing OpenMM Quantities

static encode(python_obj: pathlib.Path) str[source]

Stringify path object

static decode(json_obj: str) pathlib.Path[source]

Resolve string into system Path

class polymerist.genutils.fileutils.jsonio.serialize.QuantitySerializer[source]

Bases: TypeSerializer

For JSON-serializing OpenMM Quantities

static encode(python_obj: openmm.unit.Quantity) dict[str, str | float][source]

Separate openmm.unit.Quantity’s value and units to serialize as a single dict

static decode(json_obj: dict[str, str | float]) openmm.unit.Quantity[source]

Unpack a value-unit string dict back into a usable openmm.unit.Quantity

class polymerist.genutils.fileutils.jsonio.serialize.NDArraySerializer[source]

Bases: TypeSerializer

For JSON-serializing of numpy n-dimensional arrays

static encode(python_obj: numpy.ndarray[Any]) list[Any][source]

List-ify array and store string descriptor of numpy dtype

static decode(value: list[Any]) numpy.ndarray[Any][source]

Reassemble numpy array from list and dtype

polymerist.genutils.fileutils.jsonio.serialize.enum_serializer_factory(enumtype: enum.EnumType) TypeSerializer[source]

Factory for generating a TypeSerializer specific to an Enum type