Skip to content

Commit

Permalink
health start, removed chemspipy dep, UX update
Browse files Browse the repository at this point in the history
  • Loading branch information
charnley committed May 5, 2013
1 parent dbcb0d2 commit 5173196
Show file tree
Hide file tree
Showing 16 changed files with 297 additions and 469 deletions.
42 changes: 32 additions & 10 deletions README.md
@@ -1,11 +1,9 @@
# MolCalc - Molecule Calculator
# The Molecule Calculator (MolCAlc)

Hosted at [dgu.ki.ku.dk/molcalc](http://dgu.ki.ku.dk/molcalc)


![Editor Screenshot](https://raw.github.com/jensengroup/molcalc/master/manual/screenshots/molcalc_editor.png)


MolCalc is a web interface that allows anyone to build
small molecules and estimate molecular properties such as molecular structure,
heats of formation and other thermodynamic properties,
Expand All @@ -25,34 +23,58 @@ MolCalc uses

and the source is released under the GPL license.


## Installation Instructions

If you want to install it on your own server
with PHP support, of course.

### Dependency

* Python 2.x
* Python 2.7

* [OpenBabel w/ Python Bindings and PNG Support](http://openbabel.org/docs/dev/Installation/install.html)
Make sure that the the correct libs are installed before compile open babel. See above link.

* [GAMESS](http://www.msg.ameslab.gov/gamess/)

* mod rewrite. MolCalc uses a .htaccess script for redirecting the web requests. Please make sure mod\_rewrite
is enabled. On ubuntu this is done by running the command

sudo a2enmod rewrite

* A Chemspider API Token. [Sign up for a Chemspider user](http://www.chemspider.com/controls/Login/RegForm.aspx)
This is used for searches on common names in the editor.


### Installation

1. Clone
1. Clone the molcalc repo the correct folder

2. copy and paste settings.default to settings

3. fill in settings;
gamess: The path to the rungms executable
tmp: The path for the tmp folder (for writing tmp gamess log files)
chemspider: The chemspider API token.

5. Run the test.php via a browser to check if everything is setup correctly.

4. Done, Happy calculating


### Changelog

Changes in 1.2

2. cp settings.default settings
1. Removed Chemspider dependicies. Now only using Cactus for naming.

3. fill in settings
2. Removed OpenBabel charge script. Now using JSMOL FF for partial charges instead.

4. Done
3. Update UX with small improvements

### Credits

MolCalc 1.1 is written by Jimmy Charnley Kromann based on an idea by Jan Jensen.
MolCalc s written by Jimmy Charnley Kromann based on an idea by Jan Jensen.
The development of MolCalc is supported by the University of Copenhagen through
the Education at its Best Initiative (Den Gode Uddannelse).

Expand Down
11 changes: 8 additions & 3 deletions application/check.php
Expand Up @@ -111,16 +111,16 @@
// Get Common name and Inchi code
// Sometimes inchi didnt work with this search, sometimes not with smiles
$smiles = shell_exec('babel -ixyz coordinates.xyz -osmiles --title " "');
$inchi = shell_exec('babel -ixyz coordinates.xyz -oinchi --title " "');
$inchikey = shell_exec('babel -ixyz coordinates.xyz -oinchikey --title " "');
$smiles = str_replace("\n",'', $smiles);
$smiles = preg_replace("/\s+/",'', $smiles);
$inchi = shell_exec('babel -ixyz coordinates.xyz -oinchi --title " "');
$inchi = str_replace("\n",'', $inchi);
$inchikey = shell_exec('babel -ixyz coordinates.xyz -oinchikey --title " "');
$inchikey = str_replace("\n",'', $inchikey);
$inchikey = preg_replace("/\s+/",'', $inchikey);
$name = "";
//$name = shell_exec('../../tools/molecule_name.py "'.$smiles.'"');

// TODO Check if SMILES is empty

if(!strpos($smiles, "."))
{
Expand All @@ -147,6 +147,11 @@ function get_http_response_code($url) {
return substr($headers[0], 9, 3);
}

// TODO Cactus name
// Check if the response is HTML code
// because catus response is a .html file
// when SMILE is empty

if(get_http_response_code($cactus) != "404"){
$names = file_get_contents($cactus);
// for 'names'
Expand Down
8 changes: 4 additions & 4 deletions application/views/editor.php
Expand Up @@ -65,7 +65,7 @@
<!--<li class="action load"><a rel="" class="button"><span class="hvrHlpCnt"><span class="hvrHlp">Load molecule structure</span></span><span class="text">Load</span></a></li>-->
<li class="action save"><a rel="" class="button"><span class="hvrHlpCnt "><span class="hvrHlp">Temporarily save state </span></span> <span class="text">Save</span></a></li>
<li class="action restore"><a rel="" class="button"><span class="hvrHlpCnt "><span class="hvrHlp">Restore saved state</span></span> <span class="text">Restore</span></a></li>
<li class="action minimise"><a rel="" class="button"><span class="hvrHlpCnt "><span class="hvrHlp">Minimize geometry using MMFF forcefield</span></span><span class="text">Minimize</span></a></li>
<li class="action minimise"><a rel="" class="button"><span class="hvrHlpCnt "><span class="hvrHlp">Minimise geometry using MMFF forcefield</span></span><span class="text">Minimise</span></a></li>
</ul>
<div class="clean"></div>
</div>
Expand All @@ -83,15 +83,15 @@
</div>
<div class="actions atoms">
<ul>
<li class="action atom"><a rel="H" class="button"><span class="hvrHlpCnt"><span class="hvrHlp">Hydrogen</span></span><span class="text">H</span></a></li>
<li class="action atom"><a rel="H" class="button"><span class="hvrHlpCnt"><span class="hvrHlp">Hydrogen</span></span><span class="text">H</span></a></li>
<li class="action atom"><a rel="Li" class="button"><span class="hvrHlpCnt"><span class="hvrHlp">Lithium</span></span><span class="text">Li</span></a></li>
<li class="action atom"><a rel="Be" class="button"><span class="hvrHlpCnt"><span class="hvrHlp">Beryllium</span></span><span class="text">Be</span></a></li>
<!--<li class="action atom"><a rel="B" class="button"><span class="hvrHlpCnt"><span class="hvrHlp">Boron</span></span><span class="text">B</span></a></li> --><!-- not in pm3 -->
<!--<li class="action atom"><a rel="B" class="button"><span class="hvrHlpCnt"><span class="hvrHlp">Boron</span></span><span class="text">B</span></a></li> --><!-- not in pm3 -->
<li class="action atom"><a rel="C" class="button"><span class="hvrHlpCnt"><span class="hvrHlp">Carbon</span></span><span class="text">C</span></a></li>
<li class="action atom"><a rel="N" class="button"><span class="hvrHlpCnt"><span class="hvrHlp">Nitrogen</span></span><span class="text">N</span></a></li>
<li class="action atom"><a rel="O" class="button"><span class="hvrHlpCnt"><span class="hvrHlp">Oxygen</span></span><span class="text">O</span></a></li>
<li class="action atom"><a rel="F" class="button"><span class="hvrHlpCnt"><span class="hvrHlp">Fluorine</span></span><span class="text">F</span></a></li>
<li class="action atom"><a rel="Ne" class="button"><span class="hvrHlpCnt"><span class="hvrHlp">Neon</span></span><span class="text">Ne</span></a></li>
<li class="action atom"><a rel="Ne" class="button"><span class="hvrHlpCnt"><span class="hvrHlp">Neon</span></span><span class="text">Ne</span></a></li>
<li class="action atom"><a rel="Na" class="button"><span class="hvrHlpCnt"><span class="hvrHlp">Sodium</span></span><span class="text">Na</span></a></li>
<li class="action atom"><a rel="Mg" class="button"><span class="hvrHlpCnt"><span class="hvrHlp">Magnesium</span></span><span class="text">Mg</span></a></li>
<li class="action atom"><a rel="Al" class="button"><span class="hvrHlpCnt"><span class="hvrHlp">Aluminium</span></span><span class="text">Al</span></a></li>
Expand Down
2 changes: 1 addition & 1 deletion application/views/header.inc.php
Expand Up @@ -78,7 +78,7 @@
<a href="<?php print BASEURL ?>">
<h1>
<span class="sep">MolCalc</span>
<span class="ret">Molecule Calculator</span>
<span class="ret">The Molecule Calculator</span>
</h1>
</a>
</section>
Expand Down
33 changes: 25 additions & 8 deletions assets/molstruc/check.php
@@ -1,8 +1,8 @@
<?php

// Check if ChemSpider can find the molecule
// and return image source,
// otherwise return 0
/* Using Cactus to find chemical structure from
* search pattern.
*/

if(isset($_GET['search']))
{
Expand All @@ -14,14 +14,31 @@
die();
}

$search = str_replace("%20", " ", $search);

// Search Chemspider, and get MF results
$smiles = shell_exec('../../tools/molecule_search_mol.py "'.$search.'"');
$smiles = str_replace("\n", '', $smiles);
# Prepare search, if in SMILES format.
$search = str_replace(" ", "%20", $search);
$search = str_replace("[", "%5B", $search);
$search = str_replace("]", "%5D", $search);
$search = str_replace("@", "%40", $search);
//$search = str_replace(")", "", $search);
//$search = str_replace("(", "", $search);
$search = str_replace("=", "%3D", $search); #double bond
$search = str_replace("#", "%23", $search); #triple bond

if($smiles == "0")
$cactus_inchi = "http://cactus.nci.nih.gov/chemical/structure/".$search."/iupac_name";
$cactus_smiles = "http://cactus.nci.nih.gov/chemical/structure/".$search."/smiles";

// IF 404
function get_http_response_code($url) {
$headers = get_headers($url);
return substr($headers[0], 9, 3);
}

if(get_http_response_code($cactus_smiles) != "404")
{
$smiles = file_get_contents($cactus_smiles);
$smiles = str_replace("\n",'',$smiles);
}else{
print "0";
die();
}
Expand Down
46 changes: 30 additions & 16 deletions assets/molstruc/search.php
@@ -1,21 +1,35 @@
<?php

// TODO
// Check also for POST information, because
// some search patterns are too destroted (like inchi)
/* Using Cactus to find chemical structure from
* search pattern.
* The use babel to generate 3D structure based in inchi
*/

if(isset($_GET['search']))
{
$search = $_GET['search'];
}
else
{
print "0";
die();
}
if(isset($_GET['search']))
{
$search = $_GET['search'];
}
else
{
print "0";
die();
}

$search = str_replace("%20", " ", $search);
// Search for $search in webspider database
//print shell_exec('../../tools/molecule_search.py '.$search.' | obabel -imol -oxyz -h --gen3d');
print shell_exec('../../tools/molecule_search.py "'.$search.'" | obabel -iinchi -oxyz -h --gen3d');
# Prepare search, if in SMILES format.
$search = str_replace(" ", "%20", $search);
$search = str_replace("[", "%5B", $search);
$search = str_replace("]", "%5D", $search);
$search = str_replace("@", "%40", $search);
//$search = str_replace(")", "", $search);
//$search = str_replace("(", "", $search);
$search = str_replace("=", "%3D", $search); #double bond
$search = str_replace("#", "%23", $search); #triple bond

$cactus_inchi = "http://cactus.nci.nih.gov/chemical/structure/".$search."/inchi";
$cactus_smiles = "http://cactus.nci.nih.gov/chemical/structure/".$search."/smiles";

$inchi = file_get_contents($cactus_inchi);
$inchi = str_replace("\n", '', $inchi);

print shell_exec("echo \"".$inchi."\" | obabel -iinchi -oxyz -h --gen3d");

26 changes: 25 additions & 1 deletion assets/script/jquery.prompt.js
Expand Up @@ -27,6 +27,14 @@ $(function()
// this could be java applets like Jmol
var hideElements = $('.canvas');


// Center Div plugin
jQuery.fn.center = function ()
{
var top_margin = Math.max(($(window).height() - $(this).outerHeight() )/ 2);
this.css('margin-top',top_margin+'px');
return this;
}

/**
* Prompt gives the user a prompt message to respond too.
Expand All @@ -35,6 +43,7 @@ $(function()
{
// Define the parent block
var stamp = new Date().getTime();
this.stamp = stamp;
this.parentblock = $('<div></div>');
this.parentblock.attr('id', stamp);
this.parentblock.hide();
Expand Down Expand Up @@ -77,6 +86,7 @@ $(function()
var btn = $('<a class="button">'+msg+'</a>');
btn.click(action);
this.responselist.append($('<li></li>').append(btn));
return btn;
}

this.addCancelBtn = function addCancelBtn(msg)
Expand All @@ -88,6 +98,11 @@ $(function()
});
}

this.getStamp = function getStamp()
{
return this.stamp;
}

this.show = function show()
{
//if(this.responselist.find('li').size() > 0)
Expand Down Expand Up @@ -115,14 +130,23 @@ $(function()
this.parentblock.html(html);
this.parentblock.show();

box.center();

$(window).resize(function() {
box.center();
});

}

function hide()
{
$('#'+stamp).fadeOut(100, function()
$('#'+stamp).fadeOut(100, function()
{
hideElements.show();
});

// Unbind window resize
$(window).unbind('resize');
}

this.cancel = function cancel()
Expand Down
19 changes: 14 additions & 5 deletions assets/script/views/editor.js
Expand Up @@ -98,16 +98,17 @@ $(function(){
var askuser = new $.Prompt();
askuser.setTitle('Load Structure');

var message = $('<div></div>');
var message = $('<div class="form"></div>');

// Search Field
var field = $('<input placeholder="Search" type="text" style="width:50%;" />');
var field = $('<input placeholder="fx. Ethanol" type="text" />');
message.append(field);
message.append('<p>Large molecules will be ignored.</p>');
message.append('<span><br />Large molecules will be ignored.</span>');

askuser.setMessage(message);

askuser.addResponseBtn('Load', function() {
var load_button = askuser.addResponseBtn('Load', function()
{
var state = field.attr('class');
if (state != 'success') return false;
var val = field.val().replace(/\s/g,"%20");
Expand All @@ -120,11 +121,17 @@ $(function(){
askuser.show();
field.focus();

load_button.addClass('inactive');

/* AJAX Search */
var min_length = 2; // min length before searching
var req = null; // init ajax request
field.keyup(function() {

field.keyup(function()
{
load_button.removeClass('inactive');
load_button.addClass('inactive');

var that = $(this);
value = that.val();
if(req != null) req.abort();
Expand All @@ -146,6 +153,7 @@ $(function(){
}
else
{
load_button.removeClass('inactive')
that.addClass('success');
}
}
Expand Down Expand Up @@ -314,6 +322,7 @@ $(function(){
partial_charge = atominfo[i].partialCharge;
elem_no = atominfo[i].elemno;

mole_charges += formal_charge;
mole_charges += partial_charge;
core_charges += elem_no;
}
Expand Down

0 comments on commit 5173196

Please sign in to comment.