Skip to content

Commit

Permalink
Merge pull request #52 from molssi-seamm/dev
Browse files Browse the repository at this point in the history
Added new names for systems and configurations
  • Loading branch information
seamm authored Jul 28, 2024
2 parents ca03a31 + da1110f commit 889278a
Show file tree
Hide file tree
Showing 11 changed files with 146 additions and 60 deletions.
6 changes: 6 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
=======
History
=======
2024.7.28 -- Added new names for systems and configurations
* Made the naming of systems and configurations consistent with the standard
parameters for them in the GUI.
* Removed all "from file" options, replacing them with "title", which means the title
from the file, if it exists, or the filename if it doesn't.

2023.11.16 -- Bugfix: titles in SDF files
* Crashed reading some SDF files write by SEAMM due to the system and configuration
names encoded in the title having multiple slashes (/).
Expand Down
12 changes: 3 additions & 9 deletions read_structure_step/formats/cif/cif.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,7 @@ def load_cif(
with (
gzip.open(path, mode="rt")
if path.suffix == ".gz"
else bz2.open(path, mode="rt")
if path.suffix == ".bz2"
else open(path, "r")
else bz2.open(path, mode="rt") if path.suffix == ".bz2" else open(path, "r")
) as fd:
for line in fd:
if line[0:5] == "data_":
Expand Down Expand Up @@ -166,9 +164,7 @@ def load_cif(
with (
gzip.open(path, mode="rt")
if path.suffix == ".gz"
else bz2.open(path, mode="rt")
if path.suffix == ".bz2"
else open(path, "r")
else bz2.open(path, mode="rt") if path.suffix == ".bz2" else open(path, "r")
) as fd:
for line in fd:
if line[0:5] == "data_":
Expand Down Expand Up @@ -378,9 +374,7 @@ def write_cif(
with (
gzip.open(path, mode="wb")
if path.suffix == ".gz"
else bz2.open(path, mode="wb")
if path.suffix == ".bz2"
else open(path, "w")
else bz2.open(path, mode="wb") if path.suffix == ".bz2" else open(path, "w")
) as fd:
for configuration in configurations:
text = configuration.to_cif_text()
Expand Down
4 changes: 1 addition & 3 deletions read_structure_step/formats/cif/mmcif.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,9 +295,7 @@ def write_mmcif(
with (
gzip.open(path, mode="wb")
if path.suffix == ".gz"
else bz2.open(path, mode="wb")
if path.suffix == ".bz2"
else open(path, "w")
else bz2.open(path, mode="wb") if path.suffix == ".bz2" else open(path, "w")
) as fd:
for configuration in configurations:
text = configuration.to_mmcif_text()
Expand Down
30 changes: 25 additions & 5 deletions read_structure_step/formats/mol2/mol2.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def load_mol2(
Normally and subsequent structures are loaded into new systems; however,
if this option is True, they will be added as configurations.
system_name : str = "from file"
system_name : str = "title"
The name for systems. Can be directives like "SMILES" or
"Canonical SMILES". If None, no name is given.
Expand Down Expand Up @@ -174,24 +174,44 @@ def load_mol2(
# Set the system name
if system_name is not None and system_name != "":
lower_name = system_name.lower()
if "from file" in lower_name:
system.name = obMol.GetTitle()
if lower_name == "title":
tmp = obMol.GetTitle()
if tmp != "":
system.name = tmp
else:
system.name = f"{path.stem} {structure_no}"
elif "canonical smiles" in lower_name:
system.name = configuration.canonical_smiles
elif "smiles" in lower_name:
system.name = configuration.smiles
elif "iupac" in lower_name:
system.name = configuration.PC_iupac_name
elif "inchikey" in lower_name:
system.name = configuration.inchikey
elif "inchi" in lower_name:
system.name = configuration.inchi
else:
system.name = system_name

# And the configuration name
if configuration_name is not None and configuration_name != "":
lower_name = configuration_name.lower()
if "from file" in lower_name:
configuration.name = obMol.GetTitle()
if lower_name == "title":
tmp = obMol.GetTitle()
if tmp != "":
configuration.name = tmp
else:
configuration.name = f"{path.stem} {structure_no}"
elif "canonical smiles" in lower_name:
configuration.name = configuration.canonical_smiles
elif "smiles" in lower_name:
configuration.name = configuration.smiles
elif "iupac" in lower_name:
configuration.name = configuration.PC_iupac_name
elif "inchikey" in lower_name:
configuration.name = configuration.inchikey
elif "inchi" in lower_name:
configuration.name = configuration.inchi
elif lower_name == "sequential":
configuration.name = str(structure_no)
else:
Expand Down
18 changes: 14 additions & 4 deletions read_structure_step/formats/mop/obabel.py
Original file line number Diff line number Diff line change
Expand Up @@ -497,9 +497,7 @@ def load_mop(
# Set the system name
if system_name is not None and system_name != "":
lower_name = system_name.lower()
if "from file" in lower_name:
system.name = str(path)
elif lower_name == "title":
if lower_name == "title":
if len(description_lines) > 0:
system.name = description_lines[0]
else:
Expand All @@ -508,18 +506,30 @@ def load_mop(
system.name = configuration.canonical_smiles
elif "smiles" in lower_name:
system.name = configuration.smiles
elif "iupac" in lower_name:
system.name = configuration.PC_iupac_name
elif "inchikey" in lower_name:
system.name = configuration.inchikey
elif "inchi" in lower_name:
system.name = configuration.inchi
else:
system.name = system_name

# And the configuration name
if configuration_name is not None and configuration_name != "":
lower_name = configuration_name.lower()
if "from file" in lower_name:
if lower_name == "title":
configuration.name = obMol.GetTitle()
elif "canonical smiles" in lower_name:
configuration.name = configuration.canonical_smiles
elif "smiles" in lower_name:
configuration.name = configuration.smiles
elif "iupac" in lower_name:
configuration.name = configuration.PC_iupac_name
elif "inchikey" in lower_name:
configuration.name = configuration.inchikey
elif "inchi" in lower_name:
configuration.name = configuration.inchi
elif lower_name == "sequential":
configuration.name = "1"
else:
Expand Down
30 changes: 25 additions & 5 deletions read_structure_step/formats/openbabel_io/obabel.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def load_file(
path,
configuration,
extension=".sdf",
add_hydrogens=True,
add_hydrogens=False,
system_db=None,
system=None,
indices="1:end",
Expand Down Expand Up @@ -111,24 +111,44 @@ def load_file(
# Set the system name
if system_name is not None and system_name != "":
lower_name = system_name.lower()
if "from file" in lower_name:
system.name = obMol.GetTitle()
if lower_name == "title":
tmp = obMol.GetTitle()
if tmp != "":
system.name = tmp
else:
system.name = path.stem
elif "canonical smiles" in lower_name:
system.name = configuration.canonical_smiles
elif "smiles" in lower_name:
system.name = configuration.smiles
elif "iupac" in lower_name:
system.name = configuration.PC_iupac_name
elif "inchikey" in lower_name:
system.name = configuration.inchikey
elif "inchi" in lower_name:
system.name = configuration.inchi
else:
system.name = system_name

# And the configuration name
if configuration_name is not None and configuration_name != "":
lower_name = configuration_name.lower()
if "from file" in lower_name:
configuration.name = obMol.GetTitle()
if lower_name == "title":
tmp = obMol.GetTitle()
if tmp != "":
configuration.name = tmp
else:
configuration.name = path.stem
elif "canonical smiles" in lower_name:
configuration.name = configuration.canonical_smiles
elif "smiles" in lower_name:
configuration.name = configuration.smiles
elif "iupac" in lower_name:
configuration.name = configuration.PC_iupac_name
elif "inchikey" in lower_name:
configuration.name = configuration.inchikey
elif "inchi" in lower_name:
configuration.name = configuration.inchi
elif lower_name == "sequential":
configuration.name = "1"
else:
Expand Down
40 changes: 27 additions & 13 deletions read_structure_step/formats/sdf/sdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def load_sdf(
system=None,
indices="1-end",
subsequent_as_configurations=False,
system_name="Canonical SMILES",
system_name="title",
configuration_name="sequential",
printer=None,
references=None,
Expand Down Expand Up @@ -105,7 +105,7 @@ def load_sdf(
Normally and subsequent structures are loaded into new systems; however,
if this option is True, they will be added as configurations.
system_name : str = "from file"
system_name : str = "title"
The name for systems. Can be directives like "SMILES" or
"Canonical SMILES". If None, no name is given.
Expand Down Expand Up @@ -139,9 +139,7 @@ def load_sdf(
with (
gzip.open(path, mode="rt")
if path.suffix == ".gz"
else bz2.open(path, mode="rt")
if path.suffix == ".bz2"
else open(path, "r")
else bz2.open(path, mode="rt") if path.suffix == ".bz2" else open(path, "r")
) as fd:
for line in fd:
if line[0:4] == "$$$$":
Expand Down Expand Up @@ -172,9 +170,7 @@ def load_sdf(
with (
gzip.open(path, mode="rt")
if path.suffix == ".gz"
else bz2.open(path, mode="rt")
if path.suffix == ".bz2"
else open(path, "r")
else bz2.open(path, mode="rt") if path.suffix == ".bz2" else open(path, "r")
) as fd:
for line in fd:
text += line
Expand Down Expand Up @@ -213,7 +209,7 @@ def load_sdf(
if subsequent_as_configurations:
configuration = system.create_configuration()
else:
if have_sysname and "from file" in system_name.lower():
if have_sysname and "title" in system_name.lower():
# Reuse the system if it exists
if system_db.system_exists(sysname):
system = system_db.get_system(sysname)
Expand Down Expand Up @@ -245,24 +241,42 @@ def load_sdf(
# Set the system name
if system_name is not None and system_name != "":
lower_name = system_name.lower()
if "from file" in lower_name:
system.name = sysname
if lower_name == "title":
if sysname != "":
system.name = sysname
else:
system.name = f"{path.stem}_{record_no}"
elif "canonical smiles" in lower_name:
system.name = configuration.canonical_smiles
elif "smiles" in lower_name:
system.name = configuration.smiles
elif "iupac" in lower_name:
system.name = configuration.PC_iupac_name
elif "inchikey" in lower_name:
system.name = configuration.inchikey
elif "inchi" in lower_name:
system.name = configuration.inchi
else:
system.name = system_name

# And the configuration name
if configuration_name is not None and configuration_name != "":
lower_name = configuration_name.lower()
if "from file" in lower_name:
configuration.name = confname
if lower_name == "title":
if confname != "":
configuration.name = confname
else:
configuration.name = f"{path.stem}_{record_no}"
elif "canonical smiles" in lower_name:
configuration.name = configuration.canonical_smiles
elif "smiles" in lower_name:
configuration.name = configuration.smiles
elif "iupac" in lower_name:
configuration.name = configuration.PC_iupac_name
elif "inchikey" in lower_name:
configuration.name = configuration.inchikey
elif "inchi" in lower_name:
configuration.name = configuration.inchi
elif lower_name == "sequential":
configuration.name = str(record_no)
else:
Expand Down
28 changes: 24 additions & 4 deletions read_structure_step/formats/smi/smi.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,24 +188,44 @@ def load_mol2(
# Set the system name
if system_name is not None and system_name != "":
lower_name = system_name.lower()
if "from file" in lower_name:
system.name = obMol.GetTitle()
if lower_name == "title":
tmp = obMol.GetTitle()
if tmp != "":
system.name = tmp
else:
system.name = f"{path.stem}_{structure_no}"
elif "canonical smiles" in lower_name:
system.name = configuration.canonical_smiles
elif "smiles" in lower_name:
system.name = configuration.smiles
elif "iupac" in lower_name:
system.name = configuration.PC_iupac_name
elif "inchikey" in lower_name:
system.name = configuration.inchikey
elif "inchi" in lower_name:
system.name = configuration.inchi
else:
system.name = system_name

# And the configuration name
if configuration_name is not None and configuration_name != "":
lower_name = configuration_name.lower()
if "from file" in lower_name:
configuration.name = obMol.GetTitle()
if lower_name == "title":
tmp = obMol.GetTitle()
if tmp != "":
configuration.name = tmp
else:
configuration.name = f"{path.stem}_{structure_no}"
elif "canonical smiles" in lower_name:
configuration.name = configuration.canonical_smiles
elif "smiles" in lower_name:
configuration.name = configuration.smiles
elif "iupac" in lower_name:
configuration.name = configuration.PC_iupac_name
elif "inchikey" in lower_name:
configuration.name = configuration.inchikey
elif "inchi" in lower_name:
configuration.name = configuration.inchi
elif lower_name == "sequential":
configuration.name = str(structure_no)
else:
Expand Down
Loading

0 comments on commit 889278a

Please sign in to comment.