def test_write_dx(tmpdir, nptype, dxtype, outfile, counts=100, ndim=3): # conversion from numpy array to DX file h, edges = np.histogramdd(np.random.random((counts, ndim)), bins=10) g = Grid(h, edges) # hack the grid to be a different dtype g.grid = g.grid.astype(nptype) assert_equal(g.grid.sum(), counts) with tmpdir.as_cwd(): g.export(outfile) g2 = Grid(outfile) # check that dxtype was written dx = gridData.OpenDX.field(0) dx.read(outfile) data = dx.components['data'] out_dxtype = data.type assert_almost_equal(g.grid, g2.grid, err_msg="written grid does not match original") assert_almost_equal(g.delta, g2.delta, decimal=6, err_msg="deltas of written grid do not match original") assert_equal(out_dxtype, dxtype)
def _test_write_dx(counts=100, ndim=3, nptype="float32", dxtype="float"): h, edges = np.histogramdd(np.random.random((counts, ndim)), bins=10) g = Grid(h, edges) # hack the grid to be a different dtype g.grid = g.grid.astype(nptype) assert_equal(g.grid.sum(), counts) with tempdir.in_tempdir(): outfile = "grid.dx" g.export(outfile) g2 = Grid(outfile) # check that dxtype was written dx = gridData.OpenDX.field(0) dx.read(outfile) data = dx.components['data'] out_dxtype = data.type assert_almost_equal(g.grid, g2.grid, err_msg="written grid does not match original") assert_almost_equal( g.delta, g2.delta, decimal=6, err_msg="deltas of written grid do not match original") assert_equal(out_dxtype, dxtype)
def test_write_dx(tmpdir, nptype, dxtype, counts=100, ndim=3): # conversion from numpy array to DX file h, edges = np.histogramdd(np.random.random((counts, ndim)), bins=10) g = Grid(h, edges) # hack the grid to be a different dtype g.grid = g.grid.astype(nptype) assert_equal(g.grid.sum(), counts) with tmpdir.as_cwd(): outfile = "grid.dx" g.export(outfile) g2 = Grid(outfile) # check that dxtype was written dx = gridData.OpenDX.field(0) dx.read(outfile) data = dx.components['data'] out_dxtype = data.type assert_almost_equal(g.grid, g2.grid, err_msg="written grid does not match original") assert_almost_equal( g.delta, g2.delta, decimal=6, err_msg="deltas of written grid do not match original") assert_equal(out_dxtype, dxtype)
def test_write_dx_ValueError(tmpdir, nptype, outfile, counts=100, ndim=3): h, edges = np.histogramdd(np.random.random((counts, ndim)), bins=10) g = Grid(h, edges) # hack the grid to be a different dtype g.grid = g.grid.astype(nptype) with pytest.raises(ValueError): with tmpdir.as_cwd(): g.export(outfile)
def test_write_dx_ValueError(tmpdir, nptype, counts=100, ndim=3): h, edges = np.histogramdd(np.random.random((counts, ndim)), bins=10) g = Grid(h, edges) # hack the grid to be a different dtype g.grid = g.grid.astype(nptype) with pytest.raises(ValueError): with tmpdir.as_cwd(): outfile = "grid.dx" g.export(outfile)
def write_dx_input(self, param_charge, param_diel): ''' Generate the dielectric constant and charge grid for APBS calculations. ``generate_charge`` and ``generate_diel`` are used to generate the profile of the charge and dielectric constant on the one-dimensional z-axis which is then broadcast to cover the whole 3D space. The generated files are named as ``dielx.dx``, ``diely.dx``, ``dielz.dx`` and ``charge.dx``. Parameters ---------- **kwargs : dict ``generate_charge`` uses the arguments from kwargs['charge'] and ``generate_diel`` uses the arguments from kwargs['diel']. ''' # generate the one dimensional z axis z_list = np.linspace(0 * pq.angstrom, self.dim[-1], self.grid[-1]) charge = self.generate_charge(z_list, param_charge) diel = self.generate_diel(z_list, param_diel) # expand to 3D diel = np.ones((self.grid[0], self.grid[1], 1)) * diel.reshape( (1, 1, self.grid[2])) charge = np.ones((self.grid[0], self.grid[1], 1)) * charge.reshape( (1, 1, self.grid[2])) origin = self.dim / 2 * -1 origin = origin.rescale(pq.angstrom) delta = self.delta.rescale(pq.angstrom) # Write diel # write x origin_x = origin.copy() origin_x[0] += self.delta[0] / 2 g = Grid(diel, origin=origin_x.magnitude, delta=delta.magnitude) g.export('dielx.dx', typequote='') # write y origin_y = origin.copy() origin_y[1] += self.delta[1] / 2 g = Grid(diel, origin=origin_y.magnitude, delta=delta.magnitude) g.export('diely.dx', typequote='') # write z origin_z = origin.copy() origin_z[2] += self.delta[2] / 2 g = Grid(diel, origin=origin_z.magnitude, delta=delta.magnitude) g.export('dielz.dx', typequote='') # Write charge charge = charge.rescale(pq.e / pq.angstrom**3) g = Grid(charge.magnitude, origin=origin.magnitude, delta=delta.magnitude) g.export('charge.dx', typequote='')
def test_write_dx(counts=100, ndim=3): h, edges = np.histogramdd(np.random.random((counts, ndim)), bins=10) g = Grid(h, edges) assert_equal(g.grid.sum(), counts) with tempdir.in_tempdir(): outfile = "grid.dx" g.export(outfile) g2 = Grid(outfile) assert_array_almost_equal(g.grid, g2.grid, err_msg="written grid does not match original") assert_array_almost_equal( g.delta, g2.delta, err_msg="deltas of written grid do not match original")
def grid_to_dx(self, save_dir, grid, bin_size, use_channel_names=False): #origin = np.array([7.473, 4.334, 7.701]) - 5.0 if grid.shape[0] % 2 != 0: raise ValueError('Number of channels must be even (%i)' % grid.shape[0]) ch_per_mol = grid.shape[0] / 2 for shift, prefix in [(0, 'rec'), (ch_per_mol, 'lig')]: for ch in range(ch_per_mol): ch += shift if use_channel_names: names = self.prop_table.columns[1:] names *= 2 channel_name = names[ch] else: channel_name = str(ch) g = Grid(grid[ch], origin=np.array([7.473, 4.334, 7.701]) - 5.0, delta=bin_size) g.export(Path(save_dir).joinpath(channel_name + '.dx'), 'DX')
from gridData import Grid g = Grid(sys.argv[1]) values = g.grid coordinates = g.edges max_value = np.amax(values) scaled_values = values * (1 / max_value) g_scaled = Grid(scaled_values, edges=coordinates) g_scaled.export(sys.argv[1].split(".")[0] + "_scaled.dx", "DX") """ # plot to test the result import matplotlib.pyplot as plt x=[] y=[] point=0 for i in range(48): for j in range(48): for k in range(48): y.append(scaled_values[i,j,k]) point+=1 x.append(point)
edge_1=g_1.edges print(values_1[0,0,0]) print(type(values_1)) print(values_1[0]) print(type(edge_1)) print(edge_1[0]) values_O=g_O.grid edge_O=g_O.edges print(values_O[0,0,0]) print(values_O[0]) print(values_1[0]) empty_gO_grid=Grid(np.zeros((48,48,48)),edges=edge_O) empty_gO_grid.export("empty_gO.dx","DX") empty_gO=Grid("empty_gO.dx") empty_values=empty_gO.grid print(empty_values[0,0,0]) empty_edges=empty_gO.edges file=open("102_ligand_coordinate.txt","r").readlines() for line in file: print(line) target=line.split()[0] x_center=line.split()[2]
fp.close() fp = open(args.outputfile, "w") fp.write("# Original file " + args.inputfile + "\n") fp.write("# converted\n") for l in header: if l != "end": fp.write(l + "\n") counter = 0 for e in values: fp.write("%20.15f " % (e)) counter += 1 if counter == 3: fp.write("\n") counter = 0 if counter < 3: fp.write("\n") for l in tail: if l != "end": fp.write(l + "\n") fp.close() g = Grid(args.outputfile) g.export(args.outputfile, type="double")
import sys import numpy as np from gridData import Grid data = np.genfromtxt(sys.argv[1], delimiter=" ") xmin = min(data[:, 0]) ymin = min(data[:, 1]) zmin = min(data[:, 2]) density = data[:, 4] dstep = data[0, 2] - data[1, 2] density.shape = [50, 50, 50] g = Grid(density, origin=[xmin, ymin, zmin], \ delta=[dstep, dstep, dstep]) g.export(sys.argv[1].replace(".txt", ".dx"))
import caffe from gridData import Grid import numpy as np caffe.set_mode_gpu() net = caffe.Net('modelTan.prototxt', 'TanH_00001SGD_100000.caffemodel', caffe.TEST) maxs = open("maxs.txt", "w") e =np.mgrid[-10:10:1] for i in range(0, 50): net.forward() for x in range(0, 20): grid = Grid(grid=net.blobs['ndim'].data[x].reshape((100,100,100)), origin=[0,0,0], edges=[e,e,e]) grid.export('binmaps/actualGrid' + str(i) + str(x) + '.dx') grid = Grid(grid=net.blobs['unit3_conv'].data[x].reshape((100,100,100)), origin=[0,0,0], edges=[e,e,e]) grid.export('binmaps/predictedGrid' + str(i) + str(x) + '.dx') print "Mean " + str(x) + ":" z = abs(net.blobs['ndim'].data[x] - net.blobs['unit3_conv'].data[x][0].mean()) print z[0][0][0] print "Max" + str(x) + ":" y = abs(net.blobs['ndim'].data[x] - net.blobs['unit3_conv'].data[x][0].max()) print y[0][0][0] maxs.close()
# break #print('{:d} coordinates loaded.'.format(len(data))) #print('DCD Min-Max:') #print(' x: {:f} {:f}'.format(mm.min[0], mm.max[0])) #print(' y: {:f} {:f}'.format(mm.min[1], mm.max[1])) #print(' z: {:f} {:f}'.format(mm.min[2], mm.max[2])) #data_target = [] #for xyz in data: # if mm_target.in_or_out(xyz, CUT_DIST): # data_target.append(xyz) bins = [] for i in range(3): b = [] for k in range(floor(mm_target.min[i] - CUT_DIST), ceil(mm_target.max[i] + CUT_DIST)+1): b.append(float(k)) b.append(float(k)+0.5) bins.append(b) #print (bins) H, edges = np.histogramdd(np.array(data), bins=bins) #print (H.shape, edges[0].size, edges[1].size, edges[2].size) #print (H) g = Grid(H, edges=edges) g.export(filename_dx)
def dx4resample(name, factor): """Comments""" gddx = Grid() gddx.load(name) gddx.resample_factor(factor) gddx.export(name, file_format='dx')
import numpy as np from gridData import Grid import sys import argparse # one PMEpot unit (kT/e) of electrostatic potential is equivalent to 0.0258 Volts. (or 25.8 mV) # Parse inputs parser = argparse.ArgumentParser() parser.add_argument("-f",dest="infile",action="store") parser.add_argument("-e",dest="eField",type=float,action="store") parser.add_argument("-o",dest="outname",action="store") args = parser.parse_args() # Open the .dx from PMEPot, and calculate grid-demensions PMEPotIN = Grid(args.infile) lenx, leny, lenz = PMEPotIN.grid.shape # loop through the z-axis of the reaction potential and add the applied linear-potential for z in range(lenz): for x in range(lenx): for y in range(leny): PMEPotIN.grid[x][y][z] = PMEPotIN.grid[x][y][z] + (z*args.eField) # writeout new potential grid PMEPotIN.export(args.outname+'.dx')
print("After fit Min Max: ", min(S), max(S)) #for v in S: # print (v) print("") #s = np.sin(x*y*z)/(x*y*z) S = S.reshape(N, N, N) #print(S.shape, type(S)) g = Grid(S, origin=[min(X), min(Y), min(Z)], \ delta=[dxstep, dystep, dzstep]) g.export(fieldfilename.replace(".txt", ".dx")) """ import numpy as np from scipy.interpolate import RegularGridInterpolator def f(x, y, z): return 2 * x**3 + 3 * y**2 - z x = np.linspace(1, 4, 11) y = np.linspace(4, 7, 22) z = np.linspace(7, 9, 33) xg, yg ,zg = np.meshgrid(x, y, z, indexing='ij', sparse=True) print(xg.shape) print(yg.shape)