def makeLens(this, r0, d, h, direction = [1, 0, 0], invert = False, simulation = -1):
		length = this.stateNumbers[simulation];
		lastSim = this.simulations[simulation];
		splitted = this.splitted[simulation];
		path = this.path;
		simNumber = len(this.splitted) - 1;
		if(splitted):
			mdf.combine(lastSim, length, states = "last");
		#end
		loadfile = lastSim + "/%05d/combined.xyz"%length;
		newPath = path + "/" + str(simNumber + 1) + "_lens";
		#Creating new directories and data
		if(not os.path.exists(newPath + "/init")):
			os.makedirs(newPath + "/init");
		#end
		datafilename = newPath + "/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("0\n0\n");
		#Creating directory to hold xyz files
		directory = newPath + "/00000";
		this.resetRun(directory);
		os.makedirs(directory);
		savefile = directory + "/combined.xyz";
		N = mdm.makeLens(loadfile, savefile, r0, h, d, this.s, direction, invert);
		datafile.write(str(N) + "\n");
		datafile.close();
		mdf.split(newPath, this.p, this.s, source = newPath + "/00000/combined.xyz");
		this.simulations.append(newPath);
		this.stateNumbers.append(0);
		this.splitted.append(True);
		return simNumber + 1;
	def radialDistribution(this, bins, simulation = -1, states = "all", label = ''):
		print "Calculating radial distribution";
		simPath = this.simulations[simulation];
		length = this.stateNumbers[simulation];
		mdf.combine(simPath, length, );
		r, g = mda.calculateRadialDistribution(simPath, bins, length, states);
		mdplot.plotRadialDistribution(this.path, g, r, label = label);
		return r, g;
	def angularDistribution(this, bins, states = "all", simulation = -1, label = ''):
		print "Calculating angular distribution";
		length = this.stateNumbers[simulation];
		runName = this.simulations[simulation];
		mdf.combine(runName, length);
		angle, angleDistribution = mda.angularDistribution(bins, runName, length, states);
		mdplot.plotAngularDistribution(this.path, angleDistribution, angle*180/np.pi, label = label);
		return angle, angleDistribution;
	def makeInitState(this, path, state, dest):
		mdf.combine(path, state, states = "last");
		splitDir = path + "/%05d"%state;
		#Removes all files in directory before recreating
		shutil.rmtree(dest);
		os.makedirs(dest);
		mdf.split(path, this.p, this.s, dest, splitDir + "/combined.xyz");
		#Get number of particles from datafile
		datafile = open(path + "/init/data.dat");
		lines = [l for l in datafile];
		N = int(lines[4]);
		return N;
Ejemplo n.º 5
0
	def selectBox(this, r0, r1, simulation = -1, types = "all"):
		splitted = this.splitted[simulation];
		length = this.stateNumbers[simulation];
		lastSim = this.simulations[simulation];
		if(splitted):
			mdf.combine(lastSim, length, states = "last");
		#end
		markFile = lastSim + "/init/mark_%d.dat"%this.selections;
		this.selections += 1;
		filename = lastSim + "/%05d/combined.xyz"%length;
		mdm.selectBox(filename, markFile, r0, r1, types);
		return this.selections - 1;
Ejemplo n.º 6
0
	def angularDistribution(this, bins, states = "all", simulation = -1, label = ''):
		print "Calculating angular distribution";
		length = this.stateNumbers[simulation];
		runName = this.simulations[simulation];
		mdf.combine(runName, length);
		angle, angleDistribution = mda.angularDistribution(bins, runName, length, states);
		
		datadirname = this.path + "/data/";
		if(not os.path.exists(datadirname)):
			os.makedirs(datadirname);
		#end
		
		np.save(datadirname + "/angle" + label + ".npy", angle);
		np.save(datadirname + "/angleData" + label + ".npy", angleDistribution);
		
		# mdplot.plotAngularDistribution(this.path, angleDistribution, angle*180/np.pi, label = label);
		return angle, angleDistribution;
Ejemplo n.º 7
0
	def moveParticles(this, dr, simulation = -1):
		length = this.stateNumbers[simulation];
		lastSim = this.simulations[simulation];
		splitted = this.splitted[simulation];
		path = this.path;
		simNumber = len(this.splitted) - 1;
		if(splitted):
			mdf.combine(lastSim, length, states = "last");
		#end
		loadfile = lastSim + "/%05d/combined.xyz"%length;
		newPath = path + "/" + str(simNumber + 1) + "_displaced";
		#Creating new directories and data
		if(not os.path.exists(newPath + "/init")):
			os.makedirs(newPath + "/init");
		#end
		datafilename = newPath + "/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("0\n0\n");
		#Number of particles
		lastDatafile = open(lastSim + "/init/data.dat");
		lines = [l for l in lastDatafile];
		N = int(lines[4]);
		datafile.write(str(N) + "\n");
		lastDatafile.close();
		datafile.close();
		#Copying mark files
		initfiles = os.listdir(lastSim + "/init");
		for f in initfiles:
			if(f != "data.dat"):
				shutil.copyfile(lastSimPath + "/init/" + f, newSimPath + "/init/" + f);
			#end
		#end
		#Creating directory to hold xyz files
		directory = newPath + "/00000";
		this.resetRun(directory);
		os.makedirs(directory);
		savefile = directory + "/combined.xyz";
		mdm.moveParticles(loadfile, savefile, dr, this.s);
		mdf.split(newPath, this.p, this.s, source = newPath + "/00000/combined.xyz");
		this.simulations.append(newPath);
		this.stateNumbers.append(0);
		this.splitted.append(True);
		return simNumber + 1;
Ejemplo n.º 8
0
	def radialDistribution(this, bins, simulation = -1, states = "all", label = ''):
		print "Calculating radial distribution";
		simPath = this.simulations[simulation];
		length = this.stateNumbers[simulation];
		mdf.combine(simPath, length, );
		r, g = mda.calculateRadialDistribution(simPath, bins, length, states);
		
		
		datadirname = this.path + "/data/";
		if(not os.path.exists(datadirname)):
			os.makedirs(datadirname);
		#end
		
		np.save(datadirname + "/radial" + label + ".npy", r);
		np.save(datadirname + "/radialData" + label + ".npy", g);
		
		# mdplot.plotRadialDistribution(this.path, g, r, label = label);
		return r, g;
	def freeze(this, r1, r2, v = [0, 0, 0], types = "all", simulation = -1):
		if(types == "all"):
			types = [0, 1, 2];
		elif(types == "Si"):
			types = [0];
		elif(types == "O"):
			types = [1];
		elif(types == "H"):
			types = [2];
		#end
		splitted = this.splitted[simulation];
		length = this.stateNumbers[simulation];
		lastSim = this.simulations[simulation];
		if(splitted):
			mdf.combine(lastSim, length, states = "last");
		#end
		filename = lastSim + "/%05d/combined.xyz"%length;
		markFilename = lastSim + "/init/mark.dat";
		mdm.freeze(filename, markFilename, r1, r2, v, types);
Ejemplo n.º 10
0
	def displaceCylindrical(this, R, direction, simulation = -1):
		length = this.stateNumbers[simulation];
		lastSim = this.simulations[simulation];
		splitted = this.splitted[simulation];
		path = this.path;
		simNumber = len(this.splitted) - 1;
		if(splitted):
			mdf.combine(lastSim, length, states = "last");
		#end
		loadfile = lastSim + "/%05d/combined.xyz"%length;
		newPath = path + "/" + str(simNumber + 1) + "_cylindricallyDisplaced";
		#Creating new directories and data
		this.resetRun(newPath);
		os.makedirs(newPath + "/00000");
		os.makedirs(newPath + "/init");
		#Creatign data file
		datafilename = newPath + "/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("0\n0\n");
		lastDatafile = open(lastSim + "/init/data.dat");
		lines = [l for l in lastDatafile];
		N = int(lines[4]);
		datafile.write(str(N) + "\n");
		lastDatafile.close();
		datafile.close();
		#Copying mark files
		initfiles = os.listdir(lastSim + "/init");
		for i in range(len(initfiles)):
			if(initfiles[i][0:4] == "mark"):
				shutil.copyfile(lastSim + "/init/" + initfiles[i], newPath + "/init/" + initfiles[i]);
			#end
		#end
		#Displacing particles
		mdm.displaceCylindrical(lastSim, newPath, R, direction)
		mdf.split(newPath, this.p, this.s, source = newPath + "/00000/combined.xyz");
		this.simulations.append(newPath);
		this.stateNumbers.append(0);
		this.splitted.append(True);
		return simNumber + 1;
	def combine(this, simulation1, simulation2):
		path = this.path;
		simNumber = len(this.splitted) - 1;
		
		length1 = this.stateNumbers[simulation1];
		lastSim1 = this.simulations[simulation1];
		splitted1 = this.splitted[simulation1];
		length2 = this.stateNumbers[simulation2];
		lastSim2 = this.simulations[simulation2];
		splitted2 = this.splitted[simulation2];
		if(splitted1):
			mdf.combine(lastSim1, length1, states = "last");
		#end
		if(splitted2):
			mdf.combine(lastSim2, length2, states = "last");
		#end
		loadfile1 = lastSim1 + "/%05d/combined.xyz"%length1;
		loadfile2 = lastSim2 + "/%05d/combined.xyz"%length2;
		
		newPath = path + "/" + str(simNumber + 1) + "_combined";
		#Creating new directories and data
		if(not os.path.exists(newPath + "/init")):
			os.makedirs(newPath + "/init");
		#end
		datafilename = newPath + "/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("0\n0\n");
		#Number of particles
		lastDatafile = open(lastSim1 + "/init/data.dat");
		lines = [l for l in lastDatafile];
		N1 = int(lines[4]);
		lastDatafile.close();
		lastDatafile = open(lastSim2 + "/init/data.dat");
		lines = [l for l in lastDatafile];
		N2 = int(lines[4]);
		lastDatafile.close();
		datafile.write(str(N1 + N2) + "\n");
		datafile.close();
		#Creating directory to hold xyz files
		directory = newPath + "/00000";
		this.resetRun(directory);
		os.makedirs(directory);
		savefile = directory + "/combined.xyz";
		markFile1 = lastSim1 + "/init/mark.dat";
		markFile2 = lastSim2 + "/init/mark.dat";
		markFileSave = newPath + "/init/mark.dat";
		mdm.combine(loadfile1, loadfile2, savefile, markFile1, markFile2, markFileSave);
		mdf.split(newPath, this.p, this.s, source = newPath + "/00000/combined.xyz");
		this.simulations.append(newPath);
		this.stateNumbers.append(0);
		this.splitted.append(True);
		return simNumber + 1;
Ejemplo n.º 12
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;
Ejemplo n.º 13
0
	def combine(this, simulation1, simulation2):
		path = this.path;
		simNumber = len(this.splitted) - 1;
		
		length1 = this.stateNumbers[simulation1];
		lastSim1 = this.simulations[simulation1];
		splitted1 = this.splitted[simulation1];
		length2 = this.stateNumbers[simulation2];
		lastSim2 = this.simulations[simulation2];
		splitted2 = this.splitted[simulation2];
		if(splitted1):
			mdf.combine(lastSim1, length1, states = "last");
		#end
		if(splitted2):
			mdf.combine(lastSim2, length2, states = "last");
		#end
		newPath = path + "/" + str(simNumber + 1) + "_combined";
		#Creating new directories and data
		this.resetRun(newPath);
		os.makedirs(newPath + "/init");
		
		#Creating datafile
		datafilename = newPath + "/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("0\n0\n");
		#Number of particles
		lastDatafile = open(lastSim1 + "/init/data.dat");
		lines = [l for l in lastDatafile];
		N1 = int(lines[4]);
		lastDatafile.close();
		lastDatafile = open(lastSim2 + "/init/data.dat");
		lines = [l for l in lastDatafile];
		N2 = int(lines[4]);
		lastDatafile.close();
		datafile.write(str(N1 + N2) + "\n");
		datafile.close();
		
		#Combining files and splitting xyz file
		mdm.combine(lastSim1, lastSim2, newPath);
		mdf.split(newPath, this.p, this.s, source = newPath + "/00000/combined.xyz");
		this.simulations.append(newPath);
		this.stateNumbers.append(0);
		this.splitted.append(True);
		return simNumber + 1;
	def makeVmdData(this, simulation = -1):
		print "Making vmd input files";
		path = this.simulations[simulation];
		length = this.stateNumbers[simulation];
		mdf.makeVmdData(path, length);
		mdf.combine(path, length);
Ejemplo n.º 15
0
	def makeVmdData(this, simulation = -1, processors = "all"):
		path = this.simulations[simulation];
		length = this.stateNumbers[simulation];
		mdf.makeVmdData(path, length);
		mdf.combine(path, length, processors = processors);