Ejemplo n.º 1
0
def _run_job(ssh, sftp, gjfstring, jobstring=None, **kwargs):
    try:
        error = _make_folders(ssh)
        if error:
            return None, "folder - " + error

        name = kwargs.get("name", "chemtoolsjob")
        gjfname = "chemtools/%s.gjf" % name
        jobname = "chemtools/%s.job" % name

        f = sftp.open(gjfname, 'w')
        f.write(gjfstring)
        f.close()

        if jobstring is None:
            jobstring = JobTemplate.render(internal=True, **kwargs)
        f2 = sftp.open(jobname, 'w')
        f2.write(jobstring)
        f2.close()

        # TODO: Make this safer, this should fail before
        # TODO: Make test for failing before
        s = "cd chemtools; qsub %s.job" % name
        _, stdout, stderr = ssh.exec_command(s)
        stderr = stderr.readlines()
        if stderr:
            return None, "qsub - " + stderr[0]

        jobid = stdout.readlines()[0].split(".")[0]
    except Exception as e:
        logger.warn("Could not run the job: %s" % e)
        return None, str(e)
    return jobid, None
Ejemplo n.º 2
0
 def get_results(self, request, string, mol_form):
     job_settings = dict(self.cleaned_data)
     mol_settings = dict(mol_form.cleaned_data)
     if request.method == "GET":
         if request.REQUEST.get('molname'):
             job_settings['name'] = request.REQUEST.get('molname')
         job_string = JobTemplate.render(**job_settings)
         response = HttpResponse(job_string, content_type="text/plain")
         filename = '%s.job' % job_settings['name']
         add = "" if request.REQUEST.get("view") else "attachment; "
         response['Content-Disposition'] = add + 'filename=' + filename
         return response
     elif request.method == "POST":
         cred = job_settings.pop("credential")
         do_html = request.REQUEST.get("html", False)
         results = run_standard_jobs(
             cred, string, mol_settings, job_settings)
         if results["failed"]:
             failed_names = zip(*results['failed'])[0]
             results["failed_mols"] = ','.join(failed_names)
         if do_html:
             html = render_to_string("chem/multi_submit.html", results)
             temp = {"success": True, "html": html}
             return HttpResponse(json.dumps(temp),
                                 content_type="application/json")
         else:
             return HttpResponse(json.dumps(results),
                                 content_type="application/json")
Ejemplo n.º 3
0
 def get_results(self, request, string, mol_form):
     job_settings = dict(self.cleaned_data)
     mol_settings = dict(mol_form.cleaned_data)
     if request.method == "GET":
         if request.REQUEST.get('molname'):
             job_settings['name'] = request.REQUEST.get('molname')
         job_string = JobTemplate.render(**job_settings)
         response = HttpResponse(job_string, content_type="text/plain")
         filename = '%s.job' % job_settings['name']
         add = "" if request.REQUEST.get("view") else "attachment; "
         response['Content-Disposition'] = add + 'filename=' + filename
         return response
     elif request.method == "POST":
         cred = job_settings.pop("credential")
         do_html = request.REQUEST.get("html", False)
         results = run_standard_jobs(cred, string, mol_settings,
                                     job_settings)
         if results["failed"]:
             failed_names = zip(*results['failed'])[0]
             results["failed_mols"] = ','.join(failed_names)
         if do_html:
             html = render_to_string("chem/multi_submit.html", results)
             temp = {"success": True, "html": html}
             return HttpResponse(json.dumps(temp),
                                 content_type="application/json")
         else:
             return HttpResponse(json.dumps(results),
                                 content_type="application/json")
Ejemplo n.º 4
0
def get_multi_job(string, form):
    buff = StringIO()
    zfile = zipfile.ZipFile(buff, 'w', zipfile.ZIP_DEFLATED)

    for name in mol_name.name_expansion(string):
        if not name:
            continue
        name, _ = os.path.splitext(name)
        dnew = form.get_single_data(name)
        zfile.writestr("%s.job" % dnew["name"], JobTemplate.render(**dnew))

    zfile.close()
    buff.flush()

    ret_zip = buff.getvalue()
    buff.close()
    return ret_zip
Ejemplo n.º 5
0
def template_settings(request, username):
    state = "Change Settings"

    if request.method == "POST":
        if "delete" in request.POST:
            i = 0
            for i, template in enumerate(get_templates_from_request(request)):
                template.delete()
            logger.info("%s deleted %d template(s)" % (username, i + 1))
            state = "Settings Successfully Saved"
            form = JobTemplateForm(request.user)

        elif "save" in request.POST:
            form = JobTemplateForm(request.user, request.POST)
            if form.is_valid():
                try:
                    name = form.cleaned_data.get("name")
                    obj = JobTemplate.objects.get(creator=request.user,
                                                  name=name)
                    obj.template.delete(False)
                    obj.template = form.cleaned_data.get("template")
                    obj.save()

                except JobTemplate.DoesNotExist:
                    obj = form.save(commit=False)
                    obj.creator = request.user
                    obj.save()
                state = "Settings Successfully Saved"
                form = JobTemplateForm(request.user)
        else:
            form = JobTemplateForm(request.user)

    else:
        form = JobTemplateForm(request.user)

    c = {
        "pages": PAGES,
        "page": "templates",
        "state": state,
        "form": form,
        "templates": JobTemplate.get_templates(request.user),
    }
    return render(request, "data/template_settings.html", c)
Ejemplo n.º 6
0
def get_multi_molecule(molecules, options, mol_form, job_form):
    buff = StringIO()
    zfile = zipfile.ZipFile(buff, "w", zipfile.ZIP_DEFLATED)
    mol_settings = dict(mol_form.cleaned_data)

    generrors = []
    for name in molecules:
        try:
            dnew = job_form.get_single_data(name)
            mol_name = dnew['name']
        except AttributeError:
            mol_name = name

        try:
            out = gjfwriter.NamedMolecule(name, **mol_settings)
            others = False

            if "image" in options:
                zfile.writestr(mol_name + ".png", out.get_png(10))
                others = True
            if "mol2" in options:
                zfile.writestr(mol_name + ".mol2", out.get_mol2())
                others = True
            if "job" in options:
                zfile.writestr(mol_name + ".job", JobTemplate.render(**dnew))
                others = True

            if "gjf" in options or not others:
                zfile.writestr(mol_name + ".gjf", out.get_gjf())

        except Exception as e:
            logger.warn("Multigen error: %s - %s" % (name, e))
            generrors.append("%s - %s" % (name, e))
    if generrors:
        zfile.writestr("errors.txt", '\n'.join(generrors))

    zfile.close()
    buff.flush()

    ret_zip = buff.getvalue()
    buff.close()
    return ret_zip
Ejemplo n.º 7
0
def template_settings(request, username):
    state = "Change Settings"

    if request.method == "POST":
        if "delete" in request.POST:
            i = 0
            for i, template in enumerate(get_templates_from_request(request)):
                template.delete()
            logger.info("%s deleted %d template(s)" % (username, i+1))
            state = "Settings Successfully Saved"
            form = JobTemplateForm(request.user)

        elif "save" in request.POST:
            form = JobTemplateForm(request.user, request.POST)
            if form.is_valid():
                try:
                    name = form.cleaned_data.get("name")
                    obj = JobTemplate.objects.get(creator=request.user, name=name)
                    obj.template.delete(False)
                    obj.template = form.cleaned_data.get("template")
                    obj.save()

                except JobTemplate.DoesNotExist:
                    obj = form.save(commit=False)
                    obj.creator = request.user
                    obj.save()
                state = "Settings Successfully Saved"
                form = JobTemplateForm(request.user)
        else:
            form = JobTemplateForm(request.user)

    else:
        form = JobTemplateForm(request.user)

    c = {
        "pages": PAGES,
        "page": "templates",
        "state": state,
        "form": form,
        "templates": JobTemplate.get_templates(request.user),
    }
    return render(request, "data/template_settings.html", c)