@synlexa/wasm-bridge 0.0.0-stage → 0.4.3
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/ABI.md +92 -0
- package/LICENSE +201 -0
- package/NOTICE +72 -0
- package/README.md +31 -2
- package/package.json +20 -4
- package/src/index.ts +2 -0
- package/src/types.ts +429 -0
- package/src/wasmLoader.ts +222 -0
- package/wasm/synlexa_bio_core.wasm +0 -0
package/ABI.md
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
# Synlexa Studio Wasm ABI Contract v1 (`synlexa_bio_core.wasm`)
|
|
2
|
+
|
|
3
|
+
Target: `wasm32-unknown-unknown` (`crates/studio-wasm`, compiled to `apps/web/public/wasm/synlexa_bio_core.wasm`)
|
|
4
|
+
All functions operate deterministically with zero network/filesystem/DOM dependencies and return UTF-8 JSON payloads (and typed float64/uint32 coordinate buffers where requested).
|
|
5
|
+
|
|
6
|
+
## Exported Linear-Memory ABI Functions
|
|
7
|
+
|
|
8
|
+
1. `alloc(len: usize) -> *mut u8`
|
|
9
|
+
Allocates `len` bytes in Wasm linear memory for caller writes.
|
|
10
|
+
2. `dealloc(ptr: *mut u8, len: usize)`
|
|
11
|
+
Frees a buffer previously allocated via `alloc`.
|
|
12
|
+
3. `abi_version() -> u32`
|
|
13
|
+
Returns `1`.
|
|
14
|
+
4. `last_result_len() -> usize`
|
|
15
|
+
Returns the byte length of the UTF-8 buffer returned by the most recent call.
|
|
16
|
+
5. `invoke_json(req_ptr: *const u8, req_len: usize) -> *const u8`
|
|
17
|
+
Takes a UTF-8 JSON request envelope and returns a pointer to a static/retained UTF-8 JSON response buffer of length `last_result_len()`.
|
|
18
|
+
(Caller reads `Uint8Array(memory.buffer, ptr, last_result_len())` and decodes UTF-8.)
|
|
19
|
+
6. `extract_ca_coords_f64(req_ptr: *const u8, req_len: usize, out_ptr: *mut f64, max_atoms: usize) -> usize`
|
|
20
|
+
Fast binary path writing packed `[x, y, z, b_or_plddt, ...]` (stride 4 `f64` per C-alpha) directly into a pre-allocated Wasm linear-memory `Float64Array` slice; returns atom count written.
|
|
21
|
+
|
|
22
|
+
## JSON Request / Response Envelope (`invoke_json`)
|
|
23
|
+
|
|
24
|
+
### Request Envelope
|
|
25
|
+
```json
|
|
26
|
+
{
|
|
27
|
+
"op": "inspect_structure" | "compare_structures" | "analyze_peptide" | "analyze_gene_crispr" | "analyze_molecule_smiles" | "analyze_ramachandran",
|
|
28
|
+
"payload": { ... }
|
|
29
|
+
}
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
### Response Envelope
|
|
33
|
+
```json
|
|
34
|
+
{
|
|
35
|
+
"ok": true,
|
|
36
|
+
"op": "...",
|
|
37
|
+
"data": { ... },
|
|
38
|
+
"error": null
|
|
39
|
+
}
|
|
40
|
+
```
|
|
41
|
+
On error:
|
|
42
|
+
```json
|
|
43
|
+
{
|
|
44
|
+
"ok": false,
|
|
45
|
+
"op": "...",
|
|
46
|
+
"data": null,
|
|
47
|
+
"error": {
|
|
48
|
+
"code": "ERR_AMBIGUOUS_CHAIN" | "ERR_OVERSIZED_INPUT" | "ERR_MALFORMED_STRUCTURE" | "ERR_NO_COORDINATES" | "ERR_INVALID_SMILES" | "ERR_INVALID_INPUT",
|
|
49
|
+
"message": "...",
|
|
50
|
+
"details": { ... }
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Operation Payloads & Outputs
|
|
56
|
+
|
|
57
|
+
### 1. `inspect_structure`
|
|
58
|
+
Payload:
|
|
59
|
+
`{ "label": string, "content": string, "sourceTypeHint"?: "experimental" | "prediction" | "auto", "sourceUrl"?: string, "dataRevision"?: string, "retrievedAtUtc"?: string, "license"?: string }`
|
|
60
|
+
Returns:
|
|
61
|
+
`{ "sha256": string, "format": "mmcif" | "pdb", "modelIndex": number, "confidenceKind": "experimental_b_factor" | "prediction_plddt" | "none", "chains": [{ "chainId": string, "authChainId": string, "observedCaCount": number, "declaredSeqLength": number | null, "denominatorKind": "declared_polymer_sequence" | "coordinate_only", "sequence1Letter": string, "hasAltLocs": boolean, "hasInsertionCodes": boolean, "residues": [{ "seqId": number, "insCode": string, "resName3": string, "resCode1": string, "ca": [number, number, number] | null, "bOrPlddt": number | null }] }], "ligands": [{ "resName": string, "chainId": string, "seqId": number, "atoms": [{ "name": string, "element": string, "xyz": [number, number, number] }] }] }`
|
|
62
|
+
|
|
63
|
+
### 2. `compare_structures`
|
|
64
|
+
Payload:
|
|
65
|
+
`{ "refLabel": string, "refContent": string, "refChain"?: string, "refMeta"?: object, "mobLabel": string, "mobContent": string, "mobChain"?: string, "mobMeta"?: object, "paeJson"?: string }`
|
|
66
|
+
- If a structure has >1 polymer chain and its chain parameter is omitted/empty, returns `ERR_AMBIGUOUS_CHAIN` with `details.chains`.
|
|
67
|
+
- Returns full `ComparisonResultV1` PLUS `refDisplayAtoms` / `mobTransformedCa` (`[[x,y,z], ...]`), `refContacts` (Zn/ligand coordination & pocket residues within 4.5 A), and validated `paeMatrixSummary` (`{ "status": "valid"|"missing"|"incompatible_shape", "size": number, "maxPae": number | null }`).
|
|
68
|
+
|
|
69
|
+
### 3. `analyze_peptide`
|
|
70
|
+
Payload:
|
|
71
|
+
`{ "sequence": string, "mutations"?: string[], "sliceStart"?: number, "sliceEnd"?: number, "structureContent"?: string, "chainId"?: string, "focusSeqId"?: number }`
|
|
72
|
+
Returns:
|
|
73
|
+
`{ "ruoNotice": string, "wildType": PeptideDescriptors, "engineered": PeptideDescriptors, "deltas": { "mwAverageDa": number, "mwMonoisotopicDa": number, "pi": number, "chargeAtPh74": number, "gravy": number, "stericVolumeDeltaA3": number }, "titrationCurve": [{ "ph": number, "wtCharge": number, "engCharge": number }], "gravyProfile": [{ "index": number, "res": string, "wtScore": number, "engScore": number }], "appliedMutations": [{ "notation": string, "pos": number, "from": string, "to": string, "notes": string[] }], "local3dContacts": [{ "seqId": number, "resName3": string, "distanceAngstrom": number }] }`
|
|
74
|
+
|
|
75
|
+
### 4. `analyze_gene_crispr`
|
|
76
|
+
Payload:
|
|
77
|
+
`{ "transcriptId"?: string, "codingDna"?: string, "targetCodonIndex": number, "baseEditIndex"?: number, "newBase"?: "A"|"C"|"G"|"T", "nuclease"?: "SpCas9"|"SaCas9"|"Cas12a" }`
|
|
78
|
+
Returns:
|
|
79
|
+
`{ "ruoNotice": string, "transcriptId": string, "geneSymbol": string, "assembly": string, "cdsLengthBp": number, "proteinLengthAa": number, "targetCodon": { "codonIndex1": number, "dnaStartBp1": number, "wtCodon": string, "wtAa": string, "editedCodon": string, "editedAa": string, "consequence": "synonymous"|"missense"|"nonsense"|"unchanged" }, "pamSites": [{ "nuclease": string, "pam": string, "strand": "+"|"-", "protospacer": string, "cutBp1": number, "distanceToTargetCodonBp": number, "gcPercent": number, "hasPolyT": boolean }] }`
|
|
80
|
+
|
|
81
|
+
### 5. `analyze_molecule_smiles`
|
|
82
|
+
Payload:
|
|
83
|
+
`{ "name"?: string, "smiles": string }`
|
|
84
|
+
Returns:
|
|
85
|
+
`{ "ruoNotice": string, "name": string, "smiles": string, "formula": string, "molecularWeight": number, "exactMass": number, "heavyAtomCount": number, "ringCount": number, "aromaticAtomCount": number, "hbd": number, "hba": number, "rotatableBonds": number, "tpsa": number, "crippenLogP": number, "lipinskiViolations": number, "veberCompliant": boolean, "layout2d": { "atoms": [{ "id": number, "element": string, "charge": number, "aromatic": boolean, "x": number, "y": number }], "bonds": [{ "from": number, "to": number, "order": 1|2|3|4 }] } }`
|
|
86
|
+
|
|
87
|
+
### 6. `analyze_ramachandran`
|
|
88
|
+
Payload:
|
|
89
|
+
`{ "content": string, "chainId"?: string }`
|
|
90
|
+
- Enforces `ERR_AMBIGUOUS_CHAIN` with `details.chains` if >1 polymer chain is present and `chainId` is omitted/empty.
|
|
91
|
+
Returns:
|
|
92
|
+
`{ "ruoNotice": string, "chainId": string, "authChainId": string, "format": "mmcif" | "pdb", "residueCount": number, "residues": [{ "seqId": number, "insCode": string, "resName3": string, "resCode1": string, "phiDeg": number | null, "psiDeg": number | null, "secondary": "helix" | "sheet" | "loop", "region": "favored" | "allowed" | "outlier" | "terminal" }], "secondaryCounts": { "helix": number, "sheet": number, "loop": number }, "regionCounts": { "favored": number, "allowed": number, "outlier": number }, "contactPairs": [[number, number, number]] }`
|
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright notice to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate misconduct
|
|
156
|
+
and gross negligence) or agreed to in writing, shall any Contributor
|
|
157
|
+
be liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 ATIL YALI / Synlexa
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/NOTICE
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
Synlexa Studio
|
|
2
|
+
Copyright 2026 ATIL YALI / Synlexa
|
|
3
|
+
|
|
4
|
+
This product includes software developed by Synlexa (https://www.synlexa.com).
|
|
5
|
+
Original Synlexa source code in this repository is licensed under the Apache
|
|
6
|
+
License, Version 2.0 (see LICENSE).
|
|
7
|
+
|
|
8
|
+
===========================================================================
|
|
9
|
+
TRADEMARKS & BRAND ASSETS (Apache License 2.0 Section 6)
|
|
10
|
+
===========================================================================
|
|
11
|
+
"Synlexa", "Synlexa Studio", "Synlexa Core", and the official logo, icon,
|
|
12
|
+
and wordmark files under apps/web/public/ and apps/desktop/src-tauri/icons/
|
|
13
|
+
remain trademarks of Synlexa. See TRADEMARKS.md for usage terms.
|
|
14
|
+
|
|
15
|
+
===========================================================================
|
|
16
|
+
THIRD-PARTY SOFTWARE ATTRIBUTIONS
|
|
17
|
+
===========================================================================
|
|
18
|
+
|
|
19
|
+
1. Mol* (molstar)
|
|
20
|
+
License: MIT License
|
|
21
|
+
Copyright (c) Mol* contributors, https://molstar.org
|
|
22
|
+
|
|
23
|
+
2. RDKit / @rdkit/rdkit (MinimalLib WebAssembly)
|
|
24
|
+
License: BSD-3-Clause License
|
|
25
|
+
Copyright (c) 2006-2026, Greg Landrum and other RDKit contributors
|
|
26
|
+
Redistribution and use in source and binary forms, with or without
|
|
27
|
+
modification, are permitted under the 3-Clause BSD License
|
|
28
|
+
(https://github.com/rdkit/rdkit/blob/master/license.txt).
|
|
29
|
+
|
|
30
|
+
3. @anthropic-ai/sdk & TypeScript
|
|
31
|
+
License: Apache License, Version 2.0
|
|
32
|
+
|
|
33
|
+
4. React, React DOM, Vite, Vitest, Tailwind CSS
|
|
34
|
+
License: MIT License
|
|
35
|
+
|
|
36
|
+
5. Lucide React
|
|
37
|
+
License: ISC License
|
|
38
|
+
|
|
39
|
+
6. lightningcss (build-time CSS bundler dependency via @tailwindcss/vite)
|
|
40
|
+
License: Mozilla Public License 2.0 (MPL-2.0)
|
|
41
|
+
|
|
42
|
+
7. Tauri v2 & tauri-plugin-deep-link (apps/desktop/src-tauri scaffold)
|
|
43
|
+
License: Apache-2.0 OR MIT
|
|
44
|
+
|
|
45
|
+
8. Optional external Python compute adapters (services/compute-worker)
|
|
46
|
+
Users who opt in to installing optional external scientific engines in
|
|
47
|
+
their own compute environments remain responsible for compliance with
|
|
48
|
+
those packages' upstream licenses:
|
|
49
|
+
- AutoDock Vina, PySCF, Nextflow: Apache-2.0
|
|
50
|
+
- FastAPI, Uvicorn, Pydantic, Boltz-2, Chemprop, Snakemake: MIT
|
|
51
|
+
- Biopython, RDKit: BSD-3-Clause / Biopython License
|
|
52
|
+
- Meeko: LGPL-2.1
|
|
53
|
+
- OpenMM: MIT / LGPL components
|
|
54
|
+
- GROMACS: LGPL-2.1+
|
|
55
|
+
- xTB: LGPL-3.0
|
|
56
|
+
- Open Babel (strictly user-installed external CLI plugin): GPL-2.0
|
|
57
|
+
|
|
58
|
+
===========================================================================
|
|
59
|
+
SCIENTIFIC TEST & DEMO FIXTURES (SEPARATE DATA LICENSES)
|
|
60
|
+
===========================================================================
|
|
61
|
+
The reference scientific datasets under tests/fixtures/ and
|
|
62
|
+
apps/web/public/fixtures/ (listed in fixtures-manifest.json) are NOT original
|
|
63
|
+
Synlexa software and remain governed by their upstream data licenses:
|
|
64
|
+
|
|
65
|
+
- RCSB Protein Data Bank structures (3HS4.cif, 3HS4.pdb, 1UBQ.cif, 1A3N.cif,
|
|
66
|
+
1LZ1.cif): CC0-1.0 Universal Public Domain Dedication
|
|
67
|
+
- NCBI PubChem PUG REST compound snapshot (pubchem-panel.json):
|
|
68
|
+
CC0-1.0 / NCBI Public Domain Policy
|
|
69
|
+
- AlphaFold Protein Structure Database v6 models & PAE matrix
|
|
70
|
+
(AF-P00918-F1-*, AF-P0CG48-F1-*, AF-P68871-F1-*, AF-P61626-F1-*):
|
|
71
|
+
Creative Commons Attribution 4.0 International (CC-BY-4.0),
|
|
72
|
+
EMBL-EBI / Google DeepMind (Jumper et al., Varadi et al.)
|
package/README.md
CHANGED
|
@@ -1,3 +1,32 @@
|
|
|
1
|
-
#
|
|
1
|
+
# `@synlexa/wasm-bridge` (Developer WebAssembly SDK)
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
> **Looking for the Synlexa Studio desktop app?** Install [`@synlexa/studio`](https://github.com/orgs/Synlexa/packages/npm/package/studio) or download the macOS/Windows/Linux installer from [synlexa.com/download](https://www.synlexa.com/download).
|
|
4
|
+
|
|
5
|
+
This package is for **JavaScript / TypeScript developers** embedding Synlexa Studio's deterministic WebAssembly biological & cheminformatics core (`synlexa_bio_core.wasm`, ABI v1) directly inside Node.js or browser apps (Research-Use-Only).
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
# Direct zero-auth install from GitHub Releases:
|
|
11
|
+
npm install https://github.com/Synlexa/synlexa-studio/releases/download/v0.4.3/synlexa-wasm-bridge-0.4.3.tgz
|
|
12
|
+
|
|
13
|
+
# Or via GitHub Packages (with read:packages token in ~/.npmrc):
|
|
14
|
+
npm install @synlexa/wasm-bridge --@synlexa:registry=https://npm.pkg.github.com
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Example Usage
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
import { readFile } from 'node:fs/promises';
|
|
21
|
+
import { loadWasmBioCore } from '@synlexa/wasm-bridge';
|
|
22
|
+
|
|
23
|
+
const wasmBytes = await readFile(new URL('./wasm/synlexa_bio_core.wasm', import.meta.url));
|
|
24
|
+
const session = await loadWasmBioCore(new Uint8Array(wasmBytes));
|
|
25
|
+
const res = session.invokeJson('analyze_molecule_smiles', {
|
|
26
|
+
name: 'Acetazolamide',
|
|
27
|
+
smiles: 'CC(=O)Nc1nnc(S(N)(=O)=O)s1',
|
|
28
|
+
});
|
|
29
|
+
console.log(res.data?.formula, res.data?.molecularWeight);
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
See [`ABI.md`](ABI.md) and [Synlexa Studio](https://github.com/Synlexa/synlexa-studio) for full documentation.
|
package/package.json
CHANGED
|
@@ -1,6 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@synlexa/wasm-bridge",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.4.3",
|
|
4
|
+
"private": false,
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/Synlexa/synlexa-studio.git"
|
|
9
|
+
},
|
|
10
|
+
"type": "module",
|
|
11
|
+
"main": "src/index.ts",
|
|
12
|
+
"description": "For JS/TS Developers: WebAssembly biological & cheminformatics SDK for Node.js and browsers (not the desktop app; Research-Use-Only).",
|
|
13
|
+
"homepage": "https://www.synlexa.com/docs",
|
|
14
|
+
"files": [
|
|
15
|
+
"src/",
|
|
16
|
+
"wasm/",
|
|
17
|
+
"ABI.md",
|
|
18
|
+
"README.md",
|
|
19
|
+
"LICENSE",
|
|
20
|
+
"NOTICE"
|
|
21
|
+
]
|
|
22
|
+
}
|
package/src/index.ts
ADDED
package/src/types.ts
ADDED
|
@@ -0,0 +1,429 @@
|
|
|
1
|
+
export type EngineTarget = 'native-rust' | 'wasm-rust' | 'native-cpp';
|
|
2
|
+
|
|
3
|
+
export type ConfidenceKind = 'experimental_b_factor' | 'prediction_plddt' | 'none';
|
|
4
|
+
|
|
5
|
+
export type CoverageDenominatorKind = 'declared_polymer_sequence' | 'coordinate_only';
|
|
6
|
+
|
|
7
|
+
export type PaeStatus = 'valid' | 'missing' | 'incompatible_shape';
|
|
8
|
+
|
|
9
|
+
export interface CoverageRecord {
|
|
10
|
+
numerator: number;
|
|
11
|
+
denominator: number;
|
|
12
|
+
denominatorKind: CoverageDenominatorKind;
|
|
13
|
+
ratio: number;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface StructureInputRecord {
|
|
17
|
+
label: string;
|
|
18
|
+
chainId: string;
|
|
19
|
+
authChainId: string | null;
|
|
20
|
+
modelIndex: number;
|
|
21
|
+
sha256: string;
|
|
22
|
+
confidenceKind: ConfidenceKind;
|
|
23
|
+
sourceUrl: string | null;
|
|
24
|
+
dataRevision: string | null;
|
|
25
|
+
retrievedAtUtc: string | null;
|
|
26
|
+
license: string | null;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface MatchedResidueRecord {
|
|
30
|
+
refSeqId: number;
|
|
31
|
+
refInsCode: string;
|
|
32
|
+
mobSeqId: number;
|
|
33
|
+
mobInsCode: string;
|
|
34
|
+
resName3: string;
|
|
35
|
+
resCode1: string;
|
|
36
|
+
distanceAngstrom: number;
|
|
37
|
+
refBFactor: number | null;
|
|
38
|
+
mobPlddt: number | null;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface ComparisonResultV1 {
|
|
42
|
+
schemaVersion: '1.0.0';
|
|
43
|
+
ruoNotice: string;
|
|
44
|
+
resultId: string;
|
|
45
|
+
engine: {
|
|
46
|
+
name: string;
|
|
47
|
+
version: string;
|
|
48
|
+
target: EngineTarget;
|
|
49
|
+
floatPrecision: 'float64';
|
|
50
|
+
};
|
|
51
|
+
createdAtUtc: string;
|
|
52
|
+
reference: StructureInputRecord;
|
|
53
|
+
mobile: StructureInputRecord;
|
|
54
|
+
metrics: {
|
|
55
|
+
matchedCaCount: number;
|
|
56
|
+
rmsdAngstrom: number;
|
|
57
|
+
units: 'angstrom';
|
|
58
|
+
refCoverage: CoverageRecord;
|
|
59
|
+
mobCoverage: CoverageRecord;
|
|
60
|
+
paeStatus: PaeStatus;
|
|
61
|
+
};
|
|
62
|
+
transform: {
|
|
63
|
+
direction: 'mobile_to_reference';
|
|
64
|
+
matrixRowMajor4x4: number[];
|
|
65
|
+
};
|
|
66
|
+
matchedResidues: MatchedResidueRecord[];
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export type BioCoreOp =
|
|
70
|
+
| 'inspect_structure'
|
|
71
|
+
| 'compare_structures'
|
|
72
|
+
| 'analyze_peptide'
|
|
73
|
+
| 'analyze_gene_crispr'
|
|
74
|
+
| 'analyze_molecule_smiles'
|
|
75
|
+
| 'analyze_ramachandran';
|
|
76
|
+
|
|
77
|
+
export type BioCoreErrorCode =
|
|
78
|
+
| 'ERR_AMBIGUOUS_CHAIN'
|
|
79
|
+
| 'ERR_OVERSIZED_INPUT'
|
|
80
|
+
| 'ERR_MALFORMED_STRUCTURE'
|
|
81
|
+
| 'ERR_NO_COORDINATES'
|
|
82
|
+
| 'ERR_INVALID_SMILES'
|
|
83
|
+
| 'ERR_INVALID_INPUT';
|
|
84
|
+
|
|
85
|
+
export interface BioCoreError {
|
|
86
|
+
code: BioCoreErrorCode | string;
|
|
87
|
+
message: string;
|
|
88
|
+
details?: Record<string, unknown>;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export type BioCoreResponse<T> =
|
|
92
|
+
| {
|
|
93
|
+
ok: true;
|
|
94
|
+
op: BioCoreOp | string;
|
|
95
|
+
data: T;
|
|
96
|
+
error: null;
|
|
97
|
+
}
|
|
98
|
+
| {
|
|
99
|
+
ok: false;
|
|
100
|
+
op: BioCoreOp | string;
|
|
101
|
+
data: null;
|
|
102
|
+
error: BioCoreError;
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
export interface StructureInputMeta {
|
|
106
|
+
sourceTypeHint?: 'experimental' | 'prediction' | 'auto';
|
|
107
|
+
sourceUrl?: string;
|
|
108
|
+
dataRevision?: string;
|
|
109
|
+
retrievedAtUtc?: string;
|
|
110
|
+
license?: string;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export interface InspectStructureRequest extends StructureInputMeta {
|
|
114
|
+
label: string;
|
|
115
|
+
content: string;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export interface InspectResidue {
|
|
119
|
+
seqId: number;
|
|
120
|
+
insCode: string;
|
|
121
|
+
resName3: string;
|
|
122
|
+
resCode1: string;
|
|
123
|
+
ca: [number, number, number] | null;
|
|
124
|
+
bOrPlddt: number | null;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export interface InspectChain {
|
|
128
|
+
chainId: string;
|
|
129
|
+
authChainId: string;
|
|
130
|
+
observedCaCount: number;
|
|
131
|
+
declaredSeqLength: number | null;
|
|
132
|
+
denominatorKind: CoverageDenominatorKind;
|
|
133
|
+
sequence1Letter: string;
|
|
134
|
+
hasAltLocs: boolean;
|
|
135
|
+
hasInsertionCodes: boolean;
|
|
136
|
+
residues: InspectResidue[];
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
export interface InspectLigandAtom {
|
|
140
|
+
name: string;
|
|
141
|
+
element: string;
|
|
142
|
+
xyz: [number, number, number];
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export interface InspectLigand {
|
|
146
|
+
resName: string;
|
|
147
|
+
chainId: string;
|
|
148
|
+
seqId: number;
|
|
149
|
+
atoms: InspectLigandAtom[];
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
export interface InspectStructureResult {
|
|
153
|
+
sha256: string;
|
|
154
|
+
format: 'mmcif' | 'pdb';
|
|
155
|
+
modelIndex: number;
|
|
156
|
+
confidenceKind: ConfidenceKind;
|
|
157
|
+
chains: InspectChain[];
|
|
158
|
+
ligands: InspectLigand[];
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
export interface CompareStructuresRequest {
|
|
162
|
+
refLabel: string;
|
|
163
|
+
refContent: string;
|
|
164
|
+
refChain?: string;
|
|
165
|
+
refMeta?: StructureInputMeta;
|
|
166
|
+
mobLabel: string;
|
|
167
|
+
mobContent: string;
|
|
168
|
+
mobChain?: string;
|
|
169
|
+
mobMeta?: StructureInputMeta;
|
|
170
|
+
paeJson?: string;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
export interface RefDisplayResidue {
|
|
174
|
+
seqId: number;
|
|
175
|
+
insCode: string;
|
|
176
|
+
resName3: string;
|
|
177
|
+
resCode1: string;
|
|
178
|
+
ca: [number, number, number];
|
|
179
|
+
bFactor: number | null;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
export interface RefPocketAtom {
|
|
183
|
+
seqId: number;
|
|
184
|
+
resName3: string;
|
|
185
|
+
atomName: string;
|
|
186
|
+
element: string;
|
|
187
|
+
xyz: [number, number, number];
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
export interface RefDisplayAtoms {
|
|
191
|
+
ca: Array<[number, number, number]>;
|
|
192
|
+
residues: RefDisplayResidue[];
|
|
193
|
+
ligands: InspectLigand[];
|
|
194
|
+
pocketAtoms: RefPocketAtom[];
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
export interface MobTransformedResidue {
|
|
198
|
+
seqId: number;
|
|
199
|
+
insCode: string;
|
|
200
|
+
resName3: string;
|
|
201
|
+
resCode1: string;
|
|
202
|
+
xyz: [number, number, number];
|
|
203
|
+
plddt: number | null;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
export interface RefContactRecord {
|
|
207
|
+
ligandResName: string;
|
|
208
|
+
ligandChainId: string;
|
|
209
|
+
ligandSeqId: number;
|
|
210
|
+
ligandAtom: string;
|
|
211
|
+
proteinSeqId: number;
|
|
212
|
+
proteinResName3: string;
|
|
213
|
+
proteinAtom: string;
|
|
214
|
+
distanceAngstrom: number;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
export interface PaeMatrixSummary {
|
|
218
|
+
status: PaeStatus;
|
|
219
|
+
size: number;
|
|
220
|
+
maxPae: number | null;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
export interface CompareStructuresResult extends ComparisonResultV1 {
|
|
224
|
+
refDisplayAtoms?: RefDisplayAtoms;
|
|
225
|
+
mobTransformedCa?: Array<[number, number, number]>;
|
|
226
|
+
mobTransformedResidues?: MobTransformedResidue[];
|
|
227
|
+
refContacts?: RefContactRecord[];
|
|
228
|
+
paeMatrixSummary?: PaeMatrixSummary;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
export interface AnalyzePeptideRequest {
|
|
232
|
+
sequence: string;
|
|
233
|
+
mutations?: string[];
|
|
234
|
+
sliceStart?: number;
|
|
235
|
+
sliceEnd?: number;
|
|
236
|
+
structureContent?: string;
|
|
237
|
+
chainId?: string;
|
|
238
|
+
focusSeqId?: number;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
export interface PeptideDescriptors {
|
|
242
|
+
sequence: string;
|
|
243
|
+
length: number;
|
|
244
|
+
mwAverageDa: number;
|
|
245
|
+
mwMonoisotopicDa: number;
|
|
246
|
+
pi: number;
|
|
247
|
+
chargeAtPh74: number;
|
|
248
|
+
gravy: number;
|
|
249
|
+
extinctionReduced: number;
|
|
250
|
+
extinctionCystine: number;
|
|
251
|
+
stericVolumeA3: number;
|
|
252
|
+
aromaticFraction: number;
|
|
253
|
+
hydrophobicFraction: number;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
export interface AnalyzePeptideResult {
|
|
257
|
+
ruoNotice: string;
|
|
258
|
+
wildType: PeptideDescriptors;
|
|
259
|
+
engineered: PeptideDescriptors;
|
|
260
|
+
deltas: {
|
|
261
|
+
mwAverageDa: number;
|
|
262
|
+
mwMonoisotopicDa: number;
|
|
263
|
+
pi: number;
|
|
264
|
+
chargeAtPh74: number;
|
|
265
|
+
gravy: number;
|
|
266
|
+
stericVolumeDeltaA3: number;
|
|
267
|
+
};
|
|
268
|
+
titrationCurve: Array<{
|
|
269
|
+
ph: number;
|
|
270
|
+
wtCharge: number;
|
|
271
|
+
engCharge: number;
|
|
272
|
+
}>;
|
|
273
|
+
gravyProfile: Array<{
|
|
274
|
+
index: number;
|
|
275
|
+
res: string;
|
|
276
|
+
wtScore: number;
|
|
277
|
+
engScore: number;
|
|
278
|
+
}>;
|
|
279
|
+
appliedMutations: Array<{
|
|
280
|
+
notation: string;
|
|
281
|
+
pos: number;
|
|
282
|
+
from: string;
|
|
283
|
+
to: string;
|
|
284
|
+
notes: string[];
|
|
285
|
+
}>;
|
|
286
|
+
local3dContacts: Array<{
|
|
287
|
+
seqId: number;
|
|
288
|
+
resName3: string;
|
|
289
|
+
distanceAngstrom: number;
|
|
290
|
+
}>;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
export interface AnalyzeGeneCrisprRequest {
|
|
294
|
+
transcriptId?: string;
|
|
295
|
+
codingDna?: string;
|
|
296
|
+
targetCodonIndex: number;
|
|
297
|
+
baseEditIndex?: number;
|
|
298
|
+
newBase?: 'A' | 'C' | 'G' | 'T';
|
|
299
|
+
nuclease?: 'SpCas9' | 'SaCas9' | 'Cas12a';
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
export interface CrisprPamSite {
|
|
303
|
+
nuclease: string;
|
|
304
|
+
pam: string;
|
|
305
|
+
strand: '+' | '-';
|
|
306
|
+
protospacer: string;
|
|
307
|
+
cutBp1: number;
|
|
308
|
+
distanceToTargetCodonBp: number;
|
|
309
|
+
gcPercent: number;
|
|
310
|
+
hasPolyT: boolean;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
export interface AnalyzeGeneCrisprResult {
|
|
314
|
+
ruoNotice: string;
|
|
315
|
+
transcriptId: string;
|
|
316
|
+
geneSymbol: string;
|
|
317
|
+
assembly: string;
|
|
318
|
+
cdsLengthBp: number;
|
|
319
|
+
proteinLengthAa: number;
|
|
320
|
+
codingDna?: string;
|
|
321
|
+
targetCodon: {
|
|
322
|
+
codonIndex1: number;
|
|
323
|
+
dnaStartBp1: number;
|
|
324
|
+
wtCodon: string;
|
|
325
|
+
wtAa: string;
|
|
326
|
+
editedCodon: string;
|
|
327
|
+
editedAa: string;
|
|
328
|
+
consequence: 'synonymous' | 'missense' | 'nonsense' | 'unchanged';
|
|
329
|
+
};
|
|
330
|
+
pamSites: CrisprPamSite[];
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
export interface AnalyzeMoleculeSmilesRequest {
|
|
334
|
+
name?: string;
|
|
335
|
+
smiles: string;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
export interface MoleculeLayoutAtom {
|
|
339
|
+
id: number;
|
|
340
|
+
element: string;
|
|
341
|
+
charge: number;
|
|
342
|
+
aromatic: boolean;
|
|
343
|
+
x: number;
|
|
344
|
+
y: number;
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
export interface MoleculeLayoutBond {
|
|
348
|
+
from: number;
|
|
349
|
+
to: number;
|
|
350
|
+
order: 1 | 2 | 3 | 4;
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
export interface AnalyzeMoleculeSmilesResult {
|
|
354
|
+
ruoNotice: string;
|
|
355
|
+
name: string;
|
|
356
|
+
smiles: string;
|
|
357
|
+
formula: string;
|
|
358
|
+
molecularWeight: number;
|
|
359
|
+
exactMass: number;
|
|
360
|
+
heavyAtomCount: number;
|
|
361
|
+
ringCount: number;
|
|
362
|
+
aromaticAtomCount: number;
|
|
363
|
+
hbd: number;
|
|
364
|
+
hba: number;
|
|
365
|
+
rotatableBonds: number;
|
|
366
|
+
tpsa: number;
|
|
367
|
+
crippenLogP: number;
|
|
368
|
+
lipinskiViolations: number;
|
|
369
|
+
veberCompliant: boolean;
|
|
370
|
+
layout2d: {
|
|
371
|
+
atoms: MoleculeLayoutAtom[];
|
|
372
|
+
bonds: MoleculeLayoutBond[];
|
|
373
|
+
};
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
export type RamachandranSecondary = 'helix' | 'sheet' | 'loop';
|
|
377
|
+
|
|
378
|
+
export type RamachandranRegion = 'favored' | 'allowed' | 'outlier' | 'terminal';
|
|
379
|
+
|
|
380
|
+
export interface AnalyzeRamachandranRequest {
|
|
381
|
+
content: string;
|
|
382
|
+
chainId?: string;
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
export interface RamachandranResidue {
|
|
386
|
+
seqId: number;
|
|
387
|
+
insCode: string;
|
|
388
|
+
resName3: string;
|
|
389
|
+
resCode1: string;
|
|
390
|
+
phiDeg: number | null;
|
|
391
|
+
psiDeg: number | null;
|
|
392
|
+
secondary: RamachandranSecondary;
|
|
393
|
+
region: RamachandranRegion;
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
export interface AnalyzeRamachandranResult {
|
|
397
|
+
ruoNotice: string;
|
|
398
|
+
chainId: string;
|
|
399
|
+
authChainId: string;
|
|
400
|
+
format: 'mmcif' | 'pdb';
|
|
401
|
+
residueCount: number;
|
|
402
|
+
residues: RamachandranResidue[];
|
|
403
|
+
secondaryCounts: {
|
|
404
|
+
helix: number;
|
|
405
|
+
sheet: number;
|
|
406
|
+
loop: number;
|
|
407
|
+
};
|
|
408
|
+
regionCounts: {
|
|
409
|
+
favored: number;
|
|
410
|
+
allowed: number;
|
|
411
|
+
outlier: number;
|
|
412
|
+
};
|
|
413
|
+
contactPairs: Array<[number, number, number]>;
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
export interface WasmBioCoreExports extends WebAssembly.Exports {
|
|
417
|
+
memory: WebAssembly.Memory;
|
|
418
|
+
alloc(len: number): number;
|
|
419
|
+
dealloc(ptr: number, len: number): void;
|
|
420
|
+
abi_version(): number;
|
|
421
|
+
last_result_len(): number;
|
|
422
|
+
invoke_json(reqPtr: number, reqLen: number): number;
|
|
423
|
+
extract_ca_coords_f64(
|
|
424
|
+
reqPtr: number,
|
|
425
|
+
reqLen: number,
|
|
426
|
+
outPtr: number,
|
|
427
|
+
maxAtoms: number,
|
|
428
|
+
): number;
|
|
429
|
+
}
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
AnalyzeRamachandranRequest,
|
|
3
|
+
AnalyzeRamachandranResult,
|
|
4
|
+
BioCoreOp,
|
|
5
|
+
BioCoreResponse,
|
|
6
|
+
WasmBioCoreExports,
|
|
7
|
+
} from './types.js';
|
|
8
|
+
|
|
9
|
+
const textEncoder = new TextEncoder();
|
|
10
|
+
const textDecoder = new TextDecoder('utf-8', { fatal: false });
|
|
11
|
+
|
|
12
|
+
export type WasmSource =
|
|
13
|
+
| string
|
|
14
|
+
| URL
|
|
15
|
+
| Response
|
|
16
|
+
| ArrayBuffer
|
|
17
|
+
| ArrayBufferView
|
|
18
|
+
| WebAssembly.Module;
|
|
19
|
+
|
|
20
|
+
export class WasmAbiError extends Error {
|
|
21
|
+
constructor(message: string) {
|
|
22
|
+
super(message);
|
|
23
|
+
this.name = 'WasmAbiError';
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function assertExports(exportsObj: WebAssembly.Exports): WasmBioCoreExports {
|
|
28
|
+
const candidate = exportsObj as Partial<WasmBioCoreExports>;
|
|
29
|
+
const required = [
|
|
30
|
+
'memory',
|
|
31
|
+
'alloc',
|
|
32
|
+
'dealloc',
|
|
33
|
+
'abi_version',
|
|
34
|
+
'last_result_len',
|
|
35
|
+
'invoke_json',
|
|
36
|
+
'extract_ca_coords_f64',
|
|
37
|
+
] as const;
|
|
38
|
+
|
|
39
|
+
for (const key of required) {
|
|
40
|
+
if (candidate[key] === undefined) {
|
|
41
|
+
throw new WasmAbiError(
|
|
42
|
+
`Wasm module missing required ABI export "${key}".`,
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return candidate as WasmBioCoreExports;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
async function instantiateFromSource(
|
|
50
|
+
source: WasmSource,
|
|
51
|
+
): Promise<WebAssembly.Instance> {
|
|
52
|
+
const imports: WebAssembly.Imports = {};
|
|
53
|
+
|
|
54
|
+
if (source instanceof WebAssembly.Module) {
|
|
55
|
+
return WebAssembly.instantiate(source, imports);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if (source instanceof ArrayBuffer) {
|
|
59
|
+
const result = await WebAssembly.instantiate(source, imports);
|
|
60
|
+
return result.instance;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (ArrayBuffer.isView(source)) {
|
|
64
|
+
const copy = new Uint8Array(source.byteLength);
|
|
65
|
+
copy.set(
|
|
66
|
+
new Uint8Array(source.buffer, source.byteOffset, source.byteLength),
|
|
67
|
+
);
|
|
68
|
+
const result = await WebAssembly.instantiate(copy.buffer, imports);
|
|
69
|
+
return result.instance;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
let response: Response;
|
|
73
|
+
if (typeof source === 'string' || source instanceof URL) {
|
|
74
|
+
response = await fetch(source);
|
|
75
|
+
if (!response.ok) {
|
|
76
|
+
throw new WasmAbiError(
|
|
77
|
+
`Failed to fetch Wasm module (${response.status} ${response.statusText})`,
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
} else {
|
|
81
|
+
response = source;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (typeof WebAssembly.instantiateStreaming === 'function') {
|
|
85
|
+
try {
|
|
86
|
+
const cloned = response.clone();
|
|
87
|
+
const result = await WebAssembly.instantiateStreaming(cloned, imports);
|
|
88
|
+
return result.instance;
|
|
89
|
+
} catch {
|
|
90
|
+
// Fallback when MIME type is not application/wasm or streaming fails.
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const buffer = await response.arrayBuffer();
|
|
95
|
+
const result = await WebAssembly.instantiate(buffer, imports);
|
|
96
|
+
return result.instance;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export class BioCoreWasmSession {
|
|
100
|
+
private readonly exports: WasmBioCoreExports;
|
|
101
|
+
public readonly abiVersion: number;
|
|
102
|
+
|
|
103
|
+
constructor(instanceOrExports: WebAssembly.Instance | WasmBioCoreExports) {
|
|
104
|
+
const rawExports =
|
|
105
|
+
'exports' in instanceOrExports
|
|
106
|
+
? (instanceOrExports as WebAssembly.Instance).exports
|
|
107
|
+
: instanceOrExports;
|
|
108
|
+
this.exports = assertExports(rawExports);
|
|
109
|
+
this.abiVersion = this.exports.abi_version();
|
|
110
|
+
if (this.abiVersion !== 1) {
|
|
111
|
+
throw new WasmAbiError(
|
|
112
|
+
`Unsupported Synlexa Wasm ABI version ${this.abiVersion} (expected 1).`,
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
invokeRaw(requestJson: string): string {
|
|
118
|
+
const bytes = textEncoder.encode(requestJson);
|
|
119
|
+
const reqLen = bytes.byteLength;
|
|
120
|
+
const reqPtr = reqLen > 0 ? this.exports.alloc(reqLen) : 0;
|
|
121
|
+
|
|
122
|
+
if (reqLen > 0 && reqPtr === 0) {
|
|
123
|
+
throw new WasmAbiError(`Wasm alloc(${reqLen}) returned null pointer.`);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
try {
|
|
127
|
+
if (reqLen > 0) {
|
|
128
|
+
const memView = new Uint8Array(
|
|
129
|
+
this.exports.memory.buffer,
|
|
130
|
+
reqPtr,
|
|
131
|
+
reqLen,
|
|
132
|
+
);
|
|
133
|
+
memView.set(bytes);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
const resPtr = this.exports.invoke_json(reqPtr, reqLen);
|
|
137
|
+
const resLen = this.exports.last_result_len();
|
|
138
|
+
if (resPtr === 0 || resLen === 0) {
|
|
139
|
+
throw new WasmAbiError('Wasm invoke_json returned empty response buffer.');
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// Re-read memory.buffer in case Wasm memory grew during invoke_json.
|
|
143
|
+
const resBytes = new Uint8Array(
|
|
144
|
+
this.exports.memory.buffer,
|
|
145
|
+
resPtr,
|
|
146
|
+
resLen,
|
|
147
|
+
).slice();
|
|
148
|
+
return textDecoder.decode(resBytes);
|
|
149
|
+
} finally {
|
|
150
|
+
if (reqLen > 0 && reqPtr !== 0) {
|
|
151
|
+
this.exports.dealloc(reqPtr, reqLen);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
invokeJson<TReq, TRes>(
|
|
157
|
+
op: BioCoreOp,
|
|
158
|
+
payload: TReq,
|
|
159
|
+
): BioCoreResponse<TRes> {
|
|
160
|
+
const requestStr = JSON.stringify({ op, payload });
|
|
161
|
+
const responseStr = this.invokeRaw(requestStr);
|
|
162
|
+
return JSON.parse(responseStr) as BioCoreResponse<TRes>;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
analyzeRamachandran(
|
|
166
|
+
payload: AnalyzeRamachandranRequest,
|
|
167
|
+
): BioCoreResponse<AnalyzeRamachandranResult> {
|
|
168
|
+
return this.invokeJson<AnalyzeRamachandranRequest, AnalyzeRamachandranResult>(
|
|
169
|
+
'analyze_ramachandran',
|
|
170
|
+
payload,
|
|
171
|
+
);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
extractCaCoordsF64(
|
|
175
|
+
payload: { content: string; chainId?: string },
|
|
176
|
+
maxAtoms = 65536,
|
|
177
|
+
): Float64Array {
|
|
178
|
+
const reqBytes = textEncoder.encode(JSON.stringify(payload));
|
|
179
|
+
const reqLen = reqBytes.byteLength;
|
|
180
|
+
const reqPtr = this.exports.alloc(reqLen);
|
|
181
|
+
if (reqPtr === 0) {
|
|
182
|
+
throw new WasmAbiError(`Wasm alloc(${reqLen}) failed.`);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
// Allocate extra 8 bytes to allow manual 8-byte alignment if alloc returns 4-byte aligned address.
|
|
186
|
+
const outByteSize = maxAtoms * 4 * 8 + 8;
|
|
187
|
+
const outRawPtr = this.exports.alloc(outByteSize);
|
|
188
|
+
if (outRawPtr === 0) {
|
|
189
|
+
this.exports.dealloc(reqPtr, reqLen);
|
|
190
|
+
throw new WasmAbiError(`Wasm alloc(${outByteSize}) failed for f64 buffer.`);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
const alignedOutPtr = ((outRawPtr + 7) & ~7) >>> 0;
|
|
194
|
+
|
|
195
|
+
try {
|
|
196
|
+
new Uint8Array(this.exports.memory.buffer, reqPtr, reqLen).set(reqBytes);
|
|
197
|
+
const atomCount = this.exports.extract_ca_coords_f64(
|
|
198
|
+
reqPtr,
|
|
199
|
+
reqLen,
|
|
200
|
+
alignedOutPtr,
|
|
201
|
+
maxAtoms,
|
|
202
|
+
);
|
|
203
|
+
const count = Math.min(atomCount, maxAtoms);
|
|
204
|
+
const view = new Float64Array(
|
|
205
|
+
this.exports.memory.buffer,
|
|
206
|
+
alignedOutPtr,
|
|
207
|
+
count * 4,
|
|
208
|
+
);
|
|
209
|
+
return view.slice();
|
|
210
|
+
} finally {
|
|
211
|
+
this.exports.dealloc(reqPtr, reqLen);
|
|
212
|
+
this.exports.dealloc(outRawPtr, outByteSize);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
export async function loadWasmBioCore(
|
|
218
|
+
source: WasmSource,
|
|
219
|
+
): Promise<BioCoreWasmSession> {
|
|
220
|
+
const instance = await instantiateFromSource(source);
|
|
221
|
+
return new BioCoreWasmSession(instance);
|
|
222
|
+
}
|
|
Binary file
|