Does MolPrinter.setMol(string) have a error?

User 5094e8fc34

12-08-2010 06:25:33

Hi!


I want to create EMF by MolPrinter class.


So, I coded it according to the sample of the following sites.


http://www.chemaxon.com/dotNET/examples/marvin/MoleculeImage/MoleculeImage.cs.html


 


I set the following structure(SDF) by MolPrinter.setMol(string) method.


3-dimethylamino-1,1-di-(2-thienyl)-1-butene
Marvin 05251012162D

17 18 0 0 0 0 999 V2000
oB6WMS4W60
9S4WvR3W60
9S4W-Q1W60
oB6WYQ0W60
oB6WeP+V60
4q7WtDzV60
FC7WGJxV60
LB5WGJxV60
VZ4WtDzVG0
Rx7WcV1W60
v88WoV3W60
-6AW-r3W60
S7BWM62W60
Bn9WZc0WG0
Wi2WMS4W70
0.3896 1.4073 0.0000 R# 0 0 0 0 0 0 0 0 0 0 0 0
1.1630 2.6448 0.0000 R# 0 0 0 0 0 0 0 0 0 0 0 0
10201
20301
30402
40501
50602
60701
70802
80901
50901
40A01
A0B02
B0C01
C0D02
D0E01
A0E01
20F01
F0G01
F0H01
M STY 2 1 SUP 2 SUP
M SAL 1 1 17
M SBL 1 1 18
M SMT 1 Alk
M SAL 2 1 16
M SBL 2 1 17
M SMT 2 Alk
M END




(This structure's group is not expand.)


 


Then, "Alk" was expanded to "R" automatically.


That is bad. Is it bug?


 


When I converted by MolImporter.importMol(string) The above-mentioned structure to Molecule class instance


and set to MolPrinter.setMol(Molecule),


then "Alk" wasn't expanded to "R" automatically.


That is good.


 


When I create PNG,


both MolPrinter.setMol(string) and MolPrinter.setMol(Molecule) are good working.


 


See the attachment Excel file.


 


I hope the same behavior in case createing EMF.


 


I use the Marvin and JChem version 5.3.6 .NET API.


 


Best Regards.

ChemAxon bd13b5bd77

13-08-2010 13:26:51

Hi,


 


could you please send us a sample code that compiles and we can check your problem.


 


Thanks,


Viktor

User 5094e8fc34

16-08-2010 09:58:11

Hi,


Thanks for reply.


Following is sample code.


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using chemaxon.marvin;
using chemaxon.marvin.paint;
using System.Drawing.Imaging;
using System.IO;
using ikvm.awt;
using chemaxon.struc;
using chemaxon.formats;

namespace MolPrinterEmfTest
{
public partial class MolImageForm : Form
{
public MolImageForm()
{
InitializeComponent();
}

private void MolImageForm_Load(object sender, EventArgs e)
{
string molStr = @"
Marvin 05251012162D

17 18 0 0 0 0 999 V2000
oB6WMS4W60
9S4WvR3W60
9S4W-Q1W60
oB6WYQ0W60
oB6WeP+V60
4q7WtDzV60
FC7WGJxV60
LB5WGJxV60
VZ4WtDzVG0
Rx7WcV1W60
v88WoV3W60
-6AW-r3W60
S7BWM62W60
Bn9WZc0WG0
Wi2WMS4W70
0.3896 1.4073 0.0000 R# 0 0 0 0 0 0 0 0 0 0 0 0
1.1630 2.6448 0.0000 R# 0 0 0 0 0 0 0 0 0 0 0 0
10201
20301
30402
40501
50602
60701
70802
80901
50901
40A01
A0B02
B0C01
C0D02
D0E01
A0E01
20F01
F0G01
F0H01
M STY 2 1 SUP 2 SUP
M SAL 1 1 17
M SBL 1 1 18
M SMT 1 Alk
M SAL 2 1 16
M SBL 2 1 17
M SMT 2 Alk
M END
";

SetMoleculeImageUsingMolPrinter(molStr, molStrPictureBox);

Molecule mol = MolImporter.importMol(molStr);
SetMoleculeImageUsingMolPrinter(mol, molculePictureBox);
}

private void SetMoleculeImageUsingMolPrinter(object mol, PictureBox targetPictureBox)
{
Bitmap bmp;
Graphics graphicsMf = null;
Graphics graphics = null;
Metafile mf = null;

try
{
MolPrinter molPrinter = new MolPrinter();
if (mol is Molecule)
molPrinter.setMol((Molecule)mol);
else if (mol is String || mol is string)
molPrinter.setMol((string)mol);
else
return;

bmp = new Bitmap(300, 300, 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, 600, 600), MetafileFrameUnit.Pixel);

graphics = Graphics.FromImage(mf);

NetGraphics g = new NetGraphics(graphics);

molPrinter.setDispopts(molPrinter.getDispopts() | DispOptConsts.__Fields.RGROUPS_FLAG);
java.awt.Rectangle r = new java.awt.Rectangle(300, 300);
molPrinter.setScale(molPrinter.maxScale(r));

molPrinter.paint(g, r);

targetPictureBox.Image = mf;
graphics.Dispose();
bmp.Dispose();


graphicsMf.Dispose();
g.dispose();
g = null;
graphics = null;
graphicsMf = null;
}
finally
{
if (graphics != null)
{
graphics.Dispose();
}
}
}
}
}

 


 


I attached project file.


Thanks.


Cunjing

ChemAxon bd13b5bd77

17-08-2010 13:15:30

I am checking your code and it does not work for any reason, I am back to you asap.


Viktor

User 5094e8fc34

17-08-2010 15:00:42

Hi,


Thank you for your working.


I am looking forward to be solved.


 


Best regards.


cunjing

ChemAxon bd13b5bd77

17-08-2010 19:09:29

Dear Cunjing,


you should call


   Molecule mol = MolImporter.importMol(molStr);
              
         mol.expandSgroups();
   SetMoleculeImageUsingMolPrinter(mol, molculePictureBox);


otherwise the molecule leave it as is. It seems that that is the default behaviour. WHen it is passed as string,


the painter makes a "clean" on it before rendering.


 


 Viktor

User 5094e8fc34

18-08-2010 00:43:29

Dear Viktor.


 


No. No. No.


I don't want expand S-Group automatically by using MolPrinter.setMol(String).


I hope setMol(String)  behave same as setMol(Molecule).


 


Thanks.

ChemAxon bd13b5bd77

18-08-2010 14:09:58

Dear Cunjing,


in the meantime  I passed this issue over to Erika, she is involved more in R/S-Groups,


I think this issue is not reallt related to the .NET solution but to the basic java api.


Thanks,


Viktor

ChemAxon e500b51457

19-08-2010 10:50:16

Dear Cunjing,


We need some more time to find the cause. We will get back with the solution shortly.


Thanks for your patience.


Regards,


Erika.

User 5094e8fc34

20-08-2010 00:42:46

Dear Erika.


Hi,


Thanks for your reply soon.


Regards.


 


Cunjing

ChemAxon bd13b5bd77

24-08-2010 22:22:15

Dear Cunjing,


 


on java side Erika did not manage to reproduce the issue. I try to use her code to reproduce the issue with dotnet or find the difference between her code and our tests.


 


For the time being you can use the workaround I sent to you.


Viktor

ChemAxon bd13b5bd77

25-08-2010 07:33:04

Erika,


please try out with the molPrinter and with the string directly not by passing the imported Molecule object.


molPrinter.setMol(string); The mol string can be found in the forum (code snippet).


Viktor


 

User 5094e8fc34

25-08-2010 08:44:57

Dear Viktor,


 


Thank you for your support.


 


Regards,


 


Cunjing

ChemAxon bd13b5bd77

25-08-2010 16:11:22

Dear Cunjing,


it seems what you reported is an inconsistent work, lets say a kind of bug,


For the time being we highly recommend with Erika you should use MolImporter and with the returned molecule object you should initialize the MolpRinter with, in setMol. In this way the object will give you the desired behaviour.
If you even want to expand the Alk to R explicitly please call the mol.expandSgroups();


The bug has been registered in issue tracking system.


Viktor



 

User 5094e8fc34

26-08-2010 01:08:23

Dear Viktor and Erika


 


 Thank you for your working.


 


Regards.


 


Cunjing

ChemAxon e500b51457

04-10-2010 13:28:00

Dear Cunjing,

The correction will be available in Marvin 5.4.
Can you please confirm if it is working for you?

Best Regards,
Erika

User 5094e8fc34

06-10-2010 01:02:45


Dear Erika,

Thank you for your woking.

Best Regards,
Cunjing