react-cheminfo 0.134.0 → 0.135.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.
- package/README.md +13 -0
- package/lib/crystal/core/bondGrid.d.ts +26 -0
- package/lib/crystal/core/bondGrid.d.ts.map +1 -0
- package/lib/crystal/core/bondGrid.js +76 -0
- package/lib/crystal/core/bondGrid.js.map +1 -0
- package/lib/crystal/core/cellBonds.d.ts +21 -0
- package/lib/crystal/core/cellBonds.d.ts.map +1 -0
- package/lib/crystal/core/cellBonds.js +100 -0
- package/lib/crystal/core/cellBonds.js.map +1 -0
- package/lib/crystal/core/cif/element.d.ts +9 -0
- package/lib/crystal/core/cif/element.d.ts.map +1 -0
- package/lib/crystal/core/cif/element.js +41 -0
- package/lib/crystal/core/cif/element.js.map +1 -0
- package/lib/crystal/core/cif/index.d.ts +4 -0
- package/lib/crystal/core/cif/index.d.ts.map +1 -0
- package/lib/crystal/core/cif/index.js +3 -0
- package/lib/crystal/core/cif/index.js.map +1 -0
- package/lib/crystal/core/cif/number.d.ts +27 -0
- package/lib/crystal/core/cif/number.d.ts.map +1 -0
- package/lib/crystal/core/cif/number.js +57 -0
- package/lib/crystal/core/cif/number.js.map +1 -0
- package/lib/crystal/core/cif/read.d.ts +12 -0
- package/lib/crystal/core/cif/read.d.ts.map +1 -0
- package/lib/crystal/core/cif/read.js +183 -0
- package/lib/crystal/core/cif/read.js.map +1 -0
- package/lib/crystal/core/cif/readGeometry.d.ts +17 -0
- package/lib/crystal/core/cif/readGeometry.d.ts.map +1 -0
- package/lib/crystal/core/cif/readGeometry.js +93 -0
- package/lib/crystal/core/cif/readGeometry.js.map +1 -0
- package/lib/crystal/core/cif/tags.d.ts +62 -0
- package/lib/crystal/core/cif/tags.d.ts.map +1 -0
- package/lib/crystal/core/cif/tags.js +115 -0
- package/lib/crystal/core/cif/tags.js.map +1 -0
- package/lib/crystal/core/cif/types.d.ts +158 -0
- package/lib/crystal/core/cif/types.d.ts.map +1 -0
- package/lib/crystal/core/cif/types.js +2 -0
- package/lib/crystal/core/cif/types.js.map +1 -0
- package/lib/crystal/core/components.d.ts +56 -0
- package/lib/crystal/core/components.d.ts.map +1 -0
- package/lib/crystal/core/components.js +132 -0
- package/lib/crystal/core/components.js.map +1 -0
- package/lib/crystal/core/covalentRadii.d.ts +24 -0
- package/lib/crystal/core/covalentRadii.d.ts.map +1 -0
- package/lib/crystal/core/covalentRadii.js +55 -0
- package/lib/crystal/core/covalentRadii.js.map +1 -0
- package/lib/crystal/core/disorder.d.ts +59 -0
- package/lib/crystal/core/disorder.d.ts.map +1 -0
- package/lib/crystal/core/disorder.js +168 -0
- package/lib/crystal/core/disorder.js.map +1 -0
- package/lib/crystal/core/expand.d.ts +62 -0
- package/lib/crystal/core/expand.d.ts.map +1 -0
- package/lib/crystal/core/expand.js +61 -0
- package/lib/crystal/core/expand.js.map +1 -0
- package/lib/crystal/core/index.d.ts +18 -0
- package/lib/crystal/core/index.d.ts.map +1 -0
- package/lib/crystal/core/index.js +12 -0
- package/lib/crystal/core/index.js.map +1 -0
- package/lib/crystal/core/moleculeOf.d.ts +31 -0
- package/lib/crystal/core/moleculeOf.d.ts.map +1 -0
- package/lib/crystal/core/moleculeOf.js +128 -0
- package/lib/crystal/core/moleculeOf.js.map +1 -0
- package/lib/crystal/core/moleculeTypes.d.ts +80 -0
- package/lib/crystal/core/moleculeTypes.d.ts.map +1 -0
- package/lib/crystal/core/moleculeTypes.js +2 -0
- package/lib/crystal/core/moleculeTypes.js.map +1 -0
- package/lib/crystal/core/molecules.d.ts +39 -0
- package/lib/crystal/core/molecules.d.ts.map +1 -0
- package/lib/crystal/core/molecules.js +140 -0
- package/lib/crystal/core/molecules.js.map +1 -0
- package/lib/crystal/core/operations.d.ts +19 -0
- package/lib/crystal/core/operations.d.ts.map +1 -0
- package/lib/crystal/core/operations.js +68 -0
- package/lib/crystal/core/operations.js.map +1 -0
- package/lib/crystal/core/packing.d.ts +43 -0
- package/lib/crystal/core/packing.d.ts.map +1 -0
- package/lib/crystal/core/packing.js +89 -0
- package/lib/crystal/core/packing.js.map +1 -0
- package/lib/crystal/core/periodicBonds.d.ts +57 -0
- package/lib/crystal/core/periodicBonds.d.ts.map +1 -0
- package/lib/crystal/core/periodicBonds.js +167 -0
- package/lib/crystal/core/periodicBonds.js.map +1 -0
- package/lib/crystal/core/resolve.d.ts +61 -0
- package/lib/crystal/core/resolve.d.ts.map +1 -0
- package/lib/crystal/core/resolve.js +149 -0
- package/lib/crystal/core/resolve.js.map +1 -0
- package/lib/crystal/core/spaceGroups/index.d.ts +5 -0
- package/lib/crystal/core/spaceGroups/index.d.ts.map +1 -0
- package/lib/crystal/core/spaceGroups/index.js +4 -0
- package/lib/crystal/core/spaceGroups/index.js.map +1 -0
- package/lib/crystal/core/spaceGroups/spaceGroupOperations.d.ts +14 -0
- package/lib/crystal/core/spaceGroups/spaceGroupOperations.d.ts.map +1 -0
- package/lib/crystal/core/spaceGroups/spaceGroupOperations.js +24 -0
- package/lib/crystal/core/spaceGroups/spaceGroupOperations.js.map +1 -0
- package/lib/crystal/core/spaceGroups/spaceGroupRows.d.ts +3 -0
- package/lib/crystal/core/spaceGroups/spaceGroupRows.d.ts.map +1 -0
- package/lib/crystal/core/spaceGroups/spaceGroupRows.js +536 -0
- package/lib/crystal/core/spaceGroups/spaceGroupRows.js.map +1 -0
- package/lib/crystal/core/spaceGroups/spaceGroupSymbols.d.ts +43 -0
- package/lib/crystal/core/spaceGroups/spaceGroupSymbols.d.ts.map +1 -0
- package/lib/crystal/core/spaceGroups/spaceGroupSymbols.js +169 -0
- package/lib/crystal/core/spaceGroups/spaceGroupSymbols.js.map +1 -0
- package/lib/crystal/core/spaceGroups/spaceGroups.d.ts +78 -0
- package/lib/crystal/core/spaceGroups/spaceGroups.d.ts.map +1 -0
- package/lib/crystal/core/spaceGroups/spaceGroups.js +83 -0
- package/lib/crystal/core/spaceGroups/spaceGroups.js.map +1 -0
- package/lib/crystal/core/symmetry/group.d.ts +15 -0
- package/lib/crystal/core/symmetry/group.d.ts.map +1 -0
- package/lib/crystal/core/symmetry/group.js +37 -0
- package/lib/crystal/core/symmetry/group.js.map +1 -0
- package/lib/crystal/core/symmetry/index.d.ts +8 -0
- package/lib/crystal/core/symmetry/index.d.ts.map +1 -0
- package/lib/crystal/core/symmetry/index.js +6 -0
- package/lib/crystal/core/symmetry/index.js.map +1 -0
- package/lib/crystal/core/symmetry/integerMatrix.d.ts +45 -0
- package/lib/crystal/core/symmetry/integerMatrix.d.ts.map +1 -0
- package/lib/crystal/core/symmetry/integerMatrix.js +139 -0
- package/lib/crystal/core/symmetry/integerMatrix.js.map +1 -0
- package/lib/crystal/core/symmetry/lattice.d.ts +64 -0
- package/lib/crystal/core/symmetry/lattice.d.ts.map +1 -0
- package/lib/crystal/core/symmetry/lattice.js +113 -0
- package/lib/crystal/core/symmetry/lattice.js.map +1 -0
- package/lib/crystal/core/symmetry/operation.d.ts +91 -0
- package/lib/crystal/core/symmetry/operation.d.ts.map +1 -0
- package/lib/crystal/core/symmetry/operation.js +184 -0
- package/lib/crystal/core/symmetry/operation.js.map +1 -0
- package/lib/crystal/core/symmetry/parseOperation.d.ts +18 -0
- package/lib/crystal/core/symmetry/parseOperation.d.ts.map +1 -0
- package/lib/crystal/core/symmetry/parseOperation.js +145 -0
- package/lib/crystal/core/symmetry/parseOperation.js.map +1 -0
- package/lib/crystal/core/symmetry/types.d.ts +29 -0
- package/lib/crystal/core/symmetry/types.d.ts.map +1 -0
- package/lib/crystal/core/symmetry/types.js +5 -0
- package/lib/crystal/core/symmetry/types.js.map +1 -0
- package/lib/crystal/core/symmetryClasses.d.ts +28 -0
- package/lib/crystal/core/symmetryClasses.d.ts.map +1 -0
- package/lib/crystal/core/symmetryClasses.js +93 -0
- package/lib/crystal/core/symmetryClasses.js.map +1 -0
- package/lib/crystal.d.ts +12 -0
- package/lib/crystal.d.ts.map +1 -0
- package/lib/crystal.js +12 -0
- package/lib/crystal.js.map +1 -0
- package/lib/server/spaSite.d.ts.map +1 -1
- package/lib/server/spaSite.js +9 -0
- package/lib/server/spaSite.js.map +1 -1
- package/package.json +3 -1
- package/src/crystal/core/bondGrid.ts +98 -0
- package/src/crystal/core/cellBonds.ts +121 -0
- package/src/crystal/core/cif/element.ts +40 -0
- package/src/crystal/core/cif/index.ts +12 -0
- package/src/crystal/core/cif/number.ts +62 -0
- package/src/crystal/core/cif/read.ts +218 -0
- package/src/crystal/core/cif/readGeometry.ts +104 -0
- package/src/crystal/core/cif/tags.ts +143 -0
- package/src/crystal/core/cif/types.ts +164 -0
- package/src/crystal/core/components.ts +183 -0
- package/src/crystal/core/covalentRadii.ts +56 -0
- package/src/crystal/core/disorder.ts +190 -0
- package/src/crystal/core/expand.ts +105 -0
- package/src/crystal/core/index.ts +44 -0
- package/src/crystal/core/moleculeOf.ts +169 -0
- package/src/crystal/core/moleculeTypes.ts +85 -0
- package/src/crystal/core/molecules.ts +165 -0
- package/src/crystal/core/operations.ts +79 -0
- package/src/crystal/core/packing.ts +116 -0
- package/src/crystal/core/periodicBonds.ts +234 -0
- package/src/crystal/core/resolve.ts +187 -0
- package/src/crystal/core/spaceGroups/index.ts +16 -0
- package/src/crystal/core/spaceGroups/spaceGroupOperations.ts +32 -0
- package/src/crystal/core/spaceGroups/spaceGroupRows.ts +536 -0
- package/src/crystal/core/spaceGroups/spaceGroupSymbols.ts +179 -0
- package/src/crystal/core/spaceGroups/spaceGroups.ts +154 -0
- package/src/crystal/core/symmetry/group.ts +42 -0
- package/src/crystal/core/symmetry/index.ts +23 -0
- package/src/crystal/core/symmetry/integerMatrix.ts +153 -0
- package/src/crystal/core/symmetry/lattice.ts +152 -0
- package/src/crystal/core/symmetry/operation.ts +223 -0
- package/src/crystal/core/symmetry/parseOperation.ts +180 -0
- package/src/crystal/core/symmetry/types.ts +32 -0
- package/src/crystal/core/symmetryClasses.ts +105 -0
- package/src/crystal.ts +12 -0
- package/src/server/spaSite.ts +9 -0
package/README.md
CHANGED
|
@@ -43,6 +43,7 @@ only when it drags a heavy dependency behind it.
|
|
|
43
43
|
| `react-cheminfo/molecule3d` | the 3D molecule viewer and its toolbar | React, molstar |
|
|
44
44
|
| `react-cheminfo/structure` | the structure editor and renderer | React, react-ocl, OCL |
|
|
45
45
|
| `react-cheminfo/conformers` | conformer generation, ranking and refinement | OCL |
|
|
46
|
+
| `react-cheminfo/crystal` | a CIF read, expanded by its space group, cut into molecules | cif-to-json; Node and browser |
|
|
46
47
|
| `react-cheminfo/slides` | the deck format and the slideshow player | React, react-markdown |
|
|
47
48
|
| `react-cheminfo/spectra` | the spectra processing settings editors | React; types only from spectra-processor, ml-pca |
|
|
48
49
|
| `react-cheminfo/ir` | the infrared chart, band table and editor | React, ir-spectrum, convert-to-jcamp |
|
|
@@ -125,6 +126,18 @@ so the code choosing a relaxer loads neither openchemlib nor WebAssembly; `xtbRe
|
|
|
125
126
|
`import()`s `xtb-wasm` on the **first call**, so a site that offers refinement as
|
|
126
127
|
an action still ships nothing extra to a visitor who never clicks it.
|
|
127
128
|
|
|
129
|
+
`react-cheminfo/crystal` reads a crystal structure and cuts its cell into
|
|
130
|
+
molecules, in the browser or in a Node batch over a whole database: `readCif`
|
|
131
|
+
reads a CIF — the asymmetric unit with its disorder groups, and the bond
|
|
132
|
+
distances and torsion angles the authors reported — `structureOperations`
|
|
133
|
+
finds the space group's operations in the file or in the 230 groups it names,
|
|
134
|
+
and `crystalMolecules` returns each crystallographically independent molecule
|
|
135
|
+
once and whole, in Cartesian coordinates with its bonds, and reports a salt, a
|
|
136
|
+
mineral or a framework as the network it is. Bonds follow openchemlib's rule —
|
|
137
|
+
covalent radii plus 0.45 Å — with metals bonded too, and the cell is searched
|
|
138
|
+
on a grid, so a cell of thousands of atoms costs milliseconds. It loads neither
|
|
139
|
+
React nor openchemlib nor molstar.
|
|
140
|
+
|
|
128
141
|
`react-cheminfo/storage` is what a site needs so a crash loses nothing:
|
|
129
142
|
`openSiteDatabase` opens IndexedDB through `idb` and turns a blocked upgrade or
|
|
130
143
|
a browser refusing storage into an error rather than a hang; `createAutosave`
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { PackedAtom } from './periodicBonds.ts';
|
|
2
|
+
import type { Lattice } from './symmetry/lattice.ts';
|
|
3
|
+
/** The atoms of each bin, and the bin each atom falls in. */
|
|
4
|
+
export interface Grid {
|
|
5
|
+
/** Bins along a, b and c. */
|
|
6
|
+
readonly counts: readonly [number, number, number];
|
|
7
|
+
/** How many bins away along each axis a bond can reach. */
|
|
8
|
+
readonly reaches: readonly [number, number, number];
|
|
9
|
+
/** `start[bin]` to `start[bin + 1]` index the atoms of a bin in `members`. */
|
|
10
|
+
readonly start: Int32Array;
|
|
11
|
+
readonly members: Int32Array;
|
|
12
|
+
/** The bin of each atom, three indices per atom. */
|
|
13
|
+
readonly cells: Int32Array;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Bin the atoms of a cell on a grid of the cell itself.
|
|
17
|
+
*
|
|
18
|
+
* A bin holds about one atom and is never thinner than a bond, so a dense cell
|
|
19
|
+
* is not compared pair by pair and a sparse one is not cut into empty bins.
|
|
20
|
+
* @param atoms - The atoms, fractional, wrapped into [0, 1).
|
|
21
|
+
* @param lattice - The cell.
|
|
22
|
+
* @param reach - The longest bond searched for, Å.
|
|
23
|
+
* @returns The bins, and how many of them a bond can reach along each axis.
|
|
24
|
+
*/
|
|
25
|
+
export declare function createGrid(atoms: readonly PackedAtom[], lattice: Lattice, reach: number): Grid;
|
|
26
|
+
//# sourceMappingURL=bondGrid.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bondGrid.d.ts","sourceRoot":"","sources":["../../../src/crystal/core/bondGrid.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAErD,6DAA6D;AAC7D,MAAM,WAAW,IAAI;IACnB,6BAA6B;IAC7B,QAAQ,CAAC,MAAM,EAAE,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;IACnD,2DAA2D;IAC3D,QAAQ,CAAC,OAAO,EAAE,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;IACpD,8EAA8E;IAC9E,QAAQ,CAAC,KAAK,EAAE,UAAU,CAAC;IAC3B,QAAQ,CAAC,OAAO,EAAE,UAAU,CAAC;IAC7B,oDAAoD;IACpD,QAAQ,CAAC,KAAK,EAAE,UAAU,CAAC;CAC5B;AAED;;;;;;;;;GASG;AACH,wBAAgB,UAAU,CACxB,KAAK,EAAE,SAAS,UAAU,EAAE,EAC5B,OAAO,EAAE,OAAO,EAChB,KAAK,EAAE,MAAM,GACZ,IAAI,CAwCN"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bin the atoms of a cell on a grid of the cell itself.
|
|
3
|
+
*
|
|
4
|
+
* A bin holds about one atom and is never thinner than a bond, so a dense cell
|
|
5
|
+
* is not compared pair by pair and a sparse one is not cut into empty bins.
|
|
6
|
+
* @param atoms - The atoms, fractional, wrapped into [0, 1).
|
|
7
|
+
* @param lattice - The cell.
|
|
8
|
+
* @param reach - The longest bond searched for, Å.
|
|
9
|
+
* @returns The bins, and how many of them a bond can reach along each axis.
|
|
10
|
+
*/
|
|
11
|
+
export function createGrid(atoms, lattice, reach) {
|
|
12
|
+
const count = atoms.length;
|
|
13
|
+
const spacing = Math.max(reach, Math.cbrt(lattice.volume / count));
|
|
14
|
+
const widths = planeSpacings(lattice);
|
|
15
|
+
const counts = [1, 1, 1];
|
|
16
|
+
const reaches = [1, 1, 1];
|
|
17
|
+
for (let axis = 0; axis < 3; axis++) {
|
|
18
|
+
const width = widths[axis] ?? 1;
|
|
19
|
+
const bins = Math.max(1, Math.floor(width / spacing));
|
|
20
|
+
counts[axis] = bins;
|
|
21
|
+
reaches[axis] = Math.max(1, Math.ceil((reach * bins) / width - 1e-9));
|
|
22
|
+
}
|
|
23
|
+
const [na, nb, nc] = counts;
|
|
24
|
+
const cells = new Int32Array(count * 3);
|
|
25
|
+
const binOf = new Int32Array(count);
|
|
26
|
+
const start = new Int32Array(na * nb * nc + 1);
|
|
27
|
+
for (let index = 0; index < count; index++) {
|
|
28
|
+
const position = atoms[index].position;
|
|
29
|
+
for (let axis = 0; axis < 3; axis++) {
|
|
30
|
+
const bins = counts[axis] ?? 1;
|
|
31
|
+
const value = Math.floor((position[axis] ?? 0) * bins);
|
|
32
|
+
cells[index * 3 + axis] = Math.min(bins - 1, Math.max(0, value));
|
|
33
|
+
}
|
|
34
|
+
const bin = ((cells[index * 3] ?? 0) * nb + (cells[index * 3 + 1] ?? 0)) * nc +
|
|
35
|
+
(cells[index * 3 + 2] ?? 0);
|
|
36
|
+
binOf[index] = bin;
|
|
37
|
+
start[bin + 1] = (start[bin + 1] ?? 0) + 1;
|
|
38
|
+
}
|
|
39
|
+
for (let bin = 0; bin < na * nb * nc; bin++) {
|
|
40
|
+
start[bin + 1] = (start[bin + 1] ?? 0) + (start[bin] ?? 0);
|
|
41
|
+
}
|
|
42
|
+
const cursor = start.slice(0, -1);
|
|
43
|
+
const members = new Int32Array(count);
|
|
44
|
+
for (let index = 0; index < count; index++) {
|
|
45
|
+
const bin = binOf[index] ?? 0;
|
|
46
|
+
members[cursor[bin] ?? 0] = index;
|
|
47
|
+
cursor[bin] = (cursor[bin] ?? 0) + 1;
|
|
48
|
+
}
|
|
49
|
+
return { counts, reaches, start, members, cells };
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* The distance between consecutive lattice planes normal to each axis, Å.
|
|
53
|
+
* @param lattice - The cell.
|
|
54
|
+
* @returns The spacings normal to a, b and c.
|
|
55
|
+
*/
|
|
56
|
+
function planeSpacings(lattice) {
|
|
57
|
+
const m = lattice.cartesian;
|
|
58
|
+
const column = (index) => [
|
|
59
|
+
m[0]?.[index] ?? 0,
|
|
60
|
+
m[1]?.[index] ?? 0,
|
|
61
|
+
m[2]?.[index] ?? 0,
|
|
62
|
+
];
|
|
63
|
+
const [a, b, c] = [column(0), column(1), column(2)];
|
|
64
|
+
return [
|
|
65
|
+
lattice.volume / crossLength(b, c),
|
|
66
|
+
lattice.volume / crossLength(c, a),
|
|
67
|
+
lattice.volume / crossLength(a, b),
|
|
68
|
+
];
|
|
69
|
+
}
|
|
70
|
+
function crossLength(u, v) {
|
|
71
|
+
const x = (u[1] ?? 0) * (v[2] ?? 0) - (u[2] ?? 0) * (v[1] ?? 0);
|
|
72
|
+
const y = (u[2] ?? 0) * (v[0] ?? 0) - (u[0] ?? 0) * (v[2] ?? 0);
|
|
73
|
+
const z = (u[0] ?? 0) * (v[1] ?? 0) - (u[1] ?? 0) * (v[0] ?? 0);
|
|
74
|
+
return Math.hypot(x, y, z);
|
|
75
|
+
}
|
|
76
|
+
//# sourceMappingURL=bondGrid.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bondGrid.js","sourceRoot":"","sources":["../../../src/crystal/core/bondGrid.ts"],"names":[],"mappings":"AAgBA;;;;;;;;;GASG;AACH,MAAM,UAAU,UAAU,CACxB,KAA4B,EAC5B,OAAgB,EAChB,KAAa;IAEb,MAAM,KAAK,GAAG,KAAK,CAAC,MAAM,CAAC;IAC3B,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,GAAG,KAAK,CAAC,CAAC,CAAC;IACnE,MAAM,MAAM,GAAG,aAAa,CAAC,OAAO,CAAC,CAAC;IACtC,MAAM,MAAM,GAA6B,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;IACnD,MAAM,OAAO,GAA6B,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;IACpD,KAAK,IAAI,IAAI,GAAG,CAAC,EAAE,IAAI,GAA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AI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;IAChE,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;IAChE,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;IAChE,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;AAC7B,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { CrystalSite } from './cif/types.ts';
|
|
2
|
+
import type { ExpandedAtom } from './expand.ts';
|
|
3
|
+
import type { PeriodicPairs } from './periodicBonds.ts';
|
|
4
|
+
/**
|
|
5
|
+
* The atoms to drop because another one already stands in their place.
|
|
6
|
+
* @param atoms - The atoms of one cell.
|
|
7
|
+
* @param coincident - The pairs of atoms closer than an atom to itself.
|
|
8
|
+
* @returns One flag per atom, 1 for an atom dropped.
|
|
9
|
+
*/
|
|
10
|
+
export declare function writtenTwice(atoms: readonly ExpandedAtom[], coincident: Int32Array): Uint8Array;
|
|
11
|
+
/**
|
|
12
|
+
* The pairs kept as bonds: none to an atom dropped, none between the copies of
|
|
13
|
+
* a disorder about a special position, and one per hydrogen.
|
|
14
|
+
* @param pairs - The bonded pairs of the cell.
|
|
15
|
+
* @param atoms - The atoms of the cell.
|
|
16
|
+
* @param sites - The asymmetric unit.
|
|
17
|
+
* @param removed - One flag per atom, 1 for an atom dropped.
|
|
18
|
+
* @returns One flag per pair, 1 to keep it.
|
|
19
|
+
*/
|
|
20
|
+
export declare function keptPairs(pairs: PeriodicPairs, atoms: readonly ExpandedAtom[], sites: readonly CrystalSite[], removed: Uint8Array): Uint8Array;
|
|
21
|
+
//# sourceMappingURL=cellBonds.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cellBonds.d.ts","sourceRoot":"","sources":["../../../src/crystal/core/cellBonds.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAElD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAExD;;;;;GAKG;AACH,wBAAgB,YAAY,CAC1B,KAAK,EAAE,SAAS,YAAY,EAAE,EAC9B,UAAU,EAAE,UAAU,GACrB,UAAU,CAYZ;AAED;;;;;;;;GAQG;AACH,wBAAgB,SAAS,CACvB,KAAK,EAAE,aAAa,EACpB,KAAK,EAAE,SAAS,YAAY,EAAE,EAC9B,KAAK,EAAE,SAAS,WAAW,EAAE,EAC7B,OAAO,EAAE,UAAU,GAClB,UAAU,CAWZ"}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { disorderGroupOf } from "./disorder.js";
|
|
2
|
+
/**
|
|
3
|
+
* The atoms to drop because another one already stands in their place.
|
|
4
|
+
* @param atoms - The atoms of one cell.
|
|
5
|
+
* @param coincident - The pairs of atoms closer than an atom to itself.
|
|
6
|
+
* @returns One flag per atom, 1 for an atom dropped.
|
|
7
|
+
*/
|
|
8
|
+
export function writtenTwice(atoms, coincident) {
|
|
9
|
+
const removed = new Uint8Array(atoms.length);
|
|
10
|
+
for (let pair = 0; pair < coincident.length; pair += 2) {
|
|
11
|
+
const first = coincident[pair] ?? 0;
|
|
12
|
+
const second = coincident[pair + 1] ?? 0;
|
|
13
|
+
if (removed[first] === 1 || removed[second] === 1)
|
|
14
|
+
continue;
|
|
15
|
+
const higher = atoms[second].occupancy >
|
|
16
|
+
atoms[first].occupancy;
|
|
17
|
+
removed[higher ? first : second] = 1;
|
|
18
|
+
}
|
|
19
|
+
return removed;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* The pairs kept as bonds: none to an atom dropped, none between the copies of
|
|
23
|
+
* a disorder about a special position, and one per hydrogen.
|
|
24
|
+
* @param pairs - The bonded pairs of the cell.
|
|
25
|
+
* @param atoms - The atoms of the cell.
|
|
26
|
+
* @param sites - The asymmetric unit.
|
|
27
|
+
* @param removed - One flag per atom, 1 for an atom dropped.
|
|
28
|
+
* @returns One flag per pair, 1 to keep it.
|
|
29
|
+
*/
|
|
30
|
+
export function keptPairs(pairs, atoms, sites, removed) {
|
|
31
|
+
const keep = new Uint8Array(pairs.count);
|
|
32
|
+
for (let pair = 0; pair < pairs.count; pair++) {
|
|
33
|
+
const first = pairs.from[pair] ?? 0;
|
|
34
|
+
const second = pairs.to[pair] ?? 0;
|
|
35
|
+
if (removed[first] === 1 || removed[second] === 1)
|
|
36
|
+
continue;
|
|
37
|
+
if (keptApart(atoms[first], atoms[second], sites))
|
|
38
|
+
continue;
|
|
39
|
+
keep[pair] = 1;
|
|
40
|
+
}
|
|
41
|
+
keepNearestToHydrogen(pairs, atoms, keep);
|
|
42
|
+
return keep;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Whether two atoms are copies of a disorder that lies about a special
|
|
46
|
+
* position — a negative group, as SHELX writes it — made by different
|
|
47
|
+
* operations: such copies overlap on purpose, and are never bonded.
|
|
48
|
+
* @param a - One atom of the cell.
|
|
49
|
+
* @param b - Another one.
|
|
50
|
+
* @param sites - The asymmetric unit.
|
|
51
|
+
* @returns Whether they are kept apart.
|
|
52
|
+
*/
|
|
53
|
+
function keptApart(a, b, sites) {
|
|
54
|
+
if (a === undefined || b === undefined)
|
|
55
|
+
return false;
|
|
56
|
+
if (a.operationIndex === b.operationIndex)
|
|
57
|
+
return false;
|
|
58
|
+
const groupA = disorderGroupOf(sites[a.siteIndex]);
|
|
59
|
+
const groupB = disorderGroupOf(sites[b.siteIndex]);
|
|
60
|
+
return (groupA !== null &&
|
|
61
|
+
groupB !== null &&
|
|
62
|
+
(groupA.startsWith('-') || groupB.startsWith('-')));
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* A hydrogen holds one bond, to its nearest neighbour: one sitting between two
|
|
66
|
+
* oxygens of a short hydrogen bond would otherwise chain the molecules.
|
|
67
|
+
* @param pairs - The bonded pairs of the cell.
|
|
68
|
+
* @param atoms - The atoms of the cell.
|
|
69
|
+
* @param keep - One flag per pair, cleared where a hydrogen has a nearer partner.
|
|
70
|
+
*/
|
|
71
|
+
function keepNearestToHydrogen(pairs, atoms, keep) {
|
|
72
|
+
const nearest = new Int32Array(atoms.length).fill(-1);
|
|
73
|
+
for (let pair = 0; pair < pairs.count; pair++) {
|
|
74
|
+
if (keep[pair] === 0)
|
|
75
|
+
continue;
|
|
76
|
+
for (let side = 0; side < 2; side++) {
|
|
77
|
+
const atom = (side === 0 ? pairs.from[pair] : pairs.to[pair]) ?? 0;
|
|
78
|
+
if (atoms[atom].element !== 'H')
|
|
79
|
+
continue;
|
|
80
|
+
const best = nearest[atom] ?? -1;
|
|
81
|
+
if (best === -1 ||
|
|
82
|
+
(pairs.lengths[pair] ?? 0) < (pairs.lengths[best] ?? 0)) {
|
|
83
|
+
nearest[atom] = pair;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
for (let pair = 0; pair < pairs.count; pair++) {
|
|
88
|
+
if (keep[pair] === 0)
|
|
89
|
+
continue;
|
|
90
|
+
const from = pairs.from[pair] ?? 0;
|
|
91
|
+
const to = pairs.to[pair] ?? 0;
|
|
92
|
+
const fromHydrogen = atoms[from].element === 'H';
|
|
93
|
+
const toHydrogen = atoms[to].element === 'H';
|
|
94
|
+
if ((fromHydrogen && nearest[from] !== pair) ||
|
|
95
|
+
(toHydrogen && nearest[to] !== pair)) {
|
|
96
|
+
keep[pair] = 0;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
//# sourceMappingURL=cellBonds.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cellBonds.js","sourceRoot":"","sources":["../../../src/crystal/core/cellBonds.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAIhD;;;;;GAKG;AACH,MAAM,UAAU,YAAY,CAC1B,KAA8B,EAC9B,UAAsB;IAEtB,MAAM,OAAO,GAAG,IAAI,UAAU,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IAC7C,KAAK,IAAI,IAAI,GAAG,CAAC,EAAE,IAAI,GAAG,UAAU,CAAC,MAAM,EAAE,IAAI,IAAI,CAAC,EAAE,CAAC;QACvD,MAAM,KAAK,GAAG,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACpC,MAAM,MAAM,GAAG,UAAU,CAAC,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC;QACzC,IAAI,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC;YAAE,SAAS;QAC5D,MAAM,MAAM,GACT,KAAK,CAAC,MAAM,CAAkB,CAAC,SAAS;YACxC,KAAK,CAAC,KAAK,CAAkB,CAAC,SAAS,CAAC;QAC3C,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IACvC,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,SAAS,CACvB,KAAoB,EACpB,KAA8B,EAC9B,KAA6B,EAC7B,OAAmB;IAEnB,MAAM,IAAI,GAAG,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MAAM,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACnC,MAAM,EAAE,GAAG,KAAK,CAAC,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC/B,MAAM,YAAY,GAAI,KAAK,CAAC,IAAI,CAAkB,CAAC,OAAO,KAAK,GAAG,CAAC;QACnE,MAAM,UAAU,GAAI,KAAK,CAAC,EAAE,CAAkB,CAAC,OAAO,KAAK,GAAG,CAAC;QAC/D,IACE,CAAC,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC,KAAK,IAAI,CAAC;YACxC,CAAC,UAAU,IAAI,OAAO,CAAC,EAAE,CAAC,KAAK,IAAI,CAAC,EACpC,CAAC;YACD,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACjB,CAAC;IACH,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Read the element of an atom site: the type symbol's, else the label's.
|
|
3
|
+
* @param typeSymbol - `_atom_site_type_symbol`, or `null` when absent.
|
|
4
|
+
* @param label - `_atom_site_label`.
|
|
5
|
+
* @returns The chemical symbol.
|
|
6
|
+
* @throws {Error} When neither opens with an element symbol.
|
|
7
|
+
*/
|
|
8
|
+
export declare function elementOf(typeSymbol: string | null, label: string): string;
|
|
9
|
+
//# sourceMappingURL=element.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"element.d.ts","sourceRoot":"","sources":["../../../../src/crystal/core/cif/element.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AACH,wBAAgB,SAAS,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAQ1E"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { elementBySymbol } from "../../../periodic/core/elements.js";
|
|
2
|
+
/**
|
|
3
|
+
* Read the element of an atom site: the type symbol's, else the label's.
|
|
4
|
+
* @param typeSymbol - `_atom_site_type_symbol`, or `null` when absent.
|
|
5
|
+
* @param label - `_atom_site_label`.
|
|
6
|
+
* @returns The chemical symbol.
|
|
7
|
+
* @throws {Error} When neither opens with an element symbol.
|
|
8
|
+
*/
|
|
9
|
+
export function elementOf(typeSymbol, label) {
|
|
10
|
+
const fromType = typeSymbol === null ? null : symbolOf(typeSymbol);
|
|
11
|
+
if (fromType !== null)
|
|
12
|
+
return fromType;
|
|
13
|
+
const fromLabel = symbolOf(label);
|
|
14
|
+
if (fromLabel !== null)
|
|
15
|
+
return fromLabel;
|
|
16
|
+
throw new Error(`Atom site "${label}" names no element: neither its type symbol nor its label opens with one.`);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Read the chemical symbol a CIF token opens with.
|
|
20
|
+
*
|
|
21
|
+
* A type symbol carries the oxidation state (`Na1+`, `Cl1-`) and a label
|
|
22
|
+
* carries an index in whatever case the refinement wrote it (`NA1`, `CL2`), so
|
|
23
|
+
* the letters are taken, recapitalised and checked against the periodic table.
|
|
24
|
+
* Deuterium, which a neutron structure writes `D`, is hydrogen.
|
|
25
|
+
* @param token - a type symbol or an atom-site label.
|
|
26
|
+
* @returns the symbol, or `null` when the letters name no element.
|
|
27
|
+
*/
|
|
28
|
+
function symbolOf(token) {
|
|
29
|
+
const letters = /^(?<letters>[A-Za-z]{1,2})/.exec(token)?.groups?.letters;
|
|
30
|
+
if (letters === undefined)
|
|
31
|
+
return null;
|
|
32
|
+
for (let length = letters.length; length >= 1; length--) {
|
|
33
|
+
const symbol = letters.charAt(0).toUpperCase() + letters.slice(1, length).toLowerCase();
|
|
34
|
+
if (elementBySymbol(symbol) !== undefined)
|
|
35
|
+
return symbol;
|
|
36
|
+
if (symbol === 'D')
|
|
37
|
+
return 'H';
|
|
38
|
+
}
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=element.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"element.js","sourceRoot":"","sources":["../../../../src/crystal/core/cif/element.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,oCAAoC,CAAC;AAErE;;;;;;GAMG;AACH,MAAM,UAAU,SAAS,CAAC,UAAyB,EAAE,KAAa;IAChE,MAAM,QAAQ,GAAG,UAAU,KAAK,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC;IACnE,IAAI,QAAQ,KAAK,IAAI;QAAE,OAAO,QAAQ,CAAC;IACvC,MAAM,SAAS,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;IAClC,IAAI,SAAS,KAAK,IAAI;QAAE,OAAO,SAAS,CAAC;IACzC,MAAM,IAAI,KAAK,CACb,cAAc,KAAK,2EAA2E,CAC/F,CAAC;AACJ,CAAC;AAED;;;;;;;;;GASG;AACH,SAAS,QAAQ,CAAC,KAAa;IAC7B,MAAM,OAAO,GAAG,4BAA4B,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC;IAC1E,IAAI,OAAO,KAAK,SAAS;QAAE,OAAO,IAAI,CAAC;IACvC,KAAK,IAAI,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,MAAM,IAAI,CAAC,EAAE,MAAM,EAAE,EAAE,CAAC;QACxD,MAAM,MAAM,GACV,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,WAAW,EAAE,CAAC;QAC3E,IAAI,eAAe,CAAC,MAAM,CAAC,KAAK,SAAS;YAAE,OAAO,MAAM,CAAC;QACzD,IAAI,MAAM,KAAK,GAAG;YAAE,OAAO,GAAG,CAAC;IACjC,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { formatCifNumber, formatNumber, parseCifNumber } from './number.ts';
|
|
2
|
+
export { readCif } from './read.ts';
|
|
3
|
+
export type { CifGeometryBond, CifGeometryTorsion, CifNumber, CrystalCell, CrystalSite, CrystalSource, CrystalSpaceGroup, CrystalStructure, } from './types.ts';
|
|
4
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/crystal/core/cif/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC5E,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,YAAY,EACV,eAAe,EACf,kBAAkB,EAClB,SAAS,EACT,WAAW,EACX,WAAW,EACX,aAAa,EACb,iBAAiB,EACjB,gBAAgB,GACjB,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/crystal/core/cif/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC5E,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { CifNumber } from './types.ts';
|
|
2
|
+
/**
|
|
3
|
+
* Read a CIF numeric token.
|
|
4
|
+
*
|
|
5
|
+
* `cif-to-json` never converts anything: every field arrives as a string, with
|
|
6
|
+
* the standard uncertainty still attached and with `.` and `?` already
|
|
7
|
+
* collapsed to the empty string.
|
|
8
|
+
* @param token - the raw field, e.g. `0.30475(3)`, `90`, `.5`, `-1.5e2`, `.`, `?` or ``.
|
|
9
|
+
* @returns the number, or `null` when the field is absent, unknown or not a number.
|
|
10
|
+
*/
|
|
11
|
+
export declare function parseCifNumber(token: string | null | undefined): CifNumber | null;
|
|
12
|
+
/**
|
|
13
|
+
* Write a CIF numeric token, re-attaching the standard uncertainty.
|
|
14
|
+
* @param number - the value to write.
|
|
15
|
+
* @returns `0.30475(3)` for `{ value: 0.30475, su: 0.00003 }`.
|
|
16
|
+
*/
|
|
17
|
+
export declare function formatCifNumber(number: CifNumber): string;
|
|
18
|
+
/**
|
|
19
|
+
* Write a plain number the way a CIF field wants it.
|
|
20
|
+
*
|
|
21
|
+
* `String` gives the shortest text that reads back as the same double, so a
|
|
22
|
+
* value written here and read by `parseCifNumber` is bit-identical.
|
|
23
|
+
* @param value - the value to write.
|
|
24
|
+
* @returns the field text.
|
|
25
|
+
*/
|
|
26
|
+
export declare function formatNumber(value: number): string;
|
|
27
|
+
//# sourceMappingURL=number.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"number.d.ts","sourceRoot":"","sources":["../../../../src/crystal/core/cif/number.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAE5C;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAC5B,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAC/B,SAAS,GAAG,IAAI,CAkBlB;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,SAAS,GAAG,MAAM,CAMzD;AAED;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAElD"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Read a CIF numeric token.
|
|
3
|
+
*
|
|
4
|
+
* `cif-to-json` never converts anything: every field arrives as a string, with
|
|
5
|
+
* the standard uncertainty still attached and with `.` and `?` already
|
|
6
|
+
* collapsed to the empty string.
|
|
7
|
+
* @param token - the raw field, e.g. `0.30475(3)`, `90`, `.5`, `-1.5e2`, `.`, `?` or ``.
|
|
8
|
+
* @returns the number, or `null` when the field is absent, unknown or not a number.
|
|
9
|
+
*/
|
|
10
|
+
export function parseCifNumber(token) {
|
|
11
|
+
if (token === null || token === undefined)
|
|
12
|
+
return null;
|
|
13
|
+
const raw = token.trim();
|
|
14
|
+
if (MISSING.has(raw))
|
|
15
|
+
return null;
|
|
16
|
+
const match = NUMBER.exec(raw);
|
|
17
|
+
if (match?.groups === undefined)
|
|
18
|
+
return null;
|
|
19
|
+
const { sign, mantissa, digits, exponent } = match.groups;
|
|
20
|
+
if (mantissa === undefined)
|
|
21
|
+
return null;
|
|
22
|
+
const power = exponent === undefined ? 0 : Number(exponent);
|
|
23
|
+
const value = Number(`${sign ?? ''}${mantissa}e${power}`);
|
|
24
|
+
if (!Number.isFinite(value))
|
|
25
|
+
return null;
|
|
26
|
+
const dot = mantissa.indexOf('.');
|
|
27
|
+
const decimals = dot === -1 ? 0 : mantissa.length - dot - 1;
|
|
28
|
+
const su = digits === undefined ? null : Number(`${digits}e${power - decimals}`);
|
|
29
|
+
return { value, su, raw };
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Write a CIF numeric token, re-attaching the standard uncertainty.
|
|
33
|
+
* @param number - the value to write.
|
|
34
|
+
* @returns `0.30475(3)` for `{ value: 0.30475, su: 0.00003 }`.
|
|
35
|
+
*/
|
|
36
|
+
export function formatCifNumber(number) {
|
|
37
|
+
const text = formatNumber(number.value);
|
|
38
|
+
if (number.su === null)
|
|
39
|
+
return text;
|
|
40
|
+
const dot = text.indexOf('.');
|
|
41
|
+
const decimals = dot === -1 ? 0 : text.length - dot - 1;
|
|
42
|
+
return `${text}(${Math.round(number.su * 10 ** decimals)})`;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Write a plain number the way a CIF field wants it.
|
|
46
|
+
*
|
|
47
|
+
* `String` gives the shortest text that reads back as the same double, so a
|
|
48
|
+
* value written here and read by `parseCifNumber` is bit-identical.
|
|
49
|
+
* @param value - the value to write.
|
|
50
|
+
* @returns the field text.
|
|
51
|
+
*/
|
|
52
|
+
export function formatNumber(value) {
|
|
53
|
+
return Object.is(value, -0) ? '0' : String(value);
|
|
54
|
+
}
|
|
55
|
+
const MISSING = new Set(['', '.', '?']);
|
|
56
|
+
const NUMBER = /^(?<sign>[+-]?)(?<mantissa>\d+\.?\d*|\.\d+)(?:\((?<digits>\d+)\))?(?:[Ee](?<exponent>[+-]?\d+))?$/;
|
|
57
|
+
//# sourceMappingURL=number.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"number.js","sourceRoot":"","sources":["../../../../src/crystal/core/cif/number.ts"],"names":[],"mappings":"AAEA;;;;;;;;GAQG;AACH,MAAM,UAAU,cAAc,CAC5B,KAAgC;IAEhC,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS;QAAE,OAAO,IAAI,CAAC;IACvD,MAAM,GAAG,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC;IACzB,IAAI,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC;QAAE,OAAO,IAAI,CAAC;IAClC,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC/B,IAAI,KAAK,EAAE,MAAM,KAAK,SAAS;QAAE,OAAO,IAAI,CAAC;IAE7C,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,KAAK,CAAC,MAAM,CAAC;IAC1D,IAAI,QAAQ,KAAK,SAAS;QAAE,OAAO,IAAI,CAAC;IACxC,MAAM,KAAK,GAAG,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IAC5D,MAAM,KAAK,GAAG,MAAM,CAAC,GAAG,IAAI,IAAI,EAAE,GAAG,QAAQ,IAAI,KAAK,EAAE,CAAC,CAAC;IAC1D,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC;IAEzC,MAAM,GAAG,GAAG,QAAQ,CAA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M,GACV,mGAAmG,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { CrystalStructure } from './types.ts';
|
|
2
|
+
/**
|
|
3
|
+
* Read one crystal structure from a CIF.
|
|
4
|
+
* @param text - CIF file content, one `data_` block.
|
|
5
|
+
* @returns the structure, with every value converted from the strings
|
|
6
|
+
* `cif-to-json` returns. `geometryBonds` and `geometryTorsions` are present
|
|
7
|
+
* only when the file carries the loop.
|
|
8
|
+
* @throws {Error} when the file holds more than one data block, carries no unit cell,
|
|
9
|
+
* or names an atom whose element cannot be read.
|
|
10
|
+
*/
|
|
11
|
+
export declare function readCif(text: string): CrystalStructure;
|
|
12
|
+
//# sourceMappingURL=read.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"read.d.ts","sourceRoot":"","sources":["../../../../src/crystal/core/cif/read.ts"],"names":[],"mappings":"AAiBA,OAAO,KAAK,EAKV,gBAAgB,EACjB,MAAM,YAAY,CAAC;AAEpB;;;;;;;;GAQG;AACH,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,gBAAgB,CAyBtD"}
|