feat(biochem): Фаза 2.1/2.2/2.4 — серверный chem.js + /analyze + подсказки валентности
- biochem-core.js dual-export (browser window.BIO + Node module.exports), без дублей - BIO.valency: подробные подсказки валентности (2.4), общие для редактора и сервера - services/chem.js: серверный анализ поверх того же ядра (analyze/validate) - POST /api/biochem/analyze (2.2); /validate переведён на ядро (+фикс формата связей) - api.js: LS.biochemAnalyze Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
'use strict';
|
||||
/*
|
||||
* chem.js — серверный химический слой (Фаза 2.1/2.2).
|
||||
*
|
||||
* Переиспользует то же ядро, что и фронт (frontend/js/biochem-core.js,
|
||||
* `window.BIO`), вместо дублирования химии: формулы/масса/DBE, частичные
|
||||
* заряды, дипольный момент (по 3D-геометрии VSEPR), полярность, функциональные
|
||||
* группы, гибридизация, проверка валентности.
|
||||
*
|
||||
* Ядро самодостаточно (без DOM/canvas в чистых функциях) и при require в Node
|
||||
* экспортирует объект BIO через module.exports.
|
||||
*/
|
||||
const path = require('path');
|
||||
const BIO = require(path.join(__dirname, '..', '..', '..', 'frontend', 'js', 'biochem-core.js'));
|
||||
|
||||
/* Полный анализ структуры → {formula, mass, dbe, geometry, polarity, dipole,
|
||||
* charges, groups, massFractions, valency}. Бросает на некорректном вводе. */
|
||||
function analyze(atoms, bonds) {
|
||||
const an = BIO.analyze(atoms, bonds || []);
|
||||
if (!an) return null;
|
||||
return {
|
||||
formula: an.formula,
|
||||
mass: an.mass,
|
||||
dbe: an.dbe,
|
||||
atomCount: an.atomCount,
|
||||
geometry: an.geometry, // {shape, hybridization, angle, centerSym}
|
||||
polarity: an.polarity ? an.polarity.label : null, // «Полярная» / «Неполярная» / …
|
||||
dipole: an.dipole,
|
||||
charges: an.charges,
|
||||
groups: an.groups,
|
||||
massFractions: an.massFractions,
|
||||
valency: BIO.valency(atoms, bonds || []),
|
||||
};
|
||||
}
|
||||
|
||||
/* Проверка корректности: формула + проблемы валентности (с подсказками). */
|
||||
function validate(atoms, bonds) {
|
||||
const issues = BIO.valency(atoms, bonds || []);
|
||||
return {
|
||||
valid: issues.length === 0,
|
||||
formula: BIO.hillFormula(atoms || []),
|
||||
issues,
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = { analyze, validate, BIO };
|
||||
Reference in New Issue
Block a user