Skip to content

Commit

Permalink
bug fixes and additions to correctly handle PDB (mm)cif files.
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Saxe committed May 7, 2022
1 parent 335c4eb commit 2233c4f
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 31 deletions.
16 changes: 8 additions & 8 deletions read_structure_step/formats/cif/cif.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def load_cif(

# Set the system name
if system_name is not None and system_name != "":
lower_name = system_name.lower()
lower_name = str(system_name).lower()
if "from file" in lower_name:
system.name = block_name
elif "file name" in lower_name:
Expand All @@ -159,11 +159,11 @@ def load_cif(
elif "empirical formula" in lower_name:
system.name = configuration.formula()[1]
else:
system.name = system_name
system.name = str(system_name)

# And the configuration name
if configuration_name is not None and configuration_name != "":
lower_name = configuration_name.lower()
lower_name = str(configuration_name).lower()
if "from file" in lower_name:
configuration.name = block_name
elif "file name" in lower_name:
Expand All @@ -173,7 +173,7 @@ def load_cif(
elif "empirical formula" in lower_name:
configuration.name = configuration.formula()[1]
else:
configuration.name = configuration_name
configuration.name = str(configuration_name)
logger.debug(f" added system {system_db.n_systems}: {block_name}")
block_name = line[5:].strip()
lines = []
Expand All @@ -194,7 +194,7 @@ def load_cif(

# Set the system name
if system_name is not None and system_name != "":
lower_name = system_name.lower()
lower_name = str(system_name).lower()
if "from file" in lower_name:
system.name = block_name
elif "file name" in lower_name:
Expand All @@ -204,11 +204,11 @@ def load_cif(
elif "empirical formula" in lower_name:
system.name = configuration.formula()[1]
else:
system.name = system_name
system.name = str(system_name)

# And the configuration name
if configuration_name is not None and configuration_name != "":
lower_name = configuration_name.lower()
lower_name = str(configuration_name).lower()
if "from file" in lower_name:
configuration.name = block_name
elif "file name" in lower_name:
Expand All @@ -218,4 +218,4 @@ def load_cif(
elif "empirical formula" in lower_name:
configuration.name = configuration.formula()[1]
else:
configuration.name = configuration_name
configuration.name = str(configuration_name)
58 changes: 36 additions & 22 deletions read_structure_step/formats/cif/mmcif.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,19 +138,26 @@ def load_mmcif(
block_name = line[5:].strip()
else:
structure_no += 1
if structure_no > 1:
if subsequent_as_configurations:
configuration = system.create_configuration()
else:
system = system_db.create_system()
configuration = system.create_configuration()
# Check for NMR ensemble
text = "\n".join(lines)
if "_pdbx_nmr_ensemble.conformers_submitted_total_number" in text:
system = system_db.create_system()
system.from_mmcif_text(text)
else:
if structure_no > 1:
if subsequent_as_configurations:
configuration = system.create_configuration()
else:
system = system_db.create_system()
configuration = system.create_configuration()

configuration.from_mmcif_text(text)

configuration.from_mmcif_text("\n".join(lines))
logger.debug(f" added system {system_db.n_systems}: {block_name}")

# Set the system name
if system_name is not None and system_name != "":
lower_name = system_name.lower()
lower_name = str(system_name).lower()
if "from file" in lower_name:
system.name = block_name
elif "file name" in lower_name:
Expand All @@ -160,11 +167,11 @@ def load_mmcif(
elif "empirical formula" in lower_name:
system.name = configuration.formula()[1]
else:
system.name = system_name
system.name = str(system_name)

# And the configuration name
if configuration_name is not None and configuration_name != "":
lower_name = configuration_name.lower()
lower_name = str(configuration_name).lower()
if "from file" in lower_name:
configuration.name = block_name
elif "file name" in lower_name:
Expand All @@ -174,7 +181,7 @@ def load_mmcif(
elif "empirical formula" in lower_name:
configuration.name = configuration.formula()[1]
else:
configuration.name = configuration_name
configuration.name = str(configuration_name)
logger.debug(f" added system {system_db.n_systems}: {block_name}")
block_name = line[5:].strip()
lines = []
Expand All @@ -183,19 +190,26 @@ def load_mmcif(
if len(lines) > 0:
# The last block just ends at the end of the file
structure_no += 1
if structure_no > 1:
if subsequent_as_configurations:
configuration = system.create_configuration()
else:
system = system_db.create_system()
configuration = system.create_configuration()
# Check for NMR ensemble
text = "\n".join(lines)
if "_pdbx_nmr_ensemble.conformers_submitted_total_number" in text:
system = system_db.create_system()
system.from_mmcif_text(text)
else:
if structure_no > 1:
if subsequent_as_configurations:
configuration = system.create_configuration()
else:
system = system_db.create_system()
configuration = system.create_configuration()

configuration.from_mmcif_text(text)

configuration.from_mmcif_text("\n".join(lines))
logger.debug(f" added system {system_db.n_systems}: {block_name}")

# Set the system name
if system_name is not None and system_name != "":
lower_name = system_name.lower()
lower_name = str(system_name).lower()
if "from file" in lower_name:
system.name = block_name
elif "file name" in lower_name:
Expand All @@ -205,11 +219,11 @@ def load_mmcif(
elif "empirical formula" in lower_name:
system.name = configuration.formula()[1]
else:
system.name = system_name
system.name = str(system_name)

# And the configuration name
if configuration_name is not None and configuration_name != "":
lower_name = configuration_name.lower()
lower_name = str(configuration_name).lower()
if "from file" in lower_name:
configuration.name = block_name
elif "file name" in lower_name:
Expand All @@ -219,4 +233,4 @@ def load_mmcif(
elif "empirical formula" in lower_name:
configuration.name = configuration.formula()[1]
else:
configuration.name = configuration_name
configuration.name = str(configuration_name)
5 changes: 4 additions & 1 deletion read_structure_step/read_structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,9 @@ def run(self):
)

# Finish the output
system, configuration = self.get_system_configuration(
P, structure_handling=False
)
if configuration.periodicity == 3:
space_group = configuration.symmetry.group
if space_group == "":
Expand All @@ -200,7 +203,7 @@ def run(self):
printer.important(
__(
"\n Created a molecular structure with "
"{configuration.n_atoms} atoms."
f"{configuration.n_atoms} atoms."
f"\n System name = {system.name}"
f"\n Configuration name = {configuration.name}",
indent=4 * " ",
Expand Down

0 comments on commit 2233c4f

Please sign in to comment.