Ignore:
Timestamp:
Aug 28, 2010, 1:45:13 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:
6c438f
Parents:
8fd934 (diff), 653542 (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.
Message:

Merge branch 'stable' into StructureRefactoring

File:
1 edited

Legend:

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

    r8fd934 rfd4905  
    2020#include "Helpers/MemDebug.hpp"
    2121
    22 #include "Actions/FragmentationAction/SubgraphDissectionAction.hpp"
    23 #include "Actions/ActionRegistry.hpp"
    2422#include "Descriptors/AtomIdDescriptor.hpp"
    2523#include "Descriptors/MoleculeDescriptor.hpp"
     
    3836#include <string>
    3937
     38typedef std::map< moleculeId_t, std::vector<atomId_t> > MolAtomList;
     39typedef std::map< atomId_t, atomId_t > AtomAtomList;
     40
    4041using namespace std;
    4142
    42 #include "UIElements/UIFactory.hpp"
    43 #include "UIElements/Dialog.hpp"
    44 #include "Actions/ValueStorage.hpp"
    45 
    46 // memento to remember the state when undoing
    47 
    48 typedef std::map< moleculeId_t, std::vector<atomId_t> > MolAtomList;
    49 
    50 class FragmentationSubgraphDissectionState : public ActionState {
    51 public:
    52   FragmentationSubgraphDissectionState(const MolAtomList &_moleculelist) :
    53    moleculelist(_moleculelist)
    54   {}
    55   MolAtomList moleculelist;
    56 };
    57 
    58 const char FragmentationSubgraphDissectionAction::NAME[] = "subgraph-dissect";
    59 
    60 FragmentationSubgraphDissectionAction::FragmentationSubgraphDissectionAction() :
    61   Action(NAME)
    62 {}
    63 
    64 FragmentationSubgraphDissectionAction::~FragmentationSubgraphDissectionAction()
    65 {}
    66 
    67 /** Dissects given \a *mol into connected subgraphs and inserts them as new molecules but with old atoms into \a this.
    68  */
    69 void FragmentationSubgraphDissection() {
    70   ActionRegistry::getInstance().getActionByName(FragmentationSubgraphDissectionAction::NAME)->call(Action::NonInteractive);
    71 };
    72 
    73 Dialog* FragmentationSubgraphDissectionAction::fillDialog(Dialog *dialog) {
    74   ASSERT(dialog,"No Dialog given when filling action dialog");
    75 
    76   dialog->queryEmpty(NAME, MapOfActions::getInstance().getDescription(NAME));
    77 
    78   return dialog;
    79 }
    80 
    81 
     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 ====================== */
    8249Action::state_ptr FragmentationSubgraphDissectionAction::performCall() {
     50  // obtain information
     51  getParametersfromValueStorage();
     52
    8353  DoLog(1) && (Log() << Verbose(1) << "Dissecting molecular system into a set of disconnected subgraphs ... " << endl);
    8454
    85   // first create undo state
     55  // first create stuff for undo state
    8656  MolAtomList moleculelist;
    8757  vector<molecule *> allmolecules = World::getInstance().getAllMolecules();
     
    9464    moleculelist.insert( std::pair< moleculeId_t, std::vector<atomId_t> > ((*moliter)->getId(), atomlist));
    9565  }
    96   FragmentationSubgraphDissectionState *UndoState = new FragmentationSubgraphDissectionState(moleculelist);
    97 
     66  FragmentationSubgraphDissectionState *UndoState = new FragmentationSubgraphDissectionState(moleculelist, params);
     67
     68  // 0a. remove all present molecules
    9869  MoleculeListClass *molecules = World::getInstance().getMolecules();
    99   config * const configuration = World::getInstance().getConfig();
    100 
    101   // 0a. remove all present molecules
    10270  for (vector<molecule *>::iterator MolRunner = allmolecules.begin(); MolRunner != allmolecules.end(); ++MolRunner) {
    10371    molecules->erase(*MolRunner);
     
    10775  // 0b. remove all bonds and construct a molecule with all atoms
    10876  molecule *mol = World::getInstance().createMolecule();
     77  int BondCount = 0;
    10978  {
    11079    vector <atom *> allatoms = World::getInstance().getAllAtoms();
    11180    for(vector<atom *>::iterator AtomRunner = allatoms.begin(); AtomRunner != allatoms.end(); ++AtomRunner) {
    112       for(BondList::iterator BondRunner = (*AtomRunner)->ListOfBonds.begin(); !(*AtomRunner)->ListOfBonds.empty(); BondRunner = (*AtomRunner)->ListOfBonds.begin())
    113         delete(*BondRunner);
     81      BondCount += (*AtomRunner)->ListOfBonds.size();
     82//      for(BondList::iterator BondRunner = (*AtomRunner)->ListOfBonds.begin(); !(*AtomRunner)->ListOfBonds.empty(); BondRunner = (*AtomRunner)->ListOfBonds.begin())
     83//        delete(*BondRunner);
    11484      mol->AddAtom(*AtomRunner);
    11585    }
     
    11787
    11888  // 1. create the bond structure of the single molecule
    119   if (configuration->BG != NULL) {
    120     if (!configuration->BG->ConstructBondGraph(mol)) {
    121       World::getInstance().destroyMolecule(mol);
    122       DoeLog(1) && (eLog()<< Verbose(1) << "There are no bonds." << endl);
     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);
    12399      return Action::failure;
    124100    }
    125   } else {
    126     DoeLog(1) && (eLog()<< Verbose(1) << "There is no BondGraph class present to create bonds." << endl);
    127     return Action::failure;
    128101  }
    129102
     
    138111    return Action::failure;
    139112  }
    140   int FragmentCounter = Subgraphs->next->Count();
     113
     114  //int FragmentCounter = Subgraphs->next->Count();
    141115
    142116  // TODO: When DepthFirstSearchAnalysis does not use AddCopyAtom() anymore, we don't need to delete all original atoms
    143117  {
    144     // 3a. destroy the original molecule
    145     for (molecule::iterator AtomRunner = mol->begin(); !mol->empty(); AtomRunner = mol->begin())
    146       World::getInstance().destroyAtom(*AtomRunner);
    147     World::getInstance().destroyMolecule(mol);
    148     // 3b. correct fathers (AddCopyAtom sets father to original atom, which has been destroyed).
     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
    149134    vector <atom *> allatoms = World::getInstance().getAllAtoms();
    150     for(vector<atom *>::iterator AtomRunner = allatoms.begin(); AtomRunner != allatoms.end(); ++AtomRunner) {
    151       (*AtomRunner)->father = *AtomRunner;
     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      }
    152154    }
    153155  }
     
    162164  MolecularWalker->Leaf = NULL;
    163165  delete(MolecularWalker);
    164   DoLog(1) && (Log() << Verbose(1) << "I scanned " << FragmentCounter << " molecules." << endl);
     166  DoLog(1) && (Log() << Verbose(1) << "I scanned " << molecules->ListOfMolecules.size() << " molecules." << endl);
    165167
    166168  return Action::state_ptr(UndoState);
     
    182184  {
    183185    // construct the old state
     186    MoleculeListClass *molecules = World::getInstance().getMolecules();
    184187    molecule *mol = NULL;
    185188    for (MolAtomList::const_iterator iter = state->moleculelist.begin(); iter != state->moleculelist.end(); ++iter) {
     
    187190      if (mol->getId() != (*iter).first)
    188191        World::getInstance().changeMoleculeId(mol->getId(), (*iter).first);
    189       for (std::vector<atomId_t>::const_iterator atomiter = (*iter).second.begin(); atomiter != (*iter).second.end(); ++atomiter)
    190         mol->AddAtom(World::getInstance().getAtom(AtomById(*atomiter)));
     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);
    191197    }
    192198  }
     
    210216  return NAME;
    211217}
     218/** =========== end of function ====================== */
Note: See TracChangeset for help on using the changeset viewer.