Skip to content

Commit

Permalink
get biojs-sniper snippets working again
Browse files Browse the repository at this point in the history
  • Loading branch information
biasmv committed Feb 12, 2015
1 parent 2be90e2 commit 382a145
Show file tree
Hide file tree
Showing 15 changed files with 216 additions and 193 deletions.
8 changes: 5 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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
Expand Down
73 changes: 41 additions & 32 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 : {
Expand All @@ -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: {
Expand All @@ -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'),
Expand All @@ -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
Expand All @@ -149,5 +159,4 @@ module.exports = function(grunt) {
grunt.registerTask('default', [
'jshint', 'requirejs:js', 'removelogging', 'uglify'
]);

};
4 changes: 1 addition & 3 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
<script src='js/jquery-2.0.2.min.js'></script>
<script src='js/modernizr.js'></script>
<script src='js/modernizr-2.8.3.min.js'></script>
<script src="js/foundation-5.4.7.min.js"></script>
<script data-main='demo' src='js/require.js'></script>
<link rel='stylesheet' href='css/foundation.css'>
Expand Down Expand Up @@ -90,8 +90,6 @@ <h1><a href="#">PV</a></h1>
</section>
</nav>
</div>
<script>
</script>
</body>
</html>

1 change: 0 additions & 1 deletion index.js

This file was deleted.

File renamed without changes.
15 changes: 3 additions & 12 deletions make-release.sh
Original file line number Diff line number Diff line change
@@ -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
21 changes: 18 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
2 changes: 0 additions & 2 deletions scripts/mangle-private-identifiers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down
4 changes: 2 additions & 2 deletions snippets/dengue-chooser.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
font-family: Helvetica;
background-color: #fff;/*#f0f0f0;*/
font-weight: lighter;
font-size:10pt;
margin: 0px;
width:100%;
height:100%x;
Expand All @@ -20,7 +21,6 @@
#inspector {
top:10px;
left:10px;
box-shadow: 2px 2px 5px #888888;
border-radius:8px;
position:absolute;
background-color:#fafafa;
Expand Down Expand Up @@ -61,7 +61,7 @@ <h1>Choose Style</h1>
<li id=sline>Smooth Line Trace</li>
<li id=trace>Trace</li>
</ul>
<div id=status>initialising...</div>

<span><a href='index.html'>About</a> | Code on <a href="http://github.com/biasmv/pv">github.com</a></span>
</div>
<div id=status>initialising...</div>
82 changes: 46 additions & 36 deletions snippets/dengue-chooser.js
Original file line number Diff line number Diff line change
@@ -1,64 +1,74 @@
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 = '&nbsp;';
});
}

document.getElementById('cartoon').onclick = cartoon;
document.getElementById('line-trace').onclick = lineTrace;
document.getElementById('preset').onclick = preset;
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);
3 changes: 1 addition & 2 deletions snippets/example.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ <h1></h1>
<li id=trace>Trace</li>
<li id=spheres>Spheres</li>
<li id=balls-and-sticks>Balls and Sticks</li>
<li id=test>Test</li>
</ul>
<ul id=colorTab>
<h1></h1>
Expand Down Expand Up @@ -51,7 +50,7 @@ <h1></h1>
</div>
<div id=gl>
</div>
<div id=copyright>Copyright (2014) Marco Biasini</div>
<div id=copyright>Copyright (2015) Marco Biasini</div>


<style>
Expand Down
Loading

0 comments on commit 382a145

Please sign in to comment.