def get_rmsd(pdb1, pdb2, segments1, segments2, atom_types): polymer1 = pdbstruct.Polymer(pdb1) atoms1 = get_superposable_atoms(polymer1, segments1, atom_types) polymer2 = pdbstruct.Polymer(pdb2) atoms2 = get_superposable_atoms(polymer2, segments2, atom_types) center1 = pdbstruct.get_center(atoms1) polymer1.transform(vector3d.Translation(-center1)) polymer2.transform(vector3d.Translation(-pdbstruct.get_center(atoms2))) crds1 = get_crds(atoms1) crds2 = get_crds(atoms2) return rmsd(crds1, crds2)
def get_best_alignment(pdb1, pdb2, segments1, segments2, atom_types): """Returns rmsd and filename of transformed pdb2.""" polymer1 = pdbstruct.Polymer(pdb1) atoms1 = get_superposable_atoms(polymer1, segments1, atom_types) polymer2 = pdbstruct.Polymer(pdb2) atoms2 = get_superposable_atoms(polymer2, segments2, atom_types) center1 = pdbstruct.get_center(atoms1) polymer1.transform(vector3d.Translation(-center1)) polymer2.transform(vector3d.Translation(-pdbstruct.get_center(atoms2))) polymer2.transform(calculate_superposition_matrix(atoms1, atoms2)) rmsd = sum_rmsd(atoms1, atoms2) temp_pdb2 = util.fname_variant(pdb2) polymer2.transform(vector3d.Translation(center1)) polymer2.write_pdb(temp_pdb2) return rmsd, temp_pdb2
def volume(atoms, grid_spacing, out_fname=""): center = pdbstruct.get_center(atoms) width = pdbstruct.get_width(atoms, center) + 4.0 grid = Grid(grid_spacing, width, center) print "Grid %d x %d x %d; Width %.2f Å" % \ (grid.n, grid.n, grid.n, grid.actual_width) for atom in atoms: grid.exclude_sphere(atom.pos, atom.radius) d_volume = float(grid_spacing)**3 volume = grid.n_excluded() * d_volume print u"Volume %.1f Å^3 (%d x %.3f Å^3)" \ % (volume, grid.n_excluded(), d_volume) if out_fname: atoms = grid.make_mol("HOH", "O").atoms() pdbstruct.save_atoms(atoms, out_fname)
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)