From 074d399984245eb20e383a9d7b5bb4fc17c9ed3f Mon Sep 17 00:00:00 2001 From: Daniel Bauer Date: Wed, 31 Jul 2019 13:10:14 +0200 Subject: [PATCH] wham2d can now hide some output when verbose is set to False --- adaptiveumbrella/__init__.py | 2 +- adaptiveumbrella/wham2d.py | 16 ++++++++++------ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/adaptiveumbrella/__init__.py b/adaptiveumbrella/__init__.py index be3b501..2c12eed 100644 --- a/adaptiveumbrella/__init__.py +++ b/adaptiveumbrella/__init__.py @@ -3,4 +3,4 @@ from .runner import UmbrellaRunner from .wham2d import WHAM2DRunner __all__ = ['AdaptiveUmbrella'] -__version__ = "0.3.5" +__version__ = "0.3.6" diff --git a/adaptiveumbrella/wham2d.py b/adaptiveumbrella/wham2d.py index eaf5ead..8b6379f 100644 --- a/adaptiveumbrella/wham2d.py +++ b/adaptiveumbrella/wham2d.py @@ -21,6 +21,7 @@ class WHAM2DRunner(UmbrellaRunner): def __init__(self): UmbrellaRunner.__init__(self) + self.verbose = False self.WHAM_EXEC = 'wham-2d' self.tmp_folder = "tmp/WHAM" self.simulation_folder = "tmp/simulations" @@ -34,7 +35,7 @@ class WHAM2DRunner(UmbrellaRunner): with open(path, 'w') as out: for file in os.listdir(self.simulation_folder): filepath = os.path.join(self.simulation_folder, file, "COLVAR") - if not os.path.exists(filepath): + if not os.path.exists(filepath) and self.verbose: print("Not found: {}".format(filepath)) continue prefix, x, y = file.split("_") @@ -59,9 +60,9 @@ class WHAM2DRunner(UmbrellaRunner): self._get_lambdas_for_index((nonzero[0].min(), nonzero[1].min())), self._get_lambdas_for_index((nonzero[0].max(), nonzero[1].max())) ]) - + borders = borders.flatten() - # increase borders by 1 lambda step from minimal dimensions + # increase borders by 1 lambda step from minimal dimensions borders[0] -= self.cvs[0][2] borders[1] -= self.cvs[1][2] borders[2] += self.cvs[0][2] @@ -88,8 +89,12 @@ class WHAM2DRunner(UmbrellaRunner): metafile=metafile_path, outfile=output_path ) - print(cmd) - err_code = subprocess.call(cmd, shell=True) + if self.verbose: + print(cmd) + err_code = subprocess.call(cmd, shell=True) + else: + FNULL = open(os.devnull, 'w') + err_code = subprocess.call(cmd, shell=True, stdout=FNULL) if err_code != 0: print("wham exited with error code {}".format(err_code)) exit(1) @@ -118,7 +123,6 @@ class WHAM2DRunner(UmbrellaRunner): def calculate_new_pmf(self): - print("Running wham-2d") metafile_path = self.create_metadata_file() wham_pmf_file = self.get_wham_output_file() self.run_wham2d(metafile_path, wham_pmf_file)