User e3b516b760
17-03-2011 10:10:01
Hello,
Is there a function or method that takes .mol file as input and outputs it into InChi or smiles format?
A sample code will be much helpful.
Thanks
User e3b516b760
17-03-2011 10:10:01
Hello,
Is there a function or method that takes .mol file as input and outputs it into InChi or smiles format?
A sample code will be much helpful.
Thanks
ChemAxon bd13b5bd77
18-03-2011 14:10:15
Dear Srikanth,
sending you an example soon.
Viktor
ChemAxon bd13b5bd77
18-03-2011 17:30:35
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Conversion {
class Program {
static void Main(string[] args) {
string mol =
"" + "\r\n" +
" Mrv0541 03181112082D" + "\r\n" +
"" + "\r\n" +
" 2 1 0 0 0 0 999 V2000" + "\r\n" +
" -8.1616 3.8598 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0" + "\r\n" +
" -7.4471 4.2723 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0" + "\r\n" +
" 1 2 1 0 0 0 0" + "\r\n" +
"M END";
var converter = new ChemAxon.NET.IKVM.Chemistry.MolConverter();
var format = converter.RecognizeFormat(mol);
var smiles = converter.ConvertToFormat(mol, format, ChemAxon.NET.Base.Marvin.Formats.SMILESFormat.GetShortName());
var inchi = converter.ConvertToFormat(mol, format, ChemAxon.NET.Base.Marvin.Formats.InChiFormat.GetShortName());
}
}
}
ChemAxon bd13b5bd77
18-03-2011 18:13:06
Please add reference of
ChemAxon.NET.* dlls
User e3b516b760
28-03-2011 12:36:35
HI,
Thanks a lot for the reply, Just wanted to clear a small doubt, Is
there any memory leak in the functions because when I stop the debugging
of the program the entire software (VS 2010) is crashing.
User e3b516b760
28-03-2011 12:38:28
This is the code I used:
private void button1_Click(object sender, EventArgs e)
{
moleculeContentTxt.Text ="" + "\r\n" +
" Mrv0541 03181112082D" + "\r\n" +
"" + "\r\n" +
" 2 1 0 0 0 0 999 V2000" + "\r\n" +
" -8.1616 3.8598 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0" + "\r\n" +
" -7.4471 4.2723 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0" + "\r\n" +
" 1 2 1 0 0 0 0" + "\r\n" +
"M END";
Molecule mol1 = MolImporter.importMol(moleculeContentTxt.Text);
SetMoleculeImageUsingtoBinFormat1(mol1);
var converter = new ChemAxon.NET.IKVM.Chemistry.MolConverter();
var format = converter.RecognizeFormat(moleculeContentTxt.Text);
var smiles = converter.ConvertToFormat(moleculeContentTxt.Text, format, ChemAxon.NET.Base.Marvin.Formats.SMILESFormat.GetShortName());
var inchi = converter.ConvertToFormat(moleculeContentTxt.Text, format, ChemAxon.NET.Base.Marvin.Formats.InChiFormat.GetShortName());
textBox2.Text = inchi;
Molecule mol = MolImporter.importMol(textBox2.Text);
SetMoleculeImageUsingMolPrinter(mol);
}
public void SetMoleculeImageUsingMolPrinter(Molecule mol)
{
Bitmap bmp;
Bitmap bmp1;
Graphics graphicsMf = null;
Graphics graphics = null;
Metafile mf = null;
Metafile mf1 = null;
pictureBox1.Image = null;
try
{
MolPrinter molPrinter = new MolPrinter();
molPrinter.setMol(mol);
bmp = new Bitmap(700, 700, PixelFormat.Format32bppArgb);
graphicsMf = Graphics.FromImage(bmp);
IntPtr hdc = graphicsMf.GetHdc();
//Creating double size rectangle fixes some drawing issues.
mf = new Metafile(new MemoryStream(), hdc, new RectangleF(0, 0, 700, 700), MetafileFrameUnit.Pixel);
graphics = Graphics.FromImage(mf);
NetGraphics g = new NetGraphics(graphics);
//molPrinter.setDispopts(molPrinter.getDispopts() | DispOptConsts.__Fields.ATMAP_FLAG);
molPrinter.setDispopts(molPrinter.getDispopts() | DispOptConsts.__Fields.RGROUPS_FLAG);
java.awt.Rectangle r = new java.awt.Rectangle(580, 320);
molPrinter.setScale(molPrinter.maxScale(r));
molPrinter.paint(g, r);
pictureBox1.Image = mf;
//mf.Dispose();
graphics.Dispose();
bmp.Dispose();
//graphicsMf.ReleaseHdc();
graphicsMf.Dispose();
g.dispose();
g = null;
//mf = null;
graphics = null;
graphicsMf = null;
graphics.Dispose();
bmp.Dispose();
}
catch
{
}
}
private void SetMoleculeImageUsingtoBinFormat1(Molecule mol)
{
try
{
byte[] imageBytes = mol.toBinFormat("jpeg:h320,w580");
pictureBox2.Image = Image.FromStream(new MemoryStream(imageBytes));
}
catch { }
}
ChemAxon bd13b5bd77
28-03-2011 20:41:18
Sorry I am using VS 2008 ( I am "old-fashioned" :) ),
and the code you sent me works fine, obviously I had to set up the UI elements to get a compiled version.