File: minimizationDialog.C

package info (click to toggle)
ball 1.5.0%2Bgit20180813.37fc53c-6
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 239,888 kB
  • sloc: cpp: 326,149; ansic: 4,208; python: 2,303; yacc: 1,778; lex: 1,099; xml: 958; sh: 322; makefile: 95
file content (221 lines) | stat: -rw-r--r-- 5,144 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
// -*- Mode: C++; tab-width: 2; -*-
// vi: set ts=2:
//

#include <BALL/VIEW/DIALOGS/minimizationDialog.h>
#include <BALL/VIEW/DIALOGS/amberConfigurationDialog.h>
#include <BALL/VIEW/DIALOGS/charmmConfigurationDialog.h>
#include <BALL/VIEW/DIALOGS/MMFF94ConfigurationDialog.h>
#include <BALL/VIEW/KERNEL/common.h>
#include <BALL/SYSTEM/path.h>

#include <QtWidgets/QFileDialog>
#include <QtWidgets/QLineEdit>
#include <QtWidgets/QMessageBox>

namespace BALL
{
	namespace VIEW
	{

		MinimizationDialog::MinimizationDialog(QWidget* parent, const char* name)
			:	QDialog(parent),
				Ui_MinimizationDialogData(),
				PreferencesEntry(),
				amber_dialog_(0),
				charmm_dialog_(0),
				mmff_dialog_(0)
		{
			setupUi(this);
			setObjectName(name);
			setINIFileSectionName("MINIMIZATION");
			registerWidgets_();
			
			// signals and slots connections
			connect( start_button, SIGNAL( clicked() ), this, SLOT( accept() ) );
			connect( cancel_button, SIGNAL( clicked() ), this, SLOT( reject() ) );
			connect( advanced_button, SIGNAL( clicked() ), this, SLOT( advancedOptions() ) );
		}

		MinimizationDialog::~MinimizationDialog()
		{
		}

		Size MinimizationDialog::getMaxIterations() const	
		{
			try
			{
				return (Size)ascii(max_iterations_lineedit->text()).toUnsignedInt();
			}
			catch(...)
			{
				Log.error() << (String)tr("Invalid max iterations!") << std::endl;
				return 0;
			}
		}

		void MinimizationDialog::setMaxIterations(Size n)
		{
			max_iterations_lineedit->setText(QString(String(n).c_str()));
		}

		Size MinimizationDialog::getRefresh() const
		{
			try
			{
				return (Size)ascii(refresh_iterations_lineedit->text()).toUnsignedInt();
			}
			catch(...)
			{
				Log.error() << (String)tr("Invalid refresh iterations!") << std::endl;
				return 0;
			}
		}

		void MinimizationDialog::setRefresh(Size n)
		{
			refresh_iterations_lineedit->setText(QString(String(n).c_str()));
		}

		double MinimizationDialog::getMaxGradient() const
		{
			try
			{
				return (double)ascii(max_grad_lineedit->text()).toFloat();
			}
			catch(...)
			{
				Log.error() << (String)tr("Invalid max gradient!") << std::endl;
				return 0;
			}
		}

		void MinimizationDialog::setMaxGradient(double max_gradient)
		{
			max_grad_lineedit->setText(QString(String(max_gradient).c_str()));
		}

		double MinimizationDialog::getEnergyDifference() const
		{
			try
			{
				return (double)ascii(energy_difference_lineedit->text()).toFloat();
			}
			catch(...)
			{
				Log.error() << (String)tr("Invalid Energy Difference!") << std::endl;
				return 0;
			}
		}

		void MinimizationDialog::setEnergyDifference(double energy_difference)
		{
			energy_difference_lineedit->setText(QString(String(energy_difference).c_str()));
		}

		bool MinimizationDialog::getUseStrangLBFGS() const
		{
			return SLBFGS_button->isChecked();
		}

		void MinimizationDialog::setUseStrangLBFGS(bool use_LBFGS)
		{
			SLBFGS_button->setChecked(use_LBFGS);
		}

		bool MinimizationDialog::getUseShiftedLVMM() const
		{
			return SLVMM_button->isChecked();
		}

		void MinimizationDialog::setUseShiftedLVMM(bool use_shifted)
		{
			SLVMM_button->setChecked(use_shifted);
		}

		bool MinimizationDialog::getUseConjugateGradient() const
		{
			return conjugate_button->isChecked();
		}

		void MinimizationDialog::setUseConjugateGradient(bool use_CG)
		{
			conjugate_button->setChecked(use_CG);
		}

		void MinimizationDialog::advancedOptions()
		{
			if (useAmberRadioButton->isChecked())
			{
				if (amber_dialog_ != 0) amber_dialog_->exec();
			}
			else if (useCharmmRadioButton->isChecked())
			{
				if (charmm_dialog_ != 0) charmm_dialog_->exec();
			}
			else if (useMMFF94RadioButton->isChecked())
			{
				if (mmff_dialog_ != 0) mmff_dialog_->exec();
			}
		}

		void MinimizationDialog::setAmberDialog(AmberConfigurationDialog* dialog)
		{
			amber_dialog_ = dialog;
		}

		void MinimizationDialog::setCharmmDialog(CharmmConfigurationDialog* dialog)
		{
			charmm_dialog_ = dialog;
		}

		void MinimizationDialog::setMMFF94Dialog(MMFF94ConfigurationDialog* dialog)
		{
			mmff_dialog_ = dialog;
		}
		void MinimizationDialog::selectForceField(Position nr)
		{
			if 			(nr == 0) useAmberRadioButton->setChecked(true);
			else if (nr == 1) useCharmmRadioButton->setChecked(true);
			else if (nr == 2) useMMFF94RadioButton->setChecked(true);
			else
			{
				BALLVIEW_DEBUG
			}
		}
		
		Position MinimizationDialog::selectedForceField() const
		{
			if 			(useAmberRadioButton->isChecked())  return 0;
			else if (useCharmmRadioButton->isChecked()) return 1;
			else if (useMMFF94RadioButton->isChecked()) return 2;

			return 0;
		}
	
			
		void MinimizationDialog::accept()
		{
			QString error;
			if (getMaxGradient() == 0)
			{
				error = tr("maximum gradient.");
			}

			if(getEnergyDifference() == 0.0)
			{
				error = tr("energy difference.");
			}

			if (error == "")
			{
				QDialog::accept();
				return;
			}

			QMessageBox::critical(this, tr("Invalid values"), tr("Please apply correct settings") + " (> 0) " + tr("for the") + " " + error,
					QMessageBox::Ok| QMessageBox::Default);
		}

	} // namespace VIEW
} //namespace BALL