Changeset f89b45


Ignore:
Timestamp:
Nov 7, 2011, 4:13:18 PM (14 years ago)
Author:
Frederik Heber <heber@…>
Branches:
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
Children:
f894fe
Parents:
55f299
git-author:
Frederik Heber <heber@…> (11/02/11 01:13:59)
git-committer:
Frederik Heber <heber@…> (11/07/11 16:13:18)
Message:

Added Reaction CalculateBoundingBoxAction.

exporting std::vector<double> as return value.

  • had to add trick with exporting std::vector<double> to python with help from stackoverflow("does boost python support a function returning a vector, by ref or value?") answer. We construct a vec_item template class which exports getter/setter, append, ... functionality to python.
  • This ends in typedef doubleVec in namespace MoleCuilder::PythonTypes, while within the Reaction its just a typedef defined in the .def file.
  • this type had to be prefix with PythonType_ to make it distinguishable from the functions in dir(mol) for Python/AllActions regression test.
  • TESTFIX: Also we modified Python/AllActions regression test to go in a loop over each command, thus stdout and stderr can be uniquely associated to the very command that caused them. This makes debugging a lot easier ... for this purpose the dir(mol) and filtering was placed into new listcmds.py.
Files:
5 added
8 edited

Legend:

Unmodified
Added
Removed
  • src/Actions/GlobalListOfActions.hpp

    r55f299 rf89b45  
    4848        (ParserSetParserParameters) \
    4949        (ParserSetOutputFormats) \
     50        (AnalysisCalculateBoundingBox) \
    5051        (AnalysisCalculateCellVolume) \
    5152        (AnalysisCalculateMolarMass) \
  • src/Actions/Makefile.am

    r55f299 rf89b45  
    8787
    8888ANALYSISACTIONSOURCE = \
     89  Actions/AnalysisAction/CalculateBoundingBoxAction.cpp \
    8990  Actions/AnalysisAction/CalculateCellVolumeAction.cpp \
    9091  Actions/AnalysisAction/CalculateMolarMassAction.cpp \
     
    9798  Actions/AnalysisAction/SurfaceCorrelationAction.cpp
    9899ANALYSISACTIONHEADER = \
     100  Actions/AnalysisAction/CalculateBoundingBoxAction.hpp \
    99101  Actions/AnalysisAction/CalculateCellVolumeAction.hpp \
    100102  Actions/AnalysisAction/CalculateMolarMassAction.hpp \
     
    107109  Actions/AnalysisAction/SurfaceCorrelationAction.hpp
    108110ANALYSISACTIONDEFS = \
     111  Actions/AnalysisAction/CalculateBoundingBoxAction.def \
    109112  Actions/AnalysisAction/CalculateCellVolumeAction.def \
    110113  Actions/AnalysisAction/CalculateMolarMassAction.def \
  • src/Actions/pyMoleCuilder.cpp

    r55f299 rf89b45  
    6161}
    6262
     63} /* namespace detail */
     64
     65namespace PythonTypes {
     66
     67inline void IndexError(){
     68    PyErr_SetString(PyExc_IndexError, "Index out of range");
     69    boost::python::throw_error_already_set();
     70}
     71
     72template<class T>
     73struct vec_item{
     74    typedef typename T::value_type V;
     75    static V& get(T& x, int i){
     76        static V nothing;
     77        if(i < 0) i += x.size();
     78        if(i >= 0 && i < int(x.size())) return x[i];
     79        IndexError();
     80        return nothing;
     81    }
     82    static void set(T& x, int i, V const& v){
     83        if(i < 0) i += x.size();
     84        if(i >= 0 && i < int(x.size())) x[i] = v;
     85        else IndexError();
     86    }
     87    static void del(T& x, int i){
     88        if(i < 0) i += x.size();
     89        if(i >= 0 && i < int(x.size())) x.erase(x.begin() + i);
     90        else IndexError();
     91    }
     92    static void add(T& x, V const& v){
     93        x.push_back(v);
     94    }
     95};
     96
     97
     98} /* namespace PythonTypes */
    6399} /* namespace MoleCuilder */
    64 } /* namespace detail */
    65100
    66101BOOST_PYTHON_MODULE(pyMoleCuilder)
     
    77112
    78113  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.");
     114
     115  // STL Vectors:
     116  // doubleVec
     117  boost::python::class_< std::vector< double > >("PythonType_doubleVec")
     118      .def("__len__", &std::vector< double >::size)
     119      .def("clear", &std::vector< double >::clear)
     120      .def("append", &MoleCuilder::PythonTypes::vec_item< std::vector< double > >::add,
     121            boost::python::with_custodian_and_ward<1, 2>()) // let container keep value
     122      .def("__getitem__", &MoleCuilder::PythonTypes::vec_item< std::vector< double > >::get,
     123           boost::python::return_value_policy<boost::python::copy_non_const_reference>())
     124      .def("__setitem__", &MoleCuilder::PythonTypes::vec_item< std::vector< double > >::set,
     125           boost::python::with_custodian_and_ward<1,2>()) // to let container keep value
     126      .def("__delitem__", &MoleCuilder::PythonTypes::vec_item< std::vector< double > >::del)
     127      .def("__iter__", boost::python::iterator< std::vector< double > >())
     128  ;
     129
     130
    79131#define export_print(z,n,list) \
    80132        BOOST_PP_CAT(export_, BOOST_PP_SEQ_ELEM(n, list))();
  • tests/regression/Analysis/testsuite-analysis.at

    r55f299 rf89b45  
    3030# calculates molar mass
    3131m4_include([Analysis/CalculateMolarMass/testsuite-analysis-calculate-molar-mass.at])
     32
     33# calculates bounding box
     34m4_include([Analysis/CalculateBoundingBox/testsuite-analysis-calculate-bounding-box.at])
  • tests/regression/Makefile.am

    r55f299 rf89b45  
    3434        $(srcdir)/Atoms/Translation/testsuite-atoms-translation.at \
    3535        $(srcdir)/Analysis/testsuite-analysis.at \
     36        $(srcdir)/Analysis/CalculateBoundingBox/testsuite-analysis-calculate-bounding-box.at \
    3637        $(srcdir)/Analysis/CalculateCellVolume/testsuite-analysis-calculate-cell-volume.at \
    3738        $(srcdir)/Analysis/CalculateMolarMass/testsuite-analysis-calculate-molar-mass.at \
  • tests/regression/Python/AllActions/moltest.py

    r55f299 rf89b45  
    1010import sys, re, subprocess
    1111
    12 cmds =  filter(lambda s: s[0] != '_', dir(mol))
     12# cmd given?
     13if len(sys.argv) < 1:
     14  sys.stderr.write("Usage: "+sys.argv[0]+" <cmd>\n")
     15  sys.exit(255)
     16
     17cmd = sys.argv[1]
    1318
    1419# options.dat einlesen
     
    4752    return result
    4853
    49 for cmd in cmds:
    50     doc = eval('mol.%s.__doc__' % cmd)
    51     params = ParseParameters(doc)
    52    
    53     print '--BEGIN-- %s mit %s --------' % (cmd, params)
     54doc = eval('mol.%s.__doc__' % cmd)
     55params = ParseParameters(doc)
     56
     57print '--BEGIN-- %s mit %s --------' % (cmd, params)
    5458   
    55     # write command to file
    56     output=open("test.py", "w")
    57     output.write('import pyMoleCuilder as mol\nparams = %s\nmol.%s(*params)\n' % (params, cmd))
    58     output.close()
    59     # call python externally on this file and catch retcode
    60     p = subprocess.Popen(["python", "test.py"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    61     stdout, stderr = p.communicate()
    62     print ' --- STDOUT ---'
    63     print ' %s ' % (stdout)
    64     print ' --- STDERR ---'
    65     print ' %s ' % (stderr)
    66     retcode = p.returncode
    67     if retcode == 134 or retcode == 0:
    68       print ' ---- ok ----'
    69     else:
    70       print ' -- FAILED with %s --' % (retcode)
    71     #exec('mol.%s(*params)' % cmd)
    72    
    73     print '---END--- %s mit %s --------' % (cmd, params)
     59# write command to file
     60output=open("test.py", "w")
     61output.write('import pyMoleCuilder as mol\nparams = %s\nmol.%s(*params)\n' % (params, cmd))
     62output.close()
     63# call python externally on this file and catch retcode
     64p = subprocess.Popen(["python", "test.py"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
     65stdout, stderr = p.communicate()
     66print ' --- STDOUT ---'
     67print ' %s ' % (stdout)
     68print ' --- STDERR ---'
     69print ' %s ' % (stderr)
     70retcode = p.returncode
     71if retcode == 134 or retcode == 0:
     72  print ' ---- ok ----'
     73else:
     74  print ' -- FAILED with %s --' % (retcode)
     75#  if retcode == 1:
     76#    sys.exit(1)
     77#exec('mol.%s(*params)' % cmd)
     78
     79print '---END--- %s mit %s --------' % (cmd, params)
    7480
    7581sys.exit(0)
  • tests/regression/Python/AllActions/options.dat

    r55f299 rf89b45  
    3333bond-file       "bond.dat"
    3434bond-table      "table.dat"
     35calculate-bounding-box  ""
    3536calculate-molar-mass    ""
    3637center-in-box   "10 0 0 10 0 10"
  • tests/regression/Python/AllActions/testsuite-python-allactions.at

    r55f299 rf89b45  
    99AT_CHECK([../../Python/run test.py], 1, [ignore], [stderr])
    1010AT_CHECK([fgrep "object has no attribute" stderr], 0, [ignore], [ignore])
     11AT_CHECK([../../Python/run ${abs_top_srcdir}/tests/regression/Python/AllActions/listcmds.py], 0, [stdout], [ignore])
    1112AT_CHECK([/bin/cp -f ${abs_top_srcdir}/tests/regression/Python/AllActions/options.dat .],  0, [ignore], [ignore])
    12 AT_CHECK([../../Python/run ${abs_top_srcdir}/tests/regression/Python/AllActions/moltest.py], 0, [stdout], [ignore])
     13for cmd in `head -n 1 stdout`
     14do
     15        AT_CHECK([echo "Checking presence of $cmd ..."], 0, [ignore], [ignore])
     16        AT_CHECK([../../Python/run ${abs_top_srcdir}/tests/regression/Python/AllActions/moltest.py $cmd], 0, [stdout], [ignore])
     17done
    1318AT_CLEANUP
Note: See TracChangeset for help on using the changeset viewer.