Revert "Rename fix python/move to move/python"

This reverts commit 4d915dba08.
This commit is contained in:
Richard Berger
2017-12-15 13:17:12 -05:00
parent 1b07a4edee
commit 4d725c3153
5 changed files with 50 additions and 47 deletions

View File

@ -1,16 +1,16 @@
This folder contains several LAMMPS input scripts and a python module This folder contains several LAMMPS input scripts and a python module
file py_nve.py to demonstrate the use of the fix style move/python file py_nve.py to demonstrate the use of the fix style python/move
to reimplement NVE using Python. to reimplement NVE using Python.
in.fix_move_python_nve_melt: in.fix_python_nve_melt:
This is a version of the melt example which replaces the default NVE integrator This is a version of the melt example which replaces the default NVE integrator
with a Python implementation. Fix move/python is used to create an with a Python implementation. Fix python/move is used to create an
instance of the py_nve.NVE class which implements the required interface. instance of the py_nve.NVE class which implements the required interface.
It demonstrates how to access LAMMPS data as numpy arrays. This gives direct It demonstrates how to access LAMMPS data as numpy arrays. This gives direct
access to memory owned by the C++ code, allows easy manipulation through numpy access to memory owned by the C++ code, allows easy manipulation through numpy
operations and avoids unnecessary copies. operations and avoids unnecessary copies.
in.fix_move_python_nve_melt_opt: in.fix_python_nve_melt_opt:
This version of melt example uses NVE_Opt instead of NVE. While this Python This version of melt example uses NVE_Opt instead of NVE. While this Python
implementation is still much slower than the native version, it shows that implementation is still much slower than the native version, it shows that
simple code transformations can lead to speedups. simple code transformations can lead to speedups.

View File

@ -17,7 +17,7 @@ pair_coeff 1 1 1.0 1.0 2.5
neighbor 0.3 bin neighbor 0.3 bin
neigh_modify every 20 delay 0 check no neigh_modify every 20 delay 0 check no
fix 1 all move/python py_nve.NVE fix 1 all python/move py_nve.NVE
thermo 50 thermo 50
run 250 run 250

View File

@ -17,7 +17,7 @@ pair_coeff 1 1 1.0 1.0 2.5
neighbor 0.3 bin neighbor 0.3 bin
neigh_modify every 20 delay 0 check no neigh_modify every 20 delay 0 check no
fix 1 all move/python py_nve.NVE_Opt fix 1 all python/move py_nve.NVE_Opt
thermo 50 thermo 50
run 250 run 250

View File

@ -19,7 +19,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include "fix_move_python.h" #include "fix_python_move.h"
#include "atom.h" #include "atom.h"
#include "comm.h" #include "comm.h"
#include "force.h" #include "force.h"
@ -34,7 +34,7 @@ using namespace FixConst;
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
FixMovePython::FixMovePython(LAMMPS *lmp, int narg, char **arg) : FixPythonMove::FixPythonMove(LAMMPS *lmp, int narg, char **arg) :
Fix(lmp, narg, arg) Fix(lmp, narg, arg)
{ {
dynamic_group_allow = 1; dynamic_group_allow = 1;
@ -42,7 +42,7 @@ FixMovePython::FixMovePython(LAMMPS *lmp, int narg, char **arg) :
python->init(); python->init();
py_move = NULL; py_integrator = NULL;
PyGILState_STATE gstate = PyGILState_Ensure(); PyGILState_STATE gstate = PyGILState_Ensure();
@ -51,12 +51,12 @@ FixMovePython::FixMovePython(LAMMPS *lmp, int narg, char **arg) :
PyList_Append(py_path, PY_STRING_FROM_STRING(".")); PyList_Append(py_path, PY_STRING_FROM_STRING("."));
// create move instance // create integrator instance
char * full_cls_name = arg[3]; char * full_cls_name = arg[3];
char * lastpos = strrchr(full_cls_name, '.'); char * lastpos = strrchr(full_cls_name, '.');
if (lastpos == NULL) { if (lastpos == NULL) {
error->all(FLERR,"Fix move/python requires fully qualified class name"); error->all(FLERR,"Fix python/integrate requires fully qualified class name");
} }
size_t module_name_length = strlen(full_cls_name) - strlen(lastpos); size_t module_name_length = strlen(full_cls_name) - strlen(lastpos);
@ -74,15 +74,18 @@ FixMovePython::FixMovePython(LAMMPS *lmp, int narg, char **arg) :
PyErr_Print(); PyErr_Print();
PyErr_Clear(); PyErr_Clear();
PyGILState_Release(gstate); PyGILState_Release(gstate);
error->all(FLERR,"Loading python move module failure"); error->all(FLERR,"Loading python integrator module failure");
} }
PyObject *py_move_type = PyObject_GetAttrString(pModule, cls_name); // create LAMMPS atom type to potential file type mapping in python class
if (!py_move_type) { // by calling 'lammps_pair_style.map_coeff(name,type)'
PyObject *py_integrator_type = PyObject_GetAttrString(pModule, cls_name);
if (!py_integrator_type) {
PyErr_Print(); PyErr_Print();
PyErr_Clear(); PyErr_Clear();
PyGILState_Release(gstate); PyGILState_Release(gstate);
error->all(FLERR,"Could not find move class in module'"); error->all(FLERR,"Could not find integrator class in module'");
} }
delete [] module_name; delete [] module_name;
@ -90,34 +93,34 @@ FixMovePython::FixMovePython(LAMMPS *lmp, int narg, char **arg) :
PyObject * ptr = PY_VOID_POINTER(lmp); PyObject * ptr = PY_VOID_POINTER(lmp);
PyObject * arglist = Py_BuildValue("(O)", ptr); PyObject * arglist = Py_BuildValue("(O)", ptr);
PyObject * py_move_obj = PyObject_CallObject(py_move_type, arglist); PyObject * py_integrator_obj = PyObject_CallObject(py_integrator_type, arglist);
Py_DECREF(arglist); Py_DECREF(arglist);
if (!py_move_obj) { if (!py_integrator_obj) {
PyErr_Print(); PyErr_Print();
PyErr_Clear(); PyErr_Clear();
PyGILState_Release(gstate); PyGILState_Release(gstate);
error->all(FLERR,"Could not instantiate instance of move class'"); error->all(FLERR,"Could not instantiate instance of integrator class'");
} }
// check object interface // check object interface
py_move = (void *) py_move_obj; py_integrator = (void *) py_integrator_obj;
PyGILState_Release(gstate); PyGILState_Release(gstate);
} }
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
FixMovePython::~FixMovePython() FixPythonMove::~FixPythonMove()
{ {
PyGILState_STATE gstate = PyGILState_Ensure(); PyGILState_STATE gstate = PyGILState_Ensure();
if(py_move) Py_DECREF((PyObject*) py_move); if(py_integrator) Py_DECREF((PyObject*) py_integrator);
PyGILState_Release(gstate); PyGILState_Release(gstate);
} }
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
int FixMovePython::setmask() int FixPythonMove::setmask()
{ {
int mask = 0; int mask = 0;
mask |= INITIAL_INTEGRATE; mask |= INITIAL_INTEGRATE;
@ -129,11 +132,11 @@ int FixMovePython::setmask()
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
void FixMovePython::init() void FixPythonMove::init()
{ {
PyGILState_STATE gstate = PyGILState_Ensure(); PyGILState_STATE gstate = PyGILState_Ensure();
PyObject *py_move_obj = (PyObject *) py_move; PyObject *py_integrator_obj = (PyObject *) py_integrator;
PyObject *py_init = PyObject_GetAttrString(py_move_obj,"init"); PyObject *py_init = PyObject_GetAttrString(py_integrator_obj,"init");
if (!py_init) { if (!py_init) {
PyErr_Print(); PyErr_Print();
PyErr_Clear(); PyErr_Clear();
@ -146,11 +149,11 @@ void FixMovePython::init()
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
void FixMovePython::initial_integrate(int vflag) void FixPythonMove::initial_integrate(int vflag)
{ {
PyGILState_STATE gstate = PyGILState_Ensure(); PyGILState_STATE gstate = PyGILState_Ensure();
PyObject *py_move_obj = (PyObject *) py_move; PyObject *py_integrator_obj = (PyObject *) py_integrator;
PyObject *py_initial_integrate = PyObject_GetAttrString(py_move_obj,"initial_integrate"); PyObject *py_initial_integrate = PyObject_GetAttrString(py_integrator_obj,"initial_integrate");
if (!py_initial_integrate) { if (!py_initial_integrate) {
PyErr_Print(); PyErr_Print();
PyErr_Clear(); PyErr_Clear();
@ -165,11 +168,11 @@ void FixMovePython::initial_integrate(int vflag)
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
void FixMovePython::final_integrate() void FixPythonMove::final_integrate()
{ {
PyGILState_STATE gstate = PyGILState_Ensure(); PyGILState_STATE gstate = PyGILState_Ensure();
PyObject *py_move_obj = (PyObject *) py_move; PyObject *py_integrator_obj = (PyObject *) py_integrator;
PyObject *py_final_integrate = PyObject_GetAttrString(py_move_obj,"final_integrate"); PyObject *py_final_integrate = PyObject_GetAttrString(py_integrator_obj,"final_integrate");
if (!py_final_integrate) { if (!py_final_integrate) {
PyErr_Print(); PyErr_Print();
PyErr_Clear(); PyErr_Clear();
@ -182,11 +185,11 @@ void FixMovePython::final_integrate()
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
void FixMovePython::initial_integrate_respa(int vflag, int ilevel, int iloop) void FixPythonMove::initial_integrate_respa(int vflag, int ilevel, int iloop)
{ {
PyGILState_STATE gstate = PyGILState_Ensure(); PyGILState_STATE gstate = PyGILState_Ensure();
PyObject *py_move_obj = (PyObject *) py_move; PyObject *py_integrator_obj = (PyObject *) py_integrator;
PyObject *py_initial_integrate_respa = PyObject_GetAttrString(py_move_obj,"initial_integrate_respa"); PyObject *py_initial_integrate_respa = PyObject_GetAttrString(py_integrator_obj,"initial_integrate_respa");
if (!py_initial_integrate_respa) { if (!py_initial_integrate_respa) {
PyErr_Print(); PyErr_Print();
PyErr_Clear(); PyErr_Clear();
@ -201,11 +204,11 @@ void FixMovePython::initial_integrate_respa(int vflag, int ilevel, int iloop)
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
void FixMovePython::final_integrate_respa(int ilevel, int iloop) void FixPythonMove::final_integrate_respa(int ilevel, int iloop)
{ {
PyGILState_STATE gstate = PyGILState_Ensure(); PyGILState_STATE gstate = PyGILState_Ensure();
PyObject *py_move_obj = (PyObject *) py_move; PyObject *py_integrator_obj = (PyObject *) py_integrator;
PyObject *py_final_integrate_respa = PyObject_GetAttrString(py_move_obj,"final_integrate_respa"); PyObject *py_final_integrate_respa = PyObject_GetAttrString(py_integrator_obj,"final_integrate_respa");
if (!py_final_integrate_respa) { if (!py_final_integrate_respa) {
PyErr_Print(); PyErr_Print();
PyErr_Clear(); PyErr_Clear();
@ -220,11 +223,11 @@ void FixMovePython::final_integrate_respa(int ilevel, int iloop)
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
void FixMovePython::reset_dt() void FixPythonMove::reset_dt()
{ {
PyGILState_STATE gstate = PyGILState_Ensure(); PyGILState_STATE gstate = PyGILState_Ensure();
PyObject *py_move_obj = (PyObject *) py_move; PyObject *py_integrator_obj = (PyObject *) py_integrator;
PyObject *py_reset_dt = PyObject_GetAttrString(py_move_obj,"reset_dt"); PyObject *py_reset_dt = PyObject_GetAttrString(py_integrator_obj,"reset_dt");
if (!py_reset_dt) { if (!py_reset_dt) {
PyErr_Print(); PyErr_Print();
PyErr_Clear(); PyErr_Clear();

View File

@ -23,21 +23,21 @@
#ifdef FIX_CLASS #ifdef FIX_CLASS
FixStyle(move/python,FixMovePython) FixStyle(python/move,FixPythonMove)
#else #else
#ifndef LMP_FIX_MOVE_PYTHON_H #ifndef LMP_FIX_PYTHON_MOVE_H
#define LMP_FIX_MOVE_PYTHON_H #define LMP_FIX_PYTHON_MOVE_H
#include "fix.h" #include "fix.h"
namespace LAMMPS_NS { namespace LAMMPS_NS {
class FixMovePython : public Fix { class FixPythonMove : public Fix {
public: public:
FixMovePython(LAMMPS *lmp, int narg, char **arg); FixPythonMove(LAMMPS *lmp, int narg, char **arg);
virtual ~FixMovePython(); virtual ~FixPythonMove();
int setmask(); int setmask();
virtual void init(); virtual void init();
@ -48,7 +48,7 @@ class FixMovePython : public Fix {
virtual void reset_dt(); virtual void reset_dt();
protected: protected:
void * py_move; void * py_integrator;
}; };
} }