def quad_term_fast(self, fn, data): """ Fast routine for estimating the quadratic term fn -- a lambda expression for the function \psi. data1 -- data from the distribution we are trying to estimate Returns the value of the estimator Note: this shouldn't be called externally """ n = data.shape[0] total = 0.0 for k in lattice.lattice(self.dim, self.m): sub1 = np.array(self.comp_exp(k, data)) sub2 = sub1*np.array(fn(data)) total += np.sum((np.sum(sub2) - sub2) * sub1) term2 = 0.0 for k in lattice.lattice(self.dim, self.m): for kp in lattice.lattice(self.dim, self.m): bi = fast_integration(lambda x: np.array(self.comp_exp(k,x))*np.array(self.comp_exp(kp,x))*np.array(fn(x)), [0.0 for t in range(self.dim)], [1.0 for t in range(self.dim)], pts=100) sub1 = np.array(self.comp_exp(k, data)) sub2 = np.array(self.comp_exp(kp, data)) term2 += np.sum(bi* sub1* (np.sum(sub2) - sub2)) # print (np.real(2.0*total/(n*(n-1))), np.real(term2/(n*(n-1)))) return np.real(2.0*total/(n*(n-1))) - np.real(term2/(n*(n-1)))
def quad_term_slow(self, fn, data): """ Deprected Slow routine for estimating the quadratic terms fn -- a lambda expression for the function \psi. data1 -- data from the distribution we are trying to estimate Returns the value of the estimator """ assert False, "Deprecated" n = data.shape[0] total = 0.0 for k in lattice.lattice(self.dim, self.m): for i in range(n): for j in range(n): if j != i: total += self.comp_exp(k, data[i, :]) * self.comp_exp( k, data[j, :]) * fn(data[j, :]) term2 = 0.0 for k in lattice.lattice(self.dim, self.m): for kp in lattice.lattice(self.dim, self.m): bi = fast_integration( lambda x: np.array(self.comp_exp(k, x)) * np.array( self.comp_exp(kp, x)) * np.array(fn(x)), [0 for t in range(self.dim)], [1 for t in range(self.dim)]) for i in range(n): for j in range(n): if j != i: term2 += bi * self.comp_exp( k, data[i, :]) * self.comp_exp(kp, data[j, :]) return np.real(2.0 * total / (n * (n - 1)) - 1.0 * term2 / (n * (n - 1)))
def quad_term_fast(self, fn, data): """ Fast routine for estimating the quadratic term fn -- a lambda expression for the function \psi. data1 -- data from the distribution we are trying to estimate Returns the value of the estimator Note: this shouldn't be called externally """ n = data.shape[0] total = 0.0 for k in lattice.lattice(self.dim, self.m): sub1 = np.array(self.comp_exp(k, data)) sub2 = sub1 * np.array(fn(data)) total += np.sum((np.sum(sub2) - sub2) * sub1) term2 = 0.0 for k in lattice.lattice(self.dim, self.m): for kp in lattice.lattice(self.dim, self.m): bi = fast_integration(lambda x: np.array(self.comp_exp( k, x)) * np.array(self.comp_exp(kp, x)) * np.array(fn(x)), [0.0 for t in range(self.dim)], [1.0 for t in range(self.dim)], pts=100) sub1 = np.array(self.comp_exp(k, data)) sub2 = np.array(self.comp_exp(kp, data)) term2 += np.sum(bi * sub1 * (np.sum(sub2) - sub2)) # print (np.real(2.0*total/(n*(n-1))), np.real(term2/(n*(n-1)))) return np.real(2.0 * total / (n * (n - 1))) - np.real(term2 / (n * (n - 1)))
def quad_term_slow(self, fn, data): """ Deprected Slow routine for estimating the quadratic terms fn -- a lambda expression for the function \psi. data1 -- data from the distribution we are trying to estimate Returns the value of the estimator """ assert False, "Deprecated" n = data.shape[0] total = 0.0 for k in lattice.lattice(self.dim, self.m): for i in range(n): for j in range(n): if j != i: total += self.comp_exp(k, data[i,:])*self.comp_exp(k, data[j,:])*fn(data[j,:]) term2 = 0.0 for k in lattice.lattice(self.dim, self.m): for kp in lattice.lattice(self.dim, self.m): bi = fast_integration(lambda x: np.array(self.comp_exp(k,x))*np.array(self.comp_exp(kp,x))*np.array(fn(x)), [0 for t in range(self.dim)], [1 for t in range(self.dim)]) for i in range(n): for j in range(n): if j != i: term2 += bi*self.comp_exp(k, data[i,:])*self.comp_exp(kp, data[j,:]) return np.real(2.0*total/(n*(n-1)) - 1.0*term2/(n*(n-1)))
def __init__(self, size=20, r=3, k=2, rule=rule_30, RIC=False): """Initializes the simulation with the passed parameters. parameters: size: The size of the simulation. The simulation will be square according to this parameter. Defaults to 20 r: The number of neighbors that will be evaluated by the rule function. Defaults to 3 k: The number of possible states in the system. The minimum value is 2. The states are represented as numbers beginning with 0. Defaults to 2 rule: A function that accepts a tuple of r variables representing the neighbors and returns one of k states. Defaults to rule 30 RIC (Rancom Initial Condition): a boolean variable that specifies if the simulation should start from a random initial state. If True is passed, each cell in the first row will be initialized to one of the k states. Defaults to Fales. """ from lattice import lattice from loc import loc as Loc import random self.size = size self.r = r self.k = k self.rule = rule self.__ran = False self.state = lattice(self.size) if RIC: for i in range(size): if random.random() <= 1/k: self.state.set_cell(Loc(0, i), 1) else: self.state.set_cell(Loc(0, int(size/2)), 1)
def eval(self, fast=True): """ Evaluate the estimator on the data. See the paper for details about the estimator. """ T1 = 0.0 T2 = 0.0 ## T1 = \int p^2. T2 = \int q^2, T3 = -2 \int pq for k in lattice.lattice(self.dim, self.m): T1 += 1.0/self.pdata.shape[0]**2 *(np.sum(np.array(self.comp_exp(k, self.pdata)))**2 - np.sum(np.array(self.comp_exp(k,self.pdata))**2)) T2 += 1.0/self.qdata.shape[0]**2 *(np.sum(np.array(self.comp_exp(k, self.qdata)))**2 - np.sum(np.array(self.comp_exp(k,self.qdata))**2)) T3 = -2.0 * np.sum([ np.mean(self.comp_exp(k,self.pdata)) * np.mean(np.array(self.comp_exp(k, self.qdata))) for k in lattice.lattice(self.dim, self.m)]) return np.real(T1 + T2 + T3)
def eval(self, fast=True): """ Evaluate the estimator on the data. See the paper for details about the estimator. """ T1 = 0.0 T2 = 0.0 ## T1 = \int p^2. T2 = \int q^2, T3 = -2 \int pq for k in lattice.lattice(self.dim, self.m): T1 += 1.0 / self.pdata.shape[0]**2 * ( np.sum(np.array(self.comp_exp(k, self.pdata)))**2 - np.sum(np.array(self.comp_exp(k, self.pdata))**2)) T2 += 1.0 / self.qdata.shape[0]**2 * ( np.sum(np.array(self.comp_exp(k, self.qdata)))**2 - np.sum(np.array(self.comp_exp(k, self.qdata))**2)) T3 = -2.0 * np.sum([ np.mean(self.comp_exp(k, self.pdata)) * np.mean(np.array(self.comp_exp(k, self.qdata))) for k in lattice.lattice(self.dim, self.m) ]) return np.real(T1 + T2 + T3)
def bilinear_term_fast(self, fn, data1, data2): """ Faster routine for estimating the bilinear term. fn -- a lambda expression for the function \psi. data1 -- data from the distribution p data2 -- data from the distribution q Returns the value of the estimator Note: This shouldn't be called externally. """ total = np.sum([ np.mean(self.comp_exp(k,data1)) * np.mean(np.array(self.comp_exp(k, data2)) * np.array(fn(data2))) for k in lattice.lattice(self.dim, self.m)]) return np.real(total)
def bilinear_term_fast(self, fn, data1, data2): """ Faster routine for estimating the bilinear term. fn -- a lambda expression for the function \psi. data1 -- data from the distribution p data2 -- data from the distribution q Returns the value of the estimator Note: This shouldn't be called externally. """ total = np.sum([ np.mean(self.comp_exp(k, data1)) * np.mean(np.array(self.comp_exp(k, data2)) * np.array(fn(data2))) for k in lattice.lattice(self.dim, self.m) ]) return np.real(total)
def generate_density(self): """ Construct a d-dimensional density in the Sobolev class W(s,L) under the trigonometric basis \phi_k(x) = e^{2i \pi k^Tx} """ coeffs = [1] fns = [np.matrix([0 for i in range(self.d)])] total = 0 f = lattice.lattice(self.d, limit=None) f.next() while total <= self.L : curr = np.matrix(f.next()) new_coeff = np.random.uniform(-0.1, 0.1) coeffs.append(new_coeff) fns.append(curr) total += new_coeff**2 * np.sum([np.abs(curr[i,0])**(2*self.s) for i in range(curr.shape[0])]) self.coeffs = coeffs[0:len(coeffs)-1] self.fns = fns[0:len(fns)-1]
def bilinear_term_slow(self, fn, data1, data2): """ Deprected A slow routine for estimating the bilinear term. This iterates over all of the basis elements and then over all of the points in the sample. fn -- a lambda expression for the function \psi. data1 -- data from the distribution p data2 -- data from the distribution q Returns the value of the estimator """ assert False, "Deprected" n1 = data1.shape[0] n2 = data2.shape[0] total = 0.0 for k in lattice.lattice(self.dim, self.m): for i in range(n1): for j in range(n2): total += self.comp_exp(k, data1[i,:])*self.comp_exp(k, data2[j,:])*fn(data2[j,:]) return np.real(total[0,0]/(n1*n2))
def generate_density(self): """ Construct a d-dimensional density in the Sobolev class W(s,L) under the trigonometric basis \phi_k(x) = e^{2i \pi k^Tx} """ coeffs = [1] fns = [np.matrix([0 for i in range(self.d)])] total = 0 f = lattice.lattice(self.d, limit=None) f.next() while total <= self.L: curr = np.matrix(f.next()) new_coeff = np.random.uniform(-0.1, 0.1) coeffs.append(new_coeff) fns.append(curr) total += new_coeff**2 * np.sum([ np.abs(curr[i, 0])**(2 * self.s) for i in range(curr.shape[0]) ]) self.coeffs = coeffs[0:len(coeffs) - 1] self.fns = fns[0:len(fns) - 1]
def bilinear_term_slow(self, fn, data1, data2): """ Deprected A slow routine for estimating the bilinear term. This iterates over all of the basis elements and then over all of the points in the sample. fn -- a lambda expression for the function \psi. data1 -- data from the distribution p data2 -- data from the distribution q Returns the value of the estimator """ assert False, "Deprected" n1 = data1.shape[0] n2 = data2.shape[0] total = 0.0 for k in lattice.lattice(self.dim, self.m): for i in range(n1): for j in range(n2): total += self.comp_exp(k, data1[i, :]) * self.comp_exp( k, data2[j, :]) * fn(data2[j, :]) return np.real(total[0, 0] / (n1 * n2))
from __future__ import print_function import lattice, libRNG, sys #rid='overdispersed_large' #resdir='/home/colin/projects/SEED/int' resdir = str(sys.argv[1]) rid=str(sys.argv[2]) dump=bool(sys.argv[3]) Hex=lattice.lattice(50,50,wrap=False) Hex.fillNYC() canopy = lattice.getEndCanopy(resdir, rid) DT = libRNG.getDelaunayGraph(Hex, canopy) RNG = libRNG.getRelativeNeighborGraph(Hex, DT) #import matplotlib.pyplot as plt #import matplotlib.collections as coll #from matplotlib import cm #Hex.plot(plt, coll, [1 if i in canopy else 0 for i in xrange(Hex.N)], [cm.binary(1.0) if i in canopy else cm.binary(0.0) for i in xrange(Hex.N)],[cm.binary(0) for x in xrange(Hex.N)], (0,), '', net=RNG) D,avgMIJ = libRNG.getRNGstats(Hex, canopy, RNG) maxMij= libRNG.getExtent(Hex, canopy) if dump: f=open(resdir+'/RNG.'+rid, 'w') for i,j,w in RNG.edges(data=True): print(i,j,w['weight'], file=f) f.close()
def test_03(self): self.assertEqual(20, lattice.lattice(3))
def test_04(self): self.assertEqual(70, lattice.lattice(4))
s = action(phi, system.hop, system.kappa, system.lamb) dh = hamiltonian(pi, s) - oldham expdh += np.exp(-dh) #metropolis if (dh < 0.0): acc += 1 elif (np.exp(-dh) > np.random.uniform(0, 1.0)): acc += 1 else: rej += 1 phi = np.copy(oldphi) system = latt.lattice() tau = 1.0 nhamdyn = 50 niter = 5000 nbin = 500 eps = tau / nhamdyn acc = 0 rej = 0 phi = gaussrand(system.v) expdh = 0.0 m = 0.0 for it in range(niter): hmc_update()
def calc(reservoir_pressure): rc = 500 # initial guess for potential cut off distance npart = 50 # particles temp = 2 # temperature rho = 0.6 # initial density of fluid in box n_nodes = 1000 # grid nodes for cavity biasing equil_cycles = 200 prod_cycles = 100 sample_frequency = 2 displ_attempts = 100 max_displ = 0.09 exch_attempts = 10 epsilon = 1.0 sigma = 1.0 mass = 1.0 i_seed = 68324 tail_corr = 1 shift_pot = 0 use_cavity_bias = True box_length = (npart / rho)**(1.0 / 3.0) rc = min(rc, box_length / 2.0) rc_sq = rc * rc beta = 1.0 / temp zz = beta * reservoir_pressure epsilon4 = 4.0 * epsilon epsilon48 = 48.0 * epsilon sigma_sq = sigma * sigma coru = 0.0 corp = 0.0 e_cut = 0.0 part_pos_array = lattice.lattice(box_length, npart) press_list = [] en_list = [] rho_list = [] np.random.seed(i_seed) if shift_pot: e_cut, dummy = cener.ener(rc_sq, rc_sq, sigma_sq, epsilon4, epsilon48, shift_pot, e_cut) if tail_corr: corp = ccor.corp(rc, rho, sigma, epsilon4) coru = ccor.coru(rc, rho, sigma, epsilon4) en, vir, rho = cener.totenerg(npart, part_pos_array, box_length, rc, sigma, rc_sq, sigma_sq, epsilon4, epsilon48, shift_pot, e_cut, tail_corr) nmoves = displ_attempts + exch_attempts # display particles in real time atomvis.Clear() atomvis.Init(part_pos_array, box_length) cavity_nodes = ccavity.cavity_locations(box_length, n_nodes) for ii in range(2): """ ii = 0 equilibration ii = 1 production """ if ii == 0: ncycles = equil_cycles else: ncycles = prod_cycles attempt = 0 naccp = 0 attemptp = 0 nacc = 0 atte = 0 acce = 0 rhoav = 0.0 nsampav = 0 naccp, attemptp, max_displ = adjust.adjust(attempt, nacc, max_displ, box_length / 2.0, attemptp, naccp) for icycle in range(ncycles): for imove in range(nmoves): ran = np.random.random() * nmoves if ran < displ_attempts and len(part_pos_array) != 0: # attempt to displace a particle en, vir, nacc, attempt, part_pos_array = mcmove.mcmove( npart, part_pos_array, max_displ, beta, en, vir, attempt, nacc, box_length, rc_sq, sigma_sq, epsilon4, epsilon48, shift_pot, e_cut) else: av_cav, n_cavs = ccavity.available_cavities( cavity_nodes, part_pos_array, 0.8 * sigma) # attempt to exchange a particle with the reservoir en, vir, nacc, attempt, part_pos_array, npart = mcexch.mcexch( npart, part_pos_array, beta, en, vir, attempt, nacc, box_length, rc, rc_sq, sigma, sigma_sq, epsilon4, epsilon48, shift_pot, tail_corr, e_cut, zz, av_cav, n_cavs, n_nodes, use_cavity_bias) if len(part_pos_array) > 0: atomvis.Update(part_pos_array) if ii == 1: # sample averages if icycle % sample_frequency == 0: samp_enp, samp_press, samp_rho = sample.sample( icycle, en, vir, npart, box_length, beta, tail_corr, rc, sigma, epsilon4) # to determine excess chem. potential nsampav += 1 rhoav += npart / (box_length**3) press_list.append(samp_press) en_list.append(samp_enp) rho_list.append(samp_rho) if (icycle % ncycles / 5) == 0: naccp, attemptp, max_displ = adjust.adjust( attempt, nacc, max_displ, box_length / 2.0, attemptp, naccp) if ncycles != 0: en, vir, rho = cener.totenerg(npart, part_pos_array, box_length, rc, sigma, rc_sq, sigma_sq, epsilon4, epsilon48, shift_pot, e_cut, tail_corr) if rhoav != 0 and nsampav != 0: muex = np.log(zz) / beta - np.log(rhoav / nsampav) / beta mu = muex + np.log(rhoav / nsampav) / beta print muex, mu print attempt, nacc print attemptp, naccp print npart return np.mean(en_list), np.mean(press_list), np.mean(rho_list)
def save(self): """ @Make the files """ directory = self.savedir.text() os.chdir(directory) self.setCurrentWidget(self._setup) self.setCurrentWidget(self._grids) self.setCurrentWidget(self._configuration) #self.configurationChanged(self._configuration) self.configurationChanged() try: _mystate = self.state() configuration = self._configuration _format_vector = " {0: 10.8f} {1: 10.8f} {2: 10.8f}\n" _format_with_comment = " {0: 10.8f} {1: 10.8f} {2: 10.8f} {3}\n" _ncsu_atom_format = " %s %.12e %.12e %.12e 1\n" _elements = [] _element_types = [] _element_count = [] _positions_line = "# undefined configuration\n" zipped_counts = {} # Test whether we have a configuration defined: # generate types of atoms encountered: _elements = configuration.conf[0].elements _element_types = list(set(_elements)) _element_count = [_elements.count(ii) for ii in _element_types] # write positions: _positions_line = "#\n **** Lattice constants **** \n\n" zipped_coordinates = zip(_elements, configuration.conf[0].coords) _positions_line += 'atoms=\n"' for name, v in zipped_coordinates: _positions_line += (_ncsu_atom_format % (name, v[0], v[1], v[2])) _positions_line += '"\n' #define dictionary for number of orbitals and radius num_orbital_dict = {} num_orbital = [ self._species.num_orbital[i].value() for i in range(len(_element_types)) ] num_orbital_dict = dict(zip(_element_types, num_orbital)) orbital_radius_dict = {} orbital_radius = [ self._species.orbital_radius[i].text() for i in range(len(_element_types)) ] orbital_radius_dict = dict(zip(_element_types, orbital_radius)) common_lines = _mystate['input_setup_lines'] common_lines += _mystate['input_misc_lines'] common_lines += _mystate['input_io_lines'] common_lines += _mystate['input_species_lines'] common_lines += _mystate['input_units_lines'] except: print "failed to save1" try: # Use the lattice parameter from left lead for the one atom calculation electrodes = configuration.conf[1] latt = lattice(electrodes.lattice) for i_pp in range(len(_element_types)): dir_name = _element_types[i_pp] + '-atom' oneatom_lines = 'atoms=\n"\n' oneatom_lines += _element_types[ i_pp] + ' 0.0 0.0 0.0 1 1 ' oneatom_lines += "%d" % num_orbital_dict[ _element_types[i_pp]] oneatom_lines += '\n"\n\n' oneatom_lines += 'orbitals=\n"\n' oneatom_lines += str( self._species.num_orbital[i_pp].text()) oneatom_lines += ' 0.0 0.0 0.0 ' oneatom_lines += orbital_radius_dict[_element_types[i_pp]] oneatom_lines += ' 1 1\n"\n\n' oneatom_lines += 'number_of_orbitals="' oneatom_lines += str( self._species.num_orbital[i_pp].text()) oneatom_lines += '"\n\n' if not os.path.exists(dir_name): os.mkdir(dir_name) with open(dir_name + '/input', 'w') as inc_file: inc_file.write(_mystate['input_oneatom_grid_lines']) inc_file.write(_mystate['input_mdscf_lines_ON']) inc_file.write(common_lines) inc_file.write(latt) inc_file.write(oneatom_lines) inc_file.write(_mystate['default_input_for_oneatom']) inc_file.write(_mystate['default_input_forON']) # # write out order-n calculation input for lead1 except: print "failed to save2" try: electrodes = configuration.conf[1] latt = lattice(electrodes.lattice) position = position_orbital(electrodes, num_orbital_dict, orbital_radius_dict) dir_name = 'lead1' if not os.path.exists(dir_name): os.mkdir(dir_name) with open(dir_name + '/input', 'w') as inc_file: inc_file.write('start_mode="FIREBALL Start"') inc_file.write(_mystate['input_grids_left_lines']) inc_file.write(_mystate['input_mdscf_lines_ON']) inc_file.write(common_lines) inc_file.write(latt) inc_file.write(position) inc_file.write(_mystate['default_input_forON']) # # write out order-n calculation input for lead2 except: print "failed to save2a" try: electrodes = configuration.conf[2] latt = lattice(electrodes.lattice) position = position_orbital(electrodes, num_orbital_dict, orbital_radius_dict) dir_name = 'lead2' if not os.path.exists(dir_name): os.mkdir(dir_name) with open(dir_name + '/input', 'w') as inc_file: inc_file.write('start_mode="FIREBALL Start"') inc_file.write(_mystate['input_grids_right_lines']) inc_file.write(_mystate['input_mdscf_lines_ON']) inc_file.write(common_lines) inc_file.write(latt) inc_file.write(position) inc_file.write(_mystate['default_input_forON']) # # write out order-n calculation input for center part except: print "failed to save2b" try: center_ctrl = {} if (self._grids.center_periodicity.isChecked()): center_ctrl = { 'state_begin': 0, 'ion_begin': 0, 'num_atoms': 0 } position = position_orbital_center_ON( configuration, num_orbital_dict, orbital_radius_dict) else: position, center_ctrl = position_orbital_center_ON_nop( configuration, num_orbital_dict, orbital_radius_dict) dir_name = 'center' if not os.path.exists(dir_name): os.mkdir(dir_name) with open(dir_name + '/input', 'w') as inc_file: inc_file.write('start_mode="FIREBALL Start"') inc_file.write(_mystate['input_grids_center_lines']) inc_file.write(_mystate['input_mdscf_lines_ON']) inc_file.write(common_lines) inc_file.write(position) inc_file.write(_mystate['default_input_forON']) except: print "failed to save3" try: electrods = configuration.conf conf1 = electrods[1] conf2 = electrods[1] conf3 = electrods[1] position = position_orbital_3part(conf1, conf2, conf3, num_orbital_dict, orbital_radius_dict) dir_name = '3lead_lead1' if not os.path.exists(dir_name): os.mkdir(dir_name) a1 = self._grids._Nx_left.value() a2 = self._grids._Nx_left.value() * 2 b = self._grids._Ny_left.value() c = self._grids._Nz_left.value() tem = 'potential_compass = "******"\n' % (a1, a2, b, c) tem += 'chargedensity_compass = "******"\n' % ( a1, a2, b, c) with open(dir_name + '/input', 'w') as inc_file: inc_file.write('start_mode_NEGF="111"') inc_file.write('start_mode="FIREBALL Start"') inc_file.write(_mystate['input_grids_left3_lines']) inc_file.write(_mystate['input_mdscf_lines_NEGF']) inc_file.write(common_lines) inc_file.write(position) inc_file.write(tem) inc_file.write(_mystate['default_input_forON']) except: print "failed to save3a" try: conf1 = electrods[2] conf2 = electrods[2] conf3 = electrods[2] position = position_orbital_3part(conf1, conf2, conf3, num_orbital_dict, orbital_radius_dict) dir_name = '3lead_lead2' if not os.path.exists(dir_name): os.mkdir(dir_name) a1 = self._grids._Nx_right.value() a2 = self._grids._Nx_right.value() * 2 b = self._grids._Ny_right.value() c = self._grids._Nz_right.value() tem = 'potential_compass = "******"\n' % (a1, a2, b, c) tem += 'chargedensity_compass = "******"\n' % ( a1, a2, b, c) with open(dir_name + '/input', 'w') as inc_file: inc_file.write('start_mode_NEGF="111"') inc_file.write('start_mode="FIREBALL Start"') inc_file.write(_mystate['input_grids_right3_lines']) inc_file.write(_mystate['input_mdscf_lines_NEGF']) inc_file.write(common_lines) inc_file.write(position) inc_file.write(tem) inc_file.write(_mystate['default_input_forON']) except: print "failed to save3b" try: conf1 = electrods[1] conf2 = electrods[0] conf3 = electrods[2] position = position_orbital_negf(conf1, conf2, conf3, num_orbital_dict, orbital_radius_dict) dir_name = 'bias_0.0' if not os.path.exists(dir_name): os.mkdir(dir_name) a1 = self._grids._Nx_left.value() a2 = self._grids._Nx_negf - self._grids._Nx_right.value() b = self._grids._Ny_right.value() c = self._grids._Nz_right.value() tem = 'potential_compass = "******"\n' % (a1, a2, b, c) tem += 'chargedensity_compass = "******"\n' % ( a1, a2, b, c) with open(dir_name + '/input', 'w') as inc_file: inc_file.write('start_mode_NEGF="112"') inc_file.write('start_mode="FIREBALL Start"') inc_file.write(_mystate['input_grids_negf_lines']) inc_file.write(_mystate['input_mdscf_lines_NEGF']) inc_file.write(common_lines) inc_file.write(position) inc_file.write(tem) inc_file.write(_mystate['default_input_forON']) except: print "failed to save3c" try: write_out_LCR(self._io, self._grids, center_ctrl, configuration, num_orbital_dict) except: print "failed to save3d" try: write_out_others(configuration, self._negf_para, self._grids, self._mdscf, num_orbital_dict) except: print "failed to save3e" try: write_out_jobfiles(configuration, self._setup, self._grids) except: print "failed to save"
def test_01(self): self.assertEqual(1, lattice.lattice(0))
def test_02(self): self.assertEqual(6, lattice.lattice(2))
import unittest import lattice class Test(unittest.TestCase): def test_01(self): self.assertEqual(1, lattice.lattice(0)) def test_02(self): self.assertEqual(6, lattice.lattice(2)) def test_03(self): self.assertEqual(20, lattice.lattice(3)) def test_04(self): self.assertEqual(70, lattice.lattice(4)) print(lattice.lattice(20)) if __name__ == '__main__': unittest.main()
DataWat = data_lammps(WaterDataFile) water = data_to_molecule( DataWat) # create a molecule object from the Data input Cat = atom(idx=0, iSpc=1, Type=2, charge=+1.0, xyz=np.zeros(3, np.double)) An = atom(idx=0, iSpc=2, Type=3, charge=-1.0, xyz=np.zeros(3, np.double)) # what to build is an array of tuples that contains the molecule/atom # and the corresponding num of the species to be created what_to_build = [None] * 3 what_to_build[0] = (water, NWaters) what_to_build[1] = (Cat, NCations) what_to_build[2] = (An, NAnions) NSpecies = NWaters + NCations + NAnions edgeUC = [3.1] * 3 latt = lattice( 'cub', edgeUC, NSpecies ) # type of latt, edge lengths of the UC, minimum # of Nodes in the latt # create a molecular system with the what_to_build directives, on the the lattice latt molSys = Create_config_on_lattice(latt, what_to_build) # num of random Swaps, one species of the swaped pair is always in the IonIndices slice IonIndices = slice(NWaters, -1, 1) molSys.rand_swaps(NSwaps=10000, TargetSlice=IonIndices) DataOut = Mol_System_to_data(molSys) DataOut.write(DataFileOut)