@chemistry/molecule 3.1.0 → 3.1.2

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.
package/README.md CHANGED
@@ -1,11 +1,10 @@
1
1
  # @chemistry/molecule
2
2
 
3
- [![npm version](https://badge.fury.io/js/%40chemistry%2Fmolecule.svg)](https://badge.fury.io/js/%40chemistry%2Fmolecule)
4
- [![License: MIT](https://img.shields.io/badge/License-MIT-gren.svg)](https://opensource.org/licenses/MIT)
3
+ [![npm](https://img.shields.io/npm/v/@chemistry/molecule)](https://www.npmjs.com/package/@chemistry/molecule)
5
4
 
6
- Library for working with molecular structures add atoms, bonds, and export to SVG.
5
+ Molecule data structureload, manipulate, and export molecular data.
7
6
 
8
- ## Install
7
+ ## Installation
9
8
 
10
9
  ```bash
11
10
  npm install @chemistry/molecule
@@ -16,55 +15,18 @@ npm install @chemistry/molecule
16
15
  ```typescript
17
16
  import { Molecule } from '@chemistry/molecule';
18
17
 
19
- // Load molecule from JNMol format
20
- const mol = new Molecule();
21
- mol.load({
22
- id: 'acetone',
23
- title: 'Acetone',
24
- atoms: {
25
- a1: { x: 0, y: 0, z: 0, type: 'C' },
26
- a2: { x: 1.2, y: 0, z: 0, type: 'C' },
27
- a3: { x: 2.4, y: 0, z: 0, type: 'O' },
28
- },
29
- bonds: {
30
- b1: { atom1: 'a1', atom2: 'a2', order: 1 },
31
- b2: { atom1: 'a2', atom2: 'a3', order: 2 },
32
- },
33
- });
34
-
35
- // Query molecule properties
36
- console.log(mol.getAtomCount()); // 3
37
- console.log(mol.getBondCount()); // 2
38
-
39
- // Export to SVG string
40
- const svg = mol.toSVG();
18
+ const mol = Molecule.fromJNMol(jnmolData);
19
+ const atoms = mol.getAtoms();
20
+ const bonds = mol.getBonds();
41
21
  ```
42
22
 
43
- ## API
44
-
45
- ### `new Molecule()`
46
-
47
- Creates an empty molecule instance.
48
-
49
- ### `mol.load(data: unknown)`
50
-
51
- Loads molecular data in JNMol format (atoms with x/y/z coordinates and type, bonds with atom references and order).
52
-
53
- ### `mol.getAtomCount(): number`
54
-
55
- Returns the number of atoms in the molecule.
56
-
57
- ### `mol.getBondCount(): number`
58
-
59
- Returns the number of bonds in the molecule.
60
-
61
- ### `mol.toSVG(options?: SvgExportOptions): string`
62
-
63
- Renders the molecule as an SVG string. Accepts optional display options for bond length, colors, labels, etc.
64
-
65
- ## Peer Dependencies
23
+ ## Features
66
24
 
67
- - `react` (optional) required only for SVG export functionality
25
+ - Molecule data structure with atoms and bonds
26
+ - JNMol format loading
27
+ - SVG export for 2D visualization
28
+ - Molecule state management via store
29
+ - Isomorphic — works in Node.js and browsers
68
30
 
69
31
  ## License
70
32
 
@@ -1,3 +1,6 @@
1
+ import { MoleculeDataFormat } from '../models.js';
1
2
  import type { IMoleculeState } from './reducer.js';
2
- export declare const exportMolecule: (molecule: IMoleculeState, _format: string) => IMoleculeState;
3
+ export declare const exportMolecule: (molecule: IMoleculeState, format: MoleculeDataFormat) => IMoleculeState;
4
+ export declare const selectAtomCount: (state: IMoleculeState) => number;
5
+ export declare const selectBondCount: (state: IMoleculeState) => number;
3
6
  //# sourceMappingURL=selectors.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"selectors.d.ts","sourceRoot":"","sources":["../../src/store/selectors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAEnD,eAAO,MAAM,cAAc,GAAI,UAAU,cAAc,EAAE,SAAS,MAAM,KAAG,cAE1E,CAAC"}
1
+ {"version":3,"file":"selectors.d.ts","sourceRoot":"","sources":["../../src/store/selectors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAEnD,eAAO,MAAM,cAAc,GACzB,UAAU,cAAc,EACxB,QAAQ,kBAAkB,KACzB,cAKF,CAAC;AAEF,eAAO,MAAM,eAAe,GAAI,OAAO,cAAc,KAAG,MAEvD,CAAC;AAEF,eAAO,MAAM,eAAe,GAAI,OAAO,cAAc,KAAG,MAEvD,CAAC"}
@@ -1,4 +1,14 @@
1
- export const exportMolecule = (molecule, _format) => {
2
- return molecule;
1
+ import { MoleculeDataFormat } from '../models.js';
2
+ export const exportMolecule = (molecule, format) => {
3
+ if (format === MoleculeDataFormat.jnmol) {
4
+ return JSON.parse(JSON.stringify(molecule));
5
+ }
6
+ throw new Error(format + ' is not supported');
7
+ };
8
+ export const selectAtomCount = (state) => {
9
+ return Object.keys(state.atoms).length;
10
+ };
11
+ export const selectBondCount = (state) => {
12
+ return Object.keys(state.bonds).length;
3
13
  };
4
14
  //# sourceMappingURL=selectors.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"selectors.js","sourceRoot":"","sources":["../../src/store/selectors.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,QAAwB,EAAE,OAAe,EAAkB,EAAE;IAC1F,OAAO,QAAQ,CAAC;AAClB,CAAC,CAAC"}
1
+ {"version":3,"file":"selectors.js","sourceRoot":"","sources":["../../src/store/selectors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAGlD,MAAM,CAAC,MAAM,cAAc,GAAG,CAC5B,QAAwB,EACxB,MAA0B,EACV,EAAE;IAClB,IAAI,MAAM,KAAK,kBAAkB,CAAC,KAAK,EAAE,CAAC;QACxC,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAmB,CAAC;IAChE,CAAC;IACD,MAAM,IAAI,KAAK,CAAC,MAAM,GAAG,mBAAmB,CAAC,CAAC;AAChD,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,KAAqB,EAAU,EAAE;IAC/D,OAAO,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC;AACzC,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,KAAqB,EAAU,EAAE;IAC/D,OAAO,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC;AACzC,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chemistry/molecule",
3
- "version": "3.1.0",
3
+ "version": "3.1.2",
4
4
  "description": "Molecule",
5
5
  "type": "module",
6
6
  "author": {
@@ -21,7 +21,7 @@
21
21
  "directory": "packages/molecule"
22
22
  },
23
23
  "engines": {
24
- "node": ">=20.0.0"
24
+ "node": ">=22.0.0"
25
25
  },
26
26
  "publishConfig": {
27
27
  "registry": "https://registry.npmjs.org/",