<p>my attempt :</p>
<pre><code>import pymol

from pymol.cgo import *

from pymol import (
                    
                    cmd ,
                    )


print('########## PYMOL VERSION ##########################################')
print('         ',  cmd.get_version() )
print('###################################################################')


pymol.finish_launching()

cmd.fetch('1tqn')

cmd.remove('solvent')

pos = cmd.get_position()

r = 3

print('###############################################################################\n')

print('### POSITION : ' , pos,'  ###\n')

print('###############################################################################\n')



spherelist = [
    [COLOR,    1.000,    1.000,    0.000,
    SPHERE,   pos[0] , pos[1] , pos[2]  , r ],

    ]

for i in spherelist:
    
    a = str(spherelist.index(i))

    cmd.load_cgo(i, 'sphere_'+a )


cmd.zoom()

cmd.set('cartoon_transparency' , '0.5')

</code></pre>
<p>result:</p>
<p><a href="https://i.sstatic.net/Etqeo.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/Etqeo.png" alt="enter image description here" /></a></p>

CC BY-SA 4.0
2023-10-16T16:08:49.473Z
Aaah, `load_cgo()` https://pymolwiki.org/index.php/Load_CGO ("Compiled Graphics Objects"). There are also other shapes: https://pymolwiki.org/index.php/CGO_Shapes. Thank you!
jhutar
CC BY-SA 4.0
2023-10-16T10:20:28.550Z
2023-10-16T10:20:28.550Z
pippo1980
<p>I would like to add some 3D elements (balls and lines) to the PyMOL visualization to highlight some &quot;holes&quot; in the structure. Say I <code>fetch 1tqn</code> and I want to add a yellow ball somewhere (to specific coordinates, say <code>[-19, -23, -14]</code>) in the view. Or a bar from - to coordinates.</p>
<p><a href="https://i.sstatic.net/1sSQv.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/1sSQv.png" alt="enter image description here" /></a></p>
<p>I was going through wiki, did a online search but have not found a way how to add these simple 3D entities into the scene. I guess it should be trivial and I'm just using wrong queries. Because I need to add lots of these, I need to be able to do that via scripting interface.</p>
<p>Thank you in advance for any help!</p>

CC BY-SA 4.0
2023-10-16T08:59:40.483Z
see here https://stackoverflow.com/questions/2060582/draw-a-colored-sphere-from-cartesian-coordinates-in-pymol/76749167#76749167 Draw a colored sphere from cartesian coordinates in pymol  and here https://pymolwiki.org/index.php/Load_CGO and https://pymolwiki.org/index.php/CGO_Shapes
pippo1980
<pymol><modelling><3d-structure>
how to add a custom elements into PyMOL visualization?
# how to add a custom elements into PyMOL visualization?

(Asked by: username_0 on 2023-10-15)

I would like to add some 3D elements (balls and lines) to the PyMOL visualization to highlight some "holes" in the structure. Say I `fetch 1tqn` and I want to add a yellow ball somewhere (to specific coordinates, say `[-19, -23, -14]`) in the view. Or a bar from - to coordinates.

[![enter image description here](https://i.sstatic.net/1sSQv.png)](https://i.sstatic.net/1sSQv.png)

I was going through wiki, did a online search but have not found a way how to add these simple 3D entities into the scene. I guess it should be trivial and I'm just using wrong queries. Because I need to add lots of these, I need to be able to do that via scripting interface.

Thank you in advance for any help!

**Tags:** pymol, modelling, 3d-structure
> **Comments:**
> **username_1**: see here https://stackoverflow.com/questions/2060582/draw-a-colored-sphere-from-cartesian-coordinates-in-pymol/76749167#76749167 Draw a colored sphere from cartesian coordinates in pymol  and here https://pymolwiki.org/index.php/Load_CGO and https://pymolwiki.org/index.php/CGO_Shapes  

---

## 1 answers

### Answer by username_1 on 2023-10-16. Score: 2 | Accepted answer

my attempt :
import pymol

from pymol.cgo import *

from pymol import (
                    
                    cmd ,
                    )


print('########## PYMOL VERSION ##########################################')
print('         ',  cmd.get_version() )
print('###################################################################')


pymol.finish_launching()

cmd.fetch('1tqn')

cmd.remove('solvent')

pos = cmd.get_position()

r = 3

print('###############################################################################\n')

print('### POSITION : ' , pos,'  ###\n')

print('###############################################################################\n')



spherelist = [
    [COLOR,    1.000,    1.000,    0.000,
    SPHERE,   pos[0] , pos[1] , pos[2]  , r ],

    ]

for i in spherelist:
    
    a = str(spherelist.index(i))

    cmd.load_cgo(i, 'sphere_'+a )


cmd.zoom()

cmd.set('cartoon_transparency' , '0.5')


result:

> **Comments:**
> **username_0**: Aaah, `load_cgo()` https://pymolwiki.org/index.php/Load_CGO ("Compiled Graphics Objects"). There are also other shapes: https://pymolwiki.org/index.php/CGO_Shapes. Thank you!  

---

