From 5efec7de3020ea844a0f568a0733e18decd1b68f Mon Sep 17 00:00:00 2001 From: Paul Saxe Date: Mon, 18 Dec 2023 11:44:57 -0500 Subject: [PATCH 1/6] Bugfix: error creating new bondsets --- mopac_step/energy.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/mopac_step/energy.py b/mopac_step/energy.py index 62f24a9..1a79aa2 100644 --- a/mopac_step/energy.py +++ b/mopac_step/energy.py @@ -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): @@ -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 " From fcc0a4606195cb0bf12d3acf18ac8e3af2b34f8d Mon Sep 17 00:00:00 2001 From: Paul Saxe Date: Mon, 18 Dec 2023 11:45:18 -0500 Subject: [PATCH 2/6] Added flag to create input but not run. --- mopac_step/energy_parameters.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/mopac_step/energy_parameters.py b/mopac_step/energy_parameters.py index 2558563..7f35288 100644 --- a/mopac_step/energy_parameters.py +++ b/mopac_step/energy_parameters.py @@ -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", From 95d68050c5a4f963d4cde388345cc2daf78d4e0b Mon Sep 17 00:00:00 2001 From: Paul Saxe Date: Mon, 18 Dec 2023 11:46:09 -0500 Subject: [PATCH 3/6] Added input-only, and checking if previously ran OK. --- mopac_step/mopac.py | 73 +++++++++++++++++++++++++++++---------------- 1 file changed, 48 insertions(+), 25 deletions(-) diff --git a/mopac_step/mopac.py b/mopac_step/mopac.py index 44e2ed5..079159c 100644 --- a/mopac_step/mopac.py +++ b/mopac_step/mopac.py @@ -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. @@ -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: @@ -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. From 63bebba59c2d11ec9c7e2fd8d7342db3d36ebc1a Mon Sep 17 00:00:00 2001 From: Paul Saxe Date: Mon, 18 Dec 2023 11:46:30 -0500 Subject: [PATCH 4/6] Adding input-only key --- mopac_step/tk_energy.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/mopac_step/tk_energy.py b/mopac_step/tk_energy.py index 0746b34..24de02e 100644 --- a/mopac_step/tk_energy.py +++ b/mopac_step/tk_energy.py @@ -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, @@ -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 @@ -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 From 2374732c664d784dd482fd9e0430ac4732f0ac95 Mon Sep 17 00:00:00 2001 From: Paul Saxe Date: Mon, 18 Dec 2023 11:46:46 -0500 Subject: [PATCH 5/6] Updating versioneer of changes in Pyhton. --- versioneer.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/versioneer.py b/versioneer.py index 64fea1c..3aa5da3 100644 --- a/versioneer.py +++ b/versioneer.py @@ -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): From f6bd8e20a78221b96a67cadd9fa48d40483399f4 Mon Sep 17 00:00:00 2001 From: Paul Saxe Date: Mon, 18 Dec 2023 11:48:14 -0500 Subject: [PATCH 6/6] Updated for release. --- HISTORY.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/HISTORY.rst b/HISTORY.rst index 3cf684e..349582f 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -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.