Exemple #1
0
def _getMoleculeByMoleculeCode(db, molecule_code):
    molecules = [x for x in db.retrieveAll()]

    for m in molecules:
        molecule_code_infoset = m.getInfosets(infoset_type=InfosetType.getMoleculeCodeType())
        if len(molecule_code_infoset) != 1:
            continue
        if molecule_code_infoset[0].value(None) == molecule_code:
            return m
   
    return None
Exemple #2
0
def browsemol(request, dbname, mol_code):
    try:
        db = DBAccess.DBAccess(os.path.join(settings.DB_PATH, dbname))
    except:
        raise Http404
   
    mol = _getMoleculeByMoleculeCode(db, mol_code)
    if mol is None:
        raise Http404
    
    infosets = mol.getInfosets()

    _createXYZFile(mol)

    render_data = { "dbname" : dbname, 
                    "molname" : str(mol.uuid()), 
                    "uuid" : str(mol.uuid())
                    }
    render_data["molecule"] = {}
    render_data["grrm"] = {}
    render_data["unrecognized"] = []

    for i in infosets:
        if i.type() == InfosetType.getMoleculeCodeType():
            render_data["molecule"]["MoleculeCode"] = i.value(None)
        elif i.typeURI() == InfosetTypeURI.INFOSET_TYPE_URI_BASE+"StructureType":
            render_data["grrm"]["StructureType"] = i.value(None)
        elif i.typeURI() == InfosetTypeURI.INFOSET_TYPE_URI_BASE+"Spin":
            render_data["grrm"]["Spin"] = i.value(None)
        elif i.typeURI() == InfosetTypeURI.INFOSET_TYPE_URI_BASE+"HFEnergy":
            render_data["grrm"]["HFEnergy"] = i.value(None)
        elif i.typeURI() == InfosetTypeURI.INFOSET_TYPE_URI_BASE+"ZeroPointVibrationalEnergy":
            render_data["grrm"]["ZeroPointVibrationalEnergy"] = i.value(None)
        elif i.typeURI() == InfosetTypeURI.INFOSET_TYPE_URI_BASE+"NormalModesEigenvalues":
            render_data["grrm"]["NormalModesEigenvalues"] = i.value(None)
        elif i.typeURI() == InfosetTypeURI.INFOSET_TYPE_URI_BASE+"ReactionConnectivityMarker":
            render_data["grrm"]["ReactionConnectivityMarker"] = i.value(None)
        elif i.typeURI() == InfosetTypeURI.INFOSET_TYPE_URI_BASE+"ReactionConnectivityCodes":
            render_data["grrm"]["ReactionConnectivityCodes"] = i.value(None)
            render_data["grrm"]["first_code"] = i.value(None)[0]
            render_data["grrm"]["second_code"] = i.value(None)[1]
        else:
            render_data["unrecognized"].append( ( i.typeURI(), i.dimensionality()))
    

    return render_to_response("application/browsemol.html", render_data )
def browsedb(request,dbname):
    try:
        db = DBAccess.DBAccess(os.path.join(settings.DB_PATH, dbname))
    except:
        raise Http404

    molecule_list = []

    all = db.retrieveAll()
    molecule_list = []
    for graph in all:
        molecule={}
        code = graph.getInfosets(infoset_type=InfosetType.getMoleculeCodeType())
        if len(code) == 0:
            continue 
        else:
            molecule["code"] = code[0].value(graph)

        name = graph.getInfosets(infoset_type=InfosetType.getConventionalMoleculeNameType())
        if len(name) == 0:
            molecule["name"] = molecule["code"]
        else:
            molecule["name"] = name[0].value(graph)

        elements = graph.getInfosets(infoset_type=InfosetType.getElementType())
        if len(elements) == 0:
            continue
        else:
            molecule["num_of_atoms"] = elements[0].size()
            molecule["brute_formula"] = Utilities.hillFormula(map(lambda x: x[1], elements[0].allValues()))
        
        hf_energy = graph.getInfosets(infoset_type=InfosetType.getHFEnergyType())
        if len(hf_energy) == 0:
            continue
        else:
            molecule["hf_energy"] = hf_energy[0].value(graph)
            

        #molecule["uuid"] = graph.uuid()
        molecule_list.append(molecule)

    database = { "name": dbname }
    
    return render_to_response("application/browsedb.html", { "database" : database, "molecule_list" : molecule_list })
def browsemol(request, dbname, mol_code):
    try:
        db = DBAccess.DBAccess(os.path.join(settings.DB_PATH, dbname))
    except:
        raise Http404

    molecules = [x for x in db.retrieveAll()]

    mol = None
    for m in molecules:
        molecule_code_infoset = m.getInfosets(
            infoset_type=InfosetType.getMoleculeCodeType())
        if len(molecule_code_infoset) != 1:
            continue
        if molecule_code_infoset[0].value(None) == mol_code:
            mol = m
            break

    if mol is None:
        raise Http404

    infosets = mol.getInfosets()

    _createXYZFile(mol)
    infosets_data = []
    graph_infosets_data = []
    angle_data = []
    for i in infosets:
        if i.dimensionality() == 0:
            graph_infosets_data.append((i.uuid(), i.value(None), i.typeURI()))
        else:
            infosets_data.append(
                (i.uuid(), i.dimensionality(), i.typeURI(), i.size()))
    return render_to_response(
        "application/browsemol.html", {
            "dbname": dbname,
            "molname": str(mol.uuid()),
            "uuid": str(mol.uuid()),
            "graph_infosets_data": graph_infosets_data,
            "infosets_data": infosets_data,
            "angle_data": angle_data
        })
Exemple #5
0
def searchdb(request):
    if request.method == "POST" and request.POST:
        db_name = request.POST["db_name"]
        page = int(request.POST['page'])
        rows_per_page = int(request.POST['rp'])
        sortname = request.POST['sortname']
        sortorder = request.POST['sortorder']
    else:
        raise Http404

    try:
        db = DBAccess.DBAccess(os.path.join(settings.DB_PATH, db_name))
    except:
        raise Http404

    all = db.retrieveAll()

    json_response = {"page": page, "total": len(all), "rows": []}
    rows = []
    for id, graph in enumerate(all):
        molecule = {}

        code = graph.getInfosets(
            infoset_type=InfosetType.getMoleculeCodeType())
        if len(code) == 0:
            continue
        else:
            # FIXME possible danger of injection of db_name by the user
            molecule["code"] = "<a href=\"/browsedb/" + db_name + "/" + code[
                0].value(graph) + "\">" + code[0].value(graph) + "</a>"

        name = graph.getInfosets(
            infoset_type=InfosetType.getConventionalMoleculeNameType())
        if len(name) == 0:
            molecule["name"] = molecule["code"]
        else:
            molecule["name"] = name[0].value(graph)

        elements = graph.getInfosets(infoset_type=InfosetType.getElementType())
        if len(elements) == 0:
            continue
        else:
            molecule["num_of_atoms"] = elements[0].size()
            molecule["brute_formula"] = Utilities.hillFormula(
                map(lambda x: x[1], elements[0].allValues()))

        hf_energy = graph.getInfosets(
            infoset_type=InfosetType.getHFEnergyType())
        if len(hf_energy) == 0:
            molecule["hf_energy"] = ""
        else:
            molecule["hf_energy"] = hf_energy[0].value(graph).value()

        row = {}
        row["id"] = molecule["code"]
        row["cell"] = [
            molecule["code"], molecule["name"], molecule["brute_formula"],
            molecule["num_of_atoms"], molecule["hf_energy"], ""
        ]
        rows.append(row)

    json_response["rows"].extend(
        sortAndTrim(rows, page, rows_per_page, sortname, sortorder))

    json_response = {
        "total":
        3,
        "page":
        1,
        "rows": [{
            "cell": ["foo", "bar"]
        }, {
            "cell": ["foo", "bar"]
        }, {
            "cell": ["foo", "bar"]
        }]
    }

    return HttpResponse(simplejson.dumps(json_response),
                        mimetype='application/javascript')