Refresh Molecule in JSME Editor


How to refresh (read and reset) molecule created in JSME editor with the Web server?



If you want refresh molecule properties displayed in the JSME editor, you can use a PHP script on the Web server to read and reset the molecule structure in the JSME editor.

1. Create an HTML form with an input field for submitting the molecule structure to the server.

<form id="jmeForm" action="update-molecule.php" method="post">
  <input id="jmeVar" type="hidden" name="JME"/>
  <button type="button" onclick="jsmeOnClick();">Update"</button>

2. Create a JavaScript function jsmeOnClick(), which will be called when the "Update" button is clicked. It reads the molecule structure in JME format from the JSME editor and submit the structure to the server using the HTML form.

  function jsmeOnClick() {
    var jme = jsmeObj.jmeFile(); 
    document.getElementById("jmeVar").value = jme;

3. Retrieve the molecule structure on the server side in the PHP script, update-molecule.php.

$jme = _REQUEST["JME"];
# save the structure to database or to a file.

4. Generate HTML document with JavaScript code to load the molecule structure into the JSME editor.

$jme = _REQUEST["JME"];
$htm = <<< EndOfHtml
  function jsmeOnLoad() {
    jsmeObj = new JSApplet.JSME("jsme_container", "380px", "340px");

Note that you also use the jsmeObj.readGenericMolecularInput($jme) to load the molecule structure in JME format. But it will display the "ERROR: Invalid JME string" message on the JSME editor, for an empty structure.

So JSME has a bug in the readGenericMolecularInput() code for a given empty structure in JME format: "0 0".


JSME Molecule Editor Options

Save Molecule from JSME to Server

JSME JavaScript API

⇑⇑ JSME Tutorials

2023-04-13, 320🔥, 0💬