Esempio n. 1
0
def find_bb_hbonds(residues):

    cutoff_d_of_n_o = 3.5

    vertices = []
    atoms = []
    for i_residue, residue in enumerate(residues):
        residue.i = i_residue
        for atom in residue.atoms():
            atom.residue = residue
        if residue.has_atom('O'):
            atom = residue.atom('O')
            atoms.append(atom)
            vertices.append(atom.pos)
        if residue.has_atom('N'):
            atom = residue.atom('N')
            atoms.append(atom)
            vertices.append(atom.pos)

    for i, j in spacehash.SpaceHash(vertices).close_pairs():
        if abs(i - j) < 3:
            continue

        if atoms[i].element == 'O' and atoms[j].element == 'N':
            o = atoms[i]
            n = atoms[j]
        elif atoms[i].element == 'N' and atoms[j].element == 'O':
            n = atoms[i]
            o = atoms[j]
        else:
            continue

        if v3.distance(o.pos, n.pos) < cutoff_d_of_n_o:
            o.residue.co_partners.append(n.residue.i)
            n.residue.nh_partners.append(o.residue.i)
Esempio n. 2
0
def get_width(atoms, center):
  max_diff = 0
  for atom in atoms:
    diff = v3.distance(atom.pos, center)
    if diff > max_diff:
      max_diff = diff
  return 2*max_diff
Esempio n. 3
0
def find_bb_hbonds(residues):

    cutoff_d_of_n_o = 3.5

    vertices = []
    atoms = []
    for i_residue, residue in enumerate(residues):
        residue.i = i_residue
        for atom in residue.atoms():
            atom.residue = residue
        if residue.has_atom('O'):
            atom = residue.atom('O')
            atoms.append(atom)
            vertices.append(atom.pos)
        if residue.has_atom('N'):
            atom = residue.atom('N')
            atoms.append(atom)
            vertices.append(atom.pos)
    
    for i, j in spacehash.SpaceHash(vertices).close_pairs():
        if abs(i - j) < 3:
            continue

        if atoms[i].element == 'O' and atoms[j].element == 'N':
            o = atoms[i]
            n = atoms[j]
        elif atoms[i].element == 'N' and atoms[j].element == 'O':
            n = atoms[i]
            o = atoms[j]
        else:
            continue

        if v3.distance(o.pos, n.pos) < cutoff_d_of_n_o:
            o.residue.co_partners.append(n.residue.i)
            n.residue.nh_partners.append(o.residue.i)
Esempio n. 4
0
def get_width(atoms, center):
    max_diff = 0
    for atom in atoms:
        diff = v3.distance(atom.pos, center)
        if diff > max_diff:
            max_diff = diff
    return 2 * max_diff
Esempio n. 5
0
def is_peptide_connected(res1, res2):
  if res1.has_atom('CA') and \
     res1.has_atom('C') and \
     res2.has_atom('N') and \
     res2.has_atom('CA'):
     d = v3.distance(res1.atom('C').pos, res2.atom('N').pos)
     if d < 2.0:
       return True
  return False
Esempio n. 6
0
def is_peptide_connected(res1, res2):
    if res1.has_atom('CA') and \
       res1.has_atom('C') and \
       res2.has_atom('N') and \
       res2.has_atom('CA'):
        d = v3.distance(res1.atom('C').pos, res2.atom('N').pos)
        if d < 2.0:
            return True
    return False
Esempio n. 7
0
def is_connected(i, j, soup, cutoff=3.5):
  if i == j:
    return False
  min_dist = 1000.0
  for atom_i in soup.residue(i).atoms():
    for atom_j in soup.residue(j).atoms():
      dist = v3.distance(atom_i.pos, atom_j.pos)
      if dist < min_dist:
        min_dist = dist
  return min_dist < cutoff
def sum_rmsd(crds1, crds2):
  """
  Returns the direct rmsd between two sets of vectors *without*
  doing any optimal rotation. If calculated between optimal sets,
  should give the proper RMSD.
  """
  sum_squared = 0.0
  for crd1, crd2 in zip(crds1, crds2):
    sum_squared += v3.distance(crd1, crd2)**2
  return math.sqrt(sum_squared/float(len(crds1)))
Esempio n. 9
0
def is_connected(i, j, soup, cutoff=3.5):
    if i == j:
        return False
    min_dist = 1000.0
    for atom_i in soup.residue(i).atoms():
        for atom_j in soup.residue(j).atoms():
            dist = v3.distance(atom_i.pos, atom_j.pos)
            if dist < min_dist:
                min_dist = dist
    return min_dist < cutoff
Esempio n. 10
0
def sum_rmsd(crds1, crds2):
    """
  Returns the direct rmsd between two sets of vectors *without*
  doing any optimal rotation. If calculated between optimal sets,
  should give the proper RMSD.
  """
    sum_squared = 0.0
    for crd1, crd2 in zip(crds1, crds2):
        sum_squared += v3.distance(crd1, crd2)**2
    return math.sqrt(sum_squared / float(len(crds1)))
Esempio n. 11
0
def get_width(atoms, center=None):
  """
  Returns twice the longest distance from the center.
  """
  max_diff = 0
  if center is None:
    center = get_center(atoms)
  for atom in atoms:
    diff = v3.distance(atom.pos, center)
    if diff > max_diff:
      max_diff = diff
  return 2*max_diff
Esempio n. 12
0
def is_sidechain_connected(i, j, soup, cutoff=3.5):
  if abs(i-j) <= 2:
    return False
  min_dist = 1000.0
  sidechain_atoms_i = [a for a in soup.residue(i).atoms() 
                       if a.type not in backbone]
  for atom_i in sidechain_atoms_i:
    for atom_j in soup.residue(j).atoms():
      dist = v3.distance(atom_i.pos, atom_j.pos)
      if dist < min_dist:
        min_dist = dist
  return min_dist < cutoff
Esempio n. 13
0
def is_sidechain_connected(i, j, soup, cutoff=3.5):
    if abs(i - j) <= 2:
        return False
    min_dist = 1000.0
    sidechain_atoms_i = [
        a for a in soup.residue(i).atoms() if a.type not in backbone
    ]
    for atom_i in sidechain_atoms_i:
        for atom_j in soup.residue(j).atoms():
            dist = v3.distance(atom_i.pos, atom_j.pos)
            if dist < min_dist:
                min_dist = dist
    return min_dist < cutoff
Esempio n. 14
0
def find_neighbor_indices(atoms, probe, k):
    """
  Returns list of indices of atoms within probe distance to atom k. 
  """
    neighbor_indices = []
    atom_k = atoms[k]
    radius = atom_k.radius + probe + probe
    indices = range(k)
    indices.extend(range(k + 1, len(atoms)))
    for i in indices:
        atom_i = atoms[i]
        dist = v3.distance(atom_k.pos, atom_i.pos)
        if dist < radius + atom_i.radius:
            neighbor_indices.append(i)
    return neighbor_indices
Esempio n. 15
0
def find_neighbor_indices(atoms, probe, k):
  """
  Returns list of indices of atoms within probe distance to atom k. 
  """
  neighbor_indices = []
  atom_k = atoms[k]
  radius = atom_k.radius + probe + probe
  indices = range(k)
  indices.extend(range(k+1, len(atoms)))
  for i in indices:
    atom_i = atoms[i]
    dist = v3.distance(atom_k.pos, atom_i.pos)
    if dist < radius + atom_i.radius:
      neighbor_indices.append(i)
  return neighbor_indices
Esempio n. 16
0
 def calculate_results(self):
   ref_crds = []
   crds = []
   for ref_residue, residue in zip(self.ref_soup.residues(), self.soup.residues()):
     if residue.type not in data.solvent_res_types:
       if residue.has_atom('CA'):
         ref_crds.append(ref_residue.atom('CA').pos.copy())
         crds.append(residue.atom('CA').pos.copy())
   center = v3.get_center(crds)
   crds = [c - center for c in crds]
   ref_center = v3.get_center(ref_crds)
   ref_crds = [c - ref_center for c in ref_crds]
   rmsd_val, transform_ref_to_this = rmsd.calc_rmsd_rot(ref_crds, crds)
   ref_crds = [v3.transform(transform_ref_to_this, c) for c in ref_crds]
   return [v3.distance(crd, ref_crd) for crd, ref_crd in zip(crds, ref_crds)]
Esempio n. 17
0
 def calculate_results(self):
     ref_crds = []
     crds = []
     for ref_residue, residue in zip(self.ref_soup.residues(),
                                     self.soup.residues()):
         if residue.type not in data.solvent_res_types:
             if residue.has_atom('CA'):
                 ref_crds.append(ref_residue.atom('CA').pos.copy())
                 crds.append(residue.atom('CA').pos.copy())
     center = v3.get_center(crds)
     crds = [c - center for c in crds]
     ref_center = v3.get_center(ref_crds)
     ref_crds = [c - ref_center for c in ref_crds]
     rmsd_val, transform_ref_to_this = rmsd.calc_rmsd_rot(ref_crds, crds)
     ref_crds = [v3.transform(transform_ref_to_this, c) for c in ref_crds]
     return [
         v3.distance(crd, ref_crd) for crd, ref_crd in zip(crds, ref_crds)
     ]
Esempio n. 18
0
def calculate_asa(atoms, probe, n_sphere_point=960):
    """
  Returns the accessible-surface areas of the atoms, by rolling a
  ball with probe radius over the atoms with their radius
  defined.
  """
    sphere_points = generate_sphere_points(n_sphere_point)

    const = 4.0 * math.pi / len(sphere_points)
    areas = []
    for i, atom_i in enumerate(atoms):

        neighbor_indices = find_neighbor_indices(atoms, probe, i)
        n_neighbor = len(neighbor_indices)
        j_closest_neighbor = 0
        radius = probe + atom_i.radius

        n_accessible_point = 0
        for point in sphere_points:
            is_accessible = True
            test_point = v3.scale(point, radius) + atom_i.pos
            cycled_indices = range(j_closest_neighbor, n_neighbor)
            cycled_indices.extend(range(j_closest_neighbor))

            for j in cycled_indices:
                atom_j = atoms[neighbor_indices[j]]
                r = atom_j.radius + probe
                diff = v3.distance(atom_j.pos, test_point)
                if diff * diff < r * r:
                    j_closest_neighbor = j
                    is_accessible = False
                    break
            if is_accessible:
                n_accessible_point += 1

        area = const * n_accessible_point * radius * radius
        areas.append(area)

    return areas
Esempio n. 19
0
def calculate_asa(atoms, probe, n_sphere_point=960):
  """
  Returns the accessible-surface areas of the atoms, by rolling a
  ball with probe radius over the atoms with their radius
  defined.
  """
  sphere_points = generate_sphere_points(n_sphere_point)
 
  const = 4.0 * math.pi / len(sphere_points)
  areas = []
  for i, atom_i in enumerate(atoms):
    
    neighbor_indices = find_neighbor_indices(atoms, probe, i)
    n_neighbor = len(neighbor_indices)
    j_closest_neighbor = 0
    radius = probe + atom_i.radius
    
    n_accessible_point = 0
    for point in sphere_points:
      is_accessible = True
      test_point = v3.scale(point, radius) + atom_i.pos
      cycled_indices = range(j_closest_neighbor, n_neighbor)
      cycled_indices.extend(range(j_closest_neighbor))
      
      for j in cycled_indices:
        atom_j = atoms[neighbor_indices[j]]
        r = atom_j.radius + probe
        diff = v3.distance(atom_j.pos, test_point)
        if diff*diff < r*r:
          j_closest_neighbor = j
          is_accessible = False
          break
      if is_accessible:
        n_accessible_point += 1
    
    area = const*n_accessible_point*radius*radius 
    areas.append(area)

  return areas
Esempio n. 20
0
def make_disulfide_script(pdb):
  """
  Returns the psfgen script for disulfide bonds.

  This function opens in_pdb in a soup object, and searches for
  CYS residues where the SG-SG distance < 3 angs. These residues
  are then renamed to CYX and written to out_pdb. The disulfide bonds
  are then returned in a .tleap script fragment.
  """
  soup = pdbatoms.Soup(pdb)
  n = len(soup.residues())

  # First generate the residue names recognized by psfgen
  res_names = []
  chain_id = None
  i_res = None
  for i in range(n):
    res = soup.residue(i)
    if res.chain_id != chain_id:
      chain_id = res.chain_id
      i_res = 1
    res_names.append("%s:%s" % (chain_id, i_res))
    i_res += 1

  # Then search through for all CYS-CYS pairs and identify disulfide bonds
  script = ""
  for i in range(n):
    for j in range(i+1, n):
      if soup.residue(i).type in 'CYS' and soup.residue(j).type in 'CYS':
        sg1 = soup.residue(i).atom('SG')
        sg2 = soup.residue(j).atom('SG')
        if v3.distance(sg1.pos, sg2.pos) < 3.0:
          script += "patch DISU %s %s\n" % (res_names[i], res_names[j])
  if script:
     script = "# disulfide bonds\n" + script + "\n"

  return script
Esempio n. 21
0
def disulfide_script_and_rename_cysteines(in_pdb, out_pdb):
    """
  Returns the tleap script for disulfide bonds in the in_pdb file.

  This function opens in_pdb in a Soup, and searches for
  CYS residues where the SG-SG distance < 3 angs. These residues
  are then renamed to CYX and written to out_pdb. The disulfide bonds
  are then returned in a .tleap script fragment.
  """
    soup = pdbatoms.Soup(in_pdb)
    script = " # disulfide bonds\n"
    n = len(soup.residues())
    for i in range(n):
        for j in range(i + 1, n):
            if soup.residue(i).type in 'CYS' and soup.residue(j).type in 'CYS':
                p1 = soup.residue(i).atom('SG').pos
                p2 = soup.residue(j).atom('SG').pos
                if v3.distance(p1, p2) < 3.0:
                    soup.residue(i).set_type('CYX')
                    soup.residue(j).set_type('CYX')
                    script += "bond pdb.%d.SG pdb.%d.SG\n" % (i + 1, j + 1)
    soup.write_pdb(out_pdb)
    util.check_output(out_pdb)
    return script
Esempio n. 22
0
def disulfide_script_and_rename_cysteines(in_pdb, out_pdb):
  """
  Returns the tleap script for disulfide bonds in the in_pdb file.

  This function opens in_pdb in a Soup, and searches for
  CYS residues where the SG-SG distance < 3 angs. These residues
  are then renamed to CYX and written to out_pdb. The disulfide bonds
  are then returned in a .tleap script fragment.
  """
  soup = pdbatoms.Soup(in_pdb)
  script = " # disulfide bonds\n"
  n = len(soup.residues())
  for i in range(n):
    for j in range(i+1, n):
      if soup.residue(i).type in 'CYS' and soup.residue(j).type in 'CYS':
        p1 = soup.residue(i).atom('SG').pos
        p2 = soup.residue(j).atom('SG').pos
        if v3.distance(p1, p2) < 3.0:
          soup.residue(i).set_type('CYX')
          soup.residue(j).set_type('CYX')
          script += "bond pdb.%d.SG pdb.%d.SG\n" % (i+1, j+1)
  soup.write_pdb(out_pdb)
  util.check_output(out_pdb)
  return script