Skip to content

Commit

Permalink
Merge pull request #60 from molssi-seamm/dev
Browse files Browse the repository at this point in the history
Enhancements to SDF and XYZ files
  • Loading branch information
seamm authored Jan 3, 2025
2 parents 86d17ff + 9fb64c0 commit 436e7e1
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 7 deletions.
9 changes: 9 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
=======
History
=======
2025.1.3 -- Enhancements to SDF and XYZ files
* Added more keywords to the header of XYZ files to allow for more flexibility in
reading them. Specifically 'title', 'model', and 'name', which can be used to name
the system and/or configuration.
* When reading SDF files, 'keep current name' will use the encoded system name in SDF
files written by SEAMM, if it exists.
* Fixed minor issue writing SDF files where the 'configurations' widget was displayed
when writing the current configuration. The widget is now correctly hidden.

2024.12.29 -- Bugfix: Issue with reusing systems matching SDF files.
* The logic was faulty, so if the first structure in an SDF file was a configuration
of an existing system, it was not added to the system correctly.
Expand Down
12 changes: 8 additions & 4 deletions read_structure_step/formats/sdf/sdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import string
import subprocess
import time
import traceback

from openbabel import openbabel

Expand Down Expand Up @@ -209,15 +210,15 @@ def load_sdf(
# See if either the system or configuration names are "title"
if (
system_name is not None
and system_name.lower() == "title"
and system_name.lower() in ("keep current name", "title")
and have_sysname
):
# Reuse the system if it exists
if system_db.system_exists(sysname):
system = system_db.get_system(sysname)
elif structure_no > 1:
system = system_db.create_system()
if configuration_name.lower() == "title":
if configuration_name.lower() in ("keep current name", "title"):
names = system.configuration_names
if confname in names:
cid = system.get_configuration_id(confname)
Expand All @@ -238,6 +239,9 @@ def load_sdf(
printer("")
printer(f" Error handling entry {record_no} in the SDF file:")
printer(" " + str(e))
printer(60 * "-")
printer("\n".join(traceback.format_exception(e)))
printer(60 * "-")
printer(" Text of the entry is")
printer(" " + 60 * "-")
for line in text.splitlines():
Expand All @@ -253,7 +257,7 @@ def load_sdf(
# Set the system name
if system_name is not None and system_name != "":
lower_name = system_name.lower()
if lower_name == "title":
if lower_name in ("keep current name", "title"):
if sysname != "":
system.name = sysname
else:
Expand All @@ -276,7 +280,7 @@ def load_sdf(
# And the configuration name
if configuration_name is not None and configuration_name != "":
lower_name = configuration_name.lower()
if lower_name == "title":
if lower_name in ("keep current name", "title"):
if confname != "":
configuration.name = confname
else:
Expand Down
22 changes: 21 additions & 1 deletion read_structure_step/formats/xyz/xyz.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,9 @@ def load_xyz(
):
logger.warning(f"{structure_no}: {tmp}")

# Extract any additional information from the title
extra = {}

if file_type == "Minnesota":
# Record the charge, and the spin state
configuration.charge = charge
Expand All @@ -415,8 +418,17 @@ def load_xyz(
configuration.spin_multiplicity = int(val)
except Exception:
pass
elif key == "CSD_code":
elif key in ("CSD_code", "title"):
title = val
elif key == "model":
extra["model"] = val
elif key == "name":
extra["name"] = val
elif key == "symmetry":
extra["symmetry"] = val
else:
if tmp == "TS":
extra["target"] = "TS"

# Set the system name
if system_name is not None and system_name != "":
Expand All @@ -438,6 +450,10 @@ def load_xyz(
system.name = configuration.inchi
elif "formula" in lower_name:
system.name = configuration.formula[0]
elif "name" in lower_name and "name" in extra:
system.name = extra["name"]
elif "model" in lower_name and "model" in extra:
system.name = extra["model"]
else:
system.name = system_name

Expand All @@ -463,6 +479,10 @@ def load_xyz(
configuration.name = str(structure_no)
elif "formula" in lower_name:
configuration.name = configuration.formula[0]
elif "name" in lower_name and "name" in extra:
configuration.name = extra["name"]
elif "model" in lower_name and "model" in extra:
configuration.name = extra["model"]
else:
configuration.name = configuration_name

Expand Down
6 changes: 4 additions & 2 deletions read_structure_step/tk_write_structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def create_dialog(self):
self[key] = P[key].widget(frame)

# Set bindings
for name in ("file", "file type"):
for name in ("file", "file type", "structures"):
combobox = self[name].combobox
combobox.bind("<<ComboboxSelected>>", self.reset_dialog)
combobox.bind("<Return>", self.reset_dialog)
Expand All @@ -72,6 +72,7 @@ def reset_dialog(self, widget=None):
extension = ""
filename = self["file"].get().strip()
file_type = self["file type"].get()
structures = self["structures"].get()

if self.is_expr(filename) or self.is_expr(file_type):
extension = "all"
Expand Down Expand Up @@ -100,7 +101,8 @@ def reset_dialog(self, widget=None):
items = []
if extension == "all" or not metadata["single_structure"]:
items.append("structures")
items.append("configurations")
if structures != "current configuration":
items.append("configurations")
items.append("ignore missing")
items.append("number per file")
items.append("remove hydrogens")
Expand Down

0 comments on commit 436e7e1

Please sign in to comment.