jcampconverter 12.3.0 → 12.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/jcampconverter.d.ts
CHANGED
package/dist/jcampconverter.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import{ensureString as me}from"ensure-string";var $=/\s*\$\$.*/;function E(e,m=/\r\n/.exec(e)?`\r
|
|
2
2
|
`:`
|
|
3
|
-
`){return e.split(m).map(o=>o.replace($,"")).filter(Boolean).join(m).trim()}function Le(e,m={}){e=me(e);let{flatten:t=!1}=m,o=e.split(/\r?\n/),f=[],i=[],n=[],l={title:"",jcamp:"",children:[]},s=0,
|
|
3
|
+
`){return e.split(m).map(o=>o.replace($,"")).filter(Boolean).join(m).trim()}function Le(e,m={}){e=me(e);let{flatten:t=!1}=m,o=e.split(/\r?\n/),f=[],i=[],n=[],l={title:"",jcamp:"",children:[]},s=0,c=e.includes("## ");for(let u=0;u<o.length;u++){let b=o[u],p=c?b.replaceAll(" ",""):b;if(p.startsWith("##NTUPLES")&&s++,p.startsWith("##TITLE")){let r=[p.slice(8).trim()];for(let a=u+1;a<o.length&&!o[a].startsWith("##");a++)r.push(o[a].trim());l={title:r.join(`
|
|
4
4
|
`),jcamp:`${b}
|
|
5
5
|
`,children:[]},i.push(l),f.push(l)}else if(p.startsWith("##END")&&s===0&&l){l.jcamp+=`${b}
|
|
6
6
|
`;let r=i.pop();if(!r)throw new Error("Not finished");l=i.at(-1),l!==void 0?l.children?.push(r):n.push(r)}else if(l?.jcamp){l.jcamp+=`${b}
|
|
7
|
-
`;let r=p.match(/^##(.*?)=(.+)/);if(r){let a=r[1].replaceAll(/[ _-]/g,"").toUpperCase();a==="DATATYPE"?l.dataType=r[2].trim():a==="DATACLASS"?l.dataClass=r[2].trim():a==="JCAMPDX"?l.jcampDX=E(r[2].trim()):a==="JCAMPCS"&&(l.jcampCS=E(r[2].trim()))}}p.startsWith("##END")&&s>0&&s--}if(t){for(let c of f)c.children=void 0;return f}else return n}import{parseString as be}from"dynamic-typing";import{ensureString as ge}from"ensure-string";var te=["TIC",".RIC","SCANNUMBER"];function ne(e){let m=e.spectra,t=m.length,o={times:new Array(t),series:{ms:{dimension:2,data:new Array(t)}}},f=[];for(let i of te){let n=k(i);m[0][n]&&(f.push(n),o.series[n]={dimension:1,data:new Array(t)})}for(let i=0;i<t;i++){let n=m[i];o.times[i]=n.pageValue;for(let l of f)o.series[l].data[i]=Number(n[l]);n.data&&(o.series.ms.data[i]=[n.data.x,n.data.y])}e.chromatogram=o}function re(e){return te.includes(e)}function k(e){return e.toLowerCase().replaceAll(/[^a-z0-9]/g,"")}function O(e){return e.map(Number)}function V(e,m,t){let{logger:o}=t;o&&(e.xFactor||o.info("The xFactor is not defined, it will be set to 1"),e.yFactor||o.info("The yFactor is not defined, it will be set to 1"));let f=e.yFactor??1,i=e.xFactor??1,n=e.deltaX??1,l=Math.abs(n*.1),s=.01;e.isXYdata=!0;let u={x:[],y:[]};e.data=u;let c=e.firstX||0,b=e.firstY||0,p=!1,r,a=0;for(;a<m.length;a++)if(r=m.codePointAt(a),r===13||r===10)p=!0;else if(p)break;let d=0,g=!0,A=!1,x=!1,I=0,S=!1,C=!1,h=0,X=0,L=!1,N=!1,Y=!1,F=0;for(;a<=m.length;a++)if(a===m.length?r=13:r=m.codePointAt(a),C)(r===13||r===10)&&(g=!0,C=!1,d++);else if(r<=57&&r>=48)N=!0,F>0?h+=(r-48)/10**F++:(h*=10,h+=r-48);else if(r===44||r===46)N=!0,F++;else{if(N){if(L&&(h=h*-1,L=!1),g)h*=i,o&&(x?Math.abs(c-n-h)>l&&(Math.abs(c-h)<l?o.trace(`Data line ${d}: After a DIFFERENCE the next line should repeat the last value and this does not seem to be the case: Current value: ${h} - Expected: ${c}.`):Math.abs(c-n-h)>10*l?o.trace(`Data line ${d}: The difference between the first value ${h} and the expected first x value ${c} based on increment after a DIFFERENCE is too high`):o.trace(`Data line ${d}: The difference between the first value ${h} and the expected first x value ${c} based on increment after a DIFFERENCE is too high`)):Math.abs(c-h)>l&&o.trace(`Data line ${d}: The difference between the first value ${h} and the first x value ${c} is too high`)),g=!1,x&&(Y=!0);else if(Y)Y=!1,o&&Math.abs(b-h)>s&&o.trace(`Data line ${d}: After a duplicate the next line should repeat the same value ${h} !== ${b}`),b=h;else{A?(I=L?0-h:h,x=!0,A=!1):S||(X=L?0-h:h);let y=S?h-1:1;for(let M=0;M<y;M++)x?b+=I:b=X,u.x.push(c),u.y.push(b*f),c+=n}L=!1,h=0,F=0,N=!1,S=!1}if(r<74&&r>63)N=!0,x=!1,h=r-64;else if(r>96&&r<106)N=!0,x=!1,h=r-96,L=!0;else if(r===115)N=!0,S=!0,h=9;else if(r>82&&r<91)N=!0,S=!0,h=r-82;else if(r>73&&r<83)N=!0,A=!0,h=r-73;else if(r>105&&r<115)N=!0,A=!0,h=r-105,L=!0;else if(r===36&&m.codePointAt(a+1)===36)N=!0,C=!0;else if(r===37)N=!0,A=!0,h=0,L=!1;else if(r===45){let y=m.codePointAt(a+1);(y!==void 0&&y>=48&&y<=57||y===44||y===46)&&(N=!0,g||(x=!1),L=!0)}else(r===13||r===10)&&(g=!0,C=!1,d++)}o&&x&&o.warn("The last value is a difference, it should be repeated on the next line")}var oe=/[,\t ]+/;function w(e,m,t){if(e.isPeaktable=!0,!e.variables||Object.keys(e.variables).length===2?ce(e,m,t):ue(e,m,t),e.variables)for(let o in e.variables)e.variables[o].data=e.data?.[o]}function ce(e,m,t){let{logger:o}=t,f={x:[],y:[]};e.data=f;let i=m.split(/,? *,?[;\r\n]+ */);for(let n=1;n<i.length;n++){let l=i[n].trim().replace($,"").split(oe);if(l.length%2===0)for(let s=0;s<l.length;s=s+2)e.xFactor!==void 0&&e.yFactor!==void 0&&(f.x.push(Number(l[s])*e.xFactor),f.y.push(Number(l[s+1])*e.yFactor));else o?.warn(`Format error: ${l.toString()}`)}}function ue(e,m,t){let{logger:o}=t,f={},i=Object.keys(e.variables),n=i.length;for(let s of i)f[s]=[];e.data=f;let l=m.split(/,? *,?[;\r\n]+ */);for(let s=1;s<l.length;s++){let u=l[s].trim().replace($,"").split(oe);if(u.length%n===0)for(let c=0;c<u.length;c++)f[i[c%n]].push(Number(u[c]));else o?.warn(`Wrong number of columns: ${u.toString()}`)}}function B(e,m){e.isXYAdata=!0;let t={};e.data=t;let o=m.split(/\r?\n/),f=o[0].replace(/^.*?([A-Z]+).*$/,"$1").split("").map(i=>i.toLowerCase());for(let i=1;i<o.length;i++){let n=o[i].replace(/^\((.*)\)$/,"$1").split(/ *, */);for(let l=0;l<f.length;l++){let s=n[l];switch(f[l]){case"x":case"y":case"w":s=Number.parseFloat(s);break;case"a":s=s.replace(/^<(.*)>$/,"$1");break;case"m":break;default:continue}t[f[l]]||(t[f[l]]=[]),t[f[l]].push(s)}}}import{parseString as le}from"dynamic-typing";import{getGyromagneticRatio as ie}from"gyromagnetic-ratio";import ae from"ml-array-median";function se(e){return Array.isArray(e)?e[0]:e}function Z(e){let{spectra:m}=e,t=m[0].data.y[0],o=t,f=m.length,i=m[0].data.x.length||0,n=new Array(f);for(let r=0;r<f;r++){n[r]=m[r].data.y;for(let a=0;a<i;a++){let d=n[r][a];d<t&&(t=d),d>o&&(o=d)}}let l=m[0].data.x[0],s=m[0].data.x.at(-1),{firstY:u,lastY:c}=pe(e);if(l>s)for(let r of n)r.reverse();u>c&&n.reverse();let b=[];for(let r of n){let a=Float64Array.from(r);for(let d=0;d<a.length;d++)a[d]<0&&(a[d]=-a[d]);b.push(ae(a))}let p=ae(b);return{z:n,minX:Math.min(l,s),maxX:Math.max(l,s),minY:Math.min(u,c),maxY:Math.max(u,c),minZ:t,maxZ:o,noise:p}}function pe(e){let{spectra:m,ntuples:t,info:o}=e;if(t)for(let f of t){let{symbol:i,nucleus:n,units:l}=f;if(i.match(/[F|T]1/)&&l?.toUpperCase().match("HZ")){let s=se(o[".OBSERVEFREQUENCY"]),{nucleus:u}=t.find(d=>d.symbol.match(/[F|T]2/));if([s,u,n].some(d=>!d))break;let c=ie(u),b=ie(n),{first:p,last:r}=f,a=b!==null&&c!==null?s*b/c:s;return{firstY:p/a,lastY:r/a}}}return{firstY:m[0].pageValue,lastY:m.at(-1).pageValue}}function H(e,m){let t=e.noise,o=e.z,f,i,n,l,s,u,c,b,p=o.length,r=o[0].length,a,d,g,A,x=e.minX,S=(e.maxX-x)/(r-1),C=e.minY,X=(e.maxY-C)/(p-1),L=e.minZ,N=e.maxZ,Y=m.nbContourLevels*2,F=new Array(Y),y;for(let M=0;M<Y;M++){let U={};F[M]=U;let fe=M%2,Q=(N-m.noiseMultiplier*t)*Math.exp((M>>1)-m.nbContourLevels);fe===0?y=Q+m.noiseMultiplier*t:y=0-Q-m.noiseMultiplier*t;let D=[];if(U.zValue=y,U.lines=D,!(y<=L||y>=N))for(let v=0;v<p-1;v++){let _=o[v],ee=o[v+1];for(let T=0;T<r-1;T++)f=_[T],i=_[T+1],n=ee[T],l=ee[T+1],s=f>y,u=i>y,c=n>y,b=l>y,s!==u&&s!==c&&(a=T+(y-f)/(i-f),d=v,g=T,A=v+(y-f)/(n-f),D.push(a*S+x,d*X+C,g*S+x,A*X+C)),b!==u&&b!==c&&(a=T+1,d=v+1-(y-l)/(i-l),g=T+1-(y-l)/(n-l),A=v+1,D.push(a*S+x,d*X+C,g*S+x,A*X+C)),u!==c&&(a=(T+1-(y-i)/(n-i))*S+x,d=(v+(y-i)/(n-i))*X+C,u!==s&&(g=T+1-(y-i)/(f-i),A=v,D.push(a,d,g*S+x,A*X+C)),c!==s&&(g=T,A=v+1-(y-n)/(f-n),D.push(a,d,g*S+x,A*X+C)),u!==b&&(g=T+1,A=v+(y-i)/(l-i),D.push(a,d,g*S+x,A*X+C)),c!==b&&(g=T+(y-n)/(l-n),A=v+1,D.push(a,d,g*S+x,A*X+C)))}}return{minX:e.minX,maxX:e.maxX,minY:e.minY,maxY:e.maxY,segments:F}}function G(e,m){let t=Z(e);m.noContour||(e.contourLines=H(t,m),delete t.z),e.minMax=t}import{getGyromagneticRatio as W}from"gyromagnetic-ratio";function z(e,m){for(let t of e){let o=0,f=0;for(let i of t.spectra){if(t.ntuples?.symbol?(!o&&i.observeFrequency&&(o=i.observeFrequency),!f&&i.shiftOffsetVal&&(f=i.shiftOffsetVal)):(o=i.observeFrequency,f=i.shiftOffsetVal),o&&i.xUnits?.toUpperCase().includes("HZ")&&(i.xUnits="PPM",i.xFactor=i.xFactor!==void 0?i.xFactor/o:void 0,i.firstX=i.firstX!==void 0?i.firstX/o:void 0,i.lastX=i.lastX!==void 0?i.lastX/o:void 0,i.deltaX=i.deltaX!==void 0?i.deltaX/o:void 0,i.data))for(let n=0;n<i.data.x.length;n++)i.data.x[n]/=o;if(f&&i.xUnits.toLowerCase().includes("ppm")&&i.firstX!==void 0&&i.lastX!==void 0){let n=i.firstX-f;if(i.firstX=i.firstX-n,i.lastX=i.lastX-n,i.data)for(let l=0;l<i.data.x.length;l++)i.data.x[l]-=n}if(t.ntuples?.nucleus&&t.ntuples.symbol)for(let n=0;n<t.ntuples.nucleus.length;n++){let l=t.ntuples.symbol[n],s=t.ntuples.nucleus[n];if(l.match(/^[F|T]/)&&!s){if(l.match(/[F|T]1/))if(t.tmp.$NUC2&&typeof t.tmp.$NUC2=="string")t.ntuples.nucleus[n]=t.tmp.$NUC2;else{let u=t.ntuples.symbol.indexOf(l.replace(/^([F|T]).*/,"$12"));u&&t.ntuples.nucleus[u]&&(t.ntuples.nucleus[n]=t.ntuples.nucleus[u])}l.match(/[F|T]2/)&&typeof t.tmp.$NUC1=="string"&&(t.ntuples.nucleus[n]=t.tmp.$NUC1)}l.match(/[F|T]2/)&&(t.yType=t.ntuples.nucleus[0],t.xType&&!W(t.xType)&&(t.xType=t.ntuples.nucleus[1]))}if(o&&t.ntuples?.symbol&&t.ntuples.nucleus){let n="",l=t.ntuples.symbol.indexOf(i.pageSymbol);t.ntuples.units?.[l]&&(n=t.ntuples.units[l]);let{nucleus:s}=t.ntuples;if(!n.toLowerCase().match(/(ppm|seconds)/)&&s.length>1){if(l!==0){let p="Not sure about this ntuples format";if(m){m.warn(p);continue}else throw new Error(p)}let{nucleus:u}=t.ntuples,c=W(u[0]),b=W(u[1]);if(!c||!b){let p=`Problem with determination of gyromagnetic ratio for ${u.join("-")}`;if(m)m.error(p);else throw new Error(p)}else{let p=c/b*o;i.pageValue/=p}}}}}}function J(e){let m=e.spectra[0].data;e.chromatogram={times:m.x.slice(),series:{intensity:{dimension:1,data:m.y.slice()}}}}function q(e,m,t){z(e,t.logger),de(e,t);for(let o of e){if(Object.keys(o.ntuples).length>0){let f=[],i=Object.keys(o.ntuples);for(let n of i){let l=o.ntuples[n];if(l)for(let s=0;s<l.length;s++)f[s]||(f[s]={}),f[s][n]=l[s]}o.ntuples=f}o.twoD&&t.wantXY&&(G(o,t),t.logger?.trace({profiling:!0},"Finished countour plot calculation"),t.keepSpectra||delete o.spectra),t.chromatogram&&(o.spectra.length>1?ne(o):J(o),t.logger?.trace({profiling:!0},"Finished chromatogram calculation")),delete o.tmp}}function de(e,m){for(let t of e)for(let o in t.meta){let f=t.meta[o];if(typeof f=="string"){if(f.startsWith("{")){if(!f.includes(":")&&f.endsWith("}")){let i=f.slice(1,-1).split(/[,; ]+/).filter(Boolean);for(let n=0;n<i.length;n++)t.meta[o+String(n)]=m.dynamicTyping?le(i[n]):i[n]}}else if(f.startsWith("(")){let i=f.split(/\r?\n/),n=/^\((?<from>\d+)\.\.(?<to>\d+)\).*$/;if(n.test(i[0])){let[l,s]=i[0].match(n)?.slice(1).map(Number)??[],u=i.slice(1).join(" ").split(/[,; ]+/).filter(Boolean);for(let c=l;c<=s;c++)m.dynamicTyping&&typeof u[c-l]=="string"?t.meta[o+String(c)]=le(u[c-l]):t.meta[o+String(c)]=u[c-l]}}}}}function K(e,m,t){let o=-1,f=-1,i="",n="";if(t.indexOf("++")>0)i=t.replace(/.*\(([a-zA-Z0-9]+)\+\+.*/,"$1"),n=t.replace(/.*\.\.([a-zA-Z0-9]+).*/,"$1");else{t=t.replaceAll(/[^a-zA-Z%]/g,""),i=t.charAt(0),n=t.charAt(1),m.variables={};for(let l of t){let s=l.toLowerCase(),u=e.ntuples.symbol?.indexOf(l)||0;if(u===-1)throw new Error(`Symbol undefined: ${l}`);m.variables[s]={};for(let c in e.ntuples)e.ntuples[c]?.[u]&&(m.variables[s][c.replace(/^var/,"")]=e.ntuples[c]?.[u])}}o=e.ntuples.symbol?.indexOf(i)??-1,f=e.ntuples.symbol?.indexOf(n)??-1,o===-1&&(o=0),f===-1&&(f=0),e.ntuples.first&&(e.ntuples.first.length>o&&(m.firstX=e.ntuples.first[o]),e.ntuples.first.length>f&&(m.firstY=e.ntuples.first[f])),e.ntuples.last&&(e.ntuples.last.length>o&&(m.lastX=e.ntuples.last[o]),e.ntuples.last.length>f&&(m.lastY=e.ntuples.last[f])),e.ntuples.vardim&&e.ntuples.vardim.length>o&&(m.nbPoints=e.ntuples.vardim[o]),e.ntuples.factor&&(e.ntuples.factor.length>o&&(m.xFactor=e.ntuples.factor[o]),e.ntuples.factor.length>f&&(m.yFactor=e.ntuples.factor[f])),e.ntuples.units&&(e.ntuples.units.length>o&&(e.ntuples.varname?.[o]?m.xUnits=`${e.ntuples.varname[o]} [${e.ntuples.units[o]}]`:m.xUnits=e.ntuples.units[o]),e.ntuples.units.length>f&&(e.ntuples.varname?.[f]?m.yUnits=`${e.ntuples.varname[f]} [${e.ntuples.units[f]}]`:m.yUnits=e.ntuples.units[f]))}function j(e){e.xFactor||(e.xFactor=1),e.yFactor||(e.yFactor=1)}var R=/[ \t]*,[ \t]*/,he={removeComments:!1,keepRecordsRegExp:/^$/,canonicDataLabels:!0,canonicMetadataLabels:!1,dynamicTyping:!0,withoutXY:!1,noTrimRegExp:/^$/,chromatogram:!1,keepSpectra:!1,noContour:!1,nbContourLevels:7,noiseMultiplier:5};function pt(e,m={}){e=ge(e);let t={...he,...m};t.logger?.debug("Starting jcamp conversion"),t.wantXY=!t.withoutXY,t.start=Date.now();let o=[],f={entries:[],flatten:[]},i={children:[],spectra:[],ntuples:{},info:{},meta:{},tmp:{}},n=i,l=[],s={data:{}};t.logger?.trace({profiling:!0},"Before split to LDRS");let u=e.replaceAll(/[\r\n]+##/g,`
|
|
7
|
+
`;let r=p.match(/^##(.*?)=(.+)/);if(r){let a=r[1].replaceAll(/[ _-]/g,"").toUpperCase();a==="DATATYPE"?l.dataType=r[2].trim():a==="DATACLASS"?l.dataClass=r[2].trim():a==="JCAMPDX"?l.jcampDX=E(r[2].trim()):a==="JCAMPCS"&&(l.jcampCS=E(r[2].trim()))}}p.startsWith("##END")&&s>0&&s--}if(t){for(let u of f)u.children=void 0;return f}else return n}import{parseString as be}from"dynamic-typing";import{ensureString as ge}from"ensure-string";var te=["TIC",".RIC","SCANNUMBER"];function ne(e){let m=e.spectra,t=m.length,o={times:new Array(t),series:{ms:{dimension:2,data:new Array(t)}}},f=[];for(let i of te){let n=k(i);m[0][n]&&(f.push(n),o.series[n]={dimension:1,data:new Array(t)})}for(let i=0;i<t;i++){let n=m[i];o.times[i]=n.pageValue;for(let l of f)o.series[l].data[i]=Number(n[l]);n.data&&(o.series.ms.data[i]=[n.data.x,n.data.y])}e.chromatogram=o}function re(e){return te.includes(e)}function k(e){return e.toLowerCase().replaceAll(/[^a-z0-9]/g,"")}function O(e){return e.map(Number)}function V(e,m,t){let{logger:o}=t;o&&(e.xFactor||o.info("The xFactor is not defined, it will be set to 1"),e.yFactor||o.info("The yFactor is not defined, it will be set to 1"));let f=e.yFactor??1,i=e.xFactor??1,n=e.deltaX??1,l=Math.abs(n*.1),s=.01;e.isXYdata=!0;let c={x:[],y:[]};e.data=c;let u=e.firstX||0,b=e.firstY||0,p=!1,r,a=0;for(;a<m.length;a++)if(r=m.codePointAt(a),r===13||r===10)p=!0;else if(p)break;let d=0,g=!0,A=!1,x=!1,I=0,S=!1,C=!1,h=0,X=0,L=!1,N=!1,Y=!1,F=0;for(;a<=m.length;a++)if(a===m.length?r=13:r=m.codePointAt(a),C)(r===13||r===10)&&(g=!0,C=!1,d++);else if(r<=57&&r>=48)N=!0,F>0?h+=(r-48)/10**F++:(h*=10,h+=r-48);else if(r===44||r===46)N=!0,F++;else{if(N){if(L&&(h=h*-1,L=!1),g)h*=i,o&&(x?Math.abs(u-n-h)>l&&(Math.abs(u-h)<l?o.trace(`Data line ${d}: After a DIFFERENCE the next line should repeat the last value and this does not seem to be the case: Current value: ${h} - Expected: ${u}.`):Math.abs(u-n-h)>10*l?o.trace(`Data line ${d}: The difference between the first value ${h} and the expected first x value ${u} based on increment after a DIFFERENCE is too high`):o.trace(`Data line ${d}: The difference between the first value ${h} and the expected first x value ${u} based on increment after a DIFFERENCE is too high`)):Math.abs(u-h)>l&&o.trace(`Data line ${d}: The difference between the first value ${h} and the first x value ${u} is too high`)),g=!1,x&&(Y=!0);else if(Y)Y=!1,o&&Math.abs(b-h)>s&&o.trace(`Data line ${d}: After a duplicate the next line should repeat the same value ${h} !== ${b}`),b=h;else{A?(I=L?0-h:h,x=!0,A=!1):S||(X=L?0-h:h);let y=S?h-1:1;for(let M=0;M<y;M++)x?b+=I:b=X,c.x.push(u),c.y.push(b*f),u+=n}L=!1,h=0,F=0,N=!1,S=!1}if(r<74&&r>63)N=!0,x=!1,h=r-64;else if(r>96&&r<106)N=!0,x=!1,h=r-96,L=!0;else if(r===115)N=!0,S=!0,h=9;else if(r>82&&r<91)N=!0,S=!0,h=r-82;else if(r>73&&r<83)N=!0,A=!0,h=r-73;else if(r>105&&r<115)N=!0,A=!0,h=r-105,L=!0;else if(r===36&&m.codePointAt(a+1)===36)N=!0,C=!0;else if(r===37)N=!0,A=!0,h=0,L=!1;else if(r===45){let y=m.codePointAt(a+1);(y!==void 0&&y>=48&&y<=57||y===44||y===46)&&(N=!0,g||(x=!1),L=!0)}else(r===13||r===10)&&(g=!0,C=!1,d++)}o&&x&&o.warn("The last value is a difference, it should be repeated on the next line")}var oe=/[,\t ]+/;function w(e,m,t){if(e.isPeaktable=!0,!e.variables||Object.keys(e.variables).length===2?ue(e,m,t):ce(e,m,t),e.variables)for(let o in e.variables)e.variables[o].data=e.data?.[o]}function ue(e,m,t){let{logger:o}=t,f={x:[],y:[]};e.data=f;let i=m.split(/,? *,?[;\r\n]+ */);for(let n=1;n<i.length;n++){let l=i[n].trim().replace($,"").split(oe);if(l.length%2===0)for(let s=0;s<l.length;s=s+2)e.xFactor!==void 0&&e.yFactor!==void 0&&(f.x.push(Number(l[s])*e.xFactor),f.y.push(Number(l[s+1])*e.yFactor));else o?.warn(`Format error: ${l.toString()}`)}}function ce(e,m,t){let{logger:o}=t,f={},i=Object.keys(e.variables),n=i.length;for(let s of i)f[s]=[];e.data=f;let l=m.split(/,? *,?[;\r\n]+ */);for(let s=1;s<l.length;s++){let c=l[s].trim().replace($,"").split(oe);if(c.length%n===0)for(let u=0;u<c.length;u++)f[i[u%n]].push(Number(c[u]));else o?.warn(`Wrong number of columns: ${c.toString()}`)}}function B(e,m){e.isXYAdata=!0;let t={};e.data=t;let o=m.split(/\r?\n/),f=o[0].replace(/^.*?([A-Z]+).*$/,"$1").split("").map(i=>i.toLowerCase());for(let i=1;i<o.length;i++){let n=o[i].replace(/^\((.*)\)$/,"$1").split(/ *, */);for(let l=0;l<f.length;l++){let s=n[l];switch(f[l]){case"x":case"y":case"w":s=Number.parseFloat(s);break;case"a":s=s.replace(/^<(.*)>$/,"$1");break;case"m":break;default:continue}t[f[l]]||(t[f[l]]=[]),t[f[l]].push(s)}}}import{parseString as le}from"dynamic-typing";import{getGyromagneticRatio as ie}from"gyromagnetic-ratio";import ae from"ml-array-median";function se(e){return Array.isArray(e)?e[0]:e}function Z(e){let{spectra:m}=e,t=m[0].data.y[0],o=t,f=m.length,i=m[0].data.x.length||0,n=new Array(f);for(let r=0;r<f;r++){n[r]=m[r].data.y;for(let a=0;a<i;a++){let d=n[r][a];d<t&&(t=d),d>o&&(o=d)}}let l=m[0].data.x[0],s=m[0].data.x.at(-1),{firstY:c,lastY:u}=pe(e);if(l>s)for(let r of n)r.reverse();c>u&&n.reverse();let b=[];for(let r of n){let a=Float64Array.from(r);for(let d=0;d<a.length;d++)a[d]<0&&(a[d]=-a[d]);b.push(ae(a))}let p=ae(b);return{z:n,minX:Math.min(l,s),maxX:Math.max(l,s),minY:Math.min(c,u),maxY:Math.max(c,u),minZ:t,maxZ:o,noise:p}}function pe(e){let{spectra:m,ntuples:t,info:o}=e;if(t)for(let f of t){let{symbol:i,nucleus:n,units:l}=f;if(i.match(/[F|T]1/)&&l?.toUpperCase().match("HZ")){let s=se(o[".OBSERVEFREQUENCY"]),{nucleus:c}=t.find(d=>d.symbol.match(/[F|T]2/));if([s,c,n].some(d=>!d))break;let u=ie(c),b=ie(n),{first:p,last:r}=f,a=b!==null&&u!==null?s*b/u:s;return{firstY:p/a,lastY:r/a}}}return{firstY:m[0].pageValue,lastY:m.at(-1).pageValue}}function H(e,m){let t=e.noise,o=e.z,f,i,n,l,s,c,u,b,p=o.length,r=o[0].length,a,d,g,A,x=e.minX,S=(e.maxX-x)/(r-1),C=e.minY,X=(e.maxY-C)/(p-1),L=e.minZ,N=e.maxZ,Y=m.nbContourLevels*2,F=new Array(Y),y;for(let M=0;M<Y;M++){let U={};F[M]=U;let fe=M%2,Q=(N-m.noiseMultiplier*t)*Math.exp((M>>1)-m.nbContourLevels);fe===0?y=Q+m.noiseMultiplier*t:y=0-Q-m.noiseMultiplier*t;let D=[];if(U.zValue=y,U.lines=D,!(y<=L||y>=N))for(let v=0;v<p-1;v++){let _=o[v],ee=o[v+1];for(let T=0;T<r-1;T++)f=_[T],i=_[T+1],n=ee[T],l=ee[T+1],s=f>y,c=i>y,u=n>y,b=l>y,s!==c&&s!==u&&(a=T+(y-f)/(i-f),d=v,g=T,A=v+(y-f)/(n-f),D.push(a*S+x,d*X+C,g*S+x,A*X+C)),b!==c&&b!==u&&(a=T+1,d=v+1-(y-l)/(i-l),g=T+1-(y-l)/(n-l),A=v+1,D.push(a*S+x,d*X+C,g*S+x,A*X+C)),c!==u&&(a=(T+1-(y-i)/(n-i))*S+x,d=(v+(y-i)/(n-i))*X+C,c!==s&&(g=T+1-(y-i)/(f-i),A=v,D.push(a,d,g*S+x,A*X+C)),u!==s&&(g=T,A=v+1-(y-n)/(f-n),D.push(a,d,g*S+x,A*X+C)),c!==b&&(g=T+1,A=v+(y-i)/(l-i),D.push(a,d,g*S+x,A*X+C)),u!==b&&(g=T+(y-n)/(l-n),A=v+1,D.push(a,d,g*S+x,A*X+C)))}}return{minX:e.minX,maxX:e.maxX,minY:e.minY,maxY:e.maxY,segments:F}}function G(e,m){let t=Z(e);m.noContour||(e.contourLines=H(t,m),delete t.z),e.minMax=t}import{getGyromagneticRatio as W}from"gyromagnetic-ratio";function z(e,m){for(let t of e){let o=0,f=0;for(let i of t.spectra){if(t.ntuples?.symbol?(!o&&i.observeFrequency&&(o=i.observeFrequency),!f&&i.shiftOffsetVal&&(f=i.shiftOffsetVal)):(o=i.observeFrequency,f=i.shiftOffsetVal),o&&i.xUnits?.toUpperCase().includes("HZ")&&(i.xUnits="PPM",i.xFactor=i.xFactor!==void 0?i.xFactor/o:void 0,i.firstX=i.firstX!==void 0?i.firstX/o:void 0,i.lastX=i.lastX!==void 0?i.lastX/o:void 0,i.deltaX=i.deltaX!==void 0?i.deltaX/o:void 0,i.data))for(let n=0;n<i.data.x.length;n++)i.data.x[n]/=o;if(f&&i.xUnits.toLowerCase().includes("ppm")&&i.firstX!==void 0&&i.lastX!==void 0){let n=i.firstX-f;if(i.firstX=i.firstX-n,i.lastX=i.lastX-n,i.data)for(let l=0;l<i.data.x.length;l++)i.data.x[l]-=n}if(t.ntuples?.nucleus&&t.ntuples.symbol)for(let n=0;n<t.ntuples.nucleus.length;n++){let l=t.ntuples.symbol[n],s=t.ntuples.nucleus[n];if(l.match(/^[F|T]/)&&!s){if(l.match(/[F|T]1/))if(t.tmp.$NUC2&&typeof t.tmp.$NUC2=="string")t.ntuples.nucleus[n]=t.tmp.$NUC2;else{let c=t.ntuples.symbol.indexOf(l.replace(/^([F|T]).*/,"$12"));c&&t.ntuples.nucleus[c]&&(t.ntuples.nucleus[n]=t.ntuples.nucleus[c])}l.match(/[F|T]2/)&&typeof t.tmp.$NUC1=="string"&&(t.ntuples.nucleus[n]=t.tmp.$NUC1)}l.match(/[F|T]2/)&&(t.yType=t.ntuples.nucleus[0],t.xType&&!W(t.xType)&&(t.xType=t.ntuples.nucleus[1]))}if(o&&t.ntuples?.symbol&&t.ntuples.nucleus){let n="",l=t.ntuples.symbol.indexOf(i.pageSymbol);t.ntuples.units?.[l]&&(n=t.ntuples.units[l]);let{nucleus:s}=t.ntuples;if(!n.toLowerCase().match(/(ppm|seconds)/)&&s.length>1){if(l!==0){let p="Not sure about this ntuples format";if(m){m.warn(p);continue}else throw new Error(p)}let{nucleus:c}=t.ntuples,u=W(c[0]),b=W(c[1]);if(!u||!b){let p=`Problem with determination of gyromagnetic ratio for ${c.join("-")}`;if(m)m.error(p);else throw new Error(p)}else{let p=u/b*o;i.pageValue/=p}}}}}}function J(e){let m=e.spectra[0].data;e.chromatogram={times:m.x.slice(),series:{intensity:{dimension:1,data:m.y.slice()}}}}function q(e,m,t){z(e,t.logger),de(e,t);for(let o of e){if(Object.keys(o.ntuples).length>0){let f=[],i=Object.keys(o.ntuples);for(let n of i){let l=o.ntuples[n];if(l)for(let s=0;s<l.length;s++)f[s]||(f[s]={}),f[s][n]=l[s]}o.ntuples=f}o.twoD&&t.wantXY&&(G(o,t),t.logger?.trace({profiling:!0},"Finished countour plot calculation"),t.keepSpectra||delete o.spectra),t.chromatogram&&(o.spectra.length>1?ne(o):J(o),t.logger?.trace({profiling:!0},"Finished chromatogram calculation")),delete o.tmp}}function de(e,m){for(let t of e)for(let o in t.meta){let f=t.meta[o];if(typeof f=="string"){if(f.startsWith("{")){if(!f.includes(":")&&f.endsWith("}")){let i=f.slice(1,-1).split(/[,; ]+/).filter(Boolean);for(let n=0;n<i.length;n++)t.meta[o+String(n)]=m.dynamicTyping?le(i[n]):i[n]}}else if(f.startsWith("(")){let i=f.split(/\r?\n/),n=/^\((?<from>\d+)\.\.(?<to>\d+)\).*$/;if(n.test(i[0])){let[l,s]=i[0].match(n)?.slice(1).map(Number)??[],c=i.slice(1).join(" ").split(/[,; ]+/).filter(Boolean);for(let u=l;u<=s;u++)m.dynamicTyping&&typeof c[u-l]=="string"?t.meta[o+String(u)]=le(c[u-l]):t.meta[o+String(u)]=c[u-l]}}}}}function K(e,m,t){let o=-1,f=-1,i="",n="";if(t.indexOf("++")>0)i=t.replace(/.*\(([a-zA-Z0-9]+)\+\+.*/,"$1"),n=t.replace(/.*\.\.([a-zA-Z0-9]+).*/,"$1");else{t=t.replaceAll(/[^a-zA-Z%]/g,""),i=t.charAt(0),n=t.charAt(1),m.variables={};for(let l of t){let s=l.toLowerCase(),c=e.ntuples.symbol?.indexOf(l)||0;if(c===-1)throw new Error(`Symbol undefined: ${l}`);m.variables[s]={};for(let u in e.ntuples)e.ntuples[u]?.[c]&&(m.variables[s][u.replace(/^var/,"")]=e.ntuples[u]?.[c])}}o=e.ntuples.symbol?.indexOf(i)??-1,f=e.ntuples.symbol?.indexOf(n)??-1,o===-1&&(o=0),f===-1&&(f=0),e.ntuples.first&&(e.ntuples.first.length>o&&(m.firstX=e.ntuples.first[o]),e.ntuples.first.length>f&&(m.firstY=e.ntuples.first[f])),e.ntuples.last&&(e.ntuples.last.length>o&&(m.lastX=e.ntuples.last[o]),e.ntuples.last.length>f&&(m.lastY=e.ntuples.last[f])),e.ntuples.vardim&&e.ntuples.vardim.length>o&&(m.nbPoints=e.ntuples.vardim[o]),e.ntuples.factor&&(e.ntuples.factor.length>o&&(m.xFactor=e.ntuples.factor[o]),e.ntuples.factor.length>f&&(m.yFactor=e.ntuples.factor[f])),e.ntuples.units&&(e.ntuples.units.length>o&&(e.ntuples.varname?.[o]?m.xUnits=`${e.ntuples.varname[o]} [${e.ntuples.units[o]}]`:m.xUnits=e.ntuples.units[o]),e.ntuples.units.length>f&&(e.ntuples.varname?.[f]?m.yUnits=`${e.ntuples.varname[f]} [${e.ntuples.units[f]}]`:m.yUnits=e.ntuples.units[f]))}function j(e){e.xFactor||(e.xFactor=1),e.yFactor||(e.yFactor=1)}var R=/[ \t]*,[ \t]*/,he={removeComments:!1,keepRecordsRegExp:/^$/,canonicDataLabels:!0,canonicMetadataLabels:!1,dynamicTyping:!0,withoutXY:!1,noTrimRegExp:/^$/,chromatogram:!1,keepSpectra:!1,noContour:!1,nbContourLevels:7,noiseMultiplier:5};function pt(e,m={}){e=ge(e);let t={...he,...m};t.logger?.debug("Starting jcamp conversion"),t.wantXY=!t.withoutXY,t.start=Date.now();let o=[],f={entries:[],flatten:[]},i={children:[],spectra:[],ntuples:{},info:{},meta:{},tmp:{}},n=i,l=[],s={data:{}};t.logger?.trace({profiling:!0},"Before split to LDRS");let c=e.replaceAll(/[\r\n]+##/g,`
|
|
8
8
|
##`).split(`
|
|
9
|
-
##`);t.logger?.trace({profiling:!0},"Split to LDRS"),
|
|
9
|
+
##`);t.logger?.trace({profiling:!0},"Split to LDRS"),c[0]&&(c[0]=c[0].replace(/^[\r\n ]*##/,""));for(let u of c){let b=u.indexOf("="),p=b>0?u.slice(0,Math.max(0,b)):u,r=b>0?p.match(t.noTrimRegExp)?u.slice(Math.max(0,b+1)):u.slice(Math.max(0,b+1)).trim():"",a=p.replaceAll(/[_ -]/g,"").toUpperCase();if(a==="DATATABLE"){let d=r.indexOf(`
|
|
10
10
|
`);if(d===-1&&(d=r.indexOf("\r")),d>0){let g=r.slice(0,Math.max(0,d)).split(/[ ,;\t]+/);K(n,s,g[0]),s.datatable=g[0],g[1]?.includes("PEAKS")?a="PEAKTABLE":g[1]&&(g[1].indexOf("XYDATA")||g[0].indexOf("++")>0)&&(a="XYDATA",s.nbPoints&&s.lastX!==void 0&&s.firstX!==void 0&&(s.deltaX=(s.lastX-s.firstX)/(s.nbPoints-1)))}}if(a==="XYDATA"){t.wantXY&&(j(s),r.match(/.*\+\+.*/)?(s.nbPoints&&s.lastX!==void 0&&s.firstX!==void 0&&(s.deltaX=(s.lastX-s.firstX)/(s.nbPoints-1)),V(s,r,t)):w(s,r,t),n?.spectra.push(s),s={data:{}});continue}else if(a==="PEAKTABLE"){t.wantXY&&(j(s),w(s,r,t),n?.spectra.push(s),s={data:{}});continue}if(a==="PEAKASSIGNMENTS"){t.wantXY&&(r.match(/.*[^A-Z]*.*/)&&B(s,r),n?.spectra.push(s),s={data:{}});continue}if(t.removeComments&&(r=r.split(/\r?\n/).map(d=>d.replace(/ *\$\$.*$/,"")).join(`
|
|
11
|
-
`)),a==="TITLE"){let d=n;d.children||(d.children=[]),n={spectra:[],ntuples:{},info:{},meta:{},tmp:{}},d.children.push(n),l.push(d),o.push(n),n.title=r}else a==="DATATYPE"?(n.dataType=r,r.match(/^nd|\snd\s/i)&&(n.twoD=!0)):a==="NTUPLES"?r.match(/^nd|\snd\s/i)&&(n.twoD=!0):a==="DATACLASS"?n.dataClass=r:a==="JCAMPDX"?n.jcampDX=E(r):a==="JCAMPCS"?n.jcampCS=E(r):a==="XUNITS"?s.xUnits=r:a==="YUNITS"?s.yUnits=r:a==="FIRSTX"?s.firstX=Number(r):a==="LASTX"?s.lastX=Number(r):a==="FIRSTY"?s.firstY=Number(r):a==="LASTY"?s.lastY=Number(r):a==="NPOINTS"?s.nbPoints=Number(r):a==="XFACTOR"?s.xFactor=Number(r):a==="YFACTOR"?s.yFactor=Number(r):a==="MAXX"?s.maxX=Number(r):a==="MINX"?s.minX=Number(r):a==="MAXY"?s.maxY=Number(r):a==="MINY"?s.minY=Number(r):a==="DELTAX"?s.deltaX=Number(r):a===".OBSERVEFREQUENCY"||a==="$SFO1"?s.observeFrequency||(s.observeFrequency=Number(r)):a===".OBSERVENUCLEUS"?s.xType||(n.xType=r.replaceAll(/[^a-zA-Z0-9]/g,"")):a==="$OFFSET"?(n.shiftOffsetNum=0,s.shiftOffsetVal||(s.shiftOffsetVal=Number(r))):a==="$REFERENCEPOINT"||(a==="VARNAME"?n.ntuples.varname=r.split(R):a==="SYMBOL"?n.ntuples.symbol=r.split(R):a==="VARTYPE"?n.ntuples.vartype=r.split(R):a==="VARFORM"?n.ntuples.varform=r.split(R):a==="VARDIM"?n.ntuples.vardim=O(r.split(R)):a==="UNITS"?n.ntuples.units=r.split(R):a==="FACTOR"?n.ntuples.factor=O(r.split(R)):a==="FIRST"?n.ntuples.first=O(r.split(R)):a==="LAST"?n.ntuples.last=O(r.split(R)):a==="MIN"?n.ntuples.min=O(r.split(R)):a==="MAX"?n.ntuples.max=O(r.split(R)):a===".NUCLEUS"?n.ntuples&&(n.ntuples.nucleus=r.split(R).map(d=>d.replaceAll(/[^a-zA-Z0-9]/g,""))):a==="PAGE"?(s.page=r.trim(),s.pageValue=Number(r.replace(/^.*=/,"")),s.pageSymbol=s.page.replace(/[=].*/,"")):a==="RETENTIONTIME"?s.pageValue=Number(r):re(a)?s[k(a)]=r:a==="SAMPLEDESCRIPTION"?s.sampleDescription=r:a.startsWith("$NUC")?!n.tmp[a]&&!r.includes("off")&&(n.tmp[a]=r.replaceAll(/[<>]/g,"")):a==="END"&&(n=l.pop()));if(n?.info&&n.meta&&a.match(t.keepRecordsRegExp)){let d,g;p.startsWith("$")?(g=t.canonicMetadataLabels?a.slice(1):p.slice(1),d=n.meta):(g=t.canonicDataLabels?a:p,d=n.info),t.dynamicTyping&&(r=be(r)),d[g]?(Array.isArray(d[g])||(d[g]=[d[g]]),d[g].push(r)):d[g]=r}}if(t.logger?.trace({profiling:!0},"Finished parsing"),q(o,f,t),t.logger?.trace({profiling:!0},"Total time"),f.entries=i.children||[],f.flatten=o,t.logger){t.logger.debug("Finished jcamp conversion");for(let
|
|
11
|
+
`)),a==="TITLE"){let d=n;d.children||(d.children=[]),n={spectra:[],ntuples:{},info:{},meta:{},tmp:{}},d.children.push(n),l.push(d),o.push(n),n.title=r}else a==="DATATYPE"?(n.dataType=r,r.match(/^nd|\snd\s/i)&&(n.twoD=!0)):a==="NTUPLES"?r.match(/^nd|\snd\s/i)&&(n.twoD=!0):a==="DATACLASS"?n.dataClass=r:a==="JCAMPDX"?n.jcampDX=E(r):a==="JCAMPCS"?n.jcampCS=E(r):a==="XUNITS"?s.xUnits=r:a==="YUNITS"?s.yUnits=r:a==="FIRSTX"?s.firstX=Number(r):a==="LASTX"?s.lastX=Number(r):a==="FIRSTY"?s.firstY=Number(r):a==="LASTY"?s.lastY=Number(r):a==="NPOINTS"?s.nbPoints=Number(r):a==="XFACTOR"?s.xFactor=Number(r):a==="YFACTOR"?s.yFactor=Number(r):a==="MAXX"?s.maxX=Number(r):a==="MINX"?s.minX=Number(r):a==="MAXY"?s.maxY=Number(r):a==="MINY"?s.minY=Number(r):a==="DELTAX"?s.deltaX=Number(r):a===".OBSERVEFREQUENCY"||a==="$SFO1"?s.observeFrequency||(s.observeFrequency=Number(r)):a===".OBSERVENUCLEUS"?s.xType||(n.xType=r.replaceAll(/[^a-zA-Z0-9]/g,"")):a==="$OFFSET"?(n.shiftOffsetNum=0,s.shiftOffsetVal||(s.shiftOffsetVal=Number(r))):a==="$REFERENCEPOINT"||(a==="VARNAME"?n.ntuples.varname=r.split(R):a==="SYMBOL"?n.ntuples.symbol=r.split(R):a==="VARTYPE"?n.ntuples.vartype=r.split(R):a==="VARFORM"?n.ntuples.varform=r.split(R):a==="VARDIM"?n.ntuples.vardim=O(r.split(R)):a==="UNITS"?n.ntuples.units=r.split(R):a==="FACTOR"?n.ntuples.factor=O(r.split(R)):a==="FIRST"?n.ntuples.first=O(r.split(R)):a==="LAST"?n.ntuples.last=O(r.split(R)):a==="MIN"?n.ntuples.min=O(r.split(R)):a==="MAX"?n.ntuples.max=O(r.split(R)):a===".NUCLEUS"?n.ntuples&&(n.ntuples.nucleus=r.split(R).map(d=>d.replaceAll(/[^a-zA-Z0-9]/g,""))):a==="PAGE"?(s.page=r.trim(),s.pageValue=Number(r.replace(/^.*=/,"")),s.pageSymbol=s.page.replace(/[=].*/,"")):a==="RETENTIONTIME"?s.pageValue=Number(r):re(a)?s[k(a)]=r:a==="SAMPLEDESCRIPTION"?s.sampleDescription=r:a.startsWith("$NUC")?!n.tmp[a]&&!r.includes("off")&&(n.tmp[a]=r.replaceAll(/[<>]/g,"")):a==="END"&&(n=l.pop()));if(n?.info&&n.meta&&a.match(t.keepRecordsRegExp)){let d,g;p.startsWith("$")?(g=t.canonicMetadataLabels?a.slice(1):p.slice(1),d=n.meta):(g=t.canonicDataLabels?a:p,d=n.info),t.dynamicTyping&&(r=be(r)),d[g]?(Array.isArray(d[g])||(d[g]=[d[g]]),d[g].push(r)):d[g]=r}}if(t.logger?.trace({profiling:!0},"Finished parsing"),q(o,f,t),t.logger?.trace({profiling:!0},"Total time"),f.entries=i.children||[],f.flatten=o,t.logger){t.logger.debug("Finished jcamp conversion");for(let u of f.flatten)t.logger.debug(`${u.dataType} - ${u.title}`)}return f}function gt(e,m){let{logger:t,OCL:o}=m;if(!e.info.ATOMLIST||!e.info.BONDLIST){t?.warn("No ATOMLIST or BONDLIST in the JCAMP-CS entry");return}Te(e,t);let f=xe(e.info.ATOMLIST),i=Ae(e.info.BONDLIST),n=Ne(e.info.CHARGE,t),l=Se(e.info.XYRASTER,t),s=Ce(e.info.STEREOCENTER,t),c=ye(o,{atoms:f,bonds:i,charges:n,xyRasters:l,stereocenters:s},t);return{molecule:c,molfile:c.toMolfile()}}function ye(e,m,t){let{atoms:o,bonds:f,charges:i,xyRasters:n,stereocenters:l}=m,s={S:e.Molecule.cBondTypeSingle,D:e.Molecule.cBondTypeDouble,T:e.Molecule.cBondTypeTriple,Q:e.Molecule.cBondTypeQuadruple},c={},u=new e.Molecule(o.length,f.length);for(let p of o){let r=e.Molecule.getAtomicNoFromLabel(p.element);r||(t?.error(`Atomic number of ${p.element} could not be determined`),r=e.Molecule.getAtomicNoFromLabel("X")),c[p.atomNumber]=u.addAtom(r),u.setAtomMapNo(c[p.atomNumber],p.atomNumber,!1)}for(let p of f){if(c[p.atomNumber1]===void 0){t?.error(`A bond goes from atomNumber ${p.atomNumber1} that does not exists`);continue}if(c[p.atomNumber2]===void 0){t?.error(`A bond goes to atomNumber ${p.atomNumber2} that does not exists`);continue}let r=u.addBond(c[p.atomNumber1],c[p.atomNumber2]);u.setBondType(r,s[p.bondType])}for(let p of i){if(c[p.atomNumber]===void 0){t?.error(`A charge goes to atomNumber ${p.atomNumber} that does not exists`);continue}u.setAtomCharge(c[p.atomNumber],p.value)}let b=n.length===0||l.length>0;for(let p of n){if(c[p.atomNumber]===void 0){t?.error(`A XYRASTER goes to atomNumber ${p.atomNumber} that does not exists`);continue}u.setAtomX(c[p.atomNumber],p.x),u.setAtomY(c[p.atomNumber],p.y),u.setAtomZ(c[p.atomNumber],p.z)}u.ensureHelperArrays(e.Molecule.cHelperParities);for(let p of l){let{atomNumber:r,type:a}=p,d=c[r];if(d===void 0){t?.error(`A stereocenter goes to atomNumber ${r} that does not exists`);continue}if(!u.isAtomStereoCenter(d)){t?.warn(`Want to set chirality of atom number ${r} but it is not a stereocenter`);continue}if(u.getAtomParity(d)!==e.Molecule.cAtomParityUnknown){t?.debug(`Atom number ${r} already has a parity defined based on 3D coordinates`);continue}let x=a==="P"?e.Molecule.cAtomParity1:e.Molecule.cAtomParity2;u.setAtomParity(c[r],x,!1)}return u.ensureHelperArrays(e.Molecule.cHelperParities),b&&u.inventCoordinates({keepHydrogens:!0}),u}function xe(e){let m=P(e),t=[];for(let o of m){let[f,i,n]=o.trim().split(/\s+/);t.push({atomNumber:Number(f),element:i,nbImplicitHydrogens:n?.length>0?Number(n):void 0})}return t}function Ae(e){let m=P(e),t=[];for(let o of m){let[f,i,n]=o.trim().split(/\s+/);t.push({atomNumber1:Number(f),atomNumber2:Number(i),bondType:n})}return t}function Ne(e,m){if(!e)return[];let t=P(e),o=[];for(let f of t){let[i,n,l]=f.trim().split(/\s+/);l!==void 0&&m?.warn("Charge on multiple atom is not supported"),o.push({atomNumber:Number(n),value:Number(i)})}return o}function Se(e,m){if(!e)return[];let t=P(e),o=[];for(let f of t){let[i,n,l,s]=f.trim().split(/\s+/);if(i===void 0){m?.warn("XYRASTER without atom number is not supported");continue}o.push({atomNumber:Number(i),x:Number(n),y:Number(l),z:s!==void 0?Number(s):0})}return o}function Ce(e,m){if(!e)return[];let t=P(e),o=[];for(let f of t){let[i,n]=f.trim().split(/\s+/);if(!["P","M"].includes(n)){m?.warn(`Stereocenter type ${n} is not supported`);continue}o.push({atomNumber:Number(i),type:n})}return o}function P(e){return e.split(/\r?\n/).map(m=>E(m)).filter(Boolean)}function Te(e,m){let t=["STEREOPAIR","STEREOCENTER","RADICAL","STEREOMOLECULE"];for(let o of t)e.info[o]&&m?.warn(`JCAMP-CS parser do not support: ${o}`)}export{pt as convert,Le as createTree,gt as parseJcampCS,E as removeComment,$ as removeCommentRegExp};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "jcampconverter",
|
|
3
|
-
"version": "12.3.
|
|
3
|
+
"version": "12.3.2",
|
|
4
4
|
"description": "Parse and convert JCAMP-DX data",
|
|
5
5
|
"license": "CC-BY-NC-SA-4.0",
|
|
6
6
|
"type": "module",
|
|
@@ -44,8 +44,8 @@
|
|
|
44
44
|
"jscpd": "^4.0.9",
|
|
45
45
|
"ml-spectra-processing": "^14.28.1",
|
|
46
46
|
"rimraf": "^6.1.3",
|
|
47
|
-
"typescript": "~6.0.
|
|
48
|
-
"vitest": "^4.1.
|
|
47
|
+
"typescript": "~6.0.3",
|
|
48
|
+
"vitest": "^4.1.5"
|
|
49
49
|
},
|
|
50
50
|
"dependencies": {
|
|
51
51
|
"cheminfo-types": "^1.15.0",
|
|
@@ -58,5 +58,5 @@
|
|
|
58
58
|
"volta": {
|
|
59
59
|
"extends": "../../../package.json"
|
|
60
60
|
},
|
|
61
|
-
"gitHead": "
|
|
61
|
+
"gitHead": "7424678b162b8d5cf98b47444caf2a71a04fc3df"
|
|
62
62
|
}
|