Spaces:
Running
Running
Update
Browse files- .ipynb_checkpoints/app-checkpoint.py +30 -13
- app.py +30 -13
.ipynb_checkpoints/app-checkpoint.py
CHANGED
@@ -27,7 +27,7 @@ from gradio_molecule3d import Molecule3D
|
|
27 |
# Biopython imports
|
28 |
from Bio.PDB import PDBParser, Select, PDBIO
|
29 |
from Bio.PDB.DSSP import DSSP
|
30 |
-
from Bio.PDB import PDBList
|
31 |
|
32 |
from matplotlib import cm # For color mapping
|
33 |
from matplotlib.colors import Normalize
|
@@ -225,7 +225,7 @@ def score_to_color(score):
|
|
225 |
|
226 |
def process_pdb(pdb_id):
|
227 |
# Fetch PDB file
|
228 |
-
pdbl = PDBList()
|
229 |
pdb_path = pdbl.retrieve_pdb_file(pdb_id, pdir='pdb_files', file_format='pdb')
|
230 |
|
231 |
if not pdb_path or not os.path.exists(pdb_path):
|
@@ -243,20 +243,37 @@ def process_pdb(pdb_id):
|
|
243 |
# Prepare result string
|
244 |
result_str = "\n".join([f"{aa}: {score:.2f}" for aa, score in zip(sequence, normalized_scores)])
|
245 |
|
246 |
-
# Prepare
|
247 |
-
reps = [
|
248 |
-
|
249 |
-
reps.append({
|
250 |
"model": 0,
|
251 |
-
"
|
252 |
-
"
|
253 |
-
"
|
254 |
-
"
|
255 |
-
"byres":
|
256 |
"visible": True
|
257 |
-
}
|
|
|
258 |
|
259 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
260 |
|
261 |
return result_str, molecule_viewer
|
262 |
|
|
|
27 |
# Biopython imports
|
28 |
from Bio.PDB import PDBParser, Select, PDBIO
|
29 |
from Bio.PDB.DSSP import DSSP
|
30 |
+
from Bio.PDB import PDBList
|
31 |
|
32 |
from matplotlib import cm # For color mapping
|
33 |
from matplotlib.colors import Normalize
|
|
|
225 |
|
226 |
def process_pdb(pdb_id):
|
227 |
# Fetch PDB file
|
228 |
+
pdbl = PDBList()
|
229 |
pdb_path = pdbl.retrieve_pdb_file(pdb_id, pdir='pdb_files', file_format='pdb')
|
230 |
|
231 |
if not pdb_path or not os.path.exists(pdb_path):
|
|
|
243 |
# Prepare result string
|
244 |
result_str = "\n".join([f"{aa}: {score:.2f}" for aa, score in zip(sequence, normalized_scores)])
|
245 |
|
246 |
+
# Prepare representations for Molecule3D
|
247 |
+
reps = [
|
248 |
+
{
|
|
|
249 |
"model": 0,
|
250 |
+
"style": "cartoon",
|
251 |
+
"color": "whiteCarbon",
|
252 |
+
"residue_range": "",
|
253 |
+
"around": 0,
|
254 |
+
"byres": False,
|
255 |
"visible": True
|
256 |
+
}
|
257 |
+
]
|
258 |
|
259 |
+
# Add color-coded residues based on binding site scores
|
260 |
+
for i, score in enumerate(normalized_scores):
|
261 |
+
if score > 0.7: # You can adjust this threshold
|
262 |
+
reps.append({
|
263 |
+
"model": 0,
|
264 |
+
"chain": chain.get_id(),
|
265 |
+
"style": "stick",
|
266 |
+
"color": score_to_color(score),
|
267 |
+
"residue_range": f"{i+1}-{i+1}",
|
268 |
+
"byres": True,
|
269 |
+
"visible": True
|
270 |
+
})
|
271 |
+
|
272 |
+
# Create Molecule3D with the PDB file and representations
|
273 |
+
molecule_viewer = Molecule3D(
|
274 |
+
file=filtered_pdb_path,
|
275 |
+
reps=reps
|
276 |
+
)
|
277 |
|
278 |
return result_str, molecule_viewer
|
279 |
|
app.py
CHANGED
@@ -27,7 +27,7 @@ from gradio_molecule3d import Molecule3D
|
|
27 |
# Biopython imports
|
28 |
from Bio.PDB import PDBParser, Select, PDBIO
|
29 |
from Bio.PDB.DSSP import DSSP
|
30 |
-
from Bio.PDB import PDBList
|
31 |
|
32 |
from matplotlib import cm # For color mapping
|
33 |
from matplotlib.colors import Normalize
|
@@ -225,7 +225,7 @@ def score_to_color(score):
|
|
225 |
|
226 |
def process_pdb(pdb_id):
|
227 |
# Fetch PDB file
|
228 |
-
pdbl = PDBList()
|
229 |
pdb_path = pdbl.retrieve_pdb_file(pdb_id, pdir='pdb_files', file_format='pdb')
|
230 |
|
231 |
if not pdb_path or not os.path.exists(pdb_path):
|
@@ -243,20 +243,37 @@ def process_pdb(pdb_id):
|
|
243 |
# Prepare result string
|
244 |
result_str = "\n".join([f"{aa}: {score:.2f}" for aa, score in zip(sequence, normalized_scores)])
|
245 |
|
246 |
-
# Prepare
|
247 |
-
reps = [
|
248 |
-
|
249 |
-
reps.append({
|
250 |
"model": 0,
|
251 |
-
"
|
252 |
-
"
|
253 |
-
"
|
254 |
-
"
|
255 |
-
"byres":
|
256 |
"visible": True
|
257 |
-
}
|
|
|
258 |
|
259 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
260 |
|
261 |
return result_str, molecule_viewer
|
262 |
|
|
|
27 |
# Biopython imports
|
28 |
from Bio.PDB import PDBParser, Select, PDBIO
|
29 |
from Bio.PDB.DSSP import DSSP
|
30 |
+
from Bio.PDB import PDBList
|
31 |
|
32 |
from matplotlib import cm # For color mapping
|
33 |
from matplotlib.colors import Normalize
|
|
|
225 |
|
226 |
def process_pdb(pdb_id):
|
227 |
# Fetch PDB file
|
228 |
+
pdbl = PDBList()
|
229 |
pdb_path = pdbl.retrieve_pdb_file(pdb_id, pdir='pdb_files', file_format='pdb')
|
230 |
|
231 |
if not pdb_path or not os.path.exists(pdb_path):
|
|
|
243 |
# Prepare result string
|
244 |
result_str = "\n".join([f"{aa}: {score:.2f}" for aa, score in zip(sequence, normalized_scores)])
|
245 |
|
246 |
+
# Prepare representations for Molecule3D
|
247 |
+
reps = [
|
248 |
+
{
|
|
|
249 |
"model": 0,
|
250 |
+
"style": "cartoon",
|
251 |
+
"color": "whiteCarbon",
|
252 |
+
"residue_range": "",
|
253 |
+
"around": 0,
|
254 |
+
"byres": False,
|
255 |
"visible": True
|
256 |
+
}
|
257 |
+
]
|
258 |
|
259 |
+
# Add color-coded residues based on binding site scores
|
260 |
+
for i, score in enumerate(normalized_scores):
|
261 |
+
if score > 0.7: # You can adjust this threshold
|
262 |
+
reps.append({
|
263 |
+
"model": 0,
|
264 |
+
"chain": chain.get_id(),
|
265 |
+
"style": "stick",
|
266 |
+
"color": score_to_color(score),
|
267 |
+
"residue_range": f"{i+1}-{i+1}",
|
268 |
+
"byres": True,
|
269 |
+
"visible": True
|
270 |
+
})
|
271 |
+
|
272 |
+
# Create Molecule3D with the PDB file and representations
|
273 |
+
molecule_viewer = Molecule3D(
|
274 |
+
file=filtered_pdb_path,
|
275 |
+
reps=reps
|
276 |
+
)
|
277 |
|
278 |
return result_str, molecule_viewer
|
279 |
|