         trigger (make-sweep-vector current-z search-params)
         current-exposure (core getExposure)]
     (let [images (acquire-images z-drive trigger (:exposure search-params))
-          scores (map #(score-image "Sum" %) images)
+          scores (map #(score-image (:score-type search-params) %) (seque images))
           best-index (apply max-key #(nth scores %) (range (count images)))
           best-z (nth trigger best-index)]
+      (core stopSequenceAcquisition)
+      (core stopStageSequence z-drive)
       (core setPosition z-drive best-z)
       (core setExposure current-exposure)
       best-z)))
            
 (defn run-test []
   (reset! search-params
-          {:range 10
-           :tolerance 1.00
-           :score-type "Sum"
-           :exposure 10})
-  (run-autofocus @search-params))+          {:range 5
+           :tolerance 0.25
+           :score-type "Sharpness"
+           :exposure 2})
+  (run-autofocus @search-params)
+  (. gui snapSingleImage))
(ns zippy-focus.core
  (:import [org.micromanager.utils PropertyItem]
           [org.micromanager.api Autofocus])
  (:use [org.micromanager.mm
            :only (load-mm gui mmc core double-vector)])
  (:gen-class

    (core setPosition z-drive (first trigger))
    (core loadStageSequence z-drive (double-vector trigger))
    (core startStageSequence z-drive)
    (core startSequenceAcquisition (count trigger) 0 false)
    (grab-images (count trigger)))

(defn run-autofocus [search-params]
  (let [z-drive (core getFocusDevice)
