Scripts: placeimod.py

File placeimod.py, 1.5 KB (added by goddard, 11 years ago)
Line 
1# Place copies of a model specified by the csv output of IMOD createAlignedModel.
2# Example Chimera command:
3#
4# run placeimod.py #2 /tmp/positions.csv
5
6def place_copies(volumes, csv_file):
7
8 f = open(csv_file, 'r')
9 lines = f.readlines()
10 f.close()
11
12 from chimera import Xform
13 v0 = volumes[0]
14 for line in lines:
15 if not line[0].isdigit():
16 continue # Comment line
17 # translation in pixel units, rotation angles in degrees
18 x,y,z,rx,ry,rz = [float(x) for x in line.split(',')[1:]]
19 d = v0.data
20 # Convert translation from box center to box corner and from pixels to Angstroms.
21 tx, ty, tz = [s*t for t,s in zip ((x,y,z), d.step)]
22 # Center of rotation is center of map grid.
23 cx, cy, cz = d.ijk_to_xyz(tuple(0.5*(i-1) for i in d.size))
24 # Calculate the position matrix.
25 pos = Xform.translation(-cx,-cy,-cz) # Put center of rotation at 0,0,0
26 pos.premultiply(Xform.zRotation(rz))
27 pos.premultiply(Xform.yRotation(ry))
28 pos.premultiply(Xform.xRotation(rx))
29 pos.premultiply(Xform.translation(tx,ty,tz))
30 # Make copies of the density map at the positions
31 for v in volumes:
32 vc = v.copy()
33 vc.show()
34 vc.copy_settings_from(v) # Copy per-vertex coloring
35 cxf = vc.openState.xform
36 cxf.multiply(pos)
37 vc.openState.xform = cxf
38
39import Commands
40vlist = Commands.volumes_from_specifier(arguments[0])
41csv_file = arguments[1]
42place_copies(vlist, csv_file)