#!/usr/bin/env python import grid.grid as grid import sys print "# Input format: RDFfromDX.py <dxfilename> <x> <y> <z> <delta> <max> (concentration)" print "If you input a concentration (particles per unit volume), the coordination number will also be printed in the 3rd column" if len(sys.argv) < 6: quit("Error, insufficient arguments") dxfilename, x, y, z, delta, maxval = sys.argv[1:7] concentration = False if len(sys.argv) > 7: concentration = float(sys.argv[7]) griddata = grid.dx2Grid(dxfilename) if not concentration: rdf = griddata.interpRDF([float(x),float(y),float(z)], float(delta), float(maxval)) for i, value in enumerate(rdf): print i*float(delta), value else: rdf, coordnums = griddata.interpRDF([float(x),float(y),float(z)], float(delta), float(maxval), concentration) for i, value in enumerate(rdf): print i*float(delta), value, coordnums[i]
import grid.grid as grid import numpy as np import os testscriptdir = os.getcwd() # Test reading/writing print "Testing reading/writing dx files.." dxfilename = os.path.join(testscriptdir, "data", "dxfiles", "AlaDP_3DRISM_smallbuffer.dx.gz") originalgrid = grid.dx2Grid(dxfilename) maxvalue = originalgrid.distribution.max() maxindices = tuple(np.argwhere(originalgrid.distribution == maxvalue)[0]) originalgrid.distribution[maxindices] = maxvalue * 2.0 originalgrid.writedx("modified.dx") newgrid = grid.dx2Grid("modified.dx") newmax = newgrid.distribution.max() assert newmax == maxvalue * 2.0 #cleanup os.remove("modified.dx") # Test shells print "Testing shell-related utilities.." storedprecomputedshells = grid.readshellindices() newshells = grid.precomputeshellindices(40) for storedshell, newshell in zip(storedprecomputedshells, newshells): for storedpoint, newpoint in zip(storedshell, newshell): for storedindex, newindex in zip(storedpoint, newpoint): assert storedindex == newindex
#!/Users/nosaka/Documents/UNCC/ITSC 3155/Twitter Visualizations/venv/bin/python import grid.grid as grid import sys print "# Input format: RDFfromDX.py <dxfilename> <x> <y> <z> <delta> <max> (concentration)" print "If you input a concentration (particles per unit volume), the coordination number will also be printed in the 3rd column" if len(sys.argv) < 6: quit("Error, insufficient arguments") dxfilename, x, y, z, delta, maxval = sys.argv[1:7] concentration = False if len(sys.argv) > 7: concentration = float(sys.argv[7]) griddata = grid.dx2Grid(dxfilename) if not concentration: rdf = griddata.interpRDF([float(x),float(y),float(z)], float(delta), float(maxval)) for i, value in enumerate(rdf): print i*float(delta), value else: rdf, coordnums = griddata.interpRDF([float(x),float(y),float(z)], float(delta), float(maxval), concentration) for i, value in enumerate(rdf): print i*float(delta), value, coordnums[i]
datadir = os.path.join(os.path.dirname(grid.__file__), "tests", "data") print "Testing reading TINKER guv files.." datafilename = os.path.join(datadir, 'TKRguv', 'h2o.guv.sample') dists = grid.TKRguv2Grids(datafilename) assert len(dists) == 2 assert 1.1 > dists[0].distribution[31, 31, 31] > 0.9 print "Testing reading UxDATA files.." uxdatafilename = os.path.join(datadir, 'UxDATAfiles', 'UVDATA.sample') uxdists = grid.data2Grids(uxdatafilename, disttypes=['g', 'c']) assert len(uxdists) == 4 assert 1.1 > uxdists['O.g'].distribution[31, 31, 31] > 0.9 dxfilename = os.path.join(datadir, "dxfiles", "AlaDP_3DRISM_smallbuffer.dx.gz") griddata = grid.dx2Grid(dxfilename) print "Testing Trilinear interpolation.." assert griddata.getvalue([9.0, 1.0, 1.0]) - 0.609013742553 < 1 * 10**(-10) # Test 3D->RDF function. print "Testing RDF interpolation..." rdfnearO = griddata.interpRDF([3.6, 6.653, 0.00], 0.1, 10.0) #Carbonyl O rdfnearH = griddata.interpRDF([6.737, 6.359, 0], 0.1, 10.0) #NH H rdfnearH2 = griddata.interpRDF([2.733, 4.556, 0], 0.1, 10.0) #another NH H #Debugging section #import matplotlib #import pylab #from numpy import arange #xset = arange(0, 10.0, 0.1)
def main(): parser = \ argparse.ArgumentParser(description=''+ 'Converts volumetric data via grid.py.\n'+ 'Currently available formats:\n\n'+ "Input:\n"+ 'OpenDX (.dx)\n'+ '3D-RISM TINKER "xuv" style (.guv, .huv, etc)\n'+ '3D-RISM GAMESS "UxDATA" style (UVDATA, VVDATA, etc)\n'+ 'MDF 3D-RISM HDF5 "H5" style\n\n'+ 'Output:\n'+ 'OpenDX (.dx)\n'+ 'Accelrys DS grid file (.grd) NOT UHBD grid!!!\n'+ 'Input filetypes are determined by file names.') outtypes = ['dx', 'grd'] parser.add_argument('inputfile', type=str, help='Input volumetric data file') parser.add_argument('outtype', type=str, help='Type of output file: %s' % outtypes) args = parser.parse_args() if args.outtype not in outtypes: exit("Error! Output type not recognized. Choose from %s" % outtypes) if not os.path.isfile(args.inputfile): exit("Error! Input file not found.") # Read intypes = ['dx', 'uv', 'DATA'] if '.dx' in args.inputfile: print "Reading OpenDX input" #Contains only one distribution mygrids = {'.': grid.dx2Grid(args.inputfile)} elif args.inputfile[-2:] == 'uv': print "Reading TINKER xuv input" ## Temporarily try 2.7+/3.0+ #my = {key: value for (key, value) in sequence} # Using Python 2.6 compatible "dictionary comprehension" mygrids = dict(('%d.' % (i+1), mygrid) for (i, mygrid) in \ enumerate(grid.TKRguv2Grids(args.inputfile))) elif "DATA" in args.inputfile: print "Reading UxDATA input" mygrids = grid.data2Grids(args.inputfile) # Already a dictionary for key in mygrids.keys(): # Modify keys to be used as output filenames mygrids['%s.' % key] = mygrids.pop(key) elif ".uv.h5" in args.inputfile: print "Reading MDF .h5 input" mygrids = {} for speciesname, dictofgrids in grid.h5ToGrids( args.inputfile).iteritems(): for disttype, mygrid in dictofgrids.iteritems(): mygrids["%s.%s." % (speciesname, disttype)] = mygrid # Write if args.outtype == 'dx': print "Outputting .dx file(s)" for key, mygrid in mygrids.iteritems(): mygrid.writedx('%sdx' % key) elif args.outtype == 'grd': print "Outputting Accelrys DS .grd file(s)" for key, mygrid in mygrids.iteritems(): mygrid.writegrd('%sgrd' % key)
def main(): parser = \ argparse.ArgumentParser(description=''+ 'Converts volumetric data via grid.py.\n'+ 'Currently available formats:\n\n'+ "Input:\n"+ 'OpenDX (.dx)\n'+ '3D-RISM TINKER "xuv" style (.guv, .huv, etc)\n'+ '3D-RISM GAMESS "UxDATA" style (UVDATA, VVDATA, etc)\n'+ 'MDF 3D-RISM HDF5 "H5" style\n\n'+ 'Output:\n'+ 'OpenDX (.dx)\n'+ 'Accelrys DS grid file (.grd) NOT UHBD grid!!!\n'+ 'Input filetypes are determined by file names.') outtypes = ['dx', 'grd'] parser.add_argument('inputfile', type=str, help='Input volumetric data file') parser.add_argument('outtype', type=str, help='Type of output file: %s' % outtypes) args = parser.parse_args() if args.outtype not in outtypes: exit("Error! Output type not recognized. Choose from %s" % outtypes) if not os.path.isfile(args.inputfile): exit("Error! Input file not found.") # Read intypes = ['dx', 'uv', 'DATA'] if '.dx' in args.inputfile: print "Reading OpenDX input" #Contains only one distribution mygrids = {'.' : grid.dx2Grid(args.inputfile)} elif args.inputfile[-2:] == 'uv': print "Reading TINKER xuv input" ## Temporarily try 2.7+/3.0+ #my = {key: value for (key, value) in sequence} # Using Python 2.6 compatible "dictionary comprehension" mygrids = dict(('%d.' % (i+1), mygrid) for (i, mygrid) in \ enumerate(grid.TKRguv2Grids(args.inputfile))) elif "DATA" in args.inputfile: print "Reading UxDATA input" mygrids = grid.data2Grids(args.inputfile) # Already a dictionary for key in mygrids.keys(): # Modify keys to be used as output filenames mygrids['%s.' % key] = mygrids.pop(key) elif ".uv.h5" in args.inputfile: print "Reading MDF .h5 input" mygrids = {} for speciesname, dictofgrids in grid.h5ToGrids(args.inputfile).iteritems(): for disttype, mygrid in dictofgrids.iteritems(): mygrids["%s.%s." % (speciesname, disttype)] = mygrid # Write if args.outtype == 'dx': print "Outputting .dx file(s)" for key, mygrid in mygrids.iteritems(): mygrid.writedx('%sdx' % key) elif args.outtype == 'grd': print "Outputting Accelrys DS .grd file(s)" for key, mygrid in mygrids.iteritems(): mygrid.writegrd('%sgrd' % key)