def test_relative_position_mover(self, ): """ Test the RelativePositionMover """ log.info("test RelativePositionMover") fn_rec1 = self.get_input_file_name("1suvA_xlinked.pdb") fn_rec2 = self.get_input_file_name("1suvC_xlinked.pdb") fn_lig = self.get_input_file_name("1suvE_xlinked.pdb") fn_tr1 = \ self.get_input_file_name("transforms-1suvA-1suvE_reduced.txt") fn_tr2 = \ self.get_input_file_name("transforms-1suvC-1suvE_filtered.txt") m = IMP.kernel.Model() sel = atom.ATOMPDBSelector() h_rec1 = atom.read_pdb(fn_rec1, m, sel) rb_rec1 = atom.create_rigid_body(h_rec1) rec1_coords = [core.XYZ(l).get_coordinates() for l in atom.get_leaves(h_rec1)] h_rec2 = atom.read_pdb(fn_rec2, m, sel) rb_rec2 = atom.create_rigid_body(h_rec2) rec2_coords = [core.XYZ(l).get_coordinates() for l in atom.get_leaves(h_rec2)] h_ligand = atom.read_pdb(fn_lig, m, sel) rb_lig = atom.create_rigid_body(h_ligand) Ts = get_relative_transforms(fn_tr1) Tis1 = [] for i, T in enumerate(Ts): V = get_internal_transform3(T, rb_rec1, rb_lig) Tis1.append(V) docked_refs1 = get_docked_reference_frames(Ts, rb_lig) Ts = get_relative_transforms(fn_tr2) Tis2 = [] for i, T in enumerate(Ts): V = get_internal_transform3(T, rb_rec2, rb_lig) Tis2.append(V) docked_refs2 = get_docked_reference_frames(Ts, rb_lig) mv = em2d.RelativePositionMover(rb_lig, 10, 20) mv.add_internal_transformations(rb_rec1, Tis1) mv.add_internal_transformations(rb_rec2, Tis2) for i in range(2): # prob_random = 0 ref_before = rb_lig.get_reference_frame() ps = mv.propose() # _move(prob_random) ref_after = rb_lig.get_reference_frame() found = False current_coords = [core.XYZ(l).get_coordinates() for l in atom.get_leaves(h_ligand)] # check all possible reference frames where the ligand could be for r in itertools.chain(docked_refs1, docked_refs2): rb_lig.set_reference_frame(r) docked_coords = [core.XYZ(l).get_coordinates() for l in atom.get_leaves(h_ligand)] rmsd = alg.get_rmsd(current_coords, docked_coords) if rmsd < 0.1: found = True self.assertTrue(found, msg="the proposed move is not " "in the relative solutions") mv.accept()
def get_center_coordinates(ps): x = [] for p in ps: p = IC.XYZ(p) x.append([p.get_x(), p.get_y(), p.get_z()]) return x
def get_residue_coordinates(self, h, ch, res): """ Get the coordinates for a residue in a molecular hierarchy @param h atom.Hierarchy object @param ch The chain id @param res Residue index """ p = self.get_residue_particle(h, ch, res) return core.XYZ(p).get_coordinates()
def get_residue_coordinates(h, chain_id=False, res=1): """ Get the coordinates of a residue (the coordinates of the first particle) @param h Hierarchy @param chain See help for get_residue_particle() @param res See help for get_residue_particle() """ p = get_residue_particle(h, chain_id, res) return core.XYZ(p).get_coordinates()
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 create_simplified_dna(dna_hierarchy, n_res): """ Gets a hierarchy containing a molecule of DNA and simplifies it, generating a coarse representation of spheres. The function returns a hierarchy with the spheres. n_res - Number of residues to use per sphere. """ chain = dna_hierarchy.get_as_chain() if (not chain.get_is_valid(True)): raise TypeError( "create_simplified_dna: the hierarchy provided is not a " "chain.") model = dna_hierarchy.get_model() ph = IMP.kernel.Particle(model) simplified_h = atom.Hierarchy.setup_particle(ph) atom.Chain.setup_particle(ph, "0") residues = atom.get_by_type(dna_hierarchy, atom.RESIDUE_TYPE) l = len(residues) # print "the DNA has ",l,"residues" for i in range(0, l, n_res): xyzrs = [] equivalent_mass = 0.0 residues_numbers = [] for r in residues[i:i + n_res]: rr = atom.Residue(r) residues_numbers.append(rr.get_index()) # print "residue",rr.get_name(),rr.get_index() residue_xyzrs = [ core.XYZ(a.get_particle()) for a in rr.get_children() ] xyzrs += residue_xyzrs # print "residue",r,"mass",get_residue_mass(r) equivalent_mass += get_residue_mass(r) s = core.get_enclosing_sphere(xyzrs) p = IMP.kernel.Particle(model) xyzr = core.XYZR.setup_particle(p) xyzr.set_radius(s.get_radius()) xyzr.set_coordinates(s.get_center()) fragment = atom.Fragment.setup_particle(p) fragment.set_residue_indexes(residues_numbers) atom.Mass.setup_particle(p, equivalent_mass) simplified_h.add_child(fragment) simplified_h.set_name("DNA") # print "simplified_h is valid:",simplified_h.get_is_valid(True) return simplified_h
def get_coordinates(hierarchy): xyz = [core.XYZ(l) for l in atom.get_leaves(hierarchy)] coords = [x.get_coordinates() for x in xyz] return coords
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 get_rmsd(hierarchy1, hierarchy2): xyz1 = [core.XYZ(l) for l in atom.get_leaves(hierarchy1)] xyz2 = [core.XYZ(l) for l in atom.get_leaves(hierarchy2)] return atom.get_rmsd(xyz1, xyz2)