[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: variable command interpretter

From: Westley A Sherman
Subject: Re: variable command interpretter
Date: Mon, 18 Jun 2001 15:34:11 -0400 (EDT)

On Mon, 18 Jun 2001 address@hidden wrote:

> A team is about to start designing/writing a molecular graphics
> program.
> ...
> I of course would be interested in using guile.

Mostly for my own education, I wrote a small molecular graphics program
that used guile as the extension language. I've included a few
observations below.

For simple command line use one wants to be able to execute a series of
simple statements that change the global state of the molecular graphics
program. A language like Scheme which tries to do everything in terms of
nested function calls and argument passing may not be the best choice.

Most serious molecular graphics programs allow one to construct and save
complex views of a given molecule and I found that Scheme could be useful
for this. Along the same lines, small routines written in Scheme work work
well for generating animations.

The ability in Scheme to pass functions around as arguments makes it
possible to do something like the following:

(apply-to-all-atoms (lambda(atom)
                     (if (= (atom-number atom) 5)
                         (set-atom-color atom 'PURPLE))))

Also, most molecular graphics programs have all kinds of data files for
things like atomic connectivity (bonds). Since large molecules like
proteins have a hierarchical organization I've thought about using a
Scheme-like nested list syntax for the data files but I've never thought
up a way of doing this that was good enough to be worth implementing.

One conclusion that I've come to is that it is currently impossible to
write a molecular graphics program that can correctly parse all PDB format
molecular structure files. If the Protein Data Bank were ever to release a
reference implementation of routines that were guaranteed to correctly
parse PDB format files it might be worth making one's molecular graphics
program compatible with whatever language the reference implementation was
written in (most likely C++ or Java).

I've included a sample script that I used with my molecular graphics
program below. If nothing else, it demonstrates that things can get
quickly become quite complicated.

Westley Sherman

;; This script sets up a particular representation of a protein and
;; then does an animation of the protein rotating and wobbling.

(debug-enable 'backtrace)


  (define (extrapolate old-value old-low old-high new-low new-high)
    (+ (* (/ (- old-value old-low) (- old-high old-low))
          (- new-high new-low))

  (define (ca-trace atom)
    ((lambda(atom-chain atom-res atom-res-num atom-name)
       (if (or (equal? atom-res "ZN ")
               (equal? atom-res "MG ")
               (equal? atom-res "PO4"))
           (pmk-set-structure-mode atom 'MOLS-SPHERE)
           (if (or (equal? atom-name " N  ")
                   (equal? atom-name " CA ")
                   (equal? atom-name " C  "))
               (if (equal? atom-chain "A")
                    atom 74.0
                    (extrapolate atom-res-num 1 499 0.2 2.6)
                    atom 74.0
                    (extrapolate atom-res-num 1 499 2.8 5.5)
               (if (and
                    (equal? atom-res "TRP")
                    (not (or (equal? atom-name " H  ")
                             (equal? atom-name " O  "))))
                     (pmk-set-structure-mode atom 'MOLS-PRISMS)
                     (pmk-set-structure-param atom 1))
                   (pmk-set-structure-mode atom 'MOLS-NONE)))))
     (pmk-atom-chain atom)
     (pmk-atom-residue atom)
     (pmk-atom-residue-number atom )
     (pmk-atom-name atom)))

  (define (rotation-loop n-frames frames-completed
                         n-rotations axis-x axis-y axis-z)
    (if (>= frames-completed n-frames)
        (begin (pmk-set-rotation-matrix
                (/ frames-completed (/ n-frames n-rotations))
                axis-x axis-y axis-z)
               (pmk-render global-frame-number)
               (if (>= global-frame-number 0)
                   (set! global-frame-number (+ global-frame-number 1)))
               (rotation-loop n-frames
                              (+ frames-completed 1)
                              axis-x axis-y axis-z))))

  (define (set-wobble wobble-direction wobble-amount)
        (cos wobble-angle)
        (- (sin wobble-angle))
     (* 4.0 (acos 0.0) wobble-direction)))

  (define (wobble-loop n-frames frames-completed wobble-amount)
    (if (>= frames-completed n-frames)
        (begin (set-wobble
                (/ frames-completed n-frames)
               (pmk-render global-frame-number)
               (if (>= global-frame-number 0)
                   (set! global-frame-number
                         (+ global-frame-number 1)))
               (wobble-loop n-frames
                            (+ frames-completed 1)


  (pmk-apply-to-atoms ca-trace)
  (pmk-render -1))

  (pmk-set-all-atoms-flag 'ATOM-FLAG-ROTATE)
  (pmk-rotate-about-origin  0.34  0.0 0.0 1.0)
  (pmk-rotate-about-origin  0.23  1.0 0.0 0.0)
  (pmk-rotate-about-origin -0.06  0.0 0.0 1.0)
  (pmk-rotate-about-origin  0.012 1.0 0.0 0.0)
  (pmk-rotate-about-origin  0.005 0.0 1.0 0.0)
  (pmk-rotate-about-origin  0.004 0.0 0.0 1.0)
  (pmk-render -1))

(define global-frame-number -1)

(rotation-loop 100 0 1.0 0.0 1.0 0.0)

(wobble-loop 100 0 0.05)

reply via email to

[Prev in Thread] Current Thread [Next in Thread]