Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated to standard structure handling #121

Merged
merged 2 commits into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
=======
History
=======
2023.10.30 -- Updated to standard structure handling
* Adds IUPAC names, InChI and InChIKey as possible names for configurations
* Cleaned up output to be properly indented and laid out.

2023.8.30 -- Support for spacegroup symmetry

2023.7.27 -- Bugfix: printing bond order info
Expand Down
34 changes: 0 additions & 34 deletions mopac_step/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,40 +43,6 @@
# Handle versioneer
from ._version import get_versions

# Parameters used for handling the structure if it is changed.
structure_handling_parameters = {
"structure handling": {
"default": "be put in a new configuration",
"kind": "enum",
"default_units": "",
"enumeration": (
"overwrite the current configuration",
"be put in a new configuration",
),
"format_string": "s",
"description": "Optimized structure will",
"help_text": (
"Whether to overwrite the current configuration, or create a new "
"configuration or system and configuration for the new structure"
),
},
"configuration name": {
"default": "optimized with <Hamiltonian>",
"kind": "string",
"default_units": "",
"enumeration": (
"optimized with <Hamiltonian>",
"keep current name",
"use SMILES string",
"use Canonical SMILES string",
"use configuration number",
),
"format_string": "s",
"description": "Configuration name:",
"help_text": "The name for the new configuration",
},
}

__author__ = """Paul Saxe"""
__email__ = "psaxe@molssi.org"
versions = get_versions()
Expand Down
68 changes: 40 additions & 28 deletions mopac_step/energy.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def __init__(self, flowchart=None, title="Energy", extension=None):
self._calculation = "energy"
self._model = None
self._metadata = mopac_step.metadata
self._use_mozyme = None
self.parameters = mopac_step.EnergyParameters()
self.description = "A single point energy calculation"

Expand Down Expand Up @@ -83,13 +84,17 @@ def description_text(self, P=None):
)

# MOZYME localized molecular orbitals.
if P["MOZYME"] == "always":
if ["MOZYME"] == "always" or (
self._use_mozyme is not None and self._use_mozyme
):
text += (
"\n\nThe SCF will be solved using localized molecular orbitals "
"(MOZYME), which is faster than the traditional method for larger "
"systems."
)
used_mozyme = True
elif self._use_mozyme is not None and not self._use_mozyme:
used_mozyme = False
elif P["MOZYME"] == "for larger systems":
text += (
"\n\nThe SCF will be solved using localized molecular orbitals "
Expand Down Expand Up @@ -171,9 +176,19 @@ def get_input(self):
if isinstance(PP[key], units_class):
PP[key] = "{:~P}".format(PP[key])

if P["MOZYME"] == "always":
self._use_mozyme = True
elif (
P["MOZYME"] == "for larger systems"
and configuration.n_atoms >= P["nMOZYME"]
):
self._use_mozyme = True
else:
self._use_mozyme = False

# Save the description for later printing
self.description = []
self.description.append(__(self.description_text(PP), **PP, indent=self.indent))
self.description.append(__(self.description_text(PP), **PP, indent=4 * " "))

# Start gathering the keywords
keywords = copy.deepcopy(P["extra keywords"])
Expand Down Expand Up @@ -748,16 +763,14 @@ def analyze(self, indent="", data_sections=[], out_sections=[], table=None):
else:
data = data_sections[0]

if "GRADIENT_NORM" in data:
tmp = data["GRADIENT_NORM"]
table["Property"].append("Gradient Norm")
table["Value"].append(f"{tmp:.2f}")
table["Units"].append("kcal/mol/Å")

if "POINT_GROUP" in data and data["POINT_GROUP"] != "":
text += "The molecule has {POINT_GROUP} symmetry."
table["Property"].append("Symmetry")
table["Value"].append(data["POINT_GROUP"])
table["Units"].append("")
else:
text += "The symmetry of the molecule was not determined."
table["Property"].append("Symmetry")
table["Value"].append("?")
table["Units"].append("")

if "HEAT_OF_FORMATION" in data:
tmp = data["HEAT_OF_FORMATION"]
Expand Down Expand Up @@ -794,10 +807,16 @@ def analyze(self, indent="", data_sections=[], out_sections=[], table=None):
text += (
" You followed up with an exact calculation. A large "
"difference in the energy could indicate a problem "
"with the localcized molecular orbitals. Check the MOPAC "
"with the localized molecular orbitals. Check the MOPAC "
"output carefully!"
)

if "GRADIENT_NORM" in data:
tmp = data["GRADIENT_NORM"]
table["Property"].append("Gradient Norm")
table["Value"].append(f"{tmp:.2f}")
table["Units"].append("kcal/mol/Å")

if "SPIN_COMPONENT" in data:
tmp = data["SPIN_COMPONENT"]
table["Property"].append("Sz")
Expand Down Expand Up @@ -995,9 +1014,9 @@ def analyze(self, indent="", data_sections=[], out_sections=[], table=None):
)
)

text = str(__(text, **data, indent=self.indent + 4 * " "))
text = str(__(text, **data, indent=8 * " "))
text += "\n\n"
text += textwrap.indent("\n".join(text_lines), self.indent + 7 * " ")
text += textwrap.indent("\n".join(text_lines), 12 * " ")

if "BOND_ORDERS" in data:
text += self._bond_orders(
Expand All @@ -1019,7 +1038,7 @@ def analyze(self, indent="", data_sections=[], out_sections=[], table=None):
elif "CPU_TIME" in data:
t0 = data_sections[0]["CPU_TIME"]
text = f"This calculation took {t0:.2f} s."
printer.normal(str(__(text, **data, indent=self.indent + 4 * " ")))
printer.normal(str(__(text, **data, indent=4 * " ")))

# Put any requested results into variables or tables
self.store_results(
Expand Down Expand Up @@ -1073,41 +1092,34 @@ def _bond_orders(self, control, bond_order_matrix, configuration):
table = {
"i": [name[i] for i in bond_i],
"j": [name[j] for j in bond_j],
"bond order": orders,
"bond order": [f"{o:6.3f}" for o in orders],
"bond multiplicity": bond_order_str,
}
tmp = tabulate(
table,
headers="keys",
tablefmt="pretty",
tablefmt="psql",
disable_numparse=True,
colalign=("center", "center", "right", "center"),
colalign=("center", "center", "center", "center"),
)
length = len(tmp.splitlines()[0])
text_lines.append("\n")
text_lines.append("Bond Orders".center(length))
text_lines.append(
tabulate(
table,
headers="keys",
tablefmt="psql",
colalign=("center", "center", "decimal", "center"),
)
)
text_lines.append(tmp)
text += "\n\n"
text += textwrap.indent("\n".join(text_lines), self.indent + 7 * " ")
text += textwrap.indent("\n".join(text_lines), 12 * " ")

if control == "yes, and apply to structure":
ids = configuration.atoms.ids
iatoms = [ids[i] for i in bond_i]
jatoms = [ids[j] for j in bond_j]
configuration.bonds.delete()
configuration.bonds.new_bondset()
configuration.bonds.append(i=iatoms, j=jatoms, bondorder=bond_order)
text2 = (
"\nReplaced the bonds in the configuration with those from the "
"calculated bond orders.\n"
)

text += str(__(text2, indent=self.indent + 4 * " "))
text += str(__(text2, indent=8 * " "))

return text
7 changes: 6 additions & 1 deletion mopac_step/energy_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,5 +293,10 @@ def __init__(self, defaults={}, data=None):
parameters given in the class"""

super().__init__(
defaults={**EnergyParameters.parameters, **defaults}, data=data
defaults={
**EnergyParameters.parameters,
**seamm.standard_parameters.structure_handling_parameters,
**defaults,
},
data=data,
)
2 changes: 1 addition & 1 deletion mopac_step/forceconstants.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def get_input(self):

# Save the description for later printing
self.description = []
self.description.append(__(self.description_text(PP), **PP, indent=self.indent))
self.description.append(__(self.description_text(PP), **PP, indent=4 * " "))

_, configuration = self.get_system_configuration(None)

Expand Down
10 changes: 9 additions & 1 deletion mopac_step/forceconstants_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,16 @@ def __init__(self, defaults={}, data=None):
super().__init__(
defaults={
**ForceconstantsParameters.parameters,
**mopac_step.structure_handling_parameters,
**defaults,
},
data=data,
)

# Do any local editing of defaults
tmp = self["system name"]
tmp._data["enumeration"] = (*tmp.enumeration, "MOPAC standard orientation")
tmp.default = "keep current name"

tmp = self["configuration name"]
tmp._data["enumeration"] = ["MOPAC standard orientation", *tmp.enumeration]
tmp.default = "MOPAC standard optimization"
4 changes: 2 additions & 2 deletions mopac_step/ir.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def get_input(self):

# Save the description for later printing
self.description = []
self.description.append(__(self.description_text(PP), **PP, indent=self.indent))
self.description.append(__(self.description_text(PP), **PP, indent=4 * " "))

# Remove the 1SCF keyword from the energy setup
inputs = super().get_input()
Expand Down Expand Up @@ -221,7 +221,7 @@ def analyze(self, indent="", data_sections=[], out_sections=[], table=None):
colalign=("center", "decimal", "decimal", "decimal", "left"),
)
text_lines += "\n"
text = textwrap.indent(text_lines, self.indent + 7 * " ")
text = textwrap.indent(text_lines, 8 * " ")
printer.normal(text)

# And the vibrational modes to a csv file
Expand Down
10 changes: 9 additions & 1 deletion mopac_step/ir_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,16 @@ def __init__(self, defaults={}, data=None):
super().__init__(
defaults={
**IRParameters.parameters,
**mopac_step.structure_handling_parameters,
**defaults,
},
data=data,
)

# Do any local editing of defaults
tmp = self["system name"]
tmp._data["enumeration"] = (*tmp.enumeration, "MOPAC standard orientation")
tmp.default = "keep current name"

tmp = self["configuration name"]
tmp._data["enumeration"] = ["MOPAC standard orientation", *tmp.enumeration]
tmp.default = "MOPAC standard optimization"
6 changes: 3 additions & 3 deletions mopac_step/lewis_structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ def analyze(self, indent="", lines=[], n_calculations=None):
if same:
iatoms = [ids[i] for i in bonds["i"]]
jatoms = [ids[j] for j in bonds["j"]]
configuration.bonds.delete()
configuration.new_bondset()
configuration.bonds.append(
i=iatoms, j=jatoms, bondorder=bonds["bondorder"]
)
Expand All @@ -462,7 +462,7 @@ def analyze(self, indent="", lines=[], n_calculations=None):
iatoms.append(ids[i])
jatoms.append(ids[j])
bondorders.append(1)
configuration.bonds.delete()
configuration.new_bondset()
configuration.bonds.append(
i=iatoms, j=jatoms, bondorder=bonds["bondorder"]
)
Expand All @@ -479,4 +479,4 @@ def analyze(self, indent="", lines=[], n_calculations=None):
t_total = data["CPU_TIME"]
text += f"\nThe Lewis structure took a total of {t_total:.2f} s.\n"

printer.normal(textwrap.indent(text, self.indent + 4 * " "))
printer.normal(textwrap.indent(text, 4 * " "))
Loading
Loading