@zakodium/nmrium-core-plugins 0.5.3 → 0.6.1

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.
@@ -15,6 +15,6 @@ var oi=Object.defineProperty;var xt=(e,t)=>{for(var r in t)oi(e,r,{get:t[r],enum
15
15
  `)?l=`\r
16
16
  `:y.has("\r")&&(l="\r")}let m=e.split(new RegExp(`${l}\\$\\$\\$\\$.*${l}`)),u=[],f={},g=Date.now();for(let y of m){let p=y.split(`${l}>`);if(p.length>0&&p[0].length>5){let h={molfile:p[0]+l},d=[];for(let b=1;b<p.length;b++){let F=p[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)){u.push(h);for(let b of d)f[b].counter++}}}for(let y in f){let p=f[y];if(p.isNumeric){p.minValue=1/0,p.maxValue=-1/0;for(let h of u)if(h[y]){let d=Number.parseFloat(h[y]);h[y]=d,d>p.maxValue&&(p.maxValue=d),d<p.minValue&&(p.minValue=d)}}}for(let y in f)f[y].always=f[y].counter===u.length;return{time:Date.now()-g,molecules:u,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 fn(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[Ls(a)]=ks(s,a)}return t}function Ls(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 ks(e,t){switch(t){case"l":return _s(e);case"j":return Ne(e);default:return e}}function _s(e){return e.replaceAll(/\s*/g,"").split(",")}var qs=["y","x"];function dn(e){e=e.replaceAll(" ",""),e=e.replaceAll(/[l=] /g,""),e=e.replaceAll(/,(\w+=)/g,":$1");let t=e.split(":"),r=js(t[0]);for(let n=1;n<t.length;n++){let{value:i,key:o}=gn(t[n]);r[Us(o)]=Bs(i,o)}return r}function js(e){let{value:t}=gn(e),r={delta:{}},n=t.split("/");for(let i=0;i<n.length;i++){let o=n[i].replaceAll(/[(|)]/g,"").split(",");r.delta[qs[i]]=Array.isArray(o)?o:[o]}return r}function gn(e){let t=e.toLowerCase();return{value:t.replace(/^.*=/,""),key:t.replace(/[=].*/,"")}}function Bs(e,t){switch(t){case"ja":case"j1":case"j2":return Ne(e);default:return e}}function Us(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 hn(e,t){let r=$s(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(",")?bn(e):r(e)}function $s(e){let t=e.toLowerCase();switch(t.match(/1d/)&&(t="1d"),t.match(/2d/)&&(t="2d"),t){case"id":return bn;case"1d":return fn;case"2d":return dn;case"assignment":case"signals":return yn;case"j":return yn;case"smiles":case"inchi":case"version":case"solvent":case"temperature":case"level":default:return r=>r}}function bn(e){let t=e.replace(/^.*=/,""),r=e.replace(/[=].*/,"").toLowerCase();return ct([{key:r,value:t}])}function yn(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,filePath:r.relativePath,root:s!==""?`${s}/`:""})}}return t}function xn(e){let{sdf:t,fileCollection:r}=e,{molecule:n}=e,i=mt(t);n??=Fn.fromMolfile(i.molecules[0].molfile),n.addImplicitHydrogens();let o=Fn.fromMolfileWithAtomMap(n.toMolfile()),s=zs(i);return pn(s,{moleculeAndMap:o,root:i.root,fileCollection:r})}function zs(e){let t=mt(e),r={name:t.filename},n=Js(t);for(let i of Object.keys(n)){r[i]||(r[i]={data:[]});let o=r[i],s=n[i].split(`
17
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=hn(c,i);o.data.push({comment:l,value:m})}}return r}function Js(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,filePath:r}}return e}import{generateID as An}from"@zakodium/nmrium-core";import{generateID as Dn}from"@zakodium/nmrium-core";import{xyIntegration as Ws}from"ml-spectra-processing";function Sn(e,t){let{x:r,re:n}=t.data;return e.map(i=>{let o=Ws({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:u=[],...f}=a;s.push({...f,kind:c||"signal",js:m,id:l||Dn(),diaIDs:u})}return{...i,id:i.id||Dn(),kind:s?.[0].kind||"signal",absolute:o,signals:s}})}function In(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=Xs({delta:o,js:l,frequency:n});if(l&&a&&l.length===a.length){l.sort((u,f)=>f.coupling-u.coupling);for(let u=0;u<l.length;u++)l[u].multiplicity=a[u]}r.push({id:An(),...m,integration:c,signals:[{id:An(),js:l,delta:o,diaIDs:s,multiplicity:a}]})}t.ranges.values=Sn(Q(r),t)}function Xs(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 Mn}from"@zakodium/nmrium-core";var Vs=["x","y"],Hs={x:0,y:0};function Nn(e,t,r={}){let n=[],{shift:i=Hs}=r,{originFrequency:o=[400,400]}=t.info,s={x:o[0],y:o[1]};for(let a of e){let c={x:{},y:{},id:Mn(),kind:"signal"},l={id:Mn(),kind:"signal",peaks:[]},m={x:10,y:10};for(let u of Vs){let{coupling:f=[],delta:g,diaIDs:y=[]}=a[u];for(let p of f)m[u]+=p.coupling;if(a.activeCoupling){let{activeCoupling:p=[]}=a;for(let h of p)m[u]+=h.coupling}m[u]/=s[u],c[u]={from:g-m[u],to:g+m[u]},l[u]={delta:g,diaIDs:y,originalDelta:g-i[u]}}n.push({...c,signals:[l]})}t.zones.values=n}function Pn(e){return Gs(e.data)}function Gs(e){return"rr"in e||!("x"in e)&&"re"in e}async function En(e,t,r={}){let n={spectra:[],molecules:[]},i=await Ys(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 Ys(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=xn({sdf:c,fileCollection:e}).then(m=>{let{spectra:u,molecules:f=[]}=m;return n.push(c.root+c.filename),o.molecules.push(...f),Ks(u,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 Ks(e,t,r){let n=[],i=[],o={spectra:[],molecules:[]};for(let s of e){let a=Zs(s.source,t,r).then(c=>{let{spectra:l,files:m}=c;n.push(...m);for(let u of l)Pn(u)?Nn(s.signals,u):In(s.signals,u);o.spectra.push(...l)});i.push(a)}return await Promise.allSettled(i),{...o,usedFiles:n}}async function Zs(e,t,r={}){let{file:n,jcampURL:i}=e,{converter:o}=r;if(i){let c=await Qs(i,t,o?.jcamp);if(c)return{...c,files:[]}}let s=[];for(let c of n||[])s.push(ea(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 Qs(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 ea(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});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 ta({id:"@zakodium/nmrium-core-plugins#NMReDATALoaderPlugin",version:1,shouldSerialize:!0,migrations:[],onReadProcess:{onFiles(t,r){return En(t,e,r)}}})}import{defineNMRiumPlugin as ia}from"@zakodium/nmrium-core";import{parse as ra}from"sdf-parser";function Tn(e,t={}){let{mixedEOL:r}=t,{molecules:n}=ra(e,{mixedEOL:r}),i=[];for(let[o,{molfile:s}]of n.entries()){let a=K(s).entries();for(let[c,l]of a)l.sourceSelector={sdfIndex:o,molfileIndex:c},i.push(l)}return i}async function On(e,t={}){let{logger:r,mixedEOL:n,sourceSelector:i}=t;if(i?.files&&!i.files.includes(e.relativePath))return{molecules:[],spectra:[]};let o=await e.text(),s=Tn(o,{mixedEOL:n,sourceSelector:i});for(let c of s)c.sourceSelector={...c.sourceSelector,files:[e.relativePath]};let a={molecules:na(s,i),spectra:[]};return r&&r[s.length>0?"info":"debug"](`Loaded ${a.molecules.length} molecules from the ${e.name} file`),a}function na(e,t){if(!t)return e;let{sdfIndex:r,molfileIndex:n}=t;return e.filter(i=>(typeof r=="number"?r===i.sourceSelector?.sdfIndex:!0)&&(typeof n=="number"?n===i.sourceSelector?.molfileIndex:!0))}function oa(e,t={}){let{logger:r,sourceSelector:n}=t;return r?.debug(`Reading sdf file: ${e.name}`),On(e,{logger:r,sourceSelector:n})}function pt(){return ia({id:"@zakodium/nmrium-core-plugins#SDFLoaderPlugin",version:1,shouldSerialize:!0,migrations:[],onReadProcess:{supportedExtensions:["sdf"],onFile:oa}})}import{defineNMRiumPlugin as aa}from"@zakodium/nmrium-core";import{Molecule as sa}from"openchemlib";function Cn(e,t){let r=t?.smilesIndex,n=[],i=e.split(/\r?\n/).filter(Boolean);for(let[o,s]of i.entries()){if(typeof r=="number"&&r!==o)continue;let c=sa.fromSmiles(s).toMolfile();n.push({molfile:c,sourceSelector:{smilesIndex:o}})}return n}async function Rn(e,t={}){let{logger:r,sourceSelector:n}=t;if(n?.files&&!n.files.includes(e.relativePath))return{molecules:[],spectra:[]};let i=await e.text(),o=Cn(i,n);for(let a of o)a.sourceSelector={...a.sourceSelector,files:[e.relativePath]};let s={molecules:o,spectra:[]};return r?.info(`Found ${o.length} molecules from the ${e.name} file`),s}function ft(){return aa({id:"@zakodium/nmrium-core-plugins#SMILESLoaderPlugin",version:1,shouldSerialize:!0,migrations:[],onReadProcess:{supportedExtensions:["smi","smiles"],onFile:Rn}})}import{defineNMRiumPlugin as ga}from"@zakodium/nmrium-core";import{formatSpectra as pa}from"@zakodium/nmrium-core";import{createFromToArray as la}from"ml-spectra-processing/utils";function wn(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
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,filePath:r}}return e}import{generateID as An}from"@zakodium/nmrium-core";import{generateID as Dn}from"@zakodium/nmrium-core";import{xyIntegration as Ws}from"ml-spectra-processing";function Sn(e,t){let{x:r,re:n}=t.data;return e.map(i=>{let o=Ws({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:u=[],...f}=a;s.push({...f,kind:c||"signal",js:m,id:l||Dn(),diaIDs:u})}return{...i,id:i.id||Dn(),absolute:o,signals:s}})}function In(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=Xs({delta:o,js:l,frequency:n});if(l&&a&&l.length===a.length){l.sort((u,f)=>f.coupling-u.coupling);for(let u=0;u<l.length;u++)l[u].multiplicity=a[u]}r.push({id:An(),...m,integration:c,signals:[{id:An(),js:l,delta:o,diaIDs:s,multiplicity:a}]})}t.ranges.values=Sn(Q(r),t)}function Xs(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 Mn}from"@zakodium/nmrium-core";var Vs=["x","y"],Hs={x:0,y:0};function Nn(e,t,r={}){let n=[],{shift:i=Hs}=r,{originFrequency:o=[400,400]}=t.info,s={x:o[0],y:o[1]};for(let a of e){let c={x:{},y:{},id:Mn(),kind:"signal"},l={id:Mn(),kind:"signal",peaks:[]},m={x:10,y:10};for(let u of Vs){let{coupling:f=[],delta:g,diaIDs:y=[]}=a[u];for(let p of f)m[u]+=p.coupling;if(a.activeCoupling){let{activeCoupling:p=[]}=a;for(let h of p)m[u]+=h.coupling}m[u]/=s[u],c[u]={from:g-m[u],to:g+m[u]},l[u]={delta:g,diaIDs:y,originalDelta:g-i[u]}}n.push({...c,signals:[l]})}t.zones.values=n}function Pn(e){return Gs(e.data)}function Gs(e){return"rr"in e||!("x"in e)&&"re"in e}async function En(e,t,r={}){let n={spectra:[],molecules:[]},i=await Ys(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 Ys(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=xn({sdf:c,fileCollection:e}).then(m=>{let{spectra:u,molecules:f=[]}=m;return n.push(c.root+c.filename),o.molecules.push(...f),Ks(u,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 Ks(e,t,r){let n=[],i=[],o={spectra:[],molecules:[]};for(let s of e){let a=Zs(s.source,t,r).then(c=>{let{spectra:l,files:m}=c;n.push(...m);for(let u of l)Pn(u)?Nn(s.signals,u):In(s.signals,u);o.spectra.push(...l)});i.push(a)}return await Promise.allSettled(i),{...o,usedFiles:n}}async function Zs(e,t,r={}){let{file:n,jcampURL:i}=e,{converter:o}=r;if(i){let c=await Qs(i,t,o?.jcamp);if(c)return{...c,files:[]}}let s=[];for(let c of n||[])s.push(ea(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 Qs(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 ea(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});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 ta({id:"@zakodium/nmrium-core-plugins#NMReDATALoaderPlugin",version:1,shouldSerialize:!0,migrations:[],onReadProcess:{onFiles(t,r){return En(t,e,r)}}})}import{defineNMRiumPlugin as ia}from"@zakodium/nmrium-core";import{parse as ra}from"sdf-parser";function Tn(e,t={}){let{mixedEOL:r}=t,{molecules:n}=ra(e,{mixedEOL:r}),i=[];for(let[o,{molfile:s}]of n.entries()){let a=K(s).entries();for(let[c,l]of a)l.sourceSelector={sdfIndex:o,molfileIndex:c},i.push(l)}return i}async function On(e,t={}){let{logger:r,mixedEOL:n,sourceSelector:i}=t;if(i?.files&&!i.files.includes(e.relativePath))return{molecules:[],spectra:[]};let o=await e.text(),s=Tn(o,{mixedEOL:n,sourceSelector:i});for(let c of s)c.sourceSelector={...c.sourceSelector,files:[e.relativePath]};let a={molecules:na(s,i),spectra:[]};return r&&r[s.length>0?"info":"debug"](`Loaded ${a.molecules.length} molecules from the ${e.name} file`),a}function na(e,t){if(!t)return e;let{sdfIndex:r,molfileIndex:n}=t;return e.filter(i=>(typeof r=="number"?r===i.sourceSelector?.sdfIndex:!0)&&(typeof n=="number"?n===i.sourceSelector?.molfileIndex:!0))}function oa(e,t={}){let{logger:r,sourceSelector:n}=t;return r?.debug(`Reading sdf file: ${e.name}`),On(e,{logger:r,sourceSelector:n})}function pt(){return ia({id:"@zakodium/nmrium-core-plugins#SDFLoaderPlugin",version:1,shouldSerialize:!0,migrations:[],onReadProcess:{supportedExtensions:["sdf"],onFile:oa}})}import{defineNMRiumPlugin as aa}from"@zakodium/nmrium-core";import{Molecule as sa}from"openchemlib";function Cn(e,t){let r=t?.smilesIndex,n=[],i=e.split(/\r?\n/).filter(Boolean);for(let[o,s]of i.entries()){if(typeof r=="number"&&r!==o)continue;let c=sa.fromSmiles(s).toMolfile();n.push({molfile:c,sourceSelector:{smilesIndex:o}})}return n}async function Rn(e,t={}){let{logger:r,sourceSelector:n}=t;if(n?.files&&!n.files.includes(e.relativePath))return{molecules:[],spectra:[]};let i=await e.text(),o=Cn(i,n);for(let a of o)a.sourceSelector={...a.sourceSelector,files:[e.relativePath]};let s={molecules:o,spectra:[]};return r?.info(`Found ${o.length} molecules from the ${e.name} file`),s}function ft(){return aa({id:"@zakodium/nmrium-core-plugins#SMILESLoaderPlugin",version:1,shouldSerialize:!0,migrations:[],onReadProcess:{supportedExtensions:["smi","smiles"],onFile:Rn}})}import{defineNMRiumPlugin as ga}from"@zakodium/nmrium-core";import{formatSpectra as pa}from"@zakodium/nmrium-core";import{createFromToArray as la}from"ml-spectra-processing/utils";function wn(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
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=ca(t,r)}};function ca(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 vn(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 Ln(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);wn(i);let o=new ve(i);if(o.nBlocks!==1)throw new Error("We currently do not support 2D varian spectra ");let s=vn(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=la({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 fa}from"is-any-array";import{xMultiply as da}from"ml-spectra-processing";import{normalizeNucleus as ma}from"nmr-processing";function kn(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:u,rp:f,sw:g,rfl:y,rfp:p}=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(u)),D(o,"phc0",f&&Number(f[0])),D(s,"rfl",y&&Number(q(y))),D(s,"rfp",p&&Number(q(p))),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}=ua(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(ma)),o.dimension=1,o.isFid=!r.status.isSpectrum,{info:o,meta:{...s,..._n(r),...i}}}function q(e){return e&&(Array.isArray(e)?e[0]:e)}function ua(e,t){let r={};for(let n of t){let i=e[n];i&&typeof i=="number"&&(r[n]=i)}return r}function _n(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]=_n(n):t[r]=n}return t}function qn(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 jn(e,t={}){let{logger:r,sourceSelector:n}=t,i=qn(e);r&&r.debug(`Found ${Object.keys(i).length} varian experiments`);let o=[],s={spectra:[],molecules:[]};e:for(let c of i){let{name:l,files:m}=c;if(n?.files){let f=m;if(f.length===0)continue;let g=new Set(n.files);for(let y of f)if(!g.has(y.relativePath))continue e}let u=Ln(m).then(f=>{let{info:g,meta:y}=kn(f),p=f.fid.data[0],h=fa(p.im),d={data:{...p,x:f.x},meta:y,info:{isComplex:h,name:l,...g},display:{name:l}};if(g.isFid&&h){let{im:b}=d.data;da(b,-1,{output:b})}d.sourceSelector={files:m.map(b=>b.relativePath)},s.spectra.push(d)});o.push(u)}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;r?.warn(`Varian data: ${m}, fails with: ${l.reason}`)}}return s.spectra.length>0&&r?.info(`Loaded ${s.spectra.length} spectra from Varian files`),pa(s)}function ya(e,t){let{logger:r}=t??{};return jn(e,{logger:r})}function yt(){return ga({id:"@zakodium/nmrium-core-plugins#VarianLoaderPlugin",version:1,shouldSerialize:!0,migrations:[],onReadProcess:{onFiles:ya}})}function ba(e,t=[]){return[ut(e),yt(),Ge(),Qe(),at(),pt(),ft(),st(),$e()].concat(t)}function Fa(e=[]){let t=new ha;return t.registerPlugins(ba(t,e)),t}import{getOneIfArray as Un}from"@zakodium/nmrium-core";import{from1DNMRVariables as xa}from"convert-to-jcamp";function Bn(e,t){return e.filters.find(r=>r.name===t)}function Da(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:u,nucleus:f,solvent:g,scaleFactor:y,frequencyOffset:p,decim:h,dspfvs:d,digitalFilter:b}=n,F=Un(m||u),{x:S,re:I,im:x}=o,A=new Float64Array(I),M=!r&&x?new Float64Array(x):void 0,T=Bn(e,"fft")?.enabled,j={owner:s,isFid:c,title:a,nucleus:f,solvent:g,scaleFactor:y,spectralWidth:l,frequencyOffset:p,originFrequency:u,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=Sa(i,$n),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"}),xa(oe,Le)}function ht(e,t,r){r!==void 0&&(e[t]=Un(r))}var $n=["title","decim","dspfvs","grpdly","bf1","sw","offset",".solvent","owner","firsty","page","vardim","symbol","symbols","varform","vartype","datatype","dataclass",".observefrequency",".observenucleus","ncproc"];function Sa(e,t=$n){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,Fa as default,Fa as init,Qe as jcampDXLoader,st as jeolLoader,at as molfileLoader,ut as nmreDATALoader,kr as processJCAMPDX,Tn as readSDF,Cn as readSMILES,ba as recommended,pt as sdfLoader,ft as smilesLoader,Da 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.5.3",
3
+ "version": "0.6.1",
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",
@@ -30,7 +30,7 @@
30
30
  "@types/node": "^24.9.1",
31
31
  "@zakodium/bruker-parser": "^0.0.0",
32
32
  "@zakodium/jeol-parser": "^0.0.0",
33
- "@zakodium/nmr-types": "^0.3.2",
33
+ "@zakodium/nmr-types": "^0.4.0",
34
34
  "@zakodium/nmredata": "^0.0.0",
35
35
  "@zakodium/varian-parser": "^0.0.0",
36
36
  "bruker-data-test": "^1.0.0",
@@ -47,18 +47,18 @@
47
47
  },
48
48
  "dependencies": {
49
49
  "@date-fns/utc": "^2.1.1",
50
- "@zakodium/nmrium-core": "^0.4.2",
50
+ "@zakodium/nmrium-core": "^0.4.4",
51
51
  "cheminfo-types": "^1.8.1",
52
52
  "convert-to-jcamp": "^6.0.0",
53
53
  "date-fns": "^4.1.0",
54
- "file-collection": "^5.4.0",
54
+ "file-collection": "^6.0.0",
55
55
  "gyromagnetic-ratio": "^2.0.0",
56
56
  "is-any-array": "^2.0.1",
57
57
  "jcampconverter": "^12.0.1",
58
58
  "linear-sum-assignment": "^1.0.9",
59
59
  "lodash.merge": "^4.6.2",
60
60
  "ml-spectra-processing": "^14.18.0",
61
- "nmr-processing": "^20.1.0",
61
+ "nmr-processing": "^21.0.0",
62
62
  "openchemlib": "^9.12.1",
63
63
  "openchemlib-utils": "^8.7.0",
64
64
  "sdf-parser": "^7.0.4"
@@ -66,5 +66,5 @@
66
66
  "volta": {
67
67
  "extends": "../../../package.json"
68
68
  },
69
- "gitHead": "855ca9bc2b57519dcbb59e869e0144da374642ce"
69
+ "gitHead": "1310603aac371c50b102bf75a893da385d2a4ee4"
70
70
  }