changes to argparese for endstation and use mosflm for indexing

This commit is contained in:
Beale John Henry
2023-10-10 09:14:30 +02:00
parent 5e6b5160f1
commit ae019084f2

View File

@@ -13,6 +13,7 @@ python detector-distance-refinement.py -l <path to lst file generated by daq>
-d central clen to refine around
-c cell_file
-s sample size
-e endstation - alvra or cristallina
# other variables
-f = fine only = only perform fine scan
@@ -76,7 +77,7 @@ def geom_amend( lab6_geom_file, clen ):
# return clen_geom file name
return clen_geom_file
def write_crystfel_run( clen, sample_h5_file, clen_geom_file, cell_file ):
def write_crystfel_run( clen, sample_h5_file, clen_geom_file, cell_file, threshold ):
# crystfel file name
cryst_run_file = "{0}_run.sh".format( clen )
@@ -90,9 +91,9 @@ def write_crystfel_run( clen, sample_h5_file, clen_geom_file, cell_file ):
run_sh.write( " --output={0}.stream \\\n".format( clen ) )
run_sh.write( " --geometry={0}\\\n".format( clen_geom_file ) )
run_sh.write( " --pdb={0} \\\n".format( cell_file ) )
run_sh.write( " --indexing=xgandalf-latt-cell --peaks=peakfinder8 \\\n" )
run_sh.write( " --threshold=15 --min-snr=10 --int-radius=3,5,9 \\\n" )
run_sh.write( " -j 36 --no-multi --no-retry --max-res=3000 --min-pix-count=2 --min-res=85\n\n" )
run_sh.write( " --indexing=mosflm --peaks=peakfinder8 \\\n" )
run_sh.write( " --threshold={0} --min-snr=5 --int-radius=3,5,9 \\\n".format( threshold ) )
run_sh.write( " -j 32 --no-multi --no-retry --max-res=3000 --min-pix-count=2 --min-res=85\n\n" )
run_sh.close()
# make file executable
@@ -234,7 +235,6 @@ def scrub_helper( top_dir ):
stream_pwd, clen = row[ "stream_pwd" ], row[ "clen" ]
# open stream file
print( "scrubbing stream for clen={0}".format( clen ) )
stream = open( stream_pwd, "r" ).read()
# scrub unit cell information
@@ -267,10 +267,9 @@ def scrub_helper( top_dir ):
stats_df_1 = pd.DataFrame( stats )
stats_df = pd.concat( ( stats_df, stats_df_1 ) )
print( "done" )
# reset index
stats_df = stats_df.reset_index( drop=True )
print( "done" )
return stats_df
@@ -346,7 +345,7 @@ def plot_indexed_std_alpha_beta_gamma( stats_df, ax1, ax2 ):
color = "green"
ax2.plot(stats_df.clen, stats_df.std_gamma, color=color)
def scan( cwd, lst, sample, lab6_geom_file, centre_clen, cell_file, step_size ):
def scan( cwd, lst, sample, lab6_geom_file, centre_clen, cell_file, threshold, step_size ):
# define coarse or fine scan
if step_size == "coarse":
@@ -374,7 +373,6 @@ def scan( cwd, lst, sample, lab6_geom_file, centre_clen, cell_file, step_size ):
# loop to cycle through clen steps
for clen in step_range:
print( "processing clen = {0}".format( clen ) )
# define process directory
proc_dir = "{0}/{1}/{2}".format( cwd, scan_name, clen )
@@ -388,13 +386,12 @@ def scan( cwd, lst, sample, lab6_geom_file, centre_clen, cell_file, step_size ):
clen_geom_file = geom_amend( lab6_geom_file, clen )
# make crystfel run file
cryst_run_file = write_crystfel_run( clen, sample_h5_file, clen_geom_file, cell_file )
cryst_run_file = write_crystfel_run( clen, sample_h5_file, clen_geom_file, cell_file, threshold )
# run crystfel file
job_list.append( cryst_run_file )
job_id = submit_job( cryst_run_file )
submitted_job_ids.add( job_id )
print( "done" )
# move back to cwd
os.chdir( cwd )
@@ -428,13 +425,13 @@ def scrub_scan( scan_top_dir, scan ):
return suggested_clen
def main( cwd, lst, sample, geom, centre_clen, cell_file, fine_only ):
def main( cwd, lst, sample, geom, centre_clen, cell_file, fine_only, threshold ):
# if statement to do coarse if fine_only==False
if fine_only == False:
top_dir_coarse = "{0}/coarse".format( cwd )
scan( cwd, lst, sample, geom, centre_clen, cell_file, step_size="coarse" )
scan( cwd, lst, sample, geom, centre_clen, cell_file, threshold, step_size="coarse" )
suggested_clen = scrub_scan( top_dir_coarse, scan="coarse" )
else:
@@ -442,7 +439,7 @@ def main( cwd, lst, sample, geom, centre_clen, cell_file, fine_only ):
top_dir_fine = "{0}/fine".format( cwd )
scan( cwd, lst, sample, geom, suggested_clen, cell_file, step_size="fine" )
scan( cwd, lst, sample, geom, suggested_clen, cell_file, threshold, step_size="fine" )
scrub_scan( top_dir_fine, scan="fine" )
plt.show()
@@ -453,25 +450,29 @@ if __name__ == "__main__":
"-l",
"--lst",
help="path to crystfel list file containing enough patterns for detector distance refinement",
type=os.path.abspath
type=os.path.abspath,
required=True
)
parser.add_argument(
"-g",
"--geom",
help="path to geom file to be used in the refinement",
type=os.path.abspath
type=os.path.abspath,
required=True
)
parser.add_argument(
"-d",
"--central_distance",
help="intial clen to use for refinement - usually from detector shift refinement",
type=float
type=float,
required=True
)
parser.add_argument(
"-c",
"--cell_file",
help="path to cell file of the crystals used in the refinement",
type=os.path.abspath
type=os.path.abspath,
required=True
)
parser.add_argument(
"-s",
@@ -487,9 +488,24 @@ if __name__ == "__main__":
type=bool,
default=False
)
parser.add_argument(
"-e",
"--endstation",
help="which endstation did you collect these data from, e.g., alvra or cristallina",
type=str,
default="cristallina"
)
args = parser.parse_args()
# set threshold based on endstation
if args.endstation == "alvra":
threshold = 3000
elif args.endstation == "cristallina":
threshold = 10
else:
print( "you must say which beamline you collected the data on, alvra or cristallina, to set the threshold value correctly for crystfel" )
exit()
# run main
cwd = os.getcwd()
print( "top working directory = {0}".format( cwd ) )
main( cwd, args.lst, args.sample, args.geom, args.central_distance, args.cell_file, args.fine_only )
main( cwd, args.lst, args.sample, args.geom, args.central_distance, args.cell_file, args.fine_only, threshold )