Changeset 7a51be for src/Actions
- Timestamp:
- Feb 11, 2011, 9:37:26 PM (14 years ago)
- 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:
- f649de
- Parents:
- 170ba6
- Location:
- src/Actions/MoleculeAction
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Actions/MoleculeAction/FillVoidWithMoleculeAction.cpp
r170ba6 r7a51be 23 23 #include "bondgraph.hpp" 24 24 #include "boundary.hpp" 25 #include "CodePatterns/Verbose.hpp" 25 26 #include "config.hpp" 27 #include "Descriptors/MoleculeIdDescriptor.hpp" 28 #include "Descriptors/MoleculeOrderDescriptor.hpp" 26 29 #include "molecule.hpp" 27 #include " CodePatterns/Verbose.hpp"30 #include "Parser/FormatParserStorage.hpp" 28 31 #include "World.hpp" 29 32 30 #include "Descriptors/MoleculeIdDescriptor.hpp"31 #include "Parser/MpqcParser.hpp"32 #include "Parser/PcpParser.hpp"33 #include "Parser/PdbParser.hpp"34 #include "Parser/TremoloParser.hpp"35 #include "Parser/XyzParser.hpp"36 #include "Parser/FormatParserStorage.hpp"37 33 38 34 #include <algorithm> … … 70 66 ifstream input; 71 67 input.open(params.fillername.string().c_str()); 72 switch (FormatParserStorage::getInstance().getTypeFromSuffix(FilenameSuffix)) { 73 case mpqc: 74 { 75 MpqcParser mpqcparser; 76 mpqcparser.load(&input); 77 break; 78 } 79 case pcp: 80 { 81 PcpParser pcpparser; 82 pcpparser.load(&input); 83 break; 84 } 85 case pdb: 86 { 87 PdbParser pdbparser; 88 pdbparser.load(&input); 89 break; 90 } 91 case tremolo: 92 { 93 TremoloParser tremoloparser; 94 tremoloparser.load(&input); 95 break; 96 } 97 case xyz: 98 { 99 XyzParser xyzparser; 100 xyzparser.load(&input); 101 break; 102 } 103 default: 104 DoeLog(0) && (eLog()<< Verbose(0) << "Could not parse filler molecule from " << params.fillername << "." << endl); 105 break; 106 } 68 ParserTypes type = FormatParserStorage::getInstance().getTypeFromSuffix(FilenameSuffix); 69 FormatParser &parser = FormatParserStorage::getInstance().get(type); 70 parser.load(&input); 107 71 108 72 // search the filler molecule that has been just parsed 109 molecule *filler = NULL; 110 for (World::MoleculeIterator iter = World::getInstance().getMoleculeIter(); 111 iter != World::getInstance().moleculeEnd(); 112 ++iter) 113 filler = *iter; // get last molecule 73 molecule *filler = World::getInstance().getMolecule(MoleculeByOrder(-1)); // get last molecule 114 74 filler->SetNameFromFilename(params.fillername.string().c_str()); 115 75 World::getInstance().getConfig()->BG->ConstructBondGraph(filler); -
src/Actions/MoleculeAction/FillWithMoleculeAction.cpp
r170ba6 r7a51be 23 23 #include "bondgraph.hpp" 24 24 #include "boundary.hpp" 25 #include "CodePatterns/Verbose.hpp" 25 26 #include "config.hpp" 27 #include "Descriptors/MoleculeIdDescriptor.hpp" 28 #include "Descriptors/MoleculeOrderDescriptor.hpp" 26 29 #include "molecule.hpp" 27 #include " CodePatterns/Verbose.hpp"30 #include "Parser/FormatParserStorage.hpp" 28 31 #include "World.hpp" 29 32 … … 53 56 << ", DoRotate " << params.DoRotate << "." << endl); 54 57 // construct water molecule 55 molecule *filler = World::getInstance().createMolecule(); 56 if (!filler->AddXYZFile(params.fillername.string())) { 57 DoeLog(0) && (eLog()<< Verbose(0) << "Could not parse filler molecule from " << params.fillername << "." << endl); 58 } 58 std::vector<molecule *> presentmolecules = World::getInstance().getAllMolecules(); 59 // DoLog(0) && (Log() << Verbose(0) << presentmolecules.size() << " molecules initially are present." << std::endl); 60 std::string FilenameSuffix = params.fillername.string().substr(params.fillername.string().find_last_of('.')+1, params.fillername.string().length()); 61 ifstream input; 62 input.open(params.fillername.string().c_str()); 63 ParserTypes type = FormatParserStorage::getInstance().getTypeFromSuffix(FilenameSuffix); 64 FormatParser &parser = FormatParserStorage::getInstance().get(type); 65 parser.load(&input); 66 67 // search the filler molecule that has been just parsed 68 molecule *filler = World::getInstance().getMolecule(MoleculeByOrder(-1)); // get last molecule 59 69 filler->SetNameFromFilename(params.fillername.string().c_str()); 60 molecule *Filling = NULL;61 // atom *first = NULL, *second = NULL, *third = NULL;62 // first = World::getInstance().createAtom();63 // first->type = World::getInstance().getPeriode()->FindElement(1);64 // first->x = Vector(0.441, -0.143, 0.);65 // filler->AddAtom(first);66 // second = World::getInstance().createAtom();67 // second->type = World::getInstance().getPeriode()->FindElement(1);68 // second->x = Vector(-0.464, 1.137, 0.0);69 // filler->AddAtom(second);70 // third = World::getInstance().createAtom();71 // third->type = World::getInstance().getPeriode()->FindElement(8);72 // third->x = Vector(-0.464, 0.177, 0.);73 // filler->AddAtom(third);74 // filler->AddBond(first, third, 1);75 // filler->AddBond(second, third, 1);76 70 World::getInstance().getConfig()->BG->ConstructBondGraph(filler); 77 // filler->SetNameFromFilename("water"); 71 // TODO: Remove the erasure of molecule when saving does not depend on them anymore. 72 World::getInstance().getMolecules()->erase(filler); // remove it, Parser adds it automatically 73 78 74 // call routine 79 75 double distance[NDIM]; 80 76 for (int i=0;i<NDIM;i++) 81 77 distance[i] = params.distances[i]; 82 Fill ing = FillBoxWithMolecule(78 FillBoxWithMolecule( 83 79 World::getInstance().getMolecules(), 84 80 filler, *(World::getInstance().getConfig()), … … 89 85 params.RandMoleculeDisplacement, 90 86 params.DoRotate); 91 if (Filling != NULL) {92 Filling->ActiveFlag = false;93 World::getInstance().getMolecules()->insert(Filling);94 }95 87 for (molecule::iterator iter = filler->begin(); !filler->empty(); iter = filler->begin()) { 96 88 atom *Walker = *iter; … … 100 92 World::getInstance().destroyMolecule(filler); 101 93 102 return Action::success; 94 // generate list of newly created molecules 95 // (we can in general remove more quickly from a list than a vector) 96 std::vector<molecule *> fillermolecules = World::getInstance().getAllMolecules(); 97 // DoLog(0) && (Log() << Verbose(0) << fillermolecules.size() << " molecules are present." << std::endl); 98 std::list<molecule *> fillermolecules_list; 99 std::copy( fillermolecules.begin(), fillermolecules.end(), std::back_inserter( fillermolecules_list )); 100 // DoLog(0) && (Log() << Verbose(0) << fillermolecules_list.size() << " molecules have been copied." << std::endl); 101 for (std::vector<molecule *>::const_iterator iter = presentmolecules.begin(); 102 iter != presentmolecules.end(); 103 ++iter) { 104 fillermolecules_list.remove(*iter); 105 } 106 // DoLog(0) && (Log() << Verbose(0) << fillermolecules_list.size() << " molecules left after removal." << std::endl); 107 fillermolecules.clear(); 108 std::copy(fillermolecules_list.begin(), fillermolecules_list.end(), std::back_inserter( fillermolecules )); 109 110 // DoLog(0) && (Log() << Verbose(0) << fillermolecules.size() << " molecules have been inserted." << std::endl); 111 112 return Action::state_ptr(new MoleculeFillWithMoleculeState(fillermolecules,params)); 103 113 } 104 114 105 115 Action::state_ptr MoleculeFillWithMoleculeAction::performUndo(Action::state_ptr _state) { 106 //MoleculeFillWithMoleculeState *state = assert_cast<MoleculeFillWithMoleculeState*>(_state.get());116 MoleculeFillWithMoleculeState *state = assert_cast<MoleculeFillWithMoleculeState*>(_state.get()); 107 117 108 // string newName = state->mol->getName(); 109 // state->mol->setName(state->lastName); 118 MoleculeListClass *MolList = World::getInstance().getMolecules(); 110 119 111 return Action::failure; 120 BOOST_FOREACH(molecule *_mol, state->fillermolecules) { 121 MolList->erase(_mol); 122 if ((_mol != NULL) && (!(World::getInstance().getAllMolecules(MoleculeById(_mol->getId()))).empty())) { 123 for(molecule::iterator iter = _mol->begin(); 124 !_mol->empty(); 125 iter = _mol->begin()) { 126 atom *Walker = *iter; 127 _mol->erase(iter); 128 World::getInstance().destroyAtom(Walker); 129 } 130 World::getInstance().destroyMolecule(_mol); 131 } 132 } 133 134 // as molecules and atoms from state are removed, we have to create a new one 135 std::vector<molecule *> fillermolecules; 136 return Action::state_ptr(new MoleculeFillWithMoleculeState(fillermolecules,state->params)); 112 137 } 113 138 114 139 Action::state_ptr MoleculeFillWithMoleculeAction::performRedo(Action::state_ptr _state){ 115 // Undo and redo have to do the same for this action 116 return performUndo(_state); 140 //MoleculeFillWithMoleculeState *state = assert_cast<MoleculeFillWithMoleculeState*>(_state.get()); 141 142 return Action::failure; 143 //return Action::state_ptr(_state); 117 144 } 118 145 119 146 bool MoleculeFillWithMoleculeAction::canUndo() { 120 return false;147 return true; 121 148 } 122 149 123 150 bool MoleculeFillWithMoleculeAction::shouldUndo() { 124 return false;151 return true; 125 152 } 126 153 /** =========== end of function ====================== */ -
src/Actions/MoleculeAction/FillWithMoleculeAction.def
r170ba6 r7a51be 19 19 #define paramreferences (fillername)(distances)(boundary)(RandAtomDisplacement)(RandMoleculeDisplacement)(MaxDistance)(DoRotate) 20 20 21 # undef statetypes22 # undef statereferences21 #define statetypes (std::vector<molecule *>) 22 #define statereferences (fillermolecules) 23 23 24 24 // some defines for all the names, you may use ACTION, STATE and PARAMS
Note:
See TracChangeset
for help on using the changeset viewer.