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:
@@ -911,15 +911,53 @@
|
||||
},
|
||||
};
|
||||
|
||||
/* ── Экспорт ──────────────────────────────────────────────────────────── */
|
||||
global.BIO = {
|
||||
/* ── Валентность: подробная проверка с подсказками (Фаза 2.4) ──────────
|
||||
* Возвращает массив проблем-«перевалентностей» с готовым человекочитаемым
|
||||
* текстом: [{ id, symbol, name, used, max, over, kind:'error', msg }].
|
||||
* Работает с обоими форматами связей (from/to/order и f/t/o) через bF/bT/bO.
|
||||
*/
|
||||
function _bondWord(n) {
|
||||
const m10 = n % 10, m100 = n % 100;
|
||||
if (m10 === 1 && m100 !== 11) return 'связь';
|
||||
if (m10 >= 2 && m10 <= 4 && (m100 < 12 || m100 > 14)) return 'связи';
|
||||
return 'связей';
|
||||
}
|
||||
function valency(atoms, bonds) {
|
||||
if (!atoms || !atoms.length) return [];
|
||||
const sum = {};
|
||||
for (const b of (bonds || [])) {
|
||||
const f = bF(b), t = bT(b), o = bO(b);
|
||||
sum[f] = (sum[f] || 0) + o;
|
||||
sum[t] = (sum[t] || 0) + o;
|
||||
}
|
||||
const out = [];
|
||||
for (const a of atoms) {
|
||||
const e = el(a.s);
|
||||
const used = sum[a.id] || 0;
|
||||
const max = e.maxV != null ? e.maxV : 4;
|
||||
if (used > max) {
|
||||
const over = used - max;
|
||||
out.push({
|
||||
id: a.id, symbol: a.s, name: e.name, used, max, over, kind: 'error',
|
||||
msg: e.name + ' (' + a.s + '): занято ' + used + ' ' + _bondWord(used) +
|
||||
', максимум ' + max + ' — убери ' + over,
|
||||
});
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/* ── Экспорт (браузер: window.BIO; Node: module.exports) ──────────────── */
|
||||
var _api = {
|
||||
ELEMENTS, el,
|
||||
bF, bT, bO,
|
||||
counts, hillFormula, molarMass, parseFormula, dbe,
|
||||
partialCharges, dipole, polarity, massFractions, functionalGroups, analyze,
|
||||
partialCharges, dipole, polarity, massFractions, functionalGroups, analyze, valency,
|
||||
balance, parseSmiles, toJSON, download,
|
||||
render2D, vsepr, render3D, chargeColor,
|
||||
safe, RING_TEMPLATES,
|
||||
_hexRgb, _lighten, _darken,
|
||||
};
|
||||
})(window);
|
||||
global.BIO = _api;
|
||||
if (typeof module !== 'undefined' && module.exports) module.exports = _api;
|
||||
})(typeof window !== 'undefined' ? window : globalThis);
|
||||
|
||||
Reference in New Issue
Block a user