Hi ChemAxon- Team,
Getting the molecular structure to show in a way I can use it to save it in a file worked (I used importMol for that though). I do have another question though- a picture is added as attachment.
I'm currently using marvinSketch to calculate properties of different compounds. I can export the molecular structure to the textarea on the left without problems [(1)]. The table on the right [(3)] should contain the properties of the given compound. I took caffeine [(2)] as an example here and only some properties are getting calculated. Here's the code I used to do this. It is - except for the layout of the tables - the same as you used for the tutorial- site here: http://www.chemaxon.com/marvin/examples/applets/sketch/chemicalterms2.html
I can't seem to find the error why those properties are not calculated correctly.
Thank you in advance and best wishes,
Alex
<table id="styleTable" border=1>
<!--<table align="center" width="100%" border="1" style="font-size: 90%"> -->
<br><tr>
<th id="col4"><img src="../buttons/enum_1.png">Submit your own molfile in the given format. "Import this Molfile" will import it to the Applett in the middle of the screen.</th>
<th id="col4"><img src="../buttons/enum_2.png">Draw your own chemical structures here or simply open a structure from a file and calculate the properties or export the molecule structure.</th>
<th id="col4"><img src="../buttons/enum_3.png">Calculated chemical properties. These values will also be saved in the Database. Proceed with the upload tool down below.</th>
</tr>
<td align="center">
<form NAME=MolForm onSubmit="return false">
<table BORDER=0>
<textarea NAME="MolTxt" ROWS=30 COLS=45>
</textarea>
<p>
<br>
<input class="formButton" TYPE=BUTTON VALUE="Import this Molfile" onClick="importMol(null)">
</p>
</form>
</td>
</table>
<td align="center">
<body onLoad="document.MSketch=null">
<script type="text/javascript" LANGUAGE="JavaScript1.1" SRC="marvin/marvin.js"></script>
<script type="text/javascript" LANGUAGE="JavaScript1.1" SRC="marvin/js2java.js"></script>
<script type="text/javascript" LANGUAGE="JavaScript1.1">
<!--
var isJs2Java = isLiveConnect(); // Is JavaScript - Java communication available?
setPath("marvin"); // Sets the relative path of the Marvin directory.
function importMol(opts) {
var s = document.MolForm.MolTxt.value;
if((document.MSketch != null) && isJs2Java) {
document.MSketch.setMol(s, opts);
} else if(!isJs2Java) {
mparams = "java.lang.String";
if(opts != null) {
mparams += ",java.lang.String";
}
setMethod("MSketch.setMol",mparams);
addMethodParam(s);
if(opts != null) {
addMethodParam(opts);
}
runMethod();
} else {
alert("Cannot import molecule:\n"+
"no JavaScript to Java communication in your browser.\n");
}
}
function printMol() {
var s = getResult();
s = convertJs2Html(s);
document.MolForm.MolTxt.value = s;
}
function exportMol(format) {
if((document.MSketch != null) && isJs2Java) {
var s = document.MSketch.getMol(format);
s = unix2local(s); // Convert "\n" to local line separator
document.MolForm.MolTxt.value = s;
} else if(!isJs2Java) {
if(format == 'smiles') {
setIsCompressed(false);
} else {
setIsCompressed(true);
}
setMethod("MSketch.getMol","java.lang.String");
addMethodParam(format);
setPostJsMethod("parent.printMol()");
runMethod();
} else {
alert("Cannot import molecule:\n"+
"no JavaScript to Java communication in your browser.\n");
}
}
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() {
var mass = evaluateChemicalTerms("mass()");
setElementValueAndBackgroundColor('mass', mass, mass <= 500, '#0f0', '#f00');
var logp = evaluateChemicalTerms("logP()");
setElementValueAndBackgroundColor('logp', logp, logp <= 5, '#0f0', '#f00');
var donorcount = evaluateChemicalTerms("donorCount()");
setElementValueAndBackgroundColor('donorcount', donorcount, donorcount <= 5, '#0f0', '#f00');
var acceptorcount = evaluateChemicalTerms("acceptorCount()");
setElementValueAndBackgroundColor('acceptorcount', acceptorcount, acceptorcount <= 10, '#0f0', '#f00');
var lipinskiruleof5 = evaluateChemicalTerms("(mass() <= 500) && (logP() <= 5) && (donorCount() <= 5) && (acceptorCount() <= 10)");
setElementValueAndBackgroundColor('lipinskiruleof5', lipinskiruleof5, lipinskiruleof5 == 1, '#0f0', '#f00');
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 setElementValueAndBackgroundColor(elementID, value, booleanExpression, trueColor, falseColor) {
document.getElementById(elementID).innerHTML = value;
if (booleanExpression) {
document.getElementById(elementID).style.backgroundColor = trueColor;
} else {
document.getElementById(elementID).style.backgroundColor = falseColor;
}
}
function propertyChange(prop) {
if (prop.indexOf('mol=') !=-1) {
setFields();
}
}
msketch_name = "MSketch";
msketch_mayscript = true;
msketch_begin("marvin", 540, 480);
msketch_param("mol", "marvin/mols-2d/caffeine.csmol");
msketch_param("listenpropertychange","true");
msketch_end();
//-->
</script>
<table align=center>
<tr>
<td><input align=left class="formButton" TYPE=BUTTON value="Export as Molfile" onClick="exportMol('mol')"/></td>
<td><input align=right class="formButton" type=BUTTON value="Calculate Properties" onClick="window.location.reload()"/></td>
</tr>
</table>
<td>
<form NAME="CTForm" method="post" action="update.php">
<table border=1>
<tr>
<td>Molecular weight:</td>
<td><textarea ROWS=1 COLS=60 ID="mass" name="mass"></textarea></td>
</tr>
<tr>
<td>logP:</td>
<td><textarea ROWS=1 COLS=60 ID="logp" name="logp"></textarea></td>
</tr>
<tr>
<td>H bond donor count:</td>
<td><textarea ROWS=1 COLS=60 ID="donorcount" name="donorcount"></textarea></td>
</tr>
<tr>
<td>H bond acceptor count:</td>
<td><textarea ROWS=1 COLS=60 ID="acceptorcount" name="acceptorcount"></textarea></td>
</tr>
<tr>
<td>Lipinski rule of 5:</td>
<td><textarea ROWS=1 COLS=60 ID="lipinskiruleof5" name="lipinskiruleof5"></textarea></td>
</tr>
<tr>
<td>Atom count:</td>
<td><textarea ROWS=1 COLS=60 ID="atomcount" name="atomcount"></textarea></td>
</tr>
<tr>
<td>Ring count:</td>
<td><textarea ROWS=1 COLS=60 ID="ringcount" name="ringcount"></textarea></td>
</tr>
<tr>
<td>Polar surface area:</td>
<td><textarea ROWS=1 COLS=60 ID="psa" name="psa"></textarea></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>
</center>
<script type="text/javascript">
<!--
setFields();
//-->
</script>