diff --git a/3Dmol/3dmol.js b/3Dmol/3dmol.js index 315ffe32..17791def 100644 --- a/3Dmol/3dmol.js +++ b/3Dmol/3dmol.js @@ -455,8 +455,9 @@ $3Dmol.getPropertyRange = function (atomlist, prop) { return [ min, max ]; } -//hackish way to work with requirejs +//hackish way to work with requirejs - doesn't actually work yet +//since we doing use the require optimizer to combine modules if( typeof(define) === 'function' && define.amd) { - define($3Dmol); + define('$3Dmol',$3Dmol); } diff --git a/py3Dmol/examples.ipynb b/py3Dmol/examples.ipynb index e70bd11d..110c5b6a 100644 --- a/py3Dmol/examples.ipynb +++ b/py3Dmol/examples.ipynb @@ -13,7 +13,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 3, "metadata": { "collapsed": false, "scrolled": false @@ -22,39 +22,36 @@ { "data": { "text/html": [ - "
\n", + "
\n", "" ], "text/plain": [ "" ] }, - "execution_count": 2, + "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "p = py3Dmol.view(query='pdb:1ycr')\n", + "p = py3Dmol.view(query='pdb:1ycr',js='http://localhost/3Dmol/build/3Dmol.js')\n", "p.setStyle({'cartoon': {'color':'spectrum'}})\n", "p.show()" ] }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 4, "metadata": { "collapsed": false }, @@ -79,21 +76,18 @@ { "data": { "text/html": [ - "
\n", + "
\n", "" ], "text/plain": [ @@ -125,24 +119,21 @@ { "data": { "text/html": [ - "
\n", + "
\n", "" ], "text/plain": [ - "" + "" ] }, "execution_count": 6, @@ -167,21 +158,18 @@ { "data": { "text/html": [ - "
\n", + "
\n", "" ], "text/plain": [ @@ -213,23 +201,20 @@ { "data": { "text/html": [ - "
\n", + "
\n", "" ], "text/plain": [ - "" + "" ] }, "execution_count": 8, diff --git a/py3Dmol/py3Dmol/__init__.py b/py3Dmol/py3Dmol/__init__.py index 117f668e..dc5df184 100644 --- a/py3Dmol/py3Dmol/__init__.py +++ b/py3Dmol/py3Dmol/__init__.py @@ -17,7 +17,7 @@ class view(object): the exception that the functions all return None. http://3dmol.csb.pitt.edu/doc/$3Dmol.GLViewer.html ''' - def __init__(self,width=640,height=480,query='',options=dict(),js='3dmol.csb.pitt.edu/build/3Dmol-min.js'): + def __init__(self,width=640,height=480,query='',options=dict(),js='http://3dmol.csb.pitt.edu/build/3Dmol.js'): '''Create a 3Dmol.js view. width -- width in pixels of container height -- height in pixels of container @@ -30,10 +30,11 @@ class view(object): self.startjs += ''; - #load 3dmol with requirejs - self.startjs += "requirejs.config({\n\tpaths: {\n\t'$3Dmol': ['//%s'],},\n});\n" % js.rstrip('.js') - self.startjs += "require(['$3Dmol'], function(mol) {\n"; - self.endjs = "return {};});\n" + self.endjs; + #load 3dmol, but only once + self.startjs += "if(typeof $3Dmolpromise === 'undefined') $3Dmolpromise = $.when($.getScript('%s'))\n" % js + + self.startjs += "$3Dmolpromise.done(function() {\n"; + self.endjs = "});\n" + self.endjs self.startjs += 'var viewer = $3Dmol.createViewer($("#%s"),{backgroundColor:"white"});\n' % divid if query: