Serialization

class scine_molassembler.JsonSerialization

Class representing a compact JSON serialization of a molecule

>>> # Demonstrate a serialize-deserialize loop
>>> spiro = io.experimental.from_smiles("C12(CCCC1)CCC2")
>>> serializer = JsonSerialization(spiro)
>>> bson_format = JsonSerialization.BinaryFormat.BSON
>>> spiro_as_bson = serializer.to_binary(bson_format)
>>> bson_in_b64 = serializer.base_64_encode(spiro_as_bson)
>>> reverted_bson = JsonSerialization.base_64_decode(bson_in_b64)
>>> serializer = JsonSerialization(reverted_bson, bson_format)
>>> reverted = serializer.to_molecule()
>>> reverted == spiro # Compare the deserialized molecule
True
class BinaryFormat

Specifies the type of JSON binary format

Members:

CBOR : Compact Binary Object Representation

BSON : Binary JSON

MsgPack : MsgPack

UBJSON : Universal Binary JSON

BSON = <BinaryFormat.BSON: 1>
CBOR = <BinaryFormat.CBOR: 0>
MsgPack = <BinaryFormat.MsgPack: 2>
UBJSON = <BinaryFormat.UBJSON: 3>
__init__(self: scine_molassembler.JsonSerialization.BinaryFormat, value: int) → None
property name
property value
__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: scine_molassembler.JsonSerialization, json_string: str) -> None

Parse a JSON molecule serialization

  1. __init__(self: scine_molassembler.JsonSerialization, molecule: scine_molassembler.Molecule) -> None

Serialize a molecule into JSON

  1. __init__(self: scine_molassembler.JsonSerialization, bytes: bytes, binary_format: scine_molassembler.JsonSerialization.BinaryFormat) -> None

Parse a binary JSON molecule serialization

static base_64_decode(base_64_string: str) → bytes

Decode base-64 string into binary

static base_64_encode(binary: bytes) → str

Encode binary format as base-64 string

static equal_decision_lists(string_a: str, string_b: str) → bool

Compare the decision lists given as strings. For each of the decision list elements,the symmetry number has to be identical and the angle has to be within the intervalof the corresponding other decision list entry.

static equal_molecules(string_a: str, string_b: str, binary_format: scine_molassembler.JsonSerialization.BinaryFormat = <BinaryFormat.CBOR: 0>) → bool

Compare the molecules given by the string representation.

standardize(self: scine_molassembler.JsonSerialization)scine_molassembler.JsonSerialization

Standardize the internal JSON serialization (only for canonical molecules)

to_binary(self: scine_molassembler.JsonSerialization, binary_format: scine_molassembler.JsonSerialization.BinaryFormat) → bytes

Serialize a molecule into a binary format

to_molecule(self: scine_molassembler.JsonSerialization)scine_molassembler.Molecule

Construct a molecule from the serialization

to_string(self: scine_molassembler.JsonSerialization) → str

Dump the JSON serialization into a string