@zakodium/nmrium-core-plugins 0.1.1 → 0.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/LICENSE +438 -0
- package/README.md +2 -14
- package/dist/nmrium-core-plugins.js +10 -0
- package/package.json +23 -44
- package/dist/nmrium-core-plugins.cjs +0 -6
- package/dist/nmrium-core-plugins.mjs +0 -6
package/LICENSE
ADDED
|
@@ -0,0 +1,438 @@
|
|
|
1
|
+
Attribution-NonCommercial-ShareAlike 4.0 International
|
|
2
|
+
|
|
3
|
+
=======================================================================
|
|
4
|
+
|
|
5
|
+
Creative Commons Corporation ("Creative Commons") is not a law firm and
|
|
6
|
+
does not provide legal services or legal advice. Distribution of
|
|
7
|
+
Creative Commons public licenses does not create a lawyer-client or
|
|
8
|
+
other relationship. Creative Commons makes its licenses and related
|
|
9
|
+
information available on an "as-is" basis. Creative Commons gives no
|
|
10
|
+
warranties regarding its licenses, any material licensed under their
|
|
11
|
+
terms and conditions, or any related information. Creative Commons
|
|
12
|
+
disclaims all liability for damages resulting from their use to the
|
|
13
|
+
fullest extent possible.
|
|
14
|
+
|
|
15
|
+
Using Creative Commons Public Licenses
|
|
16
|
+
|
|
17
|
+
Creative Commons public licenses provide a standard set of terms and
|
|
18
|
+
conditions that creators and other rights holders may use to share
|
|
19
|
+
original works of authorship and other material subject to copyright
|
|
20
|
+
and certain other rights specified in the public license below. The
|
|
21
|
+
following considerations are for informational purposes only, are not
|
|
22
|
+
exhaustive, and do not form part of our licenses.
|
|
23
|
+
|
|
24
|
+
Considerations for licensors: Our public licenses are
|
|
25
|
+
intended for use by those authorized to give the public
|
|
26
|
+
permission to use material in ways otherwise restricted by
|
|
27
|
+
copyright and certain other rights. Our licenses are
|
|
28
|
+
irrevocable. Licensors should read and understand the terms
|
|
29
|
+
and conditions of the license they choose before applying it.
|
|
30
|
+
Licensors should also secure all rights necessary before
|
|
31
|
+
applying our licenses so that the public can reuse the
|
|
32
|
+
material as expected. Licensors should clearly mark any
|
|
33
|
+
material not subject to the license. This includes other CC-
|
|
34
|
+
licensed material, or material used under an exception or
|
|
35
|
+
limitation to copyright. More considerations for licensors:
|
|
36
|
+
wiki.creativecommons.org/Considerations_for_licensors
|
|
37
|
+
|
|
38
|
+
Considerations for the public: By using one of our public
|
|
39
|
+
licenses, a licensor grants the public permission to use the
|
|
40
|
+
licensed material under specified terms and conditions. If
|
|
41
|
+
the licensor's permission is not necessary for any reason--for
|
|
42
|
+
example, because of any applicable exception or limitation to
|
|
43
|
+
copyright--then that use is not regulated by the license. Our
|
|
44
|
+
licenses grant only permissions under copyright and certain
|
|
45
|
+
other rights that a licensor has authority to grant. Use of
|
|
46
|
+
the licensed material may still be restricted for other
|
|
47
|
+
reasons, including because others have copyright or other
|
|
48
|
+
rights in the material. A licensor may make special requests,
|
|
49
|
+
such as asking that all changes be marked or described.
|
|
50
|
+
Although not required by our licenses, you are encouraged to
|
|
51
|
+
respect those requests where reasonable. More considerations
|
|
52
|
+
for the public:
|
|
53
|
+
wiki.creativecommons.org/Considerations_for_licensees
|
|
54
|
+
|
|
55
|
+
=======================================================================
|
|
56
|
+
|
|
57
|
+
Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International
|
|
58
|
+
Public License
|
|
59
|
+
|
|
60
|
+
By exercising the Licensed Rights (defined below), You accept and agree
|
|
61
|
+
to be bound by the terms and conditions of this Creative Commons
|
|
62
|
+
Attribution-NonCommercial-ShareAlike 4.0 International Public License
|
|
63
|
+
("Public License"). To the extent this Public License may be
|
|
64
|
+
interpreted as a contract, You are granted the Licensed Rights in
|
|
65
|
+
consideration of Your acceptance of these terms and conditions, and the
|
|
66
|
+
Licensor grants You such rights in consideration of benefits the
|
|
67
|
+
Licensor receives from making the Licensed Material available under
|
|
68
|
+
these terms and conditions.
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
Section 1 -- Definitions.
|
|
72
|
+
|
|
73
|
+
a. Adapted Material means material subject to Copyright and Similar
|
|
74
|
+
Rights that is derived from or based upon the Licensed Material
|
|
75
|
+
and in which the Licensed Material is translated, altered,
|
|
76
|
+
arranged, transformed, or otherwise modified in a manner requiring
|
|
77
|
+
permission under the Copyright and Similar Rights held by the
|
|
78
|
+
Licensor. For purposes of this Public License, where the Licensed
|
|
79
|
+
Material is a musical work, performance, or sound recording,
|
|
80
|
+
Adapted Material is always produced where the Licensed Material is
|
|
81
|
+
synched in timed relation with a moving image.
|
|
82
|
+
|
|
83
|
+
b. Adapter's License means the license You apply to Your Copyright
|
|
84
|
+
and Similar Rights in Your contributions to Adapted Material in
|
|
85
|
+
accordance with the terms and conditions of this Public License.
|
|
86
|
+
|
|
87
|
+
c. BY-NC-SA Compatible License means a license listed at
|
|
88
|
+
creativecommons.org/compatiblelicenses, approved by Creative
|
|
89
|
+
Commons as essentially the equivalent of this Public License.
|
|
90
|
+
|
|
91
|
+
d. Copyright and Similar Rights means copyright and/or similar rights
|
|
92
|
+
closely related to copyright including, without limitation,
|
|
93
|
+
performance, broadcast, sound recording, and Sui Generis Database
|
|
94
|
+
Rights, without regard to how the rights are labeled or
|
|
95
|
+
categorized. For purposes of this Public License, the rights
|
|
96
|
+
specified in Section 2(b)(1)-(2) are not Copyright and Similar
|
|
97
|
+
Rights.
|
|
98
|
+
|
|
99
|
+
e. Effective Technological Measures means those measures that, in the
|
|
100
|
+
absence of proper authority, may not be circumvented under laws
|
|
101
|
+
fulfilling obligations under Article 11 of the WIPO Copyright
|
|
102
|
+
Treaty adopted on December 20, 1996, and/or similar international
|
|
103
|
+
agreements.
|
|
104
|
+
|
|
105
|
+
f. Exceptions and Limitations means fair use, fair dealing, and/or
|
|
106
|
+
any other exception or limitation to Copyright and Similar Rights
|
|
107
|
+
that applies to Your use of the Licensed Material.
|
|
108
|
+
|
|
109
|
+
g. License Elements means the license attributes listed in the name
|
|
110
|
+
of a Creative Commons Public License. The License Elements of this
|
|
111
|
+
Public License are Attribution, NonCommercial, and ShareAlike.
|
|
112
|
+
|
|
113
|
+
h. Licensed Material means the artistic or literary work, database,
|
|
114
|
+
or other material to which the Licensor applied this Public
|
|
115
|
+
License.
|
|
116
|
+
|
|
117
|
+
i. Licensed Rights means the rights granted to You subject to the
|
|
118
|
+
terms and conditions of this Public License, which are limited to
|
|
119
|
+
all Copyright and Similar Rights that apply to Your use of the
|
|
120
|
+
Licensed Material and that the Licensor has authority to license.
|
|
121
|
+
|
|
122
|
+
j. Licensor means the individual(s) or entity(ies) granting rights
|
|
123
|
+
under this Public License.
|
|
124
|
+
|
|
125
|
+
k. NonCommercial means not primarily intended for or directed towards
|
|
126
|
+
commercial advantage or monetary compensation. For purposes of
|
|
127
|
+
this Public License, the exchange of the Licensed Material for
|
|
128
|
+
other material subject to Copyright and Similar Rights by digital
|
|
129
|
+
file-sharing or similar means is NonCommercial provided there is
|
|
130
|
+
no payment of monetary compensation in connection with the
|
|
131
|
+
exchange.
|
|
132
|
+
|
|
133
|
+
l. Share means to provide material to the public by any means or
|
|
134
|
+
process that requires permission under the Licensed Rights, such
|
|
135
|
+
as reproduction, public display, public performance, distribution,
|
|
136
|
+
dissemination, communication, or importation, and to make material
|
|
137
|
+
available to the public including in ways that members of the
|
|
138
|
+
public may access the material from a place and at a time
|
|
139
|
+
individually chosen by them.
|
|
140
|
+
|
|
141
|
+
m. Sui Generis Database Rights means rights other than copyright
|
|
142
|
+
resulting from Directive 96/9/EC of the European Parliament and of
|
|
143
|
+
the Council of 11 March 1996 on the legal protection of databases,
|
|
144
|
+
as amended and/or succeeded, as well as other essentially
|
|
145
|
+
equivalent rights anywhere in the world.
|
|
146
|
+
|
|
147
|
+
n. You means the individual or entity exercising the Licensed Rights
|
|
148
|
+
under this Public License. Your has a corresponding meaning.
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
Section 2 -- Scope.
|
|
152
|
+
|
|
153
|
+
a. License grant.
|
|
154
|
+
|
|
155
|
+
1. Subject to the terms and conditions of this Public License,
|
|
156
|
+
the Licensor hereby grants You a worldwide, royalty-free,
|
|
157
|
+
non-sublicensable, non-exclusive, irrevocable license to
|
|
158
|
+
exercise the Licensed Rights in the Licensed Material to:
|
|
159
|
+
|
|
160
|
+
a. reproduce and Share the Licensed Material, in whole or
|
|
161
|
+
in part, for NonCommercial purposes only; and
|
|
162
|
+
|
|
163
|
+
b. produce, reproduce, and Share Adapted Material for
|
|
164
|
+
NonCommercial purposes only.
|
|
165
|
+
|
|
166
|
+
2. Exceptions and Limitations. For the avoidance of doubt, where
|
|
167
|
+
Exceptions and Limitations apply to Your use, this Public
|
|
168
|
+
License does not apply, and You do not need to comply with
|
|
169
|
+
its terms and conditions.
|
|
170
|
+
|
|
171
|
+
3. Term. The term of this Public License is specified in Section
|
|
172
|
+
6(a).
|
|
173
|
+
|
|
174
|
+
4. Media and formats; technical modifications allowed. The
|
|
175
|
+
Licensor authorizes You to exercise the Licensed Rights in
|
|
176
|
+
all media and formats whether now known or hereafter created,
|
|
177
|
+
and to make technical modifications necessary to do so. The
|
|
178
|
+
Licensor waives and/or agrees not to assert any right or
|
|
179
|
+
authority to forbid You from making technical modifications
|
|
180
|
+
necessary to exercise the Licensed Rights, including
|
|
181
|
+
technical modifications necessary to circumvent Effective
|
|
182
|
+
Technological Measures. For purposes of this Public License,
|
|
183
|
+
simply making modifications authorized by this Section 2(a)
|
|
184
|
+
(4) never produces Adapted Material.
|
|
185
|
+
|
|
186
|
+
5. Downstream recipients.
|
|
187
|
+
|
|
188
|
+
a. Offer from the Licensor -- Licensed Material. Every
|
|
189
|
+
recipient of the Licensed Material automatically
|
|
190
|
+
receives an offer from the Licensor to exercise the
|
|
191
|
+
Licensed Rights under the terms and conditions of this
|
|
192
|
+
Public License.
|
|
193
|
+
|
|
194
|
+
b. Additional offer from the Licensor -- Adapted Material.
|
|
195
|
+
Every recipient of Adapted Material from You
|
|
196
|
+
automatically receives an offer from the Licensor to
|
|
197
|
+
exercise the Licensed Rights in the Adapted Material
|
|
198
|
+
under the conditions of the Adapter's License You apply.
|
|
199
|
+
|
|
200
|
+
c. No downstream restrictions. You may not offer or impose
|
|
201
|
+
any additional or different terms or conditions on, or
|
|
202
|
+
apply any Effective Technological Measures to, the
|
|
203
|
+
Licensed Material if doing so restricts exercise of the
|
|
204
|
+
Licensed Rights by any recipient of the Licensed
|
|
205
|
+
Material.
|
|
206
|
+
|
|
207
|
+
6. No endorsement. Nothing in this Public License constitutes or
|
|
208
|
+
may be construed as permission to assert or imply that You
|
|
209
|
+
are, or that Your use of the Licensed Material is, connected
|
|
210
|
+
with, or sponsored, endorsed, or granted official status by,
|
|
211
|
+
the Licensor or others designated to receive attribution as
|
|
212
|
+
provided in Section 3(a)(1)(A)(i).
|
|
213
|
+
|
|
214
|
+
b. Other rights.
|
|
215
|
+
|
|
216
|
+
1. Moral rights, such as the right of integrity, are not
|
|
217
|
+
licensed under this Public License, nor are publicity,
|
|
218
|
+
privacy, and/or other similar personality rights; however, to
|
|
219
|
+
the extent possible, the Licensor waives and/or agrees not to
|
|
220
|
+
assert any such rights held by the Licensor to the limited
|
|
221
|
+
extent necessary to allow You to exercise the Licensed
|
|
222
|
+
Rights, but not otherwise.
|
|
223
|
+
|
|
224
|
+
2. Patent and trademark rights are not licensed under this
|
|
225
|
+
Public License.
|
|
226
|
+
|
|
227
|
+
3. To the extent possible, the Licensor waives any right to
|
|
228
|
+
collect royalties from You for the exercise of the Licensed
|
|
229
|
+
Rights, whether directly or through a collecting society
|
|
230
|
+
under any voluntary or waivable statutory or compulsory
|
|
231
|
+
licensing scheme. In all other cases the Licensor expressly
|
|
232
|
+
reserves any right to collect such royalties, including when
|
|
233
|
+
the Licensed Material is used other than for NonCommercial
|
|
234
|
+
purposes.
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
Section 3 -- License Conditions.
|
|
238
|
+
|
|
239
|
+
Your exercise of the Licensed Rights is expressly made subject to the
|
|
240
|
+
following conditions.
|
|
241
|
+
|
|
242
|
+
a. Attribution.
|
|
243
|
+
|
|
244
|
+
1. If You Share the Licensed Material (including in modified
|
|
245
|
+
form), You must:
|
|
246
|
+
|
|
247
|
+
a. retain the following if it is supplied by the Licensor
|
|
248
|
+
with the Licensed Material:
|
|
249
|
+
|
|
250
|
+
i. identification of the creator(s) of the Licensed
|
|
251
|
+
Material and any others designated to receive
|
|
252
|
+
attribution, in any reasonable manner requested by
|
|
253
|
+
the Licensor (including by pseudonym if
|
|
254
|
+
designated);
|
|
255
|
+
|
|
256
|
+
ii. a copyright notice;
|
|
257
|
+
|
|
258
|
+
iii. a notice that refers to this Public License;
|
|
259
|
+
|
|
260
|
+
iv. a notice that refers to the disclaimer of
|
|
261
|
+
warranties;
|
|
262
|
+
|
|
263
|
+
v. a URI or hyperlink to the Licensed Material to the
|
|
264
|
+
extent reasonably practicable;
|
|
265
|
+
|
|
266
|
+
b. indicate if You modified the Licensed Material and
|
|
267
|
+
retain an indication of any previous modifications; and
|
|
268
|
+
|
|
269
|
+
c. indicate the Licensed Material is licensed under this
|
|
270
|
+
Public License, and include the text of, or the URI or
|
|
271
|
+
hyperlink to, this Public License.
|
|
272
|
+
|
|
273
|
+
2. You may satisfy the conditions in Section 3(a)(1) in any
|
|
274
|
+
reasonable manner based on the medium, means, and context in
|
|
275
|
+
which You Share the Licensed Material. For example, it may be
|
|
276
|
+
reasonable to satisfy the conditions by providing a URI or
|
|
277
|
+
hyperlink to a resource that includes the required
|
|
278
|
+
information.
|
|
279
|
+
3. If requested by the Licensor, You must remove any of the
|
|
280
|
+
information required by Section 3(a)(1)(A) to the extent
|
|
281
|
+
reasonably practicable.
|
|
282
|
+
|
|
283
|
+
b. ShareAlike.
|
|
284
|
+
|
|
285
|
+
In addition to the conditions in Section 3(a), if You Share
|
|
286
|
+
Adapted Material You produce, the following conditions also apply.
|
|
287
|
+
|
|
288
|
+
1. The Adapter's License You apply must be a Creative Commons
|
|
289
|
+
license with the same License Elements, this version or
|
|
290
|
+
later, or a BY-NC-SA Compatible License.
|
|
291
|
+
|
|
292
|
+
2. You must include the text of, or the URI or hyperlink to, the
|
|
293
|
+
Adapter's License You apply. You may satisfy this condition
|
|
294
|
+
in any reasonable manner based on the medium, means, and
|
|
295
|
+
context in which You Share Adapted Material.
|
|
296
|
+
|
|
297
|
+
3. You may not offer or impose any additional or different terms
|
|
298
|
+
or conditions on, or apply any Effective Technological
|
|
299
|
+
Measures to, Adapted Material that restrict exercise of the
|
|
300
|
+
rights granted under the Adapter's License You apply.
|
|
301
|
+
|
|
302
|
+
|
|
303
|
+
Section 4 -- Sui Generis Database Rights.
|
|
304
|
+
|
|
305
|
+
Where the Licensed Rights include Sui Generis Database Rights that
|
|
306
|
+
apply to Your use of the Licensed Material:
|
|
307
|
+
|
|
308
|
+
a. for the avoidance of doubt, Section 2(a)(1) grants You the right
|
|
309
|
+
to extract, reuse, reproduce, and Share all or a substantial
|
|
310
|
+
portion of the contents of the database for NonCommercial purposes
|
|
311
|
+
only;
|
|
312
|
+
|
|
313
|
+
b. if You include all or a substantial portion of the database
|
|
314
|
+
contents in a database in which You have Sui Generis Database
|
|
315
|
+
Rights, then the database in which You have Sui Generis Database
|
|
316
|
+
Rights (but not its individual contents) is Adapted Material,
|
|
317
|
+
including for purposes of Section 3(b); and
|
|
318
|
+
|
|
319
|
+
c. You must comply with the conditions in Section 3(a) if You Share
|
|
320
|
+
all or a substantial portion of the contents of the database.
|
|
321
|
+
|
|
322
|
+
For the avoidance of doubt, this Section 4 supplements and does not
|
|
323
|
+
replace Your obligations under this Public License where the Licensed
|
|
324
|
+
Rights include other Copyright and Similar Rights.
|
|
325
|
+
|
|
326
|
+
|
|
327
|
+
Section 5 -- Disclaimer of Warranties and Limitation of Liability.
|
|
328
|
+
|
|
329
|
+
a. UNLESS OTHERWISE SEPARATELY UNDERTAKEN BY THE LICENSOR, TO THE
|
|
330
|
+
EXTENT POSSIBLE, THE LICENSOR OFFERS THE LICENSED MATERIAL AS-IS
|
|
331
|
+
AND AS-AVAILABLE, AND MAKES NO REPRESENTATIONS OR WARRANTIES OF
|
|
332
|
+
ANY KIND CONCERNING THE LICENSED MATERIAL, WHETHER EXPRESS,
|
|
333
|
+
IMPLIED, STATUTORY, OR OTHER. THIS INCLUDES, WITHOUT LIMITATION,
|
|
334
|
+
WARRANTIES OF TITLE, MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
|
335
|
+
PURPOSE, NON-INFRINGEMENT, ABSENCE OF LATENT OR OTHER DEFECTS,
|
|
336
|
+
ACCURACY, OR THE PRESENCE OR ABSENCE OF ERRORS, WHETHER OR NOT
|
|
337
|
+
KNOWN OR DISCOVERABLE. WHERE DISCLAIMERS OF WARRANTIES ARE NOT
|
|
338
|
+
ALLOWED IN FULL OR IN PART, THIS DISCLAIMER MAY NOT APPLY TO YOU.
|
|
339
|
+
|
|
340
|
+
b. TO THE EXTENT POSSIBLE, IN NO EVENT WILL THE LICENSOR BE LIABLE
|
|
341
|
+
TO YOU ON ANY LEGAL THEORY (INCLUDING, WITHOUT LIMITATION,
|
|
342
|
+
NEGLIGENCE) OR OTHERWISE FOR ANY DIRECT, SPECIAL, INDIRECT,
|
|
343
|
+
INCIDENTAL, CONSEQUENTIAL, PUNITIVE, EXEMPLARY, OR OTHER LOSSES,
|
|
344
|
+
COSTS, EXPENSES, OR DAMAGES ARISING OUT OF THIS PUBLIC LICENSE OR
|
|
345
|
+
USE OF THE LICENSED MATERIAL, EVEN IF THE LICENSOR HAS BEEN
|
|
346
|
+
ADVISED OF THE POSSIBILITY OF SUCH LOSSES, COSTS, EXPENSES, OR
|
|
347
|
+
DAMAGES. WHERE A LIMITATION OF LIABILITY IS NOT ALLOWED IN FULL OR
|
|
348
|
+
IN PART, THIS LIMITATION MAY NOT APPLY TO YOU.
|
|
349
|
+
|
|
350
|
+
c. The disclaimer of warranties and limitation of liability provided
|
|
351
|
+
above shall be interpreted in a manner that, to the extent
|
|
352
|
+
possible, most closely approximates an absolute disclaimer and
|
|
353
|
+
waiver of all liability.
|
|
354
|
+
|
|
355
|
+
|
|
356
|
+
Section 6 -- Term and Termination.
|
|
357
|
+
|
|
358
|
+
a. This Public License applies for the term of the Copyright and
|
|
359
|
+
Similar Rights licensed here. However, if You fail to comply with
|
|
360
|
+
this Public License, then Your rights under this Public License
|
|
361
|
+
terminate automatically.
|
|
362
|
+
|
|
363
|
+
b. Where Your right to use the Licensed Material has terminated under
|
|
364
|
+
Section 6(a), it reinstates:
|
|
365
|
+
|
|
366
|
+
1. automatically as of the date the violation is cured, provided
|
|
367
|
+
it is cured within 30 days of Your discovery of the
|
|
368
|
+
violation; or
|
|
369
|
+
|
|
370
|
+
2. upon express reinstatement by the Licensor.
|
|
371
|
+
|
|
372
|
+
For the avoidance of doubt, this Section 6(b) does not affect any
|
|
373
|
+
right the Licensor may have to seek remedies for Your violations
|
|
374
|
+
of this Public License.
|
|
375
|
+
|
|
376
|
+
c. For the avoidance of doubt, the Licensor may also offer the
|
|
377
|
+
Licensed Material under separate terms or conditions or stop
|
|
378
|
+
distributing the Licensed Material at any time; however, doing so
|
|
379
|
+
will not terminate this Public License.
|
|
380
|
+
|
|
381
|
+
d. Sections 1, 5, 6, 7, and 8 survive termination of this Public
|
|
382
|
+
License.
|
|
383
|
+
|
|
384
|
+
|
|
385
|
+
Section 7 -- Other Terms and Conditions.
|
|
386
|
+
|
|
387
|
+
a. The Licensor shall not be bound by any additional or different
|
|
388
|
+
terms or conditions communicated by You unless expressly agreed.
|
|
389
|
+
|
|
390
|
+
b. Any arrangements, understandings, or agreements regarding the
|
|
391
|
+
Licensed Material not stated herein are separate from and
|
|
392
|
+
independent of the terms and conditions of this Public License.
|
|
393
|
+
|
|
394
|
+
|
|
395
|
+
Section 8 -- Interpretation.
|
|
396
|
+
|
|
397
|
+
a. For the avoidance of doubt, this Public License does not, and
|
|
398
|
+
shall not be interpreted to, reduce, limit, restrict, or impose
|
|
399
|
+
conditions on any use of the Licensed Material that could lawfully
|
|
400
|
+
be made without permission under this Public License.
|
|
401
|
+
|
|
402
|
+
b. To the extent possible, if any provision of this Public License is
|
|
403
|
+
deemed unenforceable, it shall be automatically reformed to the
|
|
404
|
+
minimum extent necessary to make it enforceable. If the provision
|
|
405
|
+
cannot be reformed, it shall be severed from this Public License
|
|
406
|
+
without affecting the enforceability of the remaining terms and
|
|
407
|
+
conditions.
|
|
408
|
+
|
|
409
|
+
c. No term or condition of this Public License will be waived and no
|
|
410
|
+
failure to comply consented to unless expressly agreed to by the
|
|
411
|
+
Licensor.
|
|
412
|
+
|
|
413
|
+
d. Nothing in this Public License constitutes or may be interpreted
|
|
414
|
+
as a limitation upon, or waiver of, any privileges and immunities
|
|
415
|
+
that apply to the Licensor or You, including from the legal
|
|
416
|
+
processes of any jurisdiction or authority.
|
|
417
|
+
|
|
418
|
+
=======================================================================
|
|
419
|
+
|
|
420
|
+
Creative Commons is not a party to its public
|
|
421
|
+
licenses. Notwithstanding, Creative Commons may elect to apply one of
|
|
422
|
+
its public licenses to material it publishes and in those instances
|
|
423
|
+
will be considered the “Licensor.” The text of the Creative Commons
|
|
424
|
+
public licenses is dedicated to the public domain under the CC0 Public
|
|
425
|
+
Domain Dedication. Except for the limited purpose of indicating that
|
|
426
|
+
material is shared under a Creative Commons public license or as
|
|
427
|
+
otherwise permitted by the Creative Commons policies published at
|
|
428
|
+
creativecommons.org/policies, Creative Commons does not authorize the
|
|
429
|
+
use of the trademark "Creative Commons" or any other trademark or logo
|
|
430
|
+
of Creative Commons without its prior written consent including,
|
|
431
|
+
without limitation, in connection with any unauthorized modifications
|
|
432
|
+
to any of its public licenses or any other arrangements,
|
|
433
|
+
understandings, or agreements concerning use of licensed material. For
|
|
434
|
+
the avoidance of doubt, this paragraph does not form part of the
|
|
435
|
+
public licenses.
|
|
436
|
+
|
|
437
|
+
Creative Commons may be contacted at creativecommons.org.
|
|
438
|
+
|
package/README.md
CHANGED
|
@@ -9,11 +9,7 @@
|
|
|
9
9
|
|
|
10
10
|
# nmrium-core-plugins
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
[![npm download][download-image]][download-url]
|
|
14
|
-
[![DOI][doi-image]][doi-url]
|
|
15
|
-
|
|
16
|
-
Package containing core plugins to work with nmrium.
|
|
12
|
+
Package containing core plugins to work with NMRium.
|
|
17
13
|
It provides essential loaders:
|
|
18
14
|
|
|
19
15
|
- bruker
|
|
@@ -77,7 +73,7 @@ console.log(result);
|
|
|
77
73
|
// molecules: [],
|
|
78
74
|
// }
|
|
79
75
|
|
|
80
|
-
// readSource function accept a partial FileCollectionItems and a baseURL to generate a
|
|
76
|
+
// readSource function accept a partial FileCollectionItems and a baseURL to generate a
|
|
81
77
|
// data structure with a source object inside with { files, filter, baseURL }
|
|
82
78
|
|
|
83
79
|
const nmriumObject = await core.readFromWebSource(
|
|
@@ -105,11 +101,3 @@ It returns an array of plugins, you have to register them in the core.
|
|
|
105
101
|
© 2025 Zakodium Sàrl. This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License. [CC BY-NC-SA 4.0](./LICENSE)
|
|
106
102
|
|
|
107
103
|
This package is based on MIT-licensed code that can be found here: https://doi.org/10.5281/zenodo.7100132
|
|
108
|
-
|
|
109
|
-
[npm-image]: https://img.shields.io/npm/v/@zakodium/nmrium-core-plugins.svg
|
|
110
|
-
[npm-url]: https://www.npmjs.com/package/@zakodium/nmrium-core-plugins
|
|
111
|
-
[download-image]: https://img.shields.io/npm/dm/@zakodium/nmrium-core-plugins.svg
|
|
112
|
-
[download-url]: https://www.npmjs.com/package/@zakodium/nmrium-core-plugins
|
|
113
|
-
[doi-image]: https://zenodo.org/badge/DOI/10.5281/zenodo.7101438.svg
|
|
114
|
-
<!-- TODO: fix doi-url for nmrium-core-plugins package -->
|
|
115
|
-
[doi-url]: https://doi.org/10.5281/zenodo.7101438
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import{NMRiumCore as ms}from"@zakodium/nmrium-core";import{Filters1D as Or,Filters2D as wr}from"nmr-processing";import{getOneIfArray as xr}from"@zakodium/nmrium-core";function re(e={},r={},t={}){e===null&&(e={}),typeof e=="string"&&(e={pulseSequence:e});let i=Array.isArray(e.pulseSequence)?e.pulseSequence[0]:e.pulseSequence||"";if(typeof i!="string")return e.dimension?`${e.dimension}d`:"";if(i=i.toLowerCase(),i.includes("zg")||i.includes("single_pulse_dec")||i.includes("udeft"))return"1d";if(i.includes("hsqct")||i.includes("invi")&&(i.includes("ml")||i.includes("di")))return"hsqctocsy";if(i.includes("hsqc")||i.includes("invi"))return"hsqc";if(i.includes("hmbc")||i.includes("inv4")&&i.includes("lp"))return"hmbc";if(i.includes("hmqc"))return"hmqc";if(i.includes("cosy"))return"cosy";if(i.includes("jres"))return"jres";if(i.includes("dosy"))return"dosy";if(i.includes("tocsy")||i.includes("mlev")||i.includes("dipsi"))return"tocsy";if(i.includes("noesy"))return"noesy";if(i.includes("roesy"))return"roesy";if(i.includes("dept"))return"dept";if(i.includes("jmod")||i.includes("apt"))return"aptjmod";if(i.includes("inad"))return"inadequate";if(i.includes("adeq"))return"adequate";let{prefix:n=""}=t,s=(xr(r[`${n}SPECTYP`])||"").replace(/^<(.*)>$/,"$1").toLowerCase();return s.length>0&&s!=="undefined"?s:e.dimension?`${e.dimension}d`:""}import{getOneIfArray as He}from"@zakodium/nmrium-core";var Mr=["no","exponential","modifiedGaussian","sine","qsine","trap","user","sinc","qsinc","traf","trafs"];function Rr(e){return e in Ze}function Me(e,r){let{prefix:t="",index:i=0}=r,n=He(e[`${t}WDW`],i),s=Mr[n?Number(n):0],o={};if(!Rr(s))return o;let l=Ze[s];if(l){let{kind:a,parameters:m}=l,f={};for(let c in m){let b=m[c],{source:u,processor:y}=b;if(u){let g=He(e[`${t}${u}`],i);if(!g)continue;let p=Number(g);f[c]=y?y(p):p}else b.value!==void 0&&(f[c]=b.value)}o[a]={apply:!0,options:f}}return o}var Ze={exponential:{kind:"exponential",parameters:{lineBroadening:{source:"LB"}}},modifiedGaussian:{kind:"gaussian",parameters:{lineBroadening:{source:"LB"},lineBroadeningCenter:{source:"GB"}}},sine:{kind:"sineBell",parameters:{offset:{source:"SSB",processor:e=>1/e},exponent:{value:1}}},qsine:{kind:"sineSquare",parameters:{offset:{source:"SSB",processor:e=>1/e}}},traf:{kind:"traf",parameters:{lineBroadening:{source:"LB"}}}};var Ke={sineBell:et({offset:0})},Qe={cosy:{...Ke},hmbc:{...Ke},hsqc:{sineBell:et({offset:.5})}},Ir={...Qe};function Re(e="",r=1){let t=Er(e),i={},n=r===1?Qe[t||""]:Ir[t||""];return n&&(i=structuredClone(n)),i}function et(e){return{apply:!0,options:e}}function Er(e){let t=e.toLowerCase().match(/cosy|hsqc|hmbc/);return t?t[0]:null}function tt(e,r={}){let{prefix:t="",experiment:i=re(e)}=r;return e[`${t}WDW`]?{f2:Me(e,{...r,index:0}),f1:Me(e,{...r,index:1})}:{f2:Re(i,1),f1:Re(i,2)}}import{Filters1D as Cr}from"nmr-processing";var Ie=["digitalFilter","backwardLinearPrediction","forwardLinearPrediction","apodization","zeroFilling","fft",["shiftX","phaseCorrection","baselineCorrection"]],z={};for(let e=0;e<Ie.length;e++){let r=Ie[e];for(let t of Array.isArray(r)?r:[r])z[t]=e}for(let e of Object.values(Cr))e.name in z||(z[e.name]=Ie.length);import{Filters2D as Tr}from"nmr-processing";var Ee=["digitalFilter2D","blpDimension1","flpDimension1","apodizationDimension1","zeroFillingDimension1","fftDimension1","blpDimension2","flpDimension2","nusDimension2","apodizationDimension2","zeroFillingDimension2","fftDimension2","phaseCorrectionTwoDimensions",["shift2DX","shift2DY","symmetrizeCosyLike"]],W={};for(let e=0;e<Ee.length;e++){let r=Ee[e];for(let t of Array.isArray(r)?r:[r])W[t]=e}for(let e of Object.values(Tr))e.name in W||(W[e.name]=Ee.length);var vr=new Set(["backwardLinearPrediction","forwardLinearPrediction","digitalFilter2D","phaseCorrectionTwoDimensions","blpDimension1","flpDimension1","apodizationDimension1","apodizationDimension2","zeroFillingDimension1","fftDimension1","blpDimension2","flpDimension2","zeroFillingDimension2","fftDimension2","nusDimension2","symmetrizeCosyLike"]);function Lr(e,r){let{filter:t,experimentalFeatures:i=!1}=r,{name:n}=t;({...Or,...wr})[n]&&(e.some(o=>o.name===n)||(i||!vr.has(n))&&e.push({...t,enabled:!0}))}function rt(e,r={}){let{data:t}=e;if(!t)return e;let{autoProcessing:i,experimentalFeatures:n}=r,s=(l,a)=>Lr(l,{...a,experimentalFeatures:n}),{spectra:o}=t;for(let l of o){let{data:a,info:m,meta:f,filters:c}=l,{dimension:b,isFid:u}=m;if(u){if(b===1){let y=a.re.length,{tdOff:g,digitalFilter:p}=m;if(p&&p>0&&s(c,{filter:{name:"digitalFilter",value:{digitalFilterValue:p}}}),!i)continue;g&&Math.abs(g)>0&&s(c,{filter:{name:"backwardLinearPrediction",value:{nbInputs:y/2}}}),s(c,{filter:{name:"apodization",value:{exponential:{apply:!0,options:{lineBroadening:1}}}}}),s(c,{filter:{name:"zeroFilling",value:{nbPoints:2*y}}}),s(c,{filter:{name:"fft",value:{}}}),s(c,{filter:{name:"phaseCorrection",value:kr(m)}}),c.sort((d,h)=>z[d.name]-z[h.name])}else if(b===2){if(!i||!n)continue;let y=a.re.z.length,g=a.re.z[0].length,{tdOff:p,experiment:d=""}=m,h=m.spectrumSize;Array.isArray(h)&&h.length>1?(h[0]<=g&&(h[0]=g*2),h[0]<=y&&(h[0]=y*2)):h=[g*2,2*y];let F=d.toLowerCase().includes("cosy");p&&Math.abs(p[0])>0&&s(c,{filter:{name:"blpDimension1",value:{nbInputs:g/2}}});let N=tt(f,{experiment:d});s(c,{filter:{name:"apodizationDimension1",value:N.f2}}),s(c,{filter:{name:"zeroFillingDimension1",value:{nbPoints:h[0]}}}),s(c,{filter:{name:"fftDimension1",value:{}}}),f&&"nuslist"in f&&s(c,{filter:{name:"nusDimension2",value:{}}}),s(c,{filter:{name:"apodizationDimension2",value:N.f1}}),s(c,{filter:{name:"zeroFillingDimension2",value:{nbPoints:h[F?0:1]}}}),F?s(c,{filter:{name:"symmetrizeCosyLike",value:{}}}):s(c,{filter:{name:"phaseCorrectionTwoDimensions",value:{}}}),s(c,{filter:{name:"fftDimension2",value:{}}}),c.sort((x,S)=>W[x.name]-W[S.name])}}}}function kr(e){let{phc0:r=0,phc1:t=0}=e;return nt([r,t])?{}:{ph0:r,ph1:t}}function nt(e){return Array.isArray(e)?e.every(r=>!r&&r===0):nt([e])}var ne=class{id="@zakodium/nmrium-core-plugins#AutoPostProcessingPlugin";version=1;migrations=[];onReadProcess;constructor(){this.onReadProcess={onProcessing:this.onPostProcessing.bind(this)}}onPostProcessing(r,t){rt(r,t)}};function Ce(){return new ne}import{fileCollectionFromZip as $s}from"filelist-utils";import{convert as Vr}from"jcampconverter";function Te(e,r="utf8"){return new TextDecoder(r).decode(e)}var qr=new TextEncoder;function it(e){return qr.encode(e)}var Br=1024*8,_r=(()=>{let e=new Uint8Array(4),r=new Uint32Array(e.buffer);return!((r[0]=1)&e[0])})(),Oe={int8:globalThis.Int8Array,uint8:globalThis.Uint8Array,int16:globalThis.Int16Array,uint16:globalThis.Uint16Array,int32:globalThis.Int32Array,uint32:globalThis.Uint32Array,uint64:globalThis.BigUint64Array,int64:globalThis.BigInt64Array,float32:globalThis.Float32Array,float64:globalThis.Float64Array},v=class e{buffer;byteLength;byteOffset;length;offset;lastWrittenByte;littleEndian;_data;_mark;_marks;constructor(r=Br,t={}){let i=!1;typeof r=="number"?r=new ArrayBuffer(r):(i=!0,this.lastWrittenByte=r.byteLength);let n=t.offset?t.offset>>>0:0,s=r.byteLength-n,o=n;(ArrayBuffer.isView(r)||r instanceof e)&&(r.byteLength!==r.buffer.byteLength&&(o=r.byteOffset+n),r=r.buffer),i?this.lastWrittenByte=s:this.lastWrittenByte=0,this.buffer=r,this.length=s,this.byteLength=s,this.byteOffset=o,this.offset=0,this.littleEndian=!0,this._data=new DataView(this.buffer,o,s),this._mark=0,this._marks=[]}available(r=1){return this.offset+r<=this.length}isLittleEndian(){return this.littleEndian}setLittleEndian(){return this.littleEndian=!0,this}isBigEndian(){return!this.littleEndian}setBigEndian(){return this.littleEndian=!1,this}skip(r=1){return this.offset+=r,this}back(r=1){return this.offset-=r,this}seek(r){return this.offset=r,this}mark(){return this._mark=this.offset,this}reset(){return this.offset=this._mark,this}pushMark(){return this._marks.push(this.offset),this}popMark(){let r=this._marks.pop();if(r===void 0)throw new Error("Mark stack empty");return this.seek(r),this}rewind(){return this.offset=0,this}ensureAvailable(r=1){if(!this.available(r)){let i=(this.offset+r)*2,n=new Uint8Array(i);n.set(new Uint8Array(this.buffer)),this.buffer=n.buffer,this.length=i,this.byteLength=i,this._data=new DataView(this.buffer)}return this}readBoolean(){return this.readUint8()!==0}readInt8(){return this._data.getInt8(this.offset++)}readUint8(){return this._data.getUint8(this.offset++)}readByte(){return this.readUint8()}readBytes(r=1){return this.readArray(r,"uint8")}readArray(r,t){let i=Oe[t].BYTES_PER_ELEMENT*r,n=this.byteOffset+this.offset,s=this.buffer.slice(n,n+i);if(this.littleEndian===_r&&t!=="uint8"&&t!=="int8"){let l=new Uint8Array(this.buffer.slice(n,n+i));l.reverse();let a=new Oe[t](l.buffer);return this.offset+=i,a.reverse(),a}let o=new Oe[t](s);return this.offset+=i,o}readInt16(){let r=this._data.getInt16(this.offset,this.littleEndian);return this.offset+=2,r}readUint16(){let r=this._data.getUint16(this.offset,this.littleEndian);return this.offset+=2,r}readInt32(){let r=this._data.getInt32(this.offset,this.littleEndian);return this.offset+=4,r}readUint32(){let r=this._data.getUint32(this.offset,this.littleEndian);return this.offset+=4,r}readFloat32(){let r=this._data.getFloat32(this.offset,this.littleEndian);return this.offset+=4,r}readFloat64(){let r=this._data.getFloat64(this.offset,this.littleEndian);return this.offset+=8,r}readBigInt64(){let r=this._data.getBigInt64(this.offset,this.littleEndian);return this.offset+=8,r}readBigUint64(){let r=this._data.getBigUint64(this.offset,this.littleEndian);return this.offset+=8,r}readChar(){return String.fromCharCode(this.readInt8())}readChars(r=1){let t="";for(let i=0;i<r;i++)t+=this.readChar();return t}readUtf8(r=1){return Te(this.readBytes(r))}decodeText(r=1,t="utf8"){return Te(this.readBytes(r),t)}writeBoolean(r){return this.writeUint8(r?255:0),this}writeInt8(r){return this.ensureAvailable(1),this._data.setInt8(this.offset++,r),this._updateLastWrittenByte(),this}writeUint8(r){return this.ensureAvailable(1),this._data.setUint8(this.offset++,r),this._updateLastWrittenByte(),this}writeByte(r){return this.writeUint8(r)}writeBytes(r){this.ensureAvailable(r.length);for(let t=0;t<r.length;t++)this._data.setUint8(this.offset++,r[t]);return this._updateLastWrittenByte(),this}writeInt16(r){return this.ensureAvailable(2),this._data.setInt16(this.offset,r,this.littleEndian),this.offset+=2,this._updateLastWrittenByte(),this}writeUint16(r){return this.ensureAvailable(2),this._data.setUint16(this.offset,r,this.littleEndian),this.offset+=2,this._updateLastWrittenByte(),this}writeInt32(r){return this.ensureAvailable(4),this._data.setInt32(this.offset,r,this.littleEndian),this.offset+=4,this._updateLastWrittenByte(),this}writeUint32(r){return this.ensureAvailable(4),this._data.setUint32(this.offset,r,this.littleEndian),this.offset+=4,this._updateLastWrittenByte(),this}writeFloat32(r){return this.ensureAvailable(4),this._data.setFloat32(this.offset,r,this.littleEndian),this.offset+=4,this._updateLastWrittenByte(),this}writeFloat64(r){return this.ensureAvailable(8),this._data.setFloat64(this.offset,r,this.littleEndian),this.offset+=8,this._updateLastWrittenByte(),this}writeBigInt64(r){return this.ensureAvailable(8),this._data.setBigInt64(this.offset,r,this.littleEndian),this.offset+=8,this._updateLastWrittenByte(),this}writeBigUint64(r){return this.ensureAvailable(8),this._data.setBigUint64(this.offset,r,this.littleEndian),this.offset+=8,this._updateLastWrittenByte(),this}writeChar(r){return this.writeUint8(r.charCodeAt(0))}writeChars(r){for(let t=0;t<r.length;t++)this.writeUint8(r.charCodeAt(t));return this}writeUtf8(r){return this.writeBytes(it(r))}toArray(){return new Uint8Array(this.buffer,this.byteOffset,this.lastWrittenByte)}getWrittenByteLength(){return this.lastWrittenByte-this.byteOffset}_updateLastWrittenByte(){this.offset>this.lastWrittenByte&&(this.lastWrittenByte=this.offset)}};import{createStepArray as Yr,xMinMaxValues as Gr}from"ml-spectra-processing";import{isAnyArray as Zr}from"is-any-array";import{matrixCreateEmpty as Kr,xSequentialFillFromStep as Qr}from"ml-spectra-processing";var st=["acqus","acqu2s"],ie=["procs","proc2s"];function Ur(e){return e.is1D?$r(e):e.is2D?jr(e):{checked:!1,message:"Multi-dimensional n > 2 is not supported"}}function $r(e){let r=e.isFID?["acqus"]:["acqus","procs"],t=r.every(i=>e[i]);return{checked:t,message:t?"":`File: ${e[e.isFID?"fid":"1r"]?.relativePath} is ignored, files: ${r.join(",")} are required.`}}function jr(e){let r=e.isFID?st:st.concat(ie),t=r.every(i=>e[i]);return t&&e.isFID&&ie.some(i=>e[i])&&!ie.every(i=>e[i])&&(t=!1,r.push(...ie)),{checked:t,message:t?"":`File: ${e.name} is ignored, files: ${r.join(",")} are required.`}}function ct(e,r={}){let{logger:t,processingNumbers:i,experimentNumbers:n,dataSelection:s="both",keep1D:o=!0,keep2D:l=!0,onlyFirstProcessedData:a=!0}=r,m={},f=e.files.map(u=>u.relativePath);for(let u of e){let y,g,p,d,h=u.relativePath.split("/"),F=h.indexOf("pdata");if(F!==-1)y=Number(h[F+1]),g=Number(h[F-1]),d=h.slice(0,-3).join("/");else if(Wr(u,f)){let N=h.indexOf(u.name);g=Number(h[N-1]),d=h.slice(0,-1).join("/")}else continue;if(Number.isNaN(g)&&(g=void 0),Number.isNaN(y)&&(y=void 0),!(n&&!n.includes(g))){if(m[d]||(m[d]={name:d,expno:g,processedData:{},fileCollectionItems:[]}),p=m[d],u.name==="vdlist"&&(p.vdlist=u),u.name==="difflist"&&(p.difflist=u),y){p.processedData[y]||(p.processedData[y]={fileCollectionItems:[],name:d,expno:g,procno:y});let N=p.processedData[y];N.fileCollectionItems.push(u),u.name.match(/^(1r|1i|2rr|2ir|2ii|2ri|procs|proc2s|title|integrals.txt)$/)&&(N[u.name]=u),u.name==="2rr"&&(N.is2D=!0,N.isFT=!0),u.name==="1r"&&(N.is1D=!0,N.isFT=!0)}else p.fileCollectionItems.push(u),u.name.match(/^(ser|fid|acqus|acqu2s|nuslist)$/)&&(p[u.name]=u),u.name==="ser"&&(p.is2D=!0,p.isFID=!0),u.name==="fid"&&(p.is1D=!0,p.isFID=!0);u.name==="QuantFactorSample.xml"&&(p.quantFactorSample=u)}}if(i)for(let u in m){let y=m[u].processedData,g={};for(let p in y)i.includes(Number.parseInt(p,10))&&(g[p]=y[p]);m[u].processedData=g}else if(a)for(let u in m){let y=m[u].processedData,g=Object.keys(y).sort((p,d)=>Number(p)-Number(d))[0];g!==void 0&&(m[u].processedData={firstProcessedNumber:y[g]})}let c=Xr(t),b=[];for(let u in m){let y=m[u],{processedData:g,...p}=y;if(c(y,s)){let h=Object.keys(g);if(h.length>0){let F=g[h[0]];F.procs&&(p.fileCollectionItems.push(F.procs),p.procs=F.procs),F.proc2s&&(p.fileCollectionItems.push(F.proc2s),p.proc2s=F.proc2s),F["integrals.txt"]&&(p.integrals=F["integrals.txt"])}b.push(p)}let d="ser"in p||"fid"in p;if(s==="fid"||s==="preferFID"&&d){t?.warn("Skipping FT data because it does not match the import filters");continue}for(let h in g){let F=g[h];(F["1r"]||F["2rr"])&&(p.acqus&&F.fileCollectionItems.push(p.acqus),p.acqu2s&&F.fileCollectionItems.push(p.acqu2s),p.vdlist&&(F.vdlist=p.vdlist),b.push({integrals:F["integrals.txt"],acqus:p.acqus,acqu2s:p.acqu2s,...F}))}}return o||(t?.warn("Skipping 1D data because it does not match the import filters"),b=b.filter(u=>!u.is1D)),l||(t?.warn("Skipping 2D data because it does not match the import filters"),b=b.filter(u=>!u.is2D)),zr(b,r.logger)}function zr(e,r){return e.filter(t=>{let{checked:i,message:n}=Ur(t);return i||r?.warn(n),i})}function Wr(e,r){return e.name.match(/^(ser|acqus|acqu2s|nuslist|vdlist|difflist|QuantFactorSample.xml)$/)||e.name.match(/^(fid)$/)&&r.includes(e.relativePath.replace(/fid$/,"acqus"))}function Xr(e){return(r,t)=>{let{processedData:i}=r,n=Object.keys(i),s=n.length>0&&["1r","1i","2rr"].some(a=>a in i[n[0]]),o="ser"in r||"fid"in r,l=o&&(t!=="ft"&&t!=="preferFT"||t==="preferFT"&&!s);return o&&!l&&e?.warn("Skipping RAW data because it does not match import filters"),l}}function mt(e){if(e===void 0||Array.isArray(e)&&e.length===0)return{epoch:null,date:""};let r=e[0]*1e3;return{epoch:r,date:new Date(r).toUTCString()}}function ut(e,r){for(let t in r.meta)e.meta[t]===void 0&&(e.meta[t]=r.meta[t]);for(let t in r.info)e.info[t]===void 0&&(e.info[t]=r.info[t]);for(let t in e.meta)Array.isArray(e.meta[t])||(e.meta[t]=[e.meta[t]])}async function X(e,r){if(!e)return{info:{},meta:{}};let t=await e.text(),{keepRecordsRegExp:i=/.*/}=r,n=Vr(t,{keepRecordsRegExp:i});return n.flatten.length===0?{}:n.flatten[0]}async function Jr(e){let r=(await e.integrals.text()).split(/\r?\n/).slice(3).filter(Boolean),t=[];for(let i=1;i<r.length;i++){let n=r[i].replace(/^\s*/,"").replaceAll(/[\s\t]+/g,";").match(/\d+;(?<from>[0-9.]+);(?<to>[0-9.]+);(?<integration>[0-9.]+)/);if(n){let{from:s,to:o,integration:l}=n.groups;t.push({from:Number.parseFloat(s),to:Number.parseFloat(o),integration:Number.parseFloat(l)})}}return t}function pt(e,r){let{x:t,minMax:i,nbSubSpectra:n,template:s}=r;e.spectra||(e.spectra=[]);for(let o=0;o<n;o++){let l={};for(let a in i)l[a]=i[a].z[o];e.spectra.push({...s,data:{...l,x:t}})}}function ft(e,r,t){let i=Number.parseInt(r.meta.TD[0],10),n=new v(e),s=r.meta.nbSubSpectra||1,o=r.meta.AQ_mod,l=Number.parseInt(r.meta.DTYPA,10)===2,a=Number.parseFloat(r.meta.SW_h[0]),m=Number.parseFloat(r.meta.SFO1[0]);r.meta.DATATYPE="NMR FID";let f=1/(2*a),c=i*f,b=Number.parseInt(r.meta.BYTORDA,10);b=b?0:1,b?n.setLittleEndian():n.setBigEndian();let u=o===2?f:2*f,y=Hr({nbSubSpectra:s,isFloat:l,aqMode:o,td:i}),g={dataType:"NMR FID",dataTable:"(X++(R..R))",nbPoints:y,firstX:0,lastX:c,nucleus:r.meta.NUC1,xUnit:"Sec",yUnit:"Arbitrary",isXYdata:!0,isFID:!0,observeFrequency:m,title:r.meta.TITLE,deltaX:u},p=Yr({length:y,step:u});if(s<2){let d=at(n,{nbPoints:y,isFloat:l,aqMode:o});r.spectra=[{data:{x:p,...d},...g}]}else{let d={minX:p[0],maxX:p.at(-1),minY:0,maxY:s},h=o===2?{re:{z:[],...d},im:null}:{re:{z:[],...d},im:{z:[],...d}},F={re:{min:Number.MAX_SAFE_INTEGER,max:Number.MIN_SAFE_INTEGER},im:{min:Number.MAX_SAFE_INTEGER,max:Number.MIN_SAFE_INTEGER}};for(let N=0;N<s;N++){let x=at(n,{nbPoints:y,isFloat:l,aqMode:o});F.re=ot(x.re,F.re),F.im=ot(x.im,F.im),h.re.z.push(x.re),h.im&&h.im.z.push(x.im)}h.re={...h.re,minZ:F.re.min,maxZ:F.re.max},h.im={...h.im,minZ:F.im.min,maxZ:F.im.max},t.keepSpectra&&pt(r,{minMax:h,x:p,nbSubSpectra:s,template:g}),r.minMax=h}}function ot(e,r){let{min:t,max:i}=Gr(e),{min:n,max:s}=r;return{min:Math.min(n,t),max:Math.max(s,i)}}function at(e,r){let{nbPoints:t,isFloat:i,aqMode:n}=r,s={re:new Float64Array(t),im:null},o=i?"readFloat64":"readInt32";if(n===2)for(let l=0;l<t;l++)s.re[l]=e[o]();else{s.im=new Float64Array(t);for(let l=0;l<t;l++)s.re[l]=e[o](),s.im[l]=e[o]()}return s}function Hr(e){let{nbSubSpectra:r,isFloat:t,aqMode:i,td:n}=e,s=n;if(r>1){let o=t?128:256;s=Math.trunc(Math.ceil(n/o)*o)}return i===2?s:s/2>>0}function en(e){for(let r in e){let{z:t}=e[r],{minX:i,minY:n,maxX:s,maxY:o}=e[r];if(i>s){[i,s]=[s,i];for(let l of t)l.reverse()}n>o&&(t.reverse(),[n,o]=[o,n]),e[r]={...e[r],z:t,minX:i,minY:n,maxY:o,maxX:s}}}function dt(e,r,t={}){let i={};for(let y in e)e[y]&&(i[y]=new v(e[y]));let n=se(r.meta.SI),s=se(r.meta.SW_p),o=se(r.meta.SF),l=o,a=se(r.shiftOffsetVal||r.meta.OFFSET);r.meta.observeFrequency=o,r.meta.brukerReference=l,r.meta.DATATYPE="NMR Spectrum";let m=Number.parseInt(r.meta.BYTORDP,10);m=m?0:1;let f=r.meta.nbSubSpectra||1;if(m)for(let y in i)i[y].setLittleEndian();else for(let y in i)i[y].setBigEndian();let c={dataType:"NMR Spectrum",nbPoints:n,firstX:a,lastX:a-s/o,xUnit:"PPM",yUnit:"Arbitrary",isXYdata:!0,isFT:!0,nucleus:r.meta.NUC1,observeFrequency:o,title:r.meta.TITLE,deltaX:-(s/o)/(n-1)},b=c.deltaX,u=Qr({from:a,step:b,size:n});if(f===1){let y={};for(let g in i){let p=i[g],d=new Float64Array(n);for(let h=0;h<n;++h)d[h]=p.readInt32();y[g]=d}r.spectra.push({...c,data:{...y,x:u}})}else{let{meta:y}=r,g=Number(y.SF[1]),p=Number(y.SW_p[1]||y.SW[1]),d=Number(y.OFFSET[1]),h=d-p/g,F={};for(let N in i)F[N]={minY:d,maxY:h,minX:u[0],maxX:u.at(-1),...tn(y,i[N])};en(F),t.keepSpectra&&pt(r,{minMax:F,x:u,nbSubSpectra:f,template:c}),r.minMax=F}}function se(e){return Number(Zr(e)?e[0]:e)}function tn(e,r){let t=e.SI.slice().reverse(),i=e.XDIM.slice().reverse(),n=t.map((u,y)=>Number.parseInt(u/i[y],10)),[s,o]=t,[l,a]=i,m=Kr({nbRows:s,nbColumns:o}),[f,c]=[Number.MAX_SAFE_INTEGER,Number.MIN_SAFE_INTEGER],b=[];for(let u=0;u<n[0];u++)for(let y=0;y<n[1];y++){let g=y*a,p=u*l;b.push([p,g])}for(let[u,y]of b)for(let g=0;g<l;g++)for(let p=0;p<a;p++){let d=r.readInt32();f>d&&(f=d),c<d&&(c=d),m[g+u][p+y]=d}return{z:m,minZ:f,maxZ:c}}async function rn(e,r){let t={},i=[],n=e["1r"]||e["1i"]?["1r","1i"]:["fid"];function s(o,l){return o.then(a=>{t[l]=a})}for(let o of n)e[o]&&i.push(s(e[o].arrayBuffer(),o));return i.push(s(X(e.procs,r),"procs"),s(X(e.acqus,r),"acqus")),e.quantFactorSample&&i.push(s(sn(e),"ereticFactor")),e.integrals&&i.push(s(Jr(e),"integrals")),e.title&&i.push(s(e.title.text(),"titleFile")),await Promise.all(i),nn(t)}function nn(e){let{procs:r,acqus:t,integrals:i,ereticFactor:n,titleFile:s}=e;ut(r,t);let{epoch:o,date:l}=mt(r.meta.DATE);return l.length>0&&(r.info={...r.info,epoch:o,date:l}),i&&(r.integrals=i),n&&(r.info.ereticFactor=n),s&&(r.meta.TITLE_FILE=s),e["1r"]||e["1i"]?dt({re:e["1r"],im:e["1i"]},r):e.fid&&ft(e.fid,r),r}async function sn(e){let r=(await e.quantFactorSample.text()).match(/<Application[\w\W]+<Eretic_Factor>(?<ereticFactor>[\d.]+)/);return Number(r.groups.ereticFactor)}function lt(e,r){for(let t in r.meta)t in e.meta?(Array.isArray(e.meta[t])||(e.meta[t]=[e.meta[t]]),e.meta[t].push(r.meta[t])):e.meta[t]===void 0&&(e.meta[t]=[r.meta[t]]);return e}async function on(e,r){let t={},i=[],n=["2rr","2ri","2ir","2ii","ser"];function s(o,l){return o.then(a=>{t[l]=a})}for(let o of n)e[o]&&i.push(s(e[o].arrayBuffer(),o));return i.push(s(X(e.procs,r),"procs"),s(X(e.proc2s,r),"proc2s"),s(X(e.acqus,r),"acqus"),s(X(e.acqu2s,r),"acqu2s")),e.nuslist&&i.push(s(e.nuslist.text(),"nuslist")),e.vdlist&&i.push(s(e.vdlist.text(),"vdlist")),e.difflist&&i.push(s(e.difflist.text(),"difflist")),await Promise.all(i),an(t,r)}function an(e,r){let t=lt(e.procs,e.proc2s),i=lt(e.acqus,e.acqu2s);ut(t,i);let{epoch:n,date:s}=mt(t.meta.DATE);if(s.length>0&&(t.info={...t.info,epoch:n,date:s}),e.nuslist&&(t.info.nuslist=e.nuslist.split(/\r?\n/).filter(Boolean).map(Number.parseFloat)),e.vdlist){let g=[];for(let p of e.vdlist.split(`
|
|
2
|
+
`)){if(!p)continue;let[d,h]=p.trim().match(/\s*([\d.]+)\s*([a-zA-Z]+)/)?.slice(1)||[];h&&g.push(`${d}${h}`)}t.meta.vdlist=g}if(e.difflist){let g=[];for(let p of e.difflist.split(`
|
|
3
|
+
`)){if(!p)continue;let[d]=p.trim().match(/\s*([\d.]+)\s*/)?.slice(1)||[];g.push(d)}t.meta.difflist=g}t.meta.SW_p||(t.meta.SW_p=t.meta.SW_h),t.meta.SF||(t.meta.SF=t.meta.SFO1);let o=["2rr","2ri","2ir","2ii"].some(g=>g in e);t.meta.nbSubSpectra=o?Number.parseInt(t.meta.SI[1],10):Number.parseInt(t.meta.TD[1],10);let l,a,m,f;if(o){let g=Number(t.meta.SF[1]),p=Number(t.meta.SW_p[1]||t.meta.SW[1]);f=Number(t.meta.OFFSET[1]),m=Number(t.meta.OFFSET[0]),l=f,a=f-p/g,t.meta.firstY=l,t.meta.lastY=a,dt({rr:e["2rr"],ri:e["2ri"],ir:e["2ir"],ii:e["2ii"]},t,r)}else if(e.ser){l=0,a=t.meta.nbSubSpectra;let g=Number(t.meta.SW[0]),p=Number(t.meta.SW[1]),d=Number(t.meta.SFO1[0]),h=Number(t.meta.SFO1[1]),F=Number(t.meta.O1[0]),N=Number(t.meta.O1[1]);m=F/d+g/2,f=N/h+p/2,ft(e.ser,t,r)}if(r.keepSpectra){let{nbSubSpectra:g}=t.meta,p=(a-l)/(g-1),d=l;for(let h=0;h<g;h++)d+=p,t.spectra[h].pageValue=d}let{NUC1:c,AXNUC:b,SF:u}=t.meta,y=b||c||[];return t.info["2D_Y_NUCLEUS"]=y[1],t.info["2D_X_NUCLEUS"]=y[0],t.info["2D_Y_FRECUENCY"]=u[1],t.info["2D_X_FRECUENCY"]=u[0],t.info["2D_Y_OFFSET"]=f,t.info["2D_X_OFFSET"]=m,t.info.twoD=!0,t.twoD=!0,t}async function gt(e,r={}){let t;if(["ser","2rr","2ri","2ir","2ii"].some(i=>i in e))t=await on(e,r);else if(e["1r"]||e["1i"]||e.fid)t=await rn(e,r);else throw new RangeError("The current files are invalid");t.source={};for(let i in e)(typeof e[i]).match(/number|string|boolean/)&&(t.source[i]=e[i]);r.keepFiles&&(t.source.files=e.fileCollectionItems),t.meta.DATE=Number(t.meta.DATE),t.meta.GRPDLY&&(we(t.meta,"DSPFVS",t.meta.DSPFVS),we(t.meta,"GRPDLY",t.meta.GRPDLY),we(t.meta,"DECIM",t.meta.DECIM));for(let i in t.meta)Array.isArray(t.meta[i])&&(t.meta[i].length===1||typeof t.meta[i][0]=="string"&&t.meta[i][0].includes("(0.."))&&(t.meta[i]=t.meta[i][0]);return t}function we(e,r,t){t!==void 0&&(Array.isArray(t)?e[r]=t.slice():e[r]=[t])}import{formatSpectra as Fn}from"@zakodium/nmrium-core";function oe(e){let r=[];for(let t of e){if(!t)continue;let{groups:{value:i,unit:n}={}}=t.trim().match(/[$$]*\s*(?<value>[\d.]+)\s*(?<unit>[a-zA-Z]+)/)||{};r.push(ln(i,n))}return r}function ln(e,r){switch(r.toLowerCase()){case"s":return Number.parseFloat(e);case"ms":return Number.parseFloat(e)/1e3;case"m":case"min":return Number.parseFloat(e)*60;default:return Number.NaN}}import{isAnyArray as yt}from"is-any-array";function $(e){if(cn(e))return mn(e)?e.map(ht):ht(e);if(typeof e=="object"&&e!==null){let r={};for(let t in e)r[t]=$(e[t]);return r}return e}function cn(e){return yt(e)}function ht(e){return Float64Array.from(e)}function mn(e){return yt(e[0])}import{getOneIfArray as Q}from"@zakodium/nmrium-core";import{getGyromagneticRatio as fn}from"gyromagnetic-ratio";import{isAnyArray as Le}from"is-any-array";import{getFrequency as dn}from"nmr-processing";import{isAnyArray as V}from"is-any-array";function ae(e){return typeof e=="number"}function le(e){let{phc0:r,phc1:t}=e;return!V(r)&&!ae(r)||!V(t)&&!ae(t)||V(r)&&!ae(r[0])||V(t)&&!ae(t[0])?{}:(V(t)?t[0]*=-1:t*=-1,V(r)?r[0]*=-1:r*=-1,{phc0:r,phc1:t})}function Ft(e,r,t){if(e>0)return Number(e);if(r>14||r===0)return 0;if(bt[r]){let i=bt[r];if(!i[t])throw new Error(`decim ${t} not in lookup table for dspfvs ${r}`);return i[t]}else throw new Error(`dspfvs ${r} not in lookup table`)}var bt={10:{2:44.75,3:33.5,4:66.625,6:59.08333333333333,8:68.5625,12:60.375,16:69.53125,24:61.02083333333333,32:70.015625,48:61.34375,64:70.2578125,96:61.50520833333333,128:70.37890625,192:61.5859375,256:70.439453125,384:61.62630208333333,512:70.4697265625,768:61.646484375,1024:70.48486328125,1536:61.65657552083333,2048:70.492431640625},11:{2:46,3:36.5,4:48,6:50.16666666666667,8:53.25,12:69.5,16:72.25,24:70.16666666666667,32:72.75,48:70.5,64:73,96:70.66666666666667,128:72.5,192:71.33333333333333,256:72.25,384:71.66666666666667,512:72.125,768:71.83333333333333,1024:72.0625,1536:71.91666666666667,2048:72.03125},12:{2:46,3:36.5,4:48,6:50.16666666666667,8:53.25,12:69.5,16:71.625,24:70.16666666666667,32:72.125,48:70.5,64:72.375,96:70.66666666666666,128:72.5,192:71.333333333,256:72.25,384:71.66666666666667,512:72.125,768:71.83333333333333,1024:72.0625,1536:71.91666666666667,2048:72.03125},13:{2:2.75,3:2.833333333333333,4:2.875,6:2.916666666666667,8:2.9375,12:2.958333333333333,16:2.96875,24:2.979166666666667,32:2.984375,48:2.989583333333333,64:2.9921875,96:2.994791666666667}};import{normalizeNucleus as un}from"nmr-processing";function j(e,r=","){if(e&&typeof e=="string")return e.split(r)}function ce(e,r,t){let i=[];if(e[`${t}AXNUC`]&&(i=e[`${t}AXNUC`],Array.isArray(i)||(i=[i]),i=k(i)),i.length===0&&e[`${t}NUC1`]&&(i=e[`${t}NUC1`],Array.isArray(i)||(i=[i]),i=k(i)),i.length===0&&e[".NUCLEUS"]){let n=j(e[".NUCLEUS"]);if(e[`${t}SYMBOL`]){let s=e[`${t}SYMBOL`].split(","),o=s.findIndex(a=>a.includes("2")),l=s.findIndex(a=>a.includes("1"));o!==-1&&l!==-1&&n?i=k([n[o],n[l]]):i=k(n).reverse()}else i=k(n)}return i.length===0&&e[".OBSERVENUCLEUS"]&&(i=k([e[".OBSERVENUCLEUS"]])),i.length===0&&r.experiment&&(i=k(St(r.experiment[0]))),pn(e)&&(i=[e["2D_X_NUCLEUS"].replaceAll(/[^A-Za-z0-9]/g,""),e["2D_Y_NUCLEUS"].replaceAll(/[^A-Za-z0-9]/g,"")]),r.experiment&&(r.experiment[0].match("jres")||r.experiment[0].match("dosy"))&&(i=St(r.experiment[0])),i.map(un)}function pn(e){return e["2D_X_NUCLEUS"]&&!e["2D_X_NUCLEUS"].includes("off")&&e["2D_Y_NUCLEUS"]&&!e["2D_Y_NUCLEUS"].includes("off")}function St(e){return typeof e!="string"?[]:(e=e.toLowerCase(),e.includes("jres")?["1H","Hz"]:e.includes("dosy")?["1H","D"]:e.includes("hmbc")||e.includes("hsqc")?["1H","13C"]:e.includes("cosy")||e.includes("tocsy")?["1H","1H"]:[])}function k(e){if(!e)return[];let r=e.map(i=>String(i).replaceAll(/[^A-Za-z0-9]/g,"").replace("NA","").replace("off","")),t=0;for(let i of r)i||t++;return t===0?r:[]}function D(e,r,t,i=!1){t===void 0||r in e&&!i||(Array.isArray(t)?e[r]=t.map(Nt):e[r]=[Nt(t)])}function Nt(e){return typeof e=="string"&&(e.startsWith("<")&&e.endsWith(">")&&(e=e.slice(1,-1)),e=e.replace(/\$.*/,"").trim()),e}function ue(e,r={}){let{prefix:t="",logger:i}=r,n={dimension:0,nucleus:[],isFid:!1,isFt:!1},s=JSON.stringify(e),o=/\r\n/.exec(s)?`\r
|
|
4
|
+
`:`
|
|
5
|
+
`,{JCAMPDX:l="",ORIGIN:a=""}=e,m=String(l).toLowerCase()+String(a).toLowerCase();"SPECTROMETER/DATASYSTEM"in e&&(m=e["SPECTROMETER/DATASYSTEM"]);let f=(d=[])=>{for(let h of d)if(!(h in n))return!1;return!0};(m.includes("mestre")||m.includes("nova"))&&(m="mnova"),n.creator=m,e.LONGDATE&&ve(n,Date.parse(e.LONGDATE)),D(n,"pulseSequence",e[".PULSESEQUENCE"]||e[".PULPROG"]||e[`${t}PULPROG`]);let c=e[`${t}OWNER`];if(c&&D(n,"owner",c.replaceAll(/\$\$.*/gm,"")),D(n,"aqMod",e[`${t}AQ_mod`]),D(n,"experiment",re(n,e,{prefix:t})),n.nucleus=ce(e,n,t),n.nucleus.length===0)if(i)i?.warn("There is not a nucleus detected, assuming 1H"),n.nucleus=["1H"];else throw new Error("There is not a nucleus detected");n.dimension=n.nucleus.length;let b=e[`${t}.ACQUISITIONSCHEME`]||e[`${t}FnMODE`];if(b&&D(n,"acquisitionScheme",hn(Q(b,1))),D(n,"acquisitionMode",e[`${t}.ACQUISITIONMODE`]),C(n,"lpNumberOfCoefficients",e[`${t}NCOEF`]),C(n,"linearPredictionBin",e[`${t}LPBIN`]),C(n,"tdOff",e[`${t}TDoff`]),D(n,"windowMultiplicationMode",e[`${t}WDW`]),D(n,"title",e.TITLE),D(n,"solvent",e[".SOLVENTNAME"]),D(n,"temperature",e[`${t}TE`]||e[".TE"]),D(n,"type",e.DATATYPE),D(n,"dataClass",e[`${t}DATACLASS`]),D(n,"phc1",e[`${t}PHC1`]),D(n,"phc0",e[`${t}PHC0`]),n.type){let d=n.type[0].toUpperCase();d.includes("FID")?(n.isFid=!0,n.isComplex=!0):d.includes("SPECTRUM")&&(n.isFt=!0)}if(D(n,"firstX",e[`${t}FIRSTX`]),D(n,"lastX",e[`${t}LASTX`]),D(n,"numberOfPoints",e[`${t}NPOINTS`]),D(n,"originFrequency",e[`${t}SFO1`]),n.dimension===1&&C(n,"originFrequency",e[".OBSERVEFREQUENCY"]),"originFrequency"in n&&(n.originFrequency=me(n.originFrequency)),!n.originFrequency&&n.dimension===2&&".OBSERVEFREQUENCY"in e){let{nucleus:d}=n,h=me(e[".OBSERVEFREQUENCY"]);if(Le(h)&&h.length>1){let F=e[`${t}SYMBOL`].split(","),N=F.findIndex(S=>S.includes("2")),x=F.findIndex(S=>S.includes("1"));N!==-1&&x!==-1?n.originFrequency=[h[N],h[x]]:n.originFrequency=h.slice()}else if(typeof h=="number"){let F=dn(d[1],{frequency:h,nucleus:d[0]});n.originFrequency=[h,F]}}if((!n.originFrequency||n.originFrequency.some(d=>Number.isNaN(d)||d===0))&&(n.originFrequency||(n.originFrequency=n.dimension>1?[400,400]:[400]),n.originFrequency=n.originFrequency.map(d=>Number.isNaN(d)||d===0?400:d),i?.warn("The frequency could not be determined and was set to 400 MHz")),m.toLocaleLowerCase().includes("oxford instruments")?yn(n,e,{...r,separator:o}):m.includes("nanalysis")&&bn(n,e),m!=="mnova"&&m!=="mestre"){let d=n.nucleus[0],h=fn(d);if(D(n,"probeName",e[`${t}PROBHD`]),D(n,"baseFrequency",e[`${t}BF1`]),D(n,"baseFrequency",e[`${t}SF`]),C(n,"scaleFactor",e[`${t}NC_proc`]),"scaleFactor"in n)for(let S=0;S<n.scaleFactor.length;)n.scaleFactor[S]=2**n.scaleFactor[S++];if(!("baseFrequency"in n)&&"originFrequency"in n?D(n,"baseFrequency",n.originFrequency):n.baseFrequency=me(n.baseFrequency),!["baseFrequency","originFrequency"].some(S=>!n[S])&&h){let{baseFrequency:S}=n,A=2*Math.PI*(S[0]/h)*1e6;D(n,"fieldStrength",A)}C(n,"spectralWidth",e[`${t}SW`]),C(n,"spectralWidth",e[`${t}QM_SPECTRAL_WIDTH`]),n.dimension===1&&e[`${t}SweepWidth`]&&n.originFrequency&&C(n,"spectralWidth",e[`${t}SweepWidth`]/n.originFrequency[0]),D(n,"numberOfPoints",e[`${t}TD`],!0);let F=n.numberOfPoints;if(D(n,"spectrumSize",e[`${t}SI`]??F),D(n,"sampleName",e[`${t}NAME`]),e[`${t}FNTYPE`]!==void 0&&D(n,"acquisitionMode",Number.parseInt(e[`${t}FNTYPE`],10)),(e[`${t}VARNAME`]?e[`${t}VARNAME`].split(",")[0]:"")==="TIME"){let S=typeof e.LAST=="string"?e.LAST.replace(" ","").split(",")[0]:e.LAST;C(n,"acquisitionTime",S)}if(!n.acquisitionTime&&f(["numberOfPoints","spectralWidth"])){let{spectralWidth:S,originFrequency:A}=n;D(n,"acquisitionTime",Number((F[0]-1)/(2*S[0]*A[0])))}if(e[`${t}P`]){let S=1e6/(Q(e[`${t}P`]).split(o)[1].split(" ")[1]*4);D(n,"pulseStrength90",S)}if(e[`${t}D`]){let S=Q(e[`${t}D`]).split(o)[1].split(" ")[1];C(n,"relaxationTime",S)}if(C(n,"numberOfScans",e[`${t}NS`]),C(n,"numberOfScans",e[`${t}QM_NSCANS`]),D(n,"groupDelay",e[`${t}GRPDLY`]),D(n,"dspfvs",e[`${t}DSPFVS`]),D(n,"decim",e[`${t}DECIM`]),n.isFid&&("groupDelay"in n||f(["dspfvs","decim"]))){let{groupDelay:S,dspfvs:A,decim:M}=n,I=Ft(S?.[0]??0,A?.[0],M?.[0]);D(n,"digitalFilter",I)}let x;if(f(["numberOfPoints","spectralWidth"])){let{spectralWidth:S,numberOfPoints:A}=n;n.isFid?x=A.map(M=>n.acquisitionTime[0]/(M-1)):x=A.map((M,I)=>S[I]/(M-1))}if(D(n,"increment",x),e[`${t}DATE`]){let S=Q(e[`${t}DATE`]),A=Number.parseInt(S,10)*1e3;Number.isNaN(A)?ve(n,Date.parse(S)):ve(n,A)}n.solvent||D(n,"solvent",Q(e[`${t}SOLVENT`]))}!("baseFrequency"in n)&&"originFrequency"in n&&D(n,"baseFrequency",n.originFrequency);let u=n.dimension<2,y="dataClass"in n&&n.dataClass[0].toUpperCase()==="NTUPLES",g=["LAST","FIRST","VARDIM","SYMBOL"].every(d=>`${t}${d}`in e);if(u&&(y||g)&&(D(n,"last",j(e[`${t}LAST`])),D(n,"first",j(e[`${t}FIRST`])),D(n,"varDim",j(e[`${t}VARDIM`])),D(n,"symbols",j(e[`${t}SYMBOL`])),n.symbols&&Array.isArray(n.symbols))){n.symbols.includes("R")&&n.symbols.includes("I")&&(n.isComplex=!0);let d=n.symbols.findIndex(h=>h.toLowerCase()==="x");if(C(n,"firstX",n.first[d]),C(n,"lastX",n.last[d]),C(n,"numberOfPoints",n.varDim[d]),!("spectralWidth"in n)){let{lastX:h,numberOfPoints:F,firstX:N}=n;D(n,"spectralWidth",n.isFid?F/(2*h):Math.abs(h-N)/n.originFrequency)}}if(`${t}REVERSE`in e){let d=e[`${t}REVERSE`];n.reverse=(Array.isArray(d)?d:[d]).map(h=>typeof h=="string"?h.includes("yes"):h)}let p=e[`${t}REFERENCE_POINT`];if(!("frequencyOffset"in n)&&p&&f(["spectralWidth","baseFrequency"])){let d=typeof p=="number"?p:e[`${t}REFERENCE_POINT`].match(/(?<reference>[+-]?\d+(?:\.\d+)?)\s*.*/),h;if(typeof p=="number"?h=p:(p.match(/(?<reference>[+-]?\d+(?:\.\d+)?)\s*.*/),h=Number(d?.groups?.reference)),!Number.isNaN(h)){let{spectralWidth:F,baseFrequency:N}=n;D(n,"frequencyOffset",.5*F*N-h)}}if(!("frequencyOffset"in n)&&f(["baseFrequency","originFrequency"])){let{baseFrequency:d,originFrequency:h}=n,F=d.map((N,x)=>(h[x]-N)*1e6);D(n,"frequencyOffset",F)}for(let d in n)n[d]&&n[d].length===1&&(n[d]=n[d][0]);return!n.frequencyOffset&&".SHIFTREFERENCE"in e&&gn(e,n),Array.isArray(n.nucleus)||(n.nucleus=[n.nucleus]),n}function C(e,r,t){t!==void 0&&D(e,r,me(t))}function ve(e,r){if(!Number.isNaN(r)){e.epoch=r;let t=new Date(r);e.date=t.toUTCString(),e.localeDate=t.toLocaleString()}}function gn(e,r){let t=e[".SHIFTREFERENCE"],i=t.trim().startsWith("(")?/\((?<data>[^)]+)\)/:/(?<data>[^)]+)/,n=t.match(i);if(n.groups.data){let s=n.groups.data.split(",");if(s.length<4)return;let o=Number.parseInt(r.numberOfPoints,10),{spectralWidth:l,baseFrequency:a}=r,m=Number.parseInt(s[2],10),f=Number.parseFloat(s[3]),c;if(r.isFid){if(["baseFrequency","numberOfPoints","spectralWidth"].some(b=>!(b in r)))return;c=f+(o*.5-m)*l/o}else{let b=Number.parseFloat(r.firstX),u=Number.parseFloat(r.lastX),y=(u+b)/2,g=(u-b)/(o+1),p=g<0?b:u+(m-1)*g;c=(y-p)/a+f}c!==void 0&&!Number.isNaN(c)&&(r.frequencyOffset=c*a)}}function me(e){if(Le(e)){let r=[];for(let t of e)r.push(typeof t=="string"?Number.parseFloat(t):t);return r}return typeof e=="string"?Number.parseFloat(e):e}function hn(e){switch(String(Le(e)?e[1]:e).toLowerCase().replaceAll(/\s/g,"")){case"1":case"notphasesensitive":return"notPhaseSensitive";case"2":return"QSEQ";case"3":case"tppi":return"TPPI";case"4":case"states":return"States";case"5":case"tppi-states":return"States-TPPI";case"6":case"echo-antiecho":return"Echo-antiecho";default:return"undefined"}}function yn(e,r,t={}){let{prefix:i="",separator:n=`
|
|
6
|
+
`}=t;D(e,"spectralWidth",r[`${i}SweepWidth`]/e.originFrequency[0]);let s=r[`${i}.PULSESEQUENCE`].split(n),o=[];r[".OBSERVENUCLEUS"]&&o.push(r[".OBSERVENUCLEUS"]),r.INDIRECTNUCLEUS&&o.push(r.INDIRECTNUCLEUS),e.nucleus=k(o),e.pulseSequence=s[0];let l=s.slice(2,-1);if(o.length>1)if(o[0]===o[1])e.spectralWidth.push(e.spectralWidth[0]);else{let a=JSON.stringify(l).match(/\$\$SW1=\s*(?<sw>[+-]?(?:[0-9]*[.])?[0-9]+)/);if(a?.groups){let{originFrequency:m}=e,f=Number.parseFloat(a.groups.sw);e.spectralWidth.push(f/m[1])}}return e}function bn(e,r){let{T1NUCLEUS:t,T2NUCLEUS:i,PAGE:n}=r;e.pulseSequence=r.EXPERIMENT||r[".PULSESEQUENCE"];let s=[],{dimension:o,isComplex:l}=e;if(o===2&&e.pulseSequence==="T1"){let f=l?2:1;for(let c=0;c<n.length;c+=f){let b=n[c].replace(/T1=/,"");s.push(Number(b))}r.vdlistValues=s}e.nucleus=o>1?[i,t]:i;let{phc0:a,phc1:m}=e;if(a&&m){let f=le({phc0:a,phc1:m});e={...e,...f}}}var Sn={keepRecordsRegExp:/.*/,keepFiles:!0};async function pe(e,r={}){let t={spectra:[],molecules:[]},{converter:i={},selector:n={},logger:s}=r,o=ct(e,{logger:s,...Dn(n)}),l=[];for(let m of o)l.push(gt(m,{...Sn,...i}).then(f=>Nn(f,r)));let a=await Promise.allSettled(l);for(let m=0;m<a.length;m++){let f=a[m];if(f.status==="fulfilled"){let c=le(f.value.info);t.spectra.push({...f.value,info:{...f.value.info,...c}})}else if(f.reason){let c=o[m].name;s?.warn(`Bruker data: ${c}, fails with: ${f.reason}`);continue}}return s&&s[t.spectra.length>0?"info":"debug"](`Loaded ${t.spectra.length} spectra from Bruker files`),Fn(t)}function Nn(e,r={}){let{keepSource:t=!1,logger:i}=r,n={...e.info,...e.meta},s=ue(n,{logger:i}),o={},{isFid:l}=s;if(Pn(e)){let u=e.minMax;for(let y in u){let g=u[y];g&&(g.z=$(g.z))}o.components=e.minMax}else s.dimension===1&&(o.components=e.spectra);let{source:a}=e,{expno:m,name:f,files:c}=a;n.vdlist&&(n.vdlistValues=oe(n.vdlist));let b={dependentVariables:[o],meta:n,info:{...s,experimentNumber:m,name:f}};return c&&t&&(b.sourceSelector={files:c.map(u=>u.relativePath)}),An(b,e),b}function Dn(e){let{general:r={},bruker:t={}}=e,{processingNumbers:i,experimentNumbers:n,...s}=t;return{...r,...s,processingNumbers:Dt(i),experimentNumbers:Dt(n)}}function Dt(e){if(e)return e.split(/[^\d]+/).filter(Boolean).map(r=>Number.parseInt(r,10))}function Pn(e){let{info:r}=e;return r.twoD}function An(e,r){if(!("integrals"in r))return;let{integrals:t=[]}=r;e.integrals={values:t.map(i=>{let{from:n,to:s,integration:o}=i;return{from:n,to:s,integral:o,kind:"signal"}})}}var fe=class{id="@zakodium/nmrium-core-plugins#BrukerLoaderPlugin";version=1;migrations=[];onReadProcess;constructor(){this.onReadProcess={onFiles:this.onReadProcessFiles}}onReadProcessFiles=(r,t)=>{let{sourceSelector:i,converter:n,keepSource:s,logger:o}=t??{};return pe(r,{converter:n?.bruker,selector:i,keepSource:s,logger:o})}};function ke(){return new fe}import{formatSpectra as ii}from"@zakodium/nmrium-core";import{createTree as si}from"jcampconverter";function Pt(e,r,t={}){let{selector:i={},keepSource:n=!1}=t;if(!n)return e;for(let s=0;s<e.spectra.length;s++){let o=e.spectra[s];o.sourceSelector={files:[r.relativePath],jcamp:{index:s,...i}}}return e}import{convert as xn}from"jcampconverter";function qe(e,r,t){let{dataType:i,children:n}=e,s=i==="LINK"&&n?n:[e];for(let o of s){if(o.dataType==="LINK"){qe(o,r,t);continue}let l=xn(o.jcamp,t);r.push(...l.flatten)}}function Mt(e,r={}){let t=[],i=Rt(e,r);for(let o of i?e:[])o.dataType==="LINK"?o.children=Be(o.children,r):o=Be([o],r)[0],t.push(o);let{name:n,logger:s}=r;return e.length===0&&s?.warn(`There is no data ${n?`in ${n}`:"in the JCAMP-DX"}`),t}function Be(e=[],r={}){let{name:t,logger:i,tree:n=[],dataSelection:s="both"}=r,o=[];for(let f of e){let{dataType:c,dataClass:b}=f;if(c==="LINK")f.children=Be(f.children,r);else if(n.some(u=>{let{dataClass:y=b,dataType:g=c}=u;return b===y&&c===g})){i?.warn(`Skipping ${b} and ${c} ${t?`in ${t}`:"in the JCAMP-DX"},
|
|
7
|
+
because it didn't match the import filters`);continue}o.push(f)}let l=[],a=o.some(xt),m=o.some(At);for(let f of o){if(s!=="both"&&f.dataType!=="LINK"){if(xt(f)&&(s==="ft"||s==="preferFT"&&m)){i?.warn(`Skipping raw data ${t?`in ${t}`:"in the JCAMP-DX"} because it didn't match the import filters`);continue}if(At(f)&&(s==="fid"||s==="preferFID"&&a)){i?.warn(`Skipping FFT data ${t?`in ${t}`:"in the JCAMP-DX"} because it didn't match the import filters`);continue}}l.push(f)}return l}function At(e){return e.dataType?.toUpperCase().includes("SPECTRUM")&&e.dataClass&&!e.dataClass.toUpperCase().includes("PEAK")}function xt(e){return e.dataType?.toUpperCase().includes("FID")}function Rt(e,r={}){let{logger:t,name:i=""}=r;for(let n of e){if(n.dataType==="LINK"&&Rt(n.children,r))return!0;let{dataType:s=""}=n,o=s.toLowerCase();if(o.length>0){if(o.includes("spectrum")&&!o.includes("nmr"))return t?.warn(`File ${i} was ignored because it is a ${s}`),!1;if(o.includes("nmr"))return!0}}return!1}import{generateID as Ct}from"@zakodium/nmrium-core";import{parseJcampCS as On}from"jcampconverter";import*as wn from"openchemlib";import{isMolfileNotEmpty as Mn}from"nmr-processing";import{Molecule as Rn}from"openchemlib";async function It(e,r={}){let t=await e.text(),i=J(t),n={molecules:i,spectra:[]};return i.length===0&&r.logger?.debug(`${e.name} is an empty molfile`),n}function J(e){let r=[];if(!Mn(e))return[];let i=Rn.fromMolfile(e).toMolfile();return r.push({molfile:i}),r}import{isMolfileNotEmpty as En}from"nmr-processing";import*as Cn from"openchemlib";import{getDiastereotopicAtomIDsFromMolfile as Tn}from"openchemlib-utils";var In=new Set(["ndnmrspectrum","ndnmrfid","nmrspectrum","nmrfid"]);function de(e){let{dataType:r="",dataClass:t=""}=e,i=r.replaceAll(/\s/g,"").toLowerCase(),n=t.replaceAll(/\s/g,"").toLowerCase();return In.has(i)&&n!=="peaktable"}function Et(e,r,t={}){let{spectra:i,info:n,meta:s}=e,o=i[0].data,l=[],a={x:"delta",y:"intensity",w:"width",m:"multiplicity",a:"atom"},{logger:m,name:f,spectraData:c}=t,{CROSSREFERENCE:b}=n,u=typeof b!="string"?b:b.split(/\r?\n/).map(S=>S.trim()).filter(Boolean),y=u.find(S=>S?.toLowerCase().includes("structure"));if(y===void 0)return m&&m.warn(`There is not a structure reference for ${f} file, assignment object could not be completed`),null;let g=Number.parseInt(y?.toLowerCase().replace(/_/,"").replace(/structure:\s*blockid\s*=\s*(?<blockId>.*)/,"$<blockId>"),10);if(Number.isNaN(g)||g<1)return m&&m.warn(`Structure block_id not found for ${f} file, assignment object could not be completed`),null;let d=c?.molecules?.find(S=>S.blockId===g)?.molfile??"";if(d===""){let S=r.find(M=>M.info.BLOCKID===g),{MOLFILE:A=""}=S?.meta||{};d=A}if(!En(d))return m&&m.warn(`Empty molfile for ${f} file with structure block_id = ${g}, assignment object could not be completed`),null;let h=Tn(Cn,d),F=ce({...n,...s},{},"");for(let S=0;S<o.x.length;S++){let A={};for(let M in o){let I=o[M][S];typeof I=="string"&&I.startsWith("<")&&I.endsWith(">")&&(I=I.slice(1,-1)),A[a[M]]=I}if("atom"in A){let M=h.map[A.atom-1];F.includes("1H")?M.nbHydrogens>0?(A.diaIDs=M.hydrogenOCLIDs,A.nbHydrogens=M.nbHydrogens):(A.diaIDs=[M.oclID],A.nbHydrogens=M.nbHydrogens):(A.diaIDs=[M.oclID],A.nbHydrogens=1)}l.push(A)}let N={};for(let S of l){let{delta:A,diaIDs:M}=S,I=`${A}_${M.join("_")}`;if(N[I])N[I].atoms.push(S.atom);else{let{atom:Pe,...P}=S;N[I]={...P,atoms:[S.atom]}}}let x=[];for(let S of u)S.toLowerCase().includes("spectrum")&&x.push(Number(S.toLowerCase().replace(/_/,"").replace(/.*:\s*blockid=(?<blockId>.*)/,"$<blockId>")));if(x.length===0){for(let S of r)if(de(S)){let{BLOCKID:A}=S.info;x.push(Number(A))}x.length>1&&(x=[],m&&m.warn(`There is not a spectral cross-reference for the peak assignment in the ${f} file`))}return{moleculeBlockID:g,spectraBlockIDs:x,assignments:Object.values(N),molecule:h.molecule}}function Tt(e,r,t,i){for(let n of e){let{meta:s,dataClass:o="",dataType:l="",info:a}=n,m=Number.parseInt(String(a.BLOCKID),10);s.MOLFILE?qn(String(s.MOLFILE),r,m):n.jcampCS&&kn(n,r,m),vn(o,l)&&Ln(r,n,e,i),de(n)&&t.push(n)}}function vn(e,r){return e?.toLowerCase().includes("assignments")&&r?.toLowerCase().includes("assignments")}function Ln(e,r,t,i){let n=Et(r,t,{spectraData:e,logger:i.logger,name:i.name});if(e.assignmentsByBlocks||(e.assignmentsByBlocks={}),n){let{spectraBlockIDs:s}=n;for(let o of s)e.assignmentsByBlocks[o]=n}}function kn(e,r,t){r.molecules||(r.molecules=[]);let i=On(e,{OCL:wn}),n=J(i?.molfile||"");n.length>0&&r.molecules.push({id:Ct(),blockId:t,...n[0]})}function qn(e,r,t){r.molecules||(r.molecules=[]);let i=J(String(e));r.molecules.push({id:Ct(),blockId:t,...i[0]})}import{generateID as Wt}from"@zakodium/nmrium-core";import{matrixMinMaxZ as zt,reimPhaseCorrection as Yn}from"ml-spectra-processing";import{xyAutoRangesPicking as Gn}from"nmr-processing";function Y(e){return e.slice(0,Math.max(0,e.lastIndexOf(".")))}function G(e){e.sort((r,t)=>r.from-t.from);for(let r=0;r<e.length-1;r++)e[r].to>e[r+1].from&&(e[r].to=Math.max(e[r+1].to,e[r].to),e[r].signals=e[r].signals.concat(e[r+1].signals),e[r].integration+=e[r+1].integration,e.splice(r+1,1),r--);return e}import{splitPatterns as jn}from"nmr-processing";import{xMaxValue as Bn}from"ml-spectra-processing";function ee(e){return e.trim().slice(1,-1).split(/,\s*/).map(r=>r.trim())}var _n={I:"id",X:"from",Y:"to",Hs:"delta",An:"integration",H:"nbAtoms",C:"multiplicity",N:"assignment","(J)":"js"},Ot=["I","X","Y","Hs","An","H","C","N","(J)"];function wt(e){let r={headersFromParenthesis:[],headersFromComments:[],comments:[],data:[],multiplets:[]},t=e.split(/\r?\n/).filter(i=>i.trim()!=="");if(t.length===0)return r;if(t[0].startsWith("(")&&!t[0].match(/\d/)){let i=t.shift();r.headersFromParenthesis=ee(i)}return r.comments=t.filter(i=>i.startsWith("$$")).map(i=>i.replace(/^\$\$\s*/,"")),r.headersFromComments=$n(r.comments),r.data=t.filter(i=>!i.startsWith("$$")).map(ee),r.multiplets=Un(r),r}function Un(e,r={}){let{logger:t}=r,i=e.data[0].map((a,m)=>m).filter(a=>e.data.every(m=>Number.isNaN(m[a])||Number.isNaN(Number(m[a]))));if(t?.trace(`Parsing JCAMP-DX assignment: stringColumnIndexes: ${i.join(",")}`),i.length===0)return t?.warn("Parsing JCAMP-DX assignment: No string columns found. Skipping parsing of assignment."),[];let n=i[0],s;if(e.headersFromParenthesis.length>0&&e.headersFromParenthesis[n]==="C")s=e.headersFromParenthesis;else if(e.headersFromComments.length>0&&e.headersFromComments[n]==="C")s=e.headersFromComments;else if(Ot[n]==="C")s=Ot;else return t?.warn("No header found for multiplicity. Skipping parsing of assignment."),[];return Bn(e.data.map(a=>a.length))>s.length&&t?.warn("Some assignments are containing more values than headers"),e.data.map(a=>{let m={};for(let f=0;f<s.length;f++){let c=s[f];m[_n[c]||c]=a[f]}return m})}function $n(e){return e.map(r=>r.split(":")[0].trim()).filter(r=>r.length>0)}function vt(e,r={}){let{logger:t}=r,i=wt(e),n={multiplets:[],comments:i.comments};for(let s of i.multiplets){let{id:o,from:l,to:a,delta:m,integration:f,nbAtoms:c,multiplicity:b}=s,u={id:o,js:[],multiplicity:"",...zn({from:l,to:a,delta:m,integration:f,nbAtoms:c})};if(typeof s.js=="string"){let y=s.js.split(/\s+/).map(Number.parseFloat),g=0,p=jn(b).map(F=>{let N=(F?.multiplicity||1)-1;return g+=N,{value:F.value,multiplicity:F?.multiplicity,js:y.slice(g-N,g)}}),d=p.reduce((F,N)=>F+(N.multiplicity?N.multiplicity-1:0),0);y.length!==d&&t?.warn(`The number of j values (${y.length}) is not equal to the sum of the multiplicities - 1 (${d})`);let h=[];for(let F of p){if(F.js.every(N=>N===F.js[0])){h.push(F);continue}if(F.multiplicity!==F.js.length+1){h.push(F);continue}for(let N=0;N<F.multiplicity-1;N++)h.push({value:"d",multiplicity:2,js:[F.js[N]]})}h.sort((F,N)=>N.js[0]-F.js[0]),u.js=h.map(F=>({coupling:F.js[0],multiplicity:F.value}))}typeof s.assignment=="string"&&(u.assignment=Xn(s.assignment)),typeof s.multiplicity=="string"&&(u.multiplicity=s.multiplicity),n.multiplets.push(u)}return n}function zn(e){let r={};for(let t in e){let i=e[t],n=typeof i=="number"?i:Number.parseFloat(i);Number.isNaN(n)||(r[t]=n)}return r}var Wn={quot:'"',apos:"'",comma:",",amp:"&",lpar:"(",rpar:")",lt:"<",gt:">",colon:":",semi:";"};function Xn(e){return e.replaceAll(/&(\w+);/gi,(r,t)=>Wn[t.toLowerCase()]||r)}function Lt(e){let r=e.split(/\r?\n/).filter(i=>i.trim()!==""),t=[];for(let i of r)if(i.startsWith("(")){let[n,s,o]=ee(i).map(Number.parseFloat);t.push({id:n,x:s,y:o})}return t}function kt(e,r={}){let t={};if(!e["OBSERVED MULTIPLETS"])return[];let i=vt(e["OBSERVED MULTIPLETS"],r);if(!i)return[];let{multiplets:n}=i;for(let s of n){let{id:o,from:l,to:a,integration:m=0,...f}=s;t[o]={from:l,to:a,integration:m,signals:[{id:o,...f}]}}if(e["OBSERVED MULTIPLETS PEAKS"]){let s=Lt(e["OBSERVED MULTIPLETS PEAKS"]),o={};for(let l of s){let{id:a,x:m,y:f}=l;o[a]||(o[a]=[]),o[a].push({x:m,y:f,width:.05})}for(let l in t)o[l]&&(t[l].signals[0].peaks=o[l])}return G(Object.values(t))}function qt(e,r){let i=[...e.getMolecularFormula().formula.matchAll(/(?<element>[A-Z][a-z]?)(?<count>\d*)/g)].map(s=>({element:s?.groups?.element,count:s?.groups?.count?Number(s.groups.count):1})),n=[...r.nucleus[0].matchAll(/[0-9]*(?<element>[A-Z][a-z]?)/g,"$element")][0].groups.element;return i.find(s=>s.element===n)?.count||100}function Bt(e){let r={};return".PHASE0"in e&&(r.ph0=Number.parseFloat(e[".PHASE0"]),r.ph1=Number.parseFloat(e[".PHASE1"])),r}function _e(e){let{ph0:r,ph1:t}=e;return Number.isFinite(r)&&Number.isFinite(t)}import{generateID as _t}from"@zakodium/nmrium-core";function Ut(e,r,t){for(let i=0;i<e.length;i++){if(r.includes(i))continue;let{delta:n,multiplicity:s="",diaIDs:o}=e[i],l=Number(n)-.01,a=Number(n)+.01;t.push({from:l,to:a,integration:1,id:_t(),signals:[{id:_t(),delta:n,multiplicity:s,diaIDs:o}]})}}import{linearSumAssignment as Vn}from"linear-sum-assignment";import{xCostMatrix as Jn}from"ml-spectra-processing";function $t(e,r){let t=e.map(o=>o.delta),i=r.map(o=>o.delta),n=Jn(i,t,{fct:(o,l)=>Math.abs(o-l)}),{rowAssignments:s}=Vn(n,{maximaze:!1});return Array.from(s)}function jt(e,r){let{assignments:t,ranges:i}=r;t?.sort((o,l)=>l.delta-o.delta);let n=[],s=[];for(let o of i){let l=0,{from:a,to:m}=o,f=[];for(let c=l;c<t.length;c++){let{delta:b}=t[c];b<=m&&b>=a?(f.push(t[c]),s.push(c)):b>m&&(l=c)}if(f.length>0){let c=o.signals,b=[],u=f.length>1&&c.length>1?$t(c,f):[0];for(let y=0;y<f.length;y++){let g=u[y],{delta:p,multiplicity:d,diaIDs:h}=f[y];g>-1?b.push({...c[g],diaIDs:h}):b.push({delta:p,multiplicity:d,diaIDs:h})}o.signals=b,n.push(o)}}Ut(t,s,n),n.sort((o,l)=>o.from-l.from),e.ranges={values:G(n).map(o=>{let{integration:l,...a}=o;return a}),options:{sum:r.integrationSum,isSumConstant:!0,sumAuto:!0}},e.ranges.options.moleculeId=String(r.moleculeId)}function Xt(e,r,t,i,n){let{logger:s}=n,o={components:Vt(e)?Kn(e,t.isFid):Zn(e)},{name:l=t.title||`jcamp_${Wt()}`}=n,a={dependentVariables:[o],meta:r,info:{...t,name:Y(l)}};return Hn(e)&&Qn(a,i,r,e,t,{logger:s}),a}function Vt(e){return"minMax"in e}function Hn(e){return!Vt(e)}function Zn(e){return e.spectra.map(r=>{let t=$(r.data);return{...r,data:t}})}function Kn(e,r){let t={...e.minMax,z:$(e.minMax?.z)};return r?ei(t):{rr:t}}function Qn(e,r,t,i,n,s){let{assignmentsByBlocks:o}=r,l=Bt(t);_e(l)&&ti(e,l);let a=String(i.info.BLOCKID);if(o?.[a]){let{molecule:m,assignments:f,moleculeBlockID:c}=o[a],b=qt(m,n),u=$(i.spectra[0].data);if(u.x[0]>u.x[1])for(let d of i.spectra)d.data.x.reverse(),d.data.y.reverse();if(_e(l)&&i.spectra.length>1){let{re:d}=ri(i,l);u.y=d}let{x:y,y:g}=u,p=kt(t,s)??Gn({x:y,y:g},{peakPicking:{frequency:n.originFrequency},ranges:{frequency:n.originFrequency,integrationSum:b}});jt(e,{moleculeId:c,ranges:p,assignments:f,integrationSum:b})}}function ei(e){let{z:r,...t}=e,i=[],n=[];for(let l=0;l<r.length;l+=2)i.push(r[l].slice()),n.push(r[l+1].slice());let s=zt(i),o=zt(n);return{re:{...t,z:i,minZ:s.min,maxZ:s.max},im:{...t,z:n,minZ:o.min,maxZ:o.max}}}function ti(e,r){let{ph0:t,ph1:i}=r;e.filters||(e.filters=[]),e.filters.push({id:Wt(),name:"phaseCorrection",value:{ph0:t,ph1:i,absolute:!1},enabled:!0})}function ri(e,r){let{ph0:t,ph1:i}=r,{re:n,im:s}=Yn({re:e.spectra[0].data.y,im:e.spectra[1].data.y},t*Math.PI/180,i*Math.PI/180);return{re:n,im:s}}function Jt(e,r,t){let{logger:i}=t,n=[];for(let s of e)if(s.spectra&&s.spectra.length>0||s.minMax){ni(s);let o={...s.info,...s.meta},l=ue(o,{logger:i});if(l.experiment==="wobble_curve")continue;n.push(Xt(s,o,l,r,t))}return n}function ni(e){let r=e.meta["BRUKER FILE EXP"];if(!r)return;let i=(Array.isArray(r)?r:[r]).find(s=>s.slice(0,10).includes("vdlist"));if(!i)return;let n=i.split(`
|
|
8
|
+
`).slice(1);e.info.vdlistValues=oe(n)}async function ge(e,r={}){let t=await e.text(),i=Yt(t,{name:e.name,...r});return Pt(i,e,r)}function Yt(e,r={}){let t={spectra:[],molecules:[]},{name:i,converter:n={},selector:s={},logger:o}=r,{keepRecordsRegExp:l=/.*/}=n,a={keepSpectra:!0,noContour:!0,noTrimRegExp:/\$MOLFILE/,keepRecordsRegExp:l,logger:o},m=Mt(si(e),{name:i,...s,logger:o});for(let f of m)oi(f,t,a,i);if(ai(t,s),t.spectra.length===0&&m.length>0){let f=t.molecules.length===0?" nor molecule":"";o?.warn(`No spectra${f} data was loaded from file ${i}`)}return ii(t)}function oi(e,r,t,i){let n=[],s=[],o={molecules:[]},{logger:l}=t,a={name:i,logger:l};qe(e,s,t),Tt(s,o,n,a),r.spectra.push(...Jt(n,o,a)),r.molecules.push(...o.molecules)}function ai(e,r){r.index!==void 0&&(e.spectra=e.spectra.slice(r.index,r.index+1))}var he=class{id="@zakodium/nmrium-core-plugins#JCAMPDXLoaderPlugin";version=1;migrations=[];onReadProcess;constructor(){this.onReadProcess={supportedExtensions:["jcamp","jdx","dx"],onFile:this.onReadProcessFile.bind(this)}}onReadProcessFile(r,t={}){let{sourceSelector:i={},converter:n,keepSource:s,logger:o}=t;return o?.debug(`Reading JCAMP-DX file: ${r.name}`),ge(r,{selector:this.getJCAMPDXSelector(i),converter:n?.jcamp,keepSource:s,logger:o})}getJCAMPDXSelector(r={}){let{jcamp:t={},general:i={}}=r,{dataSelection:n="both"}=i;return{...t,dataSelection:n}}};function Ue(){return new he}var li={0:"bigEndian",1:"littleEndian"},ci={0:"NONE",1:"GSX",2:"ALPHA",3:"ECLIPSE",4:"MASS_SPEC",5:"COMPILER",6:"OTHER_NMR",7:"UNKNOWN",8:"GEMINI",9:"UNITY",10:"ASPECT",11:"UX",12:"FELIX",13:"LAMBDA",14:"GE_1280",15:"GE_OMEGA",16:"CHEMAGNETICS",17:"CDFF",18:"GALACTIC",19:"TRIAD",20:"GENERIC_NMR",21:"GAMMA",22:"JCAMP_DX",23:"AMX",24:"DMX",25:"ECA",26:"ALICE",27:"NMR_PIPE",28:"SIMPSON"},mi={0:"64Bit Float",1:"32Bit Float",2:"Reserved",3:"Reserved"},ui={1:"One_D",2:"Two_D",3:"Three_D",4:"Four_D",5:"Five_D",6:"Six_D",7:"Seven_D",8:"Eight_D",9:"not for NMR data formats",10:"not for NMR data formats",11:"not for NMR data formats",12:"Small_Two_D",13:"Small_Three_D",14:"Small_Four_D"},pi={0:"None",1:"Real",2:"TPPI",3:"Complex",4:"Real_Complex",5:"Envelope"},fi={"-8":"Yotta","-6":"Exa","-7":"Zetta","-5":"Pecta","-4":"Tera","-3":"Giga","-2":"Mega","-1":"Kilo",0:"None",1:"Milli",2:"Micro",3:"Nano",4:"Pico",5:"Femto",6:"Atto",7:"Zepto"},di={Yotta:24,Exa:21,Zetta:18,Pecta:15,Tera:12,Giga:9,Mega:6,Kilo:3,None:0,Milli:-3,Micro:-6,Nano:-9,Pico:-12,Femto:-15,Atto:-18,Zepto:-21},gi={0:"None",1:"Abundance",2:"Ampere",3:"Candela",4:"Celsius",5:"Coulomb",6:"Degree",7:"Electronvolt",8:"Farad",9:"Sievert",10:"Gram",11:"Gray",12:"Henry",13:"Hertz",14:"Kelvin",15:"Joule",16:"Liter",17:"Lumen",18:"Lux",19:"Meter",20:"Mole",21:"Newton",22:"Ohm",23:"Pascal",24:"Percent",25:"Point",26:"Ppm",27:"Radian",28:"Second",29:"Siemens",30:"Steradian",31:"Tesla",32:"Volt",33:"Watt",34:"Weber",35:"Decibel",36:"Dalton",37:"Thompson",38:"Ugeneric",39:"LPercent ",40:"PPT",41:"PPB ",42:"Index"},Gt={0:"Ranged",1:"Listed",2:"Sparse",3:"Listed"},hi={0:"String",1:"Integer",2:"Float",3:"Complex",4:"Infinity"};function yi(e){if(e===void 0)return{epoch:null,date:""};let r=e*1e3;return{epoch:r,date:new Date(r).toUTCString()}}function L(e,r){return e.paramArray.find(t=>t.name===r)||""}function bi(e,r){let t=e.paramArray.find(u=>u.name==="orders"),i=e.paramArray.find(u=>u.name==="factors"),n=e.paramArray.find(u=>u.name==="x_sweep"),s=e.paramArray.find(u=>u.name==="x_acq_time"),o=e.paramArray.find(u=>u.name==="x_points");if([t,i,n,s,o].includes(void 0)){r?.error("There is not all parameters to calculate the number of point of digital filter");return}let l=Number.parseInt(t.value.slice(0,1),10),a=t.value.slice(1).length/l,m=0,f=new Int8Array(l),c=1,b=0;for(let u=0;u<l;u++)f[u]=Number.parseInt(i.value.slice(b,b+1),10),b+=1;for(let u=0;u<l;u++){let y=1;for(let g=u;g<l;g++)y*=f[g];m+=(Number.parseInt(t.value.slice(c,c+a),10)-1)/y,c+=a}return m/=2,m/n.value/s.value*(o.value-1)}function T(e,r){let t=L(e,r)||"NA";if(t==="NA")return{magnitude:"NA",unit:"NA"};let i=t.unit[0].base,n=di[t.unit[0].prefix];return{magnitude:t.value*10**n,unit:i}}function Ht(e,r){let t=[];for(let i=0;i<r;i++){let n=e.readByte(),s=fi[n>>4],o=n&15,l=gi[e.readInt8()];t.push({prefix:s,power:o,base:l})}return t}function H(e,r){let t=[];for(let i=0;i<r;i++){let n=e.readChar();n!=="\0"&&t.push(n)}return t.join("")}function Zt(e,r){let t=[];for(let i=0;i<r;i++){let n=e.readChar();n!==" "&&t.push(n)}return t.join("")}function R(e,r,t){let i=[];for(let n=0;n<r;n++)switch(t){case"readUint32":i.push(e.readUint32());break;case"readFloat64":i.push(e.readFloat64());break;case"readFloat32":i.push(e.readFloat32());break;case"readUint8":i.push(e.readUint8());break;case"readBoolean":i.push(e.readBoolean());break;default:break}return i}function Kt(e,r){let t=new v(e);t.setBigEndian();let i,n={},s=[];n.fileIdentifier=t.readChars(8),n.endian=li[t.readInt8()],n.majorVersion=t.readUint8(),n.minorVersion=t.readUint16(),n.dataDimensionNumber=t.readUint8(),n.dataDimensionExist=t.readByte().toString(2).split("").map(P=>!!Number(P)),i=t.readByte(),n.dataType=mi[i>>6],n.dataFormat=ui[i&63],n.dataInstrument=ci[t.readInt8()],n.translate=R(t,8,"readUint8"),n.dataAxisType=R(t,8,"readUint8").map(P=>pi[P]),n.dataUnits=Ht(t,8),n.title=H(t,124);for(i in R(t,4,"readUint8"))s.push(Gt[i>>4],Gt[i&15]);n.dataAxisRanged=s,n.dataPoints=R(t,8,"readUint32"),n.dataOffsetStart=R(t,8,"readUint32"),n.dataOffsetStop=R(t,8,"readUint32"),n.dataAxisStart=R(t,8,"readFloat64"),n.dataAxisStop=R(t,8,"readFloat64"),s=new Uint8Array(4);for(let P=0;P<4;P++)s[P]=t.readByte();let o=1990+(s[0]>>1),l=(s[0]<<3&8)+(s[1]>>5),a=s[2]&31;n.creationTime={year:o,month:l,day:a};for(let P=0;P<4;P++)s[P]=t.readByte();o=1990+(s[0]>>1),l=(s[0]<<3&8)+(s[1]>>5),a=s[2]&31,n.revisionTime={year:o,month:l,day:a},n.nodeName=H(t,16),n.site=H(t,128),n.author=H(t,128),n.comment=H(t,128);let m=[];for(let P=0;P<8;P++)m.push(H(t,32));n.dataAxisTitles=m,n.baseFreq=R(t,8,"readFloat64"),n.zeroPoint=R(t,8,"readFloat64"),n.reversed=R(t,8,"readBoolean"),t.skip(3),n.annotationOK=!!(t.readByte()>>7),n.historyUsed=t.readUint32(),n.historyLength=t.readUint32(),n.paramStart=t.readUint32(),n.paramLength=t.readUint32(),n.ListStart=R(t,8,"readUint32"),n.ListLength=R(t,8,"readUint32"),n.dataStart=t.readUint32(),n.dataLength=t.readUint32()<<32|t.readUint32(),n.contextStart=t.readUint32()<<32|t.readUint32(),n.contextLength=t.readUint32(),n.annoteStart=t.readUint32()<<32|t.readUint32(),n.annoteLength=t.readUint32(),n.totalSize=t.readUint32()<<32|t.readUint32(),n.unitLocation=R(t,8,"readUint8");let f=[];for(let P=0;P<2;P++){let O=[],K=t.readInt16();for(let U=0;U<5;U++)i=t.readInt16(),O.push(i);f.push({scaler:K,unit:O})}n.compoundUnit=f,n.endian==="littleEndian"&&t.setLittleEndian(),t.seek(n.paramStart);let c={parameterSize:t.readUint32(),lowIndex:t.readUint32(),highIndex:t.readUint32(),totalSize:t.readUint32()},b=[];for(let P=0;P<c.highIndex+1;P++){t.skip(4);let O=t.readInt16(),K=Ht(t,5);t.skip(16);let U=hi[t.readInt32()];t.seek(t.offset-20);let E;switch(U){case"String":E=Zt(t,16);break;case"Integer":E=t.readInt32(),t.skip(12);break;case"Float":E=t.readFloat64(),t.skip(8);break;case"Complex":E.Real=t.readFloat64(),E.Imag=t.readFloat64();break;case"Infinity":E=t.readInt32(),t.skip(12);break;default:t.skip(16);break}t.skip(4);let w=Zt(t,28);b.push({name:w.toLowerCase(),scaler:O,unit:K,value:E,valueType:U})}c.paramArray=b,t.seek(n.dataStart),n.endian==="littleEndian"&&t.setLittleEndian();let u={},y=1,g=0;for(let P of n.dataAxisType)P==="Real_Complex"&&g===0&&(y+=1,g+=1),P==="Complex"&&(y*=2);if(n.dataFormat!=="One_D"&&n.dataFormat!=="Two_D"){r?.error("Only One_D and two_D data formats are implemented yet");return}if(n.dataFormat==="One_D")for(let P=0;P<y;P++){let O;n.dataType==="32Bit Float"?O=R(t,n.dataPoints[0],"readFloat32"):n.dataType==="64Bit Float"&&(O=R(t,n.dataPoints[0],"readFloat64")),P===0&&(u.re=O),P===1&&(u.im=O)}if(n.dataFormat==="Two_D"){let P=32,O=n.dataPoints[0],K=n.dataPoints[1]/P,U=O/P;for(let E=0;E<y;E++){let w;for(let Ae=0;Ae<K;Ae++){let q=[];for(let xe=0;xe<U;xe++)for(let B=0;B<P;B++)xe===0?n.dataType==="32Bit Float"?q[B]=R(t,P,"readFloat32"):n.dataType==="64Bit Float"&&(q[B]=R(t,P,"readFloat64")):n.dataType==="32Bit Float"?q[B]=q[B].concat(R(t,P,"readFloat32")):n.dataType==="64Bit Float"&&(q[B]=q[B].concat(R(t,P,"readFloat64")));Ae===0?w=q:w=w.concat(q)}y===2&&(E===0&&(u.re=w),E===1&&(u.im=w)),y===4&&(E===0&&(u.re={},u.re.re=w),E===1&&(u.re.im=w),E===2&&(u.im={},u.im.re=w),E===3&&(u.im.im=w))}}let p=[],d=[],h=[],F=[],N=[],x=[],S=[],A=[],M=[],I=[];if(n.dataFormat==="One_D"||n.dataFormat==="Two_D"){let P=yi(L(c,"actual_start_time").value);P.date&&(d.push(P.date),h.push(P.epoch)),p.push(L(c,"x_domain").value),F.push(T(c,"x_acq_time")),N.push(T(c,"x_sweep")),x.push(T(c,"x_sweep_clipped")),S.push(T(c,"x_resolution")),A.push(T(c,"x_freq")),M.push(T(c,"x_offset")),I.push(n.dataUnits[0].base)}n.dataFormat==="Two_D"&&(p.push(L(c,"y_domain").value),F.push(T(c,"y_acq_time")),N.push(T(c,"y_sweep")),S.push(T(c,"y_resolution")),A.push(T(c,"y_freq")),M.push(T(c,"y_offset")),I.push(n.dataUnits[1].base));let Pe={info:{sampleName:L(c,"sample_id").value,creationTime:n.creationTime,revisionTime:n.revisionTime,author:n.author,comment:n.comment,solvent:L(c,"solvent").value,temperature:T(c,"temp_get"),probeName:L(c,"probe_id").value,fieldStrength:T(c,"field_strength"),experiment:L(c,"experiment").value,dimension:n.dataDimensionNumber,nucleus:p,date:d,epoch:h,pulseStrength90:T(c,"x90"),numberOfScans:L(c,"scans").value,relaxationTime:T(c,"relaxation_delay"),dataPoints:n.dataPoints.slice(0,n.dataDimensionNumber),dataOffsetStart:n.dataOffsetStart,dataOffsetStop:n.dataOffsetStop,dataUnits:I,dataSections:Object.keys(u),originFrequency:A,frequencyOffset:M,acquisitionTime:F,spectralWidth:N,spectralWidthClipped:x,dataAxisStart:n.dataAxisStart,dataAxisStop:n.dataAxisStop,resolution:S,decimationRate:L(c,"decimation_rate").value,paramList:JSON.stringify(c.paramArray.map(P=>P.name))},headers:n,parameters:c,data:u};return Pe.info.digitalFilter=bi(c,r),Pe}import{formatSpectra as Di,getOneIfArray as Pi}from"@zakodium/nmrium-core";import{getGyromagneticRatio as Ai}from"gyromagnetic-ratio";import{isAnyArray as xi}from"is-any-array";import Mi from"lodash.merge";import{normalizeNucleus as Ri}from"nmr-processing";import{isAnyArray as Z}from"is-any-array";var Qt={0:"uint8",1:"uint16",2:"uint32",3:"uint64",4:"int8",5:"int16",6:"int32",7:"int64",8:"float32",9:"float64",10:"complex64",11:"complex128"},er={0:"scalar",1:"vector",2:"matrix",3:"symetricMatrix",4:"pixel"};function tr(e,r,t={}){let{quantityType:i=0,encoding:n="none",name:s="",unit:o="",quantityName:l="",sparseSampling:a={},from:m=[0],to:f=[-1]}=t;if(Z(e))throw new Error("JEOL with an array of data is not yet supported");if(!("re"in e&&"im"in e))throw new Error("Only re/im data is supported");let c=je(e,m,f),{componentLabels:b=c.componentLabels}=t;return{type:"internal",quantityType:er[i],numericType:Qt[r],encoding:n,name:s,unit:o,quantityName:l,componentLabels:b,sparseSampling:a,description:t.description||"",application:t.application||"",components:c.components,dataLength:c.dataLength}}function Fi(e){return Z(e.re)&&Z(e.im)}function Si(e){return!Z(e.re[0])}function je(e,r,t){let i=[],n=[],s=[];if(Fi(e))if(Si(e)){i[0]=$e(r[0],t[0],e.re.length);let o=new Float64Array(i[0]);for(let l=0;l<i[0];l+=2){let a=l+r[0]*2;o[l]=e.re[a/2],o[l+1]=e.im[a/2]}s.push(o),n.push("complex")}else if(Z(e.re[0])){i[0]=Ni(r[1],t[1],e.re.length),i[1]=$e(r[0],t[0],e.re[0].length);for(let o=0;o<i[0];o++){let l=new Float64Array(i[1]);for(let a=0;a<i[1];a+=2){let m=a+r[0]*2;l[a]=e.re[o][m/2],l[a+1]=e.im[o][m/2]}s.push(l)}}else throw new Error("check your object");else if(Z(e.re.re)){i[0]=$e(r[1],t[1],e.re.re.length);let o=je(e.re,r,t).components,l=je(e.im,r,t).components;for(let a=0;a<i[0]/2;a++)s.push(o[a],l[a])}else throw new Error("check the dimension or the type of data in your array");return{dataLength:i,componentLabels:n,components:s}}function Ni(e,r,t){return r-e+1<t?r-e+1:t}function $e(e,r,t){return r-e+1<t?(r-e+1)*2:t*2}async function nr(e,r={}){let t=await e.arrayBuffer(),{name:i=Y(e.name),keepSource:n=!1}=r,s={spectra:[],molecules:[]},l=Ci(t)[0],{metadata:a,...m}=l.description,f=0,c=m.dimension===1?"1d":"2d",b="NMR SPECTRUM",u=m.dimension===1?m.nucleus[0]:m.nucleus,y=m.spectralWidthClipped[0],g;l.dependentVariables&&(m.dimension===1?g=Ii(l):m.dimension===2&&(g=Ei(l)));for(let d in m)Array.isArray(m[d])&&m[d].length===1&&(m[d]=m[d][0]);let p={data:g,info:{...m,acquisitionMode:f,experiment:c,type:b,nucleus:u,spectralWidthClipped:y,name:i},meta:a};return n&&(p.sourceSelector={files:[e.relativePath]}),s.spectra=[p],Di(s)}function Ii(e){let r=e.dimensions[0],t=e.dependentVariables,i=r.quantityName,n=r.count,s=r.increment.magnitude,o=r.originOffset.magnitude,l=r.coordinatesOffset.magnitude,a=t[0].components[0],m=new Float64Array(n),f=new Float64Array(n);for(let g=a.length-1,p=0;g>0;g-=2)m[p]=a[g-1],f[p++]=a[g];let c={},[b,u]=[0,0];switch(i){case"frequency":u=0+l/o*1e6,b=s/o*1e6,c.re=m,c.im=f;break;case"time":u=o,b=s,c.re=m.reverse(),c.im=f.reverse().map(g=>-g);break;default:break}let y=[];for(let g=0;g<n;g++)y.push(u+g*b);return c.x=y,c}function Ei(e){let r=e.dimensions,t=e.dependentVariables,i=r[0].quantityName,n=[],s=[],o=Number.MIN_SAFE_INTEGER,l=Number.MAX_SAFE_INTEGER,a=Number.MAX_SAFE_INTEGER,m=Number.MIN_SAFE_INTEGER;for(let b of t[0].components){let u=new Float64Array(b.length/2),y=new Float64Array(b.length/2);for(let g=b.length-1,p=0;g>0;g-=2){let d=b[g-1],h=b[g];d>o&&(o=d),d<l&&(l=d),h>m&&(m=h),h<a&&(a=h),u[p]=d,y[p++]=h}if(i==="frequency")n.push(u),s.push(y);else{let g=u.length,p=new Float64Array(y.length);for(let d=0,h=g-1;d<g;d++)p[d]=-y[h--];n.push(u.reverse()),s.push(p)}}let f={re:{z:n,minZ:l,maxZ:o},im:{z:s,minZ:a,maxZ:m}},c=["X","Y"];for(let b=0;b<c.length;b++){let u=r[b].count,y=r[b].increment.magnitude,g=r[b].originOffset.magnitude,p=r[b].coordinatesOffset.magnitude,d=c[b];for(let h of["re","im"])i==="frequency"?(f[h][`min${d}`]=0+p/g*1e6,f[h][`max${d}`]=u*(y/g)*1e6):(f[h][`min${d}`]=g,f[h][`max${d}`]=u*y)}return f}function Ci(e){let r=Kt(e),t=r.info,i=r.headers,n=r.parameters,{dimension:s}=t,o={};for(let p of n.paramArray){let{name:d,value:h}=p;o[d]=ir(h,s)}delete n.paramArray;let l=r.data,a={};a.title=`title: ${i.title} / comment: ${i.comment} / author:${i.author} / site: ${i.site}`,a.nucleus=t.nucleus.map(Ri),a.sampleName=t.sampleName,a.date=t.date,a.epoch=t.epoch,a.localeDate=new Date(Pi(t.epoch)).toLocaleString(),a.author=t.author,a.solvent=t.solvent,a.temperature=t.temperature.magnitude,a.probeName=t.probeName||"",a.fieldStrength=t.fieldStrength.magnitude;let m=a.nucleus.map(Ai);a.baseFrequency=m.map(p=>t.fieldStrength.magnitude*p/(2*Math.PI*1e6)),a.pulseSequence=t.experiment,a.temperature=t.temperature?.unit?.toLowerCase()==="celsius"?273.15+t.temperature.magnitude:t.temperature.magnitude,a.digitalFilter=t.digitalFilter,a.pulseStrength90=1/(4*t.pulseStrength90.magnitude),a.numberOfScans=t.numberOfScans,a.relaxationTime=t.relaxationTime.magnitude,a.isComplex=t.dataSections.includes("im"),a.isFid=t.dataUnits[0]==="Second",a.isFt=t.dataUnits[0]==="Ppm",a.dimension=t.dimension,a.originFrequency=t.originFrequency.map(p=>p.magnitude/1e6).slice(0,s),a.numberOfPoints=t.dataPoints.slice(0,1),a.frequencyOffset=t.frequencyOffset.map((p,d)=>p.magnitude*a.baseFrequency[d]).slice(0,s),a.acquisitionTime=t.acquisitionTime.map(p=>p.magnitude).slice(0,s),a.spectralWidth=t.spectralWidth.map((p,d)=>p.magnitude/t.originFrequency[d].magnitude*1e6).slice(0,s),a.spectralWidthClipped=t.spectralWidthClipped.map((p,d)=>p.magnitude/a.baseFrequency[d]*1e6).slice(0,s);let f=[],c={},b;for(let p=0;p<t.dimension;p++){if(b={magnitude:t.acquisitionTime[p].magnitude/(t.dataPoints[p]-1),unit:"s"},t.dataUnits[p]==="Second")c.quantityName="time",c.originOffset={magnitude:0,unit:"s"},p===0?c.coordinatesOffset={magnitude:t.digitalFilter*b.magnitude,unit:"s"}:c.coordinatesOffset={magnitude:0,unit:"s"},c.reciprocal={originOffset:{magnitude:t.originFrequency[p].magnitude,unit:"Hz"},quantityName:"frequency",coordinatesOffset:{magnitude:t.frequencyOffset[p].magnitude*t.originFrequency[p].magnitude/1e6,unit:"Hz"}};else if(t.dataUnits[p]==="Ppm"){c.quantityName="frequency";let d=t.originFrequency[p].magnitude;c.originOffset={magnitude:d,unit:"Hz"};let h=t.dataOffsetStart[p],N=t.dataOffsetStop[p]-h+1;b={magnitude:Ti(t,p)/(N-1),unit:"Hz"};let A=t.dataAxisStop[p]*d/1e6;c.coordinatesOffset={magnitude:A,unit:"Hz"},N!==t.dataPoints[p]&&(t.dataPoints[p]=N)}p===0?c.description="direct dimension":c.description="indirect dimension",f.push({label:String(i.dataAxisTitles[p]),count:Number(t.dataPoints[p]),increment:b,type:"linear",description:String(c.description)||"",application:c.application||{},coordinatesOffset:c.coordinatesOffset||0,originOffset:c.originOffset||0,quantityName:String(c.quantityName)||"",reciprocal:c.reciprocal||{},period:c.period||0,complexFFT:c.complexFFT||!1})}let u=[];u.push(tr(l,11,{unit:"none",quantityName:"relative intensity",from:t.dataOffsetStart,to:t.dataOffsetStop}));let y={...a};return delete y.paramList,y.metadata={...rr(i,s),...rr(n,s),...Mi({},o)},[{timeStamp:Date.now(),description:y,dimensions:f,dependentVariables:u}]}function Ti(e,r){let{spectralWidth:t,spectralWidthClipped:i}=e;return i[r].magnitude!=="NA"?i[r].magnitude:t[r].magnitude}function rr(e,r){let t={};for(let i in e)t[i]=ir(e[i],r);return t}function ir(e,r){return xi(e)?r>1?e.slice(0,r):e[0]:e}var ye=class{id="@zakodium/nmrium-core-plugins#JEOLLoaderPlugin";version=1;migrations=[];onReadProcess;constructor(){this.onReadProcess={supportedExtensions:["jdf"],onFile:this.onReadProcessFile.bind(this)}}onReadProcessFile(r,t={}){let{logger:i,keepSource:n}=t;return i?.debug(`Reading JEOL file: ${r.name}`),nr(r,{name:r.name,keepSource:n,logger:i})}};function ze(){return new ye}var be=class{id="@zakodium/nmrium-core-plugins#MolfileLoaderPlugin";version=1;migrations=[];onReadProcess;constructor(){this.onReadProcess={supportedExtensions:["mol"],onFile:this.onReadProcessFile.bind(this)}}onReadProcessFile(r,t={}){let{logger:i}=t;return i?.debug(`Reading molfile file: ${r.name}`),It(r,{logger:i})}};function We(){return new be}import{getSDF as qi,nmrRecordToJSON as Bi}from"nmredata";import{generateID as ar}from"@zakodium/nmrium-core";import{generateID as sr}from"@zakodium/nmrium-core";import{xyIntegration as Oi}from"ml-spectra-processing";function or(e,r){let{x:t,re:i}=r.data;return e.map(n=>{let s=Oi({x:t,y:i},{from:n.from,to:n.to}),o=[];for(let l of n.signals||[]){let{kind:a=null,id:m,js:f=[],diaIDs:c=[],...b}=l;o.push({...b,kind:a||"signal",js:f,id:m||sr(),diaIDs:c})}return{...n,id:n.id||sr(),kind:o?.[0].kind||"signal",absolute:s,signals:o}})}function lr(e,r){let t=[],{baseFrequency:i=500}=r.info;for(let n of e){let{delta:s,diaIDs:o=[],multiplicity:l="",integration:a=0}=n,m=n.jCoupling||[],f=wi({delta:s,js:m,frequency:i});if(m&&l&&m.length===l.length){m.sort((c,b)=>b.coupling-c.coupling);for(let c=0;c<m.length;c++)m[c].multiplicity=l[c]}t.push({id:ar(),...f,integration:a,signals:[{id:ar(),js:m,delta:s,diaIDs:o,multiplicity:l}]})}r.ranges.values=or(G(t),r)}function wi(e){let{delta:r,js:t=[],frequency:i}=e,n=.5;for(let s of t)n+=s.coupling;return n/=i,{from:r-n,to:r+n}}import{generateID as cr}from"@zakodium/nmrium-core";var vi=["x","y"],Li={x:0,y:0};function mr(e,r,t={}){let i=[],{shift:n=Li}=t,{originFrequency:s=[400,400]}=r.info,o={x:s[0],y:s[1]};for(let l of e){let a={x:{},y:{},id:cr(),kind:"signal"},m={id:cr(),kind:"signal",peaks:[]},f={x:10,y:10};for(let c of vi){let{coupling:b=[],delta:u,diaIDs:y=[]}=l[c];for(let g of b)f[c]+=g.coupling;if(l.activeCoupling){let{activeCoupling:g=[]}=l;for(let p of g)f[c]+=p.coupling}f[c]/=o[c],a[c]={from:u-f[c],to:u+f[c]},m[c]={delta:u,diaIDs:y,originalDelta:u-n[c]}}i.push({...a,signals:[m]})}r.zones.values=i}function ur(e){return ki(e.data)}function ki(e){return"rr"in e||!("x"in e)&&"re"in e}async function pr(e,r,t={}){let i={spectra:[],molecules:[]},n=await _i(e,r,t);if(n.spectra.length>0){let{spectra:s,molecules:o,usedFiles:l}=n;i.spectra.push(...s),i.molecules.push(...o);let a=e.files.length;for(let m=a-1;m>=0;m--){let f=e.files[m].relativePath;!f.match(/acqu.*/s)&&l.includes(f)&&e.files.splice(m,1)}}return i}async function _i(e,r,t){let i=[],n=await qi(e),s={spectra:[],molecules:[]};if(n.length===0)return{...s,usedFiles:i};let o=[];for(let a of n){let m=Bi({sdf:a,fileCollection:e}).then(f=>{let{spectra:c,molecules:b=[]}=f;return i.push(a.root+a.filename),s.molecules.push(...b),Ui(c,r,t)});o.push(m)}let l=await Promise.allSettled(o);for(let a of l)a.status==="fulfilled"?(s.spectra.push(...a.value.spectra),i.push(...a.value.usedFiles)):a.reason&&t?.logger?.error(a.reason);return{...s,usedFiles:i}}async function Ui(e,r,t){let i=[],n=[],s={spectra:[],molecules:[]};for(let o of e){let l=$i(o.source,r,t).then(a=>{let{spectra:m,files:f}=a;i.push(...f);for(let c of m)ur(c)?mr(o.signals,c):lr(o.signals,c);s.spectra.push(...m)});n.push(l)}return await Promise.allSettled(n),{...s,usedFiles:i}}async function $i(e,r,t={}){let{file:i,jcampURL:n}=e,{converter:s}=t;if(n){let a=await ji(n,r,s?.jcamp);if(a)return{...a,files:[]}}let o=[];for(let a of i||[])o.push(zi(a,t).then(m=>({...m,files:a.fileCollection.files.map(f=>f.relativePath)})));let l=await Promise.allSettled(o);for(let a of l){if(a.status==="fulfilled")return a.value;a.reason&&t?.logger?.error(a.reason)}return{spectra:[],molecules:[],files:[]}}async function ji(e,r,t={}){let i={entries:[{relativePath:e}]},n={name:Y(e||""),xy:!0,noContours:!0,...t},{data:s}=await r.readFromWebSource(i,n);return s}async function zi(e,r={}){let{converter:t,sourceSelector:i}=r;switch(e.type){case"jcamp":return ge(e.fileCollection.files[0],{name:e?.fileCollection.files[0].name||"",converter:t?.jcamp,selector:i?.jcamp,logger:r.logger,keepSource:r.keepSource});case"brukerFiles":return pe(e.fileCollection,{converter:t?.bruker,selector:i});default:throw new Error("There is not a supported source")}}var Fe=class{constructor(r){this.core=r;this.onReadProcess={onFiles:this.onReadProcessFiles}}id="@zakodium/nmrium-core-plugins#NMReDATALoaderPlugin";version=1;migrations=[];onReadProcess;onReadProcessFiles=(r,t)=>pr(r,this.core,t)};function Xe(e){return new Fe(e)}import{parse as Wi}from"sdf-parser";function fr(e,r={}){let{mixedEOL:t}=r,{molecules:i}=Wi(e,{mixedEOL:t}),n=[];for(let{molfile:s}of i){let o=J(s);n.push(...o)}return n}async function dr(e,r={}){let{logger:t,mixedEOL:i}=r,n=await e.text(),s=fr(n,{mixedEOL:i}),o={molecules:s,spectra:[]};return t&&t[s.length>0?"info":"debug"](`Loaded ${o.molecules.length} molecules from the ${e.name} file`),o}var Se=class{id="@zakodium/nmrium-core-plugins#SDFLoaderPlugin";version=1;migrations=[];onReadProcess;constructor(){this.onReadProcess={supportedExtensions:["sdf"],onFile:this.onReadProcessFile.bind(this)}}onReadProcessFile(r,t={}){let{logger:i}=t;return i?.debug(`Reading sdf file: ${r.name}`),dr(r,{logger:i})}};function Ve(){return new Se}import{Molecule as Xi}from"openchemlib";function gr(e){let r=[],t=e.split(/\r?\n/).filter(Boolean);for(let i of t){let s=Xi.fromSmiles(i).toMolfile();r.push({molfile:s})}return r}async function hr(e,r={}){let t=await e.text(),i=gr(t),n={molecules:i,spectra:[]};return r.logger?.info(`Found ${i.length} molecules from the ${e.name} file`),n}var Ne=class{id="@zakodium/nmrium-core-plugins#SMILESLoaderPlugin";version=1;migrations=[];onReadProcess;constructor(){this.onReadProcess={supportedExtensions:["smi","smiles"],onFile:this.onReadProcessFile.bind(this)}}onReadProcessFile(r,t={}){let{logger:i}=t;return hr(r,{logger:i})}};function Je(){return new Ne}import{formatSpectra as os}from"@zakodium/nmrium-core";import{createFromToArray as Vi}from"ml-spectra-processing/utils";function Ji(e){e.setLittleEndian();let r=e.offset,t=32*3;e.offset=t/8;let i=e.readInt32(),n=[2,4],s=[2**25,2**26];if(!n.includes(i))if(s.includes(i))e.setBigEndian();else throw new Error(`Unexpected value of eBytes (${i}). Expect one of
|
|
9
|
+
${n.concat(s).join(",")}`);return e.offset=r,e.isBigEndian()?"BE":"LE"}var yr=class{storesData;isSpectrum;isInt32;isFloat32;isComplex;isHypercomplex;isBaselineCorrected;constructor(e){if(this.storesData=(e&1)!==0,!this.storesData)throw new Error("No data stored in file. Exiting...");if(this.isSpectrum=(e&2)!==0,this.isSpectrum)throw new Error("Script only analyzes FIDs. Found spectrum.");if(this.isInt32=(e&4)!==0,this.isFloat32=(e&8)!==0,this.isComplex=(e&16)!==0,this.isHypercomplex=(e&32)!==0,this.isHypercomplex)throw new Error("Script does not analyze hypercomplex data (yet).");this.isBaselineCorrected=(e&64)!==0}},Yi=class extends yr{moreBlocks;npComplex;nfComplex;niComplex;ni2Complex;constructor(e){super(e),this.moreBlocks=(e&128)!==0,this.npComplex=(e&256)!==0,this.nfComplex=(e&512)!==0,this.niComplex=(e&1024)!==0,this.ni2Complex=(e&2048)!==0}},Gi=class extends yr{isAcqPar;isSecondFT;isTransformed;is3D;isNp;isNf;isNi;isNi2;constructor(e){super(e),this.isAcqPar=(e&128)!==0,this.isSecondFT=(e&256)!==0,this.isTransformed=(e&512)!==0,this.is3D=(e&1024)!==0,this.isNp=(e&2048)!==0,this.isNf=(e&4096)!==0,this.isNi=(e&8192)!==0,this.isNi2=(e&16384)!==0}},Hi=class{lines;length;index;eol;constructor(e,r={}){let{eol:t=`
|
|
10
|
+
`,index:i=0}=r;this.eol=t,this.index=i,this.lines=e.split(this.eol),this.length=this.lines.length}readLine(){if(this.index>=this.length)throw new Error(`Last index is ${this.length-1}. Current index ${this.index}.`);return this.lines[this.index++]}readLines(e){let r=this.lines.slice(this.index,this.index+e);return this.index+=e,r}},Zi=class{softwareVersion;typeOfFile;vendorIdStatus;constructor(e){this.softwareVersion=e&2**6-1,this.typeOfFile={fidFile:(e&64)!==0,dataFile:(e&128)!==0,data3DFile:(e&256)!==0},this.vendorIdStatus={isVar:(e&0)!==0,isQOne:(e&2048)!==0,isMakeFid:(e&4096)!==0,isJeol:(e&8192)!==0,isBru:(e&16384)!==0,isMag:(e&6144)!==0,isOx:(e&10240)!==0,ipVers:(e&63)!==0,ipFileId:(e&1984)!==0,ipVendorId:(e&30720)!==0}}},Ki=class{npPhMode;npAvMode;npPwrMode;nfPhMode;nfAvMode;nfPwrMode;niPhMode;niAvMode;niPwrMode;ni2PhMode;ni2AvMode;ni2PwrMode;niPaMode;ni2PaMode;constructor(e){this.npPhMode=(e&1)!==0,this.npAvMode=(e&2)!==0,this.npPwrMode=(e&4)!==0,this.nfPhMode=(e&16)!==0,this.nfAvMode=(e&32)!==0,this.nfPwrMode=(e&64)!==0,this.niPhMode=(e&256)!==0,this.niAvMode=(e&512)!==0,this.niPwrMode=(e&1024)!==0,this.ni2PhMode=(e&8)!==0,this.ni2AvMode=(e&256)!==0,this.ni2PwrMode=(e&8192)!==0,this.niPaMode=(e&16384)!==0,this.ni2PaMode=(e&32768)!==0}},Qi=class{scale;status;index;mode;ctCount;lpVal;rpVal;lvl;tlt;data;constructor(e,r,t){t&&(e.offset=t),this.scale=e.readInt16(),this.status=new Yi(e.readInt16()),this.index=e.readInt16(),this.mode=new Ki(e.readInt16()),this.ctCount=e.readInt32(),this.lpVal=e.readFloat32(),this.rpVal=e.readFloat32(),this.lvl=e.readFloat32(),this.tlt=e.readFloat32(),this.data=es(e,r)}};function es(e,r){let{np:t,nTraces:i,status:{isFloat32:n,isInt32:s}}=r;return n?Ye(e,i,t,"readFloat32"):s?Ye(e,i,t,"readInt32"):Ye(e,i,t,"readInt16")}function Ye(e,r,t,i){let n=[],s;i==="readFloat32"?s={re:new Float32Array(t/2),im:new Float32Array(t/2)}:i==="readInt32"?s={re:new Int32Array(t/2),im:new Int32Array(t/2)}:s={re:new Int16Array(t/2),im:new Int16Array(t/2)};for(let o=0;o<r;o++){for(let l=0;l<t;l+=2)s.re[l>>>1]=e[i](),s.im[l>>>1]=e[i]();n[o]=s}return n}var ts=class{nBlocks;nTraces;np;eBytes;tBytes;bBytes;version;status;nBlockHeaders;constructor(e){e.offset=0,this.nBlocks=e.readInt32(),this.nTraces=e.readInt32(),this.np=e.readInt32(),this.eBytes=e.readInt32(),this.tBytes=e.readInt32(),this.bBytes=e.readInt32(),this.version=new Zi(e.readInt16()),this.status=new Gi(e.readInt16()),this.nBlockHeaders=e.readInt32()}},rs=class{name;subType;basicType;maxValue;minValue;stepSize;gGroup;dGroup;protection;active;intptr;constructor(e){let r=e.split(" ");this.name=r[0],this.subType=Number.parseInt(r[1],10),this.basicType=Number.parseInt(r[2],10),this.maxValue=Number.parseFloat(r[3]),this.minValue=Number.parseFloat(r[4]),this.stepSize=Number.parseFloat(r[5]),this.gGroup=Number.parseInt(r[6],10),this.dGroup=Number.parseInt(r[7],10),this.protection=Number.parseInt(r[8],10),this.active=Number.parseInt(r[9],10),this.intptr=Number.parseInt(r[10],10)}};function ns(e){let r=[],t=new Hi(e.readChars(e.length));for(;t.index<t.length-1;){let i=[],n=[],s=new rs(t.readLine()),o=t.readLine();if(s.basicType!==0){if(s.basicType===1)i=o.split(" ").slice(1).map(m=>Number.parseFloat(m));else if(s.basicType===2){i=o.split('"').slice(1,2);let m=Number.parseInt(o.split(" ")[0],10);for(;m>1;)i.push(t.readLine().split('"')[1]),m--}}let l=t.readLine(),a=Number.parseInt(l.split(" ")[0],10);a!==0&&(s.basicType===1?n=l.split(" ").slice(1):s.basicType===2&&(n=l.split('"').filter((m,f)=>f%2===1))),r.push({...s,values:i,enumerable:a,enumerables:n})}return r}async function br(e){let r={};function t(a,m){return a.then(f=>{r[m]=f})}let i=[];for(let a of e)switch(a.name.toLowerCase()){case"fid":{i.push(t(a.arrayBuffer(),"fidB"));break}case"procpar":{i.push(t(a.arrayBuffer(),"procparB"));break}default:break}if(await Promise.all(i),!r.fidB||!r.procparB)throw new RangeError("fid and procpar must exist.");let n=new v(r.fidB);Ji(n);let s=new ts(n);if(s.nBlocks!==1)throw new Error("We currently do not support 2D varian spectra ");let o=ns(new v(r.procparB)),l;for(let a of o)if(a.name==="at"){l=a.values[0];break}if(typeof l!="number")throw new Error("acquisition time parameter must exist and be a number.");{let a=Vi({from:0,to:l,length:s.np/2,distribution:"uniform"}),m=new Qi(n,s);return{meta:s,fid:m,procpar:o,x:a}}}import{FileCollection as as}from"filelist-utils";import{isAnyArray as ls}from"is-any-array";import{xMultiply as cs}from"ml-spectra-processing";import{normalizeNucleus as is}from"nmr-processing";function Fr(e,r){let{meta:t,procpar:i}=e,n={};for(let h of i)n[h.name]=h.values;let s={},o={},{np:l,solvent:a,sfrq:m,reffrq:f,temp:c,rp:b,sw:u,rfl:y,rfp:g}=n;D(s,"numberOfPoints",l&&Number(_(l))/2),D(s,"solvent",_(a)),D(s,"originFrequency",_(m)),D(s,"baseFrequency",_(f)),(Number.isNaN(s.originFrequency)||s.originFrequency===0)&&(s.originFrequency=400,r?.warn("The frequency could not be determined and was set to 400MHz")),D(s,"temperature",_(c)),D(s,"phc0",b&&Number(b[0])),D(o,"rfl",y&&Number(_(y))),D(o,"rfp",g&&Number(_(g))),D(o,"sw",u&&Number(_(u)));for(let h in o){let F=o[h];Array.isArray(F)&&F.length===1&&(o[h]=F[0])}if(!("baseFrequency"in s)&&"originFrequency"in s){let h=Number.parseFloat(s.originFrequency);if(["sw","rfl","rfp"].every(F=>F in o)){let{sw:F=1,rfl:N=1,rfp:x=1}=ss(o,["sw","rfl","rfp"]);D(s,"baseFrequency",h-(F/2-N+x)/1e6)}else D(s,"baseFrequency",h)}let{baseFrequency:p,originFrequency:d}=s;D(s,"frequencyOffset",(d-p)*1e6),D(s,"spectralWidth",u&&Number(u[0])/s.baseFrequency);for(let h in s)s[h].length===1&&(s[h]=s[h][0]);return n.tn&&(s.nucleus=n.tn.map(is)),s.dimension=1,s.isFid=!t.status.isSpectrum,{info:s,meta:{...o,...Sr(t),...n}}}function _(e){return e&&(Array.isArray(e)?e[0]:e)}function ss(e,r){let t={};for(let i of r){let n=e[i];n&&typeof n=="number"&&(t[i]=n)}return t}function Sr(e){let r={};for(let t of Object.keys(e)){let i=e[t];typeof i=="object"&&i!==null&&i.constructor&&i.constructor!==Object?r[t]=Sr(i):r[t]=i}return r}function Nr(e){let r={},t=new Set(e.files.map(i=>i.relativePath));for(let i of e){let n=i.name.toLowerCase();if(n.match(/^(?:fid|procpar|text|log)$/)){if(n.match(/^(?:fid|text|log)$/)){let l=i.relativePath.replace(/(?:fid|text|log)$/,"procpar");if(!t.has(l))continue}let s=i.relativePath.split("/"),o=s.slice(0,-1).join("/");r[o]||(r[o]={name:s.at(-2),files:[]}),r[o].files.push(i)}}return Object.values(r)}async function Dr(e,r={}){let{keepSource:t,logger:i}=r,n=Nr(e);i&&i.debug(`Found ${Object.keys(n).length} varian experiments`);let s=[],o={spectra:[],molecules:[]};for(let a of n){let{name:m,files:f}=a,c=new as(f),b=br(c).then(u=>{let{info:y,meta:g}=Fr(u),p=u.fid.data[0],d=ls(p.im),h={data:{...p,x:u.x},meta:g,info:{isComplex:d,name:m,...y},display:{name:m}};if(y.isFid&&d){let{im:F}=h.data;cs(F,-1,{output:F})}f&&t&&(h.sourceSelector={files:f.map(F=>F.relativePath)}),o.spectra.push(h)});s.push(b)}let l=await Promise.allSettled(s);for(let a=0;a<l.length;a++){let m=l[a];if(m.status==="rejected"&&m.reason){let f=n[a].name;i?.warn(`Varian data: ${f}, fails with: ${m.reason}`)}}return o.spectra.length>0&&i?.info(`Loaded ${o.spectra.length} spectra from Varian files`),os(o)}var De=class{id="@zakodium/nmrium-core-plugins#VarianLoaderPlugin";version=1;migrations=[];onReadProcess;constructor(){this.onReadProcess={onFiles:this.onReadProcessFiles}}onReadProcessFiles=(r,t)=>{let{keepSource:i,logger:n}=t??{};return Dr(r,{keepSource:i,logger:n})}};function Ge(){return new De}function us(e,r=[]){return[Xe(e),Ge(),ke(),Ue(),We(),Ve(),Je(),ze(),Ce()].concat(r)}function ps(){let e=new ms;return e.registerPlugins(us(e)),e}import{getOneIfArray as Ar}from"@zakodium/nmrium-core";import{from1DNMRVariables as fs}from"convert-to-jcamp";function Pr(e,r){return e.filters.find(t=>t.name===r)}function ds(e,r={}){let{info:t,meta:i,data:n}=e,{onlyReal:s=!1}=r,{isFid:o,spectralWidth:l}=t,a=Ar(t.baseFrequency||t.originFrequency),{x:m,re:f,im:c}=n,b=new Float64Array(f),u=!s&&c?new Float64Array(c):void 0,y={};te(y,"SW",l),te(y,"BF1",a);let g=Pr(e,"fft")?.enabled,p={originFrequency:t.originFrequency,dataType:!t.isFid||g?"NMR SPECTRUM":"NMR FID",dataClass:!s&&c?"NTUPLES":"XYDATA"};if(o){let F=e.filters.find(N=>N.name==="digitalFilter");if(F&&!g){let{value:{digitalFilterValue:N},enabled:x}=F;if(x){let S=Math.floor(N);b.set(f.slice(f.length-S)),b.set(f.slice(0,f.length-S),S),c&&u&&(u.set(c.slice(c.length-S)),u.set(c.slice(0,c.length-S),S))}}te(p,"decim",t.decim),te(p,"dspfvs",t.dspfvs),te(p,"digitalFilter",t.digitalFilter)}let d={xyEncoding:"DIFDUP",info:{...t,...p},meta:{...i,...y}},h={x:{data:m,label:t.isFid?"TIME":"FREQUENCY",units:t.isFid?"second":"HZ",symbol:"X"},r:{data:b,label:`${t.isFid?"FID":"SPECTRUM"}/REAL`,units:"ARBITRARY UNITS",symbol:"R"}};return u&&(h.i={data:u,label:`${t.isFid?"FID":"SPECTRUM"}/IMAG`,units:"ARBITRARY UNITS",symbol:"I"}),fs(h,d)}function te(e,r,t){t!==void 0&&(e[r]=Ar(t))}export{ne as AutoPostProcessingPlugin,fe as BrukerLoaderPlugin,he as JCAMPDXLoaderPlugin,ye as JEOLLoaderPlugin,be as MolfileLoaderPlugin,Fe as NMReDATALoaderPlugin,Se as SDFLoaderPlugin,Ne as SMILESLoaderPlugin,De as VarianLoaderPlugin,Ce as autoPostProcessing,ke as brukerLoader,ps as default,ps as init,Ue as jcampDXLoader,ze as jeolLoader,We as molfileLoader,Xe as nmreDATALoader,Yt as processJCAMPDX,fr as readSDF,gr as readSMILES,us as recommended,Ve as sdfLoader,Je as smilesLoader,ds as spectrum1DToJCAMPDX,Ge as varianLoader};
|
package/package.json
CHANGED
|
@@ -1,83 +1,62 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zakodium/nmrium-core-plugins",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "Recommended plugins for NMRium, loaders of common formats like bruker or jcamp, and some post-processing plugins",
|
|
5
|
-
"author": "",
|
|
5
|
+
"author": "Zakodium Sàrl",
|
|
6
6
|
"license": "CC-BY-NC-SA-4.0",
|
|
7
7
|
"type": "module",
|
|
8
|
-
"exports":
|
|
9
|
-
".": {
|
|
10
|
-
"types": "./dist/nmrium-core-plugins.d.ts",
|
|
11
|
-
"require": "./dist/nmrium-core-plugins.cjs",
|
|
12
|
-
"default": "./dist/nmrium-core-plugins.mjs"
|
|
13
|
-
}
|
|
14
|
-
},
|
|
8
|
+
"exports": "./dist/nmrium-core-plugins.js",
|
|
15
9
|
"files": [
|
|
16
|
-
"dist
|
|
17
|
-
"dist/nmrium-core-plugins.cjs",
|
|
18
|
-
"dist/nmrium-core-plugins.mjs"
|
|
10
|
+
"dist"
|
|
19
11
|
],
|
|
20
12
|
"imports": {
|
|
21
13
|
"#assets": "./src/assets.js"
|
|
22
14
|
},
|
|
23
15
|
"scripts": {
|
|
24
16
|
"api-extractor": "api-extractor run --local",
|
|
25
|
-
"bundle": "
|
|
26
|
-
"bundle-common": "esbuild src/index.ts --bundle --packages=external --minify",
|
|
27
|
-
"bundle-cjs": "npm run bundle-common -- --format=cjs --outfile=./dist/nmrium-core-plugins.cjs",
|
|
28
|
-
"bundle-esm": "npm run bundle-common -- --format=esm --outfile=./dist/nmrium-core-plugins.mjs",
|
|
17
|
+
"bundle": "node scripts/esbuild.js && npm run bundle-types",
|
|
29
18
|
"bundle-types": "npm run tsc && npm run api-extractor",
|
|
30
|
-
"check-types": "tsc --noEmit",
|
|
31
19
|
"clean": "rimraf types dist coverage",
|
|
32
|
-
"eslint": "eslint src --cache",
|
|
33
|
-
"eslint-fix": "npm run eslint -- --fix",
|
|
34
20
|
"dev:eslint-fix": "eslint --cache --fix $(git diff --name-only --relative) --quiet",
|
|
35
|
-
"prepack": "npm run bundle",
|
|
36
|
-
"prettier": "prettier --check src",
|
|
37
|
-
"prettier-write": "prettier --write src",
|
|
21
|
+
"prepack": "npm run clean && npm run bundle",
|
|
38
22
|
"dev:prettier-write": "prettier --write $(git diff --name-only --relative)",
|
|
39
|
-
"test": "
|
|
40
|
-
"test-only": "vitest run --coverage",
|
|
23
|
+
"test": "yarn g:test-only && yarn g:check-types && yarn g:eslint && yarn g:prettier",
|
|
41
24
|
"tsc": "tsc --project tsconfig.types.json"
|
|
42
25
|
},
|
|
43
26
|
"devDependencies": {
|
|
44
|
-
"@microsoft/api-extractor": "^7.52.
|
|
27
|
+
"@microsoft/api-extractor": "^7.52.7",
|
|
45
28
|
"@types/lodash.merge": "^4.6.9",
|
|
46
|
-
"@types/node": "^22.
|
|
47
|
-
"@
|
|
29
|
+
"@types/node": "^22.15.16",
|
|
30
|
+
"@zakodium/bruker-parser": "^0.0.0",
|
|
31
|
+
"@zakodium/jeol-parser": "^0.0.0",
|
|
32
|
+
"@zakodium/varian-parser": "^0.0.0",
|
|
48
33
|
"bruker-data-test": "^0.5.4",
|
|
49
|
-
"esbuild": "^0.25.
|
|
50
|
-
"eslint": "^9.22.0",
|
|
51
|
-
"eslint-config-cheminfo-typescript": "^18.0.0",
|
|
34
|
+
"esbuild": "^0.25.4",
|
|
52
35
|
"fifo-logger": "^1.0.0",
|
|
53
36
|
"jcamp-data-test": "^0.8.3",
|
|
54
37
|
"jeol-data-test": "^0.5.2",
|
|
55
38
|
"jest-matcher-deep-close-to": "^3.0.2",
|
|
56
|
-
"msw": "^2.7.
|
|
39
|
+
"msw": "^2.7.6",
|
|
57
40
|
"nmredata-data-test": "^0.4.0",
|
|
58
|
-
"prettier": "^3.5.3",
|
|
59
41
|
"rimraf": "^6.0.1",
|
|
60
|
-
"
|
|
61
|
-
"vitest": "^3.0.9"
|
|
42
|
+
"vitest": "^3.1.3"
|
|
62
43
|
},
|
|
63
44
|
"dependencies": {
|
|
64
|
-
"@zakodium/nmrium-core": "^0.1.
|
|
65
|
-
"
|
|
45
|
+
"@zakodium/nmrium-core": "^0.1.1",
|
|
46
|
+
"cheminfo-types": "^1.8.1",
|
|
66
47
|
"convert-to-jcamp": "^5.4.11",
|
|
67
48
|
"filelist-utils": "^1.11.3",
|
|
68
|
-
"gyromagnetic-ratio": "^
|
|
49
|
+
"gyromagnetic-ratio": "^2.0.0",
|
|
69
50
|
"is-any-array": "^2.0.1",
|
|
70
51
|
"jcampconverter": "^11.0.1",
|
|
71
|
-
"jeolconverter": "^1.0.4",
|
|
72
52
|
"linear-sum-assignment": "^1.0.7",
|
|
73
53
|
"lodash.merge": "^4.6.2",
|
|
74
|
-
"ml-spectra-processing": "^14.
|
|
75
|
-
"nmr-processing": "^18.0.
|
|
54
|
+
"ml-spectra-processing": "^14.12.0",
|
|
55
|
+
"nmr-processing": "^18.0.2",
|
|
76
56
|
"nmredata": "^1.0.0",
|
|
77
|
-
"openchemlib": "^9.
|
|
78
|
-
"openchemlib-utils": "^8.1.
|
|
79
|
-
"sdf-parser": "^7.0.4"
|
|
80
|
-
"varian-converter": "^2.0.1"
|
|
57
|
+
"openchemlib": "^9.1.1",
|
|
58
|
+
"openchemlib-utils": "^8.1.1",
|
|
59
|
+
"sdf-parser": "^7.0.4"
|
|
81
60
|
},
|
|
82
61
|
"volta": {
|
|
83
62
|
"extends": "../../../package.json"
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
"use strict";var Tr=Object.create;var Z=Object.defineProperty;var Er=Object.getOwnPropertyDescriptor;var Lr=Object.getOwnPropertyNames;var kr=Object.getPrototypeOf,wr=Object.prototype.hasOwnProperty;var vr=(e,r)=>{for(var t in r)Z(e,t,{get:r[t],enumerable:!0})},_e=(e,r,t,i)=>{if(r&&typeof r=="object"||typeof r=="function")for(let n of Lr(r))!wr.call(e,n)&&n!==t&&Z(e,n,{get:()=>r[n],enumerable:!(i=Er(r,n))||i.enumerable});return e};var Se=(e,r,t)=>(t=e!=null?Tr(kr(e)):{},_e(r||!e||!e.__esModule?Z(t,"default",{value:e,enumerable:!0}):t,e)),qr=e=>_e(Z({},"__esModule",{value:!0}),e);var Jn={};vr(Jn,{AutoPostProcessingPlugin:()=>z,BrukerLoaderPlugin:()=>B,JCAMPDXLoaderPlugin:()=>X,JEOLLoaderPlugin:()=>J,MolfileLoaderPlugin:()=>_,NMReDATALoaderPlugin:()=>V,SDFLoaderPlugin:()=>H,SMILESLoaderPlugin:()=>Y,VarianLoaderPlugin:()=>G,autoPostProcessing:()=>te,brukerLoader:()=>ue,default:()=>Ar,init:()=>Ar,jcampDXLoader:()=>de,jeolLoader:()=>ye,molfileLoader:()=>he,nmreDATALoader:()=>Fe,processJCAMPDX:()=>qe,readSDF:()=>We,readSMILES:()=>Xe,recommended:()=>Mr,sdfLoader:()=>Pe,smilesLoader:()=>Ne,spectrum1DToJCAMPDX:()=>Or,varianLoader:()=>De});module.exports=qr(Jn);var Rr=require("@zakodium/nmrium-core");var ee=require("nmr-processing");var Ve=require("@zakodium/nmrium-core");function Q(e={},r={},t={}){e===null&&(e={}),typeof e=="string"&&(e={pulseSequence:e});let i=Array.isArray(e.pulseSequence)?e.pulseSequence[0]:e.pulseSequence||"";if(typeof i!="string")return e.dimension?`${e.dimension}d`:"";if(i=i.toLowerCase(),i.includes("zg")||i.includes("single_pulse_dec")||i.includes("udeft"))return"1d";if(i.includes("hsqct")||i.includes("invi")&&(i.includes("ml")||i.includes("di")))return"hsqctocsy";if(i.includes("hsqc")||i.includes("invi"))return"hsqc";if(i.includes("hmbc")||i.includes("inv4")&&i.includes("lp"))return"hmbc";if(i.includes("hmqc"))return"hmqc";if(i.includes("cosy"))return"cosy";if(i.includes("jres"))return"jres";if(i.includes("dosy"))return"dosy";if(i.includes("tocsy")||i.includes("mlev")||i.includes("dipsi"))return"tocsy";if(i.includes("noesy"))return"noesy";if(i.includes("roesy"))return"roesy";if(i.includes("dept"))return"dept";if(i.includes("jmod")||i.includes("apt"))return"aptjmod";if(i.includes("inad"))return"inadequate";if(i.includes("adeq"))return"adequate";let{prefix:n=""}=t,o=((0,Ve.getOneIfArray)(r[`${n}SPECTYP`])||"").replace(/^<(.*)>$/,"$1").toLowerCase();return o.length>0&&o!=="undefined"?o:e.dimension?`${e.dimension}d`:""}var Re=require("@zakodium/nmrium-core"),$r=["no","exponential","modifiedGaussian","sine","qsine","trap","user","sinc","qsinc","traf","trafs"];function jr(e){return e in He}function Me(e,r){let{prefix:t="",index:i=0}=r,n=(0,Re.getOneIfArray)(e[`${t}WDW`],i),o=$r[n?Number(n):0],s={};if(!jr(o))return s;let l=He[o];if(l){let{kind:a,parameters:m}=l,u={};for(let c in m){let g=m[c],{source:y,processor:d}=g;if(y){let p=(0,Re.getOneIfArray)(e[`${t}${y}`],i);if(!p)continue;let f=Number(p);u[c]=d?d(f):f}else g.value!==void 0&&(u[c]=g.value)}s[a]={apply:!0,options:u}}return s}var He={exponential:{kind:"exponential",parameters:{lineBroadening:{source:"LB"}}},modifiedGaussian:{kind:"gaussian",parameters:{lineBroadening:{source:"LB"},lineBroadeningCenter:{source:"GB"}}},sine:{kind:"sineBell",parameters:{offset:{source:"SSB",processor:e=>1/e},exponent:{value:1}}},qsine:{kind:"sineSquare",parameters:{offset:{source:"SSB",processor:e=>1/e}}},traf:{kind:"traf",parameters:{lineBroadening:{source:"LB"}}}};var Ye={sineBell:Ke({offset:0})},Ge={cosy:{...Ye},hmbc:{...Ye},hsqc:{sineBell:Ke({offset:.5})}},zr={...Ge};function Ae(e="",r=1){let t=Br(e),i={},n=r===1?Ge[t||""]:zr[t||""];return n&&(i=structuredClone(n)),i}function Ke(e){return{apply:!0,options:e}}function Br(e){let t=e.toLowerCase().match(/cosy|hsqc|hmbc/);return t?t[0]:null}function Ze(e,r={}){let{prefix:t="",experiment:i=Q(e)}=r;return e[`${t}WDW`]?{f2:Me(e,{...r,index:0}),f1:Me(e,{...r,index:1})}:{f2:Ae(i,1),f1:Ae(i,2)}}var Qe=require("nmr-processing"),xe=["digitalFilter","backwardLinearPrediction","forwardLinearPrediction","apodization","zeroFilling","fft",["shiftX","phaseCorrection","baselineCorrection"]],k={};for(let e=0;e<xe.length;e++){let r=xe[e];for(let t of Array.isArray(r)?r:[r])k[t]=e}for(let e of Object.values(Qe.Filters1D))e.name in k||(k[e.name]=xe.length);var et=require("nmr-processing"),Ce=["digitalFilter2D","blpDimension1","flpDimension1","apodizationDimension1","zeroFillingDimension1","fftDimension1","blpDimension2","flpDimension2","nusDimension2","apodizationDimension2","zeroFillingDimension2","fftDimension2","phaseCorrectionTwoDimensions",["shift2DX","shift2DY","symmetrizeCosyLike"]],w={};for(let e=0;e<Ce.length;e++){let r=Ce[e];for(let t of Array.isArray(r)?r:[r])w[t]=e}for(let e of Object.values(et.Filters2D))e.name in w||(w[e.name]=Ce.length);var Ur=new Set(["backwardLinearPrediction","forwardLinearPrediction","digitalFilter2D","phaseCorrectionTwoDimensions","blpDimension1","flpDimension1","apodizationDimension1","apodizationDimension2","zeroFillingDimension1","fftDimension1","blpDimension2","flpDimension2","zeroFillingDimension2","fftDimension2","nusDimension2","symmetrizeCosyLike"]);function Wr(e,r){let{filter:t,experimentalFeatures:i=!1}=r,{name:n}=t;({...ee.Filters1D,...ee.Filters2D})[n]&&(e.some(s=>s.name===n)||(i||!Ur.has(n))&&e.push({...t,enabled:!0}))}function tt(e,r={}){let{data:t}=e;if(!t)return e;let{autoProcessing:i,experimentalFeatures:n}=r,o=(l,a)=>Wr(l,{...a,experimentalFeatures:n}),{spectra:s}=t;for(let l of s){let{data:a,info:m,meta:u,filters:c}=l,{dimension:g,isFid:y}=m;if(y){if(g===1){let d=a.re.length,{tdOff:p,digitalFilter:f}=m;if(f&&f>0&&o(c,{filter:{name:"digitalFilter",value:{digitalFilterValue:f}}}),!i)continue;p&&Math.abs(p)>0&&o(c,{filter:{name:"backwardLinearPrediction",value:{nbInputs:d/2}}}),o(c,{filter:{name:"apodization",value:{exponential:{apply:!0,options:{lineBroadening:1}}}}}),o(c,{filter:{name:"zeroFilling",value:{nbPoints:2*d}}}),o(c,{filter:{name:"fft",value:{}}}),o(c,{filter:{name:"phaseCorrection",value:Xr(m)}}),c.sort((F,h)=>k[F.name]-k[h.name])}else if(g===2){if(!i||!n)continue;let d=a.re.z.length,p=a.re.z[0].length,{tdOff:f,experiment:F=""}=m,h=m.spectrumSize;Array.isArray(h)&&h.length>1?(h[0]<=p&&(h[0]=p*2),h[0]<=d&&(h[0]=d*2)):h=[p*2,2*d];let b=F.toLowerCase().includes("cosy");f&&Math.abs(f[0])>0&&o(c,{filter:{name:"blpDimension1",value:{nbInputs:p/2}}});let N=Ze(u,{experiment:F});o(c,{filter:{name:"apodizationDimension1",value:N.f2}}),o(c,{filter:{name:"zeroFillingDimension1",value:{nbPoints:h[0]}}}),o(c,{filter:{name:"fftDimension1",value:{}}}),u&&"nuslist"in u&&o(c,{filter:{name:"nusDimension2",value:{}}}),o(c,{filter:{name:"apodizationDimension2",value:N.f1}}),o(c,{filter:{name:"zeroFillingDimension2",value:{nbPoints:h[b?0:1]}}}),b?o(c,{filter:{name:"symmetrizeCosyLike",value:{}}}):o(c,{filter:{name:"phaseCorrectionTwoDimensions",value:{}}}),o(c,{filter:{name:"fftDimension2",value:{}}}),c.sort((S,D)=>w[S.name]-w[D.name])}}}}function Xr(e){let{phc0:r=0,phc1:t=0}=e;return rt([r,t])?{}:{ph0:r,ph1:t}}function rt(e){return Array.isArray(e)?e.every(r=>!r&&r===0):rt([e])}var z=class{id="@zakodium/nmrium-core-plugins#AutoPostProcessingPlugin";version=1;migrations=[];onReadProcess;constructor(){this.onReadProcess={onProcessing:this.onPostProcessing.bind(this)}}onPostProcessing(r,t){tt(r,t)}};function te(){return new z}var pt=require("@zakodium/nmrium-core"),me=require("brukerconverter");function re(e){let r=[];for(let t of e){if(!t)continue;let{groups:{value:i,unit:n}={}}=t.trim().match(/[$$]*\s*(?<value>[\d.]+)\s*(?<unit>[a-zA-Z]+)/)||{};r.push(Jr(i,n))}return r}function Jr(e,r){switch(r.toLowerCase()){case"s":return Number.parseFloat(e);case"ms":return Number.parseFloat(e)/1e3;case"m":case"min":return Number.parseFloat(e)*60;default:return Number.NaN}}var Oe=require("is-any-array");function I(e){if(_r(e))return Vr(e)?e.map(nt):nt(e);if(typeof e=="object"&&e!==null){let r={};for(let t in e)r[t]=I(e[t]);return r}return e}function _r(e){return(0,Oe.isAnyArray)(e)}function nt(e){return Float64Array.from(e)}function Vr(e){return(0,Oe.isAnyArray)(e[0])}var v=require("@zakodium/nmrium-core"),mt=require("gyromagnetic-ratio"),ae=require("is-any-array"),lt=require("nmr-processing");var T=require("is-any-array");function ne(e){return typeof e=="number"}function ie(e){let{phc0:r,phc1:t}=e;return!(0,T.isAnyArray)(r)&&!ne(r)||!(0,T.isAnyArray)(t)&&!ne(t)||(0,T.isAnyArray)(r)&&!ne(r[0])||(0,T.isAnyArray)(t)&&!ne(t[0])?{}:((0,T.isAnyArray)(t)?t[0]*=-1:t*=-1,(0,T.isAnyArray)(r)?r[0]*=-1:r*=-1,{phc0:r,phc1:t})}function ot(e,r,t){if(e>0)return Number(e);if(r>14||r===0)return 0;if(it[r]){let i=it[r];if(!i[t])throw new Error(`decim ${t} not in lookup table for dspfvs ${r}`);return i[t]}else throw new Error(`dspfvs ${r} not in lookup table`)}var it={10:{2:44.75,3:33.5,4:66.625,6:59.08333333333333,8:68.5625,12:60.375,16:69.53125,24:61.02083333333333,32:70.015625,48:61.34375,64:70.2578125,96:61.50520833333333,128:70.37890625,192:61.5859375,256:70.439453125,384:61.62630208333333,512:70.4697265625,768:61.646484375,1024:70.48486328125,1536:61.65657552083333,2048:70.492431640625},11:{2:46,3:36.5,4:48,6:50.16666666666667,8:53.25,12:69.5,16:72.25,24:70.16666666666667,32:72.75,48:70.5,64:73,96:70.66666666666667,128:72.5,192:71.33333333333333,256:72.25,384:71.66666666666667,512:72.125,768:71.83333333333333,1024:72.0625,1536:71.91666666666667,2048:72.03125},12:{2:46,3:36.5,4:48,6:50.16666666666667,8:53.25,12:69.5,16:71.625,24:70.16666666666667,32:72.125,48:70.5,64:72.375,96:70.66666666666666,128:72.5,192:71.333333333,256:72.25,384:71.66666666666667,512:72.125,768:71.83333333333333,1024:72.0625,1536:71.91666666666667,2048:72.03125},13:{2:2.75,3:2.833333333333333,4:2.875,6:2.916666666666667,8:2.9375,12:2.958333333333333,16:2.96875,24:2.979166666666667,32:2.984375,48:2.989583333333333,64:2.9921875,96:2.994791666666667}};var at=require("nmr-processing");function E(e,r=","){if(e&&typeof e=="string")return e.split(r)}function oe(e,r,t){let i=[];if(e[`${t}AXNUC`]&&(i=e[`${t}AXNUC`],Array.isArray(i)||(i=[i]),i=C(i)),i.length===0&&e[`${t}NUC1`]&&(i=e[`${t}NUC1`],Array.isArray(i)||(i=[i]),i=C(i)),i.length===0&&e[".NUCLEUS"]){let n=E(e[".NUCLEUS"]);if(e[`${t}SYMBOL`]){let o=e[`${t}SYMBOL`].split(","),s=o.findIndex(a=>a.includes("2")),l=o.findIndex(a=>a.includes("1"));s!==-1&&l!==-1&&n?i=C([n[s],n[l]]):i=C(n).reverse()}else i=C(n)}return i.length===0&&e[".OBSERVENUCLEUS"]&&(i=C([e[".OBSERVENUCLEUS"]])),i.length===0&&r.experiment&&(i=C(st(r.experiment[0]))),Hr(e)&&(i=[e["2D_X_NUCLEUS"].replaceAll(/[^A-Za-z0-9]/g,""),e["2D_Y_NUCLEUS"].replaceAll(/[^A-Za-z0-9]/g,"")]),r.experiment&&(r.experiment[0].match("jres")||r.experiment[0].match("dosy"))&&(i=st(r.experiment[0])),i.map(at.normalizeNucleus)}function Hr(e){return e["2D_X_NUCLEUS"]&&!e["2D_X_NUCLEUS"].includes("off")&&e["2D_Y_NUCLEUS"]&&!e["2D_Y_NUCLEUS"].includes("off")}function st(e){return typeof e!="string"?[]:(e=e.toLowerCase(),e.includes("jres")?["1H","Hz"]:e.includes("dosy")?["1H","D"]:e.includes("hmbc")||e.includes("hsqc")?["1H","13C"]:e.includes("cosy")||e.includes("tocsy")?["1H","1H"]:[])}function C(e){if(!e)return[];let r=e.map(i=>String(i).replaceAll(/[^A-Za-z0-9]/g,"").replace("NA","").replace("off","")),t=0;for(let i of r)i||t++;return t===0?r:[]}function P(e,r,t,i=!1){t===void 0||r in e&&!i||(Array.isArray(t)?e[r]=t.map(ct):e[r]=[ct(t)])}function ct(e){return typeof e=="string"&&(e.startsWith("<")&&e.endsWith(">")&&(e=e.slice(1,-1)),e=e.replace(/\$.*/,"").trim()),e}function ce(e,r={}){let{prefix:t="",logger:i}=r,n={dimension:0,nucleus:[],isFid:!1,isFt:!1},o=JSON.stringify(e),s=/\r\n/.exec(o)?`\r
|
|
2
|
-
`:`
|
|
3
|
-
`,{JCAMPDX:l="",ORIGIN:a=""}=e,m=String(l).toLowerCase()+String(a).toLowerCase();"SPECTROMETER/DATASYSTEM"in e&&(m=e["SPECTROMETER/DATASYSTEM"]);let u=(d=[])=>{for(let p of d)if(!(p in n))return!1;return!0};(m.includes("mestre")||m.includes("nova"))&&(m="mnova"),n.creator=m,e.LONGDATE&&Ie(n,Date.parse(e.LONGDATE)),P(n,"pulseSequence",e[".PULSESEQUENCE"]||e[".PULPROG"]||e[`${t}PULPROG`]);let c=e[`${t}OWNER`];if(c&&P(n,"owner",c.replaceAll(/\$\$.*/gm,"")),P(n,"aqMod",e[`${t}AQ_mod`]),P(n,"experiment",Q(n,e,{prefix:t})),n.nucleus=oe(e,n,t),n.nucleus.length===0)if(i)i?.warn("There is not a nucleus detected, assuming 1H"),n.nucleus=["1H"];else throw new Error("There is not a nucleus detected");n.dimension=n.nucleus.length;let g=e[`${t}.ACQUISITIONSCHEME`]||e[`${t}FnMODE`];if(g&&P(n,"acquisitionScheme",Gr((0,v.getOneIfArray)(g,1))),P(n,"acquisitionMode",e[`${t}.ACQUISITIONMODE`]),M(n,"lpNumberOfCoefficients",e[`${t}NCOEF`]),M(n,"linearPredictionBin",e[`${t}LPBIN`]),M(n,"tdOff",e[`${t}TDoff`]),P(n,"windowMultiplicationMode",e[`${t}WDW`]),P(n,"title",e.TITLE),P(n,"solvent",e[".SOLVENTNAME"]),P(n,"temperature",e[`${t}TE`]||e[".TE"]),P(n,"type",e.DATATYPE),P(n,"dataClass",e[`${t}DATACLASS`]),P(n,"phc1",e[`${t}PHC1`]),P(n,"phc0",e[`${t}PHC0`]),n.type){let d=n.type[0].toUpperCase();d.includes("FID")?(n.isFid=!0,n.isComplex=!0):d.includes("SPECTRUM")&&(n.isFt=!0)}if(P(n,"firstX",e[`${t}FIRSTX`]),P(n,"lastX",e[`${t}LASTX`]),P(n,"numberOfPoints",e[`${t}NPOINTS`]),P(n,"originFrequency",e[`${t}SFO1`]),n.dimension===1&&M(n,"originFrequency",e[".OBSERVEFREQUENCY"]),"originFrequency"in n&&(n.originFrequency=se(n.originFrequency)),!n.originFrequency&&n.dimension===2&&".OBSERVEFREQUENCY"in e){let{nucleus:d}=n,p=se(e[".OBSERVEFREQUENCY"]);if((0,ae.isAnyArray)(p)&&p.length>1){let f=e[`${t}SYMBOL`].split(","),F=f.findIndex(b=>b.includes("2")),h=f.findIndex(b=>b.includes("1"));F!==-1&&h!==-1?n.originFrequency=[p[F],p[h]]:n.originFrequency=p.slice()}else if(typeof p=="number"){let f=(0,lt.getFrequency)(d[1],{frequency:p,nucleus:d[0]});n.originFrequency=[p,f]}}if((!n.originFrequency||n.originFrequency.some(d=>Number.isNaN(d)||d===0))&&(n.originFrequency||(n.originFrequency=n.dimension>1?[400,400]:[400]),n.originFrequency=n.originFrequency.map(d=>Number.isNaN(d)||d===0?400:d),i?.warn("The frequency could not be determined and was set to 400 MHz")),m.toLocaleLowerCase().includes("oxford instruments")?Kr(n,e,{...r,separator:s}):m.includes("nanalysis")&&Zr(n,e),m!=="mnova"&&m!=="mestre"){let d=n.nucleus[0],p=(0,mt.getGyromagneticRatio)(d);if(P(n,"probeName",e[`${t}PROBHD`]),P(n,"baseFrequency",e[`${t}BF1`]),P(n,"baseFrequency",e[`${t}SF`]),M(n,"scaleFactor",e[`${t}NC_proc`]),"scaleFactor"in n)for(let b=0;b<n.scaleFactor.length;)n.scaleFactor[b]=2**n.scaleFactor[b++];if(!("baseFrequency"in n)&&"originFrequency"in n?P(n,"baseFrequency",n.originFrequency):n.baseFrequency=se(n.baseFrequency),!["baseFrequency","originFrequency"].some(b=>!n[b])&&p){let{baseFrequency:b}=n,N=2*Math.PI*(b[0]/p)*1e6;P(n,"fieldStrength",N)}M(n,"spectralWidth",e[`${t}SW`]),M(n,"spectralWidth",e[`${t}QM_SPECTRAL_WIDTH`]),n.dimension===1&&e[`${t}SweepWidth`]&&n.originFrequency&&M(n,"spectralWidth",e[`${t}SweepWidth`]/n.originFrequency[0]),P(n,"numberOfPoints",e[`${t}TD`],!0);let f=n.numberOfPoints;if(P(n,"spectrumSize",e[`${t}SI`]??f),P(n,"sampleName",e[`${t}NAME`]),e[`${t}FNTYPE`]!==void 0&&P(n,"acquisitionMode",Number.parseInt(e[`${t}FNTYPE`],10)),(e[`${t}VARNAME`]?e[`${t}VARNAME`].split(",")[0]:"")==="TIME"){let b=typeof e.LAST=="string"?e.LAST.replace(" ","").split(",")[0]:e.LAST;M(n,"acquisitionTime",b)}if(!n.acquisitionTime&&u(["numberOfPoints","spectralWidth"])){let{spectralWidth:b,originFrequency:N}=n;P(n,"acquisitionTime",Number((f[0]-1)/(2*b[0]*N[0])))}if(e[`${t}P`]){let b=1e6/((0,v.getOneIfArray)(e[`${t}P`]).split(s)[1].split(" ")[1]*4);P(n,"pulseStrength90",b)}if(e[`${t}D`]){let b=(0,v.getOneIfArray)(e[`${t}D`]).split(s)[1].split(" ")[1];M(n,"relaxationTime",b)}if(M(n,"numberOfScans",e[`${t}NS`]),M(n,"numberOfScans",e[`${t}QM_NSCANS`]),P(n,"groupDelay",e[`${t}GRPDLY`]),P(n,"dspfvs",e[`${t}DSPFVS`]),P(n,"decim",e[`${t}DECIM`]),n.isFid&&("groupDelay"in n||u(["dspfvs","decim"]))){let{groupDelay:b,dspfvs:N,decim:S}=n,D=ot(b?.[0]??0,N?.[0],S?.[0]);P(n,"digitalFilter",D)}let h;if(u(["numberOfPoints","spectralWidth"])){let{spectralWidth:b,numberOfPoints:N}=n;n.isFid?h=N.map(S=>n.acquisitionTime[0]/(S-1)):h=N.map((S,D)=>b[D]/(S-1))}if(P(n,"increment",h),e[`${t}DATE`]){let b=(0,v.getOneIfArray)(e[`${t}DATE`]),N=Number.parseInt(b,10)*1e3;Number.isNaN(N)?Ie(n,Date.parse(b)):Ie(n,N)}n.solvent||P(n,"solvent",(0,v.getOneIfArray)(e[`${t}SOLVENT`]))}if(n.dimension<2&&"dataClass"in n&&n.dataClass[0].toUpperCase()==="NTUPLES"&&(P(n,"last",E(e[`${t}LAST`])),P(n,"first",E(e[`${t}FIRST`])),P(n,"varDim",E(e[`${t}VARDIM`])),P(n,"symbols",E(e[`${t}SYMBOL`])),n.symbols&&Array.isArray(n.symbols))){n.symbols.includes("R")&&n.symbols.includes("I")&&(n.isComplex=!0);let d=n.symbols.findIndex(p=>p.toLowerCase()==="x");if(M(n,"firstX",n.first[d]),M(n,"lastX",n.last[d]),M(n,"numberOfPoints",n.varDim[d]),!("spectralWidth"in n)){let{lastX:p,numberOfPoints:f,firstX:F}=n;P(n,"spectralWidth",n.isFid?f/(2*p):Math.abs(p-F)/n.originFrequency)}}if(`${t}REVERSE`in e){let d=e[`${t}REVERSE`];n.reverse=(Array.isArray(d)?d:[d]).map(p=>typeof p=="string"?p.includes("yes"):p)}let y=e[`${t}REFERENCE_POINT`];if(!("frequencyOffset"in n)&&y&&u(["spectralWidth","baseFrequency"])){let d=typeof y=="number"?y:e[`${t}REFERENCE_POINT`].match(/(?<reference>[+-]?\d+(?:\.\d+)?)\s*.*/),p;if(typeof y=="number"?p=y:(y.match(/(?<reference>[+-]?\d+(?:\.\d+)?)\s*.*/),p=Number(d?.groups?.reference)),!Number.isNaN(p)){let{spectralWidth:f,baseFrequency:F}=n;P(n,"frequencyOffset",.5*f*F-p)}}if(!("frequencyOffset"in n)&&u(["baseFrequency","originFrequency"])){let{baseFrequency:d,originFrequency:p}=n,f=d.map((F,h)=>(p[h]-F)*1e6);P(n,"frequencyOffset",f)}for(let d in n)n[d]&&n[d].length===1&&(n[d]=n[d][0]);return!n.frequencyOffset&&".SHIFTREFERENCE"in e&&Yr(e,n),Array.isArray(n.nucleus)||(n.nucleus=[n.nucleus]),n}function M(e,r,t){t!==void 0&&P(e,r,se(t))}function Ie(e,r){if(!Number.isNaN(r)){e.epoch=r;let t=new Date(r);e.date=t.toUTCString(),e.localeDate=t.toLocaleString()}}function Yr(e,r){let t=e[".SHIFTREFERENCE"],i=t.trim().startsWith("(")?/\((?<data>[^)]+)\)/:/(?<data>[^)]+)/,n=t.match(i);if(n.groups.data){let o=n.groups.data.split(",");if(o.length<4)return;let s=Number.parseInt(r.numberOfPoints,10),{spectralWidth:l,baseFrequency:a}=r,m=Number.parseInt(o[2],10),u=Number.parseFloat(o[3]),c;if(r.isFid){if(["baseFrequency","numberOfPoints","spectralWidth"].some(g=>!(g in r)))return;c=u+(s*.5-m)*l/s}else{let g=Number.parseFloat(r.firstX),y=Number.parseFloat(r.lastX),d=(y+g)/2,p=(y-g)/(s+1),f=p<0?g:y+(m-1)*p;c=(d-f)/a+u}c!==void 0&&!Number.isNaN(c)&&(r.frequencyOffset=c*a)}}function se(e){if((0,ae.isAnyArray)(e)){let r=[];for(let t of e)r.push(typeof t=="string"?Number.parseFloat(t):t);return r}return typeof e=="string"?Number.parseFloat(e):e}function Gr(e){switch(String((0,ae.isAnyArray)(e)?e[1]:e).toLowerCase().replaceAll(/\s/g,"")){case"1":case"notphasesensitive":return"notPhaseSensitive";case"2":return"QSEQ";case"3":case"tppi":return"TPPI";case"4":case"states":return"States";case"5":case"tppi-states":return"States-TPPI";case"6":case"echo-antiecho":return"Echo-antiecho";default:return"undefined"}}function Kr(e,r,t={}){let{prefix:i="",separator:n=`
|
|
4
|
-
`}=t;P(e,"spectralWidth",r[`${i}SweepWidth`]/e.originFrequency[0]);let o=r[`${i}.PULSESEQUENCE`].split(n),s=[];r[".OBSERVENUCLEUS"]&&s.push(r[".OBSERVENUCLEUS"]),r.INDIRECTNUCLEUS&&s.push(r.INDIRECTNUCLEUS),e.nucleus=C(s),e.pulseSequence=o[0];let l=o.slice(2,-1);if(s.length>1)if(s[0]===s[1])e.spectralWidth.push(e.spectralWidth[0]);else{let a=JSON.stringify(l).match(/\$\$SW1=\s*(?<sw>[+-]?(?:[0-9]*[.])?[0-9]+)/);if(a?.groups){let{originFrequency:m}=e,u=Number.parseFloat(a.groups.sw);e.spectralWidth.push(u/m[1])}}return e}function Zr(e,r){let{T1NUCLEUS:t,T2NUCLEUS:i,PAGE:n}=r;e.pulseSequence=r.EXPERIMENT||r[".PULSESEQUENCE"];let o=[],{dimension:s,isComplex:l}=e;if(s===2&&e.pulseSequence==="T1"){let u=l?2:1;for(let c=0;c<n.length;c+=u){let g=n[c].replace(/T1=/,"");o.push(Number(g))}r.vdlistValues=o}e.nucleus=s>1?[i,t]:i;let{phc0:a,phc1:m}=e;if(a&&m){let u=ie({phc0:a,phc1:m});e={...e,...u}}}var Qr={keepRecordsRegExp:/.*/,keepFiles:!0};async function le(e,r={}){let t={spectra:[],molecules:[]},{converter:i={},selector:n={},logger:o}=r,s=(0,me.groupByExperiments)(e,{logger:o,...tn(n)}),l=[];for(let m of s)l.push((0,me.convertOneExperiment)(m,{...Qr,...i}).then(u=>en(u,r)));let a=await Promise.allSettled(l);for(let m=0;m<a.length;m++){let u=a[m];if(u.status==="fulfilled"){let c=ie(u.value.info);t.spectra.push({...u.value,info:{...u.value.info,...c}})}else if(u.reason){let c=s[m].name;o?.warn(`Bruker data: ${c}, fails with: ${u.reason}`);continue}}return o&&o[t.spectra.length>0?"info":"debug"](`Loaded ${t.spectra.length} spectra from Bruker files`),(0,pt.formatSpectra)(t)}function en(e,r={}){let{keepSource:t=!1,logger:i}=r,n={...e.info,...e.meta},o=ce(n,{logger:i}),s={},{isFid:l}=o;if(rn(e)){let y=e.minMax;for(let d in y){let p=y[d];p&&(p.z=I(p.z))}s.components=e.minMax}else o.dimension===1&&(s.components=e.spectra);let{source:a}=e,{expno:m,name:u,files:c}=a;n.vdlist&&(n.vdlistValues=re(n.vdlist));let g={dependentVariables:[s],meta:n,info:{...o,experimentNumber:m,name:u}};return c&&t&&(g.sourceSelector={files:c.map(y=>y.relativePath)}),nn(g,e),g}function tn(e){let{general:r={},bruker:t={}}=e,{processingNumbers:i,experimentNumbers:n,...o}=t;return{...r,...o,processingNumbers:ut(i),experimentNumbers:ut(n)}}function ut(e){if(e)return e.split(/[^\d]+/).filter(Boolean).map(r=>Number.parseInt(r,10))}function rn(e){let{info:r}=e;return r.twoD}function nn(e,r){if(!("integrals"in r))return;let{integrals:t=[]}=r;e.integrals={values:t.map(i=>{let{from:n,to:o,integration:s}=i;return{from:n,to:o,integral:s,kind:"signal"}})}}var B=class{id="@zakodium/nmrium-core-plugins#BrukerLoaderPlugin";version=1;migrations=[];onReadProcess;constructor(){this.onReadProcess={onFiles:this.onReadProcessFiles}}onReadProcessFiles=(r,t)=>{let{sourceSelector:i,converter:n,keepSource:o,logger:s}=t??{};return le(r,{converter:n?.bruker,selector:i,keepSource:o,logger:s})}};function ue(){return new B}var Jt=require("@zakodium/nmrium-core"),_t=require("jcampconverter");function ft(e,r,t={}){let{selector:i={},keepSource:n=!1}=t;if(!n)return e;for(let o=0;o<e.spectra.length;o++){let s=e.spectra[o];s.sourceSelector={files:[r.relativePath],jcamp:{index:o,...i}}}return e}var dt=require("jcampconverter");function Te(e,r,t){let{dataType:i,children:n}=e,o=i==="LINK"&&n?n:[e];for(let s of o){if(s.dataType==="LINK"){Te(s,r,t);continue}let l=(0,dt.convert)(s.jcamp,t);r.push(...l.flatten)}}function ht(e,r={}){let t=[],i=bt(e,r);for(let s of i?e:[])s.dataType==="LINK"?s.children=Ee(s.children,r):s=Ee([s],r)[0],t.push(s);let{name:n,logger:o}=r;return e.length===0&&o?.warn(`There is no data ${n?`in ${n}`:"in the JCAMP-DX"}`),t}function Ee(e=[],r={}){let{name:t,logger:i,tree:n=[],dataSelection:o="both"}=r,s=[];for(let u of e){let{dataType:c,dataClass:g}=u;if(c==="LINK")u.children=Ee(u.children,r);else if(n.some(y=>{let{dataClass:d=g,dataType:p=c}=y;return g===d&&c===p})){i?.warn(`Skipping ${g} and ${c} ${t?`in ${t}`:"in the JCAMP-DX"},
|
|
5
|
-
because it didn't match the import filters`);continue}s.push(u)}let l=[],a=s.some(yt),m=s.some(gt);for(let u of s){if(o!=="both"&&u.dataType!=="LINK"){if(yt(u)&&(o==="ft"||o==="preferFT"&&m)){i?.warn(`Skipping raw data ${t?`in ${t}`:"in the JCAMP-DX"} because it didn't match the import filters`);continue}if(gt(u)&&(o==="fid"||o==="preferFID"&&a)){i?.warn(`Skipping FFT data ${t?`in ${t}`:"in the JCAMP-DX"} because it didn't match the import filters`);continue}}l.push(u)}return l}function gt(e){return e.dataType?.toUpperCase().includes("SPECTRUM")&&e.dataClass&&!e.dataClass.toUpperCase().includes("PEAK")}function yt(e){return e.dataType?.toUpperCase().includes("FID")}function bt(e,r={}){let{logger:t,name:i=""}=r;for(let n of e){if(n.dataType==="LINK"&&bt(n.children,r))return!0;let{dataType:o=""}=n,s=o.toLowerCase();if(s.length>0){if(s.includes("spectrum")&&!s.includes("nmr"))return t?.warn(`File ${i} was ignored because it is a ${o}`),!1;if(s.includes("nmr"))return!0}}return!1}var Le=require("@zakodium/nmrium-core"),Mt=require("jcampconverter"),an=Se(require("openchemlib"),1);var Ft=require("nmr-processing"),Pt=require("openchemlib");async function Nt(e,r={}){let t=await e.text(),i=q(t),n={molecules:i,spectra:[]};return i.length===0&&r.logger?.debug(`${e.name} is an empty molfile`),n}function q(e){let r=[];if(!(0,Ft.isMolfileNotEmpty)(e))return[];let i=Pt.Molecule.fromMolfile(e).toMolfile();return r.push({molfile:i}),r}var Dt=require("nmr-processing"),sn=Se(require("openchemlib"),1),St=require("openchemlib-utils");var on=new Set(["ndnmrspectrum","ndnmrfid","nmrspectrum","nmrfid"]);function pe(e){let{dataType:r="",dataClass:t=""}=e,i=r.replaceAll(/\s/g,"").toLowerCase(),n=t.replaceAll(/\s/g,"").toLowerCase();return on.has(i)&&n!=="peaktable"}function Rt(e,r,t={}){let{spectra:i,info:n,meta:o}=e,s=i[0].data,l=[],a={x:"delta",y:"intensity",w:"width",m:"multiplicity",a:"atom"},{logger:m,name:u,spectraData:c}=t,{CROSSREFERENCE:g}=n,y=typeof g!="string"?g:g.split(/\r?\n/).map(D=>D.trim()).filter(Boolean),d=y.find(D=>D?.toLowerCase().includes("structure"));if(d===void 0)return m&&m.warn(`There is not a structure reference for ${u} file, assignment object could not be completed`),null;let p=Number.parseInt(d?.toLowerCase().replace(/_/,"").replace(/structure:\s*blockid\s*=\s*(?<blockId>.*)/,"$<blockId>"),10);if(Number.isNaN(p)||p<1)return m&&m.warn(`Structure block_id not found for ${u} file, assignment object could not be completed`),null;let F=c?.molecules?.find(D=>D.blockId===p)?.molfile??"";if(F===""){let D=r.find(A=>A.info.BLOCKID===p),{MOLFILE:R=""}=D?.meta||{};F=R}if(!(0,Dt.isMolfileNotEmpty)(F))return m&&m.warn(`Empty molfile for ${u} file with structure block_id = ${p}, assignment object could not be completed`),null;let h=(0,St.getDiastereotopicAtomIDsFromMolfile)(sn,F),b=oe({...n,...o},{},"");for(let D=0;D<s.x.length;D++){let R={};for(let A in s){let x=s[A][D];typeof x=="string"&&x.startsWith("<")&&x.endsWith(">")&&(x=x.slice(1,-1)),R[a[A]]=x}if("atom"in R){let A=h.map[R.atom-1];b.includes("1H")?A.nbHydrogens>0?(R.diaIDs=A.hydrogenOCLIDs,R.nbHydrogens=A.nbHydrogens):(R.diaIDs=[A.oclID],R.nbHydrogens=A.nbHydrogens):(R.diaIDs=[A.oclID],R.nbHydrogens=1)}l.push(R)}let N={};for(let D of l){let{delta:R,diaIDs:A}=D,x=`${R}_${A.join("_")}`;if(N[x])N[x].atoms.push(D.atom);else{let{atom:_n,...Ir}=D;N[x]={...Ir,atoms:[D.atom]}}}let S=[];for(let D of y)D.toLowerCase().includes("spectrum")&&S.push(Number(D.toLowerCase().replace(/_/,"").replace(/.*:\s*blockid=(?<blockId>.*)/,"$<blockId>")));if(S.length===0){for(let D of r)if(pe(D)){let{BLOCKID:R}=D.info;S.push(Number(R))}S.length>1&&(S=[],m&&m.warn(`There is not a spectral cross-reference for the peak assignment in the ${u} file`))}return{moleculeBlockID:p,spectraBlockIDs:S,assignments:Object.values(N),molecule:h.molecule}}function At(e,r,t,i){for(let n of e){let{meta:o,dataClass:s="",dataType:l="",info:a}=n,m=Number.parseInt(String(a.BLOCKID),10);o.MOLFILE?un(String(o.MOLFILE),r,m):n.jcampCS&&ln(n,r,m),cn(s,l)&&mn(r,n,e,i),pe(n)&&t.push(n)}}function cn(e,r){return e?.toLowerCase().includes("assignments")&&r?.toLowerCase().includes("assignments")}function mn(e,r,t,i){let n=Rt(r,t,{spectraData:e,logger:i.logger,name:i.name});if(e.assignmentsByBlocks||(e.assignmentsByBlocks={}),n){let{spectraBlockIDs:o}=n;for(let s of o)e.assignmentsByBlocks[s]=n}}function ln(e,r,t){r.molecules||(r.molecules=[]);let i=(0,Mt.parseJcampCS)(e,{OCL:an}),n=q(i?.molfile||"");n.length>0&&r.molecules.push({id:(0,Le.generateID)(),blockId:t,...n[0]})}function un(e,r,t){r.molecules||(r.molecules=[]);let i=q(String(e));r.molecules.push({id:(0,Le.generateID)(),blockId:t,...i[0]})}var ve=require("@zakodium/nmrium-core"),W=require("ml-spectra-processing"),Bt=require("nmr-processing");function $(e){return e.slice(0,Math.max(0,e.lastIndexOf(".")))}function j(e){e.sort((r,t)=>r.from-t.from);for(let r=0;r<e.length-1;r++)e[r].to>e[r+1].from&&(e[r].to=Math.max(e[r+1].to,e[r].to),e[r].signals=e[r].signals.concat(e[r+1].signals),e[r].integration+=e[r+1].integration,e.splice(r+1,1),r--);return e}var It=require("nmr-processing");var Ct=require("ml-spectra-processing");function U(e){return e.trim().slice(1,-1).split(/,\s*/).map(r=>r.trim())}var pn={I:"id",X:"from",Y:"to",Hs:"delta",An:"integration",H:"nbAtoms",C:"multiplicity",N:"assignment","(J)":"js"},xt=["I","X","Y","Hs","An","H","C","N","(J)"];function Ot(e){let r={headersFromParenthesis:[],headersFromComments:[],comments:[],data:[],multiplets:[]},t=e.split(/\r?\n/).filter(i=>i.trim()!=="");if(t.length===0)return r;if(t[0].startsWith("(")&&!t[0].match(/\d/)){let i=t.shift();r.headersFromParenthesis=U(i)}return r.comments=t.filter(i=>i.startsWith("$$")).map(i=>i.replace(/^\$\$\s*/,"")),r.headersFromComments=dn(r.comments),r.data=t.filter(i=>!i.startsWith("$$")).map(U),r.multiplets=fn(r),r}function fn(e,r={}){let{logger:t}=r,i=e.data[0].map((a,m)=>m).filter(a=>e.data.every(m=>Number.isNaN(m[a])||Number.isNaN(Number(m[a]))));if(t?.trace(`Parsing JCAMP-DX assignment: stringColumnIndexes: ${i.join(",")}`),i.length===0)return t?.warn("Parsing JCAMP-DX assignment: No string columns found. Skipping parsing of assignment."),[];let n=i[0],o;if(e.headersFromParenthesis.length>0&&e.headersFromParenthesis[n]==="C")o=e.headersFromParenthesis;else if(e.headersFromComments.length>0&&e.headersFromComments[n]==="C")o=e.headersFromComments;else if(xt[n]==="C")o=xt;else return t?.warn("No header found for multiplicity. Skipping parsing of assignment."),[];return(0,Ct.xMaxValue)(e.data.map(a=>a.length))>o.length&&t?.warn("Some assignments are containing more values than headers"),e.data.map(a=>{let m={};for(let u=0;u<o.length;u++){let c=o[u];m[pn[c]||c]=a[u]}return m})}function dn(e){return e.map(r=>r.split(":")[0].trim()).filter(r=>r.length>0)}function Tt(e,r={}){let{logger:t}=r,i=Ot(e),n={multiplets:[],comments:i.comments};for(let o of i.multiplets){let{id:s,from:l,to:a,delta:m,integration:u,nbAtoms:c,multiplicity:g}=o,y={id:s,js:[],multiplicity:"",...gn({from:l,to:a,delta:m,integration:u,nbAtoms:c})};if(typeof o.js=="string"){let d=o.js.split(/\s+/).map(Number.parseFloat),p=0,f=(0,It.splitPatterns)(g).map(b=>{let N=(b?.multiplicity||1)-1;return p+=N,{value:b.value,multiplicity:b?.multiplicity,js:d.slice(p-N,p)}}),F=f.reduce((b,N)=>b+(N.multiplicity?N.multiplicity-1:0),0);d.length!==F&&t?.warn(`The number of j values (${d.length}) is not equal to the sum of the multiplicities - 1 (${F})`);let h=[];for(let b of f){if(b.js.every(N=>N===b.js[0])){h.push(b);continue}if(b.multiplicity!==b.js.length+1){h.push(b);continue}for(let N=0;N<b.multiplicity-1;N++)h.push({value:"d",multiplicity:2,js:[b.js[N]]})}h.sort((b,N)=>N.js[0]-b.js[0]),y.js=h.map(b=>({coupling:b.js[0],multiplicity:b.value}))}typeof o.assignment=="string"&&(y.assignment=hn(o.assignment)),typeof o.multiplicity=="string"&&(y.multiplicity=o.multiplicity),n.multiplets.push(y)}return n}function gn(e){let r={};for(let t in e){let i=e[t],n=typeof i=="number"?i:Number.parseFloat(i);Number.isNaN(n)||(r[t]=n)}return r}var yn={quot:'"',apos:"'",comma:",",amp:"&",lpar:"(",rpar:")",lt:"<",gt:">",colon:":",semi:";"};function hn(e){return e.replaceAll(/&(\w+);/gi,(r,t)=>yn[t.toLowerCase()]||r)}function Et(e){let r=e.split(/\r?\n/).filter(i=>i.trim()!==""),t=[];for(let i of r)if(i.startsWith("(")){let[n,o,s]=U(i).map(Number.parseFloat);t.push({id:n,x:o,y:s})}return t}function Lt(e,r={}){let t={};if(!e["OBSERVED MULTIPLETS"])return[];let i=Tt(e["OBSERVED MULTIPLETS"],r);if(!i)return[];let{multiplets:n}=i;for(let o of n){let{id:s,from:l,to:a,integration:m=0,...u}=o;t[s]={from:l,to:a,integration:m,signals:[{id:s,...u}]}}if(e["OBSERVED MULTIPLETS PEAKS"]){let o=Et(e["OBSERVED MULTIPLETS PEAKS"]),s={};for(let l of o){let{id:a,x:m,y:u}=l;s[a]||(s[a]=[]),s[a].push({x:m,y:u,width:.05})}for(let l in t)s[l]&&(t[l].signals[0].peaks=s[l])}return j(Object.values(t))}function kt(e,r){let i=[...e.getMolecularFormula().formula.matchAll(/(?<element>[A-Z][a-z]?)(?<count>\d*)/g)].map(o=>({element:o?.groups?.element,count:o?.groups?.count?Number(o.groups.count):1})),n=[...r.nucleus[0].matchAll(/[0-9]*(?<element>[A-Z][a-z]?)/g,"$element")][0].groups.element;return i.find(o=>o.element===n)?.count||100}function wt(e){let r={};return".PHASE0"in e&&(r.ph0=Number.parseFloat(e[".PHASE0"]),r.ph1=Number.parseFloat(e[".PHASE1"])),r}function ke(e){let{ph0:r,ph1:t}=e;return Number.isFinite(r)&&Number.isFinite(t)}var we=require("@zakodium/nmrium-core");function vt(e,r,t){for(let i=0;i<e.length;i++){if(r.includes(i))continue;let{delta:n,multiplicity:o="",diaIDs:s}=e[i],l=Number(n)-.01,a=Number(n)+.01;t.push({from:l,to:a,integration:1,id:(0,we.generateID)(),signals:[{id:(0,we.generateID)(),delta:n,multiplicity:o,diaIDs:s}]})}}var qt=require("linear-sum-assignment"),$t=require("ml-spectra-processing");function jt(e,r){let t=e.map(s=>s.delta),i=r.map(s=>s.delta),n=(0,$t.xCostMatrix)(i,t,{fct:(s,l)=>Math.abs(s-l)}),{rowAssignments:o}=(0,qt.linearSumAssignment)(n,{maximaze:!1});return Array.from(o)}function zt(e,r){let{assignments:t,ranges:i}=r;t?.sort((s,l)=>l.delta-s.delta);let n=[],o=[];for(let s of i){let l=0,{from:a,to:m}=s,u=[];for(let c=l;c<t.length;c++){let{delta:g}=t[c];g<=m&&g>=a?(u.push(t[c]),o.push(c)):g>m&&(l=c)}if(u.length>0){let c=s.signals,g=[],y=u.length>1&&c.length>1?jt(c,u):[0];for(let d=0;d<u.length;d++){let p=y[d],{delta:f,multiplicity:F,diaIDs:h}=u[d];p>-1?g.push({...c[p],diaIDs:h}):g.push({delta:f,multiplicity:F,diaIDs:h})}s.signals=g,n.push(s)}}vt(t,o,n),n.sort((s,l)=>s.from-l.from),e.ranges={values:j(n).map(s=>{let{integration:l,...a}=s;return a}),options:{sum:r.integrationSum,isSumConstant:!0,sumAuto:!0}},e.ranges.options.moleculeId=String(r.moleculeId)}function Ut(e,r,t,i,n){let{logger:o}=n,s={components:Wt(e)?Pn(e,t.isFid):Fn(e)},{name:l=t.title||`jcamp_${(0,ve.generateID)()}`}=n,a={dependentVariables:[s],meta:r,info:{...t,name:$(l)}};return bn(e)&&Nn(a,i,r,e,t,{logger:o}),a}function Wt(e){return"minMax"in e}function bn(e){return!Wt(e)}function Fn(e){return e.spectra.map(r=>{let t=I(r.data);return{...r,data:t}})}function Pn(e,r){let t={...e.minMax,z:I(e.minMax?.z)};return r?Dn(t):{rr:t}}function Nn(e,r,t,i,n,o){let{assignmentsByBlocks:s}=r,l=wt(t);ke(l)&&Sn(e,l);let a=String(i.info.BLOCKID);if(s?.[a]){let{molecule:m,assignments:u,moleculeBlockID:c}=s[a],g=kt(m,n),y=I(i.spectra[0].data);if(y.x[0]>y.x[1])for(let F of i.spectra)F.data.x.reverse(),F.data.y.reverse();if(ke(l)&&i.spectra.length>1){let{re:F}=Rn(i,l);y.y=F}let{x:d,y:p}=y,f=Lt(t,o)??(0,Bt.xyAutoRangesPicking)({x:d,y:p},{peakPicking:{frequency:n.originFrequency},ranges:{frequency:n.originFrequency,integrationSum:g}});zt(e,{moleculeId:c,ranges:f,assignments:u,integrationSum:g})}}function Dn(e){let{z:r,...t}=e,i=[],n=[];for(let l=0;l<r.length;l+=2)i.push(r[l].slice()),n.push(r[l+1].slice());let o=(0,W.matrixMinMaxZ)(i),s=(0,W.matrixMinMaxZ)(n);return{re:{...t,z:i,minZ:o.min,maxZ:o.max},im:{...t,z:n,minZ:s.min,maxZ:s.max}}}function Sn(e,r){let{ph0:t,ph1:i}=r;e.filters||(e.filters=[]),e.filters.push({id:(0,ve.generateID)(),name:"phaseCorrection",value:{ph0:t,ph1:i,absolute:!1},enabled:!0})}function Rn(e,r){let{ph0:t,ph1:i}=r,{re:n,im:o}=(0,W.reimPhaseCorrection)({re:e.spectra[0].data.y,im:e.spectra[1].data.y},t*Math.PI/180,i*Math.PI/180);return{re:n,im:o}}function Xt(e,r,t){let{logger:i}=t,n=[];for(let o of e)if(o.spectra&&o.spectra.length>0||o.minMax){Mn(o);let s={...o.info,...o.meta},l=ce(s,{logger:i});if(l.experiment==="wobble_curve")continue;n.push(Ut(o,s,l,r,t))}return n}function Mn(e){let r=e.meta["BRUKER FILE EXP"];if(!r)return;let i=(Array.isArray(r)?r:[r]).find(o=>o.slice(0,10).includes("vdlist"));if(!i)return;let n=i.split(`
|
|
6
|
-
`).slice(1);e.info.vdlistValues=re(n)}async function fe(e,r={}){let t=await e.text(),i=qe(t,{name:e.name,...r});return ft(i,e,r)}function qe(e,r={}){let t={spectra:[],molecules:[]},{name:i,converter:n={},selector:o={},logger:s}=r,{keepRecordsRegExp:l=/.*/}=n,a={keepSpectra:!0,noContour:!0,noTrimRegExp:/\$MOLFILE/,keepRecordsRegExp:l,logger:s},m=ht((0,_t.createTree)(e),{name:i,...o,logger:s});for(let u of m)An(u,t,a,i);if(xn(t,o),t.spectra.length===0&&m.length>0){let u=t.molecules.length===0?" nor molecule":"";s?.warn(`No spectra${u} data was loaded from file ${i}`)}return(0,Jt.formatSpectra)(t)}function An(e,r,t,i){let n=[],o=[],s={molecules:[]},{logger:l}=t,a={name:i,logger:l};Te(e,o,t),At(o,s,n,a),r.spectra.push(...Xt(n,s,a)),r.molecules.push(...s.molecules)}function xn(e,r){r.index!==void 0&&(e.spectra=e.spectra.slice(r.index,r.index+1))}var X=class{id="@zakodium/nmrium-core-plugins#JCAMPDXLoaderPlugin";version=1;migrations=[];onReadProcess;constructor(){this.onReadProcess={supportedExtensions:["jcamp","jdx","dx"],onFile:this.onReadProcessFile.bind(this)}}onReadProcessFile(r,t={}){let{sourceSelector:i={},converter:n,keepSource:o,logger:s}=t;return s?.debug(`Reading JCAMP-DX file: ${r.name}`),fe(r,{selector:this.getJCAMPDXSelector(i),converter:n?.jcamp,keepSource:o,logger:s})}getJCAMPDXSelector(r={}){let{jcamp:t={},general:i={}}=r,{dataSelection:n="both"}=i;return{...t,dataSelection:n}}};function de(){return new X}var ge=require("@zakodium/nmrium-core"),Kt=require("gyromagnetic-ratio"),Zt=require("is-any-array"),Qt=require("jeolconverter"),er=Se(require("lodash.merge"),1),tr=require("nmr-processing");var L=require("is-any-array");var Vt={0:"uint8",1:"uint16",2:"uint32",3:"uint64",4:"int8",5:"int16",6:"int32",7:"int64",8:"float32",9:"float64",10:"complex64",11:"complex128"},Ht={0:"scalar",1:"vector",2:"matrix",3:"symetricMatrix",4:"pixel"};function Yt(e,r,t={}){let{quantityType:i=0,encoding:n="none",name:o="",unit:s="",quantityName:l="",sparseSampling:a={},from:m=[0],to:u=[-1]}=t;if((0,L.isAnyArray)(e))throw new Error("JEOL with an array of data is not yet supported");if(!("re"in e&&"im"in e))throw new Error("Only re/im data is supported");let c=je(e,m,u),{componentLabels:g=c.componentLabels}=t;return{type:"internal",quantityType:Ht[i],numericType:Vt[r],encoding:n,name:o,unit:s,quantityName:l,componentLabels:g,sparseSampling:a,description:t.description||"",application:t.application||"",components:c.components,dataLength:c.dataLength}}function Cn(e){return(0,L.isAnyArray)(e.re)&&(0,L.isAnyArray)(e.im)}function On(e){return!(0,L.isAnyArray)(e.re[0])}function je(e,r,t){let i=[],n=[],o=[];if(Cn(e))if(On(e)){i[0]=$e(r[0],t[0],e.re.length);let s=new Float64Array(i[0]);for(let l=0;l<i[0];l+=2){let a=l+r[0]*2;s[l]=e.re[a/2],s[l+1]=e.im[a/2]}o.push(s),n.push("complex")}else if((0,L.isAnyArray)(e.re[0])){i[0]=In(r[1],t[1],e.re.length),i[1]=$e(r[0],t[0],e.re[0].length);for(let s=0;s<i[0];s++){let l=new Float64Array(i[1]);for(let a=0;a<i[1];a+=2){let m=a+r[0]*2;l[a]=e.re[s][m/2],l[a+1]=e.im[s][m/2]}o.push(l)}}else throw new Error("check your object");else if((0,L.isAnyArray)(e.re.re)){i[0]=$e(r[1],t[1],e.re.re.length);let s=je(e.re,r,t).components,l=je(e.im,r,t).components;for(let a=0;a<i[0]/2;a++)o.push(s[a],l[a])}else throw new Error("check the dimension or the type of data in your array");return{dataLength:i,componentLabels:n,components:o}}function In(e,r,t){return r-e+1<t?r-e+1:t}function $e(e,r,t){return r-e+1<t?(r-e+1)*2:t*2}async function rr(e,r={}){let t=await e.arrayBuffer(),{name:i=$(e.name),keepSource:n=!1}=r,o={spectra:[],molecules:[]},l=Ln(t)[0],{metadata:a,...m}=l.description,u=0,c=m.dimension===1?"1d":"2d",g="NMR SPECTRUM",y=m.dimension===1?m.nucleus[0]:m.nucleus,d=m.spectralWidthClipped[0],p;l.dependentVariables&&(m.dimension===1?p=Tn(l):m.dimension===2&&(p=En(l)));for(let F in m)Array.isArray(m[F])&&m[F].length===1&&(m[F]=m[F][0]);let f={data:p,info:{...m,acquisitionMode:u,experiment:c,type:g,nucleus:y,spectralWidthClipped:d,name:i},meta:a};return n&&(f.sourceSelector={files:[e.relativePath]}),o.spectra=[f],(0,ge.formatSpectra)(o)}function Tn(e){let r=e.dimensions[0],t=e.dependentVariables,i=r.quantityName,n=r.count,o=r.increment.magnitude,s=r.originOffset.magnitude,l=r.coordinatesOffset.magnitude,a=t[0].components[0],m=new Float64Array(n),u=new Float64Array(n);for(let p=a.length-1,f=0;p>0;p-=2)m[f]=a[p-1],u[f++]=a[p];let c={},[g,y]=[0,0];switch(i){case"frequency":y=0+l/s*1e6,g=o/s*1e6,c.re=m,c.im=u;break;case"time":y=s,g=o,c.re=m.reverse(),c.im=u.reverse().map(p=>-p);break;default:break}let d=[];for(let p=0;p<n;p++)d.push(y+p*g);return c.x=d,c}function En(e){let r=e.dimensions,t=e.dependentVariables,i=r[0].quantityName,n=[],o=[],s=Number.MIN_SAFE_INTEGER,l=Number.MAX_SAFE_INTEGER,a=Number.MAX_SAFE_INTEGER,m=Number.MIN_SAFE_INTEGER;for(let g of t[0].components){let y=new Float64Array(g.length/2),d=new Float64Array(g.length/2);for(let p=g.length-1,f=0;p>0;p-=2){let F=g[p-1],h=g[p];F>s&&(s=F),F<l&&(l=F),h>m&&(m=h),h<a&&(a=h),y[f]=F,d[f++]=h}if(i==="frequency")n.push(y),o.push(d);else{let p=y.length,f=new Float64Array(d.length);for(let F=0,h=p-1;F<p;F++)f[F]=-d[h--];n.push(y.reverse()),o.push(f)}}let u={re:{z:n,minZ:l,maxZ:s},im:{z:o,minZ:a,maxZ:m}},c=["X","Y"];for(let g=0;g<c.length;g++){let y=r[g].count,d=r[g].increment.magnitude,p=r[g].originOffset.magnitude,f=r[g].coordinatesOffset.magnitude,F=c[g];for(let h of["re","im"])i==="frequency"?(u[h][`min${F}`]=0+f/p*1e6,u[h][`max${F}`]=y*(d/p)*1e6):(u[h][`min${F}`]=p,u[h][`max${F}`]=y*d)}return u}function Ln(e){let r=(0,Qt.parseJEOL)(e),t=r.info,i=r.headers,n=r.parameters,{dimension:o}=t,s={};for(let f of n.paramArray){let{name:F,value:h}=f;s[F]=nr(h,o)}delete n.paramArray;let l=r.data,a={};a.title=`title: ${i.title} / comment: ${i.comment} / author:${i.author} / site: ${i.site}`,a.nucleus=t.nucleus.map(tr.normalizeNucleus),a.sampleName=t.sampleName,a.date=t.date,a.epoch=t.epoch,a.localeDate=new Date((0,ge.getOneIfArray)(t.epoch)).toLocaleString(),a.author=t.author,a.solvent=t.solvent,a.temperature=t.temperature.magnitude,a.probeName=t.probeName||"",a.fieldStrength=t.fieldStrength.magnitude;let m=a.nucleus.map(Kt.getGyromagneticRatio);a.baseFrequency=m.map(f=>t.fieldStrength.magnitude*f/(2*Math.PI*1e6)),a.pulseSequence=t.experiment,a.temperature=t.temperature?.unit?.toLowerCase()==="celsius"?273.15+t.temperature.magnitude:t.temperature.magnitude,a.digitalFilter=t.digitalFilter,a.pulseStrength90=1/(4*t.pulseStrength90.magnitude),a.numberOfScans=t.numberOfScans,a.relaxationTime=t.relaxationTime.magnitude,a.isComplex=t.dataSections.includes("im"),a.isFid=t.dataUnits[0]==="Second",a.isFt=t.dataUnits[0]==="Ppm",a.dimension=t.dimension,a.originFrequency=t.originFrequency.map(f=>f.magnitude/1e6).slice(0,o),a.numberOfPoints=t.dataPoints.slice(0,1),a.frequencyOffset=t.frequencyOffset.map((f,F)=>f.magnitude*a.baseFrequency[F]).slice(0,o),a.acquisitionTime=t.acquisitionTime.map(f=>f.magnitude).slice(0,o),a.spectralWidth=t.spectralWidth.map((f,F)=>f.magnitude/t.originFrequency[F].magnitude*1e6).slice(0,o),a.spectralWidthClipped=t.spectralWidthClipped.map((f,F)=>f.magnitude/a.baseFrequency[F]*1e6).slice(0,o);let u=[],c={},g;for(let f=0;f<t.dimension;f++){if(g={magnitude:t.acquisitionTime[f].magnitude/(t.dataPoints[f]-1),unit:"s"},t.dataUnits[f]==="Second")c.quantityName="time",c.originOffset={magnitude:0,unit:"s"},f===0?c.coordinatesOffset={magnitude:t.digitalFilter*g.magnitude,unit:"s"}:c.coordinatesOffset={magnitude:0,unit:"s"},c.reciprocal={originOffset:{magnitude:t.originFrequency[f].magnitude,unit:"Hz"},quantityName:"frequency",coordinatesOffset:{magnitude:t.frequencyOffset[f].magnitude*t.originFrequency[f].magnitude/1e6,unit:"Hz"}};else if(t.dataUnits[f]==="Ppm"){c.quantityName="frequency";let F=t.originFrequency[f].magnitude;c.originOffset={magnitude:F,unit:"Hz"};let h=t.dataOffsetStart[f],N=t.dataOffsetStop[f]-h+1;g={magnitude:kn(t,f)/(N-1),unit:"Hz"};let R=t.dataAxisStop[f]*F/1e6;c.coordinatesOffset={magnitude:R,unit:"Hz"},N!==t.dataPoints[f]&&(t.dataPoints[f]=N)}f===0?c.description="direct dimension":c.description="indirect dimension",u.push({label:String(i.dataAxisTitles[f]),count:Number(t.dataPoints[f]),increment:g,type:"linear",description:String(c.description)||"",application:c.application||{},coordinatesOffset:c.coordinatesOffset||0,originOffset:c.originOffset||0,quantityName:String(c.quantityName)||"",reciprocal:c.reciprocal||{},period:c.period||0,complexFFT:c.complexFFT||!1})}let y=[];y.push(Yt(l,11,{unit:"none",quantityName:"relative intensity",from:t.dataOffsetStart,to:t.dataOffsetStop}));let d={...a};return delete d.paramList,d.metadata={...Gt(i,o),...Gt(n,o),...(0,er.default)({},s)},[{timeStamp:Date.now(),description:d,dimensions:u,dependentVariables:y}]}function kn(e,r){let{spectralWidth:t,spectralWidthClipped:i}=e;return i[r].magnitude!=="NA"?i[r].magnitude:t[r].magnitude}function Gt(e,r){let t={};for(let i in e)t[i]=nr(e[i],r);return t}function nr(e,r){return(0,Zt.isAnyArray)(e)?r>1?e.slice(0,r):e[0]:e}var J=class{id="@zakodium/nmrium-core-plugins#JEOLLoaderPlugin";version=1;migrations=[];onReadProcess;constructor(){this.onReadProcess={supportedExtensions:["jdf"],onFile:this.onReadProcessFile.bind(this)}}onReadProcessFile(r,t={}){let{logger:i,keepSource:n}=t;return i?.debug(`Reading JEOL file: ${r.name}`),rr(r,{name:r.name,keepSource:n,logger:i})}};function ye(){return new J}var _=class{id="@zakodium/nmrium-core-plugins#MolfileLoaderPlugin";version=1;migrations=[];onReadProcess;constructor(){this.onReadProcess={supportedExtensions:["mol"],onFile:this.onReadProcessFile.bind(this)}}onReadProcessFile(r,t={}){let{logger:i}=t;return i?.debug(`Reading molfile file: ${r.name}`),Nt(r,{logger:i})}};function he(){return new _}var be=require("nmredata");var Be=require("@zakodium/nmrium-core");var ze=require("@zakodium/nmrium-core"),ir=require("ml-spectra-processing");function or(e,r){let{x:t,re:i}=r.data;return e.map(n=>{let o=(0,ir.xyIntegration)({x:t,y:i},{from:n.from,to:n.to}),s=[];for(let l of n.signals||[]){let{kind:a=null,id:m,js:u=[],diaIDs:c=[],...g}=l;s.push({...g,kind:a||"signal",js:u,id:m||(0,ze.generateID)(),diaIDs:c})}return{...n,id:n.id||(0,ze.generateID)(),kind:s?.[0].kind||"signal",absolute:o,signals:s}})}function sr(e,r){let t=[],{baseFrequency:i=500}=r.info;for(let n of e){let{delta:o,diaIDs:s=[],multiplicity:l="",integration:a=0}=n,m=n.jCoupling||[],u=wn({delta:o,js:m,frequency:i});if(m&&l&&m.length===l.length){m.sort((c,g)=>g.coupling-c.coupling);for(let c=0;c<m.length;c++)m[c].multiplicity=l[c]}t.push({id:(0,Be.generateID)(),...u,integration:a,signals:[{id:(0,Be.generateID)(),js:m,delta:o,diaIDs:s,multiplicity:l}]})}r.ranges.values=or(j(t),r)}function wn(e){let{delta:r,js:t=[],frequency:i}=e,n=.5;for(let o of t)n+=o.coupling;return n/=i,{from:r-n,to:r+n}}var Ue=require("@zakodium/nmrium-core"),vn=["x","y"],qn={x:0,y:0};function ar(e,r,t={}){let i=[],{shift:n=qn}=t,{originFrequency:o=[400,400]}=r.info,s={x:o[0],y:o[1]};for(let l of e){let a={x:{},y:{},id:(0,Ue.generateID)(),kind:"signal"},m={id:(0,Ue.generateID)(),kind:"signal",peaks:[]},u={x:10,y:10};for(let c of vn){let{coupling:g=[],delta:y,diaIDs:d=[]}=l[c];for(let p of g)u[c]+=p.coupling;if(l.activeCoupling){let{activeCoupling:p=[]}=l;for(let f of p)u[c]+=f.coupling}u[c]/=s[c],a[c]={from:y-u[c],to:y+u[c]},m[c]={delta:y,diaIDs:d,originalDelta:y-n[c]}}i.push({...a,signals:[m]})}r.zones.values=i}function cr(e){return $n(e.data)}function $n(e){return"rr"in e||!("x"in e)&&"re"in e}async function mr(e,r,t={}){let i={spectra:[],molecules:[]},n=await jn(e,r,t);if(n.spectra.length>0){let{spectra:o,molecules:s,usedFiles:l}=n;i.spectra.push(...o),i.molecules.push(...s);let a=e.files.length;for(let m=a-1;m>=0;m--){let u=e.files[m].relativePath;!u.match(/acqu.*/s)&&l.includes(u)&&e.files.splice(m,1)}}return i}async function jn(e,r,t){let i=[],n=await(0,be.getSDF)(e),o={spectra:[],molecules:[]};if(n.length===0)return{...o,usedFiles:i};let s=[];for(let a of n){let m=(0,be.nmrRecordToJSON)({sdf:a,fileCollection:e}).then(u=>{let{spectra:c,molecules:g=[]}=u;return i.push(a.root+a.filename),o.molecules.push(...g),zn(c,r,t)});s.push(m)}let l=await Promise.allSettled(s);for(let a of l)a.status==="fulfilled"?(o.spectra.push(...a.value.spectra),i.push(...a.value.usedFiles)):a.reason&&t?.logger?.error(a.reason);return{...o,usedFiles:i}}async function zn(e,r,t){let i=[],n=[],o={spectra:[],molecules:[]};for(let s of e){let l=Bn(s.source,r,t).then(a=>{let{spectra:m,files:u}=a;i.push(...u);for(let c of m)cr(c)?ar(s.signals,c):sr(s.signals,c);o.spectra.push(...m)});n.push(l)}return await Promise.allSettled(n),{...o,usedFiles:i}}async function Bn(e,r,t={}){let{file:i,jcampURL:n}=e,{converter:o}=t;if(n){let a=await Un(n,r,o?.jcamp);if(a)return{...a,files:[]}}let s=[];for(let a of i||[])s.push(Wn(a,t).then(m=>({...m,files:a.fileCollection.files.map(u=>u.relativePath)})));let l=await Promise.allSettled(s);for(let a of l){if(a.status==="fulfilled")return a.value;a.reason&&t?.logger?.error(a.reason)}return{spectra:[],molecules:[],files:[]}}async function Un(e,r,t={}){let i={entries:[{relativePath:e}]},n={name:$(e||""),xy:!0,noContours:!0,...t},{data:o}=await r.readFromWebSource(i,n);return o}async function Wn(e,r={}){let{converter:t,sourceSelector:i}=r;switch(e.type){case"jcamp":return fe(e.fileCollection.files[0],{name:e?.fileCollection.files[0].name||"",converter:t?.jcamp,selector:i?.jcamp,logger:r.logger,keepSource:r.keepSource});case"brukerFiles":return le(e.fileCollection,{converter:t?.bruker,selector:i});default:throw new Error("There is not a supported source")}}var V=class{constructor(r){this.core=r;this.onReadProcess={onFiles:this.onReadProcessFiles}}id="@zakodium/nmrium-core-plugins#NMReDATALoaderPlugin";version=1;migrations=[];onReadProcess;onReadProcessFiles=(r,t)=>mr(r,this.core,t)};function Fe(e){return new V(e)}var lr=require("sdf-parser");function We(e,r={}){let{mixedEOL:t}=r,{molecules:i}=(0,lr.parse)(e,{mixedEOL:t}),n=[];for(let{molfile:o}of i){let s=q(o);n.push(...s)}return n}async function ur(e,r={}){let{logger:t,mixedEOL:i}=r,n=await e.text(),o=We(n,{mixedEOL:i}),s={molecules:o,spectra:[]};return t&&t[o.length>0?"info":"debug"](`Loaded ${s.molecules.length} molecules from the ${e.name} file`),s}var H=class{id="@zakodium/nmrium-core-plugins#SDFLoaderPlugin";version=1;migrations=[];onReadProcess;constructor(){this.onReadProcess={supportedExtensions:["sdf"],onFile:this.onReadProcessFile.bind(this)}}onReadProcessFile(r,t={}){let{logger:i}=t;return i?.debug(`Reading sdf file: ${r.name}`),ur(r,{logger:i})}};function Pe(){return new H}var pr=require("openchemlib");function Xe(e){let r=[],t=e.split(/\r?\n/).filter(Boolean);for(let i of t){let o=pr.Molecule.fromSmiles(i).toMolfile();r.push({molfile:o})}return r}async function fr(e,r={}){let t=await e.text(),i=Xe(t),n={molecules:i,spectra:[]};return r.logger?.info(`Found ${i.length} molecules from the ${e.name} file`),n}var Y=class{id="@zakodium/nmrium-core-plugins#SMILESLoaderPlugin";version=1;migrations=[];onReadProcess;constructor(){this.onReadProcess={supportedExtensions:["smi","smiles"],onFile:this.onReadProcessFile.bind(this)}}onReadProcessFile(r,t={}){let{logger:i}=t;return fr(r,{logger:i})}};function Ne(){return new Y}var br=require("@zakodium/nmrium-core"),Fr=require("filelist-utils"),Pr=require("is-any-array"),Nr=require("ml-spectra-processing"),Dr=require("varian-converter");var dr=require("nmr-processing");function gr(e,r){let{meta:t,procpar:i}=e,n={};for(let h of i)n[h.name]=h.values;let o={},s={},{np:l,solvent:a,sfrq:m,reffrq:u,temp:c,rp:g,sw:y,rfl:d,rfp:p}=n;P(o,"numberOfPoints",l&&Number(O(l))/2),P(o,"solvent",O(a)),P(o,"originFrequency",O(m)),P(o,"baseFrequency",O(u)),(Number.isNaN(o.originFrequency)||o.originFrequency===0)&&(o.originFrequency=400,r?.warn("The frequency could not be determined and was set to 400MHz")),P(o,"temperature",O(c)),P(o,"phc0",g&&Number(g[0])),P(s,"rfl",d&&Number(O(d))),P(s,"rfp",p&&Number(O(p))),P(s,"sw",y&&Number(O(y)));for(let h in s){let b=s[h];Array.isArray(b)&&b.length===1&&(s[h]=b[0])}if(!("baseFrequency"in o)&&"originFrequency"in o){let h=Number.parseFloat(o.originFrequency);if(["sw","rfl","rfp"].every(b=>b in s)){let{sw:b=1,rfl:N=1,rfp:S=1}=Xn(s,["sw","rfl","rfp"]);P(o,"baseFrequency",h-(b/2-N+S)/1e6)}else P(o,"baseFrequency",h)}let{baseFrequency:f,originFrequency:F}=o;P(o,"frequencyOffset",(F-f)*1e6),P(o,"spectralWidth",y&&Number(y[0])/o.baseFrequency);for(let h in o)o[h].length===1&&(o[h]=o[h][0]);return n.tn&&(o.nucleus=n.tn.map(dr.normalizeNucleus)),o.dimension=1,o.isFid=!t.status.isSpectrum,{info:o,meta:{...s,...yr(t),...n}}}function O(e){return e&&(Array.isArray(e)?e[0]:e)}function Xn(e,r){let t={};for(let i of r){let n=e[i];n&&typeof n=="number"&&(t[i]=n)}return t}function yr(e){let r={};for(let t of Object.keys(e)){let i=e[t];typeof i=="object"&&i!==null&&i.constructor&&i.constructor!==Object?r[t]=yr(i):r[t]=i}return r}function hr(e){let r={},t=new Set(e.files.map(i=>i.relativePath));for(let i of e){let n=i.name.toLowerCase();if(n.match(/^(?:fid|procpar|text|log)$/)){if(n.match(/^(?:fid|text|log)$/)){let l=i.relativePath.replace(/(?:fid|text|log)$/,"procpar");if(!t.has(l))continue}let o=i.relativePath.split("/"),s=o.slice(0,-1).join("/");r[s]||(r[s]={name:o.at(-2),files:[]}),r[s].files.push(i)}}return Object.values(r)}async function Sr(e,r={}){let{keepSource:t,logger:i}=r,n=hr(e);i&&i.debug(`Found ${Object.keys(n).length} varian experiments`);let o=[],s={spectra:[],molecules:[]};for(let a of n){let{name:m,files:u}=a,c=new Fr.FileCollection(u),g=(0,Dr.convert1D)(c).then(y=>{let{info:d,meta:p}=gr(y),f=y.fid.data[0],F=(0,Pr.isAnyArray)(f.im),h={data:{...f,x:y.x},meta:p,info:{isComplex:F,name:m,...d},display:{name:m}};if(d.isFid&&F){let{im:b}=h.data;(0,Nr.xMultiply)(b,-1,{output:b})}u&&t&&(h.sourceSelector={files:u.map(b=>b.relativePath)}),s.spectra.push(h)});o.push(g)}let l=await Promise.allSettled(o);for(let a=0;a<l.length;a++){let m=l[a];if(m.status==="rejected"&&m.reason){let u=n[a].name;i?.warn(`Varian data: ${u}, fails with: ${m.reason}`)}}return s.spectra.length>0&&i?.info(`Loaded ${s.spectra.length} spectra from Varian files`),(0,br.formatSpectra)(s)}var G=class{id="@zakodium/nmrium-core-plugins#VarianLoaderPlugin";version=1;migrations=[];onReadProcess;constructor(){this.onReadProcess={onFiles:this.onReadProcessFiles}}onReadProcessFiles=(r,t)=>{let{keepSource:i,logger:n}=t??{};return Sr(r,{keepSource:i,logger:n})}};function De(){return new G}function Mr(e,r=[]){return[Fe(e),De(),ue(),de(),he(),Pe(),Ne(),ye(),te()].concat(r)}function Ar(){let e=new Rr.NMRiumCore;return e.registerPlugins(Mr(e)),e}var Je=require("@zakodium/nmrium-core"),Cr=require("convert-to-jcamp");function xr(e,r){return e.filters.find(t=>t.name===r)}function Or(e,r={}){let{info:t,meta:i,data:n}=e,{onlyReal:o=!1}=r,{isFid:s,spectralWidth:l}=t,a=(0,Je.getOneIfArray)(t.baseFrequency||t.originFrequency),{x:m,re:u,im:c}=n,g=new Float64Array(u),y=!o&&c?new Float64Array(c):void 0,d={};K(d,"SW",l),K(d,"BF1",a);let p=xr(e,"fft")?.enabled,f={originFrequency:t.originFrequency,dataType:!t.isFid||p?"NMR SPECTRUM":"NMR FID",dataClass:!o&&c?"NTUPLES":"XYDATA"};if(s){let b=e.filters.find(N=>N.name==="digitalFilter");if(b&&!p){let{value:{digitalFilterValue:N},enabled:S}=b;if(S){let D=Math.floor(N);g.set(u.slice(u.length-D)),g.set(u.slice(0,u.length-D),D),c&&y&&(y.set(c.slice(c.length-D)),y.set(c.slice(0,c.length-D),D))}}K(f,"decim",t.decim),K(f,"dspfvs",t.dspfvs),K(f,"digitalFilter",t.digitalFilter)}let F={xyEncoding:"DIFDUP",info:{...t,...f},meta:{...i,...d}},h={x:{data:m,label:t.isFid?"TIME":"FREQUENCY",units:t.isFid?"second":"HZ",symbol:"X"},r:{data:g,label:`${t.isFid?"FID":"SPECTRUM"}/REAL`,units:"ARBITRARY UNITS",symbol:"R"}};return y&&(h.i={data:y,label:`${t.isFid?"FID":"SPECTRUM"}/IMAG`,units:"ARBITRARY UNITS",symbol:"I"}),(0,Cr.from1DNMRVariables)(h,F)}function K(e,r,t){t!==void 0&&(e[r]=(0,Je.getOneIfArray)(t))}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import{NMRiumCore as wn}from"@zakodium/nmrium-core";import{Filters1D as _t,Filters2D as Vt}from"nmr-processing";import{getOneIfArray as jt}from"@zakodium/nmrium-core";function U(e={},r={},t={}){e===null&&(e={}),typeof e=="string"&&(e={pulseSequence:e});let i=Array.isArray(e.pulseSequence)?e.pulseSequence[0]:e.pulseSequence||"";if(typeof i!="string")return e.dimension?`${e.dimension}d`:"";if(i=i.toLowerCase(),i.includes("zg")||i.includes("single_pulse_dec")||i.includes("udeft"))return"1d";if(i.includes("hsqct")||i.includes("invi")&&(i.includes("ml")||i.includes("di")))return"hsqctocsy";if(i.includes("hsqc")||i.includes("invi"))return"hsqc";if(i.includes("hmbc")||i.includes("inv4")&&i.includes("lp"))return"hmbc";if(i.includes("hmqc"))return"hmqc";if(i.includes("cosy"))return"cosy";if(i.includes("jres"))return"jres";if(i.includes("dosy"))return"dosy";if(i.includes("tocsy")||i.includes("mlev")||i.includes("dipsi"))return"tocsy";if(i.includes("noesy"))return"noesy";if(i.includes("roesy"))return"roesy";if(i.includes("dept"))return"dept";if(i.includes("jmod")||i.includes("apt"))return"aptjmod";if(i.includes("inad"))return"inadequate";if(i.includes("adeq"))return"adequate";let{prefix:n=""}=t,o=(jt(r[`${n}SPECTYP`])||"").replace(/^<(.*)>$/,"$1").toLowerCase();return o.length>0&&o!=="undefined"?o:e.dimension?`${e.dimension}d`:""}import{getOneIfArray as xe}from"@zakodium/nmrium-core";var zt=["no","exponential","modifiedGaussian","sine","qsine","trap","user","sinc","qsinc","traf","trafs"];function Bt(e){return e in Ce}function ae(e,r){let{prefix:t="",index:i=0}=r,n=xe(e[`${t}WDW`],i),o=zt[n?Number(n):0],s={};if(!Bt(o))return s;let l=Ce[o];if(l){let{kind:a,parameters:m}=l,u={};for(let c in m){let g=m[c],{source:y,processor:d}=g;if(y){let p=xe(e[`${t}${y}`],i);if(!p)continue;let f=Number(p);u[c]=d?d(f):f}else g.value!==void 0&&(u[c]=g.value)}s[a]={apply:!0,options:u}}return s}var Ce={exponential:{kind:"exponential",parameters:{lineBroadening:{source:"LB"}}},modifiedGaussian:{kind:"gaussian",parameters:{lineBroadening:{source:"LB"},lineBroadeningCenter:{source:"GB"}}},sine:{kind:"sineBell",parameters:{offset:{source:"SSB",processor:e=>1/e},exponent:{value:1}}},qsine:{kind:"sineSquare",parameters:{offset:{source:"SSB",processor:e=>1/e}}},traf:{kind:"traf",parameters:{lineBroadening:{source:"LB"}}}};var Oe={sineBell:Te({offset:0})},Ie={cosy:{...Oe},hmbc:{...Oe},hsqc:{sineBell:Te({offset:.5})}},Ut={...Ie};function ce(e="",r=1){let t=Wt(e),i={},n=r===1?Ie[t||""]:Ut[t||""];return n&&(i=structuredClone(n)),i}function Te(e){return{apply:!0,options:e}}function Wt(e){let t=e.toLowerCase().match(/cosy|hsqc|hmbc/);return t?t[0]:null}function Ee(e,r={}){let{prefix:t="",experiment:i=U(e)}=r;return e[`${t}WDW`]?{f2:ae(e,{...r,index:0}),f1:ae(e,{...r,index:1})}:{f2:ce(i,1),f1:ce(i,2)}}import{Filters1D as Xt}from"nmr-processing";var me=["digitalFilter","backwardLinearPrediction","forwardLinearPrediction","apodization","zeroFilling","fft",["shiftX","phaseCorrection","baselineCorrection"]],E={};for(let e=0;e<me.length;e++){let r=me[e];for(let t of Array.isArray(r)?r:[r])E[t]=e}for(let e of Object.values(Xt))e.name in E||(E[e.name]=me.length);import{Filters2D as Jt}from"nmr-processing";var le=["digitalFilter2D","blpDimension1","flpDimension1","apodizationDimension1","zeroFillingDimension1","fftDimension1","blpDimension2","flpDimension2","nusDimension2","apodizationDimension2","zeroFillingDimension2","fftDimension2","phaseCorrectionTwoDimensions",["shift2DX","shift2DY","symmetrizeCosyLike"]],L={};for(let e=0;e<le.length;e++){let r=le[e];for(let t of Array.isArray(r)?r:[r])L[t]=e}for(let e of Object.values(Jt))e.name in L||(L[e.name]=le.length);var Ht=new Set(["backwardLinearPrediction","forwardLinearPrediction","digitalFilter2D","phaseCorrectionTwoDimensions","blpDimension1","flpDimension1","apodizationDimension1","apodizationDimension2","zeroFillingDimension1","fftDimension1","blpDimension2","flpDimension2","zeroFillingDimension2","fftDimension2","nusDimension2","symmetrizeCosyLike"]);function Yt(e,r){let{filter:t,experimentalFeatures:i=!1}=r,{name:n}=t;({..._t,...Vt})[n]&&(e.some(s=>s.name===n)||(i||!Ht.has(n))&&e.push({...t,enabled:!0}))}function Le(e,r={}){let{data:t}=e;if(!t)return e;let{autoProcessing:i,experimentalFeatures:n}=r,o=(l,a)=>Yt(l,{...a,experimentalFeatures:n}),{spectra:s}=t;for(let l of s){let{data:a,info:m,meta:u,filters:c}=l,{dimension:g,isFid:y}=m;if(y){if(g===1){let d=a.re.length,{tdOff:p,digitalFilter:f}=m;if(f&&f>0&&o(c,{filter:{name:"digitalFilter",value:{digitalFilterValue:f}}}),!i)continue;p&&Math.abs(p)>0&&o(c,{filter:{name:"backwardLinearPrediction",value:{nbInputs:d/2}}}),o(c,{filter:{name:"apodization",value:{exponential:{apply:!0,options:{lineBroadening:1}}}}}),o(c,{filter:{name:"zeroFilling",value:{nbPoints:2*d}}}),o(c,{filter:{name:"fft",value:{}}}),o(c,{filter:{name:"phaseCorrection",value:Gt(m)}}),c.sort((F,h)=>E[F.name]-E[h.name])}else if(g===2){if(!i||!n)continue;let d=a.re.z.length,p=a.re.z[0].length,{tdOff:f,experiment:F=""}=m,h=m.spectrumSize;Array.isArray(h)&&h.length>1?(h[0]<=p&&(h[0]=p*2),h[0]<=d&&(h[0]=d*2)):h=[p*2,2*d];let b=F.toLowerCase().includes("cosy");f&&Math.abs(f[0])>0&&o(c,{filter:{name:"blpDimension1",value:{nbInputs:p/2}}});let N=Ee(u,{experiment:F});o(c,{filter:{name:"apodizationDimension1",value:N.f2}}),o(c,{filter:{name:"zeroFillingDimension1",value:{nbPoints:h[0]}}}),o(c,{filter:{name:"fftDimension1",value:{}}}),u&&"nuslist"in u&&o(c,{filter:{name:"nusDimension2",value:{}}}),o(c,{filter:{name:"apodizationDimension2",value:N.f1}}),o(c,{filter:{name:"zeroFillingDimension2",value:{nbPoints:h[b?0:1]}}}),b?o(c,{filter:{name:"symmetrizeCosyLike",value:{}}}):o(c,{filter:{name:"phaseCorrectionTwoDimensions",value:{}}}),o(c,{filter:{name:"fftDimension2",value:{}}}),c.sort((S,D)=>L[S.name]-L[D.name])}}}}function Gt(e){let{phc0:r=0,phc1:t=0}=e;return ke([r,t])?{}:{ph0:r,ph1:t}}function ke(e){return Array.isArray(e)?e.every(r=>!r&&r===0):ke([e])}var W=class{id="@zakodium/nmrium-core-plugins#AutoPostProcessingPlugin";version=1;migrations=[];onReadProcess;constructor(){this.onReadProcess={onProcessing:this.onPostProcessing.bind(this)}}onPostProcessing(r,t){Le(r,t)}};function ue(){return new W}import{formatSpectra as cr}from"@zakodium/nmrium-core";import{convertOneExperiment as mr,groupByExperiments as lr}from"brukerconverter";function X(e){let r=[];for(let t of e){if(!t)continue;let{groups:{value:i,unit:n}={}}=t.trim().match(/[$$]*\s*(?<value>[\d.]+)\s*(?<unit>[a-zA-Z]+)/)||{};r.push(Kt(i,n))}return r}function Kt(e,r){switch(r.toLowerCase()){case"s":return Number.parseFloat(e);case"ms":return Number.parseFloat(e)/1e3;case"m":case"min":return Number.parseFloat(e)*60;default:return Number.NaN}}import{isAnyArray as ve}from"is-any-array";function I(e){if(Zt(e))return Qt(e)?e.map(we):we(e);if(typeof e=="object"&&e!==null){let r={};for(let t in e)r[t]=I(e[t]);return r}return e}function Zt(e){return ve(e)}function we(e){return Float64Array.from(e)}function Qt(e){return ve(e[0])}import{getOneIfArray as j}from"@zakodium/nmrium-core";import{getGyromagneticRatio as rr}from"gyromagnetic-ratio";import{isAnyArray as fe}from"is-any-array";import{getFrequency as nr}from"nmr-processing";import{isAnyArray as k}from"is-any-array";function J(e){return typeof e=="number"}function _(e){let{phc0:r,phc1:t}=e;return!k(r)&&!J(r)||!k(t)&&!J(t)||k(r)&&!J(r[0])||k(t)&&!J(t[0])?{}:(k(t)?t[0]*=-1:t*=-1,k(r)?r[0]*=-1:r*=-1,{phc0:r,phc1:t})}function $e(e,r,t){if(e>0)return Number(e);if(r>14||r===0)return 0;if(qe[r]){let i=qe[r];if(!i[t])throw new Error(`decim ${t} not in lookup table for dspfvs ${r}`);return i[t]}else throw new Error(`dspfvs ${r} not in lookup table`)}var qe={10:{2:44.75,3:33.5,4:66.625,6:59.08333333333333,8:68.5625,12:60.375,16:69.53125,24:61.02083333333333,32:70.015625,48:61.34375,64:70.2578125,96:61.50520833333333,128:70.37890625,192:61.5859375,256:70.439453125,384:61.62630208333333,512:70.4697265625,768:61.646484375,1024:70.48486328125,1536:61.65657552083333,2048:70.492431640625},11:{2:46,3:36.5,4:48,6:50.16666666666667,8:53.25,12:69.5,16:72.25,24:70.16666666666667,32:72.75,48:70.5,64:73,96:70.66666666666667,128:72.5,192:71.33333333333333,256:72.25,384:71.66666666666667,512:72.125,768:71.83333333333333,1024:72.0625,1536:71.91666666666667,2048:72.03125},12:{2:46,3:36.5,4:48,6:50.16666666666667,8:53.25,12:69.5,16:71.625,24:70.16666666666667,32:72.125,48:70.5,64:72.375,96:70.66666666666666,128:72.5,192:71.333333333,256:72.25,384:71.66666666666667,512:72.125,768:71.83333333333333,1024:72.0625,1536:71.91666666666667,2048:72.03125},13:{2:2.75,3:2.833333333333333,4:2.875,6:2.916666666666667,8:2.9375,12:2.958333333333333,16:2.96875,24:2.979166666666667,32:2.984375,48:2.989583333333333,64:2.9921875,96:2.994791666666667}};import{normalizeNucleus as er}from"nmr-processing";function T(e,r=","){if(e&&typeof e=="string")return e.split(r)}function V(e,r,t){let i=[];if(e[`${t}AXNUC`]&&(i=e[`${t}AXNUC`],Array.isArray(i)||(i=[i]),i=C(i)),i.length===0&&e[`${t}NUC1`]&&(i=e[`${t}NUC1`],Array.isArray(i)||(i=[i]),i=C(i)),i.length===0&&e[".NUCLEUS"]){let n=T(e[".NUCLEUS"]);if(e[`${t}SYMBOL`]){let o=e[`${t}SYMBOL`].split(","),s=o.findIndex(a=>a.includes("2")),l=o.findIndex(a=>a.includes("1"));s!==-1&&l!==-1&&n?i=C([n[s],n[l]]):i=C(n).reverse()}else i=C(n)}return i.length===0&&e[".OBSERVENUCLEUS"]&&(i=C([e[".OBSERVENUCLEUS"]])),i.length===0&&r.experiment&&(i=C(je(r.experiment[0]))),tr(e)&&(i=[e["2D_X_NUCLEUS"].replaceAll(/[^A-Za-z0-9]/g,""),e["2D_Y_NUCLEUS"].replaceAll(/[^A-Za-z0-9]/g,"")]),r.experiment&&(r.experiment[0].match("jres")||r.experiment[0].match("dosy"))&&(i=je(r.experiment[0])),i.map(er)}function tr(e){return e["2D_X_NUCLEUS"]&&!e["2D_X_NUCLEUS"].includes("off")&&e["2D_Y_NUCLEUS"]&&!e["2D_Y_NUCLEUS"].includes("off")}function je(e){return typeof e!="string"?[]:(e=e.toLowerCase(),e.includes("jres")?["1H","Hz"]:e.includes("dosy")?["1H","D"]:e.includes("hmbc")||e.includes("hsqc")?["1H","13C"]:e.includes("cosy")||e.includes("tocsy")?["1H","1H"]:[])}function C(e){if(!e)return[];let r=e.map(i=>String(i).replaceAll(/[^A-Za-z0-9]/g,"").replace("NA","").replace("off","")),t=0;for(let i of r)i||t++;return t===0?r:[]}function P(e,r,t,i=!1){t===void 0||r in e&&!i||(Array.isArray(t)?e[r]=t.map(ze):e[r]=[ze(t)])}function ze(e){return typeof e=="string"&&(e.startsWith("<")&&e.endsWith(">")&&(e=e.slice(1,-1)),e=e.replace(/\$.*/,"").trim()),e}function Y(e,r={}){let{prefix:t="",logger:i}=r,n={dimension:0,nucleus:[],isFid:!1,isFt:!1},o=JSON.stringify(e),s=/\r\n/.exec(o)?`\r
|
|
2
|
-
`:`
|
|
3
|
-
`,{JCAMPDX:l="",ORIGIN:a=""}=e,m=String(l).toLowerCase()+String(a).toLowerCase();"SPECTROMETER/DATASYSTEM"in e&&(m=e["SPECTROMETER/DATASYSTEM"]);let u=(d=[])=>{for(let p of d)if(!(p in n))return!1;return!0};(m.includes("mestre")||m.includes("nova"))&&(m="mnova"),n.creator=m,e.LONGDATE&&pe(n,Date.parse(e.LONGDATE)),P(n,"pulseSequence",e[".PULSESEQUENCE"]||e[".PULPROG"]||e[`${t}PULPROG`]);let c=e[`${t}OWNER`];if(c&&P(n,"owner",c.replaceAll(/\$\$.*/gm,"")),P(n,"aqMod",e[`${t}AQ_mod`]),P(n,"experiment",U(n,e,{prefix:t})),n.nucleus=V(e,n,t),n.nucleus.length===0)if(i)i?.warn("There is not a nucleus detected, assuming 1H"),n.nucleus=["1H"];else throw new Error("There is not a nucleus detected");n.dimension=n.nucleus.length;let g=e[`${t}.ACQUISITIONSCHEME`]||e[`${t}FnMODE`];if(g&&P(n,"acquisitionScheme",or(j(g,1))),P(n,"acquisitionMode",e[`${t}.ACQUISITIONMODE`]),M(n,"lpNumberOfCoefficients",e[`${t}NCOEF`]),M(n,"linearPredictionBin",e[`${t}LPBIN`]),M(n,"tdOff",e[`${t}TDoff`]),P(n,"windowMultiplicationMode",e[`${t}WDW`]),P(n,"title",e.TITLE),P(n,"solvent",e[".SOLVENTNAME"]),P(n,"temperature",e[`${t}TE`]||e[".TE"]),P(n,"type",e.DATATYPE),P(n,"dataClass",e[`${t}DATACLASS`]),P(n,"phc1",e[`${t}PHC1`]),P(n,"phc0",e[`${t}PHC0`]),n.type){let d=n.type[0].toUpperCase();d.includes("FID")?(n.isFid=!0,n.isComplex=!0):d.includes("SPECTRUM")&&(n.isFt=!0)}if(P(n,"firstX",e[`${t}FIRSTX`]),P(n,"lastX",e[`${t}LASTX`]),P(n,"numberOfPoints",e[`${t}NPOINTS`]),P(n,"originFrequency",e[`${t}SFO1`]),n.dimension===1&&M(n,"originFrequency",e[".OBSERVEFREQUENCY"]),"originFrequency"in n&&(n.originFrequency=H(n.originFrequency)),!n.originFrequency&&n.dimension===2&&".OBSERVEFREQUENCY"in e){let{nucleus:d}=n,p=H(e[".OBSERVEFREQUENCY"]);if(fe(p)&&p.length>1){let f=e[`${t}SYMBOL`].split(","),F=f.findIndex(b=>b.includes("2")),h=f.findIndex(b=>b.includes("1"));F!==-1&&h!==-1?n.originFrequency=[p[F],p[h]]:n.originFrequency=p.slice()}else if(typeof p=="number"){let f=nr(d[1],{frequency:p,nucleus:d[0]});n.originFrequency=[p,f]}}if((!n.originFrequency||n.originFrequency.some(d=>Number.isNaN(d)||d===0))&&(n.originFrequency||(n.originFrequency=n.dimension>1?[400,400]:[400]),n.originFrequency=n.originFrequency.map(d=>Number.isNaN(d)||d===0?400:d),i?.warn("The frequency could not be determined and was set to 400 MHz")),m.toLocaleLowerCase().includes("oxford instruments")?sr(n,e,{...r,separator:s}):m.includes("nanalysis")&&ar(n,e),m!=="mnova"&&m!=="mestre"){let d=n.nucleus[0],p=rr(d);if(P(n,"probeName",e[`${t}PROBHD`]),P(n,"baseFrequency",e[`${t}BF1`]),P(n,"baseFrequency",e[`${t}SF`]),M(n,"scaleFactor",e[`${t}NC_proc`]),"scaleFactor"in n)for(let b=0;b<n.scaleFactor.length;)n.scaleFactor[b]=2**n.scaleFactor[b++];if(!("baseFrequency"in n)&&"originFrequency"in n?P(n,"baseFrequency",n.originFrequency):n.baseFrequency=H(n.baseFrequency),!["baseFrequency","originFrequency"].some(b=>!n[b])&&p){let{baseFrequency:b}=n,N=2*Math.PI*(b[0]/p)*1e6;P(n,"fieldStrength",N)}M(n,"spectralWidth",e[`${t}SW`]),M(n,"spectralWidth",e[`${t}QM_SPECTRAL_WIDTH`]),n.dimension===1&&e[`${t}SweepWidth`]&&n.originFrequency&&M(n,"spectralWidth",e[`${t}SweepWidth`]/n.originFrequency[0]),P(n,"numberOfPoints",e[`${t}TD`],!0);let f=n.numberOfPoints;if(P(n,"spectrumSize",e[`${t}SI`]??f),P(n,"sampleName",e[`${t}NAME`]),e[`${t}FNTYPE`]!==void 0&&P(n,"acquisitionMode",Number.parseInt(e[`${t}FNTYPE`],10)),(e[`${t}VARNAME`]?e[`${t}VARNAME`].split(",")[0]:"")==="TIME"){let b=typeof e.LAST=="string"?e.LAST.replace(" ","").split(",")[0]:e.LAST;M(n,"acquisitionTime",b)}if(!n.acquisitionTime&&u(["numberOfPoints","spectralWidth"])){let{spectralWidth:b,originFrequency:N}=n;P(n,"acquisitionTime",Number((f[0]-1)/(2*b[0]*N[0])))}if(e[`${t}P`]){let b=1e6/(j(e[`${t}P`]).split(s)[1].split(" ")[1]*4);P(n,"pulseStrength90",b)}if(e[`${t}D`]){let b=j(e[`${t}D`]).split(s)[1].split(" ")[1];M(n,"relaxationTime",b)}if(M(n,"numberOfScans",e[`${t}NS`]),M(n,"numberOfScans",e[`${t}QM_NSCANS`]),P(n,"groupDelay",e[`${t}GRPDLY`]),P(n,"dspfvs",e[`${t}DSPFVS`]),P(n,"decim",e[`${t}DECIM`]),n.isFid&&("groupDelay"in n||u(["dspfvs","decim"]))){let{groupDelay:b,dspfvs:N,decim:S}=n,D=$e(b?.[0]??0,N?.[0],S?.[0]);P(n,"digitalFilter",D)}let h;if(u(["numberOfPoints","spectralWidth"])){let{spectralWidth:b,numberOfPoints:N}=n;n.isFid?h=N.map(S=>n.acquisitionTime[0]/(S-1)):h=N.map((S,D)=>b[D]/(S-1))}if(P(n,"increment",h),e[`${t}DATE`]){let b=j(e[`${t}DATE`]),N=Number.parseInt(b,10)*1e3;Number.isNaN(N)?pe(n,Date.parse(b)):pe(n,N)}n.solvent||P(n,"solvent",j(e[`${t}SOLVENT`]))}if(n.dimension<2&&"dataClass"in n&&n.dataClass[0].toUpperCase()==="NTUPLES"&&(P(n,"last",T(e[`${t}LAST`])),P(n,"first",T(e[`${t}FIRST`])),P(n,"varDim",T(e[`${t}VARDIM`])),P(n,"symbols",T(e[`${t}SYMBOL`])),n.symbols&&Array.isArray(n.symbols))){n.symbols.includes("R")&&n.symbols.includes("I")&&(n.isComplex=!0);let d=n.symbols.findIndex(p=>p.toLowerCase()==="x");if(M(n,"firstX",n.first[d]),M(n,"lastX",n.last[d]),M(n,"numberOfPoints",n.varDim[d]),!("spectralWidth"in n)){let{lastX:p,numberOfPoints:f,firstX:F}=n;P(n,"spectralWidth",n.isFid?f/(2*p):Math.abs(p-F)/n.originFrequency)}}if(`${t}REVERSE`in e){let d=e[`${t}REVERSE`];n.reverse=(Array.isArray(d)?d:[d]).map(p=>typeof p=="string"?p.includes("yes"):p)}let y=e[`${t}REFERENCE_POINT`];if(!("frequencyOffset"in n)&&y&&u(["spectralWidth","baseFrequency"])){let d=typeof y=="number"?y:e[`${t}REFERENCE_POINT`].match(/(?<reference>[+-]?\d+(?:\.\d+)?)\s*.*/),p;if(typeof y=="number"?p=y:(y.match(/(?<reference>[+-]?\d+(?:\.\d+)?)\s*.*/),p=Number(d?.groups?.reference)),!Number.isNaN(p)){let{spectralWidth:f,baseFrequency:F}=n;P(n,"frequencyOffset",.5*f*F-p)}}if(!("frequencyOffset"in n)&&u(["baseFrequency","originFrequency"])){let{baseFrequency:d,originFrequency:p}=n,f=d.map((F,h)=>(p[h]-F)*1e6);P(n,"frequencyOffset",f)}for(let d in n)n[d]&&n[d].length===1&&(n[d]=n[d][0]);return!n.frequencyOffset&&".SHIFTREFERENCE"in e&&ir(e,n),Array.isArray(n.nucleus)||(n.nucleus=[n.nucleus]),n}function M(e,r,t){t!==void 0&&P(e,r,H(t))}function pe(e,r){if(!Number.isNaN(r)){e.epoch=r;let t=new Date(r);e.date=t.toUTCString(),e.localeDate=t.toLocaleString()}}function ir(e,r){let t=e[".SHIFTREFERENCE"],i=t.trim().startsWith("(")?/\((?<data>[^)]+)\)/:/(?<data>[^)]+)/,n=t.match(i);if(n.groups.data){let o=n.groups.data.split(",");if(o.length<4)return;let s=Number.parseInt(r.numberOfPoints,10),{spectralWidth:l,baseFrequency:a}=r,m=Number.parseInt(o[2],10),u=Number.parseFloat(o[3]),c;if(r.isFid){if(["baseFrequency","numberOfPoints","spectralWidth"].some(g=>!(g in r)))return;c=u+(s*.5-m)*l/s}else{let g=Number.parseFloat(r.firstX),y=Number.parseFloat(r.lastX),d=(y+g)/2,p=(y-g)/(s+1),f=p<0?g:y+(m-1)*p;c=(d-f)/a+u}c!==void 0&&!Number.isNaN(c)&&(r.frequencyOffset=c*a)}}function H(e){if(fe(e)){let r=[];for(let t of e)r.push(typeof t=="string"?Number.parseFloat(t):t);return r}return typeof e=="string"?Number.parseFloat(e):e}function or(e){switch(String(fe(e)?e[1]:e).toLowerCase().replaceAll(/\s/g,"")){case"1":case"notphasesensitive":return"notPhaseSensitive";case"2":return"QSEQ";case"3":case"tppi":return"TPPI";case"4":case"states":return"States";case"5":case"tppi-states":return"States-TPPI";case"6":case"echo-antiecho":return"Echo-antiecho";default:return"undefined"}}function sr(e,r,t={}){let{prefix:i="",separator:n=`
|
|
4
|
-
`}=t;P(e,"spectralWidth",r[`${i}SweepWidth`]/e.originFrequency[0]);let o=r[`${i}.PULSESEQUENCE`].split(n),s=[];r[".OBSERVENUCLEUS"]&&s.push(r[".OBSERVENUCLEUS"]),r.INDIRECTNUCLEUS&&s.push(r.INDIRECTNUCLEUS),e.nucleus=C(s),e.pulseSequence=o[0];let l=o.slice(2,-1);if(s.length>1)if(s[0]===s[1])e.spectralWidth.push(e.spectralWidth[0]);else{let a=JSON.stringify(l).match(/\$\$SW1=\s*(?<sw>[+-]?(?:[0-9]*[.])?[0-9]+)/);if(a?.groups){let{originFrequency:m}=e,u=Number.parseFloat(a.groups.sw);e.spectralWidth.push(u/m[1])}}return e}function ar(e,r){let{T1NUCLEUS:t,T2NUCLEUS:i,PAGE:n}=r;e.pulseSequence=r.EXPERIMENT||r[".PULSESEQUENCE"];let o=[],{dimension:s,isComplex:l}=e;if(s===2&&e.pulseSequence==="T1"){let u=l?2:1;for(let c=0;c<n.length;c+=u){let g=n[c].replace(/T1=/,"");o.push(Number(g))}r.vdlistValues=o}e.nucleus=s>1?[i,t]:i;let{phc0:a,phc1:m}=e;if(a&&m){let u=_({phc0:a,phc1:m});e={...e,...u}}}var ur={keepRecordsRegExp:/.*/,keepFiles:!0};async function G(e,r={}){let t={spectra:[],molecules:[]},{converter:i={},selector:n={},logger:o}=r,s=lr(e,{logger:o,...fr(n)}),l=[];for(let m of s)l.push(mr(m,{...ur,...i}).then(u=>pr(u,r)));let a=await Promise.allSettled(l);for(let m=0;m<a.length;m++){let u=a[m];if(u.status==="fulfilled"){let c=_(u.value.info);t.spectra.push({...u.value,info:{...u.value.info,...c}})}else if(u.reason){let c=s[m].name;o?.warn(`Bruker data: ${c}, fails with: ${u.reason}`);continue}}return o&&o[t.spectra.length>0?"info":"debug"](`Loaded ${t.spectra.length} spectra from Bruker files`),cr(t)}function pr(e,r={}){let{keepSource:t=!1,logger:i}=r,n={...e.info,...e.meta},o=Y(n,{logger:i}),s={},{isFid:l}=o;if(dr(e)){let y=e.minMax;for(let d in y){let p=y[d];p&&(p.z=I(p.z))}s.components=e.minMax}else o.dimension===1&&(s.components=e.spectra);let{source:a}=e,{expno:m,name:u,files:c}=a;n.vdlist&&(n.vdlistValues=X(n.vdlist));let g={dependentVariables:[s],meta:n,info:{...o,experimentNumber:m,name:u}};return c&&t&&(g.sourceSelector={files:c.map(y=>y.relativePath)}),gr(g,e),g}function fr(e){let{general:r={},bruker:t={}}=e,{processingNumbers:i,experimentNumbers:n,...o}=t;return{...r,...o,processingNumbers:Be(i),experimentNumbers:Be(n)}}function Be(e){if(e)return e.split(/[^\d]+/).filter(Boolean).map(r=>Number.parseInt(r,10))}function dr(e){let{info:r}=e;return r.twoD}function gr(e,r){if(!("integrals"in r))return;let{integrals:t=[]}=r;e.integrals={values:t.map(i=>{let{from:n,to:o,integration:s}=i;return{from:n,to:o,integral:s,kind:"signal"}})}}var K=class{id="@zakodium/nmrium-core-plugins#BrukerLoaderPlugin";version=1;migrations=[];onReadProcess;constructor(){this.onReadProcess={onFiles:this.onReadProcessFiles}}onReadProcessFiles=(r,t)=>{let{sourceSelector:i,converter:n,keepSource:o,logger:s}=t??{};return G(r,{converter:n?.bruker,selector:i,keepSource:o,logger:s})}};function de(){return new K}import{formatSpectra as Yr}from"@zakodium/nmrium-core";import{createTree as Gr}from"jcampconverter";function Ue(e,r,t={}){let{selector:i={},keepSource:n=!1}=t;if(!n)return e;for(let o=0;o<e.spectra.length;o++){let s=e.spectra[o];s.sourceSelector={files:[r.relativePath],jcamp:{index:o,...i}}}return e}import{convert as yr}from"jcampconverter";function ge(e,r,t){let{dataType:i,children:n}=e,o=i==="LINK"&&n?n:[e];for(let s of o){if(s.dataType==="LINK"){ge(s,r,t);continue}let l=yr(s.jcamp,t);r.push(...l.flatten)}}function Je(e,r={}){let t=[],i=_e(e,r);for(let s of i?e:[])s.dataType==="LINK"?s.children=ye(s.children,r):s=ye([s],r)[0],t.push(s);let{name:n,logger:o}=r;return e.length===0&&o?.warn(`There is no data ${n?`in ${n}`:"in the JCAMP-DX"}`),t}function ye(e=[],r={}){let{name:t,logger:i,tree:n=[],dataSelection:o="both"}=r,s=[];for(let u of e){let{dataType:c,dataClass:g}=u;if(c==="LINK")u.children=ye(u.children,r);else if(n.some(y=>{let{dataClass:d=g,dataType:p=c}=y;return g===d&&c===p})){i?.warn(`Skipping ${g} and ${c} ${t?`in ${t}`:"in the JCAMP-DX"},
|
|
5
|
-
because it didn't match the import filters`);continue}s.push(u)}let l=[],a=s.some(Xe),m=s.some(We);for(let u of s){if(o!=="both"&&u.dataType!=="LINK"){if(Xe(u)&&(o==="ft"||o==="preferFT"&&m)){i?.warn(`Skipping raw data ${t?`in ${t}`:"in the JCAMP-DX"} because it didn't match the import filters`);continue}if(We(u)&&(o==="fid"||o==="preferFID"&&a)){i?.warn(`Skipping FFT data ${t?`in ${t}`:"in the JCAMP-DX"} because it didn't match the import filters`);continue}}l.push(u)}return l}function We(e){return e.dataType?.toUpperCase().includes("SPECTRUM")&&e.dataClass&&!e.dataClass.toUpperCase().includes("PEAK")}function Xe(e){return e.dataType?.toUpperCase().includes("FID")}function _e(e,r={}){let{logger:t,name:i=""}=r;for(let n of e){if(n.dataType==="LINK"&&_e(n.children,r))return!0;let{dataType:o=""}=n,s=o.toLowerCase();if(s.length>0){if(s.includes("spectrum")&&!s.includes("nmr"))return t?.warn(`File ${i} was ignored because it is a ${o}`),!1;if(s.includes("nmr"))return!0}}return!1}import{generateID as Ye}from"@zakodium/nmrium-core";import{parseJcampCS as Sr}from"jcampconverter";import*as Rr from"openchemlib";import{isMolfileNotEmpty as hr}from"nmr-processing";import{Molecule as br}from"openchemlib";async function Ve(e,r={}){let t=await e.text(),i=w(t),n={molecules:i,spectra:[]};return i.length===0&&r.logger?.debug(`${e.name} is an empty molfile`),n}function w(e){let r=[];if(!hr(e))return[];let i=br.fromMolfile(e).toMolfile();return r.push({molfile:i}),r}import{isMolfileNotEmpty as Pr}from"nmr-processing";import*as Nr from"openchemlib";import{getDiastereotopicAtomIDsFromMolfile as Dr}from"openchemlib-utils";var Fr=new Set(["ndnmrspectrum","ndnmrfid","nmrspectrum","nmrfid"]);function Z(e){let{dataType:r="",dataClass:t=""}=e,i=r.replaceAll(/\s/g,"").toLowerCase(),n=t.replaceAll(/\s/g,"").toLowerCase();return Fr.has(i)&&n!=="peaktable"}function He(e,r,t={}){let{spectra:i,info:n,meta:o}=e,s=i[0].data,l=[],a={x:"delta",y:"intensity",w:"width",m:"multiplicity",a:"atom"},{logger:m,name:u,spectraData:c}=t,{CROSSREFERENCE:g}=n,y=typeof g!="string"?g:g.split(/\r?\n/).map(D=>D.trim()).filter(Boolean),d=y.find(D=>D?.toLowerCase().includes("structure"));if(d===void 0)return m&&m.warn(`There is not a structure reference for ${u} file, assignment object could not be completed`),null;let p=Number.parseInt(d?.toLowerCase().replace(/_/,"").replace(/structure:\s*blockid\s*=\s*(?<blockId>.*)/,"$<blockId>"),10);if(Number.isNaN(p)||p<1)return m&&m.warn(`Structure block_id not found for ${u} file, assignment object could not be completed`),null;let F=c?.molecules?.find(D=>D.blockId===p)?.molfile??"";if(F===""){let D=r.find(A=>A.info.BLOCKID===p),{MOLFILE:R=""}=D?.meta||{};F=R}if(!Pr(F))return m&&m.warn(`Empty molfile for ${u} file with structure block_id = ${p}, assignment object could not be completed`),null;let h=Dr(Nr,F),b=V({...n,...o},{},"");for(let D=0;D<s.x.length;D++){let R={};for(let A in s){let x=s[A][D];typeof x=="string"&&x.startsWith("<")&&x.endsWith(">")&&(x=x.slice(1,-1)),R[a[A]]=x}if("atom"in R){let A=h.map[R.atom-1];b.includes("1H")?A.nbHydrogens>0?(R.diaIDs=A.hydrogenOCLIDs,R.nbHydrogens=A.nbHydrogens):(R.diaIDs=[A.oclID],R.nbHydrogens=A.nbHydrogens):(R.diaIDs=[A.oclID],R.nbHydrogens=1)}l.push(R)}let N={};for(let D of l){let{delta:R,diaIDs:A}=D,x=`${R}_${A.join("_")}`;if(N[x])N[x].atoms.push(D.atom);else{let{atom:zn,...$t}=D;N[x]={...$t,atoms:[D.atom]}}}let S=[];for(let D of y)D.toLowerCase().includes("spectrum")&&S.push(Number(D.toLowerCase().replace(/_/,"").replace(/.*:\s*blockid=(?<blockId>.*)/,"$<blockId>")));if(S.length===0){for(let D of r)if(Z(D)){let{BLOCKID:R}=D.info;S.push(Number(R))}S.length>1&&(S=[],m&&m.warn(`There is not a spectral cross-reference for the peak assignment in the ${u} file`))}return{moleculeBlockID:p,spectraBlockIDs:S,assignments:Object.values(N),molecule:h.molecule}}function Ge(e,r,t,i){for(let n of e){let{meta:o,dataClass:s="",dataType:l="",info:a}=n,m=Number.parseInt(String(a.BLOCKID),10);o.MOLFILE?Cr(String(o.MOLFILE),r,m):n.jcampCS&&xr(n,r,m),Mr(s,l)&&Ar(r,n,e,i),Z(n)&&t.push(n)}}function Mr(e,r){return e?.toLowerCase().includes("assignments")&&r?.toLowerCase().includes("assignments")}function Ar(e,r,t,i){let n=He(r,t,{spectraData:e,logger:i.logger,name:i.name});if(e.assignmentsByBlocks||(e.assignmentsByBlocks={}),n){let{spectraBlockIDs:o}=n;for(let s of o)e.assignmentsByBlocks[s]=n}}function xr(e,r,t){r.molecules||(r.molecules=[]);let i=Sr(e,{OCL:Rr}),n=w(i?.molfile||"");n.length>0&&r.molecules.push({id:Ye(),blockId:t,...n[0]})}function Cr(e,r,t){r.molecules||(r.molecules=[]);let i=w(String(e));r.molecules.push({id:Ye(),blockId:t,...i[0]})}import{generateID as mt}from"@zakodium/nmrium-core";import{matrixMinMaxZ as ct,reimPhaseCorrection as jr}from"ml-spectra-processing";import{xyAutoRangesPicking as zr}from"nmr-processing";function v(e){return e.slice(0,Math.max(0,e.lastIndexOf(".")))}function q(e){e.sort((r,t)=>r.from-t.from);for(let r=0;r<e.length-1;r++)e[r].to>e[r+1].from&&(e[r].to=Math.max(e[r+1].to,e[r].to),e[r].signals=e[r].signals.concat(e[r+1].signals),e[r].integration+=e[r+1].integration,e.splice(r+1,1),r--);return e}import{splitPatterns as Lr}from"nmr-processing";import{xMaxValue as Or}from"ml-spectra-processing";function z(e){return e.trim().slice(1,-1).split(/,\s*/).map(r=>r.trim())}var Ir={I:"id",X:"from",Y:"to",Hs:"delta",An:"integration",H:"nbAtoms",C:"multiplicity",N:"assignment","(J)":"js"},Ke=["I","X","Y","Hs","An","H","C","N","(J)"];function Ze(e){let r={headersFromParenthesis:[],headersFromComments:[],comments:[],data:[],multiplets:[]},t=e.split(/\r?\n/).filter(i=>i.trim()!=="");if(t.length===0)return r;if(t[0].startsWith("(")&&!t[0].match(/\d/)){let i=t.shift();r.headersFromParenthesis=z(i)}return r.comments=t.filter(i=>i.startsWith("$$")).map(i=>i.replace(/^\$\$\s*/,"")),r.headersFromComments=Er(r.comments),r.data=t.filter(i=>!i.startsWith("$$")).map(z),r.multiplets=Tr(r),r}function Tr(e,r={}){let{logger:t}=r,i=e.data[0].map((a,m)=>m).filter(a=>e.data.every(m=>Number.isNaN(m[a])||Number.isNaN(Number(m[a]))));if(t?.trace(`Parsing JCAMP-DX assignment: stringColumnIndexes: ${i.join(",")}`),i.length===0)return t?.warn("Parsing JCAMP-DX assignment: No string columns found. Skipping parsing of assignment."),[];let n=i[0],o;if(e.headersFromParenthesis.length>0&&e.headersFromParenthesis[n]==="C")o=e.headersFromParenthesis;else if(e.headersFromComments.length>0&&e.headersFromComments[n]==="C")o=e.headersFromComments;else if(Ke[n]==="C")o=Ke;else return t?.warn("No header found for multiplicity. Skipping parsing of assignment."),[];return Or(e.data.map(a=>a.length))>o.length&&t?.warn("Some assignments are containing more values than headers"),e.data.map(a=>{let m={};for(let u=0;u<o.length;u++){let c=o[u];m[Ir[c]||c]=a[u]}return m})}function Er(e){return e.map(r=>r.split(":")[0].trim()).filter(r=>r.length>0)}function Qe(e,r={}){let{logger:t}=r,i=Ze(e),n={multiplets:[],comments:i.comments};for(let o of i.multiplets){let{id:s,from:l,to:a,delta:m,integration:u,nbAtoms:c,multiplicity:g}=o,y={id:s,js:[],multiplicity:"",...kr({from:l,to:a,delta:m,integration:u,nbAtoms:c})};if(typeof o.js=="string"){let d=o.js.split(/\s+/).map(Number.parseFloat),p=0,f=Lr(g).map(b=>{let N=(b?.multiplicity||1)-1;return p+=N,{value:b.value,multiplicity:b?.multiplicity,js:d.slice(p-N,p)}}),F=f.reduce((b,N)=>b+(N.multiplicity?N.multiplicity-1:0),0);d.length!==F&&t?.warn(`The number of j values (${d.length}) is not equal to the sum of the multiplicities - 1 (${F})`);let h=[];for(let b of f){if(b.js.every(N=>N===b.js[0])){h.push(b);continue}if(b.multiplicity!==b.js.length+1){h.push(b);continue}for(let N=0;N<b.multiplicity-1;N++)h.push({value:"d",multiplicity:2,js:[b.js[N]]})}h.sort((b,N)=>N.js[0]-b.js[0]),y.js=h.map(b=>({coupling:b.js[0],multiplicity:b.value}))}typeof o.assignment=="string"&&(y.assignment=vr(o.assignment)),typeof o.multiplicity=="string"&&(y.multiplicity=o.multiplicity),n.multiplets.push(y)}return n}function kr(e){let r={};for(let t in e){let i=e[t],n=typeof i=="number"?i:Number.parseFloat(i);Number.isNaN(n)||(r[t]=n)}return r}var wr={quot:'"',apos:"'",comma:",",amp:"&",lpar:"(",rpar:")",lt:"<",gt:">",colon:":",semi:";"};function vr(e){return e.replaceAll(/&(\w+);/gi,(r,t)=>wr[t.toLowerCase()]||r)}function et(e){let r=e.split(/\r?\n/).filter(i=>i.trim()!==""),t=[];for(let i of r)if(i.startsWith("(")){let[n,o,s]=z(i).map(Number.parseFloat);t.push({id:n,x:o,y:s})}return t}function tt(e,r={}){let t={};if(!e["OBSERVED MULTIPLETS"])return[];let i=Qe(e["OBSERVED MULTIPLETS"],r);if(!i)return[];let{multiplets:n}=i;for(let o of n){let{id:s,from:l,to:a,integration:m=0,...u}=o;t[s]={from:l,to:a,integration:m,signals:[{id:s,...u}]}}if(e["OBSERVED MULTIPLETS PEAKS"]){let o=et(e["OBSERVED MULTIPLETS PEAKS"]),s={};for(let l of o){let{id:a,x:m,y:u}=l;s[a]||(s[a]=[]),s[a].push({x:m,y:u,width:.05})}for(let l in t)s[l]&&(t[l].signals[0].peaks=s[l])}return q(Object.values(t))}function rt(e,r){let i=[...e.getMolecularFormula().formula.matchAll(/(?<element>[A-Z][a-z]?)(?<count>\d*)/g)].map(o=>({element:o?.groups?.element,count:o?.groups?.count?Number(o.groups.count):1})),n=[...r.nucleus[0].matchAll(/[0-9]*(?<element>[A-Z][a-z]?)/g,"$element")][0].groups.element;return i.find(o=>o.element===n)?.count||100}function nt(e){let r={};return".PHASE0"in e&&(r.ph0=Number.parseFloat(e[".PHASE0"]),r.ph1=Number.parseFloat(e[".PHASE1"])),r}function he(e){let{ph0:r,ph1:t}=e;return Number.isFinite(r)&&Number.isFinite(t)}import{generateID as it}from"@zakodium/nmrium-core";function ot(e,r,t){for(let i=0;i<e.length;i++){if(r.includes(i))continue;let{delta:n,multiplicity:o="",diaIDs:s}=e[i],l=Number(n)-.01,a=Number(n)+.01;t.push({from:l,to:a,integration:1,id:it(),signals:[{id:it(),delta:n,multiplicity:o,diaIDs:s}]})}}import{linearSumAssignment as qr}from"linear-sum-assignment";import{xCostMatrix as $r}from"ml-spectra-processing";function st(e,r){let t=e.map(s=>s.delta),i=r.map(s=>s.delta),n=$r(i,t,{fct:(s,l)=>Math.abs(s-l)}),{rowAssignments:o}=qr(n,{maximaze:!1});return Array.from(o)}function at(e,r){let{assignments:t,ranges:i}=r;t?.sort((s,l)=>l.delta-s.delta);let n=[],o=[];for(let s of i){let l=0,{from:a,to:m}=s,u=[];for(let c=l;c<t.length;c++){let{delta:g}=t[c];g<=m&&g>=a?(u.push(t[c]),o.push(c)):g>m&&(l=c)}if(u.length>0){let c=s.signals,g=[],y=u.length>1&&c.length>1?st(c,u):[0];for(let d=0;d<u.length;d++){let p=y[d],{delta:f,multiplicity:F,diaIDs:h}=u[d];p>-1?g.push({...c[p],diaIDs:h}):g.push({delta:f,multiplicity:F,diaIDs:h})}s.signals=g,n.push(s)}}ot(t,o,n),n.sort((s,l)=>s.from-l.from),e.ranges={values:q(n).map(s=>{let{integration:l,...a}=s;return a}),options:{sum:r.integrationSum,isSumConstant:!0,sumAuto:!0}},e.ranges.options.moleculeId=String(r.moleculeId)}function lt(e,r,t,i,n){let{logger:o}=n,s={components:ut(e)?Wr(e,t.isFid):Ur(e)},{name:l=t.title||`jcamp_${mt()}`}=n,a={dependentVariables:[s],meta:r,info:{...t,name:v(l)}};return Br(e)&&Xr(a,i,r,e,t,{logger:o}),a}function ut(e){return"minMax"in e}function Br(e){return!ut(e)}function Ur(e){return e.spectra.map(r=>{let t=I(r.data);return{...r,data:t}})}function Wr(e,r){let t={...e.minMax,z:I(e.minMax?.z)};return r?Jr(t):{rr:t}}function Xr(e,r,t,i,n,o){let{assignmentsByBlocks:s}=r,l=nt(t);he(l)&&_r(e,l);let a=String(i.info.BLOCKID);if(s?.[a]){let{molecule:m,assignments:u,moleculeBlockID:c}=s[a],g=rt(m,n),y=I(i.spectra[0].data);if(y.x[0]>y.x[1])for(let F of i.spectra)F.data.x.reverse(),F.data.y.reverse();if(he(l)&&i.spectra.length>1){let{re:F}=Vr(i,l);y.y=F}let{x:d,y:p}=y,f=tt(t,o)??zr({x:d,y:p},{peakPicking:{frequency:n.originFrequency},ranges:{frequency:n.originFrequency,integrationSum:g}});at(e,{moleculeId:c,ranges:f,assignments:u,integrationSum:g})}}function Jr(e){let{z:r,...t}=e,i=[],n=[];for(let l=0;l<r.length;l+=2)i.push(r[l].slice()),n.push(r[l+1].slice());let o=ct(i),s=ct(n);return{re:{...t,z:i,minZ:o.min,maxZ:o.max},im:{...t,z:n,minZ:s.min,maxZ:s.max}}}function _r(e,r){let{ph0:t,ph1:i}=r;e.filters||(e.filters=[]),e.filters.push({id:mt(),name:"phaseCorrection",value:{ph0:t,ph1:i,absolute:!1},enabled:!0})}function Vr(e,r){let{ph0:t,ph1:i}=r,{re:n,im:o}=jr({re:e.spectra[0].data.y,im:e.spectra[1].data.y},t*Math.PI/180,i*Math.PI/180);return{re:n,im:o}}function pt(e,r,t){let{logger:i}=t,n=[];for(let o of e)if(o.spectra&&o.spectra.length>0||o.minMax){Hr(o);let s={...o.info,...o.meta},l=Y(s,{logger:i});if(l.experiment==="wobble_curve")continue;n.push(lt(o,s,l,r,t))}return n}function Hr(e){let r=e.meta["BRUKER FILE EXP"];if(!r)return;let i=(Array.isArray(r)?r:[r]).find(o=>o.slice(0,10).includes("vdlist"));if(!i)return;let n=i.split(`
|
|
6
|
-
`).slice(1);e.info.vdlistValues=X(n)}async function Q(e,r={}){let t=await e.text(),i=ft(t,{name:e.name,...r});return Ue(i,e,r)}function ft(e,r={}){let t={spectra:[],molecules:[]},{name:i,converter:n={},selector:o={},logger:s}=r,{keepRecordsRegExp:l=/.*/}=n,a={keepSpectra:!0,noContour:!0,noTrimRegExp:/\$MOLFILE/,keepRecordsRegExp:l,logger:s},m=Je(Gr(e),{name:i,...o,logger:s});for(let u of m)Kr(u,t,a,i);if(Zr(t,o),t.spectra.length===0&&m.length>0){let u=t.molecules.length===0?" nor molecule":"";s?.warn(`No spectra${u} data was loaded from file ${i}`)}return Yr(t)}function Kr(e,r,t,i){let n=[],o=[],s={molecules:[]},{logger:l}=t,a={name:i,logger:l};ge(e,o,t),Ge(o,s,n,a),r.spectra.push(...pt(n,s,a)),r.molecules.push(...s.molecules)}function Zr(e,r){r.index!==void 0&&(e.spectra=e.spectra.slice(r.index,r.index+1))}var ee=class{id="@zakodium/nmrium-core-plugins#JCAMPDXLoaderPlugin";version=1;migrations=[];onReadProcess;constructor(){this.onReadProcess={supportedExtensions:["jcamp","jdx","dx"],onFile:this.onReadProcessFile.bind(this)}}onReadProcessFile(r,t={}){let{sourceSelector:i={},converter:n,keepSource:o,logger:s}=t;return s?.debug(`Reading JCAMP-DX file: ${r.name}`),Q(r,{selector:this.getJCAMPDXSelector(i),converter:n?.jcamp,keepSource:o,logger:s})}getJCAMPDXSelector(r={}){let{jcamp:t={},general:i={}}=r,{dataSelection:n="both"}=i;return{...t,dataSelection:n}}};function be(){return new ee}import{formatSpectra as rn,getOneIfArray as nn}from"@zakodium/nmrium-core";import{getGyromagneticRatio as on}from"gyromagnetic-ratio";import{isAnyArray as sn}from"is-any-array";import{parseJEOL as an}from"jeolconverter";import cn from"lodash.merge";import{normalizeNucleus as mn}from"nmr-processing";import{isAnyArray as $}from"is-any-array";var dt={0:"uint8",1:"uint16",2:"uint32",3:"uint64",4:"int8",5:"int16",6:"int32",7:"int64",8:"float32",9:"float64",10:"complex64",11:"complex128"},gt={0:"scalar",1:"vector",2:"matrix",3:"symetricMatrix",4:"pixel"};function yt(e,r,t={}){let{quantityType:i=0,encoding:n="none",name:o="",unit:s="",quantityName:l="",sparseSampling:a={},from:m=[0],to:u=[-1]}=t;if($(e))throw new Error("JEOL with an array of data is not yet supported");if(!("re"in e&&"im"in e))throw new Error("Only re/im data is supported");let c=Pe(e,m,u),{componentLabels:g=c.componentLabels}=t;return{type:"internal",quantityType:gt[i],numericType:dt[r],encoding:n,name:o,unit:s,quantityName:l,componentLabels:g,sparseSampling:a,description:t.description||"",application:t.application||"",components:c.components,dataLength:c.dataLength}}function Qr(e){return $(e.re)&&$(e.im)}function en(e){return!$(e.re[0])}function Pe(e,r,t){let i=[],n=[],o=[];if(Qr(e))if(en(e)){i[0]=Fe(r[0],t[0],e.re.length);let s=new Float64Array(i[0]);for(let l=0;l<i[0];l+=2){let a=l+r[0]*2;s[l]=e.re[a/2],s[l+1]=e.im[a/2]}o.push(s),n.push("complex")}else if($(e.re[0])){i[0]=tn(r[1],t[1],e.re.length),i[1]=Fe(r[0],t[0],e.re[0].length);for(let s=0;s<i[0];s++){let l=new Float64Array(i[1]);for(let a=0;a<i[1];a+=2){let m=a+r[0]*2;l[a]=e.re[s][m/2],l[a+1]=e.im[s][m/2]}o.push(l)}}else throw new Error("check your object");else if($(e.re.re)){i[0]=Fe(r[1],t[1],e.re.re.length);let s=Pe(e.re,r,t).components,l=Pe(e.im,r,t).components;for(let a=0;a<i[0]/2;a++)o.push(s[a],l[a])}else throw new Error("check the dimension or the type of data in your array");return{dataLength:i,componentLabels:n,components:o}}function tn(e,r,t){return r-e+1<t?r-e+1:t}function Fe(e,r,t){return r-e+1<t?(r-e+1)*2:t*2}async function bt(e,r={}){let t=await e.arrayBuffer(),{name:i=v(e.name),keepSource:n=!1}=r,o={spectra:[],molecules:[]},l=pn(t)[0],{metadata:a,...m}=l.description,u=0,c=m.dimension===1?"1d":"2d",g="NMR SPECTRUM",y=m.dimension===1?m.nucleus[0]:m.nucleus,d=m.spectralWidthClipped[0],p;l.dependentVariables&&(m.dimension===1?p=ln(l):m.dimension===2&&(p=un(l)));for(let F in m)Array.isArray(m[F])&&m[F].length===1&&(m[F]=m[F][0]);let f={data:p,info:{...m,acquisitionMode:u,experiment:c,type:g,nucleus:y,spectralWidthClipped:d,name:i},meta:a};return n&&(f.sourceSelector={files:[e.relativePath]}),o.spectra=[f],rn(o)}function ln(e){let r=e.dimensions[0],t=e.dependentVariables,i=r.quantityName,n=r.count,o=r.increment.magnitude,s=r.originOffset.magnitude,l=r.coordinatesOffset.magnitude,a=t[0].components[0],m=new Float64Array(n),u=new Float64Array(n);for(let p=a.length-1,f=0;p>0;p-=2)m[f]=a[p-1],u[f++]=a[p];let c={},[g,y]=[0,0];switch(i){case"frequency":y=0+l/s*1e6,g=o/s*1e6,c.re=m,c.im=u;break;case"time":y=s,g=o,c.re=m.reverse(),c.im=u.reverse().map(p=>-p);break;default:break}let d=[];for(let p=0;p<n;p++)d.push(y+p*g);return c.x=d,c}function un(e){let r=e.dimensions,t=e.dependentVariables,i=r[0].quantityName,n=[],o=[],s=Number.MIN_SAFE_INTEGER,l=Number.MAX_SAFE_INTEGER,a=Number.MAX_SAFE_INTEGER,m=Number.MIN_SAFE_INTEGER;for(let g of t[0].components){let y=new Float64Array(g.length/2),d=new Float64Array(g.length/2);for(let p=g.length-1,f=0;p>0;p-=2){let F=g[p-1],h=g[p];F>s&&(s=F),F<l&&(l=F),h>m&&(m=h),h<a&&(a=h),y[f]=F,d[f++]=h}if(i==="frequency")n.push(y),o.push(d);else{let p=y.length,f=new Float64Array(d.length);for(let F=0,h=p-1;F<p;F++)f[F]=-d[h--];n.push(y.reverse()),o.push(f)}}let u={re:{z:n,minZ:l,maxZ:s},im:{z:o,minZ:a,maxZ:m}},c=["X","Y"];for(let g=0;g<c.length;g++){let y=r[g].count,d=r[g].increment.magnitude,p=r[g].originOffset.magnitude,f=r[g].coordinatesOffset.magnitude,F=c[g];for(let h of["re","im"])i==="frequency"?(u[h][`min${F}`]=0+f/p*1e6,u[h][`max${F}`]=y*(d/p)*1e6):(u[h][`min${F}`]=p,u[h][`max${F}`]=y*d)}return u}function pn(e){let r=an(e),t=r.info,i=r.headers,n=r.parameters,{dimension:o}=t,s={};for(let f of n.paramArray){let{name:F,value:h}=f;s[F]=Ft(h,o)}delete n.paramArray;let l=r.data,a={};a.title=`title: ${i.title} / comment: ${i.comment} / author:${i.author} / site: ${i.site}`,a.nucleus=t.nucleus.map(mn),a.sampleName=t.sampleName,a.date=t.date,a.epoch=t.epoch,a.localeDate=new Date(nn(t.epoch)).toLocaleString(),a.author=t.author,a.solvent=t.solvent,a.temperature=t.temperature.magnitude,a.probeName=t.probeName||"",a.fieldStrength=t.fieldStrength.magnitude;let m=a.nucleus.map(on);a.baseFrequency=m.map(f=>t.fieldStrength.magnitude*f/(2*Math.PI*1e6)),a.pulseSequence=t.experiment,a.temperature=t.temperature?.unit?.toLowerCase()==="celsius"?273.15+t.temperature.magnitude:t.temperature.magnitude,a.digitalFilter=t.digitalFilter,a.pulseStrength90=1/(4*t.pulseStrength90.magnitude),a.numberOfScans=t.numberOfScans,a.relaxationTime=t.relaxationTime.magnitude,a.isComplex=t.dataSections.includes("im"),a.isFid=t.dataUnits[0]==="Second",a.isFt=t.dataUnits[0]==="Ppm",a.dimension=t.dimension,a.originFrequency=t.originFrequency.map(f=>f.magnitude/1e6).slice(0,o),a.numberOfPoints=t.dataPoints.slice(0,1),a.frequencyOffset=t.frequencyOffset.map((f,F)=>f.magnitude*a.baseFrequency[F]).slice(0,o),a.acquisitionTime=t.acquisitionTime.map(f=>f.magnitude).slice(0,o),a.spectralWidth=t.spectralWidth.map((f,F)=>f.magnitude/t.originFrequency[F].magnitude*1e6).slice(0,o),a.spectralWidthClipped=t.spectralWidthClipped.map((f,F)=>f.magnitude/a.baseFrequency[F]*1e6).slice(0,o);let u=[],c={},g;for(let f=0;f<t.dimension;f++){if(g={magnitude:t.acquisitionTime[f].magnitude/(t.dataPoints[f]-1),unit:"s"},t.dataUnits[f]==="Second")c.quantityName="time",c.originOffset={magnitude:0,unit:"s"},f===0?c.coordinatesOffset={magnitude:t.digitalFilter*g.magnitude,unit:"s"}:c.coordinatesOffset={magnitude:0,unit:"s"},c.reciprocal={originOffset:{magnitude:t.originFrequency[f].magnitude,unit:"Hz"},quantityName:"frequency",coordinatesOffset:{magnitude:t.frequencyOffset[f].magnitude*t.originFrequency[f].magnitude/1e6,unit:"Hz"}};else if(t.dataUnits[f]==="Ppm"){c.quantityName="frequency";let F=t.originFrequency[f].magnitude;c.originOffset={magnitude:F,unit:"Hz"};let h=t.dataOffsetStart[f],N=t.dataOffsetStop[f]-h+1;g={magnitude:fn(t,f)/(N-1),unit:"Hz"};let R=t.dataAxisStop[f]*F/1e6;c.coordinatesOffset={magnitude:R,unit:"Hz"},N!==t.dataPoints[f]&&(t.dataPoints[f]=N)}f===0?c.description="direct dimension":c.description="indirect dimension",u.push({label:String(i.dataAxisTitles[f]),count:Number(t.dataPoints[f]),increment:g,type:"linear",description:String(c.description)||"",application:c.application||{},coordinatesOffset:c.coordinatesOffset||0,originOffset:c.originOffset||0,quantityName:String(c.quantityName)||"",reciprocal:c.reciprocal||{},period:c.period||0,complexFFT:c.complexFFT||!1})}let y=[];y.push(yt(l,11,{unit:"none",quantityName:"relative intensity",from:t.dataOffsetStart,to:t.dataOffsetStop}));let d={...a};return delete d.paramList,d.metadata={...ht(i,o),...ht(n,o),...cn({},s)},[{timeStamp:Date.now(),description:d,dimensions:u,dependentVariables:y}]}function fn(e,r){let{spectralWidth:t,spectralWidthClipped:i}=e;return i[r].magnitude!=="NA"?i[r].magnitude:t[r].magnitude}function ht(e,r){let t={};for(let i in e)t[i]=Ft(e[i],r);return t}function Ft(e,r){return sn(e)?r>1?e.slice(0,r):e[0]:e}var te=class{id="@zakodium/nmrium-core-plugins#JEOLLoaderPlugin";version=1;migrations=[];onReadProcess;constructor(){this.onReadProcess={supportedExtensions:["jdf"],onFile:this.onReadProcessFile.bind(this)}}onReadProcessFile(r,t={}){let{logger:i,keepSource:n}=t;return i?.debug(`Reading JEOL file: ${r.name}`),bt(r,{name:r.name,keepSource:n,logger:i})}};function Ne(){return new te}var re=class{id="@zakodium/nmrium-core-plugins#MolfileLoaderPlugin";version=1;migrations=[];onReadProcess;constructor(){this.onReadProcess={supportedExtensions:["mol"],onFile:this.onReadProcessFile.bind(this)}}onReadProcessFile(r,t={}){let{logger:i}=t;return i?.debug(`Reading molfile file: ${r.name}`),Ve(r,{logger:i})}};function De(){return new re}import{getSDF as Fn,nmrRecordToJSON as Pn}from"nmredata";import{generateID as Dt}from"@zakodium/nmrium-core";import{generateID as Pt}from"@zakodium/nmrium-core";import{xyIntegration as dn}from"ml-spectra-processing";function Nt(e,r){let{x:t,re:i}=r.data;return e.map(n=>{let o=dn({x:t,y:i},{from:n.from,to:n.to}),s=[];for(let l of n.signals||[]){let{kind:a=null,id:m,js:u=[],diaIDs:c=[],...g}=l;s.push({...g,kind:a||"signal",js:u,id:m||Pt(),diaIDs:c})}return{...n,id:n.id||Pt(),kind:s?.[0].kind||"signal",absolute:o,signals:s}})}function St(e,r){let t=[],{baseFrequency:i=500}=r.info;for(let n of e){let{delta:o,diaIDs:s=[],multiplicity:l="",integration:a=0}=n,m=n.jCoupling||[],u=gn({delta:o,js:m,frequency:i});if(m&&l&&m.length===l.length){m.sort((c,g)=>g.coupling-c.coupling);for(let c=0;c<m.length;c++)m[c].multiplicity=l[c]}t.push({id:Dt(),...u,integration:a,signals:[{id:Dt(),js:m,delta:o,diaIDs:s,multiplicity:l}]})}r.ranges.values=Nt(q(t),r)}function gn(e){let{delta:r,js:t=[],frequency:i}=e,n=.5;for(let o of t)n+=o.coupling;return n/=i,{from:r-n,to:r+n}}import{generateID as Rt}from"@zakodium/nmrium-core";var yn=["x","y"],hn={x:0,y:0};function Mt(e,r,t={}){let i=[],{shift:n=hn}=t,{originFrequency:o=[400,400]}=r.info,s={x:o[0],y:o[1]};for(let l of e){let a={x:{},y:{},id:Rt(),kind:"signal"},m={id:Rt(),kind:"signal",peaks:[]},u={x:10,y:10};for(let c of yn){let{coupling:g=[],delta:y,diaIDs:d=[]}=l[c];for(let p of g)u[c]+=p.coupling;if(l.activeCoupling){let{activeCoupling:p=[]}=l;for(let f of p)u[c]+=f.coupling}u[c]/=s[c],a[c]={from:y-u[c],to:y+u[c]},m[c]={delta:y,diaIDs:d,originalDelta:y-n[c]}}i.push({...a,signals:[m]})}r.zones.values=i}function At(e){return bn(e.data)}function bn(e){return"rr"in e||!("x"in e)&&"re"in e}async function xt(e,r,t={}){let i={spectra:[],molecules:[]},n=await Nn(e,r,t);if(n.spectra.length>0){let{spectra:o,molecules:s,usedFiles:l}=n;i.spectra.push(...o),i.molecules.push(...s);let a=e.files.length;for(let m=a-1;m>=0;m--){let u=e.files[m].relativePath;!u.match(/acqu.*/s)&&l.includes(u)&&e.files.splice(m,1)}}return i}async function Nn(e,r,t){let i=[],n=await Fn(e),o={spectra:[],molecules:[]};if(n.length===0)return{...o,usedFiles:i};let s=[];for(let a of n){let m=Pn({sdf:a,fileCollection:e}).then(u=>{let{spectra:c,molecules:g=[]}=u;return i.push(a.root+a.filename),o.molecules.push(...g),Dn(c,r,t)});s.push(m)}let l=await Promise.allSettled(s);for(let a of l)a.status==="fulfilled"?(o.spectra.push(...a.value.spectra),i.push(...a.value.usedFiles)):a.reason&&t?.logger?.error(a.reason);return{...o,usedFiles:i}}async function Dn(e,r,t){let i=[],n=[],o={spectra:[],molecules:[]};for(let s of e){let l=Sn(s.source,r,t).then(a=>{let{spectra:m,files:u}=a;i.push(...u);for(let c of m)At(c)?Mt(s.signals,c):St(s.signals,c);o.spectra.push(...m)});n.push(l)}return await Promise.allSettled(n),{...o,usedFiles:i}}async function Sn(e,r,t={}){let{file:i,jcampURL:n}=e,{converter:o}=t;if(n){let a=await Rn(n,r,o?.jcamp);if(a)return{...a,files:[]}}let s=[];for(let a of i||[])s.push(Mn(a,t).then(m=>({...m,files:a.fileCollection.files.map(u=>u.relativePath)})));let l=await Promise.allSettled(s);for(let a of l){if(a.status==="fulfilled")return a.value;a.reason&&t?.logger?.error(a.reason)}return{spectra:[],molecules:[],files:[]}}async function Rn(e,r,t={}){let i={entries:[{relativePath:e}]},n={name:v(e||""),xy:!0,noContours:!0,...t},{data:o}=await r.readFromWebSource(i,n);return o}async function Mn(e,r={}){let{converter:t,sourceSelector:i}=r;switch(e.type){case"jcamp":return Q(e.fileCollection.files[0],{name:e?.fileCollection.files[0].name||"",converter:t?.jcamp,selector:i?.jcamp,logger:r.logger,keepSource:r.keepSource});case"brukerFiles":return G(e.fileCollection,{converter:t?.bruker,selector:i});default:throw new Error("There is not a supported source")}}var ne=class{constructor(r){this.core=r;this.onReadProcess={onFiles:this.onReadProcessFiles}}id="@zakodium/nmrium-core-plugins#NMReDATALoaderPlugin";version=1;migrations=[];onReadProcess;onReadProcessFiles=(r,t)=>xt(r,this.core,t)};function Se(e){return new ne(e)}import{parse as An}from"sdf-parser";function Ct(e,r={}){let{mixedEOL:t}=r,{molecules:i}=An(e,{mixedEOL:t}),n=[];for(let{molfile:o}of i){let s=w(o);n.push(...s)}return n}async function Ot(e,r={}){let{logger:t,mixedEOL:i}=r,n=await e.text(),o=Ct(n,{mixedEOL:i}),s={molecules:o,spectra:[]};return t&&t[o.length>0?"info":"debug"](`Loaded ${s.molecules.length} molecules from the ${e.name} file`),s}var ie=class{id="@zakodium/nmrium-core-plugins#SDFLoaderPlugin";version=1;migrations=[];onReadProcess;constructor(){this.onReadProcess={supportedExtensions:["sdf"],onFile:this.onReadProcessFile.bind(this)}}onReadProcessFile(r,t={}){let{logger:i}=t;return i?.debug(`Reading sdf file: ${r.name}`),Ot(r,{logger:i})}};function Re(){return new ie}import{Molecule as xn}from"openchemlib";function It(e){let r=[],t=e.split(/\r?\n/).filter(Boolean);for(let i of t){let o=xn.fromSmiles(i).toMolfile();r.push({molfile:o})}return r}async function Tt(e,r={}){let t=await e.text(),i=It(t),n={molecules:i,spectra:[]};return r.logger?.info(`Found ${i.length} molecules from the ${e.name} file`),n}var oe=class{id="@zakodium/nmrium-core-plugins#SMILESLoaderPlugin";version=1;migrations=[];onReadProcess;constructor(){this.onReadProcess={supportedExtensions:["smi","smiles"],onFile:this.onReadProcessFile.bind(this)}}onReadProcessFile(r,t={}){let{logger:i}=t;return Tt(r,{logger:i})}};function Me(){return new oe}import{formatSpectra as In}from"@zakodium/nmrium-core";import{FileCollection as Tn}from"filelist-utils";import{isAnyArray as En}from"is-any-array";import{xMultiply as Ln}from"ml-spectra-processing";import{convert1D as kn}from"varian-converter";import{normalizeNucleus as Cn}from"nmr-processing";function Et(e,r){let{meta:t,procpar:i}=e,n={};for(let h of i)n[h.name]=h.values;let o={},s={},{np:l,solvent:a,sfrq:m,reffrq:u,temp:c,rp:g,sw:y,rfl:d,rfp:p}=n;P(o,"numberOfPoints",l&&Number(O(l))/2),P(o,"solvent",O(a)),P(o,"originFrequency",O(m)),P(o,"baseFrequency",O(u)),(Number.isNaN(o.originFrequency)||o.originFrequency===0)&&(o.originFrequency=400,r?.warn("The frequency could not be determined and was set to 400MHz")),P(o,"temperature",O(c)),P(o,"phc0",g&&Number(g[0])),P(s,"rfl",d&&Number(O(d))),P(s,"rfp",p&&Number(O(p))),P(s,"sw",y&&Number(O(y)));for(let h in s){let b=s[h];Array.isArray(b)&&b.length===1&&(s[h]=b[0])}if(!("baseFrequency"in o)&&"originFrequency"in o){let h=Number.parseFloat(o.originFrequency);if(["sw","rfl","rfp"].every(b=>b in s)){let{sw:b=1,rfl:N=1,rfp:S=1}=On(s,["sw","rfl","rfp"]);P(o,"baseFrequency",h-(b/2-N+S)/1e6)}else P(o,"baseFrequency",h)}let{baseFrequency:f,originFrequency:F}=o;P(o,"frequencyOffset",(F-f)*1e6),P(o,"spectralWidth",y&&Number(y[0])/o.baseFrequency);for(let h in o)o[h].length===1&&(o[h]=o[h][0]);return n.tn&&(o.nucleus=n.tn.map(Cn)),o.dimension=1,o.isFid=!t.status.isSpectrum,{info:o,meta:{...s,...Lt(t),...n}}}function O(e){return e&&(Array.isArray(e)?e[0]:e)}function On(e,r){let t={};for(let i of r){let n=e[i];n&&typeof n=="number"&&(t[i]=n)}return t}function Lt(e){let r={};for(let t of Object.keys(e)){let i=e[t];typeof i=="object"&&i!==null&&i.constructor&&i.constructor!==Object?r[t]=Lt(i):r[t]=i}return r}function kt(e){let r={},t=new Set(e.files.map(i=>i.relativePath));for(let i of e){let n=i.name.toLowerCase();if(n.match(/^(?:fid|procpar|text|log)$/)){if(n.match(/^(?:fid|text|log)$/)){let l=i.relativePath.replace(/(?:fid|text|log)$/,"procpar");if(!t.has(l))continue}let o=i.relativePath.split("/"),s=o.slice(0,-1).join("/");r[s]||(r[s]={name:o.at(-2),files:[]}),r[s].files.push(i)}}return Object.values(r)}async function wt(e,r={}){let{keepSource:t,logger:i}=r,n=kt(e);i&&i.debug(`Found ${Object.keys(n).length} varian experiments`);let o=[],s={spectra:[],molecules:[]};for(let a of n){let{name:m,files:u}=a,c=new Tn(u),g=kn(c).then(y=>{let{info:d,meta:p}=Et(y),f=y.fid.data[0],F=En(f.im),h={data:{...f,x:y.x},meta:p,info:{isComplex:F,name:m,...d},display:{name:m}};if(d.isFid&&F){let{im:b}=h.data;Ln(b,-1,{output:b})}u&&t&&(h.sourceSelector={files:u.map(b=>b.relativePath)}),s.spectra.push(h)});o.push(g)}let l=await Promise.allSettled(o);for(let a=0;a<l.length;a++){let m=l[a];if(m.status==="rejected"&&m.reason){let u=n[a].name;i?.warn(`Varian data: ${u}, fails with: ${m.reason}`)}}return s.spectra.length>0&&i?.info(`Loaded ${s.spectra.length} spectra from Varian files`),In(s)}var se=class{id="@zakodium/nmrium-core-plugins#VarianLoaderPlugin";version=1;migrations=[];onReadProcess;constructor(){this.onReadProcess={onFiles:this.onReadProcessFiles}}onReadProcessFiles=(r,t)=>{let{keepSource:i,logger:n}=t??{};return wt(r,{keepSource:i,logger:n})}};function Ae(){return new se}function vn(e,r=[]){return[Se(e),Ae(),de(),be(),De(),Re(),Me(),Ne(),ue()].concat(r)}function qn(){let e=new wn;return e.registerPlugins(vn(e)),e}import{getOneIfArray as qt}from"@zakodium/nmrium-core";import{from1DNMRVariables as $n}from"convert-to-jcamp";function vt(e,r){return e.filters.find(t=>t.name===r)}function jn(e,r={}){let{info:t,meta:i,data:n}=e,{onlyReal:o=!1}=r,{isFid:s,spectralWidth:l}=t,a=qt(t.baseFrequency||t.originFrequency),{x:m,re:u,im:c}=n,g=new Float64Array(u),y=!o&&c?new Float64Array(c):void 0,d={};B(d,"SW",l),B(d,"BF1",a);let p=vt(e,"fft")?.enabled,f={originFrequency:t.originFrequency,dataType:!t.isFid||p?"NMR SPECTRUM":"NMR FID",dataClass:!o&&c?"NTUPLES":"XYDATA"};if(s){let b=e.filters.find(N=>N.name==="digitalFilter");if(b&&!p){let{value:{digitalFilterValue:N},enabled:S}=b;if(S){let D=Math.floor(N);g.set(u.slice(u.length-D)),g.set(u.slice(0,u.length-D),D),c&&y&&(y.set(c.slice(c.length-D)),y.set(c.slice(0,c.length-D),D))}}B(f,"decim",t.decim),B(f,"dspfvs",t.dspfvs),B(f,"digitalFilter",t.digitalFilter)}let F={xyEncoding:"DIFDUP",info:{...t,...f},meta:{...i,...d}},h={x:{data:m,label:t.isFid?"TIME":"FREQUENCY",units:t.isFid?"second":"HZ",symbol:"X"},r:{data:g,label:`${t.isFid?"FID":"SPECTRUM"}/REAL`,units:"ARBITRARY UNITS",symbol:"R"}};return y&&(h.i={data:y,label:`${t.isFid?"FID":"SPECTRUM"}/IMAG`,units:"ARBITRARY UNITS",symbol:"I"}),$n(h,F)}function B(e,r,t){t!==void 0&&(e[r]=qt(t))}export{W as AutoPostProcessingPlugin,K as BrukerLoaderPlugin,ee as JCAMPDXLoaderPlugin,te as JEOLLoaderPlugin,re as MolfileLoaderPlugin,ne as NMReDATALoaderPlugin,ie as SDFLoaderPlugin,oe as SMILESLoaderPlugin,se as VarianLoaderPlugin,ue as autoPostProcessing,de as brukerLoader,qn as default,qn as init,be as jcampDXLoader,Ne as jeolLoader,De as molfileLoader,Se as nmreDATALoader,ft as processJCAMPDX,Ct as readSDF,It as readSMILES,vn as recommended,Re as sdfLoader,Me as smilesLoader,jn as spectrum1DToJCAMPDX,Ae as varianLoader};
|