protstruct

Module for operations related to protein structures.

dms_tools2.protstruct.atomDist(a1, a2)[source]

Calculates distance between two atoms.

Args:
a1, a2 (Bio.PDB.Atom.Atom objects)

The two atoms.

Returns:

The distance between the two atoms.

>>> Atom = Bio.PDB.Atom.Atom
>>> a1 = Atom(name='CA', coord=(1.0, 2.0, 3.0), bfactor=1, occupancy=1,
...           altloc='', fullname='CA', serial_number=1, element='C')
>>> a2 = Atom(name='CA', coord=(1.5, 3.0, 4.5), bfactor=1, occupancy=1,
...           altloc='', fullname='CA', serial_number=2, element='C')
>>> round(atomDist(a1, a2), 3)
1.871
dms_tools2.protstruct.distMatrix(pdbfile, chains, dist_type, equivchains={}, ignore_hetero=True)[source]

Residue-residue distance matrix for protein or homo-oligomer.

Args:
pdbfile (str)

Name of PDB file.

chains (str or list of str)

Chain in pdbfile for which we compute residue distances, or list of chains if the residues span several chains (as for proteins like HA which are cleaved to subunits).

dist_type (str)

Distances to measure. Use CA for alpha carbon distances, and any for nearest distances of any atom in residues.

equivchains (dict)

If the structure is a homo-oligomer, each chain may have other equivalent chains. In this case, for each chain, equivchains[chain] should be list of equivalent chains that we also include in the distance calculations.

ignorehetero (bool)

Ignore hetero-residues, and only consider protein ones.

Returns:

The 2-tuple (residues, distmatrix) where residues is a list of the residue names (as strings) and distmatrix is a numpy.ndarray with element distmatrix[i, j] giving the distance between residue residues[i] and residues[j].

Here is an example computation of distances between two residues spanning two chains:

>>> with tempfile.NamedTemporaryFile(mode='w') as f:
...     n = f.write(
...      '\n'.join([
...      'ATOM   4633  N   VAL X 505A     57.621  44.297  43.089  1.00 96.43           N',
...      'ATOM   4634  CA  VAL X 505A     58.278  45.594  43.147  1.00 84.49           C',
...      'ATOM   4635  C   VAL X 505A     59.779  45.434  42.943  1.00 82.23           C',
...      'ATOM   4636  O   VAL X 505A     60.339  44.372  43.218  1.00 91.07           O',
...      'ATOM   4637  CB  VAL X 505A     58.010  46.304  44.493  1.00 98.34           C',
...      'ATOM   4638  CG1 VAL X 505A     58.732  47.644  44.544  1.00 94.96           C',
...      'ATOM   4639  CG2 VAL X 505A     56.511  46.483  44.713  1.00 92.78           C',
...      'ATOM      1  N   VAL A 518      46.814  16.139  29.171  1.00 92.74           N',
...      'ATOM      2  CA  VAL A 518      46.514  15.640  27.833  1.00 99.45           C',
...      'ATOM      3  C   VAL A 518      47.047  16.605  26.764  1.00102.76           C',
...      'ATOM      4  O   VAL A 518      47.281  17.785  27.034  1.00 86.02           O',
...      'ATOM      5  CB  VAL A 518      44.993  15.424  27.640  1.00 95.35           C',
...      'ATOM      6  CG1 VAL A 518      44.729  14.428  26.515  1.00 70.29           C',
...      'ATOM      7  CG2 VAL A 518      44.357  14.931  28.935  1.00 97.65           C',
...      'ATOM      8  CA  VAL Y 505A     47.514  16.640  28.833  1.00 99.45           C',
...      ]))
...     f.flush()
...     (residues, ca_dist) = distMatrix(f.name, ['A', 'X'], 'CA')
...     (residues, any_dist) = distMatrix(f.name, ['A', 'X'], 'any')
...     (residues, equiv_dist) = distMatrix(f.name, ['A', 'X'], 'CA', {'X':['Y']})
>>> residues
['505A', '518']
>>> numpy.allclose(ca_dist, numpy.array(
...    [[0, 35.639], [35.639, 0]]), atol=1e-3)
True
>>> numpy.allclose(any_dist, numpy.array(
...    [[0, 32.674], [32.674, 0]]), atol=1e-3)
True
>>> numpy.allclose(equiv_dist, numpy.array(
...    [[0, 1.732], [1.732, 0]]), atol=1e-3)
True
dms_tools2.protstruct.residueDist(r1, r2, atom=None)[source]

Calculates distance between closest atoms in two residues.

Args:
r1, r2 (Bio.PDB.Residue.Residue objects)

The two residues.

atom (None or str)

If None, computes closest distance between any atoms. If a string, only computes closest distance among atoms of this type (e.g., CA for alpha carbon distances).

Returns:

Distance between closest atoms in the two residues.

>>> Residue = Bio.PDB.Residue.Residue
>>> Atom = Bio.PDB.Atom.Atom
>>> r1 = Residue('r1', 'r1', 'A')
>>> a1 = Atom(name='CA', coord=(1.0, 2.0, 2.5), bfactor=1, occupancy=1,
...           altloc='', fullname='CA', serial_number=1, element='C')
>>> a2 = Atom(name='N', coord=(1.5, 3.0, 4.5), bfactor=1, occupancy=1,
...           altloc='', fullname='N', serial_number=2, element='N')
>>> r1.add(a1)
>>> r1.add(a2)
>>> r2 = Residue('r2', 'r2', 'A')
>>> a3 = Atom(name='CA', coord=(2.0, 4.0, 6.0), bfactor=1, occupancy=1,
...           altloc='', fullname='CA', serial_number=1, element='C')
>>> r2.add(a3)
>>> round(residueDist(r1, r2), 3) == 1.871
True
>>> round(residueDist(r1, r2, atom='CA'), 3) == 4.153
True