File: generateCrystalDialog.C

package info (click to toggle)
ball 1.5.0%2Bgit20180813.37fc53c-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 239,848 kB
  • sloc: cpp: 326,149; ansic: 4,208; python: 2,303; yacc: 1,778; lex: 1,099; xml: 958; sh: 322; makefile: 93
file content (197 lines) | stat: -rw-r--r-- 4,589 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
// -*- Mode: C++; tab-width: 2; -*-
// vi: set ts=2:

#include <BALL/VIEW/DIALOGS/generateCrystalDialog.h>
#include <BALL/VIEW/KERNEL/mainControl.h>
#include <BALL/FORMAT/parameters.h>
#include <BALL/SYSTEM/path.h>
#include <BALL/VIEW/KERNEL/mainControl.h>
#include <BALL/VIEW/KERNEL/threads.h>
#include <BALL/XRAY/crystalInfo.h>

#include <QComboBox>

namespace BALL
{
	namespace VIEW
	{
		GenerateCrystalDialog::GenerateCrystalDialog(QWidget* parent, const char* name, bool, Qt::WindowFlags fl)
			: QDialog(parent, fl),
			Ui_GenerateCrystalDialogData(),
			ModularWidget(name),
			//generator_(0),
			generator_(new CrystalGenerator()),
			//sg_list(0),
			//sg_entry(0),
			system_(0)

		{
#ifdef BALL_VIEW_DEBUG
			Log.error() << "new GenerateCrystalDialog" << this << std::endl;
#endif
			setupUi(this);
			setObjectName(name);
			
			initSpaceGroupList();
			// register the widget with the MainControl
			ModularWidget::registerWidget(this);
			hide();
			
			//signals and slot connections
			connect( buttonBox, SIGNAL( accepted() ), this, SLOT ( slotOk() ));
			connect( buttonBox, SIGNAL( rejected() ), this, SLOT ( slotCancel() ));

		}
			
		GenerateCrystalDialog::~GenerateCrystalDialog()
		{
#ifdef BALL_VIEW_DEBUG
			Log.info() << "Destructing object " << this << " of class GenerateCrystalDialog" << std::endl; 
#endif 

		}
		
		bool GenerateCrystalDialog::initSpaceGroupList()
		{
			if (generator_)
			{
				Path path;
				String filename = generator_->getSpaceGroupFilename();
				String filepath = path.find(filename);
				if (filepath == "")
				{
						throw Exception::FileNotFound(__FILE__, __LINE__, filename);
				}

				Parameters* param = new Parameters(filepath);
				if (!param->isValid()) return false;

				sg_list_.extractSection(*param, "SpacegroupList");	
				if (!sg_list_.isValid()) return false;
				
				delete param;
						
				space_group_combobox->clear();
				for (Position i = 0; i < sg_list_.getNumberOfKeys(); i++)
				{
					space_group_combobox->addItem(QString(sg_list_.getValue(i,0).c_str()));
				}
					
				if (space_group_combobox->count() != sg_list_.getNumberOfKeys())
				{
					space_group_combobox->clear();
				};
					
				return true;		
			}
			
			return false;
		}
		
		void GenerateCrystalDialog::slotOk()
		{
			generate();
		}
		
		void GenerateCrystalDialog::slotCancel()
		{
		}
		
		bool GenerateCrystalDialog::generate()
		{
			if (system_ == 0) system_ = getMainControl()->getSelectedSystem();
			
			if (system_ == 0)
			{
				Log.error() << "No system given! Aborting..." << std::endl;
				return false;
			}

			if (!lockComposites()) 
			{
				setStatusbarText(tr("Can not generate a crystal packing, since I can not lock the molecular data. Is a simulation running?"), true);
				return false;
			}
			
			
			generate_();
			
			system_ = 0;
			unlockComposites();
			
			return true;
		}
		
		void GenerateCrystalDialog::generate_()
		{
				
		
			generator_->setSystem(system_);
			
			boost::shared_ptr<CrystalInfo> ci_ptr;
			
			if (crystalinfo_checkbox->isChecked())
			{
				ci_ptr = boost::dynamic_pointer_cast<CrystalInfo>(system_->getAtomContainer(0)->getProperty("CRYSTALINFO").getSmartObject());
			}
			else
			{
				boost::shared_ptr<CrystalInfo> tmp_ptr(new CrystalInfo());
				ci_ptr = tmp_ptr;
				
				ci_ptr->setSpaceGroup(space_group_combobox->currentText().toStdString());
				
				ci_ptr->setCellEdgeLengthA(axis_x_spinbox->value());
				ci_ptr->setCellEdgeLengthB(axis_y_spinbox->value());
				ci_ptr->setCellEdgeLengthC(axis_z_spinbox->value());
				
			}		
			

			generator_->setCrystalInfo(ci_ptr);

			System* output = 0;
			if (generatePacking->isChecked())
			{
				std::list<System*> crystal = generator_->generatePacking(genPack_a_from->value(), genPack_a_to->value(),
						genPack_b_from->value(), genPack_b_to->value(),
						genPack_c_from->value(), genPack_c_to->value());

				if(crystal.size() != 0)		
				{
					std::list<System*>::iterator it_c = crystal.begin();	

					for(;it_c != crystal.end(); it_c++)
					{
						getMainControl()->insert(**it_c, (*it_c)->getName());
					}
				}
			}
			else
			{
				if (generateASU->isChecked())
				{
					output = generator_->generateAsymmetricUnit();	
				}

				if (generateUC->isChecked())
				{

					output = generator_->generateUnitCell(genUC_a->value(), genUC_b->value(), genUC_c->value());	
				}
				
				if (output)
				{
					getMainControl()->insert(*output, output->getName());
				}
			
			}

			

					
			//Log.info() << "Bis hierhin klappts !" << std::endl;
		}

	} // namespace VIEW
}	// namespace BALL