예제 #1
0
def get_width(atoms, center):
  max_diff = 0
  for atom in atoms:
    diff = vector3d.pos_distance(atom.pos, center)
    if diff > max_diff:
      max_diff = diff
  return 2*max_diff
예제 #2
0
파일: match.py 프로젝트: davecap/labwork
def bp_sum_rmsd(residue1, residue2, atom_types=['CA', 'N', 'C', 'CB', 'CG']):
    atoms1 = [ a for a in residue1.get_list() if a.get_name() in atom_types ]
    atoms2 = [ a for a in residue2.get_list() if a.get_name() in atom_types ]
    sum_squared = 0.0
    for atom1, atom2 in zip(atoms1, atoms2):
        sum_squared += vector3d.pos_distance(biopython_atom_to_vector3d(atom1), biopython_atom_to_vector3d(atom2))**2
    return math.sqrt(sum_squared/float(len(atoms1)))
예제 #3
0
파일: molecule.py 프로젝트: Nathx/cookbook
def get_width(atoms, center):
    max_diff = 0
    for atom in atoms:
        diff = vector3d.pos_distance(atom.pos, center)
        if diff > max_diff:
            max_diff = diff
    return 2 * max_diff
예제 #4
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 = pos_distance(atom_k.pos, atom_i.pos)
        if dist < radius + atom_i.radius:
            neighbor_indices.append(i)
    return neighbor_indices
예제 #5
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 = pos_distance(atom_k.pos, atom_i.pos)
        if dist < radius + atom_i.radius:
            neighbor_indices.append(i)
    return neighbor_indices
예제 #6
0
def calculate_average_bfactor(grid_chain, protein_atoms, bfactor_probe):
    max_bfactor = 0.0
    for atom in protein_atoms:
        if atom.bfactor > max_bfactor:
            max_bfactor = atom.bfactor
    for grid_atom in grid_chain.atoms():
        bfactors = []
        for protein_atom in protein_atoms:
            if protein_atom.element != "H":
                radius = bfactor_probe
                dist = vector3d.pos_distance(protein_atom.pos, grid_atom.pos)
                if dist < radius:
                    bfactors.append(protein_atom.bfactor)
        n_bfactor = len(bfactors)
        if n_bfactor == 0:
            grid_atom.bfactor = max_bfactor
        else:
            grid_atom.bfactor = sum(bfactors) / float(n_bfactor)
예제 #7
0
def residues_rmsd(atoms1, atoms2):
    sum_squared = []
    for atom1, atom2 in zip(atoms1, atoms2):
        each_diff = math.sqrt(vector3d.pos_distance(atom1.pos, atom2.pos)**2)
        sum_squared.append(round(each_diff, 2))
    return sum_squared, round(sum_rmsd(atoms1, atoms2), 2)
예제 #8
0
def sum_rmsd(atoms1, atoms2):
    sum_squared = 0.0
    for atom1, atom2 in zip(atoms1, atoms2):
        sum_squared += vector3d.pos_distance(atom1.pos, atom2.pos)**2
    return math.sqrt(sum_squared / float(len(atoms1)))
예제 #9
0
def sum_rmsd(atoms1, atoms2):
  sum_squared = 0.0
  for atom1, atom2 in zip(atoms1, atoms2):
    sum_squared += vector3d.pos_distance(atom1.pos, atom2.pos)**2
  return math.sqrt(sum_squared/float(len(atoms1)))
예제 #10
0
파일: compare.py 프로젝트: chhattu/apmds
def residues_rmsd(atoms1, atoms2):
  sum_squared = [] 
  for atom1, atom2 in zip(atoms1, atoms2):
    each_diff = math.sqrt(vector3d.pos_distance(atom1.pos, atom2.pos)**2)
    sum_squared.append(round(each_diff, 2))
  return sum_squared, round(sum_rmsd(atoms1, atoms2), 2) 
예제 #11
0
파일: amber.py 프로젝트: janman13/pdbtool
def convert_pdb_to_amber(pdb, top, crd, solvent_buffer=0.0): 
  """Convert a .pdb file into amber .top and .crd file."""

  script = "# generate %s and %s files from %s\n" % (top, crd, pdb)
  
  script += "\n"
  script += "# load in amber force field\n"
  script += "source leaprc.ff96\n"

  script += "\n"
  script += "# use AMBER6 GB radii for igb=1, gbparm=2\n"
  script += "set default PBradii amber6\n"
 
  # strip pdb and then load into soup
  bare_pdb = util.temp_fname('.pdb')
  txt = open(pdb, 'r').read()
  txt = pdbtext.strip_other_nmr_models(txt)
  txt = pdbtext.strip_lines(txt, lambda l: l.startswith('HETATM'))
  txt = pdbtext.strip_lines(txt, lambda l: l.startswith('ANISOU'))
  txt = pdbtext.strip_lines(txt, lambda l: l.startswith('CONECT'))
  txt = pdbtext.strip_lines(txt, lambda l: l.startswith('MASTER'))
  txt = pdbtext.strip_alternative_atoms(txt)
  txt = pdbtext.strip_hydrogens(txt)
  txt = pdbtext.renumber_residues(txt)
  open(bare_pdb, 'w').write(txt)
  soup = pdbstruct.Soup(bare_pdb)
  os.remove(bare_pdb)
  
  script += "\n"
  residues = [r.type for r in soup.residues()]
  if 'PHD' in residues:
    script += "\n"
    script += "# non-standard amino acid PHD"
    script += "source leaprc.gaff\n"
    script += "loadAmberPrep %s/parms/phd.prepin\n" % module_dir
    script += "loadAmberParams %s/parms/phd.frcmod\n" % module_dir

  for chain in soup.chains():
    if isinstance(chain, pdbstruct.Protein):
      if not chain.is_capped():
        chain.charge_c_end()

  in_pdb = pdb.replace('.pdb', '.tleap.pdb')
  soup.write_pdb(in_pdb)

  script += "\n"
  script += " # insert protein\n"
  script += "pdb = loadpdb %s\n" % in_pdb
  script += "check pdb\n"

  script += "\n"
  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 vector3d.pos_distance(p1, p2) < 3.0:
          soup.residue(i).type = 'CYX'
          for atom in soup.residue(i).atoms():
            atom.res_type = 'CYX'
          soup.residue(j).type = 'CYX'
          for atom in soup.residue(j).atoms():
            atom.res_type = 'CYX'
          script += "bond pdb.%d.SG pdb.%d.SG\n" % (i+1, j+1)
  soup.write_pdb(in_pdb)

  if solvent_buffer > 0.0:
    script += "\n"
    script += " # add explicit waters\n"
    script += "solvateBox pdb TIP3PBOX %f iso\n" % solvent_buffer
    script += "\n"

  script += "\n"
  script += " # write files\n"
  script += "saveAmberParm pdb %s %s\n" % (top, crd)
  script += "\n"
  script += "quit\n"
  script += "\n"

  name = crd.replace('.crd', '')
  tleap_in = name + ".tleap.in"
  open(tleap_in, "w").write(script)
  tleap_out = name + ".tleap.out"
  os.system("tleap -f %s > %s" % (tleap_in, tleap_out))
  convert_amber_to_pdb(top, crd, name + '.pdb')

  os.remove("leap.log")
예제 #12
0
def make_hollow_spheres(pdb,
                        out_pdb="",
                        grid_spacing=defaults.grid_spacing,
                        size_interior_probe=defaults.interior_probe,
                        is_skip_waters=defaults.is_skip_waters,
                        size_surface_probe=defaults.surface_probe,
                        constraint_file="",
                        size_bfactor_probe=defaults.bfactor_probe):

    # load protein and get protein parameters
    print "Loading", pdb
    mol = get_molecule(pdb)
    atoms = mol.atoms()
    if is_skip_waters:
        print "Skipping water molecules"
        atoms = [a for a in atoms if a.res_type != "HOH"]
    pdbstruct.add_radii(atoms)

    # setup constraints and grid size in width
    timer = util.Timer()
    if not constraint_file:
        center = pdbstruct.get_center(atoms)
        width = pdbstruct.get_width(atoms, center)
    else:
        print "Loading constraints from %s" % constraint_file
        constraints = util.read_parameters(constraint_file)
        if constraints.type == 'sphere':
            atom1 = find_atom(atoms, constraints.chain1, constraints.res_num1,
                              constraints.atom1)
            radius = constraints.radius
            constraint_fn = get_sphere_constraint_fn(atom1.pos, radius)
            center = atom1.pos
            width = 2.0 * constraints.radius + 2.0 * grid_spacing
            radius = radius - 3.0 * grid_spacing
            inner_constraint_fn = get_sphere_constraint_fn(atom1.pos, radius)
        elif constraints.type == 'cylinder':
            atom1 = find_atom(atoms, constraints.chain1, constraints.res_num1,
                              constraints.atom1)
            atom2 = find_atom(atoms, constraints.chain2, constraints.res_num2,
                              constraints.atom2)
            axis12 = atom2.pos - atom1.pos

            offset1 = -axis12.normal_vec()
            offset1.scale(constraints.axis_offset1)
            center1 = atom1.pos + offset1

            offset2 = axis12.normal_vec()
            offset2.scale(constraints.axis_offset2)
            center2 = atom2.pos + offset2

            center = center1 + center2
            center.scale(0.5)
            radius = constraints.radius
            constraint_fn = get_cylinder_constraint_fn(center1, center2,
                                                       radius)

            half_length = vector3d.pos_distance(center, center1)
            width = 2.0 * grid_spacing + 2.0 * \
                      math.sqrt(half_length*half_length \
                        + constraints.radius*constraints.radius)
            border_length = 3.0 * grid_spacing
            center1 = center1 + axis12.normal_vec().scaled_vec(border_length)
            center2 = center2 - axis12.normal_vec().scaled_vec(border_length)
            radius = radius - border_length
            inner_constraint_fn = get_cylinder_constraint_fn(
                center1, center2, radius)
        else:
            raise ValueError("Don't understand constraint type")

    # Make the grid
    n_point = width / grid_spacing
    print "Setting up grid: %d x %d x %d, spacing %.3f, width %.1f" \
           % (n_point, n_point, n_point, grid_spacing, width)
    grid = Grid(grid_spacing, width, center)
    print_time(timer)

    print "Excluding protein bulk from grid with %.1f angstrom probe" \
            % size_interior_probe
    timer.start()
    exclude_atoms_from_grid(grid, atoms, size_interior_probe)
    print_time(timer)

    if constraint_file:
        # Eliminate all grid points outside constraints
        print "Excluding grid points outside constraint"
        timer.start()
        grid.exclude_points_in_constraint(constraint_fn)
        print_time(timer)

    is_calculate_asa_shell = True
    if constraint_file:
        if not constraints.remove_asa_shell:
            is_calculate_asa_shell = False

    if is_calculate_asa_shell:
        print "Calculating asa of atoms in protein"
        # Roll large ball over surface residues to eliminate
        # grid points over surface, then drill in from the
        # edge to eliminate the rest
        timer.start()
        add_asa(atoms, 1.4)
        print_time(timer)

        print "Excluding surface shell from grid with %.1f angstrom probe" \
                % size_surface_probe
        timer.start()
        exclude_surface(grid, atoms, size_surface_probe)
        print_time(timer)

        print "Excluding edges"
        grid.exclude_edge_to_interior()

    print "Excluding surrounded points"
    timer.start()
    hole_size = int(1.5 * 1.4 / grid_spacing)
    grid.exclude_surrounded(hole_size)
    print_time(timer)

    # Make hollow spheres from grid-points
    if not out_pdb:
        out_pdb = pdb.replace('.pdb', '-hollow.pdb')
    print "Saving hollow spheres to", out_pdb
    grid_chain = grid.make_mol(defaults.res_type, defaults.atom_type)
    if size_bfactor_probe:
        print "Averaging nearby protein b-factors for each hollow atom"
        timer.start()
        if constraint_file:
            atoms = [a for a in atoms if constraint_fn(a.pos)]
        calculate_average_bfactor(grid_chain, atoms, size_bfactor_probe)
        print_time(timer)
    if constraint_file:
        for atom in grid_chain.atoms():
            if inner_constraint_fn(atom.pos):
                atom.occupancy = 1.0
            else:
                atom.occupancy = 0.0
    is_hetatm = not defaults.atom_field.startswith("ATOM")
    pdbstruct.save_atoms(grid_chain.atoms(), out_pdb, is_hetatm)
예제 #13
0
def get_sphere_constraint_fn(center, radius):
    return lambda pos: vector3d.pos_distance(center, pos) <= radius