Integrating JChembase with another web application

User cbef711ba6

24-03-2011 05:39:34

Hi,


I am developing a web application where I need to integrate JChembase for structural search similar to the following weblink


http://chem.sis.nlm.nih.gov/chemidplus/


Do I need to write extensive coding for this integration?


Could you please help me with some brief steps for this integration or if possible, with some sample code.


My entire project is in Java environment.


I am runnning on tight timelines. I am more than happy for a quick answer.


 


Thanks......


Peter

ChemAxon e274e1bada

24-03-2011 08:42:19

Hi Peter,


we have two advanced examples which show how is it possible to create web based chemical database search application with JChem Base. Both of them are open source, and free to use.


The first is a JSP example, it is part of the JChem distribution, you can fin it in the examples/db_search directory.
You can also find the online version on our website: http://www.chemaxon.com/jchem/examples/db_search/index.jsp


The second is a Web Service based AJAX example, it is part of the JChem Web Services product. Here is the online version: http://www.chemaxon.com/ajax/


Regards, Edvard

User cbef711ba6

24-03-2011 11:01:03

Hi Edvard,


Thanks for the swift reply.


I have seen your example on your site. But not sure how to integrate it with my web application similar to  http://chem.sis.nlm.nih.gov/chemidplus/


 


Any help on this.


Thanks...


Peter


 


 


 

User c1ce6b3d19

24-03-2011 11:13:39

Peter,


Which parts of the US National Library of Medicine website do you want to emulate?


For example, if you want to integrate the Marvin applet into your webpage, I would start here:


http://www.chemaxon.com/marvin/help/developer/index.html


 


For a good start with using JChemBase in a web application, this documentation link may help.


http://www.chemaxon.com/jchem/doc/dev/java/intro/index.html


 


This link has information and some code snippets of searching with JChemSearch and the search types. 


http://www.chemaxon.com/jchem/doc/dev/search/index.html


 


Search the chemaxon website for more in-depth documentation.  With more precise specifications, we can also point you to more relevant sources.


Jon


 

User cbef711ba6

24-03-2011 12:02:31

Hi Jon,


I would like to emulate the enclosed snappy of the site with search capability.


Thanks...


Peter

User c1ce6b3d19

24-03-2011 12:53:39

Peter,


Thanks for the further info. 


It looks like you want to embed a marvin sketch applet for drawing a structure.  Our searching API has many types of structure search (superstructure, substructure, exact, similarity, etc.) so be sure to research the types so that you match what you want to provide on your site.   Structure search hits are returned in a number of structure or image formats.  Displaying structures can be done with simple image output (jpg, png, etc.) or the marvin view applet can be used for simple and complex viewing.


The links provided below are great starting points in the documentation for using our software.  As Edvard stated earlier, the examples are also a good place to grab some code and alter it to fit your site's design.


Jon

User cbef711ba6

25-03-2011 06:05:01

Jon,


Thanks........ :)

User cbef711ba6

14-04-2011 14:05:07

 Hi Jon,


Thanks for the help I could able to integrate Jchem search with my
application. But one small issue, I get my results in mview applet. How do I
convert the resultset to an image format (jgp or png)?


Can you help me on this.


Peter

User c1ce6b3d19

14-04-2011 14:38:45

Peter,


I'm glad you could find a way to integrate with your application.  There are many ways to create images of your molecules.  Perhaps you can tell us what approach you ended up using and we can point you to further resources.

User cbef711ba6

15-04-2011 07:13:58

Jon,


I have included the same code of db_search example (from the link you have provided) in my code. I get the similar output in Mview applet as in the example. Now I want the output in image format rather than in a mview applet.


Could you help with a sample code for getting output (result) in image format.


Peter

ChemAxon a9ded07333

22-04-2011 14:27:25

Hi Peter,


If you know the cd_id of the structure in database you may use the following code excerpt:


<% String pictureString = "<img src=\"./img.jsp?cd_id=" + cd_id +"\">";  %>
<tr>
    <td width="20%">
        <%= pictureString%>
    </td>
</tr>

Then you need to implement img.jsp that will return the images based on cd_id parameter (sorry for superfluous imports, it's just part of a bigger jsp).


<%@ page import="
java.sql.*,
java.util.Vector,
java.util.Arrays,
chemaxon.jchem.db.*,
chemaxon.util.*,
chemaxon.sss.search.JChemSearchOptions,
chemaxon.license.*,
chemaxon.formats.*,
javax.xml.parsers.DocumentBuilder,
javax.xml.parsers.DocumentBuilderFactory,
javax.xml.parsers.ParserConfigurationException,
java.io.*,
javax.servlet.*"
%><%@ include file="init.jsp" %><%
    ConnectionHandler ch = (ConnectionHandler)session.getAttribute(sessionVarPrefix+"ch");

    if((ch==null)||(!ch.isConnected())) {

    ch = new ConnectionHandler();
    ch.setDriver(driver);
    ch.setUrl(url);
    ch.setLoginName(username);
    ch.setPassword(password);
    ch.setPropertyTable(propertyTableName);

    ch.connectToDatabase();

    session.setAttribute(sessionVarPrefix+"ch",ch);

    }

    Connection con=ch.getConnection();

    String sql =
    "SELECT " +
    structureTableName + ".cd_structure " +
    "FROM "+ structureTableName +
    " WHERE " +
    structureTableName + ".cd_id = ?";
    PreparedStatement pstmt = con.prepareStatement(sql);
    try {
    pstmt.setInt(1, Integer.valueOf(request.getParameter("cd_id")));
    ResultSet rs = pstmt.executeQuery();
    try {
        if(rs.next()) {
        byte[] molBytes = DatabaseTools.readBytes(rs, 1);
        byte[] pictureBytes = MolImporter.importMol(molBytes).toBinFormat("jpeg:setcolors,w300,h200,Q90");
        OutputStream outs = response.getOutputStream();
        response.setHeader("Content-type", "image/jpg");
        outs.flush();
        outs.write(pictureBytes, 0, pictureBytes.length);
        outs.close();
        }
    } finally {
        rs.close();
    }

    } finally {
    pstmt.close();
    }
%>

Best regards,
Tamas

User cbef711ba6

05-05-2011 10:53:35

Hi Tamas,


Thank you.


I have already used generate image.jsp code & it worked well. Is it similar code to that? I will try this as well.


Peter

User cbef711ba6

06-05-2011 08:08:32

Hi Guys,


The given code works.


Thanks a lot for the help.


Peter