def test_delete_model_constructor(self): """Constructed Python Particles should survive model deletion""" refcnt = IMP.test.RefCountChecker(self) m = IMP.Model("python restraint survival") p = IMP.Particle(m) self.assertEqual(p.get_ref_count(), 2) refcnt.assert_number(3) # New particle p should not go away until we free the Python reference del m refcnt.assert_number(1) self.assertEqual(p.get_ref_count(), 1) del p refcnt.assert_number(0)
def test_add_to_weight_derivative(self): for n in range(1, 20): w = Weight.setup_particle(IMP.Particle(self.m), n) ws = np.random.uniform(size=n) ws /= np.sum(ws) w.set_weights(ws) for k in range(0, n): dwk = np.random.normal() w.add_to_weight_derivative(k, dwk, IMP.DerivativeAccumulator()) self.assertAlmostEqual( w.get_weight_derivative(k), dwk, delta=1e-6 )
def _create_tamd_centroid(self, m): """Create a TAMD centroid for a bunch of particles, with a real centroid and restrained centroid realization""" # IMP.set_log_level(IMP.MEMORY) n = 3 p = IMP.Particle(m, "body") # "tamd_centroid") pH = IMP.core.Hierarchy.setup_particle(p) pD = IMP.core.XYZR.setup_particle(p) pD.set_radius(3) IMP.atom.Mass.setup_particle(p, n) pD.set_coordinates_are_optimized(True) # TODO: very unclear if this is needed or dangerous - to get BD to evaluate on it pDiffusion = IMP.atom.Diffusion.setup_particle(p) # pDiffusion.set_diffusion_coefficient(1000000) print(pDiffusion) fine_particles = [] for i in range(0, n): fine_p = self._create_fine_particle(m, "fine particle %d" % i) fine_particles.append(fine_p) fine_pH = IMP.core.Hierarchy.setup_particle(fine_p) pH.add_child( fine_pH ) print(pH.get_children()) refiner = IMP.core.ChildrenRefiner( IMP.core.Hierarchy.get_default_traits()) IMP.core.Centroid.setup_particle(p, refiner) m.update() # so c is up to date # TAMD realization of centroid (S for star) pstar = IMP.Particle(m, "centroid*") pstarD = IMP.core.XYZR.setup_particle(pstar) pstarD.set_coordinates( pD.get_coordinates() ) pstarD.set_radius( pD.get_radius() ) pstarD.set_coordinates_are_optimized( True ) pstarH = IMP.core.Hierarchy.setup_particle(pstar) IMP.atom.Diffusion.setup_particle( pstar ) IMP.atom.TAMDParticle.setup_particle( pstar, p, 100.0, 4.0) IMP.atom.Mass.setup_particle( pstar, 2) return (p, fine_particles, pstar)
def test_angles(self): mdl = IMP.Model() p=IMP.Particle(mdl) d=IMP.core.XYZR.setup_particle(p) d.set_coordinates((0,0,0)) d.set_radius(1.0) IMP.atom.Mass.setup_particle(p,1.0) h=IMP.atom.Hierarchy.setup_particle(p) cr=IMP.pmi.restraints.basic.CylinderRestraint(mdl,[h],10,20,-72,72) cr.set_was_used(True) for angle in range(360): anglerad=float(angle)/180.0*math.pi d.set_coordinates((math.cos(anglerad),math.sin(anglerad),0))
def setUp(self): IMP.test.TestCase.setUp(self) self.m = IMP.Model() self.prot = IMP.atom.read_pdb( self.get_input_file_name('three.pdb'), self.m, IMP.atom.NonWaterNonHydrogenPDBSelector()) #build two groups of atoms, cut at phi of residue 2 self.residues = IMP.atom.get_by_type(self.prot, IMP.atom.RESIDUE_TYPE) self.residues = [i.get_as_residue() for i in self.residues] self.res_idx = [i.get_index() for i in self.residues] self.left_atoms = set() self.right_atoms = set() for i in IMP.atom.get_by_type(self.prot, IMP.atom.ATOM_TYPE): idx = i.get_parent().get_as_residue().get_index() if idx == 1: self.left_atoms.add(i.get_particle()) elif idx == 3: self.right_atoms.add(i.get_particle()) else: at_t = i.get_as_atom().get_atom_type() if at_t == IMP.atom.AT_N: self.left_atoms.add(i.get_particle()) else: self.right_atoms.add(i.get_particle()) #build rbs from these groups self.rbs = [ IMP.core.RigidBody.setup_particle(IMP.Particle(self.m), list(self.left_atoms)), IMP.core.RigidBody.setup_particle(IMP.Particle(self.m), list(self.right_atoms)) ] # build the joint between them self.phi = IMP.atom.get_phi_dihedral_atoms( self.residues[self.res_idx.index(2)]) self.phi = [IMP.core.XYZ(i.get_particle()) for i in self.phi] self.joint = IMP.kinematics.DihedralAngleRevoluteJoint( self.rbs[0], self.rbs[1], *self.phi) #create mover self.mv = IMP.kinematics.RevoluteJointMover(self.m, [self.joint], 0.1)
def create_diffusing_particle(m, radius): ''' create an IMP particle that can be used as valid input for an IMP BrownianDynamics simulation, having coordinates, radius, mass and diffusion coefficient ''' p = IMP.Particle(m) d = IMP.core.XYZR.setup_particle(p) d.set_radius(radius) d.set_coordinates_are_optimized(True) m = IMP.atom.Mass.setup_particle(p, 1) diff = IMP.atom.Diffusion.setup_particle(p) return p
def test_values(self): mdl = IMP.Model() p=IMP.Particle(mdl) d=IMP.core.XYZR.setup_particle(p) d.set_coordinates((0,0,0)) d.set_radius(1.0) IMP.atom.Mass.setup_particle(p,1.0) h=IMP.atom.Hierarchy.setup_particle(p) cr=IMP.pmi.restraints.basic.CylinderRestraint(mdl,[h],10,20) cr.set_was_used(True) for r in range(100): d.set_coordinates((r,0,0)) cr.unprotected_evaluate(None)
def test_sample_provenance(self): """Test SampleProvenance decorator""" m = IMP.Model() p = IMP.core.SampleProvenance.setup_particle(m, IMP.Particle(m), "Monte Carlo", 100, 5) self.assertTrue(IMP.core.SampleProvenance.get_is_setup(p)) self.assertEqual(p.get_method(), "Monte Carlo") p.set_method("Molecular Dynamics") self.assertEqual(p.get_method(), "Molecular Dynamics") self.assertRaisesUsageException(p.set_method, "Garbage") self.assertRaisesUsageException( IMP.core.SampleProvenance.setup_particle, m, IMP.Particle(m), "Garbage", 100, 5) self.assertEqual(p.get_number_of_frames(), 100) p.set_number_of_frames(200) self.assertEqual(p.get_number_of_frames(), 200) self.assertEqual(p.get_number_of_iterations(), 5) p.set_number_of_iterations(42) self.assertEqual(p.get_number_of_iterations(), 42) self.assertEqual(p.get_number_of_replicas(), 1) p.set_number_of_replicas(8) self.assertEqual(p.get_number_of_replicas(), 8)
def test_init(self): """Test basic set-up.""" m = IMP.Model() ds = self._create_directions(m) a = IMP.core.DirectionAngle.setup_particle(IMP.Particle(m), ds) self.assertTrue( IMP.core.DirectionAngle.get_is_setup(m, a.get_particle_index())) self.assertEqual(a.get_particle(0), ds[0].get_particle()) self.assertEqual(a.get_particle(1), ds[1].get_particle()) a = IMP.core.DirectionAngle.setup_particle(IMP.Particle(m), ds[0], ds[1]) self.assertTrue( IMP.core.DirectionAngle.get_is_setup(m, a.get_particle_index())) self.assertEqual(a.get_particle(0), ds[0].get_particle()) self.assertEqual(a.get_particle(1), ds[1].get_particle()) a = IMP.core.DirectionAngle.setup_particle(IMP.Particle(m), ds[0].get_particle_index(), ds[1].get_particle_index()) self.assertTrue( IMP.core.DirectionAngle.get_is_setup(m, a.get_particle_index())) self.assertEqual(a.get_particle(0), ds[0].get_particle()) self.assertEqual(a.get_particle(1), ds[1].get_particle())
def create_new_granule(model, i, v, R, r, mass): # Set the information of a granule p = IMP.Particle(model, "Granule_{}".format(i)) a = set_param_for_particle(model, p, v, R, mass, 2) # Generate six binding patches for the granule sp = IMP.algebra.Sphere3D(v, R) patch_set = [ IMP.core.XYZR.setup_particle( IMP.Particle(model, "GranulePatch_" + str(i) + "_{}".format(j))) for j in range(6) ] for j in range(6): patch_set[j].set_coordinates( IMP.algebra.get_uniform_surface_cover(sp, 6)[j]) patch_set[j].set_coordinates_are_optimized(True) patch_set[j].set_radius(3) IMP.atom.Mass.setup_particle(patch_set[j], 1) IMP.atom.Diffusion.setup_particle(model, patch_set[j]) IMP.display.Colored.setup_particle(patch_set[j], IMP.display.get_display_color(0)) return a, patch_set
def test_reject_restores_initial_state(self): """Test rejecting a move returns the surface to previous state.""" m = IMP.Model() surf = IMP.core.Surface.setup_particle(IMP.Particle(m)) n = surf.get_normal() c = surf.get_coordinates() surf.set_coordinates_are_optimized(True) surf.set_normal_is_optimized(True) mv = IMP.core.SurfaceMover(surf, 1, .1, 1.) mv.propose() mv.reject() self.assertAlmostEqual((n - surf.get_normal()).get_magnitude(), 0) self.assertAlmostEqual((c - surf.get_coordinates()).get_magnitude(), 0)
def test_propose_move(self): """Test proposing move alters center and normal.""" m = IMP.Model() surf = IMP.core.Surface.setup_particle(IMP.Particle(m)) n = surf.get_normal() c = surf.get_coordinates() surf.set_coordinates_are_optimized(True) surf.set_normal_is_optimized(True) mv = IMP.core.SurfaceMover(surf, 1, .1, 1.) mv.propose() self.assertNotAlmostEqual((n - surf.get_normal()).get_magnitude(), 0) self.assertNotAlmostEqual((c - surf.get_coordinates()).get_magnitude(), 0)
def _create_singleton_particle(self, m, name): ''' create a particle for simulation fine level''' p = IMP.Particle(m, name) d = IMP.core.XYZR.setup_particle(p) d.set_coordinates_are_optimized(True) bb = IMP.algebra.BoundingBox3D([0, 0, 0], [50, 50, 50]) d.set_coordinates(IMP.algebra.get_random_vector_in(bb)) d.set_radius(2) d.set_coordinates_are_optimized(True) IMP.atom.Mass.setup_particle(p, 1) IMP.atom.Diffusion.setup_particle(p) IMP.core.Hierarchy.setup_particle(p) return p
def _create_rb(self, m): prb = IMP.Particle(m, "body") h0 = IMP.atom.Hierarchy.setup_particle(prb) core = IMP.Particle(m, "core") IMP.core.XYZR.setup_particle(core).set_radius(1) h0.add_child(IMP.atom.Hierarchy.setup_particle(core)) ps = [core] IMP.atom.Mass.setup_particle(core, 1) for i in range(0, 3): ep = IMP.Particle(m, "ep" + str(i)) d = IMP.core.XYZR.setup_particle(ep) d.set_coordinate(i, 1) d.set_radius(.1) IMP.atom.Mass.setup_particle(ep, 1) ps.append(d) h0.add_child(IMP.atom.Hierarchy.setup_particle(ep)) IMP.core.RigidBody.setup_particle( prb, ps).set_coordinates_are_optimized(True) rbd = IMP.atom.RigidBodyDiffusion.setup_particle(prb) rbd.set_rotational_diffusion_coefficient( rbd.get_rotational_diffusion_coefficient() * 10) return prb, ep, core
def test_no_model(self): """Check access of attributes from python""" m = IMP.Model() p = IMP.Particle(m) ik = IMP.IntKey("hi") m.add_attribute(ik, p.get_index(), 1) self.assertEqual(m.get_attribute(ik, p.get_index()), 1) pisk = IMP.ParticleIndexesKey("hi") m.add_attribute(pisk, p.get_index(), [p.get_index()]) self.assertEqual(m.get_attribute(pisk, p.get_index()), [p.get_index()]) pik = IMP.ParticleIndexKey("hi") m.add_attribute(pik, p.get_index(), p.get_index()) self.assertEqual(m.get_attribute(pik, p.get_index()), p.get_index())
def test_get_particle_infos(self): """Test get_particle_infos_for_pdb_writing with no particles""" m = IMP.Model() empty_hier = IMP.atom.Hierarchy.setup_particle(IMP.Particle(m)) output = IMP.pmi.output.Output() output.init_pdb("test_output.pdb", empty_hier) info, center = output.get_particle_infos_for_pdb_writing( "test_output.pdb") self.assertEqual(len(info), 0) self.assertAlmostEqual(center[0], 0., delta=1e-5) self.assertAlmostEqual(center[1], 0., delta=1e-5) self.assertAlmostEqual(center[2], 0., delta=1e-5) os.unlink('test_output.pdb')
def setUp(self): IMP.test.TestCase.setUp(self) # IMP.set_log_level(IMP.TERSE) self.m = IMP.Model() # read molecules self.m1 = IMP._create_particles_from_pdb( self.get_input_file_name("1z5s_A.pdb"), self.m) self.m2 = IMP._create_particles_from_pdb( self.get_input_file_name("1z5s_C.pdb"), self.m) # create rigid bodies self.rb0 = IMP.core.RigidBody.setup_particle(IMP.Particle(self.m), self.m1) self.rb0.set_coordinates_are_optimized(True) self.rb1 = IMP.core.RigidBody.setup_particle(IMP.Particle(self.m), self.m2) self.rb1.set_coordinates_are_optimized(True) # add restraints self.h = IMP.core.HarmonicUpperBound(0, 3.) self.dr = IMP.core.DistanceRestraint(self.m, self.h, self.rb0, self.rb1) self.sf = IMP.core.RestraintsScoringFunction([self.dr])
def test_it(self): """Test bond decorator pair container""" m = IMP.Model() p0 = IMP.Particle(m) p1 = IMP.Particle(m) p2 = IMP.Particle(m) p3 = IMP.Particle(m) b0 = IMP.atom.Bonded.setup_particle(p0) b1 = IMP.atom.Bonded.setup_particle(p1) b3 = IMP.atom.Bonded.setup_particle(p3) b = IMP.atom.create_custom_bond(b0, b1, 1, 1) pc = IMP.atom.BondedPairFilter() print(pc.get_value((p0, p0))) self.assertTrue(pc.get_value((p0, p1))) print(0) self.assertFalse(pc.get_value((p2, p0))) print(1) self.assertFalse(pc.get_value((p2, p2))) print(2) self.assertFalse(pc.get_value((p0, p0))) self.assertFalse(pc.get_value((p0, p3)))
def test_saxs_residue_particle_restraint(self): """Check residue level saxs restraint using IMP.saxs.RESIDUES particles. Needed for PMI hierarchies at resolution=1, which have no atom particles """ m = IMP.Model() mdl = IMP.Model() # New model for residue particles only #! read PDB (only CA atoms) mp = IMP.atom.read_pdb(self.get_input_file_name('6lyz.pdb'), m, IMP.atom.CAlphaPDBSelector()) # Get all CA particles particles = IMP.atom.get_by_type(mp, IMP.atom.ATOM_TYPE) outhiers = [] for ca in particles: residue = IMP.atom.Residue(ca.get_parent()) rt = residue.get_residue_type() vol = IMP.atom.get_volume_from_residue_type(rt) mass = IMP.atom.get_mass(rt) # Create new particle in mdl and set up as a Residue rp1 = IMP.Particle(mdl) this_res = IMP.atom.Residue.setup_particle(rp1, rt, residue.get_index()) # Add radius and shape information radius = IMP.algebra.get_ball_radius_from_volume_3d(vol) shape = IMP.algebra.Sphere3D( IMP.core.XYZ(ca).get_coordinates(), radius) rp1.set_name("Residue_%i" % residue.get_index()) IMP.core.XYZR.setup_particle(rp1, shape) IMP.atom.Mass.setup_particle(rp1, mass) outhiers.append(this_res) exp_profile = IMP.saxs.Profile(self.get_input_file_name('lyzexp.dat')) saxs_particles = IMP.atom.Selection(outhiers).get_selected_particles() # Ensure the particles list is equal to the number of residues self.assertEqual(len(saxs_particles), 129) model_profile = IMP.saxs.Profile() model_profile.calculate_profile(saxs_particles, IMP.saxs.RESIDUES) saxs_score = IMP.saxs.ProfileFitterChi(exp_profile) self.assertAlmostEqual(saxs_score.compute_score(model_profile), 1.03, delta=0.01)
def test_score_same_bead(self): """ This test checks when the cross-linked residues are assigned to the same particle """ IMP.test.TestCase.setUp(self) m = IMP.Model() p1 = IMP.Particle(m) slope = 0.01 length = 10 xyz1 = IMP.core.XYZR.setup_particle(p1) xyz1.set_coordinates((0, 0, 0)) sigma1 = setupnuisance(m, 5, 0, 100, False) psi = setupnuisance(m, 0.1, 0.0, 0.5, False) dr = IMP.isd.CrossLinkMSRestraint(m, length, slope) dr.add_contribution((p1, p1), (sigma1, sigma1), psi) lw = IMP.isd.LogWrapper([dr], 1.0) # initialize also a restraint which output -log(prob) dr_lp = IMP.isd.CrossLinkMSRestraint(m, length, slope, True) dr_lp.add_contribution((p1, p1), (sigma1, sigma1), psi) testdr = CrossLinkMS(length, slope) testdr.add_contribution(xyz1, xyz1, sigma1, sigma1, psi) maxradius = 40.0 npoints = 100 sigmas1 = sample([0.01, 0.1, 0.5, 1.0, 5.0, 10.0, 50.0, 100.0], 5) psis = sample( [0.01, 0.05, 0.1, 0.15, 0.2, 0.25, 0.3, 0.35, 0.4, 0.45, 0.49], 5) for s1 in sigmas1: sigma1.set_scale(s1) for p1 in psis: psi.set_scale(p1) for i in range(npoints): radius = maxradius / npoints * float(i) xyz1.set_radius(radius) scoretest = - \ log(testdr.get_probability()) score = lw.unprotected_evaluate(None) score_lp = dr_lp.unprotected_evaluate(None) self.assertAlmostEqual(score, scoretest, places=4) self.assertAlmostEqual(score_lp, scoretest, places=4)
def create_complex_system(self, mdl, parent=None): # read in system mh = IMP.atom.read_pdb(self.get_input_file_name('1z5s_C.pdb'), mdl) ch = mh.get_children()[0] idxs = [IMP.atom.Residue(h).get_index() \ for h in IMP.atom.get_by_type(ch,IMP.atom.RESIDUE_TYPE)] # prepare hierarchy p = IMP.Particle(mdl) frag = IMP.atom.Fragment.setup_particle(p, idxs) rep = IMP.atom.Representation.setup_particle(p, 0) if parent: parent.add_child(rep) for r in ch.get_children(): frag.add_child(r) # average along backbone to get Gaussians (don't do this in real life) tmp20 = IMP.atom.create_simplified_along_backbone(ch, 20) density_frag = IMP.atom.Fragment.setup_particle( IMP.Particle(mdl), idxs) for frag in tmp20.get_children(): gp = frag.get_particle() xyzr = IMP.core.XYZR(gp) g = bead2gaussian(xyzr.get_coordinates(), xyzr.get_radius(), mdl) density_frag.add_child(g) density_frag.set_name("Density:20") rep.add_representation(density_frag.get_particle(), IMP.atom.DENSITIES, 20) # also add some beads res10 = self.build_necklace(ch.get_children(), 10) res10.set_name("Res:10") rep.add_representation(res10, IMP.atom.BALLS, 10) res20 = self.build_necklace(ch.get_children(), 20) res20.set_name("Res:20") rep.add_representation(res20, IMP.atom.BALLS, 20) return rep
def _initialize_model(self): print("radius", radius, "slab radius", slab_pore_radius, "slab_height", slab_height) m = IMP.Model() self.m = m p = IMP.Particle(m, "diffuser") d = IMP.core.XYZR.setup_particle(p) self.d = d d.set_coordinates_are_optimized(True) d.set_radius(radius) bb = IMP.algebra.BoundingBox3D( 0.5 * IMP.algebra.Vector3D(-boxw, -boxw, -boxw), 0.5 * IMP.algebra.Vector3D(boxw, boxw, boxw)) p_slab = IMP.Particle(m, "slab") IMP.npctransport.SlabWithCylindricalPore.setup_particle \ (p_slab, slab_height, slab_pore_radius) self.assertTrue( IMP.npctransport.SlabWithCylindricalPore.get_is_setup(p_slab)) # test cast to slab slab = IMP.npctransport.SlabWithPore(p_slab) self.slab = slab self.assertEqual(slab.get_pore_radius(), slab_pore_radius) self.assertEqual(slab.get_thickness(), slab_height) slabps = IMP.npctransport.SlabWithCylindricalPorePairScore(1.0) self.assertFalse(slab.get_pore_radius_is_optimized() ) # verify correct default value r = IMP.core.PairRestraint( m, slabps, [p_slab.get_index(), p.get_index()], "slab") self.r = r score_init = slabps.evaluate_index( m, [p_slab.get_index(), p.get_index()], IMP.DerivativeAccumulator(1.0)) self.assertEqual(score_init, 0.0) # Create optimizer: cg = IMP.core.SteepestDescent(m) cg.set_scoring_function(r) cg.set_step_size(0.01) self.opt = cg
def test_global_min2(self): """Test clustering of states""" m = IMP.Model() p0 = IMP.Particle(m) IMP.core.XYZ.setup_particle(p0) p1 = IMP.Particle(m) IMP.core.XYZ.setup_particle(p1) pts = [] for i in range(0, 101, 5): for j in range(0, 101, 5): pts.append(IMP.algebra.Vector3D(i, j, 0)) fa = [] fb = [] for i in range(len(pts)): v = pts[i] if v[0] < 20 and v[1] < 20: fa.append(i) if v[0] > 80 and v[1] > 80: fb.append(i) self.assertEqual(len(fa), len(fb)) print("sets are") print(fa) print(fb) s = IMP.domino.Subset([p0, p1]) states = [] for i in fa: for j in fb: states.append(IMP.domino.Assignment([i, j])) states.append(IMP.domino.Assignment([j, i])) pst = IMP.domino.ParticleStatesTable() ps = IMP.domino.XYZStates(pts) pst.set_particle_states(p0, ps) pst.set_particle_states(p1, IMP.domino.XYZStates(pts)) IMP.set_log_level(IMP.TERSE) ssl = IMP.domino.get_state_clusters(s, states, pst, 6) print("Solutions are") for s in ssl: print(s)
def test_removal(self): """Check that ref counting works with removing particles""" refcnt = IMP.test.RefCountChecker(self) m = IMP.Model("ref counting and particle removal") p = IMP.Particle(m) refcnt.assert_number(2) m.remove_particle(p.get_index()) # Particle should not disappear yet since Python still has a reference refcnt.assert_number(2) self.assertFalse(p.get_is_active(), "Removed particle is still active") del p refcnt.assert_number(1) del m refcnt.assert_number(0)
def test_two_composites(self): import random m=IMP.Model() xyzrs1=[] xyzrs2=[] for i in range(10): p=IMP.Particle(m) d=IMP.core.XYZR.setup_particle(p) d.set_coordinates(IMP.algebra.get_random_vector_in(IMP.algebra.Sphere3D((0,0,0),100.0))) d.set_radius(10.0*random.random()) xyzrs1.append(d) for i in range(15): p=IMP.Particle(m) d=IMP.core.XYZR.setup_particle(p) d.set_coordinates(IMP.algebra.get_random_vector_in(IMP.algebra.Sphere3D((0,0,0),100.0))) d.set_radius(10.0*random.random()) xyzrs2.append(d) dist=IMP.pmi.get_bipartite_minimum_sphere_distance(xyzrs1,xyzrs2) self.assertAlmostEqual(dist, self.python_version_min_distance(xyzrs1,xyzrs2), delta=1e-5)
def test_set_position(self): """Make sure the Table PR works""" IMP.set_log_level(IMP.VERBOSE) print("hello") m = IMP.Model() p = IMP.Particle(m) tpr = IMP.core.TableRefiner() ps = [] ps.append(p) tpr.add_particle(p, ps) self.assertTrue(tpr.get_can_refine(p)) self.assertEqual(tpr.get_refined(p)[0], p) tpr.remove_particle(p) self.assertFalse(tpr.get_can_refine(p))
def test_named_representation(self): """Test representation when you manually set resolutions""" mdl = IMP.Model() mh = IMP.atom.read_pdb(self.get_input_file_name('1z5s_C.pdb'), mdl) mh.set_name("res0") res1 = IMP.atom.create_simplified_along_backbone(mh, 1) res1.set_name('res1') res10 = IMP.atom.create_simplified_along_backbone(mh, 10) res10.set_name('res10') root = IMP.atom.Hierarchy.setup_particle(IMP.Particle(mdl)) root.add_child(mh) rep = IMP.atom.Representation.setup_particle(root, 0) # should get res0 when it's the only resolution self.assertEqual(rep.get_representation(0), root) sel0 = IMP.atom.Selection(root, resolution=0, residue_index=432) self.assertEqual( set(sel0.get_selected_particles()), set(mh.get_children()[0].get_children()[0].get_children())) # ... and when it's not rep.add_representation(res1, IMP.atom.BALLS, 1) rep.add_representation(res10, IMP.atom.BALLS, 10) self.assertEqual(rep.get_representation(0), root) sel0 = IMP.atom.Selection(root, resolution=0, residue_index=432) self.assertEqual( set(sel0.get_selected_particles()), set(mh.get_children()[0].get_children()[0].get_children())) # checking other reps self.assertEqual(rep.get_representation(1), res1) self.assertEqual(rep.get_representation(10), res10) # should get nothing when requesting a type that isn't there #print(rep.get_representation(0,IMP.atom.DENSITIES)) self.assertTrue(not rep.get_representation(0, IMP.atom.DENSITIES)) self.assertTrue(not rep.get_representation(1, IMP.atom.DENSITIES)) self.assertTrue(not rep.get_representation(10, IMP.atom.DENSITIES)) # now test selection sel1 = IMP.atom.Selection(root, resolution=1, residue_index=432) self.assertEqual( IMP.atom.Fragment( sel1.get_selected_particles()[0]).get_residue_indexes(), [432]) sel10 = IMP.atom.Selection(root, resolution=10, residue_index=432) self.assertEqual( IMP.atom.Fragment( sel10.get_selected_particles()[0]).get_residue_indexes(), list(range(432, 442)))
def test_set_optimized(self): "Test weights_optimized" w = Weight.setup_particle(IMP.Particle(self.m)) w.add_weight() for n in range(19): w.set_weights_are_optimized(True) for k in range(n + 1): b = w.get_is_optimized(w.get_weight_key(k)) self.assertEqual(b, True) w.set_weights_are_optimized(False) for k in range(n + 1): b = w.get_is_optimized(w.get_weight_key(k)) self.assertEqual(b, False) w.add_weight()
def test_jeffreys_prior(self): m = IMP.Model() sigma = IMP.isd.Scale.setup_particle(IMP.Particle(m)) sigma.set_scale(1.) r = IMP.pmi.restraints.parameters.JeffreysPrior(sigma) self.assertAlmostEqual(float(r.get_output()["_TotalScore"]), 0., delta=1e-6) sigma.set_scale(2.) self.assertAlmostEqual(float(r.get_output()["_TotalScore"]), -math.log(.5), delta=1e-6)
def test_linear_velocity(self): """Test LinearVelocity decorator""" m = IMP.Model() p = IMP.Particle(m) self.assertFalse(IMP.atom.LinearVelocity.get_is_setup(p)) d = IMP.atom.LinearVelocity.setup_particle(p) self.assertTrue(IMP.atom.LinearVelocity.get_is_setup(p)) v = d.get_velocity() self.assertLess( IMP.algebra.get_distance(v, IMP.algebra.Vector3D(0, 0, 0)), 1e-4) d.set_velocity(IMP.algebra.Vector3D(1, 2, 3)) v = d.get_velocity() self.assertLess( IMP.algebra.get_distance(v, IMP.algebra.Vector3D(1, 2, 3)), 1e-4)