def main(): # Define list of pair potentials pairPotentials = [ Potential('Al', 'Al', ppfuncAlAl), Potential('Al', 'Fe', ppfuncAlFe), Potential('Fe', 'Fe', ppfuncFeFe)] # Assemble the EAMPotential objects eamPotentials = [ # Al EAMPotential('Al', 13, 26.98154, AlEmbedFunction, {'Al': AlAlDensityFunction, 'Fe': FeAlDensityFunction}, latticeConstant=4.04527, latticeType='fcc'), # Fe EAMPotential('Fe', 26, 55.845, FeEmbedFunction, {'Al': FeAlDensityFunction, 'Fe': FeFeDensityFunction}, latticeConstant=2.855312, latticeType='bcc')] # Number of grid points and cut-offs for tabulation. cutoff_rho = 300.0 nrho = 10000 cutoff = 6.5 nr = 10000 tabulation = TABEAM_FinnisSinclair_EAMTabulation( pairPotentials, eamPotentials, cutoff, nr, cutoff_rho, nrho) with open("TABEAM", "w") as outfile: tabulation.write(outfile)
def createSetFLEAMPots(self): fdict = self.createSetFlFuncs() eamPotentials = [ EAMPotential("Al", 13, 26.98, fdict['embed_Al'], fdict['dens_Al']), EAMPotential("Cu", 29, 63.55, fdict['embed_Cu'], fdict['dens_Cu'])] return eamPotentials
def main(): # Create EAMPotential eamPotentials = [EAMPotential("U", 92, 238.03, embed, density)] pairPotentials = [Potential('U', 'U', pair_UU)] cutoff = 8.0 #nrho = 962 # n points density nrho = 5000 # n points density #drho = 0.00103950 # distance points density drho = 0.02 # distance points density #nr = 1462 # n points embed & Vpair nr = 5000 # n points embed & Vpair dr = cutoff / nr # distance points embed & Vpair from atsim.potentials import writeFuncFL with open("U2.eam", 'wb') as outfile: writeSetFL(nrho, drho, nr, dr, eamPotentials, pairPotentials, out=outfile, comments=['Spline Uranium as U.eam', '', ''])
def main(): # Define list of pair potentials pairPotentials = [ Potential('Al', 'Al', ppfuncAlAl), Potential('Al', 'Fe', ppfuncAlFe), Potential('Fe', 'Fe', ppfuncFeFe) ] # Assemble the EAMPotential objects eamPotentials = [ #Al EAMPotential('Al', 13, 26.98154, AlEmbedFunction, { 'Al': AlAlDensityFunction, 'Fe': FeAlDensityFunction }, latticeConstant=4.04527, latticeType='fcc'), #Fe EAMPotential('Fe', 26, 55.845, FeEmbedFunction, { 'Al': FeAlDensityFunction, 'Fe': FeFeDensityFunction }, latticeConstant=2.855312, latticeType='bcc') ] # Number of grid points and cut-offs for tabulation. nrho = 10000 drho = 3.00000000000000E-2 nr = 10000 dr = 6.50000000000000E-4 cutoff = 6.5 with open("TABEAM", "w") as outfile: writeTABEAMFinnisSinclair(nrho, drho, nr, dr, eamPotentials, pairPotentials, outfile)
def testWriteFuncflDensity(self): """Test writeFuncFL() writing of density function correct""" shutil.copyfile(os.path.join(_getResourceDirectory(), "writefuncfl_pair.lmpstruct"), os.path.join(self.tempdir,"structure.lmpstruct")) shutil.copyfile(os.path.join(_getResourceDirectory(), "calc_energy.lmpin"), os.path.join(self.tempdir,"calc_energy.lmpin")) oldpwd = os.getcwd() os.chdir(self.tempdir) try: with open("potentials.lmpinc", "w") as potfile: potfile.write("pair_style eam\n") potfile.write("pair_coeff 1 1 Ag.eam\n") def embed(rho): return rho def density(rij): if rij == 0: return 0.0 return (2.928323832 / rij) ** 6.0 def pair_AgAg(rij): return 0.0 pairPotentials = [ Potential('Ag', 'Ag', pair_AgAg) ] # Create EAMPotential eamPotentials = [ EAMPotential("Ag", 47, 107.8682, embed, density) ] nrho = 200000 drho = 0.0005 nr = 5000 dr = 0.001 from atsim.potentials import writeFuncFL with open("Ag.eam", 'w') as outfile: writeFuncFL( nrho, drho, nr, dr, eamPotentials, pairPotentials, title='Sutton Chen Ag', out= outfile) runLAMMPS() energy = extractLAMMPSEnergy() self.assertAlmostEqual(83.7425918012, energy/2.0, places = 5) finally: os.chdir(oldpwd)
def testWriteFuncflPair(self): """Test that unit conversions for pair potential tabulation by writeFuncFL() are correct""" shutil.copyfile(os.path.join(_getResourceDirectory(), "writefuncfl_pair.lmpstruct"), os.path.join(self.tempdir,"structure.lmpstruct")) shutil.copyfile(os.path.join(_getResourceDirectory(), "calc_energy.lmpin"), os.path.join(self.tempdir,"calc_energy.lmpin")) oldpwd = os.getcwd() os.chdir(self.tempdir) try: with open("potentials.lmpinc", "w") as potfile: potfile.write("pair_style eam\n") potfile.write("pair_coeff 1 1 Ag.eam") def embed(rho): return 0.0 def density(rij): return 0.0 def pair_AgAg(rij): if rij == 0: return 0.0 return (2.485883762/rij) ** 12 pairPotentials = [ Potential('Ag', 'Ag', pair_AgAg) ] # Create EAMPotential eamPotentials = [ EAMPotential("Ag", 47, 107.8682, embed, density) ] nrho = 50000 drho = 0.001 nr = 12000 dr = 0.001 from atsim.potentials import writeFuncFL with open("Ag.eam", 'w') as outfile: writeFuncFL( nrho, drho, nr, dr, eamPotentials, pairPotentials, title='Sutton Chen Ag', out= outfile) runLAMMPS() energy = extractLAMMPSEnergy() self.assertAlmostEqual(982.2756583, energy) finally: os.chdir(oldpwd)
def testWriteFuncflAgU3EAM(self): """Test that lammps.writeEAMTable can reproduce a DYNAMO funcfl EAM file from the standard LAMMPS distribution here Ag_u3.eam""" #Read the expected table from the .eam file with open(os.path.join(_getResourceDirectory(), 'Ag_u3.eam'),'r') as infile: expectTable = _parseEAMTable(infile) #Create the potential callables to be passed into writeEAMTable() embeddingFunction = potentials.TableReader( open(os.path.join(_getResourceDirectory(), 'AgU3embedding.table'), 'r')) effectiveChargeFunction = potentials.TableReader( open(os.path.join(_getResourceDirectory(), 'AgU3effectivecharge.table'), 'r')) def effectiveChargeFunction_eV(rij): v = effectiveChargeFunction(rij) v *= v v *= 27.2 * 0.529 if rij != 0.0: v /= rij return v densityFunction = potentials.TableReader( open(os.path.join(_getResourceDirectory(), 'AgU3density.table'), 'r')) title = "Ag functions (universal 3), SM Foiles et al, PRB, 33, 7983 (1986)" atomicNumber = 47 mass = 107.87 latticeConstant = 4.09 latticeType = 'FCC' nrho = 500 drho = 5.0100200400801306e-04 nr = 500 dr = 1.1212121212121229e-02 eampotlist = [EAMPotential("Ag", atomicNumber, mass, embeddingFunction, densityFunction, latticeConstant, latticeType)] potlist = [Potential("Ag", "Ag", effectiveChargeFunction_eV)] actualTable = StringIO() potentials.writeFuncFL( nrho, drho, nr, dr, eampotlist, potlist, title = title, out = actualTable) actualTable.seek(0) actualTable = _parseEAMTable(actualTable) from . import testutil testutil.compareCollection(self,expectTable, actualTable, places = 3)
def __init__(self, ES, nrho=5000, drho=0.02, nr=5000, dr=0.0015): self.ES = ES self.Nelements = len(ES) self.pairPotentials = [] self.eamPotentials = [] self.nrho = nrho self.drho = drho self.nr = nr self.dr = dr self.myParameters = {} for e in self.ES: self.myParameters[e] = dbZhou.parameters[e] self.symbols = self.myParameters.keys() self.k_p = self.myParameters[self.symbols[0]].keys() for e in ES: E1 = self.myParameters[e] dens_E1 = self.makeFunc(E1['f_e'], E1['omega_'], E1['r_e'], E1['lambda_']) self.myParameters[e]['dens'] = dens_E1 F_ni_E1 = [E1['F_n0_'], E1['F_n1_'], E1['F_n2_'], E1['F_n3_']] F_i_E1 = [E1['F_0_'], E1['F_1_'], E1['F_2_'], E1['F_3_']] embed_E1 = self.makeEmbed(E1['rho_e_'], E1['rho_s_'], F_ni_E1, F_i_E1, \ E1['F_e_'], E1['eta_']) self.myParameters[e]['embed'] = embed_E1 self.eamPotentials.append(EAMPotential(E1['symbol'], E1['number'], \ E1['mass'], embed_E1, dens_E1)) pair_E1E1 = self.makePairPotAA(E1['A_'], E1['gamma_'], E1['r_e'], E1['kappa_'], E1['B_'], E1['omega_'], E1['lambda_']) self.myParameters[e]['pair'] = pair_E1E1 self.fileName = 'Zhou_' for e in self.ES: self.fileName += e self.comment = self.fileName self.fileName += '.setfl'
def main(): # Create EAMPotential eam_potentials = [EAMPotential("Ag", 47, 107.8682, embed, density)] pair_potentials = [Potential('Ag', 'Ag', pair_AgAg)] cutoff_rho = 50.0 nrho = 50000 cutoff = 12.0 nr = 12000 tabulation = SetFL_EAMTabulation( pair_potentials, eam_potentials, cutoff, nr, cutoff_rho, nrho) with open("Ag.eam.alloy", 'w') as outfile: tabulation.write(outfile)
def main(): # Create EAMPotential eamPotentials = [EAMPotential("Ag", 47, 107.8682, embed, density)] pairPotentials = [Potential('Ag', 'Ag', pair_AgAg)] nrho = 50000 drho = 0.001 nr = 12000 dr = 0.001 from atsim.potentials import writeFuncFL with open("Ag.eam", 'w') as outfile: writeFuncFL(nrho, drho, nr, dr, eamPotentials, pairPotentials, out=outfile, title='Sutton Chen Ag')
def main(): # Create EAMPotential f_UU = buck(294.640000, 0.327022, 0.0) eamPotentials = [EAMPotential("U", 92, 238.03, embed, density)] pairPotentials = [Potential('U', 'U', f_UU)] nrho = 50000 drho = 0.001 nr = 12000 dr = 0.001 from atsim.potentials import writeFuncFL with open("U.eam", 'wb') as outfile: writeSetFL(nrho, drho, nr, dr, eamPotentials, pairPotentials, out=outfile, comments=['Buckingham Uranium as U.eam', '', ''])
def makePotentialObjects(): # Potential parameters r_eCu = 2.556162 f_eCu = 1.554485 gamma_Cu = 8.127620 omega_Cu = 4.334731 A_Cu = 0.396620 B_Cu = 0.548085 kappa_Cu = 0.308782 lambda_Cu = 0.756515 rho_e_Cu = 21.175871 rho_s_Cu = 21.175395 F_ni_Cu = [-2.170269, -0.263788, 1.088878, -0.817603] F_i_Cu = [-2.19, 0.0, 0.561830, -2.100595] eta_Cu = 0.310490 F_e_Cu = -2.186568 r_eAl = 2.863924 f_eAl = 1.403115 gamma_Al = 6.613165 omega_Al = 3.527021 # A_Al = 0.134873 A_Al = 0.314873 B_Al = 0.365551 kappa_Al = 0.379846 lambda_Al = 0.759692 rho_e_Al = 20.418205 rho_s_Al = 23.195740 F_ni_Al = [-2.807602, -0.301435, 1.258562, -1.247604] F_i_Al = [-2.83, 0.0, 0.622245, -2.488244] eta_Al = 0.785902 F_e_Al = -2.824528 # Define the density functions dens_Cu = makeFunc(f_eCu, omega_Cu, r_eCu, lambda_Cu) dens_Al = makeFunc(f_eAl, omega_Al, r_eAl, lambda_Al) # Finally, define embedding functions for each species embed_Cu = makeEmbed(rho_e_Cu, rho_s_Cu, F_ni_Cu, F_i_Cu, F_e_Cu, eta_Cu) embed_Al = makeEmbed(rho_e_Al, rho_s_Al, F_ni_Al, F_i_Al, F_e_Al, eta_Al) # Wrap them in EAMPotential objects eam_potentials = [ EAMPotential("Al", 13, 26.98, embed_Al, dens_Al), EAMPotential("Cu", 29, 63.55, embed_Cu, dens_Cu) ] # Define pair functions pair_CuCu = makePairPotAA(A_Cu, gamma_Cu, r_eCu, kappa_Cu, B_Cu, omega_Cu, lambda_Cu) pair_AlAl = makePairPotAA(A_Al, gamma_Al, r_eAl, kappa_Al, B_Al, omega_Al, lambda_Al) pair_AlCu = makePairPotAB(dens_Cu, pair_CuCu, dens_Al, pair_AlAl) # Wrap them in Potential objects pair_potentials = [ Potential('Al', 'Al', pair_AlAl), Potential('Cu', 'Cu', pair_CuCu), Potential('Al', 'Cu', pair_AlCu) ] return eam_potentials, pair_potentials
def main(): params = { ('A', 'PtPt'): 0.1602, ('A', 'NiPt'): 0.1346, ('A', 'NiNi'): 0.0845, ('xi', 'PtPt'): 2.1855, ('xi', 'NiPt'): 2.3338, ('xi', 'NiNi'): 1.405, ('p', 'PtPt'): 13.00, ('p', 'NiPt'): 14.838, ('p', 'NiNi'): 11.73, ('q', 'PtPt'): 3.13, ('q', 'NiPt'): 3.036, ('q', 'NiNi'): 1.93, ('r0', 'PtPt'): 2.77, ('r0', 'NiPt'): 2.63, ('r0', 'NiNi'): 2.49, ('cut_a', 'PtPt'): 4.08707719, ('cut_b', 'PtPt'): 5.0056268338740553, ('cut_a', 'NiPt'): 4.08707719, ('cut_b', 'NiPt'): 4.4340500673763259, ('cut_a', 'NiNi'): 3.62038672, ('cut_b', 'NiNi'): 4.4340500673763259} # Create EAMPotential eam_potentials = [EAMPotential('Ni', 28, 58.6934, embedding_function, {'Ni': make_density( params[('xi', 'NiNi')], params[('q', 'NiNi')], params[('r0', 'NiNi')], params[('cut_a', 'NiNi')], params[('cut_b', 'NiNi')]), 'Pt': make_density( params[('xi', 'NiPt')], params[('q', 'NiPt')], params[('r0', 'NiPt')], params[('cut_a', 'NiPt')], params[('cut_b', 'NiPt')])}, latticeConstant=3.524, latticeType='fcc'), EAMPotential('Pt', 78, 195.084, embedding_function, {'Ni': make_density( params[('xi', 'NiPt')], params[('q', 'NiPt')], params[('r0', 'NiPt')], params[('cut_a', 'NiPt')], params[('cut_b', 'NiPt')]), 'Pt': make_density( params[('xi', 'PtPt')], params[('q', 'PtPt')], params[('r0', 'PtPt')], params[('cut_a', 'PtPt')], params[('cut_b', 'PtPt')])}, latticeConstant=3.9242, latticeType='fcc')] pair_potentials = [Potential('Ni', 'Ni', make_pair_pot(params[('A', 'NiNi')], params[('p', 'NiNi')], params[('r0', 'NiNi')], params[('cut_a', 'NiNi')], params[('cut_b', 'NiNi')])), Potential('Ni', 'Pt', make_pair_pot(params[('A', 'NiPt')], params[('p', 'NiPt')], params[('r0', 'NiPt')], params[('cut_a', 'NiPt')], params[('cut_b', 'NiPt')])), Potential('Pt', 'Pt', make_pair_pot(params[('A', 'PtPt')], params[('p', 'PtPt')], params[('r0', 'PtPt')], params[('cut_a', 'PtPt')], params[('cut_b', 'PtPt')]))] # Number of grid points and cut-offs for tabulation. cutoff_rho = 100.0 nrho = 10000 cutoff = 6.0 nr = 10000 tabulation = SetFL_FS_EAMTabulation( pair_potentials, eam_potentials, cutoff, nr, cutoff_rho, nrho) with open("NiPt.eam.fs", "w") as outfile: tabulation.write(outfile)
def tabulate(self, filename, atomic_numbers, atomic_masses, lattice_constants=dict(), lattice_types=dict(), cutoff_rho=120.0, nrho=10000, cutoff=6.2, nr=10000): """ Uses the atsim module to tabulate the potential for use in LAMMPS or similar programs. filename: str path of the output file. Note that the extension .eam.fs is added atomic_numbers: dict containing the atomic_numbers of all self.atom_types atomic_masses: dict containing the atomic mass of all self.atom_types """ from atsim.potentials import EAMPotential, Potential from atsim.potentials.eam_tabulation import SetFL_FS_EAMTabulation warnings.warn('Long range behavior of the tabulated potentials differs' ' from the tensorflow implementation!') def pair_wrapper(fun): def wrapped_fun(x): return 2 * fun(tf.reshape(x, (1, 1))) return wrapped_fun def rho_wrapper(fun): def wrapped_fun(x): return tf.math.square(fun(tf.reshape(x, (1, 1)))) return wrapped_fun def F_wrapper(fun): def wrapped_fun(x): return fun(tf.reshape(x, (1, 1))) return wrapped_fun pair_potentials = [] pair_densities = {t: {} for t in self.atom_types} for (t1, t2) in combinations_with_replacement(self.atom_types, 2): pair_type = ''.join([t1, t2]) def pair_pot(x): return self.pair_potentials[pair_type](tf.reshape(x, (1, 1))) pair_potentials.append( Potential( t1, t2, pair_wrapper(self.pair_potentials[pair_type]) #lambda x: self.pair_potentials[pair_type]( # x*tf.ones((1, 1))) )) pair_densities[t1][t2] = rho_wrapper(self.pair_rho[pair_type]) pair_densities[t2][t1] = rho_wrapper(self.pair_rho[pair_type]) eam_potentials = [] for t in self.atom_types: eam_potentials.append( EAMPotential(t, atomic_numbers[t], atomic_masses[t], F_wrapper(self.embedding_functions[t]), pair_densities[t], latticeConstant=lattice_constants.get(t, 0.0), latticeType=lattice_types.get(t, 'fcc'))) tabulation = SetFL_FS_EAMTabulation(pair_potentials, eam_potentials, cutoff, nr, cutoff_rho, nrho) with open(''.join([filename, '.eam.fs']), 'w') as outfile: tabulation.write(outfile)
def testExampleA_Pair(self): """Test pair-potentials correctly defined for EAM tabulation documentation example 2a""" exampleModule = _loadModule(self.test_nameA) shutil.copyfile( os.path.join(_getLAMMPSResourceDirectory(), "setfl_pair.lmpstruct"), os.path.join(self.tempdir, "structure.lmpstruct")) shutil.copyfile( os.path.join(_getLAMMPSResourceDirectory(), "calc_energy.lmpin"), os.path.join(self.tempdir, "calc_energy.lmpin")) inputExpect = [ (1.24246478E-02, "Al Al"), # Al Al (-0.121863537, "Al Cu"), # Al Cu (-0.179150283, "Cu Cu") # Cu Cu ] oldpwd = os.getcwd() os.chdir(self.tempdir) try: _eampotentials, pairPotentials = exampleModule.makePotentialObjects( ) eamPotentials = None # Create EAMPotential def density(r): return 0.0 def embed(rho): return 0.0 eamPotentials = [ EAMPotential("Cu", 29, 63.55, embed, density), EAMPotential("Al", 13, 26.98, embed, density) ] nrho = 50000 drho = 0.001 nr = 12000 dr = 0.001 from atsim.potentials import writeSetFL with open("table.set", 'w') as outfile: writeSetFL(nrho, drho, nr, dr, eamPotentials, pairPotentials, comments=['Zhou Al Cu', "", ""], out=outfile) for expect, potmap in inputExpect: with open("potentials.lmpinc", "w") as potfile: potfile.write("pair_style eam/alloy\n") potfile.write("pair_coeff * * table.set " + potmap + "\n") runLAMMPS() energy = extractLAMMPSEnergy() self.assertAlmostEqual(expect, energy, msg=potmap) finally: os.chdir(oldpwd)