1111import numpy as np
1212import yaml
1313
14- # import molviewspec as mvs
1514from dlstbx .wrapper import Wrapper
1615
1716
@@ -36,7 +35,7 @@ def run(self):
3635 Path (auto_panddas_dir ).mkdir (exist_ok = True )
3736
3837 n_datasets = int (params .get ("n_datasets" ))
39- if n_datasets > 1 :
38+ if n_datasets > 1 : # array job case
4039 with open (model_dir / ".batch.json" , "r" ) as f :
4140 datasets = json .load (f )
4241 dtag = datasets [int (slurm_task_id ) - 1 ]
@@ -58,11 +57,9 @@ def run(self):
5857 self .log .error (
5958 f"Multiple .smiles files found in in { compound_dir } :, { smiles_files } , warning for dtag { dtag } "
6059 )
61- else :
62- smiles_file = smiles_files [0 ]
63- CompoundCode = smiles_file .stem
60+ return False
6461
65- smiles_file = next ( Path ( compound_dir ). rglob ( "*.smiles" ), None )
62+ smiles_file = smiles_files [ 0 ]
6663 CompoundCode = smiles_file .stem
6764
6865 # -------------------------------------------------------
@@ -122,25 +119,16 @@ def run(self):
122119 return False
123120
124121 dataset_pdir = auto_panddas_dir / "processed_datasets" / dtag
122+ ligand_dir = dataset_pdir / "ligand_files"
125123
126124 pandda_log = dataset_pdir / "pandda2.log"
127125 with open (pandda_log , "w" ) as log_file :
128126 log_file .write (result .stdout )
129127
130- # -------------------------------------------------------
131- # Integrate back with XCE via datasource
132- # db_dict = {}
133- # db_dict["DimplePANDDAwasRun"] = True
134- # # db_dict["DimplePANDDAreject"] = False
135- # db_dict["DimplePANDDApath"] = str(auto_panddas_dir / "processed_datasets")
136-
137- # try:
138- # self.update_data_source(db_dict, dtag, database_path)
139- # self.log.info(f"Updated sqlite database for dataset {dtag}")
140- # except Exception as e:
141- # self.log.info(f"Could not update sqlite database for dataset {dtag}: {e}")
128+ for item in compound_dir .iterdir ():
129+ if item .is_file ():
130+ shutil .copy2 (item , ligand_dir / item .name )
142131
143- # -------------------------------------------------------
144132 modelled_dir = dataset_pdir / "modelled_structures"
145133 out_dir = modelled_dir / "rhofit"
146134 out_dir .mkdir (parents = True , exist_ok = True )
@@ -164,7 +152,6 @@ def run(self):
164152 # bdc = best_entry["BDC"]
165153 coord = best_entry ["Centroid" ]
166154
167- ligand_dir = dataset_pdir / "ligand_files"
168155 build_dmap = dataset_pdir / f"{ dtag } -z_map.native.ccp4"
169156 restricted_build_dmap = dataset_pdir / "build.ccp4"
170157 pdb_file = dataset_pdir / f"{ dtag } -pandda-input.pdb"
@@ -196,15 +183,18 @@ def run(self):
196183 # Really all the cifs should be tried and the best used, or it should try the best
197184 # cif from PanDDA
198185 # This is a temporary fix that will get 90% of situations that can be improved upon
199- cifs = [ x for x in ligand_dir .glob ("*.cif" )]
186+ cifs = list ( ligand_dir .glob ("*.cif" ))
200187 if len (cifs ) == 0 :
201- self .log .error ("No .cif files found!" )
188+ self .log .error (
189+ f"No .cif files found for dtag { dtag } , cannot launch PanDDA2 Rhofit!"
190+ )
191+ return True
202192
203193 # -------------------------------------------------------
204194 rhofit_command = f"module load buster; source { PANDDA_2_DIR } /venv/bin/activate; \
205195 { PANDDA_2_DIR } /scripts/pandda_rhofit.sh -pdb { restricted_pdb_file } -map { build_dmap } -mtz { mtz_file } -cif { cifs [0 ]} -out { out_dir } -cut { dmap_cut } ; "
206196
207- self .log .info (f"Running rhofit command: { rhofit_command } " )
197+ self .log .info (f"Running PanDDA Rhofit command: { rhofit_command } " )
208198
209199 try :
210200 result = subprocess .run (
@@ -237,13 +227,12 @@ def run(self):
237227 contact_chain = self .get_contact_chain (protein_st , ligand_st )
238228 protein_st [0 ][contact_chain ].add_residue (ligand_st [0 ][0 ][0 ])
239229
240- protein_st .write_pdb (str (output_file ))
230+ if output_file .exists ():
231+ shutil .copy (output_file , modelled_dir / "pandda-internal-fitted.pdb" )
241232
242- pandda_model = {modelled_dir } / f"{ dtag } -pandda-model.pdb"
243- if pandda_model .exists ():
244- shutil .copy (pandda_model , modelled_dir / "pandda-internal-fitted.pdb" )
233+ protein_st .write_pdb (str (output_file ))
245234
246- self .log .info ("Auto PanDDA2 pipeline finished successfully" )
235+ self .log .info (f "Auto PanDDA2 pipeline finished successfully for dtag { dtag } " )
247236 return True
248237
249238 def save_xmap (self , xmap , xmap_file ):
@@ -406,3 +395,15 @@ def update_data_source(self, db_dict, dtag, database_path):
406395 cursor = conn .cursor ()
407396 cursor .execute (sql , db_dict )
408397 conn .commit ()
398+
399+ # Integrate back with XCE via datasource
400+ # db_dict = {}
401+ # db_dict["DimplePANDDAwasRun"] = True
402+ # # db_dict["DimplePANDDAreject"] = False
403+ # db_dict["DimplePANDDApath"] = str(auto_panddas_dir / "processed_datasets")
404+
405+ # try:
406+ # self.update_data_source(db_dict, dtag, database_path)
407+ # self.log.info(f"Updated sqlite database for dataset {dtag}")
408+ # except Exception as e:
409+ # self.log.info(f"Could not update sqlite database for dataset {dtag}: {e}")
0 commit comments