Spaces:
Paused
Paused
Update plot_pdb.py
Browse files- plot_pdb.py +23 -10
plot_pdb.py
CHANGED
|
@@ -4,18 +4,20 @@ from pathlib import Path
|
|
| 4 |
|
| 5 |
import Bio.PDB
|
| 6 |
|
| 7 |
-
def display_pdb_by_pdb(
|
| 8 |
# function to display pdb in py3dmol
|
| 9 |
# ref: https://huggingface.co/spaces/AIGE/A_B
|
| 10 |
-
|
|
|
|
| 11 |
p = Bio.PDB.PDBParser()
|
| 12 |
-
structure = p.get_structure('myStructureName',
|
| 13 |
ids = [a.get_id() for a in structure.get_atoms()]
|
| 14 |
print("structure ids:", ids)
|
| 15 |
-
|
|
|
|
| 16 |
view = py3Dmol.view(width=500, height=500)
|
| 17 |
view.setBackgroundColor('black');
|
| 18 |
-
view.addModel(
|
| 19 |
view.setStyle({'cartoon': {'color': 'spectrum'}})
|
| 20 |
view.zoomTo()
|
| 21 |
output = view._make_html().replace("'", '"')
|
|
@@ -38,12 +40,22 @@ def get_pdb(sequence):
|
|
| 38 |
retries += 1
|
| 39 |
time.sleep(0.1)
|
| 40 |
pdb = str = None
|
| 41 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
|
| 43 |
def plot_struc(sequence):
|
| 44 |
|
| 45 |
-
pdb_string = get_pdb(sequence)
|
| 46 |
-
|
|
|
|
| 47 |
name = sequence[:3] + sequence[-3:] #combine the firt and last 3 AAs of sequence as a filename.
|
| 48 |
|
| 49 |
outpath = (
|
|
@@ -53,7 +65,8 @@ def plot_struc(sequence):
|
|
| 53 |
f.write(pdb_string)
|
| 54 |
|
| 55 |
outpath_str = str(outpath)
|
| 56 |
-
|
| 57 |
-
|
|
|
|
| 58 |
|
| 59 |
return outpath_str, html_view
|
|
|
|
| 4 |
|
| 5 |
import Bio.PDB
|
| 6 |
|
| 7 |
+
def display_pdb_by_pdb(pdb_string,pdb_filename):
|
| 8 |
# function to display pdb in py3dmol
|
| 9 |
# ref: https://huggingface.co/spaces/AIGE/A_B
|
| 10 |
+
|
| 11 |
+
#get pdb column values
|
| 12 |
p = Bio.PDB.PDBParser()
|
| 13 |
+
structure = p.get_structure('myStructureName', pdb_filename)
|
| 14 |
ids = [a.get_id() for a in structure.get_atoms()]
|
| 15 |
print("structure ids:", ids)
|
| 16 |
+
|
| 17 |
+
#plot 3D structure
|
| 18 |
view = py3Dmol.view(width=500, height=500)
|
| 19 |
view.setBackgroundColor('black');
|
| 20 |
+
view.addModel(pdb_string, "pdb")
|
| 21 |
view.setStyle({'cartoon': {'color': 'spectrum'}})
|
| 22 |
view.zoomTo()
|
| 23 |
output = view._make_html().replace("'", '"')
|
|
|
|
| 40 |
retries += 1
|
| 41 |
time.sleep(0.1)
|
| 42 |
pdb = str = None
|
| 43 |
+
|
| 44 |
+
#save a pdb format file
|
| 45 |
+
name = sequence[:3] + sequence[-3:] #combine the firt and last 3 AAs of sequence as a filename.
|
| 46 |
+
outpath = (
|
| 47 |
+
Path.cwd() / f"PDB-{name}.pdb")
|
| 48 |
+
with open(outpath.name, "w") as f:
|
| 49 |
+
f.write(pdb_string)
|
| 50 |
+
outpath_str = str(outpath)
|
| 51 |
+
|
| 52 |
+
return pdb_str, outpath_str
|
| 53 |
|
| 54 |
def plot_struc(sequence):
|
| 55 |
|
| 56 |
+
pdb_string, pdb_filename = get_pdb(sequence)
|
| 57 |
+
|
| 58 |
+
'''
|
| 59 |
name = sequence[:3] + sequence[-3:] #combine the firt and last 3 AAs of sequence as a filename.
|
| 60 |
|
| 61 |
outpath = (
|
|
|
|
| 65 |
f.write(pdb_string)
|
| 66 |
|
| 67 |
outpath_str = str(outpath)
|
| 68 |
+
'''
|
| 69 |
+
|
| 70 |
+
html_view = display_pdb_by_pdb(pdb_string, pdb_filename)
|
| 71 |
|
| 72 |
return outpath_str, html_view
|