add integration testing for python module
This commit is contained in:
18
test/lib_python/Makefile
Normal file
18
test/lib_python/Makefile
Normal file
@ -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.*
|
||||
|
||||
27
test/lib_python/in.simple
Normal file
27
test/lib_python/in.simple
Normal file
@ -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
|
||||
32
test/lib_python/in.simple-001.py
Executable file
32
test/lib_python/in.simple-001.py
Executable file
@ -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]
|
||||
|
||||
Reference in New Issue
Block a user