import type { MoleculeView, StateMolecule } from '@zakodium/nmrium-core'; import { Molecule } from 'openchemlib'; import getAtomsFromMF from '../utilities/getAtomsFromMF.js'; export interface StateMoleculeExtended extends Required>, Omit { mf: string; em: number; mw: number; svg: string; atoms: Record; } export interface MoleculeBoundingRect { width: number; height: number; x: number; y: number; } export const DRAGGABLE_STRUCTURE_INITIAL_BOUNDING_REACT: MoleculeBoundingRect = { x: 10, y: 10, width: 130, height: 120, }; export type MoleculesView = Record; export function initMolecule( options: Partial = {}, ): StateMoleculeExtended { const id = options.id || crypto.randomUUID(); const label = options.label || 'p#'; const molfile = options.molfile || ''; const mol = Molecule.fromMolfile(molfile); const mfInfo = mol.getMolecularFormula(); return { id, molfile, label, selector: options.selector, mf: mfInfo.formula, em: mfInfo.absoluteWeight, mw: mfInfo.relativeWeight, svg: mol.toSVG(50, 50), atoms: getAtomsFromMF(mfInfo.formula), }; } export function toJSON(molecule: StateMoleculeExtended): StateMolecule { const { molfile, label, id, selector } = molecule; return { molfile, label, id, selector, }; }