LAMMPS WWW Site - LAMMPS Documentation - LAMMPS Mailing List Archives
[lammps-users] multiple instances of lammps in python
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lammps-users] multiple instances of lammps in python

From: Gideon Simpson <gideon.simpson@...24...>
Date: Sat, 11 Nov 2017 12:17:13 -0800

I am trying to test out some algorithmic ideas using lammps for forces/energies within python, and I’m encountering the following issue that I do not entirely know how to resolve.

My code layout is as follows:

# Problem setup

import numpy as np
from lammps import lammps
#from ctypes import *

lmp = lammps()
lmp2 = lammps()


natoms = lmp.get_natoms()

# Create two numpy wrappers for positions and forces for easy access/manipuliton
X = np.ctypeslib.as_array(lmp.extract_atom("x",3).contents,shape=(natoms,3))
F = np.ctypeslib.as_array(lmp.extract_atom("f",3).contents,shape=(natoms,3))

X2 = np.ctypeslib.as_array(lmp2.extract_atom("x",3).contents,shape=(natoms,3))
F2 = np.ctypeslib.as_array(lmp2.extract_atom("f",3).contents,shape=(natoms,3))

# run some standard lammps code (i.e., with a standard fix) for some number of time steps
# not reproduced here

# As a first test, I will try copying over the current configuration, stored in X, and quench it 
# to inspect the minimized state
X2 = np.copy(X)
lmp2.command("run 0")
lmp2.command("min_style cg")
lmp2.command("minimize 1.e-14 1.e-14 1000 1000")

It is at this point that I am encountering my “problem."  I would have thought X2 now held the quenched 
positions.  But the values in X2 are unchanged.  The forces associated with lmp2, stored in F2, are altered
and are close to zero, as expected.