88import subprocess
99from shutil import ignore_patterns
1010
11- # import molviewspec as mvs
1211from iotbx import pdb
13- from rdkit import Chem
14- from rdkit .Chem import Draw
12+
13+ # import molviewspec as mvs
14+ from openbabel import pybel
1515
1616import dlstbx .util .symlink
1717from dlstbx .wrapper import Wrapper
@@ -34,7 +34,7 @@ def pull_CC_from_log(self, pipeline_directory):
3434 CC = float (match .group (1 ))
3535 return CC
3636
37- def send_attachments_to_ispyb (self , pipeline_directory ):
37+ def send_attachments_to_ispyb (self , pipeline_directory , final_directory ):
3838 for f in pipeline_directory .iterdir ():
3939 if f .stem .endswith ("final" ):
4040 file_type = "Result"
@@ -54,6 +54,7 @@ def send_attachments_to_ispyb(self, pipeline_directory):
5454 else :
5555 continue
5656 try :
57+ shutil .copy (pipeline_directory / f .name , final_directory )
5758 result_dict = {
5859 "file_path" : str (pipeline_directory ),
5960 "file_name" : f .name ,
@@ -62,6 +63,7 @@ def send_attachments_to_ispyb(self, pipeline_directory):
6263 }
6364 self .record_result_individual_file (result_dict )
6465 self .log .info (f"Uploaded { f .name } as an attachment" )
66+
6567 except Exception :
6668 self .log .warning (f"Could not attach { f .name } to ISPyB" , exc_info = True )
6769
@@ -102,6 +104,15 @@ def run(self):
102104 working_directory .mkdir (parents = True , exist_ok = True )
103105 results_directory = pathlib .Path (params ["results_directory" ])
104106 results_directory .mkdir (parents = True , exist_ok = True )
107+
108+ if pipeline_final_params := params .get ("pipeline-final" , []):
109+ final_directory = pathlib .Path (pipeline_final_params ["path" ])
110+ final_directory .mkdir (parents = True , exist_ok = True )
111+ if params .get ("create_symlink" ):
112+ dlstbx .util .symlink .create_parent_symlink (
113+ final_directory , params .get ("create_symlink" )
114+ )
115+
105116 with open (working_directory / "LIG.smi" , "w" ) as smi_file :
106117 smi_file .write (smiles )
107118
@@ -110,7 +121,7 @@ def run(self):
110121 # if pipeline == "phenix":
111122 # phenix_command = f"phenix.ligandfit data={mtz} model={pdb} ligand=LIG.smi min_ligand_cc_keep={min_cc_keep} nproc=8" # ligand={ligand_code}
112123 if pipeline == "phenix_pipeline" :
113- phenix_command = f"phenix.ligand_pipeline { pdb } { mtz } LIG.smi min_ligand_cc_keep={ min_cc_keep } nproc=8"
124+ phenix_command = f"phenix.ligand_pipeline { pdb } { mtz } LIG.smi min_ligand_cc_keep={ min_cc_keep } nproc=8" # build=False
114125
115126 try :
116127 result = subprocess .run (
@@ -145,7 +156,7 @@ def run(self):
145156 acr = params .get ("acronym" , "Protein" )
146157
147158 os .system (
148- f"module load molviewspec; gen_html .py --pdb_file { out_pdb } --map_file { out_map } --cc { CC } --outdir { pipeline_directory } --smiles '{ smiles } ' --acr { acr } "
159+ f"module load molviewspec; gen_html_ligandfit .py --pdb_file { out_pdb } --map_file { out_map } --cc { CC } --outdir { pipeline_directory } --smiles '{ smiles } ' --acr { acr } "
149160 )
150161
151162 self .generate_smiles_png (smiles , pipeline_directory )
@@ -175,7 +186,7 @@ def run(self):
175186 )
176187
177188 self .log .info ("Sending results to ISPyB" )
178- self .send_attachments_to_ispyb (pipeline_directory )
189+ self .send_attachments_to_ispyb (pipeline_directory , final_directory )
179190
180191 if CC >= min_cc_keep :
181192 self .log .info ("Ligand_fitting pipeline finished successfully" )
@@ -187,9 +198,9 @@ def run(self):
187198 return False
188199
189200 def generate_smiles_png (self , smiles , outdir ):
190- mol = Chem . MolFromSmiles ( smiles )
191- img = Draw . MolToImage ( mol , size = ( 450 , 450 ) )
192- img . save ( f"{ outdir } /SMILES.png" )
201+ mol = pybel . readstring ( "smi" , smiles )
202+ mol . make2D ( )
203+ mol . draw ( show = False , filename = ( f"{ outdir } /SMILES.png" ) )
193204
194205
195206# def generate_html_visualisation(pdb_file, map_file, outdir, acr, smiles, cc):
0 commit comments