def write_pdb_for_reference_frames(self, RFs, fn_pdb): """ Write a PDB file with a solution given by a set of reference frames @param RFs Reference frames for the elements of the complex @param fn_pdb File to write the solution """ log.debug("Writting PDB %s for reference frames %s", fn_pdb, RFs) representation.set_reference_frames(self.components_rbs, RFs) atom.write_pdb(self.assembly, fn_pdb)
def write_pdbs_for_reference_frames(self, RFs, fn_base): """ Write a separate PDB for each of the elements @param RFs Reference frames for the elements of the complex @param fn_base base string to build the names of the PDBs files """ log.debug("Writting PDBs with basename %s", fn_base) representation.set_reference_frames(self.components_rbs, RFs) for i, ch in enumerate(self.assembly.get_children()): atom.write_pdb(ch, fn_base + "component-%02d.pdb" % i)
def write_pdb_for_configuration(self, n, fn_pdb): """ Write a file with a configuration for the model (configuration here means a configuration in DOMINO) @param n Index of the configuration desired. """ if not self.configuration_sampling_done: raise ValueError("DominoModel: sampling not done") log.debug("Writting PDB %s for configuration %s", fn_pdb, n) configuration_set.load_configuration(n) atom.write_pdb(self.assembly, fn_pdb)
def write_pdb_for_component(self, component_index, ref, fn_pdb): """ Write one component of the assembly @param component_index Position of the component in the assembly @param ref Reference frame of the component @param fn_pdb Output PDB """ ("Writting PDB %s for component %s", fn_pdb, component_index) self.components_rbs[component_index].set_reference_frame(ref) hierarchy_component = self.assembly.get_child(component_index) atom.write_pdb(hierarchy_component, fn_pdb)
def write_pdb_for_reference_frames(fn_pdbs, refs_texts, fn_output): """ Read the PDB files, apply reference frames to them, and write a pdb """ model = IMP.kernel.Model() assembly = representation.create_assembly(model, fn_pdbs) rbs = representation.create_rigid_bodies(assembly) for t, rb in zip(refs_texts, rbs): r = TextToReferenceFrame(t).get_reference_frame() rb.set_reference_frame(r) atom.write_pdb(assembly, fn_output)
def write_pdb_for_assignment(self, assignment, fn_pdb): """ Write the solution in the assignment @param assignment Assignment class with the states for the subset @param fn_pdb File to write the model """ if not self.assignments_sampling_done: raise ValueError("DominoModel: sampling not done") log.info("Writting PDB %s for assignment %s", fn_pdb, assignment) self.load_state(assignment) atom.write_pdb(self.assembly, fn_pdb)
def write_pdb_for_configuration(self, n, fn_pdb): """ Write a file with a configuration for the model (configuration here means a configuration in DOMINO) @param n Index of the configuration desired. @param fn_pdb """ if not self.configuration_sampling_done: raise ValueError("DominoModel: sampling not done") log.debug("Writting PDB %s for configuration %s", fn_pdb, n) configuration_set.load_configuration(n) atom.write_pdb(self.assembly, fn_pdb)
def apply_transformation_to_hierarchy(prot, T, fn_write=False): """ If fn_write is different from False, write to file """ R = T.get_rotation() t = T.get_translation() xyz1 = [core.XYZ(l) for l in atom.get_leaves(prot)] coords = [p.get_coordinates() for p in xyz1] newvs = [R.get_rotated(v) + t for v in coords] for i in range(len(newvs)): xyz1[i].set_coordinates(newvs[i]) if (fn_write): atom.write_pdb(prot, fn_write)
def apply_transformation_to_hierarchy(prot, T, fn_write=False): """ If fn_write is different from False, write to file """ R = T.get_rotation() t = T.get_translation() xyz1 = [core.XYZ(l) for l in atom.get_leaves(prot)] coords = [p.get_coordinates() for p in xyz1] newvs = [R.get_rotated(v) + t for v in coords] for i in range(len(newvs)): xyz1[i].set_coordinates(newvs[i]) if(fn_write): atom.write_pdb(prot, fn_write)
def get_drms_for_backbone(assembly, native_assembly): """ Measure the DRMS ob the backbone between two assemblies. @param assembly The DRMS is computed for this assembly @param native_assembly The assembly that acts as a reference Notes: 1) The components of the assembly can be proteins or nucleic acids 2) If a protein, the c-alphas are used for calculating the drms 3) If a nucleic acid, the backbone of C4' atoms is used 4) The chains are treated as rigid bodies to speed the calculation. WARNING: if the function fails with a segmentation fault, one of the possible problems is that IMP reads some HETATM as calphas. Check that the chain does not have heteroatoms. """ begin_range = 0 ranges = [] backbone = [] h_chains = atom.get_by_type(assembly, atom.CHAIN_TYPE) for h in h_chains: atoms = representation.get_backbone(h) backbone.extend(atoms) end_range = begin_range + len(atoms) ranges.append((begin_range, end_range )) begin_range = end_range # log.debug("Ranges %s number of CA %s", ranges, len(calphas1)) xyzs = [core.XYZ(l) for l in backbone] native_chains = atom.get_by_type(native_assembly, atom.CHAIN_TYPE) native_backbone = [] for h in native_chains: native_backbone.extend( representation.get_backbone(h)) native_xyzs = [core.XYZ(l) for l in native_backbone] if(len(xyzs) != len(native_xyzs)): raise ValueError( "Cannot compute DRMS for sets of atoms of different size") drms = atom.get_rigid_bodies_drms(xyzs, native_xyzs, ranges) if(drms < 0 or math.isnan(drms) or drms > 100): log.debug("len(xyzs) = %s. len(native_xyzs) = %s",len(xyzs), len(native_xyzs)) log.debug("drms = %s",drms) atom.write_pdb(native_assembly, "drms_filtering_calphas.pdb") raise ValueError("There is a problem with the drms") return drms
def generate_monte_carlo_model(params, fn_database, seed, write_solution=False, fn_log = None): """ Generate a model for an assembly using MonteCarlo optimization @param params Class with the parameters for the experiment @param fn_database Datbase file where the solutions will be written. SQLite format. @param write_solution If True, writes a PDB with the final model @param fn_log File for logging. If the value is None, no file is written """ log.info(io.imp_info([IMP, em2d])) m = DominoModel.DominoModel() m.set_assembly_components(params.fn_pdbs, params.names) set_pair_score_restraints(params, m) set_xlink_restraints(params, m) set_geometric_complementarity_restraints(params, m) set_connectivity_restraints(params, m) set_pairs_excluded_restraint(params, m) set_em2d_restraints(params, m ) if hasattr(params, "benchmark"): m.set_native_assembly_for_benchmark(params) MonteCarloRelativeMoves.set_random_seed(seed) mc = MonteCarloRelativeMoves.MonteCarloRelativeMoves(m.model, m.components_rbs, params.anchor) mc.set_temperature_pattern(params.monte_carlo.temperatures, params.monte_carlo.iterations, params.monte_carlo.cycles) mc.set_moving_parameters(params.monte_carlo.max_translations, params.monte_carlo.max_rotations) if not hasattr(params,"dock_transforms"): mc.dock_transforms = [] else: mc.dock_transforms = params.dock_transforms # Probability for a component of the assembly of doing random movement # of doing a relative movement respect to another component mc.non_relative_move_prob = params.monte_carlo.non_relative_move_prob mc.run_monte_carlo_with_relative_movers() m.write_monte_carlo_solution(fn_database) if write_solution: atom.write_pdb(m.assembly, fn_database + ".pdb")
def get_drms_for_backbone(assembly, native_assembly): """ Measure the DRMS ob the backbone between two assemblies. @param assembly The DRMS is computed for this assembly @param native_assembly The assembly that acts as a reference Notes: 1) The components of the assembly can be proteins or nucleic acids 2) If a protein, the c-alphas are used for calculating the drms 3) If a nucleic acid, the backbone of C4' atoms is used 4) The chains are treated as rigid bodies to speed the calculation. WARNING: if the function fails with a segmentation fault, one of the possible problems is that IMP reads some HETATM as calphas. Check that the chain does not have heteroatoms. """ log.debug("Measuring DRMS of the backbone") begin_range = 0 ranges = [] backbone = [] h_chains = atom.get_by_type(assembly, atom.CHAIN_TYPE) for h in h_chains: atoms = representation.get_backbone(h) """" for a in atoms: print "atom ===> ", at = atom.Atom(a) hr = at.get_parent() res = atom.Residue(hr) ch = atom.Chain(h) ch.show() print " - ", res.show() print " - ", at.show() print "" """ backbone.extend(atoms) end_range = begin_range + len(atoms) ranges.append((begin_range, end_range)) begin_range = end_range log.debug("Ranges %s number of atoms %s", ranges, len(backbone)) xyzs = [core.XYZ(l) for l in backbone] native_chains = atom.get_by_type(native_assembly, atom.CHAIN_TYPE) names = [atom.Chain(ch).get_id() for ch in native_chains] native_backbone = [] for h in native_chains: native_backbone.extend(representation.get_backbone(h)) native_xyzs = [core.XYZ(l) for l in native_backbone] if len(xyzs) != len(native_xyzs): raise ValueError( "Cannot compute DRMS for sets of atoms of different size") log.debug("Getting rigid bodies rmsd") drms = atom.get_rigid_bodies_drms(xyzs, native_xyzs, ranges) if drms < 0 or math.isnan(drms): # or drms > 100: log.debug( "len(xyzs) = %s. len(native_xyzs) = %s", len(xyzs), len(native_xyzs)) log.debug("drms = %s", drms) atom.write_pdb(assembly, "drms_model_calphas.pdb") atom.write_pdb(native_assembly, "drms_native_calphas.pdb") raise ValueError("There is a problem with the drms. I wrote the pdbs " "for you: drms_model_calphas.pdb drms_native_calphas.pdb") return drms
def write_ligand(self, fn): """ Write a pdb file the coordinates of the ligand @param fn """ atom.write_pdb(self.h_ligand, fn)
native_chain_centers.append(rbd.get_coordinates()) bb=alg.BoundingBox3D(alg.Vector3D(-25, -40,-60), alg.Vector3D( 25, 40, 60)) # rotate and translate the chains for rbd in rigid_bodies: # rotation rotation= alg.get_random_rotation_3d() transformation1=alg.get_rotation_about_point(rbd.get_coordinates(),rotation) # translation transformation2=alg.Transformation3D(alg.get_random_vector_in(bb)) # Apply final_transformation = alg.compose(transformation1,transformation2) core.transform(rbd,final_transformation) print "Writing transformed assembly" atom.write_pdb (prot,"1z5s-transformed.pdb") # set distance restraints measusring some distances between rigid bodies # for the solution. d01 = alg.get_distance(native_chain_centers[0],native_chain_centers[1]) r01 = core.DistanceRestraint(core.Harmonic(d01,1),chains[0],chains[1]) r01.set_name("distance 0-1") d12 = alg.get_distance(native_chain_centers[1],native_chain_centers[2]) r12 = core.DistanceRestraint(core.Harmonic(d12,1),chains[1],chains[2]) r12.set_name("distance 1-2") d23 = alg.get_distance(native_chain_centers[2],native_chain_centers[3]) r23 = core.DistanceRestraint(core.Harmonic(d23,1),chains[2],chains[3]) r23.set_name("distance 2-3") d30 = alg.get_distance(native_chain_centers[3],native_chain_centers[0]) r30 = core.DistanceRestraint(core.Harmonic(d30,1),chains[3],chains[0]) r30.set_name("distance 3-0")
em2d_scores = get_columns(fn_em2d_scores,[1]) em2d_scores = em2d_scores[0] # get biggest clusters below a certain rmsd rmsd_cutoff=1.4 print "clusters below cutoff",rmsd_cutoff,"Angstroms" clusters=cluster_set.get_clusters_below_cutoff(rmsd_cutoff) for c in clusters: elems=cluster_set.get_cluster_elements(c) scores_elements=[] for cid in elems: scores_elements.append(em2d_scores[cid]) print "Cluster",c,":",elems,scores_elements, # find model with best score min_value,min_index= argmin(scores_elements) min_elem_id=elems[min_index] # The representative element is the one with the minimum em2d score print "representative element",min_elem_id,min_value for i in elems: pdb_name="cluster-%03d-elem-%03d.pdb" % (c,i) if(i!=min_elem_id): print "Writing element",i,"aligned to ",min_elem_id,":",pdb_name T=core.Transform(transformations[i][min_elem_id]) ps=atom.get_leaves(hierarchies[i]) for p in ps: T.apply(p) else: print "Writing representative element",min_elem_id,":",pdb_name atom.write_pdb(hierarchies[i],pdb_name)
sel = atom.ATOMPDBSelector() m = IMP.Model() h_receptor = atom.read_pdb(args.fn_receptor, m, sel) rb_receptor = atom.create_rigid_body(h_receptor) h_ligand = atom.read_pdb(args.fn_ligand, m, sel) rb_ligand = atom.create_rigid_body(h_ligand) if args.dock: check_for_hexdock() if not args.fn_transforms or not args.fn_internal_transforms: raise IOError("Docking requires the --int and --hex arguments") hex_docking = HexDocking() hex_docking.dock(args.fn_receptor, args.fn_ligand, args.fn_transforms) # read the HEX file of solutions and get the internal transformations # giving the relative orientation of the ligand respect to the receptor Ts = read_hex_transforms(args.fn_transforms) rb_receptor = atom.create_rigid_body(h_receptor) Tis = [get_internal_transform(T, rb_receptor, rb_ligand) for T in Ts] io.write_transforms(Tis, args.fn_internal_transforms) elif args.write: # To write the positions correctly, the script requires that the # ligand file is the same that was used for the docking Tinternal = io.read_transforms(args.fn_internal_transforms) max_number = min(args.write, len(Tinternal)) Trec = rb_receptor.get_reference_frame().get_transformation_to() for i in range(max_number): Tdock = alg.compose(Trec, Tinternal[i]) ref = alg.ReferenceFrame3D(Tdock) rb_ligand.set_reference_frame(ref) atom.write_pdb(h_ligand,"docked-%03d.pdb" % i)