source: src/Actions/Action_impl_python.hpp@ d93d2c

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 d93d2c was 0c74aa, checked in by Frederik Heber <heber@…>, 10 years ago

FIX: Fixes to Action_impl_python, lacked boost preprocessor includes.

  • Property mode set to 100644
File size: 5.0 KB
Line 
1/*
2 * Action_impl_python.hpp
3 *
4 * Created on: Sep 25, 2011
5 * Author: heber
6 */
7
8// include config.h
9#ifdef HAVE_CONFIG_H
10#include <config.h>
11#endif
12
13#include <boost/preprocessor/cat.hpp>
14#include <boost/preprocessor/comparison/equal.hpp>
15#include <boost/preprocessor/control/if.hpp>
16#include <boost/preprocessor/control/expr_if.hpp>
17#include <boost/preprocessor/debug/assert.hpp>
18#include <boost/preprocessor/facilities/expand.hpp>
19#include <boost/preprocessor/iteration/local.hpp>
20#include <boost/preprocessor/list/adt.hpp>
21#include <boost/preprocessor/punctuation/comma_if.hpp>
22#include <boost/preprocessor/punctuation/paren.hpp>
23#include <boost/preprocessor/seq/elem.hpp>
24#include <boost/preprocessor/seq/size.hpp>
25#include <boost/preprocessor/seq/transform.hpp>
26
27// some derived names: if CATEGORY is not given, we don't prefix with it
28#ifdef CATEGORY
29#define ACTION BOOST_PP_CAT(CATEGORY, BOOST_PP_CAT(ACTIONNAME, Action))
30#define COMMAND BOOST_PP_CAT(CATEGORY, ACTIONNAME)
31#define PARAMS BOOST_PP_CAT(CATEGORY, BOOST_PP_CAT(ACTIONNAME, Parameters))
32#else
33#define ACTION BOOST_PP_CAT(ACTIONNAME, Action)
34#define COMMAND ACTIONNAME
35#define PARAMS BOOST_PP_CAT(ACTIONNAME, Parameters)
36#endif
37
38// for paramdefaults entries
39#define PARAM_DEFAULT(x) \
40 (x, BOOST_PP_NIL)
41
42// check if no lists given
43#ifndef paramtokens
44#define MAXPARAMTYPES 0
45#else
46#define MAXPARAMTYPES BOOST_PP_SEQ_SIZE(paramtokens)
47#endif
48
49// calculate numbers and check whether all have same size
50#ifdef paramtokens
51BOOST_PP_ASSERT_MSG(BOOST_PP_EQUAL(MAXPARAMTYPES, BOOST_PP_SEQ_SIZE(paramdescriptions)),\
52 ERROR: There are not the same number of "paramtokens" and "paramdescriptions" in: __FILE__ \
53)
54#endif
55#ifdef paramreferences
56BOOST_PP_ASSERT_MSG(BOOST_PP_EQUAL(MAXPARAMTYPES, BOOST_PP_SEQ_SIZE(paramreferences)),\
57 ERROR: There are not the same number of "paramtokens" and "paramreferences" in: __FILE__ \
58)
59#endif
60
61#ifdef paramtypes
62BOOST_PP_ASSERT_MSG(BOOST_PP_EQUAL(MAXPARAMTYPES, BOOST_PP_SEQ_SIZE(paramtypes)),\
63 ERROR: There are not the same number of "paramtokens" and "paramtypes" in: __FILE__ \
64)
65#endif
66
67// print a list of "action separator description linenend, i.e. "Action - descrption\n"
68#define help_print(z,n,TYPELIST, VARLIST, separator, lineend) \
69 BOOST_PP_IF(n, +, BOOST_PP_EMPTY()) \
70 "\t" + std::string( BOOST_PP_SEQ_ELEM(n, TYPELIST) ) + \
71 std::string( separator ) + \
72 std::string( BOOST_PP_SEQ_ELEM(n, VARLIST) ) + \
73 std::string( lineend )
74
75// print a list of comma-separated list, i.e. (,)arg("Action")=default
76#define stringdefault_print(z,n,STRINGLIST, DEFAULTLIST) \
77 BOOST_PP_COMMA_IF(n) \
78 boost::python::arg( \
79 BOOST_PP_SEQ_ELEM(n, STRINGLIST) \
80 ) \
81 = \
82 BOOST_PP_IF( \
83 BOOST_PP_NOT( BOOST_PP_LIST_IS_NIL( BOOST_PP_SEQ_ELEM(n, paramdefaults) ) ), \
84 toString BOOST_PP_LPAREN() \
85 BOOST_PP_LIST_FIRST( BOOST_PP_SEQ_ELEM(n, DEFAULTLIST) ) \
86 BOOST_PP_RPAREN(), \
87 std::string("") \
88 )
89
90// print a list of comma-separated list, i.e. (,)arg("Action")
91#define string_print(z,n,STRINGLIST) \
92 BOOST_PP_COMMA_IF(n) \
93 boost::python::arg( \
94 BOOST_PP_SEQ_ELEM(n, STRINGLIST) \
95 )
96
97// print a list of type ref followed, i.e. "int i, double position"
98#define type_list(z,n,TYPELIST, VARLIST) \
99 BOOST_PP_COMMA_IF(n) \
100 BOOST_PP_SEQ_ELEM(n, TYPELIST) \
101 BOOST_PP_SEQ_ELEM(n, VARLIST)
102
103// prints set/queryCurrentValue (command) for paramreferences and paramtokens
104#define value_print(z, n, container, prefix) \
105 prefix \
106 BOOST_PP_SEQ_ELEM(n, container) \
107 .set( \
108 BOOST_PP_SEQ_ELEM(n, container) \
109 );
110
111#define stringtype std::string
112
113#define type2string(s, data, elem) \
114 stringtype
115
116#include "Actions/Action.hpp"
117
118namespace MoleCuilder {
119#ifdef returntype
120 returntype
121#else
122 void
123#endif
124BOOST_PP_CAT( COMMAND, _stringargs)(
125#if defined paramtypes
126#define BOOST_PP_LOCAL_MACRO(n) type_list(~, n, BOOST_PP_SEQ_TRANSFORM( type2string, ~, paramtypes), paramreferences)
127#define BOOST_PP_LOCAL_LIMITS (0, MAXPARAMTYPES-1)
128#include BOOST_PP_LOCAL_ITERATE()
129#endif
130 );
131}
132
133void BOOST_PP_CAT(export_, COMMAND)()
134{
135 std::string docstring =
136 std::string( DESCRIPTION ) + "\n\n"
137#if defined paramtokens && defined paramdescriptions
138#define BOOST_PP_LOCAL_MACRO(n) help_print(~, n, paramtokens, paramdescriptions, " - ", "\n")
139#define BOOST_PP_LOCAL_LIMITS (0, MAXPARAMTYPES-1)
140#include BOOST_PP_LOCAL_ITERATE()
141#endif
142 ;
143 boost::python::def(
144 BOOST_PP_STRINGIZE(COMMAND),
145 MoleCuilder:: BOOST_PP_CAT( COMMAND, _stringargs)
146#if defined paramtokens // do we have parameters at all?
147 ,(
148#if defined paramdefaults
149#define BOOST_PP_LOCAL_MACRO(n) stringdefault_print(~, n, paramtokens, paramdefaults)
150#else
151#define BOOST_PP_LOCAL_MACRO(n) string_print(~, n, paramtokens)
152#endif
153#define BOOST_PP_LOCAL_LIMITS (0, MAXPARAMTYPES-1)
154#include BOOST_PP_LOCAL_ITERATE()
155 ), docstring.c_str()
156#else
157 , DESCRIPTION
158#endif
159 );
160}
161
162#undef COMMAND
163#undef ACTION
164#undef PARAMS
165#undef MAXPARAMTYPES
166#undef PARAM_DEFAULT
167
168#undef help_print
169#undef string_print
170#undef stringdefault_print
171#undef type_list
172#undef value_print
173
174#undef type2string
175#undef stringtype
Note: See TracBrowser for help on using the repository browser.