moleculekit.viewer.molstar.serialize module#

Serialize a Molecule into the MoleculeKitDict shape consumed by the viewer-frontend (moleculeToCIF.ts).

moleculekit.viewer.molstar.serialize.molecule_to_dict(mol, frame=0)#

Return a JSON-serializable MoleculeKitDict for a single frame.

The returned dict holds the per-atom fields, bonds/bond types and a flat coordinate vector for the requested frame, plus the atom and frame counts. Multi-frame trajectories are sent separately as a binary blob via /coords/<slot>/<topohash>.

Parameters:
  • mol (Molecule) – The molecule to serialize.

  • frame (int) – The coordinate frame to include in coords. Defaults to 0.

Returns:

out – A JSON-serializable dict with the per-atom topology fields, bonds, bondtype, a flat float32 coords list for frame (ordered [x0..xN, y0..yN, z0..zN]), and integer numAtoms / numFrames.

Return type:

dict