MarvinSketch Example - Calculating molecular properties on the fly

Modify the molecule (delete some atoms or bonds, draw new ones), and watch how the calculated fields change.

Molecular weight:
Atom count:
Ring count:
Polar surface area:
logP:
IUPAC name:
SMILES:

Molecular properties are calculated by evaluating Chemical Terms expressions. When the molecule is changed the Chemical Terms expressions are re-evaluated and the results are updated.

<!--  Important!  -->
<body onUnLoad="document.MSketch=null">

<center>
<script LANGUAGE="JavaScript1.1" SRC="../../../marvin.js"></script>
<script LANGUAGE="JavaScript1.1">
<!--
function evaluateChemicalTerms(expression) {
    if(document.MSketch != null) {
        return document.MSketch.evaluateChemicalTerms(expression);
    } else {
        alert("Cannot evaluate expression on molecule:\n"+
              "no JavaScript to Java communication in your browser.\n");
    }
}

function setFields(){
    document.getElementById('mass').innerHTML = evaluateChemicalTerms("mass()");
    document.getElementById('atomcount').innerHTML = evaluateChemicalTerms("atomCount()");
    document.getElementById('ringcount').innerHTML = evaluateChemicalTerms("ringCount()");
    document.getElementById('logp').innerHTML = evaluateChemicalTerms("logP()");
    document.getElementById('psa').innerHTML = evaluateChemicalTerms("PSA()");
    document.CTForm.name.value = evaluateChemicalTerms("name()"); 
    document.CTForm.smiles.value = evaluateChemicalTerms("molString('smiles')");
}

function propertyChange(prop) {
    if (prop.indexOf('mol=') !=-1) {
        setFields();
    } 
}

msketch_name = "MSketch";
msketch_mayscript = true;
msketch_begin("../../..", 540, 480);
msketch_param("mol", "../../../mols-2d/caffeine.csmol");
msketch_param("listenpropertychange","true");
msketch_end();
//-->
</script>
<p>
<form NAME="CTForm">
<table border=0>
    <tr>
        <td>Molecular weight:</td>
        <td><div ID="mass"></div></td>
    </tr>
    <tr>
        <td>Atom count:</td>
        <td><div ID="atomcount"></div></td>
    </tr>
    <tr>
        <td>Ring count:</td>
        <td><div ID="ringcount"></div></td>
    </tr>
    <tr>
        <td>Polar surface area:</td>
        <td><div ID="psa"></div></td>
    </tr>
    <tr>
        <td>logP:</td>
        <td><div ID="logp"></div></td>
    </tr>
    <tr>
        <td>IUPAC name:</td>
        <td><textarea NAME="name" ROWS=2 COLS=60 READONLY="readonly"></textarea></td>
    </tr>
    <tr>
        <td>SMILES:</td>
        <td><textarea NAME="smiles" ROWS=2 COLS=60 READONLY="readonly"></textarea></td>
    </tr>
</table>
</form>
</center>
<script language="javaScript1.1">
<!--
    setFields();
//-->
</script>

</body>