@zakodium/nmrium-core-plugins 0.1.7 → 0.1.8
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.
|
@@ -46,9 +46,9 @@ declare interface FilterTreeByDataTypeDataClass {
|
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
/**
|
|
49
|
-
* Init NMRiumCore with recommended plugins.
|
|
49
|
+
* Init NMRiumCore with recommended plugins and plugins passed as argument.
|
|
50
50
|
*/
|
|
51
|
-
declare function init(): NMRiumCore;
|
|
51
|
+
declare function init(plugins?: NMRiumPlugin[]): NMRiumCore;
|
|
52
52
|
export default init;
|
|
53
53
|
export { init }
|
|
54
54
|
|
|
@@ -15,4 +15,4 @@ var Yr=Object.defineProperty;var Nt=(e,t)=>{for(var n in t)Yr(e,n,{get:t[n],enum
|
|
|
15
15
|
`);for(let a of s){let l=a.replaceAll(/;.*/g,"").replaceAll("\r",""),c=a.match(";")?a.replaceAll(/.*;+(.*)/g,"$1"):"";if(l.length===0){o.headComment||(o.headComment=[]),o.headComment.push(c);continue}let u=ir(l,r);o.data.push({comment:c,value:u})}}return n}function ys(e){let t=ft(e),n=Number.parseFloat(t.molecules[0].NMREDATA_VERSION),i={};for(let r of t.labels)if(r.toLowerCase().match("nmredata")){if(!t.molecules[0]?.[r])continue;let o=r.replace(/NMREDATA_/,""),s=String(t.molecules[0][r]);s=n>1?s.replaceAll(/\n*/g,""):s,s=s.replaceAll(/\\\n*/g,`
|
|
16
16
|
`),i[o]=s}return i}function ft(e,t={}){if(typeof e=="string"){let{filename:n="nmredata.sdf",root:i=""}=t;return{...Ne(e,{mixedEOL:!0}),root:i,filename:n}}return e}import{generateID as mr}from"@zakodium/nmrium-core";import{generateID as cr}from"@zakodium/nmrium-core";import{xyIntegration as hs}from"ml-spectra-processing";function lr(e,t){let{x:n,re:i}=t.data;return e.map(r=>{let o=hs({x:n,y:i},{from:r.from,to:r.to}),s=[];for(let a of r.signals||[]){let{kind:l=null,id:c,js:u=[],diaIDs:f=[],...d}=a;s.push({...d,kind:l||"signal",js:u,id:c||cr(),diaIDs:f})}return{...r,id:r.id||cr(),kind:s?.[0].kind||"signal",absolute:o,signals:s}})}function ur(e,t){let n=[],{baseFrequency:i=500}=t.info;for(let r of e){let{delta:o,diaIDs:s=[],multiplicity:a="",integration:l=0}=r,c=r.jCoupling||[],u=bs({delta:o,js:c,frequency:i});if(c&&a&&c.length===a.length){c.sort((f,d)=>d.coupling-f.coupling);for(let f=0;f<c.length;f++)c[f].multiplicity=a[f]}n.push({id:mr(),...u,integration:l,signals:[{id:mr(),js:c,delta:o,diaIDs:s,multiplicity:a}]})}t.ranges.values=lr(H(n),t)}function bs(e){let{delta:t,js:n=[],frequency:i}=e,r=.5;for(let o of n)r+=o.coupling;return r/=i,{from:t-r,to:t+r}}import{generateID as pr}from"@zakodium/nmrium-core";var Fs=["x","y"],Ds={x:0,y:0};function fr(e,t,n={}){let i=[],{shift:r=Ds}=n,{originFrequency:o=[400,400]}=t.info,s={x:o[0],y:o[1]};for(let a of e){let l={x:{},y:{},id:pr(),kind:"signal"},c={id:pr(),kind:"signal",peaks:[]},u={x:10,y:10};for(let f of Fs){let{coupling:d=[],delta:g,diaIDs:h=[]}=a[f];for(let p of d)u[f]+=p.coupling;if(a.activeCoupling){let{activeCoupling:p=[]}=a;for(let b of p)u[f]+=b.coupling}u[f]/=s[f],l[f]={from:g-u[f],to:g+u[f]},c[f]={delta:g,diaIDs:h,originalDelta:g-r[f]}}i.push({...l,signals:[c]})}t.zones.values=i}function dr(e){return xs(e.data)}function xs(e){return"rr"in e||!("x"in e)&&"re"in e}async function gr(e,t,n={}){let i={spectra:[],molecules:[]},r=await Ss(e,t,n);if(r.spectra.length>0){let{spectra:o,molecules:s,usedFiles:a}=r;i.spectra.push(...o),i.molecules.push(...s);let l=e.files.length;for(let c=l-1;c>=0;c--){let u=e.files[c].relativePath;!u.match(/acqu.*/s)&&a.includes(u)&&e.files.splice(c,1)}}return i}async function Ss(e,t,n){let i=[],r=await pt(e),o={spectra:[],molecules:[]};if(r.length===0)return{...o,usedFiles:i};let s=[];for(let l of r){let c=ar({sdf:l,fileCollection:e}).then(u=>{let{spectra:f,molecules:d=[]}=u;return i.push(l.root+l.filename),o.molecules.push(...d),Ps(f,t,n)});s.push(c)}let a=await Promise.allSettled(s);for(let l of a)l.status==="fulfilled"?(o.spectra.push(...l.value.spectra),i.push(...l.value.usedFiles)):l.reason&&n?.logger?.error(l.reason);return{...o,usedFiles:i}}async function Ps(e,t,n){let i=[],r=[],o={spectra:[],molecules:[]};for(let s of e){let a=Ns(s.source,t,n).then(l=>{let{spectra:c,files:u}=l;i.push(...u);for(let f of c)dr(f)?fr(s.signals,f):ur(s.signals,f);o.spectra.push(...c)});r.push(a)}return await Promise.allSettled(r),{...o,usedFiles:i}}async function Ns(e,t,n={}){let{file:i,jcampURL:r}=e,{converter:o}=n;if(r){let l=await As(r,t,o?.jcamp);if(l)return{...l,files:[]}}let s=[];for(let l of i||[])s.push(Ms(l,n).then(c=>({...c,files:l.fileCollection.files.map(u=>u.relativePath)})));let a=await Promise.allSettled(s);for(let l of a){if(l.status==="fulfilled")return l.value;l.reason&&n?.logger?.error(l.reason)}return{spectra:[],molecules:[],files:[]}}async function As(e,t,n={}){let i={entries:[{relativePath:e}]},r={name:X(e||""),xy:!0,noContours:!0,...n},{data:o}=await t.readFromWebSource(i,r);return o}async function Ms(e,t={}){let{converter:n,sourceSelector:i}=t;switch(e.type){case"jcamp":return Fe(e.fileCollection.files[0],{name:e?.fileCollection.files[0].name||"",converter:n?.jcamp,selector:i?.jcamp,logger:t.logger,keepSource:t.keepSource});case"brukerFiles":return ye(e.fileCollection,{converter:n?.bruker,selector:i});default:throw new Error("There is not a supported source")}}var Me=class{id="@zakodium/nmrium-core-plugins#NMReDATALoaderPlugin";version=1;migrations=[];onReadProcess;#e;constructor(t){this.#e=t,this.onReadProcess={onFiles:this.onReadProcessFiles}}onReadProcessFiles=(t,n)=>gr(t,this.#e,n)};function dt(e){return new Me(e)}import{parse as Is}from"sdf-parser";function yr(e,t={}){let{mixedEOL:n}=t,{molecules:i}=Is(e,{mixedEOL:n}),r=[];for(let{molfile:o}of i){let s=V(o);r.push(...s)}return r}async function hr(e,t={}){let{logger:n,mixedEOL:i}=t,r=await e.text(),o=yr(r,{mixedEOL:i}),s={molecules:o,spectra:[]};return n&&n[o.length>0?"info":"debug"](`Loaded ${s.molecules.length} molecules from the ${e.name} file`),s}var Ie=class{id="@zakodium/nmrium-core-plugins#SDFLoaderPlugin";version=1;migrations=[];onReadProcess;constructor(){this.onReadProcess={supportedExtensions:["sdf"],onFile:this.onReadProcessFile.bind(this)}}onReadProcessFile(t,n={}){let{logger:i}=n;return i?.debug(`Reading sdf file: ${t.name}`),hr(t,{logger:i})}};function gt(){return new Ie}import{Molecule as Rs}from"openchemlib";function br(e){let t=[],n=e.split(/\r?\n/).filter(Boolean);for(let i of n){let o=Rs.fromSmiles(i).toMolfile();t.push({molfile:o})}return t}async function Fr(e,t={}){let n=await e.text(),i=br(n),r={molecules:i,spectra:[]};return t.logger?.info(`Found ${i.length} molecules from the ${e.name} file`),r}var Re=class{id="@zakodium/nmrium-core-plugins#SMILESLoaderPlugin";version=1;migrations=[];onReadProcess;constructor(){this.onReadProcess={supportedExtensions:["smi","smiles"],onFile:this.onReadProcessFile.bind(this)}}onReadProcessFile(t,n={}){let{logger:i}=n;return Fr(t,{logger:i})}};function yt(){return new Re}import{formatSpectra as ws}from"@zakodium/nmrium-core";import{createFromToArray as Ts}from"ml-spectra-processing/utils";function Dr(e){e.setLittleEndian();let t=e.offset,n=32*3;e.offset=n/8;let i=e.readInt32(),r=[2,4],o=[2**25,2**26];if(!r.includes(i))if(o.includes(i))e.setBigEndian();else throw new Error(`Unexpected value of eBytes (${i}). Expect one of
|
|
17
17
|
${r.concat(o).join(",")}`);return e.offset=t,e.isBigEndian()?"BE":"LE"}var Ee=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}},Te=class extends Ee{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}},Oe=class extends Ee{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}},Ce=class{lines;length;index;eol;constructor(t,n={}){let{eol:i=`
|
|
18
|
-
`,index:r=0}=n;this.eol=i,this.index=r,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 n=this.lines.slice(this.index,this.index+t);return this.index+=t,n}},we=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}}},ve=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 ke=class{scale;status;index;mode;ctCount;lpVal;rpVal;lvl;tlt;data;constructor(t,n,i){i&&(t.offset=i),this.scale=t.readInt16(),this.status=new Te(t.readInt16()),this.index=t.readInt16(),this.mode=new ve(t.readInt16()),this.ctCount=t.readInt32(),this.lpVal=t.readFloat32(),this.rpVal=t.readFloat32(),this.lvl=t.readFloat32(),this.tlt=t.readFloat32(),this.data=Es(t,n)}};function Es(e,t){let{np:n,nTraces:i,status:{isFloat32:r,isInt32:o}}=t;return r?ht(e,i,n,"readFloat32"):o?ht(e,i,n,"readInt32"):ht(e,i,n,"readInt16")}function ht(e,t,n,i){let r=[],o;i==="readFloat32"?o={re:new Float32Array(n/2),im:new Float32Array(n/2)}:i==="readInt32"?o={re:new Int32Array(n/2),im:new Int32Array(n/2)}:o={re:new Int16Array(n/2),im:new Int16Array(n/2)};for(let s=0;s<t;s++){for(let a=0;a<n;a+=2)o.re[a>>>1]=e[i](),o.im[a>>>1]=e[i]();r[s]=o}return r}var Le=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 we(t.readInt16()),this.status=new Oe(t.readInt16()),this.nBlockHeaders=t.readInt32()}};var bt=class{name;subType;basicType;maxValue;minValue;stepSize;gGroup;dGroup;protection;active;intptr;constructor(t){let n=t.split(" ");this.name=n[0],this.subType=Number.parseInt(n[1],10),this.basicType=Number.parseInt(n[2],10),this.maxValue=Number.parseFloat(n[3]),this.minValue=Number.parseFloat(n[4]),this.stepSize=Number.parseFloat(n[5]),this.gGroup=Number.parseInt(n[6],10),this.dGroup=Number.parseInt(n[7],10),this.protection=Number.parseInt(n[8],10),this.active=Number.parseInt(n[9],10),this.intptr=Number.parseInt(n[10],10)}};function xr(e){let t=[],n=new Ce(e.readChars(e.length));for(;n.index<n.length-1;){let i=[],r=[],o=new bt(n.readLine()),s=n.readLine();if(o.basicType!==0){if(o.basicType===1)i=s.split(" ").slice(1).map(u=>Number.parseFloat(u));else if(o.basicType===2){i=s.split('"').slice(1,2);let c=Number.parseInt(s.split(" ")[0],10);for(;c>1;)i.push(n.readLine().split('"')[1]),c--}}let a=n.readLine(),l=Number.parseInt(a.split(" ")[0],10);l!==0&&(o.basicType===1?r=a.split(" ").slice(1):o.basicType===2&&(r=a.split('"').filter((c,u)=>u%2===1))),t.push({...o,values:i,enumerable:l,enumerables:r})}return t}async function Sr(e){let t={};function n(l,c){return l.then(u=>{t[c]=u})}let i=[];for(let l of e)switch(l.name.toLowerCase()){case"fid":{i.push(n(l.arrayBuffer(),"fidB"));break}case"procpar":{i.push(n(l.arrayBuffer(),"procparB"));break}default:break}if(await Promise.all(i),!t.fidB||!t.procparB)throw new RangeError("fid and procpar must exist.");let r=new O(t.fidB);Dr(r);let o=new Le(r);if(o.nBlocks!==1)throw new Error("We currently do not support 2D varian spectra ");let s=xr(new O(t.procparB)),a;for(let l of s)if(l.name==="at"){a=l.values[0];break}if(typeof a!="number")throw new Error("acquisition time parameter must exist and be a number.");{let l=Ts({from:0,to:a,length:o.np/2,distribution:"uniform"}),c=new ke(r,o);return{meta:o,fid:c,procpar:s,x:l}}}import{isAnyArray as vs}from"is-any-array";import{xMultiply as ks}from"ml-spectra-processing";import{normalizeNucleus as Os}from"nmr-processing";function Pr(e,t){let{meta:n,procpar:i}=e,r={};for(let y of i)r[y.name]=y.values;let o={},s={},{np:a,solvent:l,sfrq:c,reffrq:u,temp:f,rp:d,sw:g,rfl:h,rfp:p}=r;S(o,"numberOfPoints",a&&Number(L(a))/2),S(o,"solvent",L(l)),S(o,"originFrequency",L(c)),S(o,"baseFrequency",L(u)),(Number.isNaN(o.originFrequency)||o.originFrequency===0)&&(o.originFrequency=400,t?.warn("The frequency could not be determined and was set to 400MHz")),S(o,"temperature",L(f)),S(o,"phc0",d&&Number(d[0])),S(s,"rfl",h&&Number(L(h))),S(s,"rfp",p&&Number(L(p))),S(s,"sw",g&&Number(L(g)));for(let y in s){let F=s[y];Array.isArray(F)&&F.length===1&&(s[y]=F[0])}if(!("baseFrequency"in o)&&"originFrequency"in o){let y=Number.parseFloat(o.originFrequency);if(["sw","rfl","rfp"].every(F=>F in s)){let{sw:F=1,rfl:x=1,rfp:N=1}=Cs(s,["sw","rfl","rfp"]);S(o,"baseFrequency",y-(F/2-x+N)/1e6)}else S(o,"baseFrequency",y)}let{baseFrequency:b,originFrequency:m}=o;S(o,"frequencyOffset",(m-b)*1e6),S(o,"spectralWidth",g&&Number(g[0])/o.baseFrequency);for(let y in o)o[y].length===1&&(o[y]=o[y][0]);return r.tn&&(o.nucleus=r.tn.map(Os)),o.dimension=1,o.isFid=!n.status.isSpectrum,{info:o,meta:{...s,...Nr(n),...r}}}function L(e){return e&&(Array.isArray(e)?e[0]:e)}function Cs(e,t){let n={};for(let i of t){let r=e[i];r&&typeof r=="number"&&(n[i]=r)}return n}function Nr(e){let t={};for(let n of Object.keys(e)){let i=e[n];typeof i=="object"&&i!==null&&i.constructor&&i.constructor!==Object?t[n]=Nr(i):t[n]=i}return t}function Ar(e){let t={},n=new Set(e.files.map(i=>i.relativePath));for(let i of e){let r=i.name.toLowerCase();if(r.match(/^(?:fid|procpar|text|log)$/)){if(r.match(/^(?:fid|text|log)$/)){let a=i.relativePath.replace(/(?:fid|text|log)$/,"procpar");if(!n.has(a))continue}let o=i.relativePath.split("/"),s=o.slice(0,-1).join("/");t[s]||(t[s]={name:o.at(-2),files:[]}),t[s].files.push(i)}}return Object.values(t)}async function Mr(e,t={}){let{keepSource:n,logger:i}=t,r=Ar(e);i&&i.debug(`Found ${Object.keys(r).length} varian experiments`);let o=[],s={spectra:[],molecules:[]};for(let l of r){let{name:c,files:u}=l,f=Sr(u).then(d=>{let{info:g,meta:h}=Pr(d),p=d.fid.data[0],b=vs(p.im),m={data:{...p,x:d.x},meta:h,info:{isComplex:b,name:c,...g},display:{name:c}};if(g.isFid&&b){let{im:y}=m.data;ks(y,-1,{output:y})}u&&n&&(m.sourceSelector={files:u.map(y=>y.relativePath)}),s.spectra.push(m)});o.push(f)}let a=await Promise.allSettled(o);for(let l=0;l<a.length;l++){let c=a[l];if(c.status==="rejected"&&c.reason){let u=r[l].name;i?.warn(`Varian data: ${u}, fails with: ${c.reason}`)}}return s.spectra.length>0&&i?.info(`Loaded ${s.spectra.length} spectra from Varian files`),ws(s)}var qe=class{id="@zakodium/nmrium-core-plugins#VarianLoaderPlugin";version=1;migrations=[];onReadProcess;constructor(){this.onReadProcess={onFiles:this.onReadProcessFiles}}onReadProcessFiles=(t,n)=>{let{keepSource:i,logger:r}=n??{};return Mr(t,{keepSource:i,logger:r})}};function Ft(){return new qe}function qs(e,t=[]){return[dt(e),Ft(),Ze(),nt(),mt(),gt(),yt(),lt(),Je()].concat(t)}function _s(){let
|
|
18
|
+
`,index:r=0}=n;this.eol=i,this.index=r,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 n=this.lines.slice(this.index,this.index+t);return this.index+=t,n}},we=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}}},ve=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 ke=class{scale;status;index;mode;ctCount;lpVal;rpVal;lvl;tlt;data;constructor(t,n,i){i&&(t.offset=i),this.scale=t.readInt16(),this.status=new Te(t.readInt16()),this.index=t.readInt16(),this.mode=new ve(t.readInt16()),this.ctCount=t.readInt32(),this.lpVal=t.readFloat32(),this.rpVal=t.readFloat32(),this.lvl=t.readFloat32(),this.tlt=t.readFloat32(),this.data=Es(t,n)}};function Es(e,t){let{np:n,nTraces:i,status:{isFloat32:r,isInt32:o}}=t;return r?ht(e,i,n,"readFloat32"):o?ht(e,i,n,"readInt32"):ht(e,i,n,"readInt16")}function ht(e,t,n,i){let r=[],o;i==="readFloat32"?o={re:new Float32Array(n/2),im:new Float32Array(n/2)}:i==="readInt32"?o={re:new Int32Array(n/2),im:new Int32Array(n/2)}:o={re:new Int16Array(n/2),im:new Int16Array(n/2)};for(let s=0;s<t;s++){for(let a=0;a<n;a+=2)o.re[a>>>1]=e[i](),o.im[a>>>1]=e[i]();r[s]=o}return r}var Le=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 we(t.readInt16()),this.status=new Oe(t.readInt16()),this.nBlockHeaders=t.readInt32()}};var bt=class{name;subType;basicType;maxValue;minValue;stepSize;gGroup;dGroup;protection;active;intptr;constructor(t){let n=t.split(" ");this.name=n[0],this.subType=Number.parseInt(n[1],10),this.basicType=Number.parseInt(n[2],10),this.maxValue=Number.parseFloat(n[3]),this.minValue=Number.parseFloat(n[4]),this.stepSize=Number.parseFloat(n[5]),this.gGroup=Number.parseInt(n[6],10),this.dGroup=Number.parseInt(n[7],10),this.protection=Number.parseInt(n[8],10),this.active=Number.parseInt(n[9],10),this.intptr=Number.parseInt(n[10],10)}};function xr(e){let t=[],n=new Ce(e.readChars(e.length));for(;n.index<n.length-1;){let i=[],r=[],o=new bt(n.readLine()),s=n.readLine();if(o.basicType!==0){if(o.basicType===1)i=s.split(" ").slice(1).map(u=>Number.parseFloat(u));else if(o.basicType===2){i=s.split('"').slice(1,2);let c=Number.parseInt(s.split(" ")[0],10);for(;c>1;)i.push(n.readLine().split('"')[1]),c--}}let a=n.readLine(),l=Number.parseInt(a.split(" ")[0],10);l!==0&&(o.basicType===1?r=a.split(" ").slice(1):o.basicType===2&&(r=a.split('"').filter((c,u)=>u%2===1))),t.push({...o,values:i,enumerable:l,enumerables:r})}return t}async function Sr(e){let t={};function n(l,c){return l.then(u=>{t[c]=u})}let i=[];for(let l of e)switch(l.name.toLowerCase()){case"fid":{i.push(n(l.arrayBuffer(),"fidB"));break}case"procpar":{i.push(n(l.arrayBuffer(),"procparB"));break}default:break}if(await Promise.all(i),!t.fidB||!t.procparB)throw new RangeError("fid and procpar must exist.");let r=new O(t.fidB);Dr(r);let o=new Le(r);if(o.nBlocks!==1)throw new Error("We currently do not support 2D varian spectra ");let s=xr(new O(t.procparB)),a;for(let l of s)if(l.name==="at"){a=l.values[0];break}if(typeof a!="number")throw new Error("acquisition time parameter must exist and be a number.");{let l=Ts({from:0,to:a,length:o.np/2,distribution:"uniform"}),c=new ke(r,o);return{meta:o,fid:c,procpar:s,x:l}}}import{isAnyArray as vs}from"is-any-array";import{xMultiply as ks}from"ml-spectra-processing";import{normalizeNucleus as Os}from"nmr-processing";function Pr(e,t){let{meta:n,procpar:i}=e,r={};for(let y of i)r[y.name]=y.values;let o={},s={},{np:a,solvent:l,sfrq:c,reffrq:u,temp:f,rp:d,sw:g,rfl:h,rfp:p}=r;S(o,"numberOfPoints",a&&Number(L(a))/2),S(o,"solvent",L(l)),S(o,"originFrequency",L(c)),S(o,"baseFrequency",L(u)),(Number.isNaN(o.originFrequency)||o.originFrequency===0)&&(o.originFrequency=400,t?.warn("The frequency could not be determined and was set to 400MHz")),S(o,"temperature",L(f)),S(o,"phc0",d&&Number(d[0])),S(s,"rfl",h&&Number(L(h))),S(s,"rfp",p&&Number(L(p))),S(s,"sw",g&&Number(L(g)));for(let y in s){let F=s[y];Array.isArray(F)&&F.length===1&&(s[y]=F[0])}if(!("baseFrequency"in o)&&"originFrequency"in o){let y=Number.parseFloat(o.originFrequency);if(["sw","rfl","rfp"].every(F=>F in s)){let{sw:F=1,rfl:x=1,rfp:N=1}=Cs(s,["sw","rfl","rfp"]);S(o,"baseFrequency",y-(F/2-x+N)/1e6)}else S(o,"baseFrequency",y)}let{baseFrequency:b,originFrequency:m}=o;S(o,"frequencyOffset",(m-b)*1e6),S(o,"spectralWidth",g&&Number(g[0])/o.baseFrequency);for(let y in o)o[y].length===1&&(o[y]=o[y][0]);return r.tn&&(o.nucleus=r.tn.map(Os)),o.dimension=1,o.isFid=!n.status.isSpectrum,{info:o,meta:{...s,...Nr(n),...r}}}function L(e){return e&&(Array.isArray(e)?e[0]:e)}function Cs(e,t){let n={};for(let i of t){let r=e[i];r&&typeof r=="number"&&(n[i]=r)}return n}function Nr(e){let t={};for(let n of Object.keys(e)){let i=e[n];typeof i=="object"&&i!==null&&i.constructor&&i.constructor!==Object?t[n]=Nr(i):t[n]=i}return t}function Ar(e){let t={},n=new Set(e.files.map(i=>i.relativePath));for(let i of e){let r=i.name.toLowerCase();if(r.match(/^(?:fid|procpar|text|log)$/)){if(r.match(/^(?:fid|text|log)$/)){let a=i.relativePath.replace(/(?:fid|text|log)$/,"procpar");if(!n.has(a))continue}let o=i.relativePath.split("/"),s=o.slice(0,-1).join("/");t[s]||(t[s]={name:o.at(-2),files:[]}),t[s].files.push(i)}}return Object.values(t)}async function Mr(e,t={}){let{keepSource:n,logger:i}=t,r=Ar(e);i&&i.debug(`Found ${Object.keys(r).length} varian experiments`);let o=[],s={spectra:[],molecules:[]};for(let l of r){let{name:c,files:u}=l,f=Sr(u).then(d=>{let{info:g,meta:h}=Pr(d),p=d.fid.data[0],b=vs(p.im),m={data:{...p,x:d.x},meta:h,info:{isComplex:b,name:c,...g},display:{name:c}};if(g.isFid&&b){let{im:y}=m.data;ks(y,-1,{output:y})}u&&n&&(m.sourceSelector={files:u.map(y=>y.relativePath)}),s.spectra.push(m)});o.push(f)}let a=await Promise.allSettled(o);for(let l=0;l<a.length;l++){let c=a[l];if(c.status==="rejected"&&c.reason){let u=r[l].name;i?.warn(`Varian data: ${u}, fails with: ${c.reason}`)}}return s.spectra.length>0&&i?.info(`Loaded ${s.spectra.length} spectra from Varian files`),ws(s)}var qe=class{id="@zakodium/nmrium-core-plugins#VarianLoaderPlugin";version=1;migrations=[];onReadProcess;constructor(){this.onReadProcess={onFiles:this.onReadProcessFiles}}onReadProcessFiles=(t,n)=>{let{keepSource:i,logger:r}=n??{};return Mr(t,{keepSource:i,logger:r})}};function Ft(){return new qe}function qs(e,t=[]){return[dt(e),Ft(),Ze(),nt(),mt(),gt(),yt(),lt(),Je()].concat(t)}function _s(e=[]){let t=new Ls;return t.registerPlugins(qs(t,e)),t}import{getOneIfArray as Rr}from"@zakodium/nmrium-core";import{from1DNMRVariables as js}from"convert-to-jcamp";function Ir(e,t){return e.filters.find(n=>n.name===t)}function Bs(e,t={}){let{info:n,meta:i,data:r}=e,{onlyReal:o=!1}=t,{isFid:s,spectralWidth:a}=n,l=Rr(n.baseFrequency||n.originFrequency),{x:c,re:u,im:f}=r,d=new Float64Array(u),g=!o&&f?new Float64Array(f):void 0,h={};Q(h,"SW",a),Q(h,"BF1",l);let p=Ir(e,"fft")?.enabled,b={originFrequency:n.originFrequency,dataType:!n.isFid||p?"NMR SPECTRUM":"NMR FID",dataClass:!o&&f?"NTUPLES":"XYDATA"};if(s){let F=e.filters.find(x=>x.name==="digitalFilter");if(F&&!p){let{value:{digitalFilterValue:x},enabled:N}=F;if(N){let D=Math.floor(x);d.set(u.slice(u.length-D)),d.set(u.slice(0,u.length-D),D),f&&g&&(g.set(f.slice(f.length-D)),g.set(f.slice(0,f.length-D),D))}}Q(b,"decim",n.decim),Q(b,"dspfvs",n.dspfvs),Q(b,"digitalFilter",n.digitalFilter)}let m={xyEncoding:"DIFDUP",info:{...n,...b},meta:{...i,...h}},y={x:{data:c,label:n.isFid?"TIME":"FREQUENCY",units:n.isFid?"second":"HZ",symbol:"X"},r:{data:d,label:`${n.isFid?"FID":"SPECTRUM"}/REAL`,units:"ARBITRARY UNITS",symbol:"R"}};return g&&(y.i={data:g,label:`${n.isFid?"FID":"SPECTRUM"}/IMAG`,units:"ARBITRARY UNITS",symbol:"I"}),js(y,m)}function Q(e,t,n){n!==void 0&&(e[t]=Rr(n))}export{ne as AutoPostProcessingPlugin,he as BrukerLoaderPlugin,De as JCAMPDXLoaderPlugin,Se as JEOLLoaderPlugin,Pe as MolfileLoaderPlugin,Me as NMReDATALoaderPlugin,Ie as SDFLoaderPlugin,Re as SMILESLoaderPlugin,qe as VarianLoaderPlugin,Je as autoPostProcessing,Ze as brukerLoader,_s as default,_s as init,nt as jcampDXLoader,lt as jeolLoader,mt as molfileLoader,dt as nmreDATALoader,Nn as processJCAMPDX,yr as readSDF,br as readSMILES,qs as recommended,gt as sdfLoader,yt as smilesLoader,Bs as spectrum1DToJCAMPDX,Ft as varianLoader};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zakodium/nmrium-core-plugins",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.8",
|
|
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",
|
|
@@ -45,10 +45,10 @@
|
|
|
45
45
|
"vitest": "^3.2.4"
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@zakodium/nmrium-core": "^0.1.
|
|
48
|
+
"@zakodium/nmrium-core": "^0.1.5",
|
|
49
49
|
"cheminfo-types": "^1.8.1",
|
|
50
50
|
"convert-to-jcamp": "^5.4.11",
|
|
51
|
-
"file-collection": "^5.
|
|
51
|
+
"file-collection": "^5.1.0",
|
|
52
52
|
"gyromagnetic-ratio": "^2.0.0",
|
|
53
53
|
"is-any-array": "^2.0.1",
|
|
54
54
|
"jcampconverter": "^11.0.4",
|