source: src/UIElements/Views/Qt4/QtHomologyList.cpp@ 86c013

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 86c013 was e1fe7e, checked in by Frederik Heber <heber@…>, 11 years ago

FunctionModel now uses list_of_arguments to split sequence of subsets of distances.

  • this fixes ambiguities with the set of distances: Imagine the distances within a water molecule as OH (A) and HH (B). We then may have a sequence of argument_t as AABAAB. And with the current implementation of CompoundPotential::splitUpArgumentsByModels() we would always choose the latter (and more complex) model. Hence, we make two calls to TriplePotential_Angle, instead of calls twice to PairPotential_Harmonic for A, one to PairPotential_Harmonic for B, and once to TriplePotential_Angle for AAB.
  • now, we new list looks like A,A,B,AAB where each tuple of distances can be uniquely associated with a specific potential.
  • changed signatures of EmpiricalPotential::operator(), ::derivative(), ::parameter_derivative(). This involved changing all of the current specific potentials and CompoundPotential.
  • TrainingData must discern between the InputVector_t (just all distances) and the FilteredInputVector_t (tuples of subsets of distances).
  • FunctionApproximation now has list_of_arguments_t as parameter to evaluate() and evaluate_derivative().
  • DOCU: docu change in TrainingData.
  • Property mode set to 100644
File size: 9.4 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
45#include "CodePatterns/MemDebug.hpp"
46
47#include "CodePatterns/Log.hpp"
48
49#include "Fragmentation/Homology/HomologyContainer.hpp"
50#include "FunctionApproximation/FunctionModel.hpp"
51#include "FunctionApproximation/TrainingData.hpp"
52#include "Potentials/CompoundPotential.hpp"
53#include "Potentials/EmpiricalPotential.hpp"
54#include "Potentials/InternalCoordinates/Coordinator.hpp"
55#include "Potentials/PotentialRegistry.hpp"
56#ifdef HAVE_QWT
57#include "UIElements/Views/Qt4/Plotting/QSeisData.hpp"
58#include "UIElements/Views/Qt4/Plotting/QSeisPageRegistry.hpp"
59#include "UIElements/Views/Qt4/Plotting/QSeisPlotCurve.hpp"
60#include "UIElements/Views/Qt4/Plotting/QSeisPlotPage.hpp"
61#include "UIElements/Views/Qt4/Plotting/QSeisCurveRegistry.hpp"
62#endif
63#include "World.hpp"
64
65using namespace std;
66
67const int QtHomologyList::COLUMNCOUNT = COLUMNTYPES_MAX;
68const char *QtHomologyList::COLUMNNAMES[QtHomologyList::COLUMNCOUNT]={"Number","Nodes","Edges","Occurrence"};
69
70QtHomologyList::QtHomologyList(QWidget * _parent) :
71 QWidget(_parent),
72 Observer("QtHomologyList"),
73 potentialregistry_enabled(false)
74{
75 QSplitter *splitter = new QSplitter (Qt::Horizontal, this );
76 treewidget = new QTreeWidget (splitter);
77 splitter->addWidget(treewidget);
78
79#ifdef HAVE_QWT
80 widget = new QSeisPlotPage ("energy", splitter);
81 QSeisPageRegistry::getInstance().registerInstance(widget);
82#else
83 widget = new QWidget(splitter);
84#endif
85 splitter->addWidget(widget);
86// splitter->setStretchFactor(10, 1);
87
88 treewidget->setSelectionMode( QTreeWidget::SingleSelection );
89
90 treewidget->setColumnCount(COLUMNCOUNT);
91 QStringList header;
92 for(int i=0; i<COLUMNCOUNT;++i)
93 header << COLUMNNAMES[i];
94 treewidget->setHeaderLabels(header);
95
96 dirty = true;
97 clearing = false;
98
99 refill();
100
101 HomologyContainer &homologies = World::getInstance().getHomologies();
102 homologies.signOn(this);
103 PotentialRegistry::getInstance().signOn(this);
104 potentialregistry_enabled = true;
105
106#ifdef HAVE_QWT
107 //connect the PlotCurveRegistry directly to the PlotPage registry
108 connect(QSeisCurveRegistry::getPointer(), SIGNAL(curveAdded(std::string, QString)), QSeisPageRegistry::getPointer(), SLOT(addCurve(std::string, QString)));
109 connect(QSeisCurveRegistry::getPointer(), SIGNAL(curveRemoved(std::string, QString)), QSeisPageRegistry::getPointer(), SLOT(removeCurve(std::string, QString)));
110 connect(QSeisCurveRegistry::getPointer(), SIGNAL(curveChanged(std::string, QString)), QSeisPageRegistry::getPointer(), SLOT(updateCurve(std::string, QString)));
111#endif
112
113 connect(treewidget,SIGNAL(itemSelectionChanged()),this,SLOT(rowSelected()));
114 connect(this,SIGNAL(changed()),this,SLOT(update()));
115}
116
117QtHomologyList::~QtHomologyList()
118{
119 HomologyContainer &homologies = World::getInstance().getHomologies();
120 homologies.signOff(this);
121 if (potentialregistry_enabled)
122 PotentialRegistry::getInstance().signOff(this);
123}
124
125void QtHomologyList::update(Observable *publisher) {
126
127 dirty = true;
128
129 // force an update from Qt...
130// clearing = true;
131// treewidget->clear();
132// clearing = false;
133 emit changed(); //doesn't work!?!
134}
135
136void QtHomologyList::refill()
137{
138 clearing = true;
139 const HomologyContainer &homologies = World::getInstance().getHomologies();
140
141 // clear everything
142 HomologySelection.clear();
143 treewidget->clear();
144#ifdef HAVE_QWT
145 QSeisCurveRegistry::getInstance().resetRegistry();
146#endif
147
148 size_t count = 0;
149 for (HomologyContainer::const_key_iterator homologyiter = homologies.key_begin();
150 homologyiter != homologies.key_end();
151 homologyiter = homologies.getNextKey(homologyiter), ++count) {
152 HomologyContainer::range_t occurences = homologies.getHomologousGraphs(*homologyiter);
153 const HomologyGraph &graph = occurences.first->first;
154 const size_t times = std::distance(occurences.first, occurences.second);
155
156 // create item
157 QTreeWidgetItem *treeItem = new QTreeWidgetItem(treewidget);
158 treeItem->setText(NUMBER, QString::number(count));
159 {
160 std::stringstream output;
161 graph.printNodes(output);
162 treeItem->setText(NODES, QString(output.str().c_str()));
163 }
164 {
165 std::stringstream output;
166 graph.printEdges(output);
167 treeItem->setText(EDGES, QString(output.str().c_str()));
168 }
169 if (times > 0) {
170 treeItem->setText(OCCURRENCE, QString::number(times));
171 } else {
172 treeItem->setText(OCCURRENCE, "none");
173 treeItem->setDisabled(true);
174 }
175 HomologySelection.push_back(treeItem->isSelected());
176
177#ifdef HAVE_QWT
178 // create associated curve in plot
179 CompoundPotential *compound = new CompoundPotential(graph);
180 ASSERT( compound != NULL,
181 "QtHomologyList::refill() - compound is NULL.");
182 TrainingData data(compound->getSpecificFilter());
183 data(homologies.getHomologousGraphs(graph));
184 if (!data.getTrainingInputs().empty()) {
185 // generate QSeisData
186 const TrainingData::InputVector_t &inputs = data.getAllArguments();
187 const TrainingData::OutputVector_t &outputs = data.getTrainingOutputs();
188 std::vector<double> xvalues;
189 std::vector<double> yvalues;
190 for (TrainingData::OutputVector_t::const_iterator outputiter = outputs.begin();
191 outputiter != outputs.end(); ++outputiter)
192 yvalues.push_back((*outputiter)[0]);
193
194 // go through each potential
195 for (CompoundPotential::models_t::const_iterator potiter = compound->begin();
196 potiter != compound->end();
197 ++potiter) {
198 const EmpiricalPotential &potential = dynamic_cast<const EmpiricalPotential &>(**potiter);
199 const std::string potentialname = potential.getName();
200 Coordinator::ptr coordinator = potential.getCoordinator();
201 // then we need to sample the potential
202 xvalues.clear();
203 for (TrainingData::InputVector_t::const_iterator inputiter = inputs.begin();
204 inputiter != inputs.end(); ++inputiter)
205 xvalues.push_back((*coordinator)(*inputiter));
206
207 // We need to sort the xvalues (and yvalues also)
208 std::vector<double>::const_iterator xiter = xvalues.begin();
209 std::vector<double>::const_iterator yiter = yvalues.begin();
210 std::map<double, std::set<double> > sorted_xy;
211 for (;xiter != xvalues.end(); ++xiter, ++yiter) {
212 std::set<double> yset;
213 yset.insert(*yiter);
214 std::pair<std::map<double, std::set<double> >::iterator, bool> inserter =
215 sorted_xy.insert(std::make_pair(*xiter, yset));
216 if (!inserter.second)
217 inserter.first->second.insert(*yiter);
218 }
219 xvalues.clear();
220 yvalues.clear();
221 for (std::map<double, std::set<double> >::const_iterator iter = sorted_xy.begin();
222 iter != sorted_xy.end(); ++iter) {
223 for (std::set<double>::const_iterator valueiter = iter->second.begin();
224 valueiter != iter->second.end();
225 ++valueiter) {
226 xvalues.push_back(iter->first);
227 yvalues.push_back(*valueiter);
228 }
229 }
230
231 QSeisData data(xvalues, yvalues, QString(potentialname.c_str()));
232 // couple to QSeisPlotCurve and register the curve
233 QSeisPlotCurve *curve = new QSeisPlotCurve(QString(potentialname.c_str()), "energy");
234 curve->updateCurve(&data);
235 if (!QSeisCurveRegistry::getInstance().isPresentByName(curve->getName()))
236 QSeisCurveRegistry::getInstance().registerInstance(curve);
237 else
238 delete curve;
239 // couple to QSeisPlotPage
240 widget->addCurve(potentialname);
241
242 }
243 }
244#endif
245 }
246 dirty = false;
247 clearing = false;
248}
249
250void QtHomologyList::paintEvent(QPaintEvent * event)
251{
252 if (dirty)
253 refill();
254// treewidget->paintEvent(event);
255}
256
257void QtHomologyList::subjectKilled(Observable *publisher)
258{
259 // as a new instance should always already be present ... just sign on
260 if (static_cast<PotentialRegistry *>(publisher) == PotentialRegistry::getPointer()) {
261 potentialregistry_enabled = false;
262 } else {
263 // its HomologyContainer
264 }
265}
266
267
268void QtHomologyList::rowSelected()
269{
270 //std::cout << "rowSelected\n";
271 for (int i=0;i<treewidget->topLevelItemCount();i++){
272 QTreeWidgetItem *item = treewidget->topLevelItem(i);
273 bool newSelection = item->isSelected();
274 if (newSelection != HomologySelection[i]){
275 // TODO: Add selected curve to QTabWidget
276 }
277 }
278}
279
Note: See TracBrowser for help on using the repository browser.