Skip to content

Commit

Permalink
Merge pull request #124 from molssi-seamm/dev
Browse files Browse the repository at this point in the history
Bugfix -- bondsets, and writing input and stopping.
  • Loading branch information
seamm authored Dec 18, 2023
2 parents ddb57c9 + f6bd8e2 commit 4f37dc2
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 31 deletions.
3 changes: 3 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
=======
History
=======
2023.12.18 -- Added readonly flag
* Added a flag to prepare the input but not run the calculation.

2023.11.15 -- More updates for v2022.1.0
* Added PM6-ORG Hamiltonian to options
* Added other new data types for the AUX file.
Expand Down
5 changes: 4 additions & 1 deletion mopac_step/energy.py
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,9 @@ def get_input(self):
else:
logger.error(f"Don't recognize the MOZYME follow-up: '{follow_up}'")

# Set the attribute in the main MOPAC step for writing just the input
self.parent.input_only = P["input only"]

return result

def analyze(self, indent="", data_sections=[], out_sections=[], table=None):
Expand Down Expand Up @@ -1113,7 +1116,7 @@ def _bond_orders(self, control, bond_order_matrix, configuration):
ids = configuration.atoms.ids
iatoms = [ids[i] for i in bond_i]
jatoms = [ids[j] for j in bond_j]
configuration.bonds.new_bondset()
configuration.new_bondset()
configuration.bonds.append(i=iatoms, j=jatoms, bondorder=bond_order)
text2 = (
"\nReplaced the bonds in the configuration with those from the "
Expand Down
12 changes: 12 additions & 0 deletions mopac_step/energy_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@ class EnergyParameters(seamm.Parameters):
"""The control parameters for creating a structure from SMILES"""

parameters = {
"input only": {
"default": "no",
"kind": "boolean",
"default_units": "",
"enumeration": (
"yes",
"no",
),
"format_string": "s",
"description": "Write the input files and stop:",
"help_text": "Don't run MOPAC. Just write the input files.",
},
"structure": {
"default": "default",
"kind": "enumeration",
Expand Down
73 changes: 48 additions & 25 deletions mopac_step/mopac.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,21 @@ def __init__(
)
self._data = {}
self._lattice_opt = True
self._input_only = False

super().__init__(
flowchart=flowchart, title=title, extension=extension, logger=logger
)

@property
def input_only(self):
"""Whether to write the input only, not run MOPAC."""
return self._input_only

@input_only.setter
def input_only(self, value):
self._input_only = value

def description_text(self, P=None):
"""Return a short description of this step.
Expand All @@ -83,6 +93,10 @@ def description_text(self, P=None):

def run(self, printer=printer):
"""Run MOPAC"""
# Create the directory
directory = Path(self.directory)
directory.mkdir(parents=True, exist_ok=True)

system, configuration = self.get_system_configuration(None)
n_atoms = configuration.n_atoms
if n_atoms == 0:
Expand Down Expand Up @@ -255,35 +269,44 @@ def run(self, printer=printer):
text += "\n"
node = node.next()

files = {"mopac.dat": text}
self.logger.debug("mopac.dat:\n" + files["mopac.dat"])
os.makedirs(self.directory, exist_ok=True)
for filename in files:
with open(os.path.join(self.directory, filename), mode="w") as fd:
fd.write(files[filename])
local = seamm.ExecLocal()
return_files = ["mopac.arc", "mopac.out", "mopac.aux"]
result = local.run(
cmd=[str(mopac_exe), "mopac.dat"],
files=files,
return_files=return_files,
env=env,
in_situ=True,
directory=self.directory,
)
# Check for successful run, don't rerun
success = directory / "success.dat"
if not success.exists():
files = {"mopac.dat": text}
self.logger.debug("mopac.dat:\n" + files["mopac.dat"])
for filename in files:
path = directory / filename
path.write_text(files[filename])

if not self.input_only:
local = self.flowchart.executor
print(f"{self.flowchart=} --> {local=}")
return_files = ["mopac.arc", "mopac.out", "mopac.aux"]
result = local.run(
cmd=[str(mopac_exe), "mopac.dat"],
files=files,
return_files=return_files,
env=env,
in_situ=True,
directory=self.directory,
)

if not result:
self.logger.error("There was an error running MOPAC")
return None
if not result:
self.logger.error("There was an error running MOPAC")
return None

self.logger.debug("\n" + pprint.pformat(result))
self.logger.debug("\n" + pprint.pformat(result))

self.logger.debug(
"\n\nOutput from MOPAC\n\n" + result["mopac.out"]["data"] + "\n\n"
)
self.logger.debug(
"\n\nOutput from MOPAC\n\n" + result["mopac.out"]["data"] + "\n\n"
)

# Ran successfully, put out the success file
success.write_text("success")

# Analyze the results
self.analyze(n_calculations=n_calculations)
if not self.input_only:
# Analyze the results
self.analyze(n_calculations=n_calculations)

# Close the reference handler, which should force it to close the
# connection.
Expand Down
14 changes: 11 additions & 3 deletions mopac_step/tk_energy.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ def create_dialog(self, title="Edit MOPAC Energy Step"):
self.logger.debug("Creating the dialog")
frame = super().create_dialog(title=title, widget="notebook", results_tab=True)

P = self.node.parameters

# Just write input
self["input only"] = P["input only"].widget(frame)

# Frame to isolate widgets
e_frame = self["energy frame"] = ttk.LabelFrame(
frame,
Expand All @@ -66,9 +71,8 @@ def create_dialog(self, title="Edit MOPAC Energy Step"):
)

# Create all the widgets
P = self.node.parameters
for key in mopac_step.EnergyParameters.parameters:
if key not in ("results", "extra keywords", "create tables"):
if key not in ("results", "extra keywords", "create tables", "input only"):
self[key] = P[key].widget(e_frame)

# Set the callbacks for changes
Expand All @@ -89,8 +93,12 @@ def reset_dialog(self, widget=None):
for slave in frame.grid_slaves():
slave.grid_forget()

# Put in the energy frame
row = 0
# Whether to just write input
self["input only"].grid(row=row, column=0, sticky=tk.W)
row += 1

# Put in the energy frame
self["energy frame"].grid(row=row, column=0, sticky=tk.EW)
row += 1

Expand Down
4 changes: 2 additions & 2 deletions versioneer.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,9 +339,9 @@ def get_config_from_root(root):
# configparser.NoOptionError (if it lacks "VCS="). See the docstring at
# the top of versioneer.py for instructions on writing your setup.cfg .
setup_cfg = os.path.join(root, "setup.cfg")
parser = configparser.SafeConfigParser()
parser = configparser.ConfigParser()
with open(setup_cfg, "r") as f:
parser.readfp(f)
parser.read_file(f)
VCS = parser.get("versioneer", "VCS") # mandatory

def get(parser, name):
Expand Down

0 comments on commit 4f37dc2

Please sign in to comment.