How to hack S2S?

Use your favorite 3D viewer | S2S for protein alignments | Create new S2S tools and functions | Home

Last update : 8th July 2005

Use your favorite 3D viewer

You need to write a java class implementing the org.fjossinet.s2s.programs.Driver interface. You should direclty specialized the org.fjossinet.s2s.programs.OnHangApplicationDriver class. Take a look at how I did that for the PyMOL driver :

public class PymolApp extends OnHangApplicationDriver {

   public PymolApp() {
	     //define the command to launch. Options and arguments are stored in a String array
        super(S2SConfig.get3DViewerPath(), new String[]{"-pxq"});
    }

    public void evaluate(final S2SEvent event) {
	   if (S2SViewer.get3DMode() == Rna3D.NOTHING)
			return;
		final StringBuffer command = new StringBuffer();
		List bases = null;
		switch (event.getEventType()) {
			case S2SEvent.SHOWALL : this.runner.evaluate("show all"); break;
			case S2SEvent.HIDEALL : this.runner.evaluate("hide all"); break;
			case S2SEvent.NEW_COLOR :
				Object[] params = (Object[])event.getParameter();
				bases = (List)params[0];
				float[] rgb = ((Color)params[1]).getColorComponents(null);
				if (bases == null || bases.size() == 0 )
					return;
				for (int i = 0 ; i < bases.size()-1 ; i++ ) {
					b = (Residue)((Base2D)bases.get(i)).getS2SNode();
					command.append("resi ");
					command.append(b.getId());
					command.append(" and ");
					command.append("chain ");
					command.append(b.getChainId());
					command.append(" or ");
				}
				b = (Residue)((Base2D)bases.get(bases.size()-1)).getS2SNode();
				command.append("resi ");
				command.append(b.getId());
				command.append(" and ");
				command.append("chain ");
				command.append(b.getChainId());
				StringBuffer color = new StringBuffer("[ ");
				color.append(rgb[0]);
				color.append(", ");
				color.append(rgb[1]);
				color.append(", ");
				color.append(rgb[2]);
				color.append(" ]");
				this.runner.evaluate("set_color "+((Color)params[1]).getRGB()+", "+color.toString());
				this.runner.evaluate("color "+((Color)params[1]).getRGB()+",("+command.toString()+")");
				break;
			case S2SEvent.SELECTION :
				//and so on ....
			default : break;
		}
    
	 }

    public void close() {
        this.runner.evaluate("quit");
    }

}
Create a jar file containing your driver and copy it in the lib subdirectory. Register your driver by typing the java -jar ./lib/s2s.jar command inside the S2S directory and modify the "3D Viewer Driver" and "3D Viewer Tool" fields.

Restart S2S. Now, the Rna3DViewer tool will forward events from other tools to your favorite 3D Viewer.

S2S for protein alignments (still experimental)

S2S is designed to manipulate and display RNA data. When you open a PDB file, by default S2S takes only care of RNA molecules. If you want to use S2S to make alignments against protein sequences, you have to follow this trick. Type the java -jar ./lib/s2s.jar command inside the S2S directory. Set the "3D=>2D Tool" field to blank.

Restart S2S and open a PDB file containing at least one protein sequence. Since S2S has no value indicated in the s2s.prefs file to calculate a secondary structure, the Rna2DViewer cannot work with such configuration. Restore the initial s2s.prefs file to restore the S2S default behavior.

Create new S2S tools and functions

Using Java

You can add your own tool to S2S. These new tools can be seen as plugins for S2S. To develop your own plugin you need :

By implementing the S2SWidget interface, your tool will listen to any events launched by other tools. If you want to warn the other tools for its own changes, your tool has to provide references for one or more objects implementing the Changeable interface. These objects will be recruited by the S2S framework with the public Changeable[] getChangeables(); method described in the S2SWidget interface. This method need to return at least an empty Changeable array. Take a look at this simple example, where the S2SWidget is Changeable too :

public class MyWidget extends AbstractS2SWidget implements Changeable {
	
	public MyWidget (final String fileName, final S2SView view) {
	}

	public Changeable[] getChangeables() {
		return new Changeable[]{this};	
	}

	public void update(final S2SEvent event){
		//react to a received event
	}

	public void addS2SEventListener(final S2SEventListener l) {
		//delegate the job to a ChangeSupport object
	}

	public void fireEvent(final S2SEvent event) {
		//delegate the job to a ChangeSupport object
	}

}

Using scripts

Jython scripts can be launched from the S2SViewer's File menu or using the right mouse button menu. S2S can read Jython scripts in files ending with ".py" suffix. S2S defines two variables automatically :

Using these variables within your scripts, you can manipulate the S2SViewer and S2SView objects stored in memory. S2S provides sample jython scripts in its "scripts" sub-directory. This subdirectory is automatically added to the "sys.path" variable within the Jython scripting engine. Consequently, you can store useful methods and class in this subdirectory to use them in your scripts (take a look at the "utils.py" file in this directory).

If you want to use some of Jython's built-in functionnalities in your scripts, you need to have a complete distribution of Jython installed on your computer and you have to set the JYTHON_HOME variable. This variable stores the absolute path where you have installed your Jython's distribution.

As an example, when you have opened a file within S2S, run the script Console.py in the "scripts/jythonconsole" subdirectory (this script uses some jython's built-in functionalities, so you have to define the JYTHON_HOME variable as explained above). Then use, for example, the "seekTertiaryInteraction" method stored in the utils.py module by typing something like :

and look at the result within the S2SViewer core tool....