Functionality

NWChem input file

STREAMM creates input files by replacing keys in a template with the values of the same keys of the properties dictionary of the Calculation. Accordingly, we first need some basic templates provided in the Github repository http://github.com/NREL/streamm-tools. If you are running this example in the examples directory in the streamm-tools repository, the TEMPLATE_DIR should look like this

EXAMPLE_DIR = os.getcwd()
print(EXAMPLE_DIR)
TEMPLATE_DIR =  os.path.join(EXAMPLE_DIR,'..','templates','')
print(TEMPLATE_DIR)

If not please set the TEMPLATE_DIR variable to the location of the templates

We will use the basic nwchem.nw example template

template_file = 'nwchem.nw'

Create a NWChem Calculation object

nwchem = streamm.NWChem('ethane_nw_sp')

Set the structure of the calculation to the ethane object from Getting started.

nwchem.strucC = ethane

Get the location of the template file

template_path =  os.path.join(TEMPLATE_DIR,template_file)

print template_path

Read in the template

template_line = nwchem.read_lines(template_path)

Set the properties dictionary to contain the information for our Calculation

nwchem.properties['basis'] = '6-31g'
nwchem.properties['method'] = 'UHF'
nwchem.properties['charge'] = 0
nwchem.properties['spin_mult'] = 1
nwchem.properties['task'] = 'SCF '
nwchem.properties['coord'] = nwchem.strucC.write_coord()

Do a string replace of the dictionary keys to create an input string

input_str = nwchem.replace_keys(template_line,nwchem.properties)

Finally, write out the file.

file_name = '%s.nw'%(nwchem.tag)
with open(file_name,"w") as F:
    F.write(input_str)

LAMMPS input file

Setting Parameters

If we want to run some MD using force fields, we need to set up a Parameters container.

oplsaa = streamm.Parameters('oplsaa')

Let’s set the energy and length units we will input from the literature.

oplsaa.update_units({'energy':'kCalmol','length':'ang'})

Add some Particletype objects to our Parameters container and pass in the units_conf we are using.

CT = streamm.Particletype('CT',unit_conf=oplsaa.unit_conf)
CT.epsilon = 0.066 # kcal/mol
CT.sigma = 3.5 # Angstroms
CT.mass = 12.0107
oplsaa.add_particletype(CT)
HC = streamm.Particletype('HC',unit_conf=oplsaa.unit_conf)
HC.epsilon = 0.03 # kcal/mol
HC.sigma = 2.5 # Angstroms
HC.mass = 1.00794
oplsaa.add_particletype(HC)

Add some Bondtype, Angletype, and Dihedraltype objects.

C_H = streamm.Bondtype('CT','HC',unit_conf=oplsaa.unit_conf)
C_H.setharmonic(1.080,367.0)
oplsaa.add_bondtype(C_H)

C_C = streamm.Bondtype('CT','CT',unit_conf=oplsaa.unit_conf)
C_C.setharmonic(1.080,367.0)
oplsaa.add_bondtype(C_C)

H_C_H = streamm.Angletype('HC','CT','HC',unit_conf=oplsaa.unit_conf)
H_C_H.setharmonic(110.7,37.50)
oplsaa.add_angletype(H_C_H)

H_C_C = streamm.Angletype('HC','CT','CT',unit_conf=oplsaa.unit_conf)
H_C_C.setharmonic(90.7,60.50)
oplsaa.add_angletype(H_C_C)

Setting paramkeys

Now we need to set the paramkeys of each particle in the ethane Buildingblock we created in the Getting started section to have a key matching a Particletype key.

for pk,p in ethane.particles.iteritems():
    if( p.symbol == 'C' ):
        p.paramkey = 'CT'
    elif( p.symbol == 'H' ):
        p.paramkey = 'HC'

Create LAMMPS Calculation

If we want to run a LAMMPS simulation, we can create a Calculation object.

md_calc = streamm.LAMMPS('ethane_md')

Set our Buildingblock and Parameters objects to have the correct units for a LAMMPS simulation and add them to the Calculation object.

ethane.update_units(md_calc.unit_conf)
oplsaa.update_units(md_calc.unit_conf)
md_calc.strucC = ethane
md_calc.paramC = oplsaa

Find Molecular Connections

Next, we need to find all the Bonds, bond angles and dihedrals of the Buildingblock, using the bonded neighbor list.

md_calc.strucC.bonded_bonds()
md_calc.strucC.bonded_angles()
md_calc.strucC.bonded_dih()

Then we can use the set_ffparam function to match all the force field parameters to the Buildingblock based on their paramkeys.

md_calc.set_ffparam()

Finally, we can output a LAMMPS .data input file for our calculation.

md_calc.write_data()

You could also write out input files for our LAMMPS simulation using templates if you wished.