Submit multiple .xml files for molecule mechanism

User 4d36853ea2

04-07-2012 20:24:38

Hi!


I currently am creating an online homeowrk applet for chemistry students. The students are supposed to pick a question, and when the question is selected a mechanism is presented. Each mechanism consists of a maximum of 10 smaller marvinsketch windows that when selected, pop out and allow the student to edit the molecule inside. When the student hits the submit button each molecule needs to be saved as a .xml file and stored for later use.


So far, I have set it up so that when there is one molecule and a student hits submit their answer is saved as a .xml file. However, I do not know how to make this work with multiple molecule windows. I am using PHP and Javascript.


I've posted the main code snippet that pertains to this problem below. 


If anyone has advice it would be greatly appreciated!


 


while( $row = mysql_fetch_array($result) ) {


$identifiers[$k] = $row['identifier'];


  echo "<td align = center>";


  echo"  


  <script type='text/javascript' SRC='marvin/marvin.js'></script> 


  <script type='text/javascript'>


  <!--


msketch_name = 'MSketch';


msketch_begin('marvin', 200, 200);


msketch_param('detach', 'hide');


msketch_param('undetachByX', 'false');


msketch_param('menubar', 'false');


msketch_param('mol', ' " . $row['filepath']. "' );


msketch_param('autoscale', 'true');


msketch_param('legacy_lifecycle', 'false');


msketch_end();


     //-->


      </script>";


   echo "</td>";


    $k++;    


    if( $k < $_SESSION['numIDs'] )


      {


echo "<td align= center><img src= marvin/mols-2D/Questions/rxnArrow.jpg alt = 'didn't work'></td>";


      }


    ?>


<script type='text/javascript' SRC='marvin/marvin.js'></script>


  <script language='JavaScript' src='marvin/js2java.js'></script>


  <script type='text/javascript'>


  <!--



    function getMol(format) {


  var s = null;


    if(document.MSketch != null) {


        s = document.MSketch.getMol(format);


    } else {


        alert('Cannot get molecule:\n'+'no JavaScript to Java communication in your browser.\n');


      }


  return s;


}


 


function sendMol() {


    var m = getMol('mrv');


  if(m != null) {


       document.MolForm.mol.value = m;


    document.MolForm.submit();


  } else {


       alert('No molecule to post.');


    }


    return;


}


    //-->


      </script>


 


<p>


 




</body>


 


<?php


 


  }


  ?>


 


  <form name="MolForm" method="post" action="index2.php" enctype = "text/xml">


    <input type="" name='mol' value=""/>


</form>


 


<form name="controlform">


 


    <input type="button" name="send" value="Send" onClick="sendMol()"/>


</form>


</p>


 


 


 


 

ChemAxon 5433b8e56b

06-07-2012 10:21:30

Hi,


you should name every MarvinSketch applet instance differently, so the msketch_name variable should be different for every sketcher which is basically fine to do in the main while cycle, since the javascript variable will have the proper value for the applet tag creation every round. The applet tag creation happens in the msketch_begin...msketch_param...msketch_end methods, and uses the msketch_name variable as the id of the applet, object or embed tag that represents the applet in html.


In this way you will have different id-s for the different applets, and you can get the structures from every one of them with their unique ids. (for example for the applet which has Msketch1 as name you can get the structure with document.Msketch1.getMol() call, or the document.getElementById("Msketch1").getMol() call)


I hope this helps, if you have further questions, please do not hesitate to ask.


Regards,
Istvan

User 4d36853ea2

06-07-2012 22:12:14

Hi Istvan,


Thank you so much! That was very helpful! 


I am now having some problems when submitting. When I press the sumbit button each file is written with the xml data from the last molecule presented on the page. Do you have any suggestions for fixing this?


Thank you again!


Brigitte

ChemAxon 5433b8e56b

09-07-2012 14:46:21

Hi,


if you are using the getMol method as it was written in your previous post, then that may be a problem.


If I were you, I would rather write the getMol method with two parameter, the Msketch object, and the format string, and define it outside the while cycle in the php code, and call it from the onclick event of the submit item with the actual sketcher.


If the problem is not this one, then I need more information about the issue to understand it correctly.


Regards,
Istvan

User 4d36853ea2

11-07-2012 21:05:36

Hi Istvan,


Thank you for your help! I managed to find the source of the problem. 


I have another question though. When I try to get my saved xml file to display in a MarvinView window, no window appears. I have tried stripping the slashes from my file, but it doesn't work. When I add them back in it still doesn't work. I was wondering if you had any adivce for this. I have copied and pasted my code below. The file was saved from a MarvinSketch window in .mrv format. 


 



  echo"


  <script type='text/javascript' SRC='marvin/marvin.js'></script>


<script language='JavaScript' src='marvin/js2java.js'></script>


<script type='text/javascript'>


<!--


var mol2 = '<?php echo $s; ?>';


mview_name = 'MView';


mview_begin('.', 200, 200); 


mview_param('mol', 'testFile1.2.xml');


mview_end();


//-->


</script>";


Thanks,


Brigitte


ChemAxon 5433b8e56b

16-07-2012 13:02:34

For the first sight, I have no clue.


Can you send me the mrv file also, and check whether the applet gives any error messages to the java console?


Regards,
Istvan

ChemAxon 5433b8e56b

16-07-2012 20:51:06

Hi again,


I have got the file, and I assume, the problem is that there are backslash escapes before every quotation mark, and this makes the xml file invalid.


If I am right, there is an escaping before putting the molecule string into the file, or perhaps a double escaping before putting it to a database, or sort of things that ruins the content, and this may cause the jvm or the applet crash in the middle of the initialization process. Can you check this with a corrected xml file?

User 4d36853ea2

16-07-2012 23:18:17

Hi Istvan,


I took your advice and stripped the backslashes from the code, but the MarvinView still doesn't run.


I am getting an error message to the console now though! It is the following:



 


"Java Plug-in 1.6.0_26


Using JRE version 1.6.0_26-b03-384-9M3425 Java HotSpot(TM) 64-Bit Server VM


User home directory = /Users/bharderload: class chemaxon/marvin/applet/JMViewLaunch not found.


java.lang.ClassNotFoundException: chemaxon.marvin.applet.JMViewLaunch


at sun.plugin2.applet.Applet2ClassLoader.findClass(Applet2ClassLoader.java:195)


at sun.plugin2.applet.Plugin2ClassLoader.loadClass0(Plugin2ClassLoader.java:250)


at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Plugin2ClassLoader.java:180)


at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Plugin2ClassLoader.java:161)


at java.lang.ClassLoader.loadClass(ClassLoader.java:247)


at sun.plugin2.applet.Plugin2ClassLoader.loadCode(Plugin2ClassLoader.java:687)


at sun.plugin2.applet.Plugin2Manager.createApplet(Plugin2Manager.java:3046)


at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Plugin2Manager.java:1498)


at java.lang.Thread.run(Thread.java:680)


Exception: java.lang.ClassNotFoundException: chemaxon.marvin.applet.JMViewLaunch"


 



Thanks,


Brigitte

ChemAxon 5433b8e56b

23-07-2012 21:04:44

Hi,


can you describe me how you run the test page?


From the error message it seems to me that your codebase parameter may be wrong, this is the first parameter of mview_begin method, that points to the current directory, this means for the applet that it needs to find the appletlaunch.pack.gz file in the DocumentRoot of your webserver. Is it there?


As I see in your older posts, for a MarvinSketch applet you have set 'marvin' as the codebase value, can this be the cause of the issue?


Regards,
Istvan