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 get_multi_molecule_status(string, autoflip=False): unique_molecules = collections.OrderedDict() start = time.time() for name in name_expansion(string): if time.time() - start > 1: logger.warn("%s -- The operation timed out" % (string)) raise ValueError("The operation has timed out.") mol, name_error, error_report, new = get_molecule_status(name, autoflip=autoflip) exact_spacer = mol.get_exact_name(spacers=True) if not exact_spacer: exact_spacer = name if exact_spacer not in unique_molecules: unique_molecules[exact_spacer] = [mol.name, error_report, name_error, new] return zip(*unique_molecules.values())
def get_multi_molecule_status(string, autoflip=False): unique_molecules = collections.OrderedDict() start = time.time() for name in name_expansion(string): if time.time() - start > 1: logger.warn("%s -- The operation timed out" % (string)) raise ValueError("The operation has timed out.") mol, name_error, error_report, new = get_molecule_status( name, autoflip=autoflip) exact_spacer = mol.get_exact_name(spacers=True) if not exact_spacer: exact_spacer = name if exact_spacer not in unique_molecules: unique_molecules[exact_spacer] = [ mol.name, error_report, name_error, new ] return zip(*unique_molecules.values())
def run_standard_jobs(credential, string, mol_settings, job_settings): results = { "worked": [], "failed": [], "error": None, } # This is to catch invalid users early on try: results["cluster"] = credential.cluster.name if not credential.user.is_staff: results["error"] = "You must be a staff user to submit a job." return results except Exception as e: results["error"] = "Invalid credential" results["cluster"] = None return results names = [] gjfs = [] for mol in name_expansion(string): try: out = gjfwriter.NamedMolecule(mol, **mol_settings) # This instantiation needs to be done here because of the errors # in a structure are calculated lazily. gjf = out.get_gjf() names.append(mol) gjfs.append(gjf) except Exception as e: logger.warn("Failed gjf write -- %s -- %s" % (mol, e)) results["failed"].append((mol, str(e))) continue if names: settings = { k: v for k, v in job_settings.items() + mol_settings.items() } temp = run_jobs(credential, names, gjfs, **settings) results["worked"] = temp["worked"] results["failed"].extend(temp["failed"]) results["error"] = temp["error"] return results
def run_standard_jobs(credential, string, mol_settings, job_settings): results = { "worked": [], "failed": [], "error": None, } # This is to catch invalid users early on try: results["cluster"] = credential.cluster.name if not credential.user.is_staff: results["error"] = "You must be a staff user to submit a job." return results except Exception as e: results["error"] = "Invalid credential" results["cluster"] = None return results names = [] gjfs = [] for mol in name_expansion(string): try: out = gjfwriter.NamedMolecule(mol, **mol_settings) # This instantiation needs to be done here because of the errors # in a structure are calculated lazily. gjf = out.get_gjf() names.append(mol) gjfs.append(gjf) except Exception as e: logger.warn("Failed gjf write -- %s -- %s" % (mol, e)) results["failed"].append((mol, str(e))) continue if names: settings = { k: v for k, v in job_settings.items() + mol_settings.items()} temp = run_jobs(credential, names, gjfs, **settings) results["worked"] = temp["worked"] results["failed"].extend(temp["failed"]) results["error"] = temp["error"] return results