[Chimera-users] alter volume data with python

Tom Goddard goddard at cgl.ucsf.edu
Tue Feb 2 11:39:17 PST 2010

Hi Michael,

  Your code almost does the job.  The line

    H = em.full_matrix()

gets the actual data array that Chimera is using, not a copy of it.  So 
your loop is modifying the only copy of the data in memory.  But there 
is a problem with this.  Chimera currently does not support modifying 
map values that come from a file.  (It only reads parts of the map from 
the file on-demand, and later deletes them from memory when not needed.  
This caching can't handle modifying values.)  You have to make an 
in-memory copy of the map to do that.

  So do this.

    emc = em.writable_copy()
    H = emc.full_matrix()

    # Your thresholding code here.


That last "values_changed()" call will cause the graphics and histogram 
to update.  To save the map to a file:


  The "vop" (volume operation ) command should do this simple 
thresholding though it currently doesn't.  I've added that to our 
feature request list.



Elaine's tricky masking suggestion would probably work.  Make two 
contour surfaces (ctrl click on histogram to make second one.  Then use 
the mask command to zero everything outside of those.  Then use "vop 
scale" to shift the map as you have in your code.


-------- Original Message --------
Subject: [Chimera-users] alter volume data with python
From: Michael Zimmermann <michaelz at iastate.edu>
To: chimera users <chimera-users at cgl.ucsf.edu>
Date: 2/1/10 6:26 PM
> Dear Chimera users,
> I cannot find a way to search the chimera-users archive, so I
> appologize if this has been asked already.  I wish to alter some
> volume data in specific ways; delete (zero out) all volume values that
> do not meet certain density criteria.  The following code modifies the
> matrix values, but I can't figure out how to update the map that is
> being displayed in the volume viewer.
> I would like to be able to do something like:
> opened[0].full_matrix = H
> Then I would only see the swath that I "selected" with the following code.
> # ------------------------------------------------------------------------
> source = '1R0A_antigen_6A_8s_0.425f_inv.mrc'
> opened = chimera.openModels.open(source)
> em = opened[0]
> H = em.full_matrix()
> s = H.shape
> for k in range(0,s[2]-1):
> 	for i in range(0,s[0]-1):
> 		for j in range(0,s[1]-1):
> 			if(H[i,j,k] >= -.28) and (H[i,j,k] <= -0.001):
> 				H[i,j,k] = H[i,j,k]+1
> 			else:
> 				H[i,j,k] = 0
> # ------------------------------------------------------------------------
> Thank you,

More information about the Chimera-users mailing list