def get_molecule_status(name, autoflip=False): mol = gjfwriter.NamedMolecule(name, autoflip=autoflip) name_error = mol.get_name_error() error_report = ErrorReport.objects.filter(molecule=name).exists() or None new = not DataPoint.objects.filter( exact_name=mol.get_exact_name()).exists() return mol, name_error, error_report, new
def write_svg(request, molecule): mol_form = MoleculeForm(request.REQUEST) mol_form.is_valid() mol_settings = dict(mol_form.cleaned_data) out = gjfwriter.NamedMolecule(molecule, **mol_settings) response = HttpResponse(out.get_svg(), content_type="image/svg+xml") response['Content-Disposition'] = 'filename=%s.svg' % molecule return response
def save_names(names): for name in names: struct = gjfwriter.NamedMolecule( name, keywords="opt B3LYP/6-31g(d,p)", nprocshared=12, memory=30, ) with open(name + ".gjf", 'w') as f: f.write(struct.get_gjf())
def write_mol2(request, molecule): mol_form = MoleculeForm(request.REQUEST) mol_form.is_valid() add = "" if request.REQUEST.get("view") else "attachment; " mol_settings = dict(mol_form.cleaned_data) out = gjfwriter.NamedMolecule(molecule, **mol_settings) response = HttpResponse(out.get_mol2(), content_type="text/plain") response['Content-Disposition'] = add + 'filename=%s.mol2' % molecule return response
def run_name(name): from chemtools import gjfwriter mol = gjfwriter.NamedMolecule(name).structure links, tree = breadth_first_search(mol) cycles, link_nodes = get_cycles(links, tree) pruned_cycles = prune_cycles(cycles, link_nodes) fused = get_fused_cycles(pruned_cycles) sorted_cycles = sort_fused_cycles(fused) temp = identify_cycle_types(mol, sorted_cycles) noncycles = get_noncycles(mol, pruned_cycles) pruned_noncycles = prune_noncycles(noncycles) temp2 = identify_noncycle_types(pruned_noncycles) return set(temp + temp2)
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 wrapper(request, molecule, *args, **kwargs): if request.REQUEST.get("autoflip"): mol = gjfwriter.NamedMolecule(molecule, autoflip=True) return redirect(wrapper, mol.name) return f(request, molecule, *args, **kwargs)