def _getInterconversionEnergy(self, request, uri, interconversion_uuid):
        graph = graphstore.graph()
        try:
            route = grrm2.Interconversion.get(
                graph, utils.uuidToUri(interconversion_uuid))
        except:
            raise http.Http404

        output = {}

        start = grrm2.interconversionStart(route).get()[0]
        end = grrm2.interconversionEnd(route).get()[0]

        energies = {}
        for step in grrm2.interconversionStep(route).getAll():
            step = step[0]
            energies[grrm2.stepNumber(step).get()] = grrm2.energy(step).get()

        energies[0] = grrm2.energy(start).get()
        energies[max(energies.keys()) + 1] = grrm2.energy(end).get()

        output["energies"] = energies

        return http.HttpResponse(simplejson.dumps(output),
                                 mimetype='application/javascript')
    def dispatch(self, request, **args):
        graph = graphstore.graph()
        try:
            run = grrm2.Run.get(graph, args["uri"])
        except:
            return None

        return { "resource_uuid" : utils.uriToUuid(run.uri())}
    def _getTableData(self,request,uri):
        try:
            uris = request.GET.getlist("uris")
#            page = int(request.POST['page'])
#            rows_per_page = int(request.POST['rp'])
#            sortname = request.POST['sortname']
#            sortorder = request.POST['sortorder']
        except:
            return http.HttpResponseBadRequest()
       
        json_response = {}
        json_response["rows"] = []
        for uri in uris:
            resclass = ordfm.classByUri(graphstore.graph(),uri)
            resource = resclass.get(graphstore.graph(),uri)
            storage = filestorage.ResourceStorage(resource, web_accessible=True, settings=settings.filestorage_settings)
            iconstorage = filestorage.ResourceIcon(resource, settings=settings.filestorage_settings)

            row = {}
            row["icon"] = iconstorage.url(filestorage.ResourceIcon.STATIC)
            row["animatedicon"] = iconstorage.url(filestorage.ResourceIcon.ANIMATED)
            row["uri"] = uri
            row["url"] = utils.resourceUrl(resource)
            row["type"] = resclass.visibleName()
            json_response["rows"].append(row)


#        if page < 0:
#            return http.HttpResponseBadRequest("Invalid page number")
#
#        graph = graphstore.graph()
#        c = ordfm.Collection.get(graph, uri)
#
#        json_response = { "page": page, 
#                          "total": len(c.contents()), 
#                          "rows" : []
#                        }
#
#        for m_uri in c.contents().values()[(page-1)*rows_per_page:(page-1)*rows_per_page+rows_per_page]:
#            m = ordfm.Molecule.get(graph, m_uri)
#            json_response["rows"].append( { "cell" : [ "<span style=\"font-family: Courier\"><a href=\"/molecules/{"+utils.uriToUuid(m_uri)+"}\">"+utils.uriToUuid(m_uri)+"</a></span>", "", m.formula(), str(m.structureType()), str(m.energy()) ] } )
        return http.HttpResponse(simplejson.dumps(json_response), mimetype='application/javascript')
Exemple #4
0
def render(request, resource_uuid):
    log = logger.logger("wavemoldb.api")
    try:
        resource_uri = utils.uuidToUri(resource_uuid)
    except:
        log.info("Invalid resource uuid "+str(resource_uuid))
        raise http.Http404

    g=rdflib.ConjunctiveGraph()
    for p,o in graphstore.graph().predicate_objects(rdflib.URIRef(resource_uri)):
        if type(o) == rdflib.BNode:
            dumpBNode(graphstore.graph(), o, g)
        g.add( (rdflib.URIRef(resource_uri),p,o) )
    for s,p in graphstore.graph().subject_predicates(rdflib.URIRef(resource_uri)):
        if type(s) == rdflib.BNode:
            dumpBNode(graphstore.graph(), s, g)
        g.add( (s, p, rdflib.URIRef(resource_uri)) )
    
    response = http.HttpResponse(g.serialize(), mimetype="text/xml")
    return response
    def dispatch(self, request, uri):
        context = {}
        graph = graphstore.graph()

        try:
            molecule = grrm2.Molecule.get(graph, uri)
        except:
            return None

        if grrm2.fragments(molecule).get() is None:
            return None

        context["fragmentInfo"] = []
        fragments = grrm2.fragments(molecule).get()
        geometry = grrm2.geometry(molecule).get()
        canost_planar = grrm2.fragmentsCanostPlanar(molecule).get()
        canost_serial = grrm2.fragmentsCanostSerial(molecule).get()
        canost_planar_canonical = grrm2.fragmentsCanostPlanarCanonical(
            molecule).get()
        canost_serial_canonical = grrm2.fragmentsCanostSerialCanonical(
            molecule).get()

        for i, frag in enumerate(fragments):
            fragment_info = {}
            fragment_info["index"] = i
            fragment_info["atomIndices"] = str(frag)
            symbols = [geometry["symbols"][j - 1] for j in frag]
            fragment_info["hillFormula"] = str(chemistry.hillFormula(symbols))
            try:
                fragment_info["canostPlanar"] = "|".join(canost_planar[i])
            except:
                fragment_info["canostPlanar"] = None

            try:
                fragment_info["canostSerial"] = "|".join(canost_serial[i])
            except:
                fragment_info["canostSerial"] = None

            try:
                fragment_info[
                    "canostPlanarCanonical"] = canost_planar_canonical[i]
            except:
                fragment_info["canostPlanarCanonical"] = None

            try:
                fragment_info[
                    "canostSerialCanonical"] = canost_serial_canonical[i]
            except:
                fragment_info["canostSerialCanonical"] = None

            context["fragmentInfo"].append(fragment_info)

        return context
    def dispatch(self, request, **args):
        current_uri = args["uri"]
        graph = graphstore.graph()

        try:
            iconv = grrm2.Interconversion.get(graph, current_uri)
        except:
            return None

        ctx = {}

        ctx["steps"] = []
        ctx["start"] = ResultInfo()
        ctx["end"] = ResultInfo()

        start = grrm2.interconversionStart(iconv).get()[0]
        ctx["start"].uri = start.uri()
        ctx["start"].link = "/resources/%7B" + utils.uriToUuid(
            start.uri()) + "%7D"
        iconstorage = filestorage.ResourceIcon(
            start, settings=settings.filestorage_settings)
        ctx["start"].icon = iconstorage.url(filestorage.ResourceIcon.STATIC)
        ctx["start"].energy = grrm2.energy(start).get()
        ctx["start"].label = _getLabel(start)

        end = grrm2.interconversionEnd(iconv).get()[0]
        ctx["end"].uri = end.uri()
        ctx["end"].link = "/resources/%7B" + utils.uriToUuid(end.uri()) + "%7D"
        iconstorage = filestorage.ResourceIcon(
            end, settings=settings.filestorage_settings)
        ctx["end"].icon = iconstorage.url(filestorage.ResourceIcon.STATIC)
        ctx["end"].energy = grrm2.energy(end).get()
        ctx["end"].label = _getLabel(end)

        for s in grrm2.interconversionStep(iconv).getAll():
            step = s[0]
            iconstorage = filestorage.ResourceIcon(
                step, settings=settings.filestorage_settings)
            info = StepInfo()
            info.link = "/resources/%7B" + utils.uriToUuid(step.uri()) + "%7D"
            info.icon = iconstorage.url(filestorage.ResourceIcon.STATIC)
            info.uri = step.uri()
            info.energy = grrm2.energy(step).get()
            info.number = grrm2.stepNumber(step).get()
            ctx["steps"].append(info)

        def cmpFunc(x, y):
            return cmp(x.number, y.number)

        ctx["steps"] = sorted(ctx["steps"], cmp=cmpFunc)

        return ctx
    def dispatch(self, request, **args):
        current_uri = args["uri"]
        graph = graphstore.graph()
 
        try:
            route = grrm2.Interconversion.get(graph, current_uri)
        except:
            return None

        start = grrm2.interconversionStart(route).get()[0]
        end = grrm2.interconversionEnd(route).get()[0]
        
        iconstorage_start = filestorage.ResourceIcon(start, settings=settings.filestorage_settings)
        iconstorage_end = filestorage.ResourceIcon(end, settings=settings.filestorage_settings)
        iconstorage_route = filestorage.ResourceIcon(route, settings=settings.filestorage_settings)

        ctx = {}
        ctx["startUrl"] = "/resources/%7B"+utils.uriToUuid(start.uri())+"%7D"
        ctx["endUrl"] = "/resources/%7B"+utils.uriToUuid(end.uri())+"%7D"
        ctx["startIcon"] = iconstorage_start.url(filestorage.ResourceIcon.STATIC)
        ctx["endIcon"] = iconstorage_end.url(filestorage.ResourceIcon.STATIC)
        ctx["connectionRouteIcon"] = iconstorage_route.url(filestorage.ResourceIcon.ANIMATED)

        ctx["startStructureLabel"] = _getLabel(start)
        ctx["endStructureLabel"] = _getLabel(end)
    
        energies = {}
        for step in grrm2.interconversionStep(route).getAll():
            step = step[0]
            energies[grrm2.stepNumber(step).get()] = grrm2.energy(step).get()

        energies[0] = grrm2.energy(start).get()
        energies[max(energies.keys())+1] = grrm2.energy(end).get()

        chart_query = http.QueryDict("").copy()
        chart_query.update( {
                "cht": "lxy",
                "chs": "400x400",
                "chd": "t:"+",".join([ str(x) for x in energies.keys()])+"|"+",".join( [str(x) for x in energies.values()]),
                "chds": str(min(energies.keys()))+","+str(max(energies.keys()))+","+str(min(energies.values()))+","+str(max(energies.values())),
                "chco": "3072F3,ff0000,00aaaa",
                "chls": "2,4,1",
                "chf": "bg,s,F0F0FF",
                "chm": "s,FF0000,0,-1,5|s,0000ff,1,-1,5|s,00aa00,2,-1,5",
                "chxt": "x,y",
                "chxr": "0,"+str(min(energies.keys()))+","+str(max(energies.keys()))+"|1,"+str(min(energies.values()))+","+str(max(energies.values())),
            } )
        ctx["chartUrl"] = "http://chart.apis.google.com/chart?"+chart_query.urlencode()


        return ctx
    def dispatch(self, request, **args):
        graph = graphstore.graph()
        try:
            run = grrm2.Run.get(graph, args["uri"])
        except:
            return None

        storage = filestorage.ResourceStorage(
            run, web_accessible=True, settings=settings.filestorage_settings)
        return {
            "connectivityUrl":
            settings.HOST_BASE + storage.url("connectivity", "csv"),
            "resource_uuid":
            utils.uriToUuid(run.uri())
        }
    def dispatch(self, request, uri):
        context = {}
        graph = graphstore.graph()

        try:
            molecule = grrm2.Molecule.get(graph, uri)
        except:
            return None

        context["moleculeInfo"] = self._getMoleculeInfo(molecule)

        if context["moleculeInfo"].isInterconversionStep:
            interconversion_step = grrm2.InterconversionStep.tryCast(molecule)
            prev_step = grrm2.prevInterconversionStep(
                interconversion_step).get()
            next_step = grrm2.nextInterconversionStep(
                interconversion_step).get()

            interconversion = grrm2.interconversionStepOf(
                interconversion_step).get()
            if interconversion and interconversion[0]:
                start_structure = grrm2.interconversionStart(
                    interconversion[0]).get()
                if start_structure and start_structure[0]:
                    start_structure = start_structure[0]

                end_structure = grrm2.interconversionEnd(
                    interconversion[0]).get()
                if end_structure and end_structure[0]:
                    end_structure = end_structure[0]

            if prev_step and prev_step[0]:
                context["prevStepInfo"] = self._getMoleculeInfo(prev_step[0])
            else:
                context["prevStepInfo"] = self._getMoleculeInfo(
                    start_structure)

            if next_step and next_step[0]:
                context["nextStepInfo"] = self._getMoleculeInfo(next_step[0])
            else:
                context["nextStepInfo"] = self._getMoleculeInfo(end_structure)

        else:
            context["isInterconversion"] = False
            context["fromRoutes"] = self._getFromRoutesContext(molecule)
            context["toRoutes"] = self._getToRoutesContext(molecule)

        return context
    def _getUris(self, request, uri):
        graph = graphstore.graph()
        try:
            run = grrm2.Run.get(graph, uri)
        except:
            raise http.Http404

        try:
            offset = int(request.GET["offset"])
        except:
            offset = 0

        try:
            limit = int(request.GET["limit"])
        except:
            limit = 10

        output={}
        output["uri_list"] = []
        output["resource_type"] = []
    
        output["total"] = len(grrm2.runOutput(run).get())
        output["offset"] = offset
        output["limit"] = limit

        for output_tuple in grrm2.runOutput(run).get().limit(limit).offset(offset):
            resource = output_tuple[0]
            output["uri_list"].append(resource.uri())

            if grrm2.TransitionState.tryCast(resource):
                resource_type = "TransitionState"
            elif grrm2.EquilibriumStructure.tryCast(resource):
                resource_type = "EquilibriumStructure"
            elif grrm2.EquilibriumStructure.tryCast(resource):
                resource_type = "EquilibriumStructure"
            elif grrm2.BarrierDissociated.tryCast(resource):
                resource_type = "BarrierDissociated"
            elif grrm2.BarrierlessDissociated.tryCast(resource):
                resource_type = "BarrierlessDissociated"
            elif grrm2.Interconversion.tryCast(resource):
                resource_type = "Interconversion"
            elif grrm2.InterconversionStep.tryCast(resource):
                resource_type = "InterconversionStep"
            else:
                resource_type = "Thing"
            output["resource_type"].append(resource_type)

        return http.HttpResponse(simplejson.dumps(output), mimetype='application/javascript')
Exemple #11
0
    def dispatch(self, request, **args):
        graph = graphstore.graph()
        try:
            run = grrm2.Run.get(graph, args["uri"])
        except:
            return None

        return_dict = { "input" : [], 
                        "output": [], 
                      }

        for input_tuple in grrm2.runInput(run).getAll():
            resource = input_tuple[0]

            input = {}
            return_dict["input"].append(input)
            input["uuid"] = utils.uriToUuid(resource.uri())
            input["data"] = {}

            run_data = grrm2.RunData.tryCast(resource)
            if run_data:
                input["data"]["Type"] = "RunData"
                input["data"]["Basis set"] = grrm2.basisSet(run_data).get()
                input["data"]["Method"] = grrm2.method(run_data).get()
                input["data"]["Job"] = grrm2.job(run_data).get()
                continue

            molecule= grrm2.Molecule.tryCast(resource)
            if molecule:
                input["url"] = "/resources/%7B"+input["uuid"]+"%7D"
                input["data"]["Type"] = "Molecule"
                input["data"]["Hill Formula"] = grrm2.hillFormula(molecule).get()
                input["data"]["Mass"] = grrm2.mass(molecule).get()
                input["data"]["SMILES"] = grrm2.smiles(molecule).get()
                input["data"]["InChi"] = grrm2.inchi(molecule).get()
                input["data"]["Spin Multiplicity"] = grrm2.spinMultiplicity(molecule).get()
                continue

            input["data"]["Type"] = "Unknown"

        return return_dict
Exemple #12
0
    def dispatch(self, request, uri):
        context = {}
        graph = graphstore.graph()

        try:
            molecule = grrm2.Molecule.get(graph, uri)
        except:
            molecule = None

        if not molecule:
            return None

        fs = filestorage.ResourceStorage(
            molecule,
            web_accessible=True,
            settings=settings.filestorage_settings)
        context["xyzFilePath"] = fs.url("geometry", "xyz")
        if not fs.readable("geometry", "xyz"):
            context = None

        return context
Exemple #13
0
def _get_id(submission):
    storage = filestorage.ResourceStorage(submission, web_accessible=False, settings=settings.filestorage_settings)
    f=file(storage.path("system","uuid"), "r")
    id = str(uuid.UUID(f.readlines()[0]))
    f.close()
    return id


base_graph = None
submission_info_subgraph = None

try:
    options = Options(sys.argv)

    base_graph = graphstore.graph()
    submission_info_subgraph = ContextGraph(base_graph.store, identifier=contexts.CONTEXT_NS.SubmissionInfo)

    submission = ordfm.OriginalSubmission.get(submission_info_subgraph,uri="urn:uuid:"+options.submission_uuid)
    if submission is None:
        _usage("unexistent submission")
        sys.exit(1)

    try:
        id = _get_id(submission)
    except:
        id = _generate_id(submission)

    print id    

except Exception, e:
Exemple #14
0
    def dispatch(self, request, uri):
        context = {}
        graph = graphstore.graph()

        try:
            molecule = grrm2.Molecule.get(graph, uri)
        except:
            return None

        context["moleculeInfo"] = []
        context["moleculeInfo"].append(
            ("Formula", grrm2.hillFormula(molecule).get(), None))
        context["moleculeInfo"].append(
            ("Molecular Mass", grrm2.mass(molecule).get(), None))
        context["moleculeInfo"].append(
            ("InChi", grrm2.inchi(molecule).get(), None))
        context["moleculeInfo"].append(
            ("SMILES", grrm2.smiles(molecule).get(), None))
        context["moleculeInfo"].append(
            ("Energy", grrm2.energy(molecule).get(), None))
        context["moleculeInfo"].append(
            ("Charge", grrm2.charge(molecule).get(), None))
        context["moleculeInfo"].append(
            ("Spin", grrm2.spin(molecule).get(), None))

        context["moleculeInfo"].append(
            ("Structure Type", _getStructureType(molecule), None))

        result = grrm2.InterconversionResult.tryCast(molecule)
        if result:
            context["moleculeInfo"].append(
                ("Structure Number", grrm2.structureNumber(result).get(),
                 None))
            context["moleculeInfo"].append(
                ("Zero Point Vibrational Energy",
                 grrm2.zeroPointVibrationalEnergy(result).get(), None))

        step = grrm2.InterconversionStep.tryCast(molecule)
        if step:
            context["moleculeInfo"].append(
                ("Interconversion Step", grrm2.stepNumber(step).get(), None))
            context["moleculeInfo"].append(
                ("Belongs to interconversion",
                 grrm2.interconversionStepOf(step).get()[0].uri(),
                 "/resources/%7B" + utils.uriToUuid(
                     grrm2.interconversionStepOf(step).get()[0].uri()) +
                 "%7D"))

        context["moleculeInfo"].append(
            ("CANOST canonical planar",
             grrm2.canostSerialCanonical(molecule).get(), None))
        context["moleculeInfo"].append(
            ("CANOST canonical serial",
             grrm2.canostPlanarCanonical(molecule).get(), None))

        context["moleculeInfo"].append(
            ("CANOST planar codes", grrm2.canostPlanar(molecule).get(), None))
        context["moleculeInfo"].append(
            ("CANOST serial codes", grrm2.canostSerial(molecule).get(), None))

        fragment_strings = []
        if grrm2.fragments(molecule).get() is not None:
            geometry = grrm2.geometry(molecule).get()
            for fragment in grrm2.fragments(molecule).get():
                symbols = [geometry["symbols"][i - 1] for i in fragment]
                fragment_strings.append(chemistry.hillFormula(symbols))

        context["moleculeInfo"].append(
            ("Fragments", "/".join(fragment_strings), None))

        try:
            run = grrm2.runOutputOf(molecule).get()[0]
            context["moleculeInfo"].append(
                ("Run", run.uri(),
                 "/resources/%7B" + utils.uriToUuid(run.uri()) + "%7D"))
        except Exception, e:
            pass
Exemple #15
0
def main():
    options=Options(sys.argv)

    system_uuid = helperfuncs.getSystemUuid(graphstore.store(),  options.submission_uuid)
    submission_info_subgraph = Graph(graphstore.store(), identifier=contexts.CONTEXT_NS.SubmissionInfo)

    submission = ordfm.SystemSubmission.get(submission_info_subgraph,uri="urn:uuid:"+str(system_uuid))
    if submission is None:
        submission = ordfm.SystemSubmission.new(submission_info_subgraph,uri="urn:uuid:"+str(system_uuid))
        submission_info_subgraph.commit()
    else:
        print "Previous submission found. overwriting"
        graphstore.graph().remove_context(rdflib.URIRef("urn:uuid:"+str(system_uuid)))
        graphstore.graph().commit()

    graph = Graph(graphstore.store(), identifier=rdflib.URIRef("urn:uuid:"+str(options.submission_uuid)))
    system_graph = Graph(graphstore.store(), identifier=rdflib.URIRef("urn:uuid:"+str(system_uuid)))
    print "Adding to graph id urn:uuid:"+str(system_uuid)
    for mol in grrm2.Molecule.all(graph):
        print "-"*40
        print "molecule "+str(mol.uri())

        m = grrm2.Molecule.new(system_graph, mol.uri())
        formula = helperfuncs.generateFormula(mol)
        inchi = helperfuncs.generateInchi(mol)
        smiles = helperfuncs.generateSmiles(mol)
        mass = helperfuncs.generateMass(mol)
        
        print "Formula: "+str(formula)
        print "Inchi: "+str(inchi)
        print "Smiles: "+str(smiles)
        print "Mass: "+str(mass)

        if formula is not None: 
            grrm2.hillFormula(m).set(formula)
        if inchi is not None:
            grrm2.inchi(m).set(inchi)
        if smiles is not None:
            grrm2.smiles(m).set(smiles)
        if mass is not None:
            grrm2.mass(m).set(mass)

        try: 
            helperfuncs.generateMdl(mol)  
        except:
            pass

        canost_planar = helperfuncs.generateCanostPlanar(mol)
        canost_serial = helperfuncs.generateCanostSerial(mol)
        canost_canonical = helperfuncs.generateCanostCanonical(mol)
        print "canost planar: "+str(canost_planar)
        print "canost serial: "+str(canost_serial)
        print "canost canonical: "+str(canost_canonical)

        if canost_planar is not None:
            grrm2.canostPlanar(m).set(canost_planar)
        if canost_serial is not None:
            grrm2.canostSerial(m).set(canost_serial)
        if canost_canonical is not None:
            canost_planar_canonical, canost_serial_canonical = canost_canonical
            if canost_planar_canonical is not None:
                grrm2.canostPlanarCanonical(m).set(canost_planar_canonical)
            if canost_serial_canonical is not None:
                grrm2.canostSerialCanonical(m).set(canost_serial_canonical)

        try:
            helperfuncs.generateMdlForFragments(mol)
        except:
            pass
            
        canost_planar_fragments = helperfuncs.generateCanostPlanarFragments(mol)
        print "canost planar fragments: "+str(canost_planar_fragments)
        if canost_planar_fragments is not None:
            grrm2.fragmentsCanostPlanar(m).set(canost_planar_fragments) 

        canost_serial_fragments = helperfuncs.generateCanostSerialFragments(mol)
        print "canost serial fragments: "+str(canost_serial_fragments)
        if canost_serial_fragments is not None:
            grrm2.fragmentsCanostSerial(m).set(canost_serial_fragments)

        canost_canonical_fragments = helperfuncs.generateCanostCanonicalFragments(mol)
        print "canost canonical fragments: "+str(canost_canonical_fragments)

        if canost_canonical_fragments is not None:
            canost_planar_canonical_fragments=[]
            canost_serial_canonical_fragments=[]

            for fragment_result in canost_canonical_fragments:
                if fragment_result is None:
                    canost_planar_canonical_fragments.append(None)
                    canost_serial_canonical_fragments.append(None)
                    continue
                canost_planar_canonical_fragments.append(fragment_result[0])
                canost_serial_canonical_fragments.append(fragment_result[1])

            print "canost_planar_canonical_fragments : "+str(canost_planar_canonical_fragments)
            print "canost_serial_canonical_fragments : "+str(canost_serial_canonical_fragments)
            grrm2.fragmentsCanostPlanarCanonical(m).set(canost_planar_canonical_fragments)
            grrm2.fragmentsCanostSerialCanonical(m).set(canost_serial_canonical_fragments)

    system_graph.commit()
            m=grrm2.Run.get(graph,res[0])
            if m:
                indexer.store(res[0], { "is_grrm__run" : True})
        except:
            pass



def _indexEnergy(graph, indexer):
    indexer.addIndex("grrm__energy", "VARCHAR(255)")
    
    for m in grrm2.Molecule.all(graph):
        energy = grrm2.energy(m).get()
        if energy:
            indexer.store(m.uri(), { "grrm__energy" : float(energy)})

try:

    graph = graphstore.graph()

    indexer = indexing.DbIndex()
    indexer.drop()

    _indexRdfType(graph, indexer)
    _indexEnergy(graph, indexer)
except Exception, e:
    print e
    sys.exit(1)

sys.exit(0)
    def dispatch(self, request, **args):
        current_uri = args["uri"]
        graph = graphstore.graph()

        try:
            transition_state = grrm2.TransitionState.get(graph, current_uri)
        except:
            return None

        ctx = {}

        iconv_start_tuple_list = grrm2.interconversionStartOf(
            transition_state).getAll() or []
        iconv_end_tuple_list = grrm2.interconversionEndOf(
            transition_state).getAll() or []
        if len(iconv_start_tuple_list) + len(iconv_end_tuple_list) != 2:
            return None  # we have a problem... a transition state must have two links

        if len(iconv_start_tuple_list) == 2:
            iconv_left = iconv_start_tuple_list[0][0]
            iconv_right = iconv_start_tuple_list[1][0]
            energies_left = _getEnergies(iconv_left)
            energies_right = _getEnergies(iconv_right)
            energies = {}
            energies[0] = grrm2.energy(transition_state).get()
            for k, v in sorted(map(lambda x:
                                   (-x[0], x[1]), energies_left.items()) +
                               energies_right.items(),
                               key=lambda x: x[0]):
                print k
                energies[k] = v

            end_left = grrm2.interconversionEnd(iconv_left).get()[0]
            end_right = grrm2.interconversionEnd(iconv_right).get()[0]

            energies[min(energies.keys()) - 1] = grrm2.energy(end_left).get()
            energies[max(energies.keys()) + 1] = grrm2.energy(end_right).get()

        else:
            return None

        chart_query = http.QueryDict("").copy()
        chart_query.update({
            "cht":
            "lxy",
            "chs":
            "400x400",
            "chd":
            "t:" + ",".join([
                str(x[0]) for x in sorted(energies.items(), key=lambda x: x[0])
            ]) + "|" + ",".join([
                str(x[1]) for x in sorted(energies.items(), key=lambda x: x[0])
            ]),
            "chds":
            str(min(energies.keys())) + "," + str(max(energies.keys())) + "," +
            str(min(energies.values())) + "," + str(max(energies.values())),
            "chco":
            "3072F3,ff0000,00aaaa",
            "chls":
            "2,4,1",
            "chf":
            "bg,s,F0F0FF",
            "chm":
            "s,FF0000,0,-1,5|s,0000ff,1,-1,5|s,00aa00,2,-1,5",
            "chxt":
            "x,y",
            "chxr":
            "0," + str(min(energies.keys())) + "," +
            str(max(energies.keys())) + "|1," + str(min(energies.values())) +
            "," + str(max(energies.values())),
        })
        ctx["chartUrl"] = "http://chart.apis.google.com/chart?" + chart_query.urlencode(
        )

        iconstorage = filestorage.ResourceIcon(
            transition_state, settings=settings.filestorage_settings)
        if iconstorage.readable(filestorage.ResourceIcon.STATIC):
            icon_url = iconstorage.url(filestorage.ResourceIcon.STATIC)
        elif iconstorage.readable(filestorage.ResourceIcon.ANIMATED):
            icon_url = iconstorage.url(filestorage.ResourceIcon.ANIMATED)
        else:
            icon_url = None

        ctx["transitionStateIcon"] = icon_url

        iconstorage = filestorage.ResourceIcon(
            end_left, settings=settings.filestorage_settings)
        if iconstorage.readable(filestorage.ResourceIcon.STATIC):
            icon_url = iconstorage.url(filestorage.ResourceIcon.STATIC)
        elif iconstorage.readable(filestorage.ResourceIcon.ANIMATED):
            icon_url = iconstorage.url(filestorage.ResourceIcon.ANIMATED)
        else:
            icon_url = None

        ctx["leftEndIcon"] = icon_url

        iconstorage = filestorage.ResourceIcon(
            end_right, settings=settings.filestorage_settings)
        if iconstorage.readable(filestorage.ResourceIcon.STATIC):
            icon_url = iconstorage.url(filestorage.ResourceIcon.STATIC)
        elif iconstorage.readable(filestorage.ResourceIcon.ANIMATED):
            icon_url = iconstorage.url(filestorage.ResourceIcon.ANIMATED)
        else:
            icon_url = None

        ctx["rightEndIcon"] = icon_url

        ctx["leftEndUrl"] = "/resources/%7B" + utils.uriToUuid(
            end_left.uri()) + "%7D"
        ctx["rightEndUrl"] = "/resources/%7B" + utils.uriToUuid(
            end_right.uri()) + "%7D"
        return ctx