UNPKG

kekule

Version:

Open source JavaScript toolkit for chemoinformatics

1 lines 223 kB
!function(){"use strict";var e=Class.PropertyScope,t=Kekule.ArrayUtils,a=Kekule.Unit;Kekule.globalOptions.add("spectrum",{spectrumInfo:{enablePrefixOmissionInGetter:!0},data:{allowedComparisonErrorRate:5e-8}}),Kekule.ComparisonMethod.SPECTRUM_DATA=30,Kekule.Spectroscopy={},Kekule.Spectroscopy.DataMode={CONTINUOUS:1,PEAK:2},Kekule.Spectroscopy.DataPeakPosition={MAX:0,MIN:1},Kekule.Spectroscopy.Utils={getSpectrumPeakPosition:function(e){return(e.getSpectrumType?e.getSpectrumType():e.getParentSpectrum()&&e.getParentSpectrum().getSpectrumType())===Kekule.Spectroscopy.SpectrumType.IR?Kekule.Spectroscopy.DataPeakPosition.MIN:Kekule.Spectroscopy.DataPeakPosition.MAX},expandDataRange:function(e,a){for(var r=t.toArray(a),n=e||{},i=0,o=r.length;i<o;++i)for(var s=r[i],l=Kekule.ObjUtils.getOwnedFieldNames(s),u=0,c=l.length;u<c;++u){var d=l[u],p=s[d];n[d]?p<n[d].min?n[d].min=p:p>n[d].max&&(n[d].max=p):n[d]={min:p,max:p}}return n},mergeDataRange:function(e,a){var r={},n=t.clone(Kekule.ObjUtils.getOwnedFieldNames(e));t.pushUnique(n,Kekule.ObjUtils.getOwnedFieldNames(a));for(var i=0,o=n.length;i<o;++i){var s=n[i];e[s]?a[s]?r[s]={min:e[s].min<a[s].min?e[s].min:a[s].min,max:e[s].max>a[s].max?e[s].max:a[s].max}:r[s]=Object.extend(e[s]):r[s]=Object.extend(a[s])}return r},calcScalePointInfo:function(e,t,a){a<=0&&(a=10);var r,n=[Math.log10(Math.abs(e)),Math.log10(Math.abs(t))],i=Math.floor(Math.max(n[0],n[1])),o=Math.sign(e)===Math.sign(t)?Math.floor(Math.min(n[0],n[1],0)):-1/0,s=i>6,l=t-e,u=l/a,c=Math.max(Math.floor(Math.log10(Math.abs(u))),o),d=Math.pow(10,c);r=r<10&&l>.5?2*Math.ceil(r/d/2)*d:Math.ceil(u/d)*d;for(var p=Math.ceil(e/r)*r,f=Math.floor(t/r)*r,m={useSciForm:s,scaleFrom:p,scaleTo:f,scaleSectionCount:Math.round((f-p)/r),scaleValues:[],scaleBase:d,scaleFromOnBase:p/d,scaleToOnBase:f/d,fixDigitsCountAfterPoint:Math.max(-c,0)},h=0,S=m.scaleSectionCount+1;h<S;++h)m.scaleValues.push(Math.round(h*r/d)*d+p);return m},generateInfoKey:function(e,t,a){var n=t||a;return n?n+r.DELIMITER+e:e},getDefaultDataExtraInfoClass:function(e){return e.getMode()===Kekule.Spectroscopy.DataMode.PEAK?Kekule.Spectroscopy.SpectrumPeakDetails:Kekule.Spectroscopy.SpectrumDataDetails},createDefaultDataExtraInfoObject:function(e){var t=Kekule.Spectroscopy.Utils.getDefaultDataExtraInfoClass(e);return t&&new t}},Kekule.Spectroscopy.MetaPropNamespace={CUSTOM:"custom",DELIMITER:".",_namespaces:[],register:function(e){t.pushUnique(r._namespaces,e)},unregister:function(e){r._namespaces=t.exclude(r._namespaces,e)},getNamespaces:function(){return t.clone(r._namespaces)},createPropertyName:function(e,t){return(e||"")+r.DELIMITER+t},getPropertyNameDetail:function(e){var t,a,n=e.lastIndexOf(r.DELIMITER);return n>=0?(t=e.substring(0,n),a=e.substr(n+1)):a=e,{namespace:t,coreName:a}},getPropertyCoreName:function(e){return r.getPropertyNameDetail(e).coreName}};var r=Kekule.Spectroscopy.MetaPropNamespace;r.register(r.CUSTOM),Kekule.Spectroscopy.DataValueConverterManager={_converters:[],register:function(e){i._converters.push(e)},unregister:function(e){var t=DMC._converters.indexOf(e);t>=0&&DMC._converters.splice(t,1)},doConvert:function(e,t,a,r,n,o){if(a===r)return e;if(!Kekule.NumUtils.isNormalNumber(e))return e;var s=i._converters;if(s.length){var l=Kekule.Unit.getUnit(a),u=Kekule.Unit.getUnit(r);if(l&&u)for(var c=s.length-1;c>=0;--c){var d=s[c];if(d.canConvert(e,t,l,u,n,o))return d.convert(e,t,l,u,n,o)}}return Kekule.error(Kekule.$L("ErrorMsg.UNABLE_TO_CONVERT_BETWEEN_UNITS").format(l.getKey(),u.getKey())),null},getAltUnits:function(e,a,r,n){var o=[],s=i._converters;if(s.length){var l=Kekule.Unit.getUnit(a);if(l)for(var u=s.length-1;u>=0;--u){var c=s[u].getAltUnits(e,l,r,n)||[];t.pushUnique(o,c)}}return o}};var n,i=Kekule.Spectroscopy.DataValueConverterManager;i.register({convert:function(e,t,a,r,n,i){return a.convertValueTo(e,r)},canConvert:function(e,t,a,r,n,i){return a.canConvertValueTo(r)},getAltUnits:function(e,t,a,r){return t.category.getConvertableUnits()}}),i.register({convert:function(e,t,r,n,i,o){var s=o.getParameter("NMR.ObserveFrequency");if(r.category===a.Frequency){var l=(u=r.convertValueTo(e,s.getUnit()))/s.getValue();return a.Dimensionless.ONE.convertValueTo(l,n)}if(r.category===Kekule.Unit.Dimensionless){var u=r.convertValueToStandard(e)*s.getValue();return a.getUnit(s.getUnit()).convertValueTo(u,n)}},canConvert:function(e,t,a,r,n,i){if(i.getSpectrumType()===Kekule.Spectroscopy.SpectrumType.NMR){var o=i.getParameter("NMR.ObserveFrequency"),s=o&&o.getValue();if(o&&s&&Kekule.NumUtils.isNormalNumber(s)&&Kekule.Unit.getUnit(o.getUnit()).category===Kekule.Unit.Frequency)return a.category===Kekule.Unit.Frequency&&r.category===Kekule.Unit.Dimensionless||a.category===Kekule.Unit.Dimensionless&&r.category===Kekule.Unit.Frequency}return!1},getAltUnits:function(e,t,a,r){var n=[];if(r.getSpectrumType()===Kekule.Spectroscopy.SpectrumType.NMR){var i=r.getParameter("NMR.ObserveFrequency"),o=i&&i.getValue();i&&o&&Kekule.NumUtils.isNormalNumber(o)&&Kekule.Unit.getUnit(i.getUnit()).category===Kekule.Unit.Frequency&&(t.category===Kekule.Unit.Frequency?n.push(Kekule.Unit.Dimensionless.PARTS_PER_MILLION):t.category===Kekule.Unit.Dimensionless&&(n=n.concat(Kekule.Unit.Frequency.getConvertableUnits())))}return n}}),i.register({convert:function(e,t,r,n,i,o){if(r.category===a.Length){var s=1/r.convertValueToStandardEx(e).value;return n.convertValueFromStandard(s)}if(r.category===a.WaveNumber){var l=1/r.convertValueToStandardEx(e).value;return n.convertValueFromStandard(l)}},canConvert:function(e,t,a,r,n,i){return i.getSpectrumType()===Kekule.Spectroscopy.SpectrumType.IR&&(a.category===Kekule.Unit.Length&&r.category===Kekule.Unit.WaveNumber||a.category===Kekule.Unit.WaveNumber&&r.category===Kekule.Unit.Length)},getAltUnits:function(e,t,a,r){var n;return r.getSpectrumType()===Kekule.Spectroscopy.SpectrumType.IR&&(t.category===Kekule.Unit.Length?n=[Kekule.Unit.WaveNumber.RECIPROCAL_CENTIMETER]:t.category===Kekule.Unit.WaveNumber&&(n=[Kekule.Unit.Length.getConvertableUnits()])),n}}),Kekule.Spectroscopy.SpectrumVarDefinition=Class.create(Kekule.VarDefinition,{CLASS_NAME:"Kekule.Spectroscopy.SpectrumVarDefinition",initProperties:function(){this.defineProp("internalUnit",{dataType:DataType.STRING,serializable:!1,getter:function(){return this.getUnit()},setter:function(e){this.setUnit(e)}}),this.defineProp("externalUnit",{dataType:DataType.STRING})},getActualExternalUnit:function(){return this.getExternalUnit()||this.getInternalUnit()},hasDifferentExternalUnit:function(){var e=this.getExternalUnit();return!(!e||e===this.getInternalUnit())}}),Kekule.Spectroscopy.SpectrumDataSection=Class.create(Kekule.ChemObject,{CLASS_NAME:"Kekule.Spectroscopy.SpectrumDataSection",DATAITEM_SRC_FIELD_NAME:"_src",DATAITEM_EXTRA_FIELD_NAME:"_extra",initialize:function(e,t,a){this.updateDataModifiedTime(),this.setPropStoreFieldValue("name",e),this.setPropStoreFieldValue("localVarInfos",[]),this.setPropStoreFieldValue("dataItems",[]),this.setPropStoreFieldValue("parent",t),this.tryApplySuper("initialize",[]),a&&this.setLocalVariables(a),this.setDataSorted(!0),this._cache={}},doFinalize:function(){this.getParent()&&this.getParent().removeChild&&this.getParent().removeChild(this),this.clear();for(var e=this.getVariables(),t=0,a=e.length;t<a;++t)e[t].finalize();this.setPropStoreFieldValue("localVarInfos",null),this.tryApplySuper("doFinalize")},initProperties:function(){this.defineProp("parent",{dataType:"Kekule.MapEx",setter:null,serializable:!1}),this.defineProp("name",{dataType:DataType.STRING}),this.defineProp("title",{dataType:DataType.STRING}),this.defineProp("localVarInfos",{dataType:DataType.ARRAY,setter:null}),this.defineProp("localVarSymbols",{dataType:DataType.ARRAY,scope:e.PRIVATE,serializable:!1,getter:function(){var e=[],t=this.getActualLocalVarInfos();if(t&&t.length)for(var a=0,r=t.length;a<r;++a){var n=t[a];e.push(n.symbol)}return e},setter:function(e){var t=e||[];this._updateLocalVarInfosFromSymbols(t)}}),this.defineProp("mode",{dataType:DataType.INT,enumSource:Kekule.Spectroscopy.DataMode,setter:function(e){this.getMode()!==e&&(this.setPropStoreFieldValue("mode",e),this.notifyDataChange())}}),this.defineProp("defPeakRoot",{dataType:DataType.Hash}),this.defineProp("modifiedTime",{dataType:DataType.DATE,setter:null}),this.defineProp("dataItems",{dataType:DataType.ARRAY,setter:null,scope:e.PRIVATE})},initPropValues:function(){this.tryApplySuper("initPropValues"),this.setMode(Kekule.Spectroscopy.DataMode.CONTINUOUS)},getAutoIdPrefix:function(){return"sec"},ownerChanged:function(e,t){for(var a=0,r=this.getDataCount();a<r;++a){var n=this.getExtraInfoAt(a);n&&n.setOwner&&n.setOwner(e)}this.tryApplySuper("ownerChanged",[e,t])},doSaveProp:function(e,t,a,r,n,i,o,s){if(t.serializable){if("dataItems"===t.name){var l=n.createChildStorageNode(a,n.propNameToStorageName("dataItems"),!1),u=n.createChildStorageNode(l,n.propNameToStorageName("values"),!0);n.saveObj(e.getDataItems(),u,r,i,o,s);var c=e._extractAllExtraInfoOfDataItems();if(c.length){u=n.createChildStorageNode(l,n.propNameToStorageName("extras"),!0);n.saveObj(c,u,r,i,o,s)}return!0}return!1}},doLoadProp:function(e,t,a,r,n,i,o){if(t.serializable){if("dataItems"===t.name){var s=[],l=r.getChildStorageNode(a,r.propNameToStorageName("dataItems")),u=r.getChildStorageNode(l,r.propNameToStorageName("values"));if(r.loadObj(s,u,n,i,o),e.setPropStoreFieldValue("dataItems",s),u=r.getChildStorageNode(l,r.propNameToStorageName("extras"))){var c=[];r.loadObj(c,u,n,i,o),e._writeExtraInfoOfDataItems(c)}return!0}return!1}},_setSysFieldOfDataItem:function(e,t,a){try{Object.defineProperty?Object.defineProperty(e,t,{value:a,configurable:!0,writable:!0,enumerable:!1}):e[t]=a}catch(r){e[t]=a}},_extractAllExtraInfoOfDataItems:function(){for(var e=[],t=0,a=this.getDataCount();t<a;++t){var r=this.getExtraInfoAt(t);r&&e.push({index:t,info:r})}return e},_writeExtraInfoOfDataItems:function(e){for(var t=0,a=e.length;t<a;++t){var r=e[t];this.setExtraInfoAt(r.index,r.info)}},isEmpty:function(){return this.getDataCount()<=0},isPeakSection:function(){return this.getMode()===Kekule.Spectroscopy.DataMode.PEAK},hasPeakAssignments:function(){if(this.isPeakSection()){for(var e=!1,t=0,a=this.getDataCount();t<a;++t){var r=this.getExtraInfoAt(t);if(r&&r&&r.hasAssignments&&r.hasAssignments()){e=!0;break}}return e}return!1},getParentSpectrum:function(){for(var e=this.getParent();e&&!(e instanceof Kekule.Spectroscopy.Spectrum)&&e.getParent;)e=e.getParent();return e},getParentVariables:function(){var e=this.getParentSpectrum();return e&&e.getVariables()||[]},getActualLocalVarInfos:function(){var e=t.clone(this.getLocalVarInfos());if(!e||!e.length)for(var a=this.getParentVariables(),r=0,n=a.length;r<n;++r)e.push({symbol:a[r].symbol});return e},_updateLocalVarInfosFromSymbols:function(e,t){for(var a=e||[],r=[],n=this.getParentSpectrum(),i=0,o=a.length;i<o;++i){var s=a[i];this._pushLocalVariable(n,s,r)}this.setPropStoreFieldValue("localVarInfos",r),this.notifyPropSet("localVarInfos",r,t)},_pushLocalVariable:function(e,t,a){(a||(a=this.getLocalVarInfos()),e&&e.getVariable)&&(e.getVariable(t)&&a.push({symbol:t}))},setLocalVariables:function(e){for(var t,a=[],r=[],n=0,i=e.length;n<i;++n)"string"==typeof(t=e[n])?r.push(t):a.push(t);a.length?(this.setPropStoreFieldValue("localVarInfos",a),this.notifyPropSet("localVarInfos",a)):r.length&&this._updateLocalVarInfosFromSymbols(r)},getLocalVarInfoIndex:function(e){var t=-1,a=this.getActualLocalVarInfos();if("number"==typeof e)t=e;else for(var r=e.getSymbol?e.getSymbol():e,n=0,i=a.length;n<i;++n)if(r===a[n].symbol){t=n;break}return t},getLocalVarInfo:function(e){var t=this.getLocalVarInfoIndex(e);return t>=0?this.getActualLocalVarInfos()[t]:null},getLocalVarInfoValue:function(e,t){var a=this.getLocalVarInfo(e);return a&&a[t]},setLocalVarInfoValue:function(e,t,a){this.getLocalVarInfo(e)[t]=a},getLocalVarDef:function(e){var t=this.getLocalVarInfoValue(e,"symbol"),a=this.getParentSpectrum();return a&&a.getVariable(t)},getLocalVarInfoOfDependency:function(e){for(var t=[],a=this.getActualLocalVarInfos(),r=0,n=a.length;r<n;++r){var i=this.getLocalVarDef(r);if(i.getDependency()===e){var o=Object.extend({},a[r]);o.varDef=i,t.push(o)}}return t},getLocalVarSymbolsOfDependency:function(e){for(var t=this.getLocalVarInfoOfDependency(e),a=[],r=0,n=t.length;r<n;++r)a.push(t[r].varDef.getSymbol());return a},getContinuousVarRange:function(e){var t=this.getParent(),a=this.getLocalVarInfo(e);return a.continuousRange||t&&t.getContinuousVarRange&&t.getContinuousVarRange(a.symbol)},setContinuousVarRange:function(e,t,a){return this.setLocalVarInfoValue(e,"continuousRange",{fromValue:t,toValue:a}),this},clearContinuousVarRange:function(e){return this.setLocalVarInfoValue(e,"continuousRange",null),this},setDefaultVarValue:function(e,t){return this.setLocalVarInfoValue(e,"defaultValue",t),this},clearDefaultVarValue:function(e){return this.setDefaultVarValue(e,null)},getDefaultVarValue:function(e){var t=this.getLocalVarInfoValue(e,"defaultValue");if(Kekule.ObjUtils.isUnset(t)){var a=this.getLocalVarInfo(e),r=this.getParent();t=r&&r.getDefaultVarValue(a.symbol)}return t},getVarDisplayRange:function(e,t){var a=t||{},r=this.getLocalVarInfoIndex(e),n=this.getLocalVarInfo(r),i=n.displayRange?Object.extend({},n.displayRange):null;if(!i){var o=this.getLocalVarDef(r).getInfoValue("displayRange");o&&(i=Object.extend({},o))}return!i&&a.autoCalc&&(i=this.calcDataRange(r,{basedOnInternalUnit:!0})[n.symbol]),a.basedOnInternalUnit||(i=this._convertDataRangeToExternalUnit(i,r)),i},setVarDisplayRange:function(e,t,a,r){var n={min:t,max:a};if((r||{}).basedOnExternalUnit){var i=this.getLocalVarInfoIndex(e);n=this._convertDataRangeToInternalUnit(n,i)}return this.setLocalVarInfoValue(e,"displayRange",n),this},clearVarDisplayRange:function(e){return this.setLocalVarInfoValue(e,"displayRange",null),this},getDisplayRangeOfVars:function(e,t){var a={};e||(e=this.getLocalVarSymbols());for(var r=0,n=e.length;r<n;++r){a[this._varToVarSymbol(e[r])]=this.getVarDisplayRange(e[r],t)}return a},_varToVarSymbol:function(e){var t=this.getLocalVarDef(e);return t?t.getSymbol():null},_varToVarSymbols:function(e){var a=[],r=e?t.toArray(e):null;if(r)for(var n=0,i=r.length;n<i;++n)a.push(this._varToVarSymbol(r[n]));else a=this.getLocalVarSymbols();return a},_getDefaultPeakRoot:function(){for(var e={},t=0,a=this.getActualLocalVarInfos().length;t<a;++t){var r=this.getLocalVarDef(t);r.getDependency()!==Kekule.VarDependency.INDEPENDENT&&(e[r.getSymbol()]=0)}return e},calcDataRange:function(e,t){var a=t||{},r=this._varToVarSymbols(e),n=function(e){return!Kekule.NumUtils.isNormalNumber(e)},i={},o=this._cache.ranges;o||(o={},this._cache.ranges=o);for(var s=[],l=0,u=r.length;l<u;++l){o[p=r[l]]?i[p]=Object.extend({},o[p]):s.push(p)}if(s.length){var c=this,d=this.isPeakSection();this.forEach(function(e,t){for(var r=0,o=s.length;r<o;++r){var l=s[r];if(!n(e[l])&&(i[l]||(i[l]={}),i[l].min=n(i[l].min)?e[l]:Math.min(i[l].min,e[l]),i[l].max=n(i[l].max)?e[l]:Math.max(i[l].max,e[l]),d&&!a.ignorePeakRoot)){var u=c.getPeakRootValueOf(e);u&&!n(u[l])&&(i[l].min=n(i[l].min)?u[l]:Math.min(i[l].min,u[l]),i[l].max=n(i[l].max)?u[l]:Math.max(i[l].max,u[l]))}}},null,{basedOnInternalUnit:!0});for(l=0,u=s.length;l<u;++l){o[p=s[l]]=Object.extend({},i[p])}}if(!a.basedOnInternalUnit)for(l=0,u=r.length;l<u;++l){var p=r[l];i[p]=this._convertDataRangeToExternalUnit(i[p],l)}return i},_convertDataRangeToExternalUnit:function(e,t){if(!e)return e;for(var a=["min","max"],r=0,n=a.length;r<n;++r){var i=a[r];e[i]=this._convertVarValueToExternal(e[i],t)}if(e.min>e.max){var o=e.min;e.min=e.max,e.max=o}return e},_convertDataRangeToInternalUnit:function(e,t){if(!e)return e;for(var a=["min","max"],r=0,n=a.length;r<n;++r){var i=a[r];e[i]=this._convertVarValueToInternal(e[i],t)}if(e.min>e.max){var o=e.min;e.min=e.max,e.max=o}return e},calcDataAverage:function(e,t){var a=t||{},r=this._varToVarSymbols(e),n={},i=this._cache.averages,o=function(e){return!Kekule.NumUtils.isNormalNumber(e)};i||(i={},this._cache.averages=i);for(var s=[],l=0,u=r.length;l<u;++l){var c=r[l];o(i[c])?s.push(c):n[c]=i[c]}if(s.length){var d={},p={};for(l=0,u=s.length;l<u;++l)d[s[l]]=0,p[s[l]]=0;this.forEach(function(e,t){for(var a=0,r=s.length;a<r;++a){var n=s[a],i=e[n];o(i)||(d[n]+=i,++p[n])}},null,{basedOnInternalUnit:!0});for(l=0,u=s.length;l<u;++l){n[c=s[l]]=d[c]/p[c],i[c]=n[c]}}if(!a.basedOnInternalUnit)for(l=0,u=r.length;l<u;++l){n[c=r[l]]=this._convertVarValueToExternal(n[l])}return n},getContinuousVarSymbols:function(){for(var e=[],t=this.getActualLocalVarInfos(),a=0,r=t.length;a<r;++a)this.getContinuousVarRange(a)&&e.push(t[a].symbol);return e},_itemHashToArray:function(e){if(!e)return null;for(var a=[],r=this.getLocalVarSymbols(),n=0,i=r.length;n<i;++n)a.push(e[r[n]]);var o,s=this._getDataValueSrc(e);if(s&&this._setSysFieldOfDataItem(a,this.DATAITEM_SRC_FIELD_NAME,s),s&&s[this.DATAITEM_EXTRA_FIELD_NAME])o=s[this.DATAITEM_EXTRA_FIELD_NAME];else{var l=t.exclude(Kekule.ObjUtils.getOwnedFieldNames(e,!1),[this.DATAITEM_SRC_FIELD_NAME,this.DATAITEM_EXTRA_FIELD_NAME].concat(r));l.length&&(o={});for(n=0,i=l.length;n<i;++n)o[l[n]]=e[l[n]]}return o&&this._setSysFieldOfDataItem(s||a,this.DATAITEM_EXTRA_FIELD_NAME,o),a},_convArrayToSymboledHash:function(e,t){for(var a={},r=0,n=Math.min(t.length,e.length);r<n;++r){var i=e[r];a[t[r]]=i}return a},_itemArrayToHash:function(e,t){if(!e)return null;for(var a={},r=this.getLocalVarSymbols(),n=0,i=Math.min(r.length,e.length);n<i;++n){var o;o=t.basedOnInternalUnit?e[n]:this._convertVarValueToExternal(e[n],n),a[r[n]]=o}var s=this._getDataValueSrc(e);return s[this.DATAITEM_EXTRA_FIELD_NAME]&&this._setSysFieldOfDataItem(a,this.DATAITEM_EXTRA_FIELD_NAME,e[this.DATAITEM_EXTRA_FIELD_NAME]),this._setSysFieldOfDataItem(a,this.DATAITEM_SRC_FIELD_NAME,s||e),a},_convertVarValueToNewUnit:function(e,t,a,r){return Kekule.NumUtils.isNormalNumber(e)?Kekule.Spectroscopy.DataValueConverterManager.doConvert(e,t,a,r,this,this.getParent()):e},_convertVarValueToExternal:function(e,t){var a=e,r=this.getLocalVarDef(t);return r&&r.hasDifferentExternalUnit&&r.hasDifferentExternalUnit()&&(a=this._convertVarValueToNewUnit(e,r,r.getInternalUnit(),r.getActualExternalUnit())),a},_convertVarValueToInternal:function(e,t){var a=e,r=this.getLocalVarDef(t);return r&&r.hasDifferentExternalUnit&&r.hasDifferentExternalUnit()&&(a=this._convertVarValueToNewUnit(e,r,r.getActualExternalUnit(),r.getInternalUnit())),a},isDataSorted:function(){return this._sorted||this.getDataCount()<=1},setDataSorted:function(e){return this._sorted=!!e,this},sort:function(e){if(!this.isDataSorted()){var a=this,r=e?function(t,r){return e(a._itemArrayToHash(t),a._itemArrayToHash(r))}:function(e,a){return t.compare(e,a)};return this.getDataItems().sort(r),this.setDataSorted(!0),this}},getIndependentVarValueOrder:function(e){var t=0;if(this.isDataSorted()){var a=this,r=function(e,t,r,i){var o=t,s={},l=!1;do{s.value=a.getHashValueAt(o)[e],s.index=o,o+=i,l=Kekule.NumUtils.isNormalNumber(s.value)}while(!l&&(i>0&&o<=n||i<0&&o>=r));return l?s:null},n=this.getDataCount()-1,i=r(e,0,n,1),o=r(e,n,0,-1);i&&o&&i.index<o.index&&(t=Math.sign(o.value-i.value))}return t},getDataCount:function(){return this.getDataItems().length},clearCache:function(){this._cache={}},notifyDataChange:function(){var e=this.getDataItems();this.setDataSorted(!1),this.clearCache(),this.updateDataModifiedTime(),this.notifyPropSet("dataItems",e),this.invokeEvent("dataChange",{data:e})},updateDataModifiedTime:function(){this.setPropStoreFieldValue("modifiedTime",new Date)},clear:function(){this.setDataItems([]),this.notifyDataChange(),this.setDataSorted(!0)},indexOfDataItem:function(e){var t=e[this.DATAITEM_SRC_FIELD_NAME]||e;return this.getDataItems().indexOf(t)},appendData:function(e){var t;if(t=DataType.isArrayValue(e)?e:this._itemHashToArray(e))return this.getDataItems().push(t),t[this.DATAITEM_EXTRA_FIELD_NAME]&&this._extraInfoAdded(t[this.DATAITEM_EXTRA_FIELD_NAME]),this.notifyDataChange(),t},removeData:function(e){var t=this.getDataItems().indexOf(e);return this.removeDataItemAt(t)},removeDataAt:function(e){var t=this.getDataItems().splice(e,1);return this.notifyDataChange(),t},getRawValueAt:function(e){var a=this.getDataItems()[e];if(a){var r=t.clone(a);r[this.DATAITEM_SRC_FIELD_NAME]=a;for(var n=this.getMode()===Kekule.Spectroscopy.DataMode.CONTINUOUS,i=this.getDataCount()-1,o=0,s=r.length;o<s;++o){var l=r[o];if(DataType.isUndefinedValue(l)||DataType.isNullValue(l)){var u=this.getDefaultVarValue(o);if(Kekule.ObjUtils.notUnset(u))l=u;else if(n){var c=this.getContinuousVarRange(o);c&&(l=i>1?e/i*(c.toValue-c.fromValue)+c.fromValue:c.fromValue)}}r[o]=l}return a[this.DATAITEM_EXTRA_FIELD_NAME]&&this._setSysFieldOfDataItem(r,this.DATAITEM_EXTRA_FIELD_NAME,a._extra),r}return null},getHashValueAt:function(e,t){return this._itemArrayToHash(this.getRawValueAt(e),t||{})},getValueAt:function(e,t){return this.getHashValueAt(e,t)},setRawValueAt:function(e,t){var a=this.getDataItems()[e];return a&&a[this.DATAITEM_EXTRA_FIELD_NAME]&&this._extraInfoRemoved(a[this.DATAITEM_EXTRA_FIELD_NAME]),this.getDataItems()[e]=t,t[this.DATAITEM_EXTRA_FIELD_NAME]&&(this._setSysFieldOfDataItem(t,this.DATAITEM_EXTRA_FIELD_NAME,t[this.DATAITEM_EXTRA_FIELD_NAME]),this._extraInfoAdded(t[this.DATAITEM_EXTRA_FIELD_NAME])),this.notifyDataChange(),this},setHashValueAt:function(e,t,a){var r=this._itemHashToArray(t);return this.setRawValueAt(e,r),this},setValueAt:function(e,t,a){var r;return r=DataType.isArrayValue(t)?t:this._itemHashToArray(t),this.setRawValueAt(e,r),this},_getDataValueSrc:function(e){return e?DataType.isArrayValue(e)?e[this.DATAITEM_SRC_FIELD_NAME]||e:e[this.DATAITEM_SRC_FIELD_NAME]:null},createDefaultExtraInfoObjectFor:function(e){var t=this.isPeakSection()?Kekule.Spectroscopy.SpectrumPeakDetails:null,a=t?new t:null;return a&&Kekule.ObjUtils.notUnset(e)&&("number"==typeof e?this.setExtraInfoAt(e,a):e&&this.setExtraInfoOf(e,a)),a},getExtraInfoOf:function(e){return(this._getDataValueSrc(e)||e)[this.DATAITEM_EXTRA_FIELD_NAME]||e[this.DATAITEM_EXTRA_FIELD_NAME]},setExtraInfoOf:function(e,t){var a=this._getDataValueSrc(e)||e;return a[this.DATAITEM_EXTRA_FIELD_NAME]&&this._extraInfoRemoved(a[this.DATAITEM_EXTRA_FIELD_NAME]),this._setSysFieldOfDataItem(a,this.DATAITEM_EXTRA_FIELD_NAME,t),this._extraInfoAdded(t),this.notifyDataChange(),this},getExtraInfoAt:function(e){var t=this.getDataItems()[e];return t&&t[this.DATAITEM_EXTRA_FIELD_NAME]},setExtraInfoAt:function(e,t){var a=this.getDataItems()[e];return a[this.DATAITEM_EXTRA_FIELD_NAME]&&this._extraInfoRemoved(a[this.DATAITEM_EXTRA_FIELD_NAME]),this._setSysFieldOfDataItem(a,this.DATAITEM_EXTRA_FIELD_NAME,t),this._extraInfoAdded(t),this.notifyDataChange(),this},_extraInfoAdded:function(e){e&&e instanceof Kekule.ChemObject&&(e.setParent(this),e.setOwner(this.getOwner()))},_extraInfoRemoved:function(e){e&&e instanceof Kekule.ChemObject&&e.getParent()===this&&(e.setParent(null),e.setOwner(null))},getPeakRootValueOf:function(e){if(this.getMode()!==Kekule.Spectroscopy.DataMode.PEAK)return null;var t=this.getDefPeakRoot()||this._getDefaultPeakRoot();return Object.extend(Object.extend({},e),t)},getPeakRootValueAt:function(e){return this.getPeakRootValueOf(this.getValueAt(e))},getSurroundingDataItemIndexesFromIndependent:function(e,t){},getDataItemIndexFromIndependent:function(e,t){var a={};a="number"==typeof e?this._convArrayToSymboledHash([e],this.getLocalVarSymbolsOfDependency(Kekule.VarDependency.INDEPENDENT)):DataType.isArrayValue(e)?this._convArrayToSymboledHash(e,this.getLocalVarSymbolsOfDependency(Kekule.VarDependency.INDEPENDENT)):e;for(var r=Kekule.ObjUtils.getOwnedFieldNames(a),n=this.calcDataRange(r),i=t&&t.allowedErrorRate,o={},s=0,l=r.length;s<l;++s){if((S=a[h=r[s]])<n[h].min||S>n[h].max)return-1;o[h]=i&&(n[h].max-n[h].min)*i}var u={index:-1,distanceSqr:0};for(s=0,l=this.getDataCount();s<l;++s){for(var c,d=this.getHashValueAt(s),p=!0,f=0,m=r.length;f<m;++f){var h,S=a[h=r[f]],A=d[h],T=Math.abs(A-S);if(!(T<=o[h])){p=!1;break}c+=Math.sqr(T/n[h])}p&&(u.index<0||u.distanceSqr>c)&&(u.index=s,u.distanceSqr=c)}return u.index},getDataValueFromIndependent:function(e,t){var a=this.getDataItemIndexFromIndependent(e,t);return a>=0?this.getValueAt(a):null},calcValueFromIndependent:function(e,t){var a={};return a="number"==typeof e?this._convArrayToSymboledHash([e],this.getLocalVarSymbolsOfDependency(Kekule.VarDependency.INDEPENDENT)):DataType.isArrayValue(e)?this._convArrayToSymboledHash(e,this.getLocalVarSymbolsOfDependency(Kekule.VarDependency.INDEPENDENT)):e,this.doCalcValueFromIndependent(a,t)},doCalcValueFromIndependent:function(e,t){return this.getMode()===Kekule.Spectroscopy.DataMode.PEAK?this._doCalcValueFromIndependentInPeakMode(e,t):this._doCalcValueFromIndependentInContinousMode(e,t)},_doCalcValueFromIndependentInPeakMode:function(e,t){var a=this.getDataItemIndexFromIndependent(e,t);return a>=0?this.getHashValueAt(a):this.getPeakRootValueOf(e)},_doCalcValueFromIndependentInContinousMode:function(e,t){var a=this._doCalcValueFromIndependentInContinousModeEx(e,t);return a&&a.value},_doCalcValueFromIndependentInContinousModeEx:function(e,t){var a=this.getLocalVarSymbolsOfDependency(Kekule.VarDependency.INDEPENDENT),r=this.getLocalVarSymbolsOfDependency(Kekule.VarDependency.DEPENDENT);if(a.length>1)return null;var n,i=a[0],o=e[i],s=this.calcDataRange([i])[i];if(o<s.min||o>s.max)return null;var l=-1,u=-1,c=!0,d=this.getLocalVarDef(i),p=this.getDataCount();if(c=!d.hasDifferentExternalUnit()){var f=this.getContinuousVarRange(i);c=!!f}if(c){var m=(o-f.fromValue)/(f.toValue-f.fromValue)*(p-1);l=Math.max(Math.floor(m),0),u=Math.min(Math.ceil(m),p-1)}else{var h=this.getIndependentVarValueOrder(i);if(0===h);else{var S=h<0,A=this._calcNeighborDataIndexesToIndependentValue(i,o,0,p-1,S);l=A[0],u=A[1]}}if(l<0||u<0)return null;if(l===u)n=this.getHashValueAt(l);else{var T=this._calcIntermediateDependentVarValuesBetween(r,i,o,l,u);(n={})[i]=o,n=Object.extend(n,T)}return{value:n,dataIndexes:[l,u]}},_calcNeighborDataIndexesToIndependentValue:function(e,t,a,r,n){if(r-a<=2)return[a,r];var i=Math.round((a+r)/2),o=this.getHashValueAt(i)[e];return o===t?[i,i]:o<=t?n?this._calcNeighborDataIndexesToIndependentValue(e,t,a,i,n):this._calcNeighborDataIndexesToIndependentValue(e,t,i,r,n):n?this._calcNeighborDataIndexesToIndependentValue(e,t,i,r,n):this._calcNeighborDataIndexesToIndependentValue(e,t,a,i,n)},_calcIntermediateDependentVarValuesBetween:function(e,t,a,r,n){if(r===n){for(var i=this.getHashValueAt(r),o={},s=0,l=e.length;s<l;++s)o[e[s]]=i[e[s]];return o}var u=this.getHashValueAt(r),c=this.getHashValueAt(n),d=u[t],p=c[t];if(Kekule.NumUtils.isNormalNumber(d)){if(Kekule.NumUtils.isNormalNumber(p)){var f=(a-u[t])/(c[t]-u[t]);for(o={},s=0,l=e.length;s<l;++s){var m=e[s],h=u[m],S=c[m],A=!1;A=Kekule.NumUtils.isNormalNumber(h)?Kekule.NumUtils.isNormalNumber(S)?h+(S-h)*f:n<this.getDataCount()-1?this._calcIntermediateDependentVarValuesBetween([m],t,a,r,n+1):h[m]:r>0?this._calcIntermediateDependentVarValuesBetween([m],t,a,r-1,n):S[m],o[m]=A}return o}return n<this.getDataCount()-1?this._calcIntermediateDependentVarValuesBetween(e,t,a,r,n+1):this._calcIntermediateDependentVarValuesBetween(e,t,a,r,r)}return r>0?this._calcIntermediateDependentVarValuesBetween(e,t,a,r-1,n):this._calcIntermediateDependentVarValuesBetween(e,t,a,n,n)},calcValueRangeFromIndependentRangeEx:function(e,t){var a={};return a=DataType.isArrayValue(e)?this._convArrayToSymboledHash(e,this.getLocalVarSymbolsOfDependency(Kekule.VarDependency.INDEPENDENT)):e,this.doCalcValueRangeFromIndependentRangeEx(a,t)},doCalcValueRangeFromIndependentRangeEx:function(e,t){for(var a=this.getLocalVarSymbolsOfDependency(Kekule.VarDependency.INDEPENDENT),r=this.getLocalVarSymbolsOfDependency(Kekule.VarDependency.DEPENDENT),n=this.calcDataRange(a),i=(t&&t.findNearest,{}),o={},s=0,l=a.length;s<l;++s){var u=a[s];if(e[u]){var c=Object.extend({},e[u]),d=n[u];c.min<d.min&&(c.min=d.min),c.max>d.max&&(c.max=d.max),i[u]=c,o[u]=(c.min+c.max)/2}}var p=this.getMode()===Kekule.Spectroscopy.DataMode.PEAK?this._doCalcValueRangeFromIndependentRangeInPeakModeEx(i,o,a,r,t):this._doCalcValueRangeFromIndependentRangeInContinousModeEx(i,o,a,r,t);return p&&p.range&&Kekule.ObjUtils.getOwnedFieldNames(p.range)<=0&&(p.range=null),p},_doCalcValueRangeFromIndependentRangeInPeakModeEx:function(e,t,a,r,n){var i,o,s,l,u=!!t,c={dataIndexes:[],dataValues:[],range:{}};n.findInReversedOrder?(o=this.getDataCount()-1,s=0,l=-1):(o=0,s=this.getDataCount()-1,l=1);for(var d=o;n.findInReversedOrder?d>=s:d<=s;d+=l){for(var p=this.getHashValueAt(d),f=!0,m=0,h=0,S=a.length;h<S;++h){var A=a[h];if(!(f=p[A]>=e[A].min&&p[A]<=e[A].max))break;u&&(m+=Math.sqr(p[A]-t[A]))}f&&(c.dataIndexes.push(d),c.dataValues.push(p),u&&(void 0===i||m<i)&&(i=m,c.nearest={dataIndex:d,dataValue:p}))}return c.range=Kekule.Spectroscopy.Utils.expandDataRange(c.range,c.dataValues),c},_doCalcValueRangeFromIndependentRangeInContinousModeEx:function(e,t,a,r,n){if(a.length>1)return null;var i=a[0],o=e[i],s={},l={};s[i]=o.min,l[i]=o.max;var u=this._doCalcValueFromIndependentInContinousModeEx(s,n),c=this._doCalcValueFromIndependentInContinousModeEx(l,n);if(!u||!c)return null;var d=u.dataIndexes[0]>c.dataIndexes[0],p={};d?(p.fromIndex=c.dataIndexes[1],p.toIndex=u.dataIndexes[0]):(p.fromIndex=u.dataIndexes[1],p.toIndex=c.dataIndexes[0]);for(var f={range:{},dataIndexes:[],dataValues:[]},m=p.fromIndex;m<=p.toIndex;++m){var h=this.getHashValueAt(m);f.dataValues.push(h),f.dataIndexes.push(m),f.range=Kekule.Spectroscopy.Utils.expandDataRange(f.range,h)}return f.range=Kekule.Spectroscopy.Utils.expandDataRange(f.range,[u.value,c.value]),d?(f.dataValues.push(u.value),f.dataValues.unshift(c.value)):(f.dataValues.push(c.value),f.dataValues.unshift(u.value)),f.dataIndexes.push(-1),f.dataIndexes.unshift(-1),f},getIterator:function(){return this.doGetIterator()},doGetIterator:function(){var e=this.getDataItems(),t=this;return{index:0,next:function(a){if(this.index>=e.length)return{done:!0};var r={done:!1,value:t.getHashValueAt(this.index,a)};return++this.index,r}}},forEach:function(e,t,a){var r=this.getIterator();if(r)for(var n=0,i=r.next(a);!i.done;)e.apply(t,[i.value,n]),++n,i=r.next();return this},getComparisonPropNames:function(e){var a=this.tryApplySuper("getComparisonPropNames",[e]);return a&&(a=t.exclude(a,["parent","owner"]),t.pushUnique(a,"dataItems")),a},doGetComparisonPropNames:function(e){var t=this.tryApplySuper("doGetComparisonPropNames",[e]);return e.method===Kekule.ComparisonMethod.CHEM_STRUCTURE&&(t=(t||[]).concat("defPeakRoot","localVarInfos","mode","dataItems")),t},doCompareProperty:function(e,t,a){return"dataItems"===t?this.doCompareDataItems(this,e,a):"localVarInfos"===t?this.doCompareLocalVarInfos(this,e,a):this.tryApplySuper("doCompareProperty",[e,t,a])},doCompareLocalVarInfos:function(e,t,a){var r=e.getActualLocalVarInfos(),n=t.getActualLocalVarInfos(),i=r.length-n.length;if(!i&&a.method!==Kekule.ComparisonMethod.CHEM_STRUCTURE)for(var o=0,s=r.length;o<s;++o){var l=r[o],u=n[o];if(i=Kekule.ObjComparer.compare(l,u,a))break}if(!i)for(o=0,s=r.length;o<s;++o){var c=e.getLocalVarDef(o),d=e.getLocalVarDef(o);if(i=this.doCompareOnValue(c,d,a))break}return i},doCompareDataItems:function(e,t,a){var r=function(e,t){var a=e.getHashValueAt(t);return e._itemHashToArray(a)},n=e.getDataCount()-t.getDataCount();if(!n)for(var i=0,o=e.getDataCount();i<o;++i){var s=r(e,i),l=r(e,i);if(!(n=this._compareDataRawValue(s,l,a))){var u=e.getExtraInfoAt(i)||null,c=t.getExtraInfoAt(i)||null;u&&u.isEmpty()&&(u=null),c&&c.isEmpty()&&(c=null),n=this.doCompareOnValue(u,c,a)}if(n)break}return n},_compareDataRawValue:function(e,t,a){var r;if(!e&&!t)return 0;if(e&&!t)return 1;if(!e&&t)return-1;if(!(r=(e.length||-1)-(t.length||-1)))for(var n=Kekule.NumUtils,i=a.allowedComparisonErrorRate||Kekule.globalOptions.spectrum.data.allowedComparisonErrorRate||5e-8,o=0,s=e.length;o<s;++o){var l=e[o],u=t[o];if(r=n.isNormalNumber(l)&&n.isNormalNumber(u)?n.isFloatEqual(l,u,Math.abs(l*i))?0:Math.sign(l-u):this.doCompareOnValue(e,t,a))break}return r}}),Kekule.Spectroscopy.SpectrumData=Class.create(ObjectEx,{CLASS_NAME:"Kekule.Spectroscopy.SpectrumData",initialize:function(e,a,r){this.tryApplySuper("initialize",[e]),this.setPropStoreFieldValue("variables",a?t.clone(a):[]);var n=new Kekule.ChemObjList(null,Kekule.Spectroscopy.SpectrumDataSection,!0);this.setPropStoreFieldValue("sections",n),this.setParent(r),n.setOwner(this.getOwner())},doFinalize:function(){this.getSections().finalize();for(var e=this.getVariables()||[],t=0,a=e.length;t<a;++t)e[t].finalize();this.setPropStoreFieldValue("variables",null),this.tryApplySuper("doFinalize")},initProperties:function(){this.defineProp("owner",{dataType:"Kekule.ChemSpace",serializable:!1,scope:Class.PropertyScope.PUBLIC,getter:function(){return this.getPropStoreFieldValue("owner")||this._getDefaultOwner()},setter:function(e){if(e!==this.getPropStoreFieldValue("owner")){this.setPropStoreFieldValue("owner",e);var t=this.getOwner(),a=this.getSections();a&&a.setOwner(t)}}}),this.defineProp("parent",{dataType:"Kekule.Spectroscopy.Spectrum",serializable:!1,setter:function(e){this.setPropStoreFieldValue("parent",e);var t=this.getSections();t&&t.setParent(this.getParent()||this)}}),this.defineProp("sections",{dataType:"Kekule.ChemObjList",setter:function(e){var t=this.getSections();t!==e&&(t&&t.finalize(),e&&(e._transparent=!0,e.setParent(this.getParent()||this),e.setOwner(this.getOwner())),this.setPropStoreFieldValue("sections",e))}}),this.defineProp("autoCreateSection",{dataType:DataType.BOOL}),this.defineProp("activeSectionIndex",{dataType:DataType.INT,getter:function(){return this.getSectionCount()<=0?-1:1===this.getSectionCount()?0:this.getPropStoreFieldValue("activeSectionIndex")},setter:function(e){e>=0&&e<=this.getSectionCount()&&this.setPropStoreFieldValue("activeSectionIndex",e)}}),this.defineProp("activeSection",{dataType:"Kekule.Spectroscopy.SpectrumDataSection",serializable:!1,getter:function(){var e=this.getSectionAt(this.getActiveSectionIndex()||0);return!e&&this.getSectionCount()<=0&&this.getAutoCreateSection()&&(e=this.createSection(this.getVariables())),e},setter:function(e){this.setActiveSectionIndex(this.indexOfSection(e))}}),this.defineProp("variables",{dataType:DataType.ARRAY}),this.defineProp("varSymbols",{dataType:DataType.ARRAY,setter:null,scope:e.PRIVATE,getter:function(){for(var e=[],t=this.getVariables()||[],a=0,r=t.length;a<r;++a){var n=t[a];e.push(n.getSymbol())}return e}}),this.defineProp("mode",{dataType:DataType.INT,enumSource:Kekule.Spectroscopy.DataMode})},initPropValues:function(){this.tryApplySuper("initPropValues"),this.setAutoCreateSection(!0),this.setMode(Kekule.Spectroscopy.DataMode.CONTINUOUS)},_getDefaultOwner:function(){var e=this.getParent();return e&&e.getOwner&&e.getOwner()},getHigherLevelObj:function(){return this.getParent()},getChildHolder:function(){return this.getSections()},loaded:function(e){var t=this.getSections();t&&(t.parentChanged(this),t.ownerChanged(this.getOwner())),this.tryApplySuper("loaded",[e])},isEmpty:function(){for(var e=0,t=this.getSectionCount();e<t;++e)if(!this.getSectionAt(e).isEmpty())return!1;return!0},createSection:function(e,t){var a=new Kekule.Spectroscopy.SpectrumDataSection(void 0,this,e);return a.setMode(t||this.getMode()),this.getSections().appendChild(a),a},clearSection:function(){for(var e=this.getChildren(),t=0,a=e.length;t<a;++t)e[t].clear(),e[t].setParent(null),e[t].finalize();this.getSections().clear()},getSectionCount:function(){return this.getSections().getChildCount()},getSectionAt:function(e){return this.getSections().getItemAt(e)},indexOfSection:function(e){return this.getSections().indexOfItem(e)},hasSection:function(e){return this.indexOfSection(e)>=0},removeSectionAt:function(e){return this.getSections().removeItemAt(e)},removeSection:function(e){return this.getSections().removeItem(e)},insertSectionAt:function(e,t){return this.getSections().insertItemAt(e,t)},insertSectionBefore:function(e,t){return this.getSections().insertItemBefore(e,t)},appendSection:function(e){return this.getSections().appendChild(e)},hasMultipleSections:function(){return this.getSections().getChildCount()>1},calcDataRangeOfSection:function(e,t){return e.calcDataRange(t)},calcDataRangeOfSections:function(e,t,a){for(var r={},n=0,i=e.length;n<i;++n){var o=e[n].calcDataRange(t,a);r=Kekule.Spectroscopy.Utils.mergeDataRange(r,o)}return r},getDisplayRangeOfSection:function(e,t,a){return e.getDisplayRangeOfVars(t,a)},getDisplayRangeOfSections:function(e,t,a){for(var r={},n=0,i=e.length;n<i;++n){var o=e[n].getDisplayRangeOfVars(t,a);r=Kekule.Spectroscopy.Utils.mergeDataRange(r,o)}return r},getVariableCount:function(){return(this.getVariables()||[]).length},getVariable:function(e){return e instanceof Kekule.VarDefinition?e:"number"==typeof e?this.getVariables()[e]:this.getVariables()[this.getVarSymbols().indexOf(e)]},indexOfVariable:function(e){return this.getVariables().indexOf(e)},insertVariableAt:function(e,t){return t>=0?this.getVariables().splice(t,0,e):this.getVariables().push(e),this},insertVariableBefore:function(e,t){var a=t?this.indexOfVarDefinition(t):-1;return this.insertVarDefinitionAt(e,a)},appendVariable:function(e){return this.insertVariableAt(e,-1)},removeVariableAt:function(e){return this.getVariables().splice(e,1),this},removeVariable:function(e){var t=this.indexOfVariable(e);return t>=0&&this.removeVariableAt(t),this},getVariablesOfDependency:function(e){for(var t=[],a=0,r=this.getVariableCount();a<r;++a){var n=this.getVariable(a);n&&n.getDependency()===e&&t.push(n)}return t},getContinuousVarRange:function(e){var t=this.getVariable(e),a=t&&t.getInfo();return a&&a.continuous?{fromValue:a.fromValue,toValue:a.toValue}:null},setContinuousVarRange:function(e,t,a){var r=this.getVariable(e),n=r&&r.getInfo(!0);return n.continuous=!0,n.fromValue=t,n.toValue=a,this},clearContinuousVarRange:function(e){var t=this.getVariable(e).getInfo();return t&&t.continuous&&(t.continuous=!1),this},setDefaultVarValue:function(e,t){var a=this.getVariable(e);return(a&&a.getInfo(!0)).defaultValue=t,this},clearDefaultVarValue:function(e){return this.setDefaultVarValue(e,null)},getDefaultVarValue:function(e){var t=this.getVariable(e),a=t&&t.getInfo();if(a)return a.defaultValue},iterateSections:function(e){for(var t=0,a=this.getSectionCount();t<a;++t)e(this.getSectionAt(t),t)},sort:function(e){this.iterateSections(function(t){t.sort(e)})},getDataCount:function(){var e=0;return this.iterateSections(function(t){e+=t.getDataCount()}),e},clearData:function(){this.iterateSections(function(e){e.clear()})},appendData:function(e){return this.getActiveSection().appendData(e)},removeData:function(e){return this.getActiveSection().removeData(e)},removeDataAt:function(e){return this.getActiveSection().removeDataAt(e)},getRawValueAt:function(e){return this.getActiveSection().getRawValueAt(e)},getHashValueAt:function(e){return this.getActiveSection().getHashValueAt(e)},getValueAt:function(e){return this.getHashValueAt(e)},setRawValueAt:function(e,t){return this.getActiveSection().setRawValueAt(e,t),this},setHashValueAt:function(e,t,a){return this.getActiveSection().setHashValueAt(e,t,a),this},setValueAt:function(e,t,a){return this.getActiveSection().setValueAt(e,t),this},getExtraInfoOf:function(e){return this.getActiveSection().getExtraInfoOf(e)},setExtraInfoOf:function(e,t){return this.getActiveSection().setExtraInfoOf(e,t),this},getExtraInfoAt:function(e){return this.getActiveSection().getExtraInfoAt(e)},setExtraInfoAt:function(e,t){return this.getActiveSection().setExtraInfoAt(e,t),this},getIterator:function(){return this.doGetIterator()},doGetIterator:function(){var e=this.getSections().getItems();return{sectionIndex:0,index:0,next:function(){var t=this,a=function(){return t.sectionIndex>=e.length||t.sectionIndex===e.length-1&&t.index>=e[e.length-1].getDataCount()};if(a())return{done:!0};if(!(this.index<e[this.sectionIndex].getDataCount())){do{++this.sectionIndex,this.index=0}while(this.index>=e[this.sectionIndex].getDataCount()||t.sectionIndex>=e.length);return a()?{done:!0}:{done:!1,value:e[this.sectionIndex].getValueAt(this.index)}}var r={done:!1,value:e[this.sectionIndex].getValueAt(this.index)};return++this.index,r}}},forEach:function(e,t){var a=this.getIterator();if(a)for(var r=0,n=a.next();!n.done;)e.apply(t,[n.value,r]),++r,n=a.next();return this}}),Kekule.Spectroscopy.PeakShape={SHARP:"sharp",BROAD:"broad"},Kekule.Spectroscopy.PeakMultiplicity={UNKNOWN:0,SINGLET:1,DOUBLET:2,TRIPLET:3,QUARTET:4,QUINTET:5,SEXTUPLET:6,DOUBLE_DOUBLET:22,TRIPLE_DOUBLET:32,MULTIPLET:255},Kekule.Spectroscopy.SpectrumDataDetails=Class.create(Kekule.ChemObject,{CLASS_NAME:"Kekule.Spectroscopy.SpectrumDataDetails",initialize:function(e){this.setPropStoreFieldValue("assignments",[]),this.tryApplySuper("initialize",[]),this.setPropValues(e)},initProperties:function(){this.defineProp("assignments",{dataType:DataType.ARRAY,objRef:!0,autoUpdate:!0,setter:function(e){var a=e?DataType.isArrayValue(e)?t.clone(e):t.toArray(e):[];this.setPropStoreFieldValue("assignments",a)}}),this.defineProp("assignment",{dataType:"Kekule.ChemObject",serializable:!1,scope:Class.PropertyScope.PUBLIC,getter:function(){return(this.getAssignments()||[])[0]},setter:function(e){this.setAssignments(e)}})},doFinalize:function(){this.setPropStoreFieldValue("assignments",null),this.tryApplySuper("doFinalize")},getAutoIdPrefix:function(){return"d"},isEmpty:function(){var e=this.getAssignments();return!e||!e.length},hasAssignments:function(){var e=this.getAssignments();return!(!e||!e.length)},doGetComparisonPropNames:function(e){var t=this.tryApplySuper("doGetComparisonPropNames",[e]);return e.method===Kekule.ComparisonMethod.CHEM_STRUCTURE&&(t=t||[]).unshift("assignments"),t}}),Kekule.Spectroscopy.SpectrumPeakDetails=Class.create(Kekule.Spectroscopy.SpectrumDataDetails,{CLASS_NAME:"Kekule.Spectroscopy.SpectrumPeakDetails",initProperties:function(){this.defineProp("shape",{dataType:DataType.STRING}),this.defineProp("multiplicity",{dataType:DataType.VARIANT})},getAutoIdPrefix:function(){return"p"},isEmpty:function(){var e=this.tryApplySuper("isEmpty");return e=e&&!this.getShape()&&Kekule.ObjUtils.isUnset(this.getMultiplicity())},doGetComparisonPropNames:function(e){var t=this.tryApplySuper("doGetComparisonPropNames",[e]);return e.method===Kekule.ComparisonMethod.CHEM_STRUCTURE&&((t=t||[]).unshift("shape"),t.unshift("multiplicity")),t}}),Kekule.Spectroscopy.SpectrumType={NMR:"NMR",IR:"IR",MS:"MS",UV_VIS:"UV_VIS",IMS:"IMS",RAMAN:"Raman",CHROMATOGRAPHY:"chromatography",GENERAL:"general"},Kekule.Spectroscopy.SpectrumNMR={TargetNucleus:{C13:"C13",H:"H"}},Kekule.Spectroscopy.Spectrum=Class.create(Kekule.ChemObject,{CLASS_NAME:"Kekule.Spectroscopy.Spectrum",initialize:function(e){this.setPropStoreFieldValue("data",new Kekule.Spectroscopy.SpectrumData(null,null,this)),this.tryApplySuper("initialize",[e]),this._initDelegatedMethods()},doFinalize:function(){this.setPropStoreFieldValue("refMolecules",null);var e=this.getData();e&&e.finalize(),this.tryApplySuper("doFinalize")},initProperties:function(){this.defineProp("spectrumType",{dataType:DataType.STRING}),this.defineProp("name",{dataType:DataType.STRING}),this.defineProp("data",{dataType:"Kekule.Spectroscopy.SpectrumData",setter:function(e){var t=this.getData();e!==t&&(t&&t.finalize(),e&&e.setPropValue("parent",this,!0),this.setPropStoreFieldValue("data",e))}}),this.defineProp("refMolecules",{dataType:DataType.ARRAY,objRef:!0,autoUpdate:!0,setter:function(e){var a=e?DataType.isArrayValue(e)?t.clone(e):t.toArray(e):[];this.setPropStoreFieldValue("refMolecules",a)}}),this.defineProp("refMolecule",{dataType:"Kekule.Molecule",serializable:!1,scope:Class.PropertyScope.PUBLIC,getter:function(){return(this.getRefMolecules()||[])[0]},setter:function(e){this.setrRefMolecules(e)}}),this._defineInfoProperty("title"),this._defineInfoProperty("metaData",null,{dataType:DataType.HASH}),this._defineInfoProperty("conditions",null,{dataType:DataType.HASH}),this._defineInfoProperty("parameters",null,{dataType:DataType.HASH}),this._defineInfoProperty("annotations",null,{dataType:DataType.HASH}),this._defineDataDelegatedProperty("variables"),this._defineDataDelegatedProperty("varSymbols"),this._defineDataDelegatedProperty("dataSections","sections"),this._defineDataDelegatedProperty("activeDataSectionIndex","activeSectionIndex"),this._defineDataDelegatedProperty("activeDataSection","activeSection")},_initDelegatedMethods:function(){this._defineDataDelegatedMethod("isEmpty"),this._defineDataDelegatedMethod("createDataSection","createSection"),this._defineDataDelegatedMethod("clearDataSection","clearSection"),this._defineDataDelegatedMethod("getDataSectionCount","getSectionCount"),this._defineDataDelegatedMethod("getDataSectionAt","getSectionAt"),this._defineDataDelegatedMethod("indexOfDataSection","indexOfSection"),this._defineDataDelegatedMethod("hasDataSection","hasSection"),this._defineDataDelegatedMethod("removeDataSectionAt","removeSectionAt"),this._defineDataDelegatedMethod("removeDataSection","removeSection"),this._defineDataDelegatedMethod("insertDataSectionAt","insertSectionAt"),this._defineDataDelegatedMethod("insertDataSectionBefore","insertSectionBefore"),this._defineDataDelegatedMethod("appendDataSection","appendSection"),this._defineDataDelegatedMethod("iterateDataSection","iterateSection"),this._defineDataDelegatedMethod("sortData","sort"),this._defineDataDelegatedMethod("clearData"),this._defineDataDelegatedMethod("getVariableCount"),this._defineDataDelegatedMethod("getVariable"),this._defineDataDelegatedMethod("indexOfVariable"),this._defineDataDelegatedMethod("insertVariableAt"),this._defineDataDelegatedMethod("insertVariableBefore"),this._defineDataDelegatedMethod("appendVariable"),this._defineDataDelegatedMethod("removeVariableAt"),this._defineDataDelegatedMethod("removeVariable"),this._defineDataDelegatedMethod("getVariablesOfDependency"),this._defineDataDelegatedMethod("getContinuousVarRange"),this._defineDataDelegatedMethod("setContinuousVarRange"),this._defineDataDelegatedMethod("clearContinuousVarRange"),this._defineDataDelegatedMethod("getDefaultVarValue"),this._defineDataDelegatedMethod("setDefaultVarValue"),this._defineDataDelegatedMethod("clearDefaultVarValue")},_defineInfoProperty:function(e,t,a){var r,n,i;return i=(n=t||e).upperFirst(),r=Object.extend({getter:function(){return this.getInfoValue(n)||this.getInfoValue(i)},setter:function(e){this.setInfoValue(n,e)},serializable:!1},a),this.defineProp(e,r)},_defineDataDelegatedProperty:function(e,t){t||(t=e);var a=ClassEx.getPropInfo(Kekule.Spectroscopy.SpectrumData,t),r=Object.create(a);return r.getter=null,r.setter=null,r.serializable=!1,a.getter&&(r.getter=function(){return this.getData().getPropValue(t)}),a.setter&&(r.setter=function(e){this.getData().setPropValue(t,e)}),this.defineProp(e,r)},_defineDataDelegatedMethod:function(e,t){t||(t=e),ClassEx.getPrototype(this.getClass())[e]=function(){var e=this.getData(),a=e[t].apply(e,arguments);return a===e&&(a=this),a}},getAutoIdPrefix:function(){return"s"},ownerChanged:function(e,t){var a=this.getData();a&&a.setOwner(e),this.tryApplySuper("ownerChanged",[e,t])},isEmpty:function(){if(this.getDataSectionCount()<=0)return!0;for(var e=0,t=this.getDataSectionCount();e<t;++e)if(!this.getDataSectionAt(e).isEmpty())return!1;return!0},getChildSubgroupNames:function(){return["dataSection"].concat(this.tryApplySuper("getChildSubgroupNames"))},getBelongChildSubGroupName:function(e){return e instanceof Kekule.Spectroscopy.SpectrumDataSection?"dataSection":this.tryApplySuper("getBelongChildSubGroupName",[e])},doGetChildCount:function(){return this.getDataSectionCount()},doGetChildAt:function(e){return this.getDataSectionAt(e)},doIndexOfChild:function(e){return this.indexOfDataSection(e)},_getCandidateInfoPropNames:function(e){if(e.indexOf(r.DELIMITER)>=0)return[e];var t=r.getNamespaces(),a=this.getSpectrumType();a&&(t=[a].concat(t));for(var n=[e],i=0,o=t.length;i<o;++i)n.push(t[i]+r.DELIMITER+e);return n},_getSpectrumInfoValueOfCategory:function(e,t){var a=e?this.getInfoValue(e):this.getInfo();if(a){if(!Kekule.globalOptions.spectrum.spectrumInfo.enablePrefixOmissionInGetter)return a[t];for(var r=this._getCandidateInfoPropNames(t),n=0,i=r.length;n<i;++n){var o=r[n];if(void 0!==a[o])return a[o]}}},setSpectrumInfoValue:function(e,t,a){if(e){var r=this.getInfoValue(e);r||(r={},this.setInfoValue(e,r)),r[t]=a}else this.setInfoValue(t,a);return this},getSpectrumInfoKeysOfCategory:function(e){if(e){var a=this.getInfoValue(e);return a?Kekule.ObjUtils.getOwnedFieldNames(a,!1):[]}if(""===e){var r=this.getInfoKeys();return r=t.exclude(r,this.getSpectrumInfoCategories())}return[]},getSpectrumInfoCategories:function(){for(var e=["metaData","conditions","parameters","annotations"],t=[],a=0,r=e.length;a<r;++a){var n=e[a],i=this.getSpectrumInfoKeysOfCategory(n);i&&i.length&&t.push(n)}return t},getSpectrumInfoValue:function(e,a){for(var r,n=0,i=(r=a?t.toArray(a):["conditions","parameters","metaData","annotations",""]).length;n<i;++n){var o=r[n],s=this._getSpectrumInfoValueOfCategory(o,e);if(Kekule.ObjUtils.notUnset(s))return s}},getMeta:function(e){return this._getSpectrumInfoValueOfCategory("metaData",e)},setMeta:function(e,t){return this.setSpectrumInfoValue("metaData",e,t),this},getMetaKeys:function(){return this.getSpectrumInfoKeysOfCategory("metaData")},getCondition:function(e){return this._getSpectrumInfoValueOfCategory("conditions",e)},setCondition:function(e,t){return this.setSpectrumInfoValue("conditions",e,t),this},getConditionKeys:function(){return this.getSpectrumInfoKeysOfCategory("conditions")},getParameter:function(e){return this._getSpectrumInfoValueOfCategory("parameters",e)},setParameter:function(e,t){return this.setSpectrumInfoValue("parameters",e,t),this},getParameterKeys:function(){return this.getSpectrumInfoKey