@@ -238,7 +238,7 @@ def trigger_pandda_xchem(
238238 proposal = query .first ()
239239
240240 # 0. Check that this is an XChem expt & locate .SQLite database
241- if proposal .proposalCode not in {"lb" }: # need to handle industrial 'sw' also
241+ if proposal .proposalCode not in {"lb" }:
242242 self .log .debug (
243243 f"Not triggering PanDDA2 pipeline for dcid={ dcid } with proposal_code={ proposal .proposalCode } "
244244 )
@@ -338,12 +338,6 @@ def trigger_pandda_xchem(
338338 db = processing_dir / "database" / "soakDBDataFile.sqlite"
339339 processed_dir = xchem_visit_dir / "processed"
340340
341- # Make a copy of the most recent sqlite for reading
342- # db_copy = xchem_visit_dir / "processing/database" / "auto_soakDBDataFile.sqlite"
343- # if not db_copy.exists() or (db.stat().st_mtime != db_copy.stat().st_mtime):
344- # shutil.copy2(str(db), str(db_copy))
345- # self.log.info(f"Made a copy of {db}, auto_soakDBDataFile.sqlite")
346-
347341 # 1. Trigger when all upstream pipelines & related dimple jobs have finished
348342
349343 program_list = [
@@ -600,11 +594,10 @@ def trigger_pandda_xchem(
600594 self .log .info (f"Chosen mtz for dcid { dcid } is { upstream_mtz } " )
601595 else :
602596 self .log .info (
603- "Exiting PanDDA2/Pipedream trigger: no environment information"
597+ f "Exiting PanDDA2/Pipedream trigger: no environment information for dcid { dcid } "
604598 )
605599 return {"success" : True }
606600
607- # upstream_proc = df[df['autoProcScalingId']==scaling_id]['processingPrograms'].item() # fails
608601 pdb = chosen_dataset_path + "/final.pdb"
609602 mtz = chosen_dataset_path + "/final.mtz"
610603
@@ -634,7 +627,7 @@ def trigger_pandda_xchem(
634627
635628 except Exception as e :
636629 self .log .info (
637- f"Exiting PanDDA2/Pipedream trigger: Exception whilst reading ligand information from { db } for dtag { dtag } : { e } "
630+ f"Exiting PanDDA2/Pipedream trigger: Exception whilst reading ligand information from { db } for dtag { dtag } , dcid { dcid } : { e } "
638631 )
639632 return {"success" : True }
640633
@@ -644,7 +637,7 @@ def trigger_pandda_xchem(
644637
645638 if len (df ) != 1 :
646639 self .log .info (
647- f"Exiting PanDDA2/Pipedream trigger: Unique row in .sqlite for dtag { dtag } , puck { code } , puck position { location } cannot be found in { db } , skipping... "
640+ f"Exiting PanDDA2/Pipedream trigger: Unique row in .sqlite for dtag { dtag } , puck { code } , puck position { location } cannot be found in { db } , skipping dcid { dcid } "
648641 )
649642 return {"success" : True }
650643
@@ -683,13 +676,33 @@ def trigger_pandda_xchem(
683676 # Copy the dimple files of the selected dataset
684677 shutil .copy (pdb , str (dataset_dir / "dimple.pdb" ))
685678 shutil .copy (mtz , str (dataset_dir / "dimple.mtz" ))
686- shutil .copy (
687- upstream_mtz , str (dataset_dir / pathlib .Path (upstream_mtz ).parts [- 1 ])
688- )
679+ shutil .copy (upstream_mtz , str (dataset_dir / f"{ dtag } .free.mtz" ))
689680
690681 with open (compound_dir / f"{ CompoundCode } .smiles" , "w" ) as smi_file :
691682 smi_file .write (CompoundSMILES )
692683
684+ # Check if Pipedream job was recently launched
685+ min_start_time = datetime .now () - timedelta (hours = 3 )
686+
687+ query = (
688+ (
689+ session .query (AutoProcProgram , ProcessingJob .dataCollectionId ).join (
690+ ProcessingJob ,
691+ ProcessingJob .processingJobId == AutoProcProgram .processingJobId ,
692+ )
693+ )
694+ .filter (ProcessingJob .dataCollectionId == dcid )
695+ .filter (ProcessingJob .automatic == True ) # noqa E711
696+ .filter (AutoProcProgram .processingPrograms .in_ (["Pipedream" ]))
697+ .filter (AutoProcProgram .recordTimeStamp > min_start_time )
698+ )
699+
700+ if triggered_processing_job := query .first ():
701+ self .log .info (
702+ f"Pipedream job recently launched for dcid { dcid } , skipping pipedream trigger"
703+ )
704+ pipedream = False
705+
693706 # Create seperate pipedream directory
694707 if pipedream :
695708 pipedream_dir = analysis_dir / "pipedream"
@@ -700,9 +713,7 @@ def trigger_pandda_xchem(
700713 pathlib .Path (compound_dir_pd ).mkdir (parents = True , exist_ok = True )
701714 shutil .copy (pdb , str (dataset_dir_pd / "dimple.pdb" ))
702715 shutil .copy (mtz , str (dataset_dir_pd / "dimple.mtz" ))
703- shutil .copy (
704- upstream_mtz , str (dataset_dir_pd / pathlib .Path (upstream_mtz ).parts [- 1 ])
705- )
716+ shutil .copy (upstream_mtz , str (dataset_dir_pd / f"{ dtag } .free.mtz" ))
706717
707718 with open (compound_dir_pd / f"{ CompoundCode } .smiles" , "w" ) as smi_file :
708719 smi_file .write (CompoundSMILES )
0 commit comments