Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -54,11 +54,11 @@ def predict_molecule(structure_file, task_name, charge=0, spin_multiplicity=1):
|
|
| 54 |
return f"Error: Empty file: {file_path}", "Error"
|
| 55 |
|
| 56 |
atoms = read(file_path)
|
| 57 |
-
|
| 58 |
# Solo aplicar charge/spin para OMol
|
| 59 |
if task_name in ["OMol", "OMol-Direct"]:
|
| 60 |
atoms.info = {"charge": int(charge), "spin": int(spin_multiplicity)}
|
| 61 |
-
|
| 62 |
atoms.calc = calc
|
| 63 |
energy = atoms.get_potential_energy()
|
| 64 |
forces = atoms.get_forces()
|
|
@@ -75,7 +75,7 @@ def predict_molecule(structure_file, task_name, charge=0, spin_multiplicity=1):
|
|
| 75 |
lines += ["", f"Max Force: {max_force:.4f} eV/Å"]
|
| 76 |
|
| 77 |
return "\n".join(lines), f"Calculation completed with {task_name}"
|
| 78 |
-
|
| 79 |
except Exception as e:
|
| 80 |
import traceback
|
| 81 |
traceback.print_exc()
|
|
@@ -139,7 +139,7 @@ with gr.Blocks(theme=gr.themes.Ocean(), title="OrbMol Demo") as demo:
|
|
| 139 |
with gr.Column(scale=2):
|
| 140 |
gr.Markdown("# OrbMol — Quantum-Accurate Molecular Predictions")
|
| 141 |
gr.Markdown("**Supported formats:** .xyz, .pdb, .cif, .traj, .mol, .sdf")
|
| 142 |
-
|
| 143 |
xyz_input = gr.File(
|
| 144 |
label="Upload Structure File",
|
| 145 |
file_types=[".xyz", ".pdb", ".cif", ".traj", ".mol", ".sdf"],
|
|
@@ -153,23 +153,23 @@ with gr.Blocks(theme=gr.themes.Ocean(), title="OrbMol Demo") as demo:
|
|
| 153 |
with gr.Row():
|
| 154 |
charge_input = gr.Slider(-10, 10, 0, step=1, label="Charge")
|
| 155 |
spin_input = gr.Slider(1, 11, 1, step=1, label="Spin Multiplicity")
|
| 156 |
-
|
| 157 |
run_spe = gr.Button("Run OrbMol Prediction", variant="primary")
|
| 158 |
-
|
| 159 |
with gr.Column(variant="panel", min_width=500):
|
| 160 |
spe_out = gr.Textbox(label="Energy & Forces", lines=15, interactive=False)
|
| 161 |
spe_status = gr.Textbox(label="Status", interactive=False)
|
| 162 |
-
|
| 163 |
spe_viewer = Molecule3D(
|
| 164 |
label="Input Structure Viewer",
|
| 165 |
reps=DEFAULT_MOLECULAR_REPRESENTATIONS,
|
| 166 |
config=DEFAULT_MOLECULAR_SETTINGS,
|
| 167 |
-
render=
|
| 168 |
inputs=[xyz_input],
|
| 169 |
value=lambda x: x,
|
| 170 |
interactive=False
|
| 171 |
)
|
| 172 |
-
|
| 173 |
task_name_spe.change(
|
| 174 |
lambda x: (
|
| 175 |
gr.update(visible=x in ["OMol", "OMol-Direct"]),
|
|
@@ -178,7 +178,7 @@ with gr.Blocks(theme=gr.themes.Ocean(), title="OrbMol Demo") as demo:
|
|
| 178 |
[task_name_spe],
|
| 179 |
[charge_input, spin_input]
|
| 180 |
)
|
| 181 |
-
|
| 182 |
run_spe.click(
|
| 183 |
predict_molecule,
|
| 184 |
[xyz_input, task_name_spe, charge_input, spin_input],
|
|
@@ -190,7 +190,7 @@ with gr.Blocks(theme=gr.themes.Ocean(), title="OrbMol Demo") as demo:
|
|
| 190 |
with gr.Row():
|
| 191 |
with gr.Column(scale=2):
|
| 192 |
gr.Markdown("## Molecular Dynamics Simulation")
|
| 193 |
-
|
| 194 |
xyz_md = gr.File(
|
| 195 |
label="Upload Structure File",
|
| 196 |
file_types=[".xyz", ".pdb", ".cif", ".traj", ".mol", ".sdf"],
|
|
@@ -215,21 +215,21 @@ with gr.Blocks(theme=gr.themes.Ocean(), title="OrbMol Demo") as demo:
|
|
| 215 |
with gr.Column(variant="panel", min_width=520):
|
| 216 |
md_status = gr.Textbox(label="MD Status", interactive=False)
|
| 217 |
md_traj = gr.File(label="Trajectory (.traj)", interactive=False)
|
| 218 |
-
|
| 219 |
md_viewer = Molecule3D(
|
| 220 |
label="MD Result Viewer",
|
| 221 |
reps=DEFAULT_MOLECULAR_REPRESENTATIONS,
|
| 222 |
config=DEFAULT_MOLECULAR_SETTINGS,
|
| 223 |
-
render=
|
| 224 |
inputs=[md_traj],
|
| 225 |
value=lambda x: x,
|
| 226 |
interactive=False
|
| 227 |
)
|
| 228 |
-
|
| 229 |
md_log = gr.Textbox(label="Log", interactive=False, lines=15)
|
| 230 |
md_script = gr.Code(label="Reproduction Script", language="python", interactive=False, lines=20)
|
| 231 |
md_explain = gr.Markdown()
|
| 232 |
-
|
| 233 |
task_name_md.change(
|
| 234 |
lambda x: (
|
| 235 |
gr.update(visible=x in ["OMol", "OMol-Direct"]),
|
|
@@ -238,7 +238,7 @@ with gr.Blocks(theme=gr.themes.Ocean(), title="OrbMol Demo") as demo:
|
|
| 238 |
[task_name_md],
|
| 239 |
[charge_md, spin_md]
|
| 240 |
)
|
| 241 |
-
|
| 242 |
run_md_btn.click(
|
| 243 |
md_wrapper,
|
| 244 |
[xyz_md, task_name_md, charge_md, spin_md, steps_md, temp_md, timestep_md, ensemble_md],
|
|
@@ -250,7 +250,7 @@ with gr.Blocks(theme=gr.themes.Ocean(), title="OrbMol Demo") as demo:
|
|
| 250 |
with gr.Row():
|
| 251 |
with gr.Column(scale=2):
|
| 252 |
gr.Markdown("## Structure Relaxation/Optimization")
|
| 253 |
-
|
| 254 |
xyz_rlx = gr.File(
|
| 255 |
label="Upload Structure File",
|
| 256 |
file_types=[".xyz", ".pdb", ".cif", ".traj", ".mol", ".sdf"],
|
|
@@ -273,17 +273,17 @@ with gr.Blocks(theme=gr.themes.Ocean(), title="OrbMol Demo") as demo:
|
|
| 273 |
with gr.Column(variant="panel", min_width=520):
|
| 274 |
rlx_status = gr.Textbox(label="Status", interactive=False)
|
| 275 |
rlx_traj = gr.File(label="Trajectory (.traj)", interactive=False)
|
| 276 |
-
|
| 277 |
rlx_viewer = Molecule3D(
|
| 278 |
label="Optimized Structure Viewer",
|
| 279 |
reps=DEFAULT_MOLECULAR_REPRESENTATIONS,
|
| 280 |
config=DEFAULT_MOLECULAR_SETTINGS,
|
| 281 |
-
render=
|
| 282 |
inputs=[rlx_traj],
|
| 283 |
value=lambda x: x,
|
| 284 |
interactive=False
|
| 285 |
)
|
| 286 |
-
|
| 287 |
rlx_log = gr.Textbox(label="Log", interactive=False, lines=15)
|
| 288 |
rlx_script = gr.Code(label="Reproduction Script", language="python", interactive=False, lines=20)
|
| 289 |
rlx_explain = gr.Markdown()
|
|
@@ -296,7 +296,7 @@ with gr.Blocks(theme=gr.themes.Ocean(), title="OrbMol Demo") as demo:
|
|
| 296 |
[task_name_rlx],
|
| 297 |
[charge_rlx, spin_rlx]
|
| 298 |
)
|
| 299 |
-
|
| 300 |
run_rlx_btn.click(
|
| 301 |
relax_wrapper,
|
| 302 |
[xyz_rlx, task_name_rlx, steps_rlx, fmax_rlx, charge_rlx, spin_rlx, relax_cell],
|
|
@@ -304,4 +304,4 @@ with gr.Blocks(theme=gr.themes.Ocean(), title="OrbMol Demo") as demo:
|
|
| 304 |
)
|
| 305 |
|
| 306 |
if __name__ == "__main__":
|
| 307 |
-
demo.launch(server_name="0.0.0.0", server_port=7860, show_error=True)
|
|
|
|
| 54 |
return f"Error: Empty file: {file_path}", "Error"
|
| 55 |
|
| 56 |
atoms = read(file_path)
|
| 57 |
+
|
| 58 |
# Solo aplicar charge/spin para OMol
|
| 59 |
if task_name in ["OMol", "OMol-Direct"]:
|
| 60 |
atoms.info = {"charge": int(charge), "spin": int(spin_multiplicity)}
|
| 61 |
+
|
| 62 |
atoms.calc = calc
|
| 63 |
energy = atoms.get_potential_energy()
|
| 64 |
forces = atoms.get_forces()
|
|
|
|
| 75 |
lines += ["", f"Max Force: {max_force:.4f} eV/Å"]
|
| 76 |
|
| 77 |
return "\n".join(lines), f"Calculation completed with {task_name}"
|
| 78 |
+
|
| 79 |
except Exception as e:
|
| 80 |
import traceback
|
| 81 |
traceback.print_exc()
|
|
|
|
| 139 |
with gr.Column(scale=2):
|
| 140 |
gr.Markdown("# OrbMol — Quantum-Accurate Molecular Predictions")
|
| 141 |
gr.Markdown("**Supported formats:** .xyz, .pdb, .cif, .traj, .mol, .sdf")
|
| 142 |
+
|
| 143 |
xyz_input = gr.File(
|
| 144 |
label="Upload Structure File",
|
| 145 |
file_types=[".xyz", ".pdb", ".cif", ".traj", ".mol", ".sdf"],
|
|
|
|
| 153 |
with gr.Row():
|
| 154 |
charge_input = gr.Slider(-10, 10, 0, step=1, label="Charge")
|
| 155 |
spin_input = gr.Slider(1, 11, 1, step=1, label="Spin Multiplicity")
|
| 156 |
+
|
| 157 |
run_spe = gr.Button("Run OrbMol Prediction", variant="primary")
|
| 158 |
+
|
| 159 |
with gr.Column(variant="panel", min_width=500):
|
| 160 |
spe_out = gr.Textbox(label="Energy & Forces", lines=15, interactive=False)
|
| 161 |
spe_status = gr.Textbox(label="Status", interactive=False)
|
| 162 |
+
|
| 163 |
spe_viewer = Molecule3D(
|
| 164 |
label="Input Structure Viewer",
|
| 165 |
reps=DEFAULT_MOLECULAR_REPRESENTATIONS,
|
| 166 |
config=DEFAULT_MOLECULAR_SETTINGS,
|
| 167 |
+
render=True, # ← activado
|
| 168 |
inputs=[xyz_input],
|
| 169 |
value=lambda x: x,
|
| 170 |
interactive=False
|
| 171 |
)
|
| 172 |
+
|
| 173 |
task_name_spe.change(
|
| 174 |
lambda x: (
|
| 175 |
gr.update(visible=x in ["OMol", "OMol-Direct"]),
|
|
|
|
| 178 |
[task_name_spe],
|
| 179 |
[charge_input, spin_input]
|
| 180 |
)
|
| 181 |
+
|
| 182 |
run_spe.click(
|
| 183 |
predict_molecule,
|
| 184 |
[xyz_input, task_name_spe, charge_input, spin_input],
|
|
|
|
| 190 |
with gr.Row():
|
| 191 |
with gr.Column(scale=2):
|
| 192 |
gr.Markdown("## Molecular Dynamics Simulation")
|
| 193 |
+
|
| 194 |
xyz_md = gr.File(
|
| 195 |
label="Upload Structure File",
|
| 196 |
file_types=[".xyz", ".pdb", ".cif", ".traj", ".mol", ".sdf"],
|
|
|
|
| 215 |
with gr.Column(variant="panel", min_width=520):
|
| 216 |
md_status = gr.Textbox(label="MD Status", interactive=False)
|
| 217 |
md_traj = gr.File(label="Trajectory (.traj)", interactive=False)
|
| 218 |
+
|
| 219 |
md_viewer = Molecule3D(
|
| 220 |
label="MD Result Viewer",
|
| 221 |
reps=DEFAULT_MOLECULAR_REPRESENTATIONS,
|
| 222 |
config=DEFAULT_MOLECULAR_SETTINGS,
|
| 223 |
+
render=True, # ← activado
|
| 224 |
inputs=[md_traj],
|
| 225 |
value=lambda x: x,
|
| 226 |
interactive=False
|
| 227 |
)
|
| 228 |
+
|
| 229 |
md_log = gr.Textbox(label="Log", interactive=False, lines=15)
|
| 230 |
md_script = gr.Code(label="Reproduction Script", language="python", interactive=False, lines=20)
|
| 231 |
md_explain = gr.Markdown()
|
| 232 |
+
|
| 233 |
task_name_md.change(
|
| 234 |
lambda x: (
|
| 235 |
gr.update(visible=x in ["OMol", "OMol-Direct"]),
|
|
|
|
| 238 |
[task_name_md],
|
| 239 |
[charge_md, spin_md]
|
| 240 |
)
|
| 241 |
+
|
| 242 |
run_md_btn.click(
|
| 243 |
md_wrapper,
|
| 244 |
[xyz_md, task_name_md, charge_md, spin_md, steps_md, temp_md, timestep_md, ensemble_md],
|
|
|
|
| 250 |
with gr.Row():
|
| 251 |
with gr.Column(scale=2):
|
| 252 |
gr.Markdown("## Structure Relaxation/Optimization")
|
| 253 |
+
|
| 254 |
xyz_rlx = gr.File(
|
| 255 |
label="Upload Structure File",
|
| 256 |
file_types=[".xyz", ".pdb", ".cif", ".traj", ".mol", ".sdf"],
|
|
|
|
| 273 |
with gr.Column(variant="panel", min_width=520):
|
| 274 |
rlx_status = gr.Textbox(label="Status", interactive=False)
|
| 275 |
rlx_traj = gr.File(label="Trajectory (.traj)", interactive=False)
|
| 276 |
+
|
| 277 |
rlx_viewer = Molecule3D(
|
| 278 |
label="Optimized Structure Viewer",
|
| 279 |
reps=DEFAULT_MOLECULAR_REPRESENTATIONS,
|
| 280 |
config=DEFAULT_MOLECULAR_SETTINGS,
|
| 281 |
+
render=True, # ← activado
|
| 282 |
inputs=[rlx_traj],
|
| 283 |
value=lambda x: x,
|
| 284 |
interactive=False
|
| 285 |
)
|
| 286 |
+
|
| 287 |
rlx_log = gr.Textbox(label="Log", interactive=False, lines=15)
|
| 288 |
rlx_script = gr.Code(label="Reproduction Script", language="python", interactive=False, lines=20)
|
| 289 |
rlx_explain = gr.Markdown()
|
|
|
|
| 296 |
[task_name_rlx],
|
| 297 |
[charge_rlx, spin_rlx]
|
| 298 |
)
|
| 299 |
+
|
| 300 |
run_rlx_btn.click(
|
| 301 |
relax_wrapper,
|
| 302 |
[xyz_rlx, task_name_rlx, steps_rlx, fmax_rlx, charge_rlx, spin_rlx, relax_cell],
|
|
|
|
| 304 |
)
|
| 305 |
|
| 306 |
if __name__ == "__main__":
|
| 307 |
+
demo.launch(server_name="0.0.0.0", server_port=7860, show_error=True)
|