diff --git a/test/Makefile b/test/Makefile index 750239bd0..88f6cdcfb 100644 --- a/test/Makefile +++ b/test/Makefile @@ -1,14 +1,21 @@ # Hey emacs, this is a -*- Makefile -*- ! SHELL=/bin/sh DIRS=$(wildcard [0-9]*) EXE=../src/lmp_$(MACH) +LIB=../src/liblammps_$(MACH).so default: @echo Run tests with "make test MACH=<build make target> MPICMD=<MPI launch command> LMPFLAGS=<additional flags for LAMMPS>" test: $(EXE) for dir in $(DIRS); do cd $$dir ; $(MAKE) $(MFLAGS) MACH=$(MACH) MPICMD="$(MPICMD)" LMPFLAGS="$(LMPFLAGS)" test || exit 1; cd ..; done +python: lib_python/lammps.py lib_python/liblammps.so $(LIB) + for dir in lib_python; do cd $$dir ; $(MAKE) $(MFLAGS) MACH=$(MACH) MPICMD="$(MPICMD)" LMPFLAGS="$(LMPFLAGS)" test || exit 1; cd ..; done + +lib_python/lammps.py lib_python/liblammps.so : ../python/install.py ../python/lammps.py $(LIB) + python ../python/install.py $(PWD)/lib_python + clean: - for dir in $(DIRS); do cd $$dir ; $(MAKE) $(MFLAGS) clean; cd ..; done + for dir in $(DIRS) lib_python; do cd $$dir ; $(MAKE) $(MFLAGS) clean; cd ..; done diff --git a/test/lib_python/Makefile b/test/lib_python/Makefile new file mode 100644 index 000000000..a7830477e --- /dev/null +++ b/test/lib_python/Makefile @@ -0,0 +1,18 @@ +# Hey emacs, this is a -*- Makefile -*- ! +SHELL=/bin/sh +INPUTS=$(wildcard in.*.py) +OUTPUTS=$(INPUTS:in.%.py=log.%-$(MACH)$(TAG)) +LIB=liblammps.so lammps.py + +default: + @echo Run tests with "make test MACH=<build make target> MPICMD=<MPI launch command> LMPFLAGS=<additional flags for LAMMPS>" + +test: $(LIB) $(OUTPUTS) + +log.%-$(MACH)$(TAG): in.%.py $(LIB) + $(MPICMD) python $(LMPFLAGS) $< + mv log.lammps $@ + +clean: + -rm -f log.* + diff --git a/test/lib_python/in.simple b/test/lib_python/in.simple new file mode 100644 index 000000000..977a84254 --- /dev/null +++ b/test/lib_python/in.simple @@ -0,0 +1,27 @@ +# 3d Lennard-Jones melt + +units lj +timer off +atom_style atomic +atom_modify map array + +lattice fcc 0.8442 +region box block 0 4 0 4 0 4 +create_box 1 box +create_atoms 1 box +mass 1 1.0 + +velocity all create 1.44 87287 loop geom + +pair_style lj/cut 2.5 +pair_coeff 1 1 1.0 1.0 2.5 + +neighbor 0.3 bin +neigh_modify delay 0 every 20 check no + +fix 1 all nve + +variable fx atom fx + +run 10 +info all diff --git a/test/lib_python/in.simple-001.py b/test/lib_python/in.simple-001.py new file mode 100755 index 000000000..b5d29c942 --- /dev/null +++ b/test/lib_python/in.simple-001.py @@ -0,0 +1,32 @@ +#!/usr/bin/env python -i +# preceeding line should have path for Python on your machine + +# simple.py +# Purpose: mimic operation of couple/simple/simple.cpp via Python +# Syntax: simple.py in.lammps +# in.lammps = LAMMPS input script + +infile = 'in.simple' +me = 0 + +from lammps import lammps +lmp = lammps(cmdargs=['-echo','screen']) + +# run infile one line at a time + +lines = open(infile,'r').readlines() +for line in lines: lmp.command(line) + +lmp.command("run 10") +x = lmp.gather_atoms("x",1,3) +epsilon = 0.1 +x[0] += epsilon +lmp.scatter_atoms("x",1,3,x) +lmp.command("run 1"); + +f = lmp.extract_atom("f",3) +print "Force on 1 atom via extract_atom: ",f[0][0] + +fx = lmp.extract_variable("fx","all",1) +print "Force on 1 atom via extract_variable:",fx[0] +