how to get equations form marvin sketch using java?

User 8769aa7b37

01-03-2007 08:58:26

Hi can any body help me , i want to get equations from marvin sketch using java how can i get and how can i insert those equations into the data base

User 870ab5b546

01-03-2007 17:02:47

Set up a Javascript page, thisPage.jsp, that looks something like this:





Code:
<%@ page language="java" %>


<%@ page import="chemaxon.util.HTMLTools"


%>





<%


String molstruct = request.getParameter("molstruct");


if (molstruct != null) {


     System.out.println("Now we can pass this structure to a Java method:");


     System.out.println(molstruct);


}


%>





<html>


<head>


<script src="marvin.js" type="text/javascript"></script>


<script>


    function submitIt() {


        document.thisform.molstruct.value = document.marvin.getMol("mrv");


        document.thisform.submit();


    } // submitIt


</script>


</head>





<body>


    <form name="thisform" action="thisPage.jsp" method="post">


        <input type="hidden" name="molstruct" >


        <script type="text/javascript">


            msketch_name = "marvin";


            msketch_begin("marvin", 410, 320);


            msketch_begin("mol", <%= molstruct != null ? 


                     HTMLTools.convertForJavaScript(molstruct) : "" %>);


            msketch_end();


        </script>


        <input type="submit" value="Submit" onclick="submitIt();">


    </form>


</body>


</html>








You need to have the marvin.js and marvin.jar files handy, as well as the Java class chemaxon.util.HTMLTools and any other Java classes you will need to process the structure.





The example also shows you how to pass the Java variable containing the structure back to Javascript.

User f359e526a1

01-03-2007 18:41:59

Thank you, seems you are more vigilant then the chemaxon staff!

ChemAxon 7c2d26e5cf

01-03-2007 21:16:55

Just a few notes for Bob's example.


- The attached example is a JSP (Java Server Page) example (not a JavaScript page). Bob might mistype it.


- To run Marvin applet, the whole Marvin Applets package is required (not only marvin.js and (j)marvin.jar).


The chemaxon.util.HTMLTools class is in the jchem.jar (that is part of the JChem package). To be able to import HTMLTools into the JSP code, you have to insert it in the CLASSPATH of Tomcat (or your web server that process your JSP pages).





I suggest to take a look at JChem examples where you can find live demo for inserting structure into a DB:


http://www.chemaxon.com/jchem/examples/jsp1_x/index.jsp


(After logging in, choose the "Inserting" button on "Search Result" page. The source of JSP examples are available in the JChem package.

User 8769aa7b37

02-03-2007 09:03:44

I used ur code it works fine if i removed the below code


msketch_begin("mol", <%= molstruct != null ?


HTMLTools.convertForJavaScript(molstruct) : "" %>);


it also displays the structure on the console but not on the sketch


if i include the above code only the submit button is dispalying on the browser.I am having all the required jar files.Help me with required information.

User 870ab5b546

02-03-2007 14:04:06

Sorry, that line should be:





msketch_begin("mol", "<%= molstruct != null ?


HTMLTools.convertForJavaScript(molstruct) : "" %>");





That is, the string returned from the Java needs to be enclosed in quotes for the Javascript to read it.

User 8769aa7b37

02-03-2007 15:30:51

Hi bob,


Thanks for your reply but still i am having a small problem.I used your code,the structure of the molecule was displaying in the console but i am not getting any thing in the browser.Can u please help me with a sample code.

User 870ab5b546

02-03-2007 20:09:34

My bad again. Here's the code again, confirmed to work:





Code:
<%@ page language="java" %>


<%@ page import="chemaxon.util.HTMLTools"


%>





<%


String molstruct = request.getParameter("molstruct");


if (molstruct != null) {


     System.out.println("Now we can pass this structure to a Java method:");


     System.out.println(molstruct);


}


%>





<html>


<head>


<script src="/nosession/marvin/marvin.js" type="text/javascript"></script>


<script>


    function submitIt() {


        document.thisform.molstruct.value = document.marvin.getMol("mrv");


        document.thisform.submit();


    } // submitIt


</script>


</head>





<body>


    <form name="thisform" action="testMarvin.jsp" method="post">


        <input type="hidden" name="molstruct" >


        <table>


        <tr><td>


        <script type="text/javascript">


            msketch_name = "marvin";


            msketch_begin("/nosession/marvin", 410, 320);


            msketch_param("mol", "<%= molstruct != null ?


                     HTMLTools.convertForJavaScript(molstruct) : "" %>");


            msketch_end();


        </script>


        </td></tr>


        <tr><td>


        <input type="submit" value="Submit" onclick="submitIt();">


        </td></tr></table>


    </form>


</body>


</html>

User 870ab5b546

02-03-2007 20:27:12

I should mention that you will have to change these lines:





Code:
<script src="/nosession/marvin/marvin.js" type="text/javascript"></script>



replace /nosession/marvin/marvin.js with the actual path to marvin.js on your machine





Code:
<form name="thisform" action="testMarvin.jsp" method="post">



replace testMarvin.jsp with the name of this jsp page in your system





Code:
 msketch_begin("/nosession/marvin", 410, 320);



replace /nosession/marvin with the actual path to Marvin in your system.

ChemAxon 7c2d26e5cf

02-03-2007 22:02:38

Bob, thanks for the help. I am always happy when users help each other.





Dear Satish,


I suggest you to see the Marvin applets example where you can learn how to call applet and access it from JavaScript, step by step:


MarvinSketch Applet Examples


Especially, the first example is recommended where you can learn how to insert an applet into a web page by "marvin.js".


http://www.chemaxon.com/marvin/examples/applets/example-sketch1.1.html