UNPKG

3dmol

Version:

JavaScript/TypeScript molecular visualization library

961 lines (792 loc) 95.8 kB
<!DOCTYPE html><html lang="en" style="font-size:16px"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><meta name="Author" content="David Koes & 3Dmoljs Contributors"><meta name="Description" content="A modern, object-oriented JavaScript library for visualizing molecular data"><title>Source: ui/ui.js</title><!--[if lt IE 9]> <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script> <![endif]--><script src="scripts/third-party/hljs.js" defer="defer"></script><script src="scripts/third-party/hljs-line-num.js" defer="defer"></script><script src="scripts/third-party/popper.js" defer="defer"></script><script src="scripts/third-party/tippy.js" defer="defer"></script><script src="scripts/third-party/tocbot.min.js"></script><script>var baseURL="/",locationPathname="";baseURL=(locationPathname=document.location.pathname).substr(0,locationPathname.lastIndexOf("/")+1)</script><link rel="stylesheet" href="styles/clean-jsdoc-theme.min.css"><style>article ul li{list-style:disc}</style><svg aria-hidden="true" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" style="display:none"><defs><symbol id="copy-icon" viewbox="0 0 488.3 488.3"><g><path d="M314.25,85.4h-227c-21.3,0-38.6,17.3-38.6,38.6v325.7c0,21.3,17.3,38.6,38.6,38.6h227c21.3,0,38.6-17.3,38.6-38.6V124 C352.75,102.7,335.45,85.4,314.25,85.4z M325.75,449.6c0,6.4-5.2,11.6-11.6,11.6h-227c-6.4,0-11.6-5.2-11.6-11.6V124 c0-6.4,5.2-11.6,11.6-11.6h227c6.4,0,11.6,5.2,11.6,11.6V449.6z"/><path d="M401.05,0h-227c-21.3,0-38.6,17.3-38.6,38.6c0,7.5,6,13.5,13.5,13.5s13.5-6,13.5-13.5c0-6.4,5.2-11.6,11.6-11.6h227 c6.4,0,11.6,5.2,11.6,11.6v325.7c0,6.4-5.2,11.6-11.6,11.6c-7.5,0-13.5,6-13.5,13.5s6,13.5,13.5,13.5c21.3,0,38.6-17.3,38.6-38.6 V38.6C439.65,17.3,422.35,0,401.05,0z"/></g></symbol><symbol id="search-icon" viewBox="0 0 512 512"><g><g><path d="M225.474,0C101.151,0,0,101.151,0,225.474c0,124.33,101.151,225.474,225.474,225.474 c124.33,0,225.474-101.144,225.474-225.474C450.948,101.151,349.804,0,225.474,0z M225.474,409.323 c-101.373,0-183.848-82.475-183.848-183.848S124.101,41.626,225.474,41.626s183.848,82.475,183.848,183.848 S326.847,409.323,225.474,409.323z"/></g></g><g><g><path d="M505.902,476.472L386.574,357.144c-8.131-8.131-21.299-8.131-29.43,0c-8.131,8.124-8.131,21.306,0,29.43l119.328,119.328 c4.065,4.065,9.387,6.098,14.715,6.098c5.321,0,10.649-2.033,14.715-6.098C514.033,497.778,514.033,484.596,505.902,476.472z"/></g></g></symbol><symbol id="font-size-icon" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"/><path d="M11.246 15H4.754l-2 5H.6L7 4h2l6.4 16h-2.154l-2-5zm-.8-2L8 6.885 5.554 13h4.892zM21 12.535V12h2v8h-2v-.535a4 4 0 1 1 0-6.93zM19 18a2 2 0 1 0 0-4 2 2 0 0 0 0 4z"/></symbol><symbol id="add-icon" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"/><path d="M11 11V5h2v6h6v2h-6v6h-2v-6H5v-2z"/></symbol><symbol id="minus-icon" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"/><path d="M5 11h14v2H5z"/></symbol><symbol id="dark-theme-icon" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"/><path d="M10 7a7 7 0 0 0 12 4.9v.1c0 5.523-4.477 10-10 10S2 17.523 2 12 6.477 2 12 2h.1A6.979 6.979 0 0 0 10 7zm-6 5a8 8 0 0 0 15.062 3.762A9 9 0 0 1 8.238 4.938 7.999 7.999 0 0 0 4 12z"/></symbol><symbol id="light-theme-icon" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"/><path d="M12 18a6 6 0 1 1 0-12 6 6 0 0 1 0 12zm0-2a4 4 0 1 0 0-8 4 4 0 0 0 0 8zM11 1h2v3h-2V1zm0 19h2v3h-2v-3zM3.515 4.929l1.414-1.414L7.05 5.636 5.636 7.05 3.515 4.93zM16.95 18.364l1.414-1.414 2.121 2.121-1.414 1.414-2.121-2.121zm2.121-14.85l1.414 1.415-2.121 2.121-1.414-1.414 2.121-2.121zM5.636 16.95l1.414 1.414-2.121 2.121-1.414-1.414 2.121-2.121zM23 11v2h-3v-2h3zM4 11v2H1v-2h3z"/></symbol><symbol id="reset-icon" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"/><path d="M18.537 19.567A9.961 9.961 0 0 1 12 22C6.477 22 2 17.523 2 12S6.477 2 12 2s10 4.477 10 10c0 2.136-.67 4.116-1.81 5.74L17 12h3a8 8 0 1 0-2.46 5.772l.997 1.795z"/></symbol><symbol id="down-icon" viewBox="0 0 16 16"><path fill-rule="evenodd" clip-rule="evenodd" d="M12.7803 6.21967C13.0732 6.51256 13.0732 6.98744 12.7803 7.28033L8.53033 11.5303C8.23744 11.8232 7.76256 11.8232 7.46967 11.5303L3.21967 7.28033C2.92678 6.98744 2.92678 6.51256 3.21967 6.21967C3.51256 5.92678 3.98744 5.92678 4.28033 6.21967L8 9.93934L11.7197 6.21967C12.0126 5.92678 12.4874 5.92678 12.7803 6.21967Z"></path></symbol><symbol id="codepen-icon" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"/><path d="M16.5 13.202L13 15.535v3.596L19.197 15 16.5 13.202zM14.697 12L12 10.202 9.303 12 12 13.798 14.697 12zM20 10.869L18.303 12 20 13.131V10.87zM19.197 9L13 4.869v3.596l3.5 2.333L19.197 9zM7.5 10.798L11 8.465V4.869L4.803 9 7.5 10.798zM4.803 15L11 19.131v-3.596l-3.5-2.333L4.803 15zM4 13.131L5.697 12 4 10.869v2.262zM2 9a1 1 0 0 1 .445-.832l9-6a1 1 0 0 1 1.11 0l9 6A1 1 0 0 1 22 9v6a1 1 0 0 1-.445.832l-9 6a1 1 0 0 1-1.11 0l-9-6A1 1 0 0 1 2 15V9z"/></symbol><symbol id="close-icon" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"/><path d="M12 10.586l4.95-4.95 1.414 1.414-4.95 4.95 4.95 4.95-1.414 1.414-4.95-4.95-4.95 4.95-1.414-1.414 4.95-4.95-4.95-4.95L7.05 5.636z"/></symbol><symbol id="menu-icon" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"/><path d="M3 4h18v2H3V4zm0 7h18v2H3v-2zm0 7h18v2H3v-2z"/></symbol></defs></svg></head><body data-theme="light"><div class="sidebar-container"><div class="sidebar" id="sidebar"><a href="/" class="sidebar-title sidebar-title-anchor">3Dmol.js</a><div class="sidebar-items-container"><div class="sidebar-section-title with-arrow" data-isopen="false" id="mei5HJjYKLn6aua5Z5PM5"><div>Classes</div><svg><use xlink:href="#down-icon"></use></svg></div><div class="sidebar-section-children-container"><div class="sidebar-section-children"><a href="$3Dmol.Label.html">Label</a></div><div class="sidebar-section-children"><a href="$3Dmol.StateManager.html">StateManager</a></div><div class="sidebar-section-children"><a href="$3Dmol.UI.html">UI</a></div><div class="sidebar-section-children"><a href="Color.html">Color</a></div><div class="sidebar-section-children"><a href="CustomLinear.html">CustomLinear</a></div><div class="sidebar-section-children"><a href="Cylinder.html">Cylinder</a></div><div class="sidebar-section-children"><a href="GLModel.html">GLModel</a></div><div class="sidebar-section-children"><a href="GLShape.html">GLShape</a></div><div class="sidebar-section-children"><a href="GLShape_GLShape.html">GLShape</a></div><div class="sidebar-section-children"><a href="GLViewer.html">GLViewer</a></div><div class="sidebar-section-children"><a href="GLVolumetricRender.html">GLVolumetricRender</a></div><div class="sidebar-section-children"><a href="Matrix3.html">Matrix3</a></div><div class="sidebar-section-children"><a href="Matrix4.html">Matrix4</a></div><div class="sidebar-section-children"><a href="Quaternion.html">Quaternion</a></div><div class="sidebar-section-children"><a href="ROYGB.html">ROYGB</a></div><div class="sidebar-section-children"><a href="RWB.html">RWB</a></div><div class="sidebar-section-children"><a href="Ray.html">Ray</a></div><div class="sidebar-section-children"><a href="Sinebow.html">Sinebow</a></div><div class="sidebar-section-children"><a href="Sphere.html">Sphere</a></div><div class="sidebar-section-children"><a href="Surface.html">Surface</a></div><div class="sidebar-section-children"><a href="Triangle.html">Triangle</a></div><div class="sidebar-section-children"><a href="Vector2.html">Vector2</a></div><div class="sidebar-section-children"><a href="Vector3.html">Vector3</a></div><div class="sidebar-section-children"><a href="VolumeData.html">VolumeData</a></div></div><div class="sidebar-section-title with-arrow" data-isopen="false" id="kv4Yx5z0THf_b8XR4Gje1"><div>Namespaces</div><svg><use xlink:href="#down-icon"></use></svg></div><div class="sidebar-section-children-container"><div class="sidebar-section-children"><a href="GLDraw.html">GLDraw</a></div></div><div class="sidebar-section-title with-arrow" data-isopen="false" id="ykThSufQWJcKGT1kXzr-A"><div>Tutorials</div><svg><use xlink:href="#down-icon"></use></svg></div><div class="sidebar-section-children-container"><div class="sidebar-section-children"><a href="tutorial-code.html">Using 3Dmol within your code</a></div><div class="sidebar-section-children"><a href="tutorial-embeddable.html">Embedding a 3Dmol Viewer</a></div><div class="sidebar-section-children"><a href="tutorial-home.html">3Dmol Tutorials - Home</a></div><div class="sidebar-section-children"><a href="tutorial-learning_environment.html">Active Learning with 3Dmol.js</a></div><div class="sidebar-section-children"><a href="tutorial-url.html">Viewing Molecules with the 3Dmol Server</a></div></div><div class="sidebar-section-title with-arrow" data-isopen="false" id="XcP4RUEg6tp7YKHbBVi9E"><div>Interfaces</div><svg><use xlink:href="#down-icon"></use></svg></div><div class="sidebar-section-children-container"><div class="sidebar-section-children"><a href="AmbientOcclusionStyle.html">AmbientOcclusionStyle</a></div><div class="sidebar-section-children"><a href="ArrowSpec.html">ArrowSpec</a></div><div class="sidebar-section-children"><a href="AtomSelectionSpec.html">AtomSelectionSpec</a></div><div class="sidebar-section-children"><a href="AtomSpec.html">AtomSpec</a></div><div class="sidebar-section-children"><a href="AtomStyleSpec.html">AtomStyleSpec</a></div><div class="sidebar-section-children"><a href="BondStyle.html">BondStyle</a></div><div class="sidebar-section-children"><a href="BoxSpec.html">BoxSpec</a></div><div class="sidebar-section-children"><a href="CartoonStyleSpec.html">CartoonStyleSpec</a></div><div class="sidebar-section-children"><a href="ClickSphereStyleSpec.html">ClickSphereStyleSpec</a></div><div class="sidebar-section-children"><a href="CrossStyleSpec.html">CrossStyleSpec</a></div><div class="sidebar-section-children"><a href="CurveSpec.html">CurveSpec</a></div><div class="sidebar-section-children"><a href="CustomShapeSpec.html">CustomShapeSpec</a></div><div class="sidebar-section-children"><a href="CylinderSpec.html">CylinderSpec</a></div><div class="sidebar-section-children"><a href="DashedBondSpec.html">DashedBondSpec</a></div><div class="sidebar-section-children"><a href="FogSpec.html">FogSpec</a></div><div class="sidebar-section-children"><a href="IsoSurfaceSpec.html">IsoSurfaceSpec</a></div><div class="sidebar-section-children"><a href="LabelSpec.html">LabelSpec</a></div><div class="sidebar-section-children"><a href="LineSpec.html">LineSpec</a></div><div class="sidebar-section-children"><a href="LineStyleSpec.html">LineStyleSpec</a></div><div class="sidebar-section-children"><a href="OutlineStyle.html">OutlineStyle</a></div><div class="sidebar-section-children"><a href="ParserOptionsSpec.html">ParserOptionsSpec</a></div><div class="sidebar-section-children"><a href="ShapeSpec.html">ShapeSpec</a></div><div class="sidebar-section-children"><a href="SphereSpec.html">SphereSpec</a></div><div class="sidebar-section-children"><a href="SphereStyleSpec.html">SphereStyleSpec</a></div><div class="sidebar-section-children"><a href="StickStyleSpec.html">StickStyleSpec</a></div><div class="sidebar-section-children"><a href="SurfaceStyleSpec.html">SurfaceStyleSpec</a></div><div class="sidebar-section-children"><a href="UnitCellStyleSpec.html">UnitCellStyleSpec</a></div><div class="sidebar-section-children"><a href="ViewStyle.html">ViewStyle</a></div><div class="sidebar-section-children"><a href="ViewerGridSpec.html">ViewerGridSpec</a></div><div class="sidebar-section-children"><a href="ViewerSpec.html">ViewerSpec</a></div><div class="sidebar-section-children"><a href="VolumetricRendererSpec.html">VolumetricRendererSpec</a></div><div class="sidebar-section-children"><a href="WithinSelectionSpec.html">WithinSelectionSpec</a></div><div class="sidebar-section-children"><a href="global.html#XYZ">XYZ</a></div></div><div class="sidebar-section-title with-arrow" data-isopen="false" id="jmKnIXRJjdjZ366ci7cdd"><div>Global</div><svg><use xlink:href="#down-icon"></use></svg></div><div class="sidebar-section-children-container"><div class="sidebar-section-children"><a href="global.html#BCIF">BCIF</a></div><div class="sidebar-section-children"><a href="global.html#CAP">CAP</a></div><div class="sidebar-section-children"><a href="global.html#CDJSON">CDJSON</a></div><div class="sidebar-section-children"><a href="global.html#CIF">CIF</a></div><div class="sidebar-section-children"><a href="global.html#CUBE">CUBE</a></div><div class="sidebar-section-children"><a href="global.html#ColorSpec">ColorSpec</a></div><div class="sidebar-section-children"><a href="global.html#ColorschemeSpec">ColorschemeSpec</a></div><div class="sidebar-section-children"><a href="global.html#GRO">GRO</a></div><div class="sidebar-section-children"><a href="global.html#GradientSpec">GradientSpec</a></div><div class="sidebar-section-children"><a href="global.html#MMTFparser">MMTFparser</a></div><div class="sidebar-section-children"><a href="global.html#MOL2">MOL2</a></div><div class="sidebar-section-children"><a href="global.html#OFFSETS">OFFSETS</a></div><div class="sidebar-section-children"><a href="global.html#PDB">PDB</a></div><div class="sidebar-section-children"><a href="global.html#PQR">PQR</a></div><div class="sidebar-section-children"><a href="global.html#PRMTOP">PRMTOP</a></div><div class="sidebar-section-children"><a href="global.html#SDF">SDF</a></div><div class="sidebar-section-children"><a href="global.html#SurfaceType">SurfaceType</a></div><div class="sidebar-section-children"><a href="global.html#VASP">VASP</a></div><div class="sidebar-section-children"><a href="global.html#XYZ">XYZ</a></div><div class="sidebar-section-children"><a href="global.html#assignPDBBonds">assignPDBBonds</a></div><div class="sidebar-section-children"><a href="global.html#builtinColorSchemes">builtinColorSchemes</a></div><div class="sidebar-section-children"><a href="global.html#builtinGradients">builtinGradients</a></div><div class="sidebar-section-children"><a href="global.html#conversionMatrix3">conversionMatrix3</a></div><div class="sidebar-section-children"><a href="global.html#createViewer">createViewer</a></div><div class="sidebar-section-children"><a href="global.html#createViewerGrid">createViewerGrid</a></div><div class="sidebar-section-children"><a href="global.html#decode">decode</a></div><div class="sidebar-section-children"><a href="global.html#dic">dic</a></div><div class="sidebar-section-children"><a href="global.html#download">download</a></div><div class="sidebar-section-children"><a href="global.html#elementColors">elementColors</a></div><div class="sidebar-section-children"><a href="global.html#get">get</a></div><div class="sidebar-section-children"><a href="global.html#getColorFromStyle">getColorFromStyle</a></div><div class="sidebar-section-children"><a href="global.html#getbin">getbin</a></div><div class="sidebar-section-children"><a href="global.html#parseV3000">parseV3000</a></div><div class="sidebar-section-children"><a href="global.html#setSyncSurface">setSyncSurface</a></div><div class="sidebar-section-children"><a href="global.html#ssColors">ssColors</a></div><div class="sidebar-section-children"><a href="global.html#syncSurface">syncSurface</a></div><div class="sidebar-section-children"><a href="global.html#viewers">viewers</a></div></div></div></div></div><div class="navbar-container" id="VuAckcnZhf"><nav class="navbar"><div class="navbar-left-items"><div class="navbar-item"><a id="" href="https://3dmol.org/doc/index.html" target="">Documentation</a></div><div class="navbar-item"><a id="" href="tutorial-home.html" target="">Tutorials</a></div><div class="navbar-item"><a id="" href="https://github.com/3dmol/3Dmol.js" target="_blank">GitHub</a></div></div><div class="navbar-right-items"><div class="navbar-right-item"><button class="icon-button search-button" aria-label="open-search"><svg><use xlink:href="#search-icon"></use></svg></button></div><div class="navbar-right-item"><button class="icon-button theme-toggle" aria-label="toggle-theme"><svg><use class="theme-svg-use" xlink:href="#dark-theme-icon"></use></svg></button></div><div class="navbar-right-item"><button class="icon-button font-size" aria-label="change-font-size"><svg><use xlink:href="#font-size-icon"></use></svg></button></div></div><nav></nav></nav></div><div class="toc-container"><div class="toc-content"><span class="bold">On this page</span><div id="eed4d2a0bfd64539bb9df78095dec881"></div></div></div><div class="body-wrapper"><div class="main-content"><div class="main-wrapper"><section id="source-page" class="source-page"><header><h1 id="title" class="has-anchor">ui_ui.js</h1></header><article><pre class="prettyprint source lang-js"><code>/** * $3Dmol.UI - UI creates panels in the viewer to assist control of the viewport * @constructor * @param {$3Dmol.StateManager} stateManager StateManager is required to have interaction between glviewer and the ui. * @param {Object} config Loads the user defined parameters to generate the ui * @param {Object} parentElement Refers the parent division used to hold the canvas for 3Dmol.js */ $3Dmol.UI = (function () { /* The dictionaries are for dropdown menus and validation of the viewer */ // prop : It is used to add the option for property in context menu in the 3dmol ui // the code for prop can be found under /ui/ui.js -> UI -> ContextMenu -> setProperties -> submit.ui.on // gui : It is used to generate forms for different features in the 3dmol ui // the code for gui can be found under /ui/form.js -> Form (Form defination) // floatType : separates integer from float since these are used in // input validation of the 3dmol ui var validAtomSpecs = { "resn": { type: "string", valid: true, prop: true, gui: true }, // Parent residue name "x": { type: "number", floatType: true, valid: false, step: 0.1, prop: true }, // Atom's x coordinate "y": { type: "number", floatType: true, valid: false, step: 0.1, prop: true }, // Atom's y coordinate "z": { type: "number", floatType: true, valid: false, step: 0.1, prop: true }, // Atom's z coordinate "color": { type: "color", gui: false }, // Atom's color, as hex code "surfaceColor": { type: "color", gui: false }, // Hex code for color to be used for surface patch over this atom "elem": { type: "element", gui: true, prop: true }, // Element abbreviation (e.g. 'H', 'Ca', etc) "hetflag": { type: "boolean", valid: false, gui: true }, // Set to true if atom is a heteroatom "chain": { type: "string", gui: true, prop: true }, // Chain this atom belongs to, if specified in input file (e.g 'A' for chain A) "resi": { type: "array_range", gui: true }, // Residue number "icode": { type: "number", valid: false, step: 0.1 }, "rescode": { type: "number", valid: false, step: 0.1, prop: true }, "serial": { type: "number", valid: false, step: 0.1 }, // Atom's serial id numbermodels "atom": { type: "string", valid: false, gui: true, prop: true }, // Atom name; may be more specific than 'elem' (e.g 'CA' for alpha carbon) "bonds": { type: "array", valid: false }, // Array of atom ids this atom is bonded to "ss": { type: "string", valid: false }, // Secondary structure identifier (for cartoon render; e.g. 'h' for helix) "singleBonds": { type: "boolean", valid: false }, // true if this atom forms only single bonds or no bonds at all "bondOrder": { type: "array", valid: false }, // Array of this atom's bond orders, corresponding to bonds identfied by 'bonds' "properties": { type: "properties", valid: false }, // Optional mapping of additional properties "b": { type: "number", floatType: true, valid: false, step: 0.1, prop: true }, // Atom b factor data "pdbline": { type: "string", valid: false }, // If applicable, this atom's record entry from the input PDB file (used to output new PDB from models) "clickable": { type: "boolean", valid: false, gui: false }, // Set this flag to true to enable click selection handling for this atom "contextMenuEnabled": { type: "boolean", valid: false, gui: false }, // Set this flag to true to enable click selection handling for this atom "callback": { type: "function", valid: false }, // Callback click handler function to be executed on this atom and its parent viewer "invert": { type: "boolean", valid: false }, // for selection, inverts the meaning of the selection //unsure about this "reflectivity": { type: "number", floatType: true, gui: false, step: 0.1 }, //for describing the reflectivity of a model "altLoc": { type: "invalid", valid: false }, //alternative location, e.g. in PDB "sym": { type: 'number', gui: false }, //which symmetry }; //type is irrelivent here becuase htey are are invalid var validExtras = { // valid atom specs are ok too "model": { type: "string", valid: false }, // a single model or list of models from which atoms should be selected "bonds": { type: "number", valid: false, gui: true }, // overloaded to select number of bonds, e.g. {bonds: 0} will select all nonbonded atoms "predicate": { type: "string", valid: false }, // user supplied function that gets passed an {AtomSpec} and should return true if the atom should be selected "invert": { type: "boolean", valid: false, gui: true }, // if set, inverts the meaning of the selection "byres": { type: "boolean", valid: false, gui: true }, // if set, expands the selection to include all atoms of any residue that has any atom selected "expand": { type: "number", valid: false, gui: false }, // expands the selection to include all atoms within a given distance from the selection "within": { type: "string", valid: false }, // intersects the selection with the set of atoms within a given distance from another selection "and": { type: "string", valid: false }, // and boolean logic "or": { type: "string", valid: false }, // or boolean logic "not": { type: "string", valid: false }, // not boolean logic }; var validAtomSelectionSpecs = $3Dmol.extend({}, validAtomSpecs); validAtomSelectionSpecs = $3Dmol.extend(validAtomSelectionSpecs, validExtras); var validLineSpec = { "hidden": { type: "boolean", gui: true }, "linewidth": { type: "number", floatType: true, gui: true, step: 0.1, default: 1.0 }, "colorscheme": { type: "colorscheme", gui: true }, "color": { type: "color", gui: true }, "opacity": { type: "number", floatType: true, gui: true, step: 0.1, default: 1, min: 0, max: 1 }, }; var validCrossSpec = { "hidden": { type: "boolean", gui: true }, "linewidth": { type: "number", floatType: true, gui: false, step: 0.1, default: 1.0, min: 0 },//deprecated "colorscheme": { type: "colorscheme", gui: true }, "color": { type: "color", gui: true }, "radius": { type: "number", floatType: true, gui: true, step: 0.1, default: 1, min: 0.1 }, "scale": { type: "number", floatType: true, gui: true, step: 0.1, default: 1, min: 0 }, "opacity": { type: "number", floatType: true, gui: true, step: 0.1, default: 1, min: 0, max: 1 }, }; var validStickSpec = { "hidden": { type: "boolean", gui: true }, "colorscheme": { type: "colorscheme", gui: true }, "color": { type: "color", gui: true }, "radius": { type: "number", floatType: true, gui: true, step: 0.1, default: 0.25, min: 0.1 }, "singleBonds": { type: "boolean", gui: true }, "opacity": { type: "number", floatType: true, gui: true, step: 0.1, default: 1, min: 0, max: 1 }, }; var validSphereSpec = { "hidden": { type: "boolean", gui: false }, // needed in the new gui it has separate function to hide the spheres "singleBonds": { type: "boolean", gui: true }, "colorscheme": { type: "colorscheme", gui: true }, "color": { type: "color", gui: true }, "radius": { type: "number", floatType: true, gui: true, step: 0.1, default: 1.5, min: 0 }, "scale": { type: "number", floatType: true, gui: true, step: 0.1, default: 1.0, min: 0.1 }, "opacity": { type: "number", floatType: true, gui: true, step: 0.1, default: 1, min: 0, max: 1 }, }; var validCartoonSpec = { "style": { validItems: ["trace", "oval", "rectangle", "parabola", "edged"], gui: true }, "color": { type: "color", gui: true, spectrum: true }, "arrows": { type: "boolean", gui: true }, "ribbon": { type: "boolean", gui: true }, "hidden": { type: "boolean", gui: true }, "tubes": { type: "boolean", gui: true }, "thickness": { type: "number", floatType: true, gui: true, step: 0.1, default: 1, min: 0 }, "width": { type: "number", floatType: true, gui: true, step: 0.1, default: 1, min: 0 }, "opacity": { type: "number", floatType: true, gui: true, step: 0.1, default: 1, min: 0, max: 1 }, }; var validAtomStyleSpecs = { "line": { validItems: validLineSpec, type: "form", gui: true }, // draw bonds as lines "cross": { validItems: validCrossSpec, type: "form", gui: true }, // draw atoms as crossed lines (aka stars) "stick": { validItems: validStickSpec, type: "form", gui: true }, // draw bonds as capped cylinders "sphere": { validItems: validSphereSpec, type: "form", gui: true }, // draw atoms as spheres "cartoon": { validItems: validCartoonSpec, type: "form", gui: true }, // draw cartoon representation of secondary structure "colorfunc": { validItems: null, type: "js", valid: false }, "clicksphere": { validItems: validSphereSpec, type: "form" } //invisible style for click handling }; var validSurfaceSpecs = { "opacity": { type: "number", floatType: true, gui: true, step: 0.01, default: 1, min: 0, max: 1 }, "colorscheme": { type: "colorscheme", gui: true }, "color": { type: "color", gui: true }, "voldata": { type: "number", floatType: true, gui: false }, "volscheme": { type: "number", floatType: true, gui: false }, "map": { type: "number", gui: false } }; function UI(stateManager, config, parentElement) { config = config || {} // Extract the viewer and then render it var icons = new $3Dmol.UI.Icons(); var _editingForm = null; var mainParent = $(parentElement[0]); // Generates the necessary UI elements var HEIGHT = config.height; this.tools = generateUI(config); /** * Creates all the jquery object of different UI features */ function generateUI() { var modelToolBar = new ModelToolbar(); mainParent.append(modelToolBar.ui); setLocation(mainParent, modelToolBar.ui, 'left', 'top'); // modelToolBar.updateInputLength(); var contextMenu = new ContextMenu(); mainParent.append(contextMenu.ui); setPosition(contextMenu.ui, 100, 100) var surfaceMenu = new SurfaceMenu(); mainParent.append(surfaceMenu.ui); setLocation(mainParent, surfaceMenu.ui, 'right', 'top', 0, modelToolBar.ui.height() + 5); var selectionBox = new SelectionBox(icons.select); mainParent.append(selectionBox.ui); setLocation(mainParent, selectionBox.ui, 'left', 'top', 0, modelToolBar.ui.height() + 5); // Fixing Context Menu Behaviour selectionBox.ui.on('mousedown', () => { stateManager.exitContextMenu(); }); surfaceMenu.ui.on('mousedown', () => { stateManager.exitContextMenu(); }); return { modelToolBar: modelToolBar, selectionBox: selectionBox, contextMenu: contextMenu, surfaceMenu: surfaceMenu } } /** * Resize the panel with respect to the new viewport * * @function $3Dmol.UI#resize */ this.resize = function () { var selectionBox = this.tools.selectionBox; var surfaceMenu = this.tools.surfaceMenu; var modelToolBar = this.tools.modelToolBar; var HEIGHT = mainParent.height(); setLocation(mainParent, modelToolBar.ui, 'left', 'top'); // modelToolBar.updateInputLength(); setLocation(mainParent, selectionBox.ui, 'left', 'top', 0, modelToolBar.ui.height() + 5); selectionBox.updateScrollBox(HEIGHT); setLocation(mainParent, surfaceMenu.ui, 'right', 'top', 0, modelToolBar.ui.height() + 5); surfaceMenu.updateScrollBox(HEIGHT); } /* * ModelToolbar is part of $3Dmol.UI to edit or change the model loaded into the viewer * * @function ModelToolbar */ function ModelToolbar() { var boundingBox = this.ui = $('&lt;div>&lt;/div>'); boundingBox.css({ 'position': 'relative', 'min-width': '150px' }); var modelButton = new button(icons.molecule, 20, { tooltip: 'Toggle Model Selection Bar' }); boundingBox.append(modelButton.ui); modelButton.ui.css({ 'display': 'inline-block', 'top': '3px', }); var control = { urlType: { active: true, value: null, key: 'Model type' }, url: { active: true, value: null, key: 'Url' }, }; var surroundingBox = $('&lt;div>&lt;/div>'); surroundingBox.css({ 'display': 'inline-block', 'background': '#e4e4e4', 'padding': '2px', 'border-radius': '3px', // 'width' : '90%' }); boundingBox.append(surroundingBox); var currentModelBox = $('&lt;div>&lt;/div>'); currentModelBox.css({ }); var currentModel = $('&lt;div>&lt;/div>'); currentModel.css({ 'display': 'inline-block', 'font-family': 'Arial', 'font-size': '12px', 'font-weight': 'bold', // 'padding' : '3px' }); currentModelBox.append(currentModel); var changeButton = new button(icons.change, 16, { tooltip: 'Change Model', backgroundColor: 'white', bfr: 0.5 }); changeButton.ui.css({ 'display': 'inline-block', 'margin-left': '4px', }); currentModelBox.append(changeButton.ui); currentModelBox.hide(); surroundingBox.append(currentModelBox); var formBox = $('&lt;div>&lt;/div>'); surroundingBox.append(formBox); var dbs = 'pdb,mmtf,cid'.split(','); var list = this.list = new $3Dmol.UI.Form.ListInput(control.urlType, dbs); list.showAlertBox = false; list.ui.css({ 'display': 'inline-block', }) formBox.append(list.ui); var input = this.url = new $3Dmol.UI.Form.Input(control.url); formBox.append(input.ui); input.ui.css({ 'display': 'inline-block', 'width': '125px' }); // input.setWidth(125); var submitButton = new button(icons.tick, 16, { bfr: 0.5, backgroundColor: 'lightgreen', tooltip: 'Add Model' }); submitButton.ui.css({ 'margin': '0px' }) formBox.append(submitButton.ui); this.updateInputLength = function () { // var width = parentElement.width()*0.3; // boundingBox.width(width); // input.setWidth(width - 12); } modelButton.ui.on('click', () => { surroundingBox.toggle(); }); submitButton.ui.on('click', function () { var validateDb = list.validate(); var validateId = input.validate(); if (validateId &amp;&amp; validateDb) { stateManager.addModel(control); } }); /* * Sets the title in the ui with specified value * * @function ModelToolbar#setModel * @param {String} heading Name of the molecule that is to be displayed on the title */ this.setModel = function (heading) { currentModel.text(heading); currentModelBox.show(); formBox.hide(); } changeButton.ui.on('click', function () { currentModelBox.hide(); formBox.show(); input.setValue(''); }); boundingBox.on('keypress', function (e) { if (e.key == 'Enter' || e.key == 'Return') { submitButton.ui.trigger('click') } }); } /* * Selection box creates the UI panel to manipulate selections and style that are drawn * on the viewport * * @function SelectionBox * @param {$3Dmol.UI.Icons} icon takes the svg code for the icon that is to be used to display * selection box * @return {Object} Jquery element of div */ function SelectionBox(icon, side = 'left') { var selectionBox = this.ui = $('&lt;div>&lt;/div>'); _editingForm = false; var selectionObjects = []; var selections = $('&lt;div>&lt;/div>'); var scrollBox = $('&lt;div>&lt;/div>'); selections.css('opacity', '0.9'); var showArea = $('&lt;div>&lt;/div>'); var addArea = $('&lt;div>&lt;/div>'); var plusButton = new button(icons.plus, 20, { tooltip: 'Add New Selection' }); plusButton.ui.css('margin', '0px'); var hideButton = new button(icon, 20, { tooltip: 'Toggle Selection Menu' }); this.selectionObjects = []; // Content selectionBox.append(hideButton.ui); selectionBox.append(showArea); selectionBox.css('position', 'absolute'); scrollBox.append(selections); showArea.append(scrollBox); addArea.append(plusButton.ui); var alertBox = new AlertBox(); showArea.append(alertBox.ui); showArea.append(addArea); alertBox.ui.css('width', 162); // CSS if (side == 'left') { selectionBox.css('text-align', 'left'); } else if (side == 'right') { selectionBox.css('text-align', 'right'); } else { // Add alert box code selectionBox.css('text-align', 'right'); } showArea.css('box-sizing', 'border-box'); showArea.css('padding', '3px'); // showArea.css('width', '162px'); scrollBox.css('max-height', HEIGHT * 0.8); scrollBox.css('overflow-y', 'auto'); scrollBox.css('overflow-x', 'visible'); selections.css('box-sizing', 'content-box'); this.updateScrollBox = function (height) { scrollBox.css('max-height', height * 0.8); } // Action var hidden = true; showArea.hide(); hideButton.ui.click(toggleHide); function toggleHide() { if (hidden) { showArea.show(100); } else { showArea.hide(100); } hidden = !hidden; } /* * Card for manipulation of a selection form and related styles * * @function Selection */ function Selection() { var boundingBox = this.ui = $('&lt;div>&lt;/div>'); var sid = this.id = null; selectionObjects.push(this); boundingBox.css({ 'background': '#e8e8e8', 'padding': '4px 4px 2px 4px', 'border-radius': '6px', 'margin-bottom': '3px', 'position': 'relative', 'width': '156px' }); var header = $('&lt;div>&lt;/div>'); boundingBox.append(header); var heading = $('&lt;div>&lt;/div>'); var controls = $('&lt;div>&lt;/div>'); header.append(heading, controls); heading.css({ 'font-family': 'Arial', 'font-weight': 'bold', 'font-size': '12px', 'display': 'inline-block', 'width': '60px' }); controls.css({ 'display': 'inline-block' }); header.hide(); controls.editMode = false; var removeButton = new button(icons.minus, 16, { bfr: 0.5, backgroundColor: '#f06f6f', tooltip: 'Remove Selection' }); var editButton = new button(icons.pencil, 16, { tooltip: 'Edit Selection' }); var visibleButton = new button(icons.visible, 16, { tooltip: 'Show / Hide Selection' }); controls.append(removeButton.ui) controls.append(editButton.ui); controls.append(visibleButton.ui); var parameters = $('&lt;div>&lt;/div>'); boundingBox.append(parameters); var styleHolder = $('&lt;div>&lt;/div>'); removeButton.ui.on('click', function () { stateManager.removeSelection(sid); boundingBox.detach(); //delete this; }); editButton.ui.on('click', function () { parameters.toggle(); }); var hidden = false; visibleButton.ui.on('click', () => { stateManager.toggleHide(sid); if (hidden) { hidden = false; visibleButton.setSVG(icons.visible); } else { hidden = true; visibleButton.setSVG(icons.invisible); } }); var styleBox = new StyleBox(); styleHolder.append(styleBox.ui); styleBox.ui.css({ 'position': 'static', // 'left' : '0', 'width': 'px', 'border-radius': '4px' }); styleBox.ui.hide(); var allControl = this.allSelector = { key: 'Select All Atom', value: null, active: true } var allCheckBox = new $3Dmol.UI.Form.Checkbox(allControl); parameters.append(allCheckBox.ui); var selectionFormControl = this.selectionValue = { key: 'Selection Spec', value: null, active: true } var selectionSpecForm = new $3Dmol.UI.Form(validAtomSelectionSpecs, selectionFormControl); parameters.append(selectionSpecForm.ui); var submitControls = $('&lt;div>&lt;/div>'); var submit = new button(icons.tick, 16, { backgroundColor: 'lightgreen', tooltip: 'Submit' }); var cancel = new button(icons.cross, 16, { backgroundColor: 'lightcoral', tooltip: 'Cancel' }); submitControls.append(submit.ui, cancel.ui); var alertBox = new AlertBox(); parameters.append(alertBox.ui); parameters.append(submitControls); boundingBox.append(styleHolder); allCheckBox.update = function () { selectionSpecForm.ui.toggle(); } function finalizeSelection(id) { header.show(); controls.editMode = true; sid = this.id = id; heading.text('Sel#' + id); boundingBox.attr('data-id', id); parameters.hide(); styleBox.setSid(id); styleBox.ui.show(); } function checkAndAddSelection(sid = null) { var validate = selectionSpecForm.validate(); if (validate) { selectionSpecForm.getValue(); var checkAtoms = stateManager.checkAtoms(selectionFormControl.value); if (Object.keys(selectionFormControl.value).length == 0) { alertBox.error('Please enter some input'); } else { if (checkAtoms) { var id = stateManager.addSelection(selectionFormControl.value, sid); finalizeSelection(id); if (sid == null) _editingForm = false; } else { alertBox.error('No atom selected'); } } } else { alertBox.error('Invalid Input'); } } function removeSelf() { // delete selectionToRemove; } submit.ui.on('click', () => { if (controls.editMode == false) { if (allControl.value) { let id = stateManager.addSelection({}); finalizeSelection(id); _editingForm = false; } else { checkAndAddSelection(); } } else { if (allControl.value) { stateManager.addSelection({}, sid); finalizeSelection(sid); } else { checkAndAddSelection(sid); } } }); var self = this; cancel.ui.on('click', () => { if (controls.editMode) { parameters.hide(); } else { boundingBox.detach(); removeSelf(self); _editingForm = false; } }); boundingBox.on('keyup', (e) => { if (e.key == 'Enter') { submit.ui.trigger('click'); } }); /* * @function Selection#setProperty * @param {string} id Id of the selection created in StateManager * @param {Object} specs Defination of the selection that will be used to set default * values in the form */ this.setProperty = function (id, specs) { // check for all selection if (Object.keys(specs).length == 0) { allCheckBox.setValue(true) } else { selectionSpecForm.setValue(specs); } // finalize the selection finalizeSelection(id); } /* * Adds style to the given selection * * @function Selection#addStyle * @param {String} selId Id of the selection to inititate the StyleBox * @param {String} styleId Id of the style that is created through StateManager * @param {AtomStyleSpecs} styleSpecs */ this.addStyle = function (selId, styleId, styleSpecs) { styleBox.addStyle(selId, styleId, styleSpecs); } } plusButton.ui.on('click', () => { if (!_editingForm) { var newSelection = new Selection(); selections.append(newSelection.ui); _editingForm = true; } else { alertBox.warning('Please complete the previous form'); } }); /* * Remove all the selection card from the ui */ this.empty = function () { selections.empty(); _editingForm = false; } /* * Adds or create new selection card * * @function SelectionBox#editSelection * @param {String} id Id created in StateManager and passed down to this function during call * @param {AtomSelectionSpec} selSpec Selection spec that is used to generate the selection form * @param {String} styleId Id of style created in StateManager * @param {AtomStyleSpecs} styleSpec Style spec if specified add the selection to the current selection */ this.editSelection = function (id, selSpec, styleId, styleSpec) { // if selection does not exist create new // This thing works but I am not sure how! // Search selection with id var selectionUI = selections.children('[data-id=' + id + ']'); if (selectionUI.length == 0) { var selection = new Selection(); selection.setProperty(id, selSpec); selections.append(selection.ui); if (styleId != null) { selection.addStyle(id, styleId, styleSpec); } } } } /* * Creates StyleBox for listing out different styles inside the selection * * @function StyleBox * @param {String} selId Id of the selection for which the style box is created * @param {String} side Alignment of text inside the box */ function StyleBox(selId, side = 'left') { var styleBox = this.ui = $('&lt;div>&lt;/div>'); _editingForm = false; var sid = this.sid = selId; // selection id this.setSid = function (id) { sid = this.sid = id; } var styles = $('&lt;div>&lt;/div>'); var scrollBox = $('&lt;div>&lt;/div>'); styles.css('opacity', '0.9'); var showArea = $('&lt;div>&lt;/div>'); var addArea = $('&lt;div>&lt;/div>'); addArea.css('text-align', 'center'); var plusButton = new button(icons.plus, 20, { tooltip: 'Add New Style' }); plusButton.ui.css('margin', '0px'); this.selectionObjects = []; // Content styleBox.append(showArea); styleBox.css('position', 'absolute'); scrollBox.append(styles); showArea.append(scrollBox); var alertBox = new AlertBox(); showArea.append(alertBox.ui); addArea.append(plusButton.ui); showArea.append(addArea); // CSS if (side == 'left') { styleBox.css('text-align', 'left'); } else if (side == 'right') { styleBox.css('text-align', 'right'); } else { // Add alert box code styleBox.css('text-align', 'right'); } showArea.css('box-sizing', 'border-box'); showArea.css('padding', '3px'); // showArea.css('width', '162px'); showArea.css('background-color', '#a4a4a4') showArea.css('border-radius', '4px'); // scrollBox.css('max-height', HEIGHT*0.8); scrollBox.css('overflow', 'hidden'); // styles.css('max-height', HEIGHT*0.8); // styles.css('overflow', 'auto'); styles.css('box-sizing', 'content-box'); /* * Style card to define the value of the style * * @param {string} sid Id of the selction for which the style box is created * and this stye will be added under that selection */ function Style(sid) { var boundingBox = this.ui = $('&lt;div>&lt;/div>'); var stid = this.id = null; // style id boundingBox.css({ 'background': '#e8e8e8', 'padding': '4px 4px 2px 4px', 'border-radius': '6px', 'margin-bottom': '3px', 'position': 'relative' }); var header = $('&lt;div>&lt;/div>'); boundingBox.append(header); var heading = $('&lt;div>&lt;/div>'); var controls = $('&lt;div>&lt;/div>'); header.append(heading, controls); heading.css({ 'font-family': 'Arial', 'font-weight': 'bold', 'font-size': '12px', 'display': 'inline-block', 'width': '60px' }); controls.css({ 'display': 'inline-block' }); header.hide(); controls.editMode = false; var removeButton = new button(icons.minus, 16, { bfr: 0.5, backgroundColor: '#f06f6f', tooltip: 'Remove Style' }); var editButton = new button(icons.pencil, 16, { tooltip: 'Edit Style' }); var visibleButton = new button(icons.visible, 16, { tooltip: 'Show / Hide Style' }); controls.append(removeButton.ui) controls.append(editButton.ui); controls.append(visibleButton.ui); var parameters = $('&lt;div>&lt;/div>'); boundingBox.append(parameters); removeButton.ui.on('click', { parent: this, stid: stid }, function () { stateManager.removeStyle(sid, stid); boundingBox.detach(); //delete this; }); editButton.ui.on('click', function () { parameters.toggle(); }); var hidden = false; visibleButton.ui.on('click', () => { stateManager.toggleHideStyle(sid, stid); if (hidden) { hidden = false; visibleButton.setSVG(icons.visible); } else { hidden = true; visibleButton.setSVG(icons.invisible); } }); var styleFormControl = this.selectionValue = { key: 'Style Spec', value: null, active: true } var styleSpecForm = new $3Dmol.UI.Form(validAtomStyleSpecs, styleFormControl); parameters.append(styleSpecForm.ui); var submitControls = $('&lt;div>&lt;/div>'); var submit = new button(icons.tick, 16, { backgroundColor: 'lightgreen', tooltip: 'Submit' }); var cancel = new button(icons.cross, 16, { backgroundColor: 'lightcoral', tooltip: 'Cancel' }); submitControls.append(submit.ui, cancel.ui); var alertBox = new AlertBox(); parameters.append(alertBox.ui); parameters.append(submitControls); function finalizeStyle(id) { header.show(); controls.editMode = true; stid = id; heading.text('Sty#' + id); parameters.hide(); } function checkAndAddStyle(stid = null) { var validate = styleSpecForm.validate(); if (validate) { styleSpecForm.getValue(); if (Object.keys(styleFormControl.value).length == 0) { alertBox.error('Please enter some value'); } else { var id = stateManager.addStyle(styleFormControl.value, sid, stid); finalizeStyle(id); if (stid == null) _editingForm = false; } } else { alertBox.error('Invalid Input'); } } submit.ui.on('click', () => { if (controls.editMode == false) { checkAndAddStyle(); } else { var id = stid styleSpecForm.getValue(); if (Object.keys(styleFormControl.value).length == 0) { alertBox.error('Please enter some value'); } else { checkAndAddStyle(id); } } }); cancel.ui.on('click', () => { if (controls.editMode) { parameters.hide(); } else { boundingBox.detach(); //delete this; } }); boundingBox.on('keyup', (e) => { if (e.key == 'Enter') { submit.ui.trigger('click'); } }); /** * @function Style#updateStyle * @param {String} styleId Id of the style created by StateManager * @param {AtomStyleSpecs} styleSpec Specs for defining the style and setting default values */ this.updateStyle = function (styleId, styleSpec) { styleSpecForm.setValue(styleSpec);