Skip to content

Commit

Permalink
Merge pull request #11 from cch1999/use_hydrite
Browse files Browse the repository at this point in the history
Use hydrite
  • Loading branch information
cch1999 authored Aug 20, 2024
2 parents 617fcee + 0c67956 commit a0419fc
Show file tree
Hide file tree
Showing 13 changed files with 410 additions and 237 deletions.
18 changes: 9 additions & 9 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,21 @@ jobs:
- name: Install Extras
run: pip install -r requirements.txt

- name: Install OpenBabel
run: mamba install -c conda-forge openbabel
# - name: Install OpenBabel
# run: mamba install -c conda-forge openbabel

- name: Install reduce
run: mamba install -c speleo3 reduce
# - name: Install reduce
# run: mamba install -c speleo3 reduce

# Install coverage tool
- name: Install Coverage
run: pip install coverage

# # Run tests with coverage
# - name: Run unit tests and generate coverage report
# run: |
# coverage run --source=posecheck -m unittest discover -s tests -p "test_*.py"
# coverage xml
# Run tests with coverage
- name: Run unit tests and generate coverage report
run: |
coverage run --source=posecheck -m unittest discover -s tests -p "test_*.py"
coverage xml
# # Upload coverage to Codecov
# - name: Upload coverage to Codecov
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
posecheck/__pycache__/*.pyc
*/*/__pycache__/
.vscode/*
.DS_Store
.DS_Store
*.pyc
5 changes: 5 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## [1.3] - 20-08-2024

### Changed
- Changed protonation script from `reduce` to `hydride` to make app dependencies pip installable

## [1.2] - 25-07-2024

### Changed
Expand Down
6 changes: 3 additions & 3 deletions posecheck/posecheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ def __init__(
self.reduce_path = reduce_path
self.clash_tolerance = clash_tolerance

# Check if reduce is installed
if not is_reduce_installed(reduce_path):
print_reduce_warning()
# # Check if reduce is installed
# if not is_reduce_installed(reduce_path):
# print_reduce_warning()

def load_protein_from_pdb(self, pdb_path: str) -> None:
"""Load a protein from a PDB file.
Expand Down
113 changes: 113 additions & 0 deletions posecheck/utils/biopython.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@

from Bio.PDB import PDBParser, PDBIO
from Bio.PDB.Structure import Structure

def load_biopython_structure(pdb_path: str) -> Structure:
"""
Load a structure from a PDB file using Biopython's PDBParser.
Args:
pdb_path (str): The file path to the PDB file.
Returns:
Bio.PDB.Structure.Structure: The structure parsed from the PDB file.
"""
parser = PDBParser()
structure = parser.get_structure("PDB_structure", pdb_path)
return structure

def save_biopython_structure(structure: Structure, pdb_path: str):
"""
Save a structure to a PDB file using Biopython's PDBIO.
Args:
structure (Bio.PDB.Structure.Structure): The structure to save.
pdb_path (str): The file path to save the PDB file to.
"""
io = PDBIO()
io.set_structure(structure)
io.save(pdb_path)

def ids_scriptly_increasing(structure: Structure) -> bool:
"""
Check if the IDs of residues in a structure are strictly increasing.
Args:
structure (Bio.PDB.Structure.Structure): The structure to check.
Returns:
bool: True if the IDs are strictly increasing, False otherwise.
"""
ids = []

for model in structure:
for chain in model:
for i, residue in enumerate(chain):
ids.append((chain.id, residue.id, i))

if ids != sorted(ids):
return False
return True

def reorder_ids(structure: Structure) -> Structure:
"""
Reorder the IDs of residues in a structure to be strictly increasing.
Args:
structure (Bio.PDB.Structure.Structure): The structure to reorder.
Returns:
Bio.PDB.Structure.Structure: The structure with reordered IDs.
"""
for model in structure:
for chain in model:
chain_id = chain.id
# Extract residues from the chain
residues = [residue for residue in chain]
# Sort residues based on their id[1]
sorted_residues = sorted(residues, key=lambda residue: residue.id[1])
# Clear the chain of residues before adding them back in sorted order
# Iterate over a copy of the list of residues to safely remove them
for residue in residues:
chain.detach_child(residue.id)
for residue in sorted_residues:
# Prevent adding a residue that is already present
if not chain.has_id(residue.id):
chain.add(residue)
return structure


def remove_connect_lines(pdb_path):
"""
Remove CONECT lines from a PDB file.
"""

with open(pdb_path, "r") as f:
lines = f.readlines()
with open(pdb_path, "w") as f:
for line in lines:
if line.startswith("CONECT"):
continue
f.write(line)


if __name__ == "__main__":
from posecheck.utils.constants import EXAMPLE_PDB_PATH
# import temp path
import tempfile

structure = load_biopython_structure(EXAMPLE_PDB_PATH)

print(ids_scriptly_increasing(structure))

reordered_structure = reorder_ids(structure)

print(ids_scriptly_increasing(reordered_structure))

with tempfile.NamedTemporaryFile(suffix=".pdb") as temp:
print(temp.name)
save_biopython_structure(reordered_structure, temp.name)
print(load_biopython_structure(temp.name))



Loading

0 comments on commit a0419fc

Please sign in to comment.