Skip to content

Commit

Permalink
feat(server): added route to get user dynamic run status
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivo committed Apr 9, 2023
1 parent ba2a914 commit ee3bbac
Show file tree
Hide file tree
Showing 10 changed files with 59 additions and 118 deletions.
17 changes: 0 additions & 17 deletions apps/server/app.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
from flask import Flask
from flask_cors import CORS
from flask_restful import Api
from flask_sock import Sock
from server.config import Config
from server.resources.downloads import DownloadDynamicAssets
from server.resources.generate_acpype import GenerateAcpypeCommands
from server.resources.generate_apo import GenerateApoCommands
from server.resources.generate_prodrg import GenerateProdrgCommands
from server.resources.health import Health
from server.resources.run import RunDynamic
from server.utils.run_command import run_command

app = Flask(__name__)
app.config.from_object(Config)
api = Api(app)
sock = Sock(app)

CORS(app)

Expand All @@ -34,19 +31,5 @@
api.add_resource(Health, "/api/v1/health")


@sock.route("/api/v1/run-status")
# @requires_connection
def run(ws):
"""
Format expected:
data: {
dynamic_id: str
}
"""
data = ws.receive()

ws.close(reason="success")


if __name__ == "__main__":
app.run(debug=True)
3 changes: 2 additions & 1 deletion apps/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"scripts": {
"dev": "poetry run flask run --reload",
"padd": "poetry add",
"pinstall": "poetry install"
"pinstall": "poetry install",
"prm": "poetry remove"
},
"keywords": [],
"author": "",
Expand Down
48 changes: 1 addition & 47 deletions apps/server/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion apps/server/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ python = "^3.10"
flask = "^2.2.3"
flask-restful = "^0.3.9"
prisma = "^0.8.2"
flask-sock = "^0.6.0"
asyncio = "^3.4.3"
flask-cors = "^3.0.10"

Expand Down
22 changes: 11 additions & 11 deletions apps/server/server/resources/generate_apo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def post(self):
f'{gmx} grompp -f PME_em.mdp -c "{filename}_charged.gro" -p "{filename}.top" -o "{filename}_charged" -maxwarn 2\n',
f'{gmx} mdrun -v -s "{filename}_charged.tpr" -deffnm "{filename}_sd_em"\n',
f'echo \'10 0\' | {gmx} energy -f "{filename}_sd_em.edr" -o "{filename}_potentialsd.xvg"\n',
f'{grace} -nxy "{filename}_potentialsd.xvg" -hdevice PNG -hardcopy -printfile "../graficos/{filename}_potentialsd.png"\n\n',
f'{grace} -nxy "{filename}_potentialsd.xvg" -hdevice PNG -hardcopy -printfile "../figures/{filename}_potentialsd.png"\n\n',
]
)

Expand All @@ -70,34 +70,34 @@ def post(self):
f'{gmx} grompp -f PME_cg_em.mdp -c "{filename}_sd_em.gro" -p "{filename}.top" -o "{filename}_cg_em" -maxwarn 2\n',
f'{gmx} mdrun -v -s "{filename}_cg_em.tpr" -deffnm "{filename}_cg_em"\n',
f'echo \'10 0\' | {gmx} energy -f "{filename}_cg_em.edr" -o "{filename}_potentialcg.xvg"\n',
f'{grace} -nxy "{filename}_potentialcg.xvg" -hdevice PNG -hardcopy -printfile "../graficos/{filename}_potentialcg.png"\n\n',
f'{grace} -nxy "{filename}_potentialcg.xvg" -hdevice PNG -hardcopy -printfile "../figures/{filename}_potentialcg.png"\n\n',
"#equilibrationnvt\n",
f'{gmx} grompp -f nvt.mdp -c "{filename}_cg_em.gro" -r "{filename}_cg_em.gro" -p "{filename}.top" -o "{filename}_nvt.tpr" -maxwarn 2\n',
f'{gmx} mdrun -v -s "{filename}_nvt.tpr" -deffnm "{filename}_nvt"\n',
f'echo \'16 0\' | {gmx} energy -f "{filename}_nvt.edr" -o "{filename}_temperature_nvt.xvg"\n',
f'{grace} -nxy "{filename}_temperature_nvt.xvg" -hdevice PNG -hardcopy -printfile "../graficos/{filename}_temperature_nvt.png"\n\n',
f'{grace} -nxy "{filename}_temperature_nvt.xvg" -hdevice PNG -hardcopy -printfile "../figures/{filename}_temperature_nvt.png"\n\n',
"#equilibrationnpt\n",
f'{gmx} grompp -f npt.mdp -c "{filename}_nvt.gro" -r "{filename}_nvt.gro" -p "{filename}.top" -o "{filename}_npt.tpr" -maxwarn 2\n',
f'{gmx} mdrun -v -s "{filename}_npt.tpr" -deffnm "{filename}_npt"\n',
f'echo \'16 0\' | {gmx} energy -f "{filename}_npt.edr" -o "{filename}_temperature_npt.xvg"\n',
f'{grace} -nxy "{filename}_temperature_npt.xvg" -hdevice PNG -hardcopy -printfile "../graficos/{filename}_temperature_npt.png"\n\n',
f'{grace} -nxy "{filename}_temperature_npt.xvg" -hdevice PNG -hardcopy -printfile "../figures/{filename}_temperature_npt.png"\n\n',
"#productionmd\n",
f'{gmx} grompp -f md_pr.mdp -c "{filename}_npt.gro" -p "{filename}.top" -o "{filename}_pr" -maxwarn 2\n',
f'{gmx} mdrun -v -s "{filename}_pr.tpr" -deffnm "{filename}_pr"\n\n',
"#analyzemd\n",
f'echo \'1 1\' | {gmx} trjconv -s "{filename}_pr.tpr" -f "{filename}_pr.xtc" -o "{filename}_pr_PBC.xtc" -pbc mol -center\n',
f'echo \'4 4\' | {gmx} rms -s "{filename}_pr.tpr" -f "{filename}_pr_PBC.xtc" -o "{filename}_rmsd_prod.xvg" -tu ns\n',
f'{grace} -nxy "{filename}_rmsd_prod.xvg" -hdevice PNG -hardcopy -printfile "../graficos/{filename}_rmsd_prod.png"\n',
f'{grace} -nxy "{filename}_rmsd_prod.xvg" -hdevice PNG -hardcopy -printfile "../figures/{filename}_rmsd_prod.png"\n',
f'echo \'4 4\' | {gmx} rms -s "{filename}_charged.tpr" -f "{filename}_pr_PBC.xtc" -o "{filename}_rmsd_cris.xvg" -tu ns\n',
f'{grace} -nxy "{filename}_rmsd_cris.xvg" -hdevice PNG -hardcopy -printfile "../graficos/{filename}_rmsd_cris.png"\n',
f'{grace} -nxy "{filename}_rmsd_prod.xvg" "{filename}_rmsd_cris.xvg" -hdevice PNG -hardcopy -printfile "../graficos/{filename}_rmsd_prod_cris.png"\n',
f'{grace} -nxy "{filename}_rmsd_cris.xvg" -hdevice PNG -hardcopy -printfile "../figures/{filename}_rmsd_cris.png"\n',
f'{grace} -nxy "{filename}_rmsd_prod.xvg" "{filename}_rmsd_cris.xvg" -hdevice PNG -hardcopy -printfile "../figures/{filename}_rmsd_prod_cris.png"\n',
f'echo \'1\' | {gmx} gyrate -s "{filename}_pr.tpr" -f "{filename}_pr_PBC.xtc" -o "{filename}_gyrate.xvg"\n',
f'{grace} -nxy "{filename}_gyrate.xvg" -hdevice PNG -hardcopy -printfile "../graficos/{filename}_gyrate.png"\n',
f'{grace} -nxy "{filename}_gyrate.xvg" -hdevice PNG -hardcopy -printfile "../figures/{filename}_gyrate.png"\n',
f'echo \'1\' | {gmx} rmsf -s "{filename}_pr.tpr" -f "{filename}_pr_PBC.xtc" -o "{filename}_rmsf_residue.xvg" -res\n',
f'{grace} -nxy "{filename}_rmsf_residue.xvg" -hdevice PNG -hardcopy -printfile "../graficos/{filename}_rmsf_residue.png"\n',
f'{grace} -nxy "{filename}_rmsf_residue.xvg" -hdevice PNG -hardcopy -printfile "../figures/{filename}_rmsf_residue.png"\n',
f'echo \'1\' | {gmx} sasa -s "{filename}_pr.tpr" -f "{filename}_pr_PBC.xtc" -o "{filename}_solvent_accessible_surface.xvg" -or "{filename}_sas_residue.xvg"\n',
f'{grace} -nxy "{filename}_solvent_accessible_surface.xvg" -hdevice PNG -hardcopy -printfile "../graficos/{filename}_solvent_accessible_surface.png"\n',
f'{grace} -nxy "{filename}_sas_residue.xvg" -hdevice PNG -hardcopy -printfile "../graficos/{filename}_sas_residue.png"\n',
f'{grace} -nxy "{filename}_solvent_accessible_surface.xvg" -hdevice PNG -hardcopy -printfile "../figures/{filename}_solvent_accessible_surface.png"\n',
f'{grace} -nxy "{filename}_sas_residue.xvg" -hdevice PNG -hardcopy -printfile "../figures/{filename}_sas_residue.png"\n',
]
)

Expand Down
54 changes: 43 additions & 11 deletions apps/server/server/resources/run/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import threading
import json
import os
import shutil
from flask import request
from flask_restful import Resource, reqparse
from server.config import Config
from server.utils.run_command import run_command
Expand All @@ -17,6 +17,9 @@ def post(self):
# Get absolute path to run folder
folder_run = os.path.abspath(args["folder_run"])

# Get absolute path to dynamic folder
folder = os.path.abspath(os.path.join(folder_run, ".."))

# Get absolute path to the folder where our default MDP files are stored
folder_mdp = os.path.abspath(Config.MDP_LOCATION_FOLDER)

Expand All @@ -29,13 +32,14 @@ def post(self):
if os.path.isfile(file_path):
shutil.copy(file_path, folder_run)

file_log_path = os.path.join(folder_run, "logs", "gmx.log")
file_step_path = os.path.join(folder_run, "..", "steps.txt")
file_log_path = os.path.abspath(os.path.join(folder_run, "logs", "gmx.log"))
file_step_path = os.path.abspath(os.path.join(folder, "steps.txt"))
file_is_running = os.path.abspath(os.path.join(folder, "..", "is-running"))

# UPDATE STATUS ON DB THAT `dynamic_id` is now running

# Load commands file contents to a variable
file_commands_path = os.path.join(folder_run, "..", "commands.txt")
file_commands_path = os.path.join(folder, "commands.txt")
with open(file_commands_path, "r") as f:
commands_file_content = f.readlines()

Expand All @@ -49,10 +53,13 @@ def run_commands():
# Make our shell go to the run folder
os.chdir(folder_run)

with open(file_is_running, "w") as f:
f.write(folder)

# Iterate in our command list
for command in commands:
if command[0] == "#":
with open(file_step_path, "w+") as f:
with open(file_step_path, "a+") as f:
f.write(f"{command}\n")
else:
(pid, rcode) = run_command(command, file_log_path)
Expand All @@ -64,20 +71,45 @@ def run_commands():
# UPDATE ON DB THAT EXECUTION FAILED

# SEND MAIL NOTIFYING DYNAMIC ERRORED
return {"status": "errored"}
# ws.close(reason="errored", message=command)
with open(os.path.join(folder_run, "error"), "w") as f:
f.writelines(f"errored at: {command}")

# UPDATE ON DB THAT EXECUTION ENDED WITH SUCCESS

# SEND EMAIL NOTIFYING DYNAMIC ENDED
# ws.close(reason="success")
return {
"status": "success",
}
with open(file_log_path, "a+") as f:
f.write("\n\nfinished")

if os.path.exists(file_is_running):
os.remove(file_is_running)

# Start the command execution in a new thread
thread = threading.Thread(target=run_commands)
thread.start()

# Return a response indicating that the command has started
return {"status": "started"}

def get(self):
args = request.args

user_id = args["user_id"]

folder_user = os.path.abspath(os.path.join(Config.UPLOAD_FOLDER, user_id))

file_is_running = os.path.abspath(os.path.join(folder_user, "is-running"))

if os.path.exists(file_is_running):
with open(file_is_running, "r") as f:
folder = f.readline()

file_gmx_log = os.path.abspath(
os.path.join(folder, "run", "logs", "gmx.log")
)

with open(file_gmx_log, "r") as f:
log_lines = f.readlines()

return {"status": "running", "log": log_lines[-30:]}

return {"status": "running", "folder": args["folder"]}
2 changes: 1 addition & 1 deletion apps/server/server/static/mdp/md_pr.mdp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
title = OPLS Lysozyme MD simulation
; Run parameters
integrator = md ; leap-frog integrator
nsteps = 1250000 ; 2 * 50000 = 1000 ps (1 ns)
nsteps = 300 ;1250000 ; 2 * 50000 = 1000 ps (1 ns)
dt = 0.002 ; 2 fs
; Output control
nstxout = 5000 ; save coordinates every 10.0 ps
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
"author": "",
"license": "ISC",
"devDependencies": {
"concurrently": "^8.0.1",
"prisma": "^4.12.0"
"concurrently": "^8.0.1"
}
}
16 changes: 0 additions & 16 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 0 additions & 11 deletions prisma/schema.prisma

This file was deleted.

0 comments on commit ee3bbac

Please sign in to comment.