add example for Python with vector-style variable

This commit is contained in:
Steve Plimpton
2025-05-20 13:33:36 -06:00
parent 2351418c94
commit 37a344a2ad
6 changed files with 596 additions and 77 deletions

View File

@ -1,9 +1,9 @@
# 3d Lennard-Jones melt with equal- and atom-style variables which
# use a Python function wrapper in their formulas
variable x index 5
variable y index 5
variable z index 5
variable x index 3
variable y index 3
variable z index 3
units lj
atom_style atomic
@ -24,21 +24,37 @@ neigh_modify delay 0 every 20 check no
fix 1 all nve
# define Python truncate() function
variable foo python truncate
python truncate return v_foo input 1 iv_arg format fi here """
def truncate(x):
return int(x)
"""
# use in equal-style variable
variable scalar equal py_foo(4.5)
print "TRUNCATE ${scalar}"
# use in atom-style variable
# examine dump file to see truncated xyz coords of each atom
variable xtrunc atom py_foo(x)
variable ytrunc atom py_foo(y)
variable ztrunc atom py_foo(z)
# examine dump file to see truncated xyz coords of each atom
dump 1 all custom 100 tmp.dump id x y z v_xtrunc v_ytrunc v_ztrunc
# use in vector-style variable
compute ke all temp
variable ke vector c_ke
variable ketrunc vector py_foo(v_ke)
thermo_style custom step temp epair v_ketrunc[*6]
run 100
print "KE TENSOR ${ketrunc}"