def calculate_residue_asas(soup): residue_asas = [] atoms = [] for r in soup.residues(): atoms.extend(r.atoms()) pdbstruct.add_radii(atoms) atom_asas = calculate_asa(atoms, 1.4) for atom, asa in zip(atoms, atom_asas): atom.asa = asa for r in soup.residues(): atom_asas = [a.asa for a in r.atoms()] residue_asas.append(sum(atom_asas)) return residue_asas
def main(): import sys import getopt import pdbstruct opts, args = getopt.getopt(sys.argv[1:], "n:") usage = \ """ Copyright (c) 2007 Bosco Ho Calculates the total Accessible Surface Area (ASA) of atoms in a PDB file. Usage: asa.py -n n_sphere in_pdb [out_pdb] - out_pdb PDB file in which the atomic ASA values are written to the b-factor column. -n n_sphere number of points used in generating the spherical dot-density for the calculation (default=960). The more points, the more accurate (but slower) the calculation. """ if len(args) == 0: print usage return mol = pdbstruct.Molecule(args[0]) atoms = mol.atoms() pdbstruct.add_radii(atoms) n_sphere = 960 for o, a in opts: if '-n' in o: n_sphere = int(a) print "Points on sphere: ", n_sphere asas = calculate_asa(atoms, 1.4, n_sphere) print "%.1f angstrom squared." % sum(asas) if len(args) > 1: for asa, atom in zip(asas, atoms): atom.bfactor = asa mol.write_pdb(args[1])
dot-density for the calculation (default=960). The more points, the more accurate (but slower) the calculation. """ import sys import getopt opts, args = getopt.getopt(sys.argv[1:], "n:") if len(args) == 0: print usage sys.exit(1) mol = pdbstruct.Molecule(args[0]) atoms = mol.atoms() pdbstruct.add_radii(atoms) n_sphere = 960 for o, a in opts: if '-n' in o: n_sphere = int(a) print "Points on sphere: ", n_sphere asas = calculate_asa(atoms, 1.4, n_sphere) print "%.1f angstrom squared." % sum(asas) if len(args) > 1: for asa, atom in zip(asas, atoms): atom.bfactor = asa mol.write_pdb(args[1])
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)