Changeset f6ba43 for src


Ignore:
Timestamp:
Oct 5, 2011, 4:23:19 PM (13 years ago)
Author:
Frederik Heber <heber@…>
Branches:
Action_Thermostats, Add_AtomRandomPerturbation, Add_FitFragmentPartialChargesAction, Add_RotateAroundBondAction, Add_SelectAtomByNameAction, Added_ParseSaveFragmentResults, AddingActions_SaveParseParticleParameters, Adding_Graph_to_ChangeBondActions, Adding_MD_integration_tests, Adding_ParticleName_to_Atom, Adding_StructOpt_integration_tests, AtomFragments, Automaking_mpqc_open, AutomationFragmentation_failures, Candidate_v1.5.4, Candidate_v1.6.0, Candidate_v1.6.1, ChangeBugEmailaddress, ChangingTestPorts, ChemicalSpaceEvaluator, CombiningParticlePotentialParsing, Combining_Subpackages, Debian_Package_split, Debian_package_split_molecuildergui_only, Disabling_MemDebug, Docu_Python_wait, EmpiricalPotential_contain_HomologyGraph, EmpiricalPotential_contain_HomologyGraph_documentation, Enable_parallel_make_install, Enhance_userguide, Enhanced_StructuralOptimization, Enhanced_StructuralOptimization_continued, Example_ManyWaysToTranslateAtom, Exclude_Hydrogens_annealWithBondGraph, FitPartialCharges_GlobalError, Fix_BoundInBox_CenterInBox_MoleculeActions, Fix_ChargeSampling_PBC, Fix_ChronosMutex, Fix_FitPartialCharges, Fix_FitPotential_needs_atomicnumbers, Fix_ForceAnnealing, Fix_IndependentFragmentGrids, Fix_ParseParticles, Fix_ParseParticles_split_forward_backward_Actions, Fix_PopActions, Fix_QtFragmentList_sorted_selection, Fix_Restrictedkeyset_FragmentMolecule, Fix_StatusMsg, Fix_StepWorldTime_single_argument, Fix_Verbose_Codepatterns, Fix_fitting_potentials, Fixes, ForceAnnealing_goodresults, ForceAnnealing_oldresults, ForceAnnealing_tocheck, ForceAnnealing_with_BondGraph, ForceAnnealing_with_BondGraph_continued, ForceAnnealing_with_BondGraph_continued_betteresults, ForceAnnealing_with_BondGraph_contraction-expansion, FragmentAction_writes_AtomFragments, FragmentMolecule_checks_bonddegrees, GeometryObjects, Gui_Fixes, Gui_displays_atomic_force_velocity, ImplicitCharges, IndependentFragmentGrids, IndependentFragmentGrids_IndividualZeroInstances, IndependentFragmentGrids_IntegrationTest, IndependentFragmentGrids_Sole_NN_Calculation, JobMarket_RobustOnKillsSegFaults, JobMarket_StableWorkerPool, JobMarket_unresolvable_hostname_fix, MoreRobust_FragmentAutomation, ODR_violation_mpqc_open, PartialCharges_OrthogonalSummation, PdbParser_setsAtomName, PythonUI_with_named_parameters, QtGui_reactivate_TimeChanged_changes, Recreated_GuiChecks, Rewrite_FitPartialCharges, RotateToPrincipalAxisSystem_UndoRedo, SaturateAtoms_findBestMatching, SaturateAtoms_singleDegree, StoppableMakroAction, Subpackage_CodePatterns, Subpackage_JobMarket, Subpackage_LinearAlgebra, Subpackage_levmar, Subpackage_mpqc_open, Subpackage_vmg, Switchable_LogView, ThirdParty_MPQC_rebuilt_buildsystem, TrajectoryDependenant_MaxOrder, TremoloParser_IncreasedPrecision, TremoloParser_MultipleTimesteps, TremoloParser_setsAtomName, Ubuntu_1604_changes, stable
Children:
8990879
Parents:
c521e1
git-author:
Frederik Heber <heber@…> (09/27/11 09:07:46)
git-committer:
Frederik Heber <heber@…> (10/05/11 16:23:19)
Message:

Many smaller changes to CreateMicelleAction to get it fully working and compliant.

Changes to MoleculeCreateMicelleAction::performCall():

  • returns Action::success when no molecule is selected.
  • we check for selection of not more than one molecule.
  • we store full undo (positions in selected molecule and added molecules).
  • new parameter DoRotate to tell whether to mirror molecule along z axis or not.
  • FIX: we rotate to PAS only in case of more than one atom present in molecule.
  • FIX: copied molecules are added to World's MoleculeListClass (and correctly removed in performUndo()).
  • FIX: Placed shifting original molecule into own block and corrected usage of RotationAxis.
  • Also performUndo() is fully implemented.
  • we can... and shouldUndo().
  • added regression test on both do and Undo.
Location:
src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/Actions/MoleculeAction/CreateMicelleAction.cpp

    rc521e1 rf6ba43  
    5151#include "Action_impl_pre.hpp"
    5252
    53 using namespace std;
    54 
    5553#include "UIElements/UIFactory.hpp"
    5654#include "UIElements/Dialog.hpp"
     
    7169  // we don't need to create one and add them all to it
    7270  MoleculeVector all = World::getInstance().getSelectedMolecules();
    73   ASSERT(!all.empty(), "MoleculeCreateMicelleAction::performCall() - no molecules selected.");
     71
     72  // return success when none are selected
     73  if (all.empty())
     74    return Action::success;
     75
     76  // check that there is precisely one molecule
     77  ASSERT(all.size() == 1,
     78      "MoleculeCreateMicelleAction::performCall() - more than one molecule selected, this is not supported.");
     79
    7480  molecule *stick = *(all.begin());
    7581
     82
     83  // create undo state for original molecule
     84  std::vector<Vector> stickPositions;
     85  for (molecule::const_iterator iter = stick->begin(); iter != stick->end(); ++iter)
     86    stickPositions.push_back((*iter)->getPosition());
     87
     88  // determine principal axis system and rotate such that greatest extension is along z axis
     89  if(stick->size() > 1) { // only rotate if more than one molecule present
     90    Vector den(0.0,0.0,1.0);
     91
     92    MoleculeRotateToPrincipalAxisSystem(den);
     93  }
     94
    7695  // center molecule
    77 
    7896  stick->CenterOrigin();
    7997
    80   // determine principal axis system and rotate such that greatest extension is along z axis
    81   Vector den(0.0,0.0,1.0);
    82 
    83   MoleculeRotateToPrincipalAxisSystem(den);
    84   /* determine
    85   principal axis system and make greatest eigenvector be aligned along
    86   (0,0,1)
    87   */
    88   string path;
    89 
    90   Line RotationAxis(Vector(0.0,0.0,0.0), Vector(1.0,0.0,0.0)); // pt is the current Vector of point on surface
    91 
    92   //for (molecule::iterator it=stick->begin(); it !=stick->end(); ++it)
    93     //(*it)->setPosition(RotationAxis.rotateVector((*it)->getPosition(),M_PI));
    94 
    9598  /// Align molecule with its PAS multiple times with the some surface
    9699
    97100  // get points on surface
    98101
    99   int ka =0;
    100102  //double radius= 1.5*sqrt(pow(1.55, 2)*params.N);
    101103
     
    104106
    105107  // mirror along x-y plane
     108
     109  // additionally invert molecule if desired
     110  if (params.DoRotate) {
     111    for (molecule::iterator it2=stick->begin();it2 !=stick->end();++it2)
     112    {
     113      Vector pos= (**it2).getPosition();
     114      pos[2]= - pos[2];// -Min[2]
     115      (**it2).setPosition(pos);
     116    }
     117  }
     118
     119  // shift molecule by its extension along z axis
    106120
    107121  for (molecule::iterator it2=stick->begin();it2 !=stick->end();++it2)
    108122  {
    109123          Vector pos= (**it2).getPosition();
    110           pos[2]= - pos[2];// -Min[2]
     124          pos[2]=pos[2]+params.radius;
    111125          (**it2).setPosition(pos);
    112126  }
    113127
    114   // shift molecule by its extension along z axis
    115 
    116   for (molecule::iterator it2=stick->begin();it2 !=stick->end();++it2)
    117   {
    118           Vector pos= (**it2).getPosition();
    119           pos[2]=pos[2]+params.radius; // -Min[2]
    120           (**it2).setPosition(pos);
    121   }
    122 
    123128  // copy molecule N times and rotate it to point radially away from surface
    124129
    125130  //double MYEPSILON=1e-10;
    126131
    127   for (ka = 0; ka<pt.size()-1; ka++)
     132  // gather created molecules for undo state
     133  std::vector<molecule *> CreatedMolecules;
     134
     135  // TODO: remove this when we do not need MoleculeListClass anymore
     136  MoleculeListClass *&molecules = World::getInstance().getMolecules();
     137
     138  size_t ka = 0;
     139  for (; ka<pt.size()-1; ka++)
    128140  {
    129141    LOG(1, "STATUS: Creating " << ka+1 << " copy of tenside molecule 'stick' with " << stick->getAtomCount() << " atoms, ");
    130           molecule *Tensid=stick->CopyMolecule();
    131 
    132           LOG(2, "INFO: Rotating ... ");
     142    molecule *Tensid=stick->CopyMolecule();
     143    molecules->insert(Tensid);
     144    CreatedMolecules.push_back(Tensid);
     145
    133146    Vector ZAxis(Vector(0.0,0.0,1.0));
    134147    Vector Axis(pt[ka]);
     
    136149    Axis.VectorProduct(ZAxis);
    137150    Line RotationAxis(Vector(0.0,0.0,1.0), Axis);       // pt is the current Vector of point on surface
     151    LOG(2, "INFO: Rotating along axis " << RotationAxis << " by angle " << alpha << ".");
    138152
    139153    for (molecule::iterator it2=Tensid->begin();it2 !=Tensid->end();++it2)
     
    142156      *(*it2)+=params.center;
    143157    }
    144     LOG(2, "INFO: \tdone.");
    145158
    146159    Tensid=NULL;
     
    148161
    149162  // shift molecule at given position on surface
    150 
    151   LOG(1, "STATUS: Shifting " << ka+1 << " copy of tenside molecule, ");
    152   molecule *Tensid=stick;
    153   LOG(2, "INFO: Rotating ...");
    154   Vector ZAxis(Vector(0.0,0.0,1.0));
    155   Vector Axis(pt[pt.size()-1]);
    156   const double alpha = ZAxis.Angle(Axis);
    157   Axis.VectorProduct(ZAxis);
    158   Line RotationAxis2(Vector(0.0,0.0,1.0), Axis);        // pt is the current Vector of point on surface
    159 
    160   for (molecule::iterator it2=Tensid->begin();it2 !=Tensid->end();++it2)
    161163  {
    162     (*it2)->setPosition(RotationAxis.rotateVector((*it2)->getPosition(),alpha));
    163     *(*it2)+=params.center;
    164   }
    165   LOG(2, "INFO: \tdone.");
    166 
    167   Tensid=NULL;
    168 
    169   return Action::success;
     164    LOG(1, "STATUS: Shifting " << ka+1 << " copy of tenside molecule 'stick' with " << stick->getAtomCount() << " atoms, ");
     165    molecule *Tensid=stick;
     166    // this molecule was present before, hence do not remove it!
     167    //CreatedMolecules.push_back(Tensid);
     168
     169    Vector ZAxis(Vector(0.0,0.0,1.0));
     170    Vector Axis(pt[pt.size()-1]);
     171    const double alpha = ZAxis.Angle(Axis);
     172    Axis.VectorProduct(ZAxis);
     173    Line RotationAxis(Vector(0.0,0.0,1.0), Axis);       // pt is the current Vector of point on surface
     174    LOG(2, "INFO: Rotating along axis " << RotationAxis << " by angle " << alpha << ".");
     175
     176    for (molecule::iterator it2=Tensid->begin();it2 !=Tensid->end();++it2)
     177    {
     178      (*it2)->setPosition(RotationAxis.rotateVector((*it2)->getPosition(),alpha));
     179      *(*it2)+=params.center;
     180    }
     181  }
     182
     183
     184  return Action::state_ptr(new MoleculeCreateMicelleState(CreatedMolecules, stick, stickPositions, params));
    170185}
    171186
    172187Action::state_ptr MoleculeCreateMicelleAction::performUndo(Action::state_ptr _state)
    173188{
    174   //  MoleculeFillVoidWithMoleculeState *state = assert_cast<MoleculeFillVoidWithMoleculeState*>(_state.());
    175 
    176   //  string newName = state->mol->Name();
    177   //  state->mol->setName(state->lastName);
    178 
     189  MoleculeCreateMicelleState *state = assert_cast<MoleculeCreateMicelleState*>(_state.get());
     190
     191  // removing all created molecules
     192  MoleculeListClass *&molecules = World::getInstance().getMolecules();
     193  LOG(0, "STATUS: Removing " << state->CreatedMolecules.size() << " molecules again.");
     194  for(std::vector<molecule *>::const_iterator iter = state->CreatedMolecules.begin();
     195     iter != state->CreatedMolecules.end();
     196     ++iter) {
     197    LOG(2, "INFO: Removing " << (*iter)->getName());
     198    for(molecule::iterator AtomRunner = (*iter)->begin();
     199      !(*iter)->empty();
     200      AtomRunner = (*iter)->begin()) {
     201      World::getInstance().destroyAtom(*AtomRunner);
     202    }
     203    //LOG(3, "INFO: molecules contains still " << molecules->ListOfMolecules.size() << " molecules.");
     204    molecules->erase(*iter);
     205    World::getInstance().destroyMolecule(*iter);
     206  }
     207 
     208  // undo changes to original molecule
     209  ASSERT(state->stickPositions.size() == state->stick->size(),
     210      "MoleculeCreateMicelleAction::performUndo() - number of stored positions ("
     211      +toString(state->stickPositions.size())+") and number of atoms ("
     212      +toString(state->stick->size())+") do not match.");
     213  std::vector<Vector>::const_iterator PosIter = state->stickPositions.begin();
     214  molecule::iterator iter = state->stick->begin();
     215  for (; iter != state->stick->end(); ++iter, ++PosIter)
     216    (*iter)->setPosition(*PosIter);
     217
     218  return Action::state_ptr(_state);
     219}
     220
     221Action::state_ptr MoleculeCreateMicelleAction::performRedo(Action::state_ptr _state)
     222{
     223  LOG(0, "STATUS: CreateMicelleAction::performRedo() is nit implemented yet.");
    179224  return Action::failure;
    180225}
    181226
    182 Action::state_ptr MoleculeCreateMicelleAction::performRedo(Action::state_ptr _state)
    183 {
    184   // Undo and redo have to do the same for this action
    185   return performUndo(_state);
    186 }
    187 
    188227
    189228bool MoleculeCreateMicelleAction::canUndo()
    190229{
    191   return false;
     230  return true;
    192231}
    193232
    194233bool MoleculeCreateMicelleAction::shouldUndo()
    195234{
    196   return false;
     235  return true;
    197236}
    198237
  • src/Actions/MoleculeAction/CreateMicelleAction.def

    rc521e1 rf6ba43  
    99#include <vector>
    1010#include "LinearAlgebra/Vector.hpp"
    11 class CreateMicelle;
    1211
     12class molecule;
    1313
    1414// "undefine" if no parameters are required
    15 #define paramtypes (int) (Vector) (double)
    16 #define paramtokens ("create-micelle") ("position") ("radius")
    17 #define paramdescriptions ("number of molecules")("center of micelle in R^3 space")("radius of mcielle")
    18 #undef paramdefaults
    19 #define paramreferences (N) (center) (radius)
     15#define paramtypes (int)(Vector)(double)(bool)
     16#define paramtokens ("create-micelle")("position")("radius")("DoRotate")
     17#define paramdescriptions ("number of molecules")("center of micelle in R^3 space")("radius of mcielle")("whether to mirror molecule perpendicular to z axis")
     18#define paramdefaults (NODEFAULT)(NODEFAULT)(NODEFAULT)("0")
     19#define paramreferences (N)(center)(radius)(DoRotate)
    2020
    21 #undef statetypes
    22 #undef statereferences
     21#define statetypes (std::vector<molecule *>)(molecule *)(std::vector<Vector>)
     22#define statereferences (CreatedMolecules)(stick)(stickPositions)
    2323
    2424// some defines for all the names, you may use ACTION, STATE and PARAMS
     
    3030
    3131// finally the information stored in the ActionTrait specialization
    32 #define DESCRIPTION "creates a micelle of molecules"
     32#define DESCRIPTION "creates a micelle of molecules by aligning molecule along z axis and placing perpendicular to sphere\'s surface. Note that alignment has freedom with respect to z axis, use DoRotate to compensate."
    3333#undef SHORTFORM
  • src/Shapes/BaseShapes.cpp

    rc521e1 rf6ba43  
    6969 * \param N number of points on surface
    7070 */
    71 std::vector<Vector> Sphere_impl::getHomogeneousPointsOnSurface(const size_t N) const {
     71std::vector<Vector> Sphere_impl::getHomogeneousPointsOnSurface(const size_t N) const
     72{
    7273  std::vector<Vector> PointsOnSurface;
    7374
     
    108109    length = length + dlength;*/
    109110
    110   //ASSERT(PointsOnSurface.size() == N, "Sphere_impl::getHomogeneousPointsOnSurface() did not create enough points.");
     111//  ASSERT(PointsOnSurface.size() == N,
     112//      "Sphere_impl::getHomogeneousPointsOnSurface() did not create "
     113//      +::toString(N)+" but "+::toString(PointsOnSurface.size())+" points.");
    111114  return PointsOnSurface;
    112115}
Note: See TracChangeset for help on using the changeset viewer.