Thank you. I made a few mistakes in my code. I wasn't paying attention
to the commented code because I was only trying stuff there. I still
get:
1) a bunch of 3 kb black png's
2) I still have no idea what the command cmd.get_pdbstr do
3) can you give me a line using iterate to get the residue names and numbers?
import __main__
__main__.pymol_argv = ['pymol','-qc']
import pymol
from pymol import cmd, stored, util
pymol.finish_launching()
residues = {'3s4m.pdb': {'102': 'THR',
'143': 'TYR',
'158': 'SER',
'166': 'TYR',
'173': 'TRP',
'181': 'SER',
'183': 'HIS',
'206': 'SER',
'95': 'TYR'}}
for name, data in residues.items():
for resnumber, resname in data.items():
cmd.delete('all')
bare_name = name.split('.')[0]
cmd.load(name, bare_name)
cmd.select('%s_%s%s' % (bare_name, resname, resnumber), 'byres
resn %s around 10' % resnumber)
cmd.dist('mysele_polar_conts','%s_%s%s' % (bare_name, resname,
resnumber),'all within 5 of %s_%s%s' % (bare_name, resname,
resnumber), quiet=1,mode=2,label=0,reset=1)
cmd.show_as('sticks', '%s_%s%s' % (bare_name, resname, resnumber))
util.cnc('%s_%s%s' % (bare_name, resname, resnumber))
cmd.hide('everything', 'all and not %s_%s%s' % (bare_name,
resname, resnumber))
cmd.zoom('%s_%s%s' % (bare_name, resname, resnumber), 5)
cmd.png('%s_%s%s.png' % (bare_name, resname, resnumber), ray=1)
On Tue, May 2, 2017 at 7:14 AM, Jared Sampson
<[email protected]> wrote:
> Hi Ahmad - Please see below for some suggestions on getting your script to
> do what I understand you would like to do.
>
> Cheers,
> Jared
>
>
> On May 1, 2017, at 4:54 PM, Ahmad Abdelzaher <[email protected]> wrote:
>
> OK I finally tried some of Jared suggestions, I'm not sure why
> util.cnc doesn't work I get "NameError: name 'util' is not defined",
>
>
> You will need to import the `util` namespace. Try changing the pymol
> submodule import line to:
>
> from pymol import cmd, stored, util
>
> Again, I want to color by element, second option from the gui. Also
> the script outputs black screenshots, nothing is there, so there is a
> bug somewhere! I attached the script and pdb below. I would appreciate
> your help.
>
> import __main__
> __main__.pymol_argv = ['pymol','-qc']
> import pymol
> from pymol import cmd, stored
>
> pymol.finish_launching()
>
> residues = {'3s4m.pdb': {'102': 'THR',
> '143': 'TYR',
> '158': 'SER',
> '166': 'TYR',
> '173': 'TRP',
> '181': 'SER',
> '183': 'HIS',
> '206': 'SER',
> '95': 'TYR'}}
>
> for name, data in residues.items():
> for resnumber, resname in data.items():
> cmd.delete('all')
> cmd.load(name, name)
>
>
> The load command here gives you an object called "3s4m.pdb" but you later
> try to use a selection called only "3s4m" (`bare_name`). If you leave the
> second argument off from cmd.load(), the .pdb extension will be stripped
> automatically. Alternatively, you could assign `bare_name` first and give
> that as the 2nd argument:
>
> bare_name = name.split('.')[0]
> cmd.load(name, bare_name)
>
>
> bare_name = name.split('.')[0]
> cmd.select('%s_%s%s' % (bare_name, resname, resnumber), 'byres
> resn %s around 3' % resnumber)
> #selee = cmd.get_pdbstr('%s' % name.split('.')[0])
>
>
> Since you've already assigned a variable for this, you can (and should!) use
> `bare_name` instead of `name.split('.')[0]` wherever it occurs. Also, you
> don't need to do "%"-style string formatting if your variable is a string
> and comprises the entire argument string. Simply
> `cmd.get_pdbstr(bare_name)`, for example, will work just fine.
>
> #print(selee)
> cmd.dist('mysele_polar_conts','%s_%s%s' % (bare_name, resname,
> resnumber),'all within 5 of %s_%s%s' % (name.split('.')[0], resname,
> resnumber), quiet=1,mode=2,label=0,reset=1)
> cmd.show_as('sticks', '%s_%s%s' % (bare_name, resname, resnumber))
> #util.cnc('%s' % name.split('.')[0])
> cmd.hide('everything', 'all and not %s_%s%s' % (bare_name,
> resname, resnumber))
> cmd.zoom('%s_%s%s' % (bare_name, resname, resnumber), 5)
> cmd.png('%s_%s%s.png' % (bare_name, resname, resnumber), ray=1)
>
>
> Also, to get information about residues in your selection as you asked in
> your later message, have a look at cmd.iterate().
> https://pymolwiki.org/index.php/Iterate
>
>
> Hope that helps.
>
> Cheers,
> Jared
>
>
> On Sat, Apr 29, 2017 at 3:34 PM, Ahmad Abdelzaher
> <[email protected]> wrote:
>
> Thanks Jared. A lot of fantastic tips there. Much appreciated.
>
> Regards.
>
> On Sat, Apr 29, 2017 at 6:03 AM, Jared Sampson
> <[email protected]> wrote:
>
> Hi Ahmad -
>
> Here are a few suggestions:
>
> I'm still a bit new to the API so I'm not sure which commands to use.
> At least I know I will start with cmd.select(string name, string
> selection).
>
> How can I tell Pymol to:
>
> 1) look within a certain radius distance, and return resi's within
> that distacne.
>
>
> cmd.select('mysele', 'byres all within 5 of sele')
>
> See https://pymolwiki.org/index.php/Selection_Algebra for more handy
> operators (`beyond`, `around`, `expand`, etc.)
>
>
> 2) find all polar interactions within a distance,
>
>
> You can use cmd.distance (https://pymolwiki.org/index.php/Distance), e.g.
> (as done in the GUI by [A] > find > polar contacts...)
>
> cmd.dist("mysele_polar_conts","mysele","all within 5 of
> mysele",quiet=1,mode=2,label=0,reset=1)
>
> or for a list of atoms, check out https://pymolwiki.org/index.php/Polarpairs
>
>
> use sticks,
>
>
> cmd.show('sticks', 'mysele')
>
> or to hide all other representations,
>
> cmd.show_as('sticks', 'mysele')
>
>
> color by atom
>
>
> util.cnc('mysele')
>
> I use this one all the time ("cnc" == color non-carbon). There is also
> `util.cbc` == color by chain.
>
>
> hide everything else
>
>
> cmd.hide('everything', 'all and not mysele')
>
>
> and output an image of the selections and interactions around it.
>
>
> cmd.zoom('mysele', 5)
> cmd.png('mysele.png', ray=1)
>
>
> Please feel free to throw in any useful commands that can you might think is
> helpful.
>
>
> One useful trick to learn new commands is to open a log file (via `log_open
> log.pml` or the File menu) and then perform the desired action in the GUI.
> The log file will show the API commands that are called from the GUI. It
> doesn't work for everything (e.g. wizards), but for most basic actions, it
> should be helpful. At least it will give you the right command to look up
> on the PyMOL wiki!
>
> Hope that helps.
>
> Cheers,
> Jared
>
>
> Your help is greatly appreciated.
>
> Regards.
>
> ------------------------------------------------------------------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> _______________________________________________
> PyMOL-users mailing list ([email protected])
> Info Page: https://lists.sourceforge.net/lists/listinfo/pymol-users
> Archives: http://www.mail-archive.com/[email protected]
>
>
> <3s4m.pdb><pymol_png_test.py>
>
>
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
PyMOL-users mailing list ([email protected])
Info Page: https://lists.sourceforge.net/lists/listinfo/pymol-users
Archives: http://www.mail-archive.com/[email protected]