Capturing Stereochemistry

User 3d7989d1a7

11-12-2007 18:30:20

I am writing a tutorial for undergraduate organic chemistry students involving the addition reactions of alkenes. Clearly this involves stereochemistry. MarvinSketch can identify the absolute configurations (R/S) and display it on the screen. Is there any way I can capture that in javascript and use it as a variable to compare the student answer to the right answers?





Or is there another way to do that comparison? The problem is that we sometimes need hydrogens so I cannot turn H off, but I cannot anticipate the ways students may put hydogens with wedges at achiral centers. It seems best to just capture the absolute stereochemistry of whatever they have drawn.

User 3d7989d1a7

11-12-2007 18:47:25

I could also work with capturing the name with stereochemical designation.

User 870ab5b546

12-12-2007 03:27:03

I don't think there's any way to do what you want in Javascript only. It's easy to do in Java, though, so you should use a JSP page that includes both Java and Javascript.





See, for example, this page. If you View Source, you can see how the Javascript code in this file is designed. There is also Java code (not visible through View Source) in this file which collects the MOL file as a Java String (and also the desired task) and processes it with Marvin and JChem methods.





Code:
<%


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


...


%>

ChemAxon 7c2d26e5cf

12-12-2007 08:44:20

I've consulted with my colleagues.


They have got two tips to compare:


- Gets the IUPAC name of the drawn structure from the applet:


Code:
String s = JMSketch.getMol("name")



- Retrieve the unique SMILES of the structure from the applet:


Code:
String s = JMSketch.getMol("smiles:u")

User 870ab5b546

12-12-2007 13:27:44

OK, so I was wrong. ;-)

User 3d7989d1a7

12-12-2007 23:44:02

I appreciate the comments. But.... Always a but:-)





Using "String s =" in Javascript bombs. "s=" or "var s =" works.





The problem with var s = JMSketch.getMol("smiles") is that it picks up all of the hydrogens that a user might want to put in. I cannot plan for that.





The var s = JMSketch.getMol("name") worked at first, but I have not been able to get to work repeatedly and reliably. Is there a licensing issue with getting names. For me alert(s) simply returns "undefined".





However, a google search on "Marvin getMol() options" led me to:


var s = JMSketch.getMol("smiles:a-H").





This does what I want: removes all of the extraneous hydrogens for evaluation of the smiles string.








User 870ab5b546

13-12-2007 02:39:46

Of course using "String s = " in Javascript bombs. It's a Java command. Javascript doesn't define variable types like Java does.





To make a JSP page that has both Javascript and Java, begin it with,





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


<%@ page import="chemaxon.struc.Molecule,


                chemaxon.struc.MolAtom,


                chemaxon.struc.MolBond,


                chemaxon.util.HTMLTools,


                java.math.*"


%>


<%


String moleculeStr = request.getParameter("molecule");


[more Java code here; classes need to be imported above]


%>





<html> 


<head> 


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


<script type="text/javascript">


    function submitIt() {


        var strMolecule = document.Marvin.getMol("mrv");


        document.tester.molecule.value = strMolecule;


        document.tester.submit();


    }


</script>


</head>





<body>


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


<input type="hidden" name="molecule" value="">


...


    <script type="text/javascript">


        msketch_name="Marvin";


        msketch_begin("/nosession/marvin", 400, 400);


        // arguments: CODEBASE, WIDTH, HEIGHT


        msketch_param("preload","SmilesExport,MolExport,Parity");


        <% if (moleculeStr != null) { %>


            msketch_param("mol","<%= HTMLTools.convertForJavaScript(moleculeStr) %>");


        <% } %>


        msketch_param("molbg", "#ffffff");


        msketch_param("atomsize", "0.533");


            // font size -> 16 pt (parameter = points/30)


        msketch_param("scale", "32");  // C-C bond length in pixels


        msketch_param("extraBonds","wedge,either");


        msketch_param("implicitH", "heteroterm");


        msketch_end();


    </script>





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


</form>


   


</body>


</html>


User 3d7989d1a7

13-12-2007 03:09:14

Thanks Bob: You are really up early -- or still up late:-)





I am not a java programmer. Appreciate the advice, but I think I will stick with my little (smiles:a-H).





Oe of the problems is that I have no sense of what kinds of things you can get using the getMol() function. I just tried your mrv and see lots of useful information. Where might this all be documented? I do not see it in the Examples for the applet or in the parameters that are listed associated with that.

ChemAxon 7c2d26e5cf

13-12-2007 10:09:17

Yes, you are right. "String" is not needed in the JavaScript statement.

User 3d7989d1a7

13-12-2007 11:25:49

This then brings up the question I posed to Bob last night (my time). Where do I find documentation, other than the examples that come with Marvin? In particular, what can I get from the applet using getMol()? And why won't "name" work for me? And what has to be special licensed vs. academic licensed? I really just stumbled across the "smiles:a-H" solution by googling.

User 870ab5b546

13-12-2007 13:24:32

Marvin file formats, including MRV, are documented here. The documentation of the MRV file format is complete, though difficult to read. The MOL file format is documented here; I believe you have to register with MDL to access this document.





We used to use the MOL file format, but we've now switched to MRV. Basically, the amount of information that can be stored increases from SMILES to MOL to MRV. Shortcut groups such as Ph and Et can be stored in MOL or MRV but not SMILES. Graphical information such as electron-flow arrows, boxes, colors, etc. can be stored in MRV but not in SMILES or MOL. The downside of the MRV format is that it is a ChemAxon-only format; if you're planning to use Marvin structures in other programs, store them as MOL or SMILES.





I understand your reluctance to venture into Java, but it's really not hard to learn if you already have some programming experience in Javascript, and it gives you access to the whole JChem library of cheminformatics methods. You can import an MRV or MOL or SMILES structure into a Molecule object, then get information about or manipulate specific bonds (called MolBonds) and atoms (called MolAtoms) in that Molecule. You can put all the Java code in the same JSP document as your Javascript.





You can find the JChem documentation here. The lower left frame lists all the classes (variable types such as Molecule, String, etc.); clicking on one of those links brings you to the set of methods that you can use to do operations on members of that class. I suggest you examine the Molecule, MolAtom, MolBond, and MolImporter classes. Before you do that, it would behoove you to find and read a short tutorial on the basic concepts behind Java classes (a.k.a. objects), if you do not already have that knowledge.





The ChemAxon folks can explain why "name" won't work for you; we have never used that function. My understanding of the licenses is that the academic license covers everything. If you have an academic license, perhaps your HTML page is simply not configured to read it correctly.





I wasn't up that late. I am in the USA, and the posted times are in Budapest time.

User 870ab5b546

13-12-2007 14:41:18

Here, I wrote a JSP page for you that uses JChem to get the CIP configuration of each asymmetric atom in a compound and displays it to the student. You can use it as a starting point for learning Java in general and JChem in particular.





For what you want to do, it would be better to use one of JChem's sophisticated search functions that can compare and match structures to one another, including their stereochemistry. See this page for a JSP example of how you can compare structures to one another. You can grab a student's molecule and compare it to one that you have previously constructed and whose SMILES string is hardwired into the Java code.