source: src/UIElements/Views/Qt4/QtHomologyList.cpp@ 5c8807

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 5c8807 was 9bdcc9, checked in by Frederik Heber <heber@…>, 11 years ago

FIX: QtHomologyList lacked use of FunctionModel::filter_t to split up arguments.

  • we need to split up the vector of arguments into lists of argument tuples that each potential can digest. And these tuples are different per potential.
  • Property mode set to 100644
File size: 10.1 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2013 Frederik Heber. All rights reserved.
5 *
6 *
7 * This file is part of MoleCuilder.
8 *
9 * MoleCuilder is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation, either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * MoleCuilder is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with MoleCuilder. If not, see <http://www.gnu.org/licenses/>.
21 */
22
23/*
24 * QtHomologyList.cpp
25 *
26 * Created on: Jun 24, 2013
27 * Author: heber
28 */
29
30// include config.h
31#ifdef HAVE_CONFIG_H
32#include <config.h>
33#endif
34
35#include "Views/Qt4/QtHomologyList.hpp"
36
37#include <iterator>
38#include <iostream>
39
40#include <QAbstractItemView>
41#include <QtGui/QTreeWidget>
42#include <QtGui/QTabWidget>
43#include <Qt/qsplitter.h>
44#include <Qt/qboxlayout.h>
45
46#include "CodePatterns/MemDebug.hpp"
47
48#include "CodePatterns/Log.hpp"
49
50#include "Fragmentation/Homology/HomologyContainer.hpp"
51#include "FunctionApproximation/FunctionModel.hpp"
52#include "FunctionApproximation/TrainingData.hpp"
53#include "Potentials/CompoundPotential.hpp"
54#include "Potentials/EmpiricalPotential.hpp"
55#include "Potentials/InternalCoordinates/Coordinator.hpp"
56#include "Potentials/PotentialRegistry.hpp"
57#ifdef HAVE_QWT
58#include "UIElements/Views/Qt4/Plotting/QSeisData.hpp"
59#include "UIElements/Views/Qt4/Plotting/QSeisPageRegistry.hpp"
60#include "UIElements/Views/Qt4/Plotting/QSeisPlotCurve.hpp"
61#include "UIElements/Views/Qt4/Plotting/QSeisPlotPage.hpp"
62#include "UIElements/Views/Qt4/Plotting/QSeisCurveRegistry.hpp"
63#endif
64#include "World.hpp"
65
66using namespace std;
67
68const int QtHomologyList::COLUMNCOUNT = COLUMNTYPES_MAX;
69const char *QtHomologyList::COLUMNNAMES[QtHomologyList::COLUMNCOUNT]={"Number","Nodes","Edges","Occurrence"};
70
71QtHomologyList::QtHomologyList(QWidget * _parent) :
72 QWidget(_parent),
73 Observer("QtHomologyList"),
74 potentialregistry_enabled(false)
75{
76 QVBoxLayout* layout = new QVBoxLayout(this);
77 QSplitter *splitter = new QSplitter (Qt::Horizontal, this );
78 layout->addWidget(splitter);
79
80 // tree widget
81 treewidget = new QTreeWidget (splitter);
82 treewidget->setSelectionMode( QTreeWidget::SingleSelection );
83 treewidget->setColumnCount(COLUMNCOUNT);
84 QStringList header;
85 for(int i=0; i<COLUMNCOUNT;++i)
86 header << COLUMNNAMES[i];
87 treewidget->setHeaderLabels(header);
88 splitter->addWidget(treewidget);
89
90 // plot widget
91#ifdef HAVE_QWT
92 widget = new QSeisPlotPage ("energy", splitter);
93 QSeisPageRegistry::getInstance().registerInstance(widget);
94#else
95 widget = new QWidget(splitter);
96#endif
97 splitter->addWidget(widget);
98
99 dirty = true;
100 clearing = false;
101
102 refill();
103
104 HomologyContainer &homologies = World::getInstance().getHomologies();
105 homologies.signOn(this);
106 PotentialRegistry::getInstance().signOn(this);
107 potentialregistry_enabled = true;
108
109#ifdef HAVE_QWT
110 //connect the PlotCurveRegistry directly to the PlotPage registry
111 connect(QSeisCurveRegistry::getPointer(), SIGNAL(curveAdded(std::string, QString)), QSeisPageRegistry::getPointer(), SLOT(addCurve(std::string, QString)));
112 connect(QSeisCurveRegistry::getPointer(), SIGNAL(curveRemoved(std::string, QString)), QSeisPageRegistry::getPointer(), SLOT(removeCurve(std::string, QString)));
113 connect(QSeisCurveRegistry::getPointer(), SIGNAL(curveChanged(std::string, QString)), QSeisPageRegistry::getPointer(), SLOT(updateCurve(std::string, QString)));
114#endif
115
116 connect(treewidget,SIGNAL(itemSelectionChanged()),this,SLOT(rowSelected()));
117 connect(this,SIGNAL(changed()),this,SLOT(update()));
118}
119
120QtHomologyList::~QtHomologyList()
121{
122 HomologyContainer &homologies = World::getInstance().getHomologies();
123 homologies.signOff(this);
124 if (potentialregistry_enabled)
125 PotentialRegistry::getInstance().signOff(this);
126}
127
128void QtHomologyList::update(Observable *publisher) {
129
130 dirty = true;
131
132 // force an update from Qt...
133// clearing = true;
134// treewidget->clear();
135// clearing = false;
136 emit changed(); //doesn't work!?!
137}
138
139void QtHomologyList::refill()
140{
141 clearing = true;
142 const HomologyContainer &homologies = World::getInstance().getHomologies();
143
144 // clear everything
145 HomologySelection.clear();
146 treewidget->clear();
147#ifdef HAVE_QWT
148 QSeisCurveRegistry::getInstance().resetRegistry();
149#endif
150
151 size_t count = 0;
152 for (HomologyContainer::const_key_iterator homologyiter = homologies.key_begin();
153 homologyiter != homologies.key_end();
154 homologyiter = homologies.getNextKey(homologyiter), ++count) {
155 HomologyContainer::range_t occurences = homologies.getHomologousGraphs(*homologyiter);
156 const HomologyGraph &graph = occurences.first->first;
157 const size_t times = std::distance(occurences.first, occurences.second);
158
159 // create item
160 QTreeWidgetItem *treeItem = new QTreeWidgetItem(treewidget);
161 treeItem->setText(NUMBER, QString::number(count));
162 {
163 std::stringstream output;
164 graph.printNodes(output);
165 treeItem->setText(NODES, QString(output.str().c_str()));
166 }
167 {
168 std::stringstream output;
169 graph.printEdges(output);
170 treeItem->setText(EDGES, QString(output.str().c_str()));
171 }
172 if (times > 0) {
173 treeItem->setText(OCCURRENCE, QString::number(times));
174 } else {
175 treeItem->setText(OCCURRENCE, "none");
176 treeItem->setDisabled(true);
177 }
178 HomologySelection.push_back(treeItem->isSelected());
179
180#ifdef HAVE_QWT
181 // create associated curve in plot
182 CompoundPotential *compound = new CompoundPotential(graph);
183 ASSERT( compound != NULL,
184 "QtHomologyList::refill() - compound is NULL.");
185 TrainingData data(compound->getSpecificFilter());
186 data(homologies.getHomologousGraphs(graph));
187 if (!data.getTrainingInputs().empty()) {
188 // generate QSeisData
189 const TrainingData::InputVector_t &inputs = data.getAllArguments();
190 const TrainingData::OutputVector_t &outputs = data.getTrainingOutputs();
191 std::vector<double> xvalues;
192 std::vector<double> yvalues;
193 for (TrainingData::OutputVector_t::const_iterator outputiter = outputs.begin();
194 outputiter != outputs.end(); ++outputiter)
195 yvalues.push_back((*outputiter)[0]);
196
197 // go through each potential
198 for (CompoundPotential::models_t::const_iterator potiter = compound->begin();
199 potiter != compound->end();
200 ++potiter) {
201 const EmpiricalPotential &potential = dynamic_cast<const EmpiricalPotential &>(**potiter);
202 const std::string potentialname = potential.getName();
203 const FunctionModel::filter_t filter = potential.getSpecificFilter();
204 Coordinator::ptr coordinator = potential.getCoordinator();
205 // then we need to sample the potential
206 xvalues.clear();
207 for (TrainingData::InputVector_t::const_iterator inputiter = inputs.begin();
208 inputiter != inputs.end(); ++inputiter) {
209 const FunctionModel::list_of_arguments_t specificargs = filter(*inputiter);
210 double average = 0.;
211 for (FunctionModel::list_of_arguments_t::const_iterator argiter = specificargs.begin();
212 argiter != specificargs.end(); ++argiter) {
213 const FunctionModel::arguments_t args = *argiter;
214 average += (*coordinator)(args);
215 }
216 if (specificargs.size() > 1) {
217 const size_t index = xvalues.size();
218 xvalues.push_back(average/(double)specificargs.size());
219 yvalues[index] *= 1./(double)specificargs.size();
220 }
221 }
222
223 // We need to sort the xvalues (and associated yvalues also)
224 std::vector<double>::const_iterator xiter = xvalues.begin();
225 std::vector<double>::const_iterator yiter = yvalues.begin();
226 std::map<double, std::set<double> > sorted_xy;
227 for (;xiter != xvalues.end(); ++xiter, ++yiter) {
228 std::set<double> yset;
229 yset.insert(*yiter);
230 std::pair<std::map<double, std::set<double> >::iterator, bool> inserter =
231 sorted_xy.insert(std::make_pair(*xiter, yset));
232 if (!inserter.second)
233 inserter.first->second.insert(*yiter);
234 }
235 xvalues.clear();
236 yvalues.clear();
237 for (std::map<double, std::set<double> >::const_iterator iter = sorted_xy.begin();
238 iter != sorted_xy.end(); ++iter) {
239 for (std::set<double>::const_iterator valueiter = iter->second.begin();
240 valueiter != iter->second.end();
241 ++valueiter) {
242 xvalues.push_back(iter->first);
243 yvalues.push_back(*valueiter);
244 }
245 }
246
247 QSeisData data(xvalues, yvalues, QString(potentialname.c_str()));
248 // couple to QSeisPlotCurve and register the curve
249 QSeisPlotCurve *curve = new QSeisPlotCurve(QString(potentialname.c_str()), "energy");
250 curve->updateCurve(&data);
251 if (!QSeisCurveRegistry::getInstance().isPresentByName(curve->getName()))
252 QSeisCurveRegistry::getInstance().registerInstance(curve);
253 else
254 delete curve;
255 // couple to QSeisPlotPage
256 widget->addCurve(potentialname);
257
258 }
259 }
260#endif
261 }
262 dirty = false;
263 clearing = false;
264}
265
266void QtHomologyList::paintEvent(QPaintEvent * event)
267{
268 if (dirty)
269 refill();
270// treewidget->paintEvent(event);
271}
272
273void QtHomologyList::subjectKilled(Observable *publisher)
274{
275 // as a new instance should always already be present ... just sign on
276 if (static_cast<PotentialRegistry *>(publisher) == PotentialRegistry::getPointer()) {
277 potentialregistry_enabled = false;
278 } else {
279 // its HomologyContainer
280 }
281}
282
283
284void QtHomologyList::rowSelected()
285{
286 //std::cout << "rowSelected\n";
287 for (int i=0;i<treewidget->topLevelItemCount();i++){
288 QTreeWidgetItem *item = treewidget->topLevelItem(i);
289 bool newSelection = item->isSelected();
290 if (newSelection != HomologySelection[i]){
291 // TODO: Add selected curve to QTabWidget
292 }
293 }
294}
295
Note: See TracBrowser for help on using the repository browser.