• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

tools/python/vgrid/average.py

00001 from vgrid import *
00002 import sys
00003 import math
00004 from sys import stdout, stderr
00005 
00006 """
00007     average.py - An example script for interfacing Python with APBS
00008               Vgrid routines
00009 """
00010 
00011 header = "\n\n\
00012     ----------------------------------------------------------------------\n\
00013     Adaptive Poisson-Boltzmann Solver (APBS)\n\
00014     Version 1.3 (November 2009)\n\
00015     \n\
00016     Nathan A. Baker (baker@biochem.wustl.edu)\n\
00017     Dept. of Biochemistry and Molecular Biophysics\n\
00018     Center for Computational Biology\n\
00019     Washington University in St. Louis\n\
00020     Additional contributing authors listed in the code documentation.\n\n\
00021     Copyright (c) 2002-2010. Washington University in St. Louis\n\
00022     All Rights Reserved.\n\n\
00023     Portions copyright (c) 1999-2002.  University of California.\n\
00024     Portions copyright (c) 1995.  Michael Holst.\n\n\
00025     Permission to use, copy, modify, and distribute this software and its\n\
00026     documentation for educational, research, and not-for-profit purposes,\n\
00027     without fee and without a signed licensing agreement, is hereby granted,\n\
00028     provided that the above copyright notice, this paragraph and the\n\
00029     following two paragraphs appear in all copies, modifications, and\n\
00030     distributions.\n\n\
00031     IN NO EVENT SHALL THE AUTHORS BE LIABLE TO ANY PARTY FOR DIRECT,\n\
00032     INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST\n\
00033     PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION,\n\
00034     EVEN IF THE AUTHORS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH\n\
00035     DAMAGE.\n\n\
00036     THE AUTHORS SPECIFICALLY DISCLAIM ANY WARRANTIES, INCLUDING, BUT NOT\n\
00037     LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A\n\
00038     PARTICULAR PURPOSE.  THE SOFTWARE AND ACCOMPANYING DOCUMENTATION, IF\n\
00039     ANY, PROVIDED HEREUNDER IS PROVIDED \"AS IS\".  THE AUTHORS HAVE NO\n\
00040     OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR\n\
00041     MODIFICATIONS.\n\
00042     ----------------------------------------------------------------------\n\
00043     \n\n"
00044     
00045 
00046 usage = "python[2] average.py file.dx\n";
00047 
00048 def main():
00049 
00050     # *************** CHECK INVOCATION *******************
00051     
00052     startVio()
00053 
00054     if len(sys.argv) != 2:
00055         stderr.write("\n*** Syntax error: got %d arguments, expected 2.\n\n" % len(sys.argv))
00056         stderr.write("%s\n" % usage)
00057         sys.exit(2)
00058 
00059     else:
00060         inpath = sys.argv[1]
00061 
00062     # *************** APBS INITIALIZATION ******************* 
00063 
00064     stdout.write(header)
00065     data = []
00066 
00067     stdout.write("main:  Reading data from %s... \n" % inpath)
00068     grid = Vgrid_ctor(0, 0, 0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, data)
00069     Vgrid_readDX(grid, "FILE", "ASC", "", inpath)
00070 
00071     nx = grid.nx
00072     ny = grid.ny
00073     nz = grid.nz
00074     hx = grid.hx
00075     hy = grid.hy
00076     hzed = grid.hzed
00077     xmin = grid.xmin
00078     ymin = grid.ymin
00079     zmin = grid.zmin
00080 
00081     stdout.write("#     nx = %d, ny = %d, nz = %d\n" % (nx, ny, nz))
00082     stdout.write("#     hx = %g, hy = %g, hz = %g\n" % (hx, hy, hzed))
00083     stdout.write("#     xmin = %g, ymin = %g, zmin = %g\n" % (xmin, ymin, zmin))
00084     # *************** SETTINGS ********************
00085 
00086     xcentAVG = 112.160
00087     ycentAVG = 63.5
00088     zcentAVG = 137.245
00089     xlenAVG = 70.0
00090     zlenAVG = 70.0
00091     ylenAVG = hy*(ny-1)
00092 
00093     # *************** AVERAGE **********************
00094 
00095     xminAVG = xcentAVG - 0.5*xlenAVG
00096     xmaxAVG = xcentAVG + 0.5*xlenAVG
00097     yminAVG = ycentAVG - 0.5*ylenAVG
00098     ymaxAVG = ycentAVG + 0.5*ylenAVG
00099     zminAVG = zcentAVG - 0.5*zlenAVG
00100     zmaxAVG = zcentAVG + 0.5*zlenAVG
00101     imin = int(math.floor((xminAVG - xmin)/hx))
00102     imin = max(imin, 0)
00103     jmin = int(math.floor((yminAVG - ymin)/hy))
00104     jmin = max(jmin, 0)
00105     kmin = int(math.floor((zminAVG - zmin)/hzed))
00106     kmin = max(kmin, 0)
00107     imax = int(math.ceil((xmaxAVG - xmin)/hx))
00108     imax = min(imax, nx-1)
00109     jmax = int(math.ceil((ymaxAVG - ymin)/hy))
00110     jmax = min(jmax, ny-1)
00111     kmax = int(math.ceil((zmaxAVG - zmin)/hzed))
00112     kmax = min(kmax, nz-1)
00113 
00114     stdout.write("#  \tY POS\t\tAVERAGE\n")
00115     for j in range(jmin, jmax):
00116         avg = 0.0
00117         navg = 0
00118         for k in range(kmin, kmax):
00119             for i in range(imin, imax):
00120                 pt = [i,j,k]
00121                 val = 0.0
00122                 ret, value = Vgrid_value(grid, pt, val)
00123                 if ret:
00124                     avg = avg + value
00125                     navg = navg + 1
00126 
00127         if navg != 0:
00128             avg = avg/navg
00129             stdout.write("   \t%e\t\t%e\n" % ((hy*j + ymin), avg))
00130         else:
00131             stdout.write("   \t%e\t\t%s\n" % ((hy*j + ymin), "nan"))
00132 
00133 if __name__ == "__main__": main()

Generated on Wed Oct 20 2010 11:12:21 for APBS by  doxygen 1.7.2