<div dir="ltr">Hi Josh, from a very superficial look, your code to write the RMF files seems fine - do you get an output RMF file? Could you load it in Chimera?</div><div class="gmail_extra"><br><br><div class="gmail_quote">
On Tue, Jul 1, 2014 at 2:40 AM, Josh Bullock <span dir="ltr"><<a href="mailto:jma.bullock@gmail.com" target="_blank">jma.bullock@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr"><div style="font-family:arial,sans-serif;font-size:13px">Hello,</div><div style="font-family:arial,sans-serif;font-size:13px"><br></div><div style="font-family:arial,sans-serif;font-size:13px">I'm relatively new to all this so please let me know if i'm making any obvious errors ...</div>
<div style="font-family:arial,sans-serif;font-size:13px"><br></div><div style="font-family:arial,sans-serif;font-size:13px">Essentially all i'm trying to do is generate an ensemble of models made from four subunits - constrained by MS connectivity restraints. The models get scored but nothing seems to write to the pymol file. Ideally i'd like to write to an .rmf but i haven't worked that one out either ...</div>
<div style="font-family:arial,sans-serif;font-size:13px"><br></div><div style="font-family:arial,sans-serif;font-size:13px">Is this a reasonable way to go about my problem ?</div><div style="font-family:arial,sans-serif;font-size:13px">
<br></div><div style="font-family:arial,sans-serif;font-size:13px">Many thanks,</div><div style="font-family:arial,sans-serif;font-size:13px"><br></div><div style="font-family:arial,sans-serif;font-size:13px">Josh</div><div style="font-family:arial,sans-serif;font-size:13px">
<br></div><div><div><font face="arial, sans-serif">-------------------------------------------</font></div><div><font face="arial, sans-serif"><br></font></div><div><font face="arial, sans-serif">import IMP</font></div>
<div><font face="arial, sans-serif">import IMP.atom</font></div><div><font face="arial, sans-serif">import IMP.rmf</font></div><div><font face="arial, sans-serif">import inspect</font></div><div><font face="arial, sans-serif">import IMP.container</font></div>
<div><font face="arial, sans-serif">import IMP.display</font></div><div><font face="arial, sans-serif">import IMP.statistics</font></div><div><font face="arial, sans-serif">#import IMP.example</font></div>
<div><font face="arial, sans-serif">import sys, math, os, optparse</font></div><div><font face="arial, sans-serif">import RMF</font></div><div><font face="arial, sans-serif"><br></font></div><div><font face="arial, sans-serif">from optparse import OptionParser</font></div>
<div><font face="arial, sans-serif"><br></font></div><div><font face="arial, sans-serif"><br></font></div><div><font face="arial, sans-serif"># Convert the arguments into strings and number</font></div><div>
<font face="arial, sans-serif">Firstpdb = str(sys.argv[1])</font></div><div><font face="arial, sans-serif">Secondpdb = str(sys.argv[2])</font></div><div><font face="arial, sans-serif">Thirdpdb = str(sys.argv[3])</font></div>
<div><font face="arial, sans-serif">Fourthpdb = str(sys.argv[4])</font></div><div><font face="arial, sans-serif">models = float(sys.argv[5])</font></div><div><font face="arial, sans-serif"><br></font></div>
<div><font face="arial, sans-serif">#***************************************** </font></div><div><font face="arial, sans-serif"><br></font></div><div><font face="arial, sans-serif"># the spring constant to use, it doesnt really matter</font></div>
<div><font face="arial, sans-serif">k=100</font></div><div><font face="arial, sans-serif"># the target resolution for the representation, this is used to specify how detailed</font></div><div><font face="arial, sans-serif"># the representation used should be</font></div>
<div><font face="arial, sans-serif">resolution=300</font></div><div><font face="arial, sans-serif"># the box to perform everything </font></div><div><font face="arial, sans-serif">bb=IMP.algebra.BoundingBox3D(IMP.algebra.Vector3D(0,0,0),</font></div>
<div><font face="arial, sans-serif"> IMP.algebra.Vector3D(300, 300, 300))</font></div><div><font face="arial, sans-serif"><br></font></div><div><font face="arial, sans-serif"><br>
</font></div><div><font face="arial, sans-serif"># this function creates the molecular hierarchies for the various involved proteins</font></div><div><font face="arial, sans-serif">def create_representation():</font></div>
<div><font face="arial, sans-serif"> m= IMP.Model()</font></div><div><font face="arial, sans-serif"> all=IMP.atom.Hierarchy.setup_particle(IMP.Particle(m))</font></div><div><font face="arial, sans-serif"> all.set_name("the universe")</font></div>
<div><font face="arial, sans-serif"> # create a protein, represented as a set of connected balls of appropriate</font></div><div><font face="arial, sans-serif"> # radii and number, chose by the resolution parameter and the number of</font></div>
<div><font face="arial, sans-serif"> # amino acids.</font></div><div><font face="arial, sans-serif"> </font></div><div><font face="arial, sans-serif"> def create_protein_from_pdbs(name, files):</font></div>
<div><font face="arial, sans-serif"> </font></div><div><font face="arial, sans-serif"> def create_from_pdb(file):</font></div><div><font face="arial, sans-serif"> sls=IMP.SetLogState(IMP.NONE)</font></div>
<div><font face="arial, sans-serif"> datadir = os.getcwd()</font></div><div><font face="arial, sans-serif"> print datadir</font></div><div><font face="arial, sans-serif"><span style="white-space:pre-wrap">        </span> t=IMP.atom.read_pdb( datadir+'/' + file, m,</font></div>
<div><font face="arial, sans-serif"> IMP.atom.ATOMPDBSelector())</font></div><div><font face="arial, sans-serif"> del sls</font></div><div><font face="arial, sans-serif"> #IMP.atom.show_molecular_hierarchy(t)</font></div>
<div><font face="arial, sans-serif"> c=IMP.atom.Chain(IMP.atom.get_by_type(t, IMP.atom.CHAIN_TYPE)[0])</font></div><div><font face="arial, sans-serif"> if c.get_number_of_children()==0:</font></div>
<div><font face="arial, sans-serif"> IMP.atom.show_molecular_hierarchy(t)</font></div><div><font face="arial, sans-serif"> # there is no reason to use all atoms, just approximate the pdb shape instead</font></div>
<div><font face="arial, sans-serif"> s=IMP.atom.create_simplified_along_backbone(c,</font></div><div><font face="arial, sans-serif"> resolution/300.0)</font></div>
<div><font face="arial, sans-serif"> IMP.atom.destroy(t)</font></div><div><font face="arial, sans-serif"> # make the simplified structure rigid</font></div><div><font face="arial, sans-serif"> rb=IMP.atom.create_rigid_body(s)</font></div>
<div><font face="arial, sans-serif"># rb=IMP.atom.create_rigid_body(c)</font></div><div><font face="arial, sans-serif"> rb.set_coordinates_are_optimized(True)</font></div><div><font face="arial, sans-serif"> return s</font></div>
<div><font face="arial, sans-serif"># return c </font></div><div><font face="arial, sans-serif"><br></font></div><div><font face="arial, sans-serif"> h= create_from_pdb(files[0])</font></div>
<div><font face="arial, sans-serif"> h.set_name(name)</font></div><div><font face="arial, sans-serif"> all.add_child(h)</font></div><div><font face="arial, sans-serif"><br></font></div><div>
<font face="arial, sans-serif"> create_protein_from_pdbs("A", [Firstpdb])</font></div><div><font face="arial, sans-serif"> create_protein_from_pdbs("B", [Secondpdb])</font></div><div>
<font face="arial, sans-serif"> create_protein_from_pdbs("C", [Thirdpdb])</font></div><div><font face="arial, sans-serif"> create_protein_from_pdbs("D", [Fourthpdb])</font></div><div>
<font face="arial, sans-serif"> #create_protein_from_pdbs("C", ["rpt3_imp.pdb"])</font></div><div><font face="arial, sans-serif"> return (m, all)</font></div><div><font face="arial, sans-serif"><br>
</font></div><div><font face="arial, sans-serif"># create the needed restraints and add them to the model</font></div><div><font face="arial, sans-serif"><br></font></div><div><font face="arial, sans-serif">def create_restraints(m, all):</font></div>
<div><font face="arial, sans-serif"> def add_connectivity_restraint(s):</font></div><div><font face="arial, sans-serif"> </font></div><div><font face="arial, sans-serif"> tr= IMP.core.TableRefiner()</font></div>
<div><font face="arial, sans-serif"> rps=[]</font></div><div><font face="arial, sans-serif"> for sc in s:</font></div><div><font face="arial, sans-serif"> ps= sc.get_selected_particles() </font></div>
<div><font face="arial, sans-serif"> rps.append(ps[0])</font></div><div><font face="arial, sans-serif"> tr.add_particle(ps[0], ps)</font></div><div><font face="arial, sans-serif"> </font></div>
<div><font face="arial, sans-serif"> # duplicate the IMP.atom.create_connectivity_restraint functionality</font></div><div><font face="arial, sans-serif"> </font></div><div><font face="arial, sans-serif"> score= IMP.core.KClosePairsPairScore(IMP.core.HarmonicSphereDistancePairScore(0,1),tr)</font></div>
<div><font face="arial, sans-serif"> </font></div><div><font face="arial, sans-serif"> r= IMP.core.MSConnectivityRestraint(m,score)</font></div><div><font face="arial, sans-serif"> </font></div>
<div><font face="arial, sans-serif"> iA = r.add_type([rps[0]])</font></div><div><font face="arial, sans-serif"> iB = r.add_type([rps[1]])</font></div><div><font face="arial, sans-serif"> iC = r.add_type([rps[2]])</font></div>
<div><font face="arial, sans-serif"> iD = r.add_type([rps[3]])</font></div><div><font face="arial, sans-serif"> n1 = r.add_composite([iA, iB, iC, iD])</font></div><div><font face="arial, sans-serif"> n2 = r.add_composite([iA, iB], n1)</font></div>
<div><font face="arial, sans-serif"> n3 = r.add_composite([iC, iD], n1)</font></div><div><font face="arial, sans-serif"> n4 = r.add_composite([iB, iC, iD], n1)</font></div><div><font face="arial, sans-serif"><br>
</font></div><div><font face="arial, sans-serif"> m.add_restraint(r)</font></div><div><font face="arial, sans-serif"><br></font></div><div><font face="arial, sans-serif"> evr=IMP.atom.create_excluded_volume_restraint([all])</font></div>
<div><font face="arial, sans-serif"> m.add_restraint(evr)</font></div><div><font face="arial, sans-serif"> # a Selection allows for natural specification of what the restraints act on</font></div><div>
<font face="arial, sans-serif"> S= IMP.atom.Selection</font></div><div><font face="arial, sans-serif"> sA=S(hierarchy=all, molecule="A")</font></div><div><font face="arial, sans-serif"> sB=S(hierarchy=all, molecule="B")</font></div>
<div><font face="arial, sans-serif"> sC=S(hierarchy=all, molecule="C")</font></div><div><font face="arial, sans-serif"> sD=S(hierarchy=all, molecule="D")</font></div><div><font face="arial, sans-serif"> add_connectivity_restraint([sA, sB, sC, sD])</font></div>
<div><font face="arial, sans-serif"> </font></div><div><font face="arial, sans-serif"><br></font></div><div><font face="arial, sans-serif"># find acceptable conformations of the model</font></div><div>
<font face="arial, sans-serif">def get_conformations(m):</font></div><div><font face="arial, sans-serif"> sampler= IMP.core.MCCGSampler(m)</font></div><div><font face="arial, sans-serif"> sampler.set_bounding_box(bb)</font></div>
<div><font face="arial, sans-serif"> # magic numbers, experiment with them and make them large enough for things to work</font></div><div><font face="arial, sans-serif"> sampler.set_number_of_conjugate_gradient_steps(100)</font></div>
<div><font face="arial, sans-serif"> sampler.set_number_of_monte_carlo_steps(20)</font></div><div><font face="arial, sans-serif"> sampler.set_number_of_attempts(models)</font></div><div><font face="arial, sans-serif"> # We don't care to see the output from the sampler</font></div>
<div><font face="arial, sans-serif"> sampler.set_log_level(IMP.SILENT)</font></div><div><font face="arial, sans-serif"> # return the IMP.ConfigurationSet storing all the found configurations that</font></div>
<div><font face="arial, sans-serif"> # meet the various restraint maximum scores.</font></div><div><font face="arial, sans-serif"> cs= sampler.create_sample()</font></div><div><font face="arial, sans-serif"> return cs</font></div>
<div><font face="arial, sans-serif"> </font></div><div><font face="arial, sans-serif"><br></font></div><div><font face="arial, sans-serif"># cluster the conformations and write them to a file</font></div>
<div><font face="arial, sans-serif">def analyze_conformations(cs, all, gs):</font></div><div><font face="arial, sans-serif"> # we want to cluster the configurations to make them easier to understand</font></div>
<div><font face="arial, sans-serif"> # in the case, the clustering is pretty meaningless</font></div><div><font face="arial, sans-serif"> embed= IMP.statistics.ConfigurationSetXYZEmbedding(cs,</font></div>
<div><font face="arial, sans-serif"> IMP.container.ListSingletonContainer(IMP.atom.get_leaves(all)), True)</font></div><div><font face="arial, sans-serif"> cluster= IMP.statistics.create_lloyds_kmeans(embed, 10, 10000)</font></div>
<div><font face="arial, sans-serif"> # dump each cluster center to a file so it can be viewed.</font></div><div><font face="arial, sans-serif"> for i in range(cluster.get_number_of_clusters()):</font></div>
<div><font face="arial, sans-serif"> center= cluster.get_cluster_center(i)</font></div><div><font face="arial, sans-serif"> cs.load_configuration(i)</font></div><div><font face="arial, sans-serif"> w= IMP.display.PymolWriter("cluster.%d.pym"%i)</font></div>
<div><font face="arial, sans-serif"> for g in gs:</font></div><div><font face="arial, sans-serif"> w.add_geometry(g)</font></div><div><font face="arial, sans-serif"><br></font></div><div>
<font face="arial, sans-serif"><br></font></div><div><font face="arial, sans-serif">#******************************************************************************************</font></div><div><font face="arial, sans-serif"># now do the actual work</font></div>
<div><font face="arial, sans-serif"><br></font></div><div><font face="arial, sans-serif">(m,all)= create_representation()</font></div><div><font face="arial, sans-serif">IMP.atom.show_molecular_hierarchy(all)</font></div>
<div><font face="arial, sans-serif">create_restraints(m, all)</font></div><div><font face="arial, sans-serif"><br></font></div><div><font face="arial, sans-serif"># in order to display the results, we need something that maps the particles onto</font></div>
<div><font face="arial, sans-serif"># geometric objets. The IMP.display.Geometry objects do this mapping.</font></div><div><font face="arial, sans-serif"># IMP.display.XYZRGeometry map an IMP.core.XYZR particle onto a sphere</font></div>
<div><font face="arial, sans-serif">gs=[]</font></div><div><font face="arial, sans-serif">for i in range(all.get_number_of_children()):</font></div><div><font face="arial, sans-serif"> color= IMP.display.get_display_color(i)</font></div>
<div><font face="arial, sans-serif"> n= all.get_child(i)</font></div><div><font face="arial, sans-serif"> name= n.get_name()</font></div><div><font face="arial, sans-serif"> g= IMP.atom.HierarchyGeometry(n)</font></div>
<div><font face="arial, sans-serif"> g.set_color(color)</font></div><div><font face="arial, sans-serif"> gs.append(g)</font></div><div><font face="arial, sans-serif"><br></font></div><div><font face="arial, sans-serif">cs= get_conformations(m)</font></div>
<div><font face="arial, sans-serif"><br></font></div><div><font face="arial, sans-serif">print "found", cs.get_number_of_configurations(), "solutions"</font></div><div><font face="arial, sans-serif"><br>
</font></div><div><font face="arial, sans-serif">ListScores = []</font></div><div><font face="arial, sans-serif">for i in range(0, cs.get_number_of_configurations()):</font></div><div><font face="arial, sans-serif"> cs.load_configuration(i)</font></div>
<div><font face="arial, sans-serif"> # print the configuration</font></div><div><font face="arial, sans-serif"> print "solution number: ",i,"scored :", m.evaluate(False)</font></div>
<div><font face="arial, sans-serif"> ListScores.append(m.evaluate(False))</font></div><div><font face="arial, sans-serif"> </font></div><div><font face="arial, sans-serif">f1 = open("out_scores.csv", "w")</font></div>
<div><font face="arial, sans-serif">f1.write("\n".join(map(lambda x: str(x), ListScores)))</font></div><div><font face="arial, sans-serif">f1.close()</font></div><div><font face="arial, sans-serif"><br>
</font></div><div><font face="arial, sans-serif"># for each of the configuration, dump it to a file to view in pymol</font></div><div><font face="arial, sans-serif">for i in range(0, cs.get_number_of_configurations()):</font></div>
<div><font face="arial, sans-serif"> JOSH = cs.load_configuration(i)</font></div><div><font face="arial, sans-serif"> S= IMP.atom.Selection</font></div><div><font face="arial, sans-serif"> h= IMP.atom.Hierarchy.get_children(cs)</font></div>
<div><font face="arial, sans-serif"> tfn = IMP.create_temporary_file_name("josh%d"%i, ".rmf")</font></div><div><font face="arial, sans-serif"> rh = RMF.create_rmf_file(tfn)</font></div>
<div><font face="arial, sans-serif"> </font></div><div><font face="arial, sans-serif"> # add the hierarchy to the file</font></div><div><font face="arial, sans-serif"> IMP.rmf.add_hierarchies(rh, h)</font></div>
<div><font face="arial, sans-serif"> </font></div><div><font face="arial, sans-serif"> # add the current configuration to the file as frame 0</font></div><div><font face="arial, sans-serif"> IMP.rmf.save_frame(rh)</font></div>
<div><font face="arial, sans-serif"> </font></div><div><font face="arial, sans-serif"> for g in gs:</font></div><div><font face="arial, sans-serif"> w.add_geometry(g)</font></div><div>
<font face="arial, sans-serif"><br></font></div><div><font face="arial, sans-serif">analyze_conformations(cs, all, gs)</font></div><div style="font-family:arial,sans-serif;font-size:13px"><br></div></div></div>
<br>_______________________________________________<br>
IMP-users mailing list<br>
<a href="mailto:IMP-users@salilab.org">IMP-users@salilab.org</a><br>
<a href="https://salilab.org/mailman/listinfo/imp-users" target="_blank">https://salilab.org/mailman/listinfo/imp-users</a><br>
<br></blockquote></div><br><br clear="all"><div><br></div>-- <br>Barak
</div>