Ejemplo n.º 1
0
 def init_representation_beads_pmi2(self, m):
     s = IMP.pmi.topology.System(m)
     st = s.create_state()
     protA = st.create_molecule("ProtA", sequence='A' * 30, chain_id='A')
     protA.add_representation(protA[0:10],
                              resolutions=[1],
                              bead_default_coord=[0, 0, 0])
     protA.add_representation(protA[10:20],
                              resolutions=[1],
                              bead_default_coord=[10, 0, 0])
     protA.add_representation(protA[20:30],
                              resolutions=[1],
                              bead_default_coord=[20, 0, 0])
     protB = st.create_molecule("ProtB", sequence='A' * 30, chain_id='B')
     protB.add_representation(protB[0:10],
                              resolutions=[1],
                              bead_default_coord=[0, 0, 0])
     protB.add_representation(protB[10:20],
                              resolutions=[1],
                              bead_default_coord=[10, 0, 0])
     protB.add_representation(protB[20:30],
                              resolutions=[1],
                              bead_default_coord=[20, 0, 0])
     hier = s.build()
     dof = IMP.pmi.dof.DegreesOfFreedom(m)
     dof.create_flexible_beads(protA)
     dof.create_flexible_beads(protB)
     return hier, dof
Ejemplo n.º 2
0
    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)
Ejemplo n.º 3
0
 def test_mc_flexible_beads3(self):
     """Test flex beads don't work if nothing passed"""
     mdl = IMP.Model()
     s,mols = self.init_topology3(mdl)
     dof = IMP.pmi.dof.DegreesOfFreedom(mdl)
     fb_movers = dof.create_flexible_beads(mols[1].get_non_atomic_residues(),max_trans=1.0)
     self.assertEqual(len(fb_movers),0)
 def init_representation_beads_pmi2(self,m):
     s = IMP.pmi.topology.System(m)
     st = s.create_state()
     protA = st.create_molecule("ProtA",sequence='A'*30,chain_id='A')
     protA.add_representation(protA[0:10],resolutions=[1],bead_default_coord=[0,0,0])
     protA.add_representation(protA[10:20],resolutions=[1],bead_default_coord=[10,0,0])
     protA.add_representation(protA[20:30],resolutions=[1],bead_default_coord=[20,0,0])
     protB = st.create_molecule("ProtB",sequence='A'*30,chain_id='B')
     protB.add_representation(protB[0:10],resolutions=[1],bead_default_coord=[0,0,0])
     protB.add_representation(protB[10:20],resolutions=[1],bead_default_coord=[10,0,0])
     protB.add_representation(protB[20:30],resolutions=[1],bead_default_coord=[20,0,0])
     hier = s.build()
     dof = IMP.pmi.dof.DegreesOfFreedom(m)
     dof.create_flexible_beads(protA)
     dof.create_flexible_beads(protB)
     return hier,dof
Ejemplo n.º 5
0
 def test_mc_flexible_beads3(self):
     """Test flex beads don't work if nothing passed"""
     mdl = IMP.Model()
     s, mols = self.init_topology3(mdl)
     dof = IMP.pmi.dof.DegreesOfFreedom(mdl)
     fb_movers = dof.create_flexible_beads(
         mols[1].get_non_atomic_residues(), max_trans=1.0)
     self.assertEqual(len(fb_movers), 0)
Ejemplo n.º 6
0
 def test_mc_flexible_beads(self):
     mdl = IMP.Model()
     molecule = self.init_topology1(mdl)
     hier = molecule.get_hierarchy()
     dof = IMP.pmi.dof.DegreesOfFreedom(mdl)
     sel_nonrigid = IMP.atom.Selection(hier, residue_indexes=[3, 4, 10])
     fbs = dof.create_flexible_beads(sel_nonrigid, max_trans=1.0)
     mvs = fbs.get_movers()
     self.assertEqual(len(mvs), 3)
Ejemplo n.º 7
0
 def test_mc_flexible_beads(self):
     mdl = IMP.Model()
     molecule = self.init_topology1(mdl)
     hier = molecule.get_hierarchy()
     dof = IMP.pmi.dof.DegreesOfFreedom(mdl)
     sel_nonrigid = IMP.atom.Selection(hier,residue_indexes=[3,4,10])
     fbs = dof.create_flexible_beads(sel_nonrigid,max_trans=1.0)
     mvs = fbs.get_movers()
     self.assertEqual(len(mvs),3)
Ejemplo n.º 8
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()
Ejemplo n.º 9
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()
Ejemplo n.º 10
0
    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)
##fname = 'test2.rmf'
##rh = RMF.create_rmf_file(fname)
##IMP.rmf.add_hierarchy(rh, root_hier)
##IMP.rmf.save_frame(rh)

##(receptor_radius,receptor_center_residue)=get_radius_center_residue(receptor)
##(ligand_radius,ligand_center_residue)=get_radius_center_residue(ligand)

##print "radius",receptor_radius +ligand_radius+5.0

## Setup degrees of freedom
##  The DOF functions automatically select all resolutions
##  Objects passed to nonrigid_parts move with the frame but also have their own independent movers.
dof = IMP.pmi.dof.DegreesOfFreedom(mdl)
dof.create_flexible_beads(ligand_mol,max_trans = -1, resolutions_list=resolutions,move_sizes_list = move_sizes)

########################## RESTRAINTS #####################
output_objects = [] # keep a list of functions that need to be reported
display_restraints = [] # display as springs in RMF
 
# Connectivity keeps things connected along the backbone (ignores if inside same rigid body)
crs = []
for mol in mols:
    cr = IMP.pmi.restraints.stereochemistry.ConnectivityRestraint(mol)
    cr.add_to_model()
    output_objects.append(cr)
    crs.append(cr)

# Excluded volume - automatically more efficient due to rigid bodies
evr1 = IMP.pmi.restraints.stereochemistry.ExcludedVolumeSphere(included_objects = ligand_mol)
Ejemplo n.º 12
0
# State 2: ProtA (chainA), ProtC (chainC)
m2A = st2.create_molecule('ProtA',sequence,chain_id='A')
m2A.add_representation(m2A,resolutions=[1])
m2C = st2.create_molecule('ProtC',sequence,chain_id='C')
m2C.add_representation(m2C,resolutions=[1])
root_hier = s.build()

### Display all the states, molecules, representations
IMP.atom.show_with_representations(root_hier)

### Setup all molecules to move as flexible beads and super rigid bodies
#  "Super rigid bodies" aren't really rigid, it's just a mover that moves the whole body together
dof = IMP.pmi.dof.DegreesOfFreedom(mdl)
for mol in (m1A,m1B,m1C,m2A,m2C):
    dof.create_flexible_beads(mol,
                              max_trans=0.1)
    dof.create_super_rigid_body(mol)


###################### RESTRAINTS #####################
output_objects = [] # keep a list of functions that need to be reported
rmf_restraints = [] # display these restraints as springs in the RMF

### Crosslinks setup
# 1) Create file. This one XL has 3 ambiguity options: State1 has 2, State2 has 1
lines = '''id,mol1,res1,mol2,res2,score
1,ProtA,3,ProtC,9,1.0
'''
tf = tempfile.NamedTemporaryFile(delete=False, mode='w')
tf.write(lines)
tf.close()
    def test_restraint_copy_ambiguity(self):
        """Test restraint works for systems with configuration ambiguity in PMI2"""

        # setup system
        m = IMP.Model()
        s = IMP.pmi.topology.System(m)
        st = s.create_state()
        protA = st.create_molecule("ProtA",sequence='A'*30,chain_id='A')
        protA.add_representation(protA[0:10],resolutions=[1],bead_default_coord=[0,0,0])
        protA.add_representation(protA[10:20],resolutions=[1],bead_default_coord=[10,0,0])
        protA.add_representation(protA[20:30],resolutions=[1],bead_default_coord=[20,0,0])
        protA2 = protA.create_clone('C')
        protB = st.create_molecule("ProtB",sequence='A'*30,chain_id='B')
        protB.add_representation(protB[0:10],resolutions=[1],bead_default_coord=[0,0,0])
        protB.add_representation(protB[10:20],resolutions=[1],bead_default_coord=[10,0,0])
        protB.add_representation(protB[20:30],resolutions=[1],bead_default_coord=[20,0,0])
        protB2 = protB.create_clone('D')
        hier = s.build()
        dof = IMP.pmi.dof.DegreesOfFreedom(m)
        dof.create_flexible_beads([protA,protA2,protB,protB2])

        xlbeads,cldb = self.setup_crosslinks_beads(root_hier=hier,mode="single_category")

        # check enough clones were created
        self.assertEqual(len(cldb.data_base['1']),8)
        self.assertEqual(len(cldb.data_base['2']),4)
        self.assertEqual(len(cldb.data_base['3']),4)
        self.assertEqual(len(cldb.data_base['4']),4)

        # check score
        for j in range(100):
            IMP.pmi.tools.shuffle_configuration(hier,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)
        for output in ['excluded.None.xl.db',
                       'included.None.xl.db', 'missing.None.xl.db']:
            os.unlink(output)
Ejemplo n.º 14
0
for i, mol in enumerate(pol2g_mols):
    # create a rigid body for each domain with structural information, the flexible beads inside are part of the rigid body, the remaining part of the
    #crystal structures of RPB1 and RPB2
    if i in range(12):
        print(i, mol)
        pol2g_unstructured = mol.get_non_atomic_residues()
        pol2g_structured = mol.get_atomic_residues()
        pol2g_all = mol.get_residues()
        pol2g_complex.append(pol2g_all)
        pol2g_complexn.append(pol2g_unstructured)

    if i in [12]:
        pol2g_u = mol.get_non_atomic_residues()
        pol2g_rigid1 = mol.get_residues()
        dof.create_flexible_beads(pol2g_rigid1,
                                  max_trans=FLEX_MAX_TRANS,
                                  resolution=10)

print(dof)

pol2g_molc2 = [x for x in pol2g_complex]
pol2g_molc3 = [x for x in pol2g_complexn]
dof.create_flexible_beads(pol2g_molc3, max_trans=FLEX_MAX_TRANS, resolution=10)

##############################################################
##############################################################
##############################################################
##############################################################
##############################################################
####################### RESTRAINTS #####################
output_objects = []  # keep a list of functions that need to be reported
Ejemplo n.º 15
0
        pass


sys.stdout = DummyFile()
"""setting up the representation
PMI 2 representation. Creates two particles and
an harmonic distance restraints between them"""
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()

start_time = process_time()

rex = IMP.pmi.macros.ReplicaExchange0(
    m,
    root_hier=hier,
    monte_carlo_sample_objects=dof.get_movers(),
Ejemplo n.º 16
0
    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)
Ejemplo n.º 17
0
# State 2: ProtA (chainA), ProtC (chainC)
m2A = st2.create_molecule('ProtA', sequence, chain_id='A')
m2A.add_representation(m2A, resolutions=[1])
m2C = st2.create_molecule('ProtC', sequence, chain_id='C')
m2C.add_representation(m2C, resolutions=[1])
root_hier = s.build()

### Display all the states, molecules, representations
IMP.atom.show_with_representations(root_hier)

### Setup all molecules to move as flexible beads and super rigid bodies
#  "Super rigid bodies" aren't really rigid, it's just a mover that moves the whole body together
dof = IMP.pmi.dof.DegreesOfFreedom(mdl)
for mol in (m1A, m1B, m1C, m2A, m2C):
    dof.create_flexible_beads(mol, max_trans=0.1)
    dof.create_super_rigid_body(mol)

###################### RESTRAINTS #####################
output_objects = []  # keep a list of functions that need to be reported

### Crosslinks setup
# 1) Create file. This one XL has 3 ambiguity options: State1 has 2, State2 has 1
lines = '''id,mol1,res1,mol2,res2,score
1,ProtA,3,ProtC,9,1.0
'''
tf = tempfile.NamedTemporaryFile(delete=False, mode='w')
tf.write(lines)
tf.close()

# 2) Define the columns
Ejemplo n.º 18
0
    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)
Ejemplo n.º 19
0
# Create a symmetry constraint
#  A constrant is invariant: IMP will automatically move all clones to match the reference
#  If instead you want some more flexiblity, consider IMP.pmi.restraints.stereochemistry.SymmetryRestraint
dof = IMP.pmi.dof.DegreesOfFreedom(mdl)
center = IMP.algebra.Vector3D([50,0,0])
for nc in range(7):
    rot = IMP.algebra.get_rotation_about_axis([0,0,1],2*math.pi*(nc+1)/8)
    transform = IMP.algebra.get_rotation_about_point(center,rot)
    dof.constrain_symmetry(mols[0],mols[nc+1],transform)
mdl.update() # propagates coordinates


############ Make stuff look cool with restraints ###########

# set up the original molecule as flexible beads
dof.create_flexible_beads(mols[0])

# Create a connectivity restraint for the first molecule
cr = IMP.pmi.restraints.stereochemistry.ConnectivityRestraint(objects=mol)
cr.add_to_model()

# Create excluded volume for all particles
evr = IMP.pmi.restraints.stereochemistry.ExcludedVolumeSphere(included_objects=mols)
evr.add_to_model()

# Quickly move all flexible beads into place
dof.optimize_flexible_beads(100)

# write a single-frame RMF to view the helix
out = IMP.pmi.output.Output()
out.init_rmf("example_symmetry.rmf3",hierarchies=[hier])
Ejemplo n.º 20
0
# Create a symmetry constraint
#  A constrant is invariant: IMP will automatically move all clones to match the reference
#  If instead you want some more flexiblity, consider IMP.pmi.restraints.stereochemistry.SymmetryRestraint
dof = IMP.pmi.dof.DegreesOfFreedom(mdl)
center = IMP.algebra.Vector3D([50,0,0])
for nc in range(7):
    rot = IMP.algebra.get_rotation_about_axis([0,0,1],2*math.pi*(nc+1)/8)
    transform = IMP.algebra.get_rotation_about_point(center,rot)
    dof.constrain_symmetry(mols[0],mols[nc+1],transform)
mdl.update() # propagates coordinates


############ Make stuff look cool with restraints ###########

# set up the original molecule as flexible beads
dof.create_flexible_beads(mols[0])

# Create a connectivity restraint for the first molecule
cr = IMP.pmi.restraints.stereochemistry.ConnectivityRestraint(objects=mol)
cr.add_to_model()

# Create excluded volume for all particles
evr = IMP.pmi.restraints.stereochemistry.ExcludedVolumeSphere(included_objects=mols)
evr.add_to_model()

# Quickly move all flexible beads into place
dof.optimize_flexible_beads(100)

# write a single-frame RMF to view the helix
out = IMP.pmi.output.Output()
out.init_rmf("example_symmetry.rmf3",hierarchies=[hier])
Ejemplo n.º 21
0
    def test_shuffle_deep(self):
        """Test moving rbs, fbs"""
        mdl = IMP.Model()
        s = IMP.pmi.topology.System(mdl)
        seqs = IMP.pmi.topology.Sequences(
            self.get_input_file_name('chainA.fasta'))
        st1 = s.create_state()
        mol = st1.create_molecule("GCP2_YEAST",
                                  sequence=seqs["GCP2_YEAST"][:100],
                                  chain_id='A')
        atomic_res = mol.add_structure(self.get_input_file_name('chainA.pdb'),
                                       chain_id='A',
                                       res_range=(1, 100))
        mol.add_representation(mol.get_atomic_residues(), resolutions=[10])
        mol.add_representation(mol.get_non_atomic_residues(), resolutions=[10])

        mol2 = mol.create_clone('B')

        mol3 = st1.create_molecule("GCP2_YEAST_BEADS",
                                   sequence=seqs["GCP2_YEAST"][:100],
                                   chain_id='C')
        mol3.add_representation(mol3.get_non_atomic_residues(),
                                resolutions=[10])

        hier = s.build()

        dof = IMP.pmi.dof.DegreesOfFreedom(mdl)
        dof.create_rigid_body(mol,
                              nonrigid_parts=mol.get_non_atomic_residues())
        dof.create_rigid_body(mol2,
                              nonrigid_parts=mol2.get_non_atomic_residues())
        dof.create_flexible_beads(mol3.get_non_atomic_residues(),
                                  max_trans=1.0)

        rbs, fbs = IMP.pmi.tools.get_rbs_and_beads([hier])

        rbs_trans_before = {}
        fbs_position_before = {}

        rbs_trans_after = {}
        fbs_position_after = {}

        for rb in rbs:
            rbs_trans_before[rb] = rb.get_reference_frame(
            ).get_transformation_to()

        for fb in fbs:
            if IMP.core.NonRigidMember.get_is_setup(fb):
                fbs_position_before[fb] = \
                        IMP.core.NonRigidMember(fb).get_internal_coordinates()
            else:
                fbs_position_before[fb] = IMP.core.XYZ(fb).get_coordinates()

        IMP.pmi.tools.shuffle_configuration(hier)

        for rb in rbs:
            rbs_trans_after[rb] = rb.get_reference_frame(
            ).get_transformation_to()

        for fb in fbs:
            if IMP.core.NonRigidMember.get_is_setup(fb):
                fbs_position_after[fb] = \
                        IMP.core.NonRigidMember(fb).get_internal_coordinates()
            else:
                fbs_position_after[fb] = IMP.core.XYZ(fb).get_coordinates()

        for fb in fbs:
            position_after = fbs_position_after[fb]
            position_before = fbs_position_before[fb]
            for i in [0, 1, 2]:
                self.assertNotEqual(position_after[i], position_before[i])

        for rb in rbs:
            position_after = rbs_trans_after[rb].get_translation()
            position_before = rbs_trans_before[rb].get_translation()
            rotation_after = rbs_trans_after[rb].get_rotation(
            ) * IMP.algebra.Vector3D(1, 1, 1)
            rotation_before = rbs_trans_before[rb].get_rotation(
            ) * IMP.algebra.Vector3D(1, 1, 1)
            for i in [0, 1, 2]:
                self.assertNotEqual(position_after[i], position_before[i])
                self.assertNotEqual(rotation_after[i], rotation_before[i])
Ejemplo n.º 22
0
            TREM2_mol.append(mol)

        elif 'Abeta' in molname:
            crA = IMP.pmi.restraints.stereochemistry.ConnectivityRestraint(mol, scale=2.0)
            crA.add_to_model()
            output_objects.append(crA)
            sample_objects.append(crA)
            crs.append(crA)

            atomic = mol.get_atomic_residues()
            dof.create_rigid_body(atomic,
                                  max_trans=0,
                                  max_rot=0,
                                  resolution='all')
            dof.create_flexible_beads(mol.get_non_atomic_residues(),
                                      max_trans=1.0,
                                      resolution=1)
            active_tri_mol.append(mol)

# ______Composite Restraint for Fibril___________________________________________________________________
shuffle_exclude_rbs = dof.get_rigid_bodies()[:-1]

# Constrain the fibril trimer unit copies with z-trans. symmetry ### This is very important
for i in range(0, len(chains)):
    for t in range(0, len(fibril_transforms)):
        threefold_trans = fibril_transforms[t]
        dof.constrain_symmetry(protofil_mols[i][0], protofil_mols[i][t + 1], threefold_trans)
mdl.update()

print("|||||  All sym constraints added  |||||")
Ejemplo n.º 23
0
    def test_restraint_copy_ambiguity(self):
        """Test restraint works for systems with configuration ambiguity in PMI2"""

        # setup system
        m = IMP.Model()
        s = IMP.pmi.topology.System(m)
        st = s.create_state()
        protA = st.create_molecule("ProtA", sequence='A' * 30, chain_id='A')
        protA.add_representation(protA[0:10],
                                 resolutions=[1],
                                 bead_default_coord=[0, 0, 0])
        protA.add_representation(protA[10:20],
                                 resolutions=[1],
                                 bead_default_coord=[10, 0, 0])
        protA.add_representation(protA[20:30],
                                 resolutions=[1],
                                 bead_default_coord=[20, 0, 0])
        protA2 = protA.create_clone('C')
        protB = st.create_molecule("ProtB", sequence='A' * 30, chain_id='B')
        protB.add_representation(protB[0:10],
                                 resolutions=[1],
                                 bead_default_coord=[0, 0, 0])
        protB.add_representation(protB[10:20],
                                 resolutions=[1],
                                 bead_default_coord=[10, 0, 0])
        protB.add_representation(protB[20:30],
                                 resolutions=[1],
                                 bead_default_coord=[20, 0, 0])
        protB2 = protB.create_clone('D')
        hier = s.build()
        dof = IMP.pmi.dof.DegreesOfFreedom(m)
        dof.create_flexible_beads([protA, protA2, protB, protB2])

        xlbeads, cldb = self.setup_crosslinks_beads(root_hier=hier,
                                                    mode="single_category")

        # check enough clones were created
        self.assertEqual(len(cldb.data_base['1']), 8)
        self.assertEqual(len(cldb.data_base['2']), 4)
        self.assertEqual(len(cldb.data_base['3']), 4)
        self.assertEqual(len(cldb.data_base['4']), 4)

        # check score
        for j in range(100):
            IMP.pmi.tools.shuffle_configuration(hier, 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)
        for output in [
                'excluded.None.xl.db', 'included.None.xl.db',
                'missing.None.xl.db'
        ]:
            os.unlink(output)
Ejemplo n.º 24
0
    def test_shuffle_deep(self):
        """Test moving rbs, fbs"""
        mdl = IMP.Model()
        s = IMP.pmi.topology.System(mdl)
        seqs = IMP.pmi.topology.Sequences(self.get_input_file_name('chainA.fasta'))
        st1 = s.create_state()
        mol = st1.create_molecule("GCP2_YEAST",sequence=seqs["GCP2_YEAST"][:100],chain_id='A')
        atomic_res = mol.add_structure(self.get_input_file_name('chainA.pdb'),
                                       chain_id='A',
                                       res_range=(1,100))
        mol.add_representation(mol.get_atomic_residues(),resolutions=[10])
        mol.add_representation(mol.get_non_atomic_residues(), resolutions=[10])

        mol2 = mol.create_clone('B')

        mol3 = st1.create_molecule("GCP2_YEAST_BEADS",sequence=seqs["GCP2_YEAST"][:100],chain_id='C')
        mol3.add_representation(mol3.get_non_atomic_residues(), resolutions=[10])

        hier = s.build()

        dof = IMP.pmi.dof.DegreesOfFreedom(mdl)
        dof.create_rigid_body(mol, nonrigid_parts=mol.get_non_atomic_residues())
        dof.create_rigid_body(mol2, nonrigid_parts=mol2.get_non_atomic_residues())
        dof.create_flexible_beads(mol3.get_non_atomic_residues(),max_trans=1.0)

        rbs,fbs = IMP.pmi.tools.get_rbs_and_beads([hier])

        rbs_trans_before={}
        fbs_position_before={}

        rbs_trans_after={}
        fbs_position_after={}


        for rb in rbs:
            rbs_trans_before[rb]=rb.get_reference_frame().get_transformation_to()

        for fb in fbs:
            if IMP.core.NonRigidMember.get_is_setup(fb):
                fbs_position_before[fb] = \
                        IMP.core.NonRigidMember(fb).get_internal_coordinates()
            else:
                fbs_position_before[fb]=IMP.core.XYZ(fb).get_coordinates()

        IMP.pmi.tools.shuffle_configuration(hier)

        for rb in rbs:
            rbs_trans_after[rb]=rb.get_reference_frame().get_transformation_to()

        for fb in fbs:
            if IMP.core.NonRigidMember.get_is_setup(fb):
                fbs_position_after[fb] = \
                        IMP.core.NonRigidMember(fb).get_internal_coordinates()
            else:
                fbs_position_after[fb]=IMP.core.XYZ(fb).get_coordinates()

        for fb in fbs:
            position_after=fbs_position_after[fb]
            position_before=fbs_position_before[fb]
            for i in [0,1,2]:
                self.assertNotEqual(position_after[i],position_before[i])

        for rb in rbs:
            position_after=rbs_trans_after[rb].get_translation()
            position_before=rbs_trans_before[rb].get_translation()
            rotation_after=rbs_trans_after[rb].get_rotation()*IMP.algebra.Vector3D(1,1,1)
            rotation_before=rbs_trans_before[rb].get_rotation()*IMP.algebra.Vector3D(1,1,1)
            for i in [0,1,2]:
                self.assertNotEqual(position_after[i],position_before[i])
                self.assertNotEqual(rotation_after[i],rotation_before[i])