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 grrmMoleculeInfoFilter(thing, data_list):
    if not grrm2.Molecule.tryCast(thing):
        return (thing, data_list)

    mol = grrm2.Molecule.tryCast(thing)
    energy = grrm2.energy(mol).get()
    if energy:
        for data in data_list:
            data.grrm__energy = float(energy)

    mass = grrm2.mass(mol).get()
    if mass:
        for data in data_list:
            data.grrm__mass = float(mass)

    geometry = grrm2.geometry(mol).get()
    if geometry:
        for data in data_list:
            all_symbols = geometry["symbols"]
            data.grrm__carbons = len(filter(lambda x: x == "C", all_symbols))
            data.grrm__oxygens = len(filter(lambda x: x == "O", all_symbols))
            data.grrm__hydrogens = len(filter(lambda x: x == "H", all_symbols))
            data.grrm__nitrogens = len(filter(lambda x: x == "N", all_symbols))

    smiles = grrm2.smiles(mol).get()
    if smiles:
        for data in data_list:
            data.grrm__smiles_md5 = md5.md5(smiles).hexdigest()
    inchi = grrm2.inchi(mol).get()
    if inchi:
        for data in data_list:
            data.grrm__inchi_md5 = md5.md5(inchi).hexdigest()

    return (thing, data_list)
    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())
예제 #4
0
    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
예제 #5
0
    def _parseInput(self):
        input_tokenizer = grrm.InputTokenizer()
        token_list = input_tokenizer.tokenize(self._filename)

        molecule_dict = {}
        run_dict = {}
        for t in token_list:
            if t.__class__ == tokentypes.InputGeometryToken:
                molecule_dict["charge"] = int(t.charge())
                molecule_dict["spin_multiplicity"] = int(t.spinMultiplicity())
                molecule_dict["geometry"] = helperfuncs.parseGeometryToken(t)
            elif t.__class__ == tokentypes.CommandDirectiveToken:
                run_dict["job"] = t.jobString()
                run_dict["method"] = t.methodString()
                run_dict["basis_set"] = t.basisSetString()

        molecule = grrm2.Molecule.new(
            self._graph, rdflib.URIRef("urn:uuid:" + str(uuid.uuid4())))
        grrm2.geometry(molecule).set(molecule_dict["geometry"])
        grrm2.spinMultiplicity(molecule).set(
            molecule_dict["spin_multiplicity"])
        grrm2.charge(molecule).set(molecule_dict["charge"])

        rundata = grrm2.RunData.new(
            self._graph, rdflib.URIRef("urn:uuid:" + str(uuid.uuid4())))
        grrm2.job(rundata).set(run_dict["job"])
        grrm2.method(rundata).set(run_dict["method"])
        grrm2.basisSet(rundata).set(run_dict["basis_set"])

        run = grrm2.Run.new(self._graph,
                            rdflib.URIRef("urn:uuid:" + str(uuid.uuid4())))
        grrm2.runInput(run).add(rundata)
        grrm2.runInput(run).add(molecule)

        self._run = run
        self._molecule = molecule
예제 #6
0
    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)
        print error
        print ""


options = Options(sys.argv)

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

for mol in grrm2.Molecule.all(graph):
    fs = filestorage.ResourceStorage(mol,
                                     web_accessible=True,
                                     settings=settings.filestorage_settings)

    data = grrm2.geometry(mol).get()
    elements = data["symbols"]
    coords = data["coordinates"]

    f = file(fs.path("geometry", "xyz"), "w")

    num_atoms = len(elements)
    f.write(str(num_atoms) + "\n\n")
    for element, coord in zip(elements, coords):
        f.write("%s  %16.10f %16.10f %16.10f\n" %
                (element, coord[0], coord[1], coord[2]))

    f.close()

    fragments = grrm2.fragments(mol).get()
    if fragments:
예제 #8
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
    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()))
예제 #10
0
def generateFormula(mol):
    data = grrm2.geometry(mol).get()
    formula = chemistry.hillFormula(data["symbols"])
    return formula