Marvin Space - Basic JavaScript Example

User a8020badc4

17-05-2011 14:09:51

Hello,


Could someone illustrate a very basic example of how to set the molecule value of an MSpaceApplet using javascript?


Something along the lines of the below code


function changeMol(){


document.MSpaceApplet.setMolProperty("molecule",http://www.chemaxon.com/marvinspace/data/1ETR.mol style="font-family: courier new,courier;">)


}


    <applet codebase="../../.."
        code="chemaxon/marvin/applet/MSpaceApplet" name="MSpaceApplet" width=400 height=400
        archive="mspace.jar,jmarvin.jar,jogl.jar">
    <param name="progressbar" value="true">
    <param name="selectionpanel" value="false">
    <param name="molecule" value="http://www.chemaxon.com/marvinspace/data/1ETS.mol">
    </applet>


<input type="button" onClick"changeMol()" value="Change">


Thanks,


S

ChemAxon eb65a25631

17-05-2011 15:03:26

Hi!


You can find an example on the bottom of the following page:


https://www.chemaxon.com/marvin/examples/applets/space/embed.html


(<script type="text/javascript">
<!--
...


mspace_param("molecule",http://www.chemaxon.com/marvinspace/data/1ETS.mol);


...


//-->
</script>)


Regards,


András

User a8020badc4

17-05-2011 15:22:51

Hello Andras,


Apologies but I'm not sure I follow this.


I want to be able to click on a button and change the source of the molecule displayed in the applet.  Is this possible?  If so, what code needs to be included in the javascript function called when the button is clicked?


Many thanks,


 


Sam

ChemAxon eb65a25631

17-05-2011 16:15:33

Hi,


in this case, you can use the setMolecule function like this:



function changeMol(){




document.MSpaceApplet.setMolecule('1ETR.mol');


 }



You can use addMolecule() to add more molecules to the scene, and you can use setMoleculeString() for

SMILES strings also.


(Though, with the example molfile I tried, I had to rotate the molecule into view after setting it.)