Skip to content

Commit

Permalink
add coloring functional tests
Browse files Browse the repository at this point in the history
  • Loading branch information
biasmv committed Jan 24, 2015
1 parent 048fb9c commit a97b9b7
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 12 deletions.
10 changes: 6 additions & 4 deletions src/shade.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,13 @@ Gradient.prototype = {
// have a really small number of stops, that's not going to
// help much.
var lowerIndex = 0;
for (var i = 0; i < this._stops.length; ++i) {
for (var i = 1; i < this._stops.length; ++i) {
if (this._stops[i] > value) {
break;
}
lowerIndex = i;
}
var upperIndex = lowerIndex+1;
var upperIndex = lowerIndex + 1;
var lowerStop = this._stops[lowerIndex];
var upperStop = this._stops[upperIndex];
var t = (value - lowerStop)/ (upperStop - lowerStop);
Expand Down Expand Up @@ -214,7 +214,7 @@ exports.color = {};
exports.ColorOp = ColorOp;

exports.color.uniform = function(color) {
color = exports.forceRGB(color);
color = exports.forceRGB(color || 'white');
return new ColorOp(function(atom, out, index) {
out[index+0] = color[0];
out[index+1] = color[1];
Expand Down Expand Up @@ -326,7 +326,9 @@ exports.color.rainbow = function(grad) {
minIndex = Math.min(minIndex, bbj.residueAt(0).index());
maxIndex = Math.max(maxIndex, bbj.residueAt(bbj.length()-1).index());
}
this.chainLimits[chains[i].name()] = [minIndex, maxIndex];
if (minIndex !== maxIndex) {
this.chainLimits[chains[i].name()] = [minIndex, maxIndex];
}
}
},
function() {
Expand Down
58 changes: 50 additions & 8 deletions tests/viewer-render.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@ function createViewer() {
return pv.Viewer(document.getElementById('viewer'), options);
}

test("renders molecule asymmetric units in all styles", function(assert) {
test('renders molecule asymmetric units in all styles', function(assert) {
var done = assert.async();

var viewer = createViewer();
io.fetchPdb('/pdbs/1crn.pdb', function(structure) {
console.log(structure);
io.fetchPdb('/pdbs/1r6a.pdb', function(structure) {
for (var i = 0; i < ALL_STYLES.length; ++i) {
var obj = viewer.renderAs(ALL_STYLES[i], structure, ALL_STYLES[i]);
assert.ok(!!obj);
Expand All @@ -28,11 +27,10 @@ test("renders molecule asymmetric units in all styles", function(assert) {
});
});

test("renders molecule assembly 1 in all styles", function(assert) {
test('renders molecule assembly 1 in all styles', function(assert) {
var done = assert.async();
var viewer = createViewer();
io.fetchPdb('/pdbs/1crn.pdb', function(structure) {
console.log(structure);
io.fetchPdb('/pdbs/1r6a.pdb', function(structure) {
for (var i = 0; i < ALL_STYLES.length; ++i) {
var obj = viewer.renderAs(ALL_STYLES[i], structure,
ALL_STYLES[i], { showRelated : '1'});
Expand All @@ -44,15 +42,59 @@ test("renders molecule assembly 1 in all styles", function(assert) {
});
});

test("renders labels", function(assert) {
test('apply coloring full', function(assert) {
var done = assert.async();
var viewer = createViewer();
io.fetchPdb('/pdbs/1r6a.pdb', function(structure) {
for (var i = 0; i < ALL_STYLES.length; ++i) {
var obj = viewer.renderAs(ALL_STYLES[i], structure,
ALL_STYLES[i], { showRelated : '1'});
assert.ok(!!obj);
obj.colorBy(color.uniform());
obj.colorBy(color.byChain());
obj.colorBy(color.bySS());
obj.colorBy(color.ssSuccession());
obj.colorBy(color.rainbow());
obj.colorBy(color.byElement());
viewer.clear();
}
viewer.destroy();
done();
});
});

test('apply coloring partial', function(assert) {
var done = assert.async();
var viewer = createViewer();
io.fetchPdb('/pdbs/1r6a.pdb', function(structure) {
var view = structure.select({rnumRange : [50, 75]});
for (var i = 0; i < ALL_STYLES.length; ++i) {
var obj = viewer.renderAs(ALL_STYLES[i], structure,
ALL_STYLES[i], { showRelated : '1'});
assert.ok(!!obj);
obj.colorBy(color.uniform(), view);
obj.colorBy(color.byChain(), view);
obj.colorBy(color.bySS(), view);
obj.colorBy(color.ssSuccession(), view);
obj.colorBy(color.rainbow(), view);
obj.colorBy(color.byElement(), view);
viewer.clear();
}
viewer.destroy();
done();
});
});


test('renders labels', function(assert) {
var viewer = createViewer();
var label = viewer.label('my.label',
'somewhere over the rainbow', [0,0,0]);
assert.ok(!!label);
viewer.destroy();
});

test("renders custom meshes", function(assert) {
test('renders custom meshes', function(assert) {
var viewer = createViewer();
var mesh = viewer.customMesh('my.label');
mesh.addTube([0,0,0], [50,0,0], 3, { color : 'red', cap : true });
Expand Down

0 comments on commit a97b9b7

Please sign in to comment.