Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
@@ -545,18 +545,19 @@ def protein_diffusion_model(sequence, seq_len, helix_bias, strand_bias, loop_bia
|
|
545 |
|
546 |
return output_seq, output_pdb, display_pdb(output_pdb), get_plddt_plot(plddt_data, S.max_t)
|
547 |
|
548 |
-
|
549 |
def get_plddt_plot(plddt_data, max_t):
|
550 |
-
x = [i+1 for i in range(len(plddt_data))]
|
551 |
fig, ax = plt.subplots(figsize=(15,6))
|
552 |
-
|
553 |
-
ax.
|
554 |
-
ax.
|
555 |
-
ax.
|
|
|
556 |
ax.set_ylabel('model confidence (plddt)')
|
557 |
ax.set_xlabel('diffusion steps (t)')
|
|
|
558 |
return fig
|
559 |
|
|
|
560 |
def display_pdb(path_to_pdb):
|
561 |
'''
|
562 |
#function to display pdb in py3dmol
|
@@ -936,15 +937,25 @@ def process_chat_and_generate(message, history):
|
|
936 |
rewrite_pdb=None
|
937 |
)
|
938 |
|
|
|
939 |
# 3. ๋ชจ๋ ๋จ๊ณ์ ๊ฒฐ๊ณผ ์์ง
|
940 |
final_result = None
|
|
|
|
|
941 |
for result in generator:
|
942 |
final_result = result
|
943 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
944 |
yield (
|
945 |
history + [
|
946 |
{"role": "user", "content": message},
|
947 |
-
{"role": "assistant", "content": f"๋จ๋ฐฑ์ง ์์ฑ ์ค... {len(
|
948 |
],
|
949 |
create_radar_chart(calculate_hero_stats(
|
950 |
params['helix_bias'],
|
@@ -952,7 +963,7 @@ def process_chat_and_generate(message, history):
|
|
952 |
params['loop_bias'],
|
953 |
params['hydrophobic_target_score']
|
954 |
)),
|
955 |
-
f"๋จ๋ฐฑ์ง ์์ฑ ์งํ ์ค... {len(
|
956 |
result[0], # output_seq
|
957 |
result[1], # output_pdb
|
958 |
result[2], # structure_view
|
@@ -964,14 +975,6 @@ def process_chat_and_generate(message, history):
|
|
964 |
|
965 |
output_seq, output_pdb, structure_view, plddt_plot = final_result
|
966 |
|
967 |
-
# 4. ํ์ด๋ก ๋ฅ๋ ฅ์น ๊ณ์ฐ
|
968 |
-
stats = calculate_hero_stats(
|
969 |
-
helix_bias=params['helix_bias'],
|
970 |
-
strand_bias=params['strand_bias'],
|
971 |
-
loop_bias=params['loop_bias'],
|
972 |
-
hydrophobic_score=params['hydrophobic_target_score']
|
973 |
-
)
|
974 |
-
|
975 |
# 5. ์ต์ข
์ค๋ช
์์ฑ
|
976 |
explanation = f"""
|
977 |
์์ฒญํ์ ๊ธฐ๋ฅ์ ๋ง๋ ๋จ๋ฐฑ์ง์ ์์ฑํ์ต๋๋ค:
|
@@ -986,7 +989,8 @@ def process_chat_and_generate(message, history):
|
|
986 |
- ๋ฃจํ ๊ตฌ์กฐ ๋น์จ: {params['loop_bias']*100:.1f}%
|
987 |
- ์์์ฑ ์ ์: {params['hydrophobic_target_score']}
|
988 |
|
989 |
-
์์ฑ์ด ์๋ฃ๋์์ต๋๋ค. ์ด {len(
|
|
|
990 |
"""
|
991 |
|
992 |
# 6. ์ต์ข
๊ฒฐ๊ณผ ๋ฐํ
|
@@ -1005,6 +1009,7 @@ def process_chat_and_generate(message, history):
|
|
1005 |
|
1006 |
except Exception as e:
|
1007 |
print(f"Error in process_chat_and_generate: {str(e)}")
|
|
|
1008 |
return (
|
1009 |
history + [
|
1010 |
{"role": "user", "content": message},
|
|
|
545 |
|
546 |
return output_seq, output_pdb, display_pdb(output_pdb), get_plddt_plot(plddt_data, S.max_t)
|
547 |
|
|
|
548 |
def get_plddt_plot(plddt_data, max_t):
|
|
|
549 |
fig, ax = plt.subplots(figsize=(15,6))
|
550 |
+
x = list(range(1, len(plddt_data) + 1))
|
551 |
+
ax.plot(x, plddt_data, color='#661dbf', linewidth=3, marker='o')
|
552 |
+
ax.set_xticks(range(1, max_t + 1))
|
553 |
+
ax.set_yticks([i/10 for i in range(11)]) # 0๋ถํฐ 1๊น์ง
|
554 |
+
ax.set_ylim([0, 1])
|
555 |
ax.set_ylabel('model confidence (plddt)')
|
556 |
ax.set_xlabel('diffusion steps (t)')
|
557 |
+
plt.close() # ๋ฉ๋ชจ๋ฆฌ ๊ด๋ฆฌ๋ฅผ ์ํด ๋ซ๊ธฐ
|
558 |
return fig
|
559 |
|
560 |
+
|
561 |
def display_pdb(path_to_pdb):
|
562 |
'''
|
563 |
#function to display pdb in py3dmol
|
|
|
937 |
rewrite_pdb=None
|
938 |
)
|
939 |
|
940 |
+
|
941 |
# 3. ๋ชจ๋ ๋จ๊ณ์ ๊ฒฐ๊ณผ ์์ง
|
942 |
final_result = None
|
943 |
+
plddt_data = [] # plddt ๋ฐ์ดํฐ๋ฅผ ์ ์ฅํ ๋ฆฌ์คํธ ์ถ๊ฐ
|
944 |
+
|
945 |
for result in generator:
|
946 |
final_result = result
|
947 |
+
if result[3]: # plddt_plot์ด ์กด์ฌํ๋ ๊ฒฝ์ฐ
|
948 |
+
# matplotlib ๊ทธ๋ํ์์ ๋ฐ์ดํฐ ์ถ์ถ
|
949 |
+
ax = result[3].gca()
|
950 |
+
if ax.lines:
|
951 |
+
line = ax.lines[0]
|
952 |
+
plddt_data = line.get_ydata().tolist()
|
953 |
+
|
954 |
+
# ์ค๊ฐ ๊ฒฐ๊ณผ ์
๋ฐ์ดํธ
|
955 |
yield (
|
956 |
history + [
|
957 |
{"role": "user", "content": message},
|
958 |
+
{"role": "assistant", "content": f"๋จ๋ฐฑ์ง ์์ฑ ์ค... {len(plddt_data)}๋จ๊ณ ์๋ฃ"}
|
959 |
],
|
960 |
create_radar_chart(calculate_hero_stats(
|
961 |
params['helix_bias'],
|
|
|
963 |
params['loop_bias'],
|
964 |
params['hydrophobic_target_score']
|
965 |
)),
|
966 |
+
f"๋จ๋ฐฑ์ง ์์ฑ ์งํ ์ค... {len(plddt_data)}๋จ๊ณ ์๋ฃ",
|
967 |
result[0], # output_seq
|
968 |
result[1], # output_pdb
|
969 |
result[2], # structure_view
|
|
|
975 |
|
976 |
output_seq, output_pdb, structure_view, plddt_plot = final_result
|
977 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
978 |
# 5. ์ต์ข
์ค๋ช
์์ฑ
|
979 |
explanation = f"""
|
980 |
์์ฒญํ์ ๊ธฐ๋ฅ์ ๋ง๋ ๋จ๋ฐฑ์ง์ ์์ฑํ์ต๋๋ค:
|
|
|
989 |
- ๋ฃจํ ๊ตฌ์กฐ ๋น์จ: {params['loop_bias']*100:.1f}%
|
990 |
- ์์์ฑ ์ ์: {params['hydrophobic_target_score']}
|
991 |
|
992 |
+
์์ฑ์ด ์๋ฃ๋์์ต๋๋ค. ์ด {len(plddt_data)}๋จ๊ณ์ ์ต์ ํ๋ฅผ ์ํํ์ต๋๋ค.
|
993 |
+
์ต์ข
์์ ์ฑ ์ ์: {np.mean(plddt_data):.2f}
|
994 |
"""
|
995 |
|
996 |
# 6. ์ต์ข
๊ฒฐ๊ณผ ๋ฐํ
|
|
|
1009 |
|
1010 |
except Exception as e:
|
1011 |
print(f"Error in process_chat_and_generate: {str(e)}")
|
1012 |
+
traceback.print_exc() # ์์ธํ ์๋ฌ ์ ๋ณด ์ถ๋ ฅ
|
1013 |
return (
|
1014 |
history + [
|
1015 |
{"role": "user", "content": message},
|