Spaces:
Running on Zero
Running on Zero
mcif to pdb conversion with gemmi
Browse files- utils/pipelines.py +16 -15
utils/pipelines.py
CHANGED
|
@@ -7,6 +7,7 @@ import spaces
|
|
| 7 |
import subprocess
|
| 8 |
from Bio.PDB import MMCIFParser, PDBIO
|
| 9 |
import gzip
|
|
|
|
| 10 |
|
| 11 |
|
| 12 |
|
|
@@ -72,7 +73,7 @@ def unconditional_generation(num_batches, num_designs_per_batch, length):
|
|
| 72 |
for batch in range(num_batches):
|
| 73 |
for design in range(num_designs_per_batch):
|
| 74 |
file_name = os.path.join(directory, f"_{batch}_model_{design}.cif.gz")
|
| 75 |
-
results.append({"batch": batch, "design": design, "file": file_name, "pdb":
|
| 76 |
|
| 77 |
print(results)
|
| 78 |
return directory, results
|
|
@@ -89,18 +90,18 @@ def collect_outputs(gen_directory, num_batches, num_designs_per_batch):
|
|
| 89 |
return f"Error: {str(e)}"
|
| 90 |
|
| 91 |
|
| 92 |
-
def
|
| 93 |
-
"""
|
| 94 |
-
|
| 95 |
-
parser = MMCIFParser(QUIET=True)
|
| 96 |
-
with gzip.open(cif_gz_path, 'rt') as f:
|
| 97 |
-
struct = parser.get_structure('model', f)
|
| 98 |
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
import subprocess
|
| 8 |
from Bio.PDB import MMCIFParser, PDBIO
|
| 9 |
import gzip
|
| 10 |
+
import gemmi
|
| 11 |
|
| 12 |
|
| 13 |
|
|
|
|
| 73 |
for batch in range(num_batches):
|
| 74 |
for design in range(num_designs_per_batch):
|
| 75 |
file_name = os.path.join(directory, f"_{batch}_model_{design}.cif.gz")
|
| 76 |
+
results.append({"batch": batch, "design": design, "file": file_name, "pdb": mcif_gz_to_pdb_string_gemmi(file_name)})
|
| 77 |
|
| 78 |
print(results)
|
| 79 |
return directory, results
|
|
|
|
| 90 |
return f"Error: {str(e)}"
|
| 91 |
|
| 92 |
|
| 93 |
+
def mcif_gz_to_pdb_string_gemmi(file_path: str) -> str:
|
| 94 |
+
"""
|
| 95 |
+
Converts a .mcif.gz file to a PDB-formatted string.
|
|
|
|
|
|
|
|
|
|
| 96 |
|
| 97 |
+
Args:
|
| 98 |
+
file_path (str): Path to the .mcif.gz file.
|
| 99 |
+
|
| 100 |
+
Returns:
|
| 101 |
+
str: PDB content as string.
|
| 102 |
+
|
| 103 |
+
Requires: pip install gemmi
|
| 104 |
+
"""
|
| 105 |
+
st = gemmi.read_structure(file_path)
|
| 106 |
+
st.setup_entities() # Recommended for consistent entity handling [web:18]
|
| 107 |
+
return st.make_pdb_string(gemmi.PdbWriteOptions(minimal=True))
|