<p>from <a href="https://www.blopig.com/blog/2019/08/how-to-iterate-in-pymol/" rel="nofollow noreferrer">https://www.blopig.com/blog/2019/08/how-to-iterate-in-pymol/</a></p>
<p>Example 1: Print the names of all the selected objects</p>
<p>You’ve selected several objects in PyMOL, and you want to see their names. By default, a new selection object called “(sele)” is created. We can create a Python variable called seleobjs, say, and then loop over them:</p>
<pre><code>seleobjs = cmd.get_object_list('(sele)')
    for obj in seleobjs: print obj
</code></pre>
<p>Example 2: Disable all the selected objects</p>
<p>If you still have your selection, “(sele)”, you can disable them (effectively turn them off on the right-hand sidebar):</p>
<pre><code>seleobjs = cmd.get_object_list('(sele)')
    for obj in seleobjs: cmd.disable(obj)
</code></pre>
<p>Example 3: Delete all the selected objects</p>
<p>You’re done with the objects in your selection, “(sele)”: you might be able to delete them using “delete ”, but if you can’t write a wildcard that covers all the names of the objects, you can iterate over a selection and delete them:</p>
<pre><code>seleobjs = cmd.get_object_list('(sele)')
    for obj in seleobjs: cmd.delete(obj)
</code></pre>
<p>from <a href="https://pymolwiki.org/index.php/Get_Area" rel="nofollow noreferrer">https://pymolwiki.org/index.php/Get_Area</a></p>
<p>get_area calculates the surface area in square Angstroms of the selection given. Note that the accessibility is assessed in the context of the object(s) that the selection is part of. So, to get the surface areas of e.g. a component of a complex, you should make a new object containing a copy of just that component and calculate its area.</p>
<p>please let us know if it worked</p>

CC BY-SA 4.0
2020-12-15T22:50:43.683Z
Thanks, this code is working, but I am still not able to calculate the area of selected residues. My main hurdle is how to use the get_area pymol command and incorporate in the loop.
shome
CC BY-SA 4.0
2020-12-16T13:50:11.277Z
@shome edited my answer
pippo1980
CC BY-SA 4.0
2020-12-16T14:00:06.717Z
I typed :
seleobjs = cmd.get_object_list('(sele)')
    for obj in seleobjs: get_area obj
It is showing me invalid syntax..
shome
CC BY-SA 4.0
2020-12-16T14:24:24.310Z
cmd.get_area(str selection="(all)", int state=1, int load_b=0)     try with Parentheses (Round Berackets)
pippo1980
CC BY-SA 4.0
2020-12-16T15:10:56.643Z
showing invalid syntax
shome
CC BY-SA 4.0
2020-12-16T15:12:38.653Z
both get_area(obj) and cmd.get_area(obj) ?
pippo1980
CC BY-SA 4.0
2020-12-15T19:13:55.397Z
2020-12-16T09:23:50.497Z
2020-12-16T09:23:50.497Z
pippo1980
<p>Ok went back to this question having <code>pymol</code> within a hand's reach this time. Question is not really clear to me so I am posting a reasonable (to me) version of the question into a new code snippet;</p>
<p>I am using two PDBs containing <code>ATP</code> as ligand <code>'3dgl.pdb', '2p09.pdb'</code></p>
<p>code:</p>
<pre><code>import pymol


list_pdbs = ['3dgl.pdb', '2p09.pdb']


pymol.finish_launching()



for _i in list_pdbs :
    
    pymol.cmd.load( _i, _i.rstrip('.pdb'))


objs = pymol.cmd.get_object_list(selection='(all)')

print('structure loaded : ' , objs)


pymol.cmd.remove('resn HOH')

for _i in objs:
    
    
    pymol.cmd.create(_i+'_ATP_copy' ,  _i + ' and resn ATP')
    
    # print('after create ')
    
    area = pymol.cmd.get_area(_i+'_ATP_copy', quiet = 0)
    
    pymol.cmd.show('dots' , _i+'_ATP_copy')
    
    print(_i+'ATP_copy' + ' area ---&gt;  ' + str(area))

</code></pre>
<p>output:</p>
<pre><code>structure loaded :  ['3dgl', '2p09']
 cmd.get_area: 1013.704 Angstroms^2.
3dglATP_copy area ---&gt;  1013.7040405273438
 cmd.get_area: 1013.704 Angstroms^2.
2p09ATP_copy area ---&gt;  1013.7040405273438

</code></pre>
<p>picture of the <code>ATP</code> surfaces in Pymol itself,</p>
<p><a href="https://i.sstatic.net/jBaSs.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/jBaSs.png" alt="enter image description here" /></a></p>
<p>you can play with  <code>cmd.get_area(...)</code> parameters see <a href="https://pymolwiki.org/index.php/Get_area" rel="nofollow noreferrer">https://pymolwiki.org/index.php/Get_area</a></p>

CC BY-SA 4.0
2023-06-30T17:44:52.640Z
2023-06-30T17:44:52.640Z
pippo1980
<p>I want to select multiple residues from different PDB files loaded on the same pymol session.</p>
<pre><code>select resi LIG
get_area sele
</code></pre>
<p>How do I loop the above command to enable the command below:</p>
<pre><code>select ligands,resn LIG
</code></pre>

<python><pymol>
Loop Pymol command get_area
# Loop Pymol command get_area

(Asked by: username_0 on 2020-12-15)

I want to select multiple residues from different PDB files loaded on the same pymol session.
select resi LIG
get_area sele

How do I loop the above command to enable the command below:
select ligands,resn LIG

**Tags:** python, pymol

---

## 2 answers

### Answer by username_1 on 2020-12-15. Score: 3

from https://www.blopig.com/blog/2019/08/how-to-iterate-in-pymol/
Example 1: Print the names of all the selected objects
You’ve selected several objects in PyMOL, and you want to see their names. By default, a new selection object called “(sele)” is created. We can create a Python variable called seleobjs, say, and then loop over them:
seleobjs = cmd.get_object_list('(sele)')
    for obj in seleobjs: print obj

Example 2: Disable all the selected objects
If you still have your selection, “(sele)”, you can disable them (effectively turn them off on the right-hand sidebar):
seleobjs = cmd.get_object_list('(sele)')
    for obj in seleobjs: cmd.disable(obj)

Example 3: Delete all the selected objects
You’re done with the objects in your selection, “(sele)”: you might be able to delete them using “delete ”, but if you can’t write a wildcard that covers all the names of the objects, you can iterate over a selection and delete them:
seleobjs = cmd.get_object_list('(sele)')
    for obj in seleobjs: cmd.delete(obj)

from https://pymolwiki.org/index.php/Get_Area
get_area calculates the surface area in square Angstroms of the selection given. Note that the accessibility is assessed in the context of the object(s) that the selection is part of. So, to get the surface areas of e.g. a component of a complex, you should make a new object containing a copy of just that component and calculate its area.
please let us know if it worked

> **Comments:**
> **username_0**: Thanks, this code is working, but I am still not able to calculate the area of selected residues. My main hurdle is how to use the get_area pymol command and incorporate in the loop.  
> **username_1**: @shome edited my answer  
> **username_0**: I typed : seleobjs = cmd.get_object_list('(sele)')     for obj in seleobjs: get_area obj It is showing me invalid syntax..  
> **username_1**: cmd.get_area(str selection="(all)", int state=1, int load_b=0)     try with Parentheses (Round Berackets)  
> **username_0**: showing invalid syntax  
> **username_1**: both get_area(obj) and cmd.get_area(obj) ?  

---

### Answer by username_1 on 2023-06-30. Score: 1

Ok went back to this question having pymol within a hand's reach this time. Question is not really clear to me so I am posting a reasonable (to me) version of the question into a new code snippet;
I am using two PDBs containing ATP as ligand '3dgl.pdb', '2p09.pdb'
code:
import pymol


list_pdbs = ['3dgl.pdb', '2p09.pdb']


pymol.finish_launching()



for _i in list_pdbs :
    
    pymol.cmd.load( _i, _i.rstrip('.pdb'))


objs = pymol.cmd.get_object_list(selection='(all)')

print('structure loaded : ' , objs)


pymol.cmd.remove('resn HOH')

for _i in objs:
    
    
    pymol.cmd.create(_i+'_ATP_copy' ,  _i + ' and resn ATP')
    
    # print('after create ')
    
    area = pymol.cmd.get_area(_i+'_ATP_copy', quiet = 0)
    
    pymol.cmd.show('dots' , _i+'_ATP_copy')
    
    print(_i+'ATP_copy' + ' area --->  ' + str(area))


output:
structure loaded :  ['3dgl', '2p09']
 cmd.get_area: 1013.704 Angstroms^2.
3dglATP_copy area --->  1013.7040405273438
 cmd.get_area: 1013.704 Angstroms^2.
2p09ATP_copy area --->  1013.7040405273438


picture of the ATP surfaces in Pymol itself,

you can play with  cmd.get_area(...) parameters see https://pymolwiki.org/index.php/Get_area


---

