Пример #1
0
    def __init__(self, atom_list): # fold>>
        self._graph = Graph.Graph()
        self._elements = Infoset.Infoset(self._graph, InfosetType.getElementType())
        self._coords = Infoset.Infoset(self._graph, InfosetType.getCoordsType())

        for atom in atom_list:
            entity = self._graph.createEntity()
            self._elements.setValue(entity, atom[0])
            self._coords.setValue(entity, atom[1])
Пример #2
0
 def moleculeCode(self): # fold>>
     element_part = []
     element_infoset = self._graph.getInfosets(infoset_type=InfosetType.getElementType())[0]
     coords_infoset = self._graph.getInfosets(infoset_type=InfosetType.getCoordsType())[0]
     element_part= sorted([y.atomicNumber() for x,y in element_infoset.allValues() ])
 
     geometry_part = []
     for node_id, element in element_infoset.allValues():
         coordinate = coords_infoset.value(node_id).asUnit(Units.bohr).value()
         geometry_part.append("%d %15.10f %15.10f %15.10f" % (element.atomicNumber(), coordinate[0], coordinate[1], coordinate[2]))
 
     return "AA-"+_encode("\n".join([ str(x) for x in element_part]))+"-"+_encode("\n".join(geometry_part))
Пример #3
0
def fromGraph(graph):
    elements = graph.getInfosets(infoset_type=InfosetType.getElementType())
    coords = graph.getInfosets(infoset_type=InfosetType.getCoordsType())

    if len(elements) == 0 or len(coords) == 0:
        return None

    atom_list = []

    for id, value in elements[0].allValues():
        atom_list.append( (elements[0].value(id), coords[0].value(id)))
    
    return XYZMolecule(atom_list)
Пример #4
0
def _createXYZFile(mol):
    cache_dir = os.path.join(os.path.dirname(__file__),"..","..","cache","jmol")

    uuid = mol.uuid()
    element = mol.getInfosets(infoset_type=InfosetType.getElementType())[0]
    coords = mol.getInfosets(infoset_type=InfosetType.getCoordsType())[0]

    f = file(os.path.join(cache_dir,str(uuid)+".xyz"), "w")
    num_atoms = len(element.allValues())
    f.write(str(num_atoms)+"\n\n")
    for node, element in element.allValues():
        coordinates = coords.value(node).asUnit(Units.angstrom).value()
        f.write( "%s  %16.10f %16.10f %16.10f\n" % (element.symbol(), coordinates[0], coordinates[1], coordinates[2]) )

    f.close()
    def testFromGraph(self):
        g = Graph.Graph()
        elements = Infoset.Infoset(g, InfosetType.getElementType())
        coords = Infoset.Infoset(g, InfosetType.getCoordsType())

        e = g.createEntity()
        elements.setValue(e, PeriodicTable.C)
        coords.setValue(e,Measure.Measure( ( 0.0000000000,8.5886187987,0.1625164475  ), Units.bohr))
        e = g.createEntity()
        elements.setValue(e, PeriodicTable.C)
        coords.setValue(e,Measure.Measure( ( 0.0000000000,8.5886187987,0.1625164475  ), Units.bohr))

        mol = XYZMolecule.fromGraph(g)

        self.assertEqual(mol.__class__, XYZMolecule.XYZMolecule)
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 })
Пример #7
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')