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())
Ejemplo n.º 2
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
Ejemplo n.º 3
0
def generateMdlForFragments(mol):
    fragments = grrm2.fragments(mol).get()
    print "Found fragments : " + str(fragments)
    if fragments:
        for fragment_number in xrange(len(fragments)):
            fs = filestorage.ResourceStorage(
                mol,
                web_accessible=False,
                settings=settings.filestorage_settings)
            fs_web = filestorage.ResourceStorage(
                mol,
                web_accessible=True,
                settings=settings.filestorage_settings)
            xyz_path = fs_web.path("geometry",
                                   "xyz",
                                   parameters={"fragment": fragment_number})
            mol_path = fs.path("geometry",
                               "mol",
                               parameters={"fragment": fragment_number})
            p = subprocess.Popen(
                ["babel", "-ixyz", xyz_path, "-omol", mol_path],
                stdin=subprocess.PIPE,
                stdout=subprocess.PIPE)
            print["babel", "-ixyz", xyz_path, "-omol", mol_path]
            retcode = p.wait()
            if retcode != 0:
                _removeFile(mol_path)
                raise Exception("Unable to create mdl for fragment " +
                                str(fragment_number) + " molecule " +
                                mol.uri())

    return None
Ejemplo n.º 4
0
def generateCanostSerialFragments(mol):
    fragments = grrm2.fragments(mol).get()
    if not fragments:
        return None

    canost_serial_fragments = []
    for fragment_number in xrange(len(fragments)):
        fs = filestorage.ResourceStorage(
            mol, web_accessible=False, settings=settings.filestorage_settings)
        fs_web = filestorage.ResourceStorage(
            mol, web_accessible=True, settings=settings.filestorage_settings)
        mol_path = fs.path("geometry",
                           "mol",
                           parameters={'fragment': fragment_number})
        canost_path = fs.path("canost_serial",
                              "txt",
                              parameters={"fragment": fragment_number})
        canost = _generateCanostFromFile(mol_path, canost_path, "serial")
        canost_serial_fragments.append(canost)

    return canost_serial_fragments
                                     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:
        for fragment_number, fragment in enumerate(fragments):
            print mol.uri()
            f = file(
                fs.path("geometry",
                        "xyz",
                        parameters={"fragment": fragment_number}), "w")
            f.write(str(len(fragment)) + "\n\n")
            for index in fragment:
                f.write("%s  %16.10f %16.10f %16.10f\n" %
                        (elements[index - 1], coords[index - 1][0],
                         coords[index - 1][1], coords[index - 1][2]))
            f.close()
Ejemplo n.º 6
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