1)Opsin0.5.3でIUPAC名をCMLに変換
2)CDKでCMLをIMoleculeに変換
3)CDKでIMoleculeからMolファイル形式に変換
4)OpenBabelでMolファイルからSmilesに変換
フォームアプリケーション的はコードを書きます。Smilesにするだけなら2次元構造は必要なないのですが、忘記録的に入れときます。この流れがdelegateでも動いたらOkですな。
using System;
using System.Windows.Forms;
using System.IO;
using System.Diagnostics;
using org.openscience.cdk.io;
using org.openscience.cdk;
using org.openscience.cdk.interfaces;
using org.openscience.cdk.layout;
using java.io;
using uk.ac.cam.ch.wwmm.opsin;
using OpenBabel;
namespace OpsinTest
{
public partial class Form1 : Form
{
NameToStructure nts = null;
public Form1()
{
InitializeComponent();
nts = new NameToStructure();
}
private void button3_Click(object sender, EventArgs e)
{
string IUPAC = textBox1.Text;
try
{
textBox2.Text = "";
Application.DoEvents();
// Create CML from IUPAC name (Opsin)
string cml = nts.parseToCML(IUPAC).toXML();
// Convert CML to IMolecule (CDK)
StringBufferInputStream str_stream = new StringBufferInputStream(cml);
CMLReader cmlr = new CMLReader();
cmlr.setReader(str_stream);
ChemFile chemFile = new ChemFile();
ChemFile chem = (ChemFile)cmlr.read(chemFile);
IMolecule mol = chem.getChemSequence(0).getChemModel(0).getMoleculeSet().getMolecule(0);
// Convert from IMolecule to SD (CDK)
java.io.StringWriter sww = new java.io.StringWriter();
MDLWriter mw = new MDLWriter(sww);
StructureDiagramGenerator sdg = new StructureDiagramGenerator();
sdg.setMolecule(mol);
sdg.generateCoordinates();
mol = sdg.getMolecule();
mw.write(mol);
string sd = sww.toString();
// Convert from SD to smiles (OpenBabel)
OBMol obMol = new OBMol();
OBConversion obConv = new OBConversion();
if (!obConv.SetInAndOutFormats("mol", "can")) { return; }
if (!obConv.ReadString(obMol, sd)) { return; }
textBox2.Text = obConv.WriteString(obMol);
obMol.Dispose();
obConv.Dispose();
obMol = null;
obConv = null;
}
catch (Exception ex)
{
string mes = ex.Message;
textBox2.Text = mes;
}
}
}
}
0 件のコメント:
コメントを投稿