From 2379b61d65ce8ad1644567c256276639c23e7c40 Mon Sep 17 00:00:00 2001 From: Pavol Juhas Date: Mon, 7 Dec 2015 00:29:07 -0500 Subject: [PATCH 1/3] Revert "Remove unstable optimization wrappers." This reverts commit 9136349cfbda1a0bb894b6479f287761fda4cdbf. --- extensions/lsqnumobj_ext.cpp | 89 +++++++++++++++++++++++++++++++++++ extensions/montecarlo_ext.cpp | 55 ++++++++++++++++++++++ extensions/pyobjcryst.cpp | 4 ++ pyobjcryst/__init__.py | 2 + pyobjcryst/lsqnumobj.py | 22 +++++++++ pyobjcryst/montecarloobj.py | 22 +++++++++ 6 files changed, 194 insertions(+) create mode 100644 extensions/lsqnumobj_ext.cpp create mode 100644 extensions/montecarlo_ext.cpp create mode 100644 pyobjcryst/lsqnumobj.py create mode 100644 pyobjcryst/montecarloobj.py diff --git a/extensions/lsqnumobj_ext.cpp b/extensions/lsqnumobj_ext.cpp new file mode 100644 index 0000000..49775db --- /dev/null +++ b/extensions/lsqnumobj_ext.cpp @@ -0,0 +1,89 @@ +/***************************************************************************** +* +* pyobjcryst +* +* File coded by: Vincent Favre-Nicolin +* +* See AUTHORS.txt for a list of people who contributed. +* See LICENSE.txt for license information. +* +****************************************************************************** +* +* boost::python bindings to ObjCryst::LSQNumObj. +* +* Changes from ObjCryst::LSQNumObj +* +* Other Changes +* +*****************************************************************************/ + +#include +#include + +#include + +#include +#include + +namespace bp = boost::python; +using namespace boost::python; +using namespace ObjCryst; + +namespace { + +} // namespace + +void wrap_lsqnumobj() +{ + class_("LSQNumObj") + /// LSQNumObj::PrepareRefParList() must be called first! + .def("SetParIsFixed", + (void (LSQNumObj::*)(const std::string&, const bool)) + &LSQNumObj::SetParIsFixed, + (bp::arg("parName"), bp::arg("fix"))) + .def("SetParIsFixed", + (void (LSQNumObj::*)(const RefParType *, const bool)) + &LSQNumObj::SetParIsFixed, + (bp::arg("type"), bp::arg("fix"))) + .def("SetParIsFixed", + (void (LSQNumObj::*)(RefinablePar &, const bool)) + &LSQNumObj::SetParIsFixed, + (bp::arg("par"), bp::arg("fix"))) + //void SetParIsFixed(RefinableObj &obj, const bool fix); + .def("UnFixAllPar", &LSQNumObj::UnFixAllPar) + //void SetParIsUsed(const std::string& parName, const bool use); + //void SetParIsUsed(const RefParType *type, const bool use); + .def("Refine", &LSQNumObj::Refine, + (bp::arg("nbCycle")=1, + bp::arg("useLevenbergMarquardt")=false, + bp::arg("silent")=false, + bp::arg("callBeginEndOptimization")=true, + bp::arg("minChi2var")=0.01)) + .def("Rfactor", &LSQNumObj::Rfactor) + .def("RwFactor", &LSQNumObj::RwFactor) + .def("ChiSquare", &LSQNumObj::ChiSquare) + .def("SetRefinedObj", &LSQNumObj::SetRefinedObj, + (bp::arg("obj"), bp::arg("LSQFuncIndex")=0, + bp::arg("init")=true, bp::arg("recursive")=false)) + .def("GetCompiledRefinedObj", + (RefinableObj& (LSQNumObj::*)()) + &LSQNumObj::GetCompiledRefinedObj, + return_internal_reference<>()) + .def("PrintRefResults", &LSQNumObj::PrintRefResults) + .def("PrepareRefParList", &LSQNumObj::PrepareRefParList, + (bp::arg("copy_param")=false)) + .def("GetLSQCalc", &LSQNumObj::GetLSQCalc, + return_value_policy()) + .def("GetLSQObs", &LSQNumObj::GetLSQObs, + return_value_policy()) + .def("GetLSQWeight", &LSQNumObj::GetLSQWeight, + return_value_policy()) + .def("GetLSQDeriv", &LSQNumObj::GetLSQDeriv, + bp::arg("par"), + return_value_policy()) + .def("BeginOptimization", &LSQNumObj::BeginOptimization, + (bp::arg("allowApproximations")=false, + bp::arg("enableRestraints")=false)) + .def("EndOptimization", &LSQNumObj::EndOptimization) + ; +} diff --git a/extensions/montecarlo_ext.cpp b/extensions/montecarlo_ext.cpp new file mode 100644 index 0000000..e5747f4 --- /dev/null +++ b/extensions/montecarlo_ext.cpp @@ -0,0 +1,55 @@ +/***************************************************************************** +* +* pyobjcryst +* +* File coded by: Vincent Favre-Nicolin +* +* See AUTHORS.txt for a list of people who contributed. +* See LICENSE.txt for license information. +* +****************************************************************************** +* +* boost::python bindings to ObjCryst::MonteCarloObj. +* +* Changes from ObjCryst::MonteCarloObj +* +* Other Changes +* +*****************************************************************************/ + +#include + +#include + +namespace bp = boost::python; +using namespace boost::python; +using namespace ObjCryst; + +namespace { + +void mcoptimize(MonteCarloObj& obj, long nbSteps, const bool silent, + const double finalcost, const double maxTime) +{ + obj.Optimize(nbSteps, silent, finalcost, maxTime); +} + +} // namespace + + +void wrap_montecarloobj() +{ + class_("MonteCarloObj") //, bases + // .def("GetBestCost", &MonteCarloObj::GetBestCost) + .def("IsOptimizing", &MonteCarloObj::IsOptimizing) + // .add_property("Name", &MonteCarloObj::GetName, &MonteCarloObj::SetName) + .def("RandomizeStartingConfig", &MonteCarloObj::RandomizeStartingConfig) + .def("Optimize", &mcoptimize, + (bp::arg("nbSteps"), bp::arg("silent")=false, + bp::arg("finalcost")=0.0, bp::arg("maxTime")=-1)) + //.def("RunParallelTempering", &MonteCarloObj::RunParallelTempering, + // (bp::arg("nbSteps"), bp::arg("silent"), bp::arg("finalcost"), bp::arg("maxTime"))) + // From OptimizationObj: + .def("AddRefinableObj", &MonteCarloObj::AddRefinableObj) + .def("GetLogLikelihood", &MonteCarloObj::GetLogLikelihood) + ; +} diff --git a/extensions/pyobjcryst.cpp b/extensions/pyobjcryst.cpp index d88b3a2..2f7184c 100644 --- a/extensions/pyobjcryst.cpp +++ b/extensions/pyobjcryst.cpp @@ -25,6 +25,8 @@ void wrap_diffractiondatasinglecrystal(); void wrap_general(); void wrap_globalscatteringpower(); void wrap_io(); +void wrap_lsqnumobj(); +void wrap_montecarloobj(); void wrap_molatom(); void wrap_molbond(); void wrap_molbondangle(); @@ -93,12 +95,14 @@ BOOST_PYTHON_MODULE(_pyobjcryst) wrap_crystal(); wrap_diffractiondatasinglecrystal(); wrap_globalscatteringpower(); + wrap_lsqnumobj(); wrap_molatom(); wrap_molbond(); wrap_molbondangle(); wrap_moldihedralangle(); wrap_molecule(); wrap_polyhedron(); + wrap_montecarloobj(); wrap_powderpattern(); wrap_powderpatternbackground(); wrap_powderpatterndiffraction(); diff --git a/pyobjcryst/__init__.py b/pyobjcryst/__init__.py index fff7f07..2258ae7 100644 --- a/pyobjcryst/__init__.py +++ b/pyobjcryst/__init__.py @@ -59,7 +59,9 @@ import pyobjcryst.diffractiondatasinglecrystal import pyobjcryst.general import pyobjcryst.io +import pyobjcryst.lsqnumobj import pyobjcryst.molecule +import pyobjcryst.montecarloobj import pyobjcryst.polyhedron import pyobjcryst.powderpattern import pyobjcryst.refinableobj diff --git a/pyobjcryst/lsqnumobj.py b/pyobjcryst/lsqnumobj.py new file mode 100644 index 0000000..378a9e4 --- /dev/null +++ b/pyobjcryst/lsqnumobj.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python +############################################################################## +# +# pyobjcryst +# +# File coded by: Vincent Favre-Nicolin +# +# See AUTHORS.txt for a list of people who contributed. +# See LICENSE.txt for license information. +# +############################################################################## + +"""Python wrapping of LSQNumObj.h + +See the online ObjCryst++ documentation (http://vincefn.net/ObjCryst/). + +Changes from ObjCryst::LSQNumObj:: + In development ! + +""" + +from pyobjcryst._pyobjcryst import LSQNumObj diff --git a/pyobjcryst/montecarloobj.py b/pyobjcryst/montecarloobj.py new file mode 100644 index 0000000..3a1da7f --- /dev/null +++ b/pyobjcryst/montecarloobj.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python +############################################################################## +# +# pyobjcryst +# +# File coded by: Vincent Favre-Nicolin +# +# See AUTHORS.txt for a list of people who contributed. +# See LICENSE.txt for license information. +# +############################################################################## + +"""Python wrapping of MonteCarloObj.h + +See the online ObjCryst++ documentation (http://vincefn.net/ObjCryst/). + +Changes from ObjCryst::MonteCarloObj:: + In development ! + +""" + +from pyobjcryst._pyobjcryst import MonteCarloObj From 9ae03e2b00de0157ad988cb6f62f8e6f47776da1 Mon Sep 17 00:00:00 2001 From: Pavol Juhas Date: Mon, 7 Dec 2015 00:38:22 -0500 Subject: [PATCH 2/3] Display README badges for the develop branch. --- README.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.rst b/README.rst index 902f124..51baa28 100644 --- a/README.rst +++ b/README.rst @@ -1,8 +1,8 @@ -.. image:: https://travis-ci.org/diffpy/pyobjcryst.svg?branch=dev2015 +.. image:: https://travis-ci.org/diffpy/pyobjcryst.svg?branch=develop :target: https://travis-ci.org/diffpy/pyobjcryst -.. image:: http://codecov.io/github/diffpy/pyobjcryst/coverage.svg?branch=dev2015 - :target: http://codecov.io/github/diffpy/pyobjcryst?branch=dev2015 +.. image:: http://codecov.io/github/diffpy/pyobjcryst/coverage.svg?branch=develop + :target: http://codecov.io/github/diffpy/pyobjcryst?branch=develop pyobjcryst ========== From e607a31553c594e4b7bea202c2bfde62a4e9745f Mon Sep 17 00:00:00 2001 From: Pavol Juhas Date: Mon, 7 Dec 2015 00:40:29 -0500 Subject: [PATCH 3/3] Bump up FALLBACK_VERSION to 2.1a0. --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 15f1821..c8ca00d 100755 --- a/setup.py +++ b/setup.py @@ -69,7 +69,7 @@ def create_extensions(): # Use this version when git data are not available, like in git zip archive. # Update when tagging a new release. -FALLBACK_VERSION = '2.0a1.post0' +FALLBACK_VERSION = '2.1a0.post0' # versioncfgfile holds version data for git commit hash and date. # It must reside in the same directory as version.py.