Introduction

saiga12 is a lattice simulator written in C and python, created from scratch by Richard Darst. It is used or in-development work, meaning its interface may change anytime. It won't necessarily be useful to others without code changes and other internal work.

It is written partly in C (for speed, obviously), and python (for a powerful command and control interface). The two parts are inseparable, and full use will require a knowledge of both. However, the python required is very easy. This approach may not be common (yet), but I (and others) find it extremely powerful and allows for rapid development.

Installation

Dependencies:

These are all very common packages and should be available on almost any recent linux system, as well as other non-linux systems.

darcs get http://rkd.zgib.net/http/research/saiga12/
# OR get the source tarball (may not be up to date)
wget http://rkd.zgib.net/http/research/saiga12/saiga12.tar.gz
tar xzvf saiga12.tar.gz

# you must build the C module.  go to the directory and run build.sh
cd saiga12
sh build.sh    # just run a few gcc commands

be sure that the directory containing the saiga12 directory is in your PYTHONPATH. For example, if saiga12 is in /home/richard/pymod/saiga12/, then /home/richard/pymod should be in PYTHONPATH. This should work in bash-like shells:

PYTHONPATH=$PYTHONPATH:/path/to/the/dir/
export PYTHONPATH

Visualization

You can use the magic of python -m to run a script without having to install it separately. This works from any directory, you don't have to be in the saiga12 diretory

python -m saiga12/viz path/to/ughfile.ugh

This is so cool, you can even give it straight URLS without having to download them separately:

python -m saiga12/viz http://rkd.zgib.net/http/research/crystals/gceeq_mu1=7.0.ugh

Inspecting Objects

You can use the saiga12/io script to interactively inspect objects:

$ python -m saiga12/io http://rkd.zgib.net/http/research/crystals/gceeq_mu1=7.0.ugh

>>> S
<saiga12.geom.grid.Grid3d object at 0xb705364c>
>>> S.energy()
0.0
>>> S.hardness
inf
>>> S.N
1977
>>> S.density
0.58577777777777773

Example

Here is a script that take many config options, and does several simulations (equilibration to get initial parameters, more euilibration, then running while varying the chemical potentials to slowly increase density) to produce the final result.

   1 #!/usr/bin/env python2.4
   2 #$ -cwd
   3 #$ -V
   4 #$ -N crstl-1
   5 #$ -M rkd@zgib.net
   6 #$ -S /opt/rocks/bin/python2.4
   7 #$ -m be
   8 
   9 # Richard Darst, 2008
  10 
  11 import cPickle as pickle
  12 import sys
  13 
  14 import saiga12
  15 import saiga12.statefinder
  16 from saiga12.geom.grid import Grid3d
  17 
  18 # define  things used later
  19 fracA = .5
  20 
  21 speed = .1
  22 printstdout = True
  23 initialdensity = .05
  24 
  25 
  26 
  27 # start the real code
  28 a = b = c = 15
  29 S = Grid3d()
  30 S.makegrid(a, b, c)
  31 
  32 S.hardness = 1.
  33 S.addParticleRandomDensity(initialdensity * fracA , 1)  # A
  34 S.addParticleRandomDensity(initialdensity * 1.    , 3)  # B
  35 S.anneal()
  36 S.setInsertType( {1: (fracA  , 1.00),
  37                   3: (1-fracA, 0.82)} )
  38 
  39 
  40 # Do a loop to find the starting chemical potential
  41 while S.mctime < 1000:
  42     S.cycle(10)
  43     mu1 = S.chempotential(1, store=False)
  44     mu3 = S.chempotential(3, store=False)
  45     S.avgStore("mu1", mu1)
  46     S.avgStore("mu3", mu3)
  47 print S.avg("mu1")
  48 print S.avg("mu3")
  49 #import sys ; sys.exit()
  50 
  51 # the StateFinder is my thing that slowly increases both 
  52 # chemical potentials to increase the density.
  53 SF = saiga12.statefinder.StateFinder()
  54 SF.S = S
  55 SF.mu3 = round(S.avg("mu3"), 1)
  56 SF.mu1 = round(S.avg("mu1"), 1)
  57 SF.fracA = fracA
  58 SF.controlScale = .5
  59 SF.logfile = file("logfile-sft-speed=%s.txt"%speed, "w")
  60 
  61 
  62 # Equilibration
  63 SF.begin(1000, 100)
  64 SF.status(log=False)
  65 SF.S.resetTime()
  66 
  67 # Main loop.  It should be somewhat obvious what it's doing here...
  68 # (I don't quite like this way of doing things, and I improved it later)
  69 # (It's just an example of the general way things work.)
  70 # This can't make complete sense unless you know what some of these functions 
  71 # do, but you get the general idea.
  72 while SF.mu1 <= 15.:
  73     print
  74     for i in range(1000):
  75         if i % 500 == 0:
  76             S.avgReset()
  77             SF.setGCE()   # need to keep MCSP constant...
  78             
  79         SF.adjustMu()
  80         SF.S.cycle(100)
  81         log = not S.mctime % 1000
  82         SF.status(log=log, printstdout=printstdout)
  83 
  84     if round(SF.mu1, 5) % .5 == 0.:
  85         S.otherData = {"gce_mu1": SF.mu1,
  86                        "gce_mu3": SF.mu3,
  87                        }
  88         fname = "outputs/gceeq_fracA=%s_mu1=%s_speed%s.ugh"% \
  89                 (fracA, round(SF.mu1, 5), speed)
  90         pickle.dump(S, file(fname, "wb"), -1)
  91     SF.mu1 += speed

saiga12 (last edited 2008-04-30 18:01:26 by RichardDarst)