combine euler  Combines 2 Euler rotations into a single one
 

file formats: output: SPIDER document file (no input file)

USAGE:         combine euler
        
        .Enter phi1, theta1 and psi1: 10.0, 90., -30
        [Enter the three angles of the first Euler rotation, 
         phi rotation around z, theta rotation around the new y,
         psi rotation around the new z. Theta rotation is negative,
         consistent with definitions of Euler angles also in SPIDER.]
         
        .Enter phi2, theta2 and psi2: 20.,-30.,20.
        [Enter the second set of Euler angles.]
        
        .Enter varaible to receive output: v.ang
        [Enter the variable that will contain the output values. This
         will have the form of a named tuple. Access the single values
         with v.ang.phi, v.ang.theta and v.ang.psi. You can also print
         the tuple to see what is in there. (print v.ang).]

        .Create output document file Y/N: Y
        [ You can create an output document file that will contain the
         euler matrix of the combined rotation. On line contains 9
         numbers, each three form one column of the rotation matrix.
         column 1 : value 1-3 column 2: values 4-6, column 3: values 7-9]
         
         If 'Y' was answered then
            .Enter document file name: matrixdoc001
            [Enter the name of the document file that will contain the 
             resulting matrix.]
          
            .Enter key: 10
            [Enter the key under which the matrix should be stored in the 
             document file.]
          
Eplanations of usage:
	
	If this is the rotation of your volume:
	rot3d
	volume002	#Input file 
	volrot002	#Output file: 
	20,40,60	#phi,theta,psi: 
	0,0,0	#shift center by x,y,z (integer): 
	q	#linear or quadratic interpolation (def: Q):
	
	then you can update the angles in the projections with (example):
	
	for v.i from 1 to 72 do
	readdoc
	proanglesdoc001 # read document file with current projection angles
	v.i, v.phi1,v.theta1,v.psi1
	combine euler
	v.phi1,v.theta1,v.psi1  #original projection angles
	-60,-40,-20		#use inverse rotation of volume
	v.combined
	n
	writedoc
	proanglerotdoc001	#doc file with updated projection angles.
	v.i,v.combined.phi,v.combined.theta,v.combined.psi
	enddo
	writedocclose
	proanglerotdoc001
	readdocclose
	proanglesdoc001

	# put the new angles in tht projection header. In this example
	# the header is updated already in the Radon transforms prepared
	# for 3D reconstruction. An extra copy is created for not losing
	# the original ones.
	for v.i from 1 to 72 do
	readdoc
	proanglerotdoc001
	v.i,v.phi,v.theta,v.psi
	copy
	prorad[3] v.i
	proradrot[3] v.i
	setangle		# place the new angle in the header
	proradrot[3] v.i
	1			# in position 1
	v.phi,v.theta,v.psi
	enddo
	readdocclose
	proanglerotdoc001

	The reconstruction calculated with the updated angle will show the
	structure rotated by the same angle as the volume. 
	
	Instead of using a document file for the original angles you also
	can extract them from the header using "getheader". 
	Similar, since combineeuler is used in a loop, you can also update 
	the projection angles within the loop without creating a document 
	file etc....

Remarks:  This is a rewrite of the formare SPIDER vo ceul command for 
          external input.

          Combines two sets of three Euler angles into a single
          set of three Euler angles. The definition of the Euler
          rotations is as follows:
          
          r' = D(psi) D(theta) D(phi) r

          with:
                       | cos(psi) sin(psi)  0 |
                D(psi)=|-sin(psi) cos(psi)  0 |
                       |    0        0      1 |

                       | cos(theta)  0 -sin(theta) |
              D(theta)=|     0       1      0      |
                       | sin(theta)  0  cos(theta) |

                       | cos(psi) sin(psi)  0 |
                D(psi)=|-sin(psi) cos(psi)  0 |
                       |    0        0      1 |
          
          These definitions are consistent with the angle definitions used
          in "backproject" and the Radon 3D reconstruction programs. 

Programs: em_combineeuler.py, combeuler.f combeul.f mrmamule.f

Author: M. Radermacher 1990 and 2013.