kekule
Version:
Open source JavaScript toolkit for chemoinformatics
1 lines • 228 kB
JavaScript
!function(){var e=Kekule,t=Kekule.ChemStructureNodeLabels,r=Kekule.CoordMode;ClassEx.extend(Kekule.ChemObject,{getDefCoordPos:function(e){return Kekule.Render.CoordPos.CENTER},getCoordPos:function(e){var t=e===Kekule.CoordMode.COORD3D?this.getPropStoreFieldValue("coordPos3D"):this.getPropStoreFieldValue("coordPos2D");return Kekule.ObjUtils.isUnset(t)&&(t=this.getDefCoordPos(e)),t},getOverrideRenderOptions:function(e){if(e&&e.length){for(var t={},r=0,n=e.length;r<n;++r)t=Object.extend(t,e[r]);return t}return null},_appendOverrideRenderOptionItem:function(e,t){var r=this.getPropStoreFieldValue(t);r||(r=[],this.setPropStoreFieldValue(t,r));var n=r.indexOf(e);return n>=0&&r.splice(n,1),r.push(e),this.notifyPropSet(t,r),this},_deleteOverrideRenderOptionItem:function(e,t){var r=this.getPropStoreFieldValue(t);if(r){var n=r.indexOf(e);return n>=0&&(r.splice(n,1),this.notifyPropSet(t,r)),this}},addOverrideRenderOptionItem:function(e){return this._appendOverrideRenderOptionItem(e,"overrideRenderOptionItems")},addOverrideRender3DOptionItem:function(e){return this._appendOverrideRenderOptionItem(e,"overrideRender3DOptionItems")},removeOverrideRenderOptionItem:function(e){return this._deleteOverrideRenderOptionItem(e,"overrideRenderOptionItems")},removeOverrideRender3DOptionItem:function(e){return this._deleteOverrideRenderOptionItem(e,"overrideRender3DOptionItems")},getOverriddenRenderOptions:function(){var e=this.getRenderOptions()||{},t=this.getOverrideRenderOptions(this.getOverrideRenderOptionItems());return t&&(e=Object.extend(e,t)),e},getOverriddenRender3DOptions:function(){var e=Object.create(this.getRender3DOptions()||null),t=this.getOverrideRenderOptions(this.getOverrideRender3DOptionItems());return t&&(e=Object.extend(e,t)),e},setRenderOption:function(e,t){var r;(r=this.getRenderOptions())||this.setRenderOptions({}),(r=this.getRenderOptions())[e]!==t&&(r[e]=t,this.notifyPropSet("renderOptions",r))},setRender3DOption:function(e,t){var r;(r=this.getRender3DOptions())||this.setRender3DOptions({}),(r=this.getRender3DOptions())[e]!==t&&(r[e]=t,this.notifyPropSet("render3DOptions",r))},getRenderOption:function(e){var t=this.getOverriddenRenderOptions();return t?t[e]:void 0},getRender3DOption:function(e){var t=this.getOverriddenRender3DOptions();return t?t[e]:void 0},getCascadedRenderOption:function(e){var t=this.getOverriddenRenderOptions(),r=t?t[e]:void 0;if(Kekule.ObjUtils.isUnset(r)){var n=this.getParent?this.getParent():null;r=n&&n.getCascadedRenderOption?n.getCascadedRenderOption(e):void 0}return r},getCascadedRender3DOption:function(e){var t=this.getOverriddenRender3DOptions(),r=t?t[e]:void 0;if(Kekule.ObjUtils.isUnset(r)){var n=this.getParent?this.getParent():null;r=n&&n.getCascadedRender3DOption?n.getCascadedRender3DOption(e):void 0}return r},getBaseCoord:function(e,t){var n=this.getCoordPos(e),o=this.getCoordOfMode?this.getCoordOfMode(e,t):null;if(o&&n!==Kekule.Render.CoordPos.CENTER&&n===Kekule.Render.CoordPos.CORNER_TL){var i=this.getExposedContainerBox(e,t),a={x:(i.x2-i.x1)/2,y:(i.y2-i.y1)/2};e===r.COORD3D&&(a.z=(i.z2-i.z1)/2),e===r.COORD3D?o=Kekule.CoordUtils.add(o,a):(o.x+=a.x,o.y-=a.y)}return o},getBaseCoord2D:function(e){return this.getBaseCoord(Kekule.CoordMode.COORD2D,e)},getBaseCoord3D:function(e){return this.getBaseCoord(Kekule.CoordMode.COORD3D,e)},getAbsBaseCoord:function(e,t){var n=this.getCoordPos(e),o=this.getAbsCoordOfMode?this.getAbsCoordOfMode(e,t):null;if(o&&n!==Kekule.Render.CoordPos.CENTER&&n===Kekule.Render.CoordPos.CORNER_TL){var i=this.getExposedContainerBox(e,t),a={x:(i.x2-i.x1)/2,y:(i.y2-i.y1)/2};e===r.COORD3D&&(a.z=(i.z2-i.z1)/2),e===r.COORD3D?o=Kekule.CoordUtils.add(o,a):(o.x+=a.x,o.y-=a.y)}return o},getAbsBaseCoord2D:function(e){return this.getAbsBaseCoord(Kekule.CoordMode.COORD2D,e)},getAbsBaseCoord3D:function(e){return this.getAbsBaseCoord(Kekule.CoordMode.COORD3D,e)},setAbsBaseCoord:function(e,t,n){var o=this.getCoordPos(t),i=Kekule.CoordUtils.clone(e);if(e&&o!==Kekule.Render.CoordPos.CENTER&&o===Kekule.Render.CoordPos.CORNER_TL){var a=this.getExposedContainerBox(t,n),s={x:(a.x2-a.x1)/2,y:(a.y2-a.y1)/2};t===r.COORD3D&&(s.z=(a.z2-a.z1)/2),t===r.COORD3D?i=Kekule.CoordUtils.substract(i,s):(i.x-=s.x,i.y+=s.y)}return this.setAbsCoordOfMode?this.setAbsCoordOfMode(i,t):this.setCoordOfMode&&this.setCoordOfMode(i,t),this},setAbsBaseCoord2D:function(e,t){return this.setAbsCoordOfMode(e,Kekule.CoordMode.COORD2D,t)},setAbsBaseCoord3D:function(e,t){return this.setAbsCoordOfMode(e,Kekule.CoordMode.COORD3D,t)},getExposedAncestor:function(){var e=this.getParent();return e?e.isExpanded()?this:e.getExposedAncestor():this},isExposed:function(){var e=this.getParent();return!e||e.isExpanded()},isExpanded:function(){return!0},setExpanded:function(e){},getLinkedExposedObjs:function(){for(var e=[],t=0,r=this.getLinkedConnectorCount();t<r;++t){var n=this.getLinkedConnectorAt(t);if(n.isExposed())for(var o=n.getConnectedExposedObjs(),i=0,a=o.length;i<a;++i)o[i]!==this&&Kekule.ArrayUtils.pushUnique(e,o[i])}return e},getExposedContainerBox:function(e,t){return this.getContainerBox(e,t)},getAllAutoScaleRefLengths:function(e,t){return[]},getAllContainingConnectors:function(){return this.getAllChildConnectors?this.getAllChildConnectors():[]},getConnectorLengthMedian:function(e,t){var r=this.getAllContainingConnectors();return Kekule.ChemStructureUtils.getConnectorLengthMedian(r,e,t)}}),ClassEx.defineProps(Kekule.ChemObject,[{name:"coordPos2D",dataType:DataType.INT,scope:Class.PropertyScope.PUBLIC,getter:function(){return this.getCoordPos(Kekule.CoordMode.COORD2D)}},{name:"coordPos3D",dataType:DataType.INT,scope:Class.PropertyScope.PUBLIC,getter:function(){return this.getCoordPos(Kekule.CoordMode.COORD3D)}},{name:"renderOptions",dataType:DataType.OBJECT},{name:"render3DOptions",dataType:DataType.OBJECT},{name:"overrideRenderOptionItems",dataType:DataType.ARRAY,scope:Class.PropertyScope.PUBLIC,serializable:!1},{name:"overrideRender3DOptionItems",dataType:DataType.ARRAY,scope:Class.PropertyScope.PUBLIC,serializable:!1},{name:"hidden",dataType:DataType.BOOL,scope:Class.PropertyScope.PRIVATE},{name:"visible",dataType:DataType.BOOL,serializable:!1,getter:function(){return!this.getHidden()},setter:function(e){e?this.setHidden(void 0):this.setHidden(!0)}}]),ClassEx.extend(Kekule.ChemObjList,{getAllContainingConnectors:function(){for(var e=[],t=0,r=this.getItemCount();t<r;++t){var n=this.getItemAt(t);n.getAllContainingConnectors&&(e=e.concat(n.getAllContainingConnectors()))}return e},getAllAutoScaleRefLengths:function(e,t){for(var r=[],n=0,o=this.getItemCount();n<o;++n){var i=this.getItemAt(n);i.getAllAutoScaleRefLengths&&(r=r.concat(i.getAllAutoScaleRefLengths(e,t)))}return r},getExposedContainerBox:function(e,t){for(var r,n=this.toArray(),o=0,i=n.length;o<i;++o){var a=n[o];if(a.isExposed()){var s=a.getExposedContainerBox?a.getExposedContainerBox(e,t):a.getContainerBox?a.getContainerBox(e,t):null;s&&(r=r?Kekule.BoxUtils.getContainerBox(r,s):Kekule.BoxUtils.clone(s))}}return r}}),Kekule.ClassDefineUtils.addStandardCoordSupport(Kekule.ChemObjList),ClassEx.extend(Kekule.ChemSpaceElement,{getAllContainingConnectors:function(){return this.getChildren().getAllContainingConnectors()},getAllAutoScaleRefLengths:function(e,t){return this.getChildren().getAllAutoScaleRefLengths(e,t)}}),ClassEx.extend(Kekule.ChemSpace,{getAllContainingConnectors:function(){return this.getRoot().getAllContainingConnectors()},getAllAutoScaleRefLengths:function(e,t){return this.getDefAutoScaleRefLength()?[this.getDefAutoScaleRefLength()]:this.getRoot().getAllAutoScaleRefLengths(e,t)}}),ClassEx.defineProps(Kekule.ChemObject,[{name:"defAutoScaleRefLength",dataType:DataType.NUMBER,scope:Class.PropertyScope.PUBLIC}]),ClassEx.extend(Kekule.BaseStructureConnector,{getBaseCoord:function(e,t){for(var r=null,n=0,o=e===Kekule.CoordMode.COORD2D?{x:0,y:0}:{x:0,y:0,z:0},i=0,a=this.getConnectedObjCount();i<a;++i){var s=this.getConnectedObjAt(i),l=s.getBaseCoord?s.getBaseCoord(e,t):null;l&&(o=Kekule.CoordUtils.add(o,l),++n)}return n&&(r=Kekule.CoordUtils.divide(o,n)),r},getAbsBaseCoord:function(e,t){for(var r=null,n=0,o=e===Kekule.CoordMode.COORD2D?{x:0,y:0}:{x:0,y:0,z:0},i=0,a=this.getConnectedObjCount();i<a;++i){var s=this.getConnectedObjAt(i),l=s.getAbsBaseCoord?s.getAbsBaseCoord(e,t):null;l&&(o=Kekule.CoordUtils.add(o,l),++n)}return n&&(r=Kekule.CoordUtils.divide(o,n)),r},getAbsCoordOfMode:function(e,t){return this.getAbsBaseCoord(e,t)},getConnectedExposedObjs:function(){for(var e=this.getConnectedObjs(),t=[],r=0,n=e.length;r<n;++r){var o=e[r].getExposedAncestor();t.indexOf(o)<0&&t.push(o)}return t},getLength:function(e,t){var r=this.getConnectedObjs();if(2!==r.length)return null;var n=r[0].getAbsBaseCoord?r[0].getAbsBaseCoord(e,t):null,o=r[1].getAbsBaseCoord?r[1].getAbsBaseCoord(e,t):null;return Kekule.CoordUtils.getDistance(n,o)},getLength2D:function(e){return this.getLength(Kekule.CoordMode.COORD2D,e)},getLength3D:function(e){return this.getLength(Kekule.CoordMode.COORD3D,e)}}),ClassEx.defineProps(Kekule.BaseStructureConnector,[{name:"absCoord2D",dataType:DataType.HASH,serializable:!1,getter:function(e){return this.getAbsBaseCoord(Kekule.CoordMode.COORD2D,e)}},{name:"absCoord3D",dataType:DataType.HASH,serializable:!1,getter:function(e){return this.getAbsBaseCoord(Kekule.CoordMode.COORD3D,e)}}]),ClassEx.extend(Kekule.ChemStructureConnector,{getAllAutoScaleRefLengths:function(e,t){return[this.getLength(e,t)]}}),ClassEx.extend(Kekule.BaseStructureNode,{getBaseCoord:function(e,t){return this.getCoordOfMode(e,t)},getAbsBaseCoord:function(e,t){return this.getAbsCoordOfMode(e,t)},getExposedContainerBox:function(e,t){return this.getContainerBox(e,t)},getExposedContainerBox2D:function(e){var t=this.getExposedContainerBox(Kekule.CoordMode.COORD2D,e);return t.width=t.x2-t.x1,t.height=t.y2-t.y1,t},getExposedContainerBox3D:function(e){var t=this.getExposedContainerBox(Kekule.CoordMode.COORD3D,e);return t.deltaX=t.x2-t.x1,t.deltaY=t.y2-t.y1,t.deltaZ=t.z2-t.z1,t}}),ClassEx.extend(Kekule.ChemStructureNode,{getDisplayRichText:function(e,t,r,n,o,i){var a=Kekule.Render;Kekule.ObjUtils.isUnset(t)&&(t=!0);var s,l=a.RichTextUtils.create(),d=this.getRenderOption("customLabel");return(s=d?a.RichTextUtils.strToRichText(d):this.getCoreDisplayRichTextItem(e,t,r,n))&&(t&&(s=this.appendElectronStateDisplayText(s,n,o,i,r.getElectronicBiasMark())),s&&(a.RichTextUtils.append(l,s),l.anchorItem=s)),l},getCoreDisplayRichTextItem:function(e,t,r,n){return null},appendElectronStateDisplayText:function(e,t,r,n,o){var i=Kekule.Render,a=this.getCharge(),s=this.getElectronicBias&&this.getElectronicBias(),l=this.getRadical(),d=i.ChemDisplayTextUtils.createElectronStateDisplayTextSection(a,l,t,r,n,s,o);if(d){var u=i.RichTextUtils.createGroup();return i.RichTextUtils.append(u,e),i.RichTextUtils.append(u,d),u.charDirection=Kekule.Render.TextDirection.LTR,u.anchorItem=e,u}return e}}),ClassEx.extend(Kekule.AbstractAtom,{getDisplayRichText:function(e,t,r,n,o,i){var a=Kekule.Render;Kekule.ObjUtils.isUnset(e)&&(e=a.HydrogenDisplayLevel.DEFAULT);var s=this.tryApplySuper("getDisplayRichText",[e,t,r,n,o,i]),l=0;switch(e){case a.HydrogenDisplayLevel.NONE:l=0;break;case a.HydrogenDisplayLevel.ALL:l=this.getHydrogenCount();break;case a.HydrogenDisplayLevel.EXPLICIT:l=this.getExplicitHydrogenCount();break;case a.HydrogenDisplayLevel.UNMATCHED_EXPLICIT:this.getImplicitHydrogenCount&&this.getImplicitHydrogenCount()!==this.getExplicitHydrogenCount()&&(l=this.getExplicitHydrogenCount())}return l&&(s=this.appendHydrogenDisplayText(s,l)),s},appendHydrogenDisplayText:function(e,t){var r=Kekule.Render;if(t)if(t>1){var n=r.RichTextUtils.createGroup();n.charDirection=Kekule.Render.TextDirection.LTR;var o=r.RichTextUtils.appendText2(n,"H");r.RichTextUtils.appendText(n,t.toString(),{textType:r.RichText.SUB,refItem:o}),r.RichTextUtils.append(e,n)}else r.RichTextUtils.appendText(e,"H");return e}}),ClassEx.extend(Kekule.Atom,{getCoreDisplayRichTextItem:function(r,n,o,i){var a,s=Kekule.Render,l=s.RichTextUtils.createGroup(),d=this.getIsotopeAlias();this.getSymbol();d||this.getSymbol()!==e.Element.UNSET_ELEMENT?d&&Kekule.ChemStructureNodeLabels.ENABLE_ISOTOPE_ALIAS?(a=s.RichTextUtils.createSection(this.getIsotopeAlias(),{charDirection:Kekule.Render.TextDirection.LTR}),(l=s.RichTextUtils.append(l,a)).anchorItem=a):(a=s.RichTextUtils.createSection(this.getSymbol(),{charDirection:Kekule.Render.TextDirection.LTR}),(l=s.RichTextUtils.append(l,a)).anchorItem=a,this.getMassNumber()!==Kekule.Isotope.UNSET_MASSNUMBER&&((l=s.RichTextUtils.insertText(l,0,this.getMassNumber().toString(),{textType:s.RichText.SUP,charDirection:Kekule.Render.TextDirection.LTR,refItem:l.anchorItem})).charDirection=Kekule.Render.TextDirection.LTR)):l=s.RichTextUtils.appendText(l,o&&o.getUnsetElement()||t.UNSET_ELEMENT);return l}}),ClassEx.extend(Kekule.Pseudoatom,{getCoreDisplayRichTextItem:function(e,r,n,o){var i,a=Kekule.Render,s=n;return(i=this.getLabel())||(i=s&&s.getUnsetElement()||t.UNSET_ELEMENT),a.RichTextUtils.createSection(i,{charDirection:Kekule.Render.TextDirection.LTR})}});var n=function(e,t,r){var n,o=Kekule.Render,i=Kekule.IsotopesDataUtil.getIsotopeIdDetail(t);i.massNumber&&(n=o.RichTextUtils.appendText2(e,i.massNumber.toString(),{textType:Kekule.Render.RichText.SUP,charDirection:Kekule.Render.TextDirection.LTR}));var a=o.RichTextUtils.appendText2(e,i.symbol,{charDirection:Kekule.Render.TextDirection.LTR},r);return n&&(n.refItem=a),e.charDirection=Kekule.Render.TextDirection.LTR,e};ClassEx.extend(Kekule.VariableAtom,{getCoreDisplayRichTextItem:function(e,r,o,i){var a,s=Kekule.Render,l=o;if(this.isListEmpty())return(a=s.RichTextUtils.strToRichText(l&&l.getVariableAtom()||t.VARIABLE_ATOM)).charDirection=Kekule.Render.TextDirection.LTR,a;var d=this.getAllowedIsotopeIds()||this.getDisallowedIsotopeIds(),u=this.isDisallowedList();if((a=s.RichTextUtils.createGroup()).charDirection=Kekule.Render.TextDirection.LTR,u&&(a=s.RichTextUtils.appendText(a,l.getIsoListDisallowPrefix())),a=s.RichTextUtils.appendText(a,l.getIsoListLeadingBracket()),d&&d.length)for(var c=0,h=d.length;c<h;++c){var g=d[c];g&&(0!=c&&(a=s.RichTextUtils.appendText(a,l.getIsoListDelimiter())),a=n(a,g,0==c))}return a=s.RichTextUtils.appendText(a,l.getIsoListTailingBracket())}}),ClassEx.extend(Kekule.StructureConnectionTable,{exposedNodesHasCoord2D:function(e){for(var t=this.getExposedNodes(),r=0,n=t.length;r<n;++r)if(t[r].hasCoord2D(e))return!0;return!1},exposedNodesHasCoord3D:function(e){for(var t=this.getExposedNodes(),r=0,n=t.length;r<n;++r)if(t[r].hasCoord3D(e))return!0;return!1},getExposedNodes:function(){for(var e=[],t=this.getNodes(),r=0,n=t.length;r<n;++r){var o=t[r];if(o.getExposedNodes&&o.isExpanded()){var i=o.getExposedNodes();e=e.concat(i)}else o.isExposed()&&e.push(o)}return e},getExposedConnectors:function(){for(var e=this.getConnectors(),t=this.getNodes(),r=0,n=t.length;r<n;++r){var o=t[r];if(o.getConnectors&&o.isExpanded()){var i=o.getExposedConnectors();e=e.concat(i)}}return e},getExposedContainerBox:function(e,t){var r=this.getExposedNodes();return r.length?this.getNodesContainBox(r,e,t):null},getExposedContainerBox2D:function(e){var t=this.getExposedContainerBox(Kekule.CoordMode.COORD2D,e);return t.width=t.x2-t.x1,t.height=t.y2-t.y1,t},getExposedContainerBox3D:function(e){var t=this.getExposedContainerBox(Kekule.CoordMode.COORD3D,e);return t.deltaX=t.x2-t.x1,t.deltaY=t.y2-t.y1,t.deltaZ=t.z2-t.z1,t},getConnectorLengthMedian:function(e,t){var r=this.getAllContainingConnectors();return Kekule.ChemStructureUtils.getConnectorLengthMedian(r,e,t)},getAllAutoScaleRefLengths:function(e,t){for(var r=this.getAllContainingConnectors(),n=[],o=0,i=r.length;o<i;++o){var a=r[o];if(a&&a.getAllAutoScaleRefLengths){var s=a.getAllAutoScaleRefLengths(e,t);s&&(n=n.concat(s))}}return n}}),ClassEx.extend(Kekule.ContentBlock,{getDefCoordPos:function(e){return e!==r.COORD3D?Kekule.Render.CoordPos.CORNER_TL:this.tryApplySuper("getDefCoordPos",[e])}}),ClassEx.extend(Kekule.ChemMarker.ChemPropertyMarker,{getDefCoordPos:function(e){return e!==r.COORD3D?Kekule.Render.CoordPos.CENTER:this.tryApplySuper("getDefCoordPos",[e])}}),ClassEx.extend(Kekule.StructureFragment,{isExpanded:function(){var e=this.getOverriddenRenderOptions();return!!e&&!!e.expanded},setExpanded:function(e){this.setRenderOption("expanded",e)},getExposedNodes:function(){return this.hasCtab()?this.getCtab().getExposedNodes():[]},getExposedConnectors:function(){return this.hasCtab()?this.getCtab().getExposedConnectors():[]},exposedNodesHasCoord2D:function(e){return!!this.hasCtab()&&this.getCtab().exposedNodesHasCoord2D(e)},exposedNodesHasCoord3D:function(e){return!!this.hasCtab()&&this.getCtab().exposedNodesHasCoord3D(e)},getExposedContainerBox:function(e,t){if(this.hasCtab()){var r=this.getCtab().getExposedContainerBox(e,t);return r||(r=this.getContainerBox(e,t)),r}return this.getContainerBox(e,t)},getConnectorLengthMedian:function(e,t){return this.hasCtab()?this.getCtab().getConnectorLengthMedian(e,t):null},getAutoScaleRefLength:function(e,t){return this.getConnectorLengthMedian(e,t)},getAllAutoScaleRefLengths:function(e,t){return this.hasCtab()?this.getCtab().getAllAutoScaleRefLengths(e,t):null}}),ClassEx.extend(Kekule.SubGroup,{getCoreDisplayRichTextItem:function(e,r,n,o){var i,a=Kekule.Render,s=null,l=this.getAbbr();if(l||(s=this.getFormulaText()?Kekule.FormulaUtils.textToFormula(this.getFormulaText()):this.getFormula(!1)||this.calcFormula())&&!s.isEmpty()||(l=n&&n.getRgroup()||t.SUBGROUP),l)if(l.length<=3)(i=a.RichTextUtils.createSection(l)).charDirection=Kekule.Render.TextDirection.LTR;else{var d=this._indexOfFirstUppercaseLetter(l);d<0&&(d=0),(i=a.RichTextUtils.createGroup()).charDirection=Kekule.Render.TextDirection.LTR,d>0&&((u=a.RichTextUtils.createSection(l.substring(0,d))).charDirection=Kekule.Render.TextDirection.INHERIT,i=a.RichTextUtils.append(i,u));var u=a.RichTextUtils.createSection(l.charAt(d));(i=a.RichTextUtils.append(i,u)).anchorItem=u,d<l.length-1&&((u=a.RichTextUtils.createSection(l.substring(d+1))).charDirection=Kekule.Render.TextDirection.INHERIT,i=a.RichTextUtils.append(i,u))}else if(s){i=s.getDisplayRichText(r,n,o),(u=a.RichTextUtils.getFirstNormalTextSection(i))||(u=i.items[0]),i.anchorItem=u}return i},_indexOfFirstUppercaseLetter:function(e){for(var t=0,r=e.length;t<r;++t){var n=e.charAt(t);if(n>="A"&&n<="Z")return t}return-1},_autoSetSelfCoord:function(e,t){if(!this._isAutoSettingSelfCoord&&!(this.getCoordOfMode(e,t)||(a=this.getAnchorNodeCount())<=0)){this.beginUpdate();try{this._isAutoSettingSelfCoord=!0;for(var r={},n=0;n<a;++n){(s=this.getAnchorNodeAt(n))._autoSetSelfCoord&&s._autoSetSelfCoord(e,t),(l=s.getAbsCoordOfMode(e,t))&&(r=Kekule.CoordUtils.add(r,l))}var o=Kekule.CoordUtils.divide(r,a);this.setAbsCoordOfMode(o,e);var i=this.getCoordOfMode(e)||{},a=this.getNodeCount();for(n=0;n<a;++n){var s,l;(l=(s=this.getNodeAt(n)).getCoordOfMode(e,t))&&(l=Kekule.CoordUtils.substract(l,i),s.setCoordOfMode(l,e))}}finally{this._isAutoSettingSelfCoord=!1,this.endUpdate()}}},doGetAbsCoord2D:function(e){return this._autoSetSelfCoord(Kekule.CoordMode.COORD2D,e),this.tryApplySuper("doGetAbsCoord2D",[e])},doGetAbsCoord3D:function(e){return this._autoSetSelfCoord(Kekule.CoordMode.COORD3D,e),this.tryApplySuper("doGetAbsCoord3D",[e])},doSetAbsCoord2D:function(e){return this._autoSetSelfCoord(Kekule.CoordMode.COORD2D),this.tryApplySuper("doSetAbsCoord2D",[e])},doSetAbsCoord3D:function(e){return this._autoSetSelfCoord(Kekule.CoordMode.COORD3D),this.tryApplySuper("doSetAbsCoord3D",[e])}}),ClassEx.extend(Kekule.MolecularFormula,{getDisplayRichText:function(e,t,r,n,o){var i=Kekule.Render;return Kekule.ObjUtils.isUnset(e)&&(e=!0),i.ChemDisplayTextUtils.formulaToRichText(this,e,null,r,t,n,o)},getDisplayText:function(e,t,r){var n=this.getDisplayRichText();return Kekule.Render.RichTextUtils.toText(n)}}),ClassEx.extend(Kekule.Molecule,{afterInitialization:function(){this.setExpanded(!0)}}),ClassEx.extend(Kekule.CompositeMolecule,{getExposedContainerBox:function(e,t){var r=null,n=this.getPropStoreFieldValue("subMolecules");if(n)for(var o=0,i=n.length;o<i;++o){var a=n[o].getExposedContainerBox(e,t);a&&(r=r?Kekule.BoxUtils.getContainerBox(r,a):Kekule.BoxUtils.clone(a))}return r},getAllAutoScaleRefLengths:function(e,t){var r=[],n=this.getPropStoreFieldValue("subMolecules");if(n)for(var o=0,i=n.getItemCount();o<i;++o){var a=n.getObjAt(o).getAllAutoScaleRefLengths(e,t);a&&(r=r.concat(a))}return r}})}(),Kekule.Render={},Kekule.Render.CoordSystem={CHEM:0,CONTEXT:1,SCREEN:2},Kekule.Render.RendererType={R2D:2,R3D:3},Kekule.Render.CoordPos={CENTER:0,CORNER_TL:21,DEFAULT:0},Kekule.Render.DEF_ATOM_ATOMIC_NUM=6,Kekule.Render.MoleculeDisplayType={SKELETAL:1,CONDENSED:2,DEFAULT:1},Kekule.Render.Molecule2DDisplayType=Kekule.Render.MoleculeDisplayType,Kekule.Render.NodeLabelDisplayMode={HIDDEN:-1,SHOWN:1,SMART:0,DEFAULT:0},Kekule.Render.HydrogenDisplayLevel={NONE:0,EXPLICIT:1,UNMATCHED_EXPLICIT:2,ALL:10,LABELED:30,DEFAULT:30},Kekule.Render.TextDirection={DEFAULT:0,LTR:1,RTL:3,TTB:2,BTT:4,INHERIT:10},Kekule.Render.TextAlign={DEFAULT:0,LEFT:1,RIGHT:2,TOP:3,BOTTOM:4,CENTER:5,LEADING:10,TRAILING:11,getAbsAlign:function(e,t){var r=e,n=Kekule.Render.TextAlign,o=Kekule.Render.TextDirection;if(e===n.LEADING||e===n.TRAILING){var i=e==n.LEADING;switch(t){case o.RTL:r=i?n.RIGHT:n.LEFT;break;case o.TTB:r=i?n.TOP:n.BOTTOM;break;case o.BTT:r=i?n.BOTTOM:n.TOP;break;case o.LTR:default:r=i?n.LEFT:n.RIGHT}}return r}},Kekule.Render.BoxXAlignment={LEFT:0,RIGHT:1,CENTER:2},Kekule.Render.BoxYAlignment={TOP:0,BOTTOM:1,CENTER:2},Kekule.Render.TextBoxAlignmentMode={BOX:0,ANCHOR:1},Kekule.Render.BondRenderType={DEFAULT:null,SINGLE:0,DOUBLE:1,TRIPLE:2,QUAD:3,DASHED:4,DASHED_DOUBLE:5,DASHED_TRIPLE:6,SOLID_DASH:7,ARROWED:8,ARROWED_INV:9,HASHED:10,BOLD:11,BOLD_DOUBLE:12,BOLD_TRIPLE:13,BOLD_QUAD:14,BOLD_DASH:16,WEDGED_SOLID:20,WEDGED_SOLID_INV:21,WEDGED_HOLLOW:22,WEDGED_HOLLOW_INV:23,WEDGED_HASHED:24,WEDGED_HASHED_INV:25,WEDGED_SOLID_BOTH:26,WEDGED_HOLLOW_BOTH:27,WAVY:30,SCISSORS_DOUBLE:40},Kekule.Render.ChargeMarkRenderType={NUM_WITH_SYMBOL:1,DEFAULT:1,CIRCLE_AROUND:3},Kekule.Render.Render3DGraphicQuality={EXTREME_LOW:1,LOW:2,MEDIUM:3,HIGH:4,EXTREME_HIGH:5},Kekule.Render.Molecule3DDisplayType={WIRE:31,STICKS:32,BALL_STICK:33,SPACE_FILL:34,DEFAULT:33},Kekule.Render.Bond3DRenderMode={NONE:0,WIRE:1,MULTI_WIRE:2,CYLINDER:3,MULTI_CYLINDER:4,isWireMode:function(e){var t=Kekule.Render.Bond3DRenderMode;return e===t.WIRE||e===t.MULTI_WIRE},isCylinderMode:function(e){var t=Kekule.Render.Bond3DRenderMode;return e===t.CYLINDER||e===t.MULTI_CYLINDER}},Kekule.Render.Bond3DSpliceMode={UNSPLIT:1,MID_SPLIT:2,WEIGHTING_SPLIT:3},Kekule.Render.Bond3DRenderType={SINGLE:1,DOUBLE:2,TRIPLE:3,DASH:-1,SOLID_DASH:-2},Kekule.Render.Node3DRenderMode={NONE:0,BALL:1,SPACE:2},Kekule.Render.MetaShapeType={POINT:0,CIRCLE:1,LINE:2,RECT:3,ARC:5,POLYLINE:11,POLYGON:10,SPHERE:101,CYLINDER:102,COMPOSITE:-1},Kekule.Render.BoundShapeType=Kekule.Render.MetaShapeType,Kekule.Render.ObjectUpdateType={MODIFY:0,ADD:1,REMOVE:2,CLEAR:3},Kekule.Render.AbstractRenderer=Class.create(ObjectEx,{CLASS_NAME:"Kekule.Render.AbstractRenderer",RENDER_CACHE_FIELD:"__$renderCache$__",initialize:function(e,t,r){this.tryApplySuper("initialize"),this.setPropValue("chemObj",e,!0),r&&this.setParent(r),this.setDrawBridge(t),this.setBubbleEvent(!0),this._suspendUpdateStatus=0,this._suspendUpdateInfos=[]},finalize:function(){var e=this.getPropStoreFieldValue("boundInfoRecorder");e&&e.finalize(),this.setPropValue("chemObj",null,!0),this.setDrawBridge(null),this.tryApplySuper("finalize")},initProperties:function(){this.defineProp("chemObj",{dataType:"Kekule.ChemObject",serializable:!1,setter:null}),this.defineProp("drawBridge",{dataType:DataType.OBJECT,serializable:!1}),this.defineProp("parent",{dateType:DataType.OBJECT,serializable:!1}),this.defineProp("parentRenderer",{dateType:"Kekule.Render.AbstractRenderer",serializable:!1,getter:function(){var e=this.getParent();return e instanceof Kekule.Render.AbstractRenderer?e:null},setter:function(e){this.setParent(e)}}),this.defineProp("redirectContext",{dataType:DataType.OBJECT,serializable:!1}),this.defineProp("canModifyTargetObj",{dataType:DataType.BOOL,serializable:!1,getter:function(){var e=this.getPropStoreFieldValue("canModifyTargetObj");if(Kekule.ObjUtils.isUnset(e)){var t=this.getParent();t&&t.getCanModifyTargetObj&&(e=t.getCanModifyTargetObj())}return e}}),this.defineProp("boundInfoRecorder",{dataType:"Kekule.Render.BoundInfoRecorder",serializable:!1,setter:null,getter:function(e){if(this.isRootRenderer()){var t=this.getPropStoreFieldValue("boundInfoRecorder");return t||e||(t=this._createBoundInfoRecorder()),t}var r=this.getRootRenderer();return r&&r.getBoundInfoRecorder(e)}}),this.defineEvent("clear"),this.defineEvent("updateBasicDrawObject")},_createBoundInfoRecorder:function(){var e=this.getPropStoreFieldValue("boundInfoRecorder");e&&e.finalize();var t=new Kekule.Render.BoundInfoRecorder(this);return this.setPropStoreFieldValue("boundInfoRecorder",t),t},isRootRenderer:function(){return!this.getParentRenderer()},getHigherLevelObj:function(){return this.getParent()},getRootRenderer:function(){if(this.isRootRenderer())return this;var e=this.getParentRenderer();return e?e.getRootRenderer():this},getRendererType:function(){return Kekule.Render.RendererType.R2D},getCoordMode:function(){return this.getRendererType()===Kekule.Render.RendererType.R3D?Kekule.CoordMode.COORD3D:Kekule.CoordMode.COORD2D},_getRenderSortIndex:function(){return 0},getRenderCache:function(e){var t=this.getExtraProp(e,this.RENDER_CACHE_FIELD);return t||(t={},this.setExtraProp(e,this.RENDER_CACHE_FIELD,t)),t},beginDraw:function(e,t,r){var n=this.getDrawBridge();n.prepareContext&&n.prepareContext(e)},endDraw:function(e,t,r){var n=this.getDrawBridge();n.renderContext&&n.renderContext(e)},updateDrawInfoInCache:function(e,t,r,n,o){var i=this.getRenderCache(t);t&&(i.context=t),r&&(i.baseCoord=r),e&&(i.chemObj=e),n&&(i.options=n),o&&(i.realDrawOptions=o)},_isCurrChemObjNeedToBeDrawn:function(e,t){for(var r=this.getChemObj(),n=0,o=e.length;n<o;++n){var i=e[n];if(i===r||i.isChildOf(r))return!0}return!1},getAutoBaseCoord:function(e){return this.doGetAutoBaseCoord(e)},doGetAutoBaseCoord:function(e){return null},getCachedDrawOptions:function(e){return this.getRenderCache(e).options},getCachedDrawnElem:function(e){return this.getRenderCache(e).drawnElem},isChemObjNeedToBeDrawn:function(){var e=this.getChemObj();return e&&(!e.getVisible||e.getVisible())},draw:function(e,t,r){if(!this.isChemObjNeedToBeDrawn())return null;try{this.__isDrawing=!0,this.getBoundInfoRecorder();var n={},o=this.getParentRenderer();if(o)var i=o.getRenderCache().options;i?(n=Object.create(i),n=Object.extend(n,r)):n=Object.create(r||null);var a=this.getChemObj(),s=n.partialDrawObjs;if(s&&!this._isCurrChemObjNeedToBeDrawn(s,e))return null;var l=this.getRendererType()===Kekule.Render.RendererType.R3D?"getRender3DOptions":"getRenderOptions",d=a[l]?a[l]():null,u=a[l=this.getRendererType()===Kekule.Render.RendererType.R3D?"getOverriddenRender3DOptions":"getOverriddenRenderOptions"]?a[l]():null;n=Kekule.Render.RenderOptionUtils.mergeRenderOptions(d||{},n),this.getRenderCache().options=n,n=Kekule.Render.RenderOptionUtils.mergeRenderOptions(u||{},n),this.updateDrawInfoInCache(this.getChemObj(),e,t,r,n);var c=this.isRootRenderer();this.doPrepareDraw(e,t,n),this.invokeEvent("prepareDrawing",{context:e,obj:this.getChemObj()}),c&&this.beginDraw(e,t,n);var h=this.doDraw(e,t,n);this.getRenderCache(e).drawnElem=h,c&&this.endDraw(e,t,n),this.invokeEvent("draw",{context:e,obj:this.getChemObj(),renderOptions:n})}finally{this.__isDrawing=!1}return h},doPrepareDraw:function(e,t,r){},doDraw:function(e,t,r){return this.doDrawSelf(e,t,r)},doDrawSelf:function(e,t,r){return null},redraw:function(e){if(!this.isChemObjNeedToBeDrawn())return null;var t=this.isRootRenderer();if(t){var r=this.getRenderCache(e)||{};this.beginDraw(e,r.baseCoord,r.options)}var n=this.doRedraw(e);return this.getRenderCache(e).drawnElem=n,t&&this.endDraw(e,r.baseCoord,r.options),n},doRedraw:function(e){var t=this.getRenderCache(e);return this.draw(e,t.baseCoord,t.options)},canModifyGraphic:function(e){var t=this.getDrawBridge();return!!t.canModifyGraphic&&t.canModifyGraphic(e)},beginUpdateRenderer:function(){++this._suspendUpdateStatus},endUpdateRenderer:function(){--this._suspendUpdateStatus,this._suspendUpdateStatus<=0&&(this._suspendUpdateStatus=0),this.isUpdatingRenderer()||this.doEndUpdateRenderer()},doEndUpdateRenderer:function(){this.updateEx(this._suspendUpdateInfos),this._suspendUpdateInfos=[]},isUpdatingRenderer:function(){return this._suspendUpdateStatus>0},updateEx:function(e){var t=!0;if(this.isUpdatingRenderer())return this._suspendUpdateInfos||(this._suspendUpdateInfos=[]),this._mergeRendererUpdateInfo(this._suspendUpdateInfos,e),!0;if(!this.canModifyGraphic(s)){if(this.isRootRenderer()){var r=[];for(o=0,i=e.length;o<i;++o){s=(a=e[o]).context;Kekule.ArrayUtils.pushUnique(r,s)}for(o=0,i=r.length;o<i;++o){this.getDrawBridge().clearContext(s);var n=this.getRenderCache(s);this.draw(s,n.baseCoord,n.options)}return!0}return this.getParentRenderer().updateEx(e)}for(var o=0,i=e.length;o<i;++o){for(var a,s=(a=e[o]).context,l=0,d=a.items.length;l<d;++l){var u=a.items[l];if(!(t=t&&this.doUpdate(s,u.updatedObjDetails,u.updateType)))break}if(!t)break}return t},_mergeRendererUpdateInfo:function(e,t){for(var r=0,n=t.length;r<n;++r){var o=t[r],i=this._indexOfContextInRendererUpdateInfos(o.context,e);if(i<0)e.push(o);else{var a=e[i];a.items=a.items.concat(o.items)}}return e},_indexOfContextInRendererUpdateInfos:function(e,t){for(var r=0,n=t.length;r<n;++r){if(t[r].context===e)return r}return-1},update:function(e,t,r){for(var n=[],o=0,i=t.length;o<i;++o){var a=t[o].obj;this.isChemObjRenderedBySelf(e,a)&&n.push(t[o])}return!n.length||this.updateEx([{context:e,items:[{updateType:r,updatedObjDetails:n}]}])},doUpdate:function(e,t,r){return this.doUpdateSelf(e,t,r)},doUpdateSelf:function(e,t,r){if(this.canModifyGraphic(e)){for(var n=!1,o=this.getChemObj(),i=0,a=t.length;i<a;++i){if(t[i].obj===o){n=!0;break}}if(n){if(r===Kekule.Render.ObjectUpdateType.CLEAR)return this.doClear(e);this.doClear(e);var s=this.getRenderCache(e);return this.draw(e,s.baseCoord,s.options)}}return!1},_extractObjsOfUpdateObjDetails:function(e){return Kekule.Render.UpdateObjUtils._extractObjsOfUpdateObjDetails(e)},_createUpdateObjDetailsFromObjs:function(e){return Kekule.Render.UpdateObjUtils._createUpdateObjDetailsFromObjs(e)},addNew:function(e,t){var r=this._createUpdateObjDetailsFromObjs(t);return this.update(e,r,Kekule.Render.ObjectUpdateType.ADD)},modify:function(e,t){return this.update(e,t,Kekule.Render.ObjectUpdateType.MODIFY)},remove:function(e,t){var r=this._createUpdateObjDetailsFromObjs(t);return this.update(e,r,Kekule.Render.ObjectUpdateType.REMOVE)},clear:function(e){this.doClear(e);this.invokeEvent("clear",{context:e,obj:this.getChemObj()})},doClear:function(e){return!!this.canModifyGraphic()&&this.doClearSelf(e)},doClearSelf:function(e){if(!this.canModifyGraphic())return!1;var t=this.getRenderCache(e).drawnElem;if(t)try{this.getDrawBridge().removeDrawnElem(e,t)}catch(e){}this.getRenderCache(e).drawnElem=null},estimateObjBox:function(e,t,r){var n=this.doEstimateObjBox(e,t,r);return n&&(n=this._fillBoxDefaultValue(n,this.getRendererType())),n},doEstimateObjBox:function(e,t,r){return this.doEstimateSelfObjBox(e,t,r)},doEstimateSelfObjBox:function(e,t,r){return null},estimateRenderBox:function(e,t,r,n){var o=this.doEstimateRenderBox(e,t,r,n);return o&&(o=this._fillBoxDefaultValue(o,this.getRendererType())),o},doEstimateRenderBox:function(e,t,r,n){return null},_fillBoxDefaultValue:function(e,t){e||(e={});var r=t===Kekule.Render.RendererType.R3D,n={x1:e.x1||0,x2:e.x2||0,y1:e.y1||0,y2:e.y2||0};return r&&(n.z1=e.z1||0,n.z2=e.z2||0),n},transformCoordToObj:function(e,t,r){return this.doTransformCoordToObj(e,t,r)},doTransformCoordToObj:function(e,t,r){return r},transformCoordToContext:function(e,t,r){return this.doTransformCoordToContext(e,t,r)},doTransformCoordToContext:function(e,t,r){return r},transformContextCoordToScreen:function(e,t){return this.doTransformContextCoordToScreen(e,t)},doTransformContextCoordToScreen:function(e,t){var r=this.getDrawBridge();return r&&r.transformContextCoordToScreen?r.transformContextCoordToScreen(e,t):t},basicDrawObjectUpdated:function(e,t,r,n,o){this.invokeEvent("updateBasicDrawObject",{context:e,obj:t,parentObj:r,boundInfo:n,updateType:o})},isChemObjRenderedBySelf:function(e,t){return t===this.getRenderCache(e).chemObj},isChemObjRenderedDirectlyBySelf:function(e,t){return!(!t||!this.getRenderCache(e).chemObj)&&t===this.getRenderCache(e).chemObj},getObjRenderBound:function(e,t,r){var n=this.getBoundInfoRecorder(),o=t;return r&&t.getCoordStickTarget&&(o=t.getCoordStickTarget()||o),n&&n.getBound(e,o)},getStickingTargetRenderBound:function(e,t){var r;if(t.getCoordStickTarget&&(r=t.getCoordStickTarget()),r){var n=this.getBoundInfoRecorder();return n&&n.getBound(e,r,!0)}return null},createBoundInfo:function(e,t,r){return Kekule.Render.MetaShapeUtils.createShapeInfo(e,t,r)},createPointBoundInfo:function(e){return this.createBoundInfo(Kekule.Render.BoundShapeType.POINT,[e])},createCircleBoundInfo:function(e,t){return this.createBoundInfo(Kekule.Render.BoundShapeType.CIRCLE,[e],{radius:t})},createArcBoundInfo:function(e,t,r,n,o,i){return this.createBoundInfo(Kekule.Render.BoundShapeType.ARC,[e],{radius:t,startAngle:r,endAngle:n,anticlockwise:o,width:i})},createLineBoundInfo:function(e,t,r){return this.createBoundInfo(Kekule.Render.BoundShapeType.LINE,[e,t],{width:r})},createRectBoundInfo:function(e,t){return this.createBoundInfo(Kekule.Render.BoundShapeType.RECT,[e,t])},createSphereBoundInfo:function(e,t){return this.createBoundInfo(Kekule.Render.BoundShapeType.SPHERE,[e],{radius:t})},createCylinderBoundInfo:function(e,t,r){return this.createBoundInfo(Kekule.Render.BoundShapeType.CYLINDER,[e,t],{radius:r})}}),Kekule.ClassDefineUtils.addExtraObjMapSupport(Kekule.Render.AbstractRenderer),Kekule.Render.DummyRenderer=Class.create(Kekule.Render.AbstractRenderer,{CLASS_NAME:"Kekule.Render.DummyRenderer",draw:function(e,t,r){},redraw:function(e){}}),Kekule.Render.CompositeRenderer=Class.create(Kekule.Render.AbstractRenderer,{CLASS_NAME:"Kekule.Render.CompositeRenderer",initProperties:function(){this.defineProp("targetChildObjs",{dataType:DataType.ARRAY,serializable:!1}),this.defineProp("childRendererMap",{dataType:DataType.OBJECT,serializable:!1,getter:function(){var e=this.getPropStoreFieldValue("childRendererMap");return e||(e=new Kekule.MapEx(!0),this.setPropStoreFieldValue("childRendererMap",e)),e}})},finalize:function(){this.reset(),this.tryApplySuper("finalize")},_getRenderSortIndex:function(){for(var e=this.tryApplySuper("_getRenderSortIndex"),t=this.prepareChildRenderers(),r=0,n=t.length;r<n;++r){var o=t[r]._getRenderSortIndex();o>e&&(e=o)}return e},doEstimateObjBox:function(e,t,r){for(var n=this.tryApplySuper("doEstimateObjBox",[e,t,r]),o=this.prepareChildRenderers(),i=Kekule.BoxUtils,a=0,s=o.length;a<s;++a){var l=o[a];if(l){var d=l.estimateObjBox(e,t,r);d&&(n=n?i.getContainerBox(n,d):i.clone(d))}}return n},isChemObjRenderedBySelf:function(e,t){var r=this.tryApplySuper("isChemObjRenderedBySelf",[e,t]);if(!r)for(var n=this.getChildRenderers(),o=0,i=n.length;o<i;++o){if(n[o].isChemObjRenderedBySelf(e,t))return!0}if(!r){this.refreshChildObjs();var a=this.getTargetChildObjs();r=a&&a.indexOf(t)>=0}return r},isChemObjRenderedDirectlyBySelf:function(e,t){return this.tryApplySuper("isChemObjRenderedDirectlyBySelf",[e,t])},doSetRedirectContext:function(e){this.tryApplySuper("doSetRedirectContext",[e]);var t=this.getChildRenderers();if(t&&t.length)for(var r=0,n=t.length;r<n;++r)t[r].setRedirectContext(e)},getChildObjs:function(){var e=this.getChemObj();return e&&e.getAttachedMarkers?[].concat(e.getAttachedMarkers()||[]):[]},prepareChildObjs:function(){var e=this.getTargetChildObjs();return e||(this.setTargetChildObjs(this.getChildObjs()),this.getTargetChildObjs())},refreshChildObjs:function(){this.setTargetChildObjs(null),this.prepareChildObjs()},getChildRenderers:function(){return this.getChildRendererMap().getValues()},getRendererForChild:function(e,t){var r=this.getRendererType()===Kekule.Render.RendererType.R3D?Kekule.Render.get3DRendererClass:Kekule.Render.get2DRendererClass,n=this.getChildRendererMap();if(!(i=n.get(e))&&t){var o=r(e)||Kekule.Render.DummyRenderer,i=o?new o(e,this.getDrawBridge(),this):null;n.set(e,i),i.setRedirectContext(this.getRedirectContext())}return i},prepareChildRenderers:function(){for(var e=this.getChildRendererMap(),t=this.prepareChildObjs()||[],r=e.getKeys(),n=0,o=r.length;n<o;++n){var i=r[n];t.indexOf(i)<0&&e.remove(i)}for(n=0,o=t.length;n<o;++n){var a=t[n];this.getRendererForChild(a,!0)}return e.getValues()},releaseChildRenderers:function(){var e=this.getChildRendererMap(),t=e.getValues();if(t){for(var r=0,n=t.length;r<n;++r)t[r].finalize();e.clear()}},hasChildRenderers:function(){var e=this.getChildRendererMap().getValues();return e&&e.length},getDirectRendererForChildObj:function(e,t){if(this.isChemObjRenderedDirectlyBySelf(e,t))return this;for(var r=this.getChildRenderers(),n=0,o=r.length;n<o;++n){var i=r[n];if(i.isChemObjRenderedBySelf(e,t))return i.isChemObjRenderedDirectlyBySelf(e,t)?i:i.getDirectRendererForChildObj?i.getDirectRendererForChildObj(e,t):null}return null},prepare:function(){this.prepareChildObjs(),this.prepareChildRenderers()},reset:function(){this.setTargetChildObjs(null),this.releaseChildRenderers()},_needWholelyDraw:function(e,t){var r=this.getChemObj();return!e||e.indexOf(r)>=0},doPrepareDraw:function(e,t,r){this.refreshChildObjs(),this.prepareChildRenderers();for(var n=this.getChildRenderers(),o=0,i=n.length;o<i;++o){n[o].doPrepareDraw(e,t,r)}},doDraw:function(e,t,r){var n=Object.create(r);if(r.partialDrawObjs&&this._needWholelyDraw(r.partialDrawObjs,e)&&(n.partialDrawObjs=null),this.getTargetChildObjs().length){var o=this.doDrawSelf(e,t,n),i=this.doDrawChildren(e,t,n);return o&&this.addToDrawGroup(o,i),i}return this.tryApplySuper("doDraw",[e,t,n])},doDrawChildren:function(e,t,r){var n=this.createDrawGroup(e),o=this.getChildRenderers();this._sortChildRenderers(o);var i=Object.create(r);this.getRenderCache(e).childDrawOptions=i;for(var a=0,s=o.length;a<s;++a){var l=o[a].draw(e,null,i);n&&l&&this.addToDrawGroup(l,n)}return n},_sortChildRenderers:function(e){e.sort(function(e,t){return e._getRenderSortIndex()-t._getRenderSortIndex()})},doClear:function(e){return this.tryApplySuper("doClear",[e]),this.hasChildRenderers()&&this.doClearChildren(e),!0},doClearChildren:function(e){for(var t=this.getChildRendererMap().getValues(),r=0,n=t.length;r<n;++r)t[r]&&t[r].clear(e)},doUpdate:function(e,t,r){return this.refreshChildObjs(),this.tryApplySuper("doUpdate",[e,t,r]),this.getTargetChildObjs().length&&this.doUpdateChildren(e,t,r),!0},doUpdateChildren:function(e,t,r){for(var n=Kekule.Render.UpdateObjUtils._extractObjsOfUpdateObjDetails(t),o=this.getTargetChildObjs()||[],i=this.getChildRendererMap(),a=Kekule.ArrayUtils.toArray(n),s=new Kekule.MapEx(!1),l=[],d=!1,u=0,c=a.length;u<c;++u){var h=a[u];this.isChemObjRenderedDirectlyBySelf(e,h)&&(d=!0)}if(d)return this.doClear(e),this.redraw(e),!0;for(u=0,c=a.length;u<c;++u){h=a[u];if(D=i.get(h))r===Kekule.Render.ObjectUpdateType.REMOVE?(D.clear(),i.remove(h)):(Kekule.ArrayUtils.pushUnique(l,D),m=[h],s.set(D,m));else{var g=this._getRenderersForChildObj(e,h);if(!g.length&&o.indexOf(h)>=0){var p=(O=this.getRendererForChild(h,!0)).draw(e,null,this.getRenderCache(e).childDrawOptions);if(p){var f=this.getCachedDrawnElem(e);f&&this.addToDrawGroup(p,f)}}for(var C=0,R=g.length;C<R;++C){var D=g[C],m=s.get(D);m||(l.push(D),m=[],s.set(D,m)),m.push(h)}}}var y=!0;for(u=0,c=l.length;u<c;++u){D=l[u];var T=s.get(D),x=Kekule.Render.UpdateObjUtils._createUpdateObjDetailsFromObjs(T),O=D.update(e,x,r);y=y&&O}return y},_getRenderersForChildObj:function(e,t){for(var r=[],n=this.getChildRenderers(),o=0,i=n.length;o<i;++o){var a=n[o];a.isChemObjRenderedBySelf(e,t)&&r.push(a)}return r}}),Kekule.Render.Renderer2DFactory=Kekule.FactoryUtils.createSimpleFactory(Kekule.FactoryUtils.MATCH_BY_CLASS),Kekule.Render.get2DRendererClass=function(e){var t=e instanceof ObjectEx?e.getClass():e;return Kekule.Render.Renderer2DFactory.getClass(t)},Kekule.Render.Renderer3DFactory=Kekule.FactoryUtils.createSimpleFactory(Kekule.FactoryUtils.MATCH_BY_CLASS),Kekule.Render.get3DRendererClass=function(e){var t=e instanceof ObjectEx?e.getClass():e;return Kekule.Render.Renderer3DFactory.getClass(t)},Kekule.Render.DrawBridgeManager=Class.create({CLASS_NAME:"Kekule.Render.DrawBridgeManager",initialize:function(){this._items=[],this._preferredItem=null},_indexOfBridgeClass:function(e){for(var t=0,r=this._items.length;t<r;++t){if(this._items[t].bridgeClass===e)return t}return-1},_sortItems:function(){this._items.sort(function(e,t){return(e.priorityLevel||0)-(t.priorityLevel||0)})},_reselectPreferred:function(){this._sortItems();for(var e=this._items.length-1;e>=0;--e){var t=this._items[e];if(t.isSupported)return this._preferredItem=t,t}return this._preferredItem=null,null},_recheckAvailabilityOfItem:function(e){var t=e.bridgeClass,r=t.getAvailabilityInformation&&t.getAvailabilityInformation();!r&&t.isSupported&&(r={available:t.isSupported(),message:null}),r?(e.isSupported=r.available,e.message=r.message):(e.isSupported=!1,e.message=null)},recheckAvailabilities:function(){for(var e=this._items,t=e.length-1;t>=0;--t){var r=e[t];this._recheckAvailabilityOfItem(r)}},register:function(e,t){t||(t=0);var r,n=this._indexOfBridgeClass(e);return n>=0&&this._items.splice(n,1),r={bridgeClass:e,priorityLevel:t},this._recheckAvailabilityOfItem(r),this._items.push(r),this._sortItems(),(!this._preferredItem||this._preferredItem.priorityLevel<t)&&r.isSupported&&(this._preferredItem=r),r},unregister:function(e){var t=null,r=this._indexOfBridgeClass(e);return r>=0&&(t=this._items[r],this._items.splice(r,1),t===this._preferredItem&&this._reselectPreferred()),t},getPreferredBridgeClass:function(){return this._preferredItem?this._preferredItem.bridgeClass:null},getPreferredBridgeInstance:function(){var e=this.getPreferredBridgeClass();return e?new e:null},getUnavailableMessages:function(){for(var e=[],t=this._items,r=t.length-1;r>=0;--r){var n=t[r];!n.isSupported&&n.message&&e.push(n.message)}return e},getUnavailableMessage:function(){var e=this._preferredItem||this._items[this._items.length-1];return!e.isSupported&&e.message?e.message:""}}),Kekule.Render.DrawBridge2DMananger=new Kekule.Render.DrawBridgeManager,Kekule.Render.DrawBridge3DMananger=new Kekule.Render.DrawBridgeManager,Kekule.Render.registerExternalModule=function(e,t){Kekule.externalResourceManager.register(e,t)},Kekule.Render.getExternalModule=function(e){return Kekule.externalResourceManager.getResource(e)},function(){var e=Kekule.Render;e.atomColorSets={jmol:["#000099","#FFFFFF","#D9FFFF","#CC80FF","#C2FF00","#FFB5B5","#909090","#3050F8","#FF0D0D","#90E050","#B3E3F5","#AB5CF2","#8AFF00","#BFA6A6","#F0C8A0","#FF8000","#FFFF30","#1FF01F","#80D1E3","#8F40D4","#3DFF00","#E6E6E6","#BFC2C7","#A6A6AB","#8A99C7","#9C7AC7","#E06633","#F090A0","#50D050","#C88033","#7D80B0","#C28F8F","#668F8F","#BD80E3","#FFA100","#A62929","#5CB8D1","#702EB0","#00FF00","#94FFFF","#94E0E0","#73C2C9","#54B5B5","#3B9E9E","#248F8F","#0A7D8C","#006985","#C0C0C0","#FFD98F","#A67573","#668080","#9E63B5","#D47A00","#940094","#429EB0","#57178F","#00C900","#70D4FF","#FFFFC7","#D9FFC7","#C7FFC7","#A3FFC7","#8FFFC7","#61FFC7","#45FFC7","#30FFC7","#1FFFC7","#00FF9C","#00E675","#00D452","#00BF38","#00AB24","#4DC2FF","#4DA6FF","#2194D6","#267DAB","#266696","#175487","#D0D0E0","#FFD123","#B8B8D0","#A6544D","#575961","#9E4FB5","#AB5C00","#754F45","#428296","#420066","#007D00","#70ABFA","#00BAFF","#00A1FF","#008FFF","#0080FF","#006BFF","#545CF2","#785CE3","#8A4FE3","#A136D4","#B31FD4","#B31FBA","#B30DA6","#BD0D87","#C70066","#CC0059","#D1004F","#D90045","#E00038","#E6002E","#EB0026","#000000","#000000"],cpk2D:["#000000","#000000","#FFC0CB","#B22222",null,"#00FF00","#000000","#8F8FFF","#F00000","#DAA520",null,"#0000FF","#228B22","#808090","#DAA520","#FFA500","#FFC832","#00FF00",null,"#0000FF","#808090","#808090","#808090","#808090","#808090","#808090","#FFA500","#A52A2A","#A52A2A","#A52A2A","#A52A2A"]};var t=e.atomColorSets.cpk2D,r=e.atomColorSets.jmol;t[35]="#A52A2A",t[47]="#808090",t[53]="#A020F0",t[56]="#FFA500",t[79]="#DAA520",t.SubGroup=r.SubGroup="#0000CC",e.atom3DColors=Kekule.Render.atomColorSets.jmol,e.atom2DColors=Kekule.Render.atomColorSets.cpk2D,e.atomColors=[],e.atomColors[e.RendererType.R2D]=e.atom2DColors,e.atomColors[e.RendererType.R3D]=e.atom3DColors}(),Kekule.Render.RichText={SECTION:"section",GROUP:"group",LINES:"lines",SUP:"superscript",SUB:"subscript",NORMAL:"normal"},Kekule.Render.RichTextUtils={STYLE_PROPS:["fontSize","fontFamily","fontWeight","fontStyle","color","opacity"],create:function(){return Kekule.Render.RichTextUtils.createGroup()},createGroup:function(e,t){var r={role:e||"group",items:[]};if(t)for(var n in t)t.hasOwnProperty(n)&&(r[n]=t[n]);return r},createSection:function(e,t){var r={text:e};if(t)for(var n in t)t.hasOwnProperty(n)&&(r[n]=t[n]);return r},strToRichText:function(e,t){e||(e="");var r=Kekule.Render.RichTextUtils,n=e.split("\n");if(n.length<=1)return Kekule.Render.RichTextUtils.appendText(r.create(),e,t);for(var o=r.createGroup(Kekule.Render.RichText.LINES),i=0,a=n.length;i<a;++i){var s=n[i]||" ";r.appendText(o,s,t)}return o},insertText:function(e,t,r,n,o){var i=Kekule.Render.RichTextUtils.createSection(r,n);return e.items.splice(t,0,i),o&&(e.anchorItem=i),e},appendText:function(e,t,r,n){var o=Kekule.Render.RichTextUtils.createSection(t,r);return e.items.push(o),n&&(e.anchorItem=o),e},appendText2:function(e,t,r,n){var o=Kekule.Render.RichTextUtils.createSection(t,r);return e.items.push(o),n&&(e.anchorItem=o),o},insert:function(e,t,r){return e.items.splice(t,0,r),e},append:function(e,t){return e.items.push(t),e},appendItems:function(e,t){return e.items=e.items.concat(Kekule.ArrayUtils.toArray(t)),e},getItemType:function(e){return e.items?e.role:Kekule.Render.RichText.SECTION},getItemRole:function(e){var t=Kekule.Render.RichText;return Kekule.Render.RichTextUtils.getItemType(e)===t.GROUP?t.GROUP:t.SECTION},getItemTextType:function(e){return e.textType||Kekule.Render.RichText.NORMAL},isSuperscript:function(e){return Kekule.Render.RichTextUtils.getItemTextType(e)==Kekule.Render.RichText.SUP},isSubscript:function(e){return Kekule.Render.RichTextUtils.getItemTextType(e)==Kekule.Render.RichText.SUB},isGroup:function(e){return Kekule.Render.RichTextUtils.getItemType(e)===Kekule.Render.RichText.GROUP},isSection:function(e){return Kekule.Render.RichTextUtils.getItemType(e)===Kekule.Render.RichText.SECTION},getFirstNormalTextSection:function(e){for(var t=0,r=e.items.length;t<r;++t){var n=e.items[t];if(Kekule.Render.RichTextUtils.getItemTextType(n)===Kekule.Render.RichText.NORMAL)return n}return null},getActualRefItem:function(e,t){var r=e.refItem;if(!r&&t.items.length>1){var n=t.items.indexOf(e);r=n>0?t.items[n-1]:0==n?t.items[1]:null}return r},getFinalAnchorItem:function(e){return e.anchorItem?Kekule.Render.RichTextUtils.getFinalAnchorItem(e.anchorItem):e},tidy:function(e){for(var t=Kekule.Render.RichTextUtils.createGroup(e.role),r=-1,n=0,o=e.items.length;n<o;++n){var i=e.items[n];if(i.items){var a=Kekule.Render.RichTextUtils.tidy(i);if(1==a.items.length){var s=Object.extend({},a);delete s.items,delete s.role,i=s=Object.extend(s,a.items[0])}else if(a.items.length>0){++r,t.items.push(a);continue}}var l=!1;if(r>=0){var d=t.items[r];d.items||Kekule.ObjUtils.equal(i,d,["text"])&&(d.text+=i.text,l=!0)}l||(++r,t.items.push(Object.extend({},i)))}return t},clone:function(e){var t={};if(Object.extend(t,e),e.items){t.items=[];for(var r=0,n=e.items.length;r<n;++r){var o={};o=Kekule.Render.RichTextUtils.clone(e.items[r]),t.items.push(o)}}if(t.items){if(e.anchorItem){var i=e.items.indexOf(e.anchorItem);t.anchorItem=i>=0?t.items[i]:null}for(r=0,n=t.items.length;r<n;++r){var a=e.items[r];o=t.items[r];if(a.refItem){i=e.items.indexOf(a.refItem);o.refItem=i>=0?t.items[i]:null}}}return t},toText:function(e){var t="";if(!e.items)return e.text||"";for(var r=0,n=e.items.length;r<n;++r){var o=e.items[r];o.items?t+=Kekule.Render.RichTextUtils.toText(o):o.text&&(t+=o.text)}return t},_toDebugHtml:function(e){if(!e.items)return e.text;for(var t="",r=0,n=e.items.length;r<n;++r){var o=e.items[r];if(o.items)t+=Kekule.Render.RichTextUtils._toDebugHtml(o);else if(o.text)switch(o.textType){case Kekule.Render.RichText.SUB:t+="<sub>"+o.text+"</sub>";break;case Kekule.Render.RichText.SUP:t+="<sup>"+o.text+"</sup>";break;default:t+=o.text}}return t},toSimpleHtmlCode:function(e){return Kekule.Render.RichTextUtils._toDebugHtml(e)},fromSimpleHtmlCode:function(e){for(var t,r=Kekule.Render.RichText,n=new RegExp("</?([a-z]+)/?>","ig"),o=[],i=0,a=r.NORMAL;null!==(t=n.exec(e));){var s=t.index,l=t[0],d=t[1].toLowerCase();i<s&&o.push({textType:a,text:e.substring(i,s)});var u=1===l.indexOf("/");if(!(l.lastIndexOf("/")===l.length-2)){var c="sup"===d?r.SUP:"sub"===d?r.SUB:null;c&&(u?a===c&&(a=r.NORMAL):a=c)}i=s+l.length}e.length>i&&o.push({textType:a,text:e.substring(i)});for(var h=Kekule.Render.RichTextUtils,g=h.createGroup(null,{charDirection:Kekule.Render.TextDirection.LTR}),p=0,f=o.length;p<f;++p){var C=o[p].textType,R=o[p].text;if(R){var D=h.createSection(R,{textType:C});h.append(g,D)}}return g},toHtml:function(e,t,r){var n,o,i=Kekule.Render.RichText;o=t.charDirection?t.charDirection===Kekule.Render.TextDirection.RTL||t.charDirection===Kekule.Render.TextDirection.BTT:r;var a=t.role;if(a===i.SECTION||t.text){var s=t.textType,l=s===i.SUB?"sub":s===i.SUP?"sup":"span";n=e.createElement(l);var d=t.text;o&&(d=d.reverse()),K