def multi_molecule(request, string): if request.REQUEST.get("random"): amount = int(request.REQUEST.get("random")) string = ','.join(name_expansion(string, rand=amount)) job_form = JobForm.get_form(request, "{{ name }}") mol_form = MoleculeForm(request.REQUEST) job_is_valid = job_form.is_valid(request.method) mol_is_valid = mol_form.is_valid() if job_is_valid and mol_is_valid: return job_form.get_results(request, string, mol_form) elif request.is_ajax(): job_form_html = render_crispy_form( job_form, context=RequestContext(request)) mol_form_html = render_crispy_form( mol_form, context=RequestContext(request)) a = { "success": False, "job_form_html": job_form_html, "mol_form_html": mol_form_html, } return HttpResponse(json.dumps(a), content_type="application/json") c = { "pagename": string, "job_form": job_form, "mol_form": MoleculeForm(), "gjf": "checked", "autoflip": request.REQUEST.get("autoflip"), } return render(request, "chem/multi_molecule.html", c)
def multi_molecule(request, string): if request.REQUEST.get("random"): amount = int(request.REQUEST.get("random")) string = ','.join(name_expansion(string, rand=amount)) job_form = JobForm.get_form(request, "{{ name }}") mol_form = MoleculeForm(request.REQUEST) job_is_valid = job_form.is_valid(request.method) mol_is_valid = mol_form.is_valid() if job_is_valid and mol_is_valid: return job_form.get_results(request, string, mol_form) elif request.is_ajax(): job_form_html = render_crispy_form(job_form, context=RequestContext(request)) mol_form_html = render_crispy_form(mol_form, context=RequestContext(request)) a = { "success": False, "job_form_html": job_form_html, "mol_form_html": mol_form_html, } return HttpResponse(json.dumps(a), content_type="application/json") c = { "pagename": string, "job_form": job_form, "mol_form": MoleculeForm(), "gjf": "checked", "autoflip": request.REQUEST.get("autoflip"), } return render(request, "chem/multi_molecule.html", c)
def molecule_detail(request, molecule): job_form = JobForm.get_form(request, molecule) mol_form = MoleculeForm(request.REQUEST) job_is_valid = job_form.is_valid(request.method) mol_is_valid = mol_form.is_valid() if job_is_valid and mol_is_valid: return job_form.get_results(request, molecule, mol_form) elif request.is_ajax(): job_form_html = render_crispy_form( job_form, context=RequestContext(request)) mol_form_html = render_crispy_form( mol_form, context=RequestContext(request)) a = { "success": False, "job_form_html": job_form_html, "mol_form_html": mol_form_html, } return HttpResponse(json.dumps(a), content_type="application/json") a = get_molecule_info_status(molecule) a["job_form"] = job_form a["mol_form"] = MoleculeForm() return render(request, "chem/molecule_detail.html", a)
def molecule_detail(request, molecule): job_form = JobForm.get_form(request, molecule) mol_form = MoleculeForm(request.REQUEST) job_is_valid = job_form.is_valid(request.method) mol_is_valid = mol_form.is_valid() if job_is_valid and mol_is_valid: return job_form.get_results(request, molecule, mol_form) elif request.is_ajax(): job_form_html = render_crispy_form(job_form, context=RequestContext(request)) mol_form_html = render_crispy_form(mol_form, context=RequestContext(request)) a = { "success": False, "job_form_html": job_form_html, "mol_form_html": mol_form_html, } return HttpResponse(json.dumps(a), content_type="application/json") a = get_molecule_info_status(molecule) a["job_form"] = job_form a["mol_form"] = MoleculeForm() return render(request, "chem/molecule_detail.html", a)
def upload_data(request): switch = { "logparse": parse_log, "longchain": long_chain_limit, "gjfreset": reset_gjf, "structureview": view_structure, } if request.method == "POST": upload_form = UploadForm(request.POST or None, files=request.FILES) if upload_form.is_valid(): return switch[request.POST["options"]](request, upload_form) else: upload_form = UploadForm() c = { "upload_form": upload_form, "job_form": JobForm.get_form(request, "{{ name }}", initial=True), } return render(request, "chem/upload_log.html", c)
def upload_data(request): switch = { "logparse": parse_log, "longchain": long_chain_limit, "gjfreset": reset_gjf, "structureview": view_structure, "percent": get_percent, } if request.method == "POST": upload_form = UploadForm(request.POST or None, files=request.FILES) if upload_form.is_valid(): return switch[request.POST["options"]](request, upload_form) else: upload_form = UploadForm() c = { "upload_form": upload_form, "job_form": JobForm.get_form(request, "{{ name }}", initial=True), } return render(request, "chem/upload_log.html", c)
def multi_job(request): form = JobForm.get_form(request, "{{ name }}") c = { "form": form, } if not form.is_valid(request.method): if request.is_ajax(): job_form_html = render_crispy_form( form, context=RequestContext(request)) a = { "success": False, "job_form_html": job_form_html, "mol_form_html": '', } return HttpResponse(json.dumps(a), content_type="application/json") return render(request, "chem/multi_job.html", c) d = dict(form.cleaned_data) if request.method == "POST": cred = d.pop("credential") files = request.FILES.getlist("files") strings = [''.join(f.readlines()) for f in files] names = [os.path.splitext(f.name)[0] for f in files] a = cluster.interface.run_jobs(cred, names, strings, **d) do_html = request.REQUEST.get("html", False) if do_html: html = render_to_string("chem/multi_submit.html", a) temp = {"success": True, "html": html} return HttpResponse(json.dumps(temp), content_type="application/json") else: return HttpResponse(json.dumps(a), content_type="application/json") string = request.REQUEST.get('filenames', '').replace('\r\n', ',').replace('\n', ',') ret_zip = get_multi_job(string, form) response = HttpResponse(ret_zip, content_type="application/zip") response["Content-Disposition"] = "attachment; filename=output.zip" return response
def multi_molecule_zip(request, string): try: autoflip = request.REQUEST.get("autoflip") molecules, warnings, errors, news = get_multi_molecule_status( string, autoflip=autoflip) except ValueError as e: logger.warn(str(e)) c = { "error": str(e) } return render(request, "chem/multi_molecule.html", c) mol_form = MoleculeForm(request.REQUEST) mol_form.is_valid() if request.REQUEST.get("job"): job_form = JobForm.get_form(request, "{{ name }}") if not job_form.is_valid(): f = lambda x: 'checked' if request.REQUEST.get(x) else '' c = { "pagename": string, "job_form": job_form, "mol_form": mol_form, "gjf": f("gjf"), "mol2": f("mol2"), "image": f("image"), "job": f("job"), } return render(request, "chem/multi_molecule.html", c) else: job_form = None selection = ("image", "mol2", "job", "gjf") options = [x for x in selection if request.REQUEST.get(x)] if request.REQUEST.get("new", ''): molecules = [x for i, x in enumerate(molecules) if news[i]] ret_zip = get_multi_molecule(molecules, options, mol_form, job_form) response = HttpResponse(ret_zip, content_type="application/zip") response["Content-Disposition"] = "attachment; filename=molecules.zip" return response
def multi_job(request): form = JobForm.get_form(request, "{{ name }}") c = { "form": form, } if not form.is_valid(request.method): if request.is_ajax(): job_form_html = render_crispy_form(form, context=RequestContext(request)) a = { "success": False, "job_form_html": job_form_html, "mol_form_html": '', } return HttpResponse(json.dumps(a), content_type="application/json") return render(request, "chem/multi_job.html", c) d = dict(form.cleaned_data) if request.method == "POST": cred = d.pop("credential") files = request.FILES.getlist("files") strings = [''.join(f.readlines()) for f in files] names = [os.path.splitext(f.name)[0] for f in files] a = cluster.interface.run_jobs(cred, names, strings, **d) do_html = request.REQUEST.get("html", False) if do_html: html = render_to_string("chem/multi_submit.html", a) temp = {"success": True, "html": html} return HttpResponse(json.dumps(temp), content_type="application/json") else: return HttpResponse(json.dumps(a), content_type="application/json") string = request.REQUEST.get('filenames', '').replace('\r\n', ',').replace('\n', ',') ret_zip = get_multi_job(string, form) response = HttpResponse(ret_zip, content_type="application/zip") response["Content-Disposition"] = "attachment; filename=output.zip" return response
def multi_molecule_zip(request, string): try: autoflip = request.REQUEST.get("autoflip") molecules, warnings, errors, news = get_multi_molecule_status( string, autoflip=autoflip) except ValueError as e: logger.warn(str(e)) c = {"error": str(e)} return render(request, "chem/multi_molecule.html", c) mol_form = MoleculeForm(request.REQUEST) mol_form.is_valid() if request.REQUEST.get("job"): job_form = JobForm.get_form(request, "{{ name }}") if not job_form.is_valid(): f = lambda x: 'checked' if request.REQUEST.get(x) else '' c = { "pagename": string, "job_form": job_form, "mol_form": mol_form, "gjf": f("gjf"), "mol2": f("mol2"), "image": f("image"), "job": f("job"), } return render(request, "chem/multi_molecule.html", c) else: job_form = None selection = ("image", "mol2", "job", "gjf") options = [x for x in selection if request.REQUEST.get(x)] if request.REQUEST.get("new", ''): molecules = [x for i, x in enumerate(molecules) if news[i]] ret_zip = get_multi_molecule(molecules, options, mol_form, job_form) response = HttpResponse(ret_zip, content_type="application/zip") response["Content-Disposition"] = "attachment; filename=molecules.zip" return response
def reset_gjf(request, upload_form): job_form = JobForm.get_form(request, "{{ name }}") errors = [] strings = [] names = [] for f in upload_form.cleaned_data["files"]: try: parser = fileparser.Log(f) name, _ = os.path.splitext(f.name) td = False if request.REQUEST.get("td_reset"): name += '_TD' td = True strings.append(parser.format_gjf(td=td)) names.append(name) except Exception as e: logger.warn("There was an error when trying to reset a gjf: '%s'" % str(e)) errors.append((f.name, e)) if request.REQUEST.get("gjf_submit"): if not job_form.is_valid(request.method): if request.is_ajax(): upload_form_html = render_crispy_form(upload_form, context=RequestContext(request)) job_form_html = render_crispy_form(job_form, context=RequestContext(request)) a = { "success": False, "job_form_html": job_form_html, "upload_form_html": upload_form_html, } return HttpResponse(json.dumps(a), content_type="application/json") c = { "job_form": job_form, "upload_form": upload_form, } return render(request, "chem/upload_log.html", c) d = dict(job_form.cleaned_data) cred = d.pop("credential") a = cluster.interface.run_jobs(cred, names, strings, **d) a["failed"].extend(errors) do_html = request.REQUEST.get("html", False) if do_html: html = render_to_string("chem/multi_submit.html", a) temp = {"success": True, "html": html} return HttpResponse(json.dumps(temp), content_type="application/json") else: return HttpResponse(json.dumps(a), content_type="application/json") buff = StringIO() zfile = zipfile.ZipFile(buff, 'w', zipfile.ZIP_DEFLATED) for name, string in zip(names, strings): zfile.writestr("%s.gjf" % name, string) if errors: temp = ['%s - %s' % (name, error) for (name, error) in errors] zfile.writestr("errors.txt", '\n'.join(temp)) zfile.close() buff.flush() ret_zip = buff.getvalue() buff.close() response = HttpResponse(ret_zip, content_type="application/zip") response["Content-Disposition"] = "attachment; filename=output.zip" return response
def reset_gjf(request, upload_form): job_form = JobForm.get_form(request, "{{ name }}") errors = [] strings = [] names = [] for f in upload_form.cleaned_data["files"]: try: parser = fileparser.Log(f) name, _ = os.path.splitext(f.name) td = False if request.REQUEST.get("td_reset"): name += '_TD' td = True strings.append(parser.format_gjf(td=td)) names.append(name) except Exception as e: logger.warn("There was an error when trying to reset a gjf: '%s'" % str(e)) errors.append((f.name, e)) if request.REQUEST.get("gjf_submit"): if not job_form.is_valid(request.method): if request.is_ajax(): upload_form_html = render_crispy_form( upload_form, context=RequestContext(request)) job_form_html = render_crispy_form( job_form, context=RequestContext(request)) a = { "success": False, "job_form_html": job_form_html, "upload_form_html": upload_form_html, } return HttpResponse(json.dumps(a), content_type="application/json") c = { "job_form": job_form, "upload_form": upload_form, } return render(request, "chem/upload_log.html", c) d = dict(job_form.cleaned_data) cred = d.pop("credential") a = cluster.interface.run_jobs(cred, names, strings, **d) a["failed"].extend(errors) do_html = request.REQUEST.get("html", False) if do_html: html = render_to_string("chem/multi_submit.html", a) temp = {"success": True, "html": html} return HttpResponse(json.dumps(temp), content_type="application/json") else: return HttpResponse(json.dumps(a), content_type="application/json") buff = StringIO() zfile = zipfile.ZipFile(buff, 'w', zipfile.ZIP_DEFLATED) for name, string in zip(names, strings): zfile.writestr("%s.gjf" % name, string) if errors: temp = ['%s - %s' % (name, error) for (name, error) in errors] zfile.writestr("errors.txt", '\n'.join(temp)) zfile.close() buff.flush() ret_zip = buff.getvalue() buff.close() response = HttpResponse(ret_zip, content_type="application/zip") response["Content-Disposition"] = "attachment; filename=output.zip" return response