From ecff539bc3dc490b556a66d25f0f273e180d44cc Mon Sep 17 00:00:00 2001 From: Lester Hedges Date: Wed, 29 Nov 2023 14:33:38 +0000 Subject: [PATCH] Make saving of YAML settings file optional. --- bin/emle-server | 7 +++++++ emle/emle.py | 18 ++++++++++++++++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/bin/emle-server b/bin/emle-server index 2a881ab..4d04c73 100755 --- a/bin/emle-server +++ b/bin/emle-server @@ -72,6 +72,7 @@ try: log = int(os.getenv("EMLE_LOG")) except: log = 1 +save_settings = os.getenv("EMLE_SAVE_SETTINGS") orca_template = os.getenv("EMLE_ORCA_TEMPLATE") deepmd_model = os.getenv("EMLE_DEEPMD_MODEL") rascal_model = os.getenv("EMLE_RASCAL_MODEL") @@ -129,6 +130,7 @@ env = { "restart": restart, "orca_template": orca_template, "log": log, + "save_settings": save_settings, } @@ -270,6 +272,11 @@ parser.add_argument( help="The frequency of logging energies to file", required=False, ) +parser.add_argument( + "--save-settings", + action=argparse.BooleanOptionalAction, + required=False, +) args = vars(parser.parse_args()) # Pop the config. diff --git a/emle/emle.py b/emle/emle.py index fecaf80..6f58365 100644 --- a/emle/emle.py +++ b/emle/emle.py @@ -370,6 +370,7 @@ def __init__( device=None, orca_template=None, log=1, + save_settings=True, ): """Constructor. @@ -458,6 +459,10 @@ def __init__( log : int The frequency of logging energies to file. + + save_settings : bool + Whether to write a YAML file containing the settings used to initialise + the calculator. """ # Validate input. @@ -833,6 +838,14 @@ def __init__( else: self._log = log + if save_settings is None: + save_settings = True + + if not isinstance(save_settings, bool): + raise TypeError("'save_settings' must be of type 'bool'") + else: + self._save_settings = save_settings + if orca_template is not None: if not isinstance(template, str): raise TypeError("'orca_template' must be of type 'str'") @@ -962,8 +975,9 @@ def __init__( } # Write to a YAML file. - with open("emle_settings.yaml", "w") as f: - yaml.dump(self._settings, f) + if save_settings: + with open("emle_settings.yaml", "w") as f: + yaml.dump(self._settings, f) def run(self, path=None): """