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

fix: add a check for to_pdb #138

Merged
merged 1 commit into from
Feb 7, 2024
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
7 changes: 7 additions & 0 deletions proteinflow/data/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,9 @@ def rename_chains(self, chain_dict):
A dictionary mapping old chain IDs to new chain IDs

"""
for chain in self.get_chains():
if chain not in chain_dict:
chain_dict[chain] = chain
self._rename_chains({k: k * 5 for k in self.get_chains()})
self._rename_chains({k * 5: v for k, v in chain_dict.items()})

Expand Down Expand Up @@ -988,6 +991,10 @@ def to_pdb(
Title of the PDB file (by default either the protein id or "Untitled")

"""
if any([x[0].upper() != x for x in self.get_chains()]):
raise ValueError(
"Chain IDs must be single uppercase letters, please rename with `rename_chains` before saving."
)
pdb_builder = PDBBuilder(
self,
only_ca=only_ca,
Expand Down
3 changes: 2 additions & 1 deletion proteinflow/data/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,8 @@ def _make_SEQRES(self):
def save_pdb(self, path, title="UntitledProtein"):
"""Write out the generated PDB file as a string to the specified path."""
with open(path, "w") as outfile:
outfile.write(self.get_pdb_string(title))
text = self.get_pdb_string(title)
outfile.write(text)


def _split_every(n, iterable):
Expand Down
Loading