Skip to content

Commit

Permalink
add polymer selection
Browse files Browse the repository at this point in the history
  • Loading branch information
biasmv committed Mar 27, 2016
1 parent 0f31c53 commit 19aac16
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 1 deletion.
1 change: 1 addition & 0 deletions doc/mol.rst
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ Mol (and MolView)
* *water*: selects residues with names HOH and DOD (deuteriated water).
* *protein*: returns all amino-acids found in the structure. Note that this might return amino acid ligands as well.
* *ligand*: selects all residues which are not water nor protein.
* *polymer*: selects all residues which are part of polymers. At the moment, this only returns nucleotides and peptides. Residues are considered to be part of polymers if they have a bond to at least one other residue of the same type. Note that the behavior of *polymer* is not identical *protein*. The latter also returns single amino acids.

Matching by predicate dictionary provides a flexible way to specify selections without having to write custom callbacks. A predicate is a condition which has to be fullfilled in order to include a chain, residue or atom in the results. Some of the predicates match against chain ,e.g. *cname*, others against residues, e.g. *rname*, and others against atoms, e.g. *ele*. When multiple predicates are specified in the dictionary, all of them have to match for an item to be included in the results.

Expand Down
3 changes: 3 additions & 0 deletions src/mol/mol.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,9 @@ MolBase.prototype = {
return !r.isAminoacid() && !r.isWater();
});
}
if (what === 'polymer') {
return select.polymer(this, new MolView(this));
}
// when what is not one of the simple strings above, we assume what
// is a dictionary containing predicates which have to be fulfilled.
return select.dict(this, new MolView(this), what || {});
Expand Down
22 changes: 21 additions & 1 deletion src/mol/select.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,28 @@ function dictSelect(structure, view, dict) {
return view;
}


function polymerSelect(structure, view) {
for (var ci = 0; ci < structure._chains.length; ++ci) {
var chain = structure._chains[ci];
var traces = chain.backboneTraces();
if (traces.length === 0) {
continue;
}
var chainView = view.addChain(chain);
for (var bi = 0; bi < traces.length; ++bi) {
var residues = traces[bi].residues();
for (var ri = 0; ri < residues.length; ++ri) {
chainView.addResidue(residues[ri], true);
}
}
}
return view;
}

return {
dict : dictSelect
dict : dictSelect,
polymer : polymerSelect
};

});
11 changes: 11 additions & 0 deletions src/mol/trace.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ BackboneTrace.prototype = {
return index;
},

residues: function() { return this._trace; },

subsets : function(residues) {
// we assume that the residue list is ordered from N- to C-
// terminus and we can traverse it in one go.
Expand Down Expand Up @@ -155,6 +157,15 @@ TraceSubset.prototype = {
residueAt : function(index) {
return this._fullTrace.residueAt(this._fullTraceBegin + index);
},

residues: function() {
var residues = [];
for (var i = 0; i < this._length; ++i) {
residues.push(this.residueAt(i));
}
return residues;
},

_interpolate : (function() {
var tangentOne = vec3.create();
var tangentTwo = vec3.create();
Expand Down
21 changes: 21 additions & 0 deletions src/tests/mol/basics.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,27 @@ test('residue select on structure', function(assert) {
assert.strictEqual(view.chains().length, 1);
});

test('select polymer on structure', function(assert) {
var view = FRAGMENT.select('polymer');
var count = 0;
view.eachResidue(function(r) {
assert.ok(r.isAminoacid());
count++;
});
assert.strictEqual(count, 9);
assert.strictEqual(view.chains().length, 1);
});

test('select polymer on view', function(assert) {
var view = FRAGMENT.select().select('polymer');
var count = 0;
view.eachResidue(function(r) {
assert.ok(r.isAminoacid());
count++;
});
assert.strictEqual(count, 9);
assert.strictEqual(view.chains().length, 1);
});

test('add residues', function(assert) {
var rnums = [268,903,904,905];
Expand Down

0 comments on commit 19aac16

Please sign in to comment.