Skip to content

Commit

Permalink
Make saving of YAML settings file optional.
Browse files Browse the repository at this point in the history
  • Loading branch information
lohedges committed Nov 29, 2023
1 parent d214bf7 commit ecff539
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
7 changes: 7 additions & 0 deletions bin/emle-server
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -129,6 +130,7 @@ env = {
"restart": restart,
"orca_template": orca_template,
"log": log,
"save_settings": save_settings,
}


Expand Down Expand Up @@ -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.
Expand Down
18 changes: 16 additions & 2 deletions emle/emle.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@ def __init__(
device=None,
orca_template=None,
log=1,
save_settings=True,
):
"""Constructor.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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'")
Expand Down Expand Up @@ -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):
"""
Expand Down

0 comments on commit ecff539

Please sign in to comment.