Ejemplo n.º 1
0
def unweighted_COM(start_atoms,end_atoms):
	start_comx = sum(a.x for a in start_atoms)/len(start_atoms)
	start_comy = sum(a.y for a in start_atoms)/len(start_atoms)
	start_comz = sum(a.z for a in start_atoms)/len(start_atoms)
	
	end_comx = sum(a.x for a in end_atoms)/len(end_atoms)
	end_comy = sum(a.y for a in end_atoms)/len(end_atoms)
	end_comz = sum(a.z for a in end_atoms)/len(end_atoms)
	
	startx = [a.x-start_comx for a in start_atoms]
	starty = [a.y-start_comy for a in start_atoms]
	startz = [a.z-start_comz for a in start_atoms]

	endx = [a.x-end_comx for a in end_atoms]
	endy = [a.y-end_comy for a in end_atoms]
	endz = [a.z-end_comz for a in end_atoms]
	
	for i in range(len(start_atoms)):
		start_atoms[i].x = startx[i]
		start_atoms[i].y = starty[i]
		start_atoms[i].z = startz[i]

	start_com = np.array([[start_comx],[start_comy],[start_comz]])
	end_com = np.array([[end_comx,end_comy,end_comz]])
	filetypes.write_xyz('out',start_atoms)
	return startx,starty,startz,endx,endy,endz,start_com,end_com
def acetone_and_pbi2():
	acetone1 = gaussian.atoms('acetone')
	pbi2 = filetypes.parse_xyz('xyz/Optimized Molecules/pbi2.xyz')

	for atom in acetone1:
		atom.x = atom.x + 10
	

	atoms = acetone1+pbi2

	filetypes.write_xyz('pbi2_1acetone', atoms)
Ejemplo n.º 3
0
def weighted_COM(start_atoms,end_atoms):
	MASS_BY_TYPE = {'Pb': 207.2, 'S': 32.065, 'O': 15.9994, 'H': 1.0079, 'C': 12.0107}
# shift all structures so that origin is the COM:
	start_comx = 0.0
	start_comy = 0.0
	start_comz = 0.0
	start_mtot = 0.0
	end_comx = 0.0
	end_comy = 0.0
	end_comz = 0.0
	end_mtot = 0.0
	# calculate center of mass
	for s,e in zip(start_atoms, end_atoms):
		start_comx  += s.x*MASS_BY_TYPE[ s.element ]
		start_comy  += s.y*MASS_BY_TYPE[ s.element ]
		start_comz  += s.z*MASS_BY_TYPE[ s.element ]
		start_mtot += MASS_BY_TYPE[ s.element ]
		
		end_comx  += e.x*MASS_BY_TYPE[ e.element ]
		end_comy  += e.y*MASS_BY_TYPE[ e.element ]
		end_comz  += e.z*MASS_BY_TYPE[ e.element ]
		end_mtot += MASS_BY_TYPE[ e.element ]
		
		start_comx = start_comx/start_mtot
		start_comy = start_comy/start_mtot
		start_comz = start_comz/start_mtot
		
		end_comx = end_comx/end_mtot
		end_comy = end_comy/end_mtot
		end_comz = end_comz/end_mtot

	startx = [a.x-start_comx for a in start_atoms]
	starty = [a.y-start_comy for a in start_atoms]
	startz = [a.z-start_comz for a in start_atoms]

	endx = [a.x-end_comx for a in end_atoms]
	endy = [a.y-end_comy for a in end_atoms]
	endz = [a.z-end_comz for a in end_atoms]
	
		
	for i in range(len(start_atoms)):
		start_atoms[i].x = startx[i]
		start_atoms[i].y = starty[i]
		start_atoms[i].z = startz[i]
	
	start_com = np.array([[start_comx],[start_comy],[start_comz]])
	end_com = np.array([[end_comx,end_comy,end_comz]])
	
	filetypes.write_xyz('out',start_atoms)
	return startx,starty,startz,endx,endy,endz,start_com,end_com
Ejemplo n.º 4
0
import math, copy, sys, random, re, os, cPickle, shutil
sys.path.append("/fs/home/jms875/Library")
import gaussian, filetypes, utils

name = sys.argv[1]
if len(sys.argv) == 3:
    low = 0
    count = int(sys.argv[2])
if len(sys.argv) == 4:
    low = int(sys.argv[2])
    count = int(sys.argv[3])

f = open('out.xyz', 'w')
energies = []
for step in range(low, count):
    energy, atoms = gaussian.parse_atoms(name % step, check_convergence=False)
    filetypes.write_xyz('', atoms, f)
    print energy, int(gaussian.parse_atoms(name % step) != None)
    energies.append(energy)


def matplot(y):
    import matplotlib.pyplot as plt
    plt.plot(y, marker='.')
    plt.show()


f.close()
energies = [(e - energies[0]) * 627.5 for e in energies]
matplot(energies)
Ejemplo n.º 5
0
def run(run_name):
	utils.Molecule.set_params('oplsaa4.prm')

	tail = utils.Molecule('acrylonitrile2.arc')

	for a in tail.atoms:
		a.x, a.z = a.z, a.x-2.0
	
	atoms = []
	bonds = []
	angles = []
	dihedrals = []

	added_atoms = []
	S = 2.4
	R = 8.0
	for phi_i in range(math.pi*R/S):
		phi = S/R*0.5 + S/R*phi_i
		z = R*math.cos(phi)
		r = (R**2 - z**2)**0.5
		N_theta = int(math.pi*2*r/S)
		for theta_i in range(N_theta):
			theta = S/r + (math.pi*2)*theta_i/N_theta
			x, y = R*math.cos(theta)*math.sin(phi), R*math.sin(theta)*math.sin(phi)
		
			weighted_charge = 0.0
		
			for added in added_atoms:
				weight = 1/( (x-added.x)**2 + (y-added.y)**2 + (z-added.z)**2 )
				weighted_charge += weight*added.charge
		
			charge = 1 if weighted_charge<0 else -1
		
			added_atoms.append( utils.Struct( x=x, y=y, z=z, theta=theta, phi=phi, charge=charge ) )

	for added in added_atoms:
		x, y, z, theta, phi = added.x, added.y, added.z, added.theta, added.phi

		old_atom_positions = [(a.x, a.y, a.z) for a in tail.atoms]
		if added.charge>0:
			for a in tail.atoms:
				a.x, a.y, a.z = -a.z-7, a.y, -a.x
			c1,c2,s1,s2 = math.cos(theta),math.cos(phi+math.pi/2),math.sin(theta),math.sin(phi+math.pi/2)
			m = [ [c1*c2, -s1, c1*s2], [c2*s1, c1, s1*s2], [-s2, 0., c2] ]
			tail.rotate(m)
			tail.add_to(x, y, z, atoms, bonds, angles, dihedrals)
		else:
			for a in tail.atoms:
				a.x, a.y, a.z = -a.z-7, a.y, -a.x
			c1,c2,s1,s2 = math.cos(theta),math.cos(phi+math.pi/2),math.sin(theta),math.sin(phi+math.pi/2)
			m = [ [c1*c2, -s1, c1*s2], [c2*s1, c1, s1*s2], [-s2, 0., c2] ]
			tail.rotate(m)
			x*=0.7; y*-0.7; z*=0.7
			tail.add_to(x, y, z, atoms, bonds, angles, dihedrals)
		for i,a in enumerate(tail.atoms): a.x, a.y, a.z = old_atom_positions[i]

	box_size = [R*2+30]*3

	T = 94.0
	P = 1.45

	filetypes.write_xyz('out', atoms)
	sys.exit()

	directory = 'lammps'
	os.chdir(directory)

	atom_types = dict( [(t.type,True) for t in atoms] ).keys()
	atom_type_numbers = dict( [(t,i+1) for i,t in enumerate(atom_types)] )
	is_charged = True

	lammps.write_data_file_general(atoms, bonds, angles, dihedrals, box_size, run_name, atom_types=atom_types)
	os.system('cp ../'+sys.argv[0]+' '+run_name+'.py')

	f = open(run_name+'.in', 'w')
	f.write('units	real\natom_style	full #bonds, angles, dihedrals, impropers, charges\n')

	if is_charged:
	#	f.write('pair_style lj/cut/coul/long 8.0\n')
		f.write('pair_style lj/cut/coul/cut 8.0\n')
	else:
		f.write('pair_style lj/cut 8.0\n')
	if bonds: f.write('bond_style harmonic\n')
	if angles: f.write('angle_style harmonic\n')
	if dihedrals: f.write('dihedral_style opls\n')
	#if is_charged: f.write('kspace_style pppm 1.0e-3\n')

	f.write('special_bonds lj/coul 0.0 0.0 0.5\nread_data	'+run_name+'.data\n')

	f.write('''thermo		0
dump	1 all xyz 100 '''+run_name+'''.xyz
thermo_modify	line multi format float %14.6f
thermo 1000
minimize 0.0 1.0e-8 1000 100000
velocity all create '''+str(T)+''' 1 rot yes dist gaussian
fix dynamics all nve
fix solvent all langevin '''+str(T)+' '+str(5*T)+''' 100 1337
timestep  2.0
neigh_modify check yes every 1 delay 0
run 100
	''')
	f.close()
	if False: #start multiple processes
		os.system('nohup ~/lammps/src/lmp_g++_no_cuda -in %s.in -log %s.log &> /dev/null &' % (run_name, run_name) )
		print 'Running', run_name
	else:
		os.system('~/lammps/src/lmp_g++_no_cuda -in %s.in -log %s.log' % (run_name, run_name) )
		sys.exit()
	os.chdir('..')
Ejemplo n.º 6
0
def run(test_molecule_filename, solvent_ratio=[100,0,0]):
	utils.Molecule.set_params('../micelle/oplsaa4.prm')
	test_molecule = utils.Molecule(test_molecule_filename)
	test_molecule_name = test_molecule_filename[ test_molecule_filename.rindex('/')+1 :-4]
	if test_molecule_name[-2:] in ['e2','n2']: test_molecule_name = test_molecule_name[:-1]

	N2 = utils.Molecule('../N2.arc')
	#N2 params: http://www.sciencedirect.com/science/article/pii/002240739290142Q
	N2.atoms[0].type.vdw_r = 3.35
	N2.atoms[0].type.vdw_e = 0.0721
	#http://cccbdb.nist.gov/exp2.asp?casno=7727379
	N2.bonds[0].type.r = 1.0977

	solvents = [utils.Molecule('../micelle/methane.arc'), utils.Molecule('../ethane.arc'), copy.deepcopy(N2)]

	water_types = []

	atoms = []
	bonds = []
	angles = []
	dihedrals = []

	test_molecule.add_to(0.0, 0.0, 0.0, atoms, bonds, angles, dihedrals)

	box_size = (20,20,20)
	atom_count = len(atoms)
	solvent_amount_to_add = [ratio for ratio in solvent_ratio]
	solvent = solvents[0] #cheesy
	solvent_spacing = [(max(solvent.atoms, key=lambda a:a.x).x-min(solvent.atoms, key=lambda a:a.x).x), (max(solvent.atoms, key=lambda a:a.y).y-min(solvent.atoms, key=lambda a:a.y).y), (max(solvent.atoms, key=lambda a:a.z).z-min(solvent.atoms, key=lambda a:a.z).z)]
	max_vdw_r = max(solvent.atoms, key=lambda a:a.type.vdw_r).type.vdw_r
	solvent_spacing = [max(x,max_vdw_r) for x in solvent_spacing]

	for x in range(-box_size[0]/2+solvent_spacing[0], box_size[0]/2, solvent_spacing[0]):
		for y in range(-box_size[1]/2+solvent_spacing[1], box_size[1]/2, solvent_spacing[1]):
			for z in range(-box_size[2]/2+solvent_spacing[2], box_size[2]/2, solvent_spacing[2]):
				try:
					for a in atoms[:atom_count]:
						if (a.x-x)**2 + (a.y-y)**2 + (a.z-z)**2 < max_vdw_r**2:
							raise AssertionError()
					while True:
						index_to_add = random.randrange(len(solvents))
						if solvent_amount_to_add[ index_to_add ] > 0:
							solvents[ index_to_add ].add_to(x, y, z, atoms, bonds, angles, dihedrals)
							solvent_amount_to_add[ index_to_add ] -= 1
							if sum(solvent_amount_to_add) == 0:
								solvent_amount_to_add = [ratio for ratio in solvent_ratio]
							break
				except AssertionError: pass

	T = 94.0
	P = 1.45

	filetypes.write_xyz('out', atoms)

	os.chdir('lammps')
	
	original_vdw_e = [a.type.vdw_e for a in test_molecule.atoms]
	original_charges = [a.type.charge for a in test_molecule.atoms]

	n_steps = 100
	for step in range(0,n_steps+1):
		for i,x in enumerate(test_molecule.atoms):
			a = atoms[i]
			a.type.vdw_e = original_vdw_e[i] * (1.0*step/n_steps)**2 #since LJ eps is geometric mean
			a.type.charge = original_charges[i] * step/n_steps
			a.charge = a.type.charge
	
		run_name = test_molecule_name+'_'+('_'.join([str(x) for x in solvent_ratio]))+'__'+str(int(step))
	
		atom_types = dict( [(t.type,True) for t in atoms] ).keys()
		atom_type_numbers = dict( [(t,i+1) for i,t in enumerate(atom_types)] )
		is_charged = any([a.charge!=0.0 for a in atoms])

		lammps.write_data_file_general(atoms, bonds, angles, dihedrals, box_size, run_name, atom_types=atom_types)
		pickle.dump((atoms, bonds, angles, dihedrals), open(run_name+'.pickle', 'w'))
		os.system('cp ../'+sys.argv[0]+' '+run_name+'.py')

		f = open(run_name+'.in', 'w')
		f.write('units	real\natom_style	full #bonds, angles, dihedrals, impropers, charges\n')

		if is_charged:
			f.write('pair_style lj/cut/coul/long 8.0\n')
		else:
			f.write('pair_style lj/cut 8.0\n')
		if bonds: f.write('bond_style harmonic\n')
		if angles: f.write('angle_style harmonic\n')
		if dihedrals: f.write('dihedral_style opls\n')
		if is_charged: f.write('kspace_style pppm 1.0e-3\n')

		f.write('special_bonds lj/coul 0.0 0.0 0.5\nread_data	'+run_name+'.data\n')
	
		test_molecule_types = dict( [(t.type,True) for t in atoms[:len(test_molecule.atoms)]] ).keys()

		f.write('''thermo		0
dump	1 all xyz 10000 '''+run_name+'''.xyz

group test_molecule id <= '''+str(len(test_molecule.atoms))+'''
group others subtract all test_molecule

compute SolEng test_molecule group/group others
thermo_style 	custom c_SolEng
#thermo_style custom etotal ke temp pe ebond eangle edihed eimp evdwl ecoul elong press vol c_SolEng tpcpu
#thermo_modify	line multi format float %14.6f

minimize 0.0 1.0e-8 1000 100000\n''')

		if water_types: #rigid water model
			f.write(('fix rigid_water all shake 0.0001 20 0 t'+(' %d'*len(water_types))+'\n') % tuple([atom_type_numbers[t] for t in water_types]) )

		f.write('''
velocity all create '''+str(T)+''' 1 rot yes dist gaussian
fix press all npt temp '''+str(T)+' '+str(T)+''' 100 iso '''+str(P)+' '+str(P)+''' 1000
timestep 2.0
thermo 1
run 250000
''')
		f.close()
		if True: #start multiple processes
			#os.system('nohup ~/lammps/src/lmp_g++_no_cuda -in %s.in -log %s.log &> /dev/null &' % (run_name, run_name) )
			makefile.write( '%s:\n\t~/lammps2/src/lmp_g++ -in %s.in -log %s.log &> /dev/null\n' % (run_name, run_name, run_name)  )
			print 'Running', run_name
		else:
			os.system('~/lammps/src/lmp_g++_no_cuda -in %s.in -log %s.log' % (run_name, run_name) )
			sys.exit()
	os.chdir('..')
Ejemplo n.º 7
0
def run(solvent_ratio):
	utils.Molecule.set_params('oplsaa4.prm')

	tail = utils.Molecule('hexanenitrile.arc')
	solvent = utils.Molecule('methane.arc')

	for a in tail.atoms:
		a.x, a.z = a.z, a.x

	directory = 'lammps'
	os.chdir(directory)

	n_steps = 1
	for step in range(0,n_steps):

		atoms = []
		bonds = []
		angles = []
		dihedrals = []

		S = 3.5
		box_size = [20,20,20]
		theta = 0; z = 0.0

		print len(atoms)/len(tail.atoms)
		atom_count = len(atoms)
		solvent_spacing = [(max(solvent.atoms, key=lambda a:a.x).x-min(solvent.atoms, key=lambda a:a.x).x), (max(solvent.atoms, key=lambda a:a.y).y-min(solvent.atoms, key=lambda a:a.y).y), (max(solvent.atoms, key=lambda a:a.z).z-min(solvent.atoms, key=lambda a:a.z).z)]
		solvent_spacing = [x+1.0 for x in solvent_spacing]
		max_vdw_r = max(solvent.atoms, key=lambda a:a.type.vdw_r).type.vdw_r
		solvent_spacing = [max(x,max_vdw_r) for x in solvent_spacing]
		for x in utils.frange(-box_size[0]/2, box_size[0]/2-solvent_spacing[0], solvent_spacing[0]):
			for y in utils.frange(-box_size[1]/2, box_size[1]/2-solvent_spacing[1], solvent_spacing[1]):
				for z in utils.frange(-box_size[2]/2, box_size[2]/2-solvent_spacing[2], solvent_spacing[2]):
					try:
						for a in atoms[:atom_count]:
							if (a.x-x)**2 + (a.y-y)**2 + (a.z-z)**2 < max_vdw_r**2:
								raise Exception()
						solvent.add_to(x, y, z, atoms, bonds, angles, dihedrals)
					except: pass

		T = 94.0
		P = 1.45

		print (len(atoms)-atom_count)/len(solvent.atoms)
		filetypes.write_xyz('out', atoms)

		run_name = 'azoto_solv__'+str(int(step))
	
		atom_types = dict( [(t.type,True) for t in atoms] ).keys()
		atom_type_numbers = dict( [(t,i+1) for i,t in enumerate(atom_types)] )
		is_charged = True

		lammps.write_data_file_general(atoms, bonds, angles, dihedrals, box_size, run_name, atom_types=atom_types)
		os.system('cp ../'+sys.argv[0]+' '+run_name+'.py')

		f = open(run_name+'.in', 'w')
		f.write('units	real\natom_style	full #bonds, angles, dihedrals, impropers, charges\n')

		if is_charged:
			f.write('pair_style lj/cut/coul/long 8.0\n')
		else:
			f.write('pair_style lj/cut 8.0\n')
		if bonds: f.write('bond_style harmonic\n')
		if angles: f.write('angle_style harmonic\n')
		if dihedrals: f.write('dihedral_style opls\n')
		if is_charged: f.write('kspace_style pppm 1.0e-3\n')

		f.write('special_bonds lj/coul 0.0 0.0 0.5\nread_data	'+run_name+'.data\n')

		f.write('''thermo		0
dump	1 all xyz 10000 '''+run_name+'''.xyz

thermo_style custom etotal ke temp pe ebond eangle edihed evdwl ecoul elong press lx ly lz tpcpu
thermo_modify	line multi format float %14.6f

minimize 0.0 1.0e-8 1000 100000
velocity all create '''+str(T)+''' 1 rot yes dist gaussian
fix press all npt temp '''+str(T)+' '+str(T)+''' 100 aniso '''+str(P)+' '+str(P)+''' 500
timestep  4.0
neigh_modify check yes every 1 delay 0
run_style respa 4 2 2 2 inner 2 4.5 6.0 middle 3 7.0 8.0 outer 4
thermo		100
run 25000
unfix press
fix dynamics all nvt temp '''+str(T)+' '+str(T)+''' 100
thermo_style 	custom epair pe etotal
thermo 1
run 25000
''')
		f.close()
		if True: #start multiple processes
			os.system('nohup ~/lammps/src/lmp_g++_no_cuda -in %s.in -log %s.log &> /dev/null &' % (run_name, run_name) )
			print 'Running', run_name
		else:
			os.system('~/lammps/src/lmp_g++_no_cuda -in %s.in -log %s.log' % (run_name, run_name) )
			sys.exit()
	os.chdir('..')
Ejemplo n.º 8
0
def run(filename):
	tail = utils.Molecule(filename+'.arc')
	
	atoms = []
	bonds = []
	angles = []
	dihedrals = []
	
	tail.add_to(0., 0., 0., atoms, bonds, angles, dihedrals)
	tail.add_to(0., 5., 0., atoms, bonds, angles, dihedrals)

	box_size = [40.]*3

	T = 100.0

	directory = 'lammps'
	if not os.path.isdir(directory):
		os.mkdir(directory)
	os.chdir(directory)

	run_name = 'bind3_'+filename

	atom_types = dict( [(t.type,True) for t in atoms] ).keys()
	atom_type_numbers = dict( [(t,i+1) for i,t in enumerate(atom_types)] )
	is_charged = any([a.charge!=0.0 for a in atoms])

	lammps.write_data_file_general(atoms, bonds, angles, dihedrals, box_size, run_name, atom_types=atom_types)
	os.system('cp ../'+sys.argv[0]+' '+run_name+'.py')

	f = open(run_name+'.in', 'w')
	f.write('''units	real\natom_style	full #bonds, angles, dihedrals, impropers, charges\n''')

	f.write('pair_style lj/cut/coul/long 8.0\n')
	if bonds: f.write('bond_style harmonic\n')
	if angles: f.write('angle_style harmonic\n')
	if dihedrals: f.write('dihedral_style opls\n')
	f.write('kspace_style pppm 1.0e-3\n')

	f.write('''special_bonds lj/coul 0.0 0.0 0.5
read_data	'''+run_name+'''.data\n

dump	1 all xyz 2500 '''+run_name+'''.xyz

thermo_modify	line multi format float %14.6f
minimize 0.0 1.0e-8 1000 100000

group mobile id > 1
velocity mobile create '''+str(T)+''' 1
run_style respa 4 2 2 2 inner 2 4.5 6.0 middle 3 7.0 8.0 outer 4
fix anneal mobile nvt temp '''+str(T)+''' 1.0 50.0
timestep 4.0
run 250000
minimize 0.0 1.0e-8 1000 100000

group aa id <= '''+str(len(atoms)/2)+'''
group bb subtract all aa
compute 1 aa group/group bb kspace yes
thermo_style custom c_1

run 0
''')
	f.close()
	os.system('lammps -in '+run_name+'.in -log '+run_name+'.log')
	os.chdir('..')
	
	
	for i,line in enumerate(open(directory+'/'+run_name+'.xyz').readlines()[ -len(atoms) : ]):
		columns = line.split()
		index, x, y, z = columns
		atoms[i].x, atoms[i].y, atoms[i].z = float(x), float(y), float(z)
	
	filetypes.write_xyz(run_name, atoms)