def test_mc_flexible_beads_disable(self): """Test disable of flexible beads""" mdl = IMP.Model() s,mol = self.init_topology1(mdl) dof = IMP.pmi.dof.DegreesOfFreedom(mdl) fb_movers = dof.create_flexible_beads(mol.get_non_atomic_residues(),max_trans=1.0) self.assertEqual(len(fb_movers),3) mvs = dof.get_movers() self.assertEqual(len(mvs),3) particles=IMP.atom.Selection(s.hier,molecule="Prot1").get_selected_particles() xyzs,rbs=dof.disable_movers(particles) self.assertEqual(len(xyzs),3) self.assertEqual(len(rbs),0) mvs = dof.get_movers() self.assertEqual(len(mvs),0) dof.enable_all_movers() particles=IMP.atom.Selection(s.hier,molecule="Prot1").get_selected_particles() xyzs,rbs=dof.disable_movers(particles,mover_types=[IMP.core.RigidBodyMover]) self.assertEqual(len(xyzs),0) self.assertEqual(len(rbs),0) mvs = dof.get_movers() self.assertEqual(len(mvs),3) dof.enable_all_movers() particles=IMP.atom.Selection(s.hier,molecule="Prot1").get_selected_particles() xyzs,rbs=dof.disable_movers(particles,mover_types=[IMP.core.BallMover]) self.assertEqual(len(xyzs),3) self.assertEqual(len(rbs),0) mvs = dof.get_movers() self.assertEqual(len(mvs),0)
def test_symmetry_disables_movers(self): """Test the creation of symmetries""" import math mdl = IMP.Model() s, m1, m2, m3 = self.init_topology_clones(mdl) dof = IMP.pmi.dof.DegreesOfFreedom(mdl) rb1_movers, rb1 = dof.create_rigid_body( m1, nonrigid_parts=m1.get_non_atomic_residues(), name="test RB 1") rb2_movers, rb2 = dof.create_rigid_body( m2, nonrigid_parts=m2.get_non_atomic_residues(), name="test RB 2") rb3_movers, rb3 = dof.create_rigid_body( m3, nonrigid_parts=m3.get_non_atomic_residues(), name="test RB 3") mvs = dof.get_movers() self.assertEqual(len(mvs), 12) rotational_axis = IMP.algebra.Vector3D(0, 0, 1.0) rotation_angle_12 = 2.0 * math.pi / float(3) * float(1) rotation3D_12 = IMP.algebra.get_rotation_about_axis( rotational_axis, rotation_angle_12) dof.constrain_symmetry([m1], [m2], rotation3D_12, resolution='all') rotation_angle_13 = 2.0 * math.pi / float(3) * float(2) rotation3D_13 = IMP.algebra.get_rotation_about_axis( rotational_axis, rotation_angle_13) dof.constrain_symmetry([m1], [m3], rotation3D_13, resolution='all') mvs = dof.get_movers() mdl.update() self.assertEqual(len(mvs), 4)
def test_mc_rigid_body(self): """Test creation of rigid body and nonrigid members""" mdl = IMP.Model() s, molecule = self.init_topology1(mdl) dof = IMP.pmi.dof.DegreesOfFreedom(mdl) # Test do-nothing if no rigid parts were passed self.assertEqual(dof.create_rigid_body([], [], name='test RB'), []) rb_movers, rb = dof.create_rigid_body( molecule, nonrigid_parts=molecule.get_non_atomic_residues(), name="test RB") self.assertEqual(rb.get_name(), "test RB") self.assertEqual(rb_movers[0].get_name(), "test RB") mvs = dof.get_movers() self.assertEqual(len(rb_movers), 4) all_members = rb.get_member_indexes() rigid_members = rb.get_rigid_members() num_nonrigid = len(all_members) - len(rigid_members) self.assertEqual(num_nonrigid, 3) # r0 r1 r10 self.assertEqual(len(rigid_members), 57 + 7 + 2) rex = IMP.pmi.macros.ReplicaExchange0( mdl, root_hier=s.get_hierarchy(), monte_carlo_sample_objects=dof.get_movers(), number_of_frames=2, test_mode=True, replica_exchange_object=rem) rex.execute_macro()
def test_mc_rigid_body(self): """Test creation of rigid body and nonrigid members""" mdl = IMP.Model() s,molecule = self.init_topology1(mdl) dof = IMP.pmi.dof.DegreesOfFreedom(mdl) # Test do-nothing if no rigid parts were passed self.assertEqual(dof.create_rigid_body([], [], name='test RB'), []) rb_movers,rb = dof.create_rigid_body(molecule, nonrigid_parts = molecule.get_non_atomic_residues(), name="test RB") self.assertEqual(rb.get_name(), "test RB") self.assertEqual(rb_movers[0].get_name(), "test RB") mvs = dof.get_movers() self.assertEqual(len(rb_movers),4) all_members = rb.get_member_indexes() rigid_members = rb.get_rigid_members() num_nonrigid = len(all_members)-len(rigid_members) self.assertEqual(num_nonrigid,3) # r0 r1 r10 self.assertEqual(len(rigid_members),57 + 7 + 2) rex = IMP.pmi.macros.ReplicaExchange0(mdl, root_hier=s.get_hierarchy(), monte_carlo_sample_objects = dof.get_movers(), number_of_frames=2, test_mode=True, replica_exchange_object=rem) rex.execute_macro()
def init_topology(self,mdl): s = IMP.pmi.topology.System(mdl) st1 = s.create_state() seqs = IMP.pmi.topology.Sequences(self.get_input_file_name('seqs.fasta'), name_map={'Protein_1':'Prot1', 'Protein_2':'Prot2', 'Protein_3':'Prot3'}) m1 = st1.create_molecule("Prot1",chain_id='A',sequence=seqs["Prot1"]) m2 = st1.create_molecule("Prot2",chain_id='B',sequence=seqs["Prot2"]) a1 = m1.add_structure(self.get_input_file_name('prot.pdb'), chain_id='A',res_range=(55,64),offset=-54) a2 = m2.add_structure(self.get_input_file_name('prot.pdb'), chain_id='B',res_range=(180,192),offset=-179) m1.add_representation(a1,resolutions=[0,1]) m1.add_representation(m1[:]-a1,resolutions=[1]) m2.add_representation(a2,resolutions=[0,1]) hier = s.build() dof = IMP.pmi.dof.DegreesOfFreedom(mdl) dof.create_rigid_body(m1,nonrigid_parts = m1.get_non_atomic_residues(), max_trans=0.1) dof.create_rigid_body(m2,nonrigid_parts = m2.get_non_atomic_residues(), max_trans=0.1) dr = IMP.pmi.restraints.basic.DistanceRestraint(root_hier = hier, tuple_selection1=(1,1,"Prot1",0), tuple_selection2=(1,1,"Prot2",0), distancemin=5, distancemax=15) dr.add_to_model() with IMP.allow_deprecated(): rex = IMP.pmi.macros.ReplicaExchange0(mdl, root_hier=hier, output_objects=[dr], monte_carlo_sample_objects=dof.get_movers(), number_of_frames=10, number_of_best_scoring_models=0, global_output_directory = \ self.get_input_file_name("pmi2_sample_0/")) rex.execute_macro() trans = IMP.algebra.Transformation3D(IMP.algebra.Vector3D(10,10,10)) for rb in dof.rigid_bodies: IMP.core.transform(rb,trans) with IMP.allow_deprecated(): rex2 = IMP.pmi.macros.ReplicaExchange0(mdl, root_hier=hier, output_objects=[dr], monte_carlo_sample_objects=dof.get_movers(), number_of_frames=10, number_of_best_scoring_models=0, global_output_directory = \ self.get_input_file_name("pmi2_sample_1/"), replica_exchange_object = rex.get_replica_exchange_object()) rex2.execute_macro()
def init_topology(self,mdl): s = IMP.pmi.topology.System(mdl) st1 = s.create_state() seqs = IMP.pmi.topology.Sequences(self.get_input_file_name('seqs.fasta'), name_map={'Protein_1':'Prot1', 'Protein_2':'Prot2', 'Protein_3':'Prot3'}) m1 = st1.create_molecule("Prot1",chain_id='A',sequence=seqs["Prot1"]) m2 = st1.create_molecule("Prot2",chain_id='B',sequence=seqs["Prot2"]) a1 = m1.add_structure(self.get_input_file_name('prot.pdb'), chain_id='A',res_range=(55,64),offset=-54) a2 = m2.add_structure(self.get_input_file_name('prot.pdb'), chain_id='B',res_range=(180,192),offset=-179) m1.add_representation(a1,resolutions=[0,1]) m1.add_representation(m1[:]-a1,resolutions=[1]) m2.add_representation(a2,resolutions=[0,1]) hier = s.build() dof = IMP.pmi.dof.DegreesOfFreedom(mdl) dof.create_rigid_body(m1,nonrigid_parts = m1.get_non_atomic_residues(), max_trans=0.1) dof.create_rigid_body(m2,nonrigid_parts = m2.get_non_atomic_residues(), max_trans=0.1) dr = IMP.pmi.restraints.basic.DistanceRestraint(root_hier = hier, tuple_selection1=(1,1,"Prot1",0), tuple_selection2=(1,1,"Prot2",0), distancemin=5, distancemax=15) dr.add_to_model() rex = IMP.pmi.macros.ReplicaExchange0(mdl, root_hier=hier, output_objects=[dr], monte_carlo_sample_objects=dof.get_movers(), number_of_frames=10, number_of_best_scoring_models=0, global_output_directory = \ self.get_input_file_name("pmi2_sample_0/")) rex.execute_macro() trans = IMP.algebra.Transformation3D(IMP.algebra.Vector3D(10,10,10)) for rb in dof.rigid_bodies: IMP.core.transform(rb,trans) rex2 = IMP.pmi.macros.ReplicaExchange0(mdl, root_hier=hier, output_objects=[dr], monte_carlo_sample_objects=dof.get_movers(), number_of_frames=10, number_of_best_scoring_models=0, global_output_directory = \ self.get_input_file_name("pmi2_sample_1/"), replica_exchange_object = rex.get_replica_exchange_object()) rex2.execute_macro()
def test_rex_multistate(self): """Test you can do multi-state replica exchange""" mdl = IMP.Model() s = IMP.pmi.topology.System(mdl) st1 = s.create_state() m1 = st1.create_molecule("Prot1") atomic_res = m1.add_structure(self.get_input_file_name('prot.pdb'), chain_id='A',res_range=(55,63),offset=-54, soft_check=True) m1.add_representation(m1,resolutions=[1]) st2 = s.create_state() m2 = st2.create_molecule("Prot1") atomic_res2 = m2.add_structure(self.get_input_file_name('prot.pdb'), chain_id='A',res_range=(55,63),offset=-54, soft_check=True) m2.add_representation(m2,resolutions=[1]) hier = s.build() self.assertEqual(len(IMP.atom.get_by_type(hier,IMP.atom.STATE_TYPE)),2) dof = IMP.pmi.dof.DegreesOfFreedom(mdl) dof.create_rigid_body(m1,nonrigid_parts = atomic_res) dof.create_rigid_body(m2,nonrigid_parts = atomic_res2) rex = IMP.pmi.macros.ReplicaExchange0(mdl, root_hier=hier, monte_carlo_sample_objects=dof.get_movers(), number_of_frames=2, test_mode=True, replica_exchange_object=rem) rex.execute_macro()
def test_gaussian_rb(self): mdl = IMP.Model() s, m1, m2, m3 = self.init_topology_densities(mdl) densities = [r.get_hierarchy() for r in m3.get_non_atomic_residues()] gem_xtal = IMP.pmi.restraints.em.GaussianEMRestraint( densities, self.get_input_file_name('prot_gmm.txt'), target_is_rigid_body=True) gem_xtal.get_restraint_set().set_was_used(True) em_rb = gem_xtal.get_rigid_body() em_rb.set_coordinates_are_optimized(False) dof = IMP.pmi.dof.DegreesOfFreedom(mdl) movers, rb = dof.create_rigid_body(em_rb) # Check assigning of names to existing rigid bodies self.assertEqual(movers[0].get_name(), 'created rigid body') movers, rb = dof.create_rigid_body(em_rb, name='foo') self.assertEqual(movers[0].get_name(), 'foo') self.assertTrue(em_rb in dof.get_rigid_bodies()) self.assertEqual(len(dof.get_rigid_bodies()), 2) self.assertTrue(em_rb.get_coordinates_are_optimized()) self.assertEqual(len(dof.get_movers()), 2)
def test_mc_rigid_body_disable(self): """Test creation of rigid body and nonrigid members""" mdl = IMP.Model() s, molecule = self.init_topology1(mdl) dof = IMP.pmi.dof.DegreesOfFreedom(mdl) rb_movers, rb = dof.create_rigid_body( molecule, nonrigid_parts=molecule.get_non_atomic_residues(), name="test RB") mvs = dof.get_movers() self.assertEqual(len(mvs), 4) #fixing all particles particles = IMP.atom.Selection( s.hier, molecule="Prot1").get_selected_particles() xyzs, rbs = dof.disable_movers(particles) self.assertEqual(len(xyzs), 3) self.assertEqual(len(rbs), 1) mvs = dof.get_movers() self.assertEqual(len(mvs), 0) #enabling everything dof.enable_all_movers() mvs = dof.get_movers() self.assertEqual(len(mvs), 4) #IMP.atom.show_molecular_hierarchy(s.hier) #fixing the rb particles = IMP.atom.Selection( s.hier, molecule="Prot1", residue_indexes=[1]).get_selected_particles() xyzs, rbs = dof.disable_movers(particles) self.assertEqual(len(xyzs), 0) self.assertEqual(len(rbs), 1) mvs = dof.get_movers() self.assertEqual(len(mvs), 3) #fixing one bead and the corresponding rb dof.enable_all_movers() particles = IMP.atom.Selection( s.hier, molecule="Prot1", residue_indexes=[10]).get_selected_particles() xyzs, rbs = dof.disable_movers(particles) self.assertEqual(len(xyzs), 1) self.assertEqual(len(rbs), 1) mvs = dof.get_movers() self.assertEqual(len(mvs), 2)
def test_mc_rigid_body_disable(self): """Test creation of rigid body and nonrigid members""" mdl = IMP.Model() s,molecule = self.init_topology1(mdl) dof = IMP.pmi.dof.DegreesOfFreedom(mdl) rb_movers,rb = dof.create_rigid_body(molecule, nonrigid_parts = molecule.get_non_atomic_residues(), name="test RB") mvs = dof.get_movers() self.assertEqual(len(mvs),4) #fixing all particles particles=IMP.atom.Selection(s.hier,molecule="Prot1").get_selected_particles() xyzs,rbs=dof.disable_movers(particles) self.assertEqual(len(xyzs),3) self.assertEqual(len(rbs),1) mvs = dof.get_movers() self.assertEqual(len(mvs),0) #enabling everything dof.enable_all_movers() mvs = dof.get_movers() self.assertEqual(len(mvs),4) #IMP.atom.show_molecular_hierarchy(s.hier) #fixing the rb particles=IMP.atom.Selection(s.hier,molecule="Prot1",residue_indexes=[1]).get_selected_particles() xyzs,rbs=dof.disable_movers(particles) self.assertEqual(len(xyzs),0) self.assertEqual(len(rbs),1) mvs = dof.get_movers() self.assertEqual(len(mvs),3) #fixing one bead and the corresponding rb dof.enable_all_movers() particles=IMP.atom.Selection(s.hier,molecule="Prot1",residue_indexes=[10]).get_selected_particles() xyzs,rbs=dof.disable_movers(particles) self.assertEqual(len(xyzs),1) self.assertEqual(len(rbs),1) mvs = dof.get_movers() self.assertEqual(len(mvs),2)
def test_mc_rigid_body_helix(self): """Test creation of rigid body and nonrigid members""" mdl = IMP.Model() s,molecule = self.init_topology_helix(mdl) dof = IMP.pmi.dof.DegreesOfFreedom(mdl) rb_movers,rb = dof.create_rigid_body(molecule, nonrigid_parts = molecule.get_non_atomic_residues(), name="test RB") mvs = dof.get_movers() all_members = rb.get_member_indexes() rigid_members = rb.get_rigid_members() num_nonrigid = len(all_members)-len(rigid_members) rex = IMP.pmi.macros.ReplicaExchange0(mdl, root_hier=s.get_hierarchy(), monte_carlo_sample_objects = dof.get_movers(), number_of_frames=1, test_mode=True, replica_exchange_object=rem) rex.execute_macro()
def test_symmetry_disables_movers(self): """Test the creation of symmetries""" import math mdl = IMP.Model() s,m1,m2,m3 = self.init_topology_clones(mdl) dof = IMP.pmi.dof.DegreesOfFreedom(mdl) rb1_movers,rb1 = dof.create_rigid_body(m1, nonrigid_parts = m1.get_non_atomic_residues(), name="test RB 1") rb2_movers,rb2 = dof.create_rigid_body(m2, nonrigid_parts = m2.get_non_atomic_residues(), name="test RB 2") rb3_movers,rb3 = dof.create_rigid_body(m3, nonrigid_parts = m3.get_non_atomic_residues(), name="test RB 3") mvs = dof.get_movers() self.assertEqual(len(mvs),12) rotational_axis=IMP.algebra.Vector3D(0, 0, 1.0) rotation_angle_12 = 2.0 * math.pi / float(3) * float(1) rotation3D_12 = IMP.algebra.get_rotation_about_axis(rotational_axis, rotation_angle_12) dof.constrain_symmetry( [m1], [m2], rotation3D_12, resolution='all') rotation_angle_13 = 2.0 * math.pi / float(3) * float(2) rotation3D_13 = IMP.algebra.get_rotation_about_axis(rotational_axis, rotation_angle_13) dof.constrain_symmetry( [m1], [m3], rotation3D_13, resolution='all') mvs = dof.get_movers() mdl.update() self.assertEqual(len(mvs),4)
def test_mc_flexible_beads_disable(self): """Test disable of flexible beads""" mdl = IMP.Model() s, mol = self.init_topology1(mdl) dof = IMP.pmi.dof.DegreesOfFreedom(mdl) fb_movers = dof.create_flexible_beads(mol.get_non_atomic_residues(), max_trans=1.0) self.assertEqual(len(fb_movers), 3) mvs = dof.get_movers() self.assertEqual(len(mvs), 3) particles = IMP.atom.Selection( s.hier, molecule="Prot1").get_selected_particles() xyzs, rbs = dof.disable_movers(particles) self.assertEqual(len(xyzs), 3) self.assertEqual(len(rbs), 0) mvs = dof.get_movers() self.assertEqual(len(mvs), 0) dof.enable_all_movers() particles = IMP.atom.Selection( s.hier, molecule="Prot1").get_selected_particles() xyzs, rbs = dof.disable_movers(particles, mover_types=[IMP.core.RigidBodyMover]) self.assertEqual(len(xyzs), 0) self.assertEqual(len(rbs), 0) mvs = dof.get_movers() self.assertEqual(len(mvs), 3) dof.enable_all_movers() particles = IMP.atom.Selection( s.hier, molecule="Prot1").get_selected_particles() xyzs, rbs = dof.disable_movers(particles, mover_types=[IMP.core.BallMover]) self.assertEqual(len(xyzs), 3) self.assertEqual(len(rbs), 0) mvs = dof.get_movers() self.assertEqual(len(mvs), 0)
def test_mc_flexible_beads(self): """Test setup of flexible beads""" mdl = IMP.Model() s,mol = self.init_topology1(mdl) dof = IMP.pmi.dof.DegreesOfFreedom(mdl) fb_movers = dof.create_flexible_beads(mol.get_non_atomic_residues(),max_trans=1.0) self.assertEqual(len(fb_movers),3) rex = IMP.pmi.macros.ReplicaExchange0(mdl, root_hier=s.get_hierarchy(), monte_carlo_sample_objects = dof.get_movers(), number_of_frames=2, test_mode=True, replica_exchange_object=rem) rex.execute_macro()
def test_mc_rigid_body_helix(self): """Test creation of rigid body and nonrigid members""" mdl = IMP.Model() s, molecule = self.init_topology_helix(mdl) dof = IMP.pmi.dof.DegreesOfFreedom(mdl) rb_movers, rb = dof.create_rigid_body( molecule, nonrigid_parts=molecule.get_non_atomic_residues(), name="test RB") mvs = dof.get_movers() all_members = rb.get_member_indexes() rigid_members = rb.get_rigid_members() num_nonrigid = len(all_members) - len(rigid_members) rex = IMP.pmi.macros.ReplicaExchange0( mdl, root_hier=s.get_hierarchy(), monte_carlo_sample_objects=dof.get_movers(), number_of_frames=1, test_mode=True, replica_exchange_object=rem) rex.execute_macro()
def test_mc_super_rigid_body(self): mdl = IMP.Model() s,mols = self.init_topology3(mdl) dof = IMP.pmi.dof.DegreesOfFreedom(mdl) rb1_mov,rb1 = dof.create_rigid_body(mols[0], nonrigid_parts = mols[0].get_non_atomic_residues()) rb2_mov,rb2 = dof.create_rigid_body(mols[1], nonrigid_parts = mols[1].get_non_atomic_residues()) rb3_mov,rb3 = dof.create_rigid_body(mols[2], nonrigid_parts = mols[2].get_non_atomic_residues()) srb_mover = dof.create_super_rigid_body(mols,chain_min_length=2, chain_max_length=2) ### rbX = dof.create_rigid_body([mols[0],mols[1]]) should fail # rb1:4, rb2:1, rb3:4, srbs:2 mvs = dof.get_movers() self.assertEqual(len(mvs),11)
def test_mc_flexible_beads(self): """Test setup of flexible beads""" mdl = IMP.Model() s, mol = self.init_topology1(mdl) dof = IMP.pmi.dof.DegreesOfFreedom(mdl) fb_movers = dof.create_flexible_beads(mol.get_non_atomic_residues(), max_trans=1.0) self.assertEqual(len(fb_movers), 3) rex = IMP.pmi.macros.ReplicaExchange0( mdl, root_hier=s.get_hierarchy(), monte_carlo_sample_objects=dof.get_movers(), number_of_frames=2, test_mode=True, replica_exchange_object=rem) rex.execute_macro()
def test_mc_super_rigid_body(self): mdl = IMP.Model() s, mols = self.init_topology3(mdl) dof = IMP.pmi.dof.DegreesOfFreedom(mdl) rb1_mov, rb1 = dof.create_rigid_body( mols[0], nonrigid_parts=mols[0].get_non_atomic_residues()) rb2_mov, rb2 = dof.create_rigid_body( mols[1], nonrigid_parts=mols[1].get_non_atomic_residues()) rb3_mov, rb3 = dof.create_rigid_body( mols[2], nonrigid_parts=mols[2].get_non_atomic_residues()) srb_mover = dof.create_super_rigid_body(mols, chain_min_length=2, chain_max_length=2) ### rbX = dof.create_rigid_body([mols[0],mols[1]]) should fail # rb1:4, rb2:1, rb3:4, srbs:2 mvs = dof.get_movers() self.assertEqual(len(mvs), 11)
def test_pdb_from_rex(self): """Test PDB writing in PMI2 from replica exchange""" mdl = IMP.Model() pdb_file = self.get_input_file_name("mini.pdb") fasta_file = self.get_input_file_name("mini.fasta") seqs = IMP.pmi.topology.Sequences(fasta_file) s = IMP.pmi.topology.System(mdl) st = s.create_state() molA = st.create_molecule("P1",seqs[0],chain_id='A') aresA = molA.add_structure(pdb_file,chain_id='A',soft_check=True) molA.add_representation(aresA,[1]) molA.add_representation(molA[:]-aresA,20) molB = st.create_molecule("P2",seqs[1],chain_id='B') aresB = molB.add_structure(pdb_file,chain_id='B',soft_check=True) molB.add_representation(aresB,[10]) molB.add_representation(molB[:]-aresB,20) molC = molB.create_copy(chain_id='C') aresC = molC.add_structure(pdb_file,chain_id='B',soft_check=True) molC.add_representation(aresC,[1,10]) molC.add_representation(molC[:]-aresC,2) root_hier = s.build() dof = IMP.pmi.dof.DegreesOfFreedom(mdl) rb_movers = dof.create_rigid_body([molA,molB,molC], name="test RB") rex = IMP.pmi.macros.ReplicaExchange0(mdl, root_hier=root_hier, monte_carlo_sample_objects = dof.get_movers(), number_of_frames=3, monte_carlo_steps=10, number_of_best_scoring_models=3, global_output_directory='pdb_test/', replica_exchange_object = rem) rex.execute_macro() for i in range(3): self.assertTrue(os.path.isfile('pdb_test/pdbs/model.%i.pdb'%i)) mhtest = IMP.atom.read_pdb('pdb_test/pdbs/model.0.pdb',mdl) self.assertEqual(len(IMP.core.get_leaves(mhtest)),17) shutil.rmtree("pdb_test/")
def test_gaussian_rb(self): mdl = IMP.Model() m1, m2, m3 = self.init_topology_densities(mdl) densities = [r.get_hierarchy() for r in m3.get_non_atomic_residues()] gem_xtal = IMP.pmi.restraints.em.GaussianEMRestraint(densities, self.get_input_file_name('prot_gmm.txt'), target_is_rigid_body=True) em_rb = gem_xtal.get_rigid_body() em_rb.set_coordinates_are_optimized(False) dof = IMP.pmi.dof.DegreesOfFreedom(mdl) dof.create_rigid_body(em_rb) self.assertTrue(em_rb in dof.get_rigid_bodies()) self.assertEqual(len(dof.get_rigid_bodies()), 1) self.assertTrue(em_rb.get_coordinates_are_optimized()) self.assertEqual(len(dof.get_movers()), 1)
def test_pdb_from_rex(self): """Test PDB writing in PMI2 from replica exchange""" mdl = IMP.Model() pdb_file = self.get_input_file_name("mini.pdb") fasta_file = self.get_input_file_name("mini.fasta") seqs = IMP.pmi.topology.Sequences(fasta_file) s = IMP.pmi.topology.System(mdl) st = s.create_state() molA = st.create_molecule("P1", seqs[0], chain_id='A') aresA = molA.add_structure(pdb_file, chain_id='A', soft_check=True) molA.add_representation(aresA, [1]) molA.add_representation(molA[:] - aresA, 20) molB = st.create_molecule("P2", seqs[1], chain_id='B') aresB = molB.add_structure(pdb_file, chain_id='B', soft_check=True) molB.add_representation(aresB, [10]) molB.add_representation(molB[:] - aresB, 20) molC = molB.create_copy(chain_id='C') aresC = molC.add_structure(pdb_file, chain_id='B', soft_check=True) molC.add_representation(aresC, [1, 10]) molC.add_representation(molC[:] - aresC, 2) root_hier = s.build() dof = IMP.pmi.dof.DegreesOfFreedom(mdl) rb_movers = dof.create_rigid_body([molA, molB, molC], name="test RB") rex = IMP.pmi.macros.ReplicaExchange0( mdl, root_hier=root_hier, monte_carlo_sample_objects=dof.get_movers(), number_of_frames=3, monte_carlo_steps=10, number_of_best_scoring_models=3, global_output_directory='pdb_test/', replica_exchange_object=rem) rex.execute_macro() for i in range(3): self.assertTrue(os.path.isfile('pdb_test/pdbs/model.%i.pdb' % i)) mhtest = IMP.atom.read_pdb('pdb_test/pdbs/model.0.pdb', mdl) self.assertEqual(len(IMP.core.get_leaves(mhtest)), 17) shutil.rmtree("pdb_test/")
def test_gaussian_rb(self): mdl = IMP.Model() m1, m2, m3 = self.init_topology_densities(mdl) densities = [r.get_hierarchy() for r in m3.get_non_atomic_residues()] gem_xtal = IMP.pmi.restraints.em.GaussianEMRestraint( densities, self.get_input_file_name('prot_gmm.txt'), target_is_rigid_body=True) em_rb = gem_xtal.get_rigid_body() em_rb.set_coordinates_are_optimized(False) dof = IMP.pmi.dof.DegreesOfFreedom(mdl) dof.create_rigid_body(em_rb) self.assertTrue(em_rb in dof.get_rigid_bodies()) self.assertEqual(len(dof.get_rigid_bodies()), 1) self.assertTrue(em_rb.get_coordinates_are_optimized()) self.assertEqual(len(dof.get_movers()), 1)
def test_rex_multistate(self): """Test you can do multi-state replica exchange""" mdl = IMP.Model() s = IMP.pmi.topology.System(mdl) st1 = s.create_state() m1 = st1.create_molecule("Prot1") atomic_res = m1.add_structure(self.get_input_file_name('prot.pdb'), chain_id='A', res_range=(55, 63), offset=-54, soft_check=True) m1.add_representation(m1, resolutions=[1]) st2 = s.create_state() m2 = st2.create_molecule("Prot1") atomic_res2 = m2.add_structure(self.get_input_file_name('prot.pdb'), chain_id='A', res_range=(55, 63), offset=-54, soft_check=True) m2.add_representation(m2, resolutions=[1]) hier = s.build() self.assertEqual(len(IMP.atom.get_by_type(hier, IMP.atom.STATE_TYPE)), 2) dof = IMP.pmi.dof.DegreesOfFreedom(mdl) dof.create_rigid_body(m1, nonrigid_parts=atomic_res) dof.create_rigid_body(m2, nonrigid_parts=atomic_res2) rex = IMP.pmi.macros.ReplicaExchange0( mdl, root_hier=hier, monte_carlo_sample_objects=dof.get_movers(), number_of_frames=2, test_mode=True, replica_exchange_object=rem) rex.execute_macro()
def test_gaussian_rb(self): mdl = IMP.Model() s, m1, m2, m3 = self.init_topology_densities(mdl) densities = [r.get_hierarchy() for r in m3.get_non_atomic_residues()] gem_xtal = IMP.pmi.restraints.em.GaussianEMRestraint(densities, self.get_input_file_name('prot_gmm.txt'), target_is_rigid_body=True) gem_xtal.get_restraint_set().set_was_used(True) em_rb = gem_xtal.get_rigid_body() em_rb.set_coordinates_are_optimized(False) dof = IMP.pmi.dof.DegreesOfFreedom(mdl) movers, rb = dof.create_rigid_body(em_rb) # Check assigning of names to existing rigid bodies self.assertEqual(movers[0].get_name(), 'created rigid body') movers, rb = dof.create_rigid_body(em_rb, name='foo') self.assertEqual(movers[0].get_name(), 'foo') self.assertTrue(em_rb in dof.get_rigid_bodies()) self.assertEqual(len(dof.get_rigid_bodies()), 2) self.assertTrue(em_rb.get_coordinates_are_optimized()) self.assertEqual(len(dof.get_movers()), 2)
#psi = xlr.psi_dictionary["PSI"][0] #psi.set_scale(0.04) sf = IMP.core.RestraintsScoringFunction(IMP.pmi.tools.get_restraint_set(mdl)) print(sf.evaluate(False)) dof.get_nuisances_from_restraint( xlr) # needed to sample the nuisance particles (noise params) ####################### SAMPLING ##################### # First shuffle the system if not s.dry_run: IMP.pmi.tools.shuffle_configuration(gdown1) dof.optimize_flexible_beads(100) print(dof.get_movers()) print(len(dof.get_movers())) print(gdown1) # Run replica exchange Monte Carlo sampling rex = IMP.pmi.macros.ReplicaExchange0( mdl, root_hier=root_hier, # pass the root hierarchy crosslink_restraints=display_restraints, # will display like XLs monte_carlo_temperature=1.0, replica_exchange_minimum_temperature=1.0, replica_exchange_maximum_temperature=2.5, num_sample_rounds=1, number_of_best_scoring_models=5, monte_carlo_sample_objects=dof.get_movers(), # pass MC movers global_output_directory='gdownrb_%d' % taskid, output_objects=output_objects,
log_objects.append(rbr) rar = IMP.pmi.restraints.stereochemistry.ResidueAngleRestraint(objects=l) rar.add_to_model() listofexcludedpairs += rar.get_excluded_pairs() log_objects.append(rar) # add excluded volume ev = IMP.pmi.restraints.stereochemistry.ExcludedVolumeSphere( included_objects=root_hier, resolution=10.0) ev.add_excluded_particle_pairs(listofexcludedpairs) ev.add_to_model() log_objects.append(ev) mc = samplers.MonteCarlo(m, dof.get_movers(), 1.0) log_objects.append(mc) start_time = process_time() # In debug mode things are way too slow to actually run MC if IMP.get_check_level() < IMP.USAGE_AND_INTERNAL: o = output.Output() rmf = o.init_rmf("conformations.rmf3", [root_hier]) o.init_stat2("modeling.stat", log_objects) o.write_rmf("conformations.rmf3") o.init_pdb("conformations.pdb", root_hier) for i in range(0, 10): # print("Running job, frame number ", i) mc.optimize(10)
def test_mc_super_rigid_body_disable(self): """test disable super rigid bodies, floppy bodies and rigid bodies""" mdl = IMP.Model() s, mols = self.init_topology3(mdl) dof = IMP.pmi.dof.DegreesOfFreedom(mdl) rb1_mov, rb1 = dof.create_rigid_body( mols[0], nonrigid_parts=mols[0].get_non_atomic_residues()) rb2_mov, rb2 = dof.create_rigid_body( mols[1], nonrigid_parts=mols[1].get_non_atomic_residues()) rb3_mov, rb3 = dof.create_rigid_body( mols[2], nonrigid_parts=mols[2].get_non_atomic_residues()) srb_mover = dof.create_super_rigid_body(mols, chain_min_length=2, chain_max_length=2) ### rbX = dof.create_rigid_body([mols[0],mols[1]]) should fail # rb1:4, rb2:1, rb3:4, srbs:2 mvs = dof.get_movers() self.assertEqual(len(mvs), 11) #fixing all particles particles = IMP.atom.Selection(s.hier).get_selected_particles() xyzs, rbs = dof.disable_movers(particles) self.assertEqual(len(xyzs), 6) self.assertEqual(len(rbs), 3) mvs = dof.get_movers() self.assertEqual(len(mvs), 0) #enabling everything dof.enable_all_movers() mvs = dof.get_movers() self.assertEqual(len(mvs), 11) #fixing prot1 particles = IMP.atom.Selection( s.hier, molecule="Prot1").get_selected_particles() xyzs, rbs = dof.disable_movers(particles) self.assertEqual(len(xyzs), 3) self.assertEqual(len(rbs), 1) mvs = dof.get_movers() self.assertEqual(len(mvs), 6) #fixing prot1 rb dof.enable_all_movers() particles = IMP.atom.Selection( s.hier, molecule="Prot1").get_selected_particles() xyzs, rbs = dof.disable_movers(particles, mover_types=[IMP.core.RigidBodyMover]) self.assertEqual(len(xyzs), 0) self.assertEqual(len(rbs), 1) mvs = dof.get_movers() self.assertEqual(len(mvs), 10) #fixing prot1 fbs dof.enable_all_movers() particles = IMP.atom.Selection( s.hier, molecule="Prot1").get_selected_particles() xyzs, rbs = dof.disable_movers(particles, mover_types=[IMP.core.BallMover]) self.assertEqual(len(xyzs), 3) self.assertEqual(len(rbs), 0) mvs = dof.get_movers() self.assertEqual(len(mvs), 8) #removing super rigid body dof.enable_all_movers() particles = IMP.atom.Selection( s.hier, molecule="Prot1").get_selected_particles() xyzs, rbs = dof.disable_movers(particles, mover_types=[IMP.pmi.TransformMover]) self.assertEqual(len(xyzs), 0) self.assertEqual(len(rbs), 0) mvs = dof.get_movers() self.assertEqual(len(mvs), 10) #removing rbmv, ballmovers and super rigid movers involving prot1 dof.enable_all_movers() particles = IMP.atom.Selection( s.hier, molecule="Prot1").get_selected_particles() xyzs, rbs = dof.disable_movers(particles, mover_types=[ IMP.core.RigidBodyMover, IMP.core.BallMover, IMP.pmi.TransformMover ]) self.assertEqual(len(xyzs), 3) self.assertEqual(len(rbs), 1) mvs = dof.get_movers() self.assertEqual(len(mvs), 6) #removing rbmv, ballmovers and super rigid movers involving prot2 dof.enable_all_movers() particles = IMP.atom.Selection( s.hier, molecule="Prot2").get_selected_particles() xyzs, rbs = dof.disable_movers(particles, mover_types=[ IMP.core.RigidBodyMover, IMP.core.BallMover, IMP.pmi.TransformMover ]) self.assertEqual(len(xyzs), 0) self.assertEqual(len(rbs), 1) mvs = dof.get_movers() self.assertEqual(len(mvs), 8)
def test_macro_rmf_stat(self): """setting up the representation PMI 2.0 representation. Creates two particles and a harmonic distance restraint between them""" import shutil import itertools m = IMP.Model() s = IMP.pmi.topology.System(m) st1 = s.create_state() mol = st1.create_molecule("A", "GG", "A") mol.add_representation(resolutions=[1]) hier = s.build() dof = IMP.pmi.dof.DegreesOfFreedom(mol) dof.create_flexible_beads(mol, max_trans=3.0, resolution=1) ps = IMP.atom.get_leaves(hier) dr = IMP.pmi.restraints.basic.DistanceRestraint(root_hier=hier, tuple_selection1=(1, 1, "A"), tuple_selection2=(2, 2, "A"), distancemin=10, distancemax=10) dr.add_to_model() rex = IMP.pmi.macros.ReplicaExchange0( m, root_hier=hier, monte_carlo_sample_objects=dof.get_movers(), output_objects=None, rmf_output_objects=[dr], monte_carlo_temperature=1.0, replica_exchange_minimum_temperature=1.0, replica_exchange_maximum_temperature=2.5, number_of_best_scoring_models=10, monte_carlo_steps=10, number_of_frames=100, write_initial_rmf=True, initial_rmf_name_suffix="initial", stat_file_name_suffix="stat", best_pdb_name_suffix="model", do_clean_first=True, do_create_directories=True, global_output_directory="./test_replica_exchange_macro_output", rmf_dir="rmfs/", best_pdb_dir="pdbs/", replica_stat_file_suffix="stat_replica", em_object_for_rmf=None, replica_exchange_object=None) # check whether the directory is existing, in case remove it try: shutil.rmtree('./test_replica_exchange_macro_output') except OSError: pass rex.execute_macro() self.check_rmf_file('./test_replica_exchange_macro_output/rmfs/0.rmf3') # check that each replica index is below the total number of replicas my_index = rex.replica_exchange_object.get_my_index() nreplicas = rex.replica_exchange_object.get_number_of_replicas() temperatures = rex.replica_exchange_object.get_my_parameter("temp") self.assertLess(my_index, nreplicas) # check that each replica has a unique index tf = open( "./test_replica_exchange_macro_output/" + str(my_index) + ".test", "w") tf.write(str(my_index)) tf.close() # sleep to synchronize time.sleep(1) if my_index == 0: for k in range(nreplicas): self.assertTrue( os.path.isfile("./test_replica_exchange_macro_output/" + str(k) + ".test")) #extract the info form the stat files rex_out_files = glob.glob( "./test_replica_exchange_macro_output/stat_replica.*.out") temp_key = "ReplicaExchange_CurrentTemp" maxtf_key = "ReplicaExchange_MaxTempFrequency" mintf_key = "ReplicaExchange_MinTempFrequency" ssr_key = "ReplicaExchange_SwapSuccessRatio" score_key = "score" score_temp_dict = {} avtemps_replicas = [] for f in rex_out_files: o = IMP.pmi.output.ProcessOutput(f) d = o.get_fields( [temp_key, maxtf_key, mintf_key, ssr_key, score_key]) temps = [float(f) for f in d[temp_key]] scores = [float(f) for f in d[score_key]] avtemp = sum(temps) / len(temps) avtemps_replicas.append(avtemp) for n, t in enumerate(temps): s = scores[n] if t not in score_temp_dict: score_temp_dict[t] = [s] else: score_temp_dict[t].append(s) # test that the average temperature per replica are similar for c in itertools.combinations(avtemps_replicas, 2): self.assertAlmostEqual(c[0], c[1], delta=0.05) for t in score_temp_dict: avscore = sum(score_temp_dict[t]) / len(score_temp_dict[t]) #check that the score is the energy of an 1D harmonic oscillator self.assertAlmostEqual(avscore, t / 2, delta=0.1) rex_out_file = "./test_replica_exchange_macro_output/rmfs/" + str( my_index) + ".rmf3" dist_key = "DistanceRestraint_Score" mc_nframe_key = "MonteCarlo_Nframe" mc_temp_key = "MonteCarlo_Temperature" rex_temp_key = "ReplicaExchange_CurrentTemp" rex_max_temp_key = "ReplicaExchange_MaxTempFrequency" rex_min_temp_key = "ReplicaExchange_MinTempFrequency" rex_swap_key = "ReplicaExchange_SwapSuccessRatio" rex_score_key = "Total_Score" rmf_file_key = "rmf_file" rmf_file_index = "rmf_frame_index" o = IMP.pmi.output.ProcessOutput(rex_out_file) d = o.get_fields([ dist_key, mc_temp_key, mc_nframe_key, rex_temp_key, rex_max_temp_key, rex_min_temp_key, rex_swap_key, rex_score_key, rmf_file_key, rmf_file_index ]) nframes = len(d[mc_nframe_key]) self.assertNotEqual(float(d[mc_nframe_key][-1]), 0) self.assertEqual(list(map(float, d[mc_temp_key])), [1.0] * nframes) self.assertGreater(float(d[rex_min_temp_key][-1]), 0.0)
def test_atomic_xl(self): """ test PMI setup of atomic XL restraint """ # fake data tname = self.get_tmp_file_name("test.txt") with open(tname, "w") as fh: fh.write("prot1,res1,prot2,res2\nProt1,7,Prot1,39\n") cldbkc = IMP.pmi.io.crosslink.CrossLinkDataBaseKeywordsConverter() cldbkc.set_protein1_key("prot1") cldbkc.set_protein2_key("prot2") cldbkc.set_residue1_key("res1") cldbkc.set_residue2_key("res2") cldb = IMP.pmi.io.crosslink.CrossLinkDataBase(cldbkc) cldb.create_set_from_file(tname) self.assertEqual(cldb.get_number_of_xlid(), 1) # create two states, each with two copies of the protein mdl = IMP.Model() s = IMP.pmi.topology.System(mdl) seqs = IMP.pmi.topology.Sequences( self.get_input_file_name('multi_seq.fasta'), name_map={'Protein_1': 'Prot1'}) # build state 1 st1 = s.create_state() m1 = st1.create_molecule("Prot1", sequence=seqs["Prot1"], chain_id='A') m1_res = m1.add_structure(self.get_input_file_name('multi.pdb'), chain_id='A', offset=-54, model_num=0) m1.add_representation(m1_res, resolutions=[0]) m1a = m1.create_copy(chain_id='G') m1a_res = m1a.add_structure(self.get_input_file_name('multi.pdb'), chain_id='G', offset=-54) m1a.add_representation(m1a_res, resolutions=[0]) # build state 2 st2 = s.create_state() m2 = st2.create_molecule("Prot1", sequence=seqs["Prot1"], chain_id='A') m2_res = m2.add_structure(self.get_input_file_name('multi.pdb'), chain_id='A', offset=-54, model_num=1) m2.add_representation(m2_res, resolutions=[0]) m2a = m2.create_copy(chain_id='G') m2a_res = m2a.add_structure(self.get_input_file_name('multi.pdb'), chain_id='G', offset=-54) m2a.add_representation(m2a_res, resolutions=[0]) hier = s.build() #IMP.atom.show_molecular_hierarchy(hier) xl = IMP.pmi.restraints.crosslinking.AtomicCrossLinkMSRestraint( hier, cldb, nstates=[0, 1], atom_type="CA") # check that you created 8 restraints: # Each state: A1-B1, A1-B2, A2-B1, A2-B2 rs = xl.get_restraint_set() rs.set_was_used(True) self.assertEqual(rs.get_number_of_restraints(), 1) xlrs = IMP.isd.AtomicCrossLinkMSRestraint.get_from(rs.get_restraint(0)) self.assertIsInstance(xlrs, IMP.isd.AtomicCrossLinkMSRestraint) self.assertEqual(xlrs.get_number_of_contributions(), 8) dof = IMP.pmi.dof.DegreesOfFreedom(mdl) dof.get_nuisances_from_restraint(xl) self.assertEqual(len(dof.get_movers()), 2)
def test_atomic_xl(self): """ test PMI setup of atomic XL restraint """ # fake data tname = self.get_tmp_file_name("test.txt") with open(tname, "w") as fh: fh.write("prot1,res1,prot2,res2\nProt1,7,Prot1,39\n") cldbkc=IMP.pmi.io.crosslink.CrossLinkDataBaseKeywordsConverter() cldbkc.set_protein1_key("prot1") cldbkc.set_protein2_key("prot2") cldbkc.set_residue1_key("res1") cldbkc.set_residue2_key("res2") cldb = IMP.pmi.io.crosslink.CrossLinkDataBase(cldbkc) cldb.create_set_from_file(tname) self.assertEqual(cldb.get_number_of_xlid(),1) # create two states, each with two copies of the protein mdl = IMP.Model() s = IMP.pmi.topology.System(mdl) seqs = IMP.pmi.topology.Sequences(self.get_input_file_name('multi_seq.fasta'), name_map={'Protein_1':'Prot1'}) # build state 1 st1 = s.create_state() m1 = st1.create_molecule("Prot1",sequence=seqs["Prot1"],chain_id='A') m1_res = m1.add_structure(self.get_input_file_name('multi.pdb'), chain_id='A',offset=-54, model_num=0) m1.add_representation(m1_res,resolutions=[0]) m1a = m1.create_copy(chain_id='G') m1a_res = m1a.add_structure(self.get_input_file_name('multi.pdb'),chain_id='G',offset=-54) m1a.add_representation(m1a_res,resolutions=[0]) # build state 2 st2 = s.create_state() m2 = st2.create_molecule("Prot1",sequence=seqs["Prot1"],chain_id='A') m2_res = m2.add_structure(self.get_input_file_name('multi.pdb'), chain_id='A',offset=-54, model_num=1) m2.add_representation(m2_res,resolutions=[0]) m2a = m2.create_copy(chain_id='G') m2a_res = m2a.add_structure(self.get_input_file_name('multi.pdb'),chain_id='G',offset=-54) m2a.add_representation(m2a_res,resolutions=[0]) hier = s.build() #IMP.atom.show_molecular_hierarchy(hier) xl = IMP.pmi.restraints.crosslinking.AtomicCrossLinkMSRestraint(hier, cldb, nstates=[0,1], atom_type="CA") # check that you created 8 restraints: # Each state: A1-B1, A1-B2, A2-B1, A2-B2 rs=xl.get_restraint_set() self.assertEqual(rs.get_number_of_restraints(),1) xlrs=IMP.isd.AtomicCrossLinkMSRestraint.get_from(rs.get_restraint(0)) self.assertIsInstance(xlrs,IMP.isd.AtomicCrossLinkMSRestraint) self.assertEqual(xlrs.get_number_of_contributions(),8) dof = IMP.pmi.dof.DegreesOfFreedom(mdl) dof.get_nuisances_from_restraint(xl) self.assertEqual(len(dof.get_movers()),2)
psi.set_scale(0.05) xl.set_psi_is_sampled(True) xl.set_sigma_is_sampled(True) sample_objects.append(xl) output_objects.append(xl) ###################### SAMPLING ##################### # First shuffle the system IMP.pmi.tools.shuffle_configuration(hier, max_translation=100) # Quickly move all flexible beads into place dof.optimize_flexible_beads(10) # Run replica exchange Monte Carlo sampling rex = IMP.pmi.macros.ReplicaExchange0( mdl, root_hier=hier, # pass the root hierarchy crosslink_restraints=[xl], # will display like XLs monte_carlo_sample_objects=dof.get_movers() + xl.get_movers(), # pass MC movers global_output_directory='output/', output_objects=output_objects, monte_carlo_temperature=1.0, replica_exchange_minimum_temperature=1.0, replica_exchange_maximum_temperature=2.5, monte_carlo_steps=10, number_of_best_scoring_models= 0, # set >0 to store best PDB files (but this is slow to do online) number_of_frames=10000) # increase number of frames to get better results! rex.execute_macro()
def test_mc_super_rigid_body_disable(self): """test disable super rigid bodies, floppy bodies and rigid bodies""" mdl = IMP.Model() s,mols = self.init_topology3(mdl) dof = IMP.pmi.dof.DegreesOfFreedom(mdl) rb1_mov,rb1 = dof.create_rigid_body(mols[0], nonrigid_parts = mols[0].get_non_atomic_residues()) rb2_mov,rb2 = dof.create_rigid_body(mols[1], nonrigid_parts = mols[1].get_non_atomic_residues()) rb3_mov,rb3 = dof.create_rigid_body(mols[2], nonrigid_parts = mols[2].get_non_atomic_residues()) srb_mover = dof.create_super_rigid_body(mols,chain_min_length=2, chain_max_length=2) ### rbX = dof.create_rigid_body([mols[0],mols[1]]) should fail # rb1:4, rb2:1, rb3:4, srbs:2 mvs = dof.get_movers() self.assertEqual(len(mvs),11) #fixing all particles particles=IMP.atom.Selection(s.hier).get_selected_particles() xyzs,rbs=dof.disable_movers(particles) self.assertEqual(len(xyzs),6) self.assertEqual(len(rbs),3) mvs = dof.get_movers() self.assertEqual(len(mvs),0) #enabling everything dof.enable_all_movers() mvs = dof.get_movers() self.assertEqual(len(mvs),11) #fixing prot1 particles=IMP.atom.Selection(s.hier,molecule="Prot1").get_selected_particles() xyzs,rbs=dof.disable_movers(particles) self.assertEqual(len(xyzs),3) self.assertEqual(len(rbs),1) mvs = dof.get_movers() self.assertEqual(len(mvs),6) #fixing prot1 rb dof.enable_all_movers() particles=IMP.atom.Selection(s.hier,molecule="Prot1").get_selected_particles() xyzs,rbs=dof.disable_movers(particles,mover_types=[IMP.core.RigidBodyMover]) self.assertEqual(len(xyzs),0) self.assertEqual(len(rbs),1) mvs = dof.get_movers() self.assertEqual(len(mvs),10) #fixing prot1 fbs dof.enable_all_movers() particles=IMP.atom.Selection(s.hier,molecule="Prot1").get_selected_particles() xyzs,rbs=dof.disable_movers(particles,mover_types=[IMP.core.BallMover]) self.assertEqual(len(xyzs),3) self.assertEqual(len(rbs),0) mvs = dof.get_movers() self.assertEqual(len(mvs),8) #removing super rigid body dof.enable_all_movers() particles=IMP.atom.Selection(s.hier,molecule="Prot1").get_selected_particles() xyzs,rbs=dof.disable_movers(particles,mover_types=[IMP.pmi.TransformMover]) self.assertEqual(len(xyzs),0) self.assertEqual(len(rbs),0) mvs = dof.get_movers() self.assertEqual(len(mvs),10) #removing rbmv, ballmovers and super rigid movers involving prot1 dof.enable_all_movers() particles=IMP.atom.Selection(s.hier,molecule="Prot1").get_selected_particles() xyzs,rbs=dof.disable_movers(particles,mover_types=[IMP.core.RigidBodyMover,IMP.core.BallMover,IMP.pmi.TransformMover]) self.assertEqual(len(xyzs),3) self.assertEqual(len(rbs),1) mvs = dof.get_movers() self.assertEqual(len(mvs),6) #removing rbmv, ballmovers and super rigid movers involving prot2 dof.enable_all_movers() particles=IMP.atom.Selection(s.hier,molecule="Prot2").get_selected_particles() xyzs,rbs=dof.disable_movers(particles,mover_types=[IMP.core.RigidBodyMover,IMP.core.BallMover,IMP.pmi.TransformMover]) self.assertEqual(len(xyzs),0) self.assertEqual(len(rbs),1) mvs = dof.get_movers() self.assertEqual(len(mvs),8)
def test_loop_reconstruction(self): """Test loop reconstruction""" # input parameter pdbfile = self.get_input_file_name( "loop_reconstruction/starting.structure.pdb") fastafile = self.get_input_file_name( "loop_reconstruction/sequence.fasta") sequences = IMP.pmi.topology.Sequences(fastafile) # create the representation log_objects = [] optimizable_objects = [] sw = tools.Stopwatch() log_objects.append(sw) m = IMP.Model() s = IMP.pmi.topology.System(m) st = s.create_state() cA = st.create_molecule("chainA", sequence=sequences[0]) atomic = cA.add_structure(pdbfile, chain_id='A') cA.add_representation(atomic, resolutions=[1, 10], color=0.) cA.add_representation(cA.get_non_atomic_residues(), resolutions=[1], color=0.) cB = st.create_molecule("chainB", sequence=sequences[0]) atomic = cB.add_structure(pdbfile, chain_id='B') cB.add_representation(atomic, resolutions=[1, 10], color=0.5) cB.add_representation(cB.get_non_atomic_residues(), resolutions=[1], color=0.) root_hier = s.build() dof = IMP.pmi.dof.DegreesOfFreedom(m) dof.create_rigid_body(cA) dof.create_rigid_body(cB) cr = IMP.pmi.restraints.stereochemistry.ConnectivityRestraint( root_hier) cr.add_to_model() log_objects.append(cr) listofexcludedpairs = [] lof = [ cA[:12], cB[:12], cA[293:339], cB[293:339], cA[685:701], cB[685:701], cA[453:464], cB[453:464], cA[471:486], cB[471:486], cA[813:859], cB[813:859] ] # add bonds and angles for l in lof: print(l) rbr = IMP.pmi.restraints.stereochemistry.ResidueBondRestraint( objects=l) rbr.add_to_model() listofexcludedpairs += rbr.get_excluded_pairs() log_objects.append(rbr) rar = IMP.pmi.restraints.stereochemistry.ResidueAngleRestraint( objects=l) rar.add_to_model() listofexcludedpairs += rar.get_excluded_pairs() log_objects.append(rar) # add excluded volume ev = IMP.pmi.restraints.stereochemistry.ExcludedVolumeSphere( included_objects=root_hier, resolution=10.0) ev.add_excluded_particle_pairs(listofexcludedpairs) ev.add_to_model() log_objects.append(ev) mc = samplers.MonteCarlo(m, dof.get_movers(), 1.0) log_objects.append(mc) o = output.Output() print("Starting test") o.write_test("test.current.dict", log_objects) o.test( self.get_input_file_name( "loop_reconstruction/test.IMP-ee1763c6.PMI-4669cfca.dict"), log_objects) os.unlink('test.current.dict')
output_objects.append(mr) # For visualization purposes mr.create_membrane_density() ########################### # External barrier ########################### eb = IMP.pmi.restraints.basic.ExternalBarrier(hierarchies=hier, radius=50) eb.add_to_model() ############################## # Shuffle ############################## IMP.pmi.tools.shuffle_configuration(hier, max_translation=300) print(dof.get_movers()) ############################## # Sampling ############################## frames = 10 if IMP.get_is_quick_test() else 2000 rex = IMP.pmi.macros.ReplicaExchange0( model, root_hier=hier, crosslink_restraints=rmf_restraints, monte_carlo_sample_objects=dof.get_movers(), replica_exchange_maximum_temperature=3.0, global_output_directory="output/", output_objects=output_objects, monte_carlo_steps=10,
### Excluded volume - one for each state (they don't interact) evr1 = IMP.pmi.restraints.stereochemistry.ExcludedVolumeSphere(included_objects = (m1A,m1B,m1C)) evr1.add_to_model() output_objects.append(evr1) evr2 = IMP.pmi.restraints.stereochemistry.ExcludedVolumeSphere(included_objects = (m2A,m2C)) evr2.add_to_model() output_objects.append(evr2) ###################### SAMPLING ##################### # randomize particles a bit IMP.pmi.tools.shuffle_configuration(root_hier, max_translation=20) # Shift state 2 # Even though the two states don't interact, # it'll be easier to look at the RMF if we separate them trans = IMP.algebra.Transformation3D([50,0,0]) for fb in IMP.core.get_leaves(m2A.get_hierarchy())+IMP.core.get_leaves(m2C.get_hierarchy()): IMP.core.transform(IMP.core.XYZ(fb),trans) # Run replica exchange Monte Carlo sampling rex=IMP.pmi.macros.ReplicaExchange0(mdl, root_hier=root_hier, # pass the root hierarchy crosslink_restraints=rmf_restraints, # will display as springs monte_carlo_sample_objects=dof.get_movers(), # pass MC movers global_output_directory='ambiguity_output/', output_objects=output_objects, monte_carlo_steps=10, number_of_frames=1) # increase number of frames to get better results! rex.execute_macro()
def test_restraint_probability_beads(self): """Test restraint works for all-bead systems""" for i in range(2): m = IMP.Model() if i==0: rbeads=self.init_representation_beads(m) xlbeads,cldb=self.setup_crosslinks_beads(rbeads,"single_category") else: rbeads,dof=self.init_representation_beads_pmi2(m) xlbeads,cldb=self.setup_crosslinks_beads(root_hier=rbeads,mode="single_category") self.assertEqual(len(dof.get_movers()),60) dof.get_nuisances_from_restraint(xlbeads) self.assertEqual(len(dof.get_movers()),62) for xl in xlbeads.xl_list: chain1 = xl[cldb.protein1_key] chain2 = xl[cldb.protein2_key] res1 = xl[cldb.residue1_key] res2 = xl[cldb.residue2_key] ids = xl[cldb.unique_id_key] # randomize coordinates and check that the probability is OK print("testing PMI version "+str(i+1)) for j in range(100): if i==0: rbeads.shuffle_configuration(max_translation=10) else: IMP.pmi.tools.shuffle_configuration(rbeads,max_translation=10) cross_link_dict={} for xl in xlbeads.xl_list: p0 = xl["Particle1"] p1 = xl["Particle2"] prob = xl["Restraint"].get_probability() resid1 = xl[cldb.residue1_key] chain1 = xl[cldb.protein1_key] resid2 = xl[cldb.residue2_key] chain2 = xl[cldb.protein2_key] xlid=xl[cldb.unique_id_key] d0 = IMP.core.XYZ(p0) d1 = IMP.core.XYZ(p1) sig1 = xl["Particle_sigma1"] sig2 = xl["Particle_sigma2"] psi = xl["Particle_psi"] if xlid not in cross_link_dict: cross_link_dict[xlid]=([d0],[d1],[sig1],[sig2],[psi],prob) else: cross_link_dict[xlid][0].append(d0) cross_link_dict[xlid][1].append(d1) cross_link_dict[xlid][2].append(sig1) cross_link_dict[xlid][3].append(sig2) cross_link_dict[xlid][4].append(psi) for xlid in cross_link_dict: test_prob=get_probability(cross_link_dict[xlid][0], cross_link_dict[xlid][1], cross_link_dict[xlid][2], cross_link_dict[xlid][3], cross_link_dict[xlid][4],21.0,0.01) prob=cross_link_dict[xlid][5] self.assertAlmostEqual(test_prob,prob, delta=0.0001) if i==0: rex0 = IMP.pmi.macros.ReplicaExchange0(m, rbeads, monte_carlo_sample_objects=[rbeads], number_of_frames=2, test_mode=True, replica_exchange_object = rem) rex0.execute_macro() else: rex = IMP.pmi.macros.ReplicaExchange0(m, root_hier=rbeads, monte_carlo_sample_objects=dof.get_movers(), number_of_frames=2, test_mode=True, replica_exchange_object = rem) rex.execute_macro() for output in ['excluded.None.xl.db', 'included.None.xl.db', 'missing.None.xl.db']: os.unlink(output)
def test_restraint_probability_complex(self): """Test restraint gets correct probabilities""" m = IMP.Model() rcomplex, dof = self.init_representation_complex_pmi2(m) xlc, cldb = self.setup_crosslinks_complex(root_hier=rcomplex, mode="single_category") self.assertEqual(len(dof.get_movers()), 42) dof.get_nuisances_from_restraint(xlc) self.assertEqual(len(dof.get_movers()), 44) # check all internals didn't change since last time o = IMP.pmi.output.Output() o.write_test("expensive_test_new_cross_link_ms_restraint.dat", [xlc]) passed = o.test( self.get_input_file_name( "expensive_test_new_cross_link_ms_restraint.dat"), [xlc]) self.assertEqual(passed, True) rs = xlc.get_restraint() # check the probability of cross-links restraints = [] for xl in xlc.xl_list: p0 = xl["Particle1"] p1 = xl["Particle2"] prob = xl["Restraint"].get_probability() resid1 = xl[cldb.residue1_key] chain1 = xl[cldb.protein1_key] resid2 = xl[cldb.residue2_key] chain2 = xl[cldb.protein2_key] d0 = IMP.core.XYZ(p0) d1 = IMP.core.XYZ(p1) sig1 = xl["Particle_sigma1"] sig2 = xl["Particle_sigma2"] psi = xl["Particle_psi"] d0 = IMP.core.XYZ(p0) d1 = IMP.core.XYZ(p1) dist = IMP.core.get_distance(d0, d1) test_prob = get_probability([d0], [d1], [sig1], [sig2], [psi], 21.0, 0.0) restraints.append(xl["Restraint"]) # check that the probability is the same for # each cross-link self.assertAlmostEqual(prob, test_prob, delta=0.00001) # check the log_wrapper log_wrapper_score = rs.unprotected_evaluate(None) test_log_wrapper_score = log_evaluate(restraints) self.assertAlmostEqual(log_wrapper_score, test_log_wrapper_score, delta=0.00001) rex = IMP.pmi.macros.ReplicaExchange0( m, root_hier=rcomplex, monte_carlo_sample_objects=dof.get_movers(), number_of_frames=2, test_mode=True, replica_exchange_object=rem) rex.execute_macro() for output in [ 'excluded.None.xl.db', 'expensive_test_new_cross_link_ms_restraint.dat', 'included.None.xl.db', 'missing.None.xl.db' ]: os.unlink(output)
included_objects=(m1A, m1B, m1C)) evr1.add_to_model() output_objects.append(evr1) evr2 = IMP.pmi.restraints.stereochemistry.ExcludedVolumeSphere( included_objects=(m2A, m2C)) evr2.add_to_model() output_objects.append(evr2) ###################### SAMPLING ##################### # randomize particles a bit IMP.pmi.tools.shuffle_configuration(root_hier, max_translation=20) # Shift state 2 # Even though the two states don't interact, # it'll be easier to look at the RMF if we separate them trans = IMP.algebra.Transformation3D([50, 0, 0]) for fb in IMP.core.get_leaves(m2A.get_hierarchy()) + IMP.core.get_leaves( m2C.get_hierarchy()): IMP.core.transform(IMP.core.XYZ(fb), trans) # Run replica exchange Monte Carlo sampling rex = IMP.pmi.macros.ReplicaExchange0( mdl, root_hier=root_hier, # pass the root hierarchy monte_carlo_sample_objects=dof.get_movers(), # pass MC movers global_output_directory='ambiguity_output/', output_objects=output_objects, monte_carlo_steps=10, number_of_frames=1) # increase number of frames to get better results! rex.execute_macro()
output_objects.append(mr) # For visualization purposes mr.create_membrane_density() ########################### # External barrier ########################### eb = IMP.pmi.restraints.basic.ExternalBarrier(hierarchies=hier, radius=50) eb.add_to_model() ############################## # Shuffle ############################## IMP.pmi.tools.shuffle_configuration(hier, max_translation=300) print(dof.get_movers()) ############################## # Sampling ############################## frames = 10 if IMP.get_is_quick_test() else 2000 rex = IMP.pmi.macros.ReplicaExchange0(model, root_hier=hier, crosslink_restraints=rmf_restraints, monte_carlo_sample_objects=dof.get_movers(), replica_exchange_maximum_temperature=3.0, global_output_directory="output/", output_objects=output_objects, monte_carlo_steps=10, number_of_frames=frames,
def test_restraint_probability_complex(self): """Test restraint gets correct probabilities""" for i in range(2): m = IMP.Model() print("Testing PMI version",i+1) if i==0: rcomplex = self.init_representation_complex(m) xlc,cldb = self.setup_crosslinks_complex(rcomplex,"single_category") else: rcomplex,dof=self.init_representation_complex_pmi2(m) xlc,cldb = self.setup_crosslinks_complex(root_hier=rcomplex, mode="single_category") self.assertEqual(len(dof.get_movers()),42) dof.get_nuisances_from_restraint(xlc) self.assertEqual(len(dof.get_movers()),44) # check all internals didn't change since last time o=IMP.pmi.output.Output() o.write_test("expensive_test_new_cross_link_ms_restraint.dat", [xlc]) passed=o.test(self.get_input_file_name("expensive_test_new_cross_link_ms_restraint.dat"), [xlc]) self.assertEqual(passed, True) rs = xlc.get_restraint() # check the probability of cross-links restraints=[] for xl in xlc.xl_list: p0 = xl["Particle1"] p1 = xl["Particle2"] prob = xl["Restraint"].get_probability() resid1 = xl[cldb.residue1_key] chain1 = xl[cldb.protein1_key] resid2 = xl[cldb.residue2_key] chain2 = xl[cldb.protein2_key] d0 = IMP.core.XYZ(p0) d1 = IMP.core.XYZ(p1) sig1 = xl["Particle_sigma1"] sig2 = xl["Particle_sigma2"] psi = xl["Particle_psi"] d0 = IMP.core.XYZ(p0) d1 = IMP.core.XYZ(p1) dist=IMP.core.get_distance(d0, d1) test_prob=get_probability([d0],[d1],[sig1],[sig2],[psi],21.0,0.0) restraints.append(xl["Restraint"]) # check that the probability is the same for # each cross-link self.assertAlmostEqual(prob, test_prob, delta=0.00001) # check the log_wrapper log_wrapper_score=rs.unprotected_evaluate(None) test_log_wrapper_score=log_evaluate(restraints) self.assertAlmostEqual(log_wrapper_score, test_log_wrapper_score, delta=0.00001) if i==0: rex0 = IMP.pmi.macros.ReplicaExchange0(m, rcomplex, monte_carlo_sample_objects=[rcomplex], number_of_frames=2, test_mode=True, replica_exchange_object = rem) rex0.execute_macro() else: rex = IMP.pmi.macros.ReplicaExchange0(m, root_hier=rcomplex, monte_carlo_sample_objects=dof.get_movers(), number_of_frames=2, test_mode=True, replica_exchange_object = rem) rex.execute_macro() for output in ['excluded.None.xl.db', 'expensive_test_new_cross_link_ms_restraint.dat', 'included.None.xl.db', 'missing.None.xl.db']: os.unlink(output)
def test_multistate(self): psiv = 0.01 sigmav = 12.0 slope = 0.0 length = 21 inputx = 70 m = IMP.Model() s = IMP.pmi.topology.System(m) # define the particles in state 1 st1 = s.create_state() mol1 = [] for mn in range(1, 4): mol = st1.create_molecule("particle%d" % mn, "G" * 10, "ABC"[mn - 1]) mol.add_representation(resolutions=[10]) mol1.append(mol) # define the particles in state 2 st2 = s.create_state() mol2 = [] for mn in range(1, 4): mol = st2.create_molecule("particle%d" % mn, "G" * 10, "ABC"[mn - 1]) mol.add_representation(resolutions=[10]) mol2.append(mol) hier = s.build() dof = IMP.pmi.dof.DegreesOfFreedom(m) # only allow particle3 in each state to move dof.create_flexible_beads(mol1[2]) dof.create_flexible_beads(mol2[2]) pp1, pp2, pp3 = IMP.atom.get_leaves(st1.hier) xyz11 = IMP.core.XYZ(pp1) xyz21 = IMP.core.XYZ(pp2) xyz31 = IMP.core.XYZ(pp3) xyz11.set_coordinates((0, 0, 0)) print(xyz11.get_coordinates()) xyz21.set_coordinates((inputx, 0, 0)) xyz31.set_coordinates((0, 0, 0)) pp1, pp2, pp3 = IMP.atom.get_leaves(st2.hier) xyz12 = IMP.core.XYZ(pp1) xyz22 = IMP.core.XYZ(pp2) xyz32 = IMP.core.XYZ(pp3) xyz12.set_coordinates((0, 0, 0)) xyz22.set_coordinates((inputx, 0, 0)) xyz32.set_coordinates((inputx, 0, 0)) eb = IMP.pmi.restraints.basic.ExternalBarrier(hierarchies=st1.hier, radius=1000) eb.add_to_model() eb = IMP.pmi.restraints.basic.ExternalBarrier(hierarchies=st2.hier, radius=1000) eb.add_to_model() xldbkwc = IMP.pmi.io.crosslink.CrossLinkDataBaseKeywordsConverter() xldbkwc.set_protein1_key("prot1") xldbkwc.set_protein2_key("prot2") xldbkwc.set_residue1_key("res1") xldbkwc.set_residue2_key("res2") xldbkwc.set_unique_id_key("id") cldb = IMP.pmi.io.crosslink.CrossLinkDataBase(xldbkwc) cldb.create_set_from_file(self.get_input_file_name('multistate.csv')) xl = IMP.pmi.restraints.crosslinking.CrossLinkingMassSpectrometryRestraint( root_hier=hier, database=cldb, length=length, slope=slope, resolution=1.0) psi = xl.psi_dictionary['PSI'][0] psi.set_scale(psiv) sigma = xl.sigma_dictionary['SIGMA'][0] sigma.set_scale(sigmav) xl.set_psi_is_sampled(False) xl.set_sigma_is_sampled(False) # psi.set_scale(0.1) # xl.get_sigma(1.0) out_dict = xl.get_output() sorted_keys = sorted(out_dict.keys()) for entry in sorted_keys: print(entry, out_dict[entry]) print(xyz11.get_coordinates()) xl.add_to_model() rset = IMP.pmi.tools.get_restraint_set(m) self.assertAlmostEqual(rset.evaluate(False), -3.03166, delta=1e-2) o = IMP.pmi.output.Output() o.init_rmf("trajectory.rmf3", [st1.hier, st2.hier]) print(o.dictionary_rmfs) mc = IMP.pmi.samplers.MonteCarlo(m, dof.get_movers(), 1.0) mc.set_simulated_annealing(min_temp=1.0, max_temp=2.0, min_temp_time=200, max_temp_time=50) o.init_stat2("modeling.stat", [mc, xl]) for i in range(1, 20): xyz31.set_coordinates((float(i), 0, 0)) for j in range(1, 20): xyz32.set_coordinates((float(j), 0, 0)) print(i, j, rset.evaluate(False)) o.write_stats2() po = IMP.pmi.output.ProcessOutput("modeling.stat") print(po.get_keys()) self.assertEqual(len(po.get_keys()), 14) fs = po.get_fields([ 'CrossLinkingMassSpectrometryRestraint_Distance_||2.1|particle1|5|particle3|5|1|PSI|', 'CrossLinkingMassSpectrometryRestraint_Distance_||1.1|particle2|5|particle3|5|1|PSI|', 'CrossLinkingMassSpectrometryRestraint_Data_Score', 'CrossLinkingMassSpectrometryRestraint_Linear_Score', 'CrossLinkingMassSpectrometryRestraint_Psi_PSI' ]) print(fs.keys()) o.close_rmf("trajectory.rmf3") for output in [ 'excluded.None.xl.db', 'included.None.xl.db', 'missing.None.xl.db', 'modeling.stat', 'trajectory.rmf3' ]: os.unlink(output)
def test_restraint_probability_beads(self): """Test restraint works for all-bead systems""" m = IMP.Model() rbeads, dof = self.init_representation_beads_pmi2(m) xlbeads, cldb = self.setup_crosslinks_beads(root_hier=rbeads, mode="single_category") self.assertEqual(len(dof.get_movers()), 60) dof.get_nuisances_from_restraint(xlbeads) self.assertEqual(len(dof.get_movers()), 62) for xl in xlbeads.xl_list: chain1 = xl[cldb.protein1_key] chain2 = xl[cldb.protein2_key] res1 = xl[cldb.residue1_key] res2 = xl[cldb.residue2_key] ids = xl[cldb.unique_id_key] # randomize coordinates and check that the probability is OK for j in range(100): IMP.pmi.tools.shuffle_configuration(rbeads, max_translation=10) cross_link_dict = {} for xl in xlbeads.xl_list: p0 = xl["Particle1"] p1 = xl["Particle2"] prob = xl["Restraint"].get_probability() resid1 = xl[cldb.residue1_key] chain1 = xl[cldb.protein1_key] resid2 = xl[cldb.residue2_key] chain2 = xl[cldb.protein2_key] xlid = xl[cldb.unique_id_key] d0 = IMP.core.XYZ(p0) d1 = IMP.core.XYZ(p1) sig1 = xl["Particle_sigma1"] sig2 = xl["Particle_sigma2"] psi = xl["Particle_psi"] if xlid not in cross_link_dict: cross_link_dict[xlid] = ([d0], [d1], [sig1], [sig2], [psi], prob) else: cross_link_dict[xlid][0].append(d0) cross_link_dict[xlid][1].append(d1) cross_link_dict[xlid][2].append(sig1) cross_link_dict[xlid][3].append(sig2) cross_link_dict[xlid][4].append(psi) for xlid in cross_link_dict: test_prob = get_probability(cross_link_dict[xlid][0], cross_link_dict[xlid][1], cross_link_dict[xlid][2], cross_link_dict[xlid][3], cross_link_dict[xlid][4], 21.0, 0.01) prob = cross_link_dict[xlid][5] self.assertAlmostEqual(test_prob, prob, delta=0.0001) rex = IMP.pmi.macros.ReplicaExchange0( m, root_hier=rbeads, monte_carlo_sample_objects=dof.get_movers(), number_of_frames=2, test_mode=True, replica_exchange_object=rem) rex.execute_macro() for output in [ 'excluded.None.xl.db', 'included.None.xl.db', 'missing.None.xl.db' ]: os.unlink(output)
def init_with_copies(self,mdl): s = IMP.pmi.topology.System(mdl) st1 = s.create_state() seqs = IMP.pmi.topology.Sequences(self.get_input_file_name('seqs.fasta'), name_map={'Protein_1':'Prot1', 'Protein_2':'Prot2', 'Protein_3':'Prot3'}) m1 = st1.create_molecule("Prot1",chain_id='A',sequence=seqs["Prot1"]) a1 = m1.add_structure(self.get_input_file_name('prot.pdb'), chain_id='A',res_range=(55,64),offset=-54) m1.add_representation(a1,resolutions=[1]) m1.add_representation(m1[:]-a1,resolutions=[1]) m2 = m1.create_clone('B') hier = s.build() dof = IMP.pmi.dof.DegreesOfFreedom(mdl) mv1,rb1 = dof.create_rigid_body(m1,nonrigid_parts = m1.get_non_atomic_residues(), max_trans=0.000001) mv2,rb2 = dof.create_rigid_body(m2,nonrigid_parts = m2.get_non_atomic_residues(), max_trans=0.000001) trans = IMP.algebra.Transformation3D(IMP.algebra.Vector3D(100,0,0)) IMP.core.transform(rb2,trans) ps0 = IMP.atom.Selection(hier,molecule='Prot1',copy_index=0).get_selected_particles() ps1 = IMP.atom.Selection(hier,molecule='Prot1',copy_index=1).get_selected_particles() with IMP.allow_deprecated(): rex = IMP.pmi.macros.ReplicaExchange0(mdl, root_hier=hier, monte_carlo_sample_objects=dof.get_movers(), number_of_frames=1, number_of_best_scoring_models=0, global_output_directory = \ self.get_input_file_name("pmi2_copies_0/")) rex.execute_macro() coords0A = [IMP.core.XYZ(p).get_coordinates() for p in ps0] coords1A = [IMP.core.XYZ(p).get_coordinates() for p in ps1] # swap the objects IMP.core.transform(rb2,trans.get_inverse()) IMP.core.transform(rb1,trans) with IMP.allow_deprecated(): rex2 = IMP.pmi.macros.ReplicaExchange0(mdl, root_hier=hier, monte_carlo_sample_objects=dof.get_movers(), number_of_frames=1, number_of_best_scoring_models=0, global_output_directory = \ self.get_input_file_name("pmi2_copies_1/"), replica_exchange_object = rex.get_replica_exchange_object()) rex2.execute_macro() coords0B = [IMP.core.XYZ(p).get_coordinates() for p in ps0] coords1B = [IMP.core.XYZ(p).get_coordinates() for p in ps1] rmsd = IMP.algebra.get_rmsd(coords0A+coords1A,coords1B+coords0B) return rmsd