Skip to content

Commit

Permalink
Serialize SurfaceMover
Browse files Browse the repository at this point in the history
  • Loading branch information
benmwebb committed Oct 25, 2023
1 parent 1baf8c6 commit 2f40b36
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 3 deletions.
14 changes: 13 additions & 1 deletion modules/core/include/SurfaceMover.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* \file IMP/core/SurfaceMover.h
* \brief A mover that transforms a Surface.
*
* Copyright 2007-2022 IMP Inventors. All rights reserved.
* Copyright 2007-2023 IMP Inventors. All rights reserved.
*
*/

Expand All @@ -16,6 +16,9 @@
#include <IMP/Particle.h>
#include <IMP/Object.h>
#include <IMP/Model.h>
#include <cereal/access.hpp>
#include <cereal/types/base_class.hpp>
#include <cereal/types/polymorphic.hpp>


IMPCORE_BEGIN_NAMESPACE
Expand All @@ -42,13 +45,22 @@ class IMPCOREEXPORT SurfaceMover : public MonteCarloMover {
void initialize(ParticleIndex pi, double max_translation,
double max_rotation, double reflect_probability);

friend class cereal::access;
template<class Archive> void serialize(Archive &ar) {
ar(cereal::base_class<MonteCarloMover>(this), last_transform_,
max_translation_, max_angle_, reflect_prob_, pi_);
}
IMP_OBJECT_SERIALIZE_DECL(SurfaceMover);

public:
SurfaceMover(Model *m, ParticleIndex pi, Float max_translation,
Float max_rotation, Float reflect_probability);

SurfaceMover(Surface s, Float max_translation, Float max_rotation,
Float reflect_probability);

SurfaceMover() {}

//! Set the maximum translation in angstroms.
void set_maximum_translation(Float mt);

Expand Down
2 changes: 1 addition & 1 deletion modules/core/pyext/swig.i-in
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ IMP_SWIG_OBJECT_SERIALIZE( IMP::core, BallMover, BallMovers);
IMP_SWIG_OBJECT_SERIALIZE( IMP::core, SerialMover, SerialMovers);
IMP_SWIG_OBJECT_SERIALIZE( IMP::core, SubsetMover, SubsetMovers);
IMP_SWIG_OBJECT_SERIALIZE( IMP::core, DirectionMover, DirectionMovers);
IMP_SWIG_OBJECT( IMP::core, SurfaceMover, SurfaceMovers);
IMP_SWIG_OBJECT_SERIALIZE( IMP::core, SurfaceMover, SurfaceMovers);
IMP_SWIG_OBJECT_INSTANCE( IMP::core, BoundingBox3DSingletonScore, BoundingBox3DSingletonScore, BoundingBox3DSingletonScores);
IMP_SWIG_OBJECT_INSTANCE( IMP::core, BoundingSphere3DSingletonScore, BoundingSphere3DSingletonScore, BoundingSphere3DSingletonScores);
#ifdef IMP_CORE_USE_IMP_CGAL
Expand Down
4 changes: 3 additions & 1 deletion modules/core/src/SurfaceMover.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* \file SurfaceMover.cpp
* \brief A mover that transforms a Surface
*
* Copyright 2007-2022 IMP Inventors. All rights reserved.
* Copyright 2007-2023 IMP Inventors. All rights reserved.
*
*/
#include <IMP/core/SurfaceMover.h>
Expand Down Expand Up @@ -97,4 +97,6 @@ ModelObjectsTemp SurfaceMover::do_get_inputs() const {
return ParticlesTemp(1, get_model()->get_particle(pi_));
}

IMP_OBJECT_SERIALIZE_IMPL(IMP::core::SurfaceMover);

IMPCORE_END_NAMESPACE
31 changes: 31 additions & 0 deletions modules/core/test/test_surface_mover.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import IMP.core
import IMP.atom
import IMP.test
import pickle


class Tests(IMP.test.TestCase):
Expand Down Expand Up @@ -65,6 +66,36 @@ def test_inputs(self):
self.assertSetEqual(set([surf.get_particle()]), set(mv.get_inputs()))
mv.set_was_used(True)

def test_pickle(self):
"""Test (un-)pickle of SurfaceMover"""
m = IMP.Model()
surf = IMP.core.Surface.setup_particle(IMP.Particle(m))
surf.set_coordinates_are_optimized(True)
surf.set_normal_is_optimized(True)
mvr = IMP.core.SurfaceMover(surf, 1, .1, 1.)
mvr.set_name("foo")
dump = pickle.dumps(mvr)

newmvr = pickle.loads(dump)
self.assertEqual(newmvr.get_name(), "foo")
self.assertSetEqual(set([surf.get_particle()]),
set(newmvr.get_inputs()))

def test_pickle_polymorphic(self):
"""Test (un-)pickle of SurfaceMover via polymorphic pointer"""
m = IMP.Model()
surf = IMP.core.Surface.setup_particle(IMP.Particle(m))
surf.set_coordinates_are_optimized(True)
surf.set_normal_is_optimized(True)
mvr = IMP.core.SurfaceMover(surf, 1, .1, 1.)
mvr.set_name("foo")
sm = IMP.core.SerialMover([mvr])
dump = pickle.dumps(sm)

newsm = pickle.loads(dump)
newmvr, = newsm.get_movers()
self.assertEqual(newmvr.get_name(), "foo")


if __name__ == '__main__':
IMP.test.main()

0 comments on commit 2f40b36

Please sign in to comment.