Example #1
0
def compare_distances_only():
    utils.Molecule.set_params('oplsaa4.prm')
    for f in [
            'propanenitrile', 'butanenitrile', 'pentanenitrile',
            'hexanenitrile', 'aminopropane2', 'aminobutane2', 'aminopentane2',
            'aminohexane2', 'hexane2', 'methane', 'hcn2', 'cyanoacetylene2',
            'acrylonitrile2', 'cyanoallene2', 'acetonitrile2', 'hc5n2'
    ]:
        atoms0 = utils.Molecule(f + '.arc').atoms
        atoms1 = gaussian.parse_atoms('gaussian/' + f + '_1.log')[1]
        for i in range(len(atoms0)):
            atoms0[i].index = i + 1
            atoms1[i].index = i + 1

            #atoms0[i].x = atoms1[i].xp
            #atoms0[i].y = atoms1[i].y
            #atoms0[i].z = atoms1[i].z

        bonds0 = filetypes.get_bonds(atoms0)
        bonds1 = filetypes.get_bonds(atoms1)

        #filetypes.write_arc(f[:-1]+'3', atoms0)
        #continue

        angles0, dihedrals0 = filetypes.get_angles_and_dihedrals(
            atoms0, bonds0)
        angles1, dihedrals1 = filetypes.get_angles_and_dihedrals(
            atoms1, bonds1)

        bond_error = 0.0
        for i in range(len(bonds0)):
            bond_error += abs(bonds0[i].d - bonds1[i].d)

        angles0.sort(key=lambda a: tuple([n.index for n in a.atoms]))
        angles1.sort(key=lambda a: tuple([n.index for n in a.atoms]))

        angle_error = 0.0
        for i in range(len(angles0)):
            d0 = utils.dist(angles0[i].atoms[0], angles0[i].atoms[2])
            d1 = utils.dist(angles1[i].atoms[0], angles1[i].atoms[2])
            angle_error += abs(d0 - d1)

        dihedrals0.sort(key=lambda a: tuple([n.index for n in a.atoms]))
        dihedrals1.sort(key=lambda a: tuple([n.index for n in a.atoms]))

        if dihedrals0:
            dihedral_error = 0.0
            for i in range(len(dihedrals0)):
                #if dihedral is single-bonded free rotor, ignore comparison
                if (dihedrals0[i].atoms[1].type.index,
                        dihedrals0[i].atoms[1].type.index) == (78, 78):
                    continue
                d0 = utils.dist(dihedrals0[i].atoms[0], dihedrals0[i].atoms[3])
                d1 = utils.dist(dihedrals1[i].atoms[0], dihedrals1[i].atoms[3])
                dihedral_error += abs(d0 - d1)

            print f, bond_error / len(bonds0), angle_error / len(
                angles0), 180 / math.pi * dihedral_error / len(dihedrals0)
        else:
            print f, bond_error / len(bonds0), angle_error / len(angles0), 0.0
Example #2
0
def minimize():
    #for f in ['propanenitrile', 'butanenitrile', 'pentanenitrile', 'hexanenitrile', 'aminopropane2', 'aminobutane2', 'aminopentane2', 'aminohexane2', 'hexane2', 'methane']:
    for f in [
            'hcn34', 'cyanoacetylene34', 'acrylonitrile34', 'cyanoallene34',
            'acetonitrile34', 'hc5n34'
    ]:
        atoms = utils.Molecule(f + '.arc').atoms
        gaussian.job(atoms,
                     'M062X/aug-cc-pVDZ',
                     'batch',
                     f + '_0',
                     'Opt',
                     procs=1)
        gaussian.job(atoms,
                     'M062X/aug-cc-pVDZ',
                     'batch',
                     f + '_1',
                     'Opt SCRF(Solvent=n-Hexane)',
                     procs=1)
Example #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('..')
Example #4
0
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('..')
Example #5
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('..')
Example #6
0
def compare():
    utils.Molecule.set_params('oplsaa4.prm')
    for f in [
            'propanenitrile', 'butanenitrile', 'pentanenitrile',
            'hexanenitrile', 'aminopropane2', 'aminobutane2', 'aminopentane2',
            'aminohexane2', 'hexane2', 'methane', 'hcn2', 'cyanoacetylene2',
            'acrylonitrile2', 'cyanoallene2', 'acetonitrile2', 'hc5n2'
    ]:
        atoms0 = utils.Molecule(f + '.arc').atoms
        atoms1 = gaussian.parse_atoms('gaussian/' + f + '_0.log')[1]
        for i in range(len(atoms0)):
            atoms0[i].index = i + 1
            atoms1[i].index = i + 1

            #atoms0[i].x = atoms1[i].xp
            #atoms0[i].y = atoms1[i].y
            #atoms0[i].z = atoms1[i].z

        bonds0 = filetypes.get_bonds(atoms0)
        bonds1 = filetypes.get_bonds(atoms1)

        #filetypes.write_arc(f[:-1]+'3', atoms0)
        #continue

        angles0, dihedrals0 = filetypes.get_angles_and_dihedrals(
            atoms0, bonds0)
        angles1, dihedrals1 = filetypes.get_angles_and_dihedrals(
            atoms1, bonds1)

        bond_error = 0.0
        for i in range(len(bonds0)):
            bond_error += abs(bonds0[i].d - bonds1[i].d)

        angles0.sort(key=lambda a: tuple([n.index for n in a.atoms]))
        angles1.sort(key=lambda a: tuple([n.index for n in a.atoms]))

        angle_error = 0.0
        for i in range(len(angles0)):
            angle_error += min(
                abs(angles0[i].theta - angles1[i].theta),
                abs(angles0[i].theta - angles1[i].theta + math.pi * 2),
                abs(angles0[i].theta - angles1[i].theta - math.pi * 2))

        dihedrals0.sort(key=lambda a: tuple([n.index for n in a.atoms]))
        dihedrals1.sort(key=lambda a: tuple([n.index for n in a.atoms]))

        angles_by_atoms = {}
        for angle in angles1:
            angles_by_atoms[tuple(angle.atoms)] = angle
            angles_by_atoms[tuple(reversed(angle.atoms))] = angle

        if dihedrals0:
            dihedral_error = 0.0
            for i in range(len(dihedrals0)):
                #if dihedral only controls a 180-degree angle, ignore comparison

                angle1 = angles_by_atoms[tuple(dihedrals1[i].atoms[1:])]
                angle2 = angles_by_atoms[tuple(dihedrals1[i].atoms[:-1])]

                #print angle1.theta, angle2.theta,

                if abs(angle1.theta -
                       180) < 2 or abs(angle1.theta + 180) < 2 or abs(
                           angle2.theta - 180) < 2 or abs(angle2.theta +
                                                          180) < 2:
                    #print angle1.theta, angle2.theta,
                    continue

                #if dihedral is single-bonded free rotor, ignore comparison
                if (dihedrals0[i].atoms[1].type.index,
                        dihedrals0[i].atoms[1].type.index) == (78, 78):
                    continue
                #else make comparison
                try:
                    a, b = utils.dihedral_angle(
                        *dihedrals0[i].atoms)[0], utils.dihedral_angle(
                            *dihedrals1[i].atoms)[0]
                    dihedral_error += min(abs(a - b), abs(a - b + math.pi * 2),
                                          abs(a - b - math.pi * 2))

                    #print [aa.element for aa in dihedrals0[i].atoms], min( abs(a-b), abs(a-b+math.pi*2), abs(a-b-math.pi*2) )
                except ZeroDivisionError:
                    pass

            print f, bond_error / len(bonds0), angle_error / len(
                angles0), 180 / math.pi * dihedral_error / len(dihedrals0)
        else:
            print f, bond_error / len(bonds0), angle_error / len(angles0), 0.0
import os, copy, sys, random, cPickle, math
sys.path.append("/fs/home/jms875/build/lammps/lammps-15May15/python")
from lammps import lammps
sys.path.append("/fs/home/jms875/Library/2.0")
import utils, files

system = utils.System(box_size=(30., 30., 30.), name='test4')

THF = utils.Molecule('cml/THF')

molecules = [THF]
molecule_ratio = [1]
density = 0.889

files.packmol(system, molecules, molecule_ratio, density)

os.chdir('lammps')
files.write_lammps_data(system)

commands = ('''units real
atom_style full
pair_style lj/cut/coul/long 10.0
bond_style harmonic
angle_style harmonic
dihedral_style opls
special_bonds lj/coul 0.0 0.0 0.5

read_data	''' + system.name + '''.data
kspace_style pppm 1.0e-4

thermo_style custom density tpcpu