Difference between revisions of "Example of use of dcoordinates"

From Dynamo
Jump to navigation Jump to search
(Created page with "<pre>vol = dsphere(30,256); v = dmodels.vesicle(); v.center = 128.5*[1,1,1]; v.separation = 20; v.radius = 40; v.updateCrop; t = v.grepTable(); myTemplate = dcylinder([4,12],...")
 
 
(4 intermediate revisions by the same user not shown)
Line 1: Line 1:
 +
This is a toy example to illustrate the conversion of volumes into spherical coordinates through the command <tt>dcoordinates</tt>.  This function has not been optimized (is purely written in Matlab, without a C++ core), and will probably stuck your computer for volumes with a size above 256 pixels of sidelength.
 +
 +
We  will create a small virus model by attaching a regular distribution of ''spikes'' (cylinders) to a virus (a sphere with a radius of 30 pixels):
 +
 
<pre>vol  = dsphere(30,256);
 
<pre>vol  = dsphere(30,256);
 
v = dmodels.vesicle();
 
v = dmodels.vesicle();
Line 14: Line 18:
 
end </pre>
 
end </pre>
  
We can quickly check how our " virus" looks like:  
+
We can quickly check how our "virus" looks like:  
 
  <pre>disoview(vol); </pre>
 
  <pre>disoview(vol); </pre>
Remember that <tt>disoview</tt> is a very basic renderer of isosurfaces.  
+
Remember that <tt>disoview</tt> is a very basic renderer of isosurfaces. We use it as a fallback when Chimera is not performing in the system.
 +
 
 +
[[File:MercatorIsosurface.png|center|right|400px| <tt>disoview</tt> ]]
 +
 
 +
Alternatively we can visualize the grey map:
 +
[[File:MercatorDview.png|center|right|400px| <tt>dview</tt> ]]
 +
 
 +
Now we can perform the coordinate conversion:
 +
<tt>vols = dcoordinates(vol,'cart2sph');</tt>
 +
 
  
vols = dcoordinates(vol,'cart2sph');
 
  
 +
After this transform, the radial direction is stored along the first dimension of <tt>vols</tt>. Second and third dimension correspond to the spherical angles.
 +
 +
We can now check the surface of the virus at the radial distance 30 (the "surface" of the virus in this example), adding  layers 28 to 32.
 
<pre>
 
<pre>
 
figure;
 
figure;
dshow(squeeze(sum(vols(30:32,:,:),1))); </pre>
+
dshow(squeeze(sum(vols(28:32,:,:),1))); </pre>
  
 +
[[File:MercatorRadiusClose.png|centering|center|400px| <tt>dshow</tt> of surface of virus ]]
 +
 +
Here,
 +
* <tt>vols(28:32,:,:); </tt> corresponds to extracting the layers 28 to 32 in the volume <tt>vols</tt>
 +
* the <tt>sum</tt> command adds all the layers of the argument along  the direction 1 (the radial direction in this case)
 +
*  the <tt>squeeze</tt> command is just Matlab formating: it converts the (nominal) volume created by <tt>sum</tt> (with dimensions 1 x 256 x512) into an image 256 x 512 that can then be fed into <tt>show</tt>;
 +
 +
A clearer view can be gained by averaging some pixels away from the surface:
 
<pre>figure;
 
<pre>figure;
 
dshow(squeeze(sum(vols(35:40,:,:),1)));</pre>
 
dshow(squeeze(sum(vols(35:40,:,:),1)));</pre>
 +
 +
[[File:MercatorRadiusFar.png|center|right|400px| <tt>dshow</tt> of spikes far away from radius of virus ]]

Latest revision as of 19:44, 12 February 2019

This is a toy example to illustrate the conversion of volumes into spherical coordinates through the command dcoordinates. This function has not been optimized (is purely written in Matlab, without a C++ core), and will probably stuck your computer for volumes with a size above 256 pixels of sidelength.

We will create a small virus model by attaching a regular distribution of spikes (cylinders) to a virus (a sphere with a radius of 30 pixels):

vol  = dsphere(30,256);
v = dmodels.vesicle();
v.center = 128.5*[1,1,1];
v.separation = 20;
v.radius = 40;
v.updateCrop;
t = v.grepTable();
myTemplate = dcylinder([4,12],24);
mask      = myTemplate;
for i=1:size(t,1);
   rotTemplate = dynamo_rot(myTemplate,t(i,7:9));
   rotMask     = dynamo_rot(mask,t(i,7:9));  
   vol = dpkvol.embed(rotTemplate,vol,t(i,24:26),rotMask);     
end 

We can quickly check how our "virus" looks like:

disoview(vol); 

Remember that disoview is a very basic renderer of isosurfaces. We use it as a fallback when Chimera is not performing in the system.

disoview

Alternatively we can visualize the grey map:

dview

Now we can perform the coordinate conversion:

vols = dcoordinates(vol,'cart2sph');


After this transform, the radial direction is stored along the first dimension of vols. Second and third dimension correspond to the spherical angles.

We can now check the surface of the virus at the radial distance 30 (the "surface" of the virus in this example), adding layers 28 to 32.

figure;
dshow(squeeze(sum(vols(28:32,:,:),1))); 
dshow of surface of virus

Here,

  • vols(28:32,:,:); corresponds to extracting the layers 28 to 32 in the volume vols
  • the sum command adds all the layers of the argument along the direction 1 (the radial direction in this case)
  • the squeeze command is just Matlab formating: it converts the (nominal) volume created by sum (with dimensions 1 x 256 x512) into an image 256 x 512 that can then be fed into show;

A clearer view can be gained by averaging some pixels away from the surface:

figure;
dshow(squeeze(sum(vols(35:40,:,:),1)));
dshow of spikes far away from radius of virus