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