From 65408b8dd71bf795a77b15f1d6336418e5d9a26c Mon Sep 17 00:00:00 2001 From: Beale John Henry Date: Wed, 8 Jan 2025 16:58:27 +0100 Subject: [PATCH] updated to also include truncate to create Fs and cut data resolution --- reduction_tools/make_mtz.py | 66 ++++++++++++++++++++++++++++++------- 1 file changed, 54 insertions(+), 12 deletions(-) diff --git a/reduction_tools/make_mtz.py b/reduction_tools/make_mtz.py index ca3c443..bb7a9f4 100644 --- a/reduction_tools/make_mtz.py +++ b/reduction_tools/make_mtz.py @@ -5,6 +5,7 @@ """ # aim to make an mtz from an hkl file output from partialator or process_hkl +runs f2mtz and then truncate for create an mtz with other intensities and structure factors # usage to make mtz from manually entered lengths and angles python make_mtz.py -i @@ -14,6 +15,8 @@ python make_mtz.py -i -d dataset name in mtz -g spacegroup -c list of cell lengths and angles to use - 59.3,59.3,153.1,90.0,90.0,90.0 + -r number of residues + -A resolution range - e.g. 40.0,2.0 # usage to make mtz from the mean angles and lengths in stream file python make_mtz.py -i @@ -22,6 +25,8 @@ python make_mtz.py -i -x xtal name in mtz -d dataset name in mtz -g spacegroup + -r number of residues + -A resolution range - e.g. 40.0,2.0 -s -u True @@ -29,8 +34,11 @@ python make_mtz.py -i python make_mtz.py -s # output -- .mtz file -- .html log file +- .mtz file - just intensities +- f2mtz.log file +- _F.mtz file - intensities and structure factors +- cuts data to desired resolution +- truncate.log file """ # modules @@ -72,27 +80,49 @@ def get_mean_cell( stream_file ): return mean_cell, len(cell_lst) -def make_mtz( hklout_file, mtzout_file, project, crystal, dataset, cell, spacegroup ): +def make_mtz( hklout_file, mtzout_file, project, crystal, dataset, cell, spacegroup, residues, res_range ): # make_mtz file name mtz_run_file = "make_mtz.sh" + # make F file name + Fout_file = os.path.splitext( mtzout_file )[0] + "_F.mtz" + # write file mtz_sh = open( mtz_run_file, "w" ) mtz_sh.write( "#!/bin/sh\n\n" ) mtz_sh.write( "module purge\n" ) mtz_sh.write( "module load ccp4/8.0\n\n" ) - mtz_sh.write( "f2mtz HKLIN {0} HKLOUT {1} > out.html << EOF\n".format( hklout_file, mtzout_file ) ) + mtz_sh.write( "f2mtz HKLIN {0} HKLOUT {1} << EOF_hkl > f2mtz.log\n".format( hklout_file, mtzout_file ) ) mtz_sh.write( "TITLE Reflections from CrystFEL\n" ) mtz_sh.write( "NAME PROJECT {0} CRYSTAL {1} DATASET {2}\n".format( project, crystal, dataset ) ) mtz_sh.write( "CELL {0} {1} {2} {3} {4} {5}\n".format( cell[0], cell[1], cell[2], cell[3], cell[4], cell[5] ) ) mtz_sh.write( "SYMM {0}\n".format( spacegroup ) ) mtz_sh.write( "SKIP 3\n" ) - mtz_sh.write( "LABOUT H K L IMEAN SIGIMEAN\n" ) - mtz_sh.write( "CTYPE H H H J Q\n" ) + mtz_sh.write( "LABOUT H K L I_stream SIGI_stream\n" ) + mtz_sh.write( "CTYPE H H H J Q\n" ) mtz_sh.write( "FORMAT '(3(F4.0,1X),F10.2,10X,F10.2)'\n" ) mtz_sh.write( "SKIP 3\n" ) - mtz_sh.write( "EOF" ) + mtz_sh.write( "EOF_hkl\n\n\n" ) + mtz_sh.write( "echo 'done'\n" ) + mtz_sh.write( "echo 'I and SIGI from CrystFEL stream saved as I_stream and SIGI_stream'\n" ) + mtz_sh.write( "echo 'I filename = {0}'\n\n\n".format( mtzout_file ) ) + mtz_sh.write( "echo 'running truncate'\n" ) + mtz_sh.write( "echo 'setting resolution range to {0}-{1}'\n".format( res_range[0], res_range[1] ) ) + mtz_sh.write( "echo 'assuming that there are {0}' in assymetric unit\n\n\n".format( residues ) ) + mtz_sh.write( "truncate HKLIN {0} HKLOUT {1} << EOF_F > truncate.log\n".format( mtzout_file, Fout_file ) ) + mtz_sh.write( "truncate YES\n" ) + mtz_sh.write( "anomalous NO\n" ) + mtz_sh.write( "nresidue {0}\n".format( residues ) ) + mtz_sh.write( "resolution {0} {1}\n".format( res_range[0], res_range[1] ) ) + mtz_sh.write( "plot OFF\n" ) + mtz_sh.write( "labin IMEAN=I_stream SIGIMEAN=SIGI_stream\n" ) + mtz_sh.write( "labout F=F_stream SIGF=SIGF_stream\n" ) + mtz_sh.write( "end\n" ) + mtz_sh.write( "EOF_F\n\n\n" ) + mtz_sh.write( "echo 'done'\n" ) + mtz_sh.write( "echo 'I_stream and SIGI_stream from f2mtz converted to F_stream and F_stream'\n" ) + mtz_sh.write( "echo 'F filename = {0} (contains both Is and Fs)'".format( Fout_file ) ) mtz_sh.close() # make file executable @@ -118,7 +148,7 @@ def cut_hkl_file( hklin_file, hklout_file ): hklout.close() -def main( hklin_file, hklout_file, mtzout, project, crystal, dataset, cell, spacegroup ): +def main( hklin_file, hklout_file, mtzout, project, crystal, dataset, cell, spacegroup, residues, res_range ): # remove final lines from crystfel hkl out print( "removing final lines from crystfel hklin" ) @@ -129,7 +159,7 @@ def main( hklin_file, hklout_file, mtzout, project, crystal, dataset, cell, spac print( "making mtz" ) print( "using cell constants\n{0} {1} {2} A {3} {4} {5} deg".format( cell[0], cell[1], cell[2], cell[3], cell[4], cell[5] ) ) print( "Titles in mtz will be:\nPROJECT {0} CRYSTAL {1} DATASET {2}".format( project, crystal, dataset ) ) - make_mtz( hklout_file, mtzout, project, crystal, dataset, cell, spacegroup ) + make_mtz( hklout_file, mtzout, project, crystal, dataset, cell, spacegroup, residues, res_range ) print( "done" ) def list_of_floats(arg): @@ -182,6 +212,18 @@ if __name__ == "__main__": help="list of complete cell length and angles, e.g. 59.3,59.3,153.1,90.0,90.0,90.0. They all should be floats", type=list_of_floats ) + parser.add_argument( + "-r", + "--residues", + help="number of residues for truncate, e.g., hewl = 129", + type=int + ) + parser.add_argument( + "-A", + "--resolution_range", + help="list of 2 floats - low res then high res cut off, e.g., 50.0,1.3", + type=list_of_floats + ) parser.add_argument( "-s", "--stream_file", @@ -200,7 +242,7 @@ if __name__ == "__main__": if args.stream_file: print( "reading stream file" ) cell, xtals = get_mean_cell( args.stream_file ) - print( "found {0} xtats".format( xtals ) ) + print( "found {0} xtals".format( xtals ) ) print( "mean lengths = {0}, {1}, {2} A".format( cell[0], cell[1], cell[2] ) ) print( "mean angles = {0}, {1}, {2} deg".format( cell[3], cell[4], cell[5] ) ) print( "# for input to make_mtz = {0},{1},{2},{3},{4},{5}".format( cell[0], cell[1], cell[2], cell[3], cell[4], cell[5] ) ) @@ -210,11 +252,11 @@ if __name__ == "__main__": mtzout = args.mtzout else: mtzout = os.path.splitext( args.hklin )[0] + ".mtz" - main( args.hklin, hklout_file, mtzout, args.project, args.crystal, args.dataset, cell, args.spacegroup ) + main( args.hklin, hklout_file, mtzout, args.project, args.crystal, args.dataset, cell, args.spacegroup, args.residues, args.resolution_range ) if args.stream_file == None and args.use_stream == False: hklout_file = os.path.splitext( args.hklin )[0] + "_cut.hkl" if args.mtzout: mtzout = args.mtzout else: mtzout = os.path.splitext( args.hklin )[0] + ".mtz" - main( args.hklin, hklout_file, mtzout, args.project, args.crystal, args.dataset, args.cell, args.spacegroup ) + main( args.hklin, hklout_file, mtzout, args.project, args.crystal, args.dataset, args.cell, args.spacegroup, args.residues, args.resolution_range )