Changeset 66fd49 for src/Actions


Ignore:
Timestamp:
Feb 3, 2011, 9:51:18 AM (14 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:
d6f886
Parents:
0b15bb
git-author:
Frederik Heber <heber@…> (12/30/10 20:52:17)
git-committer:
Frederik Heber <heber@…> (02/03/11 09:51:18)
Message:

Rewrite of FillVoidWithMoleculeAction.

FillVoidWithMoleculeAction:

  • new parameter MinDistance and default value of 0.
  • BUGFIX: filler is already created when parsing file, removed useless creation of it initially (also caused lots of confusion due to an "extra" molecule).
  • Undo implemented, regression test inserted.
  • Redo is somewhat hard to implement, as one would use performCall() if it only it would not retrieve its values from ValueStorage ...

FillVoidWithMolecule():

  • filler is now the zeroth not the last molecule, marked by firstInsertion and firstInserter. Filler is removed if no molecules are filled.
  • outsourced stuff into smaller functions
  • removed FillIt to through every atom despite only CurrentPosition, indepedent of atom position, is checked.

TESTFIXES:

  • Analysis/3: test.xyz changed because boundary is now 1.5 instead of 2.1 as 2.1 is not enough of molecules get filled in (and the filler already is).
  • Analysis/3: tensid.data was actually lacking water at (0,0,0) which is after the rewrite present.
Location:
src/Actions/MoleculeAction
Files:
2 edited

Legend:

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

    r0b15bb r66fd49  
    2828#include "World.hpp"
    2929
     30#include "Descriptors/MoleculeIdDescriptor.hpp"
    3031#include "Parser/MpqcParser.hpp"
    3132#include "Parser/PcpParser.hpp"
     
    3536#include "Parser/FormatParserStorage.hpp"
    3637
     38#include <algorithm>
    3739#include <iostream>
    3840#include <string>
     
    4749/** =========== define the function ====================== */
    4850Action::state_ptr MoleculeFillVoidWithMoleculeAction::performCall() {
    49 
    5051  // obtain information
    5152  getParametersfromValueStorage();
    5253
    53   DoLog(1) && (Log() << Verbose(1) << "Filling Box with water molecules, lengths(" << params.lengths[0] << "," << params.lengths[1] << "," << params.lengths[2] << "), distances (" << params.distances[0] << "," << params.distances[1] << "," << params.distances[2] << "), DoRotate " << params.DoRotate << "." << endl);
     54  if (!boost::filesystem::exists(params.fillername)) {
     55    DoeLog(1) && (eLog() << Verbose(1) << "File with filler molecule " << params.fillername << " does not exist!" << endl);
     56    return Action::failure;
     57  }
     58
     59  DoLog(1) && (Log() << Verbose(1) << "Filling Box with water molecules, lengths(" << params.lengths[0] << "," << params.lengths[1] << "," << params.lengths[2] << "), distances (" << params.distances[0] << "," << params.distances[1] << "," << params.distances[2] << "), MinDistance " << params.MinDistance << ", DoRotate " << params.DoRotate << "." << endl);
    5460  // construct water molecule
    55   molecule *filler = World::getInstance().createMolecule();
     61  std::vector<molecule *> presentmolecules = World::getInstance().getAllMolecules();
     62//  DoLog(0) && (Log() << Verbose(0) << presentmolecules.size() << " molecules initially are present." << std::endl);
    5663  std::string FilenameSuffix = params.fillername.string().substr(params.fillername.string().find_last_of('.')+1, params.fillername.string().length());
    5764  ifstream input;
     
    9299      break;
    93100  }
    94   World::MoleculeIterator iter = World::getInstance().getMoleculeIter();
    95   for (; iter != World::getInstance().moleculeEnd(); ++iter)
     101
     102  // search the filler molecule that has been just parsed
     103  molecule *filler = NULL;
     104  for (World::MoleculeIterator iter = World::getInstance().getMoleculeIter();
     105      iter != World::getInstance().moleculeEnd();
     106      ++iter)
    96107    filler = *iter; // get last molecule
    97108  filler->SetNameFromFilename(params.fillername.string().c_str());
     
    102113  for (int i=0;i<NDIM;i++)
    103114    distance[i] = params.distances[i];
    104   FillVoidWithMolecule(filler, *(World::getInstance().getConfig()), distance, params.lengths[0], params.lengths[1], params.lengths[2], params.DoRotate);
     115  FillVoidWithMolecule(filler, *(World::getInstance().getConfig()), distance, params.lengths[0], params.lengths[1], params.lengths[2], params.MinDistance, params.DoRotate);
    105116
    106   return Action::success;
     117  // generate list of newly created molecules
     118  // (we can in general remove more quickly from a list than a vector)
     119  std::vector<molecule *> fillermolecules = World::getInstance().getAllMolecules();
     120//  DoLog(0) && (Log() << Verbose(0) << fillermolecules.size() << " molecules are present." << std::endl);
     121  std::list<molecule *> fillermolecules_list;
     122  std::copy( fillermolecules.begin(),  fillermolecules.end(), std::back_inserter( fillermolecules_list ));
     123//  DoLog(0) && (Log() << Verbose(0) << fillermolecules_list.size() << " molecules have been copied." << std::endl);
     124  for (std::vector<molecule *>::const_iterator iter = presentmolecules.begin();
     125      iter != presentmolecules.end();
     126      ++iter) {
     127    fillermolecules_list.remove(*iter);
     128  }
     129//  DoLog(0) && (Log() << Verbose(0) << fillermolecules_list.size() << " molecules left after removal." << std::endl);
     130  fillermolecules.clear();
     131  std::copy(fillermolecules_list.begin(), fillermolecules_list.end(), std::back_inserter( fillermolecules ));
     132
     133//  DoLog(0) && (Log() << Verbose(0) << fillermolecules.size() << " molecules have been inserted." << std::endl);
     134
     135  return Action::state_ptr(new MoleculeFillVoidWithMoleculeState(fillermolecules,params));
    107136}
    108137
    109138Action::state_ptr MoleculeFillVoidWithMoleculeAction::performUndo(Action::state_ptr _state) {
    110 //  MoleculeFillVoidWithMoleculeState *state = assert_cast<MoleculeFillVoidWithMoleculeState*>(_state.get());
     139  MoleculeFillVoidWithMoleculeState *state = assert_cast<MoleculeFillVoidWithMoleculeState*>(_state.get());
    111140
    112 //  string newName = state->mol->getName();
    113 //  state->mol->setName(state->lastName);
     141  MoleculeListClass *MolList = World::getInstance().getMolecules();
    114142
    115   return Action::failure;
     143  BOOST_FOREACH(molecule *_mol, state->fillermolecules) {
     144    MolList->erase(_mol);
     145    if ((_mol != NULL) && (!(World::getInstance().getAllMolecules(MoleculeById(_mol->getId()))).empty())) {
     146      for(molecule::iterator iter = _mol->begin();
     147          !_mol->empty();
     148          iter = _mol->begin()) {
     149        atom *Walker = *iter;
     150        _mol->erase(iter);
     151        World::getInstance().destroyAtom(Walker);
     152      }
     153      World::getInstance().destroyMolecule(_mol);
     154    }
     155  }
     156
     157  // as molecules and atoms from state are removed, we have to create a new one
     158  std::vector<molecule *> fillermolecules;
     159  return Action::state_ptr(new MoleculeFillVoidWithMoleculeState(fillermolecules,state->params));
    116160}
    117161
    118162Action::state_ptr MoleculeFillVoidWithMoleculeAction::performRedo(Action::state_ptr _state){
    119   // Undo and redo have to do the same for this action
    120   return performUndo(_state);
     163  //MoleculeFillVoidWithMoleculeState *state = assert_cast<MoleculeFillVoidWithMoleculeState*>(_state.get());
     164
     165  return Action::failure;
     166  //return Action::state_ptr(_state);
    121167}
    122168
    123169bool MoleculeFillVoidWithMoleculeAction::canUndo() {
    124   return false;
     170  return true;
    125171}
    126172
    127173bool MoleculeFillVoidWithMoleculeAction::shouldUndo() {
    128   return false;
     174  return true;
    129175}
    130176/** =========== end of function ====================== */
  • src/Actions/MoleculeAction/FillVoidWithMoleculeAction.def

    r0b15bb r66fd49  
    1313// ValueStorage by the token "Z" -> first column: int, Z, "Z"
    1414// "undefine" if no parameters are required, use (NODEFAULT) for each (undefined) default value
    15 #define paramtypes (boost::filesystem::path)(Vector)(Vector)(bool)
    16 #define paramtokens ("fill-void")("distances")("lengths")("DoRotate")
    17 #define paramdescriptions ("name of xyz file of filler molecule")("list of three of distances in space, one for each axis direction")("list of three of lengths in space, one for each axis direction")("whether to rotate or not")
    18 #undef paramdefaults
    19 #define paramreferences (fillername)(distances)(lengths)(DoRotate)
     15#define paramtypes (boost::filesystem::path)(Vector)(Vector)(double)(bool)
     16#define paramtokens ("fill-void")("distances")("lengths")("MinDistance")("DoRotate")
     17#define paramdescriptions ("name of xyz file of filler molecule")("list of three of distances in space, one for each axis direction")("list of three of lengths in space, one for each axis direction")("minimum distance to boundary")("whether to rotate or not")
     18#define paramdefaults (NODEFAULT)(NODEFAULT)(NODEFAULT)("0.")("0")
     19#define paramreferences (fillername)(distances)(lengths)(MinDistance)(DoRotate)
    2020
    21 #undef statetypes
    22 #undef statereferences
     21#define statetypes (std::vector<molecule *>)
     22#define statereferences (fillermolecules)
    2323
    2424// some defines for all the names, you may use ACTION, STATE and PARAMS
Note: See TracChangeset for help on using the changeset viewer.