[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[IMP-dev] Quick cleanup of IMP.i



Here is a simple patch to IMP.i which adds macros to handle the thisowns and adds a few missed ones.


Index: kernel/include/IMP/optimizers/MonteCarlo.h
===================================================================
--- kernel/include/IMP/optimizers/MonteCarlo.h	(revision 669)
+++ kernel/include/IMP/optimizers/MonteCarlo.h	(working copy)
@@ -15,8 +15,6 @@
 namespace IMP
 {
 
-typedef std::vector<Mover*> Movers;
-
 //! A Monte Carlo optimizer.
 /** The optimizer uses a set of Mover objects to propose steps. Currently
     each Mover is called at each Monte Carlo iteration. This may change in
Index: kernel/include/IMP/optimizers/Mover.h
===================================================================
--- kernel/include/IMP/optimizers/Mover.h	(revision 669)
+++ kernel/include/IMP/optimizers/Mover.h	(working copy)
@@ -76,6 +76,8 @@
 
 IMP_OUTPUT_OPERATOR(Mover);
 
+typedef std::vector<Mover*> Movers;
+
 } // namespace IMP
 
 #endif  /* __IMP_MOVER_H */
Index: kernel/pyext/IMP_macros.i
===================================================================
--- kernel/pyext/IMP_macros.i	(revision 669)
+++ kernel/pyext/IMP_macros.i	(working copy)
@@ -1,6 +1,38 @@
 #define IMPDLLEXPORT
 #define IMPDLLLOCAL
 
+%define IMP_OWN_FIRST_CONSTRUCTOR(Ucname)
+%pythonprepend Ucname::Ucname %{
+        args[0].thisown=0
+%}
+%enddef
+
+%define IMP_OWN_FIRST_SECOND_CONSTRUCTOR(Ucname)
+%pythonprepend Ucname::Ucname %{
+        args[0].thisown=0
+        args[1].thisown=0
+%}
+%enddef
+
+%define IMP_SET_OBJECT(Ucname, methodname)
+%pythonprepend Ucname::methodname %{
+        args[1].thisown=0
+%}
+%enddef
+
+%define IMP_ADD_OBJECT(Ucname, methodname)
+%pythonprepend Ucname::methodname %{
+        args[1].thisown=0
+%}
+%enddef
+
+%define IMP_ADD_OBJECTS(Ucname, methodname)
+%pythonprepend Ucname::methodname %{
+        for p in args[1]:
+            p.thisown=0
+%}
+%enddef
+
 /* Add additional IMP_CONTAINER methods for scripting languages */
 %define IMP_CONTAINER_SWIG(type, Ucname, lcname)
 %extend type {
@@ -9,6 +41,8 @@
     return ret;
   }
 }
+IMP_ADD_OBJECT(type, add_##lcname)
+IMP_ADD_OBJECTS(type, add_##lcname##s)
 %enddef
 
 %include "IMP/macros.h"
Index: kernel/pyext/IMP.i
===================================================================
--- kernel/pyext/IMP.i	(revision 669)
+++ kernel/pyext/IMP.i	(working copy)
@@ -27,94 +27,30 @@
 %}
 
 namespace IMP {
-  %pythonprepend Model::add_restraint %{
-        args[1].thisown=0
-  %}
-  %pythonprepend Model::add_score_state %{
-        args[1].thisown=0
-  %}
-  %pythonprepend Optimizer::add_optimizer_state %{
-        args[1].thisown=0
-  %}
-  %pythonprepend RestraintSet::add_restraint %{
-        args[1].thisown=0
-  %}
-  %pythonprepend NonbondedListScoreState::add_bonded_list %{
-        args[1].thisown=0
-  %}
-  %pythonprepend DistanceRestraint::DistanceRestraint %{
-        args[0].thisown=0
-  %}
-  %pythonprepend AngleRestraint::AngleRestraint %{
-        args[0].thisown=0
-  %}
-  %pythonprepend DihedralRestraint::DihedralRestraint %{
-        args[0].thisown=0
-  %}
-  %pythonprepend TorusRestraint::TorusRestraint %{
-        args[3].thisown=0
-  %}
-  %pythonprepend NonbondedRestraint::NonbondedRestraint %{
-        args[0].thisown=0
-  %}
-  %pythonprepend BondDecoratorRestraint::BondDecoratorRestraint %{
-        args[0].thisown=0
-  %}
-  %pythonprepend SingletonListRestraint::SingletonListRestraint %{
-        args[0].thisown=0
-  %}
-  %pythonprepend PairListRestraint::PairListRestraint %{
-        args[0].thisown=0
-  %}
-  %pythonprepend TripletChainRestraint::TripletChainRestraint %{
-        args[0].thisown=0
-  %}
-  %pythonprepend PairChainRestraint::PairChainRestraint %{
-        args[0].thisown=0
-  %}
-  %pythonprepend ConnectivityRestraint::ConnectivityRestraint %{
-        args[0].thisown=0
-  %}
-  %pythonprepend DistancePairScore::DistancePairScore %{
-        args[0].thisown=0
-  %}
-  %pythonprepend TransformedDistancePairScore::TransformedDistancePairScore %{
-        args[0].thisown=0
-  %}
-  %pythonprepend BondCoverPairScore::BondCoverPairScore %{
-        args[0].thisown=0
-  %}
-  %pythonprepend SphereDistancePairScore::SphereDistancePairScore %{
-        args[0].thisown=0
-  %}
-  %pythonprepend RefineOncePairScore::RefineOncePairScore %{
-        args[0].thisown=0
-        args[1].thisown=0
-  %}
-  %pythonprepend DistanceToSingletonScore::DistanceToSingletonScore %{
-        args[0].thisown=0
-  %}
-  %pythonprepend AttributeSingletonScore::AttributeSingletonScore %{
-        args[0].thisown=0
-  %}
-  %pythonprepend TunnelSingletonScore::TunnelSingletonScore %{
-        args[0].thisown=0
-  %}
-  %pythonprepend AngleTripletScore::AngleTripletScore %{
-        args[0].thisown=0
-  %}
-  %pythonprepend MonteCarlo::add_mover %{
-        args[1].thisown=0
-  %}
-  %pythonprepend MonteCarlo::set_local_optimizer %{
-        args[1].thisown=0
-  %}
-  %pythonprepend VRMLLogOptimizerState::add_particle_refiner %{
-        args[1].thisown=0
-  %}
-  %pythonprepend TypedPairScore::set_pair_score %{
-        args[1].thisown=0
-  %}
+  // need to special case particle so can't add this to macro
+  IMP_OWN_FIRST_CONSTRUCTOR(DistanceRestraint)
+  IMP_OWN_FIRST_CONSTRUCTOR(AngleRestraint)
+  IMP_OWN_FIRST_CONSTRUCTOR(DihedralRestraint)
+  IMP_OWN_FIRST_CONSTRUCTOR(TorusRestraint)
+  IMP_OWN_FIRST_CONSTRUCTOR(NonbondedRestraint)
+  IMP_OWN_FIRST_CONSTRUCTOR(BondDecoratorRestraint)
+  IMP_OWN_FIRST_CONSTRUCTOR(SingletonListRestraint)
+  IMP_OWN_FIRST_CONSTRUCTOR(PairListRestraint)
+  IMP_OWN_FIRST_CONSTRUCTOR(TripletChainRestraint)
+  IMP_OWN_FIRST_CONSTRUCTOR(PairChainRestraint)
+  IMP_OWN_FIRST_CONSTRUCTOR(ConnectivityRestraint)
+  IMP_OWN_FIRST_CONSTRUCTOR(DistancePairScore)
+  IMP_OWN_FIRST_CONSTRUCTOR(TransformedDistancePairScore)
+  IMP_OWN_FIRST_CONSTRUCTOR(BondCoverPairScore)
+  IMP_OWN_FIRST_CONSTRUCTOR(SphereDistancePairScore)
+  IMP_OWN_FIRST_SECOND_CONSTRUCTOR(RefineOncePairScore)
+  IMP_OWN_FIRST_CONSTRUCTOR(DistanceToSingletonScore)
+  IMP_OWN_FIRST_CONSTRUCTOR(AttributeSingletonScore)
+  IMP_OWN_FIRST_CONSTRUCTOR(TunnelSingletonScore)
+  IMP_OWN_FIRST_CONSTRUCTOR(AngleTripletScore)
+  IMP_SET_OBJECT(MonteCarlo, set_local_optimizer)
+  IMP_SET_OBJECT(TypedPairScore, set_pair_score)
+
   %pythonprepend Particle::get_value %{
         check_particle(args[0], args[1])
   %}
@@ -144,10 +80,19 @@
 
   %}
 
-  IMP_CONTAINER_SWIG(Model, Particle, particle);
+  // special case since particles are ref counted
+  %extend Model {
+    Particles get_particles() const {
+      IMP::Particles ret(self->particles_begin(), self->particles_end());
+      return ret;
+    }
+  }
   IMP_CONTAINER_SWIG(Model, ScoreState, score_state);
   IMP_CONTAINER_SWIG(Model, Restraint, restraint);
   IMP_CONTAINER_SWIG(RestraintSet, Restraint, restraint);
+  IMP_CONTAINER_SWIG(MonteCarlo, Mover, mover);
+  IMP_CONTAINER_SWIG(Optimizer, OptimizerState, optimizer_state);
+  IMP_CONTAINER_SWIG(NonbondedListScoreState, BondedListScoreState, bonded_list);
 }
 
 %feature("ref")   Particle "$this->ref();"
@@ -168,6 +113,7 @@
 %feature("director") IMP::TripletScore;
 %feature("director") IMP::Optimizer;
 %feature("director") IMP::ParticleRefiner;
+%feature("director") IMP::Mover;
 
 %include "IMP/Key.h"
 %include "IMP/Object.h"
Index: SConstruct
===================================================================
--- SConstruct	(revision 669)
+++ SConstruct	(working copy)
@@ -52,7 +52,7 @@
 #SConscript('domino/SConscript')
 
 # bin script first requires kernel libraries to be built:
-env.Depends(bin, [src, pyext])
+env.Depends(bin, [pyext, src])
 
 # Build the binaries by default:
 env.Default(bin)