import {z} from 'zod' export type Atom = {atomic_number: number, position: Array, mass?: (number | null) | undefined}; export type PeriodicCellInput = {lattice_vectors: Array, is_periodic?: Array | undefined}; export type VibrationalMode = {frequency: number, reduced_mass: number, force_constant: number, displacements: Array>, ir_intensity?: (number | null) | undefined, symmetry_label?: (string | null) | undefined}; export type Solvent = 'water' | 'nitromethane' | 'nitrobenzene' | 'toluene' | 'benzene' | 'chlorobenzene' | 'carbontetrachloride' | 'dichloroethane' | 'dichloromethane' | 'chloroform' | 'diethylether' | 'diisopropylether' | 'dimethylsulfoxide' | 'tetrahydrofuran' | 'cyclohexane' | 'aceticacid' | 'hexane' | 'octane' | 'decane' | 'ethylacetate' | 'acetone' | 'acetonitrile' | 'methanol' | 'ethanol' | 'isopropanol' | 'octanol' | 'dimethylacetamide' | 'dimethylformamide' | 'n_methylpyrrolidone' | 'ethylene_glycol'; export type COSMORSParameterization = 'opencosmo_rs_24a' | 'rowan_cosmors_2026'; export type COSMORSDataInput = {solvent: Solvent, temperature: number, parameterization: COSMORSParameterization, e_diel: number, mu_res: number, mu_comb: number, g_disp: number, ring_correction: number, standard_state: number, eta: number, n_rings: number, gas_phase_energy?: (number | null) | undefined}; export type BandStructure = {kpoint_distances: Array, eigenvalues: Array>, high_symmetry_points: Array>, total_density_of_states: Array>, band_gap: number, valence_band_maximum: number, conduction_band_minimum: number}; export type MoleculeInput = {charge: number, multiplicity: number, atoms: Array, cell?: (PeriodicCellInput | null) | undefined, energy?: (number | null) | undefined, scf_iterations?: (number | null) | undefined, scf_completed?: (boolean | null) | undefined, elapsed?: (number | null) | undefined, homo_lumo_gap?: (number | null) | undefined, gradient?: (Array> | null) | undefined, stress?: (Array | null) | undefined, velocities?: (Array> | null) | undefined, mulliken_charges?: (Array | null) | undefined, mulliken_spin_densities?: (Array | null) | undefined, dipole?: (Array | null) | undefined, vibrational_modes?: (Array | null) | undefined, zero_point_energy?: (number | null) | undefined, thermal_energy_corr?: (number | null) | undefined, thermal_enthalpy_corr?: (number | null) | undefined, thermal_free_energy_corr?: (number | null) | undefined, excited_state_energies?: (Array | null) | undefined, oscillator_strengths?: (Array | null) | undefined, rotatory_strengths?: (Array | null) | undefined, cosmo_rs_data?: (COSMORSDataInput | null) | undefined, symmetry?: (string | number | null) | undefined, x_ray_diffraction_peaks?: (Array> | null) | undefined, band_structure?: (BandStructure | null) | undefined, elastic_tensor?: (Array | null) | undefined, smiles?: (string | null) | undefined, calculation_index?: (number | null) | undefined, name?: (string | null) | undefined, metadata?: ({[key: string]: boolean | number | number | string} | null) | undefined}; export type BodyQuickOptimizeMoleculeForcefieldOptimizePost = {mol: MoleculeInput, bonds?: (Array> | null) | undefined}; export type CreateApiMoleculeForcefieldOptimizeArgs = {access_token?: (string | null) | undefined, body: BodyQuickOptimizeMoleculeForcefieldOptimizePost}; export type CreateApiMoleculeForcefieldOptimizeOptions = {baseUrl: string, APIKeyHeader?: string | undefined, fetch?: typeof fetch | undefined}; export const atom = z.object({atomic_number: z.number().int().gte(0), position: z.array(z.unknown()), mass: z.number().nullable().optional()}); export const periodicCellOutput = z.object({lattice_vectors: z.array(z.unknown()), is_periodic: z.array(z.unknown()).optional(), volume: z.number()}); export const vibrationalMode = z.object({frequency: z.number(), reduced_mass: z.number(), force_constant: z.number(), displacements: z.array(z.array(z.unknown())), ir_intensity: z.number().nullable().optional(), symmetry_label: z.string().nullable().optional()}); export const solvent = z.enum(["water", "nitromethane", "nitrobenzene", "toluene", "benzene", "chlorobenzene", "carbontetrachloride", "dichloroethane", "dichloromethane", "chloroform", "diethylether", "diisopropylether", "dimethylsulfoxide", "tetrahydrofuran", "cyclohexane", "aceticacid", "hexane", "octane", "decane", "ethylacetate", "acetone", "acetonitrile", "methanol", "ethanol", "isopropanol", "octanol", "dimethylacetamide", "dimethylformamide", "n_methylpyrrolidone", "ethylene_glycol"]); export const cOSMORSParameterization = z.enum(["opencosmo_rs_24a", "rowan_cosmors_2026"]); export const cOSMORSDataOutput = z.object({solvent: solvent, temperature: z.number().gt(0), parameterization: cOSMORSParameterization, e_diel: z.number(), mu_res: z.number(), mu_comb: z.number(), g_disp: z.number(), ring_correction: z.number(), standard_state: z.number(), eta: z.number(), n_rings: z.number().int().gte(0), gas_phase_energy: z.number().nullable().optional(), solvation_free_energy: z.number()}); export const bandStructure = z.object({kpoint_distances: z.array(z.number()), eigenvalues: z.array(z.array(z.number())), high_symmetry_points: z.array(z.array(z.unknown())), total_density_of_states: z.array(z.array(z.unknown())), band_gap: z.number(), valence_band_maximum: z.number(), conduction_band_minimum: z.number()}); export const moleculeOutput = z.object({charge: z.number().int(), multiplicity: z.number().int().gt(0), atoms: z.array(atom), cell: periodicCellOutput.nullable().optional(), energy: z.number().nullable().optional(), scf_iterations: z.number().int().gte(0).nullable().optional(), scf_completed: z.boolean().nullable().optional(), elapsed: z.number().nullable().optional(), homo_lumo_gap: z.number().nullable().optional(), gradient: z.array(z.array(z.unknown())).nullable().optional(), stress: z.array(z.unknown()).nullable().optional(), velocities: z.array(z.array(z.unknown())).nullable().optional(), mulliken_charges: z.array(z.number()).nullable().optional(), mulliken_spin_densities: z.array(z.number()).nullable().optional(), dipole: z.array(z.unknown()).nullable().optional(), vibrational_modes: z.array(vibrationalMode).nullable().optional(), zero_point_energy: z.number().nullable().optional(), thermal_energy_corr: z.number().nullable().optional(), thermal_enthalpy_corr: z.number().nullable().optional(), thermal_free_energy_corr: z.number().nullable().optional(), excited_state_energies: z.array(z.number()).nullable().optional(), oscillator_strengths: z.array(z.number()).nullable().optional(), rotatory_strengths: z.array(z.number()).nullable().optional(), cosmo_rs_data: cOSMORSDataOutput.nullable().optional(), symmetry: z.union([z.string(), z.number().int()]).nullable().optional(), x_ray_diffraction_peaks: z.array(z.array(z.unknown())).nullable().optional(), band_structure: bandStructure.nullable().optional(), elastic_tensor: z.array(z.unknown()).nullable().optional(), smiles: z.string().nullable().optional(), calculation_index: z.number().int().nullable().optional(), name: z.string().nullable().optional(), metadata: z.record(z.string(), z.union([z.boolean(), z.number(), z.number().int(), z.string()])).nullable().optional(), pressure_gpa: z.number().nullable()}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * Quick Optimize * * POST /molecule/forcefield_optimize */ export const createApiMoleculeForcefieldOptimize = async (args: CreateApiMoleculeForcefieldOptimizeArgs, options: CreateApiMoleculeForcefieldOptimizeOptions) => { const {baseUrl, fetch: fetchFn = fetch, APIKeyHeader} = options ?? {} const query = new URLSearchParams() const headers = new Headers() const cookies: string[] = [] headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args.access_token != null) cookies.push("access_token=" + encodeURIComponent(String(args.access_token))) if (APIKeyHeader !== undefined) headers.set("X-API-Key", APIKeyHeader) if (cookies.length > 0) headers.set('cookie', cookies.join('; ')) const url = `${baseUrl.replace(/\/+$/, '')}/molecule/forcefield_optimize${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(moleculeOutput, await res.json()) };