Molassembler  1.0.0
Molecule graph and conformer library
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Scine::Molassembler::JsonSerialization Class Reference

Class representing a compact JSON serialization of a molecule. More...

#include <Serialization.h>

Public Types

Public types
enum  BinaryFormat { CBOR, BSON, MsgPack, UBJSON }
 Binary formats that JSON can be encoded into and decoded from.
 
using BinaryType = std::vector< std::uint8_t >
 Type used to represent binary JSON formats.
 

Public Member Functions

Special member functions
 JsonSerialization (JsonSerialization &&other) noexcept
 
JsonSerializationoperator= (JsonSerialization &&other) noexcept
 
 JsonSerialization (const JsonSerialization &other)
 
JsonSerializationoperator= (const JsonSerialization &other)
 
 ~JsonSerialization ()
 
Constructors
 JsonSerialization ()=delete
 Construct a serialization from a JSON string.
 
 JsonSerialization (const std::string &jsonString)
 Construct a serialization from a JSON string.
 
 JsonSerialization (const Molecule &molecule)
 Construct a serialization from a Molecule.
 
 JsonSerialization (const BinaryType &binary, BinaryFormat format)
 Construct a serialization from a binary JSON format.
 
Conversions
 operator std::string () const
 Dump the unprettified JSON notation as a string.
 
 operator Molecule () const
 Deserialize the JSON serialization into a Molecule.
 
BinaryType toBinary (BinaryFormat format) const
 Serialize the JSON serialization into a binary JSON format.
 
Modification
JsonSerializationstandardize ()
 Eliminate all notational freedom of the JSON serialization. More...
 

Static Public Member Functions

Static members
static std::string base64Encode (const BinaryType &binary)
 
static BinaryType base64Decode (const std::string &base64String)
 

Private Attributes

std::unique_ptr< Impl > pImpl_
 

Detailed Description

Class representing a compact JSON serialization of a molecule.

The JSON representation, although principally human readable, is very compact. Keys are heavily shortened. Each Molecule JSON Object has the following structure:

* - a: List of AtomStereopermutator Objects
*   - a: Assignment index (key omitted if unassigned)
*   - c: Central index
*   - r: Ranking
*     - s: Sorted subtituents
*     - l: Ligands
*     - lr: Ranked ligands
*     - lnk: Links (key omitted if empty)
*   - s: Shape name index
* - b: List of BondStereopermutator Objects
*   - a: Assignment index (key omitted if unassigned)
*   - e: Edge on which it is placed
* - c: Canonicalization state
* - g: Graph Object
*   - Z: List of atomic numbers
*   - E: List of edges, each a List
*     - 0: Source vertex
*     - 1: Target vertex
*     - 2: Bond type index
* - v: Library version List
*   - 0: Major
*   - 1: Minor
*   - 2: Patch
* 

For std::string - Molecule interconversions, you can implicitly call the converting operators:

Molecule mol;
std::string jsonSerialization = JsonSerialization(mol);
Molecule reverted = JsonSerialization(jsonSerialization);

For BinaryType - Molecule interconversions, only the implicit Molecule conversion operator is available since the binary JSON format must be specified:

Molecule mol;
JsonSerialization::BinaryType bson = JsonSerialization(mol).toBinary(JsonSerialization::BinaryFormat::BSON);
Molecule reverted = JsonSerialization(bson, JsonSerialization::BinaryFormat::BSON);
Warning
Serializations of molecules have substantial notational freedom. Using lexicographical comparison on serializations does not have the same semantics as calling Molecule's relational operators.

Member Function Documentation

JsonSerialization& Scine::Molassembler::JsonSerialization::standardize ( )

Eliminate all notational freedom of the JSON serialization.

The Molecule's JSON representation notational freedoms are removed:

  • Edges have ordered indices
  • The graph edge list is sorted
  • The lists of atom and bond stereopermutators are sorted by their placement atoms and bonds, respectively
  • Ranking information notational freedom is removed

Complexity \(\Theta(V + E + A + B)\)

Exceptions
std::logic_errorIf the underlying molecule is not fully canonical. It makes zero sense to standardize the JSON representation if the molecule itself is not canonicalized since then JSON representation comparison will still not yield the same behavior as Molecule comparison.
Returns
*this for method chaining

The documentation for this class was generated from the following file: