LAMMPS can be run interactively using iPython easily. This tutorial shows how to set this up.
$LAMMPS_DIR
from now on)Compile LAMMPS as a shared library and enable PNG support
cd $LAMMPS_DIR/src
python2 Make.py -m mpi -png -a file
make mode=shlib auto
Create a python virtualenv
virtualenv testing
source testing/bin/activate
Inside the virtualenv install the lammps package
(testing) cd $LAMMPS_DIR/python
(testing) python install.py
(testing) cd # move to your working directory
Install jupyter and ipython in the virtualenv
(testing) pip install ipython jupyter
Run jupyter notebook
(testing) jupyter notebook
In [1]:
from lammps import IPyLammps
In [2]:
L = IPyLammps()
In [3]:
# 3d Lennard-Jones melt
L.units("lj")
L.atom_style("atomic")
L.atom_modify("map array")
L.lattice("fcc", 0.8442)
L.region("box block", 0, 4, 0, 4, 0, 4)
L.create_box(1, "box")
L.create_atoms(1, "box")
L.mass(1, 1.0)
L.velocity("all create", 1.44, 87287, "loop geom")
L.pair_style("lj/cut", 2.5)
L.pair_coeff(1, 1, 1.0, 1.0, 2.5)
L.neighbor(0.3, "bin")
L.neigh_modify("delay 0 every 20 check no")
L.fix("1 all nve")
L.variable("fx atom fx")
L.run(10)
Out[3]:
In [4]:
L.image(zoom=1)
Out[4]:
In [5]:
L.system
Out[5]:
In [6]:
L.system.natoms
Out[6]:
In [7]:
L.communication
Out[7]:
In [8]:
L.fixes
Out[8]:
In [9]:
L.computes
Out[9]:
In [10]:
L.dumps
Out[10]:
In [11]:
L.groups
Out[11]:
In [12]:
L.variable("a index 2")
In [13]:
L.variables
Out[13]:
In [14]:
L.variable("t equal temp")
In [15]:
L.variables
Out[15]:
In [16]:
import sys
if sys.version_info < (3, 0):
# In Python 2 'print' is a restricted keyword, which is why you have to use the lmp_print function instead.
x = float(L.lmp_print('"${a}"'))
else:
# In Python 3 the print function can be redefined.
# x = float(L.print('"${a}"')")
# To avoid a syntax error in Python 2 executions of this notebook, this line is packed into an eval statement
x = float(eval("L.print('\"${a}\"')"))
x
Out[16]:
In [17]:
L.variables['t'].value
Out[17]:
In [18]:
L.eval("v_t/2.0")
Out[18]:
In [19]:
L.variable("b index a b c")
In [20]:
L.variables['b'].value
Out[20]:
In [21]:
L.eval("v_b")
Out[21]:
In [22]:
L.variables['b'].definition
Out[22]:
In [23]:
L.variable("i loop 10")
In [24]:
L.variables['i'].value
Out[24]:
In [25]:
L.next("i")
L.variables['i'].value
Out[25]:
In [26]:
L.eval("ke")
Out[26]:
In [27]:
L.atoms[0]
Out[27]:
In [28]:
[x for x in dir(L.atoms[0]) if not x.startswith('__')]
Out[28]:
In [29]:
L.atoms[0].position
Out[29]:
In [30]:
L.atoms[0].id
Out[30]:
In [31]:
L.atoms[0].velocity
Out[31]:
In [32]:
L.atoms[0].force
Out[32]:
In [33]:
L.atoms[0].type
Out[33]:
In [34]:
L.variables['fx'].value
Out[34]:
In [ ]: