source: src/Actions/FragmentationAction/FragmentationAction.cpp@ f92ef3

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 f92ef3 was 474c62, checked in by Frederik Heber <heber@…>, 11 years ago

FIX: Typo in FragmentationAction.

  • Property mode set to 100644
File size: 9.1 KB
RevLine 
[bcf653]1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
[0aa122]4 * Copyright (C) 2010-2012 University of Bonn. All rights reserved.
[5aaa43]5 * Copyright (C) 2013 Frederik Heber. All rights reserved.
[94d5ac6]6 *
7 *
8 * This file is part of MoleCuilder.
9 *
10 * MoleCuilder is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation, either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * MoleCuilder is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with MoleCuilder. If not, see <http://www.gnu.org/licenses/>.
[bcf653]22 */
23
[97ebf8]24/*
25 * FragmentationAction.cpp
26 *
27 * Created on: May 9, 2010
28 * Author: heber
29 */
30
[bf3817]31// include config.h
32#ifdef HAVE_CONFIG_H
33#include <config.h>
34#endif
35
[ad011c]36#include "CodePatterns/MemDebug.hpp"
[112b09]37
[6f0841]38#include "Atom/atom.hpp"
[c7c615]39#include "CodePatterns/IteratorAdaptors.hpp"
[ad011c]40#include "CodePatterns/Log.hpp"
[79d0b9]41#include "Descriptors/AtomSelectionDescriptor.hpp"
[ca8bea]42#include "Fragmentation/Exporters/ExportGraph_ToFiles.hpp"
[ac9ca4]43#ifdef HAVE_JOBMARKET
44#include "Fragmentation/Exporters/ExportGraph_ToJobs.hpp"
45#endif
[246e13]46#include "Fragmentation/Fragmentation.hpp"
[b4f72c]47#include "Fragmentation/Graph.hpp"
[07a47e]48#include "Fragmentation/HydrogenSaturation_enum.hpp"
[13c5c1]49#include "Fragmentation/Interfragmenter.hpp"
[0fad93]50#include "Graph/AdjacencyList.hpp"
[79d0b9]51#include "Graph/BondGraph.hpp"
[49c059]52#include "Graph/DepthFirstSearchAnalysis.hpp"
[9511c7]53#include "Helpers/defs.hpp"
[97ebf8]54#include "molecule.hpp"
55#include "World.hpp"
56
[c7c615]57#include <boost/shared_ptr.hpp>
[3aa8a5]58#include <boost/filesystem.hpp>
[c7c615]59#include <algorithm>
[97ebf8]60#include <iostream>
[2a0eb0]61#include <map>
[97ebf8]62#include <string>
[2a0eb0]63#include <vector>
[97ebf8]64
[1fd675]65#include "Actions/FragmentationAction/FragmentationAction.hpp"
[70d9b9]66
[ce7fdc]67using namespace MoleCuilder;
68
[1fd675]69// and construct the stuff
70#include "FragmentationAction.def"
71#include "Action_impl_pre.hpp"
72/** =========== define the function ====================== */
[70d9b9]73Action::state_ptr FragmentationFragmentationAction::performCall() {
[e4b5de]74 clock_t start,end;
[2a0eb0]75 int ExitFlag = -1;
76 World &world = World::getInstance();
[e4b5de]77
[2a0eb0]78 // inform about used parameters
[13c5c1]79 LOG(0, "STATUS: Fragmenting molecular system with current connection matrix up to "
[bae7bc]80 << params.order.get() << " order. ");
81 if (params.types.get().size() != 0)
82 LOG(0, "STATUS: Fragment files begin with "
83 << params.prefix.get() << " and are stored as: "
84 << params.types.get() << "." << std::endl);
[99b0dc]85
[2a0eb0]86 // check for selected atoms
87 if (world.beginAtomSelection() == world.endAtomSelection()) {
[474c62]88 ELOG(1, "There are no atoms selected for fragmentation.");
[2a0eb0]89 return Action::failure;
90 }
91
92 // go through all atoms, note down their molecules and group them
93 typedef std::multimap<molecule *, atom *> clusters_t;
[3aa8a5]94 typedef std::vector<atomId_t> atomids_t;
95 atomids_t atomids;
[2a0eb0]96 clusters_t clusters;
97 for (World::AtomSelectionConstIterator iter = world.beginAtomSelection();
98 iter != world.endAtomSelection(); ++iter) {
99 clusters.insert( std::make_pair(iter->second->getMolecule(), iter->second) );
[3aa8a5]100 atomids.push_back(iter->second->getId());
[2a0eb0]101 }
[c7c615]102 {
103 std::vector<molecule *> molecules;
104 molecules.insert( molecules.end(), MapKeyIterator<clusters_t::const_iterator>(clusters.begin()),
105 MapKeyIterator<clusters_t::const_iterator>(clusters.end()) );
106 molecules.erase( std::unique(molecules.begin(), molecules.end()), molecules.end() );
107 LOG(1, "INFO: There are " << molecules.size() << " molecules to consider.");
108 }
[2a0eb0]109
[9511c7]110 // parse in Adjacency file
[3aa8a5]111 boost::shared_ptr<AdjacencyList> FileChecker;
112 boost::filesystem::path filename(params.prefix.get() + std::string(ADJACENCYFILE));
113 if (boost::filesystem::exists(filename) && boost::filesystem::is_regular_file(filename)) {
114 std::ifstream File;
115 File.open(filename.string().c_str(), ios::out);
116 FileChecker.reset(new AdjacencyList(File));
117 File.close();
118 } else {
119 LOG(1, "INFO: Could not open default adjacency file " << filename.string() << ".");
120 FileChecker.reset(new AdjacencyList);
121 }
[9511c7]122
[79d0b9]123 // make sure bond degree is correct
124 {
125 BondGraph *BG = World::getInstance().getBondGraph();
126 World::AtomComposite Set = World::getInstance().getAllAtoms(AtomsBySelection());
127 BG->CorrectBondDegree(Set);
128 }
129
[bfbd4a]130 // we require the current bond graph
[49c059]131 DepthFirstSearchAnalysis DFS;
[bfbd4a]132
133 // we parse in the keysets from last time if present
134 Graph StoredGraph;
135 StoredGraph.ParseKeySetFile(params.prefix.get());
136
[2a0eb0]137 start = clock();
138 // go through all keys (i.e. all molecules)
139 clusters_t::const_iterator advanceiter;
[b4f72c]140 Graph TotalGraph;
141 int keysetcounter = 0;
[2a0eb0]142 for (clusters_t::const_iterator iter = clusters.begin();
143 iter != clusters.end();
144 iter = advanceiter) {
145 // get iterator to past last atom in this molecule
146 molecule * mol = iter->first;
147 advanceiter = clusters.upper_bound(mol);
148
149 // copy molecule's atoms' ids as parameters to Fragmentation's AtomMask
150 std::vector<atomId_t> mols_atomids;
151 std::transform(iter, advanceiter, std::back_inserter(mols_atomids),
152 boost::bind( &atom::getNr,
153 boost::bind( &clusters_t::value_type::second, _1 ))
154 );
155 LOG(2, "INFO: Fragmenting in molecule " << mol->getName() << " in " << clusters.count(mol)
156 << " atoms, out of " << mol->getAtomCount() << ".");
[9291d04]157 const enum HydrogenTreatment treatment = params.HowtoTreatHydrogen.get() ? ExcludeHydrogen : IncludeHydrogen;
158 Fragmentation Fragmenter(mol, *FileChecker, treatment);
[2a0eb0]159
160 // perform fragmentation
161 LOG(0, std::endl << " ========== Fragmentation of molecule " << mol->getName() << " ========================= ");
162 {
[bfbd4a]163 Graph StoredLocalGraph(StoredGraph.getLocalGraph(mol));
164 const int tempFlag = Fragmenter.FragmentMolecule(mols_atomids, params.order.get(), params.prefix.get(), DFS, StoredLocalGraph);
[2a0eb0]165 if ((ExitFlag == 2) && (tempFlag != 2))
166 ExitFlag = tempFlag; // if there is one molecule that needs further fragmentation, it overrides others
167 if (ExitFlag == -1)
168 ExitFlag = tempFlag; // if we are the first, we set the standard
[e4b5de]169 }
[569e42]170 if (TotalGraph.empty()) {
171 TotalGraph = Fragmenter.getGraph();
172 keysetcounter = TotalGraph.size();
173 } else
174 TotalGraph.InsertGraph(Fragmenter.getGraph(), keysetcounter);
[ca8bea]175
[97ebf8]176 }
[569e42]177 LOG(0, "STATUS: There are " << TotalGraph.size() << " fragments.");
[3aa8a5]178
[321470]179 {
180 // remove OrderAtSite file
181 std::string line;
182 std::ofstream file;
183 line = params.prefix.get() + ORDERATSITEFILE;
184 file.open(line.c_str(), std::ofstream::out | std::ofstream::trunc);
185 file << "";
186 file.close();
187 }
188
[13c5c1]189 // now add interfragments
190 if (params.InterOrder.get() != 0) {
191 LOG(0, "STATUS: Putting fragments together up to order "
192 << params.InterOrder.get() << " and distance of "
193 << params.distance.get() << ".");
194 Interfragmenter fragmenter(TotalGraph);
195 const enum HydrogenTreatment treatment = params.HowtoTreatHydrogen.get() ? ExcludeHydrogen : IncludeHydrogen;
196 fragmenter(params.InterOrder.get(), params.distance.get(), treatment);
197 LOG(0, "STATUS: There are now " << TotalGraph.size() << " fragments after interfragmenting.");
198 }
199
[bfbd4a]200 // store keysets to file
201 {
202 TotalGraph.StoreKeySetFile(params.prefix.get());
203 }
204
[3aa8a5]205 {
[9291d04]206 const enum HydrogenSaturation saturation = params.DoSaturation.get() ? DoSaturate : DontSaturate;
[276ac6]207 const enum HydrogenTreatment treatment = params.HowtoTreatHydrogen.get() ? ExcludeHydrogen : IncludeHydrogen;
[ac9ca4]208 if (params.types.get().size() != 0) {
209 // store molecule's fragment to file
210 ExportGraph_ToFiles exporter(TotalGraph, treatment, saturation);
211 exporter.setPrefix(params.prefix.get());
212 exporter.setOutputTypes(params.types.get());
213 exporter();
214 } else {
215#ifdef HAVE_JOBMARKET
216 // store molecule's fragment in FragmentJobQueue
217 ExportGraph_ToJobs exporter(TotalGraph, treatment, saturation);
218 exporter.setLevel(params.level.get());
219 exporter();
220#else
221 ELOG(1, "No output file types specified and JobMarket support is not compiled in.");
222 return Action::failure;
223#endif
224 }
[3aa8a5]225 }
226
227 // store Adjacency to file
228 {
229 std::string filename = params.prefix.get() + ADJACENCYFILE;
230 std::ofstream AdjacencyFile;
231 AdjacencyFile.open(filename.c_str(), ios::out);
232 AdjacencyList adjacency(atomids);
233 adjacency.StoreToFile(AdjacencyFile);
234 AdjacencyFile.close();
235 }
236
[2a0eb0]237 World::getInstance().setExitFlag(ExitFlag);
238 end = clock();
239 LOG(0, "STATUS: Clocks for this operation: " << (end-start) << ", time: " << ((double)(end-start)/CLOCKS_PER_SEC) << "s.");
240
[70d9b9]241 return Action::success;
[97ebf8]242}
243
244Action::state_ptr FragmentationFragmentationAction::performUndo(Action::state_ptr _state) {
[70d9b9]245 return Action::success;
[97ebf8]246}
247
248Action::state_ptr FragmentationFragmentationAction::performRedo(Action::state_ptr _state){
[70d9b9]249 return Action::success;
[97ebf8]250}
251
252bool FragmentationFragmentationAction::canUndo() {
[70d9b9]253 return true;
[97ebf8]254}
255
256bool FragmentationFragmentationAction::shouldUndo() {
[70d9b9]257 return true;
[97ebf8]258}
[1fd675]259/** =========== end of function ====================== */
Note: See TracBrowser for help on using the repository browser.