Skip to content

Commit

Permalink
feat: download xtc, visual status of dynamic at home page, form valid…
Browse files Browse the repository at this point in the history
…ation and more
  • Loading branch information
ivopr committed Dec 30, 2022
1 parent 268fd7b commit 4943481
Show file tree
Hide file tree
Showing 13 changed files with 483 additions and 355 deletions.
79 changes: 46 additions & 33 deletions app/blueprints/download/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,71 +8,84 @@

from app.config import Config
from . import DownloadBlueprint
from flask import render_template, make_response, request, send_file
from flask import send_file
from flask_babel import _
from app import login_manager, login_required
from app import login_required

@DownloadBlueprint.route('/imgfiles/<filename>')
@DownloadBlueprint.route('/downloads/graphics/<mode>/<protein>/<folder>')
@login_required
def imgsdownload(filename):
filename = filename.split('|')[1]
current_location = os.path.join(Config.UPLOAD_FOLDER, current_user.username, filename, 'graficos')
ziplocation = os.path.join(current_location, filename+'-graficos.zip')
def imgsdownload(mode, protein, folder):
folder_path = os.path.join(Config.UPLOAD_FOLDER, current_user.username, mode, protein, folder)
folder_graphics_path = os.path.join(folder_path, 'graficos')

ziplocation = os.path.join(folder_graphics_path, f"{mode}-{protein}-{folder}-graphics.zip")
zf = zipfile.ZipFile(ziplocation,'w')

#move os arquivos .xvg para a pasta graficos.
directory_xvg = os.path.join(Config.UPLOAD_FOLDER, current_user.username, filename,'run')
directory_xvg = os.path.join(folder_path, 'run')
for folder, subfolders, files in os.walk(directory_xvg):
for file in files:
if file.endswith('.xvg'):
file = directory_xvg +'/'+file
shutil.move(file, current_location)
file = os.path.join(directory_xvg, file)
shutil.move(file, folder_graphics_path)

for folder, subfolders, files in os.walk(current_location):
for folder, subfolders, files in os.walk(folder_graphics_path):
for file in files:
if not file.endswith('.zip'):
zf.write(os.path.join(folder, file), file, compress_type = zipfile.ZIP_DEFLATED)
zf.close()

return send_file(ziplocation, as_attachment=True)

@DownloadBlueprint.route('/downloadmdpfiles')
@DownloadBlueprint.route('/downloads/mdp')
@login_required
def downloadmdpfiles():
ziplocation = os.path.join(Config.MDP_LOCATION_FOLDER, 'mdpfiles.zip')

return send_file(ziplocation, as_attachment=True)

@DownloadBlueprint.route('/dynamiccomandsdownload/<filename>')
@DownloadBlueprint.route('/downloads/commands/<mode>/<protein>/<folder>')
@login_required
def dynamiccomandsdownload(filename):
filename = filename.split('|')[1]
os.chdir(Config.UPLOAD_FOLDER+'/'+current_user.username+'/'+filename)
def dynamiccomandsdownload(mode, protein, folder):
folder_path = os.path.join(Config.UPLOAD_FOLDER, current_user.username, mode, protein, folder)
os.chdir(folder_path)
files = glob.glob("*.txt")
files.sort(key=os.path.getmtime)
file_comands = files[len(files)-1]
directory = Config.UPLOAD_FOLDER+'/'+current_user.username+'/'+filename+'/'+file_comands
return (send_file(directory, as_attachment=True))
commands = files[len(files) - 1]
directory = os.path.join(folder_path, commands)
return send_file(directory, as_attachment=True)

@DownloadBlueprint.route('/download/<filename>')
@DownloadBlueprint.route('/downloads/xtc/<mode>/<protein>/<folder>')
@login_required
def commandsdownload(filename):
filename = ast.literal_eval(filename)
return send_file('{}{}/{}/{}'.format(Config.UPLOAD_FOLDER,
current_user.username,filename["name"],filename["complete"]), as_attachment=True)
def commandsdownload(mode, protein, folder):
folder_path = os.path.join(Config.UPLOAD_FOLDER, current_user.username, mode, protein, folder)
folder_run_path = os.path.join(folder_path, 'run')

ziplocation = os.path.join(folder_run_path, f"{mode}-{protein}-{folder}-xtc.zip")
zf = zipfile.ZipFile(ziplocation, 'w')

#move os arquivos .xvg para a pasta graficos.
for folder, subfolders, files in os.walk(folder_run_path):
for file in files:
if file.endswith('_PBC.xtc'):
zf.write(os.path.join(folder, file), file, compress_type=zipfile.ZIP_DEFLATED)

zf.close()

return send_file(ziplocation, as_attachment=True)

@DownloadBlueprint.route('/downloadlogs/<filename>')
@DownloadBlueprint.route('/downloads/logs/<mode>/<protein>/<folder>')
@login_required
def downloalogs(filename):
filename = filename.split('|')[1]
current_location = os.path.join(Config.UPLOAD_FOLDER, current_user.username, filename,'run','logs')
ziplocation = os.path.join(Config.UPLOAD_FOLDER, current_user.username, filename,'run','logs',filename+'-logs.zip')
def downloalogs(mode, protein, folder):
folder_path = os.path.join(Config.UPLOAD_FOLDER, current_user.username, mode, protein, folder)
log_path = os.path.join(folder_path, 'run', 'logs')
ziplocation = os.path.join(log_path, f"{mode}-{protein}-{folder}-logs.zip")
zf = zipfile.ZipFile(ziplocation,'w')

for folder, subfolders, files in os.walk(current_location):
for folder, subfolders, files in os.walk(log_path):
for file in files:
if not file.endswith('.zip'):
zf.write(os.path.join(folder, file), file, compress_type = zipfile.ZIP_DEFLATED)
if file.endswith('.log'):
zf.write(os.path.join(folder, file), file, compress_type=zipfile.ZIP_DEFLATED)

zf.close()
return (send_file(ziplocation, as_attachment=True))
return send_file(ziplocation, as_attachment=True)
20 changes: 16 additions & 4 deletions app/blueprints/dynamic/executors/acpype.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ def execute(folder, CommandsFileName, username, filename, itpname, groname, mol)
protein_name, _ = os.path.splitext(os.path.basename(filename))
f.write(protein_name)

#

#transferir os arquivos mdp necessarios para a execução
RunFolder = os.path.join(folder, "run") #pasta q vai rodar
SecureMdpFolder = os.path.join(os.path.expanduser('~'),Config.MDP_LOCATION_FOLDER)
Expand All @@ -21,17 +23,21 @@ def execute(folder, CommandsFileName, username, filename, itpname, groname, mol)
shutil.copy(fullmdpname, RunFolder)

# Use the `with` statement to open the file in 'x+' mode
with open(os.path.join(Config.UPLOAD_FOLDER, username, 'info_dynamics'), 'a') as f:
f.write(folder)
with open(os.path.join(Config.UPLOAD_FOLDER, username, 'info_dynamics'), 'a+') as f:
f.write(f"{folder}\n")

with open(os.path.join(Config.UPLOAD_FOLDER, username, "log_dir"), "w") as f:
f.write(os.path.join(folder, "run", "logs", f"gmx-commands.log"))

#abrir arquivo
with open(CommandsFileName) as f: #CODIGO PARA A PRODUÇÃO
content = f.readlines()
lines = [line.rstrip('\n') for line in content if line is not '\n'] #cancela as linhas em branco do arquivo
lines = [line.rstrip('\n') for line in content if line is not '\n']
linux_log_file_path = os.path.join(folder, "run", "logs", f"linux-commands.log")

with open(os.path.join(folder, 'status'), 'w') as f:
f.write(f"running\n")

for l in lines:
if l[0] == '#':
WriteUserDynamics(l, username)
Expand All @@ -40,7 +46,10 @@ def execute(folder, CommandsFileName, username, filename, itpname, groname, mol)
rcode = run_dynamics_command(l, os.path.join(folder, "run", "logs", f"gmx-commands.log"))

if rcode != 0:
with open(os.path.join(folder, 'status'), 'w') as f:
f.write(f"error: {l}\n")
os.remove(os.path.join(Config.UPLOAD_FOLDER, username, 'executing'))
os.remove(os.path.join(Config.UPLOAD_FOLDER, username, 'running_protein_name'))
os.remove(os.path.join(Config.UPLOAD_FOLDER, username, 'log_dir'))
return f"{l}"

Expand Down Expand Up @@ -98,8 +107,11 @@ def execute(folder, CommandsFileName, username, filename, itpname, groname, mol)
with open(os.path.join(folder, "run", "logs", f"dynamic-log.log"), 'a') as f:
subprocess.call(comando_moleculetype, shell=True, stdin=f, stdout=f, stderr=f)


with open(os.path.join(folder, 'status'), 'w') as f:
f.write(f"success\n")

os.remove(os.path.join(Config.UPLOAD_FOLDER, username, 'executing'))
os.remove(os.path.join(Config.UPLOAD_FOLDER, username, 'running_protein_name'))
os.remove(os.path.join(Config.UPLOAD_FOLDER, username, 'log_dir'))


Expand Down
17 changes: 14 additions & 3 deletions app/blueprints/dynamic/executors/apo.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def execute(folder, CommandsFileName, username, filename):
with open(os.path.join(Config.UPLOAD_FOLDER, username, 'running_protein_name'), 'w') as f:
protein_name, _ = os.path.splitext(os.path.basename(filename))
f.write(protein_name)

# transferir os arquivos mdp necessarios para a execução
RunFolder = os.path.join(folder, 'run') # pasta q vai rodar
SecureMdpFolder = os.path.join(os.path.expanduser('~'), Config.MDP_LOCATION_FOLDER)
Expand All @@ -20,8 +20,8 @@ def execute(folder, CommandsFileName, username, filename):
shutil.copy(fullmdpname, RunFolder)

# Use the `with` statement to open the file in 'x+' mode
with open(os.path.join(Config.UPLOAD_FOLDER, username, 'info_dynamics'), 'a') as f:
f.write(folder)
with open(os.path.join(Config.UPLOAD_FOLDER, username, 'info_dynamics'), 'a+') as f:
f.write(f"{folder}\n")

with open(os.path.join(Config.UPLOAD_FOLDER, username, "log_dir"), "w") as f:
f.write(os.path.join(folder, "run", "logs", f"dynamic-log.log"))
Expand All @@ -31,6 +31,9 @@ def execute(folder, CommandsFileName, username, filename):
content = f.readlines()
lines = [line.rstrip('\n') for line in content if line is not '\n'] #cancela as linhas em branco do arquivo

with open(os.path.join(folder, 'status'), 'w') as f:
f.write(f"running\n")

for l in lines:
if l[0] == '#':
WriteUserDynamics(l, username)
Expand All @@ -39,10 +42,18 @@ def execute(folder, CommandsFileName, username, filename):
rcode = run_dynamics_command(l, os.path.join(folder, "run", "logs", f"dynamic-log.log"))

if rcode != 0:
with open(os.path.join(folder, 'status'), 'w') as f:
f.write(f"error: {l}\n")
os.remove(os.path.join(Config.UPLOAD_FOLDER, username, 'executing'))
os.remove(os.path.join(Config.UPLOAD_FOLDER, username, 'running_protein_name'))
os.remove(os.path.join(Config.UPLOAD_FOLDER, username, 'log_dir'))
return f"{l}"

with open(os.path.join(folder, 'status'), 'w') as f:
f.write(f"success\n")

os.remove(os.path.join(Config.UPLOAD_FOLDER, username, 'executing'))
os.remove(os.path.join(Config.UPLOAD_FOLDER, username, 'running_protein_name'))
os.remove(os.path.join(Config.UPLOAD_FOLDER, username, 'log_dir'))

def WriteUserDynamics(line, username):
Expand Down
14 changes: 11 additions & 3 deletions app/blueprints/dynamic/executors/prodrg.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ def execute(folder, CommandsFileName, username, filename, itpname, groname, mol)
protein_name, _ = os.path.splitext(os.path.basename(filename))
f.write(protein_name)


#transferir os arquivos mdp necessarios para a execução
RunFolder = os.path.join(folder, "run") #pasta q vai rodar
SecureMdpFolder = os.path.join(os.path.expanduser('~'),Config.MDP_LOCATION_FOLDER)
Expand All @@ -22,8 +21,8 @@ def execute(folder, CommandsFileName, username, filename, itpname, groname, mol)
shutil.copy(fullmdpname, RunFolder)

# Use the `with` statement to open the file in 'x+' mode
with open(os.path.join(Config.UPLOAD_FOLDER, username, 'info_dynamics'), 'a') as f:
f.write(folder)
with open(os.path.join(Config.UPLOAD_FOLDER, username, 'info_dynamics'), 'a+') as f:
f.write(f"{folder}\n")

with open(os.path.join(Config.UPLOAD_FOLDER, username, "log_dir"), "w") as f:
f.write(os.path.join(folder, "run", "logs", f"gmx-commands.log"))
Expand All @@ -33,6 +32,9 @@ def execute(folder, CommandsFileName, username, filename, itpname, groname, mol)
content = f.readlines()
lines = [line.rstrip('\n') for line in content if line is not '\n'] #cancela as linhas em branco do arquivo

with open(os.path.join(folder, 'status'), 'w') as f:
f.write(f"running\n")

for l in lines:
if l[0] == '#':
WriteUserDynamics(l, username)
Expand All @@ -41,7 +43,10 @@ def execute(folder, CommandsFileName, username, filename, itpname, groname, mol)
rcode = run_dynamics_command(l, os.path.join(folder, "run", "logs", f"gmx-commands.log"))

if rcode != 0:
with open(os.path.join(folder, 'status'), 'w') as f:
f.write(f"error: {l}\n")
os.remove(os.path.join(Config.UPLOAD_FOLDER, username, 'executing'))
os.remove(os.path.join(Config.UPLOAD_FOLDER, username, 'running_protein_name'))
os.remove(os.path.join(Config.UPLOAD_FOLDER, username, 'log_dir'))
return f"{l}"

Expand Down Expand Up @@ -119,7 +124,10 @@ def execute(folder, CommandsFileName, username, filename, itpname, groname, mol)
file_complx_gro[1] = ' {:>5}\n'.format(total)
file.write(''.join(file_complx_gro))

with open(os.path.join(folder, 'status'), 'w') as f:
f.write(f"success\n")
os.remove(os.path.join(Config.UPLOAD_FOLDER, username, 'executing'))
os.remove(os.path.join(Config.UPLOAD_FOLDER, username, 'running_protein_name'))
os.remove(os.path.join(Config.UPLOAD_FOLDER, username, 'log_dir'))


Expand Down
2 changes: 1 addition & 1 deletion app/blueprints/dynamic/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def prodrg():
filename, ext = os.path.splitext(os.path.basename(request.files.get('file').filename))
fileitpname, ext1 = os.path.splitext(os.path.basename(request.files.get('fileitp').filename))
filegroname, ext2 = os.path.splitext(os.path.basename(request.files.get('filegro').filename))
folder = f"{Config.UPLOAD_FOLDER}{current_user.username}/prodrg/{filename}_{fileitpname}_{filegroname}/{timestamp}/"
folder = os.path.join(Config.UPLOAD_FOLDER,current_user.username, 'prodrg', f"{filename}_{fileitpname}_{filegroname}", timestamp)

CompleteFileName = prodrgGenerator.generate(
folder,
Expand Down
39 changes: 29 additions & 10 deletions app/blueprints/user/routes.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,46 @@
import datetime
import dateutil.parser
from app.config import Config
from . import UserBlueprint
from flask import render_template, make_response, request
from flask_babel import _
from flask_login import current_user, login_required
from app import login_manager

from app import login_manager
import os
@UserBlueprint.route('/', methods=['GET'], endpoint='index')
@login_required
def index():
try:
directory = Config.UPLOAD_FOLDER + '/' + current_user.username + '/info_dynamics'
info_dynamics = open(directory, 'r')
list_dynamics = info_dynamics.readlines()
info_dynamics.close()
directory = os.path.join(Config.UPLOAD_FOLDER, current_user.username, 'info_dynamics')
with open(directory, 'r') as f:
list_dynamics = f.readlines()
dynamics = []

for d in list_dynamics:
dsplit = d.strip().split('/')
date = dsplit[len(dsplit) - 1].replace('/', '')
protein = dsplit[len(dsplit) - 2].replace('/', '')
mode = dsplit[len(dsplit) - 3].replace('/', '')

status_path = os.path.join(d.replace('\n', ''), 'status')

print(status_path)
with open(status_path, 'r') as f:
line = f.readline()

print(line)

if 'error' in line:
status = line.replace('error: ', '').replace('\n', '')
else:
status = line.replace('\n', '')

print(status)
obj = {
"date": dateutil.parser.isoparse(d.strip().split("|")[0]),
"protein": d.strip().split("|")[1],
"original": d
"folder": date,
"date": dateutil.parser.isoparse(date),
"protein": protein,
"mode": mode,
"status": status
}
dynamics.insert(0, obj)

Expand Down
4 changes: 4 additions & 0 deletions app/static/css/custom.css
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,8 @@ a {

.order-9 {
order: 9;
}

.-mt-3 {
margin-top: -0.75rem;
}
Loading

0 comments on commit 4943481

Please sign in to comment.