def test_set_from_rmf_roundtrip(self):
        pdbfile = self.get_input_file_name("1WCM.pdb")
        fastafile = self.get_input_file_name("1WCM.fasta.txt")
        m = IMP.Model()
        with IMP.allow_deprecated():
            simo = IMP.pmi.representation.Representation(m,upperharmonic=True,disorderedlength=False)

        domains=[("Rpb8",   "Rpb8",        0.0,   fastafile, "1WCM:I",  "BEADS", None, (1,-1),      "BEADSONLY", 20,       0,     None, 0, None, None, None),
                 ("Rpb9",   "Rpb9",        0.0,   fastafile, "1WCM:I",  "BEADS", None, (1,-1),      None, 20,              1,     None, 0, None, None, None),
                 ("Rpb10",  "Rpb10",       0.0,   fastafile, "1WCM:J",  "BEADS", None, (1,-1),      None, 20,              None,     None, 0, None, None, None),
                 ("Rpb11",  "Rpb11",       0.0,   fastafile, "1WCM:K",  pdbfile, "K",  (1,-1),      None, 20,              2,     None, 0, None, None, None),
                 ("Rpb12",  "Rpb12",       0.0,   fastafile, "1WCM:L",  pdbfile, "L",  (1,-1),      True, 20,              3,     None, 2, self.get_input_file_name("gmm_Rpb12.txt"), "gmm_Rpb12.mrc", None)]
        with IMP.allow_deprecated():
            bm=IMP.pmi.macros.BuildModel1(simo)
        bm.build_model(domains)
        simo.shuffle_configuration(100)
        simo.optimize_floppy_bodies(10, temperature=100.0)
        o=IMP.pmi.output.Output()
        o.init_rmf("test_set_from_rmf_roundtrip_1.rmf3", [simo.prot])
        o.write_rmf("test_set_from_rmf_roundtrip_1.rmf3")

        simo.dump_particle_descriptors()
        simo.shuffle_configuration(100)
        simo.optimize_floppy_bodies(10, temperature=100.0)
        o.write_rmf("test_set_from_rmf_roundtrip_1.rmf3")
        simo.load_particle_descriptors()
        o.write_rmf("test_set_from_rmf_roundtrip_1.rmf3")
        o.close_rmf("test_set_from_rmf_roundtrip_1.rmf3")

        os.unlink("test_set_from_rmf_roundtrip_1.rmf3")
예제 #2
0
    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 test_restraint_ambiguity(self):
        m = IMP.Model()
        with IMP.allow_deprecated():
            r = IMP.pmi.representation.Representation(m)
        r.create_component("ProtA", color=1.0)
        r.add_component_beads("ProtA", [(1, 10)], incoord=(0, 0, 0))
        r.create_component("ProtB", color=1.0)
        r.add_component_beads("ProtB", [(1, 10)], incoord=(0, 10, 0))
        r.add_component_beads("ProtB", [(11, 20)], incoord=(10, 10, 0))
        r.add_component_beads("ProtB", [(21, 30)], incoord=(20, 10, 0))
        r.set_floppy_bodies()

        restraints_beads = '''#
ProtA ProtB 1 1  94.81973271 1
ProtA ProtB 1 11 52.4259605298 1
ProtA ProtB 1 21 87.4778223289 1'''

        ids_map = IMP.pmi.tools.map()
        ids_map.set_map_element(25.0, 0.1)
        ids_map.set_map_element(75, 0.01)

        with IMP.allow_deprecated():
            xl = IMP.pmi.restraints.crosslinking.ISDCrossLinkMS(
                r,
                restraints_beads,
                21,
                label="XL",
                slope=0.0,
                ids_map=ids_map,
                resolution=1,
                inner_slope=0.01)

        sig = xl.get_sigma(1.0)[0]
        psi1 = xl.get_psi(25.0)[0]
        psi2 = xl.get_psi(75.0)[0]
        sig.set_scale(10.0)
        psi1.set_scale(0.1)
        psi2.set_scale(0.01)

        for i in range(100):
            r.shuffle_configuration(max_translation=10)
            for p in xl.pairs:
                p0 = p[0]
                p1 = p[1]
                ln = p[2]
                resid1 = p[3]
                chain1 = p[4]
                resid2 = p[5]
                chain2 = p[6]
                attribute = p[7]
                xlid = p[11]
                d0 = IMP.core.XYZ(p0)
                d1 = IMP.core.XYZ(p1)
                sig1 = xl.get_sigma(p[8])[0]
                sig2 = xl.get_sigma(p[9])[0]
                psi = xl.get_psi(p[10])[0]
                self.assertEqual(-log(ln.get_probability()),
                                 xl.rs.unprotected_evaluate(None))
예제 #4
0
파일: test_em_fit.py 프로젝트: bkuchhal/imp
    def test_em_pmi(self):
        """Test Gaussian setup and restraint in PMI1"""
        try:
            import sklearn
        except ImportError:
            self.skipTest("no sklearn package")

        outputobjects = []
        sampleobjects = []

        # setting up topology

        m = IMP.Model()
        with IMP.allow_deprecated():
            simo = IMP.pmi.representation.Representation(
                            m,upperharmonic=True,disorderedlength=False)

        fastadirectory = self.get_input_file_name("mediator/")
        pdbdirectory=self.get_input_file_name("mediator/")
        gmmdirectory=self.get_input_file_name("mediator/")
        midpdb="cr_mid_fullmed10.pdb"

        # compname  hier_name    color         fastafile              fastaid          pdbname      chain    resrange      read    "BEADS"ize rigid_body super_rigid_body emnum_components emtxtfilename  emmrcfilename chain of super rigid bodies

        domains_middle= [("med4",  "med4_1",    0.10,  fastadirectory+"med4.fasta",  "med4",   pdbdirectory+midpdb,   "D",    (1,131,0),    True,       20,      1,         [19,1,2],     2,   gmmdirectory+"med4_1.txt",  gmmdirectory+"med4_1.mrc",   [0]),
                         ("med4",  "med4_2",    0.10,  fastadirectory+"med4.fasta",  "med4",   "BEADS",               None,   (132,284,0),  True,       20,      2,         [19,1,2],     0,   None,  None,   [0])]

        domains=domains_middle

        with IMP.allow_deprecated():
            bm=IMP.pmi.macros.BuildModel1(simo)
        bm.build_model(domains)
        bm.scale_bead_radii(40,0.8)

        resdensities_middle=bm.get_density_hierarchies([t[1] for t in domains_middle])

        # randomize the initial configuration
        simo.shuffle_configuration(100)

        # defines the movers
        simo.set_rigid_bodies_max_rot(1.0)
        simo.set_floppy_bodies_max_trans(0.1)
        simo.set_rigid_bodies_max_trans(0.1)
        outputobjects.append(simo)
        sampleobjects.append(simo)

        # scoring function
        #simo.optimize_floppy_bodies(200)

        # middle module em density
        middle_mass=sum((IMP.atom.Mass(p).get_mass() for h in resdensities_middle for p in IMP.atom.get_leaves(h)))
        gemh = IMP.pmi.restraints.em.GaussianEMRestraint(
            resdensities_middle,
            gmmdirectory+'target_gmm.txt',
            target_mass_scale=middle_mass,
            slope=0.000001,
            target_radii_scale=3.0)
        gemh.get_restraint_set().set_was_used(True)
    def test_restraint_ambiguity(self):
        m=IMP.Model()
        with IMP.allow_deprecated():
            r = IMP.pmi.representation.Representation(m)
        r.create_component("ProtA",color=1.0)
        r.add_component_beads("ProtA", [(1,10)],incoord=(0,0,0))
        r.create_component("ProtB",color=1.0)
        r.add_component_beads("ProtB", [(1,10)],incoord=(0,10,0))
        r.add_component_beads("ProtB", [(11,20)],incoord=(10,10,0))
        r.add_component_beads("ProtB", [(21,30)],incoord=(20,10,0))
        r.set_floppy_bodies()

        restraints_beads='''#
ProtA ProtB 1 1  94.81973271 1
ProtA ProtB 1 11 52.4259605298 1
ProtA ProtB 1 21 87.4778223289 1'''


        ids_map=IMP.pmi.tools.map()
        ids_map.set_map_element(25.0,0.1)
        ids_map.set_map_element(75,0.01)

        with IMP.allow_deprecated():
            xl = IMP.pmi.restraints.crosslinking.ISDCrossLinkMS(
                            r, restraints_beads, 21, label="XL", slope=0.0,
                            ids_map=ids_map, resolution=1, inner_slope=0.01)

        sig = xl.get_sigma(1.0)[0]
        psi1 = xl.get_psi(25.0)[0]
        psi2 = xl.get_psi(75.0)[0]
        sig.set_scale(10.0)
        psi1.set_scale(0.1)
        psi2.set_scale(0.01)


        for i in range(100):
            r.shuffle_configuration(max_translation=10)
            for p in xl.pairs:
                p0 = p[0]
                p1 = p[1]
                ln = p[2]
                resid1 = p[3]
                chain1 = p[4]
                resid2 = p[5]
                chain2 = p[6]
                attribute = p[7]
                xlid=p[11]
                d0 = IMP.core.XYZ(p0)
                d1 = IMP.core.XYZ(p1)
                sig1 = xl.get_sigma(p[8])[0]
                sig2 = xl.get_sigma(p[9])[0]
                psi =  xl.get_psi(p[10])[0]
                self.assertEqual(-log(ln.get_probability()),xl.rs.unprotected_evaluate(None))
def setup_crosslinks_complex(representation, mode):

    if mode == "single_category":
        columnmap = {}
        columnmap["Protein1"] = "pep1.accession"
        columnmap["Protein2"] = "pep2.accession"
        columnmap["Residue1"] = "pep1.xlinked_aa"
        columnmap["Residue2"] = "pep2.xlinked_aa"
        columnmap["IDScore"] = None
        columnmap["XLUniqueID"] = None

        ids_map = IMP.pmi.tools.map()
        ids_map.set_map_element(1.0, 1.0)

    with IMP.allow_deprecated():
        xl = IMP.pmi.restraints.crosslinking.ISDCrossLinkMS(
            representation,
            IMP.pmi.get_data_path("polii_xlinks.csv"),
            length=21.0,
            slope=0.01,
            columnmapping=columnmap,
            ids_map=ids_map,
            resolution=1.0,
            label="XL",
            csvfile=True)
    xl.add_to_model()
    xl.set_label("XL")
    psi = xl.get_psi(1.0)[0]
    psi.set_scale(0.05)
    sigma = xl.get_sigma(1)[0]
    sigma.set_scale(10.0)
    return xl
def setup_crosslinks_beads(representation, mode):

    restraints_beads = IMP.pmi.tools.get_random_cross_link_dataset(
        representation,
        number_of_cross_links=100,
        resolution=1.0,
        avoid_same_particles=True,
        ambiguity_probability=0.3,
        confidence_score_range=[0, 100])

    ids_map = IMP.pmi.tools.map()
    ids_map.set_map_element(25.0, 0.1)
    ids_map.set_map_element(75, 0.01)

    with IMP.allow_deprecated():
        xl = IMP.pmi.restraints.crosslinking.ISDCrossLinkMS(representation,
                                                            restraints_beads,
                                                            21,
                                                            label="XL",
                                                            ids_map=ids_map,
                                                            resolution=1,
                                                            inner_slope=0.01)

    sig = xl.get_sigma(1.0)[0]
    psi1 = xl.get_psi(25.0)[0]
    psi2 = xl.get_psi(75.0)[0]
    sig.set_scale(10.0)
    psi1.set_scale(0.1)
    psi2.set_scale(0.01)

    return xl, restraints_beads
예제 #8
0
    def test_rsr_file_read(self):
        """Check reading of arbitrary Modeller restraint files"""
        e = self.get_modeller_environ()
        modmodel = model(e)
        modmodel.build_sequence('GGCC')
        open('test.rsr', 'w').write('MODELLER5 VERSION: MODELLER FORMAT\n'
                                    'R    3   1   1   1   2   2   0     3'
                                    '     2       1.5380    0.0364')
        modmodel.restraints.append('test.rsr')
        # Deprecated interface
        m = IMP.Model()
        loader = IMP.modeller.ModelLoader(modmodel)
        protein = loader.load_atoms(m)
        with IMP.allow_deprecated():
            r = IMP.modeller.load_restraints_file('test.rsr', protein)
        self.assertIsInstance(r, list)
        sf = IMP.core.RestraintsScoringFunction(r)
        assertSimilarModellerIMPScores(self, sf, modmodel, protein)

        # Need atoms before loading restraints
        m = IMP.Model()
        loader = IMP.modeller.ModelLoader(modmodel)
        self.assertRaises(ValueError, loader.load_static_restraints_file,
                          'test.rsr')
        # New interface
        protein = loader.load_atoms(m)
        sf = IMP.core.RestraintsScoringFunction(list(
                                loader.load_static_restraints_file('test.rsr')))
        assertSimilarModellerIMPScores(self, sf, modmodel, protein)
        os.unlink('test.rsr')
def setup_crosslinks_complex(representation,mode):

    if mode=="single_category":
        columnmap={}
        columnmap["Protein1"]="pep1.accession"
        columnmap["Protein2"]="pep2.accession"
        columnmap["Residue1"]="pep1.xlinked_aa"
        columnmap["Residue2"]="pep2.xlinked_aa"
        columnmap["IDScore"]=None
        columnmap["XLUniqueID"]=None

        ids_map=IMP.pmi.tools.map()
        ids_map.set_map_element(1.0,1.0)

    with IMP.allow_deprecated():
        xl = IMP.pmi.restraints.crosslinking.ISDCrossLinkMS(representation,
                               IMP.pmi.get_data_path("polii_xlinks.csv"),
                               length=21.0,
                               slope=0.01,
                               columnmapping=columnmap,
                               ids_map=ids_map,
                               resolution=1.0,
                               label="XL",
                               csvfile=True)
    xl.add_to_model()
    xl.set_label("XL")
    psi=xl.get_psi(1.0)[0]
    psi.set_scale(0.05)
    sigma=xl.get_sigma(1)[0]
    sigma.set_scale(10.0)
    return xl
예제 #10
0
 def test_init_table(self):
     if matplotlib is None:
         self.skipTest("no matplotlib module")
     cldb = self.init_crosslink_db()
     self.init_representation_complex()
     with IMP.allow_deprecated():
         xlt = IMP.pmi.io.xltable.XLTable(35)
     prots = ["Rpb1", "Rpb2", "Rpb3", "Rpb4"]
     chains = "ABCD"
     for n, prot in enumerate(prots):
         xlt.load_sequence_from_fasta_file(
             self.get_input_file_name("1WCM.fasta.txt"),
             id_in_fasta_file="1WCM:" + chains[n],
             protein_name=prot)
     xlt.load_rmf_coordinates("expensive_test_io_xtable.rmf", 0, prots)
     xlt.load_crosslinks(cldb)
     xlt.setup_contact_map()
     xlt.load_pdb_coordinates(self.get_input_file_name('1WCM.pdb'),
                              {'A': 'Rpb1'})
     xlt.plot_table(prot_listx=prots,
                    prot_listy=prots,
                    alphablend=0.4,
                    scale_symbol_size=1.1,
                    gap_between_components=50,
                    filename="XL_table.pdf",
                    contactmap=True,
                    crosslink_threshold=35.0,
                    display_residue_pairs=False)
예제 #11
0
    def init_representation_complex(self):
        m = IMP.Model()
        pdbfile = self.get_input_file_name("1WCM.pdb")
        fastafile = self.get_input_file_name("1WCM.fasta.txt")
        components = ["Rpb1","Rpb2","Rpb3","Rpb4"]
        chains = "ABCD"
        colors = [0.,0.1,0.5,1.0]
        beadsize = 20
        fastids = IMP.pmi.tools.get_ids_from_fasta_file(fastafile)

        with IMP.allow_deprecated():
            r = IMP.pmi.representation.Representation(m)
        hierarchies = {}
        for n in range(len(components)):
            r.create_component(components[n], color=colors[n])
            r.add_component_sequence(components[n], fastafile,
                                     id="1WCM:"+chains[n])
            hierarchies[components[n]] = r.autobuild_model(
                components[n], pdbfile, chains[n],
                resolutions=[1, 10, 100], missingbeadsize=beadsize)
            r.setup_component_sequence_connectivity(components[n], 1)

        o=IMP.pmi.output.Output()
        o.init_rmf("expensive_test_io_xtable.rmf",[r.prot])
        o.write_rmf("expensive_test_io_xtable.rmf")
        o.close_rmf("expensive_test_io_xtable.rmf")
예제 #12
0
    def test_rsr_file_read(self):
        """Check reading of arbitrary Modeller restraint files"""
        e = self.get_modeller_environ()
        modmodel = model(e)
        modmodel.build_sequence('GGCC')
        open('test.rsr', 'w').write('MODELLER5 VERSION: MODELLER FORMAT\n'
                                    'R    3   1   1   1   2   2   0     3'
                                    '     2       1.5380    0.0364')
        modmodel.restraints.append('test.rsr')
        # Deprecated interface
        m = IMP.Model()
        loader = IMP.modeller.ModelLoader(modmodel)
        protein = loader.load_atoms(m)
        with IMP.allow_deprecated():
            r = IMP.modeller.load_restraints_file('test.rsr', protein)
        self.assertIsInstance(r, list)
        sf = IMP.core.RestraintsScoringFunction(r)
        assertSimilarModellerIMPScores(self, sf, modmodel, protein)

        # Need atoms before loading restraints
        m = IMP.Model()
        loader = IMP.modeller.ModelLoader(modmodel)
        self.assertRaises(ValueError, loader.load_static_restraints_file,
                          'test.rsr')
        # New interface
        protein = loader.load_atoms(m)
        sf = IMP.core.RestraintsScoringFunction(
            list(loader.load_static_restraints_file('test.rsr')))
        assertSimilarModellerIMPScores(self, sf, modmodel, protein)
        os.unlink('test.rsr')
예제 #13
0
    def test_restraint_probability_beads(self):
        m = IMP.Model()
        with IMP.allow_deprecated():
            r = IMP.pmi.representation.Representation(m)
        r.create_component("ProtA", color=1.0)
        r.add_component_beads("ProtA", [(1, 10)], incoord=(0, 0, 0))
        r.create_component("ProtB", color=1.0)
        r.add_component_beads("ProtB", [(1, 10)], incoord=(0, 10, 0))
        r.set_floppy_bodies()

        xl = IMP.pmi.restraints.crosslinking_new.DisulfideCrossLinkRestraint(
            r, (1, 1, "ProtA"), (1, 1, "ProtB"),
            label="DisulfideBond1",
            resolution=1,
            slope=0.01)
        xl.add_to_model()

        p1 = xl.xl["Particle1"]
        p2 = xl.xl["Particle2"]
        sigma = xl.xl["Sigma"]
        psi = xl.xl["Psi"]

        xyz1 = IMP.core.XYZ(p1)
        xyz2 = IMP.core.XYZ(p2)

        for d in range(100):
            xyz2.set_coordinates((0, d, 0))
            test_prob = get_probability([xyz1], [xyz2], [sigma], [sigma],
                                        [psi], 6.5, 0.01)
            self.assertAlmostEqual(xl.rs.unprotected_evaluate(None),
                                   -log(test_prob),
                                   delta=0.00001)
    def test_restraint_probability_beads(self):
        m = IMP.Model()
        with IMP.allow_deprecated():
            r = IMP.pmi.representation.Representation(m)
        r.create_component("ProtA",color=1.0)
        r.add_component_beads("ProtA", [(1,10)],incoord=(0,0,0))
        r.create_component("ProtB",color=1.0)
        r.add_component_beads("ProtB", [(1,10)],incoord=(0,10,0))
        r.set_floppy_bodies()

        xl = IMP.pmi.restraints.crosslinking_new.DisulfideCrossLinkRestraint(
            r,
            (1,1,"ProtA"),
            (1,1,"ProtB"),
            label="DisulfideBond1",
            resolution=1,
            slope=0.01)
        xl.add_to_model()

        p1=xl.xl["Particle1"]
        p2=xl.xl["Particle2"]
        sigma=xl.xl["Sigma"]
        psi=xl.xl["Psi"]

        xyz1=IMP.core.XYZ(p1)
        xyz2=IMP.core.XYZ(p2)

        for d in range(100):
            xyz2.set_coordinates((0,d,0))
            test_prob=get_probability([xyz1],[xyz2],[sigma],[sigma],[psi],6.5,0.01)
            self.assertAlmostEqual(xl.rs.unprotected_evaluate(None),-log(test_prob),delta=0.00001)
예제 #15
0
 def test_init_table(self):
     if matplotlib is None:
         self.skipTest("no matplotlib module")
     cldb=self.init_crosslink_db()
     self.init_representation_complex()
     with IMP.allow_deprecated():
         xlt=IMP.pmi.io.xltable.XLTable(35)
     prots = ["Rpb1","Rpb2","Rpb3","Rpb4"]
     chains = "ABCD"
     for n,prot in enumerate(prots):
         xlt.load_sequence_from_fasta_file(self.get_input_file_name("1WCM.fasta.txt"),
                               id_in_fasta_file="1WCM:"+chains[n],
                               protein_name=prot)
     xlt.load_rmf_coordinates("expensive_test_io_xtable.rmf",0,prots)
     xlt.load_crosslinks(cldb)
     xlt.setup_contact_map()
     xlt.load_pdb_coordinates(self.get_input_file_name('1WCM.pdb'),{'A':'Rpb1'})
     xlt.plot_table(prot_listx=prots,
        prot_listy=prots,
        alphablend=0.4,
        scale_symbol_size=1.1,
        gap_between_components=50,
        filename="XL_table.pdf",
        contactmap=True,
        crosslink_threshold=35.0,
        display_residue_pairs=False)
예제 #16
0
    def init_representation_complex(self, m):
        pdbfile = self.get_input_file_name("1WCM.pdb")
        fastafile = self.get_input_file_name("1WCM.fasta.txt")
        components = ["Rpb3", "Rpb4", "Rpb5", "Rpb6"]
        chains = "CDEF"
        colors = [0., 0.1, 0.5, 1.0]
        beadsize = 20
        fastids = IMP.pmi.tools.get_ids_from_fasta_file(fastafile)

        with IMP.allow_deprecated():
            r = IMP.pmi.representation.Representation(m)
        hierarchies = {}
        for n in range(len(components)):
            r.create_component(components[n], color=colors[n])
            r.add_component_sequence(components[n],
                                     fastafile,
                                     id="1WCM:" + chains[n])
            hierarchies[components[n]] = r.autobuild_model(
                components[n],
                pdbfile,
                chains[n],
                resolutions=[1, 10, 100],
                missingbeadsize=beadsize)
            r.setup_component_sequence_connectivity(components[n], 1)

        return r
def setup_crosslinks_beads(representation,mode):

    restraints_beads=IMP.pmi.tools.get_random_cross_link_dataset(representation,
                                                number_of_cross_links=100,
                                                resolution=1.0,
                                                avoid_same_particles=True,
                                                ambiguity_probability=0.3,
                                                confidence_score_range=[0,100])

    ids_map=IMP.pmi.tools.map()
    ids_map.set_map_element(25.0,0.1)
    ids_map.set_map_element(75,0.01)

    with IMP.allow_deprecated():
        xl = IMP.pmi.restraints.crosslinking.ISDCrossLinkMS(
            representation, restraints_beads, 21, label="XL", ids_map=ids_map,
            resolution=1, inner_slope=0.01)

    sig = xl.get_sigma(1.0)[0]
    psi1 = xl.get_psi(25.0)[0]
    psi2 = xl.get_psi(75.0)[0]
    sig.set_scale(10.0)
    psi1.set_scale(0.1)
    psi2.set_scale(0.01)

    return xl,restraints_beads
예제 #18
0
    def init_representation_complex(self):
        m = IMP.Model()
        pdbfile = self.get_input_file_name("1WCM.pdb")
        fastafile = self.get_input_file_name("1WCM.fasta.txt")
        components = ["Rpb1", "Rpb2", "Rpb3", "Rpb4"]
        chains = "ABCD"
        colors = [0., 0.1, 0.5, 1.0]
        beadsize = 20
        fastids = IMP.pmi.tools.get_ids_from_fasta_file(fastafile)

        with IMP.allow_deprecated():
            r = IMP.pmi.representation.Representation(m)
        hierarchies = {}
        for n in range(len(components)):
            r.create_component(components[n], color=colors[n])
            r.add_component_sequence(components[n],
                                     fastafile,
                                     id="1WCM:" + chains[n])
            hierarchies[components[n]] = r.autobuild_model(
                components[n],
                pdbfile,
                chains[n],
                resolutions=[1, 10, 100],
                missingbeadsize=beadsize)
            r.setup_component_sequence_connectivity(components[n], 1)

        o = IMP.pmi.output.Output()
        o.init_rmf("expensive_test_io_xtable.rmf", [r.prot])
        o.write_rmf("expensive_test_io_xtable.rmf")
        o.close_rmf("expensive_test_io_xtable.rmf")
예제 #19
0
    def test_ambiguity(self):
        """Test clustering with copies"""
        if not nicemodules:
            self.skipTest("missing scipy or sklearn")

        mdl = IMP.Model()
        #expected_rmsd = self.init_with_copies(mdl)
        alignment_comp = {"Prot1":"Prot1"}
        rmsd_comp = {"Prot1":"Prot1"}

        # the code should expand into:
        #alignment_comp = {"Prot1..0":(1,-1,"Prot1",0),"Prot1..1":(1,-1,"Prot1",1)}
        #rmsd_comp = {"Prot1..0":(1,-1,"Prot1",0),"Prot1..1":(1,-1,"Prot1",1)}

        with IMP.allow_deprecated():
            am = IMP.pmi.macros.AnalysisReplicaExchange0(
                mdl,
                merge_directories=[self.get_input_file_name("pmi2_copies_0/"),
                                   self.get_input_file_name("pmi2_copies_1/")],
                global_output_directory="./")

        with IMP.test.temporary_directory() as out_dir:
            am.clustering(feature_keys=["Total_Score"],
                          alignment_components=alignment_comp,
                          rmsd_calculation_components=rmsd_comp,
                          number_of_clusters=1,
                          number_of_best_scoring_models=20,
                          outputdir=out_dir)

            # check average RMSD
            av_rmsd = am.get_cluster_rmsd(0)
            self.assertLess(av_rmsd,1.5) # if swapped it'll be 100
예제 #20
0
 def test_old(self):
     """Test reading of old-style topology file"""
     topology_file = self.get_input_file_name("topology.txt")
     with IMP.allow_deprecated():
         t = IMP.pmi.topology.TopologyReader(topology_file)
     c = t.get_components()
     self.assertEqual(len(c), 3)
     self.assertEqual(c[0].molname, "Prot1")
     self.assertEqual(os.path.abspath(c[0].fasta_file),
                      self.get_input_file_name("seqs.fasta"))
     self.assertEqual(c[1].molname, "Prot2")
     with IMP.allow_deprecated():
         # Test deprecated interface
         self.assertEqual(c[1].name, "Prot2")
         self.assertEqual(c[1].domain_name, "Prot2A")
     self.assertEqual(c[1].get_unique_name(), "Prot2..0")
     self.assertEqual(c[2].get_unique_name(), "Prot2..1")
예제 #21
0
 def test_coarsening(self):
     with IMP.allow_deprecated():
         cmhs = IMP.multifit.create_coarse_molecules_from_molecules(
                                                self.mhs, 30, self.mdl, 5)
     print(len(IMP.core.get_leaves(cmhs[0])), len(IMP.atom.get_by_type(self.mhs[0], IMP.atom.RESIDUE_TYPE)))
     print(len(IMP.core.get_leaves(cmhs[1])), len(IMP.atom.get_by_type(self.mhs[1], IMP.atom.RESIDUE_TYPE)))
     self.assertEqual(len(IMP.core.get_leaves(cmhs[0])), 5)
     self.assertEqual(len(IMP.core.get_leaves(cmhs[1])), 2)
예제 #22
0
 def test_old(self):
     """Test reading of old-style topology file"""
     topology_file = self.get_input_file_name("topology.txt")
     with IMP.allow_deprecated():
         t = IMP.pmi.topology.TopologyReader(topology_file)
     c = t.get_components()
     self.assertEqual(len(c), 3)
     self.assertEqual(c[0].molname, "Prot1")
     self.assertEqual(os.path.abspath(c[0].fasta_file),
                      self.get_input_file_name("seqs.fasta"))
     self.assertEqual(c[1].molname, "Prot2")
     with IMP.allow_deprecated():
         # Test deprecated interface
         self.assertEqual(c[1].name, "Prot2")
         self.assertEqual(c[1].domain_name, "Prot2A")
     self.assertEqual(c[1].get_unique_name(), "Prot2..0")
     self.assertEqual(c[2].get_unique_name(), "Prot2..1")
예제 #23
0
 def test_molecule_model(self):
     """Test Molecule get model"""
     model = IMP.Model()
     s = IMP.pmi.topology.System(model)
     st1 = s.create_state()
     m1 = st1.create_molecule("Prot1", sequence='A' *25)
     self.assertEqual(m1.model, model)
     with IMP.allow_deprecated():
         self.assertEqual(m1.mdl, model)
예제 #24
0
 def test_coarsening(self):
     with IMP.allow_deprecated():
         cmhs = IMP.multifit.create_coarse_molecules_from_molecules(
             self.mhs, 30, self.mdl, 5)
     print(len(IMP.core.get_leaves(cmhs[0])),
           len(IMP.atom.get_by_type(self.mhs[0], IMP.atom.RESIDUE_TYPE)))
     print(len(IMP.core.get_leaves(cmhs[1])),
           len(IMP.atom.get_by_type(self.mhs[1], IMP.atom.RESIDUE_TYPE)))
     self.assertEqual(len(IMP.core.get_leaves(cmhs[0])), 5)
     self.assertEqual(len(IMP.core.get_leaves(cmhs[1])), 2)
예제 #25
0
 def test_4(self):
     """Testing the chimera writer"""
     with IMP.allow_deprecated():
         nm = self.get_tmp_file_name("test.chimera.py")
         w = IMP.display.ChimeraWriter(nm)
         e = IMP.algebra.Ellipsoid3D(IMP.algebra.Vector3D(10, 10, 10),
                                     1, 2, 3,
                                     IMP.algebra.Rotation3D(1, 0, 0, 0))
         w.add_geometry(IMP.display.EllipsoidGeometry(e))
         self._testit(w)
예제 #26
0
    def test_excluded_volume_sphere(self):
        """Test excluded volume in PMI1"""
        pdbfile = self.get_input_file_name("mini.pdb")
        fastafile = self.get_input_file_name("mini.fasta")

        comps = ["P1", "P2", "P3"]
        chains = "ABB"
        colors = [0., 0.5, 1.0]
        beadsize = 20
        fastids = IMP.pmi.tools.get_ids_from_fasta_file(fastafile)

        m = IMP.Model()
        with IMP.allow_deprecated():
            simo = IMP.pmi.representation.Representation(m)

        simo.create_component(comps[0], color=colors[0])
        simo.add_component_sequence(comps[0], fastafile, id=fastids[0])
        simo.autobuild_model(comps[0],
                             pdbfile,
                             chains[0],
                             resolutions=[1],
                             missingbeadsize=beadsize)

        simo.create_component(comps[1], color=colors[1])
        simo.add_component_sequence(comps[1], fastafile, id=fastids[1])
        simo.autobuild_model(comps[1],
                             pdbfile,
                             chains[1],
                             resolutions=[10],
                             missingbeadsize=beadsize)

        simo.create_component(comps[2], color=colors[2])
        simo.add_component_sequence(comps[2], fastafile, id=fastids[1])
        simo.autobuild_model(comps[2],
                             pdbfile,
                             chains[2],
                             resolutions=[1, 10],
                             missingbeadsize=2)

        ev1 = IMP.pmi.restraints.stereochemistry.ExcludedVolumeSphere(simo)
        ev1.add_to_model()
        print(ev1.get_output())
        sf = IMP.core.RestraintsScoringFunction(
            IMP.pmi.tools.get_restraint_set(m))
        print(sf.evaluate(False))
        self.assertEqual(len(ev1.cpc.get_all_possible_indexes()), 16)

        ev2 = IMP.pmi.restraints.stereochemistry.ExcludedVolumeSphere(
            simo, [simo.hier_dict["P2"]], [simo.hier_dict["P3"]])
        ev2.add_to_model()
        print(ev2.get_output())
        sf = IMP.core.RestraintsScoringFunction(
            IMP.pmi.tools.get_restraint_set(m))
        print(sf.evaluate(False))
        self.assertEqual(len(ev2.cpc.get_all_possible_indexes()), 8)
예제 #27
0
    def test_build_create_gmms(self):
        """Test building with macro using sklearn to create stuff"""
        try:
            import sklearn
        except ImportError:
            self.skipTest("no sklearn package")
        mdl = IMP.Model()

        topology_file = self.get_input_file_name("topology.txt")
        t = IMP.pmi.topology.TopologyReader(topology_file)
        t.set_dir("gmm_dir", os.pardir)

        with IMP.allow_deprecated():
            bm = IMP.pmi.macros.BuildModel(
                mdl,
                component_topologies=t.component_list,
                force_create_gmm_files=True)
        rep = bm.get_representation()

        o = IMP.pmi.output.Output()
        rmf_fn = self.get_tmp_file_name("buildmodeltest.rmf")
        o.init_rmf(rmf_fn, [rep.prot])
        o.write_rmf(rmf_fn)
        o.close_rmf(rmf_fn)
        f = RMF.open_rmf_file_read_only(rmf_fn)
        r = IMP.rmf.create_hierarchies(f, mdl)[0]
        IMP.rmf.load_frame(f, RMF.FrameID(0))
        self.assertEqual(len(r.get_children()), 2)
        cdict = children_as_dict(r)
        self.assertEqual(
            set([c.get_name() for c in cdict["Prot1"].get_children()]),
            set([
                "Beads", "Prot1_Res:0", "Prot1_Res:1", "Prot1_Res:10",
                "Densities"
            ]))
        self.assertEqual(
            set([c.get_name() for c in cdict["Prot2"].get_children()]),
            set(["Prot2_Res:1", "Prot2_Res:10"]))

        p1dict = children_as_dict(cdict["Prot1"])
        self.assertEqual(len(IMP.core.get_leaves(p1dict["Prot1_Res:0"])), 57)
        self.assertEqual(len(IMP.core.get_leaves(p1dict["Prot1_Res:1"])), 7)
        self.assertEqual(len(IMP.core.get_leaves(p1dict["Prot1_Res:10"])), 2)
        self.assertEqual(len(IMP.core.get_leaves(p1dict["Beads"])), 2)
        self.assertEqual(len(IMP.core.get_leaves(p1dict["Densities"])), 1)
        p2dict = children_as_dict(cdict["Prot2"])
        self.assertEqual(len(IMP.core.get_leaves(p2dict["Prot2_Res:1"])), 13)
        self.assertEqual(len(IMP.core.get_leaves(p2dict["Prot2_Res:10"])), 2)
        for output in [
                os.path.join(os.pardir, 'Prot1.mrc'),
                os.path.join(os.pardir, 'Prot1.txt')
        ]:
            os.unlink(self.get_input_file_name(output))
예제 #28
0
 def test_create_states(self):
     """Test State-creation from System"""
     s = IMP.pmi.topology.System()
     for i in range(10):
         self.assertEqual(s.get_number_of_states(), i)
         st = s.create_state()
         self.assertEqual(st.get_hierarchy().get_parent(),
                          s.get_hierarchy())
         self.assertEqual(st.model, s.model)
         with IMP.allow_deprecated():
             self.assertEqual(st.mdl, s.model)
     self.assertEqual(s.get_number_of_states(), 10)
예제 #29
0
 def init_representation_beads(self,m):
     with IMP.allow_deprecated():
         r = IMP.pmi.representation.Representation(m)
     r.create_component("ProtA",color=1.0)
     r.add_component_beads("ProtA", [(1,10)],incoord=(0,0,0))
     r.add_component_beads("ProtA", [(11,20)],incoord=(10,0,0))
     r.add_component_beads("ProtA", [(21,30)],incoord=(20,0,0))
     r.create_component("ProtB",color=1.0)
     r.add_component_beads("ProtB", [(1,10)],incoord=(0,10,0))
     r.add_component_beads("ProtB", [(11,20)],incoord=(10,10,0))
     r.add_component_beads("ProtB", [(21,30)],incoord=(20,10,0))
     r.set_floppy_bodies()
     return r
예제 #30
0
 def test_beads_only(self):
     """Test setting up BEADS-only"""
     mdl = IMP.Model()
     topology_file = self.get_input_file_name("topology_beads.txt")
     t = IMP.pmi.topology.TopologyReader(topology_file)
     with IMP.allow_deprecated():
         bm = IMP.pmi.macros.BuildModel(mdl,
                                        component_topologies=t.component_list)
     rep = bm.get_representation()
     p1 = IMP.pmi.tools.select(rep,name='detgnt')
     p2 = IMP.pmi.tools.select(rep,name='pom152')
     self.assertTrue(IMP.core.Gaussian.get_is_setup(p1[0]))
     self.assertTrue(IMP.core.Gaussian.get_is_setup(p2[0]))
예제 #31
0
 def test_beads_only(self):
     """Test setting up BEADS-only"""
     mdl = IMP.Model()
     topology_file = self.get_input_file_name("topology_beads.txt")
     t = IMP.pmi.topology.TopologyReader(topology_file)
     with IMP.allow_deprecated():
         bm = IMP.pmi.macros.BuildModel(
             mdl, component_topologies=t.component_list)
     rep = bm.get_representation()
     p1 = IMP.pmi.tools.select(rep, name='detgnt')
     p2 = IMP.pmi.tools.select(rep, name='pom152')
     self.assertTrue(IMP.core.Gaussian.get_is_setup(p1[0]))
     self.assertTrue(IMP.core.Gaussian.get_is_setup(p2[0]))
    def test_set_from_rmf_roundtrip(self):
        pdbfile = self.get_input_file_name("1WCM.pdb")
        fastafile = self.get_input_file_name("1WCM.fasta.txt")
        m = IMP.Model()
        with IMP.allow_deprecated():
            simo = IMP.pmi.representation.Representation(
                m, upperharmonic=True, disorderedlength=False)

        domains = [
            ("Rpb8", "Rpb8", 0.0, fastafile, "1WCM:I", "BEADS", None, (1, -1),
             "BEADSONLY", 20, 0, None, 0, None, None, None),
            ("Rpb9", "Rpb9", 0.0, fastafile, "1WCM:I", "BEADS", None, (1, -1),
             None, 20, 1, None, 0, None, None, None),
            ("Rpb10", "Rpb10", 0.0, fastafile, "1WCM:J", "BEADS", None,
             (1, -1), None, 20, None, None, 0, None, None, None),
            ("Rpb11", "Rpb11", 0.0, fastafile, "1WCM:K", pdbfile, "K", (1, -1),
             None, 20, 2, None, 0, None, None, None),
            ("Rpb12", "Rpb12", 0.0, fastafile, "1WCM:L", pdbfile, "L",
             (1, -1), True, 20, 3, None, 2,
             self.get_input_file_name("gmm_Rpb12.txt"), "gmm_Rpb12.mrc", None)
        ]
        with IMP.allow_deprecated():
            bm = IMP.pmi.macros.BuildModel1(simo)
        bm.build_model(domains)
        simo.shuffle_configuration(100)
        simo.optimize_floppy_bodies(10, temperature=100.0)
        o = IMP.pmi.output.Output()
        o.init_rmf("test_set_from_rmf_roundtrip_1.rmf3", [simo.prot])
        o.write_rmf("test_set_from_rmf_roundtrip_1.rmf3")

        simo.dump_particle_descriptors()
        simo.shuffle_configuration(100)
        simo.optimize_floppy_bodies(10, temperature=100.0)
        o.write_rmf("test_set_from_rmf_roundtrip_1.rmf3")
        simo.load_particle_descriptors()
        o.write_rmf("test_set_from_rmf_roundtrip_1.rmf3")
        o.close_rmf("test_set_from_rmf_roundtrip_1.rmf3")

        os.unlink("test_set_from_rmf_roundtrip_1.rmf3")
def init_representation_beads(m):
    with IMP.allow_deprecated():
        r = IMP.pmi.representation.Representation(m)
    r.create_component("ProtA",color=1.0)
    r.add_component_beads("ProtA", [(1,10)],incoord=(0,0,0))
    r.add_component_beads("ProtA", [(11,20)],incoord=(10,0,0))
    r.add_component_beads("ProtA", [(21,30)],incoord=(20,0,0))
    r.create_component("ProtB",color=1.0)
    r.add_component_beads("ProtB", [(1,10)],incoord=(0,10,0))
    r.add_component_beads("ProtB", [(11,20)],incoord=(10,10,0))
    r.add_component_beads("ProtB", [(21,30)],incoord=(20,10,0))
    r.set_floppy_bodies()
    return r
예제 #34
0
파일: test_output.py 프로젝트: salilab/imp
 def test_get_particle_infos(self):
     """Test get_particle_infos_for_pdb_writing with no particles"""
     m = IMP.Model()
     with IMP.allow_deprecated():
         simo = IMP.pmi.representation.Representation(m)
     output = IMP.pmi.output.Output()
     output.init_pdb("test_output.pdb", simo.prot)
     info, center = output.get_particle_infos_for_pdb_writing(
                                           "test_output.pdb")
     self.assertEqual(len(info), 0)
     self.assertAlmostEqual(center[0], 0., delta=1e-5)
     self.assertAlmostEqual(center[1], 0., delta=1e-5)
     self.assertAlmostEqual(center[2], 0., delta=1e-5)
     os.unlink('test_output.pdb')
예제 #35
0
    def make_representation(self):
        pdbfile = self.get_input_file_name("nonbond.pdb")
        fastafile = self.get_input_file_name("nonbond.fasta")
        fastids = IMP.pmi.tools.get_ids_from_fasta_file(fastafile)

        m = IMP.Model()
        with IMP.allow_deprecated():
            r = IMP.pmi.representation.Representation(m)

        r.create_component("A", color=0.)
        r.add_component_sequence("A", fastafile, id=fastids[0])
        r.autobuild_model("A", pdbfile, "A", offset=1,
                          resolutions=[1, 10], missingbeadsize=1)
        return m, r
예제 #36
0
 def test_get_particle_infos(self):
     """Test get_particle_infos_for_pdb_writing with no particles"""
     m = IMP.Model()
     with IMP.allow_deprecated():
         simo = IMP.pmi.representation.Representation(m)
     output = IMP.pmi.output.Output()
     output.init_pdb("test_output.pdb", simo.prot)
     info, center = output.get_particle_infos_for_pdb_writing(
         "test_output.pdb")
     self.assertEqual(len(info), 0)
     self.assertAlmostEqual(center[0], 0., delta=1e-5)
     self.assertAlmostEqual(center[1], 0., delta=1e-5)
     self.assertAlmostEqual(center[2], 0., delta=1e-5)
     os.unlink('test_output.pdb')
    def test_set_from_rmf(self):
        """Test setting coordinates from RMF"""

        # input parameter
        pdbfile = self.get_input_file_name("mini.pdb")
        fastafile = self.get_input_file_name("mini.fasta")

        components = ["Rpb1", "Rpb2"]

        chains = "AB"

        colors = [0., 1.0]

        beadsize = 20

        fastids = IMP.pmi.tools.get_ids_from_fasta_file(fastafile)

        m = IMP.Model()
        with IMP.allow_deprecated():
            simo = IMP.pmi.representation.Representation(m)

        simo.create_component("Rpb1", color=colors[0])
        simo.add_component_sequence("Rpb1", fastafile, id=fastids[0])
        simo.autobuild_model("Rpb1",
                             pdbfile,
                             "A",
                             resolutions=[1],
                             missingbeadsize=beadsize)
        simo.setup_component_sequence_connectivity("Rpb1", 1)

        simo.create_component("Rpb2", color=colors[1])
        simo.add_component_sequence("Rpb2", fastafile, id=fastids[1])
        simo.autobuild_model("Rpb2",
                             pdbfile,
                             "B",
                             resolutions=[10],
                             missingbeadsize=beadsize)
        simo.setup_component_sequence_connectivity("Rpb2", 1)

        output = IMP.pmi.output.Output()
        output.init_rmf("test_set_coordinates_from_rmf.rmf3", [simo.prot])
        output.write_rmf("test_set_coordinates_from_rmf.rmf3")
        output.close_rmf("test_set_coordinates_from_rmf.rmf3")

        simo.set_coordinates_from_rmf("Rpb1",
                                      "test_set_coordinates_from_rmf.rmf3", 0)

        os.unlink("test_set_coordinates_from_rmf.rmf3")
예제 #38
0
 def test_5(self):
     """Testing the Chimera writer and frames"""
     name = self.get_tmp_file_name("chimera.%1%.py")
     with IMP.allow_deprecated():
         w = IMP.display.ChimeraWriter(name)
         names = []
         for i in range(0, 5):
             w.set_frame(i)
             g = IMP.display.PointGeometry(IMP.algebra.Vector3D(i, i, i))
             names.append(w.get_current_file_name())
             w.add_geometry(g)
         del w
     for n in names:
         print(n)
         contents = open(n, "r").read()
         print(contents)
예제 #39
0
 def test_5(self):
     """Testing the Chimera writer and frames"""
     name = self.get_tmp_file_name("chimera.%1%.py")
     with IMP.allow_deprecated():
         w = IMP.display.ChimeraWriter(name)
         names = []
         for i in range(0, 5):
             w.set_frame(i)
             g = IMP.display.PointGeometry(IMP.algebra.Vector3D(i, i, i))
             names.append(w.get_current_file_name())
             w.add_geometry(g)
         del w
     for n in names:
         print(n)
         contents = open(n, "r").read()
         print(contents)
예제 #40
0
 def test_standard_methods(self):
     """Test standard methods of FitRestraint objects"""
     m = IMP.Model()
     ps = []
     res = 3
     apix = 1
     radius_key = IMP.core.XYZR.get_radius_key()
     weight_key = IMP.atom.Mass.get_mass_key()
     ps.append(self.create_point_particle(m, 0, 0, 0))
     ps[-1].add_attribute(radius_key, 5)
     ps[-1].add_attribute(weight_key, 100.0)
     dmap = IMP.em.particles2density(ps, res, apix)
     r = IMP.em.FitRestraint(ps, dmap)
     self.check_standard_object_methods(r)
     # Test deprecated cast() static method
     with IMP.allow_deprecated():
         self.assertTrue(IMP.em.FitRestraint.cast(r))
         self.assertFalse(IMP.em.FitRestraint.cast(None))
예제 #41
0
 def test_reading(self):
     """Test basic reading"""
     topology_file = self.get_input_file_name("topology_new.txt")
     t = IMP.pmi.topology.TopologyReader(topology_file)
     self.assertEqual(list(t.molecules.keys()),
                      ['Prot1', 'Prot2', 'Prot3', 'Prot4', 'Prot5'])
     c1 = t.get_components()
     with IMP.allow_deprecated():
         # Test deprecated interface
         c2 = t.component_list
     for c in (c1, c2):
         self.assertEqual(len(c), 9)
         self.assertEqual(c[0].molname, "Prot1")
         self.assertEqual(c[1].molname, "Prot1")
         self.assertEqual(c[1].copyname, "1")
         self.assertEqual(c[2].get_unique_name(), "Prot2..0")
         self.assertEqual(c[3].get_unique_name(), "Prot2..1")
         self.assertEqual(c[5].get_unique_name(), "Prot2.1.1")
예제 #42
0
 def test_reading(self):
     """Test basic reading"""
     topology_file = self.get_input_file_name("topology_new.txt")
     t = IMP.pmi.topology.TopologyReader(topology_file)
     self.assertEqual(list(t.molecules.keys()),
                      ['Prot1', 'Prot2', 'Prot3', 'Prot4', 'Prot5'])
     c1 = t.get_components()
     with IMP.allow_deprecated():
         # Test deprecated interface
         c2 = t.component_list
     for c in (c1, c2):
         self.assertEqual(len(c),9)
         self.assertEqual(c[0].molname,"Prot1")
         self.assertEqual(c[1].molname,"Prot1")
         self.assertEqual(c[1].copyname,"1")
         self.assertEqual(c[2].get_unique_name(),"Prot2..0")
         self.assertEqual(c[3].get_unique_name(),"Prot2..1")
         self.assertEqual(c[5].get_unique_name(),"Prot2.1.1")
예제 #43
0
    def test_build_create_gmms(self):
        """Test building with macro using sklearn to create stuff"""
        try:
            import sklearn
        except ImportError:
            self.skipTest("no sklearn package")
        mdl = IMP.Model()

        topology_file=self.get_input_file_name("topology.txt")
        t=IMP.pmi.topology.TopologyReader(topology_file)
        t.set_dir("gmm_dir",os.pardir)

        with IMP.allow_deprecated():
            bm = IMP.pmi.macros.BuildModel(mdl,
                                           component_topologies=t.component_list,
                                           force_create_gmm_files=True)
        rep = bm.get_representation()

        o = IMP.pmi.output.Output()
        rmf_fn = self.get_tmp_file_name("buildmodeltest.rmf")
        o.init_rmf(rmf_fn, [rep.prot])
        o.write_rmf(rmf_fn)
        o.close_rmf(rmf_fn)
        f = RMF.open_rmf_file_read_only(rmf_fn)
        r = IMP.rmf.create_hierarchies(f, mdl)[0]
        IMP.rmf.load_frame(f, RMF.FrameID(0))
        self.assertEqual(len(r.get_children()),2)
        cdict=children_as_dict(r)
        self.assertEqual(set([c.get_name() for c in cdict["Prot1"].get_children()]),
                         set(["Beads", "Prot1_Res:0", "Prot1_Res:1" , "Prot1_Res:10","Densities"]))
        self.assertEqual(set([c.get_name() for c in cdict["Prot2"].get_children()]),
                         set(["Prot2_Res:1", "Prot2_Res:10"]))

        p1dict=children_as_dict(cdict["Prot1"])
        self.assertEqual(len(IMP.core.get_leaves(p1dict["Prot1_Res:0"])),57)
        self.assertEqual(len(IMP.core.get_leaves(p1dict["Prot1_Res:1"])),7)
        self.assertEqual(len(IMP.core.get_leaves(p1dict["Prot1_Res:10"])),2)
        self.assertEqual(len(IMP.core.get_leaves(p1dict["Beads"])),2)
        self.assertEqual(len(IMP.core.get_leaves(p1dict["Densities"])),1)
        p2dict=children_as_dict(cdict["Prot2"])
        self.assertEqual(len(IMP.core.get_leaves(p2dict["Prot2_Res:1"])),13)
        self.assertEqual(len(IMP.core.get_leaves(p2dict["Prot2_Res:10"])),2)
        for output in [os.path.join(os.pardir,'Prot1.mrc'),os.path.join(os.pardir,'Prot1.txt')]:
            os.unlink(self.get_input_file_name(output))
    def test_set_from_rmf(self):
        """Test setting coordinates from RMF"""

        # input parameter
        pdbfile = self.get_input_file_name("mini.pdb")
        fastafile = self.get_input_file_name("mini.fasta")

        components = ["Rpb1", "Rpb2"]

        chains = "AB"

        colors = [0., 1.0]

        beadsize = 20

        fastids = IMP.pmi.tools.get_ids_from_fasta_file(fastafile)

        m = IMP.Model()
        with IMP.allow_deprecated():
            simo = IMP.pmi.representation.Representation(m)


        simo.create_component("Rpb1", color=colors[0])
        simo.add_component_sequence("Rpb1", fastafile, id=fastids[0])
        simo.autobuild_model("Rpb1", pdbfile, "A",
                             resolutions=[1], missingbeadsize=beadsize)
        simo.setup_component_sequence_connectivity("Rpb1", 1)

        simo.create_component("Rpb2", color=colors[1])
        simo.add_component_sequence("Rpb2", fastafile, id=fastids[1])
        simo.autobuild_model("Rpb2", pdbfile, "B",
                             resolutions=[10], missingbeadsize=beadsize)
        simo.setup_component_sequence_connectivity("Rpb2", 1)

        output = IMP.pmi.output.Output()
        output.init_rmf("test_set_coordinates_from_rmf.rmf3", [simo.prot])
        output.write_rmf("test_set_coordinates_from_rmf.rmf3")
        output.close_rmf("test_set_coordinates_from_rmf.rmf3")

        simo.set_coordinates_from_rmf("Rpb1",
                                      "test_set_coordinates_from_rmf.rmf3", 0)

        os.unlink("test_set_coordinates_from_rmf.rmf3")
예제 #45
0
파일: test_io.py 프로젝트: salilab/imp
    def test_save_best_models(self):
        """Test save_best_models()"""
        m = IMP.Model()
        stat_files = [self.get_input_file_name('ministat.out')]
        feature_keys = ['ISDCrossLinkMS_Distance_interrb']
        score_key = "SimplifiedModel_Total_Score_None"

        IMP.pmi.io.save_best_models(m, './', stat_files,
                                    number_of_best_scoring_models=2,
                                    score_key=score_key,
                                    feature_keys=feature_keys)
        # This makes a (deprecated) v1 statfile
        with IMP.allow_deprecated():
            po = IMP.pmi.output.ProcessOutput('top_2.out')
        fields = po.get_fields([score_key])
        self.assertEqual(len(fields[score_key]), 2)
        self.assertAlmostEqual(float(fields[score_key][0]), 10.0, delta=0.1)
        os.unlink('top_2.rmf3')
        os.unlink('top_2.out')
예제 #46
0
파일: test_io.py 프로젝트: salilab/pmi
    def test_save_best_models(self):
        """Test save_best_models()"""
        m = IMP.Model()
        stat_files = [self.get_input_file_name('ministat.out')]
        feature_keys = ['ISDCrossLinkMS_Distance_interrb']
        score_key = "SimplifiedModel_Total_Score_None"

        IMP.pmi.io.save_best_models(m,
                                    './',
                                    stat_files,
                                    number_of_best_scoring_models=2,
                                    score_key=score_key,
                                    feature_keys=feature_keys)
        # This makes a (deprecated) v1 statfile
        with IMP.allow_deprecated():
            po = IMP.pmi.output.ProcessOutput('top_2.out')
        fields = po.get_fields([score_key])
        self.assertEqual(len(fields[score_key]), 2)
        self.assertAlmostEqual(float(fields[score_key][0]), 10.0, delta=0.1)
        os.unlink('top_2.rmf3')
        os.unlink('top_2.out')
예제 #47
0
    def test_hierarchy(self):
        """Check reading a Modeller model with one protein"""
        i_num_res_type = IMP.atom.ResidueType.get_number_unique()
        i_num_atom_type = IMP.atom.AtomType.get_number_unique()
        m = IMP.Model()
        # Test both ModelLoader class and deprecated read_pdb function
        modmodel = modeller.scripts.complete_pdb(
            self.get_environ(), self.get_input_file_name('single_protein.pdb'))
        loader = IMP.modeller.ModelLoader(modmodel)

        def test_mp(mp):
            desc = IMP.core.get_all_descendants(mp)
            f_num_res_type = IMP.atom.ResidueType.get_number_unique()
            f_num_atom_type = IMP.atom.AtomType.get_number_unique()
            mpp = mp.get_parent()
            self.assertEqual(mpp, IMP.atom.Hierarchy(),
                             "Should not have a parent")
            mpc = mp.get_child(0)
            self.assertEqual(mpc.get_parent(), mp, "Should not have a parent")
            self.assertEqual(i_num_res_type, f_num_res_type,
                             "too many residue types")
            self.assertEqual(i_num_atom_type, f_num_atom_type,
                             "too many atom types")
            self.assertEqual(46, len(desc))
            rd = IMP.atom.Residue(IMP.atom.get_residue(mp, 2).get_particle())
            at = IMP.atom.get_atom(rd, IMP.atom.AtomType("C"))
            self.assertEqual(
                IMP.atom.get_residue(at).get_index(), rd.get_index())
            self.assertEqual(rd.get_index(), 2)
            at = IMP.atom.get_atom(rd, IMP.atom.AtomType("CA"))
            self.assertAlmostEqual(IMP.atom.Charged(at).get_charge(),
                                   0.16,
                                   delta=1e-5)
            self.assertEqual(IMP.atom.CHARMMAtom(at).get_charmm_type(), 'CT1')

        test_mp(loader.load_atoms(m))
        with IMP.allow_deprecated():
            mp = IMP.modeller.read_pdb(
                self.get_input_file_name('single_protein.pdb'), m)
        test_mp(mp)
예제 #48
0
    def test_build_read_gmms(self):
        """Test building with macro BuildModel using a topology file"""
        mdl = IMP.Model()

        topology_file = self.get_input_file_name("topology.txt")
        inputdir = os.path.dirname(topology_file)
        t = IMP.pmi.topology.TopologyReader(topology_file)
        self.assertEqual(os.path.abspath(t.gmm_dir), os.path.abspath(inputdir))

        with IMP.allow_deprecated():
            bm = IMP.pmi.macros.BuildModel(
                mdl,
                component_topologies=t.component_list,
                force_create_gmm_files=False)
        rep = bm.get_representation()

        o = IMP.pmi.output.Output()
        rmf_fn = self.get_tmp_file_name("buildmodeltest.rmf")
        o.init_rmf(rmf_fn, [rep.prot])
        o.write_rmf(rmf_fn)
        o.close_rmf(rmf_fn)
        f = RMF.open_rmf_file_read_only(rmf_fn)
        r = IMP.rmf.create_hierarchies(f, mdl)[0]
        IMP.rmf.load_frame(f, RMF.FrameID(0))
        self.assertEqual(len(r.get_children()), 2)
        cdict = children_as_dict(r)
        self.assertEqual(
            set([c.get_name() for c in cdict["Prot1"].get_children()]),
            set(["Beads", "Prot1_Res:1", "Prot1_Res:10", "Densities"]))
        self.assertEqual(
            set([c.get_name() for c in cdict["Prot2"].get_children()]),
            set(["Prot2_Res:1", "Prot2_Res:10"]))
        p1dict = children_as_dict(cdict["Prot1"])
        self.assertEqual(len(IMP.core.get_leaves(p1dict["Prot1_Res:1"])), 7)
        self.assertEqual(len(IMP.core.get_leaves(p1dict["Prot1_Res:10"])), 2)
        self.assertEqual(len(IMP.core.get_leaves(p1dict["Beads"])), 2)
        self.assertEqual(len(IMP.core.get_leaves(p1dict["Densities"])), 1)
        p2dict = children_as_dict(cdict["Prot2"])
        self.assertEqual(len(IMP.core.get_leaves(p2dict["Prot2_Res:1"])), 13)
        self.assertEqual(len(IMP.core.get_leaves(p2dict["Prot2_Res:10"])), 2)
예제 #49
0
    def test_hierarchy(self):
        """Check reading a Modeller model with one protein"""
        i_num_res_type = IMP.atom.ResidueType.get_number_unique()
        i_num_atom_type = IMP.atom.AtomType.get_number_unique()
        m = IMP.Model()
        # Test both ModelLoader class and deprecated read_pdb function
        modmodel = modeller.scripts.complete_pdb(self.get_environ(),
                                                 self.get_input_file_name('single_protein.pdb'))
        loader = IMP.modeller.ModelLoader(modmodel)

        def test_mp(mp):
            desc = IMP.core.get_all_descendants(mp)
            f_num_res_type = IMP.atom.ResidueType.get_number_unique()
            f_num_atom_type = IMP.atom.AtomType.get_number_unique()
            mpp = mp.get_parent()
            self.assertEqual(mpp, IMP.atom.Hierarchy(),
                             "Should not have a parent")
            mpc = mp.get_child(0)
            self.assertEqual(mpc.get_parent(), mp,
                             "Should not have a parent")
            self.assertEqual(i_num_res_type, f_num_res_type,
                             "too many residue types")
            self.assertEqual(i_num_atom_type, f_num_atom_type,
                             "too many atom types")
            self.assertEqual(46, len(desc))
            rd = IMP.atom.Residue(IMP.atom.get_residue(mp, 2).get_particle())
            at = IMP.atom.get_atom(rd, IMP.atom.AtomType("C"))
            self.assertEqual(IMP.atom.get_residue(at).get_index(),
                             rd.get_index())
            self.assertEqual(rd.get_index(), 2)
            at = IMP.atom.get_atom(rd, IMP.atom.AtomType("CA"))
            self.assertAlmostEqual(IMP.atom.Charged(at).get_charge(),
                                   0.16, delta=1e-5)
            self.assertEqual(IMP.atom.CHARMMAtom(at).get_charmm_type(), 'CT1')
        test_mp(loader.load_atoms(m))
        with IMP.allow_deprecated():
            mp = IMP.modeller.read_pdb(
                           self.get_input_file_name('single_protein.pdb'), m)
        test_mp(mp)
예제 #50
0
    def init_representation_complex(self, m):
        pdbfile = self.get_input_file_name("1WCM.pdb")
        fastafile = self.get_input_file_name("1WCM.fasta.txt")
        components = ["Rpb3","Rpb4","Rpb5","Rpb6"]
        chains = "CDEF"
        colors = [0.,0.1,0.5,1.0]
        beadsize = 20
        fastids = IMP.pmi.tools.get_ids_from_fasta_file(fastafile)

        with IMP.allow_deprecated():
            r = IMP.pmi.representation.Representation(m)
        hierarchies = {}
        for n in range(len(components)):
            r.create_component(components[n], color=colors[n])
            r.add_component_sequence(components[n], fastafile,
                                     id="1WCM:"+chains[n])
            hierarchies[components[n]] = r.autobuild_model(
                components[n], pdbfile, chains[n],
                resolutions=[1, 10, 100], missingbeadsize=beadsize)
            r.setup_component_sequence_connectivity(components[n], 1)

        return r
예제 #51
0
    def test_build_read_gmms(self):
        """Test building with macro BuildModel using a topology file"""
        mdl = IMP.Model()

        topology_file=self.get_input_file_name("topology.txt")
        inputdir=os.path.dirname(topology_file)
        t=IMP.pmi.topology.TopologyReader(topology_file)
        self.assertEqual(os.path.abspath(t.gmm_dir),
                         os.path.abspath(inputdir))

        with IMP.allow_deprecated():
            bm = IMP.pmi.macros.BuildModel(mdl,
                                           component_topologies=t.component_list,
                                           force_create_gmm_files=False)
        rep = bm.get_representation()

        o = IMP.pmi.output.Output()
        rmf_fn = self.get_tmp_file_name("buildmodeltest.rmf")
        o.init_rmf(rmf_fn, [rep.prot])
        o.write_rmf(rmf_fn)
        o.close_rmf(rmf_fn)
        f = RMF.open_rmf_file_read_only(rmf_fn)
        r = IMP.rmf.create_hierarchies(f, mdl)[0]
        IMP.rmf.load_frame(f, RMF.FrameID(0))
        self.assertEqual(len(r.get_children()),2)
        cdict=children_as_dict(r)
        self.assertEqual(set([c.get_name() for c in cdict["Prot1"].get_children()]),
                         set(["Beads", "Prot1_Res:1" , "Prot1_Res:10","Densities"]))
        self.assertEqual(set([c.get_name() for c in cdict["Prot2"].get_children()]),
                         set(["Prot2_Res:1", "Prot2_Res:10"]))
        p1dict=children_as_dict(cdict["Prot1"])
        self.assertEqual(len(IMP.core.get_leaves(p1dict["Prot1_Res:1"])),7)
        self.assertEqual(len(IMP.core.get_leaves(p1dict["Prot1_Res:10"])),2)
        self.assertEqual(len(IMP.core.get_leaves(p1dict["Beads"])),2)
        self.assertEqual(len(IMP.core.get_leaves(p1dict["Densities"])),1)
        p2dict=children_as_dict(cdict["Prot2"])
        self.assertEqual(len(IMP.core.get_leaves(p2dict["Prot2_Res:1"])),13)
        self.assertEqual(len(IMP.core.get_leaves(p2dict["Prot2_Res:10"])),2)
예제 #52
0
    def test_hierarchy_construction(self):
        """Test construction of a hierarchy"""

        # input parameter
        pdbfile = self.get_input_file_name("mini.pdb")
        fastafile = self.get_input_file_name("mini.fasta")

        components = ["Rpb1", "Rpb2" ]
        chains = "AB"
        colors = [0.,  1.]
        beadsize = 20
        fastids = IMP.pmi.tools.get_ids_from_fasta_file(fastafile)

        m = IMP.Model()
        with IMP.allow_deprecated():
            simo = IMP.pmi.representation.Representation(m)

        for n in range(len(components)):
            simo.create_component(components[n], color=colors[n])
            simo.add_component_sequence(components[n], fastafile, id=fastids[n])
            simo.autobuild_model(
                               components[n], pdbfile, chains[n],
                               resolutions=[1, 10], missingbeadsize=beadsize)
            simo.setup_component_sequence_connectivity(components[n], 1)

        ev = IMP.pmi.restraints.stereochemistry.ExcludedVolumeSphere(
                                                    simo, resolution=10)
        ev.add_to_model()

        o = IMP.pmi.output.Output()
        o.init_rmf("conformations.rmf", [simo.prot])
        o.write_rmf("conformations.rmf")

        simo.optimize_floppy_bodies(1000)

        o.write_rmf("conformations.rmf")
        o.close_rmf("conformations.rmf")
        os.unlink('conformations.rmf')
예제 #53
0
    def test_cysteine_cross_link(self):
        """Test creation of CysteineCrossLinkRestraint"""
        with open('seq.fasta', 'w') as fh:
            fh.write('>chainA\nA\n>chainB\nE\n')
        with open('expdata.txt', 'w') as fh:
            fh.write('962 alpha 691 beta 1 Epsilon-Intra-Solvent\n')

        m = IMP.Model()
        with IMP.allow_deprecated():
            r = IMP.pmi.representation.Representation(m)
        r.create_component("alpha", color=0.25)
        r.add_component_sequence("alpha", "seq.fasta", id="chainA", offs=962)
        r.add_component_beads("alpha", [(962, 962)])

        r.create_component("beta", color=0.5)
        r.add_component_sequence("beta", "seq.fasta", id="chainB", offs=691)
        r.add_component_beads("beta", [(691, 691)])

        xl = IMP.pmi.restraints.crosslinking.CysteineCrossLinkRestraint(
            [r], filename="expdata.txt", cbeta=True)
        xl.add_to_model()
        os.unlink('seq.fasta')
        os.unlink('expdata.txt')
예제 #54
0
    def test_cysteine_cross_link(self):
        """Test creation of CysteineCrossLinkRestraint"""
        with open('seq.fasta', 'w') as fh:
            fh.write('>chainA\nA\n>chainB\nE\n')
        with open('expdata.txt', 'w') as fh:
            fh.write('962 alpha 691 beta 1 Epsilon-Intra-Solvent\n')

        m = IMP.Model()
        with IMP.allow_deprecated():
            r = IMP.pmi.representation.Representation(m)
        r.create_component("alpha",color=0.25)
        r.add_component_sequence("alpha","seq.fasta", id="chainA", offs=962)
        r.add_component_beads("alpha",[(962,962)])

        r.create_component("beta",color=0.5)
        r.add_component_sequence("beta","seq.fasta", id="chainB",offs=691)
        r.add_component_beads("beta",[(691,691)])


        xl = IMP.pmi.restraints.crosslinking.CysteineCrossLinkRestraint([r],
                                          filename="expdata.txt", cbeta=True)
        xl.add_to_model()
        os.unlink('seq.fasta')
        os.unlink('expdata.txt')
예제 #55
0
 def test_process_output_v1(self):
     """Test reading stat file (v1)"""
     with IMP.allow_deprecated():
         self._check_stat_file(
             self.get_input_file_name("./output1/statv1.out"))