EMAN2
Public Member Functions | Static Public Member Functions | Static Public Attributes | Private Member Functions | List of all members
EMAN::OptimumOrientationGenerator Class Reference

Optimum orientation generator. More...

#include <symmetry.h>

Inheritance diagram for EMAN::OptimumOrientationGenerator:
Inheritance graph
[legend]
Collaboration diagram for EMAN::OptimumOrientationGenerator:
Collaboration graph
[legend]

Public Member Functions

 OptimumOrientationGenerator ()
 
virtual ~OptimumOrientationGenerator ()
 
virtual string get_name () const
 Return "opt". More...
 
virtual string get_desc () const
 Get a description. More...
 
virtual TypeDict get_param_types () const
 Get a dictionary containing the permissable parameters of this class. More...
 
virtual vector< Transformgen_orientations (const Symmetry3D *const sym) const
 Generate Saff orientations in the asymmetric unit of the symmetry. More...
 
- Public Member Functions inherited from EMAN::OrientationGenerator
 OrientationGenerator ()
 
virtual ~OrientationGenerator ()
 
bool add_orientation (vector< Transform > &v, const float &az, const float &alt) const
 This functions adds one or more Transform objects to the vector v, depending on the parameters stored in the dictionary (which the inheriting class may include by initializing the typedict in get_param_types by calling. More...
 
float get_optimal_delta (const Symmetry3D *const sym, const int &n) const
 This function gets the optimal value of the delta (or angular spacing) of the orientations based on a desired total number of orientations (n). More...
 
- Public Member Functions inherited from EMAN::FactoryBase
 FactoryBase ()
 
virtual ~FactoryBase ()
 
Dict get_params () const
 get a copy of the parameters of this class More...
 
void set_params (const Dict &new_params)
 Set new parameters. More...
 
void set_param (const string key, const EMObject val)
 
void insert_params (const Dict &new_params)
 Insert parameters. More...
 
Dict copy_relevant_params (const FactoryBase *const that) const
 

Static Public Member Functions

static OrientationGeneratorNEW ()
 Factory support function NEW. More...
 

Static Public Attributes

static const string NAME = "opt"
 The name of this class - used to access it from factories etc. Should be "icos". More...
 

Private Member Functions

 OptimumOrientationGenerator (const OptimumOrientationGenerator &)
 Disallow copy construction. More...
 
OptimumOrientationGeneratoroperator= (const OptimumOrientationGenerator &)
 Disallow assignment. More...
 
virtual int get_orientations_tally (const Symmetry3D *const sym, const float &delta) const
 This function returns how many orientations will be generated for a given delta (angular spacing) It does this by simulated gen_orientations. More...
 
vector< Vec3foptimize_distances (const vector< Transform > &v) const
 Optimize the distances in separating points on the unit sphere, as described by the the rotations in Transform objects. More...
 

Additional Inherited Members

- Protected Member Functions inherited from EMAN::OrientationGenerator
void get_az_max (const Symmetry3D *const sym, const float &altmax, const bool inc_mirror, const float &alt_iterator, const float &h, bool &d_odd_mirror_flag, float &azmax_adjusted) const
 
- Protected Attributes inherited from EMAN::FactoryBase
Dict params
 This is the dictionary the stores the parameters of the object. More...
 

Detailed Description

Optimum orientation generator.

Optimally distributes points on a unit sphere, then slices out a correctly sized asymmetric unit, depending on the symmetry type. The approach relies on an initial distribution of points on the unit sphere, which may be generated using any of the other orientation generators. By default, the Saff orientation generator is used.

Author
David Woolford
Date
March 2008

Definition at line 1438 of file symmetry.h.

Constructor & Destructor Documentation

◆ OptimumOrientationGenerator() [1/2]

EMAN::OptimumOrientationGenerator::OptimumOrientationGenerator ( )
inline

Definition at line 1441 of file symmetry.h.

1441{}

Referenced by NEW().

◆ ~OptimumOrientationGenerator()

virtual EMAN::OptimumOrientationGenerator::~OptimumOrientationGenerator ( )
inlinevirtual

Definition at line 1442 of file symmetry.h.

1442{}

◆ OptimumOrientationGenerator() [2/2]

EMAN::OptimumOrientationGenerator::OptimumOrientationGenerator ( const OptimumOrientationGenerator )
private

Disallow copy construction.

Member Function Documentation

◆ gen_orientations()

vector< Transform > OptimumOrientationGenerator::gen_orientations ( const Symmetry3D *const  sym) const
virtual

Generate Saff orientations in the asymmetric unit of the symmetry.

Parameters
symthe symmetry which defines the interesting asymmetric unit
Returns
a vector of Transform objects containing the set of evenly distributed orientations

Implements EMAN::OrientationGenerator.

Definition at line 794 of file symmetry.cpp.

795{
796 float delta = params.set_default("delta", 0.0f);
797 int n = params.set_default("n", 0);
798
799 bool inc_mirror = params.set_default("inc_mirror",false);
800
801 if ( delta <= 0 && n <= 0 ) throw InvalidParameterException("Error, you must specify a positive non-zero delta or n");
802 if ( delta > 0 && n > 0 ) throw InvalidParameterException("Error, the delta and the n arguments are mutually exclusive");
803
804 string generatorname = params.set_default("use","saff");
805
806 if ( n > 0 && generatorname != RandomOrientationGenerator::NAME ) {
807 params["delta"] = get_optimal_delta(sym,n);
808 params["n"] = (int)0;
809 }
810
811 // Force the orientation generator to include the mirror - this is because
812 // We will enventually use it to generate orientations over the intire sphere
813 // which is C1 symmetry, with the inc_mirror flag set to true
814 params["inc_mirror"] = true;
817
818
819 // get the starting orientation distribution
820 CSym* unit_sphere = new CSym();
821 Dict nsym; nsym["nsym"] = 1; unit_sphere->set_params(nsym);
822
823 vector<Transform> unitsphereorientations = g->gen_orientations(unit_sphere);
824 delete g; g = 0;
825 delete unit_sphere; unit_sphere = 0;
826
827 vector<Vec3f> angles = optimize_distances(unitsphereorientations);
828
829 vector<Transform> ret;
830 for (vector<Vec3f>::const_iterator it = angles.begin(); it != angles.end(); ++it ) {
831 if ( sym->is_in_asym_unit((*it)[1],(*it)[0],inc_mirror) ) {
832 add_orientation(ret,(*it)[0],(*it)[1]);
833 }
834 }
835
836 // reset the params to what they were before they were acted upon by this class
837 params["inc_mirror"] = inc_mirror;
838 params["delta"] = delta;
839 params["n"] = n;
840
841 return ret;
842}
An encapsulation of cyclic 3D symmetry.
Definition: symmetry.h:234
Dict is a dictionary to store <string, EMObject> pair.
Definition: emobject.h:385
type set_default(const string &key, type val)
Default setting behavior This can be achieved using a template - d.woolford Jan 2008 (before there wa...
Definition: emobject.h:569
Dict copy_relevant_params(const FactoryBase *const that) const
Definition: emobject.h:946
void set_params(const Dict &new_params)
Set new parameters.
Definition: emobject.h:916
Dict params
This is the dictionary the stores the parameters of the object.
Definition: emobject.h:953
Factory is used to store objects to create new instances.
Definition: emobject.h:725
vector< Vec3f > optimize_distances(const vector< Transform > &v) const
Optimize the distances in separating points on the unit sphere, as described by the the rotations in ...
Definition: symmetry.cpp:844
An orientation generator is a kind of class that will generate orientations for a given symmetry If o...
Definition: symmetry.h:1000
bool add_orientation(vector< Transform > &v, const float &az, const float &alt) const
This functions adds one or more Transform objects to the vector v, depending on the parameters stored...
Definition: symmetry.cpp:273
virtual vector< Transform > gen_orientations(const Symmetry3D *const sym) const =0
generate orientations given some symmetry type
float get_optimal_delta(const Symmetry3D *const sym, const int &n) const
This function gets the optimal value of the delta (or angular spacing) of the orientations based on a...
Definition: symmetry.cpp:236
static const string NAME
The name of this class - used to access it from factories etc.
Definition: symmetry.h:1278
virtual bool is_in_asym_unit(const float &altitude, const float &azimuth, const bool inc_mirror) const =0
A function to be used when generating orientations over portion of the unit sphere defined by paramet...
#define InvalidParameterException(desc)
Definition: exception.h:361

References EMAN::OrientationGenerator::add_orientation(), EMAN::FactoryBase::copy_relevant_params(), EMAN::OrientationGenerator::gen_orientations(), EMAN::OrientationGenerator::get_optimal_delta(), InvalidParameterException, EMAN::Symmetry3D::is_in_asym_unit(), EMAN::RandomOrientationGenerator::NAME, optimize_distances(), EMAN::FactoryBase::params, EMAN::Dict::set_default(), and EMAN::FactoryBase::set_params().

◆ get_desc()

virtual string EMAN::OptimumOrientationGenerator::get_desc ( ) const
inlinevirtual

Get a description.

Returns
a clear desciption of this class

Implements EMAN::FactoryBase.

Definition at line 1460 of file symmetry.h.

1460{ return "Generate optimally distributed orientations within an asymmetric using a basic optimization technique"; }

◆ get_name()

virtual string EMAN::OptimumOrientationGenerator::get_name ( ) const
inlinevirtual

Return "opt".

Returns
the unique name of this class

Implements EMAN::FactoryBase.

Definition at line 1455 of file symmetry.h.

1455{ return NAME; }
static const string NAME
The name of this class - used to access it from factories etc. Should be "icos".
Definition: symmetry.h:1483

References NAME.

◆ get_orientations_tally()

int OptimumOrientationGenerator::get_orientations_tally ( const Symmetry3D *const  sym,
const float &  delta 
) const
privatevirtual

This function returns how many orientations will be generated for a given delta (angular spacing) It does this by simulated gen_orientations.

Parameters
symthe symmetry which defines the interesting asymmetric unit
deltathe desired angular spacing of the orientations
Returns
the number of orientations that will be generated using these parameters

Implements EMAN::OrientationGenerator.

Definition at line 779 of file symmetry.cpp.

780{
781 string deltaoptname = params.set_default("use","saff");
782 Dict a;
783 a["inc_mirror"] = (bool)params.set_default("inc_mirror",false);
785 if (g) {
786 int tally = g->get_orientations_tally(sym,delta);
787 delete g;
788 g = 0;
789 return tally;
790 }
791 else throw;
792}
virtual int get_orientations_tally(const Symmetry3D *const sym, const float &delta) const =0
This function returns how many orientations will be generated for a given delta (angular spacing) It ...

References EMAN::OrientationGenerator::get_orientations_tally(), EMAN::FactoryBase::params, and EMAN::Dict::set_default().

◆ get_param_types()

virtual TypeDict EMAN::OptimumOrientationGenerator::get_param_types ( ) const
inlinevirtual

Get a dictionary containing the permissable parameters of this class.

Returns
a dictionary containing the permissable parameters of this class parameters are explained in the dictionary itself

Reimplemented from EMAN::OrientationGenerator.

Definition at line 1466 of file symmetry.h.

1467 {
1469 d.put("n", EMObject::INT, "The number of orientations to generate. This option is mutually exclusively of the delta argument.Will attempt to get as close to the number specified as possible.");
1470 d.put("inc_mirror", EMObject::BOOL, "Indicates whether or not to include the mirror portion of the asymmetric unit. Default is false.");
1471 d.put("delta", EMObject::FLOAT, "The angular separation of orientations in degrees. This option is mutually exclusively of the n argument.");
1472 d.put("use", EMObject::STRING, "The orientation generation technique used to generate the initial distribution on the unit sphere.");
1473 return d;
1474 }
virtual TypeDict get_param_types() const
Definition: symmetry.h:1011

References EMAN::EMObject::BOOL, EMAN::EMObject::FLOAT, EMAN::OrientationGenerator::get_param_types(), EMAN::EMObject::INT, EMAN::TypeDict::put(), and EMAN::EMObject::STRING.

◆ NEW()

static OrientationGenerator * EMAN::OptimumOrientationGenerator::NEW ( )
inlinestatic

Factory support function NEW.

Returns
a newly instantiated class of this type

Definition at line 1447 of file symmetry.h.

1448 {
1449 return new OptimumOrientationGenerator();
1450 }

References OptimumOrientationGenerator().

◆ operator=()

OptimumOrientationGenerator & EMAN::OptimumOrientationGenerator::operator= ( const OptimumOrientationGenerator )
private

Disallow assignment.

◆ optimize_distances()

vector< Vec3f > OptimumOrientationGenerator::optimize_distances ( const vector< Transform > &  v) const
private

Optimize the distances in separating points on the unit sphere, as described by the the rotations in Transform objects.

Definition at line 844 of file symmetry.cpp.

845{
846 vector<Vec3f> points;
847
848 for (vector<Transform>::const_iterator it = v.begin(); it != v.end(); ++it ) {
849 points.push_back(Vec3f(0,0,1)*(*it));
850 }
851
852 if ( points.size() >= 2 ) {
853 int max_it = 100;
854 float percentage = 0.01f;
855
856 for ( int i = 0; i < max_it; ++i ){
857 unsigned int p1 = 0;
858 unsigned int p2 = 1;
859
860 float distsquared = (points[p1]-points[p2]).squared_length();
861
862 // Find the nearest points
863 for(unsigned int j = 0; j < points.size(); ++j) {
864 for(unsigned int k = j+1; k < points.size(); ++k) {
865 float d = (points[j]-points[k]).squared_length();
866 if ( d < distsquared ) {
867 distsquared = d;
868 p1 = j;
869 p2 = k;
870 }
871 }
872 }
873
874 // Move them apart by a small fraction
875 Vec3f delta = percentage*(points[p2]-points[p1]);
876
877 points[p2] += delta;
878 points[p2].normalize();
879 points[p1] -= delta;
880 points[p1].normalize();
881 }
882 }
883
884 vector<Vec3f> ret;
885 for (vector<Vec3f>::const_iterator it = points.begin(); it != points.end(); ++it ) {
886 float altitude = (float)(EMConsts::rad2deg*acos((*it)[2]));
887 float azimuth = (float)(EMConsts::rad2deg*atan2((*it)[1],(*it)[0]));
888 ret.push_back(Vec3f(90.0f+azimuth,altitude,0));
889 }
890
891 return ret;
892}
static const double rad2deg
Definition: emobject.h:77
float normalize()
Normalize the vector and return its length before the normalization.
Definition: vec3.h:332
Vec3< float > Vec3f
Definition: vec3.h:693

References EMAN::Vec3< Type >::normalize(), and EMAN::EMConsts::rad2deg.

Referenced by gen_orientations().

Member Data Documentation

◆ NAME

const string OptimumOrientationGenerator::NAME = "opt"
static

The name of this class - used to access it from factories etc. Should be "icos".

Definition at line 1483 of file symmetry.h.

Referenced by get_name().


The documentation for this class was generated from the following files: