From 382a145f567695ec3dbddc44381dcaf086089b01 Mon Sep 17 00:00:00 2001 From: Marco Biasini Date: Wed, 11 Feb 2015 22:53:34 +0100 Subject: [PATCH] get biojs-sniper snippets working again --- .gitignore | 8 +- Gruntfile.js | 73 ++++++----- index.html | 4 +- index.js | 1 - js/{modernizr.js => modernizr-2.8.3.min.js} | 0 make-release.sh | 15 +-- package.json | 21 +++- scripts/mangle-private-identifiers.py | 2 - snippets/dengue-chooser.html | 4 +- snippets/dengue-chooser.js | 82 ++++++------ snippets/example.html | 3 +- snippets/example.js | 131 +++++++++----------- snippets/simple.html | 13 ++ snippets/simple.js | 50 ++++---- snippets/simple.json | 2 +- 15 files changed, 216 insertions(+), 193 deletions(-) delete mode 100644 index.js rename js/{modernizr.js => modernizr-2.8.3.min.js} (100%) create mode 100644 snippets/simple.html diff --git a/.gitignore b/.gitignore index cd0d156..e57c739 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,9 @@ .DS_Store -/js/pv.min.js -/js/pv.dbg.js -/js/pv.rel.js +/js/bio-pv.min.js +/js/bio-pv.dbg.js +/js/bio-pv.rel.js +/bio-pv.min.js +/bio-pv.js /node_modules /doc/_build build diff --git a/Gruntfile.js b/Gruntfile.js index 1fcec88..0dbc822 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -41,48 +41,54 @@ SOURCE_FILES = [ ALL_FILES = ['src/gl-matrix.js']; Array.prototype.push.apply(ALL_FILES, SOURCE_FILES); -var browserify = require("browserify"); -var fs = require("fs"); -var mkdirp = require("mkdirp"); -var START_SNIPPET="\n\ -(function (root, factory) {\n\ - if (typeof define === 'function' && define.amd) {\n\ - define([], factory);\n\ - } else {\n\ - var pv = factory();\n\ - root.pv = pv;\n\ - root.io = pv.io;\n\ - root.mol = pv.mol;\n\ - root.color = pv.color;\n\ - root.rgb = pv.rgb;\n\ - root.viewpoint = pv.viewpoint;\n\ - root.vec3 = pv.vec3;\n\ - root.vec4 = pv.vec4;\n\ - root.mat3 = pv.mat3;\n\ - root.mat4 = pv.mat4;\n\ - root.quat = pv.quat;\n\ - }\n\ -}(this, function () {\n\ - // modules will be inlined here\n\ -"; var END_SNIPPET='return pv; }));'; module.exports = function(grunt) { + var pkg = grunt.file.readJSON('package.json'); + var BANNER='/**\n\ + * PV - WebGL protein viewer v' + pkg.version + '\n\ + * http://biasmv.github.io/pv\n\ + * \n\ + * Copyright 2013-2015 Marco Biasini\n\ + * Released under the MIT license\n\ + */\n'; + + var START_SNIPPET=BANNER+"\n\ + (function (root, factory) {\n\ + if (typeof define === 'function' && define.amd) {\n\ + define([], factory);\n\ + } else {\n\ + var pv = factory();\n\ + root.pv = pv;\n\ + root.io = pv.io;\n\ + root.mol = pv.mol;\n\ + root.color = pv.color;\n\ + root.rgb = pv.rgb;\n\ + root.viewpoint = pv.viewpoint;\n\ + root.vec3 = pv.vec3;\n\ + root.vec4 = pv.vec4;\n\ + root.mat3 = pv.mat3;\n\ + root.mat4 = pv.mat4;\n\ + root.quat = pv.quat;\n\ + }\n\ + }(this, function () {\n\ + // modules will be inlined here\n\ + "; // Project configuration. grunt.initConfig({ - pkg: grunt.file.readJSON('package.json'), + pkg: pkg, uglify: { options: { - banner: '', + banner: BANNER, preserveComments : false, report : 'min' }, build: { - src: 'js/pv.rel.js', - dest: 'js/pv.min.js' + src: 'js/bio-pv.rel.js', + dest: 'js/bio-pv.min.js' } }, jshint : { @@ -106,8 +112,8 @@ module.exports = function(grunt) { removelogging : { dist : { - src : 'js/pv.dbg.js', - dest : 'js/pv.rel.js', + src : 'js/bio-pv.dbg.js', + dest : 'js/bio-pv.rel.js', } }, requirejs: { @@ -117,7 +123,7 @@ module.exports = function(grunt) { optimize: 'none', skipModuleInsertion : true, include: ['pv'], - out : 'js/pv.dbg.js', + out : 'js/bio-pv.dbg.js', onModuleBundleComplete : function(data) { var fs = require('fs'), amdclean = require('amdclean'), @@ -127,6 +133,10 @@ module.exports = function(grunt) { transformAMDChecks : false, aggressiveOptimizations : true, createAnonymousAMDModule : true, + prefixMode : 'camelCase', + escodegen : { + comment : false, + }, wrap : { start : START_SNIPPET, end : END_SNIPPET @@ -149,5 +159,4 @@ module.exports = function(grunt) { grunt.registerTask('default', [ 'jshint', 'requirejs:js', 'removelogging', 'uglify' ]); - }; diff --git a/index.html b/index.html index 423f2d8..2b0edc7 100644 --- a/index.html +++ b/index.html @@ -5,7 +5,7 @@ - + @@ -90,8 +90,6 @@

PV

- diff --git a/index.js b/index.js deleted file mode 100644 index 144040b..0000000 --- a/index.js +++ /dev/null @@ -1 +0,0 @@ -window.pv = require('./src/pv'); diff --git a/js/modernizr.js b/js/modernizr-2.8.3.min.js similarity index 100% rename from js/modernizr.js rename to js/modernizr-2.8.3.min.js diff --git a/make-release.sh b/make-release.sh index 95cd6d8..d5bc2aa 100755 --- a/make-release.sh +++ b/make-release.sh @@ -1,15 +1,6 @@ #!/bin/bash - set -e grunt -RELEASE_VERSION=`git tag | tail -n 1` -DIR="pv-$RELEASE_VERSION" -echo $DIR -rm -rf $DIR -mkdir $DIR -cp js/pv.dbg.js $DIR/pv-$RELEASE_VERSION.dbg.js -cp js/pv.rel.js $DIR/pv-$RELEASE_VERSION.rel.js -cp js/pv.min.js $DIR/pv-$RELEASE_VERSION.min.js -cp LICENSE.txt $DIR -rm -rf $DIR.zip -zip -r $DIR.zip $DIR +env +cp js/pv.dbg.js pv.js +python scripts/mangle-private-identifiers.py js/pv.min.js pv.min.js diff --git a/package.json b/package.json index 4df1c48..6be2c19 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ "url": "https://github.com/biasmv/pv/blob/master/LICENSE.txt" } ], - "main": "index.js", + "main": "bio-pv.min.js", "devDependencies": { "biojs-sniper": "0.0.6", "grunt": "~0.4.5", @@ -33,10 +33,25 @@ }, "sniper": { "js": [ - "/build/pv.js" + "/bio-pv.min.js" ], - "first": "example" + "first": "example", + "snippets" : ["snippets"] }, + "scripts" : { + "prepublish": "scripts/make.sh" + }, + "files" : [ + "README.md", + "bio-pv.js", + "bio-pv.min.js", + "LICENSE.txt", + "snippets", + "pdbs", + "js/jquery-2.0.2.min.js", + "js/jquery-ui.min.js", + "package.json" + ], "keywords": [ "protein", "3d", diff --git a/scripts/mangle-private-identifiers.py b/scripts/mangle-private-identifiers.py index 766b062..ea5189f 100644 --- a/scripts/mangle-private-identifiers.py +++ b/scripts/mangle-private-identifiers.py @@ -52,8 +52,6 @@ def next_available_name(index): replacements[token] = next_available_name(index) index += 1 -for original, replacement in replacements.iteritems(): - print '%s -> %s' % (original, replacement) replaced = [replacements.get(t, t) for t in tokens] open(sys.argv[2], 'w').write(''.join(replaced)) diff --git a/snippets/dengue-chooser.html b/snippets/dengue-chooser.html index 32f8d6c..f443d55 100644 --- a/snippets/dengue-chooser.html +++ b/snippets/dengue-chooser.html @@ -3,6 +3,7 @@ font-family: Helvetica; background-color: #fff;/*#f0f0f0;*/ font-weight: lighter; + font-size:10pt; margin: 0px; width:100%; height:100%x; @@ -20,7 +21,6 @@ #inspector { top:10px; left:10px; - box-shadow: 2px 2px 5px #888888; border-radius:8px; position:absolute; background-color:#fafafa; @@ -61,7 +61,7 @@

Choose Style

  • Smooth Line Trace
  • Trace
  • +
    initialising...
    About | Code on github.com -
    initialising...
    diff --git a/snippets/dengue-chooser.js b/snippets/dengue-chooser.js index 9fb7d9b..e5e2daf 100644 --- a/snippets/dengue-chooser.js +++ b/snippets/dengue-chooser.js @@ -1,56 +1,64 @@ -var app = require("bio-pv"); -var pv = app.Viewer(document.getElementById('gl'), +var viewer = pv.Viewer(document.getElementById('gl'), { quality : 'high', width: 'auto', height : 'auto', antialias : true, outline : true}); + var structure; + function lines() { - pv.clear(); - pv.lines('structure', structure); + viewer.clear(); + viewer.lines('structure', structure); } + function cartoon() { - pv.clear(); - pv.cartoon('structure', structure, { color: color.ssSuccession() }); + viewer.clear(); + viewer.cartoon('structure', structure, { color: color.ssSuccession() }); } + function lineTrace() { - pv.clear(); - pv.lineTrace('structure', structure); + viewer.clear(); + viewer.lineTrace('structure', structure); } + function sline() { - pv.clear(); - pv.sline('structure', structure); + viewer.clear(); + viewer.sline('structure', structure); } + function tube() { - pv.clear(); - pv.tube('structure', structure); + viewer.clear(); + viewer.tube('structure', structure); } + function trace() { - pv.clear(); - pv.trace('structure', structure); + viewer.clear(); + viewer.trace('structure', structure); } + function preset() { - pv.clear(); + viewer.clear(); var ligand = structure.select({rnames : ['RVP', 'SAH']}); - pv.ballsAndSticks('ligand', ligand); - pv.cartoon('protein', structure); + viewer.ballsAndSticks('ligand', ligand); + viewer.cartoon('protein', structure); } -function load(pdb_id) { - document.getElementById('status').innerHTML ='loading '+pdb_id; - var xhr = new XMLHttpRequest(); - xhr.open('GET', '../pdbs/'+pdb_id+'.pdb'); - xhr.setRequestHeader('Content-type', 'application/x-pdb'); - xhr.onreadystatechange = function() { - if (xhr.readyState == 4) { - structure = io.pdb(xhr.responseText); - preset(); - pv.centerOn(structure); - } - document.getElementById('status').innerHTML = ''; - } - xhr.send(); -} -function transferase() { - load('1r6a'); + +function loadTransferase() { + document.getElementById('status').innerHTML ='loading transferase'; + pv.io.fetchPdb('../pdbs/1r6a.pdb', function(molecule) { + structure = molecule; + preset(); + // set camera orientation to pre-determined rotation, zoom and + // center values that are optimal for this very molecule + var rotation = [ + 0.1728139370679855, 0.1443438231945038, 0.974320650100708, + 0.0990324765443802, 0.9816440939903259, -0.162993982434272, + -0.9799638390541077, 0.1246569454669952, 0.155347332358360 + ]; + var center = [6.514, -45.571, 2.929]; + viewer.setCamera(rotation, center, 73); + document.getElementById('status').innerHTML = ' '; + }); } + document.getElementById('cartoon').onclick = cartoon; document.getElementById('line-trace').onclick = lineTrace; document.getElementById('preset').onclick = preset; @@ -58,7 +66,9 @@ document.getElementById('lines').onclick = lines; document.getElementById('trace').onclick = trace; document.getElementById('sline').onclick = sline; document.getElementById('tube').onclick = tube; + window.onresize = function(event) { - pv.fitParent(); + viewer.fitParent(); } -document.addEventListener('DOMContentLoaded', transferase); + +viewer.on('viewerReady', loadTransferase); diff --git a/snippets/example.html b/snippets/example.html index 075ddc3..0496c62 100644 --- a/snippets/example.html +++ b/snippets/example.html @@ -17,7 +17,6 @@

  • Trace
  • Spheres
  • Balls and Sticks
  • -
  • Test