Ketcher hand over a mol file by c# application?

94 views
Skip to first unread message

gno...@web.de

unread,
Jun 13, 2015, 4:12:54 PM6/13/15
to indig...@googlegroups.com
Hello,

I like to use Ketcher in my c# application by using a webbrowser control. Is there a way to hand over mol files by c#? Sorry, I have no java oder html skills, so this concern is not so clear for me :-|

An easy way could be reding the mol file from a local disc. So I write the mol file by c# to disc and refresh my webbrowser control und the html page with ketcher sould read and display this file?  Sorry I'm unable to change the demo pages to read from a local file:-| Or is ther a better way to handle this?

I look forward to any tips an informations!

Kind reguards
Marco

Nikolay_...@epam.com

unread,
Jun 14, 2015, 3:35:13 PM6/14/15
to indig...@googlegroups.com
Hi, Marco,

I'm not sure that I got properly what you want to archive. How will c# part interact with the webbrowser? Do you intend to embed browser view in application or the .NET part will act as a server? Browser's JS cannot read files from disk due obvious security reasons but there is several ways to delegate this task to C#.

Mit besten Grüßen,
Kolya

Marco Gnotke

unread,
Jun 15, 2015, 12:48:13 AM6/15/15
to indig...@googlegroups.com, Nikolay_...@epam.com
Hello!

Tahank you for your reply! I have this html source:
Enter code here...<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
   
<head>
       
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
       
<script type="text/javascript" src="raphael.js"></script>
       
<script type="text/javascript" src="util/common.js"></script>
       
<script type="text/javascript" src="util/vec2.js"></script>
       
<script type="text/javascript" src="util/set.js"></script>
       
<script type="text/javascript" src="util/map.js"></script>
       
<script type="text/javascript" src="util/pool.js"></script>
       
<script type="text/javascript" src="chem/element.js"></script>
       
<script type="text/javascript" src="chem/sgroup.js"></script>
       
<script type="text/javascript" src="chem/struct.js"></script>
       
<script type="text/javascript" src="chem/struct_valence.js"></script>
       
<script type="text/javascript" src="chem/molfile.js"></script>
       
<script type="text/javascript" src="prototype-min.js"></script>
       
<script type="text/javascript" src="chem/dfs.js"></script>
       
<script type="text/javascript" src="chem/smiles.js"></script>
       
<script type="text/javascript" src="rnd/events.js"></script>
       
<script type="text/javascript" src="rnd/visel.js"></script>
       
<script type="text/javascript" src="rnd/restruct.js"></script>
       
<script type="text/javascript" src="rnd/restruct_rendering.js"></script>
       
<script type="text/javascript" src="rnd/render.js"></script>
       
<script type="text/javascript" src="ketcher.js"></script>
       
<title>Ketcher: Example</title>
    </
head>
   
<body onload="rrr=ketcher.showMolfileOpts('client_area', $('mf3').innerHTML, 100, {'autoScale':true, 'ignoreMouseEvents':true});">
       
<div id="client_area" style="width:640px;height:480px"></div>
       
<p id="mf3" style="display:none">
 
Marvin  09211002102D

 
0  0  0     0  0            999 V3000
M  V30
BEGIN CTAB
M  V30 COUNTS
32 34 0 0 0
M  V30
BEGIN ATOM
M  V30
1 C -0.1086 -2.4987 0 0
M  V30
2 N 1.2339 -4.8265 0 0 CHG=1
M  V30
3 C -0.1086 -4.0426 0 0
M  V30
4 C -1.4355 -1.7304 0 0
M  V30
5 N 5.261 -4.0118 0 0 RAD=3
M  V30
6 C -1.4355 -0.1941 0 0
M  V30
7 N 2.5762 -2.483 0 0
M  V30
8 C 1.2339 -1.7147 0 0
M  V30
9 O 1.2339 -6.3629 0 0 CHG=-1
M  V30
10 C 2.584 -4.0195 0 0
M  V30
11 A 5.2455 -2.4675 0 0 CFG=3
M  V30
12 C 3.9109 -4.7876 0 0
M  V30
13 C 6.5878 -4.78 0 0
M  V30
14 O -2.7701 0.5742 0 0 MASS=18
M  V30
15 C 3.903 -1.7073 0 0
M  V30
16 C -0.1086 0.5742 0 0 CFG=1
M  V30
17 C -1.4355 -4.811 0 0
M  V30
18 C -2.7701 -2.4987 0 0
M  V30
19 C -2.7701 -4.0426 0 0 RAD=2
M  V30
20 C 6.5878 -6.3241 0 0
M  V30
21 C 7.9149 -4.0118 0 0
M  V30
22 [C,N,O] 1.226 -0.1941 0 0
M  V30
23 C 9.2495 -4.78 0 0
M  V30
24 C 7.9149 -7.0922 0 0
M  V30
25 C 9.2495 -6.3241 0 0
M  V30
26 C 5.7594 -1.0158 0 0
M  V30
27 C 6.7646 -2.7207 0 0
M  V30
28 C -0.1107 2.1142 0 0 CHG=2
M  V30
29 C 1.224 1.3459 0 0
M  V30
30 C -4.1033 -1.7278 0 0 RAD=1
M  V30
31 Fe -1.4334 -6.351 0 0 MASS=56
M  V30
32 "NOT [Cl,Br,I]" 4.07 1.485 0 0
M  V30
END ATOM
M  V30
BEGIN BOND
M  V30
1 1 2 3
M  V30
2 2 3 1
M  V30
3 1 4 1
M  V30
4 1 5 12
M  V30
5 1 6 4
M  V30
6 1 7 8
M  V30
7 1 8 1
M  V30
8 1 9 2
M  V30
9 2 10 2
M  V30
10 1 11 15
M  V30
11 1 12 10
M  V30
12 1 13 5
M  V30
13 4 6 14
M  V30
14 1 10 7
M  V30
15 1 15 7
M  V30
16 1 16 6
M  V30
17 1 17 3
M  V30
18 2 18 4
M  V30
19 1 19 18
M  V30
20 4 20 13
M  V30
21 4 21 13
M  V30
22 1 22 16
M  V30
23 4 23 21
M  V30
24 4 24 20
M  V30
25 4 25 24
M  V30
26 2 17 19
M  V30
27 1 11 5 CFG=1
M  V30
28 4 25 23
M  V30
29 1 11 26 CFG=3
M  V30
30 1 11 27 CFG=2
M  V30
31 8 16 28
M  V30
32 1 16 29 CFG=1
M  V30
33 1 18 30
M  V30
34 1 17 31
M  V30
END BOND
M  V30
END CTAB
M  
END
</p>
    </
body>
</html>


That does exactly what i need.

My idear is to replace the <p></p> area to a java script function like  <p>funktion{ read \ketcherfolder\molfile.mol</p>

So my c# application could override the file and than call webbrowser refresh. Is it possible to do that? It would be very convenient for my application.

Nikolay Kuznetsov

unread,
Jun 16, 2015, 2:55:13 PM6/16/15
to Marco Gnotke, indig...@googlegroups.com

Hi Marco,

 

As was mentioned above Javascript cannot read files from disk by its own. However you could do it from your C# application and pass the contents to the webcontrol. For example you could generate the html source dynamically replacing the content of the <p></p> area and then put the string to the webcontrol or you could pass some code to invoke it from javascript. It depends of your needs.

 

Hope it helps,

Kolya

Marco Gnotke

unread,
Jun 16, 2015, 5:32:25 PM6/16/15
to indig...@googlegroups.com
Hi Kolya,

thank you very much for this tip! More simply is often the best way :-)

Cheers!
Marco

Marco Gnotke

unread,
Jun 17, 2015, 12:59:03 AM6/17/15
to indig...@googlegroups.com
Hello,

back again. The overwriting runs pretty good. But when I start the html File in a .Net WebControl I got an error in script molfile in Line 33.

chem.Molfile.partitionLine = function (/*string*/ str, /*array of int*/ parts, /*bool*/ withspace)
{
   
var res = [];
   
for (var i = 0, shift = 0; i < parts.length; ++i)
   
{
        res
.push(str.slice(shift, shift + parts[i]));
       
if (withspace)
            shift
++;
        shift
+= parts[i];
   
}
   
return res;
};


The html file ist basicly ok. When I start it with FireFox oder Internet Explorer ist runs as exspected. Have you got an idear what can be the problem?

Nikolay Kuznetsov

unread,
Jun 18, 2015, 8:12:20 AM6/18/15
to indig...@googlegroups.com, Marco Gnotke

Hi,

 

The Molfiles are very whitespace sensitive. You know, every extra whitespace or trimmed linebreak can destroy the layout completely. In other hand, according to HTML spec, the whitespaces around the "raw text elements" are stripped except some special cases. I cannot say it for sure as I don't see your code, but I guess the root of evil lies there. You could try to replace `<p>` tag with something like `<pre>` or `<textarea>` (refer the spec and hope that IE guys do its job well) or encode the Molfile directly in a script.

 

Cheers,

Kolya.

> >> <http://stackoverflow.com/a/3694080/1206628>. It depends of your needs.

Marco Gnotke

unread,
Jun 21, 2015, 3:48:59 AM6/21/15
to indig...@googlegroups.com, gno...@web.de
Hello Kolya,

the problem ist solved. I changed my standard Visual Studio WebBrowser to a third party component. Now I have what I need! Thank you very much for your hepl!

Kind regards
Marco
Reply all
Reply to author
Forward
0 new messages