Skip to content
Snippets Groups Projects
Select Git revision
  • d649a6fe381a9c5e76df59f48d10331bb7c5ee9e
  • master default protected
  • mui-unknown
  • mui-sequence
  • mui
  • compute_momentum
6 results

python_impl.cpp

Blame
  • user avatar
    Richard Berger authored
    a8b7153f
    History
    python_impl.cpp 15.21 KiB
    /* ----------------------------------------------------------------------
       LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
       http://lammps.sandia.gov, Sandia National Laboratories
       Steve Plimpton, sjplimp@sandia.gov
    
       Copyright (2003) Sandia Corporation.  Under the terms of Contract
       DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
       certain rights in this software.  This software is distributed under
       the GNU General Public License.
    
       See the README file in the top-level LAMMPS directory.
    ------------------------------------------------------------------------- */
    
    /* ----------------------------------------------------------------------
       Contributing author: Richard Berger and Axel Kohlmeyer (Temple U)
    ------------------------------------------------------------------------- */
    
    #include <Python.h>
    #include "python.h"
    #include "force.h"
    #include "input.h"
    #include "variable.h"
    #include "memory.h"
    #include "error.h"
    #include "python_compat.h"
    
    using namespace LAMMPS_NS;
    
    enum{NONE,INT,DOUBLE,STRING,PTR};
    
    #define VALUELENGTH 64               // also in variable.cpp
    
    
    /* ---------------------------------------------------------------------- */
    
    PythonImpl::PythonImpl(LAMMPS *lmp) : Pointers(lmp)
    {
      ninput = noutput = 0;
      istr = NULL;
      ostr = NULL;
      format = NULL;
      length_longstr = 0;
    
      // pfuncs stores interface info for each Python function
    
      nfunc = 0;
      pfuncs = NULL;
    
      // one-time initialization of Python interpreter
      // pyMain stores pointer to main module
      external_interpreter = Py_IsInitialized();
    
      Py_Initialize();
      PyEval_InitThreads();
    
      PyGILState_STATE gstate = PyGILState_Ensure();
    
      PyObject *pModule = PyImport_AddModule("__main__");
      if (!pModule) error->all(FLERR,"Could not initialize embedded Python");
    
      pyMain = (void *) pModule;
      PyGILState_Release(gstate);
    }
    
    /* ---------------------------------------------------------------------- */
    
    PythonImpl::~PythonImpl()
    {
      if(pyMain) {
        // clean up