def test_docking_multiple_crosslinks(self): """ Test the initial docking that is done based on minimizing the distances of the cross-linking restraints """ mydock = bx.InitialDockingFromXlinks() xl = self.xlinks.get_xlinks_for_pair(("3sfdC", "3sfdD")) mydock.set_xlinks(xl) model = IMP.kernel.Model() fn_receptor = self.get_input_file_name("3sfdC.pdb") h_receptor = atom.read_pdb(fn_receptor, model, atom.NonWaterNonHydrogenPDBSelector()) fn_ligand = self.get_input_file_name("3sfdD.pdb") h_ligand = atom.read_pdb(fn_ligand, model, atom.NonWaterNonHydrogenPDBSelector()) mydock.set_hierarchies(h_receptor, h_ligand) p = IMP.kernel.Particle(model) core.RigidBody.setup_particle(p, atom.get_leaves(h_receptor)) rb_receptor = core.RigidBody(p) p = IMP.kernel.Particle(model) core.RigidBody.setup_particle(p, atom.get_leaves(h_ligand)) rb_ligand = core.RigidBody(p) mydock.set_rigid_bodies(rb_receptor, rb_ligand) mydock.move_ligand() for res1, res2 in zip([9, 78], [37, 128]): c1 = mydock.get_residue_coordinates(h_receptor, "C", res1) c2 = mydock.get_residue_coordinates(h_ligand, "D", res2) dist = alg.get_distance(c1, c2) self.assertLessEqual(dist, self.max_distance + 4.0)
def test_docking_one_crosslink(self): """ Test the initial docking that is done based on minimizing the distances of the cross-linking restraints """ mydock = bx.InitialDockingFromXlinks() xl = self.xlinks.get_xlinks_for_pair(("3sfdB", "3sfdA")) mydock.set_xlinks(xl) self.assertEqual(len(mydock.xlinks_list), 1) mydock.clear_xlinks() self.assertEqual(len(mydock.xlinks_list), 0) model = IMP.kernel.Model() fn_receptor = self.get_input_file_name("3sfdB.pdb") h_receptor = atom.read_pdb(fn_receptor, model, atom.NonWaterNonHydrogenPDBSelector()) fn_ligand = self.get_input_file_name("3sfdA.pdb") h_ligand = atom.read_pdb(fn_ligand, model, atom.NonWaterNonHydrogenPDBSelector()) mydock.set_xlinks(xl) mydock.set_hierarchies(h_receptor, h_ligand) p = IMP.kernel.Particle(model) core.RigidBody.setup_particle(p, atom.get_leaves(h_receptor)) rb_receptor = core.RigidBody(p) p = IMP.kernel.Particle(model) core.RigidBody.setup_particle(p, atom.get_leaves(h_ligand)) rb_ligand = core.RigidBody(p) mydock.set_rigid_bodies(rb_receptor, rb_ligand) mydock.move_ligand() c1 = mydock.get_residue_coordinates(h_ligand, "A", 456) c2 = mydock.get_residue_coordinates(h_receptor, "B", 23) dist = alg.get_distance(c1, c2) self.assertLessEqual(dist, self.max_distance)
def set_complementarity_restraint(self, name1, name2, rname, max_sep_distance, max_penetration, weight, max_score=1e10): """ Set a restraint for geometric complementarity between 2 components @param name1 name of @param name2 - The restraint is applied to this components @param rname - The name given to the restraint @param max_sep_distance - maximum distance between molecules tolerated by the restraint @param max_penetration - Maximum penetration allowed (angstrom) @param weight @param max_score """ log.info("Setting geometric complementarity restraint %s: %s - %s", rname, name1, name2) A = representation.get_component(self.assembly, name1) B = representation.get_component(self.assembly, name2) restraint = multifit.ComplementarityRestraint(atom.get_leaves(A), atom.get_leaves(B), rname) restraint.set_maximum_separation(max_sep_distance) restraint.set_maximum_penetration(max_penetration) log.debug("Maximum separation: %s Maximum penetration score: %s", max_sep_distance, max_penetration) self.add_restraint(restraint, rname, weight, max_score)
def test__rigid_bodies_drms(self): """ Test drms measure taking into account rigid bodies""" m = IMP.Model() sel = atom.CAlphaPDBSelector() prot1 = atom.read_pdb(self.open_input_file("mini.pdb"), m, sel) prot2 = atom.read_pdb(self.open_input_file("mini.pdb"), m, sel) hchains1 = atom.get_by_type(prot1, atom.CHAIN_TYPE) hchains2 = atom.get_by_type(prot2, atom.CHAIN_TYPE) xyzs1 = core.XYZs(atom.get_leaves(prot1)) xyzs2 = core.XYZs(atom.get_leaves(prot2)) x = 0 ranges = [] for h in hchains1: ls1 = (atom.get_leaves(h)) y = x + len(ls1) ranges.append((x, y)) x = y drms = atom.get_drms(xyzs1, xyzs2) rb_drms = atom.get_rigid_bodies_drms(xyzs1, xyzs2, ranges) self.assertAlmostEqual(rb_drms, 0) self.assertAlmostEqual(drms, rb_drms, delta=1e-3, msg="rb_drms != drms") # Same thing after transformation of each of the chains for h in hchains2: R = alg.get_random_rotation_3d() v = alg.get_random_vector_in(alg.get_unit_bounding_box_3d()) T = alg.Transformation3D(R, v) ls = atom.get_leaves(h) for l in ls: core.transform(l.get_as_xyz(), T) drms = atom.get_drms(xyzs1, xyzs2) rb_drms = atom.get_rigid_bodies_drms(xyzs1, xyzs2, ranges) self.assertAlmostEqual(drms, rb_drms, delta=0.3, msg="rb_drms != drms")
def test_component_placement_score(self): """Testing that component placement score returns the same transformation if called twice""" m = IMP.Model() # read PDB mp1_ref = atom.read_pdb(self.open_input_file("1z5s_A.pdb"), m, atom.NonWaterPDBSelector()) mp1_mdl = atom.read_pdb(self.open_input_file("1z5s_A.pdb"), m, atom.NonWaterPDBSelector()) mp2_ref = atom.read_pdb(self.open_input_file("1z5s_C.pdb"), m, atom.NonWaterPDBSelector()) mp2_mdl = atom.read_pdb(self.open_input_file("1z5s_C.pdb"), m, atom.NonWaterPDBSelector()) xyz1_ref = core.XYZs(atom.get_leaves(mp1_ref)) xyz1_mdl = core.XYZs(atom.get_leaves(mp1_mdl)) xyz2_ref = core.XYZs(atom.get_leaves(mp2_ref)) xyz2_mdl = core.XYZs(atom.get_leaves(mp2_mdl)) # create a random transformation t = IMP.algebra.Transformation3D(IMP.algebra.get_random_rotation_3d(), IMP.algebra.get_random_vector_in(IMP.algebra.get_unit_bounding_box_3d())) for d in xyz1_mdl: core.transform(d, t) t = IMP.algebra.Transformation3D(IMP.algebra.get_random_rotation_3d(), IMP.algebra.get_random_vector_in(IMP.algebra.get_unit_bounding_box_3d())) # core.get_transformed(xyz2_mdl,t) for d in xyz2_mdl: core.transform(d, t) da1 = atom.get_component_placement_score( xyz1_ref, xyz2_ref, xyz1_mdl, xyz2_mdl) da2 = atom.get_component_placement_score( xyz1_ref, xyz2_ref, xyz1_mdl, xyz2_mdl) self.assertAlmostEqual(da1[1], da2[1])
def test_drms(self): """ Test drms measure """ m = IMP.Model() sel = atom.CAlphaPDBSelector() prot1 = atom.read_pdb(self.open_input_file("mini.pdb"), m, sel) prot2 = atom.read_pdb(self.open_input_file("mini.pdb"), m, sel) xyzs1 = core.XYZs(atom.get_leaves(prot1)) xyzs2 = core.XYZs(atom.get_leaves(prot2)) drms = atom.get_drms(xyzs1, xyzs2) # Molecule with itself self.assertAlmostEqual(drms, 0) R = IMP.algebra.get_random_rotation_3d() v = IMP.algebra.get_random_vector_in( IMP.algebra.get_unit_bounding_box_3d()) T = IMP.algebra.Transformation3D(R, v) for x in xyzs2: core.transform(x, T) drms = atom.get_drms(xyzs1, xyzs2) # Same thing after transformation self.assertAlmostEqual(drms, 0) # for x in xyzs2: R = IMP.algebra.get_random_rotation_3d() T = IMP.algebra.Transformation3D(R, v) core.transform(x, T) drms = atom.get_drms(xyzs1, xyzs2) self.assertTrue(drms > 0)
def get_native_model_info(fn_pdb1): """ Fills the information for the native structure """ model_info = ModelInfo() sel = atom.ATOMPDBSelector() m1 = IMP.Model() hierarchy1 = atom.read_pdb(fn_pdb1, m1, sel) sel = atom.CAlphaPDBSelector() malphas1 = IMP.Model() alphas1 = atom.read_pdb(fn_pdb1, malphas1, sel) axyzs1 = [core.XYZ(l) for l in atom.get_leaves(alphas1)] model_info.rmsd_calpha = 0.0 model_info.drms_alpha = 0.0 model_info.rmsd = 0.0 model_info.nat_over = 100. xyzs1 = [core.XYZ(l) for l in atom.get_leaves(hierarchy1)] model_info.radius_g = atom.get_radius_of_gyration(xyzs1) h_chains1 = atom.get_by_type(hierarchy1, atom.CHAIN_TYPE) for hc1 in h_chains1: ch1 = atom.Chain(hc1) chain_info = ChainInfo() chain_info.chain_id = ch1.get_id() chain_info.placement_distance = 0.0 chain_info.placement_angle = 0.0 chain_info.rmsd = 0.0 native_overlap_threshold = 10 chain_info.nat_over = 0.0 chain_info.model_id = -1 model_info.chains_infos.append(chain_info) model_info.model_id = -1 return model_info
def test_drms(self): """ Test drms measure """ m = IMP.kernel.Model() sel = atom.CAlphaPDBSelector() prot1 = atom.read_pdb(self.open_input_file("mini.pdb"), m, sel) prot2 = atom.read_pdb(self.open_input_file("mini.pdb"), m, sel) xyzs1 = core.XYZs(atom.get_leaves(prot1)) xyzs2 = core.XYZs(atom.get_leaves(prot2)) drms = atom.get_drms(xyzs1, xyzs2) # Molecule with itself self.assertAlmostEqual(drms, 0) R = IMP.algebra.get_random_rotation_3d() v = IMP.algebra.get_random_vector_in( IMP.algebra.get_unit_bounding_box_3d()) T = IMP.algebra.Transformation3D(R, v) for x in xyzs2: core.transform(x, T) drms = atom.get_drms(xyzs1, xyzs2) # Same thing after transformation self.assertAlmostEqual(drms, 0) # for x in xyzs2: R = IMP.algebra.get_random_rotation_3d() T = IMP.algebra.Transformation3D(R, v) core.transform(x, T) drms = atom.get_drms(xyzs1, xyzs2) self.assertTrue(drms > 0)
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_ccc(native_assembly, assembly, resolution, voxel_size, threshold, write_maps=False): """ Threshold - threshold used for the map of the native assembly. Pixels with values above this threshold in the native map are used for the calculation of the cross_correlation_coefficient """ import IMP.em as em particles_native = atom.get_leaves(native_assembly) particles_solution = atom.get_leaves(assembly) bb_native = core.get_bounding_box(core.XYZs(particles_native)) bb_solution = core.get_bounding_box(core.XYZs(particles_solution)) # bounding box enclosing both the particles of the native assembly # and the particles of the model bb_union = alg.get_union(bb_native, bb_solution) # add border of 4 voxels border = 4 * voxel_size bottom = bb_union.get_corner(0) bottom += alg.Vector3D(-border, -border, -border) top = bb_union.get_corner(1) top += alg.Vector3D(border, border, border) bb_union = alg.BoundingBox3D(bottom, top) mrw = em.MRCReaderWriter() header = em.create_density_header(bb_union, voxel_size) header.set_resolution(resolution) map_native = em.SampledDensityMap(header) map_native.set_particles(particles_native) map_native.resample() map_solution = em.SampledDensityMap(header) map_solution.set_particles(particles_solution) map_solution.resample() if (write_maps): em.write_map(map_solution, "map_solution.mrc", mrw) em.write_map(map_native, "map_native.mrc", mrw) map_native.calcRMS() map_solution.calcRMS() coarse_cc = em.CoarseCC() # base the calculation of the cross_correlation coefficient on the threshold] # for the native map, because the threshold for the map of the model changes # with each model threshold = 0.25 # threshold AFTER normalization using calcRMS() ccc = coarse_cc.cross_correlation_coefficient(map_solution, map_native, threshold) log.debug( "cross_correlation_coefficient (based on native_map " "treshold %s) %s", threshold, ccc) return ccc
def set_close_pairs_excluded_volume_restraint(self, distance=10, weight=1.0, ratio=0.05, stddev=2, max_score=False): """ Creates an excluded volume restraint between all the components of the coarse assembly.See help for @param distance Maximum distance tolerated between particles @param weight Weight for the restraint @param stddev @param max_score Maximum value for the restraint. If the parameter is None, an automatic value is computed (using the ratio). @param ratio Fraction of the number of possible pairs of particles that are tolerated to overlap. The maximum score is modified according to this ratio. I have found that ratios of 0.05-0.1 work well allowing for some interpenetration @param stddev Standard deviation used to approximate the HarmonicUpperBound function to a Gaussian """ k = core.Harmonic.get_k_from_standard_deviation(stddev) for i, c1 in enumerate(self.coarse_assembly.get_children()): for j, c2 in enumerate(self.coarse_assembly.get_children()): if j > i: name = "exc_vol_%s_%s" % (c1.get_name(), c2.get_name()) ls1 = atom.get_leaves(c1) ls2 = atom.get_leaves(c2) possible_pairs = len(ls1) * len(ls2) n_pairs = possible_pairs * ratio marker1 = IMP.Particle( self.model, "marker1 " + name) marker2 = IMP.Particle( self.model, "marker2 " + name) table_refiner = core.TableRefiner() table_refiner.add_particle(marker1, ls1) table_refiner.add_particle(marker2, ls2) score = core.HarmonicLowerBound(distance, k) pair_score = core.SphereDistancePairScore(score) close_pair_score = core.ClosePairsPairScore(pair_score, table_refiner, distance) r = core.PairRestraint(close_pair_score, IMP.ParticlePair(marker1, marker2)) if not max_score: minimum_distance_allowed = 0 max_score = weight * n_pairs * \ score.evaluate(minimum_distance_allowed) log.debug("Setting close_pairs_excluded_volume_restraint(), " "max_score %s", max_score) self.add_restraint(r, name, weight, max_score)
def set_pair_score_restraint( self, name1, name2, restraint_name, distance=10, weight=1.0, n_pairs=1, stddev=2, max_score=None ): """ Set a pair_score restraint between the coarse representation of two components @param name1 Name of the first component @param name2 Name of the second component @param restraint_name Name for the restraint @param distance Maximum distance tolerated between particles @param weight Weight of the restraint @param n_pairs @param max_score Maximum value tolerated for the restraint @param stddev Standard deviation used to approximate the HarmonicUpperBound function to a Gaussian """ table_refiner = core.TableRefiner() # The particles in A are attached to a marker particle via a refiner. # When the refiner gets a request for marker1, it returns the attached # particles A = representation.get_component(self.coarse_assembly, name1) marker1 = IMP.Particle(self.model, "marker1 " + restraint_name) table_refiner.add_particle(marker1, atom.get_leaves(A)) # same for B B = representation.get_component(self.coarse_assembly, name2) marker2 = IMP.Particle(self.model, "marker2 " + restraint_name) table_refiner.add_particle(marker2, atom.get_leaves(B)) k = core.Harmonic.get_k_from_standard_deviation(stddev) score = core.HarmonicUpperBoundSphereDistancePairScore(distance, k) # The score is set for the n_pairs closest pairs of particles pair_score = core.KClosePairsPairScore(score, table_refiner, n_pairs) # When KClosePairsPairScore is called, the refiner will provide the # particles for A and B if not max_score: # Build a maximum score based on the function type that is used, # an HarmonicUpperBound temp_score = core.HarmonicUpperBound(distance, k) error_distance_allowed = 10 max_score = weight * n_pairs * temp_score.evaluate(distance + error_distance_allowed) log.info( "Setting pair score restraint for %s %s. k = %s, max_score " "= %s, stddev %s", name1, name2, k, max_score, stddev, ) r = core.PairRestraint(pair_score, IMP.ParticlePair(marker1, marker2)) self.add_restraint(r, restraint_name, weight, max_score)
def set_close_pairs_excluded_volume_restraint(self, distance=10, weight=1.0, ratio=0.05, stddev=2, max_score=False): """ Creates an excluded volume restraint between all the components of the coarse assembly.See help for @param distance Maximum distance tolerated between particles @param weight Weight for the restraint @param stddev @param max_score Maximum value for the restraint. If the parameter is None, an automatic value is computed (using the ratio). @param ratio Fraction of the number of possible pairs of particles that are tolerated to overlap. The maximum score is modified according to this ratio. I have found that ratios of 0.05-0.1 work well allowing for some interpenetration @param stddev Standard deviation used to approximate the HarmonicUpperBound function to a Gaussian """ k = core.Harmonic.get_k_from_standard_deviation(stddev) for i, c1 in enumerate(self.coarse_assembly.get_children()): for j, c2 in enumerate(self.coarse_assembly.get_children()): if j > i: name = "exc_vol_%s_%s" % (c1.get_name(), c2.get_name()) ls1 = atom.get_leaves(c1) ls2 = atom.get_leaves(c2) possible_pairs = len(ls1) * len(ls2) n_pairs = possible_pairs * ratio marker1 = IMP.Particle( self.model, "marker1 " + name) marker2 = IMP.Particle( self.model, "marker2 " + name) table_refiner = core.TableRefiner() table_refiner.add_particle(marker1, ls1) table_refiner.add_particle(marker2, ls2) score = core.HarmonicLowerBound(distance, k) pair_score = core.SphereDistancePairScore(score) close_pair_score = core.ClosePairsPairScore(pair_score, table_refiner, distance) r = core.PairRestraint(self.model, close_pair_score, (marker1, marker2)) if not max_score: minimum_distance_allowed = 0 max_score = weight * n_pairs * \ score.evaluate(minimum_distance_allowed) log.debug("Setting close_pairs_excluded_volume_restraint(), " "max_score %s", max_score) self.add_restraint(r, name, weight, max_score)
def get_ccc(native_assembly, assembly, resolution, voxel_size, threshold, write_maps=False): """ Threshold - threshold used for the map of the native assembly. Pixels with values above this threshold in the native map are used for the calculation of the cross_correlation_coefficient """ import IMP.em as em particles_native = atom.get_leaves(native_assembly) particles_solution = atom.get_leaves(assembly) bb_native = core.get_bounding_box(core.XYZs(particles_native)) bb_solution = core.get_bounding_box(core.XYZs(particles_solution)) # bounding box enclosing both the particleso of the native assembly and # and the particles of the model bb_union = alg.get_union(bb_native, bb_solution) # add border of 4 voxels border = 4*voxel_size bottom = bb_union.get_corner(0) bottom += alg.Vector3D(-border, -border, -border) top = bb_union.get_corner(1) top += alg.Vector3D(border, border, border) bb_union = alg.BoundingBox3D(bottom, top) mrw = em.MRCReaderWriter() header = em.create_density_header(bb_union, voxel_size) header.set_resolution(resolution) map_native = em.SampledDensityMap(header) map_native.set_particles(particles_native) map_native.resample() map_solution = em.SampledDensityMap(header) map_solution.set_particles(particles_solution) map_solution.resample() if(write_maps): em.write_map(map_solution, "map_solution.mrc", mrw) em.write_map(map_native, "map_native.mrc", mrw) map_native.calcRMS(), map_solution.calcRMS() coarse_cc = em.CoarseCC() # base the calculation of the cross_correlation coefficient on the threshold] # for the native map, because the threshold for the map of the model changes # with each model # lccc = coarse_cc.local_cross_correlation_coefficient(map_solution, # map_native ,0.25) ccc = coarse_cc.cross_correlation_coefficient(map_solution, map_native, threshold) log.debug( "cross_correlation_coefficient (based on native_map treshold) %s", ccc) return ccc
def get_chains_overlap(hierarchies): """ Check if a set of chains use the same region of space. If any of the pairs of chains overlap, the function returns True. The function converts the atoms into densities and counts the number of voxels from each molecule that use the same region of space. Only a 10% of overlap of the smaller molecule is allowed """ all_points = [] for h in hierarchies: all_points += [core.XYZ(l).get_coordinates() for l in atom.get_leaves(h)] bb = alg.BoundingBox3D(all_points) sizes = bb.get_corner(1) - bb.get_corner(0) size = max([sizes[0], sizes[1], sizes[2]]) # max dimension (Angstroms) voxel_size = 3 # number of voxels for one dimension voxels_padding = 4 # voxels used to pad a little bit the bounding box size n = int(size/voxel_size) + voxels_padding # Same thing for the origin of the map, this way the coordinates are not # exactly in the edges of the box padding_dist = voxels_padding*voxel_size/2. padding_vector = alg.Vector3D(padding_dist, padding_dist, padding_dist) dh = em.DensityHeader() dh.update_map_dimensions(n, n, n) dh.set_resolution(1.0) maps = [] chain_ids = [atom.Chain(ch).get_id() for ch in hierarchies] for ch in hierarchies: density_map = em.SampledDensityMap(dh) ls = atom.get_leaves(ch) density_map.set_particles(ls) density_map.update_voxel_size(voxel_size) density_map.set_origin(bb.get_corner(0) - padding_vector ) # print density_map.get_origin(),density_map.get_header().show() density_map.resample() mrw = em.MRCReaderWriter() # em.write_map(density_map, "test-%s.mrc" % ch.get_id(), mrw) maps.append(density_map) pct = 0.2 # allowed_ratio_of_overlapping voxels_above_zero = [ number_of_voxels_above_threshold(m, 0.) for m in maps] for j, k in itertools.combinations(range(len(maps)), 2): overlapping_voxels = number_of_overlapping_voxels(maps[j],maps[k]) if (overlapping_voxels/voxels_above_zero[j] > pct or overlapping_voxels/voxels_above_zero[k] > pct): print "chains",chain_ids[j],chain_ids[k],"overlap" return True return False
def set_pair_score_restraint(self, name1, name2, restraint_name, distance=10, weight=1.0, n_pairs=1, stddev=2, max_score=None): """ Set a pair_score restraint between the coarse representation of two components @param name1 Name of the first component @param name2 Name of the second component @param restraint_name Name for the restraint @param distance Maximum distance tolerated between particles @param weight Weight of the restraint @param n_pairs @param max_score Maximum value tolerated for the restraint @param stddev Standard deviation used to approximate the HarmonicUpperBound function to a Gaussian """ table_refiner = core.TableRefiner() # The particles in A are attached to a marker particle via a refiner. # When the refiner gets a request for marker1, it returns the attached # particles A = representation.get_component(self.coarse_assembly, name1) marker1 = IMP.Particle(self.model, "marker1 " + restraint_name) table_refiner.add_particle(marker1, atom.get_leaves(A)) # same for B B = representation.get_component(self.coarse_assembly, name2) marker2 = IMP.Particle(self.model, "marker2 " + restraint_name) table_refiner.add_particle(marker2, atom.get_leaves(B)) k = core.Harmonic.get_k_from_standard_deviation(stddev) score = core.HarmonicUpperBoundSphereDistancePairScore(distance, k) # The score is set for the n_pairs closest pairs of particles pair_score = core.KClosePairsPairScore(score, table_refiner, n_pairs) # When KClosePairsPairScore is called, the refiner will provide the # particles for A and B if not max_score: # Build a maximum score based on the function type that is used, # an HarmonicUpperBound temp_score = core.HarmonicUpperBound(distance, k) error_distance_allowed = 10 max_score = weight * n_pairs * \ temp_score.evaluate(distance + error_distance_allowed) log.info("Setting pair score restraint for %s %s. k = %s, max_score " "= %s, stddev %s", name1, name2, k, max_score, stddev) r = core.PairRestraint( pair_score, IMP.ParticlePair( marker1, marker2)) self.add_restraint(r, restraint_name, weight, max_score)
def show_model_info(model, assembly, components_rbs): """ Prints information about the representation Prints the number of components (hierarchies), its children, and information about the chains and rigid bodies """ print "##################################################################################" print "Model Info" print "##################################################################################" print model.show() print "#########################" print "Hierarchies in the assembly:" print "#########################" for c in assembly.get_children(): print c.get_name(), "Is valid?", c.get_is_valid(True), "children", c.get_number_of_children() print "Child info: ",c.show() hchains = IMP.atom.get_by_type(c, IMP.atom.CHAIN_TYPE) print "Number of chains in the hierarchy:", len(hchains) for h in hchains: chain = atom.Chain(h.get_particle()) print chain.get_name(),"particles",len(atom.get_leaves(chain) ) print "#########################" print "Rigid bodies" print "#########################" for r in components_rbs: print "rigid body: Particles:",r.get_number_of_members(), print "coordinates:",r.get_coordinates() print "#########################" print "Restraints" print "#########################" n = model.get_number_of_restraints() for i in range(n): print model.get_restraint(i)
def get_em2d_restraint(assembly, images_selection_file, restraint_params, mode="fast", n_optimized=1): """ Sets a restraint for comparing the model to a set of EM images """ model = assembly.get_model() # Setup the restraint sc = em2d.EM2DScore() r = em2d.Em2DRestraint(model) r.setup(sc, restraint_params) names = em2d.read_selection_file(images_selection_file) names = [base.get_relative_path(images_selection_file, x) for x in names] log.debug("names of the images %s", names) srw = em2d.SpiderImageReaderWriter() imgs = em2d.read_images(names, srw) r.set_images(imgs) ps = atom.get_leaves(assembly) lsc = container.ListSingletonContainer(ps) r.set_particles(lsc) if (mode == "coarse"): r.set_coarse_registration_mode(True) elif (mode == "fast"): r.set_fast_mode(n_optimized) elif (mode == "complete"): pass else: raise ValueError("Em2DRestraint mode not recognized") return r
def do_clustering(self, confs_RFs, max_rmsd): """ Cluster configurations for a model based on RMSD. An IMP.ConfigurationSet is built using the reference frames for of the components of the assembly for each solution @param confs_RFs A lsit containing a tuples of reference frames. Each tuple contains the reference frame for the rigid body of one component of the assembly @param max_rmsd Maximum RMSD tolerated when clustering """ model = IMP.Model() assembly = representation.create_assembly(model, self.exp.fn_pdbs) rbs = representation.create_rigid_bodies(assembly) configuration_set = IMP.ConfigurationSet(model) for RFs in confs_RFs: representation.set_reference_frames(rbs, RFs) configuration_set.save_configuration() particles_container = container.ListSingletonContainer(model) particles_container.add_particles(atom.get_leaves(assembly)) metric = stats.ConfigurationSetRMSDMetric( configuration_set,particles_container, True) log.info("Clustering ... ") maximum_centrality = 10 self.pclus = stats.create_centrality_clustering( metric, max_rmsd, maximum_centrality) n = self.pclus.get_number_of_clusters() log.info("Number of clusters found: %s", n)
def get_em2d_restraint( assembly, images_selection_file, restraint_params, mode="fast", n_optimized=1): """ Sets a restraint for comparing the model to a set of EM images """ model = assembly.get_model() # Setup the restraint sc = em2d.EM2DScore() r = em2d.Em2DRestraint() r.setup(sc, restraint_params) names = em2d.read_selection_file(images_selection_file) names = [base.get_relative_path(images_selection_file, x) for x in names] log.debug("names of the images %s", names) srw = em2d.SpiderImageReaderWriter() imgs = em2d.read_images(names, srw) r.set_images(imgs) ps = atom.get_leaves(assembly) lsc = container.ListSingletonContainer(ps) r.set_particles(lsc) if (mode == "coarse"): r.set_coarse_registration_mode(True) elif (mode == "fast"): r.set_fast_mode(n_optimized) elif(mode == "complete"): pass else: raise ValueError("Em2DRestraint mode not recognized") return r
def get_residue_mass(residue): r = residue.get_as_residue() if (r.get_is_valid(True) == False): raise TypeError("The argument is not a residue") mass = 0.0 for l in atom.get_leaves(r): ms = atom.Mass(l) mass += ms.get_residue_mass() return mass
def get_residue_mass(residue): r = residue.get_as_residue() if(r.get_is_valid(True) == False): raise TypeError("The argument is not a residue") mass = 0.0 for l in atom.get_leaves(r): ms = atom.Mass(l) mass += ms.get_residue_mass() return mass
def test_placement_score(self): """Test placement score""" m = IMP.Model() # read PDB mp= atom.read_pdb(self.open_input_file("mini.pdb"), m, atom.NonWaterPDBSelector()) mp1= atom.read_pdb(self.open_input_file("mini.pdb"), m, atom.NonWaterPDBSelector()) xyz=core.XYZs(atom.get_leaves(mp)) xyz1=core.XYZs(atom.get_leaves(mp1)) #create a random transformation t=IMP.algebra.Transformation3D(IMP.algebra.get_random_rotation_3d(), IMP.algebra.get_random_vector_in(IMP.algebra.get_unit_bounding_box_3d())) for d in xyz1: core.transform(d,t) da=atom.get_placement_score(xyz1,xyz) d=t.get_translation().get_magnitude() a=IMP.algebra.get_axis_and_angle(t.get_rotation()).second self.assertAlmostEqual(da[0],d, 2) self.assertAlmostEqual(da[1],a, 2)
def test__rigid_bodies_drmsd_Q(self): """ Test drmsd_Q measure""" m = IMP.Model() sel = atom.CAlphaPDBSelector() prot1 = atom.read_pdb(self.open_input_file("mini.pdb"), m, sel) prot2 = atom.read_pdb(self.open_input_file("mini.pdb"), m, sel) xyzs1 = core.XYZs(atom.get_leaves(prot1)) xyzs2 = core.XYZs(atom.get_leaves(prot2)) R = IMP.algebra.get_random_rotation_3d() v = IMP.algebra.get_random_vector_in( IMP.algebra.get_unit_bounding_box_3d()) T = IMP.algebra.Transformation3D(R, v) for x in xyzs2: core.transform(x, T) thresholds = [10, 20, 30, 40, 60] for threshold in thresholds: # for x in xyzs2: R = IMP.algebra.get_random_rotation_3d() T = IMP.algebra.Transformation3D(R, v) core.transform(x, T) # test that the function is correctly implemented drmsd = 0. npairs = 0. for i in range(0, len(xyzs1) - 1): for j in range(i + 1, len(xyzs2)): dist0 = IMP.core.get_distance(xyzs1[i], xyzs1[j]) dist1 = IMP.core.get_distance(xyzs2[i], xyzs2[j]) if dist0 <= threshold or dist1 <= threshold: drmsd += (dist0 - dist1)**2 npairs += 1. drmsd = math.sqrt(drmsd / npairs) drmsd_target = atom.get_drmsd_Q(xyzs1, xyzs2, threshold) self.assertAlmostEqual(drmsd, drmsd_target) drmsd_Q = atom.get_drmsd_Q(xyzs1, xyzs2, 1000000.0) drmsd = atom.get_drmsd(xyzs1, xyzs2) self.assertAlmostEqual(drmsd, drmsd_Q)
def test__rigid_bodies_drmsd_Q(self): """ Test drmsd_Q measure""" m = IMP.kernel.Model() sel = atom.CAlphaPDBSelector() prot1 = atom.read_pdb(self.open_input_file("mini.pdb"), m, sel) prot2 = atom.read_pdb(self.open_input_file("mini.pdb"), m, sel) xyzs1 = core.XYZs(atom.get_leaves(prot1)) xyzs2 = core.XYZs(atom.get_leaves(prot2)) R = IMP.algebra.get_random_rotation_3d() v = IMP.algebra.get_random_vector_in( IMP.algebra.get_unit_bounding_box_3d()) T = IMP.algebra.Transformation3D(R, v) for x in xyzs2: core.transform(x, T) thresholds = [10, 20, 30, 40, 60] for threshold in thresholds: # for x in xyzs2: R = IMP.algebra.get_random_rotation_3d() T = IMP.algebra.Transformation3D(R, v) core.transform(x, T) # test that the function is correctly implemented drmsd = 0. npairs = 0. for i in range(0, len(xyzs1) - 1): for j in range(i + 1, len(xyzs2)): dist0 = IMP.core.get_distance(xyzs1[i], xyzs1[j]) dist1 = IMP.core.get_distance(xyzs2[i], xyzs2[j]) if dist0 <= threshold or dist1 <= threshold: drmsd += (dist0 - dist1) ** 2 npairs += 1. drmsd = math.sqrt(drmsd / npairs) drmsd_target = atom.get_drmsd_Q(xyzs1, xyzs2, threshold) self.assertAlmostEqual(drmsd, drmsd_target) drmsd_Q = atom.get_drmsd_Q(xyzs1, xyzs2, 1000000.0) drmsd = atom.get_drmsd(xyzs1, xyzs2) self.assertAlmostEqual(drmsd, drmsd_Q)
def test_placement_score(self): """Test placement score""" m = IMP.kernel.Model() # read PDB mp = atom.read_pdb(self.open_input_file("mini.pdb"), m, atom.NonWaterPDBSelector()) mp1 = atom.read_pdb(self.open_input_file("mini.pdb"), m, atom.NonWaterPDBSelector()) xyz = core.XYZs(atom.get_leaves(mp)) xyz1 = core.XYZs(atom.get_leaves(mp1)) # create a random transformation t = IMP.algebra.Transformation3D(IMP.algebra.get_random_rotation_3d(), IMP.algebra.get_random_vector_in(IMP.algebra.get_unit_bounding_box_3d())) for d in xyz1: core.transform(d, t) da = atom.get_placement_score(xyz1, xyz) d = t.get_translation().get_magnitude() a = IMP.algebra.get_axis_and_angle(t.get_rotation()).second self.assertAlmostEqual(da[0], d, 2) self.assertAlmostEqual(da[1], a, 2)
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 test__rigid_bodies_drmsd(self): """ Test drmsd measure""" m = IMP.kernel.Model() sel = atom.CAlphaPDBSelector() prot1 = atom.read_pdb(self.open_input_file("mini.pdb"), m, sel) prot2 = atom.read_pdb(self.open_input_file("mini.pdb"), m, sel) xyzs1 = core.XYZs(atom.get_leaves(prot1)) xyzs2 = core.XYZs(atom.get_leaves(prot2)) drmsd = atom.get_drmsd(xyzs1, xyzs2) # Molecule with itself self.assertAlmostEqual(drmsd, 0) R = IMP.algebra.get_random_rotation_3d() v = IMP.algebra.get_random_vector_in( IMP.algebra.get_unit_bounding_box_3d()) T = IMP.algebra.Transformation3D(R, v) for x in xyzs2: core.transform(x, T) drmsd = atom.get_drmsd(xyzs1, xyzs2) # Same thing after transformation self.assertAlmostEqual(drmsd, 0) # for x in xyzs2: R = IMP.algebra.get_random_rotation_3d() T = IMP.algebra.Transformation3D(R, v) core.transform(x, T) # test that the function is correctly implemented drmsd = 0. npairs = 0. for i in range(0, len(xyzs1) - 1): for j in range(i + 1, len(xyzs2)): dist0 = IMP.core.get_distance(xyzs1[i], xyzs1[j]) dist1 = IMP.core.get_distance(xyzs2[i], xyzs2[j]) drmsd += (dist0 - dist1) ** 2 npairs += 1. drmsd1 = math.sqrt(drmsd / npairs) drmsd2 = atom.get_drmsd(xyzs1, xyzs2) self.assertAlmostEqual(drmsd1, drmsd2)
def test__rigid_bodies_drmsd(self): """ Test drmsd measure""" m = IMP.Model() sel = atom.CAlphaPDBSelector() prot1 = atom.read_pdb(self.open_input_file("mini.pdb"), m, sel) prot2 = atom.read_pdb(self.open_input_file("mini.pdb"), m, sel) xyzs1 = core.XYZs(atom.get_leaves(prot1)) xyzs2 = core.XYZs(atom.get_leaves(prot2)) drmsd = atom.get_drmsd(xyzs1, xyzs2) # Molecule with itself self.assertAlmostEqual(drmsd, 0) R = IMP.algebra.get_random_rotation_3d() v = IMP.algebra.get_random_vector_in( IMP.algebra.get_unit_bounding_box_3d()) T = IMP.algebra.Transformation3D(R, v) for x in xyzs2: core.transform(x, T) drmsd = atom.get_drmsd(xyzs1, xyzs2) # Same thing after transformation self.assertAlmostEqual(drmsd, 0) # for x in xyzs2: R = IMP.algebra.get_random_rotation_3d() T = IMP.algebra.Transformation3D(R, v) core.transform(x, T) # test that the function is correctly implemented drmsd = 0. npairs = 0. for i in range(0, len(xyzs1) - 1): for j in range(i + 1, len(xyzs2)): dist0 = IMP.core.get_distance(xyzs1[i], xyzs1[j]) dist1 = IMP.core.get_distance(xyzs2[i], xyzs2[j]) drmsd += (dist0 - dist1)**2 npairs += 1. drmsd1 = math.sqrt(drmsd / npairs) drmsd2 = atom.get_drmsd(xyzs1, xyzs2) self.assertAlmostEqual(drmsd1, drmsd2)
def test__rigid_bodies_drms(self): """ Test drms measure taking into account rigid bodies""" m = IMP.kernel.Model() sel = atom.CAlphaPDBSelector() prot1 = atom.read_pdb(self.open_input_file("mini.pdb"), m, sel) prot2 = atom.read_pdb(self.open_input_file("mini.pdb"), m, sel) hchains1 = atom.get_by_type(prot1, atom.CHAIN_TYPE) hchains2 = atom.get_by_type(prot2, atom.CHAIN_TYPE) xyzs1 = core.XYZs(atom.get_leaves(prot1)) xyzs2 = core.XYZs(atom.get_leaves(prot2)) x = 0 ranges = [] for h in hchains1: ls1 = (atom.get_leaves(h)) y = x + len(ls1) ranges.append((x, y)) x = y drms = atom.get_drms(xyzs1, xyzs2) rb_drms = atom.get_rigid_bodies_drms(xyzs1, xyzs2, ranges) self.assertAlmostEqual(rb_drms, 0) self.assertAlmostEqual( drms, rb_drms, delta=1e-3, msg="rb_drms != drms") # Same thing after transformation of each of the chains for h in hchains2: R = alg.get_random_rotation_3d() v = alg.get_random_vector_in(alg.get_unit_bounding_box_3d()) T = alg.Transformation3D(R, v) ls = atom.get_leaves(h) for l in ls: core.transform(l.get_as_xyz(), T) drms = atom.get_drms(xyzs1, xyzs2) rb_drms = atom.get_rigid_bodies_drms(xyzs1, xyzs2, ranges) self.assertAlmostEqual(drms, rb_drms, delta=0.3, msg="rb_drms != drms")
def show_model_info(model, assembly, components_rbs): """ Prints information about the representation Prints the number of components (hierarchies), its children, and information about the chains and rigid bodies """ print( "##################################################################################" ) print("Model Info") print( "##################################################################################" ) print(model.show()) print("#########################") print("Hierarchies in the assembly:") print("#########################") for c in assembly.get_children(): print(c.get_name() + " Is valid? " + c.get_is_valid(True) + " children " + str(c.get_number_of_children())) print("Child info: " + c.show()) hchains = IMP.atom.get_by_type(c, IMP.atom.CHAIN_TYPE) print("Number of chains in the hierarchy: %d" % len(hchains)) for h in hchains: chain = atom.Chain(h.get_particle()) print(chain.get_name() + " particles %d" % len(atom.get_leaves(chain))) print("#########################") print("Rigid bodies") print("#########################") for r in components_rbs: print("rigid body: Particles: %d coordinates: %s" % (r.get_number_of_members(), r.get_coordinates())) print("#########################") print("Restraints") print("#########################") n = model.get_number_of_restraints() for i in range(n): print(model.get_restraint(i))
def create_rigid_bodies(assembly): """ set the children of a molecule type hierarchy as rigid bodies In this case, all the children are the components of the complex. I use the function create_rigid_body(), that creates a lot of sub-rigid bodies. I have changed the function and now build the rigid body directly from the leaves of each of the components. With this I guarantee that the number of rigid members is going to be the same if the components have the same number of atoms. """ molecule = assembly.get_as_molecule() if (not molecule.get_is_valid(True)): raise TypeError("create_rigid_bodies(): The argument is not a valid " "hierarchy") rbs = [] for c in molecule.get_children(): p = IMP.kernel.Particle(c.get_model()) core.RigidBody.setup_particle(p, atom.get_leaves(c)) rb = core.RigidBody(p) # rb = atom.create_rigid_body(c) rb.set_name(get_rb_name(c.get_name())) rbs.append(rb) return rbs
def show_model_info(model, assembly, components_rbs): """ Prints information about the representation Prints the number of components (hierarchies), its children, and information about the chains and rigid bodies """ print("##################################################################################") print("Model Info") print("##################################################################################") print(model.show()) print("#########################") print("Hierarchies in the assembly:") print("#########################") for c in assembly.get_children(): print(c.get_name() + " Is valid? " + c.get_is_valid(True) + " children " + str(c.get_number_of_children())) print("Child info: " + c.show()) hchains = IMP.atom.get_by_type(c, IMP.atom.CHAIN_TYPE) print("Number of chains in the hierarchy: %d" % len(hchains)) for h in hchains: chain = atom.Chain(h.get_particle()) print(chain.get_name() + " particles %d" % len(atom.get_leaves(chain))) print("#########################") print("Rigid bodies") print("#########################") for r in components_rbs: print("rigid body: Particles: %d coordinates: %s" % (r.get_number_of_members(), r.get_coordinates())) print("#########################") print("Restraints") print("#########################") n = model.get_number_of_restraints() for i in range(n): print(model.get_restraint(i))
def create_rigid_bodies(assembly): """ set the children of a molecule type hierarchy as rigid bodies In this case, all the children are the components of the complex. I use the function create_rigid_body(), that creates a lot of sub-rigid bodies. I have changed the function and now build the rigid body directly from the leaves of each of the components. With this I guarantee that the number of rigid members is going to be the same if the components have the same number of atoms. """ molecule = assembly.get_as_molecule() if(not molecule.get_is_valid(True)): raise TypeError("create_rigid_bodies(): The argument is not a valid "\ "hierarchy") rbs = [] for c in molecule.get_children(): p = IMP.kernel.Particle(c.get_model()) core.RigidBody.setup_particle(p, atom.get_leaves(c)) rb = core.RigidBody(p) # rb = atom.create_rigid_body(c) rb.set_name( get_rb_name( c.get_name() ) ) rbs.append(rb) return rbs
def show_model_info(model, assembly, components_rbs): """ Prints information about the representation Prints the number of components (hierarchies), its children, and information about the chains and rigid bodies """ print "##################################################################################" print "Model Info" print "##################################################################################" print model.show() print "#########################" print "Hierarchies in the assembly:" print "#########################" for c in assembly.get_children(): print c.get_name(), "Is valid?", c.get_is_valid( True), "children", c.get_number_of_children() print "Child info: ", c.show() hchains = IMP.atom.get_by_type(c, IMP.atom.CHAIN_TYPE) print "Number of chains in the hierarchy:", len(hchains) for h in hchains: chain = atom.Chain(h.get_particle()) print chain.get_name(), "particles", len(atom.get_leaves(chain)) print "#########################" print "Rigid bodies" print "#########################" for r in components_rbs: print "rigid body: Particles:", r.get_number_of_members(), print "coordinates:", r.get_coordinates() print "#########################" print "Restraints" print "#########################" n = model.get_number_of_restraints() for i in range(n): print model.get_restraint(i)
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_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)
def get_particle_infos_for_pdb_writing(self, name, atomistic=False): # index_residue_pair_list={} # the resindexes dictionary keep track of residues that have been already # added to avoid duplication # highest resolution have highest priority resindexes_dict = {} # this dictionary dill contain the sequence of tuples needed to # write the pdb particle_infos_for_pdb = [] geometric_center = [0, 0, 0] atom_count = 0 atom_index = 0 for n, p in enumerate(impatom.get_leaves(self.dictionary_pdbs[name])): # this loop gets the protein name from the # particle leave by descending into the hierarchy (protname, is_a_bead) = IMP.pmi.tools.get_prot_name_from_particle( p, self.dictchain[name]) if protname not in resindexes_dict: resindexes_dict[protname] = [] if impatom.Atom.get_is_setup(p) and atomistic: atom_index += 1 residue = impatom.Residue(impatom.Atom(p).get_parent()) rt = residue.get_residue_type() resind = residue.get_index() atomtype = impatom.Atom(p).get_atom_type() xyz = list(IMP.core.XYZ(p).get_coordinates()) geometric_center[0] += xyz[0] geometric_center[1] += xyz[1] geometric_center[2] += xyz[2] atom_count += 1 particle_infos_for_pdb.append( (xyz, atom_index, atomtype, rt, self.dictchain[name][protname], resind)) resindexes_dict[protname].append(resind) elif impatom.Residue.get_is_setup(p): residue = impatom.Residue(p) resind = residue.get_index() # skip if the residue was already added by atomistic resolution # 0 if resind in resindexes_dict[protname]: continue else: resindexes_dict[protname].append(resind) atom_index += 1 rt = residue.get_residue_type() xyz = IMP.core.XYZ(p).get_coordinates() geometric_center[0] += xyz[0] geometric_center[1] += xyz[1] geometric_center[2] += xyz[2] atom_count += 1 particle_infos_for_pdb.append( (xyz, atom_index, impatom.AT_CA, rt, self.dictchain[name][protname], resind)) # if protname not in index_residue_pair_list: # index_residue_pair_list[protname]=[(atom_index,resind)] # else: # index_residue_pair_list[protname].append((atom_index,resind)) elif impatom.Fragment.get_is_setup(p) and not is_a_bead: resindexes = IMP.pmi.tools.get_residue_indexes(p) resind = resindexes[len(resindexes) / 2] if resind in resindexes_dict[protname]: continue else: resindexes_dict[protname].append(resind) atom_index += 1 rt = impatom.ResidueType('BEA') xyz = IMP.core.XYZ(p).get_coordinates() geometric_center[0] += xyz[0] geometric_center[1] += xyz[1] geometric_center[2] += xyz[2] atom_count += 1 particle_infos_for_pdb.append( (xyz, atom_index, impatom.AT_CA, rt, self.dictchain[name][protname], resind)) else: if is_a_bead: atom_index += 1 rt = impatom.ResidueType('BEA') resindexes = IMP.pmi.tools.get_residue_indexes(p) resind = resindexes[len(resindexes) / 2] xyz = IMP.core.XYZ(p).get_coordinates() geometric_center[0] += xyz[0] geometric_center[1] += xyz[1] geometric_center[2] += xyz[2] atom_count += 1 particle_infos_for_pdb.append( (xyz, atom_index, impatom.AT_CA, rt, self.dictchain[name][protname], resind)) # if protname not in index_residue_pair_list: # index_residue_pair_list[protname]=[(atom_index,resind)] # else: # index_residue_pair_list[protname].append((atom_index,resind)) geometric_center = (geometric_center[0] / atom_count, geometric_center[1] / atom_count, geometric_center[2] / atom_count) return (particle_infos_for_pdb, geometric_center) '''
def get_particle_infos_for_pdb_writing(self, name, atomistic=False): # index_residue_pair_list={} # the resindexes dictionary keep track of residues that have been already # added to avoid duplication # highest resolution have highest priority resindexes_dict = {} # this dictionary dill contain the sequence of tuples needed to # write the pdb particle_infos_for_pdb = [] geometric_center = [0, 0, 0] atom_count = 0 atom_index = 0 for n, p in enumerate(impatom.get_leaves(self.dictionary_pdbs[name])): # this loop gets the protein name from the # particle leave by descending into the hierarchy (protname, is_a_bead) = IMP.pmi.tools.get_prot_name_from_particle( p, self.dictchain[name]) if protname not in resindexes_dict: resindexes_dict[protname] = [] if impatom.Atom.get_is_setup(p) and atomistic: atom_index += 1 residue = impatom.Residue(impatom.Atom(p).get_parent()) rt = residue.get_residue_type() resind = residue.get_index() atomtype = impatom.Atom(p).get_atom_type() xyz = list(IMP.core.XYZ(p).get_coordinates()) geometric_center[0] += xyz[0] geometric_center[1] += xyz[1] geometric_center[2] += xyz[2] atom_count += 1 particle_infos_for_pdb.append((xyz, atom_index, atomtype, rt, self.dictchain[name][protname], resind)) resindexes_dict[protname].append(resind) elif impatom.Residue.get_is_setup(p): residue = impatom.Residue(p) resind = residue.get_index() # skip if the residue was already added by atomistic resolution # 0 if resind in resindexes_dict[protname]: continue else: resindexes_dict[protname].append(resind) atom_index += 1 rt = residue.get_residue_type() xyz = IMP.core.XYZ(p).get_coordinates() geometric_center[0] += xyz[0] geometric_center[1] += xyz[1] geometric_center[2] += xyz[2] atom_count += 1 particle_infos_for_pdb.append((xyz, atom_index, impatom.AT_CA, rt, self.dictchain[name][protname], resind)) # if protname not in index_residue_pair_list: # index_residue_pair_list[protname]=[(atom_index,resind)] # else: # index_residue_pair_list[protname].append((atom_index,resind)) elif impatom.Fragment.get_is_setup(p) and not is_a_bead: resindexes = IMP.pmi.tools.get_residue_indexes(p) resind = resindexes[len(resindexes) / 2] if resind in resindexes_dict[protname]: continue else: resindexes_dict[protname].append(resind) atom_index += 1 rt = impatom.ResidueType('BEA') xyz = IMP.core.XYZ(p).get_coordinates() geometric_center[0] += xyz[0] geometric_center[1] += xyz[1] geometric_center[2] += xyz[2] atom_count += 1 particle_infos_for_pdb.append((xyz, atom_index, impatom.AT_CA, rt, self.dictchain[name][protname], resind)) else: if is_a_bead: atom_index += 1 rt = impatom.ResidueType('BEA') resindexes = IMP.pmi.tools.get_residue_indexes(p) resind = resindexes[len(resindexes) / 2] xyz = IMP.core.XYZ(p).get_coordinates() geometric_center[0] += xyz[0] geometric_center[1] += xyz[1] geometric_center[2] += xyz[2] atom_count += 1 particle_infos_for_pdb.append((xyz, atom_index, impatom.AT_CA, rt, self.dictchain[name][protname], resind)) # if protname not in index_residue_pair_list: # index_residue_pair_list[protname]=[(atom_index,resind)] # else: # index_residue_pair_list[protname].append((atom_index,resind)) geometric_center = (geometric_center[0] / atom_count, geometric_center[1] / atom_count, geometric_center[2] / atom_count) return (particle_infos_for_pdb, geometric_center) '''
fn_selection = em2d.get_example_path("all-models-1z5s.sel") fn_em2d_scores = em2d.get_example_path("em2d_scores_for_clustering.data") # Load models print "Reading models ..." model = IMP.Model() ssel = atom.ATOMPDBSelector() coords =[] fn_models = em2d.read_selection_file(fn_selection) n_models = len(fn_models) hierarchies=[] for fn in fn_models: fn_model=em2d.get_example_path(fn) h=atom.read_pdb(fn_model,model,ssel,True) hierarchies.append(h) xyz=core.XYZs(atom.get_leaves(h)) coords.append( [x.get_coordinates() for x in xyz]) print "Computing matrix of RMSD ..." rmsds=[[0.0 for i in range(0,n_models)] for n in range(0,n_models)] transformations=[[[] for i in range(0,n_models)] for j in range(0,n_models)] # fill rmsd and transformations for i in xrange(0,n_models): for j in xrange(i+1,n_models): if(i!=j): t=IMP.algebra.get_transformation_aligning_first_to_second( coords[i], coords[j]) transformations[i][j]=t transformations[j][i]=t.get_inverse() temp = [t.get_transformed(v) for v in coords[i]]