2.21                      *******************
                                  * MAPAVG WRITE-UP *
                                  *******************
        
           Program MAPAVG, for the averaging of electron density map 
        regions according to noncrystallographic symmetry. The NC symmetry
        related regions may be in the same map, in different maps (crystals)
        or both. The program expects the names of all input (unaveraged) map
        files, all corresponding mask files, all output (averaged) map files
        and the operators defining the noncrystallographic symmetry. The input
        map files should be created from FSFOUR maps by running EXTRMAP or
        MAPVIEW to extract the map region which encompasses only the dimer,
        trimer etc to be averaged for each crystal. For cross-crystal
        averaging monomers may be used as well. Each mask map must cover 
        EXACTLY the same region as its corresponding input map. The mask map
        is generally created by MAPVIEW, and possibly transformed by TRNMSK,
        although if it is derived from an atomic model it may be created by
        MDLMSK. The operators are generally refined by LSQROT or LSQROTGEN
        prior to use in averaging. If cross-crystal averaging is done an
        additional least squares refinement pass is automatically included
        prior to averaging to put the density maps from different crystals
        on a common scale. After averaging however, each output map, will be
        on the same scale as it was originally input.
        
                               INPUT DATA (UNIT 5)
         
         CARD I    PAMFIL      (free format)
        
                   PAMFIL = Name of input parameter file, used only to get the
                            "running log" filename.
        
      
         CARD II   NCRYST      (free format)

                   NCRYST = Number of different crystals (maps) to be used.
                            (maximum = 6)
  
       
         The following block of cards III-VII must be repeated NCRYST times,
            once for each crystal.  
 
         CARD III  INPMAP      (free format)
        
                   INPMAP = Name of input (unaveraged) map file for this
                            crystal.
        
        
        
         CARD IV   INPMSK      (free format)
        
                   INPMSK = Name of input mask file for this crystal.
        
        
        
         CARD V    OUTMAP      (free format)
        
                   OUTMAP = Name of output (averaged) map file for this
                            crystal.
        
                   
        
         CARD VI   NMOL, (MSK(j), j=1,NMOL)              (free format)
        
                   NMOL = Total number of molecules related by 
                          noncrystallographic symmetry WITHIN THIS CRYSTAL
                          (eg 2 for twofold, 3 for threefold etc, MAX=12.
                          Note that it may be one if only cross-crystal
                          averaging of monomers is used)
                          
           
                 MSK(1) = Mask no. identifying envelope mask for molecule 1
                          in this crystal
        
                 MSK(2) = Mask no. identifying envelope mask for molecule 2
                          in this crystal
                                         .
                                         .
              MSK(NMOL) = Mask no. identifying envelope mask for molecule NMOL
                          in this crystal
        
                                          
        Note that the mask numbers should correspond to those used during mask
        creation (1-12), and refinement of the operator(s).
                          
    
     
        The following card must be repeated NMOL -1 times, with each entry
        providing the operator which moves molecule 1 to each additional 
        NC related molecule WITHIN THIS CRYSTAL, eg for a pure threefold,
        operator which moves molecule 1 to molecule 2, and operator which
        moves molecule 1 to molecule 3 must be supplied, but the parameters
        however, will be the same except for CHI. In that case all three
        molecules may have the same mask no. Note that if nmol=1 this card
        should NOT be included!
        
        CARD(S) VII  PHI, PSI, CHI, OX, OY, OZ, T          (free format)
        
               Spherical polar angles defining direction and rotational order
        PHI =  of noncrystallographic symmetry axis, oriented with respect to
               orthogonal frame with X along a, Y along c* cross a, and Z
               along x cross y (i.e. c*).
        PSI =  Psi = angle between NC symmetry axis and +Y axis. Phi = angle
               between projection of NC symmetry axis on XZ plane and +X axis.
        CHI =  +Phi = CCW rotation about +Y axis as measured from +X axis. 
               +Chi = CW rotation about the directed axis, when viewed from
               the +axis toward the origin. All angles in degrees. 
        
        OX =
              Origin of NC symmetry rotation axis, in angstroms with respect
        OY =  
              to the orthogonal axes. The axis passes through this point.
        OZ =
        
         T =  Post rotation translational shift (in angstroms) parallel to the
              rotation axis.
        
        
        Note that the transformation operator input is defined as that which
        moves molecule 1 to molecule J (both molecules within this crystal,
        with J ranging from 2 to NMOL) via
              
                         Xj = (Rm) (X1 - Xo) + Xo + T*Rx
        
        where Rm is a 3x3 rotation matrix expressed in terms of the spherical
        polar angles, Xj, X1 are 3 element column vectors containing new and 
        old coordinates, respectively, Xo is a 3 element column vector 
        containing coordinates of the origin point for the rotation axis, T is 
        a post rotation translation shift scalar (in angstroms) and Rx is a 3 
        element column vector containing direction cosines of the rotation 
        axis. 
            The translation shift T is for a translation parallel to the
        rotation axis (screw like) as translations in any other direction
        can be achieved simply by changing the rotation axis origin. An
        initial estimate of T can be obtained from two points P1, P2 related
        by the NC symmetry from

              T = DX cos(PHI)sin(PSI) + DY cos(PSI) -DZ sin(PHI)sin(PSI)

              where   DX = P2x-P1x,     DY = P2y-P1y,   DZ = P2z-P1z

        and the P's are expressed in the orthogonal axial system.

        Note the directionality of the transformation (P1 going to P2 as
        opposed to P2 going to P1) affects the sign of T (and CHI).

 
          THIS IS THE END OF INPUT UNLESS DOING CROSS-CRYSTAL AVERAGING


        **** The following cards should be included ONLY if NCRYST > 1 **** 
        
        Cards VIII must be repeated NCRYST -1 times, with each entry
        providing the operator which moves molecule 1 in crystal 1 to molecule
        1 in crystal 2,  molecule 1 in crystal 1 to molecule 1 in crystal 3,
        molecule 1 in crystal 1 to molecule 1 in crystal 4 etc. 


        CARD(S) VIII  PHI, PSI, CHI, OX, OY, OZ, T          (free format)

        PHI =

        PSI =
               All defined as described above. Note that the operator
        CHI =
               is applied to ORTHOGONAL coordinates in crystal 1 to
        OX =
               generate ORTHOGONAL coordinates in the target crystal. 
        OY =

        OZ =

         T = 

         
                                                                                                         
         NOTES: Each input mask must coincide exactly with its corresponding
         input map.

         CROSS-CRYSTAL AVERAGING: If the different crystals contain different
         aggegation states of the molecule within their respective asymmetric
         units (eg monomer in one crystal, dimer in another). Then the 
         crystal with the lowest agregation state should come first in the
         input list, and mask assignments in the other crystals must uniquely
         identify molecules of this same size. Thus for example, if a
         crystal contained a dimer having pure NC twofold symmetry and it was
         the only crystal used, normally a single mask encompassing the
         entire dimer would be supplied (mask numbers would be identical for
         molecules 1 and 2). If however, in addition to averaging over this
         twofold, one also averages with another crystal form containing only
         a monomer, then the monomer crystal should come first in the list,
         and different mask numbers must be used within the dimer crystal
         to distinguish the individual monomers. If all crystal forms contain
         the same basic unit (eg dimers, trimers etc), then individual mask
         numbers for each monomer are not required, but may still be used as
         long as it is done consistantly in all crystals.
                                                                 
        
                                   ***** FILES *****
        
                 INPUT MAP FILES (BINARY)       
 
        record 1)  A,B,C,AL,BE,GA,NX,NY,NZ,IXMN,IYMN,IZMN,IXMX,IYMX,IZMX
        
        with first 6 values REAL*4, next 9 INTEGER*4, lengths in Angstroms,
        angles in degrees.
        
        NX = 
              Number of grid points defining one "cell length" along
        NY =  respective axis. Implicitly defines grid spacing as 
              del x = A/NX, del y = B/NY and del z = C/NZ
        NZ =
        
        IXMN, IXMX =  
                     Minimum, maximum grid index defining map region such
        IYMN, IYMX = that  x (fractional) = IX * (del x) / A  etc. 
                     There are no restrictions on magnitudes or signs.
        IZMN, IZMX = 
        
        The map follows as (IYMX-IYMN+1)*(IZMX-IZMN+1) records, with
        each containing one row (IXMX-IXMN+1 REAL*4 values) along X,
        starting at IXMN. Y is slowest varying, i.e. the file could have
        been created with the following FORTRAN code:
        
               DO 30 IY=IYMN,IYMX
                       DO 20 IZ=IZMN,IZMX
        20     WRITE(LU)(RHO(IX,IY,IZ),IX=IXMN,IXMX)
        30     CONTINUE
        
        
               INPUT MASK FILES (BINARY) 
        
        Header record identical to map file.
        
        Mask records similar to normal map records except that
        the mask values are written as FORTRAN type "BYTE" (INTEGER*1).
        Only grid points with mask values of 0, 10, 20, 30, 40 etc will
        be used (i.e. inside envelope masks 1,2,3,4,5 etc, respectively).
                                                   
        
                OUTPUT MAP FILES (BINARY)
        
        Identical (in structure) to input map file, but contains density
        "averaged" over the specified points.