forked from lijiext/lammps
Allow 'set' command to change atom velocities
This commit is contained in:
parent
6dfb74f23e
commit
d00eaef070
|
@ -708,6 +708,12 @@ class Atom(object):
|
|||
self.lmp.eval("vy[%d]" % self.index),
|
||||
self.lmp.eval("vz[%d]" % self.index))
|
||||
|
||||
@velocity.setter
|
||||
def velocity(self, value):
|
||||
self.lmp.set("atom", self.index, "vx", value[0])
|
||||
self.lmp.set("atom", self.index, "vy", value[1])
|
||||
self.lmp.set("atom", self.index, "vz", value[2])
|
||||
|
||||
@property
|
||||
def force(self):
|
||||
return (self.lmp.eval("fx[%d]" % self.index),
|
||||
|
@ -738,6 +744,11 @@ class Atom2D(Atom):
|
|||
return (self.lmp.eval("vx[%d]" % self.index),
|
||||
self.lmp.eval("vy[%d]" % self.index))
|
||||
|
||||
@velocity.setter
|
||||
def velocity(self, value):
|
||||
self.lmp.set("atom", self.index, "vx", value[0])
|
||||
self.lmp.set("atom", self.index, "vy", value[1])
|
||||
|
||||
@property
|
||||
def force(self):
|
||||
return (self.lmp.eval("fx[%d]" % self.index),
|
||||
|
|
26
src/set.cpp
26
src/set.cpp
|
@ -48,7 +48,7 @@ enum{TYPE,TYPE_FRACTION,MOLECULE,X,Y,Z,CHARGE,MASS,SHAPE,LENGTH,TRI,
|
|||
THETA,THETA_RANDOM,ANGMOM,OMEGA,
|
||||
DIAMETER,DENSITY,VOLUME,IMAGE,BOND,ANGLE,DIHEDRAL,IMPROPER,
|
||||
MESO_E,MESO_CV,MESO_RHO,EDPD_TEMP,EDPD_CV,CC,SMD_MASS_DENSITY,
|
||||
SMD_CONTACT_RADIUS,DPDTHETA,INAME,DNAME};
|
||||
SMD_CONTACT_RADIUS,DPDTHETA,INAME,DNAME,VX,VY,VZ};
|
||||
|
||||
#define BIG INT_MAX
|
||||
|
||||
|
@ -141,6 +141,27 @@ void Set::command(int narg, char **arg)
|
|||
set(Z);
|
||||
iarg += 2;
|
||||
|
||||
} else if (strcmp(arg[iarg],"vx") == 0) {
|
||||
if (iarg+2 > narg) error->all(FLERR,"Illegal set command");
|
||||
if (strstr(arg[iarg+1],"v_") == arg[iarg+1]) varparse(arg[iarg+1],1);
|
||||
else dvalue = force->numeric(FLERR,arg[iarg+1]);
|
||||
set(VX);
|
||||
iarg += 2;
|
||||
|
||||
} else if (strcmp(arg[iarg],"vy") == 0) {
|
||||
if (iarg+2 > narg) error->all(FLERR,"Illegal set command");
|
||||
if (strstr(arg[iarg+1],"v_") == arg[iarg+1]) varparse(arg[iarg+1],1);
|
||||
else dvalue = force->numeric(FLERR,arg[iarg+1]);
|
||||
set(VY);
|
||||
iarg += 2;
|
||||
|
||||
} else if (strcmp(arg[iarg],"vz") == 0) {
|
||||
if (iarg+2 > narg) error->all(FLERR,"Illegal set command");
|
||||
if (strstr(arg[iarg+1],"v_") == arg[iarg+1]) varparse(arg[iarg+1],1);
|
||||
else dvalue = force->numeric(FLERR,arg[iarg+1]);
|
||||
set(VZ);
|
||||
iarg += 2;
|
||||
|
||||
} else if (strcmp(arg[iarg],"charge") == 0) {
|
||||
if (iarg+2 > narg) error->all(FLERR,"Illegal set command");
|
||||
if (strstr(arg[iarg+1],"v_") == arg[iarg+1]) varparse(arg[iarg+1],1);
|
||||
|
@ -732,6 +753,9 @@ void Set::set(int keyword)
|
|||
else if (keyword == X) atom->x[i][0] = dvalue;
|
||||
else if (keyword == Y) atom->x[i][1] = dvalue;
|
||||
else if (keyword == Z) atom->x[i][2] = dvalue;
|
||||
else if (keyword == VX) atom->v[i][0] = dvalue;
|
||||
else if (keyword == VY) atom->v[i][1] = dvalue;
|
||||
else if (keyword == VZ) atom->v[i][2] = dvalue;
|
||||
else if (keyword == CHARGE) atom->q[i] = dvalue;
|
||||
else if (keyword == MASS) {
|
||||
if (dvalue <= 0.0) error->one(FLERR,"Invalid mass in set command");
|
||||
|
|
Loading…
Reference in New Issue