From f32e4867479d9ff1a5d17ea4a4740fc5aa23fb49 Mon Sep 17 00:00:00 2001 From: Rodrigo V Honorato Date: Wed, 8 Dec 2021 14:01:55 +0100 Subject: [PATCH] implement `sampling_factor` parameter in refinement modules --- examples/refine-complex/refine-complex.cfg | 1 + .../modules/refinement/emref/__init__.py | 62 ++++++++++------- .../modules/refinement/emref/defaults.cfg | 1 + .../modules/refinement/flexref/__init__.py | 66 +++++++++++-------- .../modules/refinement/flexref/defaults.cfg | 1 + .../modules/refinement/mdref/__init__.py | 65 +++++++++++------- .../modules/refinement/mdref/defaults.cfg | 1 + 7 files changed, 123 insertions(+), 74 deletions(-) diff --git a/examples/refine-complex/refine-complex.cfg b/examples/refine-complex/refine-complex.cfg index cfcf2afd0..9ff916374 100644 --- a/examples/refine-complex/refine-complex.cfg +++ b/examples/refine-complex/refine-complex.cfg @@ -32,6 +32,7 @@ hise_1 = 15 [mdref] noecv = false +sampling_factor = 10 [caprieval] reference = 'data/e2a-hpr_1GGR.pdb' diff --git a/src/haddock/modules/refinement/emref/__init__.py b/src/haddock/modules/refinement/emref/__init__.py index 5231510cd..5c97b9724 100644 --- a/src/haddock/modules/refinement/emref/__init__.py +++ b/src/haddock/modules/refinement/emref/__init__.py @@ -40,33 +40,49 @@ def _run(self): self.finish_with_error(e) refined_structure_list = [] - for idx, model in enumerate(models_to_refine, start=1): - inp_file = prepare_cns_input( - idx, - model, - self.path, - self.recipe_str, - self.params, - "emref", - ambig_fname=self.params["ambig_fname"], - ) - out_file = Path(self.path, f"emref_{idx}.out") + idx = 1 + sampling_factor = self.params["sampling_factor"] + if sampling_factor > 1: + self.log(f"sampling_factor={sampling_factor}") + if sampling_factor == 0: + self.log("[Warning] sampling_factor cannot be 0, setting it to 1") + sampling_factor = 1 + if sampling_factor > 100: + self.log("[Warning] sampling_factor is larger than 100") + + idx = 1 + for model in models_to_refine: + for _ in range(self.params['sampling_factor']): + inp_file = prepare_cns_input( + idx, + model, + self.path, + self.recipe_str, + self.params, + "emref", + ambig_fname=self.params["ambig_fname"], + ) + out_file = Path(self.path, f"emref_{idx}.out") + + # create the expected PDBobject + expected_pdb = prepare_expected_pdb( + model, idx, self.path, "emref" + ) - # create the expected PDBobject - expected_pdb = prepare_expected_pdb(model, idx, self.path, "emref") + refined_structure_list.append(expected_pdb) - refined_structure_list.append(expected_pdb) + job = CNSJob( + inp_file, + out_file, + cns_folder=self.cns_folder_path, + modpath=self.path, + config_path=self.params["config_path"], + cns_exec=self.params["cns_exec"], + ) - job = CNSJob( - inp_file, - out_file, - cns_folder=self.cns_folder_path, - modpath=self.path, - config_path=self.params["config_path"], - cns_exec=self.params["cns_exec"], - ) + jobs.append(job) - jobs.append(job) + idx += 1 # Run CNS engine self.log(f"Running CNS engine with {len(jobs)} jobs") diff --git a/src/haddock/modules/refinement/emref/defaults.cfg b/src/haddock/modules/refinement/emref/defaults.cfg index f825a8b29..e9e003d26 100644 --- a/src/haddock/modules/refinement/emref/defaults.cfg +++ b/src/haddock/modules/refinement/emref/defaults.cfg @@ -1,4 +1,5 @@ log_level = "verbose" +sampling_factor = 1 ambig_fname = "" unambig_fname = "" hbond_fname = "" diff --git a/src/haddock/modules/refinement/flexref/__init__.py b/src/haddock/modules/refinement/flexref/__init__.py index 150a174a4..929d6e4c6 100644 --- a/src/haddock/modules/refinement/flexref/__init__.py +++ b/src/haddock/modules/refinement/flexref/__init__.py @@ -39,35 +39,49 @@ def _run(self): self.finish_with_error(e) refined_structure_list = [] - for idx, model in enumerate(models_to_refine, start=1): - inp_file = prepare_cns_input( - idx, - model, - self.path, - self.recipe_str, - self.params, - "flexref", - ambig_fname=self.params["ambig_fname"], - ) + idx = 1 + sampling_factor = self.params["sampling_factor"] + if sampling_factor > 1: + self.log(f"sampling_factor={sampling_factor}") + if sampling_factor == 0: + self.log("[Warning] sampling_factor cannot be 0, setting it to 1") + sampling_factor = 1 + if sampling_factor > 100: + self.log("[Warning] sampling_factor is larger than 100") + + idx = 1 + for model in models_to_refine: + for _ in range(self.params['sampling_factor']): + inp_file = prepare_cns_input( + idx, + model, + self.path, + self.recipe_str, + self.params, + "flexref", + ambig_fname=self.params["ambig_fname"], + ) - out_file = Path(self.path, f"flexref_{idx}.out") + out_file = Path(self.path, f"flexref_{idx}.out") - # create the expected PDBobject - expected_pdb = prepare_expected_pdb( - model, idx, self.path, "flexref" - ) - refined_structure_list.append(expected_pdb) - - job = CNSJob( - inp_file, - out_file, - cns_folder=self.cns_folder_path, - modpath=self.path, - config_path=self.params["config_path"], - cns_exec=self.params["cns_exec"], - ) + # create the expected PDBobject + expected_pdb = prepare_expected_pdb( + model, idx, self.path, "flexref" + ) + refined_structure_list.append(expected_pdb) + + job = CNSJob( + inp_file, + out_file, + cns_folder=self.cns_folder_path, + modpath=self.path, + config_path=self.params["config_path"], + cns_exec=self.params["cns_exec"], + ) + + jobs.append(job) - jobs.append(job) + idx += 1 # Run CNS engine self.log(f"Running CNS engine with {len(jobs)} jobs") diff --git a/src/haddock/modules/refinement/flexref/defaults.cfg b/src/haddock/modules/refinement/flexref/defaults.cfg index 29c76d943..ffd81a7d6 100644 --- a/src/haddock/modules/refinement/flexref/defaults.cfg +++ b/src/haddock/modules/refinement/flexref/defaults.cfg @@ -1,4 +1,5 @@ log_level = "verbose" +sampling_factor = 1 ambig_fname = "" unambig_fname = "" dihe_fname = "" diff --git a/src/haddock/modules/refinement/mdref/__init__.py b/src/haddock/modules/refinement/mdref/__init__.py index 3bf24d4ce..f2823099f 100644 --- a/src/haddock/modules/refinement/mdref/__init__.py +++ b/src/haddock/modules/refinement/mdref/__init__.py @@ -39,32 +39,47 @@ def _run(self): self.finish_with_error(e) refined_structure_list = [] - for idx, model in enumerate(models_to_refine, start=1): - inp_file = prepare_cns_input( - idx, - model, - self.path, - self.recipe_str, - self.params, - "mdref", - ambig_fname=self.params["ambig_fname"], - ) - out_file = Path(self.path, f"mdref_{idx}.out") - - # create the expected PDBobject - expected_pdb = prepare_expected_pdb(model, idx, self.path, "mdref") - refined_structure_list.append(expected_pdb) - - job = CNSJob( - inp_file, - out_file, - cns_folder=self.cns_folder_path, - modpath=self.path, - config_path=self.params["config_path"], - cns_exec=self.params["cns_exec"], - ) + idx = 1 + sampling_factor = self.params["sampling_factor"] + if sampling_factor > 1: + self.log(f"sampling_factor={sampling_factor}") + if sampling_factor == 0: + self.log("[Warning] sampling_factor cannot be 0, setting it to 1") + sampling_factor = 1 + if sampling_factor > 100: + self.log("[Warning] sampling_factor is larger than 100") + + for model in models_to_refine: + for _ in range(self.params['sampling_factor']): + inp_file = prepare_cns_input( + idx, + model, + self.path, + self.recipe_str, + self.params, + "mdref", + ambig_fname=self.params["ambig_fname"], + ) + out_file = Path(self.path, f"mdref_{idx}.out") + + # create the expected PDBobject + expected_pdb = prepare_expected_pdb( + model, idx, self.path, "mdref" + ) + refined_structure_list.append(expected_pdb) + + job = CNSJob( + inp_file, + out_file, + cns_folder=self.cns_folder_path, + modpath=self.path, + config_path=self.params["config_path"], + cns_exec=self.params["cns_exec"], + ) + + jobs.append(job) - jobs.append(job) + idx += 1 # Run CNS engine self.log(f"Running CNS engine with {len(jobs)} jobs") diff --git a/src/haddock/modules/refinement/mdref/defaults.cfg b/src/haddock/modules/refinement/mdref/defaults.cfg index 2ba425938..691871f91 100644 --- a/src/haddock/modules/refinement/mdref/defaults.cfg +++ b/src/haddock/modules/refinement/mdref/defaults.cfg @@ -1,4 +1,5 @@ log_level = "verbose" +sampling_factor = 1 ambig_fname = "" unambig_fname = "" hbond_fname = ""