Ignore:
Timestamp:
Aug 28, 2010, 3:21:11 AM (15 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:
a6e6b5, f8982c
Parents:
2ad482 (diff), fd4905 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
git-author:
Frederik Heber <heber@…> (08/28/10 03:17:48)
git-committer:
Frederik Heber <heber@…> (08/28/10 03:21:11)
Message:

Merge branch 'StructureRefactoring' into Shapes

Conflicts:

src/Box.cpp
src/Box.hpp
src/Descriptors/AtomShapeDescriptor.cpp
src/Descriptors/AtomShapeDescriptor.hpp
src/Descriptors/AtomShapeDescriptor_impl.hpp
src/LinearAlgebra/Line.cpp
src/LinearAlgebra/Line.hpp
src/LinearAlgebra/Matrix.cpp
src/LinearAlgebra/Matrix.hpp
src/Makefile.am
src/Shapes/BaseShapes.cpp
src/Shapes/BaseShapes_impl.hpp
src/Shapes/Shape.cpp
src/Shapes/Shape.hpp
src/Shapes/ShapeOps_impl.hpp
src/Shapes/Shape_impl.hpp
src/unittests/ShapeUnittest.cpp

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Actions/FragmentationAction/SubgraphDissectionAction.cpp

    r2ad482 r6c438f  
     1/*
     2 * Project: MoleCuilder
     3 * Description: creates and alters molecular systems
     4 * Copyright (C)  2010 University of Bonn. All rights reserved.
     5 * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
     6 */
     7
    18/*
    29 * SubgraphDissectionAction.cpp
     
    613 */
    714
     15// include config.h
     16#ifdef HAVE_CONFIG_H
     17#include <config.h>
     18#endif
     19
    820#include "Helpers/MemDebug.hpp"
    921
    10 #include "Actions/FragmentationAction/SubgraphDissectionAction.hpp"
    11 #include "Actions/ActionRegistry.hpp"
     22#include "Descriptors/AtomIdDescriptor.hpp"
     23#include "Descriptors/MoleculeDescriptor.hpp"
     24
    1225#include "atom.hpp"
     26#include "bond.hpp"
     27#include "bondgraph.hpp"
    1328#include "config.hpp"
    14 #include "log.hpp"
     29#include "Helpers/Log.hpp"
     30#include "Helpers/Verbose.hpp"
    1531#include "molecule.hpp"
    16 #include "Descriptors/MoleculeDescriptor.hpp"
    1732#include "stackclass.hpp"
    1833#include "World.hpp"
     
    2136#include <string>
    2237
     38typedef std::map< moleculeId_t, std::vector<atomId_t> > MolAtomList;
     39typedef std::map< atomId_t, atomId_t > AtomAtomList;
     40
    2341using namespace std;
    2442
    25 #include "UIElements/UIFactory.hpp"
    26 #include "UIElements/Dialog.hpp"
    27 #include "UIElements/ValueStorage.hpp"
    28 
    29 const char FragmentationSubgraphDissectionAction::NAME[] = "subgraph-dissect";
    30 
    31 FragmentationSubgraphDissectionAction::FragmentationSubgraphDissectionAction() :
    32   Action(NAME)
    33 {}
    34 
    35 FragmentationSubgraphDissectionAction::~FragmentationSubgraphDissectionAction()
    36 {}
    37 
    38 void FragmentationSubgraphDissection() {
    39   ActionRegistry::getInstance().getActionByName(FragmentationSubgraphDissectionAction::NAME)->call(Action::NonInteractive);
    40 };
    41 
    42 Dialog* FragmentationSubgraphDissectionAction::createDialog() {
    43   Dialog *dialog = UIFactory::getInstance().makeDialog();
    44 
    45   dialog->queryEmpty(NAME, MapOfActions::getInstance().getDescription(NAME));
    46 
    47   return dialog;
    48 }
    49 
    50 
     43#include "Actions/FragmentationAction/SubgraphDissectionAction.hpp"
     44
     45// and construct the stuff
     46#include "SubgraphDissectionAction.def"
     47#include "Action_impl_pre.hpp"
     48/** =========== define the function ====================== */
    5149Action::state_ptr FragmentationSubgraphDissectionAction::performCall() {
     50  // obtain information
     51  getParametersfromValueStorage();
     52
    5253  DoLog(1) && (Log() << Verbose(1) << "Dissecting molecular system into a set of disconnected subgraphs ... " << endl);
    53   // @TODO rather do the dissection afterwards
     54
     55  // first create stuff for undo state
     56  MolAtomList moleculelist;
     57  vector<molecule *> allmolecules = World::getInstance().getAllMolecules();
     58  for (vector<molecule *>::const_iterator moliter = allmolecules.begin(); moliter != allmolecules.end(); ++moliter) {
     59    std::vector<atomId_t> atomlist;
     60    atomlist.resize((*moliter)->size());
     61    for (molecule::const_iterator atomiter = (*moliter)->begin(); atomiter != (*moliter)->end(); ++atomiter) {
     62      atomlist.push_back((*atomiter)->getId());
     63    }
     64    moleculelist.insert( std::pair< moleculeId_t, std::vector<atomId_t> > ((*moliter)->getId(), atomlist));
     65  }
     66  FragmentationSubgraphDissectionState *UndoState = new FragmentationSubgraphDissectionState(moleculelist, params);
     67
     68  // 0a. remove all present molecules
    5469  MoleculeListClass *molecules = World::getInstance().getMolecules();
    55   molecules->DissectMoleculeIntoConnectedSubgraphs(World::getInstance().getPeriode(), World::getInstance().getConfig());
    56   return Action::success;
     70  for (vector<molecule *>::iterator MolRunner = allmolecules.begin(); MolRunner != allmolecules.end(); ++MolRunner) {
     71    molecules->erase(*MolRunner);
     72    World::getInstance().destroyMolecule(*MolRunner);
     73  }
     74
     75  // 0b. remove all bonds and construct a molecule with all atoms
     76  molecule *mol = World::getInstance().createMolecule();
     77  int BondCount = 0;
     78  {
     79    vector <atom *> allatoms = World::getInstance().getAllAtoms();
     80    for(vector<atom *>::iterator AtomRunner = allatoms.begin(); AtomRunner != allatoms.end(); ++AtomRunner) {
     81      BondCount += (*AtomRunner)->ListOfBonds.size();
     82//      for(BondList::iterator BondRunner = (*AtomRunner)->ListOfBonds.begin(); !(*AtomRunner)->ListOfBonds.empty(); BondRunner = (*AtomRunner)->ListOfBonds.begin())
     83//        delete(*BondRunner);
     84      mol->AddAtom(*AtomRunner);
     85    }
     86  }
     87
     88  // 1. create the bond structure of the single molecule
     89  if (BondCount == 0) {
     90    config * const configuration = World::getInstance().getConfig();
     91    if ((configuration->BG != NULL)) {
     92      if (!configuration->BG->ConstructBondGraph(mol)) {
     93        World::getInstance().destroyMolecule(mol);
     94        DoeLog(1) && (eLog()<< Verbose(1) << "There are no bonds." << endl);
     95        return Action::failure;
     96      }
     97    } else {
     98      DoeLog(1) && (eLog()<< Verbose(1) << "There is no BondGraph class present to create bonds." << endl);
     99      return Action::failure;
     100    }
     101  }
     102
     103  // 2. scan for connected subgraphs
     104  MoleculeLeafClass *Subgraphs = NULL;      // list of subgraphs from DFS analysis
     105  class StackClass<bond *> *BackEdgeStack = NULL;
     106  Subgraphs = mol->DepthFirstSearchAnalysis(BackEdgeStack);
     107  delete(BackEdgeStack);
     108  if ((Subgraphs == NULL) || (Subgraphs->next == NULL)) {
     109    //World::getInstance().destroyMolecule(mol);
     110    DoeLog(1) && (eLog()<< Verbose(1) << "There are no atoms." << endl);
     111    return Action::failure;
     112  }
     113
     114  //int FragmentCounter = Subgraphs->next->Count();
     115
     116  // TODO: When DepthFirstSearchAnalysis does not use AddCopyAtom() anymore, we don't need to delete all original atoms
     117  {
     118    {
     119      atom **ListOfAtoms = NULL;
     120      // 3a. re-create bond structure and insert molecules into general MoleculeListClass
     121      MoleculeLeafClass *MoleculeWalker = Subgraphs->next;
     122      while (MoleculeWalker->next != NULL) {
     123        ListOfAtoms = NULL;
     124        MoleculeWalker->FillBondStructureFromReference(mol, ListOfAtoms, true);  // we want to keep the created ListOfLocalAtoms
     125        molecules->insert(MoleculeWalker->Leaf);
     126        MoleculeWalker = MoleculeWalker->next;
     127      }
     128      molecules->insert(MoleculeWalker->Leaf);
     129      ListOfAtoms = NULL;
     130      MoleculeWalker->FillBondStructureFromReference(mol, ListOfAtoms, true);  // we want to keep the created ListOfLocalAtoms
     131    }
     132
     133    // 3b. store map from new to old ids for 3d
     134    vector <atom *> allatoms = World::getInstance().getAllAtoms();
     135    AtomAtomList newtooldlist;
     136    for(vector<atom *>::iterator AtomRunner = allatoms.begin(); AtomRunner != allatoms.end(); ++AtomRunner)
     137      if ((*AtomRunner)->father != (*AtomRunner))
     138        newtooldlist.insert( std::pair<atomId_t, atomId_t> ((*AtomRunner)->getId(),(*AtomRunner)->father->getId()) );
     139
     140    {
     141      // 3c. destroy the original molecule
     142      for (molecule::iterator AtomRunner = mol->begin(); !mol->empty(); AtomRunner = mol->begin())
     143        World::getInstance().destroyAtom(*AtomRunner);
     144      World::getInstance().destroyMolecule(mol);
     145    }
     146
     147    {
     148      // 3d. convert to old Ids and correct fathers (AddCopyAtom sets father to original atom, which has been destroyed).
     149      vector <atom *> allatoms = World::getInstance().getAllAtoms();
     150      for(vector<atom *>::iterator AtomRunner = allatoms.begin(); AtomRunner != allatoms.end(); ++AtomRunner) {
     151        World::getInstance().changeAtomId((*AtomRunner)->getId(), newtooldlist[(*AtomRunner)->getId()]);
     152        (*AtomRunner)->father = *AtomRunner;
     153      }
     154    }
     155  }
     156
     157  // 4. free Leafs
     158  MoleculeLeafClass *MolecularWalker = Subgraphs;
     159  while (MolecularWalker->next != NULL) {
     160    MolecularWalker->Leaf = NULL;
     161    MolecularWalker = MolecularWalker->next;
     162    delete(MolecularWalker->previous);
     163  }
     164  MolecularWalker->Leaf = NULL;
     165  delete(MolecularWalker);
     166  DoLog(1) && (Log() << Verbose(1) << "I scanned " << molecules->ListOfMolecules.size() << " molecules." << endl);
     167
     168  return Action::state_ptr(UndoState);
    57169}
    58170
    59171Action::state_ptr FragmentationSubgraphDissectionAction::performUndo(Action::state_ptr _state) {
    60 //  ParserLoadXyzState *state = assert_cast<ParserLoadXyzState*>(_state.get());
    61 
    62   return Action::failure;
    63 //  string newName = state->mol->getName();
    64 //  state->mol->setName(state->lastName);
    65 //
    66 //  return Action::state_ptr(new ParserLoadXyzState(state->mol,newName));
     172  FragmentationSubgraphDissectionState *state = assert_cast<FragmentationSubgraphDissectionState*>(_state.get());
     173
     174  {
     175    // remove all present molecules
     176    MoleculeListClass *molecules = World::getInstance().getMolecules();
     177    vector<molecule *> allmolecules = World::getInstance().getAllMolecules();
     178    for (vector<molecule *>::iterator MolRunner = allmolecules.begin(); MolRunner != allmolecules.end(); ++MolRunner) {
     179      molecules->erase(*MolRunner);
     180      World::getInstance().destroyMolecule(*MolRunner);
     181    }
     182  }
     183
     184  {
     185    // construct the old state
     186    MoleculeListClass *molecules = World::getInstance().getMolecules();
     187    molecule *mol = NULL;
     188    for (MolAtomList::const_iterator iter = state->moleculelist.begin(); iter != state->moleculelist.end(); ++iter) {
     189      mol = World::getInstance().createMolecule();
     190      if (mol->getId() != (*iter).first)
     191        World::getInstance().changeMoleculeId(mol->getId(), (*iter).first);
     192      for (std::vector<atomId_t>::const_iterator atomiter = (*iter).second.begin(); atomiter != (*iter).second.end(); ++atomiter) {
     193        atom *Walker = World::getInstance().getAtom(AtomById(*atomiter));
     194        mol->AddAtom(Walker);
     195      }
     196      molecules->insert(mol);
     197    }
     198  }
     199
     200  return Action::state_ptr(_state);
    67201}
    68202
    69203Action::state_ptr FragmentationSubgraphDissectionAction::performRedo(Action::state_ptr _state){
    70   return Action::failure;
     204  return performCall();
    71205}
    72206
    73207bool FragmentationSubgraphDissectionAction::canUndo() {
    74   return false;
     208  return true;
    75209}
    76210
    77211bool FragmentationSubgraphDissectionAction::shouldUndo() {
    78   return false;
     212  return true;
    79213}
    80214
     
    82216  return NAME;
    83217}
     218/** =========== end of function ====================== */
Note: See TracChangeset for help on using the changeset viewer.