General Tutorial

This is an introductory tutorial for the python package currently called kappa. We will build molecules, draw them, and look at their attributes.

First we must import the package.


In [ ]:
#put matplotlib plots in the notebook, then import the package
%matplotlib inline 
import kappa

As it stands users must define a forcefield before building molecules. We will establish an Amber forcefield. We can turn interactions in the forcefield on and off, but we won't concern ourselves with that here.


In [ ]:
amber = kappa.Amber()

To build molecules, users call the build function. To see the kinds of molecules available for generation, print kappa.lattices.


In [ ]:
print(kappa.lattices)

We'll build our bread and butter molecule first, an armchair carbon nanotube. Every molecule generated through kappa.build requires a forcefield argument then a lattice string found from kappa.lattices.


In [ ]:
cnt = kappa.build(amber, "cnt")

We can plot our molecules too. This plot routine will show the bonds.


In [ ]:
kappa.plot.bonds(cnt)

Attributes of the molecules include, but are not limited to: posList, bondList, angleList, atomtypes. We'll show this off in a smaller molecule.


In [ ]:
graphene = kappa.build(amber, "graphene", radius=2)

kappa.plot.bonds(graphene, indices=True)

# print(graphene.posList)
print(graphene.bondList)
print(graphene.angleList)
print(graphene.atomtypes)

Molecule.atomtypes comes from its forcefield.

Now let's generate the lines of a .pdb text file. The .pdb format holds topology information critical for runnning Molecular Dynamics (MD) simulations. GROMACS specifically uses this file type, but others like openMM are compatible as well.

To view a PDB structure, you need a tool such as VMD (recommended) or PyMOL, both free.

First though we should add hydrogens to the ends of the CNT so no C's have just a single bond.


In [ ]:
cnt.hydrogenate()
pdb_txt = kappa.md.generate.pdb(cnt)

pdb_txt holds a list with each element a line string for the file. Let's write this to the current directory.


In [ ]:
kappa.md.save_file(pdb_txt,'.','cnt.pdb')

Let's give that graphene a shot too.


In [ ]:
pdb_txt = kappa.md.generate.pdb(graphene)
kappa.md.save_file(pdb_txt,'.','graphene.pdb')

We can also export .gro files, which contain topology + box size info (recommended).


In [ ]:
gro_txt = kappa.md.generate.gro(cnt)
kappa.md.save_file(gro_txt,'.','cnt.gro')

In [ ]: