Scripting

NanoBricks provides several tools for automating repetitive tasks:

  • The Add/Remove Voxels tool allows you to programmatically create voxel shapes.
  • The PowerEdit tool allows you to select and transform voxels or strands according to programmatic criteria

In each case, you enter some CoffeeScript code into a textbox; that code will be decorated by NanoBricks with some extra variable definitions, then compiled and executed. Your code should return a function, which will be executed once for each

Add/Remove Voxels

Allows you to add or remove voxels according to a function; the function is passed X, Y, and Z positions on the lattice and must return true or false. There are 3 modes:

  • Add: Voxels are added at any positions where the function returns true
  • Remove: Voxels are removed at any positions where the function returns true
  • Set: Voxels are added where the function returns true and removed where the function returns false

Examples:

  • 5x7x5 cuboid, centered at 10, 10, 10:

      cuboid(5, 5, 5,  10, 10, 10) 
      # you could pass true as the last argument to make a hollow cuboid
    
  • Stripes in the Z direction with periodicity 4 and height 7:

      (x, y, z) ->
          y < 7 and (x % 4) is 0
    

PowerEdit

PowerEdit (or Select/Transform) lets you choose voxels (or strands) according to an arbitrary function, then modify those objects according to another function.

  • For voxels, the functions are passed the X, Y and Z position of the voxel, as well as a reference to the voxel itself.
  • For strands, the functions as passed a reference to the strand.

Examples:

  • Color all voxels on one side of the canvas purple:

    Select:

      (x,y,z,voxel) -> x > lattice.width / 2
    

    Transform:

      (x,y,z,voxel) -> voxel.set 'color', 'purple'
    
  • Displace all voxels by +5 voxels in the X directions

    Select:

      (x,y,z,voxel) -> yes
    

    Transform:

      (x,y,z,voxel) -> voxel.move +5, 0, 0
    
  • Extend the 3' end of all Y strands with a specific sequence (e.g. for a PAINT docking site):

    Select:

      (strand) -> strand.get('plane') is 'Y'
    

    Transform:

      (strand) -> 
          strand.extend 'ATTACAGACT'
          # note that 
          #     strand.extend 'ATTACAGACT', -1 
          # would extend the 3' end 
    
  • Add a 10 nt loop at position 5 on a specific strand

    Select:

      (strand) -> 
          eq strand.get5p(), [5, 10, 4, 3]
    
          # `eq` is a NanoBricks built-in function which lets you compare arrays element-wise
          # get5p() returns a 4-element array giving the 
          # [X helix position, Y helix position, Z (voxel) position, base #]
          # for a particular strand.
    

    Transform:

      (strand) -> strand.insert 10, 5
    

Built-in variables and functions within scripting

For convenience, NanoBricks introduces a number of functions into the local namespace within scripting environments. Add functions from the following classes are available as local variables (e.g. instead of vox.shapes.cuboid, you can just write cuboid):

NanoBricks also defines some variables for you:

  • lattice: Reference to the current Lattice; you can use this to get the shape of the current lattice
  • strands: Reference to the current Strand controller; you can use this to add, remove, and modify strands
  • voxels: Reference ot the current Voxel controller; you can use this to add, remove, and modify voxels

In addition, you may have access to one or more of these:

  • strand: Reference to the current strand; you can access properties of the strand set by the translation scheme (plane, align, etc.), determine the 5' (get5p()) or 3' (get3p) end of the strand, make modifications (extend, insert, truncate, delete), and change properties of the strand (e.g. color).
  • voxel: Reference to the current voxel; you can get the voxel's position (position), move the voxel (move, moveTo), and change the voxel's color.