Jmol filter to view molecular structures

Jmol filter to view molecular structures

by Dan Stowell -
Number of replies: 113
Inspired by venkatesan iyengar's "Marvin"-based molecular viewer filter, here's a filter which renders molecular data files as 3D molecules using Jmol.

I prefer Jmol because it's open-source. It can view a large number of the standard chemical information languages such as MOL, PDB, XYZ, and so on.

In order to use it you need to add the Jmol applet to your Moodle server, by downloading it from http://jmol.sourceforge.net and copying the two files 'Jmol.js' and 'JmolApplet.jar' to the location ......../moodle/lib/jmol/

Once you've done that, just unzip the attached filter file into ........./moodle/filter/jmol/

I've tested it in forums, quizzes, etc. Seems to work without a hitch so far! The one caveat is that for security purposes, Jmol insists that the files should be on your own server, not referenced from elsewhere. So upload the files to your Moodle filestore and reference them from there...
Average of ratings: Useful (1)
In reply to Dan Stowell

Re: Jmol filter to view molecular structures

by Dan Stowell -
Here's a more convenient-to-install version - everything's all bundled into one! No need to install anything except this:

http://ucl.ac.uk/is/fiso/lifesciences/test/jmol.zip

(File size is 536KB)
Average of ratings: Useful (1)
In reply to Dan Stowell

Re: Jmol filter to view molecular structures

by venkatesan iyengar -
Dear Dan

Great work. I had done a similar thing at my localhost and try to compare with marvin. However, I felt that, Marvin has more additional features and especially rxn files can be rendered directly that has direct implication in teaching organic chemistry. Additionally, having Marvin applets on the server, students can draw their own chemical drawing online for assignment submissions etc and students need not have structure drawing packages in every machine they handle,be at home or at internet cafe.
In reply to venkatesan iyengar

Re: Jmol filter to view molecular structures

by Dan Stowell -
Hi Venkatesan -

I haven't used Marvin, but I'm sure you're right that it has some extra features. (I don't know RXN - it's for displaying reactions?) I know that the Jmol applet isn't designed for editing files. The one big problem with Marvin is that it is not available under a licence that makes it possible to distribute it as a part of Moodle.

Using Jmol as a built-in viewer for molecular data files appeals to me as a built-in Moodle functionality, similar to the built-in TeX filter for maths equations.

For people who need the extra Marvin functionality, your Marvin filter plugin is great.

Best,
Dan
In reply to Dan Stowell

Re: Jmol filter to view molecular structures

by Jean-Pierre Pawlak -
Works fine.
Is there a way to eliminate the stack overflow warning in IE6?
In reply to Jean-Pierre Pawlak

Re: Jmol filter to view molecular structures

by Dan Stowell -
I haven't seen this. I have definitely used it with IE6 as well as other browsers. How did you get it to happen?
In reply to Dan Stowell

Re: Jmol filter to view molecular structures

by Jean-Pierre Pawlak -
Just be adding a second .mol file in a forum discussion or in a  label.
I'm using IE6 and Windows XP SP2.
There's one reference to this problem in the jmol users forum (http://sourceforge.net/mailarchive/forum.php?forum_id=2151&max_rows=25&style=nested&viewmonth=200411) but... no solution.
In reply to Jean-Pierre Pawlak

Re: Jmol filter to view molecular structures

by Dan Stowell -
Thanks for this. I've replicated the problem and found that it's because of initializing the Jmol code multiple times. (Other browsers cope just fine! Ah well.)

Updated Jmol filter which should only initialise itself once per page:
Download here

If you can confirm it fixes the problem for you too, Jean-Pierre, I'd be grateful.
In reply to Dan Stowell

Re: Jmol filter to view molecular structures

by Jean-Pierre Pawlak -
I deleted the lib/jmol map and installed the new filter/jmol.
I keep on seeing these stack overflow warnings (at line 727).
Deleting the second or even all the labels  doesn't solve the problem any more: the warning keeps on popping up
Strange thing is the warning even pops up when I go to the home page...

In firefox 1.5 download of the jmolapplet stopped (at +/- 75 %) the first time I loaded it...
In reply to Jean-Pierre Pawlak

Re: Jmol filter to view molecular structures

by Geoffrey Rowland -
Picture of Plugin developers

Hi Dan & Jean-Pierre

I'm also getting the same stack overflow warnings (at line 727) with IE6 SP2 and the new Jmol filter.

As Jean-Pierre has noted, this occurs even on the home page (where there should not be any links with .mol .pdb .rxn .csmol .cml or .xyz files).

On our server setup, we don't have a /moodle directory in our webserver root, (i.e. the /filter directory is in the webserver root) - so we needed a quick hack of the first declaration of $relurl to get things to work (in Opera & Firefox).

$relurl = "";

rather than $relurl = preg_replace('|https?://.*?/|', '', $CFG->wwwroot);

Not sure if (similar) problems with converting from absolute to relative addressing problems are related to the stack overflow problem.

Sorry my knowledge of PHP and regular expressions is not good enough to add much more...

Keep up the good work Dan, this Jmol filter has lots of potential. One final question. The 'generic' deployment of the Jmol applet, using the right-click dropdown menu to configure display options, is useful. However, is it also possible to add controls using Jmol.js JavaScript (either in the filter, or the link to the structure file) to manipulate the applet?

In reply to Geoffrey Rowland

Re: Jmol filter to view molecular structures

by Dan Stowell -

These problems are very odd. Are you sure you installed the updated version? (I updated the downloadable version just this morning to include the alteration that fixes it for me.) Sorry for the patronising question but it's necessary...

The problem with the overflow error appearing even on pages which don't employ the filter (!) makes me suspect that your IE might have been still suffering from an illness it incurred earlier on. Perhaps closing down Internet Explorer entirely and restarting it might resolve the issue?

If you continue to have problems, if you could allow me to look at an example page that would make it easier to trace the issue. Contact me behind-the-scenes if necessary...

I will have a look at the "relurl" issue - although I thought it should work fine even with moodle as the root, I didn't test that out.

Re the controls etc - no, it's not possible to add controls using Jmol.js commands - Moodle's security filter prevents users from adding the necessary Javascript commands into pages. I don't think controls should be added into the filter (since they aren't the same for each instance), but it might be worth thinking about creating a Jmol "resource"-type which allows for these more advanced features (including choosing the window size etc).

In reply to Dan Stowell

Re: Jmol filter to view molecular structures

by venkatesan iyengar -
Dear Dan,

Yes you are right. Moodle security will not allow javascript on pages. Adding all controls to the filter is nearly impossible. However, you can include the jmol.js directly into javascript.php as I did it for marvin and enjoy all the features of jmol. However, I do not understand about the new jmol resource type.
In reply to venkatesan iyengar

Re: Jmol filter to view molecular structures

by Dan Stowell -
There's no need to include jmol.js directly - it gets included whenever the filter is triggered. The issue is about ading the little javascript commands to create checkboxes and other controls - Moodle will prevent those as well.
In reply to Dan Stowell

Re: Jmol filter to view molecular structures

by Geoffrey Rowland -
Picture of Plugin developers
Dan

Although I don't underestimate my own ability to be doing something daft, nor Internet Explorer's ability to get sick, I'm still getting the same symptoms (have these been sorted for Jean-Pierre?). I have rebooted, relaunched IE, cleared browser caches etc and have deleted/reinstalled your latest version a couple of times.

I still do need to set $relurl=''; to get things to work on our main server (with no /moodle directory), although it works out-of-the box on a test server (with a /moodle directory). Both servers are Moodle 1.5.3 on Fedora 4/XAMPP

Certainly, your latest filter seems to have solved the 'original' problem smile in that a page with links to mutliple .pdb files displays correctly and does not generate the overflow error in IE.

However, on some (but not all) pages of an existing Moodle installation, the filter seems to be launched 'spuriously' (i.e. when there are no linked molecular structure files) resulting in the overflow error sad. Still not sure of what exactly is causing this, although enabling the Course/Site Description block for a course seems to be (one of) the triggers of the problem. ......Yes this is odd!!!!!!

For the moment, and so as not to scare IE users too much, I have turned the filter off on our main server, but will continue to tinker and let you know if I encounter anything interesting.





In reply to Geoffrey Rowland

Re: Jmol filter to view molecular structures

by Dan Stowell -
OK - thanks for your persistence! I'm sure I'll be able to fix the $relurl problem. I'll look again at the script and see if I can spot any possible cause for the other odd problem.

If you could let me look at one of the pages which is spuriously triggering the problem, that would be a really big help, since I could look at the HTML source code.
In reply to Geoffrey Rowland

Re: Jmol filter to view molecular structures

by Dan Stowell -
Fixed!

I made a silly mistake about which I'm embarrassed. Let me find the correct emoticon... blush

Updated version: Download here

It should take care of both problems - it should work on a server where Moodle is the web root, and it should not add the JavaScript spuriously on pages where it's not needed.
In reply to Dan Stowell

Re: Jmol filter to view molecular structures

by Geoffrey Rowland -
Picture of Plugin developers

Brilliant! Solved both problems for our server big grin

In reply to Geoffrey Rowland

Re: Jmol filter to view molecular structures

by Dan Stowell -
Good! I'm glad.

If you want to vote for this to be incorporated into Moodle (or at least put on the downloads page) vote for it in the bugtracker smile

In reply to Dan Stowell

Re: Jmol filter to view molecular structures

by Ger Tielemans -
Works on a Suse server, for MS-clients with IE and Firefox and Avant.
  • Do you have a set of different model formats for more testing?
In reply to Ger Tielemans

Re: Jmol filter to view molecular structures

by Dan Stowell -
It can be tricky to find nice example files which I'm allowed to redistribute. The copyright isn't always obvious.

Here's a PDB file: http://www.rcsb.org/pdb/files/1A81.pdb

Just for the record, the systems I've tested it on so far are:
  • Servers: Slackware Linux, Mac OSX, Windows XP with EasyPHP
  • Windows browsers: Firefox, Internet Explorer, Mozilla
  • Mac browsers: Safari, Firefox
I'll look around for some other example files and post them later...
In reply to Dan Stowell

Re: Jmol filter to view molecular structures

by Geoffrey Rowland -
Picture of Plugin developers
There is a large range of different structure files in the /samples folder distributed with the full Jmol source.
In reply to Geoffrey Rowland

Re: Jmol filter to view molecular structures

by Ger Tielemans -
thanks smile
In reply to Ger Tielemans

Re: Jmol filter to view molecular structures

by Geoffrey Rowland -
Picture of Plugin developers

Hi again

I have taken the liberty of increasing the size, and adding a few generic controls to the bottom of Dan's Jmol Applet by editing the filter.php file. The controls allow simple toggling between stick, ball-and-stick, and space-filling displays, and spinning of the molecule (which helps with the 3D visualisation). The coding is taken directly from the Jmol.js javascript library http://jmol.sourceforge.net/jslibrary/

I realise all these options (and many more!) are available from the Jmol menu (right-click on the applet, or left-click on the Jmol logo), but feel the controls are more straight-forward for the novice or occasional user and encourage interaction with the structure. This is more a proof of concept than a serious alternative to Dans minimalist filter, but I will be interested to receive users reactions.

You can see demonstrations of this at Molecular Structures. Just [Login as a guest] and be aware that the displays may take a while to load.

Here is the code:

Replace

    $replace  = '<script type="text/javascript">

              to

    $newtext = preg_replace($search, $replace, $text);

with

    $replace  = '<form><script type="text/javascript">

              jmolApplet(350, "load \2");

              jmolBr();

              jmolHtml("atoms ");

              jmolRadioGroup([

               ["spacefill off",  "off"],

               ["spacefill 20%",  "20%", "checked"],

               ["spacefill 100%", "100%"]

              ]);

              jmolHtml("&nbsp; &nbsp;");

              jmolCheckbox("spin on", "spin off", "spin");

              </script>&nbsp; &nbsp; <a href="\2" title="Download the molecular data file">Download</a></form>';

    $newtext = preg_replace($search, $replace, $text);

I also attach the modified filter.php file.  Just replace (after backing up!) the original file in the /jmol folder of Dans filter.

I have not added any more generic controls as these very much depend on the educational context and type of structure.

The ability to customise an interface with particular controls is a real strength of Jmol (and Chime). Such controls help direct users to particular aspects of a molecular structure (e.g. display unit cell for a crystal structure, display secondary structures for biological macromolecule etc). As discussed elsewhere in this thread, the JavaScript security makes these controls tricky to implement directly in HTML in Moodle. Does anyone have any workarounds or other suggestions for this.  ?

Finally, I have also added     |pdb\.gz   to the search regular expression so that compressed pdb.gz files can also be handled by the Jmol Filter. This is good for larger files such as the membrane structure in the link above.

In reply to Geoffrey Rowland

Re: Jmol filter to view molecular structures

by Dan Stowell -
I originally would have said that adding any controls would be a bad idea since different situations would require different controls. But actually, what you've done there is very elegant indeed. I agree very much with your point about "encouraging interaction".

NB: Your attached "filter.php" doesn't seem to be the right one. It includes the hack to get things working on moodle-as-root, but doesn't include the modifications you describe.

I've updated my copy of filter.php with the described changes, and it seems to work well. The updated package can be downloaded from here.

I'd like to hear from other interested parties if they are happy with the current display, with the specific controls addded by Geoffrey. I vote in favour of them...
In reply to Dan Stowell

Re: Jmol filter to view molecular structures

by Geoffrey Rowland -
Picture of Plugin developers

Pleased you like the controls smile, and apologies for the wrong filter.php blush. Forgot I had edited a remote file and uploaded a local one. I guess that's what comes of moodling way past my bedtime sleepy.

In reply to Geoffrey Rowland

Re: Jmol filter to view molecular structures

by Geoffrey Rowland -
Picture of Plugin developers
At the risk of feature bloat wink, I have been tinkering with a 'Moodleized' help file for the Jmol Filter. This was partly inspired by the help popups in many of Eric Martz's Chime tutorials.

The information has been edited from http://jmol.sourceforge.net/jscolors/ and http://wiki.jmol.org/MouseManual. There has been some talk on the Jmol discussion forums of adding such help directy to Jmol (e.g in the menu, under About Jmol) but, as far as I am aware, this has not yet happened.

I have attached the help file, jmol.html, and you can see it in action here. Just [Login as a guest] and select the '?' help icons above the Jmol applets.

Be aware that this is a prototype and not yet fully working as I intended (see below). On our Moodle setup, I have placed jmol.html in /lang/en/help/jmol/ and edited filter.php as follows (see Moodle Development Manual):

immediately after:
$newtext = preg_replace($search, $replace, $text);

add:
if($newtext != $text){
helpbutton("jmol", "Click here for help with Jmol", "jmol");
}

I actually wanted to place the '?' icons below the bottom right-hand corner of the applet, i.e. immediately to the right of the Download link, but my PHP skills are appearently not yet up to this sad. I'm hoping that, if you like the Jmol help, some kind coding-guru (Dan?) can fix this!

The jmol.html file has been put together pretty quickly so may need some cleaning of the code - but I hope it is a useful start. Of course, different language versions will be needed.

Finally, and particularly if the help icon ends up at the bottom right of the applet, it may be worth replacing the text-based Download link with a suitable 'download' icon (I have not yet found one) so that the 'line' of controls uner the applet can be slightly less bulky.

Regards

Geoff

In reply to Geoffrey Rowland

Re: Jmol filter to view molecular structures

by Geoffrey Rowland -
Picture of Plugin developers
Just noticed that the '?' help icons don't always appear on the Jmol Filter demos. If this happens, try refreshing a few times, or clear browser cache and refresh and they should reappear. As indicated above this just a demo and the coding is definitely suspect! I'll have another look at it when I get time...
In reply to Geoffrey Rowland

Re: Jmol filter to view molecular structures

by Bhupinder Singh -

Hi Geoff,

I went to your test link.

It was great. I find the JMOL.html a great feature.

Trying to checkout the ? feature I was unable to find the same. Can you help me .

I believe that these features will add to the richness of the filter and functionality.

Regards

Garry

In reply to Bhupinder Singh

Re: Jmol filter to view molecular structures

by Geoffrey Rowland -
Picture of Plugin developers

Garry,

My earlier posting about the parameter-passing (? feature) may not have been clear outside the context of the Size of Embedded Flash thread.

The demo site will only show the effects of parameter passing. ie:

  •  different sizes of Jmol applets embedded in the page
  •  Jmol applets can be displayed with or without the control buttons, download icon, and help icon underneath them.

To insert a Jmol-displayed structure in your own Moodle setup (after you have installed and activated the Jmol Filter).

  1. Upload a molecular structure file to the courses /files folder. Jmol can cope with a variety of formats although I usually use .mol or .pdb format. You can find links to a wide range of structure files at: http://molvis.sdsc.edu/visres/index.html
  2. Turn Editing on and create a hyperlink to the structure file (e.g. .../molecule.pdb) using the built-in editor (e.g. in a Label, HTML block etc). This should show the default Jmol filter display, a 350 pixel square applet with the controls etc underneath.
  3. If you wish to hide the controls, re-edit the hyperlink URL to add ?c=0 immediately after the filename e.g. .../molecule.pdb?c=0.
  4. If you wish to change the size of the applet, re-edit the hyperlink URL to add (for example) ?s=500 again immediately after the filename e.g. .../molecule.pdb?s=500 (for a 500 pixel square applet).

You can also combine the parameters in any order (thanks to Dan) e.g.

 .../molecule.pdb?s=500c=0

Note that only a single 'size' parameter (e.g. s=500) is used, rather than 'height' and 'width', as in virtually all situations Jmol works best as a square applet.

Hope this answers your question!

In reply to Geoffrey Rowland

Re: Jmol filter to view molecular structures-CALLING FUNCTION ERROR

by Bhupinder Singh -

Hi Geoff,

The filter is in the filter folder . It has been selected and activated.

Downloaded a file .....pdb and loaded it to the

"...\course\files folder The package was zipped and had a tar extension.

The file was loaded into the label resource as a link.

When I try to open the link I get the ERROR

" jmolInitialize({codebase}, {badBrowserURL}, {badJava URL})

must be called before any other Jmol.js functions  ".

I am unable to figure out what is going wrong. Can you advise where I am going wrong??

Garry 

In reply to Bhupinder Singh

Re: Jmol filter to view molecular structures-CALLING FUNCTION ERROR

by Dan Stowell -
Are you able to show us this happening? Can a temporary access to your course be created?
In reply to Geoffrey Rowland

Re: Jmol filter to view molecular structures

by Bhupinder Singh -

Hi Geoffery,

I am unable to add links to the downloads of PDB files.

Can you help me as to how to go about it??

Thanks

Garry

In reply to Dan Stowell

Re: Jmol filter to view molecular structures

by venkatesan iyengar -
Dear Dan,

Thanks for the update. I was testing the updated version in my localhost (to compare with my updated marvin filter). I found that I could not load the molecule in opera (v 8) browser (in windows) but could do it successfully in IE6. However, when I hyperlink a file outside the moodle uploaddata folder, applet loads the molecule in opera also. I have my uploaddata folder outside moodle folder. Is it anything to do with that? The following the html source:
==================================
<!-- END OF HEADER -->
<div id="content">
<table align="center" class="generalbox" border="0" cellpadding="20" cellspacing="0"><tr><td class="generalboxcontent"><script type="text/javascript" src="../../../course/filter/jmol/Jmol.js"></script><script type="text/javascript">
jmolInitialize("../../../course/filter/jmol/");
</script>1<script type="text/javascript">
jmolApplet(250, "load http://localhost/course/file.php/8/psilocybin.mol");
</script><a href="http://localhost/course/file.php/8/psilocybin.mol" title="Download the molecular data file">Download</a></td></tr></table><center><p><font size="1">Last modified: Wednesday, 11 January 2006, 07:54 AM</font></p></center><br>
<br>
===========================================
In reply to venkatesan iyengar

Re: Jmol filter to view molecular structures

by Dan Stowell -
No, the data folder's location should make no difference - since the MOL file is retrieved using Moodle's standard "file.php" method...
In reply to Dan Stowell

Re: Jmol filter to view molecular structures

by Geoffrey Rowland -
Picture of Plugin developers

Here is a modified version of Dan's Jmol filter, now working as suggested in my earlier postings. It includes controls for 'stick', 'ball-and-stick', 'spacefill' display, 'spin', and icons/links for file download and Jmol help - all arranged along the bottom of the applet.

jmol_filter.zip [Login as a guest]

You can see it in action here [Login as a guest]

Please be aware that I am fairly new to PHP programming so the code may not be very elegant - but it seems to work for me.

As ever, I will be pleased to receive any feedbaqck.

In reply to Geoffrey Rowland

Re: Jmol filter to view molecular structures

by Dan Stowell -
This looks good. Thanks for the improvements!

I've had a browse through and the code is absolutely fine. I haven't made any changes but I've "tidied up" a little bit - removed a spurious HTML file, renamed "zip.gif" to "download.gif" (since that's what it is!), removed an unused variable declaration, and tidied up a tiny little bit of formatting. As always, my version is at http://ucl.ac.uk/is/fiso/lifesciences/test/jmol.zip

Average of ratings: Useful (1)
In reply to Dan Stowell

Re: Jmol filter to view molecular structures

by Geoffrey Rowland -
Picture of Plugin developers

Dan,

A big thanks for doing the 'quality control'.

For info., and to give due credit, the zip.gif (now download.gif) was from

http://cdc.humboldt.edu/moodle/course/view.php?id=3

Also for info, and so that others don't get alarmed, I have occasionally still noticed Error Line 727 messages when editing/adding structure files in Internet Explorer - presumably because, in these particular circumstances, more than one instance of the Jmol code is invoked. If you close and relaunch IE everything then displays correctly (no errors). The best work-around is to use Firefox or similar smile.

In reply to Geoffrey Rowland

Re: Jmol filter to view molecular structures

by Geoffrey Rowland -
Picture of Plugin developers
I have incorporated some of the 'tricks' from a thread discussing the size of Embedded Flash to allow adjusting the size of the Jmol applet and also allow switching off the controls.

If you simply link to a structure file e.g. molecule.pdb the applet displays with a default size of 350 pixels square and with the controls, download link, and help link discussed in earlier postings.

Alternative applet sizes can be used by adding for example ?s=500 to the link to give a 500 pixel square applet.

Similarly, if you do not wish to display the controls etc, add ?c=0 to the link to the structure file.

For example molecule.pdb?s=700c=0 would display a 700 pixel square applet without controls.

I have also added some minor edits to the jmol.html help file including adding a link to jmol.sourceforge.net.

The modified files can be downloaded from here: jmol_filter.zip -just login as a guest.

Also, you can see them in action here.

Hope this is useful.




In reply to Geoffrey Rowland

Re: Jmol filter to view molecular structures

by Helen Foster -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators
Thanks everyone for the Jmol filter - a superb job! approve Just the thing for getting our Chemistry teachers into Moodle!
In reply to Geoffrey Rowland

Re: Jmol filter to view molecular structures

by Ray Lawrence -
I have to confess I've not paid any attention to this discussion until now. Had a look at the demo site and installed the filter myself. Very impressive!
In reply to Ray Lawrence

Re: Jmol filter to view molecular structures

by Phil Houghton -

This sounds like a great piece of kit, unfortunatly i cannot for the life of me get it to work, i install the filter as instructed and enable the filter in the admin screen but it doesnt seem to pick up the mol files that i link to. The mol files still have the question mark next to them and when you click on the resource to open them it just asks you to download the file. i am running on version 1.5.3

any ideas?

Cheers

Phil

In reply to Phil Houghton

Re: Jmol filter to view molecular structures

by Dan Stowell -
"Still have the question mark next to them" - what question mark? Is it the question mark that Java displays when it's unable to load an applet? (If you can upload a screenshot that might help)

One thing to check: are you linking to mol files within your Moodle server, or on some other server? Jmol refuses to load files on a "foreign" server, so only ones you've uploaded to the same server will work.

Do you have JavaScript enabled? It's needed in order to write the applet to the page.
In reply to Dan Stowell

Re: Jmol filter to view molecular structures

by Phil Houghton -

I am linking to mol files on our moodle server itself. What i mean from the question mark is when you view your course files the mol files display as a unknown file type (see screen shot). i have javaScript enabled and is working fine.

Cheers for the help

Phil

Attachment screen1.JPG
In reply to Phil Houghton

Re: Jmol filter to view molecular structures

by Dan Stowell -
OK, I understand. The question mark icon is because we haven't fiddled with Moodle's list of mime-types - it doesn't affect anything about how the filter works.

If you copy the direct URL for octahedral.mol (for example) and then paste that into a discussion message as a link, you should get the Jmol viewer as a result. Does this work? If not, a screenshot of the forum post would help.
In reply to Dan Stowell

Re: Jmol filter to view molecular structures

by Dan Stowell -
PS I've just noticed that you're talking about adding the MOL file as a resource. The Jmol text filter can't (unfortunately) affect resources - it only affects links placed into forum messages, quizzes, etc.

The easiest way to do what you want is to create a Label or a HTML page, containing a link to the file. That will be translated.

Once the Jmol filter is stable it will be nice to look at adding it as a resource type as well...
In reply to Geoffrey Rowland

Re: Jmol filter to view molecular structures

by Dan Stowell -
Hi Geoff - I like this method of specifying parameters to the applet. Nice idea (even if stolen from the Flash people)!

I've downloaded the modified filter and although it works fine, I'd like to improve the regular expressions so they're more efficient. (Running an array of four regexes means running four times slower! Since this filter will potentially process every single piece of text on the server, it's important not to waste any processor effort.)

I'll post a message when I've modified a little bit more.
In reply to Geoffrey Rowland

Re: Jmol filter to view molecular structures

by Dan Stowell -
I've slightly reworked the latest version of the Jmol filter. Two specific changes:

1) I've reworked Geoffrey's parameter-passing trick into a single regular expression match (using a callback function to process the parameters). This should make it run faster (although you won't notice unless using it on a very large site), and slightly more flexibly in the way the parameters are matched (e.g. you can write both ?s=200&c=0 and ?c=0&s=200 ).

2) I've altered the matching so that it should ONLY match against URLs held on your own server. If you link to a PDB file on someone else's server, the Jmol applet will refuse to display it - so we may as well not even try!

I've tested this on our server and it all looks fine. Feedback gratefully received.

Download the filter

____________________________________________________
In reply to Dan Stowell

Re: Jmol filter to view molecular structures

by Geoffrey Rowland -
Picture of Plugin developers
Dan

Thanks (again) for these performance enhancements cool, and for crediting me in the code. Everything works well on our server too.

The only cosmetic difference with my earlier version is that the controls no longer wrap for small applet sizes (this was achieved by wrapping 'everything' in a single table cell) - but I'm not entirely sure how useful this was anyway.

I have recently started building prototype resources with this filter and have found the flexibility allowed by 'parameter passing' to be very useful.

In some situations the controls are distracting and just get in the way (Yes, I know I introduced them!) - so it is good to have the option to turn them off.

Similarly, it can be useful to display applets with reduced size, e.g. allowing structures to be viewed side-by-side to facilitate comparisons.

I have also considered passing an additional parameter to allow the applet background colour to be changed. In general, the default black background gives a good contrast for fine structural details, particularly if Moodle pages are viewed via a projector. However a white (or light coloured) background often helps to embed a structure in a white or (light coloured) web page and typically prints out better. If there is the user demand for this feature, it should be easy to implement.

Finally, so that there are not too many different versions of the Jmol filter 'flying around', I have redirected the Jmol Filter download link on our demo site to your latest jmol.zip file on the UCL server. I hope this is OK
In reply to Geoffrey Rowland

Re: Jmol filter to view molecular structures

by Dan Stowell -
Yes, linking to the UCL version is fine smile

I must admit I didn't notice the table cell trick of wrapping things. But to be honest, using a table cell wouldn't be a good way of doing it - using <div style="width:250px"></div> (for example) would be a more modern way of doing it, and would avoid cluttering the page with unneccessary tables.
In reply to Dan Stowell

Re: Jmol filter to view molecular structures

by Geoffrey Rowland -
Picture of Plugin developers
Yes you are right approve. Simply wrapping a link to a molecular structure file with e.g. <div style="width:250px"></div> works well. See the C60 structure on this demo course for an example of this.
In reply to Geoffrey Rowland

Re: Jmol filter to view molecular structures

by Dan Stowell -
Yes - although I must confess I don't like this wrapping. For example, when I looked at your example page, the wrapping meant that the word "Spin" and the associated tick-box were nowhere near each other!

In reply to Dan Stowell

Re: Jmol filter to view molecular structures

by Geoffrey Rowland -
Picture of Plugin developers

Hmmm...

I'd actually checked that this was not a problem with a few browser/OS combinations, and specifically chosen the 250 pixel size because it worked sad Clearly it is difficult to cope with all situations, different user-chosen text sizes etc.

As this is a property of the way html/javascript renders the controls and labels (i.e. without a non-breaking space between them), I'm not sure there is an easy way round this. Any suggestions?

In reply to Dan Stowell

Re: Jmol filter to view molecular structures

by Thomas Burkholder -
Thanks to Dan and Geoffrey (and everyone else) for all of their hard work on this filter.  It turns out to be trivial to extend the filter to ins, cif, and log (GAMESS) files by adding to the reg exp line something like this: (mol|pdb|csmol|xyz|cml|pdb\.gz|ins|cif|log).


Now, my question is can I script a button to have jmol display of proteins  etc in cartoon mode?


In reply to Thomas Burkholder

Re: Jmol filter to view molecular structures

by Geoffrey Rowland -
Picture of Plugin developers
Thomas

You are right, the Jmol filter can be 'tweaked' to understand any file type that Jmol recognises.

In theory, it should be simple to add a Jmol.js command/control to display, for example, biological macromolecules in cartoon mode. However, it turns out to be rather difficult as Moodle's security filter prevents users from adding the necessary Javascript commands into pages. In fact, that's one of the reasons that the Jmol filter was developed!

We have resisted the temptation of adding too many 'default' controls to the Jmol filter as they would not be relevant for all types structures. e.g. cartoons of protein secondary structure are not an appropriate option for the display of inorganic crystal structures.

Possible workarounds are:
  1. To customise your local Jmol filter to include the cartoon control - however this would be applied to all Jmol filter-displayed structures in you Moodle installation
  2. Customise 'variants' of the Jmol filter to link to different file types. E.g .pdb files would be displayed by a 'Protein' Filter which displays appropriate controls such as the cartoon. Similarly .mol files could be displayed by a 'Small Molecule' Filter etc.. etc.. Personally I don't favour this as it seems rather too technical & messy.
  3. Use the parameter passing trick to allow a few (and I mean a few) different 'control sets'. For example one for biological macromolecules (e.g. with options to colour subunits, H-bonds, cartoons etc), one for small (organic) molecules (the current set of controls), and one for crystal structures (e.g. with options for the display of unit cells etc). I think there may be some mileage in this, and I'll try to find some time to investigate it further wink.
In all of this, a balance has to be struck between the (relative) simplicity of using the current Jmol filter and the full complexity and power (also available from the menu) of the Jmol applet.

Of course, others may have additional ideas/insights to address this.
In reply to Geoffrey Rowland

Re: Jmol filter to view molecular structures

by Thomas Burkholder -
I very much like option 3.  It strikes the right balance.  Thank you for thinking about this.
In reply to Thomas Burkholder

Re: Jmol filter to view molecular structures

by Geoffrey Rowland -
Picture of Plugin developers

Alternatively...

See Dan's new, and very configurable, Jmol Resource cool

In reply to Geoffrey Rowland

Re: Jmol filter to view molecular structures

by James Lovatt -

Firstly, I want to say fair play to you for coming with all the above code! It's really needed to encourage the use of moodle in chemistry teaching!

Is there any word on the jmol filters being incorporated into the next version of moodle...I'm working  where it seems additions to the moodle code on the server is only aloud if it's in an official moodle update???

In reply to Geoffrey Rowland

Re: Jmol filter to view molecular structures

by Geoffrey Rowland -
Picture of Plugin developers

Hi Jmol folks

Just to let you know I have just updated Dan Stowell's Jmol Resource type to work with Moodle 1.8

See: http://moodle.org/mod/forum/discuss.php?d=70019#p314213

When I have time, I'll also get round to updating the Jmol Filter - though this already works with Moodle 1.8 and it is fairly straight-forward to replace the bundled Jmol components with the latest stable (or development) versions from: http://jmol.sourceforge.net/download/ 

In reply to Dan Stowell

Re: Jmol filter to view molecular structures

by joe cool -
Yes, thanks much for the molecule viewer.

I have a question...

I had an error on my course page:

Warning: str_repeat() [function.str-repeat]: Second argument has to be greater than or equal to 0. in /my/site/moodle/filter/jmol/filter.php on line 57
Edit summary

This error appears in both moodle/mod/resource/type/jmol/resource.class.php, and also the same error in moodle/filter/jmol/filter.php .

This is with Moodle 1.6 beta,.

Here is the code (it is the same in both files):

if(preg_match('|https?://.*?/|', $u)){
$relurl = preg_replace('|https?://.*?/|', '', $u);
}else{
$relurl = ''; // This will typically be the case if Moodle is the web root
}
$numdirs = substr_count($PHP_SELF, '/') - 1;
if($numdirs==0){
$relurl = './' . $relurl;
}else{
$relurl = str_repeat('../', $numdirs) . $relurl;
}

Any suggestions on how to get this working?
In reply to joe cool

Re: Jmol filter to view molecular structures

by joe cool -
I found the problem -

The variable $PHP_SELF is empty. I simply added this:

$PHP_SELF = $_SERVER['PHP_SELF'];

early in the function, before the variable was used.

It now works.

This variable is a global, but was not set for me. 

This was in this particular function:
jmol_filter($courseid, $text) in moodle/filter/jmol/filter.php,

and also in function
display() in moodle/mod/resource/type/jmol/resource.class.php.


To get the filter and resource both working, I added the above line to both functions in both files.
In reply to joe cool

Re: Jmol filter to view molecular structures

by Dan Stowell -
Joe -

Many thanks for pointing this out. The $PHP_SELF variable only appears if you have "register globals" turned on, which I hadn't realised - so I have updated the code so it uses $_SERVER['PHP_SELF'] instead.

(The downloadable version will update overnight.)
In reply to Dan Stowell

The filter is too crude...

by Patrick Pollet -
Hello,

I was really pleased to put the new Jmol filter in my site... and my chemistry colleagues are happily inserting 3D structures in their courses... but they stumbled on a quirk when the Moodle document already has another href link before the link to the structure file on the same page.
In that circumstance, the filter remove all text from the first link till the end of the Jmol's file link.

As an example :
 
this test page has a link to Jmol's main site and one molecule to see here


As you can see in the attached image, all text "to Jmol's main site ....to see" is removed by the filter.

I suspect that the regular expression used in filter.php is a bit too greedy (?) (glouton as we say in french wink)

I have tried without success to put the two links in separate table cells or div or span...


Attachment bug_jmol_filter.png
In reply to Patrick Pollet

French translation of jmol.html file

by Patrick Pollet -
Hello again,

Please find enclosed a french translation of the help file jmol.html, to be included in a lang/fr/help/jmol directory of the resource and the filter archives.

Hopes it does not smell too much garlic wink

Cheers

In reply to Patrick Pollet

Re: The filter is too crude...

by Dan Stowell -
Patrick - Thanks for pointing this quirk out! I've now fixed it. The updated version is in CVS, or can be downloaded from Moodle's modules database when the ZIP file updates overnight.
In reply to Dan Stowell

Re: The filter is too crude...

by Patrick Pollet -
Not yet updated overnight ...

When downloading the zip file from modules database, I get  a
version dated may 3 2006 (8567 mai  3 04:12 filter.php) instead of the
version dated may 2 2006 ( 8480 mai  2 14:45 filter.php) that looks like
an older version where the global $PHP_SELF has been removed but
nothing changed in the regular expression .

[root@cipcnet jmol]# diff -u filter.php /var/www/html/moodle/filter/jmol/
--- filter.php 2006-05-03 04:12:29.000000000 +0200
+++ /var/www/html/moodle/filter/jmol/filter.php 2006-05-02 14:45:10.000000000 +0200
@@ -19,7 +19,7 @@
/// courseid and the text to be filtered (in HTML form).

function jmol_filter($courseid, $text) {
- global $CFG, $jmol_applet_has_been_initialised;
+ global $CFG, $PHP_SELF, $jmol_applet_has_been_initialised;

// The global variable "$filter_jmol_has_initialized"
// is used by BOTH the Jmol filter and the Jmol resource type
@@ -41,7 +41,7 @@
]);
jmolHtml("&nbsp; &nbsp;");
jmolCheckbox("spin on", "spin off", "Spin");
- </script>&nbsp;&nbsp;<a href="\\2" title="Download the \\3 structure data file"><img align="absmiddle" height="17" width="17" src="'.$u.'/filter/jmol/download.gif" alt="Download" /></a>&nbsp;&nbsp;<a target="popup" href = "'.$u.'/help.php?module=jmol&amp;file=jmol.html" onclick = "return openpopup(\'/help.php?module=jmol&amp;file=jmol.html\', \'popup\', \'menubar=0,location=0,scrollbars,resizeable,width=550,height=550\', 0);" title="Help with Jmol"><img align="absmiddle" height="17" width="17" src="'.$u.'/pix/help.gif" alt="Help" /></a></form>';
+ </script>&nbsp;&nbsp;<a href="\\2" title="Download the structure data file"><img align="absmiddle" height="17" width="17" src="'.$u.'/filter/jmol/download.gif" /></a>&nbsp;&nbsp;<a target="popup" href = "'.$u.'/help.php?module=jmol&amp;file=jmol.html" onclick = "return openpopup(\'/help.php?module=jmol&amp;file=jmol.html\', \'popup\', \'menubar=0,location=0,scrollbars,resizeable,width=515,height=515\', 0);" title="Help with Jmol"><img align="absmiddle" height="17" width="17" src="'.$u.'/pix/help.gif" /></a></form>';



@@ -50,7 +50,7 @@
}else{
$relurl = ''; // This will typically be the case if Moodle is the web root
}
- $numdirs = substr_count($_SERVER['PHP_SELF'], '/') - 1;
+ $numdirs = substr_count($PHP_SELF, '/') - 1;
if($numdirs==0){
$relurl = './' . $relurl;
}else{
@@ -87,7 +87,7 @@
jmolCheckbox("set unitcell 4;color unitcell goldenrod", "set unitcell off", "Unit Cell");
jmolHtml("&nbsp;");
jmolCheckbox("spin on", "spin off", "Spin");
- </script>&nbsp;&nbsp;<a href="\'.$matches[2].\'" title="Download the .\'.$matches[3].\' structure data file"><img align="absmiddle" height="17" width="17" src="'.$u.'/filter/jmol/download.gif" /></a>&nbsp;&nbsp;<a target="popup" href = "'.$u.'/help.php?module=jmol&amp;file=jmol.html" onclick = "return openpopup(\\\'/help.php?module=jmol&amp;file=jmol.html\\\', \\\'popup\\\', \\\'menubar=0,location=0,scrollbars,resizeable,width=515,height=515\\\', 0);" title="Help with Jmol"><img align="absmiddle" height="17" width="17" src="'.$u.'/pix/help.gif" /></a></form>\';
+ </script>&nbsp;&nbsp;<a href="\'.$matches[2].\'" title="Download the structure datafile"><img align="absmiddle" height="17" width="17" src="'.$u.'/filter/jmol/download.gif" /></a>&nbsp;&nbsp;<a target="popup" href = "'.$u.'/help.php?module=jmol&amp;file=jmol.html" onclick = "return openpopup(\\\'/help.php?module=jmol&amp;file=jmol.html\\\', \\\'popup\\\', \\\'menubar=0,location=0,scrollbars,resizeable,width=515,height=515\\\', 0);" title="Help with Jmol"><img align="absmiddle" height="17" width="17" src="'.$u.'/pix/help.gif" /></a></form>\';
break;
case 3:
$controls =\'jmolBr();
@@ -101,7 +101,7 @@
]);
jmolHtml("&nbsp;");
jmolCheckbox("spin on", "spin off", "Spin");
- </script>&nbsp;&nbsp;<a href="\'.$matches[2].\'" title="Download the .\'.$matches[3].\' structure data file"><img align="absmiddle" height="17" width="17" src="'.$u.'/filter/jmol/download.gif" /></a>&nbsp;&nbsp;<a target="popup" href = "'.$u.'/help.php?module=jmol&amp;file=jmol.html" onclick = "return openpopup(\\\'/help.php?module=jmol&amp;file=jmol.html\\\', \\\'popup\\\', \\\'menubar=0,location=0,scrollbars,resizeable,width=515,height=515\\\', 0);" title="Help with Jmol"><img align="absmiddle" height="17" width="17" src="'.$u.'/pix/help.gif" /></a></form>\';
+ </script>&nbsp;&nbsp;<a href="\'.$matches[2].\'" title="Download the structure datafile"><img align="absmiddle" height="17" width="17" src="'.$u.'/filter/jmol/download.gif" /></a>&nbsp;&nbsp;<a target="popup" href = "'.$u.'/help.php?module=jmol&amp;file=jmol.html" onclick = "return openpopup(\\\'/help.php?module=jmol&amp;file=jmol.html\\\', \\\'popup\\\', \\\'menubar=0,location=0,scrollbars,resizeable,width=515,height=515\\\', 0);" title="Help with Jmol"><img align="absmiddle" height="17" width="17" src="'.$u.'/pix/help.gif" /></a></form>\';
break;
default:
$controls =\'jmolBr();
@@ -113,7 +113,7 @@
]);
jmolHtml("&nbsp; &nbsp;");
jmolCheckbox("spin on", "spin off", "Spin");
- </script>&nbsp;&nbsp;<a href="\'.$matches[2].\'" title="Download the .\'.$matches[3].\' structure data file"><img align="absmiddle" height="17" width="17" src="'.$u.'/filter/jmol/download.gif" /></a>&nbsp;&nbsp;<a target="popup" href = "'.$u.'/help.php?module=jmol&amp;file=jmol.html" onclick = "return openpopup(\\\'/help.php?module=jmol&amp;file=jmol.html\\\', \\\'popup\\\', \\\'menubar=0,location=0,scrollbars,resizeable,width=515,height=515\\\', 0);" title="Help with Jmol"><img align="absmiddle" height="17" width="17" src="'.$u.'/pix/help.gif" /></a></form>\';
+ </script>&nbsp;&nbsp;<a href="\'.$matches[2].\'" title="Download the structure datafile"><img align="absmiddle" height="17" width="17" src="'.$u.'/filter/jmol/download.gif" /></a>&nbsp;&nbsp;<a target="popup" href = "'.$u.'/help.php?module=jmol&amp;file=jmol.html" onclick = "return openpopup(\\\'/help.php?module=jmol&amp;file=jmol.html\\\', \\\'popup\\\', \\\'menubar=0,location=0,scrollbars,resizeable,width=515,height=515\\\', 0);" title="Help with Jmol"><img align="absmiddle" height="17" width="17" src="'.$u.'/pix/help.gif" /></a></form>\';
} // End of switch
if(sizeof($matches)>8){
//echo "Found Jmol script: $matches[8]";


And when  browsing the CVS I see a version 1.6 dated 23th of march  ?

In reply to Patrick Pollet

Re: The filter is too crude...

by Dan Stowell -
I don't know what timezone is used for the bundling, so I can't really define "overnight"... but it's up-to-date now.

Don't "browse the CVS" if you want up-to-date files, by the way - Sourceforge's anonymous CVS is currently not updating, so it's frozen in the past.
In reply to Dan Stowell

Re: The filter is too crude...

by Patrick Pollet -
Thanks a lot . It is indeed up to date and works like a charm !

I have set up a small course to "tease" my chemistry colleagues

http://cipcnet.insa-lyon.fr/moodle/course/view.php?id=56
(guests are OK)

It is in French, but if you can read this language, you will find in " Mode d'emploi express" a quick how-to to use Jmol under Moodle, a bit more detailed that the wiki english page.

I think I should find some time to contribute to the Wiki (at least translate your (?) Jmol resource and Jmol filter pages to the french Wiki ... wink)

Thanks again .
In reply to Patrick Pollet

Re: The filter is too crude...

by Dan Stowell -
Bonnes essais! (I hope that's right - it's a long time since I learnt French wink)

I like "Quelques molécules d'eau pour vous rafraichir..."big grin

It would be great if you put some french-language Jmol documentation into the MoodleDocs wiki - your "Mode d'emploi express" page looks like it could be suitable for the wiki (with a couple of the URLs removed) if you feel that's OK.
In reply to Dan Stowell

Re: The filter is too crude...

by jean loup valade -
I am a french teatcher from paris and I begin with moodle. I have put the jmol filter on my site and I think it's a very interesting tool for us (biochemistry teatcher).

But (there is always a but) when I try it with quiz I can't have a quiz with the applet included. I try to put the applet by a link with the html editor as I do for  the other modules. When I do that the applet is good but I can't answer the quiz !
am I wrong or isn't it possible to use jmol filter with quiz ?

I apologize for my bad english and thank you for the work on jmol filter
In reply to jean loup valade

Re: Jmol filter problem

by Dan Stowell -
Hi - what do you mean "I can't answer the quiz"? It works fine for me, so more details are needed...

Do you mean that the answer box is missing? frozen? The "submit" button is missing?

What question type are you using? Perhaps there's a specific problem there.
In reply to Dan Stowell

Re: Jmol filter problem

by jean loup valade -
No all the buttons are présents but when I clik on the submit button nothing happens.
I have tried with true/false question and with multiple choices question.
I use firfox under linux but I am going to try with IE under XP to see if it is différent.
to display the molécule I put a link using the html editor (is-it right ?).
Thank you

In reply to jean loup valade

Re: Jmol filter problem

by jean loup valade -
two sanpashots in the zip file to see the way i try to use jmol filter with quiz and the quiz where the button "envoyer" do nothing when there is a applet jmol included in the question.
In reply to jean loup valade

Re: Jmol filter problem

by jean loup valade -
I found the solution for me and perhaps for other people ( smile). In fact there was some tags (<form> and </form>) which interfere with the quiz. I have deleted all these tags in "filter.php". I think they have bin add with the buttons to the applet. When I delete this tags the buttons are till in the right place and do there jobs.
"merci" and have a nice day,
In reply to jean loup valade

Re: Jmol filter problem

by Dan Stowell -
I see. The form tag could be important sometimes, to make the page validate correctly. But in quizzes, it ends up with one-form-inside-another, which seems to confuse Internet Explorer. (I presume that's what you were using? Firefox handles it fine.)

I've committed another change to the Jmol filter so that now there's a parameter you can use to turn the <form> tags on or off. Just add ?f=0 to the end of the URL to prevent the form tags appearing.
In reply to Dan Stowell

Re: Jmol filter problem

by Russ Maurer -
Hi, I'm new to this discussion.  I've been using the jmol filter with no problems, except that it loads automatically (like it's supposed to).  But there are times when I would like the jmol to load in response to a student click on a link.  How do I code this?  For example, I would like to make a page listing all the different structure files that I have (in the moodle directory) with the idea that a student would click on, say, water, which would cause jmol to display water.pdb.  I have well over 100 files to choose from, so displaying them all simultaneously is not an option.

And while I'm thinking here, would there be a way for a student to CLOSE jmol in this case?

Russ
In reply to Russ Maurer

Re: Jmol filter problem

by Geoffrey Rowland -
Picture of Plugin developers
Russ

I think that Dan Stowell's Jmol Resource type offers most or all that you need. It provides much the same functionality as the Jmol filter, but with a more user-friendly configuration interface and, similar to other resource types, provides links to the Jmol displays (rather than displaying them directly).

An alternative 'trick', that you may find useful, is to use the Jmol filter with different structures as different Glossary entries. If appropriate, the Glossary can be set up to auto-link any reference to a particular structure in a Moodle Course, to its Jmol representation.

I'll post links to more examples of the use of Jmol with Moodle, many of which were presented at the recent Moodle Moot, in the near future (I just need to tidy few things up).

Geoff
In reply to Geoffrey Rowland

Re: Jmol filter problem

by Russ Maurer -
The jmol resource is installed at the hosting site I am using, but it does not seem to be working properly.  What happens is this:  On the "add a resource" drop down menu, I see an entry resourcetyperesource_jmol.  Choosing that produces an immediate error message,
Warning: main(/home/team/public_html/mod/resource/type/resourcejmol/resource.class.php): failed to open stream: No such file or directory in /home/team/public_html/mod/resource/mod.html on line 6

What do you suggest?

Russ
In reply to Russ Maurer

Re: Jmol filter problem

by Geoffrey Rowland -
Picture of Plugin developers
Russ

It would seem that not all the Jmol resource type components are installed in their correct folders on your hosted Moodle. The setup is a little fiddly  mixed - but well worth it smile.  It has worked for me with both Moodle 1.5.3  and Moodle 1.6 with either PHP4 or PHP5

Instructions (from the readme.txt file included with the Jmol resource type) follow. I hope this helps.

TO INSTALL:

1. Copy the folder that comes with this download, from its location
mod/resource/type/jmol, to the exact same location in your Moodle web server.

2. Copy the language files from lang/en (and various subfolders) to the exact
parallel locations in your Moodle web server.

You should also add a new 'text string' to the existing Moodle language file,
lang/en/resource.php. This is the line to add:

$string['resourcetypejmol'] = 'Display a 3D molecule viewer';

3. OPTIONAL - Setting the Jmol icon - this is a little tricksy but looks good:
Firstly, copy the icon from pix/f/jmol.gif to the equivalent position on the
Moodle server. Secondly, modify mod/resource/lib.php and modify the function
resource_get_coursemodule_info($coursemodule) so that it sets the icon
correctly for "jmol" resource type. The following shows lines 376-387 AFTER
modification - note the extra "else if" clause we've added at the end:

       if ($resource->type == 'file') {
           $icon = mimeinfo("icon", $resource->reference);
           if ($icon != 'unknown.gif') {
               $info->icon ="f/$icon";
           } else {
               $info->icon ="f/web.gif";
           }
       } else if ($resource->type == 'directory') {
           $info->icon ="f/folder.gif";
       } else if ($resource->type == 'jmol') {
           $info->icon ="f/jmol.gif";
       }

The line numbers may not correspond exactly in your copy of the lib file.
In reply to Geoffrey Rowland

Re: Jmol filter problem

by Russ Maurer -
OK, my admin got the jmol resource straightened out, thank you.  Turns out, though, I have more use for the filter, especially now that I've learned how to launch a script with the filter.  But now comes a problem that I didn't anticipate.  If I use a script to set a molecule spinning, the jmol filter is a CPU hog - much, much more so than the standalone jmol on my desktop with the same molecule, same size easel, same script.  Anyone have a clue why?  I wanted to put a randomly selected molecule spinning in a block on my chemistry class home page, but I'm not going to be able to do that as things stand because the user can't do anything else while the molecule spins...jmol takes 100% of my poor little 700 MHz processor.

Russ
In reply to Russ Maurer

Re: Jmol filter problem

by Geoffrey Rowland -
Picture of Plugin developers
Russ

Certainly, spinning the molecule is more resource intensive, although I have not made detailed comparisons with the standalone. That is why spinning is turned off by default.

A couple of things that *may* help are to reduce the size of the Jmol applet and also to turn off Perspective Depth - You can experiment with the latter using the Jmol menu (Right-click > Options > Perspective Depth) and, if useful, set it in a script.e.g. JMOLSCRIPT{ set perspectiveDepth OFF}.

Geoff
In reply to Russ Maurer

Re: Jmol filter problem

by Dan Stowell -
I've noticed this CPU issue too. It seems to be browser-dependent and I think it's basically a deficiency of the way the browser and Java interact - for example, the browser may be repainting the applet area more often than necessary (although I can't tell). I'm afraid I can't think of any way to get beyond this point, and I'm afraid I don't have time at the moment either. The Jmol user forums may be a good place to ask if there's much known about this issue.
In reply to Russ Maurer

Re: Jmol filter problem

by William Cumming -

Russ - what did the admin do - I cannot get the resource to load properly - I get the message to check permissions?

any ideas?

In reply to Dan Stowell

Re: Jmol filter to view molecular structures

by William Cumming -

I have followed all the instructions get a blank screen when I try to use the jmol filter.

Any Ideas?

In reply to William Cumming

Re: Jmol filter to view molecular structures

by kathy hooper -
I have the same problem at

http://moodle.aggs.school.nz/course/view.php?id=549

I can view the filter working on other sites, so it is not my browser thats at fault

the java consol gives this message

load: class JmolApplet not found.
java.lang.ClassNotFoundException: JmolApplet

I would reallylike to get this working as I want to move away from chime.
Any help would be appreciated
Kathy

In reply to kathy hooper

Re: Jmol filter to view molecular structures

by Geoffrey Rowland -
Picture of Plugin developers
Kathy

I can confirm your problem, so it is something server-side.

At the risk of stating the obvious, check you have followed the instructions in the Jmol filter readme file, and you are linking to a bone fide stucture file (e.g. .pdb) that you have uploaded to the /files folder of the particular course. The link should just be a simple hyperlink. Using Moodle's HTML editor, I usually type in an appropriate word, select it, then use the Insert Web link button to browse to the uploaded structure file. For more complex scripting, I usually use the 'Toggle HTML Source' button to edit the raw code directly (or turn off the HTML editor in my profile).

Hmmm... I notice you are running Moodle 1.7. I'm still on 1.6 and have not yet tested the Jmol filter, or the Jmol resource type, on 1.7 - so you may have identified a problem with Moodle 1.7 compatibility. Perhaps other Moodle 1.7 users could confirm whether or not the Jmol filter works for them! I'll check this out myself, and if necessary try to fix things, as soon as I can - but probably won't be for a few weeks.

Once this is working, I'm sure you won't be disappointed with Jmol as a Chime alternative. Indeed, the soon-to-be-released Jmol 11 has even more capabilities (e.g. orbital display, extended crystal building from unit cells, etc).
In reply to Geoffrey Rowland

Re: Jmol filter to view molecular structures

by Geoffrey Rowland -
Picture of Plugin developers
OK, I can confirm the that the problem is NOT with Moodle 1.7 - as I have just tested that both the Jmol Filter and Jmol Resource type work when installed on a fresh Moodle 1.7+ installation (PHP 5.1.6 MySQL 5.0.24).

If you continue to have problems, you could send me a separate email (not via these forums!) with teacher username/password details for a demo course, and I'll try to diagnose things on your server.
In reply to Geoffrey Rowland

Re: Jmol filter to view molecular structures

by Huw Dixon -
I "must" be missing something here on getting this filter working to display inline pdb files. I've installed the filter according to the readme.txt file, activated it via admin. I'm running Moodle 1.7. If I create a label (or anything) and put a hyperlink to the uploaded pdb file in it, I get the Download file icon inplace of the text link and no "filtered" inline image. I've tried this under Firlefox and Safari - same results. The images display fine in my browser when I visit http://moodle.yeovil.ac.uk/course/view.php?id=63 for example so it has to be something server based I've overlooked.

Can anyone point out other items to look at to determine what I'm missing?

thx


In reply to Huw Dixon

Re: Jmol filter to view molecular structures

by Huw Dixon -
I've got more info on the above problem. The java console shows errors for jmolinitialize and jmolApplet not being defined when I pull up the course page that has my test pdb links. The particular source for the page has Jmol.js referenced as:
<script type="text/javascript" src="moodle/filter/jmol/Jmol.js"></script>

I have verified that the Jmol.js is indeed in that location and that
permission, owner, group, etc. are set appropriately.

I'd appreciate any tips on looking further into possible causes.

Thanks



In reply to Dan Stowell

Re: Jmol filter to view molecular structures

by Jeff Hansen -
We have recently installed Moodle and are testing it this semester. I have incorporated some models into my site using Jmol. My problem is that these Jmol molecules do not work in Firefox 2.0.0.1 on my Mac. They work fine using the Safari browser. When using Firefox I get an error message containing the following in the Java log.

FileManager.openFile(../../file.php/11/Structures/1a3n.pdb)
SmarterJmolAdapter:The Resolver thinks:null
error opening http://moodle.depauw.edu/file.php/11/Structures/1a3n.pdb
unrecognized file format
openFile(../../file.php/11/Structures/1a3n.pdb) 827 ms

I have confirmed that this is not a Jmol problem. If anyone could confirm this problem and offer suggestions for solutions I would appreciate it. I believe the problem is only in Firefox on Mac. Others have checked with other systems and browsers and also at other Moodle sites.
In reply to Jeff Hansen

Re: Jmol filter to view molecular structures

by Thomas Burkholder -
When I tried to demonstrate Jmol to a friend with Firefox on Mac, we discovered that his java plugin was linked to a very dated version of java.

Type in about:plugins in the address bar of Firefox to see what version of java it is using. There's more information about the java plugin here:
http://javaplugin.sourceforge.net/
In reply to Thomas Burkholder

Re: Jmol filter to view molecular structures

by Jeff Hansen -
I've tried this and it doesn't help the situation. I've downloaded the java embedding plugin and installed it. The download from sourceforge includes two files, JavaEmbeddingPlugin.bundle and MRJPlugin.plugin. Both are two be copied into the /Library/Internet Plug-Ins folder. Without these two the applet appears to load but the molecule doesn't load. With the JavaEmbeddingPlugin.bundle installed the same behavior occurs. With the MRJPlugin.plugin installed the applet doesn't even load. This doesn't seem to be the problem. I'm thinking the problem is in the filter somewhere. For some reason the applet isn't recognizing the pdb file as being a format it can read. Why this happens only in Firefox is beyond me. I should add that even in Safari, when I use a different file type (xyz - which Jmol should be able to read) the same error occurs.
In reply to Jeff Hansen

Re: Jmol filter to view molecular structures

by Thomas Burkholder -
This wiki: http://wiki.jmol.org:81/index.php/Support/Osx has some details on how to get Firefox working with Java on OS X. As far as I can tell the Java plugin your installed only tells Firefox how to find the JVM.

If you suspect your Java installation is old, you can check the java version here: http://waterontheweb.org/data/java/trouble.html

The current release of Java for OS X 10.4 is here:
http://www.apple.com/support/downloads/javaformacosx104release5.html


In reply to Thomas Burkholder

Re: Jmol filter to view molecular structures

by Jeff Hansen -
Thanks for the suggestions. The waterontheweb link was helpful. It confirmed that Firefox is using the same java as Safari. So that can't be the problem.
In reply to Jeff Hansen

Re: Jmol filter to view molecular structures

by Geoffrey Rowland -
Picture of Plugin developers

Jeff

I have just updated the Jmol applet to version 11 at the following two sites, if prompted just [Login as a guest]. Have not yet updated the Moodle Jmol Filter/Resource download code.

http://moodle.yeovil.ac.uk/course/view.php?id=63

http://moodle.yeovil.ac.uk/course/view.php?id=795

These work for me (though there is a lot on them, so they may be slow to load sad) with Firefox 2.0.01 on Linux and Windows with Java 1.5/1.6. Haven't got access to Macs so can't test your problem directly. Will be grateful for your feedback whether things work for you.

If the problem is due to incompatibilities with the Moodle Jmol Filter/Resource code, it may by worth testing the Hexokinase link in the second URL as this has the Jmol 11 applet packaged rather differently as an IMS Content Package using Reload. Again, let me know if this displays correctly with your setup.

Indeed, if you have existing Jmol-based resources web pages with complex controls/scripting, you may even find it easier to bundle these up with Reload, then stick them on Moodle. They should even be portable to other VLEs (though of course you will stick with Moodle! wink)

Of course, the Jmol Filter and Resource offer a quick and convenient way to insert 3D chemical structures in a Moodle page. However, I have noticed that in certain circumstances, multiple instances of the Jmol applet, e.g in Glossaries, can be problematic.

It's our half-term, so I have a few days away from teaching to tinker with this and update some of the code and documentation.

Regards

Geoff

In reply to Geoffrey Rowland

Re: Jmol filter to view molecular structures

by Jeff Hansen -
Thanks for the help Geoff.

I tried both of your links. Both worked in Safari. Neither worked in Firefox. This includes the Hexokinase link you asked me to check. I've uploaded a screen shot from Firefox so you can see what it is doing.

I'm just getting started with Moodle and have some, but not a lot of experience with Jmol. It seems that doing Jmol in Moodle adds an additional layer of complexity. This is unfortunate since Jmol is complex enough as it is. I intende to do more with Jmol this semester than I have in the past, including having my students prepare presentations using Jmol for my Enzyme Mechanisms class. I see that there are several options for me to put Jmol content onto a site. Are there any options for students to put Jmol content onto the site?

Attachment screenshot1.jpeg
In reply to Jeff Hansen

Re: Jmol filter to view molecular structures

by Geoffrey Rowland -
Picture of Plugin developers

Hmmm...

It is tricky trying to diagnose things without being able to test with the Mac/Firefox/Java combo. From your screenshot it appears the .xyz format is not being recognised, so I'm wondering whether it is an issue with the way Moodle serves up Chemical MIME types - and that Mac/Firefox/Java is particularly fastidious about this. I am assuming Jmol applets are working fine in 'non-Moodle' locations.

Had a (possibly) similar issue with SVG graphics files a while back. So I have naively tried the same solution by adding the following lines to function get_mimetypes_array()in /lib/filelib.php on our Moodle server (may also have to do something similar with the Jmol Filter/Resource code).

'pdb' => array ('type'=>'chemical/x-pdb', 'icon'=>'jmol.gif'),

'xyz' => array ('type'=>'chemical/x-xyz', 'icon'=>'jmol.gif'),

So take another peek at the links posted previously and see if that fixes things, at least for .xyz and .pdb files. If so, I'll add similar code for other Jmol file types.

If not, its back to the straw-clutching & head-scratching....

Geoff

In reply to Geoffrey Rowland

Re: Jmol filter to view molecular structures

by Jeff Hansen -
You are correct that Jmol applets are working fine in "non-Moodle" locations.

Unfortunately, I see no change in the behavior of those pages now. Still scratching...

In reply to Jeff Hansen

Re: Jmol filter to view molecular structures

by Geoffrey Rowland -
Picture of Plugin developers

Not sure if this helps with the diagnosis, but very occasionally I'm getting the same error as in your screenshot with Opera and Firefox on Linux. Seems to occur when the system is 'overloaded' e.g. when I'm switching to/from edit mode in a Moodle course with Jmol content and possibly if I'm switching between different versions of the Jmol applet. Not definite about this as it is hard to reproduce (only seen it three times in total). In my case a browser refresh has fixed the problem. Presumably you have tried refreshing you browser, clearing your browser cache, restarting your browser, rebooting, having a cup of coffee... etc

Further straw-clutching: I have tweaked a few more things on our server, including the threshold of our DOS evasive module, so although I don't hold any great hope it may be worth revisiting.

Otherwise the applet-gurus in the Jmol user forums may be your best bet (though I see you have been there already)

...or just stick with Safari wink

In reply to Geoffrey Rowland

Re: Jmol filter to view molecular structures

by Jeff Hansen -
Ok. Thanks for taking a look at it. Perhaps an update to Firefox or Moodle in the future will somehow take care of this. For now I'll have to live with it.
In reply to Dan Stowell

Re: Jmol filter to view molecular structures

by timila dhakhwa -
Hi I am a student at lake Forest College, currently working for the LIT and mew to Jmol. We are looking at the possibilities of starting the use of Jmol for our chemistry classes. I have a question for you:
1. We have downloaded the Jmol filter for the administration acc but how do you insert it in the class?
Maybe this was the reason why even after uploading a pdb file, it did not open up in Moodle.
Any suggestions?
Thanks,
Timila
In reply to Dan Stowell

Jmol - suggestions on where to find PDB files?

by Joyce Seitzinger -
Hello everyone,
I'm aiding 2 chemistry teachers in developing 2 fully online chemistry courses. We've all gotten really excited about Jmol and Jmol filter in Moodle. However I'm not a chemist so finding it really difficult to help them get further. So I hope you can all help me with these 2 questions:

1. Can anyone suggest good places to find PDB (or other compatible files)?

2. Is it possible to get students to build their own molecular structures, using Jmol or other, which they could share?

Thanks,
Joyce
In reply to Joyce Seitzinger

Re: Jmol - suggestions on where to find PDB files?

by Geoffrey Rowland -
Picture of Plugin developers
Joyce

A good place to start for .pdb and other chemical structure files (.mol, .xyz, .cif etc) are the 'MolViz' resources developed and compiled by Eric Martz and coworkers.

Molecules: Sources of PDB Files

The MolViz site has lots of other molecular display resources, tutorials etc that you can use directly, or use as inspiration for your own. Typically these were originally developed for the MDL Chime plugin, but most have now been updated to use the Jmol Applet.

A good Windows-based tool for drawing 2D structures of, say, simple organic molecules, performing a basic 3D structure optimisation and saving in a form that can be viewed in Jmol is ChemSketch. It has a Freeware version and there is a Free Campus Licence for Academic instututions.

There lots of other commercial and free (freeware and open-source) molecular modelling/display packages that may suit your particular purposes, though they tend to be designed for specialist research use.

The Moodle Jmol filter *should* work for forum or blog posting, which may be a way for students to 'publish' their own chemical structures. I suspect that the Jmol filter won't work with the Moodle Wiki oe NWiki, though haven't actually tested this.

There are also Jmol filters/extensions for Elgg and MediaWiki, both of which 'sit nicely alongside' Moodle.

I'll post again if I think of anything else. I'm also currently working on an update of the Moodle JMol Resource/Filter that I hope to release in a month or two.

Geoff
In reply to Geoffrey Rowland

Re: Jmol - suggestions on where to find PDB files?

by Geoffrey Rowland -
Picture of Plugin developers
Here are a few more sources that may be useful...

Molecule Databases
Other sources of molecules

Tools
...Enjoy! wink
Average of ratings: Useful (1)
In reply to Dan Stowell

Re: Jmol filter to view molecular structures

by Ian Hunt -

I'm new to Moodle, but have used JMOL on webpages and in another older LMS for many years. The problem I have encountered is that the images don't show multiple bonds. My source is a pdb file that I editted to show the multiple bonds and this appoach has worked for me in the past. Why is the Moodle version different ? Do I need to use a different file type such as a mol file ?

In reply to Ian Hunt

Re: Jmol filter to view molecular structures

by Geoffrey Rowland -
Picture of Plugin developers

Hi Ian

Recent versions of Jmol have many options for displaying bond orders, single, double, triple, partial, aromatic bonds etc. Older 'hacks' such as specifying multiple CONECT records in PDB files, should still work, though you may need to add an initial Jmol script to get the precise effect you want. The following may do the trick:

set showMultipleBonds ON

For more detail see:

http://wiki.jmol.org/index.php/Support_for_bond_orders

http://chemapps.stolaf.edu/jmol/docs/#setbondstyles

Hope that helps.

In reply to Geoffrey Rowland

Re: Jmol filter to view molecular structures

by Ian Hunt -

Adding the jmol script for set showMultipleBonds did not work (though I could make other scripts work). So far none of my "hacked" pdb files work in Moodle with JMOL 1.0.39 (mol files seem to work)  and yet the same pdb files work outside of Moodle with JMOL 12.0.34

In reply to Ian Hunt

Re: Jmol filter to view molecular structures

by Geoffrey Rowland -
Picture of Plugin developers

Hi Ian

I'll take a more detailed look at this over the next few days (start of teaching and all that)

You could just try replacing the bundled Jmol applet code with the equivalent files from the version that works for you. Do check the version from the Jmol menu (right click) as Java applet caching etc can sometimes play funny tricks.

I'll also check the plugin code itself for any hard-coded scripts that may block multiple bonds being displayed. Are you using the version for Moodle 1.9 or 2.x ?

In reply to Geoffrey Rowland

Re: Jmol filter to view molecular structures

by Ian Hunt -

I now believe that the multiple bond issue is a JMOL problem and not related to Moodle because:

1. when I try JMOL 12.0.39 on our webpages the multiple bonds fail to show

2. when I put the JMOL 12.0.34 applet code into Moodle, the multiple bonds show as I would like.