2 Highly Optimized Object-oriented Many-particle Dynamics -- Blue Edition
3 (HOOMD-blue) Open Source Software License Copyright 2008-2011 Ames Laboratory
4 Iowa State University and The Regents of the University of Michigan All rights
7 HOOMD-blue may contain modifications ("Contributions") provided, and to which
8 copyright is held, by various Contributors who have granted The Regents of the
9 University of Michigan the right to modify and/or distribute such Contributions.
11 You may redistribute, use, and create derivate works of HOOMD-blue, in source
12 and binary forms, provided you abide by the following conditions:
14 * Redistributions of source code must retain the above copyright notice, this
15 list of conditions, and the following disclaimer both in the code and
16 prominently in any materials provided with the distribution.
18 * Redistributions in binary form must reproduce the above copyright notice, this
19 list of conditions, and the following disclaimer in the documentation and/or
20 other materials provided with the distribution.
22 * All publications and presentations based on HOOMD-blue, including any reports
23 or published results obtained, in whole or in part, with HOOMD-blue, will
24 acknowledge its use according to the terms posted at the time of submission on:
25 http://codeblue.umich.edu/hoomd-blue/citations.html
27 * Any electronic documents citing HOOMD-Blue will link to the HOOMD-Blue website:
28 http://codeblue.umich.edu/hoomd-blue/
30 * Apart from the above required attributions, neither the name of the copyright
31 holder nor the names of HOOMD-blue's contributors may be used to endorse or
32 promote products derived from this software without specific prior written
37 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS ``AS IS'' AND
38 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
39 WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND/OR ANY
40 WARRANTIES THAT THIS SOFTWARE IS FREE OF INFRINGEMENT ARE DISCLAIMED.
42 IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
43 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
44 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
45 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
46 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
47 OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
48 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
51 // Maintainer: joaander
53 // temporarily work around issues with the new boost fileystem libraries
54 // http://www.boost.org/doc/libs/1_46_1/libs/filesystem/v3/doc/index.htm
57 #pragma warning( push )
58 #pragma warning( disable : 4103 4244 )
61 #include <boost/version.hpp>
62 #include <boost/python.hpp>
64 #include <boost/filesystem/operations.hpp>
65 #include <boost/filesystem/convenience.hpp>
67 using namespace boost::filesystem
;
69 #include "PathUtils.h"
70 #include "HOOMDVersion.h"
78 // hack to support both version 2 and version 3 of the boost filesystem API
79 #if (BOOST_VERSION >= 104400)
80 #define native_file_string string
84 \brief Executable for running python scripts with the hoomd module builtin
87 //! forward declaration of the inithoomd function that inits the python module from hoomd_module.cc
88 extern "C" void inithoomd();
90 //! A simple method for finding the hoomd_script python module
91 string
find_hoomd_script()
93 // this works on the requirement in the hoomd build scripts that the python module is always
94 // installed in lib/hoomd/python-module on linux and mac. On windows, it actually ends up in bin/python-module
95 path exepath
= path(getExePath());
96 list
<path
> search_paths
;
97 search_paths
.push_back(exepath
/ "python-module"); // windows
98 search_paths
.push_back(exepath
/ ".." / "lib" / "hoomd" / "python-module"); // linux/mac
99 search_paths
.push_back(path(HOOMD_SOURCE_DIR
) / "python-module"); // from source builds
101 list
<path
>::iterator cur_path
;
102 for (cur_path
= search_paths
.begin(); cur_path
!= search_paths
.end(); ++cur_path
)
104 if (exists(*cur_path
/ "hoomd_script" / "__init__.py"))
105 return cur_path
->native_file_string();
109 << "***Error! HOOMD python-module directory not found. Check your HOOMD directory structure." << endl
;
110 cerr
<< "Searched for hoomd_script in:" << endl
;
111 for (cur_path
= search_paths
.begin(); cur_path
!= search_paths
.end(); ++cur_path
)
113 cerr
<< cur_path
->native_file_string() << endl
;
119 //! Main function for the executable
120 /*! \param argc argument count
121 \param argv arguments
122 Loads up the hoomd python module and then passes control onto Py_Main
124 int main(int argc
, char **argv
)
128 // This shell is an interactive launch with no arguments
129 cout
<< "Launching intractive python shell now.... run \"from hoomd_script import *\" to load the HOOMD-blue python module" << endl
<< endl
;
132 char module_name
[] = "hoomd";
133 PyImport_AppendInittab(module_name
, &inithoomd
);
136 // Need to inject the hoomd module path and the plugins dir into sys.path
137 string
python_cmds("import sys\n");
138 string hoomd_script_dir
= find_hoomd_script();
139 if (hoomd_script_dir
!= "")
141 python_cmds
+= string("sys.path.insert(0, r\"") + hoomd_script_dir
+ string("\")\n");
144 if (getenv("HOOMD_PLUGINS_DIR"))
146 string hoomd_plugins_dir
= string(getenv("HOOMD_PLUGINS_DIR"));
147 python_cmds
+= string("sys.path.insert(0, r\"") + hoomd_plugins_dir
+ string("\")\n");
148 cout
<< "Notice: Using hoomd plugins in " << hoomd_plugins_dir
<< endl
;
151 PyRun_SimpleString(python_cmds
.c_str());
153 int retval
= Py_Main(argc
, argv
);
155 // trying to clean up python's messy memory leaks
160 #pragma warning( pop )