Export MarvinSketch structure via HTML/php command

User 8d25615d6b

16-08-2011 11:54:09

Hi - i have a small problem in my current project.


 


I've written a upload function for a database. What the thing basically does is: you draw something in the MarvinSketch Applet and it calculates chemical properties like Ringcount, Atomcount etc for you. These results can then be uploaded into a mysql- database by simply clicking a button.


Now to the thing I couldn't figure out till now: how can I save the structure I have just drawn as a *.sdf into a given folder via a command line entry - instead of having to use the dropwdown menu from the applet (File -> save as)?


This command would also be linked to the button I use to upload the calculated data into the database.


Best wishes,


Alex

ChemAxon 5433b8e56b

16-08-2011 13:50:26

Hi Alex,


if i understand well, you want to upload the molecule also to the server, and save it into the database?


If yes, then you can get the source of the drawn structure by calling the getMol(String) method of the MarvinSketch applet.


Regards,
Istvan

User 8d25615d6b

18-08-2011 07:35:07

Hi Istvan,


 


thank you very much. I don't want to save the molecule directly into the database, but save it as it's own file - to which the database then again links. But, I'll give this a try as this function actually should do the trick. :)


 


Best wishes,


Alex

User 8d25615d6b

18-08-2011 13:06:22

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>


 


 

ChemAxon 5433b8e56b

19-08-2011 09:06:24

Hi Alex,


as i see, the missing data originates from calculations that requires a license. I assume the applet could not find the license file, did you installed it on the server?


You can find more information on applet licensing here.


Regards,
Istvan

User 8d25615d6b

19-08-2011 09:12:45

Hi again Istvan,


 


I tried to install the license by adding the following line


 


msketch_name = "MSketch";
msketch_mayscript = true;
msketch_begin("marvin", 540, 480);
msketch_param("mol", "marvin/mols-2d/caffeine.csmol");


msketch_param("licenseFile", "http://>my-server-address</chemaxon/license.cxl");



msketch_param("listenpropertychange","true");
msketch_end();


 This does not seem to change anything, altough the line above is pointing to the correct file destination. Do I have to change an internal license pointer in the java-applet to the location of the license.cxl?


Best wishes,


Alex

ChemAxon 5433b8e56b

22-08-2011 08:53:15

Hi,


if the license is in its default location (path/to/codebase/chemaxon/license.cxl) then you do not need to set the licenseFile parameter. By the way i could not reproduce such issue, can you send me the contents of the java console, or a link, where i can take a look at what happens? (if it contains confidential data, or the link is not public, you can send the data, or the access information via mail to ifajth_at_chemaxon.com also)


If you send me the console contents, please make sure that the enable trace parameter is set to enabled on the advanced tab on the java control panel. (this enables more verbose output in the java console.)


Regards,
Istvan