openchemlib 9.4.0 → 9.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -506,6 +506,16 @@ export declare class Molecule {
506
506
  */
507
507
  static fromIDCode(idcode: string, ensure2DCoordinates?: boolean): Molecule;
508
508
 
509
+ /**
510
+ * Tries to parse a molecule from arbitrary text, with the following algorithm:
511
+ * - If it contains V2000 or V3000, Molfile is assumed.
512
+ * - Try to parse as SMILES.
513
+ * - Try to parse as ID code.
514
+ * @param text - The text to parse.
515
+ * @returns A molecule or null if the text could not be parsed or would give an empty molecule.
516
+ */
517
+ static fromText(text: string): Molecule | null;
518
+
509
519
  static getAtomicNoFromLabel(
510
520
  atomLabel: string,
511
521
  allowedPseudoAtomGroups?: number,
@@ -273,7 +273,7 @@ function addPointerListeners(canvasElement, drawArea, JavaEditorArea) {
273
273
  document.removeEventListener("pointerup", handlePointerUp);
274
274
  };
275
275
  }
276
- function addKeyboardListeners(canvasElement, editorArea, JavaEditorArea) {
276
+ function addKeyboardListeners(parentElement, canvasElement, editorArea, JavaEditorArea, Molecule2) {
277
277
  const isMac = typeof navigator !== "undefined" && navigator.platform === "MacIntel";
278
278
  const isMenuKey = (ev) => isMac && ev.metaKey || !isMac && ev.ctrlKey;
279
279
  function fireKeyEvent(what, ev) {
@@ -296,6 +296,13 @@ function addKeyboardListeners(canvasElement, editorArea, JavaEditorArea) {
296
296
  canvasElement.addEventListener("keyup", (ev) => {
297
297
  fireKeyEvent(JavaEditorArea.KEY_EVENT_RELEASED, ev);
298
298
  });
299
+ parentElement.addEventListener("paste", (ev) => {
300
+ const textData = ev.clipboardData.getData("text");
301
+ const molecule = Molecule2.fromText(textData);
302
+ if (molecule && molecule.getAllAtoms() > 0) {
303
+ editorArea.addPastedOrDropped(molecule);
304
+ }
305
+ });
299
306
  return () => {
300
307
  };
301
308
  }
@@ -790,9 +797,11 @@ function createEditor(parentElement, options, onChange, JavaEditorArea, JavaEdit
790
797
  JavaEditorArea
791
798
  );
792
799
  removeKeyboardListeners = addKeyboardListeners(
800
+ editorContainer,
793
801
  editorCanvas,
794
802
  editorArea,
795
- JavaEditorArea
803
+ JavaEditorArea,
804
+ Molecule2
796
805
  );
797
806
  removeToolbarPointerListeners = addPointerListeners(
798
807
  toolbarCanvas,
@@ -1280,7 +1289,8 @@ function init(OCL) {
1280
1289
 
1281
1290
  // lib/extend/index.js
1282
1291
  function extendOCL(OCL) {
1283
- OCL.ConformerGenerator.prototype.molecules = function* molecules() {
1292
+ const { ConformerGenerator: ConformerGenerator2, ForceFieldMMFF94: ForceFieldMMFF942, Molecule: Molecule2 } = OCL;
1293
+ ConformerGenerator2.prototype.molecules = function* molecules() {
1284
1294
  let nextConformer;
1285
1295
  while ((nextConformer = this.getNextConformerAsMolecule()) !== null) {
1286
1296
  yield nextConformer;
@@ -1291,9 +1301,9 @@ function extendOCL(OCL) {
1291
1301
  gradTol: 1e-4,
1292
1302
  funcTol: 1e-6
1293
1303
  };
1294
- const _minimise = OCL.ForceFieldMMFF94.prototype._minimise;
1295
- delete OCL.ForceFieldMMFF94.prototype._minimise;
1296
- OCL.ForceFieldMMFF94.prototype.minimise = function minimise(options) {
1304
+ const _minimise = ForceFieldMMFF942.prototype._minimise;
1305
+ delete ForceFieldMMFF942.prototype._minimise;
1306
+ ForceFieldMMFF942.prototype.minimise = function minimise(options) {
1297
1307
  options = { ...defaultMinimiseOptions, ...options };
1298
1308
  return _minimise.call(
1299
1309
  this,
@@ -1302,7 +1312,31 @@ function extendOCL(OCL) {
1302
1312
  options.funcTol
1303
1313
  );
1304
1314
  };
1305
- OCL.Molecule.prototype.getOCL = function getOCL() {
1315
+ function parseMoleculeFromText(text) {
1316
+ if (!text) {
1317
+ return null;
1318
+ }
1319
+ if (text.includes("V2000") || text.includes("V3000")) {
1320
+ return Molecule2.fromMolfile(text);
1321
+ }
1322
+ try {
1323
+ return Molecule2.fromSmiles(text);
1324
+ } catch {
1325
+ }
1326
+ try {
1327
+ return Molecule2.fromIDCode(text);
1328
+ } catch {
1329
+ }
1330
+ return null;
1331
+ }
1332
+ Molecule2.fromText = function fromText(text) {
1333
+ const molecule = parseMoleculeFromText(text);
1334
+ if (molecule && molecule.getAllAtoms() > 0) {
1335
+ return molecule;
1336
+ }
1337
+ return null;
1338
+ };
1339
+ Molecule2.prototype.getOCL = function getOCL() {
1306
1340
  return OCL;
1307
1341
  };
1308
1342
  }
@@ -44274,7 +44308,7 @@ function getExports($wnd) {
44274
44308
  _.addDrawAreaListener = function addDrawAreaListener(l) {
44275
44309
  this.mListeners.add(l);
44276
44310
  };
44277
- _.addPastedOrDropped = function addPastedOrDropped(mol, p) {
44311
+ _.addPastedOrDropped_0 = function addPastedOrDropped(mol, p) {
44278
44312
  var atom, avbl, editorIsFragment, originalAtoms;
44279
44313
  if (isNull(mol) || mol.getAllAtoms_0() == 0)
44280
44314
  return false;
@@ -46192,7 +46226,7 @@ function getExports($wnd) {
46192
46226
  var mol;
46193
46227
  if (isNotNull(this.mClipboardHandler)) {
46194
46228
  mol = this.mClipboardHandler.pasteMolecule_0();
46195
- if (this.addPastedOrDropped(mol, null))
46229
+ if (this.addPastedOrDropped_0(mol, null))
46196
46230
  return true;
46197
46231
  this.showWarningMessage("No molecule on clipboard!");
46198
46232
  }
@@ -49048,7 +49082,7 @@ function getExports($wnd) {
49048
49082
  return creator.getMolfile();
49049
49083
  };
49050
49084
  _.toSVG = function toSVG(width_0, height, id_0, options) {
49051
- if (!width_0 || !height) {
49085
+ if (typeof width_0 !== "number" || typeof height !== "number") {
49052
49086
  throw new Error("Molecule#toSVG requires width and height to be specified");
49053
49087
  }
49054
49088
  options = options || {};
@@ -50087,6 +50121,9 @@ function getExports($wnd) {
50087
50121
  cargjag.$clinit_JSEditorArea();
50088
50122
  this.draw_0();
50089
50123
  };
50124
+ _.addPastedOrDropped = function addPastedOrDropped_0(mol, x_0, y_0) {
50125
+ this.mDrawArea.addPastedOrDropped_0(mol.getStereoMolecule(), null);
50126
+ };
50090
50127
  _.callJsEventListener = function callJsEventListener(what, isUserChange) {
50091
50128
  cargjag.$clinit_JSEditorArea();
50092
50129
  var jsObject = this.getJsObject();
@@ -70983,7 +71020,7 @@ function getExports($wnd) {
70983
71020
  $sendStats("moduleStartup", "end");
70984
71021
  $gwt && $gwt.permProps && __gwtModuleFunction.__moduleStartupDone($gwt.permProps);
70985
71022
  const toReturn = $wnd["OCL"];
70986
- toReturn.version = "9.4.0";
71023
+ toReturn.version = "9.5.0";
70987
71024
  return toReturn;
70988
71025
  }
70989
71026
  var isBrowserWindow = typeof window !== "undefined" && typeof window.document !== "undefined";
@@ -71127,8 +71164,8 @@ export {
71127
71164
  };
71128
71165
  /**
71129
71166
  * openchemlib - Manipulate molecules
71130
- * @version v9.4.0
71131
- * @date 2025-07-10T13:55:55.814Z
71167
+ * @version v9.5.0
71168
+ * @date 2025-07-11T12:27:39.091Z
71132
71169
  * @link https://github.com/cheminfo/openchemlib-js
71133
71170
  * @license BSD-3-Clause
71134
71171
  */