A simple Example

Adding a unit cell
I think one of the harder things to do in Molscript is to draw a unit cell for a crystal where at least one angle is not 90. Sometimes that is exactly what you want to do. Here is a script that will generate text to paste into your molscript input file to draw the cell. The cell even rotates as you transform the structure or use OpenGL mode. The center statement it produces is at the center of the cell.

I call this script molcell.sh.
Use: molcell.sh [pdb file]

     #!/bin/sh
     if [ $1 ]; then input=$1
      else echo "Please pick a structure file to use as a model.  These are available:"
      echo ; ls *.pdb ; echo ; echo -n "Which one?  " ;read input
     fi
     root=`echo $input |awk -F . '{print ($1)}'`
     
     if [ `grep -c "^CRYST" $root.pdb` != 1 ] ; then 
        echo Your PDB file must have a CRYST card.
        exit
     else
     
     cat << endcat > tEmP.frac
         1   1.00000   1.00000   0.00000
         2   1.00000   0.00000   0.00000
         3   0.00000   0.00000   0.00000
         4   0.00000   1.00000   0.00000
         5   1.00000   1.00000   0.00000
         6   1.00000   1.00000   1.00000
         7   1.00000   0.00000   1.00000
         8   0.00000   0.00000   1.00000
         9   0.00000   1.00000   1.00000
        10   1.00000   1.00000   1.00000
        11   1.00000   0.00000   0.00000
        12   1.00000   0.00000   1.00000
        13   0.00000   0.00000   0.00000
        14   0.00000   0.00000   1.00000
        15   0.00000   1.00000   0.00000
        16   0.00000   1.00000   1.00000
     endcat
     
     cell=`grep "^CRYST" $root.pdb| sed -e s/CRYST1/CELL/`
     coordconv XYZIN tEmP.frac XYZOUT tEmP.pdb > /dev/null << zzz
     INPUT FRAC
     OUTPUT PDB ORTH 1
     $cell
     zzz
     
     echo "transform atom *"
     grep "^ATOM"  tEmP.pdb | awk ' NR==6 {print ("   by centre "$4/2, $5/2, $6/2,";")}'
     
     echo
     echo "set objecttransform on;"
     echo "set linecolour blue, linewidth 5;"
     echo "object inline;"
     
     grep "^ATOM"  tEmP.pdb | awk 'NR==1 {print ( "L 10" )}
     NR==11 {print ( "L 2" )}
     NR==13 {print ( "L 2" )}
     NR==15 {print ( "L 2" )}
     {print ( $4, $5, $6 )}'
     echo Q
     rm -f tEmP.pdb tEmP.frac
     fi
     

The Output

     [dcoop Molscript]-> molcell.sh merlin.pdb
     transform atom *
        by centre 43.509 44.664 48.382 ;
     
     set objecttransform on;
     set linecolour blue, linewidth 5;
     object inline;
     L 10
     87.018 89.328 0.000
     87.018 0.000 0.000
     0.000 0.000 0.000
     0.000 89.328 0.000
     87.018 89.328 0.000
     87.018 89.328 96.764
     87.018 0.000 96.764
     0.000 0.000 96.764
     0.000 89.328 96.764
     87.018 89.328 96.764
     L 2
     87.018 0.000 0.000
     87.018 0.000 96.764
     L 2
     0.000 0.000 0.000
     0.000 0.000 96.764
     L 2
     0.000 89.328 0.000
     0.000 89.328 96.764
     Q
     

The final input file

     plot
     background white;
     window 168.43;
     slab 151.19;
     
       read mol "mona.pdb";
     transform atom *
        by centre 43.509 44.664 48.82 
     by rotation
       0.349419 0.171679 -0.921104
       -0.718502 0.68007 -0.145808
       0.601383 0.712763 0.360981;
     
     set objecttransform on;
     set linecolour blue, linewidth 5;
     object inline;
     L 10
     87.018 89.328 0.000
     87.018 0.000 0.000
     0.000 0.000 0.000
     0.000 89.328 0.000
     87.018 89.328 0.000
     87.018 89.328 96.764
     87.018 0.000 96.764
     0.000 0.000 96.764
     0.000 89.328 96.764
     87.018 89.328 96.764
     L 2
     87.018 0.000 0.000
     87.018 0.000 96.764
     L 2
     0.000 0.000 0.000
     0.000 0.000 96.764
     L 2
     0.000 89.328 0.000
     0.000 89.328 96.764
     Q
     
     set segments 12;
       set planecolour hsb 0.6667 1 1, plane2colour hsb 0.6667 .7 .7;
       coil from A20 to A21;
     [snip]
       coil from A312 to A313;
     
     end_plot