def testWriteSetFL(self): """Test creation of DYNAMO setfl formatted file for use with lammps pair_style eam/alloy""" with open( os.path.join(_getResourceDirectory(), 'AlCu.eam.alloy'), 'r') as infile: expectEAMTable = _parseSetFL(infile) comments = [ '##Al-Cu EAM potentials from J. Cai and Y.Y. Ye##', '##Phys. Rev. B 54, 8398-8410 (1996).############', '################################################'] alEmbedFunc = TableReader(_openResource('setfl_AlEmbed.table')) alElectronDensity = TableReader(_openResource('setfl_AlDensity.table')) cuEmbedFunc = TableReader(_openResource('setfl_CuEmbed.table')) cuElectronDensity = TableReader(_openResource('setfl_CuDensity.table')) pairpot_Al_Al = TableReader(_openResource('setfl_AlAlPair.table')) pairpot_Cu_Al = TableReader(_openResource('setfl_CuAlPair.table')) pairpot_Cu_Cu = TableReader(_openResource('setfl_CuCuPair.table')) eampots = [ potentials.EAMPotential('Al', 13, 26.982, alEmbedFunc, alElectronDensity, latticeConstant = 4.05, latticeType = 'FCC'), potentials.EAMPotential('Cu', 29, 63.546, cuEmbedFunc, cuElectronDensity, latticeConstant = 3.615, latticeType = 'FCC')] pairpots = [ Potential('Al', 'Al', pairpot_Al_Al), Potential('Cu', 'Al', pairpot_Cu_Al), Potential('Cu', 'Cu', pairpot_Cu_Cu) ] nrho = 1000 drho = 1.0396723078e+00 nr = 3000 dr = 2.2282427476e-03 cutoff = 6.6825000000e+00 actualEAMTable = StringIO() potentials.writeSetFL( nrho, drho, nr, dr, eampots, pairpots, comments = comments, out = actualEAMTable, cutoff = cutoff) actualEAMTable.seek(0) actualEAMTable = _parseSetFL(actualEAMTable) from . import testutil testutil.compareCollection(self,expectEAMTable, actualEAMTable, places = 3)
def testWriteEAMFile(self): """Test _writeTABEAM.writeTABEAM() function""" from io import StringIO #Define potentials ppbucku = potentials.Potential('U', 'U', _zerowrap(potentials.buck(668.546808, 0.408333, 0.0))) ppbuckuc = potentials.Potential('U', 'C', _zerowrap(potentials.buck(30.885011, 0.814952, 0.0))) ppswcc = potentials.Potential('C', 'C', _zerowrap(_stillingerWeber(1.1, 2.078, 1.368, 2.5257))) densU = _densityFunction( 1.301894, 2.0, 0.668659, 1.862363, 2.0) densC = _densityFunction(33.446287, 2.0, 1.318078, 1.512686, 2.0) UEAMPot = potentials.EAMPotential('U', 92, 19.05, embeddingFunction, densU ) CEAMPot = potentials.EAMPotential('C', 6, 2.267,embeddingFunction, densC ) maxrho = 410.0 cutoff = 12.0 drho = dr = 0.01 nrho = int(maxrho // drho) nr = int(cutoff // dr) outfile = StringIO() _dlpoly_writeTABEAM.writeTABEAM( nrho, drho, nr, dr, [UEAMPot, CEAMPot], [ppbucku, ppbuckuc, ppswcc], outfile, "Chartier/Van Brutzel Potentials") outfile = StringIO(outfile.getvalue()) #Check structure of the file self.assertEqual(2, self._countSections(outfile, 'embe')) self.assertEqual(2, self._countSections(outfile, 'dens')) self.assertEqual(3, self._countSections(outfile, 'pair'))
def testWriteSetFLFinnisSinclair_PairPotentialOrder(self): """Check that pair potentials are written in the correct order""" nrho = 5 drho = 0.1 nr = 5 dr = 0.1 cutoff = 0.5 import collections def defaultdens(): return lambda x: 0.0 defaultdict = collections.defaultdict(defaultdens) eampot1 =potentials.EAMPotential('A', 1, 1.0, lambda x: 0.1, defaultdict) eampot2 =potentials.EAMPotential('B', 2, 2.0, lambda x: 0.2, defaultdict) eampot3 =potentials.EAMPotential('C', 3, 3.0, lambda x: 0.3, defaultdict) pairpot_aa =potentials.Potential('A', 'A', lambda r: 1.0) pairpot_bb =potentials.Potential('B', 'B', lambda r: 2.0) pairpot_cc =potentials.Potential('C', 'C', lambda r: 3.0) pairpot_ba =potentials.Potential('B', 'A', lambda r: 5.0) pairpot_ac =potentials.Potential('A', 'C', lambda r: 6.0) pairpot_bc =potentials.Potential('B', 'C', lambda r: 7.0) # Define two species sio = StringIO() potentials.writeSetFLFinnisSinclair( nrho, drho, nr, dr, [eampot2, eampot1], [pairpot_bb, pairpot_aa, pairpot_ba], comments = ['Comment1', 'Comment2', 'Comment3'], out = sio, cutoff = cutoff) rvals = [0.0, 0.1, 0.2, 0.3, 0.4] expect = [ r * pairpot_bb.energy(r) for r in rvals] expect.extend([ r * pairpot_ba.energy(r) for r in rvals]) expect.extend([ r * pairpot_aa.energy(r) for r in rvals]) sio.seek(0) actual = sio.readlines() actual = actual[37:] actual = [float(v) for v in actual] from . import testutil testutil.compareCollection(self,expect, actual) # Try a ternary system # Define two species sio = StringIO() potentials.writeSetFLFinnisSinclair( nrho, drho, nr, dr, [eampot2, eampot1, eampot3], [pairpot_bb, pairpot_aa, pairpot_ba, pairpot_cc, pairpot_ac, pairpot_bc], sio, ['Comment1', 'Comment2', 'Comment3'], cutoff) rvals = [0.0, 0.1, 0.2, 0.3, 0.4] expect = [ r * pairpot_bb.energy(r) for r in rvals] expect.extend([ r * pairpot_ba.energy(r) for r in rvals]) expect.extend([ r * pairpot_aa.energy(r) for r in rvals]) expect.extend([ r * pairpot_bc.energy(r) for r in rvals]) expect.extend([ r * pairpot_ac.energy(r) for r in rvals]) expect.extend([ r * pairpot_cc.energy(r) for r in rvals]) sio.seek(0) actual = sio.readlines() actual = actual[68:] actual = [float(v) for v in actual] testutil.compareCollection(self,expect, actual)
def testWriteSetFLFinnisSinclair(self): """Test that lammps.potentials.writeSetFLFinnisSinclair() (suitable for use with pair_style eam/fs) can re-create AlFe_mm.eam.fs file from lammps distribution""" #Open the expected output with _openResource('AlFe_mm.eam.fs') as infile: expectEAMTable = _parseSetFL(infile, finnisSinclair = True) #Set-up tabulation of the actual EAM table from parameters found in #M.I. Mendelev, D.J. Srolovitz, G.J. Ackland and S. Han, J. Mater. Res. 20, 208-218 (2005). comments = [ "Sourse: M.I. Mendelev, D.J. Srolovitz, G.J. Ackland and S. Han, J. Mater. Res. 20, 208-218 (2005).", "Contact information: [email protected]", "Sunday, Jun 10, 2007 The potential was taken from Al3Fe_D03 (in C:\\SIMULATION.MD\\Al-Fe\\T=0)" ] #Embedding functions from ._eam_fs_AlFe import alEmbedFunction from ._eam_fs_AlFe import feEmbedFunction #Density functions from ._eam_fs_AlFe import alAlDensFunction from ._eam_fs_AlFe import feFeDensFunction from ._eam_fs_AlFe import feAlDensFunction # Pair potentials from ._eam_fs_AlFe import ppfuncAlAl from ._eam_fs_AlFe import ppfuncAlFe from ._eam_fs_AlFe import ppfuncFeFe class ErrorPotential(potentials.Potential): def energy(self, r): #There seems to be an error in the way that the lammps potential is tabulated (there is a step function at the start of each pair potential" #the following if statement has been introduced to reproduce this error and allow the test to pass if r <= 0.500: if r != 0.0: return 1e12/r else: return 1e12 return potentials.Potential.energy(self, r) pairpots = [ ErrorPotential('Al', 'Al', ppfuncAlAl), ErrorPotential('Al', 'Fe', ppfuncAlFe), ErrorPotential('Fe', 'Fe', ppfuncFeFe)] #Other parameters nrho = 10000 drho = 3.00000000000000E-0002 nr = 10000 dr = 6.50000000000000E-0004 cutoff = 6.5 #Assemble the EAMPotential objects eampots = [ #Al potentials.EAMPotential('Al', 13, 26.98154, alEmbedFunction, { 'Al' : alAlDensFunction, 'Fe' : feAlDensFunction }, latticeConstant = 4.04527, latticeType = 'fcc'), #Fe potentials.EAMPotential('Fe', 26, 55.845, feEmbedFunction, { 'Al': feAlDensFunction, 'Fe' : feFeDensFunction}, latticeConstant = 2.855312, latticeType = 'bcc') ] #Now actually generate the actual tabulated potential actualEAMTable = StringIO() potentials.writeSetFLFinnisSinclair( nrho, drho, nr, dr, eampots, pairpots, comments = comments, out = actualEAMTable, cutoff = cutoff) actualEAMTable = StringIO(actualEAMTable.getvalue()) actualEAMTable.seek(0) actualEAMTable = _parseSetFL(actualEAMTable, finnisSinclair = True) from . import testutil testutil.compareCollection(self,expectEAMTable, actualEAMTable, places = 3, percenttolerance = 7.0)
def testWriteSetFLFromParameters(self): """Test that lammps.potentials.writeSetFL() can generate the Al_zhou.eam.alloy file from LAMMPS distribution""" with open(os.path.join(_getResourceDirectory(), 'Al_zhou.eam.alloy'), 'r') as infile: expectEAMTable = _parseSetFL(infile) comments = [ '#-> LAMMPS Potential File in DYNAMO 86 setfl Format <-#', '# Zhou Al Acta mater(2001)49:4005', '# Implemented by G. Ziegenhain (2007) [email protected]'] #Density function def densityFunction(r): beta = 3.702623 r_e = 2.886166 lamb = 0.790264 f_e = 1.392302 num = f_e * math.exp( -beta * ( (r/r_e) - 1.0) ) den = 1.0 + (( (r/r_e) - lamb )**20) return num/den #Embedding function def subembed(i, F_ni, rho_n, rho): return F_ni * ((rho/rho_n) - 1.0)**float(i) def embeddingFunction(rho): rho_e = 20.226537 rho_n = 0.85 * rho_e rho_o = 1.15 * rho_e nu = 0.779208 if rho < rho_n: return subembed(0, -2.806783, rho_n, rho) + \ subembed(1, -0.276173, rho_n, rho) + \ subembed(2, 0.893409, rho_n, rho) + \ subembed(3, -1.637201, rho_n, rho) elif rho_n <= rho < rho_o: return subembed(0, -2.806783, rho_e, rho) + \ subembed(1, -0.276173, rho_e, rho) + \ subembed(2, 0.893409, rho_e, rho) + \ subembed(3, -1.637201, rho_e, rho) else: return -2.829437 * ( 1.0 - math.log( (rho/rho_e)**nu)) * (rho/rho_e)**nu #Pair potential def ppotfunc(r): A = 0.251519 alpha = 6.94219 r_e = 2.886166 kappa = 0.395132 B = 0.313394 beta = 3.702623 lamb = 0.790264 return ((A * math.exp( -alpha* ( (r/r_e) - 1.0) ))/ (1.0 + ( (r/r_e - kappa)**20))) - \ ((B * math.exp( -beta * ( (r/r_e) - 1.0) ))/ (1.0 + ( (r/r_e - lamb)**20))) alpp = potentials.Potential('Al', 'Al', ppotfunc) nrho = 10001 drho = 0.00559521603477821424 nr = 10001 dr = 0.00101014898510148996 cutoff = 10.10250000000000092371 eampots = [ potentials.EAMPotential('Al', 1, 26.982, embeddingFunction, densityFunction, latticeConstant = 4.05, latticeType = 'FCC')] pairpots = [ alpp ] actualEAMTable = StringIO() potentials.writeSetFL( nrho, drho, nr, dr, eampots, pairpots, comments = comments, out = actualEAMTable, cutoff = cutoff ) actualEAMTable.seek(0) actualEAMTable = _parseSetFL(actualEAMTable) from . import testutil testutil.compareCollection(self,expectEAMTable, actualEAMTable, places = 3, percenttolerance = 7.0)
def testFluorite_NoPair(self): """Test EAM Tabulation using pair potentials for a fluorite structure""" shutil.copyfile( os.path.join(_getResourceDirectory(), 'calc_energy.lmpin'), os.path.join(self.tempdir, 'calc_energy.lmpin')) shutil.copyfile( os.path.join(_getResourceDirectory(), 'CeO2-single_cell.lmpstruct'), os.path.join(self.tempdir, 'structure.lmpstruct')) oldpwd = os.getcwd() os.chdir(self.tempdir) try: with open("potentials.lmpinc", "w") as potfile: potfile.write("pair_style eam/fs\n") potfile.write("pair_coeff * * eam.fs O Ce\n") potfile.write("\n") potfile.write("replicate 4 4 4\n") # Now define potentials def erf(x): # save the sign of x sign = 1 if x >= 0 else -1 x = abs(x) # constants a1 = 0.254829592 a2 = -0.284496736 a3 = 1.421413741 a4 = -1.453152027 a5 = 1.061405429 p = 0.3275911 # A&S formula 7.1.26 t = 1.0/(1.0 + p*x) y = 1.0 - (((((a5*t + a4)*t) + a3)*t + a2)*t + a1)*t*math.exp(-x*x) return sign*y # erf(-x) = -erf(x) def morse(gamma, r_star, D): def f(r): return D*(math.exp(-2.0*gamma*(r-r_star)) - 2.0*math.exp(-gamma*(r-r_star))) return f def zw(origfunc): def f(r): if r == 0.0: return 0.0 return origfunc(r) return f def zeropot(r): return 0.0 def embedCe(d): return -0.30766574471*(d**0.5) def embedO(d): return -0.690017059438*(d**0.5) def densityCe(r): m=8 a=1556.80263774 #tmpa #55,100//0.00002,0.0001 return (a/(r**m))*0.5*(1+erf(20*(r-1.5))) def densityO(r): m=8 a=106.855913747 #tmpa #55,100//0.00002,0.0001 return (a/(r**m))*0.5*(1+erf(20*(r-1.5))) functionO_Ce = zw(potentials.plus(potentials.buck(351.341192796, 0.380516580733, 0.0), morse(1.86874578949, 2.35603812582, 0.719250701502))) functionO_O = zw(potentials.buck(830.283447557, 0.352856254215, 3.88437209048)) functionCe_Ce = zw(potentials.buck(18600.0, 0.26644, 0.0)) potO_O = potentials.Potential('O', 'O', functionO_O) potO_Ce = potentials.Potential('O', 'Ce', functionO_Ce) potCe_Ce = potentials.Potential('Ce', 'Ce', functionCe_Ce) eampotCe = potentials.EAMPotential('Ce', 92, 238, embedCe, {'Ce': zw(densityCe), 'O' : zw(densityO)}) eampotO = potentials.EAMPotential('O', 8, 16, embedO, {'Ce': zw(densityCe), 'O' : zw(densityO)}) eampots = [eampotCe, eampotO] pairpots = [potO_O, potO_Ce, potCe_Ce] drho = 0.001 nrho = int(100.0 // drho) cutoff = 11.0 dr = 0.01 nr = int(cutoff // dr) with open('eam.fs', 'w') as outfile: potentials.writeSetFLFinnisSinclair( nrho, drho, nr, dr, eampots, [], outfile, ["Yakub potential. Zero embed and density", "",""], cutoff) runLAMMPS() energy = extractLAMMPSEnergy() expect = -1001.27446044 self.assertAlmostEqual(expect, energy, places=5) finally: os.chdir(oldpwd)
def setUp(self): super(DLPOLYWriteTABEAMTestCase_RunDLPoly, self).setUp() shutil.copyfile(os.path.join(_getResourceDirectory(), 'CONTROL_CeO2'), os.path.join(self.tempdir, 'CONTROL')) shutil.copyfile(os.path.join(_getResourceDirectory(), 'CONFIG_CeO2'), os.path.join(self.tempdir, 'CONFIG')) shutil.copyfile(os.path.join(_getResourceDirectory(), 'FIELD_CeO2'), os.path.join(self.tempdir, 'FIELD')) # Now define potentials def erf(x): # save the sign of x sign = 1 if x >= 0 else -1 x = abs(x) # constants a1 = 0.254829592 a2 = -0.284496736 a3 = 1.421413741 a4 = -1.453152027 a5 = 1.061405429 p = 0.3275911 # A&S formula 7.1.26 t = 1.0/(1.0 + p*x) y = 1.0 - (((((a5*t + a4)*t) + a3)*t + a2)*t + a1)*t*math.exp(-x*x) return sign*y # erf(-x) = -erf(x) def morse(gamma, r_star, D): def f(r): return D*(math.exp(-2.0*gamma*(r-r_star)) - 2.0*math.exp(-gamma*(r-r_star))) return f def zw(origfunc): def f(r): if r == 0.0: return 0.0 return origfunc(r) return f def zeropot(r): return 0.0 def embedCe(d): return -0.30766574471*(d**0.5) def embedO(d): return -0.690017059438*(d**0.5) def densityCe(r): m=8 a=1556.80263774 #tmpa #55,100//0.00002,0.0001 return (a/(r**m))#*0.5*(1+erf(20*(r-1.5))) def densityO(r): m=8 a=106.855913747 #tmpa #55,100//0.00002,0.0001 return (a/(r**m))#*0.5*(1+erf(20*(r-1.5))) functionO_Ce = zw(potentials.plus(potentials.buck(351.341192796, 0.380516580733, 0.0), morse(1.86874578949, 2.35603812582, 0.719250701502))) functionO_O = zw(potentials.buck(830.283447557, 0.352856254215, 3.88437209048)) functionCe_Ce = zw(potentials.buck(18600.0, 0.26644, 0.0)) potO_O = potentials.Potential('O', 'O', functionO_O) potO_Ce = potentials.Potential('O', 'Ce', functionO_Ce) potCe_Ce = potentials.Potential('Ce', 'Ce', functionCe_Ce) eampotCe = potentials.EAMPotential('Ce', 92, 238, embedCe, zw(densityCe)) eampotO = potentials.EAMPotential('O', 8, 16, embedO, zw(densityO)) self.eampots = [eampotCe, eampotO] self.pairpots = [potO_O, potO_Ce, potCe_Ce]