Endonuclease PvuII (1PVI) DNA - GATTACAGATTACA
CAP - Catabolite gene Activating Protein (1BER)
DNA - GATTACAGATTACAGATTACA Endonuclease PvuII bound to palindromic DNA recognition site CAGCTG (1PVI) DNA - GATTACAGATTACAGATTACA TBP - TATA box Binding Protein (1C9B)
CAP - Catabolite gene Activating Protein (1BER)
GCN4 - leucine zipper transcription factor bound to palindromic DNA recognition site ATGAC(G)TCAT (1YSA)
GCN4 - leucine zipper transcription factor bound to palindromic DNA recognition site ATGAC(G)TCAT (1YSA)
GCN4 - leucine zipper transcription factor bound to palindromic DNA recognition site ATGAC(G)TCAT (1YSA)
GCN4 - leucine zipper transcription factor bound to palindromic DNA recognition site ATGAC(G)TCAT (1YSA)
GCN4 - leucine zipper transcription factor bound to palindromic DNA recognition site ATGAC(G)TCAT (1YSA)
TBP - TATA box Binding Protein (1C9B)
 

° 

Scripts

-

Use YASARA as a Python module

° 

Windows users can obtain Python from www.python.org

If you are a Linux or MacOSX user, the versatile scripting language Python is already present. If you are running Windows, it depends on your installation. Try to click Help > Install program > Python. If this option is not available, Python is already installed.

If you are new to Python, you can find a tutorial here.

° 

Copy and import yasara/pym/yasara.py

THE YASARA PYTHON MODULE IS IN BETA-TESTING PHASE, PLEASE REPORT PROBLEMS EARLIER THAN LATER

There are currently three ways of running YASARA automatically:
  • Yanaconda macros, the easiest solution.
  • Python plugins, that are activated by clicking on a menu entry and then perform certain tasks.
  • The YASARA Python module, which you can simply import into your Python scripts, as described here.

To use YASARA from your Python scripts, perform the following installation steps:
  • Make sure that YASARA has been run at least once.
  • Copy the YASARA module loader yasara/pym/yasara.py (Linux), yasara\pym\yasara.py (Windows) or YASARA.app/yasara/pym/yasara.py (MacOSX) to the directory where you keep your Python scripts. If you have administrator privileges, you can also copy it directly to the place where Python collects its modules (e.g. /usr/lib/pythonX.Y in Linux)
  • Import the YASARA module in your script as shown in the example below, which loads the PDB file 1crn:


from yasara import *

LoadPDB("1crn")

You can also resort to the following alternative, which requires more typing and is therefore not used here (if you choose this option, you have to prepend 'yasara.' to all variable names and function calls shown throughout the rest of this chapter).


import yasara

yasara.LoadPDB("1crn")

° 

There is a Python function wrapper for most YASARA commands

The syntax of YASARA commands is optimized for a minimum number of key-strokes, which conflicts with Python's own syntax. The YASARA Python module therefore contains Python function wrappers for most YASARA commands.

Example: The YASARA command to choose a new font..

Font Arial,Height=2,Spacing=1.5,Color=Yellow,Depth=5,DepthCol=Red

..has the following equivalent in the Python module:

Font("Arial",height=2,spacing=1.5,color="Yellow",depth=5,depthcol="Red")

The documentation page of each YASARA command lists the prototype of the corresponding Python function, e.g. the Font command (look at the 'Python:' row in the table at the top of each page).

° 

Python functions return either nothing, a single value or a list

In the Yanaconda macro language you can choose between a single return value and a list by appending parentheses to the variable name . This is obviously not possible in Python. Instead those functions that are guaranteed to never return more than one value simply return this value, while functions possibly returning more than one value always return a list.

Examples:


# This function never returns a result:
Clear()

# This function always returns a single result, the number of the object loaded:
obj = LoadYOb("crambin")

# This function may return many results (if the PDB file contains an NMR bundle with many MODELs)
objlist = LoadPDB("3gb1")
# Or if you know that the PDB file contains only a single MODEL/object (note the slice [0]):
obj = LoadPDB("1crn")[0]

To find out what exactly a function returns, simply check the prototype on the documentation page, e.g. LoadPDB and LoadYOb

° 

YASARA specific data is available in 'info'

Assuming you used 'from yasara import *', the following variables are defined:

info.mode
YASARA mode, 'gra' for graphics and 'txt' for text
info.opsys
The current operating system, "Linux", "MacOS" or "Windows"
info.version
The YASARA version string X.Y.Z
info.serialnumber
YASARA's serial number
info.stage
The YASARA stage View, Model, Dynamics or Structure
info.owner.firstname
Your first name
info.owner.lastname
Your last name
info.owner.email
Your e-mail address
info.atoms
The number of atoms in YASARA's soup
info.objects
The number of active objects in YASARA's soup
info.firstobj
The number of the first active object
info.lastobj
The number of the last active object
info.leftbutton
1 if the left mouse button is pressed in YASARA's window
info.middlebutton
1 if the middle mouse button is pressed in YASARA's window
info.rightbutton
1 if the right mouse button is pressed in YASARA's window
info.energyunit
YASARA's current energy unit
info.speedmax
The speed of the fastest atom during a simulation in m/s

° 

YASARA commands with multiple formats map to different Python functions

Since Yanaconda is a reinterpreted language , YASARA commands can accept arguments in a rather flexible way. In Python on the other hand, the number and order of function arguments must not change. If a YASARA command supports more than one format, it thus has to be wrapped by different Python functions. The names of these Python functions differ at the end, using either an increasing number or the name of the first argument.

Example for an increasing number:


# In Yanaconda:
# Format 1: Show an arrow between atoms 123 and 456
ShowArrow Start=AtAtom,123,End=AtAtom,456,Radius=0.5,Color=Red
# Format 2: Show an arrow between points 1/2/3 and 4/5/6
ShowArrow Start=Point,X=1,Y=2,Z=3,End=Point,X=4,Y=5,Y=6,Radius=0.5,Color=Red

# In Python:
ShowArrow(start="AtAtom",selection1=123,end="AtAtom",selection2=456,radius=0.5,color="Red")
ShowArrow2(start="Point",x=1,y=2,z=3,end="Point",x2=4,y2=5,z2=6,radius=0.5,color="Red")

Note above that argument names in Python are case-sensitive and expected to be all lowercase. They may also not be repeated, that's why the coordinates of the second point are x2/y2/z2.

Example for using the name of the first argument:


# In Yanaconda:
# Format 1: Define a 20x30x40 A cell with angles 80/90/70 degrees:
Cell X=20,Y=30,Z=40,Alpha=80,Beta=90,Gamma=70
# Format 2: Define cell automatically to enclose everything with a 10 A extension:
Cell Auto,Extension=10
# Format 3: Define cell like the crystallographic cell of object 1crn:
Cell Crystal,1crn

# In Python:
Cell(x=20,y=30,z=40,alpha=80,beta=90,gamma=70)
CellAuto(extension=10)
CellCrystal("1crn")

Again, to find out details about the function variants available in Python, check out the Python prototypes on the documentation page, e.g. ShowArrow and Cell.

° 

A subset of the YASARA soup can be obtained as a pdb_file instance

YASARA comes with a Python PDB file interface that can be found at yasara/plg/pdb_file.py. In addition, you can easily obtain any part of the YASARA soup as an instance of such a PDB file interface. This means that you can use the same piece of Python code to analyze a PDB file loaded from disk and the YASARA soup.

The following examples list all Calpha atoms in the PDB file 1crn.pdb:

  • Using the Python PDB file interface without YASARA:


import pdb_file

pdb=pdb_file.interface("1crn.pdb")
for i in range(pdb.atoms):
  if (pdb.atom[i].name=="CA"): print pdb.atom[i]

  • Using the YASARA Python module:


from yasara import *

LoadPDB("1crn")
pdb=Atom("CA")
print pdb

The instance 'pdb' stores the data in the following way:

Instance.crdsys
1 if the atom coordinates use a left-handed system (YASARA's default), and -1 otherwise (PDB file default).
Instance.atoms
the number of atoms
Instance.atom[i]
the ith atom
Instance.atom[i].element
the chemical element number of the ith atom
Instance.atom[i].name
the name of the ith atom with spaces stripped
Instance.atom[i].name4
the name of the ith atom as present in the PDB file, with all spaces
Instance.atom[i].num
the YASARA number of the ith atom (only present in the YASARA Python module)
Instance.atom[i].altloc
the alternate location indicator of the ith atom, None if empty
Instance.atom[i].pos.x/.y/.z
the position of the ith atom
Instance.atom[i].pos.c[j]
the jth 'c'omponent of the position vector of atom i
Instance.atom[i].occupancy
the occupancy of the ith atom
Instance.atom[i].bfactor
the B-factor of the ith atom
Instance.atom[i].resname
the name of the residue the ith atom belongs to
Instance.atom[i].resnum
the number of the residue the ith atom belongs to
Instance.atom[i].molname
the name of the molecule the ith atom belongs to
Instance.atom[i].segname
the name of the segment the ith atom belongs to
Instance.residues
the number of residues
Instance.residue[i]
the ith residue
Instance.residue[i].name
the name of the ith residue
Instance.residue[i].num
the number of the ith residue
Instance.residue[i].atoms
the number of atoms in the ith residue
Instance.residue[i].atom[j]
the jth atom in the ith residue with properties described above
Instance.residue[i].atomnamed["X"]
atom with name "X" in the ith residue with properties described above
Instance.molecules
the number of molecules (=chains)
Instance.molecule[i]
the ith molecule (=chain)
Instance.molecule[i].atoms
the number of atoms in the ith molecule
Instance.molecule[i].atom[j]
the jth atom in the ith molecule with properties described above
Instance.molecule[i].residues
the number of residues in the ith molecule
Instance.molecule[i].residue[j]
the jth residue in the ith molecule with properties described above
Instance.objects
the number of objects (=NMR MODELs)
Instance.object[i]
the ith object
Instance.object[i].name
the YASARA name of the ith object (only present in the YASARA Python module)
Instance.object[i].num
the YASARA number of the ith object (only present in the YASARA Python module)
Instance.object[i].atoms
the number of atoms in the ith object
Instance.object[i].atom[j]
the jth atom in the ith object with properties described above
Instance.object[i].residues
the number of residues in the ith object
Instance.object[i].residue[j]
the jth residue in the ith object with properties described above
Instance.object[i].molecules
the number of molecules in the ith object
Instance.object[i].molecule[j]
the jth molecule in the ith object with properties described above
Instance.object[i].molnamed["X"]
the molecule named "X" in the ith object with properties described above

The following data are currently only available if you use pdb_file.interface to create the instance:
Instance.cell
information about the unit cell
Instance.cell.x/.y/.z
the cell dimensions
Instance.cell.alpha/.beta/.gamma
the cell angles
Instance.cell/.spacegroup/.z
the remaining cell parameters
Instance.resolution
the X-ray resolution

The YASARA Python module provides five commands to extract selected portions of the YASARA soup as a PDB file instance: Atom, Residue , Molecule, Object and All. The first four take a selection as the only argument:


from yasara import *

# Load PDB file 5tim
LoadPDB("5tim")

# Get all atoms in molecule A that contact molecule B
contact=Atom("Mol A with distance<5 from Mol B")
print "There are %d contacts:"%contact.atoms
print contact

# Get all Arg residues that form a salt-bridge with Asp or Glu
bridge=Residue("Arg Atom NH? with distance<3.5 from Asp Glu Atom OD? OE?")
print "There are %d salt-bridged arginines"%bridge.residues
for i in range(bridge.residues):
  print bridge.residue[i].name,bridge.residue[i].num

# Get the protein molecules
protein=Molecule("Protein")
print "There are %d protein molecules containing %d atoms"%(protein.molecules,protein.atoms)

# Clear the YASARA soup and load an NMR structure bundle
Clear()
LoadPDB("3gb1")

# Get the first model (each model is stored in a separate object)
first=Object(1)
print "The first model contains %d atoms, %d residues and %d molecules"%(first.atoms,first.residues,first.molecules)

# Get the entire soup
soup=All()
print "The bundle contains %d models"%soup.objects

° 

The console needs to be switched off for maximum performance

By default, the Python module runs YASARA in interactive graphical mode. This means that the YASARA window is permanently updated (at least after each YASARA Python function you call), and that you can even work with YASARA interactively while your Python script is doing something else.

If your Python script needs to call thousands of YASARA functions in a loop, this approach soon becomes too slow. The solution is the same as used by Yanaconda macros and Python plugins , switching off the console:


Console("Off")

Your Python script is then responsible for updating the screen by calling the Wait() function.

° 

There is a specific Python function for each experiment

In YASARA Dynamics and YASARA Structure, several experiments are available that perform complex tasks at the touch of a button. In Yanaconda, experiments expect their parameters in a separate, indented section:


# Prepare neutralization experiment
Experiment Neutralization
  # Fill the cell with water at a density of 1.0 g/cm^3
  WaterDensity 1.0
  # And NaCl counter ions with 0.9%
  NaCl 0.9
  # Protonate ionizable groups according to pH 7.0
  pH 7.0
  # Save pKa predictions as dat/1crn_mutant.pka
  pKaFile 1crn_mutant
  # Finish quickly (final water density will be OK, but not exact)
  Speed Fast
# Start experiment
Experiment On
# Wait till end of experiment
Wait ExpEnd

In Python, each experiment is wrapped by its own function instead:


ExperimentNeutralization(waterdensity=1.0,nacl=0.9,ph=7.0,pkafile="1crn_mutant",speed="fast")
Experiment("On")
Wait("ExpEnd")

° 

The Python module can run YASARA in graphics or text mode

Normally the Python module runs YASARA in graphics mode, so that you can follow its work visually on screen. To choose text-only output instead, set info.mode to 'txt' before you call the first YASARA Python function:


from yasara import *

# Choose text mode before the first function call
info.mode='txt'
# First function call, load a PDB file
LoadPDB("1crn")
# List all arginine residues
ListRes("Arg")