コード例 #1
0
ファイル: md3.py プロジェクト: jminuse/azotosome-paper
def run(filename):
	tail = utils.Molecule(filename+'.arc')
	
	atoms = []
	bonds = []
	angles = []
	dihedrals = []
	
	tail.add_to(0., 0., 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 = 'opls_'+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 250000 '''+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
''')
	f.close()
	os.system('lammps -in '+run_name+'.in -log '+run_name+'.log')
	os.chdir('..')
コード例 #2
0
ファイル: azoto_ti2.py プロジェクト: jminuse/azotosome-paper
def run(mode, timescale, step, step_size, makefile):
	run_name = 'ti10_'+str(mode)+'__'+str(step)
	z_separation = step * step_size
	solvent = utils.Molecule('methane.arc')
	#solvent = utils.Molecule('benzene2.arc')
	#solvent = utils.Molecule('hexane2.arc')
	box_size = [21.,21.,42.]
	S = 3.5

	if mode==3:
		tail = utils.Molecule('propanenitrile.arc')
		z_offset = -4.5
	elif mode==4:
		tail = utils.Molecule('butanenitrile.arc')
		for a in tail.atoms:
			a.x, a.z = a.z, a.x
		z_offset = 4.5
	elif mode==5:
		tail = utils.Molecule('pentanenitrile.arc')
		for a in tail.atoms:
			a.x, a.z = a.z, a.x
		z_offset = 5.0
	elif mode==6:
		tail = utils.Molecule('hexanenitrile.arc')
		for a in tail.atoms:
			a.x, a.z = a.z, a.x
		z_offset = 6.5
	elif mode==7:
		tail = utils.Molecule('aminopropane2.arc')
		for a in tail.atoms:
			a.x, a.z = a.z, a.x
		z_offset = 2.5
	elif mode==8:
		tail = utils.Molecule('aminobutane2.arc')
		for a in tail.atoms:
			a.x, a.z = a.z, -a.x
		z_offset = 3.5
	elif mode==9:
		tail = utils.Molecule('aminopentane2.arc')
		for a in tail.atoms:
			a.x, a.z = a.z, a.x
		z_offset = 5.0
	elif mode==10:
		tail = utils.Molecule('aminohexane2.arc')
		for a in tail.atoms:
			a.x, a.z = a.z, a.x
		z_offset = 6.5
	elif mode==11:
		tail = utils.Molecule('hexane2.arc')
		for a in tail.atoms:
			a.x, a.z = a.z, a.x
		z_offset = 9.0
	elif mode==12:
		tail = utils.Molecule('hcn2.arc')
		for a in tail.atoms:
			a.x, a.z = a.z, a.x
		S = 3.0
		z_offset = -0.5
	elif mode==13:
		tail = utils.Molecule('cyanoacetylene2.arc') #unfixed dihedrals irrelevant, since angle=180
		for a in tail.atoms:
			a.x, a.z = a.z, a.x
		z_offset = -2.0
	elif mode==14:
		tail = utils.Molecule('acrylonitrile2.arc') #unfixed dihedrals irrelevant, since angle=180
		for a in tail.atoms:
			a.x, a.z = a.z, a.x
		z_offset = -4.0
	elif mode==15:
		tail = utils.Molecule('cyanoallene2.arc') #added one dihedral param (18   19   37  100), other two free, ( 36   37  100   37 ) added too, or modified? Basically, doesn't work in OPLS; allene dihedrals are wrong. 
		for a in tail.atoms:
			a.x, a.z = a.z, a.x
		z_offset = 4.0
	elif mode==16:
		tail = utils.Molecule('acetonitrile2.arc') #all dihedrals free
		z_offset = 2.0
	elif mode==17:
		tail = utils.Molecule('hc5n2.arc') #doesn't work well in OPLS
		for a in tail.atoms:
			a.x, a.z = a.z, a.x
		z_offset = -4.0

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

	theta = 0; z = 0.0
	molecules_not_added = 0
	
	held_atoms = []
	pushed_atoms = []
	
	if mode==11:
		for xi in range(box_size[0]/S):
			x = xi*S - box_size[0]/2
			for yi in range(box_size[1]/S):
				y = yi*S - box_size[1]/2

				#tail.add_to(x, y, z, atoms, bonds, angles, dihedrals)
				if xi==3 and yi==3:
					tail.add_to(x, y, z+z_separation*(1 if z_offset<0 else -1), atoms, bonds, angles, dihedrals)
					pushed_atoms.append( atoms[-15] )
				else:
					tail.add_to(x, y, z, atoms, bonds, angles, dihedrals)
					if xi==0 or yi==0:
						held_atoms.append( atoms[-15] )

				old_atom_positions = [(a.x, a.y, a.z) for a in tail.atoms]
				for a in tail.atoms:
					a.z = -a.z+z_offset
					a.y = -a.y
				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]
	else:
		for xi in range(box_size[0]/S):
			x = xi*S - box_size[0]/2
			for yi in range(box_size[1]/S):
				y = yi*S - box_size[1]/2
				if (xi%2)==(yi%2):
					if xi==3 and yi==3:
						tail.add_to(x, y, z+z_separation*(1 if z_offset<0 else -1), atoms, bonds, angles, dihedrals)
					else:
						tail.add_to(x, y, z, atoms, bonds, angles, dihedrals)
				else:
					old_atom_positions = [(a.x, a.y, a.z) for a in tail.atoms]
					for a in tail.atoms:
						a.z = -a.z+z_offset
						a.y = -a.y
					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]
				
				for a in atoms[::-1]:
					if a.element=='N':
						if xi==3 and yi==3:
							pushed_atoms.append( a )
						elif xi==0 or yi==0:
							held_atoms.append( a )
						break

	#filetypes.write_xyz('', atoms, xyz_file)
	print pushed_atoms[0].z
	return

	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 xi in range(box_size[0]/solvent_spacing[0]):
		for yi in range(box_size[1]/solvent_spacing[1]):
			for zi in range(box_size[2]/solvent_spacing[2]):
				x, y, z = xi*solvent_spacing[0]-box_size[0]/2,  yi*solvent_spacing[1]-box_size[1]/2,  zi*solvent_spacing[2]-box_size[2]/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

	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

	directory = 'lammps'
	os.chdir(directory)

	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('''
dump	1 all xyz '''+str(int(10000*timescale))+''' '''+run_name+'''.xyz

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

group held_atoms id '''+(' '.join([str(a.index) for a in held_atoms]))+'''
group pushed_atoms id '''+(' '.join([str(a.index) for a in pushed_atoms]))+'''

fix no_z held_atoms planeforce 0.0 0.0 1.0
fix hold pushed_atoms smd cvel 100.0 0.0 tether NULL NULL 100.0 0.0

fix no_z_temp pushed_atoms planeforce 0.0 0.0 1.0 #since smd is not enforced during minimization
minimize 0.0 1.0e-8 1000 100000
unfix no_z_temp

timestep  2.0
fix relax all npt temp 10.0 10.0 50 aniso '''+str(P)+' '+str(P)+''' 500
run 1000
unfix relax
velocity all create '''+str(T)+''' 1 rot yes dist gaussian
velocity held_atoms set 0.0 0.0 0.0
fix press all npt temp '''+str(T)+' '+str(T)+''' 100 aniso '''+str(P)+' '+str(P)+''' 1000

fix average all ave/time 1 1000 1000 c_thermo_pe f_hold[4] f_hold[6]
thermo 1000
thermo_style 	custom f_average[1] f_average[2] f_average[3]

run '''+str(int(50000*timescale))+'''
write_restart '''+run_name+'.restart\n')

	f.close()
	if True: #start multiple processes
		#os.system('nohup ~/lammps2/src/lmp_g++ -in %s.in -log %s.log &> /dev/null &' % (run_name, run_name) )
		#print 'Running', 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)  )
	else:
		os.system('~/lammps2/src/lmp_g++ -in %s.in -log %s.log' % (run_name, run_name) )
		sys.exit()
	os.chdir('..')
コード例 #3
0
def run(test_molecule_filename, makefile):
    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[-1] == '2':
        test_molecule_name = test_molecule_name[:-1]
    solvent = copy.deepcopy(test_molecule)

    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]

    if test_molecule_name == 'propanenitrile' or test_molecule_name == 'acetonitrile':
        solvent_spacing[2] += 1.0
    if test_molecule_name == 'hcn':
        solvent_spacing[0] += 0.5
    if test_molecule_name == 'acetylene':
        pass

    L = 6
    box_size = [L * x for x in solvent_spacing]

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

    #add staggering between layers (like shingles)

    for xi in range(L):
        for yi in range(L):
            for zi in range(L):
                x = xi * solvent_spacing[0] - box_size[0] / 2
                y = yi * solvent_spacing[1] - box_size[1] / 2
                z = (zi + xi * 0.5) * solvent_spacing[2] - box_size[2] / 2

                if xi == 0 and yi == 0 and zi == 0:
                    test_molecule.add_to(x, y, z, atoms, bonds, angles,
                                         dihedrals)
                else:
                    if True:  #(xi+yi+zi)%2==0:
                        solvent.add_to(x, y, z, atoms, bonds, angles,
                                       dihedrals)
                    else:
                        for a in solvent.atoms:
                            a.z = -a.z
                        solvent.add_to(x, y, z, atoms, bonds, angles,
                                       dihedrals)
                        for a in solvent.atoms:
                            a.z = -a.z

    T = 94.0
    P = 1.45

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

    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 + '_solid2__' + 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

fix relax all nve/limit 0.01
fix drag all viscous 0.05
timestep 2.0
run 2500
unfix relax
fix relax all nve
run 25000
unfix relax
unfix drag

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) + ''' 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('..')
コード例 #4
0
def react_dots(
    params,
    dot_size1,
    dot_size2,
    prior_run_name1,
    prior_run_name2,
    random_seed=1,
    run_name_prefix="react_",
    on_queue=True,
    method="metadynamics",
):
    random_s = str(random_seed)
    random.seed(random_seed)
    run_name = run_name_prefix + str(dot_size1) + "_" + str(dot_size2)

    spoc = utils.Molecule("/fs/home/jms875/Documents/nanocrystals/pb_oleate_hydrate_morse/" + spoc_name + ".arc")

    atoms1, bonds1, angles1, dihedrals1 = cPickle.load(open("lammps/" + prior_run_name1 + ".pickle", "rb"))
    atoms1, bonds1, angles1, dihedrals1 = remove_unattached_ligands(atoms1, bonds1, angles1, dihedrals1, spoc)
    atoms2, bonds2, angles2, dihedrals2 = cPickle.load(open("lammps/" + prior_run_name2 + ".pickle", "rb"))
    atoms2, bonds2, angles2, dihedrals2 = remove_unattached_ligands(atoms2, bonds2, angles2, dihedrals2, spoc)

    atoms1_xyz = filetypes.parse_xyz(prior_run_name1 + ".xyz")
    atoms2_xyz = filetypes.parse_xyz(prior_run_name2 + ".xyz")
    goal_atoms = filetypes.parse_xyz("dot" + str(dot_size1 + dot_size2) + ".xyz")

    # set starting coordinates
    for a, b in zip(atoms1, atoms1_xyz):
        a.x = b.x
        a.y = b.y
        a.z = b.z

    for a, b in zip(atoms2, atoms2_xyz):
        a.x = b.x
        a.y = b.y
        a.z = b.z

    atoms = atoms1 + atoms2
    bonds = bonds1 + bonds2
    angles = angles1 + angles2
    dihedrals = dihedrals1 + dihedrals2
    # make sure atom types are the same in atom1 and atom2
    atom_types_by_type_index = dict([(t.type.index, t.type) for t in atoms])
    for i, a in enumerate(atoms):
        a.type = atom_types_by_type_index[a.type.index]
        a.index = i + 1
        if coul_on and a.type.index in params:
            a.charge = params[a.type.index]
        else:
            a.charge = a.type.charge

    atom_types = dict([(t.type, True) for t in atoms]).keys()
    atom_types.sort(key=lambda t: -t.element - t.index * 0.00001)

    offset = (
        radius_of_gyration([a for a in atoms1 if (a.type.notes == "PbS Nanocrystal Pb" or a.element == "S")])
        + radius_of_gyration([a for a in atoms2 if (a.type.notes == "PbS Nanocrystal Pb" or a.element == "S")])
        + 10.0
    )
    offset_vector = utils.matvec(utils.rand_rotation(), [offset, offset, offset])
    rot = utils.rand_rotation()
    for a in atoms2:  # offset by random orientation vector
        a.x, a.y, a.z = utils.matvec(rot, [a.x, a.y, a.z])
        a.x += offset_vector[0]
        a.y += offset_vector[1]
        a.z += offset_vector[2]
    box_size = [
        15.0 + max([a.x for a in atoms]) - min([a.x for a in atoms]),
        15.0 + max([a.y for a in atoms]) - min([a.y for a in atoms]),
        15.0 + max([a.z for a in atoms]) - min([a.z for a in atoms]),
    ]

    # goal_atoms = cPickle.load( open('lammps/dot'+str(dot_size1+dot_size2)+'.pickle', 'rb') )[0]

    # filetypes.write_xyz('out_meta', atoms)
    # exit()

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

    starting_rxn_coord = radius_of_gyration(
        [a for a in atoms if (a.type.notes == "PbS Nanocrystal Pb" or a.element == "S")]
    )
    print len([a for a in atoms if (a.type.notes == "PbS Nanocrystal Pb" or a.element == "S")])
    goal_rxn_coord = radius_of_gyration(goal_atoms[0 : 2 * (dot_size1 + dot_size2)])

    colvars_file = open(run_name + ".colvars", "w")
    colvars_file.write(
        """
colvarsTrajFrequency 10000
colvarsRestartFrequency 100000

colvar {
  name gyr
  width 0.1 #size of bins, in Angstroms
  upperBoundary """
        + str(starting_rxn_coord)
        + """ #two separate dots
  lowerBoundary """
        + str(goal_rxn_coord)
        + """ #one unified dot
  lowerwallconstant 10.0
  upperwallconstant 10.0
  gyration {
	atoms {
	  atomNumbers """
        + (" ".join([str(a.index) for a in atoms if (a.type.notes == "PbS Nanocrystal Pb" or a.element == "S")]))
        + """
	}
  }
}
"""
    )
    if method.lower() == "abf":
        colvars_file.write(
            """
abf {
  colvars gyr
  hideJacobian # when using distance-based colvar: makes pmf flat at infinity
  fullSamples 1000
}
"""
        )
    elif method.lower() == "metadynamics":
        colvars_file.write(
            """
metadynamics {
  colvars gyr
  hillWeight 0.1
  newHillFrequency 1000
}
"""
        )
    else:
        raise Exception('Invalid free energy method "%s"' % method)
    colvars_file.close()

    f = open(run_name + ".in", "w")
    write_input_header(f, run_name, atom_types, read_restart=False)
    f.write(
        """
dump	1 all xyz 10000 """
        + run_name
        + """.xyz
minimize 0.0 1.0e-8 10000 1000
neigh_modify check yes every 1 delay 0
thermo_style custom pe temp
thermo 10000
restart 100000 """
        + run_name
        + """.restart1 """
        + run_name
        + """.restart2
fix motion all nve
fix implicit_solvent all langevin 400.0 400.0 100.0 """
        + random_s
        + """ zero yes gjf yes
fix		col all colvars """
        + run_name
        + """.colvars output """
        + run_name
        + """ seed """
        + random_s
        + """ tstat implicit_solvent
velocity	all create 400.0 """
        + random_s
        + """ mom yes
timestep	2.0
thermo_style	custom step temp etotal pe ke epair ebond f_col tpcpu
run """
        + str(int(1e7))
        + """
write_restart """
        + run_name
        + """.restart
"""
    )
    f.close()
    # run_job(run_name, on_queue)
    os.chdir("..")
コード例 #5
0
ファイル: md3.py プロジェクト: jminuse/titan-solvation-paper
def run(filename):
    tail = utils.Molecule(filename + '.arc')

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

    tail.add_to(0., 0., 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 = 'opls_' + 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 250000 ''' + 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
''')
    f.close()
    os.system('lammps -in ' + run_name + '.in -log ' + run_name + '.log')
    os.chdir('..')
コード例 #6
0
ファイル: micelle.py プロジェクト: jminuse/azotosome-paper
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('..')
コード例 #7
0
ファイル: colvars.py プロジェクト: jminuse/smrff
def make_lattice(params, system_size, prior_run_name, lc_x=1, lc_y=1, lc_z=1, random_seed=1, run_name_prefix='lattice_', on_queue=True):
	atoms, bonds, angles, dihedrals = [], [], [], []
	x, y, z = 0, 0, 0
	spacer = utils.Molecule('ma.arc')
	for xi in range(system_size):
		x, y, z = 0, 0, 0
		for yi in range(system_size):
			x, y, z = 0, 0, 0
			for zi in range(system_size):
				x=xi*lc_x
				y=yi*lc_y
				z=zi*lc_z
				unbonded_atoms = filetypes.parse_xyz('/fs/home/jar528/Desktop/nano/xyz/unbonded.xyz')
				for a in unbonded_atoms:
					a.x += x
					a.y += y
					a.z += z
				atoms = atoms + unbonded_atoms
				spacer.add_to(x, y, z, atoms, bonds, angles, dihedrals)
	
	iodine_type = [t for t in utils.Molecule.atom_types if t.element_name=='I'][-1]
	lead_type = [t for t in utils.Molecule.atom_types if t.element_name=='Pb'][-1]
	
	for a in atoms:
		if a.element=='I':
			a.type=iodine_type
		if a.element=='Pb':
			a.type=lead_type
	
	#filetypes.write_xyz('/fs/home/jar528/Desktop/nano/out', atoms)
	#exit()
	
	random_s = str(random_seed)
	random.seed(random_seed)
	run_name = run_name_prefix+str(system_size)

	# make sure atom types are the same in atom1 and atom2
	atom_types_by_type_index = dict( [(t.type.index,t.type) for t in atoms] )
	for i,a in enumerate(atoms):
		a.type = atom_types_by_type_index[ a.type.index ]
		a.index = i+1
		if coul_on and a.type.index in params:
			a.charge = params[a.type.index]
		else:
			a.charge = a.type.charge
	
	atom_types = dict( [(t.type,True) for t in atoms] ).keys()
	atom_types.sort(key=lambda t:-t.element-t.index*0.00001)
	
	box_size = [ 3.24+max([a.x for a in atoms])-min([a.x for a in atoms]),
				 3.24+max([a.y for a in atoms])-min([a.y for a in atoms]),
				 3.24+max([a.z for a in atoms])-min([a.z for a in atoms]) ]
	
	os.chdir('lammps')
	save_to_file( atoms, bonds, angles, dihedrals, atom_types, run_name )
	lammps.write_data_file_general(atoms, bonds, angles, dihedrals, box_size, run_name, atom_types=atom_types, pair_coeffs_included=False)
	os.system('cp ../'+sys.argv[0]+' '+run_name+'.py')
	
	f = open(run_name+'.in', 'w')
	write_input_header(f, run_name, atom_types, read_restart=False)
	f.write('''
dump	1 all xyz 10000 '''+run_name+'''.xyz
minimize 0.0 1.0e-8 10000 1000
neigh_modify check yes every 1 delay 0
thermo 10000
restart 100000 '''+run_name+'''.restart1 '''+run_name+'''.restart2
#fix motion all nve
#fix implicit_solvent all langevin 400.0 400.0 1000.0 '''+random_s+''' zero yes gjf yes
fix motion all npt temp 450.0 450.0 100.0 aniso 1.0 1.0 1000.0
velocity	all create 400.0 '''+random_s+''' mom yes
timestep	2.0
thermo_style	custom step temp etotal pe tpcpu
run '''+str(int(1e6))+'''
#thermo 1
#run 1000
minimize 0.0 1.0e-8 10000 1000
write_restart '''+run_name+'''.restart
''')
	f.close()
	run_job(run_name, on_queue)
	os.chdir('..')
コード例 #8
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('..')
コード例 #9
0
ファイル: azoto_hot.py プロジェクト: jminuse/azotosome-paper
def run():
	utils.Molecule.set_params('oplsaa4.prm')
	solvent = utils.Molecule('methane.arc')

	if False:
		tail = utils.Molecule('propanenitrile.arc')
		z_off_1 = 3.0
		z_off_2 = -5.5
	else:
		tail = utils.Molecule('hexanenitrile.arc')
		for a in tail.atoms:
			a.x, a.z = a.z, a.x
		z_off_1 = 0.0
		z_off_2 = 6.5

	directory = 'lammps'
	os.chdir(directory)

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

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

		S = 3.5
		box_size = [21.,21.,35.]
		theta = 0; z = 0.0
		molecules_not_added = 0
		
		held_Ns = []
		pushed_Ns = []
		
		for xi in range(box_size[0]/S):
			x = xi*S - box_size[0]/2
			for yi in range(box_size[1]/S):
				y = yi*S - box_size[1]/2
				if (xi%2)==(yi%2):
					tail.add_to(x, y, z+z_off_1, atoms, bonds, angles, dihedrals)
				else:
					old_atom_positions = [(a.x, a.y, a.z) for a in tail.atoms]
					for a in tail.atoms:
						a.z = -a.z+z_off_2
						a.y = -a.y
					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]
				if (xi,yi) in [(3,3)]:
					for a in atoms[::-1]:
						if a.element=='N':
							pushed_Ns.append(a)
							break
				elif (xi,yi) in [(0,0)]:
					for a in atoms[::-1]:
						if a.element=='N':
							held_Ns.append(a)
							break

		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 xi in range(box_size[0]/solvent_spacing[0]):
			for yi in range(box_size[1]/solvent_spacing[1]):
				for zi in range(box_size[2]/solvent_spacing[2]):
					x, y, z = xi*solvent_spacing[0]-box_size[0]/2,  yi*solvent_spacing[1]-box_size[1]/2,  zi*solvent_spacing[2]-box_size[2]/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
		T_hot = T*4.2
		P = 1.45

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

		run_name = 'azoto_hot__0'
	
		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 1000 '''+run_name+'''.xyz

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

minimize 0.0 1.0e-8 1000 100000

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		1000
fix relax all npt temp 10.0 10.0 50 aniso '''+str(P)+' '+str(P)+''' 500
run 1000
unfix relax
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)+''' 1000
run 1000
group held_Ns id '''+(' '.join([str(N.index) for N in held_Ns]))+'''
group pushed_Ns id '''+(' '.join([str(N.index) for N in pushed_Ns]))+'''

#fix push1 held_Ns smd cvel 20.0 -0.00001 tether NULL NULL 100.0 0.0
#fix push2 pushed_Ns smd cvel 20.0 0.00001 tether NULL NULL 100.0 0.0

unfix press
group membrane id <= '''+str(atom_count)+'''
group solvent subtract all membrane

fix press1 membrane npt temp '''+str(T_hot)+' '+str(T_hot)+''' 100 aniso '''+str(P)+' '+str(P)+''' 1000
fix press2 solvent nvt temp '''+str(T_hot)+' '+str(T_hot)+''' 100

#thermo_style 	custom epair f_push1[7] f_push2[7]
thermo 100
run 10000
''')
		f.close()
		if False: #start multiple processes
			os.system('nohup ~/lammps2/src/lmp_g++ -in %s.in -log %s.log &> /dev/null &' % (run_name, run_name) )
			print 'Running', run_name
		else:
			os.system('~/lammps2/src/lmp_g++ -in %s.in -log %s.log' % (run_name, run_name) )
			sys.exit()
	os.chdir('..')
コード例 #10
0
ファイル: azoto_bend.py プロジェクト: jminuse/azotosome-paper
def run(mode, timescale):
	run_name = 'bend11_'+str(mode)

	if mode==3:
		tail = utils.Molecule('propanenitrile.arc')
		z_offset = -4.5
	elif mode==4:
		tail = utils.Molecule('butanenitrile.arc')
		for a in tail.atoms:
			a.x, a.z = a.z, a.x
		z_offset = 4.5
	elif mode==5:
		tail = utils.Molecule('pentanenitrile.arc')
		for a in tail.atoms:
			a.x, a.z = a.z, a.x
		z_offset = 5.0
	elif mode==6:
		tail = utils.Molecule('hexanenitrile.arc')
		for a in tail.atoms:
			a.x, a.z = a.z, a.x
		z_offset = 6.5
	elif mode==7:
		tail = utils.Molecule('aminopropane2.arc')
		for a in tail.atoms:
			a.x, a.z = a.z, a.x
		z_offset = 2.5
	elif mode==8:
		tail = utils.Molecule('aminobutane2.arc')
		for a in tail.atoms:
			a.x, a.z = a.z, -a.x
		z_offset = 3.5
	elif mode==9:
		tail = utils.Molecule('aminopentane2.arc')
		for a in tail.atoms:
			a.x, a.z = a.z, a.x
		z_offset = 5.0
	elif mode==10:
		tail = utils.Molecule('aminohexane2.arc')
		for a in tail.atoms:
			a.x, a.z = a.z, a.x
		z_offset = 6.5
	elif mode==11:
		tail = utils.Molecule('hexane2.arc')
		for a in tail.atoms:
			a.x, a.z = a.z, a.x
		z_offset = 8.0
	elif mode==12:
		tail = utils.Molecule('hcn2.arc')
		for a in tail.atoms:
			a.x, a.z = a.z, a.x
		z_offset = -3.5
	elif mode==13:
		tail = utils.Molecule('cyanoacetylene2.arc')
		for a in tail.atoms:
			a.x, a.z = a.z, a.x
		z_offset = 0.0
	elif mode==14:
		tail = utils.Molecule('acrylonitrile2.arc')
		for a in tail.atoms:
			a.x, a.z = a.z, a.x
		z_offset = -4.0
	elif mode==15:
		tail = utils.Molecule('cyanoallene2.arc')
		for a in tail.atoms:
			a.x, a.z = a.z, a.x
		z_offset = 4.0
	elif mode==16:
		tail = utils.Molecule('acetonitrile2.arc')
		z_offset = 0.0
	elif mode==17:
		tail = utils.Molecule('hc5n2.arc')
		for a in tail.atoms:
			a.x, a.z = a.z, a.x
		z_offset = -4.0

	directory = 'lammps'
	os.chdir(directory)

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

	S_count = 12
	S = 3.5
	box_size = [ S_count*S ]*3
	theta = 0; z = 0.0
	molecules_not_added = 0
	
	pushable = []
	
	if mode==11:
		for xi in range(S_count):
			x = xi*S - box_size[0]/2
			for yi in range(S_count):
				y = yi*S - box_size[1]/2

				tail.add_to(x, y, z, atoms, bonds, angles, dihedrals)

				push_r = S * ( (xi-S_count/2)**2 + (yi-S_count/2)**2 )**0.5
				if xi==0 or yi==0:
					push_r = 100.0
					atoms[-15].push_r = push_r
					pushable.append( atoms[-15] )

				old_atom_positions = [(a.x, a.y, a.z) for a in tail.atoms]
				for a in tail.atoms:
					a.z = -a.z+z_offset
					a.y = -a.y
				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]
				
				atoms[-15].push_r = push_r
				pushable.append( atoms[-15] )
	else:
		for xi in range(S_count):
			x = xi*S - box_size[0]/2
			for yi in range(S_count):
				y = yi*S - box_size[1]/2
				if (xi%2)==(yi%2):
					tail.add_to(x, y, z, atoms, bonds, angles, dihedrals)
				else:
					old_atom_positions = [(a.x, a.y, a.z) for a in tail.atoms]
					for a in tail.atoms:
						a.z = -a.z+z_offset
						a.y = -a.y
					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]
				
				for a in atoms[::-1]:
					if a.element=='N':
						a.push_r = 100.0 if (xi==0 or yi==0) else S * ( (xi-S_count/2)**2 + (yi-S_count/2)**2 )**0.5
						pushable.append(a)
						break

	#for a in pushable:
	#	a.element = str(int(a.push_r))
	#for a in atoms:
	#	print a.element
	#filetypes.write_xyz('out', atoms)
	#sys.exit(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 xi in range(int(box_size[0]/solvent_spacing[0])):
		for yi in range(int(box_size[1]/solvent_spacing[1])):
			for zi in range(int(box_size[2]/solvent_spacing[2])):
				x, y, z = xi*solvent_spacing[0]-box_size[0]/2,  yi*solvent_spacing[1]-box_size[1]/2,  zi*solvent_spacing[2]-box_size[2]/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

	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 '''+str(int(10000*timescale))+''' '''+run_name+'''.xyz

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

minimize 0.0 1.0e-8 1000 100000

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		1000
fix relax all npt temp 10.0 10.0 50 aniso '''+str(P)+' '+str(P)+''' 500
run    1000
unfix relax
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)+''' 1000
run '''+str(int(25000*timescale))+'''
''')
	push_groups = [[a for a in pushable if a.push_r<=R and a.push_r>(R-0.01)] for R in [0.01*ri for ri in range(0,1000)]]
	push_groups = [p for p in push_groups if p]
	for p_i,p in enumerate(push_groups):
		f.write('group push_g'+str(p_i)+' id '+(' '.join([str(a.index) for a in p]))+'\n')
		r = p[0].push_r
		max_r = 10.0
		v = 0.5 * 1e-6*( max_r**2 - r**2 )**0.5 / timescale
		print r, v, 250000*timescale*4*v
		f.write('fix push_%d push_g%d smd cvel 20.0 %e tether NULL NULL 100.0 0.0\n' % (p_i, p_i, v) )
	
	f.write('group held_atoms id '+(' '.join([str(a.index) for a in pushable if a.push_r==100.0]))+'\nfix zrest held_atoms spring/self 20.0 z\n')
	f.write('thermo_style 	custom ' + ( ' '.join(['f_push_%d[6] f_push_%d[7]' % (p_i,p_i) for p_i,p in enumerate(push_groups)]) ) + '\n')

	f.write('''
thermo  '''+str(int(1000*timescale))+'''
run '''+str(int(250000*timescale))+'''
''')
	f.close()
	if True: #start multiple processes
		os.system('nohup ~/lammps2/src/lmp_g++ -in %s.in -log %s.log &> /dev/null &' % (run_name, run_name) )
		print 'Running', run_name
	else:
		os.system('~/lammps2/src/lmp_g++ -in %s.in -log %s.log' % (run_name, run_name) )
		sys.exit()
	os.chdir('..')
コード例 #11
0
ファイル: azoto_flat.py プロジェクト: jminuse/azotosome-paper
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('..')
コード例 #12
0
ファイル: azotosome.py プロジェクト: jminuse/azotosome-paper
def run(R):
	atoms = []
	bonds = []
	angles = []
	dihedrals = []

	added_atoms = []

	S = 3.5
	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 ) )
	
	added_atoms.append( utils.Struct( x=0., y=0., z=0., theta=0., phi=0., charge=1 ) )
	
	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, 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)
		for i,a in enumerate(tail.atoms): a.x, a.y, a.z = old_atom_positions[i]

	atom_count = len(atoms)

	box_size = [R*2+20]*3

	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+0.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 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 Exception()
					solvent.add_to(x, y, z, atoms, bonds, angles, dihedrals)
				except: pass

	T = 94.0
	P = 1.5

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

	run_name = 'azo_hex_r'+str(R)

	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

neigh_modify exclude molecule all

group test_molecules id <= '''+str(atom_count)+'''

compute 1 all pair/local eng
compute 2 test_molecules reduce sum c_1

minimize 0.0 1.0e-8 1000 100000

velocity all create '''+str(T)+''' 1 rot yes dist gaussian
fix dynamics all nvt temp '''+str(T)+' '+str(T)+''' 100
timestep 4.0
run_style respa 4 2 2 2 inner 2 4.5 6.0 middle 3 7.0 8.0 outer 4
run 2500

thermo_style custom c_2
thermo 1

run 1000
''')
	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('..')
コード例 #13
0
ファイル: azoto_smd.py プロジェクト: jminuse/azotosome-paper
def run(mode, timescale):
	run_name = 'smd20_'+str(mode)
	utils.Molecule.set_params('oplsaa4.prm')
	solvent = utils.Molecule('methane.arc')
	#solvent = utils.Molecule('benzene2.arc')
	#solvent = utils.Molecule('hexane2.arc')
	box_size = [21.,21.,42.]
	S = 3.5

	if mode==3:
		tail = utils.Molecule('propanenitrile.arc')
		z_offset = -4.5
	elif mode==4:
		tail = utils.Molecule('butanenitrile.arc')
		for a in tail.atoms:
			a.x, a.z = a.z, a.x
		z_offset = 4.5
	elif mode==5:
		tail = utils.Molecule('pentanenitrile.arc')
		for a in tail.atoms:
			a.x, a.z = a.z, a.x
		z_offset = 5.0
	elif mode==6:
		tail = utils.Molecule('hexanenitrile.arc')
		for a in tail.atoms:
			a.x, a.z = a.z, a.x
		z_offset = 6.5
	elif mode==7:
		tail = utils.Molecule('aminopropane2.arc')
		for a in tail.atoms:
			a.x, a.z = a.z, a.x
		z_offset = 2.5
	elif mode==8:
		tail = utils.Molecule('aminobutane2.arc')
		for a in tail.atoms:
			a.x, a.z = a.z, -a.x
		z_offset = 3.5
	elif mode==9:
		tail = utils.Molecule('aminopentane2.arc')
		for a in tail.atoms:
			a.x, a.z = a.z, a.x
		z_offset = 5.0
	elif mode==10:
		tail = utils.Molecule('aminohexane2.arc')
		for a in tail.atoms:
			a.x, a.z = a.z, a.x
		z_offset = 6.5
	elif mode==11:
		tail = utils.Molecule('hexane2.arc')
		for a in tail.atoms:
			a.x, a.z = a.z, a.x
		z_offset = 8.0
	elif mode==12:
		tail = utils.Molecule('hcn2.arc')
		for a in tail.atoms:
			a.x, a.z = a.z, a.x
		S = 3.0
		z_offset = -0.5
	elif mode==13:
		tail = utils.Molecule('cyanoacetylene2.arc')
		for a in tail.atoms:
			a.x, a.z = a.z, a.x
		z_offset = -2.0
	elif mode==14:
		tail = utils.Molecule('acrylonitrile2.arc')
		for a in tail.atoms:
			a.x, a.z = a.z, a.x
		z_offset = -4.0
	elif mode==15:
		tail = utils.Molecule('cyanoallene2.arc')
		for a in tail.atoms:
			a.x, a.z = a.z, a.x
		z_offset = 4.0
	elif mode==16:
		tail = utils.Molecule('acetonitrile2.arc')
		z_offset = 2.0
	elif mode==17:
		tail = utils.Molecule('hc5n2.arc')
		for a in tail.atoms:
			a.x, a.z = a.z, a.x
		z_offset = -4.0

	directory = 'lammps'
	os.chdir(directory)

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

	theta = 0; z = 0.0
	molecules_not_added = 0
	
	held_atoms = []
	pushed_atoms = []
	
	if mode==11:
		for xi in range(box_size[0]/S):
			x = xi*S - box_size[0]/2
			for yi in range(box_size[1]/S):
				y = yi*S - box_size[1]/2

				tail.add_to(x, y, z, atoms, bonds, angles, dihedrals)

				old_atom_positions = [(a.x, a.y, a.z) for a in tail.atoms]
				for a in tail.atoms:
					a.z = -a.z+z_offset
					a.y = -a.y
				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]
				
				if xi==3 and yi==3:
					pushed_atoms.append( atoms[-15] )
				elif xi==0 or yi==0:
					held_atoms.append( atoms[-15] )
	else:
		for xi in range(box_size[0]/S):
			x = xi*S - box_size[0]/2
			for yi in range(box_size[1]/S):
				y = yi*S - box_size[1]/2
				if (xi%2)==(yi%2):
					tail.add_to(x, y, z, atoms, bonds, angles, dihedrals)
				else:
					old_atom_positions = [(a.x, a.y, a.z) for a in tail.atoms]
					for a in tail.atoms:
						a.z = -a.z+z_offset
						a.y = -a.y
					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]
				
				for a in atoms[::-1]:
					if a.element=='N':
						if xi==3 and yi==3:
							pushed_atoms.append( a )
						elif xi==0 or yi==0:
							held_atoms.append( a )
						break

	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 xi in range(box_size[0]/solvent_spacing[0]):
		for yi in range(box_size[1]/solvent_spacing[1]):
			for zi in range(box_size[2]/solvent_spacing[2]):
				x, y, z = xi*solvent_spacing[0]-box_size[0]/2,  yi*solvent_spacing[1]-box_size[1]/2,  zi*solvent_spacing[2]-box_size[2]/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

	#filetypes.write_xyz(run_name, atoms)
	#os.chdir('..')
	#return

	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('''
dump	1 all xyz '''+str(int(10000*timescale))+''' '''+run_name+'''.xyz

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

minimize 0.0 1.0e-8 1000 100000

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
fix relax all npt temp 10.0 10.0 50 aniso '''+str(P)+' '+str(P)+''' 500
run 1000
unfix relax
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)+''' 1000
thermo  '''+str(int(100*timescale))+'''
run '''+str(int(25000*timescale))+'''
group held_atoms id '''+(' '.join([str(a.index) for a in held_atoms]))+'''
group pushed_atoms id '''+(' '.join([str(a.index) for a in pushed_atoms]))+'''

fix zrest held_atoms spring/self 100.0 z
fix push pushed_atoms smd cvel 100.0 '''+str((-1 if z_offset<0 else 1)*0.00001/timescale)+''' tether NULL NULL 100.0 0.0

thermo_style 	custom f_push[6] f_push[7] f_zrest
run '''+str(int(250000*timescale))+'''
''')
	f.close()
	if True: #start multiple processes
		os.system('nohup ~/lammps2/src/lmp_g++ -in %s.in -log %s.log &> /dev/null &' % (run_name, run_name) )
		print 'Running', run_name
	else:
		os.system('~/lammps2/src/lmp_g++ -in %s.in -log %s.log' % (run_name, run_name) )
		sys.exit()
	os.chdir('..')
コード例 #14
0
def run(test_molecule_filename, makefile):
	utils.Molecule.set_params('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:]=='e2': test_molecule_name = test_molecule_name[:-1]
	solvent = copy.deepcopy(test_molecule)

	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]

	solvent_spacing[2] += 1.0

	L = 6
	box_size = [L*x for x in solvent_spacing]

	atoms = []
	bonds = []
	angles = []
	dihedrals = []
	
	#add staggering between layers (like shingles)
	
	for xi in range(L):
		for yi in range(L):
			for zi in range(L):
				x = xi*solvent_spacing[0] - box_size[0]/2
				y = yi*solvent_spacing[1] - box_size[1]/2
				z = (zi+xi*0.5)*solvent_spacing[2] - box_size[2]/2
				
				if xi==0 and yi==0 and zi==0:
					test_molecule.add_to(x, y, z, atoms, bonds, angles, dihedrals)
				else:
					if True: #(xi+yi+zi)%2==0:
						solvent.add_to(x, y, z, atoms, bonds, angles, dihedrals)
					else:
						for a in solvent.atoms:
							a.z = -a.z
						solvent.add_to(x, y, z, atoms, bonds, angles, dihedrals)
						for a in solvent.atoms:
							a.z = -a.z

	T = 94.0
	P = 1.45

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

	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+'_solid2__'+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

fix relax all nve/limit 0.01
fix drag all viscous 0.05
timestep 2.0
run 2500
unfix relax
fix relax all nve
run 25000
unfix relax
unfix drag

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)+''' 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('..')