def _parseUDCTokenList(self):
        tokenizer = grrm.ListOutputTokenizer()
        tokens = tokenizer.tokenize(self._filename)

        current_molecule = None

        header_found = False
        for t in tokens:
            if t.__class__ == tokentypes.HeaderDissociatedToken:
                header_found = True
            if t.__class__ == tokentypes.StructureHeaderToken:
                if not header_found:
                    raise Exception("Header not found")
                current_molecule = grrm2.BarrierlessDissociated.new(
                    self._graph,
                    rdflib.URIRef("urn:uuid:" + str(uuid.uuid4())))
                self._molecules.append(current_molecule)
                grrm2.structureNumber(current_molecule).set(int(t.number()))

                self._struct_label_to_molecule_mapper[(
                    "uDC", t.number())] = current_molecule

            if t.__class__ == tokentypes.GeometryToken:
                if not header_found:
                    raise Exception("Header not found")
                grrm2.geometry(current_molecule).set(
                    helperfuncs.parseGeometryToken(t))
            if t.__class__ == tokentypes.EnergyToken:
                if not header_found:
                    raise Exception("Header not found")
                grrm2.energy(current_molecule).set(
                    helperfuncs.parseEnergyToken(t))
            if t.__class__ == tokentypes.SpinToken:
                if not header_found:
                    raise Exception("Header not found")
                grrm2.spin(current_molecule).set(
                    int(t.spin().rescale(units.hbar).magnitude))
            if t.__class__ == tokentypes.ZPVEToken:
                if not header_found:
                    raise Exception("Header not found")
                grrm2.zeroPointVibrationalEnergy(current_molecule).set(
                    helperfuncs.parseZPVEToken(t))
            if t.__class__ == tokentypes.NormalModesToken:
                if not header_found:
                    raise Exception("Header not found")
                grrm2.normalModesEigenvalues(current_molecule).set(
                    helperfuncs.parseNormalModesEigenvalues(t))
            if t.__class__ == tokentypes.ConnectionToken:
                if not header_found:
                    raise Exception("Header not found")
                self._connections.append(
                    (("uDC", grrm2.structureNumber(current_molecule).get()),
                     ("EQ", t.first())))

            if t.__class__ == tokentypes.DissociationFragmentsToken:
                if not header_found:
                    raise Exception("Header not found")
                grrm2.fragments(current_molecule).set(t.fragments())
    def _getMoleculeInfo(self, molecule):
        info = MoleculeInfo()

        info.icon = filestorage.ResourceIcon(
            molecule, settings=settings.filestorage_settings).url(
                filestorage.ResourceIcon.STATIC)
        info.link = "/resources/%7B" + utils.uriToUuid(molecule.uri()) + "%7D"
        info.structureLabel = "Unknown"
        info.isInterconversionStep = False

        interconversion_step = grrm2.InterconversionStep.tryCast(molecule)
        icresult = grrm2.InterconversionResult.tryCast(molecule)
        if interconversion_step:
            info.isInterconversionStep = True
            info.structureLabel = "IC - step " + str(
                grrm2.stepNumber(interconversion_step).get())
        elif icresult:
            struct_number = grrm2.structureNumber(icresult).get()
            if grrm2.EquilibriumStructure.tryCast(icresult):
                struct_type = "EQ"
            elif grrm2.TransitionState.tryCast(icresult):
                struct_type = "TS"
            elif grrm2.BarrierlessDissociated.tryCast(icresult):
                struct_type = "DDC"
            elif grrm2.BarrierDissociated.tryCast(icresult):
                struct_type = "UDC"

            info.structureLabel = struct_type + str(struct_number)

        return info
def _getLabel(mol):
    struct_number = grrm2.structureNumber(mol).get()
    if grrm2.EquilibriumStructure.tryCast(mol):
        struct_type = "EQ"
    elif grrm2.TransitionState.tryCast(mol):
        struct_type = "TS"
    elif grrm2.BarrierlessDissociated.tryCast(mol):
        struct_type = "uDC"
    elif grrm2.BarrierDissociated.tryCast(mol):
        struct_type = "dDC"

    return struct_type+str(struct_number)
    def _getFromRoutesContext(self, molecule):

        icres = grrm2.InterconversionResult.tryCast(molecule)

        context = []
        iconvs = grrm2.interconversionEndOf(icres).getAll()
        if iconvs is None:
            return context

        for iconv in iconvs:
            iconv = iconv[0]
            start = grrm2.interconversionStart(iconv).get()[0]

            route_info = RouteInfo()
            route_info.link = "/resources/%7B" + utils.uriToUuid(
                iconv.uri()) + "%7D"

            route_info.targetLink = "/resources/%7B" + utils.uriToUuid(
                start.uri()) + "%7D"
            route_info.targetIcon = filestorage.ResourceIcon(
                start, settings=settings.filestorage_settings).url(
                    filestorage.ResourceIcon.STATIC)
            struct_number = grrm2.structureNumber(start).get()
            if grrm2.EquilibriumStructure.tryCast(start):
                struct_type = "EQ"
            elif grrm2.TransitionState.tryCast(start):
                struct_type = "TS"
            elif grrm2.BarrierlessDissociated.tryCast(start):
                struct_type = "DDC"
            elif grrm2.BarrierDissociated.tryCast(start):
                struct_type = "UDC"

            route_info.targetStructureLabel = struct_type + str(struct_number)
            route_info.targetEnergy = grrm2.energy(start).get()

            route_info.energyDifference = grrm2.energy(
                start).get() - grrm2.energy(molecule).get()

            route_info.icon = filestorage.ResourceIcon(
                iconv, settings=settings.filestorage_settings).url(
                    filestorage.ResourceIcon.ANIMATED)

            context.append(route_info)

        return context
def _getLabel(molecule):
    label = "Unknown"
    interconversion_step = grrm2.InterconversionStep.tryCast(molecule)
    icresult = grrm2.InterconversionResult.tryCast(molecule)
    if interconversion_step:
        info.isInterconversionStep = True
        info.structureLabel = "IC - step "+str(grrm2.stepNumber(interconversion_step).get())
    elif icresult:
        struct_number = grrm2.structureNumber(icresult).get()
        if grrm2.EquilibriumStructure.tryCast(icresult):
            struct_type = "EQ"
        elif grrm2.TransitionState.tryCast(icresult):
            struct_type = "TS"
        elif grrm2.BarrierlessDissociated.tryCast(icresult):
            struct_type = "DDC"
        elif grrm2.BarrierDissociated.tryCast(icresult):
            struct_type = "UDC"

        label = struct_type+str(struct_number)

    return label
    def testDataProperty(self):
        graph = rdflib.ConjunctiveGraph(getStore())

        eq1 = grrm2.EquilibriumStructure.new(graph, "http://example.com/eq1")
        ts1 = grrm2.TransitionState.new(graph, "http://example.com/ts1")
        blessdiss1 = grrm2.BarrierlessDissociated.new(
            graph, "http://example.com/blessdiss1")
        bdiss1 = grrm2.BarrierDissociated.new(graph,
                                              "http://example.com/bdiss1")
        ic1 = grrm2.InterconversionStep.new(graph, "http://example.com/ic1")
        iconv1 = grrm2.Interconversion.new(graph, "http://example.com/iconv1")
        rundata1 = grrm2.RunData.new(graph, "http://example.com/rundata1")
        run1 = grrm2.Run.new(graph, "http://example.com/run1")
        mol1 = grrm2.Molecule.new(graph, "http://example.com/mol1")
        runin1 = grrm2.RunInput.new(graph, "http://example.com/runin1")
        runout1 = grrm2.RunOutput.new(graph, "http://example.com/runout1")
        icres1 = grrm2.InterconversionResult.new(graph,
                                                 "http://example.com/icres1")

        all_results = [eq1, ts1, blessdiss1, bdiss1, icres1]
        all_not_results = [iconv1, rundata1, run1, runin1, ic1, mol1, runout1]
        all_molecules = all_results + [ic1, mol1]
        all_not_molecules = [iconv1, rundata1, run1, runin1, runout1]
        all_runin = [runin1] + all_molecules
        all_runout = [runout1] + all_molecules

        for r in all_results:
            grrm2.zeroPointVibrationalEnergy(r).set(12.3)
            self.assertRaises(Exception,
                              grrm2.zeroPointVibrationalEnergy(r).set, "hello")
        for r in all_not_results:
            self.assertRaises(Exception, grrm2.zeroPointVibrationalEnergy, r)

        for r in all_results:
            grrm2.structureNumber(r).set(1)
            self.assertRaises(Exception, grrm2.structureNumber(r).set, "hello")
        for r in all_not_results:
            self.assertRaises(Exception, grrm2.structureNumber, r)

        for r in [ic1]:
            grrm2.stepNumber(r).set(1)
            self.assertRaises(Exception, grrm2.stepNumber(r).set, "hello")
        for r in [
                eq1, ts1, blessdiss1, bdiss1, icres1, iconv1, rundata1, run1,
                runin1, mol1, runout1
        ]:
            self.assertRaises(Exception, grrm2.stepNumber, r)

        for r in all_molecules:
            grrm2.spinMultiplicity(r).set(1)
            self.assertRaises(Exception,
                              grrm2.spinMultiplicity(r).set, "hello")
        for r in all_not_molecules:
            self.assertRaises(Exception, grrm2.spinMultiplicity, r)

        for r in all_molecules:
            grrm2.spin(r).set(1.4)
            self.assertRaises(Exception, grrm2.spin(r).set, "hello")
        for r in all_not_molecules:
            self.assertRaises(Exception, grrm2.spin, r)

        for r in all_molecules:
            grrm2.smiles(r).set("hello")
        for r in all_not_molecules:
            self.assertRaises(Exception, grrm2.smiles, r)

        for r in all_molecules:
            grrm2.normalModesEigenvalues(r).set([1, 2, 3])
        for r in all_not_molecules:
            self.assertRaises(Exception, grrm2.normalModesEigenvalues, r)

        for r in [rundata1]:
            grrm2.method(r).set("hello")
        for r in [
                eq1, ts1, blessdiss1, bdiss1, ic1, iconv1, run1, mol1, runin1,
                runout1, icres1
        ]:
            self.assertRaises(Exception, grrm2.method, r)

        for r in all_molecules:
            grrm2.mass(r).set(1.4)
            self.assertRaises(Exception, grrm2.mass(r).set, "hello")
        for r in all_not_molecules:
            self.assertRaises(Exception, grrm2.mass, r)

        for r in [rundata1]:
            grrm2.job(r).set("hello")
        for r in [
                eq1, ts1, blessdiss1, bdiss1, ic1, iconv1, run1, mol1, runin1,
                runout1, icres1
        ]:
            self.assertRaises(Exception, grrm2.job, r)

        for r in all_molecules:
            grrm2.inchi(r).set("hello")
        for r in all_not_molecules:
            self.assertRaises(Exception, grrm2.inchi, r)

        for r in all_molecules:
            grrm2.hillFormula(r).set("hello")
        for r in all_not_molecules:
            self.assertRaises(Exception, grrm2.hillFormula, r)

        for r in all_molecules:
            grrm2.geometry(r).set({})
        for r in all_not_molecules:
            self.assertRaises(Exception, grrm2.geometry, r)

        for r in all_molecules:
            grrm2.energy(r).set(1.4)
            self.assertRaises(Exception, grrm2.energy(r).set, "hello")
        for r in all_not_molecules:
            self.assertRaises(Exception, grrm2.energy, r)

        for r in all_molecules:
            grrm2.charge(r).set(1.4)
            self.assertRaises(Exception, grrm2.charge(r).set, "hello")
        for r in all_not_molecules:
            self.assertRaises(Exception, grrm2.charge, r)

        for r in all_molecules:
            grrm2.canostSerial(r).set(["foo"])
        for r in all_not_molecules:
            self.assertRaises(Exception, grrm2.canostSerial, r)

        for r in all_molecules:
            grrm2.canostPlanar(r).set(["foo"])
        for r in all_not_molecules:
            self.assertRaises(Exception, grrm2.canostPlanar, r)

        for r in [rundata1]:
            grrm2.basisSet(r).set("hello")
        for r in [
                eq1, ts1, blessdiss1, bdiss1, ic1, iconv1, run1, mol1, runin1,
                runout1, icres1
        ]:
            self.assertRaises(Exception, grrm2.basisSet, r)
Example #7
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