@zakodium/nmrium-core-plugins 0.3.2 → 0.3.4
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/dist/nmrium-core-plugins.js +10 -10
- package/package.json +6 -6
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
var ni=Object.defineProperty;var xt=(e,t)=>{for(var r in t)ni(e,r,{get:t[r],enumerable:!0})};import{NMRiumCore as ya}from"@zakodium/nmrium-core";import{defineNMRiumPlugin as yi}from"@zakodium/nmrium-core";import{Filters1D as ui,Filters2D as pi}from"nmr-processing";import{getOneIfArray as ii}from"@zakodium/nmrium-core";function ce(e={},t={},r={}){e===null&&(e={}),typeof e=="string"&&(e={pulseSequence:e});let n=Array.isArray(e.pulseSequence)?e.pulseSequence[0]:e.pulseSequence||"";if(typeof n!="string")return e.dimension?`${e.dimension}d`:"";if(n=n.toLowerCase(),n.includes("zg")||n.includes("single_pulse_dec")||n.includes("udeft"))return"1d";if(n.includes("hsqct")||n.includes("invi")&&(n.includes("ml")||n.includes("di")))return"hsqctocsy";if(n.includes("hsqc")||n.includes("invi"))return"hsqc";if(n.includes("hmbc")||n.includes("inv4")&&n.includes("lp"))return"hmbc";if(n.includes("hmqc"))return"hmqc";if(n.includes("cosy"))return"cosy";if(n.includes("jres"))return"jres";if(n.includes("dosy"))return"dosy";if(n.includes("tocsy")||n.includes("mlev")||n.includes("dipsi"))return"tocsy";if(n.includes("noesy"))return"noesy";if(n.includes("roesy"))return"roesy";if(n.includes("dept"))return"dept";if(n.includes("jmod")||n.includes("apt"))return"aptjmod";if(n.includes("inad"))return"inadequate";if(n.includes("adeq"))return"adequate";let{prefix:i=""}=r,o=(ii(t[`${i}SPECTYP`])||"").replace(/^<(.*)>$/,"$1").toLowerCase();return o.length>0&&o!=="undefined"?o:e.dimension?`${e.dimension}d`:""}import{getOneIfArray as Dt}from"@zakodium/nmrium-core";var oi=["no","exponential","modifiedGaussian","sine","qsine","trap","user","sinc","qsinc","traf","trafs"];function si(e){return e in St}function qe(e,t){let{prefix:r="",index:n=0}=t,i=Dt(e[`${r}WDW`],n),o=oi[i?Number(i):0],s={};if(!si(o))return s;let a=St[o];if(a){let{kind:c,parameters:l}=a,m={};for(let p in l){let f=l[p],{source:g,processor:y}=f;if(g){let u=Dt(e[`${r}${g}`],n);if(!u)continue;let h=Number(u);m[p]=y?y(h):h}else f.value!==void 0&&(m[p]=f.value)}s[c]={apply:!0,options:m}}return s}var St={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 At={sineBell:Mt({offset:0})},It={cosy:{...At},hmbc:{...At},hsqc:{sineBell:Mt({offset:.5})}},ai={...It};function je(e="",t=1){let r=ci(e),n={},i=t===1?It[r||""]:ai[r||""];return i&&(n=structuredClone(i)),n}function Mt(e){return{apply:!0,options:e}}function ci(e){let r=e.toLowerCase().match(/cosy|hsqc|hmbc/);return r?r[0]:null}function Nt(e,t={}){let{prefix:r="",experiment:n=ce(e)}=t;return e[`${r}WDW`]?{f2:qe(e,{...t,index:0}),f1:qe(e,{...t,index:1})}:{f2:je(n,1),f1:je(n,2)}}import{Filters1D as li}from"nmr-processing";var Be=["digitalFilter","backwardLinearPrediction","forwardLinearPrediction","apodization","zeroFilling","fft",["shiftX","phaseCorrection","baselineCorrection"]],W={};for(let e=0;e<Be.length;e++){let t=Be[e];for(let r of Array.isArray(t)?t:[t])W[r]=e}for(let e of Object.values(li))e.name in W||(W[e.name]=Be.length);import{Filters2D as mi}from"nmr-processing";var Ue=["digitalFilter2D","blpDimension1","flpDimension1","apodizationDimension1","zeroFillingDimension1","fftDimension1","blpDimension2","flpDimension2","nusDimension2","apodizationDimension2","zeroFillingDimension2","fftDimension2","phaseCorrectionTwoDimensions",["shift2DX","shift2DY","symmetrizeCosyLike"]],X={};for(let e=0;e<Ue.length;e++){let t=Ue[e];for(let r of Array.isArray(t)?t:[t])X[r]=e}for(let e of Object.values(mi))e.name in X||(X[e.name]=Ue.length);var fi=new Set([]);function di(e,t){let{filter:r,experimentalFeatures:n=!1}=t,{name:i}=r;({...ui,...pi})[i]&&(e.some(s=>s.name===i)||fi.has(i)&&!n||e.push({...r,enabled:!0}))}function Pt(e,t={}){let{data:r}=e;if(!r)return;let{autoProcessing:n,experimentalFeatures:i}=t,o=(a,c)=>di(a,{...c,experimentalFeatures:i}),{spectra:s}=r;for(let a of s){let{data:c,info:l,meta:m,filters:p}=a,{dimension:f,isFid:g}=l;if(g){if(f===1){let y=c.re.length,{tdOff:u,digitalFilter:h}=l;if(h&&h>0&&o(p,{filter:{name:"digitalFilter",value:{digitalFilterValue:h}}}),!n)continue;u&&Math.abs(u)>0&&o(p,{filter:{name:"backwardLinearPrediction",value:{nbInputs:y/2}}}),o(p,{filter:{name:"apodization",value:{exponential:{apply:!0,options:{lineBroadening:1}}}}}),o(p,{filter:{name:"zeroFilling",value:{nbPoints:2*y}}}),o(p,{filter:{name:"fft",value:{}}}),o(p,{filter:{name:"phaseCorrection",value:gi(l)}}),p.sort((d,b)=>W[d.name]-W[b.name])}else if(f===2){if(!n)continue;let y=c.re.z.length,u=c.re.z[0].length,{tdOff:h,experiment:d=""}=l,b=l.spectrumSize;Array.isArray(b)&&b.length>1?(b[0]<=u&&(b[0]=u*2),b[0]<=y&&(b[0]=y*2)):b=[u*2,2*y];let F=d.toLowerCase().includes("cosy");h&&Math.abs(h[0])>0&&o(p,{filter:{name:"blpDimension1",value:{nbInputs:u/2}}});let S=Nt(m,{experiment:d});o(p,{filter:{name:"apodizationDimension1",value:S.f2}}),o(p,{filter:{name:"zeroFillingDimension1",value:{nbPoints:b[0]}}}),o(p,{filter:{name:"fftDimension1",value:{}}}),m&&"nuslist"in m&&o(p,{filter:{name:"nusDimension2",value:{}}}),o(p,{filter:{name:"apodizationDimension2",value:S.f1}}),o(p,{filter:{name:"zeroFillingDimension2",value:{nbPoints:b[F?0:1]}}}),F?o(p,{filter:{name:"symmetrizeCosyLike",value:{}}}):o(p,{filter:{name:"phaseCorrectionTwoDimensions",value:{}}}),o(p,{filter:{name:"fftDimension2",value:{}}}),p.sort((I,x)=>X[I.name]-X[x.name])}}}}function gi(e){let{phc0:t=0,phc1:r=0}=e;return Et([t,r])?{}:{ph0:t,ph1:r}}function Et(e){return Array.isArray(e)?e.every(t=>!t&&t===0):Et([e])}function $e(){return yi({id:"@zakodium/nmrium-core-plugins#AutoPostProcessingPlugin",version:1,migrations:[],onReadProcess:{onProcessing:Pt}})}import{defineNMRiumPlugin as xo}from"@zakodium/nmrium-core";import{FileCollection as qc}from"file-collection";var Tt=["acqus","acqu2s"],le=["procs","proc2s"];function Ot(e){return e.is1D?hi(e):e.is2D?bi(e):{checked:!1,message:"Multi-dimensional n > 2 is not supported"}}function hi(e){let t=e.isFID?["acqus"]:["acqus","procs"],r=t.every(n=>e[n]);return{checked:r,message:r?"":`File: ${e[e.isFID?"fid":"1r"]?.relativePath} is ignored, files: ${t.join(",")} are required.`}}function bi(e){let t=e.isFID?Tt:Tt.concat(le),r=t.every(n=>e[n]);return r&&e.isFID&&le.some(n=>e[n])&&!le.every(n=>e[n])&&(r=!1,t.push(...le)),{checked:r,message:r?"":`File: ${e.name} is ignored, files: ${t.join(",")} are required.`}}function ze(e,t={}){let{logger:r,processingNumbers:n,experimentNumbers:i,dataSelection:o="both",keep1D:s=!0,keep2D:a=!0,onlyFirstProcessedData:c=!0}=t,l={},m=e.files.map(g=>g.relativePath);for(let g of e){let y,u,h,d=g.relativePath.split("/"),b=d.indexOf("pdata");if(b!==-1)y=Number(d[b+1]),u=Number(d[b-1]),h=d.slice(0,-3).join("/");else if(xi(g,m)){let S=d.indexOf(g.name);u=Number(d[S-1]),h=d.slice(0,-1).join("/")}else continue;if(Number.isNaN(u)&&(u=void 0),Number.isNaN(y)&&(y=void 0),i&&!i.includes(u))continue;l[h]||(l[h]={name:h,expno:u,processedData:{},fileCollectionItems:[]});let F=l[h];if(g.name==="vdlist"&&(F.vdlist=g),g.name==="difflist"&&(F.difflist=g),y){F.processedData||(F.processedData={}),F.processedData[y]||(F.processedData[y]={fileCollectionItems:[],name:h,expno:u,procno:y});let S=F.processedData[y];S.fileCollectionItems.push(g),g.name.match(/^(?:1r|1i|2rr|2ir|2ii|2ri|procs|proc2s|title|integrals.txt)$/)&&(S[g.name]=g),g.name==="2rr"&&(S.is2D=!0,S.isFT=!0),g.name==="1r"&&(S.is1D=!0,S.isFT=!0)}else F.fileCollectionItems.push(g),g.name.match(/^(?:ser|fid|acqus|acqu2s|nuslist)$/)&&(F[g.name]=g),g.name==="ser"&&(F.is2D=!0,F.isFID=!0),g.name==="fid"&&(F.is1D=!0,F.isFID=!0);g.name==="QuantFactorSample.xml"&&(F.quantFactorSample=g)}if(n)for(let g in l){let y=l[g].processedData,u={};for(let h in y)n.includes(Number.parseInt(h,10))&&(u[h]=y[h]);l[g].processedData=u}else if(c)for(let g in l){let y=l[g].processedData,u=Object.keys(y??{});u.sort((d,b)=>Number(d)-Number(b));let h=u[0];y&&h!==void 0&&(l[g].processedData={firstProcessedNumber:y[h]})}let p=Di(r),f=[];for(let g in l){let y=l[g],{processedData:u,...h}=y;if(p(y,o)){let b=Object.keys(u??{});if(u&&b.length>0){let F=u[b[0]];F.procs&&(h.fileCollectionItems.push(F.procs),h.procs=F.procs),F.proc2s&&(h.fileCollectionItems.push(F.proc2s),h.proc2s=F.proc2s),F["integrals.txt"]&&(h.integrals=F["integrals.txt"])}f.push(h)}let d="ser"in h||"fid"in h;if(o==="fid"||o==="preferFID"&&d){r?.warn("Skipping FT data because it does not match the import filters");continue}for(let b in u){let F=u[b];(F["1r"]||F["2rr"])&&(h.acqus&&F.fileCollectionItems.push(h.acqus),h.acqu2s&&F.fileCollectionItems.push(h.acqu2s),h.vdlist&&(F.vdlist=h.vdlist),f.push({integrals:F["integrals.txt"],acqus:h.acqus,acqu2s:h.acqu2s,...F}))}}return s||(r?.warn("Skipping 1D data because it does not match the import filters"),f=f.filter(g=>!g.is1D)),a||(r?.warn("Skipping 2D data because it does not match the import filters"),f=f.filter(g=>!g.is2D)),Fi(f,t.logger)}function Fi(e,t){return e.filter(r=>{let{checked:n,message:i}=Ot(r);return n||t?.warn(i),n})}function xi(e,t){return e.name.match(/^(?:ser|acqus|acqu2s|nuslist|vdlist|difflist|QuantFactorSample.xml)$/)||e.name.match(/^fid$/)&&t.includes(e.relativePath.replace(/fid$/,"acqus"))}function Di(e){return(t,r)=>{let{processedData:n}=t,i=Object.keys(n??{}),o=n&&i.length>0&&["1r","1i","2rr"].some(m=>m in n[i[0]]),s="ser"in t||"fid"in t,l=s&&(r!=="ft"&&r!=="preferFT"||r==="preferFT"&&!o);return s&&!l&&e?.warn("Skipping RAW data because it does not match import filters"),l}}function me(e){if(e===void 0||Array.isArray(e)&&e.length===0)return{epoch:null,date:""};let t=e[0]*1e3;return{epoch:t,date:new Date(t).toUTCString()}}function ue(e,t){for(let r in t.meta)e.meta[r]===void 0&&(e.meta[r]=t.meta[r]);for(let r in t.info)e.info[r]===void 0&&(e.info[r]=t.info[r]);for(let r in e.meta)Array.isArray(e.meta[r])||(e.meta[r]=[e.meta[r]])}import{convert as Si}from"jcampconverter";async function _(e,t){if(!e)return Ct();let r=await e.text(),{keepRecordsRegExp:n=/.*/}=t,i=Si(r,{keepRecordsRegExp:n});return i.flatten.length===0?Ct():i.flatten[0]}function Ct(){return{info:{},meta:{},tmp:{},spectra:[],ntuples:{}}}async function Rt(e){let r=(await e.integrals?.text())?.split(/\r?\n/).slice(3).filter(Boolean)??[],n=[];for(let i=1;i<r.length;i++){let o=r[i].replace(/^\s*/,"").replaceAll(/[\s\t]+/g,";").match(/\d+;(?<from>[0-9.]+);(?<to>[0-9.]+);(?<integration>[0-9.]+)/)?.groups;if(o){let{from:s,to:a,integration:c}=o;n.push({from:Number.parseFloat(s),to:Number.parseFloat(a),integration:Number.parseFloat(c)})}}return n}function Je(e,t="utf8"){return new TextDecoder(t).decode(e)}var Ai=new TextEncoder;function wt(e){return Ai.encode(e)}var Ii=1024*8,Mi=(()=>{let e=new Uint8Array(4),t=new Uint32Array(e.buffer);return!((t[0]=1)&e[0])})(),We={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},R=class e{buffer;byteLength;byteOffset;length;offset;lastWrittenByte;littleEndian;_data;_mark;_marks;constructor(t=Ii,r={}){let n=!1;typeof t=="number"?t=new ArrayBuffer(t):(n=!0,this.lastWrittenByte=t.byteLength);let i=r.offset?r.offset>>>0:0,o=t.byteLength-i,s=i;(ArrayBuffer.isView(t)||t instanceof e)&&(t.byteLength!==t.buffer.byteLength&&(s=t.byteOffset+i),t=t.buffer),n?this.lastWrittenByte=o:this.lastWrittenByte=0,this.buffer=t,this.length=o,this.byteLength=o,this.byteOffset=s,this.offset=0,this.littleEndian=!0,this._data=new DataView(this.buffer,s,o),this._mark=0,this._marks=[]}available(t=1){return this.offset+t<=this.length}isLittleEndian(){return this.littleEndian}setLittleEndian(){return this.littleEndian=!0,this}isBigEndian(){return!this.littleEndian}setBigEndian(){return this.littleEndian=!1,this}skip(t=1){return this.offset+=t,this}back(t=1){return this.offset-=t,this}seek(t){return this.offset=t,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 t=this._marks.pop();if(t===void 0)throw new Error("Mark stack empty");return this.seek(t),this}rewind(){return this.offset=0,this}ensureAvailable(t=1){if(!this.available(t)){let n=(this.offset+t)*2,i=new Uint8Array(n);i.set(new Uint8Array(this.buffer)),this.buffer=i.buffer,this.length=n,this.byteLength=n,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(t=1){return this.readArray(t,"uint8")}readArray(t,r){let n=We[r].BYTES_PER_ELEMENT*t,i=this.byteOffset+this.offset,o=this.buffer.slice(i,i+n);if(this.littleEndian===Mi&&r!=="uint8"&&r!=="int8"){let a=new Uint8Array(this.buffer.slice(i,i+n));a.reverse();let c=new We[r](a.buffer);return this.offset+=n,c.reverse(),c}let s=new We[r](o);return this.offset+=n,s}readInt16(){let t=this._data.getInt16(this.offset,this.littleEndian);return this.offset+=2,t}readUint16(){let t=this._data.getUint16(this.offset,this.littleEndian);return this.offset+=2,t}readInt32(){let t=this._data.getInt32(this.offset,this.littleEndian);return this.offset+=4,t}readUint32(){let t=this._data.getUint32(this.offset,this.littleEndian);return this.offset+=4,t}readFloat32(){let t=this._data.getFloat32(this.offset,this.littleEndian);return this.offset+=4,t}readFloat64(){let t=this._data.getFloat64(this.offset,this.littleEndian);return this.offset+=8,t}readBigInt64(){let t=this._data.getBigInt64(this.offset,this.littleEndian);return this.offset+=8,t}readBigUint64(){let t=this._data.getBigUint64(this.offset,this.littleEndian);return this.offset+=8,t}readChar(){return String.fromCharCode(this.readInt8())}readChars(t=1){let r="";for(let n=0;n<t;n++)r+=this.readChar();return r}readUtf8(t=1){return Je(this.readBytes(t))}decodeText(t=1,r="utf8"){return Je(this.readBytes(t),r)}writeBoolean(t){return this.writeUint8(t?255:0),this}writeInt8(t){return this.ensureAvailable(1),this._data.setInt8(this.offset++,t),this._updateLastWrittenByte(),this}writeUint8(t){return this.ensureAvailable(1),this._data.setUint8(this.offset++,t),this._updateLastWrittenByte(),this}writeByte(t){return this.writeUint8(t)}writeBytes(t){this.ensureAvailable(t.length);for(let r=0;r<t.length;r++)this._data.setUint8(this.offset++,t[r]);return this._updateLastWrittenByte(),this}writeInt16(t){return this.ensureAvailable(2),this._data.setInt16(this.offset,t,this.littleEndian),this.offset+=2,this._updateLastWrittenByte(),this}writeUint16(t){return this.ensureAvailable(2),this._data.setUint16(this.offset,t,this.littleEndian),this.offset+=2,this._updateLastWrittenByte(),this}writeInt32(t){return this.ensureAvailable(4),this._data.setInt32(this.offset,t,this.littleEndian),this.offset+=4,this._updateLastWrittenByte(),this}writeUint32(t){return this.ensureAvailable(4),this._data.setUint32(this.offset,t,this.littleEndian),this.offset+=4,this._updateLastWrittenByte(),this}writeFloat32(t){return this.ensureAvailable(4),this._data.setFloat32(this.offset,t,this.littleEndian),this.offset+=4,this._updateLastWrittenByte(),this}writeFloat64(t){return this.ensureAvailable(8),this._data.setFloat64(this.offset,t,this.littleEndian),this.offset+=8,this._updateLastWrittenByte(),this}writeBigInt64(t){return this.ensureAvailable(8),this._data.setBigInt64(this.offset,t,this.littleEndian),this.offset+=8,this._updateLastWrittenByte(),this}writeBigUint64(t){return this.ensureAvailable(8),this._data.setBigUint64(this.offset,t,this.littleEndian),this.offset+=8,this._updateLastWrittenByte(),this}writeChar(t){return this.writeUint8(t.charCodeAt(0))}writeChars(t){for(let r=0;r<t.length;r++)this.writeUint8(t.charCodeAt(r));return this}writeUtf8(t){return this.writeBytes(wt(t))}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{isAnyArray as Ni}from"is-any-array";import{matrixCreateEmpty as Pi,xSequentialFillFromStep as Ei}from"ml-spectra-processing";function vt(e){for(let t in e){let{z:r}=e[t],{minX:n,minY:i,maxX:o,maxY:s}=e[t];if(n>o){[n,o]=[o,n];for(let a of r)a.reverse()}i>s&&(r.reverse(),[i,s]=[s,i]),e[t]={...e[t],z:r,minX:n,minY:i,maxY:s,maxX:o}}}function pe(e,t){let{x:r,minMax:n,nbSubSpectra:i,template:o}=t;e.spectra||(e.spectra=[]);for(let s=0;s<i;s++){let a={};for(let c in n)a[c]=n[c].z[s];e.spectra.push({...o,data:{...a,x:r}})}}function de(e,t,r={}){let n={};for(let y in e)e[y]&&(n[y]=new R(e[y]));let i=fe(t.meta.SI),o=fe(t.meta.SW_p),s=fe(t.meta.SF),a=s,c=fe(t.shiftOffsetVal||t.meta.OFFSET);t.meta.observeFrequency=s,t.meta.brukerReference=a,t.meta.DATATYPE="NMR Spectrum";let l=Number.parseInt(t.meta.BYTORDP,10);l=l?0:1;let m=t.meta.nbSubSpectra||1;if(l)for(let y in n)n[y].setLittleEndian();else for(let y in n)n[y].setBigEndian();let p={dataType:"NMR Spectrum",nbPoints:i,firstX:c,lastX:c-o/s,xUnit:"PPM",yUnit:"Arbitrary",isXYdata:!0,isFT:!0,nucleus:t.meta.NUC1,observeFrequency:s,title:t.meta.TITLE,deltaX:-(o/s)/(i-1)},f=p.deltaX,g=Ei({from:c,step:f,size:i});if(m===1){let y={};for(let u in n){let h=n[u],d=new Float64Array(i);for(let b=0;b<i;++b)d[b]=h.readInt32();y[u]=d}t.spectra.push({...p,data:{...y,x:g}})}else{let{meta:y}=t,u=Number(y.SF[1]),h=Number(y.SW_p[1]||y.SW[1]),d=Number(y.OFFSET[1]),b=d-h/u,F={};for(let S in n)F[S]={minY:d,maxY:b,minX:g[0],maxX:g.at(-1),...Ti(y,n[S])};vt(F),r.keepSpectra&&pe(t,{minMax:F,x:g,nbSubSpectra:m,template:p}),t.minMax=F}}function fe(e){return Number(Ni(e)?e[0]:e)}function Ti(e,t){let r=e.SI.toReversed(),n=e.XDIM.toReversed(),i=r.map((g,y)=>Number.parseInt(String(g/n[y]),10)),[o,s]=r,[a,c]=n,l=Pi({nbRows:o,nbColumns:s}),[m,p]=[Number.MAX_SAFE_INTEGER,Number.MIN_SAFE_INTEGER],f=[];for(let g=0;g<i[0];g++)for(let y=0;y<i[1];y++){let u=y*c,h=g*a;f.push([h,u])}for(let[g,y]of f)for(let u=0;u<a;u++)for(let h=0;h<c;h++){let d=t.readInt32();m>d&&(m=d),p<d&&(p=d),l[u+g][h+y]=d}return{z:l,minZ:m,maxZ:p}}import{createStepArray as wi,xMinMaxValues as vi}from"ml-spectra-processing";var H={};xt(H,{DQD:()=>Ri,QF:()=>Oi,QSEQ:()=>V,QSIM:()=>Ci});var Oi=0,Ci=1,V=2,Ri=3;function ge(e,t,r){let n=Number.parseInt(t.meta.TD[0],10),i=new R(e),o=t.meta.nbSubSpectra||1,s=t.meta.AQ_mod,c=Number.parseInt(t.meta.DTYPA,10)===2,l=Number.parseFloat(t.meta.SW_h[0]),m=Number.parseFloat(t.meta.SFO1[0]);t.meta.DATATYPE="NMR FID";let p=1/(2*l),f=n*p,g=Number.parseInt(t.meta.BYTORDA,10);g=g?0:1,g?i.setLittleEndian():i.setBigEndian();let y=s===2?p:2*p,u=Li({nbSubSpectra:o,isFloat:c,aqMode:s,td:n}),h={dataType:"NMR FID",dataTable:"(X++(R..R))",nbPoints:u,firstX:0,lastX:f,nucleus:t.meta.NUC1,xUnit:"Sec",yUnit:"Arbitrary",isXYdata:!0,isFID:!0,observeFrequency:m,title:t.meta.TITLE,deltaX:y},d=wi({length:u,step:y});if(o<2){let b=kt(i,{nbPoints:u,isFloat:c,aqMode:s});t.spectra=[{data:{x:d,...b},...h}]}else{let b={minX:d[0],maxX:d.at(-1),minY:0,maxY:o,minZ:0,maxZ:0},F=s===2?{re:{z:[],...b}}:{re:{z:[],...b},im:{z:[],...b}},S={re:{min:Number.MAX_SAFE_INTEGER,max:Number.MIN_SAFE_INTEGER},im:{min:Number.MAX_SAFE_INTEGER,max:Number.MIN_SAFE_INTEGER}};for(let I=0;I<o;I++){let x=kt(i,{nbPoints:u,isFloat:c,aqMode:s});S.re=Lt(x.re,S.re),S.im=Lt(x.im??new Float64Array,S.im),F.re.z.push(x.re),F.im&&x.im&&F.im.z.push(x.im)}F.re={...F.re,minZ:S.re.min,maxZ:S.re.max},F.im={...F.im,minZ:S.im.min,maxZ:S.im.max},r.keepSpectra&&pe(t,{minMax:F,x:d,nbSubSpectra:o,template:h}),t.minMax=F}}function Lt(e,t){let{min:r,max:n}=vi(e),{min:i,max:o}=t;return{min:Math.min(i,r),max:Math.max(o,n)}}function kt(e,t){let{nbPoints:r,isFloat:n,aqMode:i}=t,o={re:new Float64Array(r),im:null},s=n?"readFloat64":"readInt32";if(i===2)for(let a=0;a<r;a++)o.re[a]=e[s]();else{o.im=new Float64Array(r);for(let a=0;a<r;a++)o.re[a]=e[s](),o.im[a]=e[s]()}return o}function Li(e){let{nbSubSpectra:t,isFloat:r,aqMode:n,td:i}=e,o=i;if(t>1){let s=r?128:256;o=Math.trunc(Math.ceil(i/s)*s)}return n===2?o:o/2>>0}async function _t(e,t){let r={},n=[],i=e["1r"]||e["1i"]?["1r","1i"]:["fid"];function o(a,c){return a.then(l=>{r[c]=l})}for(let a of i){let c=e[a];c&&n.push(o(c.arrayBuffer(),a))}n.push(_(e.procs,t).then(a=>{r.procs=a}),_(e.acqus,t).then(a=>{r.acqus=a})),e.quantFactorSample&&n.push(qi(e).then(a=>{r.ereticFactor=a})),e.integrals&&n.push(Rt(e).then(a=>{r.integrals=a}));let s=ki(e);return s&&n.push(s.text().then(a=>{r.titleFile=a})),await Promise.all(n),_i(r)}function ki(e){if("title"in e&&e.title)return e.title}function _i(e){let{procs:t,acqus:r,integrals:n,ereticFactor:i,titleFile:o}=e,s={...t};ue(s,r);let a={...s.info};s.info=a;let c={...s.meta};s.meta=c;let{epoch:l,date:m}=me(c.DATE);return l!==null&&Object.assign(a,{epoch:l,date:m}),n&&Object.assign(s,{integrals:n}),i&&(a.ereticFactor=i),o&&(c.TITLE_FILE=o),e["1r"]||e["1i"]?de({re:e["1r"],im:e["1i"]},s):e.fid&&ge(e.fid,s),s}async function qi(e){let r=(await e.quantFactorSample?.text())?.match(/<Application[\w\W]+<Eretic_Factor>(?<ereticFactor>[\d.]+)/);return Number(r?.groups?.ereticFactor)}function Xe(e,t){for(let r in t.meta)r in e.meta?(Array.isArray(e.meta[r])||(e.meta[r]=[e.meta[r]]),e.meta[r].push(t.meta[r])):e.meta[r]===void 0&&(e.meta[r]=[t.meta[r]]);return e}async function qt(e,t){let r={},n=[],i=["2rr","2ri","2ir","2ii","ser"];function o(s,a){return s.then(c=>{r[a]=c})}for(let s of i){let a=e[s];a&&n.push(o(a.arrayBuffer(),s))}if(n.push(o(_(e.procs,t),"procs"),o(_(e.proc2s,t),"proc2s"),o(_(e.acqus,t),"acqus"),o(_(e.acqu2s,t),"acqu2s")),"nuslist"in e&&e.nuslist){let s=e.nuslist;n.push(o(s.text(),"nuslist"))}return e.vdlist&&n.push(o(e.vdlist.text(),"vdlist")),e.difflist&&n.push(o(e.difflist.text(),"difflist")),await Promise.all(n),ji(r,t)}function ji(e,t){let r=Xe(e.procs,e.proc2s),n=Xe(e.acqus,e.acqu2s);ue(r,n);let{epoch:i,date:o}=me(r.meta.DATE);if(o.length>0&&(r.info={...r.info,epoch:i,date:o}),e.nuslist&&(r.info.nuslist=e.nuslist.split(/\r?\n/).filter(Boolean).map(Number.parseFloat)),e.vdlist){let u=[];for(let h of e.vdlist.split(`
|
|
1
|
+
var ii=Object.defineProperty;var xt=(e,t)=>{for(var r in t)ii(e,r,{get:t[r],enumerable:!0})};import{NMRiumCore as ga}from"@zakodium/nmrium-core";import{defineNMRiumPlugin as hi}from"@zakodium/nmrium-core";import{Filters1D as pi,Filters2D as fi}from"nmr-processing";import{getOneIfArray as oi}from"@zakodium/nmrium-core";function ce(e={},t={},r={}){e===null&&(e={}),typeof e=="string"&&(e={pulseSequence:e});let n=Array.isArray(e.pulseSequence)?e.pulseSequence[0]:e.pulseSequence||"";if(typeof n!="string")return e.dimension?`${e.dimension}d`:"";if(n=n.toLowerCase(),n.includes("zg")||n.includes("single_pulse_dec")||n.includes("udeft"))return"1d";if(n.includes("hsqct")||n.includes("invi")&&(n.includes("ml")||n.includes("di")))return"hsqctocsy";if(n.includes("hsqc")||n.includes("invi"))return"hsqc";if(n.includes("hmbc")||n.includes("inv4")&&n.includes("lp"))return"hmbc";if(n.includes("hmqc"))return"hmqc";if(n.includes("cosy"))return"cosy";if(n.includes("jres"))return"jres";if(n.includes("dosy"))return"dosy";if(n.includes("tocsy")||n.includes("mlev")||n.includes("dipsi"))return"tocsy";if(n.includes("noesy"))return"noesy";if(n.includes("roesy"))return"roesy";if(n.includes("dept"))return"dept";if(n.includes("jmod")||n.includes("apt"))return"aptjmod";if(n.includes("inad"))return"inadequate";if(n.includes("adeq"))return"adequate";let{prefix:i=""}=r,o=(oi(t[`${i}SPECTYP`])||"").replace(/^<(.*)>$/,"$1").toLowerCase();return o.length>0&&o!=="undefined"?o:e.dimension?`${e.dimension}d`:""}import{getOneIfArray as Dt}from"@zakodium/nmrium-core";var si=["no","exponential","modifiedGaussian","sine","qsine","trap","user","sinc","qsinc","traf","trafs"];function ai(e){return e in St}function qe(e,t){let{prefix:r="",index:n=0}=t,i=Dt(e[`${r}WDW`],n),o=si[i?Number(i):0],s={};if(!ai(o))return s;let a=St[o];if(a){let{kind:c,parameters:l}=a,m={};for(let p in l){let f=l[p],{source:g,processor:y}=f;if(g){let u=Dt(e[`${r}${g}`],n);if(!u)continue;let h=Number(u);m[p]=y?y(h):h}else f.value!==void 0&&(m[p]=f.value)}s[c]={apply:!0,options:m}}return s}var St={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 At={sineBell:Mt({offset:0})},It={cosy:{...At},hmbc:{...At},hsqc:{sineBell:Mt({offset:.5})}},ci={...It};function je(e="",t=1){let r=li(e),n={},i=t===1?It[r||""]:ci[r||""];return i&&(n=structuredClone(i)),n}function Mt(e){return{apply:!0,options:e}}function li(e){let r=e.toLowerCase().match(/cosy|hsqc|hmbc/);return r?r[0]:null}function Nt(e,t={}){let{prefix:r="",experiment:n=ce(e)}=t;return e[`${r}WDW`]?{f2:qe(e,{...t,index:0}),f1:qe(e,{...t,index:1})}:{f2:je(n,1),f1:je(n,2)}}import{Filters1D as mi}from"nmr-processing";var Be=["digitalFilter","backwardLinearPrediction","forwardLinearPrediction","apodization","zeroFilling","fft",["shiftX","phaseCorrection","baselineCorrection"]],W={};for(let e=0;e<Be.length;e++){let t=Be[e];for(let r of Array.isArray(t)?t:[t])W[r]=e}for(let e of Object.values(mi))e.name in W||(W[e.name]=Be.length);import{Filters2D as ui}from"nmr-processing";var Ue=["digitalFilter2D","blpDimension1","flpDimension1","apodizationDimension1","zeroFillingDimension1","fftDimension1","blpDimension2","flpDimension2","nusDimension2","apodizationDimension2","zeroFillingDimension2","fftDimension2","phaseCorrectionTwoDimensions",["shift2DX","shift2DY","symmetrizeCosyLike"]],X={};for(let e=0;e<Ue.length;e++){let t=Ue[e];for(let r of Array.isArray(t)?t:[t])X[r]=e}for(let e of Object.values(ui))e.name in X||(X[e.name]=Ue.length);var di=new Set([]);function gi(e,t){let{filter:r,experimentalFeatures:n=!1}=t,{name:i}=r;({...pi,...fi})[i]&&(e.some(s=>s.name===i)||di.has(i)&&!n||e.push({...r,enabled:!0}))}function Pt(e,t={}){let{data:r}=e;if(!r)return;let{autoProcessing:n,experimentalFeatures:i}=t,o=(a,c)=>gi(a,{...c,experimentalFeatures:i}),{spectra:s}=r;for(let a of s){let{data:c,info:l,meta:m,filters:p}=a,{dimension:f,isFid:g}=l;if(g){if(f===1){let y=c.re.length,{tdOff:u,digitalFilter:h}=l;if(h&&h>0&&o(p,{filter:{name:"digitalFilter",value:{digitalFilterValue:h}}}),!n)continue;u&&Math.abs(u)>0&&o(p,{filter:{name:"backwardLinearPrediction",value:{nbInputs:y/2}}}),o(p,{filter:{name:"apodization",value:{exponential:{apply:!0,options:{lineBroadening:1}}}}}),o(p,{filter:{name:"zeroFilling",value:{nbPoints:2*y}}}),o(p,{filter:{name:"fft",value:{}}}),o(p,{filter:{name:"phaseCorrection",value:yi(l)}}),p.sort((d,b)=>W[d.name]-W[b.name])}else if(f===2){if(!n)continue;let y=c.re.z.length,u=c.re.z[0].length,{tdOff:h,experiment:d=""}=l,b=l.spectrumSize;Array.isArray(b)&&b.length>1?(b[0]<=u&&(b[0]=u*2),b[0]<=y&&(b[0]=y*2)):b=[u*2,2*y];let F=d.toLowerCase().includes("cosy");h&&Math.abs(h[0])>0&&o(p,{filter:{name:"blpDimension1",value:{nbInputs:u/2}}});let S=Nt(m,{experiment:d});o(p,{filter:{name:"apodizationDimension1",value:S.f2}}),o(p,{filter:{name:"zeroFillingDimension1",value:{nbPoints:b[0]}}}),o(p,{filter:{name:"fftDimension1",value:{}}}),m&&"nuslist"in m&&o(p,{filter:{name:"nusDimension2",value:{}}}),o(p,{filter:{name:"apodizationDimension2",value:S.f1}}),o(p,{filter:{name:"zeroFillingDimension2",value:{nbPoints:b[F?0:1]}}}),F?o(p,{filter:{name:"symmetrizeCosyLike",value:{}}}):o(p,{filter:{name:"phaseCorrectionTwoDimensions",value:{}}}),o(p,{filter:{name:"fftDimension2",value:{}}}),p.sort((I,x)=>X[I.name]-X[x.name])}}}}function yi(e){let{phc0:t=0,phc1:r=0}=e;return Et([t,r])?{}:{ph0:t,ph1:r}}function Et(e){return Array.isArray(e)?e.every(t=>!t&&t===0):Et([e])}function $e(){return hi({id:"@zakodium/nmrium-core-plugins#AutoPostProcessingPlugin",version:1,shouldSerialize:!0,migrations:[],onReadProcess:{onProcessing:Pt}})}import{defineNMRiumPlugin as Do}from"@zakodium/nmrium-core";import{FileCollection as _c}from"file-collection";var Tt=["acqus","acqu2s"],le=["procs","proc2s"];function Ot(e){return e.is1D?bi(e):e.is2D?Fi(e):{checked:!1,message:"Multi-dimensional n > 2 is not supported"}}function bi(e){let t=e.isFID?["acqus"]:["acqus","procs"],r=t.every(n=>e[n]);return{checked:r,message:r?"":`File: ${e[e.isFID?"fid":"1r"]?.relativePath} is ignored, files: ${t.join(",")} are required.`}}function Fi(e){let t=e.isFID?Tt:Tt.concat(le),r=t.every(n=>e[n]);return r&&e.isFID&&le.some(n=>e[n])&&!le.every(n=>e[n])&&(r=!1,t.push(...le)),{checked:r,message:r?"":`File: ${e.name} is ignored, files: ${t.join(",")} are required.`}}function ze(e,t={}){let{logger:r,processingNumbers:n,experimentNumbers:i,dataSelection:o="both",keep1D:s=!0,keep2D:a=!0,onlyFirstProcessedData:c=!0}=t,l={},m=e.files.map(g=>g.relativePath);for(let g of e){let y,u,h,d=g.relativePath.split("/"),b=d.indexOf("pdata");if(b!==-1)y=Number(d[b+1]),u=Number(d[b-1]),h=d.slice(0,-3).join("/");else if(Di(g,m)){let S=d.indexOf(g.name);u=Number(d[S-1]),h=d.slice(0,-1).join("/")}else continue;if(Number.isNaN(u)&&(u=void 0),Number.isNaN(y)&&(y=void 0),i&&!i.includes(u))continue;l[h]||(l[h]={name:h,expno:u,processedData:{},fileCollectionItems:[]});let F=l[h];if(g.name==="vdlist"&&(F.vdlist=g),g.name==="difflist"&&(F.difflist=g),y){F.processedData||(F.processedData={}),F.processedData[y]||(F.processedData[y]={fileCollectionItems:[],name:h,expno:u,procno:y});let S=F.processedData[y];S.fileCollectionItems.push(g),g.name.match(/^(?:1r|1i|2rr|2ir|2ii|2ri|procs|proc2s|title|integrals.txt)$/)&&(S[g.name]=g),g.name==="2rr"&&(S.is2D=!0,S.isFT=!0),g.name==="1r"&&(S.is1D=!0,S.isFT=!0)}else F.fileCollectionItems.push(g),g.name.match(/^(?:ser|fid|acqus|acqu2s|nuslist)$/)&&(F[g.name]=g),g.name==="ser"&&(F.is2D=!0,F.isFID=!0),g.name==="fid"&&(F.is1D=!0,F.isFID=!0);g.name==="QuantFactorSample.xml"&&(F.quantFactorSample=g)}if(n)for(let g in l){let y=l[g].processedData,u={};for(let h in y)n.includes(Number.parseInt(h,10))&&(u[h]=y[h]);l[g].processedData=u}else if(c)for(let g in l){let y=l[g].processedData,u=Object.keys(y??{});u.sort((d,b)=>Number(d)-Number(b));let h=u[0];y&&h!==void 0&&(l[g].processedData={firstProcessedNumber:y[h]})}let p=Si(r),f=[];for(let g in l){let y=l[g],{processedData:u,...h}=y;if(p(y,o)){let b=Object.keys(u??{});if(u&&b.length>0){let F=u[b[0]];F.procs&&(h.fileCollectionItems.push(F.procs),h.procs=F.procs),F.proc2s&&(h.fileCollectionItems.push(F.proc2s),h.proc2s=F.proc2s),F["integrals.txt"]&&(h.integrals=F["integrals.txt"])}f.push(h)}let d="ser"in h||"fid"in h;if(o==="fid"||o==="preferFID"&&d){r?.warn("Skipping FT data because it does not match the import filters");continue}for(let b in u){let F=u[b];(F["1r"]||F["2rr"])&&(h.acqus&&F.fileCollectionItems.push(h.acqus),h.acqu2s&&F.fileCollectionItems.push(h.acqu2s),h.vdlist&&(F.vdlist=h.vdlist),f.push({integrals:F["integrals.txt"],acqus:h.acqus,acqu2s:h.acqu2s,...F}))}}return s||(r?.warn("Skipping 1D data because it does not match the import filters"),f=f.filter(g=>!g.is1D)),a||(r?.warn("Skipping 2D data because it does not match the import filters"),f=f.filter(g=>!g.is2D)),xi(f,t.logger)}function xi(e,t){return e.filter(r=>{let{checked:n,message:i}=Ot(r);return n||t?.warn(i),n})}function Di(e,t){return e.name.match(/^(?:ser|acqus|acqu2s|nuslist|vdlist|difflist|QuantFactorSample.xml)$/)||e.name.match(/^fid$/)&&t.includes(e.relativePath.replace(/fid$/,"acqus"))}function Si(e){return(t,r)=>{let{processedData:n}=t,i=Object.keys(n??{}),o=n&&i.length>0&&["1r","1i","2rr"].some(m=>m in n[i[0]]),s="ser"in t||"fid"in t,l=s&&(r!=="ft"&&r!=="preferFT"||r==="preferFT"&&!o);return s&&!l&&e?.warn("Skipping RAW data because it does not match import filters"),l}}function me(e){if(e===void 0||Array.isArray(e)&&e.length===0)return{epoch:null,date:""};let t=e[0]*1e3;return{epoch:t,date:new Date(t).toUTCString()}}function ue(e,t){for(let r in t.meta)e.meta[r]===void 0&&(e.meta[r]=t.meta[r]);for(let r in t.info)e.info[r]===void 0&&(e.info[r]=t.info[r]);for(let r in e.meta)Array.isArray(e.meta[r])||(e.meta[r]=[e.meta[r]])}import{convert as Ai}from"jcampconverter";async function _(e,t){if(!e)return Ct();let r=await e.text(),{keepRecordsRegExp:n=/.*/}=t,i=Ai(r,{keepRecordsRegExp:n});return i.flatten.length===0?Ct():i.flatten[0]}function Ct(){return{info:{},meta:{},tmp:{},spectra:[],ntuples:{}}}async function Rt(e){let r=(await e.integrals?.text())?.split(/\r?\n/).slice(3).filter(Boolean)??[],n=[];for(let i=1;i<r.length;i++){let o=r[i].replace(/^\s*/,"").replaceAll(/[\s\t]+/g,";").match(/\d+;(?<from>[0-9.]+);(?<to>[0-9.]+);(?<integration>[0-9.]+)/)?.groups;if(o){let{from:s,to:a,integration:c}=o;n.push({from:Number.parseFloat(s),to:Number.parseFloat(a),integration:Number.parseFloat(c)})}}return n}function Je(e,t="utf8"){return new TextDecoder(t).decode(e)}var Ii=new TextEncoder;function wt(e){return Ii.encode(e)}var Mi=1024*8,Ni=(()=>{let e=new Uint8Array(4),t=new Uint32Array(e.buffer);return!((t[0]=1)&e[0])})(),We={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},R=class e{buffer;byteLength;byteOffset;length;offset;lastWrittenByte;littleEndian;_data;_mark;_marks;constructor(t=Mi,r={}){let n=!1;typeof t=="number"?t=new ArrayBuffer(t):(n=!0,this.lastWrittenByte=t.byteLength);let i=r.offset?r.offset>>>0:0,o=t.byteLength-i,s=i;(ArrayBuffer.isView(t)||t instanceof e)&&(t.byteLength!==t.buffer.byteLength&&(s=t.byteOffset+i),t=t.buffer),n?this.lastWrittenByte=o:this.lastWrittenByte=0,this.buffer=t,this.length=o,this.byteLength=o,this.byteOffset=s,this.offset=0,this.littleEndian=!0,this._data=new DataView(this.buffer,s,o),this._mark=0,this._marks=[]}available(t=1){return this.offset+t<=this.length}isLittleEndian(){return this.littleEndian}setLittleEndian(){return this.littleEndian=!0,this}isBigEndian(){return!this.littleEndian}setBigEndian(){return this.littleEndian=!1,this}skip(t=1){return this.offset+=t,this}back(t=1){return this.offset-=t,this}seek(t){return this.offset=t,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 t=this._marks.pop();if(t===void 0)throw new Error("Mark stack empty");return this.seek(t),this}rewind(){return this.offset=0,this}ensureAvailable(t=1){if(!this.available(t)){let n=(this.offset+t)*2,i=new Uint8Array(n);i.set(new Uint8Array(this.buffer)),this.buffer=i.buffer,this.length=n,this.byteLength=n,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(t=1){return this.readArray(t,"uint8")}readArray(t,r){let n=We[r].BYTES_PER_ELEMENT*t,i=this.byteOffset+this.offset,o=this.buffer.slice(i,i+n);if(this.littleEndian===Ni&&r!=="uint8"&&r!=="int8"){let a=new Uint8Array(this.buffer.slice(i,i+n));a.reverse();let c=new We[r](a.buffer);return this.offset+=n,c.reverse(),c}let s=new We[r](o);return this.offset+=n,s}readInt16(){let t=this._data.getInt16(this.offset,this.littleEndian);return this.offset+=2,t}readUint16(){let t=this._data.getUint16(this.offset,this.littleEndian);return this.offset+=2,t}readInt32(){let t=this._data.getInt32(this.offset,this.littleEndian);return this.offset+=4,t}readUint32(){let t=this._data.getUint32(this.offset,this.littleEndian);return this.offset+=4,t}readFloat32(){let t=this._data.getFloat32(this.offset,this.littleEndian);return this.offset+=4,t}readFloat64(){let t=this._data.getFloat64(this.offset,this.littleEndian);return this.offset+=8,t}readBigInt64(){let t=this._data.getBigInt64(this.offset,this.littleEndian);return this.offset+=8,t}readBigUint64(){let t=this._data.getBigUint64(this.offset,this.littleEndian);return this.offset+=8,t}readChar(){return String.fromCharCode(this.readInt8())}readChars(t=1){let r="";for(let n=0;n<t;n++)r+=this.readChar();return r}readUtf8(t=1){return Je(this.readBytes(t))}decodeText(t=1,r="utf8"){return Je(this.readBytes(t),r)}writeBoolean(t){return this.writeUint8(t?255:0),this}writeInt8(t){return this.ensureAvailable(1),this._data.setInt8(this.offset++,t),this._updateLastWrittenByte(),this}writeUint8(t){return this.ensureAvailable(1),this._data.setUint8(this.offset++,t),this._updateLastWrittenByte(),this}writeByte(t){return this.writeUint8(t)}writeBytes(t){this.ensureAvailable(t.length);for(let r=0;r<t.length;r++)this._data.setUint8(this.offset++,t[r]);return this._updateLastWrittenByte(),this}writeInt16(t){return this.ensureAvailable(2),this._data.setInt16(this.offset,t,this.littleEndian),this.offset+=2,this._updateLastWrittenByte(),this}writeUint16(t){return this.ensureAvailable(2),this._data.setUint16(this.offset,t,this.littleEndian),this.offset+=2,this._updateLastWrittenByte(),this}writeInt32(t){return this.ensureAvailable(4),this._data.setInt32(this.offset,t,this.littleEndian),this.offset+=4,this._updateLastWrittenByte(),this}writeUint32(t){return this.ensureAvailable(4),this._data.setUint32(this.offset,t,this.littleEndian),this.offset+=4,this._updateLastWrittenByte(),this}writeFloat32(t){return this.ensureAvailable(4),this._data.setFloat32(this.offset,t,this.littleEndian),this.offset+=4,this._updateLastWrittenByte(),this}writeFloat64(t){return this.ensureAvailable(8),this._data.setFloat64(this.offset,t,this.littleEndian),this.offset+=8,this._updateLastWrittenByte(),this}writeBigInt64(t){return this.ensureAvailable(8),this._data.setBigInt64(this.offset,t,this.littleEndian),this.offset+=8,this._updateLastWrittenByte(),this}writeBigUint64(t){return this.ensureAvailable(8),this._data.setBigUint64(this.offset,t,this.littleEndian),this.offset+=8,this._updateLastWrittenByte(),this}writeChar(t){return this.writeUint8(t.charCodeAt(0))}writeChars(t){for(let r=0;r<t.length;r++)this.writeUint8(t.charCodeAt(r));return this}writeUtf8(t){return this.writeBytes(wt(t))}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{isAnyArray as Pi}from"is-any-array";import{matrixCreateEmpty as Ei,xSequentialFillFromStep as Ti}from"ml-spectra-processing";function vt(e){for(let t in e){let{z:r}=e[t],{minX:n,minY:i,maxX:o,maxY:s}=e[t];if(n>o){[n,o]=[o,n];for(let a of r)a.reverse()}i>s&&(r.reverse(),[i,s]=[s,i]),e[t]={...e[t],z:r,minX:n,minY:i,maxY:s,maxX:o}}}function pe(e,t){let{x:r,minMax:n,nbSubSpectra:i,template:o}=t;e.spectra||(e.spectra=[]);for(let s=0;s<i;s++){let a={};for(let c in n)a[c]=n[c].z[s];e.spectra.push({...o,data:{...a,x:r}})}}function de(e,t,r={}){let n={};for(let y in e)e[y]&&(n[y]=new R(e[y]));let i=fe(t.meta.SI),o=fe(t.meta.SW_p),s=fe(t.meta.SF),a=s,c=fe(t.shiftOffsetVal||t.meta.OFFSET);t.meta.observeFrequency=s,t.meta.brukerReference=a,t.meta.DATATYPE="NMR Spectrum";let l=Number.parseInt(t.meta.BYTORDP,10);l=l?0:1;let m=t.meta.nbSubSpectra||1;if(l)for(let y in n)n[y].setLittleEndian();else for(let y in n)n[y].setBigEndian();let p={dataType:"NMR Spectrum",nbPoints:i,firstX:c,lastX:c-o/s,xUnit:"PPM",yUnit:"Arbitrary",isXYdata:!0,isFT:!0,nucleus:t.meta.NUC1,observeFrequency:s,title:t.meta.TITLE,deltaX:-(o/s)/(i-1)},f=p.deltaX,g=Ti({from:c,step:f,size:i});if(m===1){let y={};for(let u in n){let h=n[u],d=new Float64Array(i);for(let b=0;b<i;++b)d[b]=h.readInt32();y[u]=d}t.spectra.push({...p,data:{...y,x:g}})}else{let{meta:y}=t,u=Number(y.SF[1]),h=Number(y.SW_p[1]||y.SW[1]),d=Number(y.OFFSET[1]),b=d-h/u,F={};for(let S in n)F[S]={minY:d,maxY:b,minX:g[0],maxX:g.at(-1),...Oi(y,n[S])};vt(F),r.keepSpectra&&pe(t,{minMax:F,x:g,nbSubSpectra:m,template:p}),t.minMax=F}}function fe(e){return Number(Pi(e)?e[0]:e)}function Oi(e,t){let r=e.SI.toReversed(),n=e.XDIM.toReversed(),i=r.map((g,y)=>Number.parseInt(String(g/n[y]),10)),[o,s]=r,[a,c]=n,l=Ei({nbRows:o,nbColumns:s}),[m,p]=[Number.MAX_SAFE_INTEGER,Number.MIN_SAFE_INTEGER],f=[];for(let g=0;g<i[0];g++)for(let y=0;y<i[1];y++){let u=y*c,h=g*a;f.push([h,u])}for(let[g,y]of f)for(let u=0;u<a;u++)for(let h=0;h<c;h++){let d=t.readInt32();m>d&&(m=d),p<d&&(p=d),l[u+g][h+y]=d}return{z:l,minZ:m,maxZ:p}}import{createStepArray as vi,xMinMaxValues as Li}from"ml-spectra-processing";var H={};xt(H,{DQD:()=>wi,QF:()=>Ci,QSEQ:()=>V,QSIM:()=>Ri});var Ci=0,Ri=1,V=2,wi=3;function ge(e,t,r){let n=Number.parseInt(t.meta.TD[0],10),i=new R(e),o=t.meta.nbSubSpectra||1,s=t.meta.AQ_mod,c=Number.parseInt(t.meta.DTYPA,10)===2,l=Number.parseFloat(t.meta.SW_h[0]),m=Number.parseFloat(t.meta.SFO1[0]);t.meta.DATATYPE="NMR FID";let p=1/(2*l),f=n*p,g=Number.parseInt(t.meta.BYTORDA,10);g=g?0:1,g?i.setLittleEndian():i.setBigEndian();let y=s===2?p:2*p,u=ki({nbSubSpectra:o,isFloat:c,aqMode:s,td:n}),h={dataType:"NMR FID",dataTable:"(X++(R..R))",nbPoints:u,firstX:0,lastX:f,nucleus:t.meta.NUC1,xUnit:"Sec",yUnit:"Arbitrary",isXYdata:!0,isFID:!0,observeFrequency:m,title:t.meta.TITLE,deltaX:y},d=vi({length:u,step:y});if(o<2){let b=kt(i,{nbPoints:u,isFloat:c,aqMode:s});t.spectra=[{data:{x:d,...b},...h}]}else{let b={minX:d[0],maxX:d.at(-1),minY:0,maxY:o,minZ:0,maxZ:0},F=s===2?{re:{z:[],...b}}:{re:{z:[],...b},im:{z:[],...b}},S={re:{min:Number.MAX_SAFE_INTEGER,max:Number.MIN_SAFE_INTEGER},im:{min:Number.MAX_SAFE_INTEGER,max:Number.MIN_SAFE_INTEGER}};for(let I=0;I<o;I++){let x=kt(i,{nbPoints:u,isFloat:c,aqMode:s});S.re=Lt(x.re,S.re),S.im=Lt(x.im??new Float64Array,S.im),F.re.z.push(x.re),F.im&&x.im&&F.im.z.push(x.im)}F.re={...F.re,minZ:S.re.min,maxZ:S.re.max},F.im={...F.im,minZ:S.im.min,maxZ:S.im.max},r.keepSpectra&&pe(t,{minMax:F,x:d,nbSubSpectra:o,template:h}),t.minMax=F}}function Lt(e,t){let{min:r,max:n}=Li(e),{min:i,max:o}=t;return{min:Math.min(i,r),max:Math.max(o,n)}}function kt(e,t){let{nbPoints:r,isFloat:n,aqMode:i}=t,o={re:new Float64Array(r),im:null},s=n?"readFloat64":"readInt32";if(i===2)for(let a=0;a<r;a++)o.re[a]=e[s]();else{o.im=new Float64Array(r);for(let a=0;a<r;a++)o.re[a]=e[s](),o.im[a]=e[s]()}return o}function ki(e){let{nbSubSpectra:t,isFloat:r,aqMode:n,td:i}=e,o=i;if(t>1){let s=r?128:256;o=Math.trunc(Math.ceil(i/s)*s)}return n===2?o:o/2>>0}async function _t(e,t){let r={},n=[],i=e["1r"]||e["1i"]?["1r","1i"]:["fid"];function o(a,c){return a.then(l=>{r[c]=l})}for(let a of i){let c=e[a];c&&n.push(o(c.arrayBuffer(),a))}n.push(_(e.procs,t).then(a=>{r.procs=a}),_(e.acqus,t).then(a=>{r.acqus=a})),e.quantFactorSample&&n.push(ji(e).then(a=>{r.ereticFactor=a})),e.integrals&&n.push(Rt(e).then(a=>{r.integrals=a}));let s=_i(e);return s&&n.push(s.text().then(a=>{r.titleFile=a})),await Promise.all(n),qi(r)}function _i(e){if("title"in e&&e.title)return e.title}function qi(e){let{procs:t,acqus:r,integrals:n,ereticFactor:i,titleFile:o}=e,s={...t};ue(s,r);let a={...s.info};s.info=a;let c={...s.meta};s.meta=c;let{epoch:l,date:m}=me(c.DATE);return l!==null&&Object.assign(a,{epoch:l,date:m}),n&&Object.assign(s,{integrals:n}),i&&(a.ereticFactor=i),o&&(c.TITLE_FILE=o),e["1r"]||e["1i"]?de({re:e["1r"],im:e["1i"]},s):e.fid&&ge(e.fid,s),s}async function ji(e){let r=(await e.quantFactorSample?.text())?.match(/<Application[\w\W]+<Eretic_Factor>(?<ereticFactor>[\d.]+)/);return Number(r?.groups?.ereticFactor)}function Xe(e,t){for(let r in t.meta)r in e.meta?(Array.isArray(e.meta[r])||(e.meta[r]=[e.meta[r]]),e.meta[r].push(t.meta[r])):e.meta[r]===void 0&&(e.meta[r]=[t.meta[r]]);return e}async function qt(e,t){let r={},n=[],i=["2rr","2ri","2ir","2ii","ser"];function o(s,a){return s.then(c=>{r[a]=c})}for(let s of i){let a=e[s];a&&n.push(o(a.arrayBuffer(),s))}if(n.push(o(_(e.procs,t),"procs"),o(_(e.proc2s,t),"proc2s"),o(_(e.acqus,t),"acqus"),o(_(e.acqu2s,t),"acqu2s")),"nuslist"in e&&e.nuslist){let s=e.nuslist;n.push(o(s.text(),"nuslist"))}return e.vdlist&&n.push(o(e.vdlist.text(),"vdlist")),e.difflist&&n.push(o(e.difflist.text(),"difflist")),await Promise.all(n),Bi(r,t)}function Bi(e,t){let r=Xe(e.procs,e.proc2s),n=Xe(e.acqus,e.acqu2s);ue(r,n);let{epoch:i,date:o}=me(r.meta.DATE);if(o.length>0&&(r.info={...r.info,epoch:i,date:o}),e.nuslist&&(r.info.nuslist=e.nuslist.split(/\r?\n/).filter(Boolean).map(Number.parseFloat)),e.vdlist){let u=[];for(let h of e.vdlist.split(`
|
|
2
2
|
`)){if(!h)continue;let[d,b]=h.trim().match(/\s*([\d.]+)\s*([a-zA-Z]+)/)?.slice(1)||[];b&&u.push(`${d}${b}`)}r.meta.vdlist=u}if(e.difflist){let u=[];for(let h of e.difflist.split(`
|
|
3
|
-
`)){if(!h)continue;let[d]=h.trim().match(/\s*([\d.]+)\s*/)?.slice(1)||[];u.push(d)}r.meta.difflist=u}r.meta.SW_p||(r.meta.SW_p=r.meta.SW_h),r.meta.SF||(r.meta.SF=r.meta.SFO1);let s=["2rr","2ri","2ir","2ii"].some(u=>u in e);r.meta.nbSubSpectra=s?Number.parseInt(r.meta.SI[1],10):Number.parseInt(r.meta.TD[1],10);let a=0,c=0,l=0,m=0;if(s){let u=Number(r.meta.SF[1]),h=Number(r.meta.SW_p[1]||r.meta.SW[1]);m=Number(r.meta.OFFSET[1]),l=Number(r.meta.OFFSET[0]),a=m,c=m-h/u,r.meta.firstY=a,r.meta.lastY=c,de({rr:e["2rr"],ri:e["2ri"],ir:e["2ir"],ii:e["2ii"]},r,t)}else if(e.ser){a=0,c=r.meta.nbSubSpectra;let u=Number(r.meta.SW[0]),h=Number(r.meta.SW[1]),d=Number(r.meta.SFO1[0]),b=Number(r.meta.SFO1[1]),F=Number(r.meta.O1[0]),S=Number(r.meta.O1[1]);l=F/d+u/2,m=S/b+h/2,ge(e.ser,r,t)}if(t.keepSpectra){let{nbSubSpectra:u}=r.meta,h=(c-a)/(u-1),d=a;for(let b=0;b<u;b++)d+=h,r.spectra[b].pageValue=d}let{NUC1:p,AXNUC:f,SF:g}=r.meta,y=f||p||[];return r.info["2D_Y_NUCLEUS"]=y[1],r.info["2D_X_NUCLEUS"]=y[0],r.info["2D_Y_FRECUENCY"]=g[1],r.info["2D_X_FRECUENCY"]=g[0],r.info["2D_Y_OFFSET"]=m,r.info["2D_X_OFFSET"]=l,r.info.twoD=!0,r.twoD=!0,r}async function He(e,t={}){let r,n=!1,i=!1;if(["ser","2rr","2ri","2ir","2ii"].some(s=>s in e))n=!0,r=await qt(e,t);else if(e["1r"]||e["1i"]||e.fid)i=!0,r=await _t(e,t);else throw new RangeError("The current files are invalid");let o={name:e.name,expno:e.expno,isFID:!!e.isFID};for(let s in e){let a=s;(typeof e[a]).match(/number|string|boolean/)&&(o[a]=e[a])}r.source=n?{...o,is2D:n}:{...o,is1D:i},t.keepFiles&&(r.source.files=e.fileCollectionItems),r.meta.DATE=Number(r.meta.DATE),r.meta.GRPDLY&&(Ve(r.meta,"DSPFVS",r.meta.DSPFVS),Ve(r.meta,"GRPDLY",r.meta.GRPDLY),Ve(r.meta,"DECIM",r.meta.DECIM));for(let s in r.meta)Array.isArray(r.meta[s])&&(r.meta[s].length===1||typeof r.meta[s][0]=="string"&&r.meta[s][0].includes("(0.."))&&(r.meta[s]=r.meta[s][0]);return r}function Ve(e,t,r){r!==void 0&&(Array.isArray(r)?e[t]=r.slice():e[t]=[r])}var B={};xt(B,{ECHO_ANTIECHO:()=>Wi,QF:()=>Bi,QSEC:()=>Ui,STATES:()=>zi,STATES_TPPI:()=>Ji,TTPI:()=>$i});var Bi=1,Ui=2,$i=3,zi=4,Ji=5,Wi=6;import{formatSpectra as fo}from"@zakodium/nmrium-core";function ye(e){let t=[];for(let r of e){if(!r)continue;let{groups:{value:n,unit:i}={}}=r.trim().match(/[$$]*\s*(?<value>[\d.]+)\s*(?<unit>[a-zA-Z]+)/)||{};t.push(Xi(n,i))}return t}function Xi(e,t){switch(t.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 Bt}from"is-any-array";function U(e){if(Vi(e))return Hi(e)?e.map(jt):jt(e);if(typeof e=="object"&&e!==null){let t={};for(let r in e)t[r]=U(e[r]);return t}return e}function Vi(e){return Bt(e)}function jt(e){return Float64Array.from(e)}function Hi(e){return Bt(e[0])}import{isAnyArray as uo}from"is-any-array";import{getOneIfArray as Yi}from"@zakodium/nmrium-core";var Gi=new Map([[String(H.QSIM),"notPhaseSensitive"],["notphasesensitive","notPhaseSensitive"],[String(H.QSEQ),"QSEQ"],["qseq","QSEQ"],[String(B.TTPI),"TPPI"],["tppi","TPPI"],[String(B.STATES),"States"],["states","States"],[String(B.STATES_TPPI),"States-TPPI"],["tppi-states","States-TPPI"],[String(B.ECHO_ANTIECHO),"Echo-antiecho"],["echo-antiecho","Echo-antiecho"]]);function Ut(e){let t=String(e).toLowerCase().replaceAll(" ","");return Gi.get(t)}function D(e,t,r,n=!1){r===void 0||t in e&&!n||(Array.isArray(r)?e[t]=r.map($t):e[t]=[$t(r)])}function $t(e){return typeof e=="string"&&(e.startsWith("<")&&e.endsWith(">")&&(e=e.slice(1,-1)),e=e.replace(/\$.*/,"").trim()),e}function G(e){return Array.isArray(e)?e.map(zt):zt(e)}function zt(e){return typeof e=="string"?Number.parseFloat(e):e}function P(e,t,r){r!==void 0&&D(e,t,G(r))}function Jt(e,t,r){let{prefix:n=""}=r,i=t[`${n}.ACQUISITIONSCHEME`]||t[`${n}FnMODE`];i&&D(e,"acquisitionScheme",Ut(Yi(i,1))),D(e,"acquisitionMode",t[`${n}.ACQUISITIONMODE`]),P(e,"lpNumberOfCoefficients",t[`${n}NCOEF`]),P(e,"linearPredictionBin",t[`${n}LPBIN`]),P(e,"tdOff",t[`${n}TDoff`])}import{getOneIfArray as no}from"@zakodium/nmrium-core";import{UTCDate as Ki}from"@date-fns/utc";import{getOneIfArray as Zi}from"@zakodium/nmrium-core";import{getTime as Xt,isValid as Vt,parse as Qi,parseISO as eo}from"date-fns";import{removeComment as to}from"jcampconverter";function Wt(e,t){if(t!==null&&Number.isInteger(t)){e.epoch=t;let r=new Date(t);e.date=r.toISOString(),e.localeDate=r.toLocaleString()}}function Ht(e,t,r={}){let n=t.LONGDATE??Zi(t.DATE);if(!n)return;let{separator:i}=r,o=Number(n)*1e3;Wt(e,o||ro(n,i))}function ro(e,t){let r=to(e,t),n=eo(r,{});if(Vt(n)){let o=n.getTimezoneOffset()*60*1e3;return Xt(n)-o}let i=["dd/MM/yyyy HH:mm:ss","EEE MMM dd HH:mm:ss yyyy","dd/MM/yyyy HH:mm:ss","yyyy/MM/dd HH:mm:ss.SSS X","yyyy/MM/dd HH:mm:ssX","yyyy/MM/dd HH:mm:ss.SSS","yyyy/MM/dd HH:mm:ss","yyyy/MM/dd HH:mm","yyyy/MM/dd","yy/MM/dd"];for(let o of i){let s=Qi(r,o,new Ki,{useAdditionalDayOfYearTokens:!0});if(Vt(s))return Xt(s)}return null}function Gt(e,t,r){let{prefix:n="",separator:i}=r;(t.LONGDATE||t.DATE)&&Ht(e,t,{separator:i}),D(e,"pulseSequence",t[".PULSESEQUENCE"]||t[".PULPROG"]||t[`${n}PULPROG`]);let o=t[`${n}OWNER`];if(o&&D(e,"owner",o.replaceAll(/\$\$.*/gm,"")),D(e,"title",t.TITLE),D(e,"aqMod",t[`${n}AQ_mod`]),D(e,"windowMultiplicationMode",t[`${n}WDW`]),D(e,"experiment",ce(e,t,{prefix:n})),D(e,"solvent",t[".SOLVENTNAME"]||no(t[`${n}SOLVENT`])),D(e,"temperature",t[`${n}TE`]||t[".TE"]),D(e,"type",t.DATATYPE),D(e,"dataClass",t[`${n}DATACLASS`]),D(e,"phc0",t[`${n}PHC0`]),D(e,"phc1",t[`${n}PHC1`]),e.type){let s=e.type[0].toUpperCase();s.includes("FID")?(e.isFid=!0,e.isComplex=!0):s.includes("SPECTRUM")&&(e.isFt=!0)}if(D(e,"firstX",t[`${n}FIRSTX`]),D(e,"lastX",t[`${n}LASTX`]),D(e,"numberOfPoints",t[`${n}NPOINTS`]),`${n}REVERSE`in t){let s=t[`${n}REVERSE`];e.reverse=(Array.isArray(s)?s:[s]).map(a=>typeof a=="string"?a.includes("yes"):a)}}function Yt(e){let{JCAMPDX:t="",ORIGIN:r=""}=e,n=String(t).toLowerCase()+String(r).toLowerCase();return"SPECTROMETER/DATASYSTEM"in e&&(n=e["SPECTROMETER/DATASYSTEM"]),(n.includes("mestre")||n.includes("nova"))&&(n="mnova"),n}import{isAnyArray as io}from"is-any-array";import{calculateRelativeFrequency as oo}from"nmr-processing";function Kt(e,t,r){let{prefix:n=""}=r;if(P(e,"originFrequency",t[`${n}SFO1`]),e.dimension===1&&P(e,"originFrequency",t[".OBSERVEFREQUENCY"]),!e.originFrequency&&e.dimension===2&&".OBSERVEFREQUENCY"in t){let i=G(t[".OBSERVEFREQUENCY"]);if(io(i)&&i.length>1){let o=t[`${n}SYMBOL`].split(","),s=o.findIndex(c=>c.includes("2")),a=o.findIndex(c=>c.includes("1"));s!==-1&&a!==-1?e.originFrequency=[i[s],i[a]]:e.originFrequency=i.slice()}else typeof i=="number"&&(e.originFrequency=oo(e.nucleus,i))}(!e.originFrequency||e.originFrequency.some(i=>Number.isNaN(i)||i===0))&&(e.originFrequency=e.dimension>1?[400,400]:[400],r.logger?.warn("Frequency could not be determined, set to 400 MHz"))}function C(e,t,r=""){return e.every(n=>`${r}${n}`in t)}import{matrixTranspose as so}from"ml-spectra-processing";function ne(e,t){return so(e).map(t)}function Zt(e,t,r){let{prefix:n=""}=r,i=t[`${n}REFERENCE_POINT`];if(!("baseFrequency"in e)&&"originFrequency"in e&&D(e,"baseFrequency",e.originFrequency),!("frequencyOffset"in e)&&i&&C(["spectralWidth","baseFrequency"],e)){let o=typeof i=="number"?i:Number(t[`${n}REFERENCE_POINT`].match(/(?<reference>[+-]?\d+(?:\.\d+)?)\s*.*/)?.groups?.reference);if(!Number.isNaN(o)){let{spectralWidth:s,baseFrequency:a}=e;D(e,"frequencyOffset",.5*s[0]*a[0]-o)}}if(!("frequencyOffset"in e)&&C(["baseFrequency","originFrequency"],e)){let{baseFrequency:o,originFrequency:s}=e;D(e,"frequencyOffset",ne([s,o],a=>(a[0]-a[1])*1e6))}!e.frequencyOffset[0]&&".SHIFTREFERENCE"in t&&ao(t,e)}function ao(e,t){let r=e[".SHIFTREFERENCE"],n=r.trim().startsWith("(")?/\((?<data>[^)]+)\)/:/(?<data>[^)]+)/,i=r.match(n);if(i.groups.data){let o=i.groups.data.split(",");if(o.length<4)return;let s=Number.parseInt(t.numberOfPoints,10),{spectralWidth:a,baseFrequency:c}=t,l=Number.parseInt(o[2],10),m=Number.parseFloat(o[3]),p;if(t.isFid){if(!C(["numberOfPoints","spectralWidth"],t))return;p=m+(s*.5-l)*a/s}else if(C(["firstX","lastX","numberOfPoints"],t)){let f=Number.parseFloat(t.firstX),g=Number.parseFloat(t.lastX),y=(g+f)/2,u=(g-f)/(s+1),h=u<0?f:g+(l-1)*u;p=(y-h)/c+m}p!==void 0&&!Number.isNaN(p)&&(t.frequencyOffset=p*c)}}import{isAnyArray as Y}from"is-any-array";function he(e){return typeof e=="number"}function be(e){let{phc0:t,phc1:r}=e;return!Y(t)&&!he(t)||!Y(r)&&!he(r)||Y(t)&&!he(t[0])||Y(r)&&!he(r[0])?{}:(Y(r)?r[0]*=-1:r*=-1,Y(t)?t[0]*=-1:t*=-1,{phc0:t,phc1:r})}function Qt(e,t){let{T1NUCLEUS:r,T2NUCLEUS:n,PAGE:i}=t;e.pulseSequence=t.EXPERIMENT||t[".PULSESEQUENCE"];let o=[],{dimension:s,isComplex:a}=e;if(s===2&&e.pulseSequence==="T1"){let m=a?2:1;for(let p=0;p<i.length;p+=m){let f=i[p].replace(/T1=/,"");o.push(Number(f))}t.vdlistValues=o}e.nucleus=s>1?[n,r]:[n];let{phc0:c,phc1:l}=e;if(c&&l){let m=be({phc0:c,phc1:l});e={...e,...m}}}import{getOneIfArray as rr}from"@zakodium/nmrium-core";import{getGyromagneticRatio as co}from"gyromagnetic-ratio";function tr(e,t,r){if(e>0)return e;if(t>14||t===0)return 0;if(er[t]){let n=er[t];if(!n[r])throw new Error(`decim ${r} not in lookup table for dspfvs ${t}`);return n[r]}else throw new Error(`dspfvs ${t} not in lookup table`)}var er={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}};function nr(e,t,r){let{prefix:n=""}=r,i=e.nucleus[0],o=co(i);if(D(e,"probeName",t[`${n}PROBHD`]),D(e,"baseFrequency",t[`${n}BF1`]||t[`${n}SF`]),P(e,"scaleFactor",t[`${n}NC_proc`]),"scaleFactor"in e&&(e.scaleFactor=e.scaleFactor.map(a=>2**a)),!("baseFrequency"in e)&&"originFrequency"in e?D(e,"baseFrequency",e.originFrequency):e.baseFrequency=G(e.baseFrequency),o&&C(["baseFrequency","originFrequency"],e)){let a=2*Math.PI*(e.baseFrequency[0]/o)*1e6;D(e,"fieldStrength",a)}if(P(e,"spectralWidth",t[`${n}SW`]||t[`${n}QM_SPECTRAL_WIDTH`]),e.dimension===1&&t[`${n}SweepWidth`]&&e.originFrequency&&P(e,"spectralWidth",t[`${n}SweepWidth`]/e.originFrequency[0]),D(e,"numberOfPoints",t[`${n}TD`],!0),D(e,"spectrumSize",t[`${n}SI`]??e.numberOfPoints),D(e,"sampleName",t[`${n}NAME`]),t[`${n}FNTYPE`]!==void 0&&D(e,"acquisitionMode",Number.parseInt(t[`${n}FNTYPE`],10)),t[`${n}VARNAME`]?.split(",")[0]==="TIME"){let a=typeof t.LAST=="string"?t.LAST.replace(" ","").split(",")[0]:t.LAST;P(e,"acquisitionTime",a)}if(!e.acquisitionTime&&C(["numberOfPoints","spectralWidth"],e)){let{spectralWidth:a,originFrequency:c,numberOfPoints:l}=e;D(e,"acquisitionTime",(l[0]-1)/(2*a[0]*c[0]))}if(t[`${n}P`]){let a=1e6/(rr(t[`${n}P`]).split(r.separator||`
|
|
3
|
+
`)){if(!h)continue;let[d]=h.trim().match(/\s*([\d.]+)\s*/)?.slice(1)||[];u.push(d)}r.meta.difflist=u}r.meta.SW_p||(r.meta.SW_p=r.meta.SW_h),r.meta.SF||(r.meta.SF=r.meta.SFO1);let s=["2rr","2ri","2ir","2ii"].some(u=>u in e);r.meta.nbSubSpectra=s?Number.parseInt(r.meta.SI[1],10):Number.parseInt(r.meta.TD[1],10);let a=0,c=0,l=0,m=0;if(s){let u=Number(r.meta.SF[1]),h=Number(r.meta.SW_p[1]||r.meta.SW[1]);m=Number(r.meta.OFFSET[1]),l=Number(r.meta.OFFSET[0]),a=m,c=m-h/u,r.meta.firstY=a,r.meta.lastY=c,de({rr:e["2rr"],ri:e["2ri"],ir:e["2ir"],ii:e["2ii"]},r,t)}else if(e.ser){a=0,c=r.meta.nbSubSpectra;let u=Number(r.meta.SW[0]),h=Number(r.meta.SW[1]),d=Number(r.meta.SFO1[0]),b=Number(r.meta.SFO1[1]),F=Number(r.meta.O1[0]),S=Number(r.meta.O1[1]);l=F/d+u/2,m=S/b+h/2,ge(e.ser,r,t)}if(t.keepSpectra){let{nbSubSpectra:u}=r.meta,h=(c-a)/(u-1),d=a;for(let b=0;b<u;b++)d+=h,r.spectra[b].pageValue=d}let{NUC1:p,AXNUC:f,SF:g}=r.meta,y=f||p||[];return r.info["2D_Y_NUCLEUS"]=y[1],r.info["2D_X_NUCLEUS"]=y[0],r.info["2D_Y_FRECUENCY"]=g[1],r.info["2D_X_FRECUENCY"]=g[0],r.info["2D_Y_OFFSET"]=m,r.info["2D_X_OFFSET"]=l,r.info.twoD=!0,r.twoD=!0,r}async function He(e,t={}){let r,n=!1,i=!1;if(["ser","2rr","2ri","2ir","2ii"].some(s=>s in e))n=!0,r=await qt(e,t);else if(e["1r"]||e["1i"]||e.fid)i=!0,r=await _t(e,t);else throw new RangeError("The current files are invalid");let o={name:e.name,expno:e.expno,isFID:!!e.isFID};for(let s in e){let a=s;(typeof e[a]).match(/number|string|boolean/)&&(o[a]=e[a])}r.source=n?{...o,is2D:n}:{...o,is1D:i},t.keepFiles&&(r.source.files=e.fileCollectionItems),r.meta.DATE=Number(r.meta.DATE),r.meta.GRPDLY&&(Ve(r.meta,"DSPFVS",r.meta.DSPFVS),Ve(r.meta,"GRPDLY",r.meta.GRPDLY),Ve(r.meta,"DECIM",r.meta.DECIM));for(let s in r.meta)Array.isArray(r.meta[s])&&(r.meta[s].length===1||typeof r.meta[s][0]=="string"&&r.meta[s][0].includes("(0.."))&&(r.meta[s]=r.meta[s][0]);return r}function Ve(e,t,r){r!==void 0&&(Array.isArray(r)?e[t]=r.slice():e[t]=[r])}var B={};xt(B,{ECHO_ANTIECHO:()=>Xi,QF:()=>Ui,QSEC:()=>$i,STATES:()=>Ji,STATES_TPPI:()=>Wi,TTPI:()=>zi});var Ui=1,$i=2,zi=3,Ji=4,Wi=5,Xi=6;import{formatSpectra as go}from"@zakodium/nmrium-core";function ye(e){let t=[];for(let r of e){if(!r)continue;let{groups:{value:n,unit:i}={}}=r.trim().match(/[$$]*\s*(?<value>[\d.]+)\s*(?<unit>[a-zA-Z]+)/)||{};t.push(Vi(n,i))}return t}function Vi(e,t){switch(t.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 Bt}from"is-any-array";function U(e){if(Hi(e))return Gi(e)?e.map(jt):jt(e);if(typeof e=="object"&&e!==null){let t={};for(let r in e)t[r]=U(e[r]);return t}return e}function Hi(e){return Bt(e)}function jt(e){return Float64Array.from(e)}function Gi(e){return Bt(e[0])}import{isAnyArray as po}from"is-any-array";import{getOneIfArray as Ki}from"@zakodium/nmrium-core";var Yi=new Map([[String(H.QSIM),"notPhaseSensitive"],["notphasesensitive","notPhaseSensitive"],[String(H.QSEQ),"QSEQ"],["qseq","QSEQ"],[String(B.TTPI),"TPPI"],["tppi","TPPI"],[String(B.STATES),"States"],["states","States"],[String(B.STATES_TPPI),"States-TPPI"],["tppi-states","States-TPPI"],[String(B.ECHO_ANTIECHO),"Echo-antiecho"],["echo-antiecho","Echo-antiecho"]]);function Ut(e){let t=String(e).toLowerCase().replaceAll(" ","");return Yi.get(t)}function D(e,t,r,n=!1){r===void 0||t in e&&!n||(Array.isArray(r)?e[t]=r.map($t):e[t]=[$t(r)])}function $t(e){return typeof e=="string"&&(e.startsWith("<")&&e.endsWith(">")&&(e=e.slice(1,-1)),e=e.replace(/\$.*/,"").trim()),e}function G(e){return Array.isArray(e)?e.map(zt):zt(e)}function zt(e){return typeof e=="string"?Number.parseFloat(e):e}function P(e,t,r){r!==void 0&&D(e,t,G(r))}function Jt(e,t,r){let{prefix:n=""}=r,i=t[`${n}.ACQUISITIONSCHEME`]||t[`${n}FnMODE`];i&&D(e,"acquisitionScheme",Ut(Ki(i,1))),D(e,"acquisitionMode",t[`${n}.ACQUISITIONMODE`]),P(e,"lpNumberOfCoefficients",t[`${n}NCOEF`]),P(e,"linearPredictionBin",t[`${n}LPBIN`]),P(e,"tdOff",t[`${n}TDoff`])}import{getOneIfArray as io}from"@zakodium/nmrium-core";import{UTCDate as Zi}from"@date-fns/utc";import{getOneIfArray as Qi}from"@zakodium/nmrium-core";import{getTime as Xt,isValid as Vt,parse as eo,parseISO as to}from"date-fns";import{removeComment as ro}from"jcampconverter";function Wt(e,t){if(t!==null&&Number.isInteger(t)){e.epoch=t;let r=new Date(t);e.date=r.toISOString(),e.localeDate=r.toLocaleString()}}function Ht(e,t,r={}){let n=t.LONGDATE??Qi(t.DATE);if(!n)return;let{separator:i}=r,o=Number(n)*1e3;Wt(e,o||no(n,i))}function no(e,t){let r=ro(e,t),n=to(r,{});if(Vt(n)){let o=n.getTimezoneOffset()*60*1e3;return Xt(n)-o}let i=["dd/MM/yyyy HH:mm:ss","EEE MMM dd HH:mm:ss yyyy","dd/MM/yyyy HH:mm:ss","yyyy/MM/dd HH:mm:ss.SSS X","yyyy/MM/dd HH:mm:ssX","yyyy/MM/dd HH:mm:ss.SSS","yyyy/MM/dd HH:mm:ss","yyyy/MM/dd HH:mm","yyyy/MM/dd","yy/MM/dd"];for(let o of i){let s=eo(r,o,new Zi,{useAdditionalDayOfYearTokens:!0});if(Vt(s))return Xt(s)}return null}function Gt(e,t,r){let{prefix:n="",separator:i}=r;(t.LONGDATE||t.DATE)&&Ht(e,t,{separator:i}),D(e,"pulseSequence",t[".PULSESEQUENCE"]||t[".PULPROG"]||t[`${n}PULPROG`]);let o=t[`${n}OWNER`];if(o&&D(e,"owner",o.replaceAll(/\$\$.*/gm,"")),D(e,"title",t.TITLE),D(e,"aqMod",t[`${n}AQ_mod`]),D(e,"windowMultiplicationMode",t[`${n}WDW`]),D(e,"experiment",ce(e,t,{prefix:n})),D(e,"solvent",t[".SOLVENTNAME"]||io(t[`${n}SOLVENT`])),D(e,"temperature",t[`${n}TE`]||t[".TE"]),D(e,"type",t.DATATYPE),D(e,"dataClass",t[`${n}DATACLASS`]),D(e,"phc0",t[`${n}PHC0`]),D(e,"phc1",t[`${n}PHC1`]),e.type){let s=e.type[0].toUpperCase();s.includes("FID")?(e.isFid=!0,e.isComplex=!0):s.includes("SPECTRUM")&&(e.isFt=!0)}if(D(e,"firstX",t[`${n}FIRSTX`]),D(e,"lastX",t[`${n}LASTX`]),D(e,"numberOfPoints",t[`${n}NPOINTS`]),`${n}REVERSE`in t){let s=t[`${n}REVERSE`];e.reverse=(Array.isArray(s)?s:[s]).map(a=>typeof a=="string"?a.includes("yes"):a)}}function Yt(e){let{JCAMPDX:t="",ORIGIN:r=""}=e,n=String(t).toLowerCase()+String(r).toLowerCase();return"SPECTROMETER/DATASYSTEM"in e&&(n=e["SPECTROMETER/DATASYSTEM"]),(n.includes("mestre")||n.includes("nova"))&&(n="mnova"),n}import{isAnyArray as oo}from"is-any-array";import{calculateRelativeFrequency as so}from"nmr-processing";function Kt(e,t,r){let{prefix:n=""}=r;if(P(e,"originFrequency",t[`${n}SFO1`]),e.dimension===1&&P(e,"originFrequency",t[".OBSERVEFREQUENCY"]),!e.originFrequency&&e.dimension===2&&".OBSERVEFREQUENCY"in t){let i=G(t[".OBSERVEFREQUENCY"]);if(oo(i)&&i.length>1){let o=t[`${n}SYMBOL`].split(","),s=o.findIndex(c=>c.includes("2")),a=o.findIndex(c=>c.includes("1"));s!==-1&&a!==-1?e.originFrequency=[i[s],i[a]]:e.originFrequency=i.slice()}else typeof i=="number"&&(e.originFrequency=so(e.nucleus,i))}(!e.originFrequency||e.originFrequency.some(i=>Number.isNaN(i)||i===0))&&(e.originFrequency=e.dimension>1?[400,400]:[400],r.logger?.warn("Frequency could not be determined, set to 400 MHz"))}function C(e,t,r=""){return e.every(n=>`${r}${n}`in t)}import{matrixTranspose as ao}from"ml-spectra-processing";function ne(e,t){return ao(e).map(t)}function Zt(e,t,r){let{prefix:n=""}=r,i=t[`${n}REFERENCE_POINT`];if(!("baseFrequency"in e)&&"originFrequency"in e&&D(e,"baseFrequency",e.originFrequency),!("frequencyOffset"in e)&&i&&C(["spectralWidth","baseFrequency"],e)){let o=typeof i=="number"?i:Number(t[`${n}REFERENCE_POINT`].match(/(?<reference>[+-]?\d+(?:\.\d+)?)\s*.*/)?.groups?.reference);if(!Number.isNaN(o)){let{spectralWidth:s,baseFrequency:a}=e;D(e,"frequencyOffset",.5*s[0]*a[0]-o)}}if(!("frequencyOffset"in e)&&C(["baseFrequency","originFrequency"],e)){let{baseFrequency:o,originFrequency:s}=e;D(e,"frequencyOffset",ne([s,o],a=>(a[0]-a[1])*1e6))}!e.frequencyOffset[0]&&".SHIFTREFERENCE"in t&&co(t,e)}function co(e,t){let r=e[".SHIFTREFERENCE"],n=r.trim().startsWith("(")?/\((?<data>[^)]+)\)/:/(?<data>[^)]+)/,i=r.match(n);if(i.groups.data){let o=i.groups.data.split(",");if(o.length<4)return;let s=Number.parseInt(t.numberOfPoints,10),{spectralWidth:a,baseFrequency:c}=t,l=Number.parseInt(o[2],10),m=Number.parseFloat(o[3]),p;if(t.isFid){if(!C(["numberOfPoints","spectralWidth"],t))return;p=m+(s*.5-l)*a/s}else if(C(["firstX","lastX","numberOfPoints"],t)){let f=Number.parseFloat(t.firstX),g=Number.parseFloat(t.lastX),y=(g+f)/2,u=(g-f)/(s+1),h=u<0?f:g+(l-1)*u;p=(y-h)/c+m}p!==void 0&&!Number.isNaN(p)&&(t.frequencyOffset=p*c)}}import{isAnyArray as Y}from"is-any-array";function he(e){return typeof e=="number"}function be(e){let{phc0:t,phc1:r}=e;return!Y(t)&&!he(t)||!Y(r)&&!he(r)||Y(t)&&!he(t[0])||Y(r)&&!he(r[0])?{}:(Y(r)?r[0]*=-1:r*=-1,Y(t)?t[0]*=-1:t*=-1,{phc0:t,phc1:r})}function Qt(e,t){let{T1NUCLEUS:r,T2NUCLEUS:n,PAGE:i}=t;e.pulseSequence=t.EXPERIMENT||t[".PULSESEQUENCE"];let o=[],{dimension:s,isComplex:a}=e;if(s===2&&e.pulseSequence==="T1"){let m=a?2:1;for(let p=0;p<i.length;p+=m){let f=i[p].replace(/T1=/,"");o.push(Number(f))}t.vdlistValues=o}e.nucleus=s>1?[n,r]:[n];let{phc0:c,phc1:l}=e;if(c&&l){let m=be({phc0:c,phc1:l});e={...e,...m}}}import{getOneIfArray as rr}from"@zakodium/nmrium-core";import{getGyromagneticRatio as lo}from"gyromagnetic-ratio";function tr(e,t,r){if(e>0)return e;if(t>14||t===0)return 0;if(er[t]){let n=er[t];if(!n[r])throw new Error(`decim ${r} not in lookup table for dspfvs ${t}`);return n[r]}else throw new Error(`dspfvs ${t} not in lookup table`)}var er={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}};function nr(e,t,r){let{prefix:n=""}=r,i=e.nucleus[0],o=lo(i);if(D(e,"probeName",t[`${n}PROBHD`]),D(e,"baseFrequency",t[`${n}BF1`]||t[`${n}SF`]),P(e,"scaleFactor",t[`${n}NC_proc`]),"scaleFactor"in e&&(e.scaleFactor=e.scaleFactor.map(a=>2**a)),!("baseFrequency"in e)&&"originFrequency"in e?D(e,"baseFrequency",e.originFrequency):e.baseFrequency=G(e.baseFrequency),o&&C(["baseFrequency","originFrequency"],e)){let a=2*Math.PI*(e.baseFrequency[0]/o)*1e6;D(e,"fieldStrength",a)}if(P(e,"spectralWidth",t[`${n}SW`]||t[`${n}QM_SPECTRAL_WIDTH`]),e.dimension===1&&t[`${n}SweepWidth`]&&e.originFrequency&&P(e,"spectralWidth",t[`${n}SweepWidth`]/e.originFrequency[0]),D(e,"numberOfPoints",t[`${n}TD`],!0),D(e,"spectrumSize",t[`${n}SI`]??e.numberOfPoints),D(e,"sampleName",t[`${n}NAME`]),t[`${n}FNTYPE`]!==void 0&&D(e,"acquisitionMode",Number.parseInt(t[`${n}FNTYPE`],10)),t[`${n}VARNAME`]?.split(",")[0]==="TIME"){let a=typeof t.LAST=="string"?t.LAST.replace(" ","").split(",")[0]:t.LAST;P(e,"acquisitionTime",a)}if(!e.acquisitionTime&&C(["numberOfPoints","spectralWidth"],e)){let{spectralWidth:a,originFrequency:c,numberOfPoints:l}=e;D(e,"acquisitionTime",(l[0]-1)/(2*a[0]*c[0]))}if(t[`${n}P`]){let a=1e6/(rr(t[`${n}P`]).split(r.separator||`
|
|
4
4
|
`)[1].split(" ")[1]*4);D(e,"pulseStrength90",a)}if(t[`${n}D`]){let a=rr(t[`${n}D`]).split(r.separator||`
|
|
5
|
-
`)[1].split(" ")[1];P(e,"relaxationTime",a)}if(P(e,"numberOfScans",t[`${n}NS`]||t[`${n}QM_NSCANS`]),D(e,"groupDelay",t[`${n}GRPDLY`]),D(e,"dspfvs",t[`${n}DSPFVS`]),D(e,"decim",t[`${n}DECIM`]),e.isFid&&("groupDelay"in e||C(["dspfvs","decim"],e))){let{groupDelay:a,dspfvs:c,decim:l}=e,m=tr(a?.[0]??0,c?.[0],l?.[0]);D(e,"digitalFilter",m)}if(C(["numberOfPoints","spectralWidth"],e)){let{spectralWidth:a,numberOfPoints:c}=e,l=c.map((m,p)=>e.isFid?e.acquisitionTime[0]/(m-1):a[p]/(m-1));D(e,"increment",l)}}function $(e,t=","){if(e&&typeof e=="string")return e.split(t)}function ir(e,t,r){let{prefix:n=""}=r,i=e.dimension<2,o=e.dataClass?.[0].toUpperCase()==="NTUPLES",s=C(["LAST","FIRST","VARDIM","SYMBOL"],t,n);if(i&&(o||s)&&(D(e,"last",$(t[`${n}LAST`])),D(e,"first",$(t[`${n}FIRST`])),D(e,"varDim",$(t[`${n}VARDIM`])),D(e,"symbols",$(t[`${n}SYMBOL`])),e.symbols&&Array.isArray(e.symbols))){e.symbols.includes("R")&&e.symbols.includes("I")&&(e.isComplex=!0);let a=e.symbols.findIndex(c=>c.toLowerCase()==="x");if(P(e,"firstX",e.first[a]),P(e,"lastX",e.last[a]),P(e,"numberOfPoints",e.varDim[a]),!("spectralWidth"in e)){let{lastX:c,numberOfPoints:l,firstX:m,originFrequency:p}=e;D(e,"spectralWidth",e.isFid?ne([l,c],f=>f[0]/(2*f[1])):ne([c,m,p],f=>Math.abs(f[0]-f[1])/f[2]))}}}import{normalizeNucleus as
|
|
5
|
+
`)[1].split(" ")[1];P(e,"relaxationTime",a)}if(P(e,"numberOfScans",t[`${n}NS`]||t[`${n}QM_NSCANS`]),D(e,"groupDelay",t[`${n}GRPDLY`]),D(e,"dspfvs",t[`${n}DSPFVS`]),D(e,"decim",t[`${n}DECIM`]),e.isFid&&("groupDelay"in e||C(["dspfvs","decim"],e))){let{groupDelay:a,dspfvs:c,decim:l}=e,m=tr(a?.[0]??0,c?.[0],l?.[0]);D(e,"digitalFilter",m)}if(C(["numberOfPoints","spectralWidth"],e)){let{spectralWidth:a,numberOfPoints:c}=e,l=c.map((m,p)=>e.isFid?e.acquisitionTime[0]/(m-1):a[p]/(m-1));D(e,"increment",l)}}function $(e,t=","){if(e&&typeof e=="string")return e.split(t)}function ir(e,t,r){let{prefix:n=""}=r,i=e.dimension<2,o=e.dataClass?.[0].toUpperCase()==="NTUPLES",s=C(["LAST","FIRST","VARDIM","SYMBOL"],t,n);if(i&&(o||s)&&(D(e,"last",$(t[`${n}LAST`])),D(e,"first",$(t[`${n}FIRST`])),D(e,"varDim",$(t[`${n}VARDIM`])),D(e,"symbols",$(t[`${n}SYMBOL`])),e.symbols&&Array.isArray(e.symbols))){e.symbols.includes("R")&&e.symbols.includes("I")&&(e.isComplex=!0);let a=e.symbols.findIndex(c=>c.toLowerCase()==="x");if(P(e,"firstX",e.first[a]),P(e,"lastX",e.last[a]),P(e,"numberOfPoints",e.varDim[a]),!("spectralWidth"in e)){let{lastX:c,numberOfPoints:l,firstX:m,originFrequency:p}=e;D(e,"spectralWidth",e.isFid?ne([l,c],f=>f[0]/(2*f[1])):ne([c,m,p],f=>Math.abs(f[0]-f[1])/f[2]))}}}import{normalizeNucleus as mo}from"nmr-processing";function Fe(e,t,r){let n=[];if(e[`${r}AXNUC`]&&(n=e[`${r}AXNUC`],Array.isArray(n)||(n=[n]),n=v(n)),n.length===0&&e[`${r}NUC1`]&&(n=e[`${r}NUC1`],Array.isArray(n)||(n=[n]),n=v(n)),n.length===0&&e[".NUCLEUS"]){let i=$(e[".NUCLEUS"]);if(e[`${r}SYMBOL`]){let o=e[`${r}SYMBOL`].split(","),s=o.findIndex(c=>c.includes("2")),a=o.findIndex(c=>c.includes("1"));s!==-1&&a!==-1&&i?n=v([i[s],i[a]]):n=v(i).toReversed()}else n=v(i)}return n.length===0&&e[".OBSERVENUCLEUS"]&&(n=v([e[".OBSERVENUCLEUS"]])),n.length===0&&t.experiment&&(n=v(or(t.experiment[0]))),uo(e)&&(n=[e["2D_X_NUCLEUS"].replaceAll(/[^A-Za-z0-9]/g,""),e["2D_Y_NUCLEUS"].replaceAll(/[^A-Za-z0-9]/g,"")]),t.experiment&&(t.experiment[0].match("jres")||t.experiment[0].match("dosy"))&&(n=or(t.experiment[0])),n.map(mo)}function uo(e){return e["2D_X_NUCLEUS"]&&!e["2D_X_NUCLEUS"].includes("off")&&e["2D_Y_NUCLEUS"]&&!e["2D_Y_NUCLEUS"].includes("off")}function or(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 v(e){if(!e)return[];let t=e.map(n=>String(n).replaceAll(/[^A-Za-z0-9]/g,"").replace("NA","").replace("off","")),r=0;for(let n of t)n||r++;return r===0?t:[]}function sr(e,t,r){let{logger:n,prefix:i=""}=r;if(e.nucleus=Fe(t,e,i),e.nucleus.length===0)if(n)n.warn("No nucleus detected, assuming 1H"),e.nucleus=["1H"];else throw new Error("No nucleus detected");e.dimension=e.nucleus.length}function ar(e,t,r={}){let{prefix:n="",separator:i=`
|
|
6
6
|
`}=r;D(e,"spectralWidth",t[`${n}SweepWidth`]/e.originFrequency[0]);let o=t[`${n}.PULSESEQUENCE`].split(i),s=[];t[".OBSERVENUCLEUS"]&&s.push(t[".OBSERVENUCLEUS"]),t.INDIRECTNUCLEUS&&s.push(t.INDIRECTNUCLEUS),e.nucleus=v(s),e.pulseSequence=o[0];let a=o.slice(2,-1);if(s.length>1)if(s[0]===s[1])e.spectralWidth.push(e.spectralWidth[0]);else{let c=JSON.stringify(a).match(/\$\$SW1=\s*(?<sw>[+-]?(?:[0-9]*[.])?[0-9]+)/);if(c?.groups){let{originFrequency:l}=e,m=Number.parseFloat(c.groups.sw);e.spectralWidth.push(m/l[1])}}}function xe(e,t={}){let{prefix:r="",logger:n}=t,i={creator:Yt(e),dimension:0,nucleus:[],isFid:!1,isFt:!1},o=JSON.stringify(e),s=/\r\n/.exec(o)?`\r
|
|
7
7
|
`:`
|
|
8
|
-
`,a=[Gt,sr,Jt,Kt],{creator:c=""}=i;c.includes("nanalysis")?a.push(Qt):c.toLocaleLowerCase().includes("oxford instruments")&&a.push(ar),c!=="mnova"&&c!=="mestre"&&a.push(nr),a.push(ir,Zt);for(let l of a)l(i,e,{prefix:r,logger:n,separator:s});return
|
|
9
|
-
because it didn't match the import filters`);continue}s.push(m)}let a=[],c=s.some(ur),l=s.some(mr);for(let m of s){if(o!=="both"&&m.dataType!=="LINK"){if(ur(m)&&(o==="ft"||o==="preferFT"&&l)){n?.warn(`Skipping raw data ${r?`in ${r}`:"in the JCAMP-DX"} because it didn't match the import filters`);continue}if(mr(m)&&(o==="fid"||o==="preferFID"&&c)){n?.warn(`Skipping FFT data ${r?`in ${r}`:"in the JCAMP-DX"} because it didn't match the import filters`);continue}}a.push(m)}return a}function mr(e){return e.dataType?.toUpperCase().includes("SPECTRUM")&&e.dataClass&&!e.dataClass.toUpperCase().includes("PEAK")}function ur(e){return e.dataType?.toUpperCase().includes("FID")}function fr(e,t={}){let{logger:r,name:n=""}=t;for(let i of e){if(i.dataType==="LINK"&&fr(i.children,t))return!0;let{dataType:o=""}=i,s=o.toLowerCase();if(s.length>0){if(s.includes("spectrum")&&!s.includes("nmr"))return r?.warn(`File ${n} was ignored because it is a ${o}`),!1;if(s.includes("nmr"))return!0}}return!1}import{generateID as yr}from"@zakodium/nmrium-core";import{parseJcampCS as Oo}from"jcampconverter";import*as Co from"openchemlib";import{isMolfileNotEmpty as Ao}from"nmr-processing";import*as Io from"openchemlib";import{fromMolfile as Mo}from"openchemlib-utils";async function dr(e,t={}){let r=await e.text(),n=K(r),i={molecules:n,spectra:[]};return n.length===0&&t.logger?.debug(`${e.name} is an empty molfile`),i}function K(e){let t=[];if(!Ao(e))return[];let n=Mo(Io,e,{customLabelPosition:"superscript"}).toMolfileV3();return t.push({molfile:n}),t}import{isMolfileNotEmpty as Po}from"nmr-processing";import*as Eo from"openchemlib";import{getDiastereotopicAtomIDsFromMolfile as To}from"openchemlib-utils";var No=new Set(["ndnmrspectrum","ndnmrfid","nmrspectrum","nmrfid"]);function Se(e){let{dataType:t="",dataClass:r=""}=e,n=t.replaceAll(/\s/g,"").toLowerCase(),i=r.replaceAll(/\s/g,"").toLowerCase();return No.has(n)&&i!=="peaktable"}function gr(e,t,r={}){let{spectra:n,info:i,meta:o}=e,s=n[0].data,a=[],c={x:"delta",y:"intensity",w:"width",m:"multiplicity",a:"atom"},{logger:l,name:m,spectraData:p}=r,{CROSSREFERENCE:f}=i,g=typeof f!="string"?f:f.split(/\r?\n/).map(x=>x.trim()).filter(Boolean),y=g.find(x=>x?.toLowerCase().includes("structure"));if(y===void 0)return l&&l.warn(`There is not a structure reference for ${m} file, assignment object could not be completed`),null;let u=Number.parseInt(y?.toLowerCase().replace(/_/,"").replace(/structure:\s*blockid\s*=\s*(?<blockId>.*)/,"$<blockId>"),10);if(Number.isNaN(u)||u<1)return l&&l.warn(`Structure block_id not found for ${m} file, assignment object could not be completed`),null;let d=p?.molecules?.find(x=>x.blockId===u)?.molfile??"";if(d===""){let x=t.find(M=>M.info.BLOCKID===u),{MOLFILE:A=""}=x?.meta||{};d=A}if(!Po(d))return l&&l.warn(`Empty molfile for ${m} file with structure block_id = ${u}, assignment object could not be completed`),null;let b=To(Eo,d),F=Fe({...i,...o},{},"");for(let x=0;x<s.x.length;x++){let A={};for(let M in s){let T=s[M][x];typeof T=="string"&&T.startsWith("<")&&T.endsWith(">")&&(T=T.slice(1,-1)),A[c[M]]=T}if("atom"in A){let M=b.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)}a.push(A)}let S={};for(let x of a){let{delta:A,diaIDs:M}=x,T=`${A}_${M.join("_")}`;if(S[T])S[T].atoms.push(x.atom);else{let{atom:j,...re}=x;S[T]={...re,atoms:[x.atom]}}}let I=[];for(let x of g)x.toLowerCase().includes("spectrum")&&I.push(Number(x.toLowerCase().replace(/_/,"").replace(/.*:\s*blockid=(?<blockId>.*)/,"$<blockId>")));if(I.length===0){for(let x of t)if(Se(x)){let{BLOCKID:A}=x.info;I.push(Number(A))}I.length>1&&(I=[],l&&l.warn(`There is not a spectral cross-reference for the peak assignment in the ${m} file`))}return{moleculeBlockID:u,spectraBlockIDs:I,assignments:Object.values(S),molecule:b.molecule}}function hr(e,t,r,n){for(let i of e){let{meta:o,dataClass:s="",dataType:a="",info:c}=i,l=Number.parseInt(String(c.BLOCKID),10);o.MOLFILE?Lo(String(o.MOLFILE),t,l):i.jcampCS&&vo(i,t,l),Ro(s,a)&&wo(t,i,e,n),Se(i)&&r.push(i)}}function Ro(e,t){return e?.toLowerCase().includes("assignments")&&t?.toLowerCase().includes("assignments")}function wo(e,t,r,n){let i=gr(t,r,{spectraData:e,logger:n.logger,name:n.name});if(e.assignmentsByBlocks||(e.assignmentsByBlocks={}),i){let{spectraBlockIDs:o}=i;for(let s of o)e.assignmentsByBlocks[s]=i}}function vo(e,t,r){t.molecules||(t.molecules=[]);let n=Oo(e,{OCL:Co}),i=K(n?.molfile||"");i.length>0&&t.molecules.push({id:yr(),blockId:r,...i[0]})}function Lo(e,t,r){t.molecules||(t.molecules=[]);let n=K(e);t.molecules.push({id:yr(),blockId:r,...n[0]})}import{generateID as Or}from"@zakodium/nmrium-core";import{matrixMinMaxZ as Tr,reimPhaseCorrection as Xo}from"ml-spectra-processing";import{xyAutoRangesPicking as Vo}from"nmr-processing";function Z(e){return e.slice(0,Math.max(0,e.lastIndexOf(".")))}function Q(e){e.sort((t,r)=>t.from-r.from);for(let t=0;t<e.length-1;t++)e[t].to>e[t+1].from&&(e[t].to=Math.max(e[t+1].to,e[t].to),e[t].signals=e[t].signals.concat(e[t+1].signals),e[t].integration+=e[t+1].integration,e.splice(t+1,1),t--);return e}import{splitPatterns as Bo}from"nmr-processing";import{xMaxValue as ko}from"ml-spectra-processing";function ie(e){return e.trim().slice(1,-1).split(/,\s*/).map(t=>t.trim())}var _o={I:"id",X:"from",Y:"to",Hs:"delta",An:"integration",H:"nbAtoms",C:"multiplicity",N:"assignment","(J)":"js"},br=["I","X","Y","Hs","An","H","C","N","(J)"];function Fr(e){let t={headersFromParenthesis:[],headersFromComments:[],comments:[],data:[],multiplets:[]},r=e.split(/\r?\n/).filter(n=>n.trim()!=="");if(r.length===0)return t;if(r[0].startsWith("(")&&!r[0].match(/\d/)){let n=r.shift();t.headersFromParenthesis=ie(n)}return t.comments=r.filter(n=>n.startsWith("$$")).map(n=>n.replace(/^\$\$\s*/,"")),t.headersFromComments=jo(t.comments),t.data=r.filter(n=>!n.startsWith("$$")).map(ie),t.multiplets=qo(t),t}function qo(e,t={}){let{logger:r}=t,n=e.data[0].map((c,l)=>l).filter(c=>e.data.every(l=>Number.isNaN(l[c])||Number.isNaN(Number(l[c]))));if(r?.trace(`Parsing JCAMP-DX assignment: stringColumnIndexes: ${n.join(",")}`),n.length===0)return r?.warn("Parsing JCAMP-DX assignment: No string columns found. Skipping parsing of assignment."),[];let i=n[0],o;if(e.headersFromParenthesis.length>0&&e.headersFromParenthesis[i]==="C")o=e.headersFromParenthesis;else if(e.headersFromComments.length>0&&e.headersFromComments[i]==="C")o=e.headersFromComments;else if(br[i]==="C")o=br;else return r?.warn("No header found for multiplicity. Skipping parsing of assignment."),[];return ko(e.data.map(c=>c.length))>o.length&&r?.warn("Some assignments are containing more values than headers"),e.data.map(c=>{let l={};for(let m=0;m<o.length;m++){let p=o[m];l[_o[p]||p]=c[m]}return l})}function jo(e){return e.map(t=>t.split(":")[0].trim()).filter(t=>t.length>0)}function xr(e,t={}){let{logger:r}=t,n=Fr(e),i={multiplets:[],comments:n.comments};for(let o of n.multiplets){let{id:s,from:a,to:c,delta:l,integration:m,nbAtoms:p,multiplicity:f}=o,g={id:s,js:[],multiplicity:"",...Uo({from:a,to:c,delta:l,integration:m,nbAtoms:p})};if(typeof o.js=="string"){let y=o.js.split(/\s+/).map(Number.parseFloat),u=0,h=Bo(f).map(F=>{let S=(F?.multiplicity||1)-1;return u+=S,{value:F.value,multiplicity:F?.multiplicity,js:y.slice(u-S,u)}}),d=h.reduce((F,S)=>F+(S.multiplicity?S.multiplicity-1:0),0);y.length!==d&&r?.warn(`The number of j values (${y.length}) is not equal to the sum of the multiplicities - 1 (${d})`);let b=[];for(let F of h){if(F.js.every(S=>S===F.js[0])){b.push(F);continue}if(F.multiplicity!==F.js.length+1){b.push(F);continue}for(let S=0;S<F.multiplicity-1;S++)b.push({value:"d",multiplicity:2,js:[F.js[S]]})}b.sort((F,S)=>S.js[0]-F.js[0]),g.js=b.map(F=>({coupling:F.js[0],multiplicity:F.value}))}typeof o.assignment=="string"&&(g.assignment=zo(o.assignment)),typeof o.multiplicity=="string"&&(g.multiplicity=o.multiplicity),i.multiplets.push(g)}return i}function Uo(e){let t={};for(let r in e){let n=e[r],i=typeof n=="number"?n:Number.parseFloat(n);Number.isNaN(i)||(t[r]=i)}return t}var $o={quot:'"',apos:"'",comma:",",amp:"&",lpar:"(",rpar:")",lt:"<",gt:">",colon:":",semi:";"};function zo(e){return e.replaceAll(/&(\w+);/gi,(t,r)=>$o[r.toLowerCase()]||t)}function Dr(e){let t=e.split(/\r?\n/).filter(n=>n.trim()!==""),r=[];for(let n of t)if(n.startsWith("(")){let[i,o,s]=ie(n).map(Number.parseFloat);r.push({id:i,x:o,y:s})}return r}function Sr(e,t={}){let r={};if(!e["OBSERVED MULTIPLETS"])return[];let n=xr(e["OBSERVED MULTIPLETS"],t);if(!n)return[];let{multiplets:i}=n;for(let o of i){let{id:s,from:a,to:c,integration:l=0,...m}=o;r[s]={from:a,to:c,integration:l,signals:[{id:s,...m}]}}if(e["OBSERVED MULTIPLETS PEAKS"]){let o=Dr(e["OBSERVED MULTIPLETS PEAKS"]),s={};for(let a of o){let{id:c,x:l,y:m}=a;s[c]||(s[c]=[]),s[c].push({x:l,y:m,width:.05})}for(let a in r)s[a]&&(r[a].signals[0].peaks=s[a])}return Q(Object.values(r))}function Ar(e,t){let n=[...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})),i=[...t.nucleus[0].matchAll(/[0-9]*(?<element>[A-Z][a-z]?)/g,"$element")][0].groups.element;return n.find(o=>o.element===i)?.count||100}function Ir(e){let t={};return".PHASE0"in e&&(t.ph0=Number.parseFloat(e[".PHASE0"]),t.ph1=Number.parseFloat(e[".PHASE1"])),t}function Ze(e){let{ph0:t,ph1:r}=e;return Number.isFinite(t)&&Number.isFinite(r)}import{generateID as Mr}from"@zakodium/nmrium-core";function Nr(e,t,r){for(let n=0;n<e.length;n++){if(t.includes(n))continue;let{delta:i,multiplicity:o="",diaIDs:s}=e[n],a=i-.01,c=i+.01;r.push({from:a,to:c,integration:1,id:Mr(),signals:[{id:Mr(),delta:i,multiplicity:o,diaIDs:s}]})}}import{linearSumAssignment as Jo}from"linear-sum-assignment";import{xCostMatrix as Wo}from"ml-spectra-processing";function Pr(e,t){let r=e.map(s=>s.delta),n=t.map(s=>s.delta),i=Wo(n,r,{fct:(s,a)=>Math.abs(s-a)}),{rowAssignments:o}=Jo(i,{maximaze:!1});return Array.from(o)}function Er(e,t){let{assignments:r,ranges:n}=t;r?.sort((s,a)=>a.delta-s.delta);let i=[],o=[];for(let s of n){let a=0,{from:c,to:l}=s,m=[];for(let p=a;p<r.length;p++){let{delta:f}=r[p];f<=l&&f>=c?(m.push(r[p]),o.push(p)):f>l&&(a=p)}if(m.length>0){let p=s.signals,f=[],g=m.length>1&&p.length>1?Pr(p,m):[0];for(let y=0;y<m.length;y++){let u=g[y],{delta:h,multiplicity:d,diaIDs:b}=m[y];u>-1?f.push({...p[u],diaIDs:b}):f.push({delta:h,multiplicity:d,diaIDs:b})}s.signals=f,i.push(s)}}Nr(r,o,i),i.sort((s,a)=>s.from-a.from),e.ranges={values:Q(i).map(s=>{let{integration:a,...c}=s;return c}),options:{sum:t.integrationSum,isSumConstant:!0,sumAuto:!0}},e.ranges.options.moleculeId=String(t.moleculeId)}function Cr(e,t,r,n,i){let{logger:o}=i,s={components:Rr(e)?Yo(e,r.isFid):Go(e)},{name:a=r.title||`jcamp_${Or()}`}=i,c={dependentVariables:[s],meta:t,info:{...r,name:Z(a)}};return Ho(e)&&Ko(c,n,t,e,r,{logger:o}),c}function Rr(e){return"minMax"in e}function Ho(e){return!Rr(e)}function Go(e){return e.spectra.map(t=>{let r=U(t.data);return{...t,data:r}})}function Yo(e,t){let r={...e.minMax,z:U(e.minMax?.z)};return t?Zo(r):{rr:r}}function Ko(e,t,r,n,i,o){let{assignmentsByBlocks:s}=t,a=Ir(r);Ze(a)&&Qo(e,a);let c=String(n.info.BLOCKID);if(s?.[c]){let{molecule:l,assignments:m,moleculeBlockID:p}=s[c],f=Ar(l,i),g=U(n.spectra[0].data);if(g.x[0]>g.x[1])for(let d of n.spectra)d.data.x.reverse(),d.data.y.reverse();if(Ze(a)&&n.spectra.length>1){let{re:d}=es(n,a);g.y=d}let{x:y,y:u}=g,h=Sr(r,o)??Vo({x:y,y:u},{peakPicking:{frequency:i.originFrequency},ranges:{frequency:i.originFrequency,integrationSum:f}});Er(e,{moleculeId:p,ranges:h,assignments:m,integrationSum:f})}}function Zo(e){let{z:t,...r}=e,n=[],i=[];for(let a=0;a<t.length;a+=2)n.push(t[a].slice()),i.push(t[a+1].slice());let o=Tr(n),s=Tr(i);return{re:{...r,z:n,minZ:o.min,maxZ:o.max},im:{...r,z:i,minZ:s.min,maxZ:s.max}}}function Qo(e,t){let{ph0:r,ph1:n}=t;e.filters||(e.filters=[]),e.filters.push({id:Or(),name:"phaseCorrection",value:{ph0:r,ph1:n,absolute:!1},enabled:!0})}function es(e,t){let{ph0:r,ph1:n}=t,{re:i,im:o}=Xo({re:e.spectra[0].data.y,im:e.spectra[1].data.y},r*Math.PI/180,n*Math.PI/180);return{re:i,im:o}}function wr(e,t,r){let{logger:n}=r,i=[];for(let o of e)if(o.spectra&&o.spectra.length>0||o.minMax){ts(o);let s={...o.info,...o.meta},a=xe(s,{logger:n});if(a.experiment==="wobble_curve")continue;i.push(Cr(o,s,a,t,r))}return i}function ts(e){let t=e.meta["BRUKER FILE EXP"];if(!t)return;let n=(Array.isArray(t)?t:[t]).find(o=>o.slice(0,10).includes("vdlist"));if(!n)return;let i=n.split(`
|
|
10
|
-
`).slice(1);e.info.vdlistValues=ye(i)}async function Ae(e,t={}){let r=await e.text(),n=vr(r,{name:e.name,...t});return lr(n,e,t)}function vr(e,t={}){let r={spectra:[],molecules:[]},{name:n,converter:i={},selector:o={},logger:s}=t,{keepRecordsRegExp:a=/.*/}=i,c={keepSpectra:!0,noContour:!0,noTrimRegExp:/\$MOLFILE/,keepRecordsRegExp:a,logger:s},l=pr(ns(e),{name:n,...o,logger:s});for(let m of l)is(m,r,c,n);if(os(r,o),r.spectra.length===0&&l.length>0){let m=r.molecules.length===0?" nor molecule":"";s?.warn(`No spectra${m} data was loaded from file ${n}`)}return rs(r)}function is(e,t,r,n){let i=[],o=[],s={molecules:[]},{logger:a}=r,c={name:n,logger:a};Ye(e,o,r),hr(o,s,i,c),t.spectra.push(...wr(i,s,c)),t.molecules.push(...s.molecules)}function os(e,t){t.index!==void 0&&(e.spectra=e.spectra.slice(t.index,t.index+1))}function as(e,t={}){let{sourceSelector:r={},converter:n,keepSource:i,logger:o}=t;return o?.debug(`Reading JCAMP-DX file: ${e.name}`),Ae(e,{selector:cs(r),converter:n?.jcamp,keepSource:i,logger:o})}function cs(e={}){let{jcamp:t={},general:r={}}=e,{dataSelection:n="both"}=r;return{dataSelection:n,...t}}function Qe(){return ss({id:"@zakodium/nmrium-core-plugins#JCAMPDXLoaderPlugin",version:1,migrations:[],onReadProcess:{supportedExtensions:["jcamp","jdx","dx"],onFile:as}})}import{defineNMRiumPlugin as Ns}from"@zakodium/nmrium-core";function Lr(e){if(e===void 0)return{epoch:null,date:""};let t=e*1e3;return{epoch:t,date:new Date(t).toUTCString()}}var kr={0:"bigEndian",1:"littleEndian"},_r={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"},qr={0:"64Bit Float",1:"32Bit Float",2:"Reserved",3:"Reserved"},jr={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"},Br={0:"None",1:"Real",2:"TPPI",3:"Complex",4:"Real_Complex",5:"Envelope"},Ur={"-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"},$r={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},zr={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"},et={0:"Ranged",1:"Listed",2:"Sparse",3:"Listed"};function w(e,t){return e.paramArray.find(r=>r.name===t)}function Jr(e,t){let r=e.paramArray.find(u=>u.name==="orders"),n=e.paramArray.find(u=>u.name==="factors"),i=e.paramArray.find(u=>u.name==="x_sweep"),o=e.paramArray.find(u=>u.name==="x_acq_time"),s=e.paramArray.find(u=>u.name==="x_points");if(!r||!n||!i||!o||!s){t?.error("There is not all parameters to calculate the number of point of digital filter");return}let a=r.value,c=Number.parseInt(a.slice(0,1),10),l=a.slice(1).length/c,m=0,p=new Int8Array(c),f=1,g=0;for(let u=0;u<c;u++)p[u]=Number.parseInt(n.value.slice(g,g+1),10),g+=1;for(let u=0;u<c;u++){let h=1;for(let d=u;d<c;d++)h*=p[d];m+=(Number.parseInt(a.slice(f,f+l),10)-1)/h,f+=l}return m/=2,m/i.value/o.value*(s.value-1)}function E(e,t){let r=w(e,t);if(r===void 0)return{magnitude:"NA",unit:"NA"};let n=r.unit[0],i=n.base,o=$r[n.prefix];return{magnitude:r.value*10**o,unit:i}}function tt(e){let t=e.readBytes(4),r=1990+(t[0]>>1),n=(t[0]<<3&8)+(t[1]>>5),i=t[2]&31;return{year:r,month:n,day:i}}function Ie(e,t){let r=[];for(let n=0;n<t;n++){let i=e.readByte(),o=i>>4,s=Ur[o],a=i&15,c=e.readInt8(),l=zr[c];r.push({prefix:s,power:a,base:l})}return r}function z(e,t){let r=[];for(let n=0;n<t;n++){let i=e.readChar();i!=="\0"&&r.push(i)}return r.join("")}function rt(e,t){let r=[];for(let n=0;n<t;n++){let i=e.readChar();i!==" "&&r.push(i)}return r.join("")}function N(e,t,r){let n=[];for(let i=0;i<t;i++)switch(r){case"readUint32":n.push(e.readUint32());break;case"readFloat64":n.push(e.readFloat64());break;case"readFloat32":n.push(e.readFloat32());break;case"readUint8":n.push(e.readUint8());break;default:break}return n}function Wr(e,t){let r=[];for(let n=0;n<t;n++)r.push(e.readBoolean());return r}function Xr(e,t,r){let n=1,i=0;for(let o of t.dataAxisType)o==="Real_Complex"&&i===0&&(n+=1,i+=1),o==="Complex"&&(n*=2);if(t.dataType!=="32Bit Float"&&t.dataType!=="64Bit Float"){r?.error("Only 32Bit Float and 64Bit Float data types are implemented yet");return}if(t.dataFormat==="One_D"){if(n!==1&&n!==2){r?.error("One_D data must have one or two data sections");return}return ms(e,t,n)}else if(t.dataFormat==="Two_D"){if(n===2)return us(e,t);if(n===4)return ps(e,t);r?.error("Two_D data must have two or four data sections");return}else{r?.error("Only One_D and two_D data formats are implemented yet");return}}function ms(e,t,r){return r===1?{re:nt(e,t)}:{re:nt(e,t),im:nt(e,t)}}function nt(e,t){return t.dataType==="32Bit Float"?N(e,t.dataPoints[0],"readFloat32"):N(e,t.dataPoints[0],"readFloat64")}var L=32;function us(e,t){let r=t.dataPoints[0],i=t.dataPoints[1]/L,o=r/L;return{re:ee(e,t,i,o),im:ee(e,t,i,o)}}function ps(e,t){let r=t.dataPoints[0],i=t.dataPoints[1]/L,o=r/L;return{re:{re:ee(e,t,i,o),im:ee(e,t,i,o)},im:{re:ee(e,t,i,o),im:ee(e,t,i,o)}}}function ee(e,t,r,n){let i=[];for(let o=0;o<r;o++){let s=[];for(let a=0;a<n;a++)for(let c=0;c<L;c++)a===0?t.dataType==="32Bit Float"?s[c]=N(e,L,"readFloat32"):t.dataType==="64Bit Float"&&(s[c]=N(e,L,"readFloat64")):t.dataType==="32Bit Float"?s[c]=s[c].concat(N(e,L,"readFloat32")):t.dataType==="64Bit Float"&&(s[c]=s[c].concat(N(e,L,"readFloat64")));i=i.concat(s)}return i}function Vr(e){let t=e.readChars(8),r=e.readInt8(),n=kr[r],i=e.readUint8(),o=e.readUint16(),s=e.readUint8(),a=e.readByte().toString(2).split("").map(O=>!!Number(O)),c=e.readByte(),l=c>>6,m=qr[l],p=c&63,f=jr[p],g=e.readInt8(),y=_r[g],u=N(e,8,"readUint8"),h=N(e,8,"readUint8").map(O=>Br[O]),d=Ie(e,8),b=z(e,124),F=[];for(let O of N(e,4,"readUint8")){let ae=O>>4,_e=O&15;F.push(et[ae],et[_e])}let S=N(e,8,"readUint32"),I=N(e,8,"readUint32"),x=N(e,8,"readUint32"),A=N(e,8,"readFloat64"),M=N(e,8,"readFloat64"),T=tt(e),j=tt(e),re=z(e,16),Le=z(e,128),oe=z(e,128),se=z(e,128),J=[];for(let O=0;O<8;O++)J.push(z(e,32));let ke=N(e,8,"readFloat64"),k=N(e,8,"readFloat64"),Un=Wr(e,8);e.skip(3);let $n=!!(e.readByte()>>7),zn=e.readUint32(),Jn=e.readUint32(),Wn=e.readUint32(),Xn=e.readUint32(),Vn=N(e,8,"readUint32"),Hn=N(e,8,"readUint32"),Gn=e.readUint32(),Yn=e.readUint32()<<32|e.readUint32(),Kn=e.readUint32()<<32|e.readUint32(),Zn=e.readUint32(),Qn=e.readUint32()<<32|e.readUint32(),ei=e.readUint32(),ti=e.readUint32()<<32|e.readUint32(),ri=N(e,8,"readUint8"),bt=[];for(let O=0;O<2;O++){let ae=[],_e=e.readInt16();for(let Ft=0;Ft<5;Ft++)ae.push(e.readInt16());bt.push({scaler:_e,unit:ae})}return{fileIdentifier:t,endian:n,majorVersion:i,minorVersion:o,dataDimensionNumber:s,dataDimensionExist:a,dataType:m,dataFormat:f,dataInstrument:y,translate:u,dataAxisType:h,dataUnits:d,title:b,dataAxisRanged:F,dataPoints:S,dataOffsetStart:I,dataOffsetStop:x,dataAxisStart:A,dataAxisStop:M,creationTime:T,revisionTime:j,nodeName:re,site:Le,author:oe,comment:se,dataAxisTitles:J,baseFreq:ke,zeroPoint:k,reversed:Un,annotationOK:$n,historyUsed:zn,historyLength:Jn,paramStart:Wn,paramLength:Xn,ListStart:Vn,ListLength:Hn,dataStart:Gn,dataLength:Yn,contextStart:Kn,contextLength:Zn,annoteStart:Qn,annoteLength:ei,totalSize:ti,unitLocation:ri,compoundUnit:bt}}var fs={0:"String",1:"Integer",2:"Float",3:"Complex",4:"Infinity"};function Hr(e){let t=e.readUint32(),r=e.readUint32(),n=e.readUint32(),i=e.readUint32(),o=[];for(let s=0;s<n+1;s++){e.skip(4);let a=e.readInt16(),c=Ie(e,5);e.skip(16);let l=e.readInt32(),m=fs[l];e.seek(e.offset-20);let p;switch(m){case"String":p=rt(e,16);break;case"Integer":p=e.readInt32(),e.skip(12);break;case"Float":p=e.readFloat64(),e.skip(8);break;case"Complex":p={Real:e.readFloat64(),Imag:e.readFloat64()};break;case"Infinity":p=e.readInt32(),e.skip(12);break;default:e.skip(16);break}e.skip(4);let f=rt(e,28);o.push({name:f.toLowerCase(),scaler:a,unit:c,value:p,valueType:m})}return{parameterSize:t,lowIndex:r,highIndex:n,totalSize:i,paramArray:o}}function Gr(e,t){let r=new R(e);r.setBigEndian();let n=Vr(r);n.endian==="littleEndian"&&r.setLittleEndian(),r.seek(n.paramStart);let i=Hr(r);r.seek(n.dataStart);let o=Xr(r,n,t),s=[],a=[],c=[],l=[],m=[],p=[],f=[],g=[],y=[],u=[];if(n.dataFormat==="One_D"||n.dataFormat==="Two_D"){let d=Lr(w(i,"actual_start_time")?.value);d.date&&(a.push(d.date),c.push(d.epoch)),s.push(w(i,"x_domain")?.value),l.push(E(i,"x_acq_time")),m.push(E(i,"x_sweep")),p.push(E(i,"x_sweep_clipped")),f.push(E(i,"x_resolution")),g.push(E(i,"x_freq")),y.push(E(i,"x_offset")),u.push(n.dataUnits[0].base)}return n.dataFormat==="Two_D"&&(s.push(w(i,"y_domain")?.value),l.push(E(i,"y_acq_time")),m.push(E(i,"y_sweep")),f.push(E(i,"y_resolution")),g.push(E(i,"y_freq")),y.push(E(i,"y_offset")),u.push(n.dataUnits[1].base)),{info:{sampleName:w(i,"sample_id")?.value,creationTime:n.creationTime,revisionTime:n.revisionTime,author:n.author,comment:n.comment,solvent:w(i,"solvent")?.value,temperature:E(i,"temp_get"),probeName:w(i,"probe_id")?.value,fieldStrength:E(i,"field_strength"),experiment:w(i,"experiment")?.value,dimension:n.dataDimensionNumber,nucleus:s,date:a,epoch:c,pulseStrength90:E(i,"x90"),numberOfScans:w(i,"scans")?.value,relaxationTime:E(i,"relaxation_delay"),dataPoints:n.dataPoints.slice(0,n.dataDimensionNumber),dataOffsetStart:n.dataOffsetStart,dataOffsetStop:n.dataOffsetStop,dataUnits:u,dataSections:o?Object.keys(o):void 0,originFrequency:g,frequencyOffset:y,acquisitionTime:l,spectralWidth:m,spectralWidthClipped:p,dataAxisStart:n.dataAxisStart,dataAxisStop:n.dataAxisStop,resolution:f,decimationRate:w(i,"decimation_rate")?.value,paramList:JSON.stringify(i.paramArray.map(d=>d.name)),digitalFilter:Jr(i,t)},headers:n,parameters:i,data:o}}import{formatSpectra as hs}from"@zakodium/nmrium-core";import{getGyromagneticRatio as bs}from"gyromagnetic-ratio";import{isAnyArray as Fs}from"is-any-array";import xs from"lodash.merge";import{normalizeNucleus as Ds}from"nmr-processing";import{isAnyArray as te}from"is-any-array";var Yr={0:"uint8",1:"uint16",2:"uint32",3:"uint64",4:"int8",5:"int16",6:"int32",7:"int64",8:"float32",9:"float64",10:"complex64",11:"complex128"},Kr={0:"scalar",1:"vector",2:"matrix",3:"symetricMatrix",4:"pixel"};function Zr(e,t,r={}){let{quantityType:n=0,encoding:i="none",name:o="",unit:s="",quantityName:a="",sparseSampling:c={},from:l=[0],to:m=[-1]}=r;if(te(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 p=ot(e,l,m),{componentLabels:f=p.componentLabels}=r;return{type:"internal",quantityType:Kr[n],numericType:Yr[t],encoding:i,name:o,unit:s,quantityName:a,componentLabels:f,sparseSampling:c,description:r.description||"",application:r.application||"",components:p.components,dataLength:p.dataLength}}function ds(e){return te(e.re)&&te(e.im)}function gs(e){return!te(e.re[0])}function ot(e,t,r){let n=[],i=[],o=[];if(ds(e))if(gs(e)){n[0]=it(t[0],r[0],e.re.length);let s=new Float64Array(n[0]);for(let a=0;a<n[0];a+=2){let c=a+t[0]*2;s[a]=e.re[c/2],s[a+1]=e.im[c/2]}o.push(s),i.push("complex")}else if(te(e.re[0])){n[0]=ys(t[1],r[1],e.re.length),n[1]=it(t[0],r[0],e.re[0].length);for(let s=0;s<n[0];s++){let a=new Float64Array(n[1]);for(let c=0;c<n[1];c+=2){let l=c+t[0]*2;a[c]=e.re[s][l/2],a[c+1]=e.im[s][l/2]}o.push(a)}}else throw new Error("check your object");else if(te(e.re.re)){n[0]=it(t[1],r[1],e.re.re.length);let s=ot(e.re,t,r).components,a=ot(e.im,t,r).components;for(let c=0;c<n[0]/2;c++)o.push(s[c],a[c])}else throw new Error("check the dimension or the type of data in your array");return{dataLength:n,componentLabels:i,components:o}}function ys(e,t,r){return t-e+1<r?t-e+1:r}function it(e,t,r){return t-e+1<r?(t-e+1)*2:r*2}async function en(e,t={}){let r=await e.arrayBuffer(),{name:n=Z(e.name),keepSource:i=!1}=t,o={spectra:[],molecules:[]},a=Is(r)[0],{metadata:c,...l}=a.description,m=0,p=l.dimension===1?"1d":"2d",f="NMR SPECTRUM",g=l.dimension===1?l.nucleus[0]:l.nucleus,y=l.spectralWidthClipped[0],u;a.dependentVariables&&(l.dimension===1?u=Ss(a):l.dimension===2&&(u=As(a)));for(let d in l)Array.isArray(l[d])&&l[d].length===1&&(l[d]=l[d][0]);let h={data:u,info:{...l,acquisitionMode:m,experiment:p,type:f,nucleus:g,spectralWidthClipped:y,name:n},meta:c};return i&&(h.sourceSelector={files:[e.relativePath]}),o.spectra=[h],hs(o)}function Ss(e){let t=e.dimensions[0],r=e.dependentVariables,n=t.quantityName,i=t.count,o=t.increment.magnitude,s=t.originOffset.magnitude,a=t.coordinatesOffset.magnitude,c=r[0].components[0],l=new Float64Array(i),m=new Float64Array(i);for(let u=c.length-1,h=0;u>0;u-=2)l[h]=c[u-1],m[h++]=c[u];let p={},[f,g]=[0,0];switch(n){case"frequency":g=0+a/s*1e6,f=o/s*1e6,p.re=l,p.im=m;break;case"time":g=s,f=o,p.re=l.reverse(),p.im=m.reverse().map(u=>-u);break;default:break}let y=[];for(let u=0;u<i;u++)y.push(g+u*f);return p.x=y,p}function As(e){let t=e.dimensions,r=e.dependentVariables,n=t[0].quantityName,i=[],o=[],s=Number.MIN_SAFE_INTEGER,a=Number.MAX_SAFE_INTEGER,c=Number.MAX_SAFE_INTEGER,l=Number.MIN_SAFE_INTEGER;for(let f of r[0].components){let g=new Float64Array(f.length/2),y=new Float64Array(f.length/2);for(let u=f.length-1,h=0;u>0;u-=2){let d=f[u-1],b=f[u];d>s&&(s=d),d<a&&(a=d),b>l&&(l=b),b<c&&(c=b),g[h]=d,y[h++]=b}if(n==="frequency")i.push(g),o.push(y);else{let u=g.length,h=new Float64Array(y.length);for(let d=0,b=u-1;d<u;d++)h[d]=-y[b--];i.push(g.reverse()),o.push(h)}}let m={re:{z:i,minZ:a,maxZ:s},im:{z:o,minZ:c,maxZ:l}},p=["X","Y"];for(let f=0;f<p.length;f++){let g=t[f].count,y=t[f].increment.magnitude,u=t[f].originOffset.magnitude,h=t[f].coordinatesOffset.magnitude,d=p[f];for(let b of["re","im"])n==="frequency"?(m[b][`min${d}`]=0+h/u*1e6,m[b][`max${d}`]=g*(y/u)*1e6):(m[b][`min${d}`]=u,m[b][`max${d}`]=g*y)}return m}function Is(e){let t=Gr(e),r=t.info,n=t.headers,{paramArray:i,...o}=t.parameters,{dimension:s}=r,a={};for(let d of i){let{name:b,value:F}=d;a[b]=tn(F,s)}let c=t.data,l={};l.title=`title: ${n.title} / comment: ${n.comment} / author:${n.author} / site: ${n.site}`,l.nucleus=r.nucleus.map(Ds),l.sampleName=r.sampleName,l.date=r.date,l.epoch=r.epoch,l.localeDate=new Date(r.epoch[0]).toLocaleString(),l.author=r.author,l.solvent=r.solvent,l.temperature=r.temperature.magnitude,l.probeName=r.probeName||"",l.fieldStrength=r.fieldStrength.magnitude;let m=l.nucleus.map(bs);l.baseFrequency=m.map(d=>r.fieldStrength.magnitude*d/(2*Math.PI*1e6)),l.pulseSequence=r.experiment,l.temperature=r.temperature?.unit?.toLowerCase()==="celsius"?273.15+r.temperature.magnitude:r.temperature.magnitude,l.digitalFilter=r.digitalFilter,l.pulseStrength90=1/(4*r.pulseStrength90.magnitude),l.numberOfScans=r.numberOfScans,l.relaxationTime=r.relaxationTime.magnitude,l.isComplex=r.dataSections?r.dataSections.includes("im"):!1,l.isFid=r.dataUnits[0]==="Second",l.isFt=r.dataUnits[0]==="Ppm",l.dimension=r.dimension,l.originFrequency=r.originFrequency.map(d=>d.magnitude/1e6).slice(0,s),l.numberOfPoints=r.dataPoints.slice(0,1),l.frequencyOffset=r.frequencyOffset.map((d,b)=>d.magnitude*l.baseFrequency[b]).slice(0,s),l.acquisitionTime=r.acquisitionTime.map(d=>d.magnitude).slice(0,s),l.spectralWidth=r.spectralWidth.map((d,b)=>d.magnitude/r.originFrequency[b].magnitude*1e6).slice(0,s),l.spectralWidthClipped=r.spectralWidthClipped.map((d,b)=>d.magnitude/l.baseFrequency[b]*1e6).slice(0,s);let p=[],f={},g;for(let d=0;d<r.dimension;d++){if(g={magnitude:r.acquisitionTime[d].magnitude/(r.dataPoints[d]-1),unit:"s"},r.dataUnits[d]==="Second")f.quantityName="time",f.originOffset={magnitude:0,unit:"s"},d===0?f.coordinatesOffset={magnitude:r.digitalFilter*g.magnitude,unit:"s"}:f.coordinatesOffset={magnitude:0,unit:"s"},f.reciprocal={originOffset:{magnitude:r.originFrequency[d].magnitude,unit:"Hz"},quantityName:"frequency",coordinatesOffset:{magnitude:r.frequencyOffset[d].magnitude*r.originFrequency[d].magnitude/1e6,unit:"Hz"}};else if(r.dataUnits[d]==="Ppm"){f.quantityName="frequency";let b=r.originFrequency[d].magnitude;f.originOffset={magnitude:b,unit:"Hz"};let F=r.dataOffsetStart[d],I=r.dataOffsetStop[d]-F+1;g={magnitude:Ms(r,d)/(I-1),unit:"Hz"};let M=r.dataAxisStop[d]*b/1e6;f.coordinatesOffset={magnitude:M,unit:"Hz"},I!==r.dataPoints[d]&&(r.dataPoints[d]=I)}d===0?f.description="direct dimension":f.description="indirect dimension",p.push({label:n.dataAxisTitles[d],count:r.dataPoints[d],increment:g,type:"linear",description:String(f.description)||"",application:f.application||{},coordinatesOffset:f.coordinatesOffset||0,originOffset:f.originOffset||0,quantityName:String(f.quantityName)||"",reciprocal:f.reciprocal||{},period:f.period||0,complexFFT:f.complexFFT||!1})}let y=[];y.push(Zr(c,11,{unit:"none",quantityName:"relative intensity",from:r.dataOffsetStart,to:r.dataOffsetStop}));let u={...l};return delete u.paramList,u.metadata={...Qr(n,s),...Qr(o,s),...xs({},a)},[{timeStamp:Date.now(),description:u,dimensions:p,dependentVariables:y}]}function Ms(e,t){let{spectralWidth:r,spectralWidthClipped:n}=e;return n[t].magnitude!=="NA"?n[t].magnitude:r[t].magnitude}function Qr(e,t){let r={};for(let n in e)r[n]=tn(e[n],t);return r}function tn(e,t){return Fs(e)?t>1?e.slice(0,t):e[0]:e}function Ps(e,t={}){let{logger:r,keepSource:n}=t;return r?.debug(`Reading JEOL file: ${e.name}`),en(e,{name:e.name,keepSource:n,logger:r})}function st(){return Ns({id:"@zakodium/nmrium-core-plugins#JEOLLoaderPlugin",version:1,migrations:[],onReadProcess:{supportedExtensions:["jdf"],onFile:Ps}})}import{defineNMRiumPlugin as Es}from"@zakodium/nmrium-core";function Ts(e,t={}){let{logger:r}=t;return r?.debug(`Reading molfile file: ${e.name}`),dr(e,{logger:r})}function at(){return Es({id:"@zakodium/nmrium-core-plugins#MolfileLoaderPlugin",version:1,migrations:[],onReadProcess:{supportedExtensions:["mol"],onFile:Ts}})}import{defineNMRiumPlugin as ta}from"@zakodium/nmrium-core";import{FileCollection as Df}from"file-collection";import{Molecule as hn}from"openchemlib";import{getShortestPaths as Os}from"openchemlib-utils";function rn(e,t){let{molecule:r,map:n}=t;r.addImplicitHydrogens();let i=Os(r,{toLabel:"H",maxLength:1});for(let s in e){let a=e[s],c=a.atoms;if(c.length!==0){if(a.position=[],c[0].toLowerCase().includes("h")){let l=Number(c[0].toLowerCase().replace("h",""))-1;l=n.indexOf(l);let m=i[l].find(p=>p&&p.length>1);a.position=i[m[0]].filter(p=>p&&p.length>1).map(p=>p.at(-1))}else if(c[0].toLowerCase().match(/\w/s))for(let l of c){let m=n.indexOf(Number(l)-1);a.position.push(m)}}}let o=r.getDiastereotopicAtomIDs();for(let s in e){let a=[];if("position"in e[s])for(let c of e[s].position)a.includes(o[c])||a.push(o[c]);e[s].diaIDs=a}return e}async function nn(e,t){let{fileCollection:r,root:n}=t,i=e.data.filter(s=>s.value.spectrum_location),o=[];for(let s of i){if(!s){new Error(`There is not spectrum for ${e}`);return}let a=s.value.spectrum_location;if(a.match(/file:/s)){let c=n+a.replace(/file:[./]*/s,""),l=c.match(/[ser|fid]/s)?/([.*/]*\w+\/[0-9]+\/).*/:/(.*\w+\/[0-9]+\/)pdata\/.*/,m=c.replace(l,"$1"),p=c.replace(/.*\/[0-9]+\/pdata\/([0-9]+)\/.*/,"$1"),f=r.filter(g=>{if(g.relativePath.match("pdata")&&p!==g.relativePath.replace(/.*\/[0-9]+\/pdata\/([0-9]+)\/.*/,"$1"))return!1;let y=g.relativePath.replace(/([.*/]*\w+\/[0-9]+\/).*/,"$1");return!(m!==y&&!["ser","fid"].some(u=>c===`${y}${u}`))});o.push({type:"brukerFiles",fileCollection:f})}else a.match("http")&&o.push({type:"url",value:a})}return o}async function on(e,t){let{fileCollection:r,root:n}=t,i=e.data.find(c=>c.value.jcamp_location);if(!i){new Error(`There is not spectrum for ${e}`);return}let o=i.value.jcamp_location,s=n+o.replace(/file:/s,""),a=r.filter(c=>c.relativePath===s);if(a.files.length===0){new Error(`There is not jcamp with path: ${s}`);return}return[{name:s,type:"jcamp",fileCollection:a}]}function sn(e={}){let t={};for(let r of e.data||[]){let{label:n,atoms:i,shift:o}=r.value;t[n]={shift:o,atoms:i}}return t}function an(e){let t=e.match(/([0-9])\w_/s)?.[1];if(t==="1")return e.slice(3).replaceAll(/(?<nucleus>[0-9]+\w+)#\w+/g,"$<nucleus>");if(t==="2"){let r=[],n=e.slice(12).split("_");for(let i=0;i<n.length;i+=2)r.push(n[i].replaceAll(/(?<nucleus>[0-9]+\w+)#\w+/g,"$<nucleus>"))}return[]}var Cs=["delta","nbAtoms","multiplicity","jCoupling"];function cn(e,t){let r={};for(let s of Cs){let a=e[s];a&&(r[s]=a)}let{nbAtoms:n,integration:i}=e;if(r.integration=i?Number(i):n?Number(n):null,e.assignment)for(let s of e.assignment){let a=t[s];r.diaIDs||(r.diaIDs=[]),a?.diaIDs&&r.diaIDs.push(...a.diaIDs)}let o=!1;if(r.jCoupling&&(o=r.jCoupling.some(s=>Object.keys(s).includes("label"))),o){for(let s of r.jCoupling)if(s.label){let a=t[s.label];a?.diaIDs&&(s.diaIDs=a.diaIDs)}}return r.delta&&(r.delta=Number.parseFloat(r.delta)),r}var Rs=["intensity","volume","activeCoupling"],ws={x:["f1Width","f1Coupling"],y:["f2Width","f2Coupling"]};function ln(e,t){let r={};for(let n of Rs)e[n]&&(r[n]=e[n]);for(let n in e.delta){r[n]||(r[n]={});let i=e.delta[n];for(let o of i)r[n].diaIDs||(r[n].diaIDs=[]),t[o]?(r[n].diaIDs.push(...t[o].diaIDs),r[n].delta=Number.parseFloat(t[o].shift)):r[n].delta=Number.parseFloat(o);for(let o of ws[n])if(e[o]){let s=o.toLowerCase().replace(/f\w(\w+)/,"$1");r[n][s]=e[o]}}return r}async function mn(e,t){let{moleculeAndMap:r}=t,n={molecules:[{molfile:r.molecule.toMolfile()}],spectra:[]},i=n.spectra,o=n.molecules;e.SMILES?.data.length>0&&(o[0].smiles=e.SMILES.data[0].value);let s=sn(e.ASSIGNMENT);s=rn(s,r);for(let a in e){let c=a.toLowerCase();if(!c.match(/[1|2]d_/s))continue;let l=e[a].data.find(d=>d.value.larmor),m=e[a].data.find(d=>d.value.pulseprogram),p=an(a),f=c.replace(/([1|2]d)_.*/,"$1"),g=f==="2d"?ln:cn,y={source:{jcampURL:null},nucleus:p,frequency:l?.value.larmor,experiment:m?m.value.pulseprogram.trim():f,headComment:e[a].headComment},u=e[a].data.filter(d=>d.value.delta);y.signals=u.map(d=>{let b=g(d.value,s);return b.comment=d.comment,b});let h=await vs(e[a],t);if(!h.jcamp&&!h.bruker)i.push(y);else for(let d in h)h[d]&&i.push({...y,source:{...y.source,file:h[d]}})}return n}async function vs(e,t){return{jcamp:await on(e,t),bruker:await nn(e,t)}}function Me(e,t={}){let{include:r,exclude:n,filter:i,modifiers:o={},forEach:s={},dynamicTyping:a=!0,mixedEOL:c=!1}=t;if(typeof e!="string")throw new TypeError('Parameter "sdf" must be a string');let l=`
|
|
8
|
+
`,a=[Gt,sr,Jt,Kt],{creator:c=""}=i;c.includes("nanalysis")?a.push(Qt):c.toLocaleLowerCase().includes("oxford instruments")&&a.push(ar),c!=="mnova"&&c!=="mestre"&&a.push(nr),a.push(ir,Zt);for(let l of a)l(i,e,{prefix:r,logger:n,separator:s});return fo(i)}function fo(e){return e.dimension===1&&(e.nucleus=[e.nucleus]),Object.fromEntries(Object.entries(e).map(([t,r])=>[t,po(r)&&r.length===1?r[0]:r]))}var yo={keepRecordsRegExp:/.*/,keepFiles:!0};async function De(e,t={}){let r={spectra:[],molecules:[]},{converter:n={},selector:i={},logger:o}=t,s=ze(e,{logger:o,...bo(i)}),a=[];for(let l of s)a.push(He(l,{...yo,...n}).then(m=>ho(m,t)));let c=await Promise.allSettled(a);for(let l=0;l<c.length;l++){let m=c[l];if(m.status==="fulfilled"){let p=be(m.value.info);r.spectra.push({...m.value,info:{...m.value.info,...p}})}else if(m.reason){let p=s[l].name;o?.warn(`Bruker data: ${p}, fails with: ${m.reason}`);continue}}return o&&o[r.spectra.length>0?"info":"debug"](`Loaded ${r.spectra.length} spectra from Bruker files`),go(r)}function ho(e,t={}){let{keepSource:r=!1,logger:n}=t,i={...e.info,...e.meta},o=xe(i,{logger:n}),s={},{isFid:a}=o;if(Fo(e)){let g=e.minMax;for(let y in g){let u=g[y];u&&(u.z=U(u.z))}s.components=e.minMax}else o.dimension===1&&(s.components=e.spectra);let{source:c}=e,{expno:l,name:m,files:p}=c;i.vdlist&&(i.vdlistValues=ye(i.vdlist));let f={dependentVariables:[s],meta:i,info:{...o,experimentNumber:l,name:m}};return p&&r&&(f.sourceSelector={files:p.map(g=>g.relativePath)}),xo(f,e),f}function bo(e){let{general:t={},bruker:r={}}=e,{processingNumbers:n,experimentNumbers:i,...o}=r;return{...t,...o,processingNumbers:cr(n),experimentNumbers:cr(i)}}function cr(e){if(e)return e.split(/[^\d]+/).filter(Boolean).map(t=>Number.parseInt(t,10))}function Fo(e){let{info:t}=e;return t.twoD}function xo(e,t){if(!("integrals"in t))return;let{integrals:r=[]}=t;e.integrals={values:r.map(n=>{let{from:i,to:o,integration:s}=n;return{from:i,to:o,integral:s,kind:"signal"}})}}function So(e,t){let{sourceSelector:r,converter:n,keepSource:i,logger:o}=t??{};return De(e,{converter:n?.bruker,selector:r,keepSource:i,logger:o})}function Ge(){return Do({id:"@zakodium/nmrium-core-plugins#BrukerLoaderPlugin",version:1,shouldSerialize:!0,migrations:[],onReadProcess:{onFiles:So}})}import{defineNMRiumPlugin as os}from"@zakodium/nmrium-core";import{formatSpectra as ts}from"@zakodium/nmrium-core";import{createTree as rs}from"jcampconverter";function lr(e,t,r={}){let{selector:n={},keepSource:i=!1}=r;if(!i)return e;for(let o=0;o<e.spectra.length;o++){let s=e.spectra[o];s.sourceSelector={files:[t.relativePath],jcamp:{index:o,...n}}}return e}import{convert as Ao}from"jcampconverter";function Ye(e,t,r){let{dataType:n,children:i}=e,o=n==="LINK"&&i?i:[e];for(let s of o){if(s.dataType==="LINK"){Ye(s,t,r);continue}let a=Ao(s.jcamp,r);t.push(...a.flatten)}}function pr(e,t={}){let r=[],n=fr(e,t);for(let s of n?e:[])s.dataType==="LINK"?s.children=Ke(s.children,t):s=Ke([s],t)[0],r.push(s);let{name:i,logger:o}=t;return e.length===0&&o?.warn(`There is no data ${i?`in ${i}`:"in the JCAMP-DX"}`),r}function Ke(e=[],t={}){let{name:r,logger:n,tree:i=[],dataSelection:o="both"}=t,s=[];for(let m of e){let{dataType:p,dataClass:f}=m;if(p==="LINK")m.children=Ke(m.children,t);else if(i.some(g=>{let{dataClass:y=f,dataType:u=p}=g;return f===y&&p===u})){n?.warn(`Skipping ${f} and ${p} ${r?`in ${r}`:"in the JCAMP-DX"},
|
|
9
|
+
because it didn't match the import filters`);continue}s.push(m)}let a=[],c=s.some(ur),l=s.some(mr);for(let m of s){if(o!=="both"&&m.dataType!=="LINK"){if(ur(m)&&(o==="ft"||o==="preferFT"&&l)){n?.warn(`Skipping raw data ${r?`in ${r}`:"in the JCAMP-DX"} because it didn't match the import filters`);continue}if(mr(m)&&(o==="fid"||o==="preferFID"&&c)){n?.warn(`Skipping FFT data ${r?`in ${r}`:"in the JCAMP-DX"} because it didn't match the import filters`);continue}}a.push(m)}return a}function mr(e){return e.dataType?.toUpperCase().includes("SPECTRUM")&&e.dataClass&&!e.dataClass.toUpperCase().includes("PEAK")}function ur(e){return e.dataType?.toUpperCase().includes("FID")}function fr(e,t={}){let{logger:r,name:n=""}=t;for(let i of e){if(i.dataType==="LINK"&&fr(i.children,t))return!0;let{dataType:o=""}=i,s=o.toLowerCase();if(s.length>0){if(s.includes("spectrum")&&!s.includes("nmr"))return r?.warn(`File ${n} was ignored because it is a ${o}`),!1;if(s.includes("nmr"))return!0}}return!1}import{generateID as hr}from"@zakodium/nmrium-core";import{parseJcampCS as To}from"jcampconverter";import*as Oo from"openchemlib";import{isMolfileNotEmpty as Io}from"nmr-processing";import*as dr from"openchemlib";async function gr(e,t={}){let r=await e.text(),n=K(r),i={molecules:n,spectra:[]};return n.length===0&&t.logger?.debug(`${e.name} is an empty molfile`),i}function K(e){let t=[];if(!Io(e))return[];let n=dr.Molecule.fromMolfile(e,{customLabelPosition:"superscript"}).toMolfileV3();return t.push({molfile:n}),t}import{isMolfileNotEmpty as No}from"nmr-processing";import*as Po from"openchemlib";import{getDiastereotopicAtomIDsFromMolfile as Eo}from"openchemlib-utils";var Mo=new Set(["ndnmrspectrum","ndnmrfid","nmrspectrum","nmrfid"]);function Se(e){let{dataType:t="",dataClass:r=""}=e,n=t.replaceAll(/\s/g,"").toLowerCase(),i=r.replaceAll(/\s/g,"").toLowerCase();return Mo.has(n)&&i!=="peaktable"}function yr(e,t,r={}){let{spectra:n,info:i,meta:o}=e,s=n[0].data,a=[],c={x:"delta",y:"intensity",w:"width",m:"multiplicity",a:"atom"},{logger:l,name:m,spectraData:p}=r,{CROSSREFERENCE:f}=i,g=typeof f!="string"?f:f.split(/\r?\n/).map(x=>x.trim()).filter(Boolean),y=g.find(x=>x?.toLowerCase().includes("structure"));if(y===void 0)return l&&l.warn(`There is not a structure reference for ${m} file, assignment object could not be completed`),null;let u=Number.parseInt(y?.toLowerCase().replace(/_/,"").replace(/structure:\s*blockid\s*=\s*(?<blockId>.*)/,"$<blockId>"),10);if(Number.isNaN(u)||u<1)return l&&l.warn(`Structure block_id not found for ${m} file, assignment object could not be completed`),null;let d=p?.molecules?.find(x=>x.blockId===u)?.molfile??"";if(d===""){let x=t.find(M=>M.info.BLOCKID===u),{MOLFILE:A=""}=x?.meta||{};d=A}if(!No(d))return l&&l.warn(`Empty molfile for ${m} file with structure block_id = ${u}, assignment object could not be completed`),null;let b=Eo(Po,d),F=Fe({...i,...o},{},"");for(let x=0;x<s.x.length;x++){let A={};for(let M in s){let T=s[M][x];typeof T=="string"&&T.startsWith("<")&&T.endsWith(">")&&(T=T.slice(1,-1)),A[c[M]]=T}if("atom"in A){let M=b.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)}a.push(A)}let S={};for(let x of a){let{delta:A,diaIDs:M}=x,T=`${A}_${M.join("_")}`;if(S[T])S[T].atoms.push(x.atom);else{let{atom:j,...re}=x;S[T]={...re,atoms:[x.atom]}}}let I=[];for(let x of g)x.toLowerCase().includes("spectrum")&&I.push(Number(x.toLowerCase().replace(/_/,"").replace(/.*:\s*blockid=(?<blockId>.*)/,"$<blockId>")));if(I.length===0){for(let x of t)if(Se(x)){let{BLOCKID:A}=x.info;I.push(Number(A))}I.length>1&&(I=[],l&&l.warn(`There is not a spectral cross-reference for the peak assignment in the ${m} file`))}return{moleculeBlockID:u,spectraBlockIDs:I,assignments:Object.values(S),molecule:b.molecule}}function br(e,t,r,n){for(let i of e){let{meta:o,dataClass:s="",dataType:a="",info:c}=i,l=Number.parseInt(String(c.BLOCKID),10);o.MOLFILE?vo(String(o.MOLFILE),t,l):i.jcampCS&&wo(i,t,l),Co(s,a)&&Ro(t,i,e,n),Se(i)&&r.push(i)}}function Co(e,t){return e?.toLowerCase().includes("assignments")&&t?.toLowerCase().includes("assignments")}function Ro(e,t,r,n){let i=yr(t,r,{spectraData:e,logger:n.logger,name:n.name});if(e.assignmentsByBlocks||(e.assignmentsByBlocks={}),i){let{spectraBlockIDs:o}=i;for(let s of o)e.assignmentsByBlocks[s]=i}}function wo(e,t,r){t.molecules||(t.molecules=[]);let n=To(e,{OCL:Oo}),i=K(n?.molfile||"");i.length>0&&t.molecules.push({id:hr(),blockId:r,...i[0]})}function vo(e,t,r){t.molecules||(t.molecules=[]);let n=K(e);t.molecules.push({id:hr(),blockId:r,...n[0]})}import{generateID as Cr}from"@zakodium/nmrium-core";import{matrixMinMaxZ as Or,reimPhaseCorrection as Wo}from"ml-spectra-processing";import{xyAutoRangesPicking as Xo}from"nmr-processing";function Z(e){return e.slice(0,Math.max(0,e.lastIndexOf(".")))}function Q(e){e.sort((t,r)=>t.from-r.from);for(let t=0;t<e.length-1;t++)e[t].to>e[t+1].from&&(e[t].to=Math.max(e[t+1].to,e[t].to),e[t].signals=e[t].signals.concat(e[t+1].signals),e[t].integration+=e[t+1].integration,e.splice(t+1,1),t--);return e}import{splitPatterns as jo}from"nmr-processing";import{xMaxValue as Lo}from"ml-spectra-processing";function ie(e){return e.trim().slice(1,-1).split(/,\s*/).map(t=>t.trim())}var ko={I:"id",X:"from",Y:"to",Hs:"delta",An:"integration",H:"nbAtoms",C:"multiplicity",N:"assignment","(J)":"js"},Fr=["I","X","Y","Hs","An","H","C","N","(J)"];function xr(e){let t={headersFromParenthesis:[],headersFromComments:[],comments:[],data:[],multiplets:[]},r=e.split(/\r?\n/).filter(n=>n.trim()!=="");if(r.length===0)return t;if(r[0].startsWith("(")&&!r[0].match(/\d/)){let n=r.shift();t.headersFromParenthesis=ie(n)}return t.comments=r.filter(n=>n.startsWith("$$")).map(n=>n.replace(/^\$\$\s*/,"")),t.headersFromComments=qo(t.comments),t.data=r.filter(n=>!n.startsWith("$$")).map(ie),t.multiplets=_o(t),t}function _o(e,t={}){let{logger:r}=t,n=e.data[0].map((c,l)=>l).filter(c=>e.data.every(l=>Number.isNaN(l[c])||Number.isNaN(Number(l[c]))));if(r?.trace(`Parsing JCAMP-DX assignment: stringColumnIndexes: ${n.join(",")}`),n.length===0)return r?.warn("Parsing JCAMP-DX assignment: No string columns found. Skipping parsing of assignment."),[];let i=n[0],o;if(e.headersFromParenthesis.length>0&&e.headersFromParenthesis[i]==="C")o=e.headersFromParenthesis;else if(e.headersFromComments.length>0&&e.headersFromComments[i]==="C")o=e.headersFromComments;else if(Fr[i]==="C")o=Fr;else return r?.warn("No header found for multiplicity. Skipping parsing of assignment."),[];return Lo(e.data.map(c=>c.length))>o.length&&r?.warn("Some assignments are containing more values than headers"),e.data.map(c=>{let l={};for(let m=0;m<o.length;m++){let p=o[m];l[ko[p]||p]=c[m]}return l})}function qo(e){return e.map(t=>t.split(":")[0].trim()).filter(t=>t.length>0)}function Dr(e,t={}){let{logger:r}=t,n=xr(e),i={multiplets:[],comments:n.comments};for(let o of n.multiplets){let{id:s,from:a,to:c,delta:l,integration:m,nbAtoms:p,multiplicity:f}=o,g={id:s,js:[],multiplicity:"",...Bo({from:a,to:c,delta:l,integration:m,nbAtoms:p})};if(typeof o.js=="string"){let y=o.js.split(/\s+/).map(Number.parseFloat),u=0,h=jo(f).map(F=>{let S=(F?.multiplicity||1)-1;return u+=S,{value:F.value,multiplicity:F?.multiplicity,js:y.slice(u-S,u)}}),d=h.reduce((F,S)=>F+(S.multiplicity?S.multiplicity-1:0),0);y.length!==d&&r?.warn(`The number of j values (${y.length}) is not equal to the sum of the multiplicities - 1 (${d})`);let b=[];for(let F of h){if(F.js.every(S=>S===F.js[0])){b.push(F);continue}if(F.multiplicity!==F.js.length+1){b.push(F);continue}for(let S=0;S<F.multiplicity-1;S++)b.push({value:"d",multiplicity:2,js:[F.js[S]]})}b.sort((F,S)=>S.js[0]-F.js[0]),g.js=b.map(F=>({coupling:F.js[0],multiplicity:F.value}))}typeof o.assignment=="string"&&(g.assignment=$o(o.assignment)),typeof o.multiplicity=="string"&&(g.multiplicity=o.multiplicity),i.multiplets.push(g)}return i}function Bo(e){let t={};for(let r in e){let n=e[r],i=typeof n=="number"?n:Number.parseFloat(n);Number.isNaN(i)||(t[r]=i)}return t}var Uo={quot:'"',apos:"'",comma:",",amp:"&",lpar:"(",rpar:")",lt:"<",gt:">",colon:":",semi:";"};function $o(e){return e.replaceAll(/&(\w+);/gi,(t,r)=>Uo[r.toLowerCase()]||t)}function Sr(e){let t=e.split(/\r?\n/).filter(n=>n.trim()!==""),r=[];for(let n of t)if(n.startsWith("(")){let[i,o,s]=ie(n).map(Number.parseFloat);r.push({id:i,x:o,y:s})}return r}function Ar(e,t={}){let r={};if(!e["OBSERVED MULTIPLETS"])return[];let n=Dr(e["OBSERVED MULTIPLETS"],t);if(!n)return[];let{multiplets:i}=n;for(let o of i){let{id:s,from:a,to:c,integration:l=0,...m}=o;r[s]={from:a,to:c,integration:l,signals:[{id:s,...m}]}}if(e["OBSERVED MULTIPLETS PEAKS"]){let o=Sr(e["OBSERVED MULTIPLETS PEAKS"]),s={};for(let a of o){let{id:c,x:l,y:m}=a;s[c]||(s[c]=[]),s[c].push({x:l,y:m,width:.05})}for(let a in r)s[a]&&(r[a].signals[0].peaks=s[a])}return Q(Object.values(r))}function Ir(e,t){let n=[...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})),i=[...t.nucleus[0].matchAll(/[0-9]*(?<element>[A-Z][a-z]?)/g,"$element")][0].groups.element;return n.find(o=>o.element===i)?.count||100}function Mr(e){let t={};return".PHASE0"in e&&(t.ph0=Number.parseFloat(e[".PHASE0"]),t.ph1=Number.parseFloat(e[".PHASE1"])),t}function Ze(e){let{ph0:t,ph1:r}=e;return Number.isFinite(t)&&Number.isFinite(r)}import{generateID as Nr}from"@zakodium/nmrium-core";function Pr(e,t,r){for(let n=0;n<e.length;n++){if(t.includes(n))continue;let{delta:i,multiplicity:o="",diaIDs:s}=e[n],a=i-.01,c=i+.01;r.push({from:a,to:c,integration:1,id:Nr(),signals:[{id:Nr(),delta:i,multiplicity:o,diaIDs:s}]})}}import{linearSumAssignment as zo}from"linear-sum-assignment";import{xCostMatrix as Jo}from"ml-spectra-processing";function Er(e,t){let r=e.map(s=>s.delta),n=t.map(s=>s.delta),i=Jo(n,r,{fct:(s,a)=>Math.abs(s-a)}),{rowAssignments:o}=zo(i,{maximaze:!1});return Array.from(o)}function Tr(e,t){let{assignments:r,ranges:n}=t;r?.sort((s,a)=>a.delta-s.delta);let i=[],o=[];for(let s of n){let a=0,{from:c,to:l}=s,m=[];for(let p=a;p<r.length;p++){let{delta:f}=r[p];f<=l&&f>=c?(m.push(r[p]),o.push(p)):f>l&&(a=p)}if(m.length>0){let p=s.signals,f=[],g=m.length>1&&p.length>1?Er(p,m):[0];for(let y=0;y<m.length;y++){let u=g[y],{delta:h,multiplicity:d,diaIDs:b}=m[y];u>-1?f.push({...p[u],diaIDs:b}):f.push({delta:h,multiplicity:d,diaIDs:b})}s.signals=f,i.push(s)}}Pr(r,o,i),i.sort((s,a)=>s.from-a.from),e.ranges={values:Q(i).map(s=>{let{integration:a,...c}=s;return c}),options:{sum:t.integrationSum,isSumConstant:!0,sumAuto:!0}},e.ranges.options.moleculeId=String(t.moleculeId)}function Rr(e,t,r,n,i){let{logger:o}=i,s={components:wr(e)?Go(e,r.isFid):Ho(e)},{name:a=r.title||`jcamp_${Cr()}`}=i,c={dependentVariables:[s],meta:t,info:{...r,name:Z(a)}};return Vo(e)&&Yo(c,n,t,e,r,{logger:o}),c}function wr(e){return"minMax"in e}function Vo(e){return!wr(e)}function Ho(e){return e.spectra.map(t=>{let r=U(t.data);return{...t,data:r}})}function Go(e,t){let r={...e.minMax,z:U(e.minMax?.z)};return t?Ko(r):{rr:r}}function Yo(e,t,r,n,i,o){let{assignmentsByBlocks:s}=t,a=Mr(r);Ze(a)&&Zo(e,a);let c=String(n.info.BLOCKID);if(s?.[c]){let{molecule:l,assignments:m,moleculeBlockID:p}=s[c],f=Ir(l,i),g=U(n.spectra[0].data);if(g.x[0]>g.x[1])for(let d of n.spectra)d.data.x.reverse(),d.data.y.reverse();if(Ze(a)&&n.spectra.length>1){let{re:d}=Qo(n,a);g.y=d}let{x:y,y:u}=g,h=Ar(r,o)??Xo({x:y,y:u},{peakPicking:{frequency:i.originFrequency},ranges:{frequency:i.originFrequency,integrationSum:f}});Tr(e,{moleculeId:p,ranges:h,assignments:m,integrationSum:f})}}function Ko(e){let{z:t,...r}=e,n=[],i=[];for(let a=0;a<t.length;a+=2)n.push(t[a].slice()),i.push(t[a+1].slice());let o=Or(n),s=Or(i);return{re:{...r,z:n,minZ:o.min,maxZ:o.max},im:{...r,z:i,minZ:s.min,maxZ:s.max}}}function Zo(e,t){let{ph0:r,ph1:n}=t;e.filters||(e.filters=[]),e.filters.push({id:Cr(),name:"phaseCorrection",value:{ph0:r,ph1:n,absolute:!1},enabled:!0})}function Qo(e,t){let{ph0:r,ph1:n}=t,{re:i,im:o}=Wo({re:e.spectra[0].data.y,im:e.spectra[1].data.y},r*Math.PI/180,n*Math.PI/180);return{re:i,im:o}}function vr(e,t,r){let{logger:n}=r,i=[];for(let o of e)if(o.spectra&&o.spectra.length>0||o.minMax){es(o);let s={...o.info,...o.meta},a=xe(s,{logger:n});if(a.experiment==="wobble_curve")continue;i.push(Rr(o,s,a,t,r))}return i}function es(e){let t=e.meta["BRUKER FILE EXP"];if(!t)return;let n=(Array.isArray(t)?t:[t]).find(o=>o.slice(0,10).includes("vdlist"));if(!n)return;let i=n.split(`
|
|
10
|
+
`).slice(1);e.info.vdlistValues=ye(i)}async function Ae(e,t={}){let r=await e.text(),n=Lr(r,{name:e.name,...t});return lr(n,e,t)}function Lr(e,t={}){let r={spectra:[],molecules:[]},{name:n,converter:i={},selector:o={},logger:s}=t,{keepRecordsRegExp:a=/.*/}=i,c={keepSpectra:!0,noContour:!0,noTrimRegExp:/\$MOLFILE/,keepRecordsRegExp:a,logger:s},l=pr(rs(e),{name:n,...o,logger:s});for(let m of l)ns(m,r,c,n);if(is(r,o),r.spectra.length===0&&l.length>0){let m=r.molecules.length===0?" nor molecule":"";s?.warn(`No spectra${m} data was loaded from file ${n}`)}return ts(r)}function ns(e,t,r,n){let i=[],o=[],s={molecules:[]},{logger:a}=r,c={name:n,logger:a};Ye(e,o,r),br(o,s,i,c),t.spectra.push(...vr(i,s,c)),t.molecules.push(...s.molecules)}function is(e,t){t.index!==void 0&&(e.spectra=e.spectra.slice(t.index,t.index+1))}function ss(e,t={}){let{sourceSelector:r={},converter:n,keepSource:i,logger:o}=t;return o?.debug(`Reading JCAMP-DX file: ${e.name}`),Ae(e,{selector:as(r),converter:n?.jcamp,keepSource:i,logger:o})}function as(e={}){let{jcamp:t={},general:r={}}=e,{dataSelection:n="both"}=r;return{dataSelection:n,...t}}function Qe(){return os({id:"@zakodium/nmrium-core-plugins#JCAMPDXLoaderPlugin",version:1,shouldSerialize:!0,migrations:[],onReadProcess:{supportedExtensions:["jcamp","jdx","dx"],onFile:ss}})}import{defineNMRiumPlugin as Ms}from"@zakodium/nmrium-core";function kr(e){if(e===void 0)return{epoch:null,date:""};let t=e*1e3;return{epoch:t,date:new Date(t).toUTCString()}}var _r={0:"bigEndian",1:"littleEndian"},qr={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"},jr={0:"64Bit Float",1:"32Bit Float",2:"Reserved",3:"Reserved"},Br={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"},Ur={0:"None",1:"Real",2:"TPPI",3:"Complex",4:"Real_Complex",5:"Envelope"},$r={"-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"},zr={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},Jr={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"},et={0:"Ranged",1:"Listed",2:"Sparse",3:"Listed"};function w(e,t){return e.paramArray.find(r=>r.name===t)}function Wr(e,t){let r=e.paramArray.find(u=>u.name==="orders"),n=e.paramArray.find(u=>u.name==="factors"),i=e.paramArray.find(u=>u.name==="x_sweep"),o=e.paramArray.find(u=>u.name==="x_acq_time"),s=e.paramArray.find(u=>u.name==="x_points");if(!r||!n||!i||!o||!s){t?.error("There is not all parameters to calculate the number of point of digital filter");return}let a=r.value,c=Number.parseInt(a.slice(0,1),10),l=a.slice(1).length/c,m=0,p=new Int8Array(c),f=1,g=0;for(let u=0;u<c;u++)p[u]=Number.parseInt(n.value.slice(g,g+1),10),g+=1;for(let u=0;u<c;u++){let h=1;for(let d=u;d<c;d++)h*=p[d];m+=(Number.parseInt(a.slice(f,f+l),10)-1)/h,f+=l}return m/=2,m/i.value/o.value*(s.value-1)}function E(e,t){let r=w(e,t);if(r===void 0)return{magnitude:"NA",unit:"NA"};let n=r.unit[0],i=n.base,o=zr[n.prefix];return{magnitude:r.value*10**o,unit:i}}function tt(e){let t=e.readBytes(4),r=1990+(t[0]>>1),n=(t[0]<<3&8)+(t[1]>>5),i=t[2]&31;return{year:r,month:n,day:i}}function Ie(e,t){let r=[];for(let n=0;n<t;n++){let i=e.readByte(),o=i>>4,s=$r[o],a=i&15,c=e.readInt8(),l=Jr[c];r.push({prefix:s,power:a,base:l})}return r}function z(e,t){let r=[];for(let n=0;n<t;n++){let i=e.readChar();i!=="\0"&&r.push(i)}return r.join("")}function rt(e,t){let r=[];for(let n=0;n<t;n++){let i=e.readChar();i!==" "&&r.push(i)}return r.join("")}function N(e,t,r){let n=[];for(let i=0;i<t;i++)switch(r){case"readUint32":n.push(e.readUint32());break;case"readFloat64":n.push(e.readFloat64());break;case"readFloat32":n.push(e.readFloat32());break;case"readUint8":n.push(e.readUint8());break;default:break}return n}function Xr(e,t){let r=[];for(let n=0;n<t;n++)r.push(e.readBoolean());return r}function Vr(e,t,r){let n=1,i=0;for(let o of t.dataAxisType)o==="Real_Complex"&&i===0&&(n+=1,i+=1),o==="Complex"&&(n*=2);if(t.dataType!=="32Bit Float"&&t.dataType!=="64Bit Float"){r?.error("Only 32Bit Float and 64Bit Float data types are implemented yet");return}if(t.dataFormat==="One_D"){if(n!==1&&n!==2){r?.error("One_D data must have one or two data sections");return}return ls(e,t,n)}else if(t.dataFormat==="Two_D"){if(n===2)return ms(e,t);if(n===4)return us(e,t);r?.error("Two_D data must have two or four data sections");return}else{r?.error("Only One_D and two_D data formats are implemented yet");return}}function ls(e,t,r){return r===1?{re:nt(e,t)}:{re:nt(e,t),im:nt(e,t)}}function nt(e,t){return t.dataType==="32Bit Float"?N(e,t.dataPoints[0],"readFloat32"):N(e,t.dataPoints[0],"readFloat64")}var L=32;function ms(e,t){let r=t.dataPoints[0],i=t.dataPoints[1]/L,o=r/L;return{re:ee(e,t,i,o),im:ee(e,t,i,o)}}function us(e,t){let r=t.dataPoints[0],i=t.dataPoints[1]/L,o=r/L;return{re:{re:ee(e,t,i,o),im:ee(e,t,i,o)},im:{re:ee(e,t,i,o),im:ee(e,t,i,o)}}}function ee(e,t,r,n){let i=[];for(let o=0;o<r;o++){let s=[];for(let a=0;a<n;a++)for(let c=0;c<L;c++)a===0?t.dataType==="32Bit Float"?s[c]=N(e,L,"readFloat32"):t.dataType==="64Bit Float"&&(s[c]=N(e,L,"readFloat64")):t.dataType==="32Bit Float"?s[c]=s[c].concat(N(e,L,"readFloat32")):t.dataType==="64Bit Float"&&(s[c]=s[c].concat(N(e,L,"readFloat64")));i=i.concat(s)}return i}function Hr(e){let t=e.readChars(8),r=e.readInt8(),n=_r[r],i=e.readUint8(),o=e.readUint16(),s=e.readUint8(),a=e.readByte().toString(2).split("").map(O=>!!Number(O)),c=e.readByte(),l=c>>6,m=jr[l],p=c&63,f=Br[p],g=e.readInt8(),y=qr[g],u=N(e,8,"readUint8"),h=N(e,8,"readUint8").map(O=>Ur[O]),d=Ie(e,8),b=z(e,124),F=[];for(let O of N(e,4,"readUint8")){let ae=O>>4,_e=O&15;F.push(et[ae],et[_e])}let S=N(e,8,"readUint32"),I=N(e,8,"readUint32"),x=N(e,8,"readUint32"),A=N(e,8,"readFloat64"),M=N(e,8,"readFloat64"),T=tt(e),j=tt(e),re=z(e,16),Le=z(e,128),oe=z(e,128),se=z(e,128),J=[];for(let O=0;O<8;O++)J.push(z(e,32));let ke=N(e,8,"readFloat64"),k=N(e,8,"readFloat64"),$n=Xr(e,8);e.skip(3);let zn=!!(e.readByte()>>7),Jn=e.readUint32(),Wn=e.readUint32(),Xn=e.readUint32(),Vn=e.readUint32(),Hn=N(e,8,"readUint32"),Gn=N(e,8,"readUint32"),Yn=e.readUint32(),Kn=e.readUint32()<<32|e.readUint32(),Zn=e.readUint32()<<32|e.readUint32(),Qn=e.readUint32(),ei=e.readUint32()<<32|e.readUint32(),ti=e.readUint32(),ri=e.readUint32()<<32|e.readUint32(),ni=N(e,8,"readUint8"),bt=[];for(let O=0;O<2;O++){let ae=[],_e=e.readInt16();for(let Ft=0;Ft<5;Ft++)ae.push(e.readInt16());bt.push({scaler:_e,unit:ae})}return{fileIdentifier:t,endian:n,majorVersion:i,minorVersion:o,dataDimensionNumber:s,dataDimensionExist:a,dataType:m,dataFormat:f,dataInstrument:y,translate:u,dataAxisType:h,dataUnits:d,title:b,dataAxisRanged:F,dataPoints:S,dataOffsetStart:I,dataOffsetStop:x,dataAxisStart:A,dataAxisStop:M,creationTime:T,revisionTime:j,nodeName:re,site:Le,author:oe,comment:se,dataAxisTitles:J,baseFreq:ke,zeroPoint:k,reversed:$n,annotationOK:zn,historyUsed:Jn,historyLength:Wn,paramStart:Xn,paramLength:Vn,ListStart:Hn,ListLength:Gn,dataStart:Yn,dataLength:Kn,contextStart:Zn,contextLength:Qn,annoteStart:ei,annoteLength:ti,totalSize:ri,unitLocation:ni,compoundUnit:bt}}var ps={0:"String",1:"Integer",2:"Float",3:"Complex",4:"Infinity"};function Gr(e){let t=e.readUint32(),r=e.readUint32(),n=e.readUint32(),i=e.readUint32(),o=[];for(let s=0;s<n+1;s++){e.skip(4);let a=e.readInt16(),c=Ie(e,5);e.skip(16);let l=e.readInt32(),m=ps[l];e.seek(e.offset-20);let p;switch(m){case"String":p=rt(e,16);break;case"Integer":p=e.readInt32(),e.skip(12);break;case"Float":p=e.readFloat64(),e.skip(8);break;case"Complex":p={Real:e.readFloat64(),Imag:e.readFloat64()};break;case"Infinity":p=e.readInt32(),e.skip(12);break;default:e.skip(16);break}e.skip(4);let f=rt(e,28);o.push({name:f.toLowerCase(),scaler:a,unit:c,value:p,valueType:m})}return{parameterSize:t,lowIndex:r,highIndex:n,totalSize:i,paramArray:o}}function Yr(e,t){let r=new R(e);r.setBigEndian();let n=Hr(r);n.endian==="littleEndian"&&r.setLittleEndian(),r.seek(n.paramStart);let i=Gr(r);r.seek(n.dataStart);let o=Vr(r,n,t),s=[],a=[],c=[],l=[],m=[],p=[],f=[],g=[],y=[],u=[];if(n.dataFormat==="One_D"||n.dataFormat==="Two_D"){let d=kr(w(i,"actual_start_time")?.value);d.date&&(a.push(d.date),c.push(d.epoch)),s.push(w(i,"x_domain")?.value),l.push(E(i,"x_acq_time")),m.push(E(i,"x_sweep")),p.push(E(i,"x_sweep_clipped")),f.push(E(i,"x_resolution")),g.push(E(i,"x_freq")),y.push(E(i,"x_offset")),u.push(n.dataUnits[0].base)}return n.dataFormat==="Two_D"&&(s.push(w(i,"y_domain")?.value),l.push(E(i,"y_acq_time")),m.push(E(i,"y_sweep")),f.push(E(i,"y_resolution")),g.push(E(i,"y_freq")),y.push(E(i,"y_offset")),u.push(n.dataUnits[1].base)),{info:{sampleName:w(i,"sample_id")?.value,creationTime:n.creationTime,revisionTime:n.revisionTime,author:n.author,comment:n.comment,solvent:w(i,"solvent")?.value,temperature:E(i,"temp_get"),probeName:w(i,"probe_id")?.value,fieldStrength:E(i,"field_strength"),experiment:w(i,"experiment")?.value,dimension:n.dataDimensionNumber,nucleus:s,date:a,epoch:c,pulseStrength90:E(i,"x90"),numberOfScans:w(i,"scans")?.value,relaxationTime:E(i,"relaxation_delay"),dataPoints:n.dataPoints.slice(0,n.dataDimensionNumber),dataOffsetStart:n.dataOffsetStart,dataOffsetStop:n.dataOffsetStop,dataUnits:u,dataSections:o?Object.keys(o):void 0,originFrequency:g,frequencyOffset:y,acquisitionTime:l,spectralWidth:m,spectralWidthClipped:p,dataAxisStart:n.dataAxisStart,dataAxisStop:n.dataAxisStop,resolution:f,decimationRate:w(i,"decimation_rate")?.value,paramList:JSON.stringify(i.paramArray.map(d=>d.name)),digitalFilter:Wr(i,t)},headers:n,parameters:i,data:o}}import{formatSpectra as ys}from"@zakodium/nmrium-core";import{getGyromagneticRatio as hs}from"gyromagnetic-ratio";import{isAnyArray as bs}from"is-any-array";import Fs from"lodash.merge";import{normalizeNucleus as xs}from"nmr-processing";import{isAnyArray as te}from"is-any-array";var Kr={0:"uint8",1:"uint16",2:"uint32",3:"uint64",4:"int8",5:"int16",6:"int32",7:"int64",8:"float32",9:"float64",10:"complex64",11:"complex128"},Zr={0:"scalar",1:"vector",2:"matrix",3:"symetricMatrix",4:"pixel"};function Qr(e,t,r={}){let{quantityType:n=0,encoding:i="none",name:o="",unit:s="",quantityName:a="",sparseSampling:c={},from:l=[0],to:m=[-1]}=r;if(te(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 p=ot(e,l,m),{componentLabels:f=p.componentLabels}=r;return{type:"internal",quantityType:Zr[n],numericType:Kr[t],encoding:i,name:o,unit:s,quantityName:a,componentLabels:f,sparseSampling:c,description:r.description||"",application:r.application||"",components:p.components,dataLength:p.dataLength}}function fs(e){return te(e.re)&&te(e.im)}function ds(e){return!te(e.re[0])}function ot(e,t,r){let n=[],i=[],o=[];if(fs(e))if(ds(e)){n[0]=it(t[0],r[0],e.re.length);let s=new Float64Array(n[0]);for(let a=0;a<n[0];a+=2){let c=a+t[0]*2;s[a]=e.re[c/2],s[a+1]=e.im[c/2]}o.push(s),i.push("complex")}else if(te(e.re[0])){n[0]=gs(t[1],r[1],e.re.length),n[1]=it(t[0],r[0],e.re[0].length);for(let s=0;s<n[0];s++){let a=new Float64Array(n[1]);for(let c=0;c<n[1];c+=2){let l=c+t[0]*2;a[c]=e.re[s][l/2],a[c+1]=e.im[s][l/2]}o.push(a)}}else throw new Error("check your object");else if(te(e.re.re)){n[0]=it(t[1],r[1],e.re.re.length);let s=ot(e.re,t,r).components,a=ot(e.im,t,r).components;for(let c=0;c<n[0]/2;c++)o.push(s[c],a[c])}else throw new Error("check the dimension or the type of data in your array");return{dataLength:n,componentLabels:i,components:o}}function gs(e,t,r){return t-e+1<r?t-e+1:r}function it(e,t,r){return t-e+1<r?(t-e+1)*2:r*2}async function tn(e,t={}){let r=await e.arrayBuffer(),{name:n=Z(e.name),keepSource:i=!1}=t,o={spectra:[],molecules:[]},a=As(r)[0],{metadata:c,...l}=a.description,m=0,p=l.dimension===1?"1d":"2d",f="NMR SPECTRUM",g=l.dimension===1?l.nucleus[0]:l.nucleus,y=l.spectralWidthClipped[0],u;a.dependentVariables&&(l.dimension===1?u=Ds(a):l.dimension===2&&(u=Ss(a)));for(let d in l)Array.isArray(l[d])&&l[d].length===1&&(l[d]=l[d][0]);let h={data:u,info:{...l,acquisitionMode:m,experiment:p,type:f,nucleus:g,spectralWidthClipped:y,name:n},meta:c};return i&&(h.sourceSelector={files:[e.relativePath]}),o.spectra=[h],ys(o)}function Ds(e){let t=e.dimensions[0],r=e.dependentVariables,n=t.quantityName,i=t.count,o=t.increment.magnitude,s=t.originOffset.magnitude,a=t.coordinatesOffset.magnitude,c=r[0].components[0],l=new Float64Array(i),m=new Float64Array(i);for(let u=c.length-1,h=0;u>0;u-=2)l[h]=c[u-1],m[h++]=c[u];let p={},[f,g]=[0,0];switch(n){case"frequency":g=0+a/s*1e6,f=o/s*1e6,p.re=l,p.im=m;break;case"time":g=s,f=o,p.re=l.reverse(),p.im=m.reverse().map(u=>-u);break;default:break}let y=[];for(let u=0;u<i;u++)y.push(g+u*f);return p.x=y,p}function Ss(e){let t=e.dimensions,r=e.dependentVariables,n=t[0].quantityName,i=[],o=[],s=Number.MIN_SAFE_INTEGER,a=Number.MAX_SAFE_INTEGER,c=Number.MAX_SAFE_INTEGER,l=Number.MIN_SAFE_INTEGER;for(let f of r[0].components){let g=new Float64Array(f.length/2),y=new Float64Array(f.length/2);for(let u=f.length-1,h=0;u>0;u-=2){let d=f[u-1],b=f[u];d>s&&(s=d),d<a&&(a=d),b>l&&(l=b),b<c&&(c=b),g[h]=d,y[h++]=b}if(n==="frequency")i.push(g),o.push(y);else{let u=g.length,h=new Float64Array(y.length);for(let d=0,b=u-1;d<u;d++)h[d]=-y[b--];i.push(g.reverse()),o.push(h)}}let m={re:{z:i,minZ:a,maxZ:s},im:{z:o,minZ:c,maxZ:l}},p=["X","Y"];for(let f=0;f<p.length;f++){let g=t[f].count,y=t[f].increment.magnitude,u=t[f].originOffset.magnitude,h=t[f].coordinatesOffset.magnitude,d=p[f];for(let b of["re","im"])n==="frequency"?(m[b][`min${d}`]=0+h/u*1e6,m[b][`max${d}`]=g*(y/u)*1e6):(m[b][`min${d}`]=u,m[b][`max${d}`]=g*y)}return m}function As(e){let t=Yr(e),r=t.info,n=t.headers,{paramArray:i,...o}=t.parameters,{dimension:s}=r,a={};for(let d of i){let{name:b,value:F}=d;a[b]=rn(F,s)}let c=t.data,l={};l.title=`title: ${n.title} / comment: ${n.comment} / author:${n.author} / site: ${n.site}`,l.nucleus=r.nucleus.map(xs),l.sampleName=r.sampleName,l.date=r.date,l.epoch=r.epoch,l.localeDate=new Date(r.epoch[0]).toLocaleString(),l.author=r.author,l.solvent=r.solvent,l.temperature=r.temperature.magnitude,l.probeName=r.probeName||"",l.fieldStrength=r.fieldStrength.magnitude;let m=l.nucleus.map(hs);l.baseFrequency=m.map(d=>r.fieldStrength.magnitude*d/(2*Math.PI*1e6)),l.pulseSequence=r.experiment,l.temperature=r.temperature?.unit?.toLowerCase()==="celsius"?273.15+r.temperature.magnitude:r.temperature.magnitude,l.digitalFilter=r.digitalFilter,l.pulseStrength90=1/(4*r.pulseStrength90.magnitude),l.numberOfScans=r.numberOfScans,l.relaxationTime=r.relaxationTime.magnitude,l.isComplex=r.dataSections?r.dataSections.includes("im"):!1,l.isFid=r.dataUnits[0]==="Second",l.isFt=r.dataUnits[0]==="Ppm",l.dimension=r.dimension,l.originFrequency=r.originFrequency.map(d=>d.magnitude/1e6).slice(0,s),l.numberOfPoints=r.dataPoints.slice(0,1),l.frequencyOffset=r.frequencyOffset.map((d,b)=>d.magnitude*l.baseFrequency[b]).slice(0,s),l.acquisitionTime=r.acquisitionTime.map(d=>d.magnitude).slice(0,s),l.spectralWidth=r.spectralWidth.map((d,b)=>d.magnitude/r.originFrequency[b].magnitude*1e6).slice(0,s),l.spectralWidthClipped=r.spectralWidthClipped.map((d,b)=>d.magnitude/l.baseFrequency[b]*1e6).slice(0,s);let p=[],f={},g;for(let d=0;d<r.dimension;d++){if(g={magnitude:r.acquisitionTime[d].magnitude/(r.dataPoints[d]-1),unit:"s"},r.dataUnits[d]==="Second")f.quantityName="time",f.originOffset={magnitude:0,unit:"s"},d===0?f.coordinatesOffset={magnitude:r.digitalFilter*g.magnitude,unit:"s"}:f.coordinatesOffset={magnitude:0,unit:"s"},f.reciprocal={originOffset:{magnitude:r.originFrequency[d].magnitude,unit:"Hz"},quantityName:"frequency",coordinatesOffset:{magnitude:r.frequencyOffset[d].magnitude*r.originFrequency[d].magnitude/1e6,unit:"Hz"}};else if(r.dataUnits[d]==="Ppm"){f.quantityName="frequency";let b=r.originFrequency[d].magnitude;f.originOffset={magnitude:b,unit:"Hz"};let F=r.dataOffsetStart[d],I=r.dataOffsetStop[d]-F+1;g={magnitude:Is(r,d)/(I-1),unit:"Hz"};let M=r.dataAxisStop[d]*b/1e6;f.coordinatesOffset={magnitude:M,unit:"Hz"},I!==r.dataPoints[d]&&(r.dataPoints[d]=I)}d===0?f.description="direct dimension":f.description="indirect dimension",p.push({label:n.dataAxisTitles[d],count:r.dataPoints[d],increment:g,type:"linear",description:String(f.description)||"",application:f.application||{},coordinatesOffset:f.coordinatesOffset||0,originOffset:f.originOffset||0,quantityName:String(f.quantityName)||"",reciprocal:f.reciprocal||{},period:f.period||0,complexFFT:f.complexFFT||!1})}let y=[];y.push(Qr(c,11,{unit:"none",quantityName:"relative intensity",from:r.dataOffsetStart,to:r.dataOffsetStop}));let u={...l};return delete u.paramList,u.metadata={...en(n,s),...en(o,s),...Fs({},a)},[{timeStamp:Date.now(),description:u,dimensions:p,dependentVariables:y}]}function Is(e,t){let{spectralWidth:r,spectralWidthClipped:n}=e;return n[t].magnitude!=="NA"?n[t].magnitude:r[t].magnitude}function en(e,t){let r={};for(let n in e)r[n]=rn(e[n],t);return r}function rn(e,t){return bs(e)?t>1?e.slice(0,t):e[0]:e}function Ns(e,t={}){let{logger:r,keepSource:n}=t;return r?.debug(`Reading JEOL file: ${e.name}`),tn(e,{name:e.name,keepSource:n,logger:r})}function st(){return Ms({id:"@zakodium/nmrium-core-plugins#JEOLLoaderPlugin",version:1,shouldSerialize:!0,migrations:[],onReadProcess:{supportedExtensions:["jdf"],onFile:Ns}})}import{defineNMRiumPlugin as Ps}from"@zakodium/nmrium-core";function Es(e,t={}){let{logger:r}=t;return r?.debug(`Reading molfile file: ${e.name}`),gr(e,{logger:r})}function at(){return Ps({id:"@zakodium/nmrium-core-plugins#MolfileLoaderPlugin",version:1,shouldSerialize:!0,migrations:[],onReadProcess:{supportedExtensions:["mol"],onFile:Es}})}import{defineNMRiumPlugin as ea}from"@zakodium/nmrium-core";import{FileCollection as Ff}from"file-collection";import{Molecule as bn}from"openchemlib";import{getShortestPaths as Ts}from"openchemlib-utils";function nn(e,t){let{molecule:r,map:n}=t;r.addImplicitHydrogens();let i=Ts(r,{toLabel:"H",maxLength:1});for(let s in e){let a=e[s],c=a.atoms;if(c.length!==0){if(a.position=[],c[0].toLowerCase().includes("h")){let l=Number(c[0].toLowerCase().replace("h",""))-1;l=n.indexOf(l);let m=i[l].find(p=>p&&p.length>1);a.position=i[m[0]].filter(p=>p&&p.length>1).map(p=>p.at(-1))}else if(c[0].toLowerCase().match(/\w/s))for(let l of c){let m=n.indexOf(Number(l)-1);a.position.push(m)}}}let o=r.getDiastereotopicAtomIDs();for(let s in e){let a=[];if("position"in e[s])for(let c of e[s].position)a.includes(o[c])||a.push(o[c]);e[s].diaIDs=a}return e}async function on(e,t){let{fileCollection:r,root:n}=t,i=e.data.filter(s=>s.value.spectrum_location),o=[];for(let s of i){if(!s){new Error(`There is not spectrum for ${e}`);return}let a=s.value.spectrum_location;if(a.match(/file:/s)){let c=n+a.replace(/file:[./]*/s,""),l=c.match(/[ser|fid]/s)?/([.*/]*\w+\/[0-9]+\/).*/:/(.*\w+\/[0-9]+\/)pdata\/.*/,m=c.replace(l,"$1"),p=c.replace(/.*\/[0-9]+\/pdata\/([0-9]+)\/.*/,"$1"),f=r.filter(g=>{if(g.relativePath.match("pdata")&&p!==g.relativePath.replace(/.*\/[0-9]+\/pdata\/([0-9]+)\/.*/,"$1"))return!1;let y=g.relativePath.replace(/([.*/]*\w+\/[0-9]+\/).*/,"$1");return!(m!==y&&!["ser","fid"].some(u=>c===`${y}${u}`))});o.push({type:"brukerFiles",fileCollection:f})}else a.match("http")&&o.push({type:"url",value:a})}return o}async function sn(e,t){let{fileCollection:r,root:n}=t,i=e.data.find(c=>c.value.jcamp_location);if(!i){new Error(`There is not spectrum for ${e}`);return}let o=i.value.jcamp_location,s=n+o.replace(/file:/s,""),a=r.filter(c=>c.relativePath===s);if(a.files.length===0){new Error(`There is not jcamp with path: ${s}`);return}return[{name:s,type:"jcamp",fileCollection:a}]}function an(e={}){let t={};for(let r of e.data||[]){let{label:n,atoms:i,shift:o}=r.value;t[n]={shift:o,atoms:i}}return t}function cn(e){let t=e.match(/([0-9])\w_/s)?.[1];if(t==="1")return e.slice(3).replaceAll(/(?<nucleus>[0-9]+\w+)#\w+/g,"$<nucleus>");if(t==="2"){let r=[],n=e.slice(12).split("_");for(let i=0;i<n.length;i+=2)r.push(n[i].replaceAll(/(?<nucleus>[0-9]+\w+)#\w+/g,"$<nucleus>"))}return[]}var Os=["delta","nbAtoms","multiplicity","jCoupling"];function ln(e,t){let r={};for(let s of Os){let a=e[s];a&&(r[s]=a)}let{nbAtoms:n,integration:i}=e;if(r.integration=i?Number(i):n?Number(n):null,e.assignment)for(let s of e.assignment){let a=t[s];r.diaIDs||(r.diaIDs=[]),a?.diaIDs&&r.diaIDs.push(...a.diaIDs)}let o=!1;if(r.jCoupling&&(o=r.jCoupling.some(s=>Object.keys(s).includes("label"))),o){for(let s of r.jCoupling)if(s.label){let a=t[s.label];a?.diaIDs&&(s.diaIDs=a.diaIDs)}}return r.delta&&(r.delta=Number.parseFloat(r.delta)),r}var Cs=["intensity","volume","activeCoupling"],Rs={x:["f1Width","f1Coupling"],y:["f2Width","f2Coupling"]};function mn(e,t){let r={};for(let n of Cs)e[n]&&(r[n]=e[n]);for(let n in e.delta){r[n]||(r[n]={});let i=e.delta[n];for(let o of i)r[n].diaIDs||(r[n].diaIDs=[]),t[o]?(r[n].diaIDs.push(...t[o].diaIDs),r[n].delta=Number.parseFloat(t[o].shift)):r[n].delta=Number.parseFloat(o);for(let o of Rs[n])if(e[o]){let s=o.toLowerCase().replace(/f\w(\w+)/,"$1");r[n][s]=e[o]}}return r}async function un(e,t){let{moleculeAndMap:r}=t,n={molecules:[{molfile:r.molecule.toMolfile()}],spectra:[]},i=n.spectra,o=n.molecules;e.SMILES?.data.length>0&&(o[0].smiles=e.SMILES.data[0].value);let s=an(e.ASSIGNMENT);s=nn(s,r);for(let a in e){let c=a.toLowerCase();if(!c.match(/[1|2]d_/s))continue;let l=e[a].data.find(d=>d.value.larmor),m=e[a].data.find(d=>d.value.pulseprogram),p=cn(a),f=c.replace(/([1|2]d)_.*/,"$1"),g=f==="2d"?mn:ln,y={source:{jcampURL:null},nucleus:p,frequency:l?.value.larmor,experiment:m?m.value.pulseprogram.trim():f,headComment:e[a].headComment},u=e[a].data.filter(d=>d.value.delta);y.signals=u.map(d=>{let b=g(d.value,s);return b.comment=d.comment,b});let h=await ws(e[a],t);if(!h.jcamp&&!h.bruker)i.push(y);else for(let d in h)h[d]&&i.push({...y,source:{...y.source,file:h[d]}})}return n}async function ws(e,t){return{jcamp:await sn(e,t),bruker:await on(e,t)}}function Me(e,t={}){let{include:r,exclude:n,filter:i,modifiers:o={},forEach:s={},dynamicTyping:a=!0,mixedEOL:c=!1}=t;if(typeof e!="string")throw new TypeError('Parameter "sdf" must be a string');let l=`
|
|
11
11
|
`;if(c)e=e.replaceAll(`\r
|
|
12
12
|
`,`
|
|
13
13
|
`),e=e.replaceAll("\r",`
|
|
14
14
|
`);else{let y=new Set(e.slice(0,1e3));y.has(`\r
|
|
15
15
|
`)?l=`\r
|
|
16
|
-
`:y.has("\r")&&(l="\r")}let m=e.split(new RegExp(`${l}\\$\\$\\$\\$.*${l}`)),p=[],f={},g=Date.now();for(let y of m){let u=y.split(`${l}>`);if(u.length>0&&u[0].length>5){let h={molfile:u[0]+l},d=[];for(let b=1;b<u.length;b++){let F=u[b].split(l),S=F[0].indexOf("<"),I=F[0].indexOf(">"),x=F[0].slice(S+1,I);if(d.push(x),f[x]||(f[x]={label:x,counter:0,nbLines:"",isNumeric:a,keep:!1},!n?.includes(x)&&(!r||r.includes(x))&&(f[x].keep=!0,o[x]&&(f[x].modifier=o[x]),s[x]&&(f[x].forEach=s[x]))),f[x].keep){for(let A=1;A<F.length-1;A++)h[x]?h[x]+=l+F[A]:h[x]=F[A];if(f[x].modifier){let A=f[x].modifier(h[x]);A==null?delete h[x]:h[x]=A}f[x].isNumeric&&(!Number.isFinite(+h[x])||h[x].match(/^0[0-9]/))&&(f[x].isNumeric=!1)}}if(!i||i(h)){p.push(h);for(let b of d)f[b].counter++}}}for(let y in f){let u=f[y];if(u.isNumeric){u.minValue=1/0,u.maxValue=-1/0;for(let h of p)if(h[y]){let d=Number.parseFloat(h[y]);h[y]=d,d>u.maxValue&&(u.maxValue=d),d<u.minValue&&(u.minValue=d)}}}for(let y in f)f[y].always=f[y].counter===p.length;return{time:Date.now()-g,molecules:p,labels:Object.keys(f),statistics:Object.values(f)}}function ct(e){let t={};for(let{key:r,value:n}of e)t[r]=n;return t}function Ne(e){let t=[];e=e.replaceAll(/,([0-9])/g,":$1");for(let r of e.split(":")){let n,i="",o=r.indexOf("(");o===-1?(n=Number(r),t.push({coupling:n})):(n=Number(r.slice(0,o)),i=r.slice(o+1,-1),t.push({coupling:n,label:i}))}return t}function
|
|
17
|
-
`);for(let a of s){let c=a.replaceAll(/;.*/g,"").replaceAll("\r",""),l=a.match(";")?a.replaceAll(/.*;+(.*)/g,"$1"):"";if(c.length===0){o.headComment||(o.headComment=[]),o.headComment.push(l);continue}let m=
|
|
18
|
-
`),n[o]=s}return n}function mt(e,t={}){if(typeof e=="string"){let{filename:r="nmredata.sdf",root:n=""}=t;return{...Me(e,{mixedEOL:!0}),root:n,filename:r}}return e}import{generateID as
|
|
16
|
+
`:y.has("\r")&&(l="\r")}let m=e.split(new RegExp(`${l}\\$\\$\\$\\$.*${l}`)),p=[],f={},g=Date.now();for(let y of m){let u=y.split(`${l}>`);if(u.length>0&&u[0].length>5){let h={molfile:u[0]+l},d=[];for(let b=1;b<u.length;b++){let F=u[b].split(l),S=F[0].indexOf("<"),I=F[0].indexOf(">"),x=F[0].slice(S+1,I);if(d.push(x),f[x]||(f[x]={label:x,counter:0,nbLines:"",isNumeric:a,keep:!1},!n?.includes(x)&&(!r||r.includes(x))&&(f[x].keep=!0,o[x]&&(f[x].modifier=o[x]),s[x]&&(f[x].forEach=s[x]))),f[x].keep){for(let A=1;A<F.length-1;A++)h[x]?h[x]+=l+F[A]:h[x]=F[A];if(f[x].modifier){let A=f[x].modifier(h[x]);A==null?delete h[x]:h[x]=A}f[x].isNumeric&&(!Number.isFinite(+h[x])||h[x].match(/^0[0-9]/))&&(f[x].isNumeric=!1)}}if(!i||i(h)){p.push(h);for(let b of d)f[b].counter++}}}for(let y in f){let u=f[y];if(u.isNumeric){u.minValue=1/0,u.maxValue=-1/0;for(let h of p)if(h[y]){let d=Number.parseFloat(h[y]);h[y]=d,d>u.maxValue&&(u.maxValue=d),d<u.minValue&&(u.minValue=d)}}}for(let y in f)f[y].always=f[y].counter===p.length;return{time:Date.now()-g,molecules:p,labels:Object.keys(f),statistics:Object.values(f)}}function ct(e){let t={};for(let{key:r,value:n}of e)t[r]=n;return t}function Ne(e){let t=[];e=e.replaceAll(/,([0-9])/g,":$1");for(let r of e.split(":")){let n,i="",o=r.indexOf("(");o===-1?(n=Number(r),t.push({coupling:n})):(n=Number(r.slice(0,o)),i=r.slice(o+1,-1),t.push({coupling:n,label:i}))}return t}function pn(e){let t={};e=e.replaceAll(" ",""),e=e.replaceAll(/[l=] /g,""),e=e.replaceAll(/,(\w=)/g,":$1");let r=e.split(":");for(let[n,i]of r.entries()){let o=i.toLowerCase(),s=o.replace(/^.*=/,""),a=o.replace(/[=].*/,"");Number.parseFloat(a)&&n===0?t.delta=s:t[vs(a)]=Ls(s,a)}return t}function vs(e){switch(e){case"j":return"jCoupling";case"s":return"multiplicity";case"l":return"assignment";case"n":return"nbAtoms";case"e":case"i":return"integration";default:return""}}function Ls(e,t){switch(t){case"l":return ks(e);case"j":return Ne(e);default:return e}}function ks(e){return e.replaceAll(/\s*/g,"").split(",")}var _s=["y","x"];function fn(e){e=e.replaceAll(" ",""),e=e.replaceAll(/[l=] /g,""),e=e.replaceAll(/,(\w+=)/g,":$1");let t=e.split(":"),r=qs(t[0]);for(let n=1;n<t.length;n++){let{value:i,key:o}=dn(t[n]);r[Bs(o)]=js(i,o)}return r}function qs(e){let{value:t}=dn(e),r={delta:{}},n=t.split("/");for(let i=0;i<n.length;i++){let o=n[i].replaceAll(/[(|)]/g,"").split(",");r.delta[_s[i]]=Array.isArray(o)?o:[o]}return r}function dn(e){let t=e.toLowerCase();return{value:t.replace(/^.*=/,""),key:t.replace(/[=].*/,"")}}function js(e,t){switch(t){case"ja":case"j1":case"j2":return Ne(e);default:return e}}function Bs(e){switch(e){case"ja":return"activeCoupling";case"j1":return"f1Coupling";case"j2":return"f2Coupling";case"i":return"intensity";case"s":return"volume";case"w1":return"f1Width";case"w2":return"f2Width";default:return e}}function yn(e,t){let r=Us(t),n=e.match(/[=]/g);return!n&&!e.match(",")?t.toLowerCase().match(/2d/)?r(e):e:t.toLowerCase().match(/[1|2]d/)&&n&&!e.match(",")?hn(e):r(e)}function Us(e){let t=e.toLowerCase();switch(t.match(/1d/)&&(t="1d"),t.match(/2d/)&&(t="2d"),t){case"id":return hn;case"1d":return pn;case"2d":return fn;case"assignment":case"signals":return gn;case"j":return gn;case"smiles":case"inchi":case"version":case"solvent":case"temperature":case"level":default:return r=>r}}function hn(e){let t=e.replace(/^.*=/,""),r=e.replace(/[=].*/,"").toLowerCase();return ct([{key:r,value:t}])}function gn(e){let t=e.replaceAll(" ","").split(",");return ct([{key:"label",value:t[0].toLowerCase()},{key:"shift",value:t.slice(1,2)},{key:"atoms",value:t.slice(2)}])}async function lt(e){let t=[];for(let r of e.files){let n=r.relativePath.split("/");if(/^[^.].+sdf|nmredata$/.exec(r.name)){let i=await r.text();if(!i.match("NMREDATA"))continue;let o=Me(i,{mixedEOL:!0}),s=n.slice(0,-1).join("/");t.push({...o,filename:r.name,root:s!==""?`${s}/`:""})}}return t}function Fn(e){let{sdf:t,fileCollection:r}=e,{molecule:n}=e,i=mt(t);n??=bn.fromMolfile(i.molecules[0].molfile),n.addImplicitHydrogens();let o=bn.fromMolfileWithAtomMap(n.toMolfile()),s=$s(i);return un(s,{moleculeAndMap:o,root:i.root,fileCollection:r})}function $s(e){let t=mt(e),r={name:t.filename},n=zs(t);for(let i of Object.keys(n)){r[i]||(r[i]={data:[]});let o=r[i],s=n[i].split(`
|
|
17
|
+
`);for(let a of s){let c=a.replaceAll(/;.*/g,"").replaceAll("\r",""),l=a.match(";")?a.replaceAll(/.*;+(.*)/g,"$1"):"";if(c.length===0){o.headComment||(o.headComment=[]),o.headComment.push(l);continue}let m=yn(c,i);o.data.push({comment:l,value:m})}}return r}function zs(e){let t=mt(e),r=Number.parseFloat(t.molecules[0].NMREDATA_VERSION),n={};for(let i of t.labels)if(i.toLowerCase().match("nmredata")){if(!t.molecules[0]?.[i])continue;let o=i.replace(/NMREDATA_/,""),s=String(t.molecules[0][i]);s=r>1?s.replaceAll(/\n*/g,""):s,s=s.replaceAll(/\\\n*/g,`
|
|
18
|
+
`),n[o]=s}return n}function mt(e,t={}){if(typeof e=="string"){let{filename:r="nmredata.sdf",root:n=""}=t;return{...Me(e,{mixedEOL:!0}),root:n,filename:r}}return e}import{generateID as Sn}from"@zakodium/nmrium-core";import{generateID as xn}from"@zakodium/nmrium-core";import{xyIntegration as Js}from"ml-spectra-processing";function Dn(e,t){let{x:r,re:n}=t.data;return e.map(i=>{let o=Js({x:r,y:n},{from:i.from,to:i.to}),s=[];for(let a of i.signals||[]){let{kind:c=null,id:l,js:m=[],diaIDs:p=[],...f}=a;s.push({...f,kind:c||"signal",js:m,id:l||xn(),diaIDs:p})}return{...i,id:i.id||xn(),kind:s?.[0].kind||"signal",absolute:o,signals:s}})}function An(e,t){let r=[],{baseFrequency:n=500}=t.info;for(let i of e){let{delta:o,diaIDs:s=[],multiplicity:a="",integration:c=0}=i,l=i.jCoupling||[],m=Ws({delta:o,js:l,frequency:n});if(l&&a&&l.length===a.length){l.sort((p,f)=>f.coupling-p.coupling);for(let p=0;p<l.length;p++)l[p].multiplicity=a[p]}r.push({id:Sn(),...m,integration:c,signals:[{id:Sn(),js:l,delta:o,diaIDs:s,multiplicity:a}]})}t.ranges.values=Dn(Q(r),t)}function Ws(e){let{delta:t,js:r=[],frequency:n}=e,i=.5;for(let o of r)i+=o.coupling;return i/=n,{from:t-i,to:t+i}}import{generateID as In}from"@zakodium/nmrium-core";var Xs=["x","y"],Vs={x:0,y:0};function Mn(e,t,r={}){let n=[],{shift:i=Vs}=r,{originFrequency:o=[400,400]}=t.info,s={x:o[0],y:o[1]};for(let a of e){let c={x:{},y:{},id:In(),kind:"signal"},l={id:In(),kind:"signal",peaks:[]},m={x:10,y:10};for(let p of Xs){let{coupling:f=[],delta:g,diaIDs:y=[]}=a[p];for(let u of f)m[p]+=u.coupling;if(a.activeCoupling){let{activeCoupling:u=[]}=a;for(let h of u)m[p]+=h.coupling}m[p]/=s[p],c[p]={from:g-m[p],to:g+m[p]},l[p]={delta:g,diaIDs:y,originalDelta:g-i[p]}}n.push({...c,signals:[l]})}t.zones.values=n}function Nn(e){return Hs(e.data)}function Hs(e){return"rr"in e||!("x"in e)&&"re"in e}async function Pn(e,t,r={}){let n={spectra:[],molecules:[]},i=await Gs(e,t,r);if(i.spectra.length>0){let{spectra:o,molecules:s,usedFiles:a}=i;n.spectra.push(...o),n.molecules.push(...s);let c=e.files.length;for(let l=c-1;l>=0;l--){let m=e.files[l].relativePath;!m.match(/acqu.*/s)&&a.includes(m)&&e.files.splice(l,1)}}return n}async function Gs(e,t,r){let n=[],i=await lt(e),o={spectra:[],molecules:[]};if(i.length===0)return{...o,usedFiles:n};let s=[];for(let c of i){let l=Fn({sdf:c,fileCollection:e}).then(m=>{let{spectra:p,molecules:f=[]}=m;return n.push(c.root+c.filename),o.molecules.push(...f),Ys(p,t,r)});s.push(l)}let a=await Promise.allSettled(s);for(let c of a)c.status==="fulfilled"?(o.spectra.push(...c.value.spectra),n.push(...c.value.usedFiles)):c.reason&&r?.logger?.error(c.reason);return{...o,usedFiles:n}}async function Ys(e,t,r){let n=[],i=[],o={spectra:[],molecules:[]};for(let s of e){let a=Ks(s.source,t,r).then(c=>{let{spectra:l,files:m}=c;n.push(...m);for(let p of l)Nn(p)?Mn(s.signals,p):An(s.signals,p);o.spectra.push(...l)});i.push(a)}return await Promise.allSettled(i),{...o,usedFiles:n}}async function Ks(e,t,r={}){let{file:n,jcampURL:i}=e,{converter:o}=r;if(i){let c=await Zs(i,t,o?.jcamp);if(c)return{...c,files:[]}}let s=[];for(let c of n||[])s.push(Qs(c,r).then(l=>({...l,files:c.fileCollection.files.map(m=>m.relativePath)})));let a=await Promise.allSettled(s);for(let c of a){if(c.status==="fulfilled")return c.value;c.reason&&r?.logger?.error(c.reason)}return{spectra:[],molecules:[],files:[]}}async function Zs(e,t,r={}){let n={entries:[{relativePath:e}]},i={name:Z(e||""),xy:!0,noContours:!0,...r},{data:o}=await t.readFromWebSource(n,i);return o}async function Qs(e,t={}){let{converter:r,sourceSelector:n}=t;switch(e.type){case"jcamp":return Ae(e.fileCollection.files[0],{name:e?.fileCollection.files[0].name||"",converter:r?.jcamp,selector:n?.jcamp,logger:t.logger,keepSource:t.keepSource});case"brukerFiles":return De(e.fileCollection,{converter:r?.bruker,selector:n});default:throw new Error("There is not a supported source")}}function ut(e){return ea({id:"@zakodium/nmrium-core-plugins#NMReDATALoaderPlugin",version:1,shouldSerialize:!0,migrations:[],onReadProcess:{onFiles(t,r){return Pn(t,e,r)}}})}import{defineNMRiumPlugin as ra}from"@zakodium/nmrium-core";import{parse as ta}from"sdf-parser";function En(e,t={}){let{mixedEOL:r}=t,{molecules:n}=ta(e,{mixedEOL:r}),i=[];for(let{molfile:o}of n){let s=K(o);i.push(...s)}return i}async function Tn(e,t={}){let{logger:r,mixedEOL:n}=t,i=await e.text(),o=En(i,{mixedEOL:n}),s={molecules:o,spectra:[]};return r&&r[o.length>0?"info":"debug"](`Loaded ${s.molecules.length} molecules from the ${e.name} file`),s}function na(e,t={}){let{logger:r}=t;return r?.debug(`Reading sdf file: ${e.name}`),Tn(e,{logger:r})}function pt(){return ra({id:"@zakodium/nmrium-core-plugins#SDFLoaderPlugin",version:1,shouldSerialize:!0,migrations:[],onReadProcess:{supportedExtensions:["sdf"],onFile:na}})}import{defineNMRiumPlugin as oa}from"@zakodium/nmrium-core";import{Molecule as ia}from"openchemlib";function On(e){let t=[],r=e.split(/\r?\n/).filter(Boolean);for(let n of r){let o=ia.fromSmiles(n).toMolfile();t.push({molfile:o})}return t}async function Cn(e,t={}){let r=await e.text(),n=On(r),i={molecules:n,spectra:[]};return t.logger?.info(`Found ${n.length} molecules from the ${e.name} file`),i}function ft(){return oa({id:"@zakodium/nmrium-core-plugins#SMILESLoaderPlugin",version:1,shouldSerialize:!0,migrations:[],onReadProcess:{supportedExtensions:["smi","smiles"],onFile:Cn}})}import{defineNMRiumPlugin as fa}from"@zakodium/nmrium-core";import{formatSpectra as ma}from"@zakodium/nmrium-core";import{createFromToArray as aa}from"ml-spectra-processing/utils";function Rn(e){e.setLittleEndian();let t=e.offset,r=96;e.offset=r/8;let n=e.readInt32(),i=[2,4],o=[2**25,2**26];if(!i.includes(n))if(o.includes(n))e.setBigEndian();else throw new Error(`Unexpected value of eBytes (${n}). Expect one of
|
|
19
19
|
${i.concat(o).join(",")}`);return e.offset=t,e.isBigEndian()?"BE":"LE"}var Pe=class{storesData;isSpectrum;isInt32;isFloat32;isComplex;isHypercomplex;isBaselineCorrected;constructor(t){if(this.storesData=(t&1)!==0,!this.storesData)throw new Error("No data stored in file. Exiting...");if(this.isSpectrum=(t&2)!==0,this.isSpectrum)throw new Error("Script only analyzes FIDs. Found spectrum.");if(this.isInt32=(t&4)!==0,this.isFloat32=(t&8)!==0,this.isComplex=(t&16)!==0,this.isHypercomplex=(t&32)!==0,this.isHypercomplex)throw new Error("Script does not analyze hypercomplex data (yet).");this.isBaselineCorrected=(t&64)!==0}},Ee=class extends Pe{moreBlocks;npComplex;nfComplex;niComplex;ni2Complex;constructor(t){super(t),this.moreBlocks=(t&128)!==0,this.npComplex=(t&256)!==0,this.nfComplex=(t&512)!==0,this.niComplex=(t&1024)!==0,this.ni2Complex=(t&2048)!==0}},Te=class extends Pe{isAcqPar;isSecondFT;isTransformed;is3D;isNp;isNf;isNi;isNi2;constructor(t){super(t),this.isAcqPar=(t&128)!==0,this.isSecondFT=(t&256)!==0,this.isTransformed=(t&512)!==0,this.is3D=(t&1024)!==0,this.isNp=(t&2048)!==0,this.isNf=(t&4096)!==0,this.isNi=(t&8192)!==0,this.isNi2=(t&16384)!==0}},Oe=class{lines;length;index;eol;constructor(t,r={}){let{eol:n=`
|
|
20
|
-
`,index:i=0}=r;this.eol=n,this.index=i,this.lines=t.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(t){let r=this.lines.slice(this.index,this.index+t);return this.index+=t,r}},Ce=class{softwareVersion;typeOfFile;vendorIdStatus;constructor(t){this.softwareVersion=t&2**6-1,this.typeOfFile={fidFile:(t&64)!==0,dataFile:(t&128)!==0,data3DFile:(t&256)!==0},this.vendorIdStatus={isVar:(t&0)!==0,isQOne:(t&2048)!==0,isMakeFid:(t&4096)!==0,isJeol:(t&8192)!==0,isBru:(t&16384)!==0,isMag:(t&6144)!==0,isOx:(t&10240)!==0,ipVers:(t&63)!==0,ipFileId:(t&1984)!==0,ipVendorId:(t&30720)!==0}}},Re=class{npPhMode;npAvMode;npPwrMode;nfPhMode;nfAvMode;nfPwrMode;niPhMode;niAvMode;niPwrMode;ni2PhMode;ni2AvMode;ni2PwrMode;niPaMode;ni2PaMode;constructor(t){this.npPhMode=(t&1)!==0,this.npAvMode=(t&2)!==0,this.npPwrMode=(t&4)!==0,this.nfPhMode=(t&16)!==0,this.nfAvMode=(t&32)!==0,this.nfPwrMode=(t&64)!==0,this.niPhMode=(t&256)!==0,this.niAvMode=(t&512)!==0,this.niPwrMode=(t&1024)!==0,this.ni2PhMode=(t&8)!==0,this.ni2AvMode=(t&256)!==0,this.ni2PwrMode=(t&8192)!==0,this.niPaMode=(t&16384)!==0,this.ni2PaMode=(t&32768)!==0}};var we=class{scale;status;index;mode;ctCount;lpVal;rpVal;lvl;tlt;data;constructor(t,r,n){n&&(t.offset=n),this.scale=t.readInt16(),this.status=new Ee(t.readInt16()),this.index=t.readInt16(),this.mode=new Re(t.readInt16()),this.ctCount=t.readInt32(),this.lpVal=t.readFloat32(),this.rpVal=t.readFloat32(),this.lvl=t.readFloat32(),this.tlt=t.readFloat32(),this.data=
|
|
20
|
+
`,index:i=0}=r;this.eol=n,this.index=i,this.lines=t.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(t){let r=this.lines.slice(this.index,this.index+t);return this.index+=t,r}},Ce=class{softwareVersion;typeOfFile;vendorIdStatus;constructor(t){this.softwareVersion=t&2**6-1,this.typeOfFile={fidFile:(t&64)!==0,dataFile:(t&128)!==0,data3DFile:(t&256)!==0},this.vendorIdStatus={isVar:(t&0)!==0,isQOne:(t&2048)!==0,isMakeFid:(t&4096)!==0,isJeol:(t&8192)!==0,isBru:(t&16384)!==0,isMag:(t&6144)!==0,isOx:(t&10240)!==0,ipVers:(t&63)!==0,ipFileId:(t&1984)!==0,ipVendorId:(t&30720)!==0}}},Re=class{npPhMode;npAvMode;npPwrMode;nfPhMode;nfAvMode;nfPwrMode;niPhMode;niAvMode;niPwrMode;ni2PhMode;ni2AvMode;ni2PwrMode;niPaMode;ni2PaMode;constructor(t){this.npPhMode=(t&1)!==0,this.npAvMode=(t&2)!==0,this.npPwrMode=(t&4)!==0,this.nfPhMode=(t&16)!==0,this.nfAvMode=(t&32)!==0,this.nfPwrMode=(t&64)!==0,this.niPhMode=(t&256)!==0,this.niAvMode=(t&512)!==0,this.niPwrMode=(t&1024)!==0,this.ni2PhMode=(t&8)!==0,this.ni2AvMode=(t&256)!==0,this.ni2PwrMode=(t&8192)!==0,this.niPaMode=(t&16384)!==0,this.ni2PaMode=(t&32768)!==0}};var we=class{scale;status;index;mode;ctCount;lpVal;rpVal;lvl;tlt;data;constructor(t,r,n){n&&(t.offset=n),this.scale=t.readInt16(),this.status=new Ee(t.readInt16()),this.index=t.readInt16(),this.mode=new Re(t.readInt16()),this.ctCount=t.readInt32(),this.lpVal=t.readFloat32(),this.rpVal=t.readFloat32(),this.lvl=t.readFloat32(),this.tlt=t.readFloat32(),this.data=sa(t,r)}};function sa(e,t){let{np:r,nTraces:n,status:{isFloat32:i,isInt32:o}}=t;return i?dt(e,n,r,"readFloat32"):o?dt(e,n,r,"readInt32"):dt(e,n,r,"readInt16")}function dt(e,t,r,n){let i=[],o;n==="readFloat32"?o={re:new Float32Array(r/2),im:new Float32Array(r/2)}:n==="readInt32"?o={re:new Int32Array(r/2),im:new Int32Array(r/2)}:o={re:new Int16Array(r/2),im:new Int16Array(r/2)};for(let s=0;s<t;s++){for(let a=0;a<r;a+=2)o.re[a>>>1]=e[n](),o.im[a>>>1]=e[n]();i[s]=o}return i}var ve=class{nBlocks;nTraces;np;eBytes;tBytes;bBytes;version;status;nBlockHeaders;constructor(t){t.offset=0,this.nBlocks=t.readInt32(),this.nTraces=t.readInt32(),this.np=t.readInt32(),this.eBytes=t.readInt32(),this.tBytes=t.readInt32(),this.bBytes=t.readInt32(),this.version=new Ce(t.readInt16()),this.status=new Te(t.readInt16()),this.nBlockHeaders=t.readInt32()}};var gt=class{name;subType;basicType;maxValue;minValue;stepSize;gGroup;dGroup;protection;active;intptr;constructor(t){let r=t.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 wn(e){let t=[],r=new Oe(e.readChars(e.length));for(;r.index<r.length-1;){let n=[],i=[],o=new gt(r.readLine()),s=r.readLine();if(o.basicType!==0){if(o.basicType===1)n=s.split(" ").slice(1).map(m=>Number.parseFloat(m));else if(o.basicType===2){n=s.split('"').slice(1,2);let l=Number.parseInt(s.split(" ")[0],10);for(;l>1;)n.push(r.readLine().split('"')[1]),l--}}let a=r.readLine(),c=Number.parseInt(a.split(" ")[0],10);c!==0&&(o.basicType===1?i=a.split(" ").slice(1):o.basicType===2&&(i=a.split('"').filter((l,m)=>m%2===1))),t.push({...o,values:n,enumerable:c,enumerables:i})}return t}async function vn(e){let t={};function r(c,l){return c.then(m=>{t[l]=m})}let n=[];for(let c of e)switch(c.name.toLowerCase()){case"fid":{n.push(r(c.arrayBuffer(),"fidB"));break}case"procpar":{n.push(r(c.arrayBuffer(),"procparB"));break}default:break}if(await Promise.all(n),!t.fidB||!t.procparB)throw new RangeError("fid and procpar must exist.");let i=new R(t.fidB);Rn(i);let o=new ve(i);if(o.nBlocks!==1)throw new Error("We currently do not support 2D varian spectra ");let s=wn(new R(t.procparB)),a;for(let c of s)if(c.name==="at"){a=c.values[0];break}if(typeof a!="number")throw new Error("acquisition time parameter must exist and be a number.");{let c=aa({from:0,to:a,length:o.np/2,distribution:"uniform"}),l=new we(i,o);return{meta:o,fid:l,procpar:s,x:c}}}import{isAnyArray as ua}from"is-any-array";import{xMultiply as pa}from"ml-spectra-processing";import{normalizeNucleus as ca}from"nmr-processing";function Ln(e,t){let{meta:r,procpar:n}=e,i={};for(let b of n)i[b.name]=b.values;let o={},s={},{np:a,solvent:c,sfrq:l,reffrq:m,temp:p,rp:f,sw:g,rfl:y,rfp:u}=i;D(o,"numberOfPoints",a&&Number(q(a))/2),D(o,"solvent",q(c)),D(o,"originFrequency",q(l)),D(o,"baseFrequency",q(m)),(Number.isNaN(o.originFrequency)||o.originFrequency===0)&&(o.originFrequency=400,t?.warn("The frequency could not be determined and was set to 400MHz")),D(o,"temperature",q(p)),D(o,"phc0",f&&Number(f[0])),D(s,"rfl",y&&Number(q(y))),D(s,"rfp",u&&Number(q(u))),D(s,"sw",g&&Number(q(g)));for(let b in s){let F=s[b];Array.isArray(F)&&F.length===1&&(s[b]=F[0])}if(!("baseFrequency"in o)&&"originFrequency"in o){let b=Number.parseFloat(o.originFrequency);if(["sw","rfl","rfp"].every(F=>F in s)){let{sw:F=1,rfl:S=1,rfp:I=1}=la(s,["sw","rfl","rfp"]);D(o,"baseFrequency",b-(F/2-S+I)/1e6)}else D(o,"baseFrequency",b)}let{baseFrequency:h,originFrequency:d}=o;D(o,"frequencyOffset",(d-h)*1e6),D(o,"spectralWidth",g&&Number(g[0])/o.baseFrequency);for(let b in o)o[b].length===1&&(o[b]=o[b][0]);return i.tn&&(o.nucleus=i.tn.map(ca)),o.dimension=1,o.isFid=!r.status.isSpectrum,{info:o,meta:{...s,...kn(r),...i}}}function q(e){return e&&(Array.isArray(e)?e[0]:e)}function la(e,t){let r={};for(let n of t){let i=e[n];i&&typeof i=="number"&&(r[n]=i)}return r}function kn(e){let t={};for(let r of Object.keys(e)){let n=e[r];typeof n=="object"&&n!==null&&n.constructor&&n.constructor!==Object?t[r]=kn(n):t[r]=n}return t}function _n(e){let t={},r=new Set(e.files.map(n=>n.relativePath));for(let n of e){let i=n.name.toLowerCase();if(i.match(/^(?:fid|procpar|text|log)$/)){if(i.match(/^(?:fid|text|log)$/)){let a=n.relativePath.replace(/(?:fid|text|log)$/,"procpar");if(!r.has(a))continue}let o=n.relativePath.split("/"),s=o.slice(0,-1).join("/");t[s]||(t[s]={name:o.at(-2),files:[]}),t[s].files.push(n)}}return Object.values(t)}async function qn(e,t={}){let{keepSource:r,logger:n}=t,i=_n(e);n&&n.debug(`Found ${Object.keys(i).length} varian experiments`);let o=[],s={spectra:[],molecules:[]};for(let c of i){let{name:l,files:m}=c,p=vn(m).then(f=>{let{info:g,meta:y}=Ln(f),u=f.fid.data[0],h=ua(u.im),d={data:{...u,x:f.x},meta:y,info:{isComplex:h,name:l,...g},display:{name:l}};if(g.isFid&&h){let{im:b}=d.data;pa(b,-1,{output:b})}m&&r&&(d.sourceSelector={files:m.map(b=>b.relativePath)}),s.spectra.push(d)});o.push(p)}let a=await Promise.allSettled(o);for(let c=0;c<a.length;c++){let l=a[c];if(l.status==="rejected"&&l.reason){let m=i[c].name;n?.warn(`Varian data: ${m}, fails with: ${l.reason}`)}}return s.spectra.length>0&&n?.info(`Loaded ${s.spectra.length} spectra from Varian files`),ma(s)}function da(e,t){let{keepSource:r,logger:n}=t??{};return qn(e,{keepSource:r,logger:n})}function yt(){return fa({id:"@zakodium/nmrium-core-plugins#VarianLoaderPlugin",version:1,shouldSerialize:!0,migrations:[],onReadProcess:{onFiles:da}})}function ya(e,t=[]){return[ut(e),yt(),Ge(),Qe(),at(),pt(),ft(),st(),$e()].concat(t)}function ha(e=[]){let t=new ga;return t.registerPlugins(ya(t,e)),t}import{getOneIfArray as Bn}from"@zakodium/nmrium-core";import{from1DNMRVariables as ba}from"convert-to-jcamp";function jn(e,t){return e.filters.find(r=>r.name===t)}function Fa(e,t={}){let{onlyReal:r=!1}=t,{info:n,meta:i,data:o}=e,{owner:s,title:a,isFid:c,spectralWidth:l,baseFrequency:m,originFrequency:p,nucleus:f,solvent:g,scaleFactor:y,frequencyOffset:u,decim:h,dspfvs:d,digitalFilter:b}=n,F=Bn(m||p),{x:S,re:I,im:x}=o,A=new Float64Array(I),M=!r&&x?new Float64Array(x):void 0,T=jn(e,"fft")?.enabled,j={owner:s,isFid:c,title:a,nucleus:f,solvent:g,scaleFactor:y,spectralWidth:l,frequencyOffset:u,originFrequency:p,baseFrequency:F,dataType:!c||T?"NMR SPECTRUM":"NMR FID",dataClass:!r&&x?"NTUPLES":"XYDATA"};if(c){let se=e.filters.find(J=>J.name==="digitalFilter");if(se&&!T){let{value:{digitalFilterValue:J},enabled:ke}=se;if(ke){let k=Math.floor(J);A.set(I.slice(I.length-k)),A.set(I.slice(0,I.length-k),k),x&&M&&(M.set(x.slice(x.length-k)),M.set(x.slice(0,x.length-k),k))}}ht(j,"decim",h),ht(j,"dspfvs",d),ht(j,"digitalFilter",b)}let re=xa(i,Un),Le={xyEncoding:"DIFDUP",nmrInfo:j,meta:re},oe={x:{data:S,label:n.isFid?"TIME":"FREQUENCY",units:n.isFid?"second":"HZ",symbol:"X"},r:{data:A,label:`${n.isFid?"FID":"SPECTRUM"}/REAL`,units:"ARBITRARY UNITS",symbol:"R"}};return M&&(oe.i={data:M,label:`${n.isFid?"FID":"SPECTRUM"}/IMAG`,units:"ARBITRARY UNITS",symbol:"I"}),ba(oe,Le)}function ht(e,t,r){r!==void 0&&(e[t]=Bn(r))}var Un=["title","decim","dspfvs","grpdly","bf1","sw","offset",".solvent","owner","firsty","page","vardim","symbol","symbols","varform","vartype","datatype","dataclass",".observefrequency",".observenucleus","ncproc"];function xa(e,t=Un){let r=new Set(t);return Object.fromEntries(Object.entries(e).filter(([n])=>!r.has(n.toLocaleLowerCase().replaceAll(/[\s|_]*/g,""))))}export{$e as autoPostProcessing,Ge as brukerLoader,ha as default,ha as init,Qe as jcampDXLoader,st as jeolLoader,at as molfileLoader,ut as nmreDATALoader,Lr as processJCAMPDX,En as readSDF,On as readSMILES,ya as recommended,pt as sdfLoader,ft as smilesLoader,Fa as spectrum1DToJCAMPDX,yt as varianLoader};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zakodium/nmrium-core-plugins",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.4",
|
|
4
4
|
"description": "Recommended plugins for NMRium, loaders of common formats like bruker or jcamp, and some post-processing plugins",
|
|
5
5
|
"author": "Zakodium Sàrl",
|
|
6
6
|
"license": "CC-BY-NC-SA-4.0",
|
|
@@ -46,24 +46,24 @@
|
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
48
|
"@date-fns/utc": "^2.1.1",
|
|
49
|
-
"@zakodium/nmrium-core": "^0.2.
|
|
49
|
+
"@zakodium/nmrium-core": "^0.2.2",
|
|
50
50
|
"cheminfo-types": "^1.8.1",
|
|
51
51
|
"convert-to-jcamp": "^6.0.0",
|
|
52
52
|
"date-fns": "^4.1.0",
|
|
53
53
|
"file-collection": "^5.1.1",
|
|
54
54
|
"gyromagnetic-ratio": "^2.0.0",
|
|
55
55
|
"is-any-array": "^2.0.1",
|
|
56
|
-
"jcampconverter": "^11.1.
|
|
56
|
+
"jcampconverter": "^11.1.1",
|
|
57
57
|
"linear-sum-assignment": "^1.0.7",
|
|
58
58
|
"lodash.merge": "^4.6.2",
|
|
59
59
|
"ml-spectra-processing": "^14.17.1",
|
|
60
|
-
"nmr-processing": "^19.3.
|
|
61
|
-
"openchemlib": "^9.
|
|
60
|
+
"nmr-processing": "^19.3.2",
|
|
61
|
+
"openchemlib": "^9.9.0",
|
|
62
62
|
"openchemlib-utils": "^8.5.0",
|
|
63
63
|
"sdf-parser": "^7.0.4"
|
|
64
64
|
},
|
|
65
65
|
"volta": {
|
|
66
66
|
"extends": "../../../package.json"
|
|
67
67
|
},
|
|
68
|
-
"gitHead": "
|
|
68
|
+
"gitHead": "53cd32cbf4a73e576f5ef817bb5d5939f411e900"
|
|
69
69
|
}
|