#!/bin/tcsh -f # # # Sort, scale and merge the data from mosflm mtz file(s) # # if (${0:h} == ${0}) then set cmd = "" else set cmd = "${0:h}/" endif # # source ${cmd}makesymbols # # source symbols # # # Define the usage specific to scale # # set input = '[[mtzfile] mtzfile ...]' # # set help = (title \ outputroot \ highres \ lowres \ merge \ addscale \ nresidue \ anomalous \ exclude \ sdadd) # # source ${cmd}cmdargs # # # Interpret the unmatched arguments # # if (${#argv} >= 1) then set merge = (${argv}) endif # # # Save the symbols # # source ${cmd}savesymbols # # # Do any symbols have defaults? # # source ${cmd}defaults # # # Check for required input # # if (${?merge} == 0) then echo " " echo " ERROR: mtz files to merge not specified, program exit. " echo " " echo " Usage:" ${0} " mtzfile [mtzfile ...] " echo " " kill -9 $$ endif # # # Make the batch numbers unique # # set num = 1 while (${num} <= ${#merge}) if (${num} == 1) then if (${#merge} == 1) then if (${merge[1]} !~ [/\\]*) then set filewd = ${cwd}/ else set filewd = endif if (-l ${merge[1]}) then cp ${filewd}${merge[1]} ${filewd}${merge[1]}.unique else ln -sf ${filewd}${merge[1]} ${filewd}${merge[1]}.unique endif else cp ${merge[${num}]} ${merge[${num}]}.unique endif else @ add = (${num} - 1) * 1000 rebatch HKLIN ${merge[${num}]} HKLOUT ${merge[${num}]}.unique << eof BATCH ADD ${add} eof if ( $status != 0 ) then echo "Problem in REBATCH, exiting" exit endif endif @ num = ${num} + 1 end # # # Make the sortmtz command file # Note sortmtz only accepts 5 sort keys # echo "H K L M/ISYM BATCH" > ${tmpfile}.sortmtz set num = 1 while (${num} <= ${#merge}) echo "${merge[${num}]}.unique" >> ${tmpfile}.sortmtz @ num = ${num} + 1 end echo "" >> ${tmpfile}.sortmtz # # # Make the scala command file # # set noscales = 0 set nointensities = 0 set norun = 0 set noreject = 0 set noanom = 0 if (${?addscale}) then set num = 1 while (${num} <= ${#addscale}) if (${noscales} == 0) then @ noscales = ("${addscale[${num}]}" =~ [Ss][Cc][Aa][Ll][Ee]*) endif if (${nointensities} == 0) then @ nointensities = ("${addscale[${num}]}" =~ [Ii][Nn][Tt][Ee][Nn]*) endif if (${norun} == 0) then @ norun = ("${addscale[${num}]}" =~ [Rr][Uu][Nn]*) endif if (${noreject} == 0) then @ noreject = ("${addscale[${num}]}" =~ [Rr][Ee][Jj][Ee]*) endif if (${noanom} == 0) then @ noanom = ("${addscale[${num}]}" =~ [Aa][Nn][Oo][Mm]*) endif @ num = ${num} + 1 end endif # # echo "" > ${tmpfile}.scala if (${norun} == 0) then set num = 1 while (${num} <= ${#merge}) @ addstart = (${num} - 1) * 1000 @ addend = ((${num} - 1) * 1000) + 999 echo -n "run ${num} include batch ${addstart} to ${addend}" >> ${tmpfile}.scala set ex = 1 set excluded = 0 if (${?exclude}) then while (${ex} <= ${#exclude}) if ((${addstart} <= ${exclude[${ex}]}) && (${addend} >= ${exclude[${ex}]})) then if (${excluded} == 0) then echo -n " exclude" >> ${tmpfile}.scala set excluded = 1 endif echo -n " ${exclude[${ex}]}" >> ${tmpfile}.scala endif @ ex = ${ex} + 1 end endif echo "" >> ${tmpfile}.scala @ num = ${num} + 1 end endif # # if (${?addscale}) then set num = 1 while (${num} <= ${#addscale}) echo "${addscale[${num}]}" >> ${tmpfile}.scala @ num = ${num} + 1 end endif # # if (${noscales} == 0) then echo "scales brotation spacing 20 batch" >> ${tmpfile}.scala endif # # if (${nointensities} == 0) then echo "intensities partials" >> ${tmpfile}.scala endif # # if (${?highres}) then echo "resolution HIGH ${highres}" >> ${tmpfile}.scala endif if (${?lowres}) then echo "resolution LOW ${lowres}" >> ${tmpfile}.scala endif # # echo "cycles 40" >> ${tmpfile}.scala # # if (${?sdadd}) then echo "sdcorrection 1.5 ${sdadd}" >> ${tmpfile}.scala else echo "sdcorrection 1.5 0.02" >> ${tmpfile}.scala endif # # if (${noreject} == 0) then echo "reject merge 4" >> ${tmpfile}.scala endif # # if (${noanom} == 0) then if (${?anomalous}) then echo "anomalous ${anomalous}" >> ${tmpfile}.scala else echo "anomalous off" >> ${tmpfile}.scala endif endif # # echo "bins 20" >> ${tmpfile}.scala # # # Make the truncate command file # # echo "" > ${tmpfile}.truncate # # if (${?title}) then echo "title ${title}" >> ${tmpfile}.truncate endif # # if (${?nresidue}) then echo "nresidue ${nresidue}" >> ${tmpfile}.truncate endif # # if (${?highres}) then echo "resolution 1000 ${highres}" >> ${tmpfile}.truncate endif # # # Sort the data # # sortmtz HKLOUT ${tmpfile}.scratch1 < ${tmpfile}.sortmtz if ( $status != 0 ) then echo "Problem in SORTMTZ, exiting" exit endif # # # Delete the .unique files # # set num = 1 while (${num} <= ${#merge}) rm -f "${merge[${num}]}.unique" @ num = ${num} + 1 end # # # Get the current version number # # set logfiles = `ls ${outputroot}.scale_log*` set version = 0 set num = 1 while (${num} <= ${#logfiles}) echo -n "set tmp = " > ${tmpfile} echo "(${logfiles[${num}]:e})" | sed "s/[a-z_]/ /g" >> ${tmpfile} source ${tmpfile} rm -f ${tmpfile} if (${tmp} > ${version}) then @ version = ${tmp} endif @ num = ${num} + 1 end @ version = ${version} + 1 # # # Create the log file # # echo "" > ${outputroot}.scale_log${version} # # # Update the link to the log file # # if (-e ${outputroot}.scale_log) then if (-l ${outputroot}.scale_log) then rm -f ${outputroot}.scale_log ln -s ${outputroot}.scale_log${version} ${outputroot}.scale_log endif else ln -s ${outputroot}.scale_log${version} ${outputroot}.scale_log endif # # # Follow the progress of the scaling with awk # # # Calculate and apply the scale factors # # scala HKLIN ${tmpfile}.scratch1 \ HKLOUT ${tmpfile}.scratch2 < ${tmpfile}.scala \ | awk '{print >"'"${outputroot}".scale_log"${version}"'"};/Mean and maximum shift/{print}' if ( $status != 0 ) then echo "Problem in SCALA, exiting" exit endif # # if (-e ANOMPLOT) then if (${?anomalous}) then if ("${anomalous}" !~ [Oo][Ff][Ff]) then mv ANOMPLOT ${outputroot}.anomplot endif else if (${noanom}) then mv ANOMPLOT ${outputroot}.anomplot endif endif endif if (-e NORMPLOT) then mv NORMPLOT ${outputroot}.normplot endif if (-e ROGUES) then mv ROGUES ${outputroot}.rogues endif if (-e SCALES) then mv SCALES ${outputroot}.scales endif if (-e CORRELPLOT) then mv CORRELPLOT ${outputroot}.correlplot endif # # # Create summary file (only on an alpha) # # if (${HOSTTYPE} == "alpha") then echo "" > ${outputroot}.scale_sum echo " Scale factors analysed by Batch for each run" >> ${outputroot}.scale_sum echo " ============================================" >> ${outputroot}.scale_sum echo "" >> ${outputroot}.scale_sum /sbin/grep -E -p"========" \ "Scales v rotation range" ${outputroot}.scale_log${version} \ >> ${outputroot}.scale_sum # # echo "" >> ${outputroot}.scale_sum /sbin/grep -E -p"[I=][N=][T=][E=][N=][S=][I=]" \ "Rmerge against resolution" ${outputroot}.scale_log${version} \ >> ${outputroot}.scale_sum # # echo " Completeness and multiplicity, including reflections measured only once" \ >> ${outputroot}.scale_sum echo " =======================================================================" \ >> ${outputroot}.scale_sum echo "" >> ${outputroot}.scale_sum /sbin/grep -E -p"=======" "TABLE: +Completeness" ${outputroot}.scale_log${version} \ >> ${outputroot}.scale_sum else if (-e ${outputroot}.scale_sum) then rm -f ${outputroot}.scale_sum endif endif # # # Check to see if output unmerged was requested # # grep -E -i "output unmer*g*e*d*" ${tmpfile}.scala if ($status == 0) then mv ${tmpfile}.scratch2 ${outputroot}_unmerged.mtz rm -f ${tmpfile}.sortmtz rm -f ${tmpfile}.scala rm -f ${tmpfile}.truncate rm -r ${tmpfile}.scratch1 echo " Unmerged data is in ${outputroot}_unmerged.mtz" exit endif # # # Otherwise . . . # Convert the averaged intensities into mean amplitudes # # truncate HKLIN ${tmpfile}.scratch2 \ HKLOUT ${outputroot}_F.mtz >> ${outputroot}.scale_log${version} < ${tmpfile}.truncate if ( $status != 0 ) then echo "Problem in TRUNCATE, exiting" exit endif # # note the paragraph separator used below means most of the truncate log goes into the summary file if (${HOSTTYPE} == "alpha") then echo " Wilson Plot" >> ${outputroot}.scale_sum echo " ===========" >> ${outputroot}.scale_sum echo "" >> ${outputroot}.scale_sum /sbin/grep -E -p"[*i][*n][*c][*l][*u][*d][*e]" \ "TABLE: Wilson Plot" ${outputroot}.scale_log${version} \ >> ${outputroot}.scale_sum endif # # # Delete all the scratch files # # rm -f ${tmpfile}.sortmtz rm -f ${tmpfile}.scala rm -f ${tmpfile}.truncate rm -f ${tmpfile}.scratch[12] exit