Skip to content

Commit

Permalink
Bug fixes for f-string handling and references to opt_level in config
Browse files Browse the repository at this point in the history
  • Loading branch information
matterhorn103 committed Mar 1, 2024
1 parent e66fec4 commit bf7b083
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 17 deletions.
4 changes: 4 additions & 0 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,11 +324,15 @@ def find_obabel():
solvent_selected = None
else:
solvent_selected = avo_input["solvent"]

# Update solvent
config["solvent"] = solvent_selected

# Update method
config["method"] = methods.index(avo_input["method"])

# Update optimization level
config["opt_lvl"] = avo_input["opt_lvl"]

with open(config_file, "w", encoding="utf-8") as config_path:
json.dump(config, config_path, indent=2)
2 changes: 1 addition & 1 deletion energy.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def energy(
result = {"moleculeFormat": "cjson", "cjson": avo_input["cjson"]}
# Currently Avogadro ignores the energy result
result["message"] = (
f"Energy from GFN{config["method"]}-xTB:\n"
f"Energy from GFN{config['method']}-xTB:\n"
+ f"{str(round(energy_hartree, 7))} hartree\n"
+ f"{str(round(energies['eV'], 7))} eV\n"
+ f"{str(round(energies['kJ'], 7))} kJ/mol\n"
Expand Down
6 changes: 3 additions & 3 deletions freq.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,9 @@ def frequencies(
if float(freq_cjson["vibrations"]["frequencies"][0]) < 0:
result["message"] = (
"At least one negative frequency found!\n"
"This is not a minimum on the potential energy surface.\n"
"You should reoptimize the geometry.\n"
"This can be avoided in future by using the Opt + Freq method."
+ "This is not a minimum on the potential energy surface.\n"
+ "You should reoptimize the geometry.\n"
+ "This can be avoided in future by using the Opt + Freq method."
)

# Save result
Expand Down
7 changes: 5 additions & 2 deletions md.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def md(
"save_dir": {
"type": "string",
"label": "Save results in",
"default": "<plugin_directory>/last",
"default": str(calc_dir),
},
},
}
Expand Down Expand Up @@ -205,7 +205,10 @@ def md(
].extend(xyz)

# If user specified a save location, copy calculation directory to there
if avo_input["save_dir"] != "<plugin_directory>/last":
if not (
avo_input["save_dir"] in ["", None]
or Path(avo_input["save_dir"]) == calc_dir
):
copytree(calc_dir, Path(avo_input["save_dir"]), dirs_exist_ok=True)

# Save result
Expand Down
6 changes: 3 additions & 3 deletions ohess.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def opt_freq(
multiplicity=avo_input["spin"],
solvation=config["solvent"],
method=config["method"],
level=config["level"],
level=config["opt_lvl"],
)

# Convert frequencies
Expand Down Expand Up @@ -141,8 +141,8 @@ def opt_freq(
if float(freq_cjson["vibrations"]["frequencies"][0]) < 0:
result["message"] = (
"At least one negative frequency found!\n"
"This is not a minimum on the potential energy surface.\n"
"You should reoptimize the geometry."
+ "This is not a minimum on the potential energy surface.\n"
+ "You should reoptimize the geometry."
)

# Save result
Expand Down
2 changes: 1 addition & 1 deletion opt.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def optimize(
multiplicity=avo_input["spin"],
solvation=config["solvent"],
method=config["method"],
level=config["level"],
level=config["opt_lvl"],
)

# Read the xyz file
Expand Down
14 changes: 7 additions & 7 deletions run_calc.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"command": {
"type": "string",
"label": "Command to run",
"default": f"xtb <geometry_file> --opt {config["level"]} --chrg 0 --uhf 0",
"default": f"xtb <geometry_file> --opt {config['opt_lvl']} --chrg 0 --uhf 0",
"order": 10.0,
},
"help": {
Expand Down Expand Up @@ -182,16 +182,16 @@
if distorted_geom.exists():
message.append(
"At least one negative frequency found!\n"
"This is not a minimum on the potential energy surface.\n"
"You should reoptimize the geometry starting from the\n"
"distorted geometry found in the calculation directory\n"
"with the filename 'xtbhess.xyz' or 'xtbhess.tmol'."
+ "This is not a minimum on the potential energy surface.\n"
+ "You should reoptimize the geometry starting from the\n"
+ "distorted geometry found in the calculation directory\n"
+ "with the filename 'xtbhess.xyz' or 'xtbhess.tmol'."
)
else:
message.append(
"At least one negative frequency found!\n"
"This is not a minimum on the potential energy surface.\n"
"You should reoptimize the geometry."
+ "This is not a minimum on the potential energy surface.\n"
+ "You should reoptimize the geometry."
)

# Check if orbitals were requested
Expand Down

0 comments on commit bf7b083

Please sign in to comment.