[MMTK] PYFAST - AN EXPERIMENTAL MD TOOLKIT

Eugene Leitl eugene.leitl@lrz.uni-muenchen.de
Tue, 15 Jun 1999 20:24:45 -0700 (PDT)


http://www.fysik.dtu.dk/~schiotz/comp/py-fast/


PyFast is an experimental MD toolkit based on fast. The individual rout=
ines
have been SWIGed and can now be called from a python script.

This toolkit is experimental. I plan to write a more modulized one late=
r....
For more information about SWIG and Python, see www.swig.org and
www.python.org. Installing them under AIX is tricky, I have written a p=
age
about how I did it.

This page will be (a little) easier to understand if you look at the FA=
ST page
first.

WARNING: This is still an experimental interface. Changes in the
functions and how you call them are possible.=20

     1. An example=20
     2. The most important functions=20
     3. How to use it=20
     4. Parallel computing=20


                      AN EXAMPLE

Here is a typical python script. It is equivalent to running fast -verb=
ose
params emt.def input.cm out.cm with the parameter file params:=20

dynamics verlet;
moves (0,5,2);
timestep 0.928;
stress summary;



import sys
import fast

c =3D fast.cvar           # Easier access to global variables

sys.stderr.write("py-fast: based on %s %s\n" % (c.Name, c.Version))

# File names
infilename, outfilename, emtfilename =3D "input.cm", "out.cm", "emt.def=
"

# Set the number of timesteps and the dynamics
major, minor =3D 5, 2
dyn =3D fast.DYNVERLET
c.timestep =3D 0.928

# Select verbose output and stress calculation
c.Verbose =3D 1
c.StressMode =3D fast.STRESSSUMMARY

# Initialize and read input file.
infile =3D fast.initfast(emtfilename, infilename, 1, dyn, 0, 0)

# Open output file, placing right info in the header segment.
outfile =3D fast.openoutput(outfilename, infile, 0, 0, major, minor*c.t=
imestep)

# Calculate the forces for the first time
fast.mkNbList(fast.cut.cutlist)   # Make the neighbor list
fast.force(c.StressMode)          # Calculate the forces

# Write the first line in the summary file
fast.summaryline(sys.stdout, 0)

# Write initial configuration
fast.writeoutput(outfile, 1, 1, 0, 0)

# Main simulation loop
for step in xrange(1,major+1):
        fast.motion(dyn, fast.BOXDYNNONE, step, minor)
        fast.summaryline(sys.stdout, step)
        fast.writeoutput(outfile, 0, 1, 0, 0)

# Close output file
fast.closeoutput(outfile)


Of course there is no need to use the python interface to do something =
this
simple.=20


       THE MOST IMPORTANT FUNCTIONS

Here is a list of the main functions that you can call, listed in the o=
rder of
appearance in the script above.=20

CmFile *initfast(char *potfilename, char *infilename, int wantclass,
int dynamics, int frame, int hmode);=20
     Initializes the simulation. Reads EMT parameters from the file
     "potfilename" and the input configuration from the CM file
     "infilename". The flag "wantclass" indicates if class information =
(L1
     column) should be read from the input file. The integer "dynamics"=

     indicates the dynamics so that the right global arrays can be allo=
cated.
     The frame to be read from the input file is indicated by "frame" (=
0 =3D
     first frame, -1 =3D last frame, N =3D frame N). "hmode" should be =
0 unless
     you know what you are doing. Return value: A pointer that should b=
e
     passed to openoutput, so it can extract the right header info (clu=
msy,
     should be changed).=20

CmFile *openoutput(char *outfilename, CmFile *infile, int
firstmoves, double firsttime, int nFrames, double frametime);=20
     Opens the output file. Parameters:=20
     outfilename=20
         File name.=20
     infile=20
         File handle returned by initfast.=20
     firstmoves=20
         No. of major moves before first frame in output file.=20
     firsttime=20
         Time passed before first frame.=20
     nFrames=20
         Number of frames after the first.=20
     frametime=20
         Time between frames.=20
     Return value: A special file handle pointer.=20

int mkNbList(double dist);=20
     Builds the neighbor lists. Call before the first force calculation=
. "dist"
     is the cutoff, recommended value is cut.cutdist.=20

void force(int calcstress);=20
     Calculate the forces. Call before the first timestep. The "calcstr=
ess"
     flag indicates if stesses should be calculated as well.=20

summaryline(File f, int n);=20
     Writes a line in the summary file "f". "f" should be an open Pytho=
n
     file. The line number "n" is written in the first field.=20

void writeoutput(CmFile *outfile, int zoutput, int momoutput, int
classoutput, int etotoutput);=20
     Writes a frame to the output file. Parameters:=20
         outfile=20
     Output file handle.=20
         zoutput=20
     Flag: include atomic numbers (only in first frame, please).=20
         momoutput=20
     Flag: include momenta.=20
         classoutput=20
     Flag: include class info.=20
         etotoutput=20
     Flag: include total energy in (nonstandard) E1 column.=20

void motion(int dyn, int boxdyn, int majorno, int steps);=20
     Performs a number of timesteps. Parameters:=20
     dyn=20
         The dynamics. Valid values:=20
         DYNVERLET=20
              Verlet dynamics.=20
         DYNMDMIN=20
              MD Minimization.=20
         DYNLANGEVIN=20
              Langevin dynamics.=20
         DYNSDMIN=20
              Steepest descent. Not recommended.=20
         DYNCGMIN=20
              Conjugate gradient minimization.=20
         DYNLANGEVINCLASS=20
              Langevin dynamics with class dependent frictions.=20
     boxdyn=20
         Box dynamics. Valid values:=20
         BOXDYNNONE=20
              Static computational box.=20
         BOXDYNMC=20
              Monte Carlo box dynamics.=20
         BOXDYNOPT=20
              Energy minimization on the box coordinates.=20
     majorno=20
         Major timestep number.=20
     steps=20
         Number of (minor) timesteps to perform.=20

Alternative ways of doing the dynamics

It is possible to call the functions doing the various kinds of dynamic=
s
directly. dt is the timestep.=20

void verlet(int nMov, double dt);=20
     Perform nMov verlet steps.

void mdmin(int nMov, double dt);=20
     Perform nMov MD-minimization timesteps.

void langevin(int nMov, double dt, double frict, double temp);=20
     Perform nMov steps of Langevin dynamics with friction coefficient
     frict and temperature temp.

void langevin_class(int nMov, double dt, double temp);=20
     Langevin dynamics, but the friction coefficient is class dependent=
 and
     specified in the global array lgvclassfrict.

void cgmin(int nMoves, double coeff);=20
     Perform nMoves conjugate gradient minimization steps.

void sdmin(int nMoves, double coeff);=20
     Perform nMoves steepest descend minimization steps.

Documentation of all functions and variables

For the remaining functions, please see the automatically generated
documentation. There are two versions:=20

     FAST. The serial version.=20
     PAST. The parallel version.=20


                     HOW TO USE IT

As this is experimental, it is only available for CAMP people and
collaborators.

To use the compiled version on the CAMP RS/6000
and SP nodes and on the Alphas

Set you Python path to point to the directory containing the modules. P=
ut
this in your .cshrc=20

# Python search path
if ( `arch` =3D=3D ibm ) then
  setenv PYTHONPATH /home/camp/schiotz/python/ibm-`arch -qtune`:$PYTHON=
PATH
else
  setenv PYTHONPATH /home/camp/schiotz/python/`arch`:$PYTHONPATH
endif

And then write a script like the one above.=20

To use the compiled version on jensen

Set you Python path to point to the directory containing the modules. P=
ut
this in your .cshrc=20

# Python search path
setenv PYTHONPATH /home/camp/schiotz/python:$PYTHONPATH

Note that python is not (yet) installed on jensen. You can find it in m=
y bin
directory: /u/schiotz/bin/python.=20

To compile and modify it yourself

  1.Get and install the CMIO library.=20
  2.Grab the py-fast.tgz archive from /home/camp/schiotz/python.=20
  3.Unpack it. Also unpack the tar file that appears in the swig
     subdirectory.=20
  4.Compile it. Requires GNU make, sometimes called gmake.=20

     make
     cd swig
     make
     make install

Some local tweaking of the makefiles is likely to be necessary.
Makefile.arch identifies the architecture and chooses compilers and fla=
gs.
swig/Makefile contains a reference to the SWIG template makefile, this
may need to be corrected.=20


               PARALLEL COMPUTING

This module also exists in a parallel version. It is called past. Essen=
tially, you
write the script in the same way, you just include the module past inst=
ead of
fast. But there are a few differences:=20

     The module is called past, not fast.=20
     You need an extra call in the beginning of the script where you
     initialize MPI. The call should look like this:=20

     past.initialize(len(sys.argv), sys.argv, 2, 2, 2)

     where the three numbers are the CPU geometry (2 * 2 * 2). The
     product must match the number of CPUs allocated by the
     LoadLeveller.=20
     You need to run a special version of python with MPI linked in. On=

     jensen, it is called /u/schiotz/bin/pythonmpi.=20

The parallel version is not yet available on the CAMP machines due to
some techical difficulties.

If you want to use the parallel version, you should also read the
documentation for the binary version of past.

If you need to create a parallel version of python for another machine,=
 the
instructions for doing it under AIX are here.=20

This page is maintained by: schiotz@fysik.dtu.dk . Last update: 05 Feb
1999 .=20
Copyright =A9 1999 Center for Atomic-scale Materials Physics . All righ=
ts
reserved.=20