openchemlib 9.4.1 → 9.5.1

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;
@@ -44773,6 +44807,8 @@ function getExports($wnd) {
44773
44807
  };
44774
44808
  _.eventHappened_2 = function eventHappened_7(e) {
44775
44809
  var atom1, atom2, bondChanged, ch_0, chainAtoms, hydrogenCount, i, isFirst, list, newRadical;
44810
+ if (this.mMouseIsDown)
44811
+ return;
44776
44812
  if (e.getWhat() == 1) {
44777
44813
  if (e.getKey() == -3) {
44778
44814
  this.mShiftIsDown = true;
@@ -46192,7 +46228,7 @@ function getExports($wnd) {
46192
46228
  var mol;
46193
46229
  if (isNotNull(this.mClipboardHandler)) {
46194
46230
  mol = this.mClipboardHandler.pasteMolecule_0();
46195
- if (this.addPastedOrDropped(mol, null))
46231
+ if (this.addPastedOrDropped_0(mol, null))
46196
46232
  return true;
46197
46233
  this.showWarningMessage("No molecule on clipboard!");
46198
46234
  }
@@ -50087,6 +50123,9 @@ function getExports($wnd) {
50087
50123
  cargjag.$clinit_JSEditorArea();
50088
50124
  this.draw_0();
50089
50125
  };
50126
+ _.addPastedOrDropped = function addPastedOrDropped_0(mol, x_0, y_0) {
50127
+ this.mDrawArea.addPastedOrDropped_0(mol.getStereoMolecule(), null);
50128
+ };
50090
50129
  _.callJsEventListener = function callJsEventListener(what, isUserChange) {
50091
50130
  cargjag.$clinit_JSEditorArea();
50092
50131
  var jsObject = this.getJsObject();
@@ -70983,7 +71022,7 @@ function getExports($wnd) {
70983
71022
  $sendStats("moduleStartup", "end");
70984
71023
  $gwt && $gwt.permProps && __gwtModuleFunction.__moduleStartupDone($gwt.permProps);
70985
71024
  const toReturn = $wnd["OCL"];
70986
- toReturn.version = "9.4.1";
71025
+ toReturn.version = "9.5.1";
70987
71026
  return toReturn;
70988
71027
  }
70989
71028
  var isBrowserWindow = typeof window !== "undefined" && typeof window.document !== "undefined";
@@ -71127,8 +71166,8 @@ export {
71127
71166
  };
71128
71167
  /**
71129
71168
  * openchemlib - Manipulate molecules
71130
- * @version v9.4.1
71131
- * @date 2025-07-11T08:21:58.008Z
71169
+ * @version v9.5.1
71170
+ * @date 2025-07-14T08:56:48.567Z
71132
71171
  * @link https://github.com/cheminfo/openchemlib-js
71133
71172
  * @license BSD-3-Clause
71134
71173
  */