source: src/Actions/FragmentationAction/SubgraphDissectionAction.cpp@ 8f4df1

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
Last change on this file since 8f4df1 was 8f4df1, checked in by Frederik Heber <heber@…>, 14 years ago

Merge branch 'AtomicPositionEncapsulation' into stable

Conflicts:

src/Actions/AtomAction/ChangeElementAction.cpp
src/Actions/WorldAction/RemoveSphereOfAtomsAction.cpp
src/Makefile.am
src/UIElements/TextUI/TextDialog.cpp
src/analysis_correlation.hpp
src/atom.cpp
src/atom_atominfo.hpp
src/bond.cpp
src/boundary.cpp
src/molecule_geometry.cpp
src/tesselation.cpp
src/tesselationhelpers.cpp
src/triangleintersectionlist.cpp
src/unittests/Makefile.am

  • fixed #includes due to moves to Helpers and LinearAlgebra
  • moved VectorInterface.* and vector_ops.* to LinearAlgebra
  • no more direct access of atom::node, remapped to set/getPosition()
  • no more direct access to atom::type, remapped to set/getType() (also in atom due to derivation and atominfo::AtomicElement is private not protected).
  • Property mode set to 100644
File size: 6.9 KB
Line 
1/*
2 * SubgraphDissectionAction.cpp
3 *
4 * Created on: May 9, 2010
5 * Author: heber
6 */
7
8#include "Helpers/MemDebug.hpp"
9
10#include "Actions/FragmentationAction/SubgraphDissectionAction.hpp"
11#include "Actions/ActionRegistry.hpp"
12#include "Descriptors/MoleculeDescriptor.hpp"
13
14#include "atom.hpp"
15#include "bond.hpp"
16#include "bondgraph.hpp"
17#include "config.hpp"
18#include "Helpers/Log.hpp"
19#include "molecule.hpp"
20#include "stackclass.hpp"
21#include "World.hpp"
22
23#include <iostream>
24#include <string>
25
26using namespace std;
27
28#include "UIElements/UIFactory.hpp"
29#include "UIElements/Dialog.hpp"
30#include "Actions/ValueStorage.hpp"
31
32const char FragmentationSubgraphDissectionAction::NAME[] = "subgraph-dissect";
33
34FragmentationSubgraphDissectionAction::FragmentationSubgraphDissectionAction() :
35 Action(NAME)
36{}
37
38FragmentationSubgraphDissectionAction::~FragmentationSubgraphDissectionAction()
39{}
40
41void FragmentationSubgraphDissection() {
42 ActionRegistry::getInstance().getActionByName(FragmentationSubgraphDissectionAction::NAME)->call(Action::NonInteractive);
43};
44
45Dialog* FragmentationSubgraphDissectionAction::fillDialog(Dialog *dialog) {
46 ASSERT(dialog,"No Dialog given when filling action dialog");
47
48 dialog->queryEmpty(NAME, MapOfActions::getInstance().getDescription(NAME));
49
50 return dialog;
51}
52
53
54Action::state_ptr FragmentationSubgraphDissectionAction::performCall() {
55 DoLog(1) && (Log() << Verbose(1) << "Dissecting molecular system into a set of disconnected subgraphs ... " << endl);
56 // @TODO rather do the dissection afterwards
57 MoleculeListClass *molecules = World::getInstance().getMolecules();
58 config * const configuration = World::getInstance().getConfig();
59
60 // 0a. remove all present molecules
61 vector<molecule *> allmolecules = World::getInstance().getAllMolecules();
62 for (vector<molecule *>::iterator MolRunner = allmolecules.begin(); MolRunner != allmolecules.end(); ++MolRunner) {
63 molecules->erase(*MolRunner);
64 World::getInstance().destroyMolecule(*MolRunner);
65 }
66
67 // 0b. remove all bonds and construct a molecule with all atoms
68 molecule *mol = World::getInstance().createMolecule();
69 vector <atom *> allatoms = World::getInstance().getAllAtoms();
70 for(vector<atom *>::iterator AtomRunner = allatoms.begin(); AtomRunner != allatoms.end(); ++AtomRunner) {
71 for(BondList::iterator BondRunner = (*AtomRunner)->ListOfBonds.begin(); !(*AtomRunner)->ListOfBonds.empty(); BondRunner = (*AtomRunner)->ListOfBonds.begin())
72 delete(*BondRunner);
73 mol->AddAtom(*AtomRunner);
74 }
75
76 // 1. create the bond structure of the single molecule
77 if (configuration->BG != NULL) {
78 if (!configuration->BG->ConstructBondGraph(mol)) {
79 World::getInstance().destroyMolecule(mol);
80 DoeLog(1) && (eLog()<< Verbose(1) << "There are no bonds." << endl);
81 return Action::failure;
82 }
83 } else {
84 DoeLog(1) && (eLog()<< Verbose(1) << "There is no BondGraph class present to create bonds." << endl);
85 return Action::failure;
86 }
87
88 // 2. scan for connected subgraphs
89 MoleculeLeafClass *Subgraphs = NULL; // list of subgraphs from DFS analysis
90 class StackClass<bond *> *BackEdgeStack = NULL;
91 Subgraphs = mol->DepthFirstSearchAnalysis(BackEdgeStack);
92 delete(BackEdgeStack);
93 if ((Subgraphs == NULL) || (Subgraphs->next == NULL)) {
94 World::getInstance().destroyMolecule(mol);
95 DoeLog(1) && (eLog()<< Verbose(1) << "There are no atoms." << endl);
96 return Action::failure;
97 }
98
99 // 3. dissect (the following construct is needed to have the atoms not in the order of the DFS, but in
100 // the original one as parsed in)
101 // TODO: Optimize this, when molecules just contain pointer list of global atoms!
102
103 // 4a. create array of molecules to fill
104 const int MolCount = Subgraphs->next->Count();
105 char number[MAXSTRINGSIZE];
106 molecule **moleculelist = new molecule *[MolCount];
107 MoleculeLeafClass *MolecularWalker = Subgraphs;
108 for (int i=0;i<MolCount;i++) {
109 MolecularWalker = MolecularWalker->next;
110 moleculelist[i] = World::getInstance().createMolecule();
111 moleculelist[i]->ActiveFlag = true;
112 strncpy(moleculelist[i]->name, mol->name, MAXSTRINGSIZE);
113 if (MolCount > 1) {
114 sprintf(number, "-%d", i+1);
115 strncat(moleculelist[i]->name, number, MAXSTRINGSIZE - strlen(mol->name) - 1);
116 }
117 DoLog(1) && (Log() << Verbose(1) << "MolName is " << moleculelist[i]->name << ", id is " << moleculelist[i]->getId() << endl);
118 for (molecule::iterator iter = MolecularWalker->Leaf->begin(); iter != MolecularWalker->Leaf->end(); ++iter) {
119 DoLog(1) && (Log() << Verbose(1) << **iter << endl);
120 }
121 molecules->insert(moleculelist[i]);
122 }
123
124 // 4b. create and fill map of which atom is associated to which connected molecule (note, counting starts at 1)
125 int FragmentCounter = 0;
126 map<int, atom *> AtomToFragmentMap;
127 MolecularWalker = Subgraphs;
128 while (MolecularWalker->next != NULL) {
129 MolecularWalker = MolecularWalker->next;
130 for (molecule::iterator iter = MolecularWalker->Leaf->begin(); !MolecularWalker->Leaf->empty(); iter = MolecularWalker->Leaf->begin()) {
131 atom * Walker = *iter;
132 DoLog(1) && (Log() << Verbose(1) << "Re-linking " << Walker << "..." << endl);
133 MolecularWalker->Leaf->erase(iter);
134 moleculelist[FragmentCounter]->AddAtom(Walker); // counting starts at 1
135 }
136 FragmentCounter++;
137 }
138 // TODO: When DepthFirstSearchAnalysis does not use AddCopyAtom() anymore, we don't need to delete all original atoms.
139 // 4d. destroy the original molecule
140 for (molecule::iterator AtomRunner = mol->begin(); !mol->empty(); AtomRunner = mol->begin())
141 World::getInstance().destroyAtom(*AtomRunner);
142 World::getInstance().destroyMolecule(mol);
143
144 // 4d. we don't need to redo bonds, as they are connected subgraphs and still maintain their ListOfBonds, but we have to remove them from first..last list
145 // TODO: check whether this is really not needed anymore
146 // 4e. free Leafs
147 MolecularWalker = Subgraphs;
148 while (MolecularWalker->next != NULL) {
149 MolecularWalker = MolecularWalker->next;
150 delete(MolecularWalker->previous);
151 }
152 delete(MolecularWalker);
153 delete[](moleculelist);
154 DoLog(1) && (Log() << Verbose(1) << "I scanned " << FragmentCounter << " molecules." << endl);
155
156 return Action::success;
157}
158
159Action::state_ptr FragmentationSubgraphDissectionAction::performUndo(Action::state_ptr _state) {
160// ParserLoadXyzState *state = assert_cast<ParserLoadXyzState*>(_state.get());
161
162 return Action::failure;
163// string newName = state->mol->getName();
164// state->mol->setName(state->lastName);
165//
166// return Action::state_ptr(new ParserLoadXyzState(state->mol,newName));
167}
168
169Action::state_ptr FragmentationSubgraphDissectionAction::performRedo(Action::state_ptr _state){
170 return Action::failure;
171}
172
173bool FragmentationSubgraphDissectionAction::canUndo() {
174 return false;
175}
176
177bool FragmentationSubgraphDissectionAction::shouldUndo() {
178 return false;
179}
180
181const string FragmentationSubgraphDissectionAction::getName() {
182 return NAME;
183}
Note: See TracBrowser for help on using the repository browser.