Molassembler  3.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)
 Compare two molecules/complexes encoded as base64 strings. The molecule order is irrelevant. More...
 
static BinaryType base64Decode (const std::string &base64String)
 Compare two molecules/complexes encoded as base64 strings. The molecule order is irrelevant. More...
 
static bool base64EqualMolecules (const std::string &stringA, const std::string &stringB, BinaryFormat binaryFormat=BinaryFormat::CBOR)
 Compare two molecules/complexes encoded as base64 strings. The molecule order is irrelevant. More...
 
static bool equalDecisionLists (const std::string &listStringA, const std::string &listStringB)
 Compare two decision lists encoded as strings. More...
 

Static Private Member Functions

static std::vector< std::tuple
< int, int, int, int > > 
unpackDecisionListString (const std::string &listString)
 
static std::tuple< int, int,
int, int > 
canonicalizeDecisionListElement (const std::tuple< int, int, int, int > &decisionListElement)
 
static bool equalVersions (const std::vector< unsigned > versionA, const std::vector< unsigned > versionB)
 
static std::vector< std::string > splitBase64StringIntoMoleculeStrings (std::string base64String)
 
static bool compareMoleculeDecisionList (const std::vector< std::tuple< int, int, int, int >> &listA, const std::vector< std::tuple< int, int, int, int >> &listB)
 

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
*   - o:(optional) Position groups of the ligands
* - 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

static BinaryType Scine::Molassembler::JsonSerialization::base64Decode ( const std::string &  base64String)
static

Compare two molecules/complexes encoded as base64 strings. The molecule order is irrelevant.

Returns
True if both strings encode the same molecule(s).
static std::string Scine::Molassembler::JsonSerialization::base64Encode ( const BinaryType binary)
static

Compare two molecules/complexes encoded as base64 strings. The molecule order is irrelevant.

Returns
True if both strings encode the same molecule(s).
static bool Scine::Molassembler::JsonSerialization::base64EqualMolecules ( const std::string &  stringA,
const std::string &  stringB,
BinaryFormat  binaryFormat = BinaryFormat::CBOR 
)
static

Compare two molecules/complexes encoded as base64 strings. The molecule order is irrelevant.

Returns
True if both strings encode the same molecule(s).
static bool Scine::Molassembler::JsonSerialization::equalDecisionLists ( const std::string &  listStringA,
const std::string &  listStringB 
)
static

Compare two decision lists encoded as strings.

The string format is expected to be
"(-100, -95, -90, 1):(10, 15, 20, 4);(1, 6, 11, 1)"
Multiple molecules have to be separated by ";". The molecule order is irrelevant.

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: