88import subprocess
99from shutil import ignore_patterns
1010
11- from iotbx import pdb
12-
1311# import molviewspec as mvs
1412import dlstbx .util .symlink
1513from dlstbx .wrapper import Wrapper
@@ -26,10 +24,11 @@ def pull_CC_from_log(self, pipeline_directory):
2624 llist = []
2725 for line in lines :
2826 if text in line :
29- llist .append (line )
27+ match = re .search (r"CC\s*=\s*([0-9.]+)" , line )
28+ if match :
29+ llist .append (match .group (1 ))
3030 file_read .close ()
31- match = re .search (r"CC\s*=\s*([0-9.]+)" , llist [- 1 ])
32- CC = float (match .group (1 ))
31+ CC = llist [- 1 ] # take the final CC
3332 return CC
3433
3534 def send_attachments_to_ispyb (self , pipeline_directory , final_directory ):
@@ -54,7 +53,7 @@ def send_attachments_to_ispyb(self, pipeline_directory, final_directory):
5453 try :
5554 shutil .copy (pipeline_directory / f .name , final_directory )
5655 result_dict = {
57- "file_path" : str (pipeline_directory ),
56+ "file_path" : str (final_directory ),
5857 "file_name" : f .name ,
5958 "file_type" : file_type ,
6059 "importance_rank" : importance_rank ,
@@ -140,9 +139,6 @@ def run(self):
140139 self .send_attachments_to_ispyb (pipeline_directory )
141140 return False
142141
143- with open (working_directory / "ligand_fit.log" , "w" ) as log_file :
144- log_file .write (result .stdout )
145-
146142 CC = self .pull_CC_from_log (pipeline_directory )
147143
148144 if CC >= min_cc_keep :
@@ -199,114 +195,3 @@ def run(self):
199195 # mol = pybel.readstring("smi", smiles)
200196 # mol.make2D()
201197 # mol.draw(show=False, filename=(f"{outdir}/SMILES.png"))
202-
203-
204- # def generate_html_visualisation(pdb_file, map_file, outdir, acr, smiles, cc):
205- # # generate html with multiple snapshots
206- # builder = mvs.create_builder()
207- # structure = builder.download(url=pdb_file).parse(format="pdb").model_structure()
208- # structure.component(selector="polymer").representation(
209- # type="surface", size_factor=0.7
210- # ).opacity(opacity=0.6).color(color="#EEC4EE")
211- # structure.component(selector="polymer").representation().opacity(opacity=0.6).color(
212- # color="grey"
213- # )
214- # structure.component(selector="ligand").representation(type="ball_and_stick").color(
215- # custom={"molstar_color_theme_name": "element-symbol"}
216- # )
217- # structure.component(selector="ligand").representation(type="surface").opacity(
218- # opacity=0.1
219- # ).color(custom={"molstar_color_theme_name": "element-symbol"})
220-
221- # ccp4 = builder.download(url=map_file).parse(format="map")
222- # ccp4.volume().representation(
223- # type="isosurface",
224- # relative_isovalue=1.5,
225- # show_wireframe=True,
226- # show_faces=False,
227- # ).color(color="blue").opacity(opacity=0.25)
228-
229- # snapshot1 = builder.get_snapshot(
230- # title="Main View",
231- # description=f"## Ligand_Fit Results: \n ### {acr} with ligand & electron density map \n - SMILES: {smiles} \n - 2FO-FC at 1.5σ, blue \n - Fitting CC = {cc}",
232- # transition_duration_ms=2000,
233- # linger_duration_ms=5000,
234- # )
235-
236- # # snapshot 2
237- # builder = mvs.create_builder()
238- # structure = builder.download(url=pdb_file).parse(format="pdb").model_structure()
239- # structure.component(selector="polymer").representation(
240- # type="surface", size_factor=0.7
241- # ).opacity(opacity=0.5).color(color="#D8BFD8")
242- # structure.component(selector="polymer").representation().opacity(opacity=0.6).color(
243- # color="grey"
244- # )
245- # structure.component(selector="ligand").focus().representation(
246- # type="ball_and_stick"
247- # ).color(custom={"molstar_color_theme_name": "element-symbol"})
248-
249- # ccp4 = builder.download(url=map_file).parse(format="map")
250- # ccp4.volume().representation(
251- # type="isosurface",
252- # relative_isovalue=1.5,
253- # show_wireframe=True,
254- # show_faces=False,
255- # ).color(color="blue").opacity(opacity=0.25)
256-
257- # # add a label
258- # info = get_chain_and_residue_numbers(pdb_file, "LIG")
259- # resid = info[0][1]
260- # residue = mvs.ComponentExpression(label_seq_id=resid)
261- # (
262- # structure.component(
263- # selector=residue,
264- # custom={
265- # "molstar_show_non_covalent_interactions": True,
266- # "molstar_non_covalent_interactions_radius_ang": 5.0,
267- # },
268- # ).label(text=f"CC = {cc}")
269- # )
270-
271- # snapshot2 = builder.get_snapshot(
272- # title="Focus View",
273- # description=f"## Ligand_Fit Results: \n ### {acr} with ligand & electron density map \n - SMILES: {smiles} \n - 2FO-FC at 1.5σ, blue \n - Fitting CC = {cc}",
274- # transition_duration_ms=2000,
275- # linger_duration_ms=5000,
276- # )
277-
278- # states = mvs.States(
279- # snapshots=[snapshot1, snapshot2],
280- # metadata=mvs.GlobalMetadata(description="Ligand_fit Results"),
281- # )
282-
283- # with open(pdb_file) as f:
284- # pdb_data = f.read()
285-
286- # with open(map_file, mode="rb") as f:
287- # map_data = f.read()
288-
289- # html = mvs.molstar_widgets.molstar_html(
290- # states,
291- # data={pdb_file: pdb_data, map_file: map_data},
292- # ui="stories",
293- # )
294-
295- # with open(outdir / "ligand_fit.html", "w") as f:
296- # f.write(html)
297-
298-
299- def get_chain_and_residue_numbers (pdb_file_path , target_residue_name ):
300- """
301- Finds (chain ID, residue number) for a given residue name in a PDB file.
302- """
303- pdb_hierarchy = pdb .input (file_name = pdb_file_path ).construct_hierarchy ()
304-
305- results = [
306- (res .parent ().id .strip (), f"{ res .resseq .strip ()} { res .icode .strip () or '' } " )
307- for res in pdb_hierarchy .residue_groups ()
308- for ag in res .atom_groups ()
309- if ag .resname .strip () == target_residue_name
310- ]
311-
312- return results
0 commit comments