Index: kernel/include/IMP/restraints/ConnectivityRestraint.h =================================================================== --- kernel/include/IMP/restraints/ConnectivityRestraint.h (revision 441) +++ kernel/include/IMP/restraints/ConnectivityRestraint.h (working copy) @@ -15,7 +15,6 @@ #include "../IMP_config.h" #include "../Restraint.h" -#include "../ScoreFuncParams.h" #include "../internal/kernel_version_info.h" #include "DistanceRestraint.h" Index: kernel/include/IMP.h =================================================================== --- kernel/include/IMP.h (revision 441) +++ kernel/include/IMP.h (working copy) @@ -1,82 +1,89 @@ /** - * \file IMP.h \brief IMP, an Integrative Modeling Platform. - * - * Copyright 2007-8 Sali Lab. All rights reserved. - * - */ - +* \\file IMP.h \\brief IMP, an Integrative Modeling Platform. +* +* Copyright 2007-8 Sali Lab. All rights reserved. +* +*/ #ifndef __IMP_H #define __IMP_H - -#include "IMP/IMP_config.h" -#include "IMP/log.h" -#include "IMP/random.h" -#include "IMP/base_types.h" -#include "IMP/Particle.h" -#include "IMP/Optimizer.h" -#include "IMP/Restraint.h" -#include "IMP/exception.h" -#include "IMP/UnaryFunction.h" -#include "IMP/unary_functions/Harmonic.h" -#include "IMP/unary_functions/HarmonicLowerBound.h" -#include "IMP/unary_functions/HarmonicUpperBound.h" -#include "IMP/unary_functions/OpenCubicSpline.h" -#include "IMP/unary_functions/ClosedCubicSpline.h" -#include "IMP/unary_functions/Cosine.h" -#include "IMP/unary_functions/Linear.h" -#include "IMP/ScoreFuncParams.h" -#include "IMP/Model.h" -#include "IMP/PairScore.h" -#include "IMP/SingletonScore.h" -#include "IMP/TripletScore.h" -#include "IMP/Vector3D.h" -#include "IMP/VersionInfo.h" -#include "IMP/decorators/HierarchyDecorator.h" -#include "IMP/decorators/MolecularHierarchyDecorator.h" -#include "IMP/decorators/NameDecorator.h" -#include "IMP/decorators/AtomDecorator.h" -#include "IMP/decorators/ResidueDecorator.h" -#include "IMP/decorators/XYZDecorator.h" -#include "IMP/decorators/bond_decorators.h" -#include "IMP/optimizers/SteepestDescent.h" -#include "IMP/optimizers/ConjugateGradients.h" -#include "IMP/optimizers/MolecularDynamics.h" -#include "IMP/optimizers/MonteCarlo.h" -#include "IMP/optimizers/Mover.h" -#include "IMP/optimizers/MoverBase.h" -#include "IMP/optimizers/movers/BallMover.h" -#include "IMP/optimizers/movers/NormalMover.h" -#include "IMP/optimizers/states/VRMLLogOptimizerState.h" -#include "IMP/optimizers/states/CMMLogOptimizerState.h" -#include "IMP/optimizers/states/VelocityScalingOptimizerState.h" -#include "IMP/pair_scores/DistancePairScore.h" -#include "IMP/pair_scores/SphereDistancePairScore.h" -#include "IMP/singleton_scores/DistanceToSingletonScore.h" -#include "IMP/triplet_scores/AngleTripletScore.h" -#include "IMP/restraints/RestraintSet.h" -#include "IMP/restraints/DistanceRestraint.h" -#include "IMP/restraints/AngleRestraint.h" -#include "IMP/restraints/DihedralRestraint.h" -#include "IMP/restraints/TorusRestraint.h" -#include "IMP/restraints/ProximityRestraint.h" -#include "IMP/restraints/ConnectivityRestraint.h" -#include "IMP/restraints/PairConnectivityRestraint.h" -#include "IMP/restraints/ExclusionVolumeRestraint.h" -#include "IMP/restraints/NonbondedRestraint.h" -#include "IMP/restraints/BondDecoratorRestraint.h" -#include "IMP/restraints/SingletonListRestraint.h" -#include "IMP/restraints/PairListRestraint.h" -#include "IMP/restraints/TripletChainRestraint.h" -#include "IMP/score_states/BipartiteNonbondedListScoreState.h" -#include "IMP/score_states/MaxChangeScoreState.h" -#include "IMP/score_states/NonbondedListScoreState.h" -#include "IMP/score_states/BondedListScoreState.h" -#include "IMP/score_states/BondDecoratorListScoreState.h" -#include "IMP/score_states/AllNonbondedListScoreState.h" -#include "IMP/score_states/AllSphereNonbondedListScoreState.h" - -/** - \namespace IMP The IMP namespace. - */ - +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #endif /* __IMP_H */ Index: kernel/pyext/IMP.i =================================================================== --- kernel/pyext/IMP.i (revision 441) +++ kernel/pyext/IMP.i (working copy) @@ -100,7 +100,6 @@ %include "IMP/unary_functions/ClosedCubicSpline.h" %include "IMP/unary_functions/Cosine.h" %include "IMP/unary_functions/Linear.h" -%include "IMP/ScoreFuncParams.h" %include "IMP/DerivativeAccumulator.h" %include "IMP/Restraint.h" %include "IMP/ScoreState.h" @@ -140,11 +139,7 @@ %include "IMP/restraints/AngleRestraint.h" %include "IMP/restraints/TripletChainRestraint.h" %include "IMP/restraints/DihedralRestraint.h" -%include "IMP/restraints/TorusRestraint.h" -%include "IMP/restraints/ProximityRestraint.h" %include "IMP/restraints/ConnectivityRestraint.h" -%include "IMP/restraints/PairConnectivityRestraint.h" -%include "IMP/restraints/ExclusionVolumeRestraint.h" %include "IMP/restraints/NonbondedRestraint.h" %include "IMP/restraints/BondDecoratorRestraint.h" %include "IMP/restraints/SingletonListRestraint.h" Index: kernel/test/pair_connectivity/test_pair_connectivity.py =================================================================== --- kernel/test/pair_connectivity/test_pair_connectivity.py (revision 441) +++ kernel/test/pair_connectivity/test_pair_connectivity.py (working copy) @@ -1,181 +0,0 @@ -import unittest -import os -import IMP -import IMP.test -import IMP.utils - -class PairConnectivityRestraintTests(IMP.test.TestCase): - """Test pair connectivity restraints.""" - - def setUp(self): - """Build test model and optimizer""" - self.imp_model = IMP.Model() - self.particles = [] - self.restraint_sets = [] - self.rsrs = [] - - for p in range(12): - self.particles.append(IMP.utils.XYZParticle(self.imp_model, - 0., 0., 0.)) - p1 = self.particles[0] - radkey= IMP.FloatKey("radius") - pkey=IMP.IntKey("protein") - idkey=IMP.IntKey("id") - - p1.add_attribute(radkey, 1.0, False) - p1.add_attribute(pkey, 1) - p1.add_attribute(idkey, 1) - - p1 = self.particles[1] - p1.add_attribute(radkey, 1.0, False) - p1.add_attribute(pkey, 1) - p1.add_attribute(idkey, 2) - - p1 = self.particles[2] - p1.add_attribute(radkey, 1.0, False) - p1.add_attribute(pkey, 1) - p1.add_attribute(idkey, 3) - - p1 = self.particles[3] - p1.add_attribute(radkey, 1.5, False) - p1.add_attribute(pkey, 1) - p1.add_attribute(idkey, 4) - - p1 = self.particles[4] - p1.add_attribute(radkey, 1.5, False) - p1.add_attribute(pkey, 1) - p1.add_attribute(idkey, 5) - - p1 = self.particles[5] - p1.add_attribute(radkey, 1.5, False) - p1.add_attribute(pkey, 2) - p1.add_attribute(idkey, 6) - - p1 = self.particles[6] - p1.add_attribute(radkey, 1.5, False) - p1.add_attribute(pkey, 2) - p1.add_attribute(idkey, 7) - - p1 = self.particles[7] - p1.add_attribute(radkey, 2.0, False) - p1.add_attribute(pkey, 2) - p1.add_attribute(idkey, 8) - - p1 = self.particles[8] - p1.add_attribute(radkey, 2.0, False) - p1.add_attribute(pkey, 2) - p1.add_attribute(idkey, 9) - - p1 = self.particles[9] - p1.add_attribute(radkey, 2.0, False) - p1.add_attribute(pkey, 2) - p1.add_attribute(idkey, 10) - - p1 = self.particles[10] - p1.add_attribute(radkey, 2.0, False) - p1.add_attribute(pkey, 2) - p1.add_attribute(idkey, 11) - - p1 = self.particles[11] - p1.add_attribute(radkey, 2.0, False) - p1.add_attribute(pkey, 2) - p1.add_attribute(idkey, 12) - - self.opt = IMP.ConjugateGradients() - self.opt.set_model(self.imp_model) - self.opt.set_threshold(1e-4) - - def _run_test_pair_connectivity(self, use_python): - """Test pair connectivity restraint. - All particles in a single protein should be connected, and all - proteins should be connected, either directly or indirectly - through other proteins """ - rs = IMP.RestraintSet("connect") - self.restraint_sets.append(rs) - self.imp_model.add_restraint(rs) - - # add connectivity restraints - - particle_indexes1 = IMP.Ints() - particle_indexes2 = IMP.Ints() - rsrs = [] - # connect 2 proteins together by two beads - particle_indexes1.clear() - for i in range(0, 5): - particle_indexes1.push_back(i) - particle_indexes2.clear() - for i in range(5, 12): - particle_indexes2.push_back(i) - num_connects = 3 - - if use_python: - # set up exclusion volumes using a Python loop: - IMP.utils.set_up_exclusion_volumes(self.imp_model, self.particles, - IMP.FloatKey("radius"), rsrs) - else: - # use the C++ exclusion volume restraint: - score_func_params = IMP.BasicScoreFuncParams("harmonic_lower_bound", - 0.0, 0.1) - rsrs.append(IMP.ExclusionVolumeRestraint(self.imp_model, - particle_indexes1, - particle_indexes2, - IMP.FloatKey("radius"), - score_func_params)) - - # it should work whether this is True or False - # However, if it is False, the close pairs should all be between - # distinct particles - particle_reuse = False - score_func_params = IMP.BasicScoreFuncParams("harmonic_upper_bound", - 0.0, 0.1) - rsrs.append(IMP.PairConnectivityRestraint(self.imp_model, - particle_indexes1, - particle_indexes2, - IMP.FloatKey("radius"), - score_func_params, - num_connects, particle_reuse)) - - # add restraints - for i in range(len(rsrs)): - rs.add_restraint(rsrs[i]) - - self.randomize_particles(self.particles, 50.0) - self.opt.optimize(55) - - # min distances - min_dist = [] - for i in range(num_connects): - min_dist.append(10000000) - - for (i, pi) in enumerate(self.particles[0:5]): - icoord = (pi.x(), pi.y(), pi.z()) - irad = pi.get_value(IMP.FloatKey("radius")) - for (j, pj) in enumerate(self.particles[5:12]): - jcoord = (pj.x(), pj.y(), pj.z()) - jrad = pj.get_value(IMP.FloatKey("radius")) - d = self.get_distance(icoord, jcoord) - irad - jrad - found = False - for k in range(num_connects): - if not found: - if d < min_dist[k]: - found = True - - if found: - d1 = min_dist[k] - min_dist[k] = d - d = d1 - - for i in range(num_connects): - self.assert_(min_dist[i] < 0.05, - "min distance for any pair condition") - - def test_pair_connectivity_python(self): - """Test pair connectivity restraint using Python exclusion volumes""" - self._run_test_pair_connectivity(True) - - def test_pair_connectivity_c(self): - """Test pair connectivity restraint using C++ exclusion volumes""" - self._run_test_pair_connectivity(False) - -if __name__ == '__main__': - unittest.main() Index: kernel/test/pair_connectivity/test_pair_connectivity.py =================================================================== --- kernel/test/pair_connectivity/test_pair_connectivity.py (revision 441) +++ kernel/test/pair_connectivity/test_pair_connectivity.py (working copy) @@ -1,181 +0,0 @@ -import unittest -import os -import IMP -import IMP.test -import IMP.utils - -class PairConnectivityRestraintTests(IMP.test.TestCase): - """Test pair connectivity restraints.""" - - def setUp(self): - """Build test model and optimizer""" - self.imp_model = IMP.Model() - self.particles = [] - self.restraint_sets = [] - self.rsrs = [] - - for p in range(12): - self.particles.append(IMP.utils.XYZParticle(self.imp_model, - 0., 0., 0.)) - p1 = self.particles[0] - radkey= IMP.FloatKey("radius") - pkey=IMP.IntKey("protein") - idkey=IMP.IntKey("id") - - p1.add_attribute(radkey, 1.0, False) - p1.add_attribute(pkey, 1) - p1.add_attribute(idkey, 1) - - p1 = self.particles[1] - p1.add_attribute(radkey, 1.0, False) - p1.add_attribute(pkey, 1) - p1.add_attribute(idkey, 2) - - p1 = self.particles[2] - p1.add_attribute(radkey, 1.0, False) - p1.add_attribute(pkey, 1) - p1.add_attribute(idkey, 3) - - p1 = self.particles[3] - p1.add_attribute(radkey, 1.5, False) - p1.add_attribute(pkey, 1) - p1.add_attribute(idkey, 4) - - p1 = self.particles[4] - p1.add_attribute(radkey, 1.5, False) - p1.add_attribute(pkey, 1) - p1.add_attribute(idkey, 5) - - p1 = self.particles[5] - p1.add_attribute(radkey, 1.5, False) - p1.add_attribute(pkey, 2) - p1.add_attribute(idkey, 6) - - p1 = self.particles[6] - p1.add_attribute(radkey, 1.5, False) - p1.add_attribute(pkey, 2) - p1.add_attribute(idkey, 7) - - p1 = self.particles[7] - p1.add_attribute(radkey, 2.0, False) - p1.add_attribute(pkey, 2) - p1.add_attribute(idkey, 8) - - p1 = self.particles[8] - p1.add_attribute(radkey, 2.0, False) - p1.add_attribute(pkey, 2) - p1.add_attribute(idkey, 9) - - p1 = self.particles[9] - p1.add_attribute(radkey, 2.0, False) - p1.add_attribute(pkey, 2) - p1.add_attribute(idkey, 10) - - p1 = self.particles[10] - p1.add_attribute(radkey, 2.0, False) - p1.add_attribute(pkey, 2) - p1.add_attribute(idkey, 11) - - p1 = self.particles[11] - p1.add_attribute(radkey, 2.0, False) - p1.add_attribute(pkey, 2) - p1.add_attribute(idkey, 12) - - self.opt = IMP.ConjugateGradients() - self.opt.set_model(self.imp_model) - self.opt.set_threshold(1e-4) - - def _run_test_pair_connectivity(self, use_python): - """Test pair connectivity restraint. - All particles in a single protein should be connected, and all - proteins should be connected, either directly or indirectly - through other proteins """ - rs = IMP.RestraintSet("connect") - self.restraint_sets.append(rs) - self.imp_model.add_restraint(rs) - - # add connectivity restraints - - particle_indexes1 = IMP.Ints() - particle_indexes2 = IMP.Ints() - rsrs = [] - # connect 2 proteins together by two beads - particle_indexes1.clear() - for i in range(0, 5): - particle_indexes1.push_back(i) - particle_indexes2.clear() - for i in range(5, 12): - particle_indexes2.push_back(i) - num_connects = 3 - - if use_python: - # set up exclusion volumes using a Python loop: - IMP.utils.set_up_exclusion_volumes(self.imp_model, self.particles, - IMP.FloatKey("radius"), rsrs) - else: - # use the C++ exclusion volume restraint: - score_func_params = IMP.BasicScoreFuncParams("harmonic_lower_bound", - 0.0, 0.1) - rsrs.append(IMP.ExclusionVolumeRestraint(self.imp_model, - particle_indexes1, - particle_indexes2, - IMP.FloatKey("radius"), - score_func_params)) - - # it should work whether this is True or False - # However, if it is False, the close pairs should all be between - # distinct particles - particle_reuse = False - score_func_params = IMP.BasicScoreFuncParams("harmonic_upper_bound", - 0.0, 0.1) - rsrs.append(IMP.PairConnectivityRestraint(self.imp_model, - particle_indexes1, - particle_indexes2, - IMP.FloatKey("radius"), - score_func_params, - num_connects, particle_reuse)) - - # add restraints - for i in range(len(rsrs)): - rs.add_restraint(rsrs[i]) - - self.randomize_particles(self.particles, 50.0) - self.opt.optimize(55) - - # min distances - min_dist = [] - for i in range(num_connects): - min_dist.append(10000000) - - for (i, pi) in enumerate(self.particles[0:5]): - icoord = (pi.x(), pi.y(), pi.z()) - irad = pi.get_value(IMP.FloatKey("radius")) - for (j, pj) in enumerate(self.particles[5:12]): - jcoord = (pj.x(), pj.y(), pj.z()) - jrad = pj.get_value(IMP.FloatKey("radius")) - d = self.get_distance(icoord, jcoord) - irad - jrad - found = False - for k in range(num_connects): - if not found: - if d < min_dist[k]: - found = True - - if found: - d1 = min_dist[k] - min_dist[k] = d - d = d1 - - for i in range(num_connects): - self.assert_(min_dist[i] < 0.05, - "min distance for any pair condition") - - def test_pair_connectivity_python(self): - """Test pair connectivity restraint using Python exclusion volumes""" - self._run_test_pair_connectivity(True) - - def test_pair_connectivity_c(self): - """Test pair connectivity restraint using C++ exclusion volumes""" - self._run_test_pair_connectivity(False) - -if __name__ == '__main__': - unittest.main() Index: kernel/test/xml/model.xml =================================================================== --- kernel/test/xml/model.xml (revision 441) +++ kernel/test/xml/model.xml (working copy) @@ -1,200 +0,0 @@ - - - - - - - - - 2.0 - F - - - 1 - - - - - - - - - 2.0 - F - - - 1 - - - - - - - - - 2.0 - F - - - 1 - - - - - - - - - 1.5 - F - - - 2 - - - - - - - - - 1.5 - F - - - 2 - - - - - - - - - 1.5 - F - - - 2 - - - - - - - - - 1.5 - F - - - 2 - - - - - - - - - 1.0 - F - - - 3 - - - - - - - - - 1.0 - F - - - 3 - - - - - - - - - 1.0 - F - - - 3 - - - - - - - - - 1.0 - F - - - 3 - - - - - - - - - 1.0 - F - - - 3 - - - - - - - - 0 1 2 3 4 5 6 7 8 9 10 11 - - harmonic_lower_bound - radius - 0.1 - - - - - - 0 1 2 3 4 5 6 7 8 9 10 11 - harmonic_upper_bound - 50 - 8 - 0.1 - - - - - - - 0 1 - 1 2 - 3 4 - 4 5 - 5 6 - 7 8 - 8 9 - 9 10 - 10 11 - - harmonic_upper_bound - radius - 0.1 - - - Index: kernel/test/xml/invalid.xml =================================================================== --- kernel/test/xml/invalid.xml (revision 441) +++ kernel/test/xml/invalid.xml (working copy) @@ -1,19 +0,0 @@ - - - - - - - - - - - - - 0 - 50 - 8 - 0.1 - - - Index: kernel/test/xml/test_xml.py =================================================================== --- kernel/test/xml/test_xml.py (revision 441) +++ kernel/test/xml/test_xml.py (working copy) @@ -1,53 +0,0 @@ -import unittest -import os -import IMP.test, IMP -import IMP.xml_loader - -class XMLTests(IMP.test.TestCase): - """Test XML file loading""" - - def setUp(self): - """Set up IMP model""" - self.imp_model = IMP.Model() - - def test_invalid_xml(self): - """Check reading of invalid XML files""" - self.assertRaises(IMP.xml_loader.MalformedError, - IMP.xml_loader.load_imp_model, self.imp_model, - "xml/invalid.xml") - - def test_xml(self): - """Check reading of XML files""" - self.doc = IMP.xml_loader.load_imp_model(self.imp_model, - "xml/model.xml") - - # test particles - num_particles = 0 - for p in self.imp_model.get_particles(): - radius = p.get_value(IMP.FloatKey("radius")) - protein = p.get_value(IMP.IntKey("protein")) - num_particles = num_particles + 1 - if protein == 1: - self.assert_(radius == 2.0, "protein1 beads should have radius 2.0") - elif protein == 2: - self.assert_(radius == 1.5, "protein2 beads should have radius 1.5") - elif protein == 3: - self.assert_(radius == 1.0, "protein3 beads should have radius 1.0") - - self.assert_(num_particles == 12, "number of particles is incorrect") - - # test restraint sets - #restraint_sets = self.imp_model.get_restraints - self.assertEqual(self.imp_model.number_of_restraints(), 3, - "xml file contains three restraint sets") - - # test restraints - score = self.imp_model.get_restraint(IMP.RestraintIndex(0)).evaluate(None) - self.assert_((score > 16000) and (score < 17000), "expecting a score of 16198.2236328 not : " + str(score)) - score = self.imp_model.get_restraint(IMP.RestraintIndex(1)).evaluate(None) - self.assert_((score > 624000) and (score < 625000), "expecting a score of 624531.0625 not : " + str(score)) - score = self.imp_model.get_restraint(IMP.RestraintIndex(2)).evaluate(None) - self.assert_((score > -100) and (score < 100), "expecting a score of 0.0 not : " + str(score)) - -if __name__ == '__main__': - unittest.main() Index: kernel/test/xml/run_xml.py =================================================================== --- kernel/test/xml/run_xml.py (revision 441) +++ kernel/test/xml/run_xml.py (working copy) @@ -1,39 +0,0 @@ -import modeller -import modeller.optimizers -import IMP -import IMP.modeller_intf -import IMP.utils -import IMP.xml_loader - -model = IMP.Model() - -# load document from an XML file -doc = IMP.xml_loader.load_imp_model(model, "test.xml") - -# intialize Modeller -modeller.log.level(0,0,0,0,0) -env = modeller.environ() -env.io.atom_files_directory = '../data/' -env.edat.dynamic_sphere = False -env.libs.topology.read(file='$(LIB)/top_heav.lib') -env.libs.parameters.read(file='$(LIB)/par.lib') - - -# add IMP model and restraints as an energy term to Modeller model -t = env.edat.energy_terms -t.append(IMP.modeller_intf.IMPRestraints(model, model.particles)) - -# get particles for Modeller -mdl = IMP.modeller_intf.create_particles_from_imp(env, model) - -atmsel = modeller.selection(mdl) -atoms = mdl.atoms -atmsel.randomize_xyz(deviation=100.0) - -model.set_up_trajectory("trajectory.txt") -opt = modeller.optimizers.conjugate_gradients() -new_mdl = opt.optimize (atmsel, max_iterations=55, actions=None) -print atmsel.energy() - -IMP.utils.show_distances(model.particles) -mdl.write(file='out_test_xml.pdb', model_format='PDB') Index: kernel/test/xml/model.xml =================================================================== --- kernel/test/xml/model.xml (revision 441) +++ kernel/test/xml/model.xml (working copy) @@ -1,200 +0,0 @@ - - - - - - - - - 2.0 - F - - - 1 - - - - - - - - - 2.0 - F - - - 1 - - - - - - - - - 2.0 - F - - - 1 - - - - - - - - - 1.5 - F - - - 2 - - - - - - - - - 1.5 - F - - - 2 - - - - - - - - - 1.5 - F - - - 2 - - - - - - - - - 1.5 - F - - - 2 - - - - - - - - - 1.0 - F - - - 3 - - - - - - - - - 1.0 - F - - - 3 - - - - - - - - - 1.0 - F - - - 3 - - - - - - - - - 1.0 - F - - - 3 - - - - - - - - - 1.0 - F - - - 3 - - - - - - - - 0 1 2 3 4 5 6 7 8 9 10 11 - - harmonic_lower_bound - radius - 0.1 - - - - - - 0 1 2 3 4 5 6 7 8 9 10 11 - harmonic_upper_bound - 50 - 8 - 0.1 - - - - - - - 0 1 - 1 2 - 3 4 - 4 5 - 5 6 - 7 8 - 8 9 - 9 10 - 10 11 - - harmonic_upper_bound - radius - 0.1 - - - Index: kernel/test/xml/invalid.xml =================================================================== --- kernel/test/xml/invalid.xml (revision 441) +++ kernel/test/xml/invalid.xml (working copy) @@ -1,19 +0,0 @@ - - - - - - - - - - - - - 0 - 50 - 8 - 0.1 - - - Index: kernel/test/xml/test_xml.py =================================================================== --- kernel/test/xml/test_xml.py (revision 441) +++ kernel/test/xml/test_xml.py (working copy) @@ -1,53 +0,0 @@ -import unittest -import os -import IMP.test, IMP -import IMP.xml_loader - -class XMLTests(IMP.test.TestCase): - """Test XML file loading""" - - def setUp(self): - """Set up IMP model""" - self.imp_model = IMP.Model() - - def test_invalid_xml(self): - """Check reading of invalid XML files""" - self.assertRaises(IMP.xml_loader.MalformedError, - IMP.xml_loader.load_imp_model, self.imp_model, - "xml/invalid.xml") - - def test_xml(self): - """Check reading of XML files""" - self.doc = IMP.xml_loader.load_imp_model(self.imp_model, - "xml/model.xml") - - # test particles - num_particles = 0 - for p in self.imp_model.get_particles(): - radius = p.get_value(IMP.FloatKey("radius")) - protein = p.get_value(IMP.IntKey("protein")) - num_particles = num_particles + 1 - if protein == 1: - self.assert_(radius == 2.0, "protein1 beads should have radius 2.0") - elif protein == 2: - self.assert_(radius == 1.5, "protein2 beads should have radius 1.5") - elif protein == 3: - self.assert_(radius == 1.0, "protein3 beads should have radius 1.0") - - self.assert_(num_particles == 12, "number of particles is incorrect") - - # test restraint sets - #restraint_sets = self.imp_model.get_restraints - self.assertEqual(self.imp_model.number_of_restraints(), 3, - "xml file contains three restraint sets") - - # test restraints - score = self.imp_model.get_restraint(IMP.RestraintIndex(0)).evaluate(None) - self.assert_((score > 16000) and (score < 17000), "expecting a score of 16198.2236328 not : " + str(score)) - score = self.imp_model.get_restraint(IMP.RestraintIndex(1)).evaluate(None) - self.assert_((score > 624000) and (score < 625000), "expecting a score of 624531.0625 not : " + str(score)) - score = self.imp_model.get_restraint(IMP.RestraintIndex(2)).evaluate(None) - self.assert_((score > -100) and (score < 100), "expecting a score of 0.0 not : " + str(score)) - -if __name__ == '__main__': - unittest.main() Index: kernel/test/xml/run_xml.py =================================================================== --- kernel/test/xml/run_xml.py (revision 441) +++ kernel/test/xml/run_xml.py (working copy) @@ -1,39 +0,0 @@ -import modeller -import modeller.optimizers -import IMP -import IMP.modeller_intf -import IMP.utils -import IMP.xml_loader - -model = IMP.Model() - -# load document from an XML file -doc = IMP.xml_loader.load_imp_model(model, "test.xml") - -# intialize Modeller -modeller.log.level(0,0,0,0,0) -env = modeller.environ() -env.io.atom_files_directory = '../data/' -env.edat.dynamic_sphere = False -env.libs.topology.read(file='$(LIB)/top_heav.lib') -env.libs.parameters.read(file='$(LIB)/par.lib') - - -# add IMP model and restraints as an energy term to Modeller model -t = env.edat.energy_terms -t.append(IMP.modeller_intf.IMPRestraints(model, model.particles)) - -# get particles for Modeller -mdl = IMP.modeller_intf.create_particles_from_imp(env, model) - -atmsel = modeller.selection(mdl) -atoms = mdl.atoms -atmsel.randomize_xyz(deviation=100.0) - -model.set_up_trajectory("trajectory.txt") -opt = modeller.optimizers.conjugate_gradients() -new_mdl = opt.optimize (atmsel, max_iterations=55, actions=None) -print atmsel.energy() - -IMP.utils.show_distances(model.particles) -mdl.write(file='out_test_xml.pdb', model_format='PDB') Index: kernel/test/modeller/test_exclusion_volumes.py =================================================================== --- kernel/test/modeller/test_exclusion_volumes.py (revision 441) +++ kernel/test/modeller/test_exclusion_volumes.py (working copy) @@ -1,239 +0,0 @@ -import modeller, unittest -import modeller -import modeller.optimizers -import os -import IMP -import IMP.modeller_intf -import IMP.test - -radius = IMP.FloatKey("radius") - -class ExclusionVolumeRestraintTests(IMP.test.TestCase): - """Test exclusion volume restraints""" - - def setUp(self): - """set up Modeller with exclusion volumes restraints """ - modeller.log.level(0,0,0,0,0) - - self.env = modeller.environ() - self.env.io.atom_files_directory = '../data/' - self.env.edat.dynamic_sphere = False - self.env.libs.topology.read(file='$(LIB)/top_heav.lib') - self.env.libs.parameters.read(file='$(LIB)/par.lib') - - self.imp_model = IMP.Model() - self.particles = [] - self.restraint_sets = [] - self.rsrs = [] - - self.t = self.env.edat.energy_terms - self.t.append(IMP.modeller_intf.IMPRestraints(self.imp_model, - self.particles)) - - self.modeller_model = IMP.modeller_intf.create_particles(12, self.env, - self.imp_model, - self.particles) - p1 = self.particles[0] - p1.add_attribute(radius, 1.0, False) - p1.add_attribute(IMP.IntKey("protein"), 1) - p1.add_attribute(IMP.IntKey("id"), 1) - - p1 = self.particles[1] - p1.add_attribute(radius, 1.0, False) - p1.add_attribute(IMP.IntKey("protein"), 1) - p1.add_attribute(IMP.IntKey("id"), 2) - - p1 = self.particles[2] - p1.add_attribute(radius, 1.0, False) - p1.add_attribute(IMP.IntKey("protein"), 1) - p1.add_attribute(IMP.IntKey("id"), 3) - - p1 = self.particles[3] - p1.add_attribute(radius, 1.5, False) - p1.add_attribute(IMP.IntKey("protein"), 1) - p1.add_attribute(IMP.IntKey("id"), 4) - - p1 = self.particles[4] - p1.add_attribute(radius, 1.5, False) - p1.add_attribute(IMP.IntKey("protein"), 1) - p1.add_attribute(IMP.IntKey("id"), 5) - - p1 = self.particles[5] - p1.add_attribute(radius, 1.5, False) - p1.add_attribute(IMP.IntKey("protein"), 2) - p1.add_attribute(IMP.IntKey("id"), 6) - - p1 = self.particles[6] - p1.add_attribute(radius, 1.5, False) - p1.add_attribute(IMP.IntKey("protein"), 2) - p1.add_attribute(IMP.IntKey("id"), 7) - - p1 = self.particles[7] - p1.add_attribute(radius, 2.0, False) - p1.add_attribute(IMP.IntKey("protein"), 2) - p1.add_attribute(IMP.IntKey("id"), 8) - - p1 = self.particles[8] - p1.add_attribute(radius, 2.0, False) - p1.add_attribute(IMP.IntKey("protein"), 2) - p1.add_attribute(IMP.IntKey("id"), 9) - - p1 = self.particles[9] - p1.add_attribute(radius, 2.0, False) - p1.add_attribute(IMP.IntKey("protein"), 2) - p1.add_attribute(IMP.IntKey("id"), 10) - - p1 = self.particles[10] - p1.add_attribute(radius, 2.0, False) - p1.add_attribute(IMP.IntKey("protein"), 2) - p1.add_attribute(IMP.IntKey("id"), 11) - - p1 = self.particles[11] - p1.add_attribute(radius, 2.0, False) - p1.add_attribute(IMP.IntKey("protein"), 2) - p1.add_attribute(IMP.IntKey("id"), 12) - - self.atmsel = modeller.selection(self.modeller_model) - - self.opt = modeller.optimizers.conjugate_gradients() - - - def test_exclusion_volumes_one_list(self): - """Test exclusion volumes (intra-protein). - All particles in a single protein should be connected but should - not be closer than allowed by their VDW radii.""" - rs = IMP.RestraintSet("one_list") - self.restraint_sets.append(rs) - self.imp_model.add_restraint(rs) - - # add connectivity restraints - - particle_indexes1 = IMP.Ints() - particle_indexes2 = IMP.Ints() - rsrs = [] - - # connect 2 proteins together by two beads - particle_indexes1.clear() - for i in range(0, 5): - particle_indexes1.push_back(i) - particle_indexes2.clear() - for i in range(5, 12): - particle_indexes2.push_back(i) - - # connect the beads within the two proteins together - for i in range(0, 4): - p1 = self.particles[i] - p2 = self.particles[i+1] - mean = p1.get_value(radius) + p2.get_value(radius) - sf = IMP.HarmonicUpperBound(mean, 0.1) - rsrs.append(IMP.DistanceRestraint(p1, p2, sf)) - - for i in range(5, 11): - p1 = self.particles[i] - p2 = self.particles[i+1] - mean = p1.get_value(radius) + p2.get_value(radius) - sf = IMP.HarmonicUpperBound(mean, 0.1) - rsrs.append(IMP.DistanceRestraint(p1, p2, sf)) - - # create the exclusion volume for each protein - score_func_params_lb = IMP.BasicScoreFuncParams("harmonic_lower_bound", 0.0, 0.1) - rsrs.append(IMP.ExclusionVolumeRestraint(self.imp_model, particle_indexes1, radius, score_func_params_lb)) - rsrs.append(IMP.ExclusionVolumeRestraint(self.imp_model, particle_indexes2, radius, score_func_params_lb)) - - # add restraints - for i in range(len(rsrs)): - rs.add_restraint(rsrs[i]) - - self.atmsel.randomize_xyz(deviation=100.0) - new_mdl = self.opt.optimize (self.atmsel, max_iterations=100, actions=None) - self.modeller_model.write (file='out_exclusion_volume_one_list.pdb', model_format='PDB') - - coords = self.load_coordinates('out_exclusion_volume_one_list.pdb') - os.unlink('out_exclusion_volume_one_list.pdb') - - # check min distances for intra-protein pairs - for i in range(0, 4): - for j in range(i+1, 5): - d = self.get_distance(coords[i], coords[j]) - self.particles[i].get_value(radius) - self.particles[j].get_value(radius) - self.assert_(d > -0.05, "particles "+str(i)+" and "+str(j)+" are too close together.") - - for i in range(5, 11): - for j in range(i+1, 12): - d = self.get_distance(coords[i], coords[j]) - self.particles[i].get_value(radius) - self.particles[j].get_value(radius) - self.assert_(d > -0.05, "particles "+str(i)+" and "+str(j)+" are too close together.") - - - def test_exclusion_volumes_two_lists(self): - """Test exclusion volumes (intra- and inter-protein). - All particles in a single protein should be connected and the two - proteins should be connected in four locations but beads should - not be closer than allowed by their VDW radii.""" - rs = IMP.RestraintSet("two_lists") - self.restraint_sets.append(rs) - self.imp_model.add_restraint(rs) - - # add connectivity restraints - - particle_indexes1 = IMP.Ints() - particle_indexes2 = IMP.Ints() - rsrs = [] - - # connect 2 proteins together by two beads - particle_indexes1.clear() - for i in range(0, 5): - particle_indexes1.push_back(i) - particle_indexes2.clear() - for i in range(5, 12): - particle_indexes2.push_back(i) - - # connect the beads within the two proteins together - for i in range(0, 4): - p1 = self.particles[i] - p2 = self.particles[i+1] - mean = p1.get_value(radius) + p2.get_value(radius) - sf = IMP.HarmonicUpperBound(mean, 0.1) - rsrs.append(IMP.DistanceRestraint(p1, p2, sf)) - - for i in range(5, 11): - p1 = self.particles[i] - p2 = self.particles[i+1] - mean = p1.get_value(radius) + p2.get_value(radius) - sf = IMP.HarmonicUpperBound(mean, 0.1) - rsrs.append(IMP.DistanceRestraint(p1, p2, sf)) - - # create the exclusion volume for each protein - score_func_params_lb = IMP.BasicScoreFuncParams("harmonic_lower_bound", 0.0, 0.1) - rsrs.append(IMP.ExclusionVolumeRestraint(self.imp_model, particle_indexes1, radius, score_func_params_lb)) - rsrs.append(IMP.ExclusionVolumeRestraint(self.imp_model, particle_indexes2, radius, score_func_params_lb)) - - # connect the beads within the two proteins together - # get 4 distinct pairs - num_connects = 4 - particle_reuse = False - score_func_params_ub = IMP.BasicScoreFuncParams("harmonic_upper_bound", - 0.0, 0.1) - rsrs.append(IMP.PairConnectivityRestraint(self.imp_model, particle_indexes1, particle_indexes2, radius, score_func_params_ub, num_connects, particle_reuse)) - - # create the exclusion volume for each protein - score_func_params_lb = IMP.BasicScoreFuncParams("harmonic_lower_bound", 0.0, 0.1) - rsrs.append(IMP.ExclusionVolumeRestraint(self.imp_model, particle_indexes1, particle_indexes2, radius, score_func_params_lb)) - - # add restraints - for i in range(len(rsrs)): - rs.add_restraint(rsrs[i]) - - self.atmsel.randomize_xyz(deviation=100.0) - new_mdl = self.opt.optimize (self.atmsel, max_iterations=200, actions=None) - self.modeller_model.write (file='out_exclusion_volume_two_lists.pdb', model_format='PDB') - - coords = self.load_coordinates('out_exclusion_volume_two_lists.pdb') - os.unlink('out_exclusion_volume_two_lists.pdb') - - # check min distances for intra-protein and inter-protein pairs - for i in range(0, 11): - for j in range(i+1, 12): - d = self.get_distance(coords[i], coords[j]) - self.particles[i].get_value(radius) - self.particles[j].get_value(radius) - self.assert_(d > -0.05, "particles "+str(i)+" and "+str(j)+" are too close together.") - -if __name__ == '__main__': - unittest.main() Index: kernel/test/modeller/test_proximity.py =================================================================== --- kernel/test/modeller/test_proximity.py (revision 441) +++ kernel/test/modeller/test_proximity.py (working copy) @@ -1,127 +0,0 @@ -import modeller, unittest -import modeller -import modeller.optimizers -import os -import IMP -import IMP.modeller_intf -import IMP.utils -import IMP.test - -radius = IMP.FloatKey("radius") - -class ProximityRestraintTests(IMP.test.TestCase): - """Test proximity restraints""" - - def setUp(self): - """set up Modeller with proximity restraints """ - modeller.log.level(0,0,0,0,0) - - self.env = modeller.environ() - self.env.io.atom_files_directory = '../data/' - self.env.edat.dynamic_sphere = False - self.env.libs.topology.read(file='$(LIB)/top_heav.lib') - self.env.libs.parameters.read(file='$(LIB)/par.lib') - - self.imp_model = IMP.Model() - self.particles = [] - self.restraint_sets = [] - self.rsrs = [] - - self.t = self.env.edat.energy_terms - self.t.append(IMP.modeller_intf.IMPRestraints(self.imp_model, - self.particles)) - - self.modeller_model = IMP.modeller_intf.create_particles(6, self.env, - self.imp_model, - self.particles) - p1 = self.particles[0] - p1.add_attribute(radius, 2.0, False) - p1.add_attribute(IMP.IntKey("protein"), 1) - p1.add_attribute(IMP.IntKey("id"), 1) - - p1 = self.particles[1] - p1.add_attribute(radius, 2.0, False) - p1.add_attribute(IMP.IntKey("protein"), 1) - p1.add_attribute(IMP.IntKey("id"), 2) - - p1 = self.particles[2] - p1.add_attribute(radius, 1.5, False) - p1.add_attribute(IMP.IntKey("protein"), 2) - p1.add_attribute(IMP.IntKey("id"), 3) - - p1 = self.particles[3] - p1.add_attribute(radius, 1.5, False) - p1.add_attribute(IMP.IntKey("protein"), 2) - p1.add_attribute(IMP.IntKey("id"), 4) - - p1 = self.particles[4] - p1.add_attribute(radius, 1.0, False) - p1.add_attribute(IMP.IntKey("protein"), 3) - p1.add_attribute(IMP.IntKey("id"), 5) - - p1 = self.particles[5] - p1.add_attribute(radius, 1.0, False) - p1.add_attribute(IMP.IntKey("protein"), 3) - p1.add_attribute(IMP.IntKey("id"), 6) - - self.atmsel = modeller.selection(self.modeller_model) - - self.opt = modeller.optimizers.conjugate_gradients() - - - def test_proximity(self): - """Test proximity restraints using Modeller optimizers""" - self.atmsel.randomize_xyz(deviation=100.0) - - self.restraint_sets.append(IMP.RestraintSet("proximity")) - rs = self.restraint_sets[len(self.restraint_sets)-1] - self.imp_model.add_restraint(rs) - - # add proximity restraints - - particle_indexes = IMP.Ints() - rsrs = [] - - # set up exclusion volumes - IMP.utils.set_up_exclusion_volumes(self.imp_model, self.particles, - radius, rsrs) - - max_distance = 10.0 - - # set max distance for two most distant particles together - particle_indexes.clear() - for i in range(6): - particle_indexes.push_back(i) - - score_func_params = IMP.BasicScoreFuncParams("harmonic_upper_bound", 0.0, 0.1) - rsrs.append(IMP.ProximityRestraint(self.imp_model, particle_indexes, - radius, max_distance, - score_func_params)) - - # add restraints - for i in range(len(rsrs)): - rs.add_restraint(rsrs[i]) - - self.atmsel.randomize_xyz(deviation=100.0) - new_mdl = self.opt.optimize (self.atmsel, max_iterations=1800, actions=None) - self.modeller_model.write (file='out_proximity.pdb', model_format='PDB') - - coords = self.load_coordinates('out_proximity.pdb') - os.unlink('out_proximity.pdb') - - # min distances - for i in range(len(coords)): - irad = self.particles[i].get_value(radius) - for j in range(i+1,len(coords)): - jrad = self.particles[j].get_value(radius) - self.assert_(self.check_min_distance(coords[i], coords[j], irad + jrad - 0.1), "min distance for any pair condition (" + str(i) + ", " + str(j) + ")") - - # max distances - for i in range(len(coords)): - irad = self.particles[i].get_value(radius) - for j in range(i+1,len(coords)): - jrad = self.particles[j].get_value(radius) - self.assert_(self.check_max_distance(coords[i], coords[j], max_distance - irad - jrad + 0.1), "max distance for any pair condition (" + str(i) + ", " + str(j) + ")") - -if __name__ == '__main__': - unittest.main() Index: kernel/test/modeller/test_easy_proximity.py =================================================================== --- kernel/test/modeller/test_easy_proximity.py (revision 441) +++ kernel/test/modeller/test_easy_proximity.py (working copy) @@ -1,111 +0,0 @@ -import modeller, unittest -import modeller.optimizers -import os -import IMP -import IMP.modeller_intf -import IMP.utils -import IMP.test - -radius = IMP.FloatKey("radius") - -class ProximityRestraintTests(IMP.test.TestCase): - """Test proximity restraints""" - - def setUp(self): - """set up Modeller with proximity restraints """ - modeller.log.level(0,0,0,0,0) - - self.env = modeller.environ() - self.env.io.atom_files_directory = '../data/' - self.env.edat.dynamic_sphere = False - self.env.libs.topology.read(file='$(LIB)/top_heav.lib') - self.env.libs.parameters.read(file='$(LIB)/par.lib') - - self.imp_model = IMP.Model() - self.particles = [] - self.restraint_sets = [] - self.rsrs = [] - - self.t = self.env.edat.energy_terms - self.t.append(IMP.modeller_intf.IMPRestraints(self.imp_model, - self.particles)) - - self.modeller_model = IMP.modeller_intf.create_particles(4, self.env, - self.imp_model, - self.particles) - p1 = self.particles[0] - p1.add_attribute(radius, 1.0, False) - p1.add_attribute(IMP.IntKey("protein"), 1) - p1.add_attribute(IMP.IntKey("id"), 1) - - p1 = self.particles[1] - p1.add_attribute(radius, 1.0, False) - p1.add_attribute(IMP.IntKey("protein"), 1) - p1.add_attribute(IMP.IntKey("id"), 2) - - p1 = self.particles[2] - p1.add_attribute(radius, 1.0, False) - p1.add_attribute(IMP.IntKey("protein"), 1) - p1.add_attribute(IMP.IntKey("id"), 3) - - p1 = self.particles[3] - p1.add_attribute(radius, 1.0, False) - p1.add_attribute(IMP.IntKey("protein"), 1) - p1.add_attribute(IMP.IntKey("id"), 4) - - self.atmsel = modeller.selection(self.modeller_model) - - self.opt = modeller.optimizers.conjugate_gradients() - - - # proximity - def test_proximity(self): - """All particles should be within a given max distance of each other""" - self.atmsel.randomize_xyz(deviation=100.0) - - self.restraint_sets.append(IMP.RestraintSet("proximity")) - rs = self.restraint_sets[len(self.restraint_sets)-1] - self.imp_model.add_restraint(rs) - - # add proximity restraints - - particle_indexes = IMP.Ints() - rsrs = [] - - # set up exclusion volumes - IMP.utils.set_up_exclusion_volumes(self.imp_model, self.particles, - radius, rsrs, 0.1) - max_distance = 4.0 - - # set max distance for two most distant particles together - particle_indexes.clear() - for i in range(4): - particle_indexes.push_back(i) - score_func_params_ub = IMP.BasicScoreFuncParams("harmonic_upper_bound", 0.0, 0.1) - rsrs.append(IMP.ProximityRestraint(self.imp_model, particle_indexes, - radius, max_distance, - score_func_params_ub)) - - # add restraints - for i in range(len(rsrs)): - rs.add_restraint(rsrs[i]) - - self.atmsel.randomize_xyz(deviation=100.0) - new_mdl = self.opt.optimize (self.atmsel, max_iterations=155, actions=None) - self.modeller_model.write (file='out_proximity.pdb', model_format='PDB') - - coords = self.load_coordinates('out_proximity.pdb') - os.unlink('out_proximity.pdb') - - # min distances - for i in range(len(coords)): - for j in range(i+1,len(coords)): - self.assert_(self.check_min_distance(coords[i], coords[j], self.particles[i].get_value(radius) + self.particles[j].get_value(radius) - 0.1), "min distance for any pair condition (" + str(i) + ", " + str(j) + ")") - - # max distances - for i in range(len(coords)): - for j in range(i+1,len(coords)): - self.assert_(self.check_max_distance(coords[i], coords[j], max_distance - self.particles[i].get_value(radius) - self.particles[j].get_value(radius) + 0.1), "max distance for any pair condition (" + str(i) + ", " + str(j) + ")") - -if __name__ == '__main__': - unittest.main() Index: kernel/test/torus/test_torus.py =================================================================== --- kernel/test/torus/test_torus.py (revision 441) +++ kernel/test/torus/test_torus.py (working copy) @@ -1,46 +0,0 @@ -import unittest -import os -import IMP -import IMP.test -import IMP.utils - -class TorusRestraintTests(IMP.test.TestCase): - """Class to test torus restraints""" - - def setUp(self): - """Build test model and optimizer""" - self.imp_model = IMP.Model() - self.particles = [] - self.restraint_sets = [] - self.rsrs = [] - - for p in range(12): - self.particles.append(IMP.utils.XYZParticle(self.imp_model, - 0., 0., 0.)) - self.opt = IMP.ConjugateGradients() - self.opt.set_model(self.imp_model); - self.opt.set_threshold(1e-4) - - - def test_torus(self): - """All particles should be inside the specified torus""" - rs = IMP.RestraintSet("torus") - self.restraint_sets.append(rs) - self.imp_model.add_restraint(rs) - - for p in self.imp_model.get_particles(): - r = IMP.TorusRestraint(p, 50, 10, IMP.HarmonicUpperBound(0.0, 0.1)) - self.rsrs.append(r) - rs.add_restraint(r) - - # Randomize particle coordinates - self.randomize_particles(self.particles, 50.0) - - self.opt.optimize(50) - for p in self.particles: - coord = (p.x(), p.y(), p.z()) - self.assert_(self.check_in_torus(coord, 50, 10.001), - "in torus condition") - -if __name__ == '__main__': - unittest.main() Index: kernel/test/torus/test_torus.py =================================================================== --- kernel/test/torus/test_torus.py (revision 441) +++ kernel/test/torus/test_torus.py (working copy) @@ -1,46 +0,0 @@ -import unittest -import os -import IMP -import IMP.test -import IMP.utils - -class TorusRestraintTests(IMP.test.TestCase): - """Class to test torus restraints""" - - def setUp(self): - """Build test model and optimizer""" - self.imp_model = IMP.Model() - self.particles = [] - self.restraint_sets = [] - self.rsrs = [] - - for p in range(12): - self.particles.append(IMP.utils.XYZParticle(self.imp_model, - 0., 0., 0.)) - self.opt = IMP.ConjugateGradients() - self.opt.set_model(self.imp_model); - self.opt.set_threshold(1e-4) - - - def test_torus(self): - """All particles should be inside the specified torus""" - rs = IMP.RestraintSet("torus") - self.restraint_sets.append(rs) - self.imp_model.add_restraint(rs) - - for p in self.imp_model.get_particles(): - r = IMP.TorusRestraint(p, 50, 10, IMP.HarmonicUpperBound(0.0, 0.1)) - self.rsrs.append(r) - rs.add_restraint(r) - - # Randomize particle coordinates - self.randomize_particles(self.particles, 50.0) - - self.opt.optimize(50) - for p in self.particles: - coord = (p.x(), p.y(), p.z()) - self.assert_(self.check_in_torus(coord, 50, 10.001), - "in torus condition") - -if __name__ == '__main__': - unittest.main() Index: kernel/include/IMP/ScoreFuncParams.h =================================================================== --- kernel/include/IMP/ScoreFuncParams.h (revision 441) +++ kernel/include/IMP/ScoreFuncParams.h (working copy) @@ -1,66 +0,0 @@ -/** - * \file ScoreFuncParams.h \brief Factory for creating UnaryFunctions. - * - * Copyright 2007-8 Sali Lab. All rights reserved. - */ - -#ifndef __IMP_SCORE_FUNC_PARAMS_H -#define __IMP_SCORE_FUNC_PARAMS_H - -#include "IMP_config.h" -#include "base_types.h" -#include "UnaryFunction.h" - -namespace IMP -{ - -//! Abstract class containing parameters for creating UnaryFunction instances. -/** Also has factory method for creating those instances. - */ -class IMPDLLEXPORT ScoreFuncParams -{ -public: - ScoreFuncParams() {} - virtual ~ScoreFuncParams() {} - virtual UnaryFunction* create_score_func() = 0; -}; - - -//! Basic mean+standard deviation parameter class for making UnaryFunctions. -class IMPDLLEXPORT BasicScoreFuncParams : public ScoreFuncParams -{ -public: - BasicScoreFuncParams(std::string score_func_type = "harmonic", - Float mean = 1.0, Float sd = 0.1); - virtual ~BasicScoreFuncParams(); - - //! Create a new score function with the current set of parameters. - /** \return pointer to score function. - */ - virtual UnaryFunction* create_score_func(); - - //! Set the mean to use in calculating this score function. - /** \param[in] mean Value for the mean. - */ - void set_mean(Float mean); - - //! Set the standard deviation to use in calculating this score function. - /** \param[in] sd Value for the standard deviation. - */ - void set_sd(Float sd); - - //! Set the type of score function to use. - /** \param[in] score_func_type Name of the score function type - */ - void set_score_func_type(std::string score_func_type); - -protected: - Float mean_; - Float sd_; - std::string score_func_type_; -}; - - -} // namespace IMP - -#endif /* __IMP_SCORE_FUNC_PARAMS_H */ Index: kernel/include/IMP/restraints/ExclusionVolumeRestraint.h =================================================================== --- kernel/include/IMP/restraints/ExclusionVolumeRestraint.h (revision 441) +++ kernel/include/IMP/restraints/ExclusionVolumeRestraint.h (working copy) @@ -1,70 +0,0 @@ -/** - * \file ExclusionVolumeRestraint.h \brief Excluded volume restraint. - * - * Prevent particles from getting too close together, by restricting the - * minimum distance between all pairs of particles formed from one or two - * sets of particles. - * - * Copyright 2007-8 Sali Lab. All rights reserved. - * - */ - -#ifndef __IMP_EXCLUSION_VOLUME_RESTRAINT_H -#define __IMP_EXCLUSION_VOLUME_RESTRAINT_H - -#include - -#include "../IMP_config.h" -#include "../Restraint.h" -#include "../ScoreFuncParams.h" -#include "../internal/kernel_version_info.h" -#include "DistanceRestraint.h" - -namespace IMP -{ - -//! Apply restraints that prevent particles from getting too close together. -/** Restrict min distance between all pairs of particles formed from one or - two sets of particles. If two sets of particles are passed, it assumes - that the two sets of particles have no overlap (otherwise, you will get - repeats). - - Calculate the distance restraints for the given particles. Use the - smallest restraints that will connect one particle of each type - together (i.e. a minimum spanning tree with nodes corresponding to - particle types and the edge weights corresponding to restraint - violation scores). - */ -class IMPDLLEXPORT ExclusionVolumeRestraint : public Restraint -{ -public: - ExclusionVolumeRestraint(Model* model, std::vector& particle1_indexes, - std::vector& particle2_indexes, - FloatKey attr_name, - BasicScoreFuncParams* score_func_params); - - ExclusionVolumeRestraint(Model* model, std::vector& particle_indexes, - FloatKey attr_name, - BasicScoreFuncParams* score_func_params); - - virtual ~ExclusionVolumeRestraint(); - - IMP_RESTRAINT(internal::kernel_version_info) - -protected: - //! number of particles all together - int num_particles_; - //! number of particles in vector 1 - int num_particles1_; - //! number of particles in vector 2 - int num_particles2_; - - //! total number of restraints - int num_restraints_; - //! restraints and their scores - std::vector dist_rsrs_; -}; - -} // namespace IMP - -#endif /* __IMP_EXCLUSION_VOLUME_RESTRAINT_H */ Index: kernel/include/IMP/restraints/ProximityRestraint.h =================================================================== --- kernel/include/IMP/restraints/ProximityRestraint.h (revision 441) +++ kernel/include/IMP/restraints/ProximityRestraint.h (working copy) @@ -1,74 +0,0 @@ -/** - * \file ProximityRestraint.h \brief Proximity restraint. - * - * Restrict maximum distance between any two particles. - * - * Copyright 2007-8 Sali Lab. All rights reserved. - * - */ - -#ifndef __IMP_PROXIMITY_RESTRAINT_H -#define __IMP_PROXIMITY_RESTRAINT_H - -#include -#include - -#include "../IMP_config.h" -#include "../Restraint.h" -#include "../ScoreFuncParams.h" -#include "../internal/kernel_version_info.h" -#include "DistanceRestraint.h" - -namespace IMP -{ - -//! Restrict maximum distance between any two particles -/** Given a list of particles, this restraint calculates the distance - restraints between all pairs of particles, and then applies the - one restraint with the greatest score. - - Calculate the distance restraints for the given particles. Use the - smallest restraints that will connect one particle of each type together - (i.e. a minimum spanning tree with nodes corresponding to particle - types and the edge weights corresponding to restraint violation score - values). - */ -class IMPDLLEXPORT ProximityRestraint : public Restraint -{ -public: - ProximityRestraint(Model* model, std::vector& particle_indexes, - const Float distance, - BasicScoreFuncParams* score_func_params); - - ProximityRestraint(Model* model, std::vector& particle_indexes, - FloatKey attr_name, const Float distance, - BasicScoreFuncParams* score_func_params); - - virtual ~ProximityRestraint(); - - IMP_RESTRAINT(internal::kernel_version_info) - -protected: - //! Internal set up for the constructors. - /** \param[in] model Pointer to the model. - \param[in] particle_indexes Vector of indexes of particles in the - restraint. - */ - void set_up(Model* model, std::vector& particle_indexes); - - //! number of particles in the restraint - int num_particles_; - - //! total number of restraints being tested - int num_restraints_; - //! calculated restraint scores - std::vector scores_; - //! indexes of local indexes sorted by energies - std::vector rsr_idx_; - //! the distance restraints - std::vector dist_rsrs_; -}; - -} // namespace IMP - -#endif /* __IMP_PROXIMITY_RESTRAINT_H */ Index: kernel/include/IMP/restraints/TorusRestraint.h =================================================================== --- kernel/include/IMP/restraints/TorusRestraint.h (revision 441) +++ kernel/include/IMP/restraints/TorusRestraint.h (working copy) @@ -1,52 +0,0 @@ -/** - * \file TorusRestraint.h \brief Score based on distance from torus interior - * - * Copyright 2007-8 Sali Lab. All rights reserved. - * - */ - -#ifndef __IMP_TORUS_RESTRAINT_H -#define __IMP_TORUS_RESTRAINT_H - -#include - -#include "../IMP_config.h" -#include "../ScoreFuncParams.h" -#include "../Restraint.h" -#include "../internal/kernel_version_info.h" - -namespace IMP -{ - -//! Restrict particle position to interior of a torus -class IMPDLLEXPORT TorusRestraint : public Restraint -{ -public: - /** \param[in] p1 Pointer to particle of the restraint. - \param[in] main_radius The main radius from the origin to the midline - of the tube. - \param[in] tube_radius The tube radius is min distance from the tube - midline to the tube surface. - \param[in] score_func Scoring function for the torus feature (distance - of the particle from the torus surface) - */ - TorusRestraint(Particle* p1, const Float main_radius, - const Float tube_radius, UnaryFunction* score_func); - virtual ~TorusRestraint(); - - IMP_RESTRAINT(internal::kernel_version_info) - -protected: - //! variables used to determine the distance - FloatKey x_, y_, z_; - //! main radius of the torus - Float main_radius_; - //! radius of the torus tube - Float tube_radius_; - //! math form for this restraint (typically one of the harmonics) - UnaryFunction* score_func_; -}; - -} // namespace IMP - -#endif /* __IMP_TORUS_RESTRAINT_H */ Index: kernel/include/IMP/restraints/PairConnectivityRestraint.h =================================================================== --- kernel/include/IMP/restraints/PairConnectivityRestraint.h (revision 441) +++ kernel/include/IMP/restraints/PairConnectivityRestraint.h (working copy) @@ -1,116 +0,0 @@ -/** - * \file PairConnectivityRestraint.h \brief Pair connectivity restraint. - * - * Restrict max distance between one or more pair of particles of any - * two sets of particles (e.g. rigid bodies). - * - * Copyright 2007-8 Sali Lab. All rights reserved. - * - */ - -#ifndef __IMP_PAIR_CONNECTIVITY_RESTRAINT_H -#define __IMP_PAIR_CONNECTIVITY_RESTRAINT_H - -#include - -#include "../IMP_config.h" -#include "../Restraint.h" -#include "../ScoreFuncParams.h" -#include "../internal/kernel_version_info.h" -#include "DistanceRestraint.h" - -namespace IMP -{ - -//! Pair connectivity restraint. -/** Restrict max distance between one or more pair of particles of any - two sets of particles (e.g. rigid bodies). - - Calculate the distance restraints for the given particles. Use the - smallest restraints that will connect one particle of each type together - (i.e. a minimum spanning tree with nodes corresponding to particle - types and the edge weights corresponding to restraint violation scores). - - There is a potential when using this restraint for two large rigid bodies - to maintain its own exclusion volume restraints. These could be calculated - only for the particles in the neighborhoods of the particles involved in - the activated restraints rather than between all particles in the two - bodies. Since once restraints are activated, they tend to be activated - over and over, the exclusion volume restraint sets should only be reset - whenever on rare occasion the neighborhoods actually change. - - */ -class IMPDLLEXPORT PairConnectivityRestraint : public Restraint -{ -public: - PairConnectivityRestraint(Model *m, std::vector& particle1_indexes, - std::vector& particle2_indexes, - BasicScoreFuncParams* score_func_params, - const int num_to_apply = 1, - const bool particle_reuse = false); - - PairConnectivityRestraint(Model *m, std::vector& particle1_indexes, - std::vector& particle2_indexes, - FloatKey attr_name, - BasicScoreFuncParams* score_func_params, - const int num_to_apply, - const bool particle_reuse = false); - - virtual ~PairConnectivityRestraint(); - - IMP_RESTRAINT(internal::kernel_version_info) - -protected: - class RestraintScore - { - public: - RestraintScore() {} - ~RestraintScore() {} - void evaluate() { - score_ = rsr_->evaluate(false); - } - bool operator<(const RestraintScore& rs) const { - return score_ < rs.score_; - } - - int part1_idx_; - int part2_idx_; - DistanceRestraint* rsr_; - Float score_; - }; - - //! Internal set up for the constructors. - /** \param[in] model Pointer to the model. - \param[in] particle1_indexes Vector of indexes of particles in first body - of the restraint. - \param[in] particle2_indexes Vector of indexes of particles in second body - of the restraint. - */ - void set_up(Model* model, std::vector& particle1_indexes, - std::vector& particle2_indexes); - - //! variables to determine the particle type - IntKey type_; - - //! number of particles all together - int num_particles_; - //! number of particles in vector 1 - int num_particles1_; - //! number of particles in vector 2 - int num_particles2_; - //! total number of restraints to apply - int num_to_apply_; - //! true if a particle can be involved in more than one restraint - int particle_reuse_; - //! which of particles have already been used - std::vector used_; - - //! total number of restraints being tested - int num_restraints_; - //! restraints and their scores - std::list rsr_scores_; -}; - -} // namespace IMP - -#endif /* __IMP_PAIR_CONNECTIVITY_RESTRAINT_H */ Index: kernel/src/restraints/ProximityRestraint.cpp =================================================================== --- kernel/src/restraints/ProximityRestraint.cpp (revision 441) +++ kernel/src/restraints/ProximityRestraint.cpp (working copy) @@ -1,229 +0,0 @@ -/** - * \file ProximityRestraint.cpp \brief Proximity restraint. - * - * Restrict maximum distance between any two particles. - * - * Copyright 2007-8 Sali Lab. All rights reserved. - * - */ - -#include - -#include "IMP/Model.h" -#include "IMP/Particle.h" -#include "IMP/log.h" -#include "IMP/restraints/ProximityRestraint.h" - -namespace IMP -{ - -//! Constructor - set up the restraint for point-like particles. -/** \param[in] model Pointer to the model. - \param[in] particle_indexes Vector of indexes of particles - \param[in] distance Maximum length allowable between any two particles. - \param[in] score_func_params Parameters for creating a score function. - */ -ProximityRestraint::ProximityRestraint(Model* model, - std::vector& particle_indexes, - const Float distance, - BasicScoreFuncParams* score_func_params) -{ - set_up(model, particle_indexes); - - // get the indexes associated with the restraints - int idx = 0; - score_func_params->set_mean(distance); - score_func_params->set_score_func_type("harmonic_upper_bound"); - for (int i = 0; i < num_particles_ - 1; i++) { - for (int j = i + 1; j < num_particles_; j++) { - // create the restraint - - UnaryFunction *sf = score_func_params->create_score_func(); - dist_rsrs_[idx] = new DistanceRestraint(get_particle(i), - get_particle(j), - sf); - idx++; - } - } - - IMP_LOG(VERBOSE, - "Number of restraints: " << num_restraints_ - << " number of particles: " << num_particles_ << std::endl); -} - - -//! Constructor - set up the restraint for particles with radii. -/** \param[in] model Pointer to the model. - \param[in] particle_indexes Vector of indexes of particles - \param[in] attr_name Name to get radii to calculate the mean distance. - \param[in] distance Maximum length allowable between any two particles. - \param[in] score_func_params Parameters for creating a score function. - */ -ProximityRestraint::ProximityRestraint(Model* model, - std::vector& particle_indexes, - FloatKey attr_name, - const Float distance, - BasicScoreFuncParams* score_func_params) -{ - // Use those radii to calculate the expected distance - set_up(model, particle_indexes); - - // get the indexes associated with the restraints - int idx = 0; - Float actual_mean; - score_func_params->set_score_func_type("harmonic_upper_bound"); - for (int i = 0; i < num_particles_ - 1; i++) { - for (int j = i + 1; j < num_particles_; j++) { - // Use those radii to calculate the expected distance between centers - Float attri, attrj; - attri = get_particle(i)->get_value(attr_name); - attrj = get_particle(j)->get_value(attr_name); - actual_mean = distance - attri - attrj; - - // create the restraint - IMP_LOG(VERBOSE, i << " " << j << " add distance: " << actual_mean); - score_func_params->set_mean(actual_mean); - UnaryFunction *sf = score_func_params->create_score_func(); - dist_rsrs_[idx] = new DistanceRestraint(get_particle(i), - get_particle(j), - sf); - idx++; - } - } -} - - -//! Internal set up for the constructors. -/** \param[in] model Pointer to the model. - \param[in] particle_indexes Vector of indexes of particles in the restraint. - */ -void ProximityRestraint::set_up(Model* model, - std::vector& particle_indexes) -{ - IMP_LOG(VERBOSE, "init ConnectivityRestraint"); - - /** number of particles in the restraint */ - num_particles_ = particle_indexes.size(); - - // set up the particles, their position indexes, and their type indexes - Particle* p1; - for (int i = 0; i < num_particles_; i++) { - p1 = model->get_particle(particle_indexes[i]); - add_particle(p1); - } - - // figure out how many restraints there are - num_restraints_ = num_particles_ * (num_particles_ - 1) / 2; - - // use number of restraints and number of types to set up some of the - // ... main arrays - dist_rsrs_.resize(num_restraints_); - scores_.resize(num_restraints_); - rsr_idx_.resize(num_restraints_); -} - - -//! Destructor -ProximityRestraint::~ProximityRestraint() -{ - for (int i = 0; i < num_restraints_; i++) { - delete dist_rsrs_[i]; - } -} - - -//! Evaluate the score for the model. -/** Calculate the distance restraints for the given particles. Use the smallest - restraints that will connect one particle of each type together (i.e. a - minimum spanning tree with nodes corresponding to particle types and the - edge weights corresponding to restraint violation score values). - - \param[in] accum If not NULL, use this object to accumulate partial first - derivatives. - \return score associated with this restraint for the given state of - the model. - */ -Float ProximityRestraint::evaluate(DerivativeAccumulator *accum) -{ - int idx; - - IMP_LOG(VERBOSE, "evaluate ProximityRestraint"); - - // calculate the scores for all of the restraints - /* - There is a problem with using just the largest violation restraint - in that it causes an inherent unsmoothness in the optimization process. - I.e. when one pair becomes more distant in another, there is a complete - switch to an orthogonal direction. - - LogMsg(VERBOSE, "calculate restraint scores"); - for (int i = 0; i < num_restraints_; i++) - { - scores_[i] = dist_rsrs_[i]->evaluate(false); - } - */ - - // dumb bubble sort of indexes by scores. - // /rsr_idx[]/ holds the sorted indexes so that all other arrays - // associated with the particles can be left as they are. - - /* - LogMsg(VERBOSE, "sort scores"); - for (int i = 0; i < num_restraints_; i++) - { - rsr_idx_[i] = i; - } - - for (int i = 0; i < num_restraints_ - 1; i++) - { - // move the next highest score index to the left most position of the - // remaining unsorted list. - for (int j = num_restraints_ - 1; j > i; j--) - { - if (scores_[rsr_idx_[j - 1]] < scores_[rsr_idx_[j]]) - { - idx = rsr_idx_[j - 1]; - rsr_idx_[j - 1] = rsr_idx_[j]; - rsr_idx_[j] = idx; - } - } - } - */ - - // apply the restraints corresponding the highest score restraints - int num_restraints_to_use = 1; // mod later if it should be more than one - - // switching back and forth seems to be less smooth - // just apply all of the restraints every time (also faster) - num_restraints_to_use = num_restraints_; - Float score = 0.0; - for (int i = 0; i < num_restraints_to_use; i++) { - // idx = rsr_idx_[i]; - idx = i; - - score += dist_rsrs_[idx]->evaluate(accum); - IMP_LOG(VERBOSE, - " " << i << " Applying Restraint: score: " - << score << std::endl); - } - - return score; -} - - -//! Show the current restraint. -/** \param[in] out Stream to send restraint description to. - */ -void ProximityRestraint::show(std::ostream& out) const -{ - if (get_is_active()) { - out << "proximity restraint (active):" << std::endl; - } else { - out << "proximity restraint (inactive):" << std::endl; - } - - get_version_info().show(out); - out << " num particles:" << num_particles_; -} - -} // namespace IMP Index: kernel/src/restraints/TorusRestraint.cpp =================================================================== --- kernel/src/restraints/TorusRestraint.cpp (revision 441) +++ kernel/src/restraints/TorusRestraint.cpp (working copy) @@ -1,135 +0,0 @@ -/** - * \file TorusRestraint.cpp \brief Score based on distance from torus interior - * - * Copyright 2007-8 Sali Lab. All rights reserved. - * - */ - -#include - -#include "IMP/Model.h" -#include "IMP/Particle.h" -#include "IMP/log.h" -#include "IMP/restraints/TorusRestraint.h" - -namespace IMP -{ - -TorusRestraint::TorusRestraint(Particle* p1, const Float main_radius, - const Float tube_radius, - UnaryFunction* score_func) -{ - add_particle(p1); - x_ = FloatKey("x"); - y_ = FloatKey("y"); - z_ = FloatKey("z"); - - main_radius_ = main_radius; - tube_radius_ = tube_radius; - score_func_ = score_func; -} - - -//! Destructor -TorusRestraint::~TorusRestraint() -{ - delete score_func_; -} - - -//! Calculate the score for this restraint for the current model state. -/** \param[in] accum If not NULL, use this object to accumulate partial first - derivatives. - \return Current score. - */ -Float TorusRestraint::evaluate(DerivativeAccumulator *accum) -{ - IMP_CHECK_OBJECT(score_func_); - - Float tube_center_x, tube_center_y; - Float xy_distance_from_center; - Float distance_from_tube_center; - Float torus_feature; - Float score, deriv; - Float x, y, z; - Float dx, dy, dz; - - IMP_LOG(VERBOSE, "... evaluating torus restraint."); - // get current position of particle - x = get_particle(0)->get_value(x_); - y = get_particle(0)->get_value(y_); - z = get_particle(0)->get_value(z_); - - // get the x, y distance from the origin - xy_distance_from_center = sqrt(x * x + y * y); - if (xy_distance_from_center == 0.0) { - // if no direction is favored, - // ... pick some arbitrary direction to head towards the - // ... torus interior - xy_distance_from_center = 0.001; - x = 0.001; - } - - // calculate the cross-section_center (large radius away from origin with z=0) - tube_center_x = x * main_radius_ / xy_distance_from_center; - tube_center_y = y * main_radius_ / xy_distance_from_center; - // by definition: tube_center_z = 0; - - // translate to cross-section center - x -= tube_center_x; - y -= tube_center_y; - - // calculate the distance from the cross-section_center - distance_from_tube_center = sqrt(x * x + y * y + z * z); - - // subtract the small radius of the torus so that if the point is within the - // ... torus the value is negative - torus_feature = distance_from_tube_center - tube_radius_; - - // if in the torus, partials should be zero - if (torus_feature <= 0) { - score = 0.0; - deriv = 0.0; - } - - // otherwise, derivatives should reduce feature as torus is neared - // the derivative vector stays constant independent of distance from torus - // i.e. a unit vector - else { - score = (*score_func_)(torus_feature, deriv); - } - - // if needed, use the partial derivatives - if (accum) { - dx = deriv * x / distance_from_tube_center; - dy = deriv * y / distance_from_tube_center; - dz = deriv * z / distance_from_tube_center; - - get_particle(0)->add_to_derivative(x_, dx, *accum); - get_particle(0)->add_to_derivative(y_, dy, *accum); - get_particle(0)->add_to_derivative(z_, dz, *accum); - } - - return score; -} - - -//! Show the current restraint. -/** \param[in] out Stream to send restraint description to. - */ -void TorusRestraint::show(std::ostream& out) const -{ - if (get_is_active()) { - out << "torus restraint (active):" << std::endl; - } else { - out << "torus restraint (inactive):" << std::endl; - } - - get_version_info().show(out); - out << " particle: " << get_particle(0)->get_index() << " "; - - out << " main radius:" << main_radius_; - out << " tube radius:" << tube_radius_; -} - -} // namespace IMP Index: kernel/src/restraints/PairConnectivityRestraint.cpp =================================================================== --- kernel/src/restraints/PairConnectivityRestraint.cpp (revision 441) +++ kernel/src/restraints/PairConnectivityRestraint.cpp (working copy) @@ -1,276 +0,0 @@ -/** - * \file PairConnectivityRestraint.cpp \brief Pair connectivity restraint. - * - * Restrict max distance between one or more pair of particles of any - * two sets of particles (e.g. rigid bodies). - * - * Copyright 2007-8 Sali Lab. All rights reserved. - * - */ - -#include - -#include "IMP/Model.h" -#include "IMP/Particle.h" -#include "IMP/log.h" -#include "IMP/restraints/PairConnectivityRestraint.h" - -namespace IMP -{ - -//! Set up a restraint using the given mean for particle-particle distance. -/** \param[in] model Pointer to the model. - \param[in] particle1_indexes Vector of indexes of particles of first body. - \param[in] particle2_indexes Vector of indexes of particles of second body. - \param[in] score_func_params Parameters for creating a score function. - \param[in] num_to_apply Number of minimum restraints to apply. - \param[in] particle_reuse Allow minimum restraints to use particle - more than once. - */ -PairConnectivityRestraint::PairConnectivityRestraint(Model* model, - std::vector& particle1_indexes, std::vector& particle2_indexes, - BasicScoreFuncParams* score_func_params, const int num_to_apply, - const bool particle_reuse) -{ - particle_reuse_ = particle_reuse; - num_to_apply_ = num_to_apply; - set_up(model, particle1_indexes, particle2_indexes); - - - // get the indexes associated with the restraints - int idx = 0; - // use iterator to move through each predefined position in the - // restraint/score list - std::list::iterator rs_iter; - rs_iter = rsr_scores_.begin(); - for (int i = 0; i < num_particles1_; i++) { - for (int j = num_particles1_; j < num_particles1_ + num_particles2_; j++) { - // create the restraint - if (rs_iter == rsr_scores_.end()) { - IMP_failure("Reached end of rsr_scores too early.", - ValueException("Reached end of rsr_scores too early")); - } else { - IMP_LOG(VERBOSE, "Adding possible restraint: " << i << " " << j); - UnaryFunction *sf = score_func_params->create_score_func(); - rs_iter->rsr_ = new DistanceRestraint(get_particle(i), - get_particle(j), - sf); - - rs_iter->part1_idx_ = i; - rs_iter->part2_idx_ = j; - } - - ++rs_iter; - } - } - - IMP_LOG(VERBOSE, idx << - " num_restraints_: " << num_restraints_ << " num_particles1_: " << - num_particles1_ << " num_particles2_:" << num_particles2_ - << std::endl); -} - -//! Set up a restraint using the given attribute for particle-particle distance. -/** \param[in] model Pointer to the model. - \param[in] particle1_indexes Vector of indexes of particles of first body. - \param[in] particle2_indexes Vector of indexes of particles of second body. - \param[in] attr_name Name to get radii to calculate the mean distance. - \param[in] score_func_params Parameters for creating a score function. - \param[in] num_to_apply Number of minimum restraints to apply. - \param[in] particle_reuse Allow minimum restraints to use particle - more than once. - */ -PairConnectivityRestraint::PairConnectivityRestraint(Model* model, - std::vector& particle1_indexes, std::vector& particle2_indexes, - FloatKey attr_name, BasicScoreFuncParams* score_func_params, - const int num_to_apply, const bool particle_reuse) -{ - particle_reuse_ = particle_reuse; - num_to_apply_ = num_to_apply; - set_up(model, particle1_indexes, particle2_indexes); - - // get the indexes associated with the restraints - int idx = 0; - Float actual_mean; - - // use iterator to move through each predefined position in the - // restraint/score list - std::list::iterator rs_iter; - rs_iter = rsr_scores_.begin(); - // particles from list 1 - for (int i = 0; i < num_particles1_; i++) { - // particles from list 2 - for (int j = num_particles1_; j < num_particles_; j++) { - // Use those radii to calculate the expected distance - Float attri, attrj; - attri = get_particle(i)->get_value(attr_name); - attrj = get_particle(j)->get_value(attr_name); - actual_mean = attri + attrj; - - score_func_params->set_mean(actual_mean); - - // create the restraint - if (rs_iter == rsr_scores_.end()) { - IMP_failure("Reached end of rsr_scores too early.", - ValueException("Reached end of rsr_scores too early")); - } else { - IMP_LOG(VERBOSE, "Adding possible restraint: " << i << " " << j); - UnaryFunction *sf = score_func_params->create_score_func(); - rs_iter->rsr_ = new DistanceRestraint(get_particle(i), - get_particle(j), - sf); - - rs_iter->part1_idx_ = i; - rs_iter->part2_idx_ = j; - } - - ++rs_iter; - } - } - - IMP_LOG(VERBOSE, idx << - " num_restraints_: " << num_restraints_ << " num_particles1_: " << - num_particles1_ << " num_particles2_:" << num_particles2_ - << std::endl); -} - - -//! Internal set up for the constructors. -/** \param[in] model Pointer to the model. - \param[in] particle1_indexes Vector of indexes of particles in first body - of the restraint. - \param[in] particle2_indexes Vector of indexes of particles in second body - of the restraint. - */ -void PairConnectivityRestraint::set_up(Model* model, - std::vector& particle1_indexes, - std::vector& particle2_indexes) -{ - Particle* p1; - - IMP_LOG(VERBOSE, "init ConnectivityRestraint"); - - //model_data_ = model.get_model_data(); - - /** number of particles in the restraint */ - num_particles1_ = particle1_indexes.size(); - num_particles2_ = particle2_indexes.size(); - num_particles_ = num_particles1_ + num_particles2_; - - IMP_LOG(VERBOSE, "set up particle types"); - // set up the particles, their position indexes, and their type indexes - for (int i = 0; i < num_particles1_; i++) { - p1 = model->get_particle(particle1_indexes[i]); - add_particle(p1); - } - - for (int i = 0; i < num_particles2_; i++) { - p1 = model->get_particle(particle2_indexes[i]); - add_particle(p1); - } - - // figure out how many restraints there are - num_restraints_ = num_particles1_ * num_particles2_; - - // use number of restraints and number of types to set up some of the - // ... main arrays - used_.resize(num_particles_); - rsr_scores_.resize(num_restraints_); -} - -//! Destructor -PairConnectivityRestraint::~PairConnectivityRestraint() -{ - std::list::iterator rs_iter; - - for (rs_iter = rsr_scores_.begin(); rs_iter != rsr_scores_.end(); ++rs_iter) { - delete(rs_iter->rsr_); - } -} - - -//! Evaluate the restraint for the current model state. -/** Calculate the distance restraints for the given particles. Use the smallest - restraints that will connect one particle of each type together (i.e. a - minimum spanning tree with nodes corresponding to particle types and the - edge weights corresponding to restraint violation scores). - - There is a potential when using this restraint for two large rigid bodies - to maintain its own exclusion volume restraints. These could be calculated - only for the particles in the neighborhoods of the particles involved in the - activated restraints rather than between all particles in the two bodies. - Since once restraints are activated, they tend to be activated over and - over, the exclusion volume restraint sets should only be reset whenever - on rare occasion the neighborhoods actually change. - - \param[in] accum If not NULL, use this object to accumulate partial first - derivatives. - \return score associated with this restraint for the given state of - the model. - */ -Float PairConnectivityRestraint::evaluate(DerivativeAccumulator *accum) -{ - std::list::iterator rs_iter; - - IMP_LOG(VERBOSE, "evaluate PairConnectivityRestraint"); - - // only use a particle at most once in set of restraints - for (int i = 0; i < num_particles_; i++) - used_[i] = false; - - // calculate the scores for all of the restraints - IMP_LOG(VERBOSE, "calculate restraint scores"); - int j = 0; - for (rs_iter = rsr_scores_.begin(); rs_iter != rsr_scores_.end(); ++rs_iter) { - rs_iter->evaluate(); - IMP_LOG(VERBOSE, j++ << " score: " << rs_iter->score_); - } - - // sort by the scores - rsr_scores_.sort(); - - IMP_LOG(VERBOSE, "sorted"); - j = 0; - for (rs_iter = rsr_scores_.begin(); rs_iter != rsr_scores_.end(); ++rs_iter) { - IMP_LOG(VERBOSE, j++ << " score: " << rs_iter->score_); - } - - Float score = 0.0; - rs_iter = rsr_scores_.begin(); - int num_applied = 0; - for (int i = 0; num_applied < num_to_apply_ && rs_iter != rsr_scores_.end(); - ++i) { - if (particle_reuse_ || (!used_[rs_iter->part1_idx_] - && !used_[rs_iter->part2_idx_])) { - used_[rs_iter->part1_idx_] = true; - used_[rs_iter->part2_idx_] = true; - score += rs_iter->rsr_->evaluate(accum); - num_applied++; - } - - ++rs_iter; - } - - return score; -} - - -//! Show the current restraint. -/** \param[in] out Stream to send restraint description to. - */ -void PairConnectivityRestraint::show(std::ostream& out) const -{ - if (get_is_active()) { - out << "pair connectivity restraint (active):" << std::endl; - } else { - out << "pair connectivity restraint (inactive):" << std::endl; - } - - get_version_info().show(out); - out << " num particles1:" << num_particles1_; - out << " num particles2:" << num_particles2_; - out << " num restraints:" << num_restraints_; - out << " num restraints to apply:" << num_to_apply_; -} - -} // namespace IMP Index: kernel/src/restraints/ExclusionVolumeRestraint.cpp =================================================================== --- kernel/src/restraints/ExclusionVolumeRestraint.cpp (revision 441) +++ kernel/src/restraints/ExclusionVolumeRestraint.cpp (working copy) @@ -1,193 +0,0 @@ -/** - * \file ExclusionVolumeRestraint.cpp \brief Excluded volume restraint. - * - * Prevent particles from getting too close together, by restricting the - * minimum distance between all pairs of particles formed from one or two - * sets of particles. - * - * Copyright 2007-8 Sali Lab. All rights reserved. - * - */ - -#include - -#include "IMP/Model.h" -#include "IMP/Particle.h" -#include "IMP/log.h" -#include "IMP/restraints/ExclusionVolumeRestraint.h" - -namespace IMP -{ - -//! Set up restraint using two sets of particles. -/** Uses the attr_name to access the radii for the minimum distance between - any two particles. Assumes that there is no overlap between the two - particle lists. Create restraints for all possible pairs between the - two lists. - - \param[in] model Pointer to the model. - \param[in] particle1_indexes Vector of indexes of particles of the - first body. - \param[in] particle2_indexes Vector of indexes of particles of the - second body. - \param[in] attr_name The attribute used to determine the radius of - each particle. - \param[in] score_func_params Scoring function parameters. - */ -ExclusionVolumeRestraint::ExclusionVolumeRestraint(Model* model, - std::vector& particle1_indexes, std::vector& particle2_indexes, - FloatKey attr_name, BasicScoreFuncParams* score_func_params) -{ - Particle* p1; - - num_particles1_ = particle1_indexes.size(); - num_particles2_ = particle2_indexes.size(); - num_particles_ = num_particles1_ + num_particles2_; - for (int i = 0; i < num_particles1_; i++) { - p1 = model->get_particle(particle1_indexes[i]); - add_particle(p1); - } - - for (int i = 0; i < num_particles2_; i++) { - p1 = model->get_particle(particle2_indexes[i]); - add_particle(p1); - } - - num_restraints_ = num_particles1_ * num_particles2_; - - // get the indexes associated with the restraints - Float actual_mean; - IMP_LOG(VERBOSE, "Add inter-body exclusion volume restraints " - << num_restraints_); - - // particle 1 indexes - for (int i = 0; i < num_particles1_; i++) { - // particle 2 indexes - for (int j = num_particles1_; j < num_particles_; j++) { - // Use those radii to calculate the expected distance - Float attri, attrj; - attri = get_particle(i)->get_value(attr_name); - attrj = get_particle(j)->get_value(attr_name); - actual_mean = attri + attrj; - - score_func_params->set_mean(actual_mean); - - // create the restraint - UnaryFunction *sf = score_func_params->create_score_func(); - dist_rsrs_.push_back(new DistanceRestraint(get_particle(i), - get_particle(j), - sf)); - } - } -} - - -//! Set up restraint using one set of particles. -/** Uses the attr_name to access the radii for the minimum distance between - any two particles. Create restraints for all possible pairs of particles - in the list. - - \param[in] model Pointer to the model. - \param[in] particle_indexes Vector of indexes of particles - \param[in] attr_name The attribute used to determine the radius of - each particle. - \param[in] score_func_params Scoring function parameters. - */ -ExclusionVolumeRestraint::ExclusionVolumeRestraint(Model* model, - std::vector& particle_indexes, FloatKey attr_name, - BasicScoreFuncParams* score_func_params) -{ - Particle* p1; - - num_particles_ = particle_indexes.size(); - for (int i = 0; i < num_particles_; i++) { - p1 = model->get_particle(particle_indexes[i]); - add_particle(p1); - } - - num_restraints_ = num_particles_ * (num_particles_ - 1) / 2; - - // get the indexes associated with the restraints - int idx = 0; - Float actual_mean; - IMP_LOG(VERBOSE, "Add intra-body exclusion volume restraints " - << num_restraints_); - - // particle 1 indexes - for (int i = 0; i < num_particles_ - 1; i++) { - // particle 2 indexes (avoid duplicates and particle with itself) - for (int j = i + 1; j < num_particles_; j++) { - // Use those radii to calculate the expected distance - Float attri, attrj; - attri = get_particle(i)->get_value(attr_name); - attrj = get_particle(j)->get_value(attr_name); - actual_mean = attri + attrj; - - score_func_params->set_mean(actual_mean); - - // create the restraint - UnaryFunction *sf = score_func_params->create_score_func(); - dist_rsrs_.push_back(new DistanceRestraint(get_particle(i), - get_particle(j), - sf)); - idx++; - } - } -} - - -//! Destructor -ExclusionVolumeRestraint::~ExclusionVolumeRestraint() -{ - std::vector::iterator rsr_iter; - - for (rsr_iter = dist_rsrs_.begin(); rsr_iter != dist_rsrs_.end(); - ++rsr_iter) { - delete(*rsr_iter); - } -} - - -//! Get the score of the restraint for the model. -/** Calculate the distance restraints for the given particles. Use the smallest - restraints that will connect one particle of each type together (i.e. a - minimum spanning tree with nodes corresponding to particle types and the - edge weights corresponding to restraint violation scores). - - \param[in] accum If not NULL, use this object to accumulate partial first - derivatives. - \return score associated with this restraint for the given state of - the model. - */ -Float ExclusionVolumeRestraint::evaluate(DerivativeAccumulator *accum) -{ - std::vector::iterator rsr_iter; - - Float score = 0.0; - - // until this is smarter, just calculate them all - for (rsr_iter = dist_rsrs_.begin(); rsr_iter != dist_rsrs_.end(); - ++rsr_iter) { - score += (*rsr_iter)->evaluate(accum); - } - - return score; -} - - -//! Show the current restraint. -/** \param[in] out Stream to send restraint description to. - */ -void ExclusionVolumeRestraint::show(std::ostream& out) const -{ - if (get_is_active()) { - out << "exclusion volume restraint (active):" << std::endl; - } else { - out << "exclusion volume restraint (inactive):" << std::endl; - } - - get_version_info().show(out); - out << " num particles:" << num_particles_; -} - -} // namespace IMP Index: kernel/src/BasicScoreFuncParams.cpp =================================================================== --- kernel/src/BasicScoreFuncParams.cpp (revision 441) +++ kernel/src/BasicScoreFuncParams.cpp (working copy) @@ -1,76 +0,0 @@ -/** - * \file BasicScoreFuncParams.cpp \brief Factory for creating UnaryFunctions. - * - * Copyright 2007-8 Sali Lab. All rights reserved. - * - */ - -#include "IMP/ScoreFuncParams.h" -#include "IMP/unary_functions/Harmonic.h" -#include "IMP/unary_functions/HarmonicLowerBound.h" -#include "IMP/unary_functions/HarmonicUpperBound.h" -#include "IMP/log.h" - -namespace IMP -{ - -//! Constructor -BasicScoreFuncParams::BasicScoreFuncParams(std::string score_func_type, - Float mean, Float sd) -{ - mean_ = mean; - sd_ = sd; - score_func_type_ = score_func_type; -} - - -//! Destructor -BasicScoreFuncParams::~BasicScoreFuncParams() -{ -} - - -//! Set the mean to use in calculating this score function. -/** \param[in] mean Value for the mean. - */ -void BasicScoreFuncParams::set_mean(Float mean) -{ - mean_ = mean; -} - -//! Set the standard deviation to use in calculating this score function. -/** \param[in] sd Value for the standard deviation. - */ -void BasicScoreFuncParams::set_sd(Float sd) -{ - sd_ = sd; -} - -//! Set the type of score function to use. -/** \param[in] score_func_type Name of the score function type - */ -void BasicScoreFuncParams::set_score_func_type(std::string score_func_type) -{ - score_func_type_ = score_func_type; -} - - -//! Create a new score function with the current set of parameters. -/** \return pointer to score function. - */ -UnaryFunction* BasicScoreFuncParams::create_score_func() -{ - if (score_func_type_ == "harmonic") { - return new Harmonic(mean_, sd_); - } else if (score_func_type_ == "harmonic_lower_bound") { - return new HarmonicLowerBound(mean_, sd_); - } else if (score_func_type_ == "harmonic_upper_bound") { - return new HarmonicUpperBound(mean_, sd_); - } - - IMP_check(0, "Unknown score function: " << score_func_type_, - ValueException("Unknown score function")); - return NULL; -} - -} // namespace IMP Index: kernel/pyext/IMP/xml_loader.py =================================================================== --- kernel/pyext/IMP/xml_loader.py (revision 441) +++ kernel/pyext/IMP/xml_loader.py (working copy) @@ -1,542 +0,0 @@ -import xml.dom.minidom -import IMP -import IMP.utils - -class MalformedError(Exception): - """Exception class for malformed XML data""" - pass - -def load_imp_model(model, xml_file_path, base_particle = 0): - """ Load imp model from given xml file """ - doc = xml.dom.minidom.parse(xml_file_path) - - # there should only be a single imp node, but just in case ... - for head in doc.childNodes: - if (head.nodeName == 'imp'): - for n in head.childNodes: - # process particle set nodes - if n.nodeName == 'particles': - load_particles(model, n, base_particle) - - # process restraint set nodes - elif n.nodeName == 'restraint_set': - load_restraint_set(model, n, base_particle) - - return doc - - -def load_particles(model, particles_node, base_particle): - """ Load particles from the DOM """ - # save particle pointers to prevent destructors from running - try: - model.particles - except AttributeError: - model.particles = [] - model.num_particles = 0 - - # process individual particle nodes - for part in particles_node.childNodes: - if (part.nodeName == 'particle'): - load_particle(model, part, base_particle) - - -def load_particle(model, particle_node, base_particle): - """ Load particle from the DOM """ - id = particle_node.getAttribute('id') - model.particles.append(IMP.utils.XYZParticle(model)) - p_idx = len(model.particles)-1 - - # process particle attributes - for attr in particle_node.childNodes: - if attr.nodeName == 'float': - load_float(model, p_idx, attr) - - elif attr.nodeName == 'int': - load_int(model, p_idx, attr) - - elif attr.nodeName == 'string': - load_string(model, p_idx, attr) - - -def load_float(model, p_idx, attr_node): - """ Load float attribute from the DOM and add it to the particle """ - name = attr_node.getAttribute('name') - p = model.particles[p_idx] - - # defaults - optimize = True - value = 0.0 - for n in attr_node.childNodes: - if n.nodeName == 'optimize': - optimize = (n.childNodes[0].nodeValue == 'T') - - if n.nodeName == 'value': - value = n.childNodes[0].nodeValue - - p.add_attribute(IMP.FloatKey(str(name)), float(value), bool(optimize)) - - -def load_int(model, p_idx, attr_node): - """ Load int attribute from the DOM and add it to the particle """ - name = attr_node.getAttribute('name') - p = model.particles[p_idx] - - # defaults - value = 0 - for n in attr_node.childNodes: - if n.nodeName == 'value': - value = n.childNodes[0].nodeValue - p.add_attribute(IMP.IntKey(str(name)), int(value)) - - -def load_string(model, p_idx, attr_node): - """ Load string attribute from the DOM and add it to the particle """ - name = attr_node.getAttribute('name') - p = model.particles[p_idx] - - # defaults - value = "" - for n in attr_node.childNodes: - if n.nodeName == 'value': - value = n.childNodes[0].nodeValue - - p.add_attribute(IMP.StringKey(name), str(value)) - - -def load_restraint_set(model, restraint_set_node, base_particle): - """ Load restraint set from the DOM """ - - # save pointers to prevent destructors from running - try: - model.restraint_sets - except AttributeError: - model.restraint_sets = [] - - try: - model.restraints - except AttributeError: - model.restraints = [] - - try: - model.score_funcs - except AttributeError: - model.score_funcs = {} - - # get restraint set parameters - name = str(restraint_set_node.getAttribute('name')) - model.restraint_sets.append(IMP.RestraintSet(name)) - rs_idx = len(model.restraint_sets) - 1 - model.add_restraint(model.restraint_sets[rs_idx]) - - # process restraints in subnodes - for r in restraint_set_node.childNodes: - if (r.nodeName == 'distance_restraint'): - load_rsr_distance(model, rs_idx, r, base_particle) - - elif (r.nodeName == 'torus_restraint'): - load_rsr_torus(model, rs_idx, r, base_particle) - - elif (r.nodeName == 'coordinate_restraint'): - load_rsr_coordinate(model, rs_idx, r, base_particle) - - elif (r.nodeName == 'connectivity_restraint'): - load_rsr_connectivity(model, rs_idx, r, base_particle) - - elif (r.nodeName == 'pair_connectivity_restraint'): - load_rsr_pair_connectivity(model, rs_idx, r, base_particle) - - elif (r.nodeName == 'proximity_restraint'): - load_rsr_proximity(model, rs_idx, r, base_particle) - - elif (r.nodeName == 'exclusion_volume_restraint'): - load_rsr_exclusion_volume(model, rs_idx, r, base_particle) - - elif (r.nodeName == 'exclusion_volume_restraint'): - load_rsr_exclusion_volume(model, rs_idx, r, base_particle) - - -def load_rsr_distance(model, rs_idx, rsr, base_particle): - """Load distance restraint from the DOM""" - - # process restraint parameters - - # defaults - distance_attribute = '' - distance = None - sd = 0.1 - score_func_str = None - - # get the parameters - for param in rsr.childNodes: - if param.nodeName == 'particle_pairs': - particle_pairs = _get_particle_pairs(param) - - elif param.nodeName == 'distance': - distance = float(param.childNodes[0].nodeValue) - - elif param.nodeName == 'sd': - sd = float(param.childNodes[0].nodeValue) - - elif param.nodeName == 'distance_attribute': - distance_attribute = str(param.childNodes[0].nodeValue) - - elif param.nodeName == 'score_func': - score_func_str = str(param.childNodes[0].nodeValue) - - # make sure we have the needed parameters - if score_func_str == None: - raise MalformedError("No score function specified.") - - if distance == None and distance_attribute == '': - raise MalformedError("No distance specified.") - - # add restraint for each particle pair in the list - for pair in particle_pairs: - p1 = model.particles[int(pair[0])] - p2 = model.particles[int(pair[1])] - if distance_attribute != '': - distance = p1.get_value(IMP.FloatKey(distance_attribute)) \ - + p2.get_value(IMP.FloatKey(distance_attribute)) - - score_func_params = get_basic_score_func_params(score_func_str, distance, sd) - sf = score_func_params.create_score_func() - model.restraints.append(IMP.DistanceRestraint(p1, p2, sf)) - model.restraint_sets[rs_idx].add_restraint(model.restraints[-1]) - - -def load_rsr_torus(model, rs_idx, rsr, base_particle): - """Load torus restraint from the DOM""" - - # process restraint parameters - - # defaults - distance_attribute = '' - sd = 0.1 - tube_radius = 5.0 - main_radius = 20.0 - score_func_str = None - - # get the parameters - for param in rsr.childNodes: - if param.nodeName == 'particle_list': - particle_list = _get_particle_list(param) - - elif param.nodeName == 'main_radius': - main_radius = float(param.childNodes[0].nodeValue) - - elif param.nodeName == 'tube_radius': - tube_radius = float(param.childNodes[0].nodeValue) - - elif param.nodeName == 'sd': - sd = float(param.childNodes[0].nodeValue) - - elif param.nodeName == 'score_func': - score_func_str = str(param.childNodes[0].nodeValue) - - # make sure we have the needed parameters - if score_func_str == None: - raise MalformedError("No score function specified.") - - # add restraint for each particle in the list - for p_idx in particle_list: - p = model.particles[int(p_idx)] - score_func_params = get_basic_score_func_params(score_func_str, 0.0, sd) - sf = score_func_params.create_score_func() - model.restraints.append(IMP.TorusRestraint(p, main_radius, - tube_radius, sf)) - model.restraint_sets[rs_idx].add_restraint(model.restraints[-1]) - - -def load_rsr_coordinate(model, rs_idx, rsr, base_particle): - """Load coordinate restraint from the DOM""" - print "Load coordinate restraint" - - # process restraint parameters - - # defaults - axis = 'X_AXIS' - sd = 0.1 - distance = 10.0 - score_func_str = None - - # get the parameters - for param in rsr.childNodes: - if param.nodeName == 'particle_list': - particle_list = _get_particle_list(param) - - elif param.nodeName == 'axis_type': - axis = str(param.childNodes[0].nodeValue) - - elif param.nodeName == 'distance': - distance = float(param.childNodes[0].nodeValue) - - elif param.nodeName == 'sd': - sd = float(param.childNodes[0].nodeValue) - - elif param.nodeName == 'score_func': - score_func_str = str(param.childNodes[0].nodeValue) - - # make sure we have the needed parameters - if score_func_str == None: - raise MalformedError("No score function specified.") - - # add restraint for each particle in the list - for p_idx in particle_list: - p = model.particles[int(p_idx)] - score_func_params = get_basic_score_func_params(score_func_str, distance, sd) - model.restraints.append(IMP.CoordinateRestraint(model, p, axis, score_func_params)) - model.restraint_sets[rs_idx].add_restraint(model.restraints[-1]) - - -def load_rsr_connectivity(model, rs_idx, rsr, base_particle): - """Load connectivity restraint from the DOM""" - print "Load connectivity restraint" - - # process restraint parameters - - # defaults - distance_attribute = '' - type_attribute = 'protein' - distance = None - sd = 0.1 - score_func_str = None - - # get the parameters - for param in rsr.childNodes: - if param.nodeName == 'particle_list': - particle_list = _get_particle_list(param) - - elif param.nodeName == 'distance': - distance = float(param.childNodes[0].nodeValue) - - elif param.nodeName == 'sd': - sd = float(param.childNodes[0].nodeValue) - - elif param.nodeName == 'distance_attribute': - distance_attribute = str(param.childNodes[0].nodeValue) - - elif param.nodeName == 'type_attribute': - type_attribute = str(param.childNodes[0].nodeValue) - - elif param.nodeName == 'score_func': - score_func_str = str(param.childNodes[0].nodeValue) - - # make sure we have the needed parameters - if score_func_str == None: - raise MalformedError("No score function specified.") - - # make sure we have the needed parameters - if distance == None and distance_attribute == '': - raise MalformedError("No distance specified.") - - # create a vector of particle indexes - particle_indexes = IMP.Ints() - for p_idx in particle_list: - particle_indexes.push_back(int(p_idx)) - - # add restraint for for vector of particles - if distance_attribute: - score_func_params = get_basic_score_func_params(score_func_str, 0.0, sd) - model.restraints.append(IMP.ConnectivityRestraint(model, particle_indexes, type_attribute, distance_attribute, score_func_params)) - model.restraint_sets[rs_idx].add_restraint(model.restraints[-1]) - else: - score_func_params = get_basic_score_func_params(score_func_str, distance, sd) - model.restraints.append(IMP.ConnectivityRestraint(model, particle_indexes, type_attribute, score_func_params)) - model.restraint_sets[rs_idx].add_restraint(model.restraints[-1]) - - -def load_rsr_pair_connectivity(model, rs_idx, rsr, base_particle): - """Load pair connectivity restraint from the DOM""" - print "Load pair connectivity restraint" - - # process restraint parameters - - # defaults - distance_attribute = '' - distance = None - sd = 0.1 - score_func_str = None - num_lists = 0 - number_of_connects = 1 - - # get the parameters - for param in rsr.childNodes: - if num_lists == 0 and param.nodeName == 'particle_list': - particle_list1 = _get_particle_list(param) - num_lists = 1 - - elif param.nodeName == 'particle_list': - particle_list2 = _get_particle_list(param) - - elif param.nodeName == 'distance': - distance = float(param.childNodes[0].nodeValue) - - elif param.nodeName == 'sd': - sd = float(param.childNodes[0].nodeValue) - - elif param.nodeName == 'distance_attribute': - distance_attribute = str(param.childNodes[0].nodeValue) - - elif param.nodeName == 'score_func': - score_func_str = str(param.childNodes[0].nodeValue) - - elif param.nodeName == 'number_of_connects': - number_of_connects = int(param.childNodes[0].nodeValue) - - # make sure we have the needed parameters - if distance == None and distance_attribute == '': - raise MalformedError("No distance specified.") - - # make sure we have the needed parameters - if score_func_str == None: - raise MalformedError("No score function specified.") - - # create a vector of particle indexes - particle_indexes1 = IMP.Ints() - particle_indexes1.clear() - for p_idx in particle_list1: - particle_indexes1.push_back(int(p_idx)) - - particle_indexes2 = IMP.Ints() - particle_indexes2.clear() - for p_idx in particle_list2: - particle_indexes2.push_back(int(p_idx)) - - # add restraint for for vector of particles - if distance_attribute: - score_func_params = get_basic_score_func_params(score_func_str, 0.0, sd) - r = IMP.PairConnectivityRestraint(model, particle_indexes1, particle_indexes2, distance_attribute, score_func_params, number_of_connects) - model.restraints.append(r) - model.restraint_sets[rs_idx].add_restraint(r) - else: - score_func_params = get_basic_score_func_params(score_func_str, distance, sd) - r = IMP.PairConnectivityRestraint(model, particle_indexes1, particle_indexes2, score_func_params, number_of_connects) - model.restraints.append(r) - model.restraint_sets[rs_idx].add_restraint(r) - - -def load_rsr_proximity(model, rs_idx, rsr, base_particle): - """Load proximity restraint from the DOM""" - print "Load proximity restraint" - - # process restraint parameters - - # defaults - distance = 5.0 - sd = 0.1 - score_func_str = None - - # get the parameters - for param in rsr.childNodes: - if param.nodeName == 'particle_list': - particle_list = _get_particle_list(param) - - elif param.nodeName == 'distance': - distance = float(param.childNodes[0].nodeValue) - - elif param.nodeName == 'sd': - sd = float(param.childNodes[0].nodeValue) - - elif param.nodeName == 'score_func': - score_func_str = str(param.childNodes[0].nodeValue) - - # make sure we have the needed parameters - if score_func_str == None: - raise MalformedError("No score function specified.") - - # create a vector of particle indexes - particle_indexes = IMP.Ints() - for p_idx in particle_list: - particle_indexes.push_back(int(p_idx)) - - # add restraint for for vector of particles - score_func_params = get_basic_score_func_params(score_func_str, 0.0, sd) - model.restraints.append(IMP.ProximityRestraint(model, particle_indexes, distance, score_func_params)) - model.restraint_sets[rs_idx].add_restraint(model.restraints[-1]) - - - -def load_rsr_exclusion_volume(model, rs_idx, rsr, base_particle): - """Load exclusion volume restraint from the DOM""" - print "Load exclusion volume restraint" - - # defaults - distance_attribute = '' - sd = 0.1 - num_lists = 0 - - # get the parameters - for param in rsr.childNodes: - if num_lists == 0 and param.nodeName == 'particle_list': - particle_list1 = _get_particle_list(param) - num_lists = 1 - - elif param.nodeName == 'particle_list': - particle_list2 = _get_particle_list(param) - num_lists = 2 - - elif param.nodeName == 'sd': - sd = float(param.childNodes[0].nodeValue) - - elif param.nodeName == 'distance_attribute': - distance_attribute = str(param.childNodes[0].nodeValue) - - # make sure we have the needed parameters - if distance_attribute == '': - raise MalformedError("No distance specified.") - - # create a vector of particle indexes - particle_indexes1 = IMP.Ints() - particle_indexes1.clear() - for p_idx in particle_list1: - particle_indexes1.push_back(int(p_idx)) - - score_func_params = get_basic_score_func_params("harmonic_lower_bound", 0.0, sd) - if (num_lists == 2): - particle_indexes2 = IMP.Ints() - particle_indexes2.clear() - for p_idx in particle_list2: - particle_indexes2.push_back(int(p_idx)) - - print "adding inter particle exclusion volumes for two bodies: ", model, particle_indexes1, particle_indexes2, distance_attribute, sd - r = IMP.ExclusionVolumeRestraint(model, particle_indexes1, particle_indexes2, distance_attribute, score_func_params) - model.restraints.append(r) - model.restraint_sets[rs_idx].add_restraint(r) - else: - print "adding intra particle exclusion volumes for one body: ", model, particle_indexes1, distance_attribute, sd - r = IMP.ExclusionVolumeRestraint(model, particle_indexes1, distance_attribute, score_func_params) - model.restraints.append(r) - model.restraint_sets[rs_idx].add_restraint(r) - - - -def get_basic_score_func_params(score_func_str, mean=0.0, sd=0.1): - """ Get score function params corresponding to the given name """ - return IMP.BasicScoreFuncParams(score_func_str, mean, sd) - - -# support different ways of specifying particle pairs in the XML. -# 1 3 direct entering of particle pair indexes: -# (1, 3) -# 3 4 5 6 all possible pairs from a list -# (3, 4) (3, 5) (3, 6) (4, 5) (4, 6) (5, 6) -def _get_particle_pairs(pairs_node): - """ Get a list of all particle pairs specified by the given node """ - pairs = [] - for pair_node in pairs_node.childNodes: - if pair_node.nodeName == 'pair': - pairs.append(str(pair_node.childNodes[0].nodeValue).split()) - - if pair_node.nodeName == 'all_pairs': - list = _get_particle_list(pair_node) - for i in range(0, len(list)-1): - for j in range(i+1, len(list)): - pairs.append((i, j)) - - return pairs - - -# 3 4 5 6 list (3, 4, 5, 6) -def _get_particle_list(particle_list_node): - """ Get a list of all particles specified by the given node """ - return str(particle_list_node.childNodes[0].nodeValue).split()