Skip to content

Commit 7734694

Browse files
committed
Pipedream trigger minor fix
1 parent 370d49d commit 7734694

2 files changed

Lines changed: 36 additions & 23 deletions

File tree

src/dlstbx/services/trigger_xchem.py

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -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)

src/dlstbx/wrapper/pandda_xchem.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,7 @@ def run(self):
6565

6666
# -------------------------------------------------------
6767
# acedrg_command = f"module load ccp4; acedrg -i {smiles_file} -o {CompoundCode}"
68-
restraints_command = f"module load buster; module load graphviz; \
69-
export CSDHOME=/dls_sw/apps/CSDS/2024.1.0/; export BDG_TOOL_MOGUL=/dls_sw/apps/CSDS/2024.1.0/ccdc-software/mogul/bin/mogul; \
70-
grade2 --in {smiles_file} --itype smi --out {CompoundCode} -f"
68+
restraints_command = f"grade2 --in {smiles_file} --itype smi --out {CompoundCode} -f"
7169

7270
try:
7371
result = subprocess.run(
@@ -97,7 +95,7 @@ def run(self):
9795
with open(dataset_dir / "restraints.log", "w") as log_file:
9896
log_file.write(result.stdout)
9997

100-
self.log.info(f"Restraints generated succesfully for dtag {dtag}")
98+
self.log.info(f"Restraints generated succesfully for dtag {dtag}, launching PanDDA2")
10199

102100
pandda2_command = f"source /dls_sw/i04-1/software/PanDDA2/venv/bin/activate; \
103101
python -u /dls_sw/i04-1/software/PanDDA2/scripts/process_dataset.py --data_dirs={model_dir} --out_dir={auto_panddas_dir} --dtag={dtag} --use_ligand_data=False --local_cpus=1"
@@ -122,10 +120,14 @@ def run(self):
122120
dataset_pdir = auto_panddas_dir / "processed_datasets" / dtag
123121
ligand_dir = dataset_pdir / "ligand_files"
124122

123+
# pandda2 not moving files into ligand_dir, fix
125124
for file in compound_dir.rglob("*"):
126125
if file.is_file() and file.suffix.lower() in {".pdb", ".cif", ".smiles"}:
127-
target = ligand_dir / file.name
128-
shutil.copy2(file, target)
126+
targets = [ligand_dir / file.name, dataset_dir / file.name]
127+
for target in targets:
128+
if target.exists() or target.is_symlink():
129+
target.unlink()
130+
target.symlink_to(file)
129131

130132
pandda_log = dataset_pdir / "pandda2.log"
131133
with open(pandda_log, "w") as log_file:

0 commit comments

Comments
 (0)