source: src/Actions/pyMoleCuilder.cpp@ d67e6c

Action_Thermostats Add_AtomRandomPerturbation Add_FitFragmentPartialChargesAction Add_RotateAroundBondAction Add_SelectAtomByNameAction Added_ParseSaveFragmentResults AddingActions_SaveParseParticleParameters Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_ParticleName_to_Atom Adding_StructOpt_integration_tests AtomFragments Automaking_mpqc_open AutomationFragmentation_failures Candidate_v1.5.4 Candidate_v1.6.0 Candidate_v1.6.1 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator CombiningParticlePotentialParsing Combining_Subpackages Debian_Package_split Debian_package_split_molecuildergui_only Disabling_MemDebug Docu_Python_wait EmpiricalPotential_contain_HomologyGraph EmpiricalPotential_contain_HomologyGraph_documentation Enable_parallel_make_install Enhance_userguide Enhanced_StructuralOptimization Enhanced_StructuralOptimization_continued Example_ManyWaysToTranslateAtom Exclude_Hydrogens_annealWithBondGraph FitPartialCharges_GlobalError Fix_BoundInBox_CenterInBox_MoleculeActions Fix_ChargeSampling_PBC Fix_ChronosMutex Fix_FitPartialCharges Fix_FitPotential_needs_atomicnumbers Fix_ForceAnnealing Fix_IndependentFragmentGrids Fix_ParseParticles Fix_ParseParticles_split_forward_backward_Actions Fix_PopActions Fix_QtFragmentList_sorted_selection Fix_Restrictedkeyset_FragmentMolecule Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns Fix_fitting_potentials Fixes ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion FragmentAction_writes_AtomFragments FragmentMolecule_checks_bonddegrees GeometryObjects Gui_Fixes Gui_displays_atomic_force_velocity ImplicitCharges IndependentFragmentGrids IndependentFragmentGrids_IndividualZeroInstances IndependentFragmentGrids_IntegrationTest IndependentFragmentGrids_Sole_NN_Calculation JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix MoreRobust_FragmentAutomation ODR_violation_mpqc_open PartialCharges_OrthogonalSummation PdbParser_setsAtomName PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks Rewrite_FitPartialCharges RotateToPrincipalAxisSystem_UndoRedo SaturateAtoms_findBestMatching SaturateAtoms_singleDegree StoppableMakroAction Subpackage_CodePatterns Subpackage_JobMarket Subpackage_LinearAlgebra Subpackage_levmar Subpackage_mpqc_open Subpackage_vmg Switchable_LogView ThirdParty_MPQC_rebuilt_buildsystem TrajectoryDependenant_MaxOrder TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps TremoloParser_setsAtomName Ubuntu_1604_changes stable
Last change on this file since d67e6c was 628577, checked in by Frederik Heber <heber@…>, 12 years ago

Introduced ActionQueue which contains internal ActionRegistry.

  • Property mode set to 100644
File size: 4.9 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2010-2012 University of Bonn. All rights reserved.
5 *
6 *
7 * This file is part of MoleCuilder.
8 *
9 * MoleCuilder is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation, either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * MoleCuilder is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with MoleCuilder. If not, see <http://www.gnu.org/licenses/>.
21 */
22
23/*
24 * pyMoleCuilder.cpp
25 *
26 * Created on: Sep 21, 2011
27 * Author: heber
28 */
29
30// include config.h
31#ifdef HAVE_CONFIG_H
32#include <config.h>
33#endif
34
35#include <boost/python.hpp>
36#include <boost/python/module.hpp>
37#include <boost/python/args.hpp>
38
39#include "CodePatterns/MemDebug.hpp"
40#include "CodePatterns/toString.hpp"
41
42//!> define all present actions
43#include "GlobalListOfActions.hpp"
44
45//!> python wrapping for all of these actions
46#include "AllActionPython.hpp"
47
48#include "cleanUp.hpp"
49#include "Actions/ActionHistory.hpp"
50#include "cleanUp.hpp"
51
52namespace MoleCuilder {
53
54namespace detail {
55
56void module_exit()
57{
58 // save everything
59 std::cout << "Saving." << std::endl;
60 saveAll();
61 // purge everything
62 std::cout << "Cleaning memory." << std::endl;
63 cleanUp();
64}
65
66void module_reinit()
67{
68 // save everything
69 std::cout << "Saving." << std::endl;
70 saveAll();
71 // purge everything
72 std::cout << "Cleaning static instances from memory." << std::endl;
73 purgeStaticInstances();
74 // need to init the history before any action is created
75 std::cout << "Reinitializing." << std::endl;
76 MoleCuilder::ActionHistory::init();
77}
78
79} /* namespace detail */
80
81namespace PythonTypes {
82
83inline void IndexError(){
84 PyErr_SetString(PyExc_IndexError, "Index out of range");
85 boost::python::throw_error_already_set();
86}
87
88template<class T>
89struct vec_item{
90 typedef typename T::value_type V;
91 static V& get(T& x, int i){
92 static V nothing;
93 if(i < 0) i += x.size();
94 if(i >= 0 && i < int(x.size())) return x[i];
95 IndexError();
96 return nothing;
97 }
98 static void set(T& x, int i, V const& v){
99 if(i < 0) i += x.size();
100 if(i >= 0 && i < int(x.size())) x[i] = v;
101 else IndexError();
102 }
103 static void del(T& x, int i){
104 if(i < 0) i += x.size();
105 if(i >= 0 && i < int(x.size())) x.erase(x.begin() + i);
106 else IndexError();
107 }
108 static void add(T& x, V const& v){
109 x.push_back(v);
110 }
111};
112
113
114} /* namespace PythonTypes */
115} /* namespace MoleCuilder */
116
117BOOST_PYTHON_MODULE(pyMoleCuilder)
118{
119 // need to init the history before any action is created
120 MoleCuilder::ActionHistory::init();
121
122 // from this moment on, we need to be sure to deeinitialize in the correct order
123 // this is handled by the cleanup function
124 atexit(MoleCuilder::detail::module_exit);
125
126 // set the docstring of the current module scope
127 boost::python::scope().attr("__doc__") = "pyMolecuilder are the python bindings to all Actions of the program suite MoleCuilder.\n\nMoleCuilder is a program to build molecular (dynamics) worlds, allowing you indefinite manipulation, control and analysis over the atoms and molecules within a simulation domain.";
128
129 boost::python::def("reinit", MoleCuilder::detail::module_reinit, "Reinitializes the internal state of the python module as if it had been freshly imported, saves all input files beforehand.");
130
131 // STL Vectors:
132 // doubleVec
133 boost::python::class_< std::vector< double > >("PythonType_doubleVec")
134 .def("__len__", &std::vector< double >::size)
135 .def("clear", &std::vector< double >::clear)
136 .def("append", &MoleCuilder::PythonTypes::vec_item< std::vector< double > >::add,
137 boost::python::with_custodian_and_ward<1, 2>()) // let container keep value
138 .def("__getitem__", &MoleCuilder::PythonTypes::vec_item< std::vector< double > >::get,
139 boost::python::return_value_policy<boost::python::copy_non_const_reference>())
140 .def("__setitem__", &MoleCuilder::PythonTypes::vec_item< std::vector< double > >::set,
141 boost::python::with_custodian_and_ward<1,2>()) // to let container keep value
142 .def("__delitem__", &MoleCuilder::PythonTypes::vec_item< std::vector< double > >::del)
143 .def("__iter__", boost::python::iterator< std::vector< double > >())
144 ;
145
146
147#define export_print(z,n,list) \
148 BOOST_PP_CAT(export_, BOOST_PP_SEQ_ELEM(n, list))();
149#define BOOST_PP_LOCAL_MACRO(n) export_print(~, n, GLOBALLISTOFACTIONS)
150#define BOOST_PP_LOCAL_LIMITS (0, BOOST_PP_DEC(BOOST_PP_SEQ_SIZE(GLOBALLISTOFACTIONS)))
151#include BOOST_PP_LOCAL_ITERATE()
152#undef instance_print
153}
Note: See TracBrowser for help on using the repository browser.