Drkcore

30 06 2008 chemoinformatics jython opsin Tweet

jython+web.pyでお手軽Webアプリ

jython+web.pyがお手軽で、ちょっとしたことをやるならいい感じ。

jythonのosモジュールにはfstatがないのでtrunkのSimpleHTTPServerの静的ファイルの転送ができない。そのため、2.2.1のSimpleHTTPServerと入れ替えた。

import java.io.StringReader as StringReader
import org.openscience.cdk.interfaces.IMolecule
import org.openscience.cdk.io.CMLReader as CMLReader
import org.openscience.cdk.ChemFile as ChemFile
import org.openscience.cdk.layout.StructureDiagramGenerator as StructureDiagramGenerator
import uk.ac.cam.ch.wwmm.opsin as opsin
import net.sf.structure.cdk.util.ImageKit as ImageKit

import web

urls = (
    '/(.*)', 'img2d' 
)

class img2d:       
    def GET(self, name):
        cml = opsin.NameToStructure().parseToCML(name).toXML()

        str_reader = StringReader(cml);
        cmlr = CMLReader()
        cmlr.setReader(str_reader)
        chem = cmlr.read(ChemFile());
        mol = chem.getChemSequence(0).getChemModel(0).getSetOfMolecules().getMolecule(0)

        sdg = StructureDiagramGenerator()
        sdg.setMolecule(mol)
        sdg.generateCoordinates()
        mol = sdg.getMolecule()

        ImageKit.writePNG(mol, 300, 300, "./static/test.png")
        print '<h1>' + name + '</h1>' + '<img src="/static/test.png" />'

if __name__ == "__main__": web.run(urls, globals())

http://localhost:8080/(2,3-diethyl-benzyl)-isobutanolというURLにアクセスすると、IUPACを2次元構造に変換していい感じに描画して表示してくれる。

opsin_web

ImageKitが必ずファイルに出力するのでテンポラリのファイルを作ればいいのだけど、とりあえず動く事を確認したかったので決めうちの名前で。

About

  • もう5年目(wishlistありマス♡)
  • 最近はPythonとDeepLearning
  • 日本酒自粛中
  • ドラムンベースからミニマルまで
  • ポケモンGOゆるめ

Tag

Python Deep Learning javascript chemoinformatics Emacs sake and more...

Ad

© kzfm 2003-2021