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

Add PDB fixer option in ProteinChain #26

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
26 changes: 25 additions & 1 deletion esm/utils/structure/protein_chain.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
from typing import Sequence, TypeVar, Union

import biotite.structure as bs
import openmm
import pdbfixer
import brotli
import msgpack
import msgpack_numpy
Expand Down Expand Up @@ -643,8 +645,30 @@ def from_rcsb(
cls,
pdb_id: str,
chain_id: str = "detect",
fix_pdb: bool = False,
):
f: io.StringIO = rcsb.fetch(pdb_id, "pdb") # type: ignore
f: io.StringIO = rcsb.fetch(pdb_id, "pdb") # type: ignore (_io.StringIO)

if fix_pdb:
fixer = pdbfixer.PDBFixer(pdbfile=f)

# PDBFixer operations
fixer.findNonstandardResidues()
fixer.replaceNonstandardResidues()
fixer.findMissingResidues()
fixer.findMissingAtoms()
fixer.addMissingAtoms(seed=0)
fixer.addMissingHydrogens()

# Create a StringIO object
f = io.StringIO()

# Write the PDBFixer object to the StringIO object
openmm.app.PDBFile.writeFile(fixer.topology, fixer.positions, f, keepIds=True)

# Reset StringIO pointer to the beginning
f.seek(0)

return cls.from_pdb(f, chain_id=chain_id, id=pdb_id)

@classmethod
Expand Down
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ dependencies = [
"brotli",
"attrs",
"pandas",
"openmm",
"pdbfixer",
]

[tool.setuptools]
Expand Down