Exemplo n.º 1
0
    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')
Exemplo n.º 2
0
def _getEnergies(iconv):
    energies = {}
    for step in grrm2.interconversionStep(iconv).getAll():
        step = step[0]
        energies[grrm2.stepNumber(step).get()] = grrm2.energy(step).get()

    return energies
    def _parseUDCAnalysis(self):
        tokenizer = grrm.UDCAnalysisOutputTokenizer()
        tokens = tokenizer.tokenize(self._filename)

        steepest_header_found = False
        m_uDC = re.search("_uDC(\d+)\.log", self._filename)

        route = grrm2.Interconversion.new(
            self._graph, rdflib.URIRef("urn:uuid:" + str(uuid.uuid4())))
        self._route = route
        self._route_additional_infos = InterconversionAdditionalInfo.InterconversionAdditionalInfo(
            route)
        self._route_additional_infos.setStartStructureLabel(
            ("uDC", int(m_uDC.group(1))))

        steps = {}
        for t in tokens:
            if t.__class__ == tokentypes.SteepestDescentHeaderToken:
                steepest_header_found = True
            if t.__class__ == tokentypes.IRCStepToken:
                if not steepest_header_found:
                    raise Exception("Steepest Header not found")

                molecule = grrm2.InterconversionStep.new(
                    self._graph,
                    rdflib.URIRef("urn:uuid:" + str(uuid.uuid4())))
                self._route_steps.append(molecule)
                grrm2.energy(molecule).set(t.energy().rescale(
                    units.hartree).magnitude)
                grrm2.spin(molecule).set(t.spin().rescale(
                    units.hbar).magnitude)
                grrm2.geometry(molecule).set(helperfuncs.parseGeometryToken(t))
                grrm2.stepNumber(molecule).set(t.step())

                grrm2.interconversionStep(route).add(molecule)
                steps[t.step()] = molecule
                if t.step() != 1:
                    grrm2.prevInterconversionStep(molecule).set(
                        steps[t.step() - 1])

            if t.__class__ == tokentypes.DownhillWalkingResultToken:
                self._route_additional_infos.setEndStructureLabel(t.result())
Exemplo n.º 4
0
    def testTSAnalysis(self):
        graph = rdflib.ConjunctiveGraph()
        p = parsinghelpers.TSAnalysisParser(
            graph,
            os.path.join(os.path.dirname(__file__), "formaldehyde-newnames",
                         "grrm_HCHO_TS3.log"))
        self.assertEqual(
            p._forward_route_additional_infos.startStructureLabel(), ("TS", 3))
        self.assertEqual(p._forward_route_additional_infos.endStructureLabel(),
                         ("UDC", 1))
        self.assertEqual(
            len(grrm2.interconversionStep(p._forward_route).getAll()), 17)

        self.assertEqual(
            p._backward_route_additional_infos.startStructureLabel(),
            ("TS", 3))
        self.assertEqual(
            p._backward_route_additional_infos.endStructureLabel(), ("UDC", 2))
        self.assertEqual(
            len(grrm2.interconversionStep(p._backward_route).getAll()), 19)
        print graph.serialize()
Exemplo n.º 5
0
    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
Exemplo n.º 6
0
    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
Exemplo n.º 7
0
    _usage()
    sys.exit(1)

graph = Graph(graphstore.store(),
              identifier=rdflib.URIRef("urn:uuid:" +
                                       str(options.submission_uuid)))

for iconv in grrm2.Interconversion.all(graph):
    print "Generating xyz for interconversion " + iconv.uri()
    res_storage = filestorage.ResourceStorage(
        iconv, web_accessible=True, settings=settings.filestorage_settings)

    all_files = []

    step_tuples = []
    for s in grrm2.interconversionStep(iconv).getAll():
        step = s[0]
        fs = filestorage.ResourceStorage(
            step, web_accessible=True, settings=settings.filestorage_settings)
        step_xyz = fs.path("geometry", "xyz")
        step_number = grrm2.stepNumber(step).get()
        step_tuples.append((step_number, step_xyz))

    def cmpFunc(x, y):
        return cmp(x[0], y[0])

    for step, file in sorted(step_tuples, cmp=cmpFunc):
        all_files.append(file)

    if len(all_files) != 0:
        os.system("cat " + " ".join(all_files + list(reversed(all_files))) +
    def _parseTSAnalysis(self):
        tokenizer = grrm.TSAnalysisOutputTokenizer()
        tokens = tokenizer.tokenize(self._filename)

        status = Anon()
        status.header_found = False
        status.doing_forward = False
        status.doing_backward = False

        m_TS = re.search("_TS(\d+)\.log", self._filename)

        forward_route = grrm2.Interconversion.new(self._graph,rdflib.URIRef("urn:uuid:"+str(uuid.uuid4())))
        backward_route = grrm2.Interconversion.new(self._graph,rdflib.URIRef("urn:uuid:"+str(uuid.uuid4())))
        self._forward_route = forward_route
        self._backward_route = backward_route

        forward_steps = {}
        backward_steps = {}

        self._forward_route_additional_infos = InterconversionAdditionalInfo.InterconversionAdditionalInfo(forward_route)
        self._forward_route_additional_infos.setStartStructureLabel( ( "TS", int(m_TS.group(1)) ) )

        self._backward_route_additional_infos = InterconversionAdditionalInfo.InterconversionAdditionalInfo(backward_route)
        self._backward_route_additional_infos.setStartStructureLabel( ( "TS", int(m_TS.group(1)) ) )

        for t in tokens:
            if t.__class__ == tokentypes.IRCHeaderToken:
                status.header_found = True
            if t.__class__ == tokentypes.ForwardIRCHeaderToken:
                if not status.header_found:
                    raise Exception("Header not found")
                status.doing_forward = True
                status.doing_backward = False

            if t.__class__ == tokentypes.BackwardIRCHeaderToken:
                if not status.header_found:
                    raise Exception("Header not found")
                status.doing_forward = False
                status.doing_backward = True

            if t.__class__ == tokentypes.IRCStepToken:
                molecule = grrm2.InterconversionStep.new(self._graph, rdflib.URIRef("urn:uuid:"+str(uuid.uuid4())))
                grrm2.energy(molecule).set(t.energy().rescale(units.hartree).magnitude)
                grrm2.spin(molecule).set(t.spin().rescale(units.hbar).magnitude)
                grrm2.geometry(molecule).set(helperfuncs.parseGeometryToken(t))
                grrm2.stepNumber(molecule).set(t.step())

                if status.doing_forward:
                    grrm2.interconversionStep(forward_route).add(molecule)
                    self._forward_steps.append(molecule)
                    forward_steps[t.step()] = molecule
                    if t.step() != 1:
                        grrm2.prevInterconversionStep(molecule).set(forward_steps[t.step()-1]) 
                     
                elif status.doing_backward:
                    grrm2.interconversionStep(backward_route).add(molecule)
                    self._backward_steps.append(molecule)

                    backward_steps[t.step()] = molecule
                    if t.step() != 1:
                        grrm2.prevInterconversionStep(molecule).set(backward_steps[t.step()-1]) 
                else:
                    raise Exception("found IRCStepToken but no idea who it belongs to") 
                
            if t.__class__ == tokentypes.IRCFollowingResultsToken:
                self._forward_route_additional_infos.setEndStructureLabel(_properNaming(t.forward()))
                self._backward_route_additional_infos.setEndStructureLabel(_properNaming(t.backward()))