[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [IMP-users] Sampling and writing to pym/rmf



Hi Josh,Â

An IMP model contains a list of particles that are tightly associated with it (a particle does not exist outside the context of a model). Given the disclaimer that I have never used ConfigurationSet, my understanding from its documentation is that when you load a configuration, the values of the particles within the model are updated accordingly. If I understand your code correctly, 'all' is the root of the hierarchy in your model, so it is 'all' that you should add to the rmf. The values of 'all' and all of its children are supposed to update when you load a configuration, automatically.

All that being said said - use this advice at own risk, perhaps someone could advise you better. Let me know if you have more questions.

Barak


On Wed, Jul 2, 2014 at 3:42 PM, Josh Bullock <" target="_blank">> wrote:


Conceptually I do ( i think ... ) but not practically. I'm hoping to view each of the models i created - with MSrestraints - separately as an .rmf in chimera, just so i can see what i'm making !

so i have created my models using:

cs= get_conformations(m)

do i have to assign each model to a particle before i can write it to an .rmf ? Or is each model already a particle with hierarchy ?

-------------------------------------------

for i in range(0, cs.get_number_of_configurations()):
  cs.load_configuration(i)
  h = IMP.atom.Hierarchy(m)  Â# <------- how do i call the hierarchy of the current loaded configuration ?
  c = p.get_children(h)
  tfn = IMP.create_temporary_file_name("josh%d"%i, ".rmf")
  rh = RMF.create_rmf_file(tfn)
 Â
  # add the hierarchy to the file
  IMP.rmf.add_hierarchies(rh, h)
 ÂÂ
  # add the current configuration to the file as frame 0
  IMP.rmf.save_frame(rh)

Send IMP-users mailing list submissions to
    " target="_blank">

To subscribe or unsubscribe via the World Wide Web, visit
    https://salilab.org/mailman/listinfo/imp-users
or, via email, send a message with subject or body 'help' to
    " target="_blank">

You can reach the person managing the list at
    " target="_blank">

When replying, please edit your Subject line so it is more specific
than "Re: Contents of IMP-users digest..."


Today's Topics:

 Â1. Re: Sampling and writing to pym/rmf (Barak Raveh)


----------------------------------------------------------------------

Message: 1
Date: Wed, 2 Jul 2014 15:03:19 -0700

From: Barak Raveh <" target="_blank">>
To: Help and discussion for users of IMP <" target="_blank">>
Subject: Re: [IMP-users] Sampling and writing to pym/rmf
Message-ID:
    <CAHp+_UqO8rXRMsUSndbg-c0jyDxnswDe9aFKvW889gGMU=" target="_blank">>
Content-Type: text/plain; charset="utf-8"


* I meant

h = IMP.atom.Hierarchy(p)
c = p.get_children(h)

this assumes that particle p was already decorated as Hierarchy (let me
know if you are not familiar with decorators, Hierarchy, or Particle).



On Wed, Jul 2, 2014 at 3:02 PM, Barak Raveh <" target="_blank">> wrote:

> Hi Josh,
>
> I think get_children() is only a member function of Hierarchy, so you
> should do something like
>
> IMP.atom.Hierarchy(p)
> c = p.get_children()
>
> 'cs' seems to be a ConfigurationSet object - are you sure that you expect
> it to have children?
>
> What do you want to do?
>
> Cheers,
> Barak
>
> On Wed, Jul 2, 2014 at 1:42 PM, Josh Bullock <" target="_blank">>
> wrote:
>
>> ah sorry ! this line gives me the error
>>
>> h= IMP.atom.Hierarchy.get_children(cs)
>>
>> thanks
>>
>> josh
>>
>> On 2 July 2014 17:45, <" target="_blank">> wrote:
>>
>>> Send IMP-users mailing list submissions to
>>> Â Â Â Â " target="_blank">
>>>
>>> To subscribe or unsubscribe via the World Wide Web, visit
>>> Â Â Â Â https://salilab.org/mailman/listinfo/imp-users
>>> or, via email, send a message with subject or body 'help' to
>>> Â Â Â Â " target="_blank">
>>>
>>> You can reach the person managing the list at
>>> Â Â Â Â " target="_blank">
>>>
>>> When replying, please edit your Subject line so it is more specific
>>> than "Re: Contents of IMP-users digest..."
>>>
>>>
>>> Today's Topics:
>>>
>>> Â Â1. Re: Sampling and writing to pym/rmf (Barak Raveh) (Barak Raveh)
>>>
>>>
>>> ----------------------------------------------------------------------
>>>
>>> Message: 1
>>> Date: Wed, 2 Jul 2014 09:45:30 -0700
>>> From: Barak Raveh <" target="_blank">>
>>> To: Help and discussion for users of IMP <" target="_blank">>
>>> Subject: Re: [IMP-users] Sampling and writing to pym/rmf (Barak Raveh)
>>> Message-ID:
>>> Â Â Â Â <CAHp+_Uo19VasJDJYi+2CoUUu=
>>> " target="_blank">u_6duKCraVetU4dW45+>
>>> Content-Type: text/plain; charset="utf-8"
>>>
>>> Which lines throws the error?
>>>
>>>
>>> On Wed, Jul 2, 2014 at 4:56 AM, Josh Bullock <" target="_blank">>
>>> wrote:
>>>
>>> > Hi Barek,
>>> >
>>> > So I'm not giving hierarchy.get_children the correct input:
>>> >
>>> > TypeError: unbound method get_children() must be called with Hierarchy
>>> > instance as first argument (got ConfigurationSet instance instead)
>>> >
>>> > I'm not sure which argument is the hierarchy instance.
>>> >
>>> > Thanks,
>>> >
>>> > Josh
>>> >
>>> > -------------------------------------------------
>>> >
>>> > cs= get_conformations(m)
>>>
>>> >
>>> > for i in range(0, cs.get_number_of_configurations()):
>>> > Â Â JOSH = cs.load_configuration(i)
>>> > Â Â S= IMP.atom.Selection
>>> > Â Â h= IMP.atom.Hierarchy.get_children(cs)
>>> > Â Â tfn = IMP.create_temporary_file_name("josh%d"%i, ".rmf")
>>> > Â Â rh = RMF.create_rmf_file(tfn)
>>> >
>>> > On 1 July 2014 17:31, <" target="_blank">> wrote:
>>> >
>>> >> Send IMP-users mailing list submissions to
>>> >> Â Â Â Â " target="_blank">
>>> >>
>>> >> To subscribe or unsubscribe via the World Wide Web, visit
>>> >> Â Â Â Â https://salilab.org/mailman/listinfo/imp-users
>>> >> or, via email, send a message with subject or body 'help' to
>>> >> Â Â Â Â " target="_blank">
>>> >>
>>> >> You can reach the person managing the list at
>>> >> Â Â Â Â " target="_blank">
>>> >>
>>> >> When replying, please edit your Subject line so it is more specific
>>> >> than "Re: Contents of IMP-users digest..."
>>> >>
>>> >>
>>> >> Today's Topics:
>>> >>
>>> >> Â Â1. Re: Sampling and writing to pym/rmf (Barak Raveh)
>>> >>
>>> >>
>>> >> ----------------------------------------------------------------------
>>> >>
>>> >> Message: 1
>>> >> Date: Tue, 1 Jul 2014 09:31:33 -0700
>>> >> From: Barak Raveh <" target="_blank">>
>>> >> To: Help and discussion for users of IMP <" target="_blank">>
>>> >> Subject: Re: [IMP-users] Sampling and writing to pym/rmf
>>> >> Message-ID:
>>> >> Â Â Â Â <CAHp+_UowiBwJozbwOfi8yFEVt7Z8o2tEZ=
>>> >> " target="_blank">>
>>> >> Content-Type: text/plain; charset="utf-8"
>>>
>>> >>
>>> >> 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?
>>> >>
>>> >>
>>> >> On Tue, Jul 1, 2014 at 2:40 AM, Josh Bullock <" target="_blank">>
>>> >> wrote:
>>> >>
>>> >> > Hello,
>>> >> >
>>> >> > I'm relatively new to all this so please let me know if i'm making
>>> any
>>> >> > obvious errors ...
>>> >> >
>>> >> > 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 ...
>>> >> >
>>> >> > Is this a reasonable way to go about my problem ?
>>> >> >
>>> >> > Many thanks,
>>> >> >
>>> >> > Josh
>>> >> >
>>> >> > -------------------------------------------
>>> >> >
>>> >> > import IMP
>>> >> > import IMP.atom
>>> >> > import IMP.rmf
>>> >> > import inspect
>>> >> > import IMP.container
>>> >> > import IMP.display
>>> >> > import IMP.statistics
>>> >> > #import IMP.example
>>> >> > import sys, math, os, optparse
>>> >> > import RMF
>>> >> >
>>> >> > from optparse import OptionParser
>>> >> >
>>> >> >
>>> >> > # Convert the arguments into strings and number
>>> >> > Firstpdb = str(sys.argv[1])
>>> >> > Secondpdb = str(sys.argv[2])
>>> >> > Thirdpdb = str(sys.argv[3])
>>> >> > Fourthpdb = str(sys.argv[4])
>>> >> > models = float(sys.argv[5])
>>> >> >
>>> >> > #*****************************************
>>> >> >
>>> >> > # the spring constant to use, it doesnt really matter
>>> >> > k=100
>>> >> > # the target resolution for the representation, this is used to
>>> specify
>>> >> > how detailed
>>> >> > # the representation used should be
>>> >> > resolution=300
>>> >> > # the box to perform everything
>>> >> > bb=IMP.algebra.BoundingBox3D(IMP.algebra.Vector3D(0,0,0),
>>> >> > Â Â Â Â Â Â Â Â Â Â Â Â Â Â ÂIMP.algebra.Vector3D(300, 300, 300))
>>> >> >
>>> >> >
>>> >> > # this function creates the molecular hierarchies for the various
>>> >> involved
>>> >> > proteins
>>> >> > def create_representation():
>>> >> > Â Â m= IMP.Model()
>>> >> > Â Â all=IMP.atom.Hierarchy.setup_particle(IMP.Particle(m))
>>> >> > Â Â all.set_name("the universe")
>>> >> > Â Â # create a protein, represented as a set of connected balls of
>>> >> > appropriate
>>> >> > Â Â # radii and number, chose by the resolution parameter and the
>>> >> number of
>>> >> > Â Â # amino acids.
>>> >> >
>>> >> > Â Â def create_protein_from_pdbs(name, files):
>>> >> >
>>> >> > Â Â Â Â def create_from_pdb(file):
>>> >> > Â Â Â Â Â Â sls=IMP.SetLogState(IMP.NONE)
>>> >> > Â Â Â Â Â Â datadir = os.getcwd()
>>> >> > Â Â Â Â Â Â print datadir
>>> >> > Â Â t=IMP.atom.read_pdb( datadir+'/' + file, m,
>>> >> > Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â ÂIMP.atom.ATOMPDBSelector())
>>> >> > Â Â Â Â Â Â del sls
>>> >> > Â Â Â Â Â Â #IMP.atom.show_molecular_hierarchy(t)
>>> >> > Â Â Â Â Â Â c=IMP.atom.Chain(IMP.atom.get_by_type(t,
>>> >> > IMP.atom.CHAIN_TYPE)[0])
>>> >> > Â Â Â Â Â Â if c.get_number_of_children()==0:
>>> >> > Â Â Â Â Â Â Â Â IMP.atom.show_molecular_hierarchy(t)
>>> >> > Â Â Â Â Â Â # there is no reason to use all atoms, just approximate
>>> the
>>> >> > pdb shape instead
>>> >> > Â Â Â Â Â Â s=IMP.atom.create_simplified_along_backbone(c,
>>> >> >
>>> >> resolution/300.0)
>>> >> > Â Â Â Â Â Â IMP.atom.destroy(t)
>>> >> > Â Â Â Â Â Â # make the simplified structure rigid
>>> >> > Â Â Â Â Â Â rb=IMP.atom.create_rigid_body(s)
>>> >> > # Â Â Â Â Â Ârb=IMP.atom.create_rigid_body(c)
>>> >> > Â Â Â Â Â Â rb.set_coordinates_are_optimized(True)
>>> >> > Â Â Â Â Â Â return s
>>> >> > # Â Â Â Â Â Âreturn c
>>> >> >
>>> >> > Â Â Â Â h= create_from_pdb(files[0])
>>> >> > Â Â Â Â h.set_name(name)
>>> >> > Â Â Â Â all.add_child(h)
>>> >> >
>>> >> > Â Â create_protein_from_pdbs("A", [Firstpdb])
>>> >> > Â Â create_protein_from_pdbs("B", [Secondpdb])
>>> >> > Â Â create_protein_from_pdbs("C", [Thirdpdb])
>>> >> > Â Â create_protein_from_pdbs("D", [Fourthpdb])
>>> >> > Â Â #create_protein_from_pdbs("C", ["rpt3_imp.pdb"])
>>> >> > Â Â return (m, all)
>>> >> >
>>> >> > # create the needed restraints and add them to the model
>>> >> >
>>> >> > def create_restraints(m, all):
>>> >> > Â Â def add_connectivity_restraint(s):
>>> >> >
>>> >> > Â Â Â Â tr= IMP.core.TableRefiner()
>>> >> > Â Â Â Â rps=[]
>>> >> > Â Â Â Â for sc in s:
>>> >> > Â Â Â Â Â Â ps= sc.get_selected_particles()
>>> >> > Â Â Â Â Â Â rps.append(ps[0])
>>> >> > Â Â Â Â Â Â tr.add_particle(ps[0], ps)
>>> >> >
>>> >> > Â Â Â Â # duplicate the IMP.atom.create_connectivity_restraint
>>> >> > functionality
>>> >> >
>>> >> > Â Â Â Â score=
>>> >> >
>>> >>
>>> IMP.core.KClosePairsPairScore(IMP.core.HarmonicSphereDistancePairScore(0,1),tr)
>>> >> >
>>> >> > Â Â Â Â r= IMP.core.MSConnectivityRestraint(m,score)
>>> >> >
>>> >> > Â Â Â Â iA = r.add_type([rps[0]])
>>> >> > Â Â Â Â iB = r.add_type([rps[1]])
>>> >> > Â Â Â Â iC = r.add_type([rps[2]])
>>> >> > Â Â Â Â iD = r.add_type([rps[3]])
>>> >> > Â Â Â Â n1 = r.add_composite([iA, iB, iC, iD])
>>> >> > Â Â Â Â n2 = r.add_composite([iA, iB], n1)
>>> >> > Â Â Â Â n3 = r.add_composite([iC, iD], n1)
>>> >> > Â Â Â Â n4 = r.add_composite([iB, iC, iD], n1)
>>> >> >
>>> >> > Â Â Â Â m.add_restraint(r)
>>> >> >
>>> >> > Â Â evr=IMP.atom.create_excluded_volume_restraint([all])
>>> >> > Â Â m.add_restraint(evr)
>>> >> > Â Â # a Selection allows for natural specification of what the
>>> >> restraints
>>> >> > act on
>>> >> > Â Â S= IMP.atom.Selection
>>> >> > Â Â sA=S(hierarchy=all, molecule="A")
>>> >> > Â Â sB=S(hierarchy=all, molecule="B")
>>> >> > Â Â sC=S(hierarchy=all, molecule="C")
>>> >> > Â Â sD=S(hierarchy=all, molecule="D")
>>> >> > Â Â add_connectivity_restraint([sA, sB, sC, sD])
>>> >> >
>>> >> >
>>> >> > # find acceptable conformations of the model
>>> >> > def get_conformations(m):
>>> >> > Â Â sampler= IMP.core.MCCGSampler(m)
>>> >> > Â Â sampler.set_bounding_box(bb)
>>> >> > Â Â # magic numbers, experiment with them and make them large
>>> enough for
>>> >> > things to work
>>> >> > Â Â sampler.set_number_of_conjugate_gradient_steps(100)
>>> >> > Â Â sampler.set_number_of_monte_carlo_steps(20)
>>> >> > Â Â sampler.set_number_of_attempts(models)
>>> >> > Â Â # We don't care to see the output from the sampler
>>> >> > Â Â sampler.set_log_level(IMP.SILENT)
>>> >> > Â Â # return the IMP.ConfigurationSet storing all the found
>>> >> configurations
>>> >> > that
>>> >> > Â Â # meet the various restraint maximum scores.
>>> >> > Â Â cs= sampler.create_sample()
>>> >> > Â Â return cs
>>> >> >
>>> >> >
>>> >> > # cluster the conformations and write them to a file
>>> >> > def analyze_conformations(cs, all, gs):
>>> >> > Â Â # we want to cluster the configurations to make them easier to
>>> >> > understand
>>> >> > Â Â # in the case, the clustering is pretty meaningless
>>> >> > Â Â embed= IMP.statistics.ConfigurationSetXYZEmbedding(cs,
>>> >> >
>>> >> > ÂIMP.container.ListSingletonContainer(IMP.atom.get_leaves(all)),
>>> True)
>>> >> > Â Â cluster= IMP.statistics.create_lloyds_kmeans(embed, 10, 10000)
>>> >> > Â Â # dump each cluster center to a file so it can be viewed.
>>> >> > Â Â for i in range(cluster.get_number_of_clusters()):
>>> >> > Â Â Â Â center= cluster.get_cluster_center(i)
>>> >> > Â Â Â Â cs.load_configuration(i)
>>> >> > Â Â Â Â w= IMP.display.PymolWriter("cluster.%d.pym"%i)
>>> >> > Â Â Â Â for g in gs:
>>> >> > Â Â Â Â Â Â w.add_geometry(g)
>>> >> >
>>> >> >
>>> >> >
>>> >> >
>>> >>
>>> #******************************************************************************************
>>> >> > # now do the actual work
>>> >> >
>>> >> > (m,all)= create_representation()
>>> >> > IMP.atom.show_molecular_hierarchy(all)
>>> >> > create_restraints(m, all)
>>> >> >
>>> >> > # in order to display the results, we need something that maps the
>>> >> > particles onto
>>> >> > # geometric objets. The IMP.display.Geometry objects do this
>>> mapping.
>>> >> > # IMP.display.XYZRGeometry map an IMP.core.XYZR particle onto a
>>> sphere
>>> >> > gs=[]
>>> >> > for i in range(all.get_number_of_children()):
>>> >> > Â Â color= IMP.display.get_display_color(i)
>>> >> > Â Â n= all.get_child(i)
>>> >> > Â Â name= n.get_name()
>>> >> > Â Â g= IMP.atom.HierarchyGeometry(n)
>>> >> > Â Â g.set_color(color)
>>> >> > Â Â gs.append(g)
>>> >> >
>>> >> > cs= get_conformations(m)
>>> >> >
>>> >> > print "found", cs.get_number_of_configurations(), "solutions"
>>> >> >
>>> >> > ListScores = []
>>> >> > for i in range(0, cs.get_number_of_configurations()):
>>> >> > Â Â Â Â cs.load_configuration(i)
>>> >> > Â Â Â Â # print the configuration
>>> >> > Â Â Â Â print "solution number: ",i,"scored :", m.evaluate(False)
>>> >> > Â Â Â Â ListScores.append(m.evaluate(False))
>>> >> >
>>> >> > f1 = open("out_scores.csv", "w")
>>> >> > f1.write("\n".join(map(lambda x: str(x), ListScores)))
>>> >> > f1.close()
>>> >> >
>>> >> > # for each of the configuration, dump it to a file to view in pymol
>>> >> > for i in range(0, cs.get_number_of_configurations()):
>>> >> > Â Â JOSH = cs.load_configuration(i)
>>> >> > Â Â S= IMP.atom.Selection
>>> >> > Â Â h= IMP.atom.Hierarchy.get_children(cs)
>>> >> > Â Â tfn = IMP.create_temporary_file_name("josh%d"%i, ".rmf")
>>> >> > Â Â rh = RMF.create_rmf_file(tfn)
>>> >> >
>>> >> > Â Â # add the hierarchy to the file
>>> >> > Â Â IMP.rmf.add_hierarchies(rh, h)
>>> >> >
>>> >> > Â Â # add the current configuration to the file as frame 0
>>> >> > Â Â IMP.rmf.save_frame(rh)
>>> >> >
>>> >> > Â Â for g in gs:
>>> >> > Â Â Â Â w.add_geometry(g)
>>> >> >
>>> >> > analyze_conformations(cs, all, gs)
>>> >> >
>>> >> >
>>> >> > _______________________________________________
>>> >> > IMP-users mailing list
>>> >> > " target="_blank">
>>> >> > https://salilab.org/mailman/listinfo/imp-users
>>> >> >
>>> >> >
>>> >>
>>> >>
>>> >> --
>>> >> Barak
>>> >> -------------- next part --------------
>>> >> An HTML attachment was scrubbed...
>>> >> URL: <
>>> >>
>>> http://salilab.org/archives/imp-users/attachments/20140701/7b0e5f9f/attachment.html
>>> >> >
>>> >>
>>> >> ------------------------------
>>>
>>> >>
>>> >> _______________________________________________
>>> >> IMP-users mailing list
>>> >> " target="_blank">
>>> >> https://salilab.org/mailman/listinfo/imp-users
>>> >>
>>> >>
>>> >> End of IMP-users Digest, Vol 38, Issue 2
>>> >> ****************************************
>>>
>>> >>
>>> >
>>> >
>>> > _______________________________________________
>>> > IMP-users mailing list
>>> > " target="_blank">
>>> > https://salilab.org/mailman/listinfo/imp-users
>>> >
>>> >
>>>
>>>
>>> --
>>> Barak
>>> -------------- next part --------------
>>> An HTML attachment was scrubbed...
>>> URL: <
>>> http://salilab.org/archives/imp-users/attachments/20140702/081e70ca/attachment.html
>>> >
>>>
>>> ------------------------------
>>>
>>>
>>> _______________________________________________
>>> IMP-users mailing list
>>> " target="_blank">
>>> https://salilab.org/mailman/listinfo/imp-users
>>>
>>>
>>> End of IMP-users Digest, Vol 38, Issue 4
>>> ****************************************
>>>
>>
>>
>> _______________________________________________
>> IMP-users mailing list
>> " target="_blank">
>> https://salilab.org/mailman/listinfo/imp-users
>>
>>
>
>
> --
> Barak
>



--
Barak
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://salilab.org/archives/imp-users/attachments/20140702/74f552a1/attachment.html>


------------------------------

_______________________________________________
IMP-users mailing list
" target="_blank">
https://salilab.org/mailman/listinfo/imp-users


End of IMP-users Digest, Vol 38, Issue 7
****************************************


_______________________________________________
IMP-users mailing list
">
https://salilab.org/mailman/listinfo/imp-users




--
Barak