#!/Users/nosaka/Documents/UNCC/ITSC 3155/Twitter Visualizations/venv/bin/python import grid.grid as grid import numpy as np import os 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
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)
import numpy as np import os 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