The following script is used to calculate the instantaneous x-ray or neutron structure factors at each time step in a NAMD simulation of a lipid bilayer system, and apply forces to the selected atoms in order to restrain the simulation structure factors to supplied target values. The target values would typically come from x-ray or neutron diffraction experiments. The scripts use the calcForces procedure in NAMD and are therefore written in TCL.
Script: sfRestraint.tcl
Additional Files: sfRest.inp, writeSFRestInp.tcl, writeSFRestInp2.tcl
Use: Include the following lines in the NAMD inputfile:
tclForces on
tclForcesScript sfRestraint.tcl
Note that the name of the restraint input file must be specified at the top of the sfRestraint.tcl file
To write the restraint input files using either writeSFRestInp.tcl or writeSFRestInp2.tcl, edit the header of the scripts as necessary and execute them in VMD:
vmd -dispdev text -e writeSFRestInp.tcl
Notes: The script sfRestraint.tcl contains the implementation of the "calcForces" procedure, along with some initialization and helper procedures used to perform the structure factor restraints in NAMD. The atoms chosen for the restraints are defined in the sfRest.inp file, which can be generated using the script makeSFRest.tcl (the sfRest.inp file provided here is for a 72 lipid DOPC bilayer, given as an example). The script makeSFRest2.tcl is essentially the same as makeSFRest.tcl, except that makeSFRest.tcl writes a structure factor restraint input file for a single set of target structure factors (i.e. x-ray or neutron) while makeSFRest2.tcl writes an input file for two sets of target structure factors (i.e. x-ray and neutron). In this version of the restraint script, the code is written entirely in TCL. This allows the script to be used on any platform at the expense of potentially increasing the simulation run time by a significant amount.
The script provided here accomplishes the same task as above (i.e. perform structure factor restraints in NAMD), though the actual calculation of the structure factors is done via a C routine wrapped-up into a TCL procedure using SWIG. This helps to reduce the overhead in calculating the instantaneous structure factors and speeds up the simulation run time. The drawback to this approach is that shared library created by SWIG must be compiled for a specific platform and many not be portable between systems.
Script: sfRestraint2_C.tcl
Additional Files: array.tcl, sfCalc.so, xnSFRest.inp
Use: The restraint script is used in the same way as the pure TCL script above (include tclForces commands in the NAMD input file). The only difference is that you must also place array.tcl and sfCalc.so in the simulation directory.
Notes: The sfCalc.so file is a shared library, which has been compiled to run on 32-bit Intel-based machines. The shared library will not likely work on other platforms, and may even have problems on other Intel boxes. As a result, it may be necessary to recreate the .so file using SWIG. See details below.
The restraint input file listed above (xnSFRest.inp) is in the same format as the restraint input files given above for the pure TCL script. Therefore, the makeSFRest2.tcl script can be used to generate the input file for this C/SWIG based script. For generality, the script and C/SWIG function were written to read two sets of target structure factors (i.e. both x-ray and neutron data) and therefore, the makeSFRest2Inp.tcl script should be used to make the inputfile. Restraints on a single set of structure factors can be achieved by simply setting the force constants for the second set of data to zero.
As mentioned above, one must have a architecture-compatible .so file to run the C/SWIG version of the structure factor restraints. This is actually a straight forward process as most Linux machines have SWIG already installed. The files used to create the sfCalc.so file are given below.
File: sfCalc_SWIG.tar.gz
Use: After unzipping the tar.gz, you will find four files: sfCalc.c, sfCalc.i, array.i and makeit. Just execute the makeit script and cross your fingers:
./makeit
If all goes well, you will end up with the shared library, sfCalc.so.
Notes: Creating shared libraries with SWIG can be a bit tricky, as the exact procedure may need modifications between platforms. However, there is good documentation on the SWIG website. While the C function (in sfCalc.c) is straight C, the sfCalc.i and makeit files may need modification. The array.i file provides the interface between C arrays and TCL lists. In the C/SWIG version of the structure factor restraints above, the file array.tcl provides the TCL function to convert TCL lists to C arrays. See sfRestraint2_C.tcl for example usage of SWIG'ed functions and procedures.
Copyright © 2007 Ryan W. Benz