Skip to content

Commit

Permalink
improve shouldIntroduceTraceBreak heuristic
Browse files Browse the repository at this point in the history
In case there is a bond between two residues don't introduce a trace
break. This gives users the option to manually connect amino acids
to avoid trace breaks.

See issue #83 for details.
  • Loading branch information
biasmv committed Mar 1, 2015
1 parent cb6d854 commit 6ef8754
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 3 deletions.
5 changes: 5 additions & 0 deletions doc/mol.rst
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,11 @@ Atom (and AtomView)

Returns the temperature factor (aka B-factor) of this atom. In case this value is not available, null will be returned.

.. function pv.mol.Atom.isConnectedTo(otherAtom)
pv.mol.AtomView.isConnectedTo(otherAtom)
Returns true if there is a bond between this atom and other atom, false otherwise. In case otherAtom is null, false is returned.
Bond
-----------------------------------------------------------------------------------------
Expand Down
18 changes: 17 additions & 1 deletion src/mol/atom.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,23 @@ AtomBase.prototype = {
for (var i = 0, e = bonds.length; i < e; ++i) {
callback(bonds[i]);
}
}
},
isConnectedTo: function(otherAtom) {
if (otherAtom === null) {
return false;
}
var other = otherAtom.full();
var me = this.full();
var bonds = this.bonds();
for (var i = 0, e = bonds.length; i < e; ++i) {
var bond = bonds[i];
if ((bond.atom_one() === me && bond.atom_two() === other) ||
(bond.atom_one() === other && bond.atom_two() === me)) {
return true;
}
}
return false;
},
};

function Atom(residue, name, pos, element, index, isHetatm,
Expand Down
8 changes: 6 additions & 2 deletions src/mol/chain.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ ChainBase.prototype = {
// binary search our way to heaven
var startIdx =
utils.indexFirstLargerEqualThan(residues, numify(start), rnumComp);
console.log(startIdx, start, residues[0].num());
if (startIdx === -1) {
return matching;
}
Expand Down Expand Up @@ -172,7 +171,7 @@ function shouldIntroduceTraceBreak(aaStretch, prevResidue, thisResidue) {
// these checks are on purpose more relaxed than the checks we use in
// deriveConnectivity(). We don't really care about correctness of bond
// lengths here. The only thing that matters is that the residues are
// more or less close so that they could potentially/ be connected.
// more or less close so that they could potentially be connected.
var prevAtom, thisAtom;
if (aaStretch) {
prevAtom = prevResidue.atom('C');
Expand All @@ -181,6 +180,11 @@ function shouldIntroduceTraceBreak(aaStretch, prevResidue, thisResidue) {
prevAtom = prevResidue.atom('O3\'');
thisAtom = thisResidue.atom('P');
}

// in case there is a bond, we don't introduce a chain break
if (prevAtom.isConnectedTo(thisAtom)) {
return false;
}
var sqrDist = vec3.sqrDist(prevAtom.pos(), thisAtom.pos());
return (Math.abs(sqrDist - 1.5*1.5) > 1);
}
Expand Down
14 changes: 14 additions & 0 deletions src/tests/mol/basics.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,20 @@ HETATM 2141 O HOH A 916 -11.502 -50.640 0.340 1.00 50.23 O

var FRAGMENT = io.pdb(PDB_FRAGMENT);

test('is atom connected to', function(assert) {
var atomA = FRAGMENT.atom('A.268.C');
var atomB = FRAGMENT.atom('A.268.O');
assert.ok(atomA.isConnectedTo(atomB));
assert.ok(atomB.isConnectedTo(atomA));
assert.ok(!atomB.isConnectedTo(atomB));
assert.ok(!atomA.isConnectedTo(atomA));

var atomC = FRAGMENT.atom('A.268.CB');
assert.ok(!atomA.isConnectedTo(atomC));
assert.ok(!atomC.isConnectedTo(atomA));
assert.ok(!atomC.isConnectedTo(null));
});

test('get atom by name', function(assert) {
var oxygen = FRAGMENT.atom('A.905.O1');
assert.strictEqual(oxygen.name(), 'O1');
Expand Down

0 comments on commit 6ef8754

Please sign in to comment.