欢迎来到天天文库
浏览记录
ID:41385911
大小:114.63 KB
页数:4页
时间:2019-08-23
《一维分子动力学模拟python代码》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、1#!/usr/bin/envpython323#Moleculardynamicsin1D45#importneededmodules6importrandom7importmath8importsys910#themainloopfunction11defmain(md):12time=0.0#initialisetime1314#opencoordinateoutputfiles15cfile=open("coords.xyz","w")16#opentemperatureoutputfile17tfile=open("temperature.dat","w")18tf
2、ile.write("#timetemperature")19#openenergyoutputfile20efile=open("energy.dat","w")21efile.write("#timeenergy")2223#mainMDloop24fortinrange(md.tsteps):25print("#----Time=",round(time,2),"----Steps=",t,"----")#python326en=md.force()#calculateforces27md.integrate(t,en)#integrateequationsof
3、motion28#printcurrentcoordinatestofile29md.printcoords(time,cfile)30#printcurrenttemperaturetofile31tfile.write(str(round(time,2))+""+str(md.temp)+"")32#printcurrentenergytofile33efile.write(str(round(time,2))+""+str(md.etot)+"")3435time+=md.dt#increasetimebydt3637md.statistics(tfile,ef
4、ile)#calculateaverages,SD,etc3839#closeoutputfiles40cfile.close()41tfile.close()42efile.close()4344classMD(object):4546N=36#numberofparticles(integerforloopcontrol)47dN=36.0#numberofparticles(doublefordoingmaths)48L=36.0#lengthof1Dbox49dim=1.0#dimensions50#initialisepositionsandvelocites51d
5、ef__init__(self):5253#declaretheglobalvariables54#constants55self.a=self.L/self.dN#latticespacing56self.dtsteps=100.0#numberoftimesteps(doubleformath)57self.tsteps=int(self.dtsteps)#numberoftimesteps(integerforcounting)58self.dt=0.01#integrationtimestep59self.rc=18.0#distancecutoffforcomput
6、ingLJinteractions60self.rc2=self.rc**2#distancecutoffsquared61self.ecut=4.0*((self.rc**-12)-(self.rc**-6))#valueofLJpotentialatr=rc:4(1/rc^{12}-1/rc^{6})6263#valuesthatchangeduringthesimulation64self.en=0.0#potentialenergy65self.etot=0.0#totalenergy(pot+kin)66self.temp=0.728#temperature6768
7、#listsforstoringstuff69self.x=[]#coordinates70self.xp=[]#previouscoordinates71self.v=[]#velocities72self.f=[]#forces7374#storedataforaveraging75self.sumTemp=0.076self.sumEtot=0.077self.temps=[]78self.etots=[]7980#initialisetheliststobethecorrectsize81for
此文档下载收益归作者所有