From 4d725c315322f39bdf77db23a7cfe55d3c164a98 Mon Sep 17 00:00:00 2001 From: Richard Berger <richard.berger@temple.edu> Date: Fri, 15 Dec 2017 13:17:12 -0500 Subject: [PATCH] Revert "Rename fix python/move to move/python" This reverts commit 4d915dba08a9b77a560a2938ac155db3a5699455. --- ...fix_move_python => README.fix_python_move} | 8 +-- ...python_nve_melt => in.fix_python_nve_melt} | 2 +- ...ve_melt_opt => in.fix_python_nve_melt_opt} | 2 +- ...ix_move_python.cpp => fix_python_move.cpp} | 71 ++++++++++--------- .../{fix_move_python.h => fix_python_move.h} | 14 ++-- 5 files changed, 50 insertions(+), 47 deletions(-) rename examples/python/{README.fix_move_python => README.fix_python_move} (77%) rename examples/python/{in.fix_move_python_nve_melt => in.fix_python_nve_melt} (90%) rename examples/python/{in.fix_move_python_nve_melt_opt => in.fix_python_nve_melt_opt} (89%) rename src/PYTHON/{fix_move_python.cpp => fix_python_move.cpp} (73%) rename src/PYTHON/{fix_move_python.h => fix_python_move.h} (87%) diff --git a/examples/python/README.fix_move_python b/examples/python/README.fix_python_move similarity index 77% rename from examples/python/README.fix_move_python rename to examples/python/README.fix_python_move index 9ab15f0b67..308d154119 100644 --- a/examples/python/README.fix_move_python +++ b/examples/python/README.fix_python_move @@ -1,16 +1,16 @@ 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. -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 -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. 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 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 implementation is still much slower than the native version, it shows that simple code transformations can lead to speedups. diff --git a/examples/python/in.fix_move_python_nve_melt b/examples/python/in.fix_python_nve_melt similarity index 90% rename from examples/python/in.fix_move_python_nve_melt rename to examples/python/in.fix_python_nve_melt index 0274b8994d..24828d7445 100644 --- a/examples/python/in.fix_move_python_nve_melt +++ b/examples/python/in.fix_python_nve_melt @@ -17,7 +17,7 @@ pair_coeff 1 1 1.0 1.0 2.5 neighbor 0.3 bin 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 run 250 diff --git a/examples/python/in.fix_move_python_nve_melt_opt b/examples/python/in.fix_python_nve_melt_opt similarity index 89% rename from examples/python/in.fix_move_python_nve_melt_opt rename to examples/python/in.fix_python_nve_melt_opt index 5f7bca3096..9564ffa02e 100644 --- a/examples/python/in.fix_move_python_nve_melt_opt +++ b/examples/python/in.fix_python_nve_melt_opt @@ -17,7 +17,7 @@ pair_coeff 1 1 1.0 1.0 2.5 neighbor 0.3 bin 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 run 250 diff --git a/src/PYTHON/fix_move_python.cpp b/src/PYTHON/fix_python_move.cpp similarity index 73% rename from src/PYTHON/fix_move_python.cpp rename to src/PYTHON/fix_python_move.cpp index a910e13aee..2c216d8aad 100644 --- a/src/PYTHON/fix_move_python.cpp +++ b/src/PYTHON/fix_python_move.cpp @@ -19,7 +19,7 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> -#include "fix_move_python.h" +#include "fix_python_move.h" #include "atom.h" #include "comm.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) { dynamic_group_allow = 1; @@ -42,7 +42,7 @@ FixMovePython::FixMovePython(LAMMPS *lmp, int narg, char **arg) : python->init(); - py_move = NULL; + py_integrator = NULL; 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(".")); - // create move instance + // create integrator instance char * full_cls_name = arg[3]; char * lastpos = strrchr(full_cls_name, '.'); 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); @@ -74,15 +74,18 @@ FixMovePython::FixMovePython(LAMMPS *lmp, int narg, char **arg) : PyErr_Print(); PyErr_Clear(); 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); - if (!py_move_type) { + // create LAMMPS atom type to potential file type mapping in python class + // 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_Clear(); 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; @@ -90,34 +93,34 @@ FixMovePython::FixMovePython(LAMMPS *lmp, int narg, char **arg) : PyObject * ptr = PY_VOID_POINTER(lmp); 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); - if (!py_move_obj) { + if (!py_integrator_obj) { PyErr_Print(); PyErr_Clear(); 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 - py_move = (void *) py_move_obj; + py_integrator = (void *) py_integrator_obj; PyGILState_Release(gstate); } /* ---------------------------------------------------------------------- */ -FixMovePython::~FixMovePython() +FixPythonMove::~FixPythonMove() { PyGILState_STATE gstate = PyGILState_Ensure(); - if(py_move) Py_DECREF((PyObject*) py_move); + if(py_integrator) Py_DECREF((PyObject*) py_integrator); PyGILState_Release(gstate); } /* ---------------------------------------------------------------------- */ -int FixMovePython::setmask() +int FixPythonMove::setmask() { int mask = 0; mask |= INITIAL_INTEGRATE; @@ -129,11 +132,11 @@ int FixMovePython::setmask() /* ---------------------------------------------------------------------- */ -void FixMovePython::init() +void FixPythonMove::init() { PyGILState_STATE gstate = PyGILState_Ensure(); - PyObject *py_move_obj = (PyObject *) py_move; - PyObject *py_init = PyObject_GetAttrString(py_move_obj,"init"); + PyObject *py_integrator_obj = (PyObject *) py_integrator; + PyObject *py_init = PyObject_GetAttrString(py_integrator_obj,"init"); if (!py_init) { PyErr_Print(); 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(); - PyObject *py_move_obj = (PyObject *) py_move; - PyObject *py_initial_integrate = PyObject_GetAttrString(py_move_obj,"initial_integrate"); + PyObject *py_integrator_obj = (PyObject *) py_integrator; + PyObject *py_initial_integrate = PyObject_GetAttrString(py_integrator_obj,"initial_integrate"); if (!py_initial_integrate) { PyErr_Print(); 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(); - PyObject *py_move_obj = (PyObject *) py_move; - PyObject *py_final_integrate = PyObject_GetAttrString(py_move_obj,"final_integrate"); + PyObject *py_integrator_obj = (PyObject *) py_integrator; + PyObject *py_final_integrate = PyObject_GetAttrString(py_integrator_obj,"final_integrate"); if (!py_final_integrate) { PyErr_Print(); 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(); - PyObject *py_move_obj = (PyObject *) py_move; - PyObject *py_initial_integrate_respa = PyObject_GetAttrString(py_move_obj,"initial_integrate_respa"); + PyObject *py_integrator_obj = (PyObject *) py_integrator; + PyObject *py_initial_integrate_respa = PyObject_GetAttrString(py_integrator_obj,"initial_integrate_respa"); if (!py_initial_integrate_respa) { PyErr_Print(); 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(); - PyObject *py_move_obj = (PyObject *) py_move; - PyObject *py_final_integrate_respa = PyObject_GetAttrString(py_move_obj,"final_integrate_respa"); + PyObject *py_integrator_obj = (PyObject *) py_integrator; + PyObject *py_final_integrate_respa = PyObject_GetAttrString(py_integrator_obj,"final_integrate_respa"); if (!py_final_integrate_respa) { PyErr_Print(); 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(); - PyObject *py_move_obj = (PyObject *) py_move; - PyObject *py_reset_dt = PyObject_GetAttrString(py_move_obj,"reset_dt"); + PyObject *py_integrator_obj = (PyObject *) py_integrator; + PyObject *py_reset_dt = PyObject_GetAttrString(py_integrator_obj,"reset_dt"); if (!py_reset_dt) { PyErr_Print(); PyErr_Clear(); diff --git a/src/PYTHON/fix_move_python.h b/src/PYTHON/fix_python_move.h similarity index 87% rename from src/PYTHON/fix_move_python.h rename to src/PYTHON/fix_python_move.h index 0573ea5062..0d06305fb9 100644 --- a/src/PYTHON/fix_move_python.h +++ b/src/PYTHON/fix_python_move.h @@ -23,21 +23,21 @@ #ifdef FIX_CLASS -FixStyle(move/python,FixMovePython) +FixStyle(python/move,FixPythonMove) #else -#ifndef LMP_FIX_MOVE_PYTHON_H -#define LMP_FIX_MOVE_PYTHON_H +#ifndef LMP_FIX_PYTHON_MOVE_H +#define LMP_FIX_PYTHON_MOVE_H #include "fix.h" namespace LAMMPS_NS { -class FixMovePython : public Fix { +class FixPythonMove : public Fix { public: - FixMovePython(LAMMPS *lmp, int narg, char **arg); - virtual ~FixMovePython(); + FixPythonMove(LAMMPS *lmp, int narg, char **arg); + virtual ~FixPythonMove(); int setmask(); virtual void init(); @@ -48,7 +48,7 @@ class FixMovePython : public Fix { virtual void reset_dt(); protected: - void * py_move; + void * py_integrator; }; } -- GitLab