Proteopedia:DIY:Macros: Difference between revisions
mNo edit summary |
m fix text |
||
(29 intermediate revisions by the same user not shown) | |||
Line 5: | Line 5: | ||
This page is meant to be a resource for finding and using macros. | This page is meant to be a resource for finding and using macros. | ||
<StructureSection load=' | <StructureSection load='1mbo' size='340' side='right' caption='Structure of myoglobin in complex with heme and oxygen' scene=''> | ||
==Defined Macros== | ==Defined Macros== | ||
Line 14: | Line 14: | ||
Integrating macro use into JSmol code is straightforward. | Integrating macro use into JSmol code is straightforward. | ||
'''Example #1: Calling a simple macro function''' | |||
This example doesn't require any parameter to act. It causes the structure shown to 'bobble'. | |||
<!-- | |||
<pre> | <pre> | ||
<jmol> | <jmol> | ||
Line 21: | Line 24: | ||
<script> | <script> | ||
script /mc/ktheis.spt; | script /mc/ktheis.spt; | ||
if (~bobble) | if (~bobble); ~bobble=false; exit; else; bobble(); ~bobble=true; endif; | ||
</script> | </script> | ||
<text>Toggle Bobble on/off</text> | <text>Toggle Bobble on/off</text> | ||
Line 28: | Line 31: | ||
</pre> | </pre> | ||
The <code><nowiki>bobble()</nowiki></code> part triggers the action. The <code><nowiki>exit</nowiki></code> ends the looping bobble.<br/> | |||
You can try the result here: | |||
<jmol> | <jmol> | ||
<jmolLink> | <jmolLink> | ||
<script> | <script> | ||
spin off; | |||
script /mc/ktheis.spt; | script /mc/ktheis.spt; | ||
if (~bobble) | if (~bobble); ~bobble=false; exit; else; bobble(); ~bobble=true; endif; | ||
</script> | </script> | ||
<text>Toggle Bobble on/off</text> | <text>Toggle Bobble on/off</text> | ||
Line 40: | Line 45: | ||
</jmol> | </jmol> | ||
The <code><nowiki>bobble()</nowiki></code> | '''Doesn't seem to stop!?!?''' So what if a make separate buttons? That seems to work. | ||
--> | |||
<pre> | |||
<jmol> | |||
<jmolButton> | |||
<script>script /mc/ktheis.spt;bobble()</script> | |||
<text>Start Bobbling</text> | |||
</jmolButton> | |||
</jmol> <jmol> | |||
<jmolButton> | |||
<script>exit</script> | |||
<text>Stop Bobble</text> | |||
</jmolButton> | |||
</jmol> | |||
</pre> | |||
The <code><nowiki>bobble()</nowiki></code> button triggers the action. The other button uses <code><nowiki>exit</nowiki></code> to stop the looping bobble.<br/> | |||
You can try the result here: | |||
<jmol> | |||
<jmolButton> | |||
<script>script /mc/ktheis.spt;bobble()</script> | |||
<text>Start Bobbling</text> | |||
</jmolButton> | |||
</jmol> <jmol> | |||
<jmolButton> | |||
<script>exit</script> | |||
<text>Stop Bobble</text> | |||
</jmolButton> | |||
</jmol> | |||
'''Example #2: Supply the macro a parameter''' | |||
This example shows how to specify an item or items to act on by passing in a parameter. It is based on the 'Link' example at [[Jmol/Interactivity#Link|Jmol/Interactivity]] where the ligand 'blinks'. | |||
Example code: | |||
<pre> | |||
(<jmol> | |||
<jmolLink> | |||
<script>script /mc/ktheis.spt;blink({HEM})</script> | |||
<text>☼</text> | |||
</jmolLink> | |||
</jmol>) | |||
</pre> | |||
You can try the result here:<br/> | |||
To highlight the heme group, click on the green sun symbol in the parentheses --> (<jmol> | |||
<jmolLink> | |||
<script>script /mc/ktheis.spt;blink({HEM})</script> | |||
<text>☼</text> | |||
</jmolLink> | |||
</jmol>) | |||
'''Example #3: Another showing supplying the macro a parameter''' | |||
Example code: | |||
<pre> | |||
<jmol> | |||
<jmolLink> | |||
<script>script /mc/ktheis.spt;peekaboo({HEM})</script> | |||
<text>Hide Heme for a moment</text> | |||
</jmolLink> | |||
</jmol> | |||
</pre> | |||
You can try the result here:<br/> | |||
<jmol> | |||
<jmolLink> | |||
<script>script /mc/ktheis.spt;peekaboo({HEM})</script> | |||
<text>Hide Heme for a moment</text> | |||
</jmolLink> | |||
</jmol> | |||
==Coding New Macros== | ==Coding New Macros== | ||
Advanced users who want to code additional macros can get a flavor for the JSmol operating behind the scenes and ideas on how they'd code their own by examining the code for macros already available. To view an example go the [[Proteopedia:Macros]] page and note that examples such as the 'bobble()' example include notes on how you import it using <code><nowiki> script /mc/ktheis.spt</nowiki></code>. In particular note the <code><nowiki>/mc/ktheis.spt</nowiki></code> part after 'script'. That is the address of the script code stored at Proteopeida. Place that part after after <code><nowiki>http://proteopedia.org/wiki/</nowiki></code> so you end up at <code><nowiki>http://proteopedia.org/wiki//mc/ktheis.spt</nowiki></code> where you can see the code for several defined macro functions. | Advanced users who want to code additional macros can get a flavor for the JSmol operating behind the scenes and ideas on how they'd code their own by examining the code for macros already available. To view an example go the [[Proteopedia:Macros]] page and note that examples such as the 'bobble()' example include notes on how you import it using <code><nowiki> script /mc/ktheis.spt</nowiki></code>. In particular note the <code><nowiki>/mc/ktheis.spt</nowiki></code> part after 'script'. That is the address of the script code stored at Proteopeida. Place that part after after <code><nowiki>http://proteopedia.org/wiki/</nowiki></code> so you end up at <code><nowiki>http://proteopedia.org/wiki//mc/ktheis.spt</nowiki></code> where you can see the code for several defined macro functions. Jmol's documentation for user-defined functions, that serve as the basis the use of macros on Proteopedia, can be found [https://chemapps.stolaf.edu/jmol/docs/#functionsuser-definedfunctions here]. | ||
</StructureSection> | </StructureSection> |