Accessing shapes created through a .BLD script

Hi, I have a bunch of shapes (spheres and cylinders) created through a .bld script. I'd like to load this script once, and then be able to change the colors of said shapes in successive operations. It is possible to set the colors directly in the .bld script, but I need to make an animation out of this. E.g: if my .bld script contains lines that draws shapes like so: .sphere 0 0 -1 5.0 .cylinder 0 0 0 1 1 1 1.0 I want to be able to later have a bunch of scripts called 1.cxc, 2.cxc, 3.cxc, .... each of which change the color of the sphere and cylinder. This way, I can load these scripts in the per-frame mode, to create an animation out of the color changes. Alternatively, I tried doing this with just the shape command and without a .bld script, but I have over ~10000 shapes; the shape command interprets each as a different model, and my computer hangs. ----- Thanks, Tanmoy Tanmoy Sanyal Postdoctoral scholar, Sali lab <https://salilab.org/>, Department of Bioengineering and Therapeutic Sciences <https://bts.ucsf.edu/>, University of California San Francisco Phone:- (+1) 805-637-0375

Hi Tanmoy, What is the question, specifically? Whether any of this is possible? Currently, no, or at least not with the regular user interface (commands and menu). You cannot change the color of Bild objects after they are created. Maybe with python, but somebody else would have to answer about that. Also, even if you could, there is no way to specify different objects within a single Bild model (opened from a single Bild file) in the command line, i.e. there is no logical equivalent to the atom serial number attribute, or the atom name, residue number, chain ID specifiers that you'd have in an atomic model. At least with the shapes, you can specify them by their unique model numbers. I can't tell whether you really want 10,000 shapes at the same time or whether you just end up with that by trying to recolor 2 shapes (or some other small number). (A) First I'll pretend you only want a few shapes, or at least some number or models that doesn't make your computer hang. When you make the shape in the new color, just use the "modelId" option to specify the existing model number so that it will overwrite the previous shape. This is one of the general options of the command. <https://rbvi.ucsf.edu/chimerax/docs/user/commands/shape.html> <https://rbvi.ucsf.edu/chimerax/docs/user/commands/shape.html#options> (B) Next I'll answer pretending you want 10,000 shapes at the same time: Given that you are just showing spheres and cylinders, can you instead make fake atoms and bonds or pseudobonds (or equivalently, markers and links)? In that way, you could open a single file making a single model, but have the mechanisms listed above of specifying each sphere or cylinder uniquely in the command line. The marker-file format is described here: <https://rbvi.ucsf.edu/chimerax/docs/user/markers.html#markerfiles> There are no links without markers (no bonds without atoms) but if you wanted flat-ended cylinders you could try making the link radius large compared to the radii of the markers delineating the ends of the cylinders, or set the bond attribute to display regardless of whether their end atoms are displayed. I hope this helps, Elaine ----- Elaine C. Meng, Ph.D. UCSF Chimera(X) team Department of Pharmaceutical Chemistry University of California, San Francisco
On Feb 26, 2021, at 4:30 PM, Tanmoy Sanyal <tanmoy.7989@gmail.com> wrote:
Hi, I have a bunch of shapes (spheres and cylinders) created through a .bld script. I'd like to load this script once, and then be able to change the colors of said shapes in successive operations. It is possible to set the colors directly in the .bld script, but I need to make an animation out of this. E.g: if my .bld script contains lines that draws shapes like so: .sphere 0 0 -1 5.0 .cylinder 0 0 0 1 1 1 1.0
I want to be able to later have a bunch of scripts called 1.cxc, 2.cxc, 3.cxc, .... each of which change the color of the sphere and cylinder. This way, I can load these scripts in the per-frame mode, to create an animation out of the color changes.
Alternatively, I tried doing this with just the shape command and without a .bld script, but I have over ~10000 shapes; the shape command interprets each as a different model, and my computer hangs.
----- Thanks, Tanmoy

Thanks Elaine and Tom for the very helpful information! I eventually chose the option of representing these spheres and bonds as markers and links, and then re-coloring the selected ones every frame. That turned out to be a simple solution and it's reasonably fast now. ----- Thanks, Tanmoy Tanmoy Sanyal Postdoctoral scholar, Sali lab <https://salilab.org/>, Department of Bioengineering and Therapeutic Sciences <https://bts.ucsf.edu/>, University of California San Francisco Phone:- (+1) 805-637-0375 On Fri, Feb 26, 2021 at 6:12 PM Elaine Meng <meng@cgl.ucsf.edu> wrote:
Hi Tanmoy, What is the question, specifically? Whether any of this is possible?
Currently, no, or at least not with the regular user interface (commands and menu). You cannot change the color of Bild objects after they are created. Maybe with python, but somebody else would have to answer about that. Also, even if you could, there is no way to specify different objects within a single Bild model (opened from a single Bild file) in the command line, i.e. there is no logical equivalent to the atom serial number attribute, or the atom name, residue number, chain ID specifiers that you'd have in an atomic model. At least with the shapes, you can specify them by their unique model numbers.
I can't tell whether you really want 10,000 shapes at the same time or whether you just end up with that by trying to recolor 2 shapes (or some other small number).
(A) First I'll pretend you only want a few shapes, or at least some number or models that doesn't make your computer hang. When you make the shape in the new color, just use the "modelId" option to specify the existing model number so that it will overwrite the previous shape. This is one of the general options of the command. <https://rbvi.ucsf.edu/chimerax/docs/user/commands/shape.html> <https://rbvi.ucsf.edu/chimerax/docs/user/commands/shape.html#options>
(B) Next I'll answer pretending you want 10,000 shapes at the same time:
Given that you are just showing spheres and cylinders, can you instead make fake atoms and bonds or pseudobonds (or equivalently, markers and links)? In that way, you could open a single file making a single model, but have the mechanisms listed above of specifying each sphere or cylinder uniquely in the command line.
The marker-file format is described here: <https://rbvi.ucsf.edu/chimerax/docs/user/markers.html#markerfiles>
There are no links without markers (no bonds without atoms) but if you wanted flat-ended cylinders you could try making the link radius large compared to the radii of the markers delineating the ends of the cylinders, or set the bond attribute to display regardless of whether their end atoms are displayed. I hope this helps, Elaine ----- Elaine C. Meng, Ph.D. UCSF Chimera(X) team Department of Pharmaceutical Chemistry University of California, San Francisco
On Feb 26, 2021, at 4:30 PM, Tanmoy Sanyal <tanmoy.7989@gmail.com> wrote:
Hi, I have a bunch of shapes (spheres and cylinders) created through a .bld script. I'd like to load this script once, and then be able to change the colors of said shapes in successive operations. It is possible to set the colors directly in the .bld script, but I need to make an animation out of this. E.g: if my .bld script contains lines that draws shapes like so: .sphere 0 0 -1 5.0 .cylinder 0 0 0 1 1 1 1.0
I want to be able to later have a bunch of scripts called 1.cxc, 2.cxc, 3.cxc, .... each of which change the color of the sphere and cylinder. This way, I can load these scripts in the per-frame mode, to create an animation out of the color changes.
Alternatively, I tried doing this with just the shape command and without a .bld script, but I have over ~10000 shapes; the shape command interprets each as a different model, and my computer hangs.
----- Thanks, Tanmoy

Hi Tanmoy, The BLD models do not support changing colors of individual spheres and cylinders. And to get decent performance for 10000 shapes you need to use a fake molecule. You can use a marker set which can have spheres and cylinders connecting spheres. Each marker is an atom and each cylinder is a bond. Each marker has an id number which is its residue number, so you can color marker 57 with "color :57 gold". Markers can be read from an XML file or made from Python. https://www.rbvi.ucsf.edu/chimerax/docs/user/markers.html Tom
On Feb 26, 2021, at 4:30 PM, Tanmoy Sanyal <tanmoy.7989@gmail.com> wrote:
Hi, I have a bunch of shapes (spheres and cylinders) created through a .bld script. I'd like to load this script once, and then be able to change the colors of said shapes in successive operations. It is possible to set the colors directly in the .bld script, but I need to make an animation out of this. E.g: if my .bld script contains lines that draws shapes like so: .sphere 0 0 -1 5.0 .cylinder 0 0 0 1 1 1 1.0
I want to be able to later have a bunch of scripts called 1.cxc, 2.cxc, 3.cxc, .... each of which change the color of the sphere and cylinder. This way, I can load these scripts in the per-frame mode, to create an animation out of the color changes.
Alternatively, I tried doing this with just the shape command and without a .bld script, but I have over ~10000 shapes; the shape command interprets each as a different model, and my computer hangs.
----- Thanks, Tanmoy
Tanmoy Sanyal Postdoctoral scholar, Sali lab <https://salilab.org/>, Department of Bioengineering and Therapeutic Sciences <https://bts.ucsf.edu/>, University of California San Francisco Phone:- (+1) 805-637-0375 _______________________________________________ ChimeraX-users mailing list ChimeraX-users@cgl.ucsf.edu Manage subscription: https://www.rbvi.ucsf.edu/mailman/listinfo/chimerax-users

There are several issues here. Bild spheres and cylinders use a fixed subdivision into triangles. Unlike atoms and bonds, which alter the amount of subdivisions based on how big they are drawn. So if all you have are atoms and bonds, a fake molecule would be much faster, if they are tiny on the screen, or much better visual quality, if they are larger on the screen. But, ignoring the subdivision issue, 10000 bild shapes should roughly the same speed as a molecule with 10000 elements. and possibly a little faster. So back to coloring bild objects, with some Python code, you can change the color of individual bild shapes. Consider this "unofficial", but this works if the bild model is the first one opened:
RED = [255, 0, 0, 255]
def recolor_shape(model, index, color): s = m.child_drawings()[0] sh = s._shapes[index]
vertices = set() tris = s.triangles for t in sh.triangle_range: vertices.update(tris[t])
vc = s.vertex_colors for v in vertices: vc[v] = color s.vertex_colors = vc
m = session.models[0] recolor_shape(m, 1, RED)
HTH, Greg On 2/26/2021 6:14 PM, Tom Goddard wrote:
Hi Tanmoy,
The BLD models do not support changing colors of individual spheres and cylinders. And to get decent performance for 10000 shapes you need to use a fake molecule. You can use a marker set which can have spheres and cylinders connecting spheres. Each marker is an atom and each cylinder is a bond. Each marker has an id number which is its residue number, so you can color marker 57 with "color :57 gold". Markers can be read from an XML file or made from Python.
https://www.rbvi.ucsf.edu/chimerax/docs/user/markers.html <https://www.rbvi.ucsf.edu/chimerax/docs/user/markers.html>
Tom
On Feb 26, 2021, at 4:30 PM, Tanmoy Sanyal <tanmoy.7989@gmail.com <mailto:tanmoy.7989@gmail.com>> wrote:
Hi, I have a bunch of shapes (spheres and cylinders) created through a .bld script. I'd like to load this script once, and then be able to change the colors of said shapes in successive operations. It is possible to set the colors directly in the .bld script, but I need to make an animation out of this. E.g: if my .bld script contains lines that draws shapes like so: .sphere 0 0 -1 5.0 .cylinder 0 0 0 1 1 1 1.0
I want to be able to later have a bunch of scripts called 1.cxc, 2.cxc, 3.cxc, .... each of which change the color of the sphere and cylinder. This way, I can load these scripts in the per-frame mode, to create an animation out of the color changes.
Alternatively, I tried doing this with just the shape command and without a .bld script, but I have over ~10000 shapes; the shape command interprets each as a different model, and my computer hangs.
----- Thanks, Tanmoy
Tanmoy Sanyal Postdoctoral scholar, Sali lab <https://salilab.org/>, Department of Bioengineering and Therapeutic Sciences <https://bts.ucsf.edu/>, University of California San Francisco Phone:- (+1) 805-637-0375 _______________________________________________ ChimeraX-users mailing list ChimeraX-users@cgl.ucsf.edu <mailto:ChimeraX-users@cgl.ucsf.edu> Manage subscription: https://www.rbvi.ucsf.edu/mailman/listinfo/chimerax-users
_______________________________________________ ChimeraX-users mailing list ChimeraX-users@cgl.ucsf.edu Manage subscription: https://www.rbvi.ucsf.edu/mailman/listinfo/chimerax-users
participants (4)
-
Elaine Meng
-
Greg Couch
-
Tanmoy Sanyal
-
Tom Goddard