#/bin/csh -f
#
# produce rfree files for F's and I's
#   with flags on the same reflections based
#   on an asci file containing I's
#
set name  = 'pmsf_1.1A'
set title = $name
set cell  = '40.4900   51.4100   69.3100   90.0000   90.0000   90.0000'
set symm  = '19'
set resol = '20.0 1.00'
#
echo " "
echo Running f2mtz ...
f2mtz hklin sp.hkli hklout ${name}.mtzi << scriptend
title ${title}
cell ${cell}
symmetry p212121
labout    H K L IMEAN SIGIMEAN
ctypout   H H H J Q
scriptend
#
#
echo " "
echo Running truncate ...
truncate hklin  ${name}.mtzi hklout ${name}.tru << eof-tru
title ${title}
!wilson
resolution  100 1.1
range       30
! rscale      10 1.12
nresidues   188
!labin   IMEAN=IMEAN SIGIMEAN=SIGIMEAN
labout  F=F SIGF=SIGF
eof-tru
#
cad HKLIN1 ${name}.mtzi HKLOUT ${name}.cadi << e
TITLE   ${title}
CELL    ${cell}
OUTLIM SPACEGROUP ${symm}
RESOLUTION OVERALL ${resol}
LABIN  FILE 1 E1=IMEAN E2=SIGIMEAN
LABOUT FILE 1 E1=IMEAN E2=SIGIMEAN
CTYP   FILE 1 E1=J  E2=Q
END
e
#
cad HKLIN1 ${name}.tru HKLOUT ${name}.cad << e
TITLE   ${title}
CELL    ${cell}
OUTLIM SPACEGROUP ${symm}
RESOLUTION OVERALL ${resol}
LABIN  FILE 1 E1=F E2=SIGF
LABOUT FILE 1 E1=F E2=SIGF
CTYP   FILE 1 E1=F  E2=Q
END
e
#
echo " "
echo Running freer on Is...
freerflag hklin ${name}.mtzi hklout ${name}rf.cadi << e
freerfac 0.05
e
mtzutils hklin1 ${name}.cad hklin2 ${name}rf.cadi  \
  hklout ${name}.all.cad << e
header full
e
mtzutils hklin1 ${name}.all.cad hklout ${name}rf.cad << e
onefile
header full
exclude IMEAN SIGIMEAN
e
foreach v (cad cadi)
mtzdump hklin ${name}rf.${v} << e
nref 100
go
e
end
