Ejemplo n.º 1
0
def generateSmiles(mol):
    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")
    smiles_path = fs.path("smiles", "txt")
    p = subprocess.Popen(["bwrap_xyz2smiles", xyz_path, smiles_path],
                         stdin=subprocess.PIPE,
                         stdout=subprocess.PIPE)
    retcode = p.wait()
    if retcode != 0:
        _removeFile(smiles_path)
        return None

    try:
        smiles_path = fs.path("smiles", "txt")
        f = file(smiles_path, "r")
        smiles = f.readlines()[0]
        f.close()
    except:
        _removeFile(smiles_path)
        return None

    return smiles
Ejemplo n.º 2
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.º 3
0
def generateCanostSerial(mol):
    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")
    canost_path = fs.path("canost_serial", "txt")
    return _generateCanostFromFile(mol_path, canost_path, "serial")
Ejemplo n.º 4
0
def generateMdl(mol):
    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")
    mol_path = fs.path("geometry", "mol")
    p = subprocess.Popen(["babel", "-ixyz", xyz_path, "-omol", mol_path],
                         stdin=subprocess.PIPE,
                         stdout=subprocess.PIPE)
    retcode = p.wait()
    print "retcode mdl " + str(retcode)

    if retcode != 0:
        _removeFile(mol_path)
        raise Exception("Unable to create mdl")
Ejemplo n.º 5
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
Ejemplo n.º 6
0
    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 _get_system_uuid(store, submission_uuid):
    graph = Graph(store, identifier=contexts.CONTEXT_NS.SubmissionInfo)
    submission = ordfm.OriginalSubmission.get(graph,
                                              uri="urn:uuid:" +
                                              submission_uuid)
    if submission is None:
        raise Exception("no submission found " + str(submission_uuid))
    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
Ejemplo n.º 8
0
    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')
Ejemplo n.º 9
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
    print ""
    if error is not None:
        print ""
        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()
Ejemplo n.º 11
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
Ejemplo n.º 12
0
def _generate_id(submission):
    storage = filestorage.ResourceStorage(submission, web_accessible=False, settings=settings.filestorage_settings)
    f=file(storage.path("system","uuid"), "w")
    f.write(str(uuid.uuid4()))
    f.close()
    return _get_id(submission)
Ejemplo n.º 13
0
        print error
        print ""


options = Options(sys.argv)
if options.submission_uuid is None:
    _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])
    elif grrm2.BarrierlessDissociated.tryCast(mol):
        struct_type = "uDC"
    elif grrm2.BarrierDissociated.tryCast(mol):
        struct_type = "dDC"

    return struct_type+str(struct_number)

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

runs = list(grrm2.Run.all(graph))

if len(runs) != 1:
    raise Exception("Run length != 1")

storage = filestorage.ResourceStorage(runs[0], web_accessible=True, settings=settings.filestorage_settings)
print "writing file : "+storage.path("connectivity","csv")
f=file(storage.path("connectivity","csv"),"w")
for icresult in grrm2.InterconversionResult.all(graph):
    label=_getLabel(icresult)
    f.write("v,"+label+","+utils.uriToUuid(icresult.uri())+"\n")


for iconv in grrm2.Interconversion.all(graph):
    start = grrm2.interconversionStart(iconv).get()[0]
    if grrm2.interconversionStart(iconv).get() is not None:
        start = grrm2.interconversionStart(iconv).get()[0]
    else:
        continue

    if grrm2.interconversionEnd(iconv).get() is not None:
        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:
        submission = ordfm.OriginalSubmission.new(submission_info_subgraph,
                                                  uri="urn:uuid:" +
                                                  options.submission_uuid)
    else:
        print "Previous submission found. overwriting"
        base_graph.remove_context(
            rdflib.URIRef("urn:uuid:" + options.submission_uuid))

    storage = filestorage.ResourceStorage(
        submission,
        web_accessible=False,
        settings=settings.filestorage_settings)
    if storage.readable("submission", "rdf"):
        print "file already present. overwriting"

    shutil.copyfile(options.submission_file, storage.path("submission", "rdf"))

    submission_subgraph = ContextGraph(
        base_graph.store,
        identifier=rdflib.URIRef("urn:uuid:" + options.submission_uuid))
    submission_subgraph.parse(storage.path("submission", "rdf"))

    print "committing"
    submission_subgraph.commit()
    submission_info_subgraph.commit()
    print "done"