Ejemplo n.º 1
0
	def thermalize(this, length, dt, tau, avglength, timesteps, combine = False, resume = -1):
		#Berendsen thermostat
		lastSimPath = this.simulations[resume];
		lastState = this.stateNumbers[resume];
		lastSim = len(this.simulations) - 1;
		T = this.T;
		path = this.path
		if(path == ""):
			print "A save directory is needed to run simulation";
			print "Use setDir(<dirName>) to set a save directory";
			return;
		#end
		#Creating path of new simulation
		newSimPath = path + "/" + str(lastSim + 1) + "_thermalization";
		#Copy old datafile to new location
		if(lastSim == -1):
			print "A initial state is needed for simulation";
			return;
		#end
		
		#Creating new directories and copy data
		mdf.makeDirs(length, newSimPath, reset = True);
		N = this.makeInitState(lastSimPath, lastState, newSimPath + "/00000");
		os.makedirs(newSimPath + "/init");
		datafilename = newSimPath + "/init/data.dat"
		datafile = open(datafilename, 'w');
		datafile.write(str(this.p[0]) + " " + str(this.p[1]) + " " + str(this.p[2]) + "\n");
		datafile.write(str(this.s[0]) + " " + str(this.s[1]) + " " + str(this.s[2]) + "\n");
		datafile.write(str(dt) + "\n");
		datafile.write(str(timesteps) + "\n");
		datafile.write(str(int(N)) + "\n");
		datafile.close();
		#Copy all other files in init directory
		initfiles = os.listdir(lastSimPath + "/init");
		for f in initfiles:
			if(f != "data.dat"):
				shutil.copyfile(lastSimPath + "/init/" + f, newSimPath + "/init/" + f);
			#end
		#end
		
		mds.thermalize(length, dt, tau, T, avglength, newSimPath, timesteps = timesteps);
		
		if(combine):
			print "Combining files";
			mdf.combine(length, newSimPath);
			print "Sorting files";
			mdf.sortStates(length, newSimPath);
		#end
		this.simulations.append(newSimPath);
		this.stateNumbers.append(length);
		this.splitted.append(True);
		return lastSim + 1;