First scripts

Scripts for all examples can be downloaded here. To used them as a template, please ajust the file according to your need.

Simple script example

var basePath = "cwd/data/";
var sysPath = "file://" + basePath + "md_1u19.gro";
stage.loadFile( sysPath ).then( function( comp ){
    comp.addRepresentation( "cartoon" );
    comp.addTrajectory( basePath  + "md_1u19.xtc" );
} );

This script example is partly extracted from the sample .ngl file. It loads a structure (structure.gro) file with the cartoon representation and a simulation (sim.xtc) into the NGL Viewer.


var trajSele = {
	sele: "backbone and not hydrogen", initialFrame: -1,
	centerPdb: true, removePbc: true, superpose: true;
	defaultTimeout: 20, defaultStep: 3
};
comp.addRepresentation( "licorice", { visible: false } );
comp.addTrajectory( basePath  + "@md_1u19.xtc", trajSele );

Trajectories can have different configurations. Some default values are displayed above, others are changed accordingly to the simulation. -1 for the initial frame refers to the conformation of the structure file. To load several parts of a continuous simulation (md_1u19.part0001.xtc, md_1u19.part0002, ... ), add the @ symbol before the name of the trajectory. This is especially useful if you inspect unprocessed trajectories.


panel.setName( "A simple example" );
stage.setParameters( { backgroundColor: "white", hoverTimeout: -1 } );

The panel (see also the NGL GUI guide) can be named and several stage options are available. Here we present how to change the background colour and how to disable the mouse visualization option - for more please consult the NGL documentation.


Basic functions

var h = scriptHelperFunctions(stage, panel)
h.uiButton(
    "reverse view",
    function(){
        stage.eachComponent( function( comp ){
            if (comp.visible === true){
                h.visible( false, comp );
            }else{
                h.visible( true, comp );
            }
        } );
    }
);
h.uiButton(
    "sidechains on/off",
    function(){
        h.representations( "licorice" ).list.forEach( function( repre ){
            h.visible(!repre.visible, repre);
        } );
    }
);

In order to generate clickable functions for session-like behaviour, a class (scriptHelperFunctions) has to be included. The first function "reverse view" changes for each component within the session the visibility, the second function "sidechains on/off" changes for each licorice representation of every component within the session the visibility. With these two functions, you can change component and representation features.

Complete script

All functions and script snipplets explained above are collected within a script, presented below and downloadable here. The ending of the file can be ".ngl" or ".js". Further scripts can be extracted and modifiered by they user. They can be downloaded.

panel.setName( "A simple example" );
stage.setParameters( { backgroundColor: "white", hoverTimeout: -1 } );
var h = scriptHelperFunctions(stage, panel)
h.uiButton(
    "reverse view",
    function(){
        stage.eachComponent( function( comp ){
            if (comp.visible === true){
                h.visible( false, comp );
            }else{
                h.visible( true, comp );
            }
        } );
    }
);
h.uiButton(
    "sidechains on/off",
    function(){
        h.representations( "licorice" ).list.forEach( function( repre ){
            h.visible(!repre.visible, repre);
        } );
    }
);

//Function to load a structure & two trajectories individually
var trajSele = {
    sele: "backbone and not #h", initialFrame: -1, centerPdb: true,
    removePbc: ture, superpose: true; defaultTimeout: 20, defaultStep: 3
    };
var basePath = "cwd/data/";
var sysPath = "file://" + basePath + "md_1u19.gro";
stage.loadFile( sysPath ).then( function( comp ){
    comp.addRepresentation( "cartoon" );
		comp.addRepresentation( "licorice", {visible: false} );
    comp.addTrajectory( basePath  + "md_1u19.xtc", trajSele );
    comp.addTrajectory( basePath  + "/@md_1u19.xtc", trajSele );
    comp.centerView();
} );

More

If you have any questions, found some bugs, or want to report enhancement requests use the Issue Tracker, use the contact formular or write a mail to johanna.tiemann@gmail.com or alexander.rose@weirdbyte.de.

Please give us feedback!

top