Re: [PyMOL] efficiency assigning b-factors

2015-06-16 Thread Robert Campbell
Hi Jordan et al.,

Yes one can use the alter command with a whole selection at once and
it is much faster. I hadn't realized that until Thomas Holder helped fix
my script that appears to do what you were wanting to do:

 http://pldserver1.biochem.queensu.ca/~rlc/work/pymol/data2bfactor.py

The B-factor data is read in and assigned to a dictionary by the
"atom_data_extract" function elsewhere in the script (indexed either by
chain and residue number, or by chain and ID) and then it is applied
like this:

b_dict = atom_data_extract(data_file)
quiet = int(quiet) == 1

def b_lookup(chain, resi, name, ID, b):
def _lookup(chain, resi, name, ID):
if resi in b_dict[chain] and isinstance(b_dict[chain][resi], dict):
return b_dict[chain][resi][name][0]
else:
# find data by ID
return b_dict[chain][int(ID)][0]
try:
if not chain in b_dict:
chain = ''
b = _lookup(chain, resi, name, ID)
if not quiet: print '///%s/%s/%s new: %f' % (chain, resi, name, b)
except KeyError:
if not quiet: print '///%s/%s/%s keeping: %f' % (chain, resi, name, 
b)
return b
stored.b = b_lookup

cmd.alter(mol, '%s=stored.b(chain, resi, name, ID, %s)' % (prop, prop))
cmd.rebuild()

Hope that helps.

Cheers,
Rob

On Tue, 2015-06-16 11:10 EDT, Tsjerk Wassenaar 
wrote:

> Hi Jordan,
> 
> The answer is something like (assuming reading from a file):
> 
> newb=[float(i) for i in open("stuff.dat").read().split()]
> alter n. ca, b=newb.pop()
> spectrum b
> 
> Hope it helps,
> 
> Tsjerk
> 
> On Tue, Jun 16, 2015 at 10:25 AM, Jordan Willis
>  wrote:
> 
> > Hi Tsjerk,
> >
> > It seems everyone is pointing to this (
> > http://www.pymolwiki.org/index.php/Color#Reassigning_B-Factors_and_Coloring)
> > which I somehow missed. However, they seem to be altering one
> > residue at a time like I’m doing.
> >
> >
> > Jordan
> >
> > On Jun 15, 2015, at 11:59 PM, Tsjerk Wassenaar 
> > wrote:
> >
> > Hi Jordan,
> >
> > Yes, although I don't have the answer at hand, it has been given on
> > the user list several times. You can find it in the archives.
> >
> > Cheers,
> >
> > Tsjerk
> > On Jun 16, 2015 08:16, "Jordan Willis" 
> > wrote:
> >
> >> Hi,
> >>
> >> I have a dictionary that has a bunch of values I want to assign to
> >> b-factors in order to color by. In my script:
> >>
> >> for residue in data:
> >>cmd.alter(“resi
> >> {}”.format(residue[‘resnum’]),”b={}”.format(residue[‘value’]))
> >>
> >> This executes the alter command for each residue. For some reason,
> >> its taking forever in my script. Is there something inherently
> >> inefficient about alter? And is there anyway to fix it? Perhaps,
> >> assign a bunch of b-factors at once.
> >>
> >> Jordan
> >>
> >>
> >> --
> >>
> >> ___
> >> PyMOL-users mailing list (PyMOL-users@lists.sourceforge.net)
> >> Info Page: https://lists.sourceforge.net/lists/listinfo/pymol-users
> >> Archives:
> >> http://www.mail-archive.com/pymol-users@lists.sourceforge.net
> >>
> >
> >
> 
> 




-- 
Robert L. Campbell, Ph.D.
Senior Research Associate/Adjunct Assistant Professor
Dept. of Biomedical & Molecular Sciences, Botterell Hall Rm 644
Queen's University, 
Kingston, ON K7L 3N6  Canada
Tel: 613-533-6821
  http://pldserver1.biochem.queensu.ca/~rlc

--
___
PyMOL-users mailing list (PyMOL-users@lists.sourceforge.net)
Info Page: https://lists.sourceforge.net/lists/listinfo/pymol-users
Archives: http://www.mail-archive.com/pymol-users@lists.sourceforge.net

Re: [PyMOL] efficiency assigning b-factors

2015-06-16 Thread Thomas Holder
Hi all,

this is what I would do:

cmd.alter('all', 'b = mapping.get(resv, b)',
space={'mapping': dict((r['resnum'], r['value']) for r in data)})

Cheers,
  Thomas

On 16 Jun 2015, at 05:10, Tsjerk Wassenaar  wrote:

> Hi Jordan,
> 
> The answer is something like (assuming reading from a file):
> 
> newb=[float(i) for i in open("stuff.dat").read().split()]
> alter n. ca, b=newb.pop()
> spectrum b
> 
> Hope it helps,
> 
> Tsjerk
> 
> On Tue, Jun 16, 2015 at 10:25 AM, Jordan Willis  wrote:
> Hi Tsjerk,
> 
> It seems everyone is pointing to this 
> (http://www.pymolwiki.org/index.php/Color#Reassigning_B-Factors_and_Coloring) 
> which I somehow missed. However, they seem to be altering one residue at a 
> time like I’m doing. 
> 
> 
> Jordan
>> On Jun 15, 2015, at 11:59 PM, Tsjerk Wassenaar  wrote:
>> 
>> Hi Jordan,
>> 
>> Yes, although I don't have the answer at hand, it has been given on the user 
>> list several times. You can find it in the archives.
>> 
>> Cheers,
>> 
>> Tsjerk
>> 
>> On Jun 16, 2015 08:16, "Jordan Willis"  wrote:
>> Hi,
>> 
>> I have a dictionary that has a bunch of values I want to assign to b-factors 
>> in order to color by. In my script:
>> 
>> for residue in data:
>>cmd.alter(“resi 
>> {}”.format(residue[‘resnum’]),”b={}”.format(residue[‘value’]))
>> 
>> This executes the alter command for each residue. For some reason, its 
>> taking forever in my script. Is there something inherently inefficient about 
>> alter? And is there anyway to fix it? Perhaps, assign a bunch of b-factors 
>> at once.
>> 
>> Jordan

-- 
Thomas Holder
PyMOL Principal Developer
Schrödinger, Inc.


--
___
PyMOL-users mailing list (PyMOL-users@lists.sourceforge.net)
Info Page: https://lists.sourceforge.net/lists/listinfo/pymol-users
Archives: http://www.mail-archive.com/pymol-users@lists.sourceforge.net


Re: [PyMOL] efficiency assigning b-factors

2015-06-16 Thread Sampson, Jared
Hi Jordan -

I think you're doing it exactly the way I would, given an existing dict 
containing the values.  Note, however, that if you have multiple loaded, or 
multiple chains with the same residue numbers, you may wish to be more specific 
with your selection string; your current script will alter every residue with 
the given resi # in all chains of all loaded objects.

If you're having to do this multiple times with the same structure and it's 
slow each time (e.g. while creating a figure from a script), maybe consider 
saving a new PDB file with the modified B-factors using PyMOL's `save` command, 
so you can just load it directly.

# After your `alter` script
save myfile_mod_b.pdb, myfile

# Then next time load the new version with the same name
# as before to avoid breaking the rest of the script. Now you can
# remove the `alter` for-loop from the script.
load myfile_mod_b.pdb, myfile

Hope that helps.

Cheers,
Jared

--
Jared Sampson
Xiangpeng Kong Lab
NYU Langone Medical Center
http://kong.med.nyu.edu/






On Jun 16, 2015, at 2:15 AM, Jordan Willis 
mailto:jwillis0...@gmail.com>> wrote:

Hi,

I have a dictionary that has a bunch of values I want to assign to b-factors in 
order to color by. In my script:

for residue in data:
   cmd.alter(“resi 
{}”.format(residue[‘resnum’]),”b={}”.format(residue[‘value’]))

This executes the alter command for each residue. For some reason, its taking 
forever in my script. Is there something inherently inefficient about alter? 
And is there anyway to fix it? Perhaps, assign a bunch of b-factors at once.

Jordan
--
___
PyMOL-users mailing list 
(PyMOL-users@lists.sourceforge.net)
Info Page: https://lists.sourceforge.net/lists/listinfo/pymol-users
Archives: http://www.mail-archive.com/pymol-users@lists.sourceforge.net

--
___
PyMOL-users mailing list (PyMOL-users@lists.sourceforge.net)
Info Page: https://lists.sourceforge.net/lists/listinfo/pymol-users
Archives: http://www.mail-archive.com/pymol-users@lists.sourceforge.net

Re: [PyMOL] efficiency assigning b-factors

2015-06-16 Thread Tsjerk Wassenaar
Hi Jordan,

The answer is something like (assuming reading from a file):

newb=[float(i) for i in open("stuff.dat").read().split()]
alter n. ca, b=newb.pop()
spectrum b

Hope it helps,

Tsjerk

On Tue, Jun 16, 2015 at 10:25 AM, Jordan Willis 
wrote:

> Hi Tsjerk,
>
> It seems everyone is pointing to this (
> http://www.pymolwiki.org/index.php/Color#Reassigning_B-Factors_and_Coloring)
> which I somehow missed. However, they seem to be altering one residue at a
> time like I’m doing.
>
>
> Jordan
>
> On Jun 15, 2015, at 11:59 PM, Tsjerk Wassenaar  wrote:
>
> Hi Jordan,
>
> Yes, although I don't have the answer at hand, it has been given on the
> user list several times. You can find it in the archives.
>
> Cheers,
>
> Tsjerk
> On Jun 16, 2015 08:16, "Jordan Willis"  wrote:
>
>> Hi,
>>
>> I have a dictionary that has a bunch of values I want to assign to
>> b-factors in order to color by. In my script:
>>
>> for residue in data:
>>cmd.alter(“resi
>> {}”.format(residue[‘resnum’]),”b={}”.format(residue[‘value’]))
>>
>> This executes the alter command for each residue. For some reason, its
>> taking forever in my script. Is there something inherently inefficient
>> about alter? And is there anyway to fix it? Perhaps, assign a bunch of
>> b-factors at once.
>>
>> Jordan
>>
>>
>> --
>>
>> ___
>> PyMOL-users mailing list (PyMOL-users@lists.sourceforge.net)
>> Info Page: https://lists.sourceforge.net/lists/listinfo/pymol-users
>> Archives: http://www.mail-archive.com/pymol-users@lists.sourceforge.net
>>
>
>


-- 
Tsjerk A. Wassenaar, Ph.D.
--
___
PyMOL-users mailing list (PyMOL-users@lists.sourceforge.net)
Info Page: https://lists.sourceforge.net/lists/listinfo/pymol-users
Archives: http://www.mail-archive.com/pymol-users@lists.sourceforge.net

Re: [PyMOL] efficiency assigning b-factors

2015-06-16 Thread Jordan Willis
Hi Tsjerk,

It seems everyone is pointing to this 
(http://www.pymolwiki.org/index.php/Color#Reassigning_B-Factors_and_Coloring 
) 
which I somehow missed. However, they seem to be altering one residue at a time 
like I’m doing. 


Jordan
> On Jun 15, 2015, at 11:59 PM, Tsjerk Wassenaar  wrote:
> 
> Hi Jordan,
> 
> Yes, although I don't have the answer at hand, it has been given on the user 
> list several times. You can find it in the archives.
> 
> Cheers,
> 
> Tsjerk
> 
> On Jun 16, 2015 08:16, "Jordan Willis"  > wrote:
> Hi,
> 
> I have a dictionary that has a bunch of values I want to assign to b-factors 
> in order to color by. In my script:
> 
> for residue in data:
>cmd.alter(“resi 
> {}”.format(residue[‘resnum’]),”b={}”.format(residue[‘value’]))
> 
> This executes the alter command for each residue. For some reason, its taking 
> forever in my script. Is there something inherently inefficient about alter? 
> And is there anyway to fix it? Perhaps, assign a bunch of b-factors at once.
> 
> Jordan
> 
> --
> 
> ___
> PyMOL-users mailing list (PyMOL-users@lists.sourceforge.net 
> )
> Info Page: https://lists.sourceforge.net/lists/listinfo/pymol-users 
> 
> Archives: http://www.mail-archive.com/pymol-users@lists.sourceforge.net 
> 

--
___
PyMOL-users mailing list (PyMOL-users@lists.sourceforge.net)
Info Page: https://lists.sourceforge.net/lists/listinfo/pymol-users
Archives: http://www.mail-archive.com/pymol-users@lists.sourceforge.net

Re: [PyMOL] efficiency assigning b-factors

2015-06-16 Thread Tsjerk Wassenaar
Hi Jordan,

Yes, although I don't have the answer at hand, it has been given on the
user list several times. You can find it in the archives.

Cheers,

Tsjerk
On Jun 16, 2015 08:16, "Jordan Willis"  wrote:

> Hi,
>
> I have a dictionary that has a bunch of values I want to assign to
> b-factors in order to color by. In my script:
>
> for residue in data:
>cmd.alter(“resi
> {}”.format(residue[‘resnum’]),”b={}”.format(residue[‘value’]))
>
> This executes the alter command for each residue. For some reason, its
> taking forever in my script. Is there something inherently inefficient
> about alter? And is there anyway to fix it? Perhaps, assign a bunch of
> b-factors at once.
>
> Jordan
>
>
> --
>
> ___
> PyMOL-users mailing list (PyMOL-users@lists.sourceforge.net)
> Info Page: https://lists.sourceforge.net/lists/listinfo/pymol-users
> Archives: http://www.mail-archive.com/pymol-users@lists.sourceforge.net
>
--
___
PyMOL-users mailing list (PyMOL-users@lists.sourceforge.net)
Info Page: https://lists.sourceforge.net/lists/listinfo/pymol-users
Archives: http://www.mail-archive.com/pymol-users@lists.sourceforge.net

[PyMOL] efficiency assigning b-factors

2015-06-15 Thread Jordan Willis
Hi,

I have a dictionary that has a bunch of values I want to assign to b-factors in 
order to color by. In my script:

for residue in data:
   cmd.alter(“resi 
{}”.format(residue[‘resnum’]),”b={}”.format(residue[‘value’]))

This executes the alter command for each residue. For some reason, its taking 
forever in my script. Is there something inherently inefficient about alter? 
And is there anyway to fix it? Perhaps, assign a bunch of b-factors at once.

Jordan--
___
PyMOL-users mailing list (PyMOL-users@lists.sourceforge.net)
Info Page: https://lists.sourceforge.net/lists/listinfo/pymol-users
Archives: http://www.mail-archive.com/pymol-users@lists.sourceforge.net