Debian Codegraph @

window.cpp

raw symbols ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
1 /****************************************************************************
2 **
3 ** Copyright (C) 2011 Christian B. Huebschle & George M. Sheldrick
4 ** All rights reserved.
5 ** Contact: [email protected]
6 **
7 ** This file is part of the ShelXle
8 **
9 ** This file may be used under the terms of the GNU Lesser
10 ** General Public License version 2.1 as published by the Free Software
11 ** Foundation and appearing in the file COPYING included in the
12 ** packaging of this file. Please review the following information to
13 ** ensure the GNU Lesser General Public License version 2.1 requirements
14 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
15 **
16 **
17 ****************************************************************************/
18 //äöüß needed to keep this file UTF8 QString::fromUtf8("»")
19 int Revision=1551;
20 #include "window.h"
21 #include "scatt.h"
22 #include "includeeditor.h"
23 #include "exportccdlg.h"
24 #include "deprecation.h"
25 #include "partcolor.h"
26 #include "highlighter.h"
27 #include "eacDlg.h"
28 //#include "dragdropatomsdlg.h"
29 #include "savehistorywidget.h"
30 #include "fcvsfo.h"
31 #include "rename_selected.h"
32
33 //QString datum=QString(__TIME__ " " __DATE__);
34 #ifdef __x86_64__
35 const int BitWidth=64;
36 #else
37 #ifdef _WIN64
38 const int BitWidth=64;
39 #else
40 const int BitWidth=32;// "<p>This is a 32 bit Version.</p> "
41 #endif
42 #endif
43 const QFileDialog::Options noneopt = QFileDialog::Options();
44 QString latestRev="no network available, or you disabled checking";
45 QString lstpatternfile=":lst_and_output_style.ini";
46 QString inspatternfile=":ins_res_style.ini";
47 QString lstpatternfile_dark=":lst_and_output_style_dark.ini";
48 QString inspatternfile_dark=":ins_res_style_dark.ini";
49
50 void Window::dragEnterEvent(QDragEnterEvent *event) {
51 if (event->mimeData()->hasFormat("text/uri-list"))
52 event->acceptProposedAction();
53 }
54
55 void Window::toggleFullScreen(){
56 if (QString(PROGRAM_NAME).compare("shelXle")) return;
57 fullscreen=!fullscreen;
58 if (fullscreen) {
59 showFullScreen();
60 updateStatusBar("+++PRESS F11 to exit full screen mode.+++PRESS F11 to exit full screen mode.+++PRESS F11 to exit full screen mode.+++PRESS F11 to exit full screen mode.+++PRESS F11 to exit full screen mode.+++");
61 }
62 else showNormal();
63 }
64
65 void Window::dropEvent(QDropEvent *event) {
66 QList<QUrl> drops = event->mimeData()->urls();
67 QString path=drops.first().path();
68 #if defined Q_WS_WIN || defined Q_OS_WIN
69 path.remove(QRegularExpression("^/"));
70 #endif
71 if ((path.endsWith(".res",Qt::CaseInsensitive))||(path.endsWith(".ins",Qt::CaseInsensitive))){
72 loadFile(path);
73 event->acceptProposedAction();
74 }
75 }
76
77 void Window::qinitres() {
78 if (!QString(PROGRAM_NAME).compare("shelXle")){
79 printf("init resorce: %s\n",PROGRAM_NAME);
80 Q_INIT_RESOURCE(icons);
81 }else{
82 printf("init resorce: %s\n",PROGRAM_NAME);
83 Q_INIT_RESOURCE(bicons);
84 Q_INIT_RESOURCE(shaders);
85 }
86 }
87
88 Window::Window(PlayOpenGL *_chgl){
89 /*! \brief the constructor of the main window rather lengthy but most widgets are created and placed here.
90 *
91 */
92 fullscreen=false;
93 setObjectName("The Main Window");
94 oldFileName=popel=QString("");
95 extraIndex = -1;
96 wght_max_cycls = 10;
97 calcmenu=nullptr;
98 printf("QT_VERSION %x \n",QT_VERSION);
99 setAcceptDrops(true);
100 mole.mynewnameis=QString(PROGRAM_NAME);
101 if (!QString(PROGRAM_NAME).compare("shelXle")){
102 theIconPath=QString(":/xle-icons/");
103 }else{
104 theIconPath=QString(":/bicons/");
105 }
106 int qtmajor=(QT_VERSION&0xff0000)>>16;
107 if (PROGRAM_NAME[0]=='s') {
108 mole.mynewnameis= QString("%1-%2-%3").arg(PROGRAM_NAME).arg(BitWidth).arg(qtmajor);//each version should get ist new ini file because qt5 seems to be
109 //incompatible in windows state
110 QSettings *testset = new QSettings( QSettings::IniFormat, QSettings::UserScope ,PROGRAM_NAME, mole.mynewnameis );
111 QSettings *oldset = new QSettings( QSettings::IniFormat, QSettings::UserScope ,PROGRAM_NAME, PROGRAM_NAME);
112 if ((!QFile::exists(testset->fileName()))&&(QFile::exists(oldset->fileName()))){
113 QFile::copy(oldset->fileName(),testset->fileName());
114 }
115 testset->deleteLater();
116 oldset->deleteLater();
117 }
118 einstellung = new QSettings( QSettings::IniFormat, QSettings::UserScope ,PROGRAM_NAME, mole.mynewnameis );
119 //QFontDatabase::addApplicationFont(":/xle-icons/droid-sans-mono.ttf");
120 falschAtom=-1;
121 CurrentCellString=QString();
122 MaxNumberOfPeaks=100;
123 altExtraIconPath="";
124 calcmenu=NULL;//if not needed it will be not created.
125 dsr=NULL;
126 qsaPNG=nullptr;
127 nowaste=true;
128 focusSet=true;
129 doNotAnnoyMe=false;
130 #if (QT_VERSION >=0x050000)
131 screen = QGuiApplication::screens().at(0);
132 hhh = screen->availableGeometry().height();
133 #else
134 hhh = qApp->desktop()->availableGeometry(-1).height();
135 #endif
136 printf("available height %d\n",hhh);
137 shxPath=shxOptions=NULL;
138 machPlatz=false;
139 char *ENUS=setlocale(LC_ALL,"C");
140 if (!ENUS)ENUS=setlocale(LC_ALL,"en_US.UTF-8");
141 //printf("%s\n",ENUS);
142 FFTErrorString="";
143 range=3.0;
144 mode=0;
145 weight=1.0;
146 //scroller=false;
147 setDockNestingEnabled(true);
148 otherOpenFiles=false;
149 QFontDatabase::addApplicationFont(theIconPath+"SourceCodePro-Bold.ttf");
150 QFontDatabase::addApplicationFont(theIconPath+"SourceCodePro-Italic.ttf");
151 int id = QFontDatabase::addApplicationFont(theIconPath+"SourceCodePro-Regular.ttf");
152 QString family = QFontDatabase::applicationFontFamilies(id).at(0);
153 QFont font(family);
154
155 {//initialize Edidor
156 navibox = new QGroupBox(this);
157 nlt = new QHBoxLayout(navibox);
158 //nlt->setMargin(0);
159 selectPart = new QCheckBox("Select Part",navibox);
160 selectPart->setChecked(false);
161 spinSelectPart = new QSpinBox(navibox);
162 spinSelectPart->setMinimum(1);
163 spinSelectPart->setMaximum(2);
164 spinSelectPart->setVisible(false);
165 inculdePartNull = new QCheckBox("incl. Pt. 0",navibox);
166 inculdePartNull->setToolTip("Include part 0 in selection");
167 inculdePartNull->setChecked(true);
168 inculdePartNull->setVisible(false);
169 QToolButton *nothing=new QToolButton(navibox);
170 nothing->setIcon(QIcon(theIconPath+"nospell.svg"));
171 nothing->setText("no errors");
172 nothing->setIconSize(QSize(22,22));
173 nothing->setToolButtonStyle(Qt::ToolButtonIconOnly);
174 spellCheckact = new QToolButton(navibox);
175 spellCheckact->setIcon(QIcon(theIconPath+"spell.svg"));
176 spellCheckact->setText("Jump to error");
177 spellCheckact->setIconSize(QSize(22,22));
178 spellCheckact->setToolTip("Jump to first error in file.");
179 spellCheckact->setToolButtonStyle(Qt::ToolButtonIconOnly);
180 lineColumn = new QLabel("",navibox);
181 nlt->addWidget(selectPart);
182 nlt->addWidget(spinSelectPart);
183 nlt->addWidget(inculdePartNull);
184 connect(selectPart,SIGNAL(toggled(bool)),spinSelectPart,SLOT(setVisible(bool)));
185 connect(selectPart,SIGNAL(toggled(bool)),inculdePartNull,SLOT(setVisible(bool)));
186 connect(selectPart,SIGNAL(stateChanged(int)),this,SLOT(selectParts()));
187 connect(inculdePartNull,SIGNAL(toggled(bool)),this,SLOT(selectParts()));
188 connect(spinSelectPart,SIGNAL(valueChanged(int)),this,SLOT(selectParts()));
189 nlt->addStretch(10);
190 nlt->addWidget(lineColumn);
191 navibox->setLayout(nlt);
192 editor = new CodeEditor(this);
193 editor->setObjectName("ShelXleEditor");
194 QApplication::setCursorFlashTime(700);
195 editor->setCursorWidth(2);
196 nlt->addWidget(editor->resiFinder);
197 nlt->addWidget(spellCheckact);
198 nlt->addWidget(nothing);
199 connect(spellCheckact,SIGNAL(clicked()),editor,SLOT(jumpToError()));
200 completer = new QCompleter(this);
201 {
202 QStringList keywords;
203 keywords << "ACTA"<<"AFIX"<<"ANIS"<<"BASF"<<"BIND"<<"BLOC"<<"BOND"<<
204 "BUMP"<<"CELL"<<"CGLS"<<"CHIV"<<"CONF"<<"CONN"<<"DAMP"<<"DANG"<<
205 "DEFS"<<"DELU"<<"DFIX"<<"DISP"<<"EADP"<<"END "<<"EQIV"<<
206 "EXTI"<<"EXYZ"<<"FEND"<<"FLAT"<<"FMAP"<<"FRAG"<<"FREE"<<
207 "FVAR"<<"GRID"<<"HFIX"<<"HKLF"<<"HOPE"<<"HTAB"<<"ISOR"<<
208 "LATT"<<"LAUE"<<"LIST"<<"L.S."<<"MERG"<<"MOLE"<<
209 "MORE"<<"MOVE"<<"MPLA"<<"NCSY"<<"OMIT"<<"PART"<<"PLAN"<<
210 "REM "<<"RESI"<<"RTAB"<<"SADI"<<"SAME"<<"SFAC"<<"SHEL"<<
211 "SIMU"<<"SIZE"<<"SPEC"<<"STIR"<<"SUMP"<<"SWAT"<<"SYMM"<<
212 "TEMP"<<"TIME"<<"TITL"<<"TWIN"<<"UNIT"<<"VECT"<<
213 "WPDB"<<"WGHT"<<"ZERR"<<
214 // New Shelxl commands!
215 "XNPD"<<//83
216 "REST"<<//84
217 "CHAN"<<//85
218 "RIGU"<<//86
219 "FLAP"<<//87
220 "RNUM"<<//88
221 "SOCC"<<//89
222 "PRIG"<<//90
223 "WIGL"<<//91
224 "RANG"<<//92
225 "TANG"<<//93
226 "ADDA"<<//94
227 "STAG"<<//;//95
228 "ABIN"<<//96
229 "ANSC"<<//97
230 "ANSR"<<//98
231 "NOTR"<<//99
232 "NEUT"<<//100
233 "TWST";//<<101
234 keywords.sort();
235
236 completer->setModel(new QStringListModel(keywords, completer));
237 }
238 completer->setModelSorting(QCompleter::CaseInsensitivelySortedModel);
239 completer->setCaseSensitivity(Qt::CaseInsensitive);
240 completer->setWrapAround(false);
241 editor->setCompleter(completer);
242 shxEditorDock = new QDockWidget("SHELXL Editor",this,Qt::Widget);//Qt::Window//Qt::Tool
243 shxEditorDock->setObjectName("Editor");
244 shxEditorDock->setFeatures(
245 QDockWidget::DockWidgetMovable|
246 QDockWidget::DockWidgetFloatable|
247 QDockWidget::DockWidgetClosable);
248 connect(shxEditorDock,SIGNAL(visibilityChanged(bool)),this,SLOT(editorIsVisible(bool)));
249 shxMW = new QMainWindow(this);
250 shx_group = new QWidget(this);
251 shxMW->setCentralWidget(shx_group);
252 shx_group->setContentsMargins(0,0,0,0);
253 sss = new QVBoxLayout(shx_group);
254 sss->addWidget(navibox);
255 sss->addWidget(editor);
256 sss->addWidget(editor->suchbox);
257 shx_group->setLayout(sss);
258 shxEditorDock->setWidget(shxMW);
259 connect(shxEditorDock,SIGNAL(visibilityChanged(bool)),this,SLOT(shxActUpdate(bool)));
260 editor->setFont(font);
261 editor->setLineWrapMode(QPlainTextEdit::NoWrap);
262 addDockWidget(Qt::RightDockWidgetArea, shxEditorDock );
263 }
264 {//init shelx output viewer
265 xlPutor = new CodeEditor();
266 xlPutor->setObjectName("shelx output viewer");
267 xlPutor->setReadOnly(true);
268 xlPutor->setFont(font);
269 xlPutor->setLineWrapMode(QPlainTextEdit::NoWrap);
270 shxOutputDock = new QDockWidget("SHELXL output",this,Qt::Widget);
271 shxOutputDock->setObjectName("Output");
272 shxOutputDock->setFeatures(
273 QDockWidget::DockWidgetMovable|
274 QDockWidget::DockWidgetFloatable|
275 QDockWidget::DockWidgetClosable);
276 shxOutputDock->hide();
277 connect(shxOutputDock,SIGNAL(visibilityChanged(bool)),this,SLOT(outputIsVisible(bool)));
278 buttomLt = new QHBoxLayout();
279 loadRes = new QPushButton(QIcon(theIconPath+"open.svg"), "Load refinement results", this);
280 withdraw = new QPushButton(QIcon(theIconPath+"cancel.svg"), "Discard results", this);
281 showLst = new QPushButton("Show output listing file",this);
282 connect(loadRes,SIGNAL(pressed()),this,SLOT(loadrefres()));
283 connect(withdraw,SIGNAL(pressed()),this,SLOT(withdrawres()));
284 connect(showLst,SIGNAL(pressed()),this,SLOT(loadLst()));
285 pro7 = new QPushButton("Visualize output");
286 connect(pro7,SIGNAL(pressed()),this,SLOT(raiseTaff()));
287 connect(pro7,SIGNAL(pressed()),this,SLOT(displayDisagreeableRestraints()));
288 buttomLt->addWidget(loadRes);
289 buttomLt->addWidget(withdraw);
290 buttomLt->addStretch(10);
291 buttomLt->addWidget(showLst);
292 stoppRefinement = new QPushButton(QIcon(theIconPath+"cancel.svg"),"STOP refinement!",this);
293 stoppRefinement->hide();
294 finishRefinement = new QPushButton(QIcon(theIconPath+"cancel.svg"),"Finish Gracefully.",this);
295 finishRefinement->hide();
296 refineButtonBox = new QGroupBox();
297 refineButtonBox->setLayout(buttomLt);
298
299 vlt = new QVBoxLayout();
300 vlt->addWidget(xlPutor);
301 vlt->addWidget(xlPutor->suchbox);
302 vlt->addWidget(refineButtonBox);
303 vlt->addWidget(stoppRefinement);
304 vlt->addWidget(finishRefinement);
305
306 vlt->addWidget(pro7);
307 refineButtonBox->hide();
308 pro7->hide();
309 gp = new QGroupBox("");
310 gp->setFlat(true);
311 gp->setLayout(vlt);
312 shxOutputDock->setWidget(gp);
313 addDockWidget(Qt::RightDockWidgetArea, shxOutputDock);
314 tabifyDockWidget (shxEditorDock,shxOutputDock);
315
316 connect(shxOutputDock,SIGNAL(visibilityChanged(bool)),this,SLOT(shxOPTUpdate(bool)));
317 }
318 {//infotainment widget
319 vis_settings = new QSettings(QSettings::IniFormat, QSettings::UserScope, PROGRAM_NAME, mole.mynewnameis);
320 vis_settings->beginGroup("infotaiment");
321 if (!vis_settings->contains("info_as_default")) {
322 vis_settings->setValue("info_as_default", false);
323 }
324 vis_settings->endGroup();
325 infotainmentDock = new QDockWidget("Visual Refinement output",this,Qt::Widget);
326 infotainmentDock->setObjectName("Painment");
327 infotainmentDock->setFeatures(
328 QDockWidget::DockWidgetMovable|
329 QDockWidget::DockWidgetFloatable|
330 QDockWidget::DockWidgetClosable);
331 infotainmentDock->hide();
332 resid_label = new QTextEdit(); // shows residuals from refinement output
333 resid_label->setAlignment(Qt::AlignTop);
334 resid_label->setStyleSheet("QLabel { background-color : white; border: 1px solid lightgray;}");
335 resid_label->setWordWrapMode(QTextOption::NoWrap); // prevents word wrap in the table
336 restr_table = new QTextEdit();
337 restr_table->setAlignment(Qt::AlignBottom);
338 restr_table->setReadOnly(true);
339 resid_label->setReadOnly(true);
340 resid_layout = new QVBoxLayout();
341 resid_layout->addWidget(resid_label, 4); // residuals
342 resid_layout->addWidget(restr_table, 2); // list of most disagreeable restraints
343 refineButtonBox2 = new QGroupBox();
344 loadRes2 = new QPushButton(QIcon(theIconPath+"open.svg"),"Load refinement results",this);
345 withdraw2 = new QPushButton(QIcon(theIconPath+"cancel.svg"),"Discard results",this);
346 connect(loadRes2,SIGNAL(pressed()),this,SLOT(loadrefres()));
347 connect(withdraw2,SIGNAL(pressed()),this,SLOT(withdrawres()));
348 QHBoxLayout *buttomLt2 = new QHBoxLayout();
349 buttomLt2->addWidget(loadRes2);
350 buttomLt2->addWidget(withdraw2);
351 QPushButton *arte= new QPushButton("show text output");
352 connect(arte,SIGNAL(pressed()),this,SLOT(raiseTaz()));
353 refineButtonBox2->setLayout(buttomLt2);
354 stoppRefinement2 = new QPushButton(QIcon(theIconPath+"cancel.svg"),"STOP refinement!",this);
355 stoppRefinement2->hide();
356 finishRefinement2 = new QPushButton(QIcon(theIconPath+"cancel.svg"),"Finish Gracefully",this);
357 finishRefinement2->hide();
358 resid_layout->addWidget(refineButtonBox2, 1);
359 resid_layout->addWidget(stoppRefinement2, 1);
360 resid_layout->addWidget(finishRefinement2, 1);
361 resid_layout->addWidget(arte);
362 refineButtonBox2->hide();
363 restr_table->setMinimumSize(150, 50);
364
365 restr_table->setToolTip("The error of a parameter should generally not be higher than 3sigma. A higher\n"
366 "value means that the assumption of the target value is not met. \n"
367 "The reason for this can be either, for example, a distorted molecular geometry \n"
368 "or systematic errors in the data.\n"
369 "\n"
370 "Disagreeable restraints will be highlighted in yellow if the error is above \n"
371 "2.5sigma. They will be highlighted in red if the error is above 3.5sigma.\n");
372
373 resid_gb = new QGroupBox("");
374 resid_gb->setFlat(true);
375 resid_gb->setLayout(resid_layout);
376 infotainmentDock->setWidget(resid_gb);
377 addDockWidget(Qt::RightDockWidgetArea, infotainmentDock);
378 tabifyDockWidget (shxEditorDock,infotainmentDock);
379 }
380
381 dock = new QDockWidget("Information Window",this);
382 dock->setObjectName("Info");
383 dock->setAllowedAreas(Qt::AllDockWidgetAreas);
384 infoKanal = new QTextBrowser(dock);
385 infoKanal->setLineWrapMode(QTextEdit::NoWrap);
386 dock->setFeatures(QDockWidget::DockWidgetFloatable|QDockWidget::DockWidgetMovable|QDockWidget::DockWidgetClosable);
387 dock->setWidget(infoKanal);
388 dock->hide();
389 addDockWidget(Qt::RightDockWidgetArea, dock);
390 // resize(qApp->desktop()->screenGeometry().width(),qApp->desktop()->screenGeometry().height());
391
392 //rename dock
393 renamDock = new QDockWidget("Rename Mode");
394 renamDock->setObjectName("Rename");
395 enterRenameMode = renamDock->toggleViewAction ();
396 enterRenameMode->setShortcut(Qt::ALT|Qt::Key_R);
397 QShortcut *altplus = new QShortcut(Qt::CTRL|Qt::ALT|Qt::Key_Plus,renamDock);
398 connect(altplus, SIGNAL(activated()),this, SLOT(incResiNr()));
399 QShortcut *altminus = new QShortcut(Qt::CTRL|Qt::ALT|Qt::Key_Minus,renamDock);
400 connect(altminus, SIGNAL(activated()),this, SLOT(decResiNr()));
401 connect(enterRenameMode,SIGNAL(triggered(bool)),this,SLOT(renamUpdate(bool)));
402 //connect(enterRenameMode,SIGNAL(triggered(bool)),enterRenameMode,SLOT(setVisible(bool)));
403 renamDock->setFeatures(
404 QDockWidget::DockWidgetMovable|
405 QDockWidget::DockWidgetFloatable|
406 QDockWidget::DockWidgetClosable);
407
408 renameBox = new QGroupBox();
409 rnla = new QVBoxLayout();
410 rnla->setObjectName("Rename Layout");
411 nliL = new QLabel("You are in 'rename mode' now.");
412 nliL->setFont(QFont("Helvetica",18,QFont::Bold));
413 spellCheckact2 = new QToolButton(renameBox);
414 spellCheckact2->setIcon(QIcon(theIconPath+"spell.svg"));
415 spellCheckact2->setText("Oops! I made a mistake! Sorry! Please check!");
416 spellCheckact2->setIconSize(QSize(22,22));
417 spellCheckact2->setToolTip("Jump to first error in file.");
418 spellCheckact2->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
419 connect(spellCheckact2,SIGNAL(clicked()),shxEditorDock,SLOT(raise()));
420 connect(spellCheckact2,SIGNAL(clicked()),renamDock,SLOT(hide()));
421 connect(spellCheckact2,SIGNAL(clicked()),editor,SLOT(jumpToError()));
422 rnla->addWidget(spellCheckact2);
423 rnla->addWidget(nliL);
424 hintL = new QLabel("<div style=color:#0000aa; style=white-space:normal; style=background-color:"
425 "#f8f5cd; style=font-size:large;><b><u>Hint:</u></b><a name=\"test\"><img width=\"23\" src=\""
426 +theIconPath+"filesave.svg\"></a> It is wise to save often. Especially after renaming a couple of Q-Peaks. "
427 "<br>Saving synchronizes the visualized structure and the editor content.<br> <b>Before</b> you start renaming and <b>after</b> "
428 "you are finished renaming you should <b>SAVE!</b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href=\"#test\" style=text-align:right;>Click here to hide this hint for ever.</a></div>");
429 hintL->setWordWrap(true);
430 rnla->addWidget(hintL);
431 hintL->setOpenExternalLinks(true);
432 connect(hintL,SIGNAL(linkActivated(const QString &)), this ,SLOT(hintLhide()));
433 rufModeBox = new QCheckBox("Automatically jump to first unused label");
434 rufModeBox->setChecked(false);
435 connect(rufModeBox,SIGNAL(stateChanged(int)),this,SLOT(rufmode()));
436 partSpinL = new QLabel("Part:");
437 partSpin = new QSpinBox();
438 partSpin->setMinimum(-99);
439 partSpin->setMaximum(99);
440 partSpin->setValue(0);
441 connect(partSpin,SIGNAL(valueChanged(int)),this,SLOT(updateLabel()));
442 resiNrSpinL = new QLabel("Residue Nr:");
443 resiNrSpin = new QSpinBox();
444 resiNrSpin->setMinimum(0);
445 resiNrSpin->setMaximum(9999);
446 resiNrSpin->setValue(0);
447 connect(resiNrSpin,SIGNAL(valueChanged(int)),this,SLOT(renameRNchanged(int)));
448 resiResiClassL = new QLabel("Residue Class:");
449 resiResiClass = new QLineEdit("");
450 resiResiClass->setMaxLength(4);
451 resiResiClass->setValidator(new QRegularExpressionValidator(QRegularExpression("^[A-Za-z]\\w{0,3}"),resiResiClass));
452 resiResiClass->setMinimumWidth(100);
453 connect(resiResiClass,SIGNAL(textEdited(const QString&)),this,SLOT(grossRC(const QString&)));
454 resiResiClass->setEnabled(false);
455 resiResiClassCB = new QComboBox(this);
456 resiResiClassCB->setLineEdit(resiResiClass);
457 resiResiClassCB->setEditable(true);
458 resiResiClassCB->setMinimumWidth(150);
459 rhla = new QHBoxLayout();
460 rhla->addWidget(partSpinL);
461 rhla->addWidget(partSpin);
462 rhla->addWidget(resiNrSpinL);
463 rhla->addWidget(resiNrSpin);
464 rhla->addWidget(resiResiClassL);
465 rhla->addWidget(resiResiClassCB);
466 rnla->addLayout(rhla);
467 rhla2 = new QHBoxLayout();
468 tieOccL = new QLabel("Tie occupancy to: ");
469 tieOccL->setAlignment(Qt::AlignRight|Qt::AlignVCenter);
470 tieType = new QComboBox();
471 tieType->addItem("its fixed value",0);
472 tieType->addItem("fv(n)",1);
473 tieType->addItem("1-fv(n)",-1);
474 tieFVNrL = new QLabel("n = ");
475 tieFVNrL->setAlignment(Qt::AlignRight|Qt::AlignVCenter);
476 tieFVNr = new QSpinBox();
477 tieFVNr->setMinimum(1);
478 tieFVNr->setMaximum(9999);
479 tieFVNr->setValue(2);
480 tieUsedL = new QLabel("fv(2) is 0x used");
481 tieFix = new QDoubleSpinBox(this);
482 tieFix->setDecimals(1);
483 tieFix->setMinimum(0.0);
484 tieFix->setMaximum(1.0);
485 tieFix->setValue(1.0);
486 tieFix->setSingleStep(0.1);
487 tieFix->hide();
488 connect(tieType,SIGNAL(currentIndexChanged(int)),this,SLOT(updateTieFreeVar()));
489 connect(tieFVNr,SIGNAL(valueChanged(int)),this,SLOT(updateTieFreeVar()));
490 connect(partSpin,SIGNAL(valueChanged(int)),this,SLOT(updateTieFreeVar()));
491 rhla2->addWidget(tieOccL);
492 rhla2->addWidget(tieType);
493 rhla2->addWidget(tieFix);
494 rhla2->addWidget(tieFVNrL);
495 rhla2->addWidget(tieFVNr);
496 rhla2->addWidget(tieUsedL);
497 rhla2->setEnabled ( false );
498 rnla->addLayout(rhla2);
499 indexla = new QHBoxLayout();
500 indexIncr = new QCheckBox("Increment Suffix ");
501 indexIncr->setChecked(false);
502 indexL = new QLabel("Number");
503 indexSpin = new QSpinBox();
504 indexSpin->setMinimum(-1);
505 indexSpin->setMaximum(999);
506 indexSpin->setValue(labelIndex);
507 connect(indexSpin,SIGNAL(valueChanged(int )),this,SLOT(changeIndexofLabel(int )));
508 sufixBox = new QComboBox();
509 sufixL =new QLabel("Suffix");
510 QFont dlg2fnt=sufixL->font();
511 alpha<<"'"<<""<<"A"<<"B"<<"C"<<"D"<<"E"<<"F"<<"G"<<"H"<<"I"<<"J"<<"K"
512 <<"L"<<"M"<<"N"<<"O"<<"P"<<"Q"<<"R"<<"S"<<"T"<<"U"<<"V"<<"W"<<"X"<<"Y"<<"Z"
513 <<"A'"<<"B'"<<"C'"<<"D'"<<"E'"<<"F'"<<"G'"<<"H'"<<"I'"<<"J'"<<"K'"<<"L'"<<"M'"
514 <<"N'"<<"O'"<<"P'"<<"Q'"<<"R'"<<"S'"<<"T'"<<"U'"<<"V'"<<"W'"<<"X'"<<"Y'"<<"Z'";
515 sufixBox->addItems(alpha);
516 sufixBox->setCurrentIndex(1);
517 sufixBox->setEditable(true);
518 connect(sufixBox,SIGNAL( currentIndexChanged (int)),this,SLOT(changeSuffixofLabel(int )));
519 indexla->addWidget(indexL);
520 indexla->addWidget(indexSpin);
521 indexla->addWidget(sufixL);
522 indexla->addWidget(sufixBox);
523 rnla->addLayout(indexla);
524 labelSuffix="";
525 nextLabel="C1";
526 labelIndex=1;
527 labelPSE="C";
528 sfacBox = new QGroupBox("Scattering factors");
529 sfacBox->setFixedSize(110*52,70);
530 sfacla = new QHBoxLayout();
531 dsm= new QSignalMapper(this);
532 sfacla->addWidget(pserbt[0] = new QRadioButton("any"));
533 /*
534 QString pth=QDir::homePath()+"/QRadioButtonFont.txt";
535 FILE *frbf=fopen(pth.toStdString().c_str(),"wt");
536 fprintf(frbf, "%d %s\n", pserbt[0]->fontInfo().pointSize(), pserbt[0]->fontInfo().family().toStdString().c_str());
537 fclose(frbf);
538 */
539 dlg2fnt.setPointSize(10);
540 pserbt[0]->setFont(dlg2fnt);
541 dsm->setMapping(pserbt[0],"any");
542 connect(pserbt[0], SIGNAL(clicked()), dsm, SLOT(map()));
543 for (int i=1; i<109; i++){
544 sfacla->addWidget(pserbt[i] = new QRadioButton(mole.pse(i-1)));
545 pserbt[i]->setFont(dlg2fnt);
546 dsm->setMapping(pserbt[i],mole.pse(i-1));
547 connect(pserbt[i], SIGNAL(clicked()), dsm, SLOT(map()));
548 pserbt[i]->hide();
549 }
550 sfacla->addWidget(pserbt[110] = new QRadioButton("D"));
551 pserbt[110]->setFont(dlg2fnt);
552 dsm->setMapping(pserbt[110],"D");
553 connect(pserbt[110], SIGNAL(clicked()), dsm, SLOT(map()));
554 pserbt[110]->hide();
555
556 //connect(dsm, SIGNAL(mappedString(const QString &)), this, SLOT(changeElemetofLabel(const QString &)));
557 #if (QT_VERSION >= 0x050f00)
558 connect(dsm, &QSignalMapper::mappedString, this, &Window::changeElemetofLabel);
559 #else
560 connect(dsm, SIGNAL(mapped(const QString &)), this, SLOT(changeElemetofLabel(const QString &)));
561 #endif
562 sfacBox->setLayout(sfacla);
563 qsa =new QScrollArea();
564 qsa->setWidget(sfacBox);
565 qsa->setMaximumHeight(100);
566 QHBoxLayout *rufla= new QHBoxLayout();
567 rufla->addWidget(rufModeBox);
568 rufla->addWidget(indexIncr);
569 rnla->addLayout(rufla);
570 nextNameL = new QLabel("Next Label is:<br> <font color=\"red\">C1</font>");
571 nextNameL->setFont(QFont("Helvetica",16,QFont::Bold));
572 rnla->addWidget(nextNameL);
573 rnla->addWidget(qsa);
574 psew = new PSEWidget(&mole,this);
575 psew->selection=0;
576 psew->setVisible(false);
577 rnla->addWidget(psew);
578 willpse = new QPushButton("more scattering factors");
579
580 willpse->setStyleSheet(
581 QString(
582 "QPushButton {"
583 "border: 1px solid #000000;"
584 "border-radius: 9px;"
585 "background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 %1, stop: 0.5 %3, stop: 1 %2);"
586 "}"
587 "QPushButton:hover {"
588 "background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 %2, stop: 0.5 %1, stop: 1 %2);"
589 "}"
590 "QPushButton:flat {"
591 " border: none; /* no border for a flat push button */"
592 "}"
593 ).arg("#dedede").arg("#eeeeee").arg("#aeaeae"));
594
595 connect(willpse,SIGNAL(clicked()),psew,SLOT(show()));
596 hidwillpse=new QTimer(this);
597 hidwillpse->setSingleShot(true);
598 hidwillpse->setInterval(100);
599
600 connect(willpse,SIGNAL(clicked()),hidwillpse,SLOT(start()));
601 connect(hidwillpse,SIGNAL(timeout()),willpse,SLOT(hide()));
602 connect(psew,SIGNAL(pseSelected(int, bool)),psew,SLOT(hide()));
603 connect(psew,SIGNAL(pseSelected(int, bool)),willpse,SLOT(show()));
604 connect(psew,SIGNAL(pseSelected(int, bool)),this,SLOT(addNewScatteringFactor(int,bool)));
605
606 rnla->addWidget(willpse);
607
608 buttonBoxRN = new QDialogButtonBox( QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
609 buttonBoxRN->hide();
610 rnla->addWidget(buttonBoxRN);
611 renameBox->setLayout(rnla);
612
613 renamDock->setWidget(renameBox);
614 addDockWidget(Qt::RightDockWidgetArea, renamDock);
615 renamDock->hide();
616 tabifyDockWidget (shxEditorDock,renamDock);
617 //rename dock
618 //
619 qPeakDock = new QDockWidget("Q-Peak-Legend");
620 qPeakDock->setObjectName("Peak");
621 qPeakDock->hide();
622 qPeakDock->setFixedWidth(50);
623 qPeakDock->setToolTip("Click or scroll here to reduce the number of Q-peaks shown.");
624 qPeakDock->setFeatures(QDockWidget::DockWidgetClosable);
625 showQPeakLegend = qPeakDock->toggleViewAction ();
626 connect(showQPeakLegend, SIGNAL(toggled(bool )),this,SLOT(setMonoQ(bool )));
627 showQPeakLegend->setIcon(QIcon(theIconPath+"qlegend.svg"));
628 qpv = new QPeakView();
629 qPeakDock->setWidget(qpv);
630 addDockWidget(Qt::LeftDockWidgetArea,qPeakDock);
631
632 //HISTORY
633 histDock = new QDockWidget("Refinement History");
634 histDock->setObjectName("History");
635 hw = new HistoryWidget();
636 qsa2 =new QScrollArea();
637 hwl = new QVBoxLayout();
638 hwl->addWidget(hw);
639 qsa2->setLayout(hwl);
640 qsa2->setWidget(hw);
641 qsa2->setAlignment(Qt::AlignBottom|Qt::AlignLeft);
642 histDock->hide();
643 histDock->setFeatures(QDockWidget::DockWidgetMovable|
644 QDockWidget::DockWidgetFloatable|
645 QDockWidget::DockWidgetClosable);
646 histDock->setWidget(qsa2);
647 histDock->setMinimumSize(100,150);
648 addDockWidget(Qt::RightDockWidgetArea,histDock);
649 connect(hw, SIGNAL(message(const QString&)), this, SLOT(updateStatusBar(const QString&)));
650 connect(hw, SIGNAL(lofi(const QString&)), this, SLOT(loadFile(const QString&)));
651 connect(hw, SIGNAL(saveHist()), this, SLOT(openSaveHistory()));
652 //HISTORY
653
654
655 scalePic=1.0;
656 if ((Revision%666)==0)
657 setWindowTitle(QString("%1 - A clumsy GUI for sHELLxl (Rev: %2)(easteregg) ")
658 .arg(PROGRAM_NAME)
659 .arg(Revision));
660 else
661 setWindowTitle(QString("%1 - A Qt GUI for SHELXL (Rev: %2)(%3bit)(Qt%4)").arg(PROGRAM_NAME).arg(Revision)
662 .arg(BitWidth)
663 .arg(qtmajor)
664 );
665 //printf("line %d %p\n", __LINE__, _chgl);
666 chgl = new PlayOpenGL(&mole);
667 #if defined (Q_OS_MAC)
668 static QWidget *container = QWidget::createWindowContainer(chgl);
669 container->setObjectName("The Main Window");
670
671 #endif
672 //printf("line %d %p\n", __LINE__, chgl,container);
673 chgl->setMolecule(&mole);
674 chgl->QPeakLegend = showQPeakLegend;
675 editor->setgl(chgl);
676 xlPutor->setgl(chgl);
677
678
679 connect(qpv,SIGNAL(cutOffChanged(double)),chgl,SLOT(setQpeakCutoff(double)));
680 connect(qpv,SIGNAL(findQP(double)),chgl,SLOT(highliteQPeak(double)));
681 connect(chgl,SIGNAL(qpfoci(double)),qpv,SLOT(qpeaksInFocus(double)));
682 connect(renamDock,SIGNAL(visibilityChanged(bool)),chgl,SLOT(setReNaMo(bool)));
683 connect(renamDock,SIGNAL(visibilityChanged(bool)),this,SLOT(updateLabel()));
684
685 connect(renamDock,SIGNAL(visibilityChanged(bool)),this,SLOT(renamUpdate(bool)));
686 connect(chgl,SIGNAL(message(const QString&)),this,SLOT(updateStatusBar(const QString&)));
687 connect(chgl,SIGNAL(bigmessage(const QString&)),this,SLOT(infoKanalNews(const QString&)));
688 connect(chgl,SIGNAL(jumpit(int)),this ,SLOT(jumpToAtom(int)));
689 connect(chgl,SIGNAL(insertDFIX(double,double,QList<MyAtom>,QString)), editor,SLOT(insertDFIX(double,double,QList<MyAtom>,QString)));
690 connect(chgl,SIGNAL(bindthem()),editor,SLOT(insertBind()));
691 connect(chgl,SIGNAL(insertDANG(double,double,QList<MyAtom>,QString)), editor,SLOT(insertDANG(double,double,QList<MyAtom>,QString)));
692 connect(chgl,SIGNAL(insertFLAT(double,QList<MyAtom>,QString)), editor,SLOT(insertFLAT(double,QList<MyAtom>,QString)));
693 connect(chgl,SIGNAL(insertEXYZ(QList<MyAtom>)), editor, SLOT(insertEXYZ(QList<MyAtom>)));
694 connect(chgl,SIGNAL(insertEADP(QList<MyAtom>)), editor, SLOT(insertEADP(QList<MyAtom>)));
695 connect(chgl,SIGNAL(insertSADI(int)), this, SLOT(insertSADI(int)));
696 connect(chgl,SIGNAL(insertDELU(double, double, QList<MyAtom>,QString)), editor,SLOT(insertDELU(double,double,QList<MyAtom>,QString)));
697 connect(chgl,SIGNAL(insertSIMU(double,double,double,QList<MyAtom>,QString)), editor,SLOT(insertSIMU(double,double,double,QList<MyAtom>,QString)));
698 connect(chgl,SIGNAL(insertISOR(double,double,QList<MyAtom>,QString)), editor,SLOT(insertISOR(double,double,QList<MyAtom>,QString)));
699 connect(chgl,SIGNAL(insertRIGU(double, double, QList<MyAtom>,QString)), editor,SLOT(insertRIGU(double,double,QList<MyAtom>,QString)));
700 connect(chgl,SIGNAL(insertCHIV(double, double, QList<MyAtom>,QString)), editor,SLOT(insertCHIV(double,double,QList<MyAtom>,QString)));
701 connect(chgl,SIGNAL(insertANIS(QList<MyAtom>)), editor, SLOT(insertANIS(QList<MyAtom>)));
702 QAction *sma =new QAction("Show matrices (for debugging)",this);
703 sma->setShortcut(tr("Alt+F1"));
704 connect(sma,SIGNAL(triggered()),chgl,SLOT(showMatrix()));
705 for (int i = 0; i < MaxRecentFiles; ++i) {
706 recentFileActs[i] = new QAction(this);
707 recentFileActs[i]->setVisible(false);
708 connect(recentFileActs[i], SIGNAL(triggered()),
709 this, SLOT(openRecentFile()));
710 }
711 fileMenu = new QMenu(tr("File"), this);
712 //printf("line %d\n",__LINE__);
713
714 chgl->sfacMenu = new QMenu(tr("Change element to..."));
715 chgl->selSfacMenu = new QMenu(tr("Change elements of selection to..."));
716 editMenu = new QMenu(tr("Edit"),this);
717 dialogMenu = new QMenu(tr("Settings"), this);
718 viewMenu = new QMenu(tr("View"), this);
719 runMenu = new QMenu(tr("SHELX"),this);
720 runMenu->setObjectName("SHELX");
721 packMenu = new QMenu(tr("Pack"),this);
722 packMenu->setEnabled(false);
723 QMenu *fcoMenu = new QMenu("Tools");
724
725 //printf("line %d\n",__LINE__);
726 {
727 QAction *a = symmElementsAct = packMenu->addAction("Show Symmetry Elements", this, SLOT(symmElements(bool)));
728 a->setCheckable(true);
729 a->setChecked(false);
730 //a->setVisible(false);
731 }
732 extraMenu = new QMenu(tr("Extra"),this);
733 {
734 QAction *a;
735 a = switch2HKLF5 = runMenu->addAction("Switch to HKLF 5 refinement.", this, SLOT(go2hklf5()));
736 a->setVisible(false);
737 switch2HKLF5->setObjectName("switch2HKLF5");
738
739 a = switch2HKLF4 = runMenu->addAction("Switch to HKLF 4 refinement.", this, SLOT(go2hklf4()));
740 a->setVisible(false);
741 a = refineAct = runMenu->addAction(QIcon(theIconPath+"refine.svg"),"Copy current file to instruction file and run shelxl",this,SLOT(runShelXL()));
742 a->setShortcut(QKeySequence("F2"));
743 a->setData(0);
744 refineAct->setVisible(false);
745 refineAct->setEnabled(false);
746
747 a->setObjectName("refineAct");
748
749 a = refineActAnis = runMenu->addAction(QIcon(theIconPath+"refineanis.svg"),"Insert ANIS and run shelxl",this,SLOT(runShelXL()));
750 a->setShortcut(QKeySequence("Alt+F2"));
751 a->setData(1);
752 refineActAnis->setVisible(false);
753 refineActAnis->setEnabled(false);
754 a->setObjectName("refineActAnis");
755 a = refineActActa = runMenu->addAction(QIcon(theIconPath+"refineacta.svg"),"Insert ACTA and run shelxl",this,SLOT(runShelXL()));
756 a->setData(2);
757 refineActActa->setVisible(false);
758 refineActActa->setEnabled(false);
759 a = refineActExti = runMenu->addAction("Insert EXTI and run shelxl",this,SLOT(runShelXL()));
760 a->setData(3);
761 refineActExti->setVisible(false);
762 refineActExti->setEnabled(false);
763
764 a = refineActConf = runMenu->addAction("Insert CONF and run shelxl",this,SLOT(runShelXL()));
765 a->setData(4);
766 refineActConf->setVisible(false);
767 refineActConf->setEnabled(false);
768 wghtRefineAct=runMenu->addAction(QIcon(theIconPath+"wghtref.svg"),QString("Try to refine until WGHT converges (max %1 runs)").arg(wght_max_cycls),this,SLOT(convergeWght()));
769 if (canWeSqueeze()) {
770 squeezeAct=a=fcoMenu->addAction(QIcon(theIconPath+"squeeze.svg"),"PLATON SQUEEZE this data",this,SLOT(runSqueeze()));
771 }
772 else squeezeAct=nullptr;
773
774 QIcon icke = QIcon(theIconPath+"autohfix.svg");
775 a=actionHFix=runMenu->addAction(icke,
776 tr("Automatic H-Fi&x"),this,SLOT(autoHFix()));
777 a->setObjectName("actionHFix");
778 a=runMenu->addAction("DISPersion from WAVElength", editor, SLOT(dispFromWave()));
779 a=runMenu->addAction("Replace SFAC by elastic electron atomic scattering factors",editor,SLOT(insertElectronSFACs()));
780 a=actionUniq=runMenu->addAction("Move centers of gravity into unit cell",this,SLOT(uniq()));
781 a->setObjectName("actionUniq");
782 runMenu->addAction("UNIQue ", this, SLOT(unique()));
783 runMenu->addAction("Update UNIT instruction", editor, SLOT(updateUnit()));
784 runMenu->addAction("Weed unused SFAC numbers ", editor, SLOT(weedEmptySfacs()));
785 wghtAct=runMenu->addAction("Update WGHT instruction",editor,SLOT(updateWght()));
786 wghtAct->setEnabled(false);
787 runMenu->addAction("Invert structure", this, SLOT(invert()));
788 runMenu->addAction("Fix some parameters", this, SLOT(fixIt()));
789 sinaAct = runMenu->addAction(QIcon(theIconPath+"sina.svg"),"Make (selected or all) atoms isotropic (ISOT)",this,SLOT(sina()));
790 sinaAct->setObjectName("sinaAct");
791 sinaAct->setData(-1);
792 fcoMenu->addAction("Create Q-Peaks from Fo-Fc map",this, SLOT(addMoreQPeaks()));
793 actionQPeakLimit = fcoMenu->addAction(QString("Change maximum number of created Q-peaks (%1)").arg(MaxNumberOfPeaks),this,SLOT(changeQPeakLimit()));
794 fcoMenu->addAction("Most Disagreeable Reflections",this,SLOT(worstReflections()));
795 fcoMenu->addAction("Split rotate molecule branch",this,SLOT(splitRotate()));
796 a=fcoMenu->addAction("test for merohedral twinning");
797 twinDlg=nullptr;
798 connect(a,SIGNAL(triggered() ),this,SLOT(testMerohedral()));
799 runMenu->addAction(QIcon(theIconPath+"aula.svg"),"Automatic Labeling", this, SLOT(aula()));
800 runMenu->addSeparator();
801 editor->sortierWeise=1;
802 soact=runMenu->addAction("Sort atoms in file.",editor ,SLOT(sortAtoms()));
803
804 runMenu->addSeparator();
805 a=runMenu->addAction("...find more functions in Menu->Tools");
806 a->setDisabled(true);
807 runMenu->addSeparator();
808 runMenu->addAction("Specify SHELXL runtime options",this , SLOT(setShelxlOptions()));
809 }
810 {
811 QToolBar *tb =fito= new QToolBar(this);
812 tb->setWindowTitle(tr("File Tools"));
813 tb->setObjectName("FileTB");
814 addToolBar(tb);
815 QAction *a;
816 openAct=a=fileMenu->addAction(QIcon(theIconPath+"open.svg"),
817 tr("&Open..."), this, SLOT(openFile() ),QKeySequence(tr("Ctrl+O", "File|Open")));
818 tb->addAction(a);
819 actionSave = new QAction(QIcon(theIconPath+"filesave.svg"),tr("&Save"), this);
820 actionSave->setShortcut(QKeySequence::Save);
821 connect(actionSave, SIGNAL(triggered()), this, SLOT(fileSave()));
822 actionSave->setEnabled(false);
823 tb->addAction(actionSave);
824 fileMenu->addAction(actionSave);
825 actionSaveAs = new QAction(QIcon(theIconPath+"filesave.svg"),tr("&Save as ..."), this);
826 actionSaveAs->setShortcut(tr("Shift+Alt+S"));
827 connect(actionSaveAs, SIGNAL(triggered()), this, SLOT(fileSaveAs()));
828 actionSaveAs->setEnabled(true);
829 fileMenu->addAction(actionSaveAs);
830 fileMenu->addAction(tr("Open save history"),this,SLOT(openSaveHistory()));
831 fileMenu->addAction("Shred a CIF and load its res",this,SLOT(shredCIF()));
832 fileMenu->addSeparator();
833 screenshotAct=a=fileMenu->addAction(QIcon(theIconPath+"diskette.svg"),
834 tr("&ScreenShot"), this, SLOT(saveScene()), QKeySequence(tr("F7","File|ScreenShot")));
835 //tb->addAction(a);
836 actionPovRay=a=fileMenu->addAction(QIcon(theIconPath+"POV-Ray.ico"),"Export Scene to Pov-Ray",this, SLOT(savePovRay()));
837 a->setShortcut(Qt::ALT|Qt::Key_P);
838 tb->addAction(a);
839 objExport=a=fileMenu->addAction(QIcon(theIconPath+"obj.svg"),"Export Wafefront .obj file",this,SLOT(obj()));
840 tb->addAction(a);
841 a->setShortcut(Qt::ALT|Qt::Key_O);
842 fileMenu->addAction("Export Fourier Maps",this,SLOT(exportFMaps()));
843 fileMenu->addAction("Export visible atoms ...",this,SLOT(exportCoordinates()));
844 actionExportCC=fileMenu->addAction("Export for computational chemistry programs",this, SLOT(exportCC()));
845
846 fileMenu->addSeparator();
847 for (int i = 0; i < MaxRecentFiles; ++i)
848 fileMenu->addAction(recentFileActs[i]);
849 fileMenu->addSeparator();
850 fileMenu->addAction("Set default path",this,SLOT(setDefaultPath()));
851 fileMenu->addSeparator();
852 a=fileMenu->addAction(QIcon(theIconPath+"cancel.svg"), tr("&Quit") ,
853 this, SLOT(close()),QKeySequence(tr("Ctrl+Q", "File|Quit")));
854 tb->addAction(a);
855 }
856
857 //printf("line %d\n", __LINE__);
858 backColor = new QAction(tr("Change background color"), this);
859 labelColor = new QAction(tr("Change label color"), this);
860 backColor->setShortcut (tr("Shift+Alt+B"));
861 labelColor->setShortcut(tr("Shift+Alt+T"));
862 connect(backColor, SIGNAL (triggered ()), chgl, SLOT(changeBColor()));
863 connect(labelColor, SIGNAL (triggered ()), chgl, SLOT(changeTColor()));
864 dialogMenu->addAction("Change tool bar icon size",this,SLOT(changeIconSize()));
865 QAction *adoptAct=
866 dialogMenu->addAction("Edit tool bar is attached to Editor",this,SLOT(adoptEditToolBar(bool)));
867 adoptAct->setCheckable(true);
868 adoptAct->setChecked(false);
869 dialogMenu->addAction("Change screen shot resolution",this,SLOT(changeScalefactor()));
870 dialogMenu->addAction("Number of atoms in asymmetric unit to skip automatic distance calculation on loading",this, SLOT(setSDMLimit()));
871 dialogMenu->addAction("Number of max cycles in WGHT refine", this ,SLOT(setMaxWGHTCycls()));
872 separateLabelFile= dialogMenu->addAction("Render labels in a separate file");
873 separateLabelFile->setCheckable(true);
874 separateLabelFile->setChecked(false);
875 dialogMenu->addAction(backColor);
876 dialogMenu->addAction(labelColor);
877 dialogMenu->addAction(tr("Change label font"), this, SLOT(changeLabelFont()));
878 dialogMenu->addAction(tr("Change editor font"), this, SLOT(changeEditorFont()));
879 astdlg = dialogMenu->addAction(QIcon(theIconPath+"eac.svg"),"Atom Styles", this,SLOT(styleDialog()),QKeySequence("Alt+Shift+A"));
880 dialogMenu->addAction("Save current orientation matrix",chgl,SLOT(saveOrientation()));
881 dialogMenu->addAction("Load orientation matrix",chgl,SLOT(loadOrientation()));
882 editMenu->addAction(enterRenameMode);
883 {
884 QToolBar *tb = editToolBar = new QToolBar(this);
885 tb->setObjectName("EditTB");
886 tb->setWindowTitle(tr("Editor Tools"));
887 QAction *a;
888 actionEP=a=viewMenu->addAction(QIcon(theIconPath+"efplus.svg"), "Increase editor fontsize");
889 actionEP->setShortcut(QKeySequence(QKeySequence::ZoomIn));
890 connect(actionEP,SIGNAL(triggered()), editor, SLOT(increaseEdtiorFont()));
891 connect(actionEP,SIGNAL(triggered()), xlPutor,SLOT(increaseEdtiorFont()));
892 tb->addAction(a);
893 actionEM=a=viewMenu->addAction(QIcon(theIconPath+"efminus.svg"), "Decrease editor fontsize");
894 actionEM->setShortcut(QKeySequence(QKeySequence::ZoomOut));
895 connect(actionEM,SIGNAL(triggered()), editor, SLOT(decreaseEdtiorFont()));
896 connect(actionEM,SIGNAL(triggered()), xlPutor, SLOT(decreaseEdtiorFont()));
897 tb->addAction(a);
898 a = actionUndo = new QAction(QIcon( theIconPath+"editundo.svg"),tr("&Undo"), this);
899 a->setShortcut(QKeySequence::Undo);
900 a->setEnabled(false);
901 tb->addAction(a);
902 editMenu->addAction(a);
903 a = actionRedo = new QAction(QIcon( theIconPath+"editredo.svg"),tr("&Redo"), this);
904 a->setShortcut(QKeySequence::Redo);
905 a->setEnabled(false);
906 tb->addAction(a);
907 editMenu->addAction(a);
908 editMenu->addSeparator();
909 a = actionCut = new QAction(QIcon(theIconPath+"editcut.svg"),tr("Cu&t"), this);
910 a->setShortcut(QKeySequence::Cut);
911 a->setEnabled(false);
912 tb->addAction(a);
913 editMenu->addAction(a);
914 a = actionCopy = new QAction(QIcon(theIconPath+"editcopy.svg"),tr("&Copy"), this);
915 a->setShortcut(QKeySequence::Copy);
916 a->setEnabled(false);
917 tb->addAction(a);
918 editMenu->addAction(a);
919 a = actionPaste = new QAction(QIcon(theIconPath+"editpaste.svg"),tr("&Paste"), this);
920 a->setShortcut(QKeySequence::Paste);
921 a->setEnabled(false);
922 tb->addAction(a);
923 editMenu->addAction(a);
924
925
926
927 //printf("line %d\n",__LINE__);
928 #ifndef QT_NO_CLIPBOARD
929 actionPaste->setEnabled(!QApplication::clipboard()->text().isEmpty());
930 connect(QApplication::clipboard(), SIGNAL(dataChanged()), this, SLOT(clipboardDataChanged()));
931 #endif
932 a=actionSearch=editMenu->addAction(QIcon(theIconPath+"search.svg"),
933 "&Find in Text",this,SLOT(showSearch()),QKeySequence(tr("Ctrl+F", "Edit|Find")));
934 tb->addAction(a);
935 a->setEnabled(false);
936 a=actionNext=editMenu->addAction(QIcon(theIconPath+"moveright.svg"),
937 tr("Find &Next"),this ,SLOT(findNext()),QKeySequence(tr("F3","Edit|Next")));
938 a->setEnabled(false);
939 a=actionPrev=editMenu->addAction(QIcon(theIconPath+"moveleft.svg"),
940 tr("Find &Previous"),this, SLOT(findPrev()), QKeySequence(tr("Shift+F3", "Edit|Previous")));
941 a->setEnabled(false);
942 editToolBar->hide();
943
944
945 //printf("line %d\n",__LINE__);
946 }
947 {
948 QToolBar *tb = refineToolBar = new QToolBar(this);
949 tb->setObjectName("RefineTB");
950 tb->setWindowTitle(tr("Refinement Tools"));
951 addToolBar(tb);
952 tb->addAction(actionHFix);
953 QIcon icke=QIcon(theIconPath+"killqs.svg");
954 QAction *a;
955 a=killQs=editMenu->addAction(icke,
956 tr("Delete all Q-peaks"), this, SLOT(deleteAllQ()), QKeySequence(tr("Meta+Shift+Q")));
957 tb->addAction(a);
958 icke=QIcon(theIconPath+"killhs.svg");
959 a=killHs=editMenu->addAction(icke, tr("Delete all Hydrogen atoms"),this,SLOT(deleteAllH()), QKeySequence(tr("Meta+Shift+H")));
960 tb->addAction(a);
961 tb->addAction(refineAct);
962 tb->addAction(refineActAnis);
963 tb->addAction(wghtRefineAct);
964 if (squeezeAct!=nullptr) tb->addAction(squeezeAct);
965 refineToolBar->hide();
966 }
967
968
969 //printf("line %d\n",__LINE__);
970 {
971 //QToolBar *tb =
972 vito = new QToolBar(this);
973 vito->setWindowTitle(tr("View Tools"));
974 vito->setObjectName("ViewTB");
975 addToolBar(vito);
976 QAction *a;
977 /*
978 stereoMenu = new QMenu("&3D Stereo Options");
979 //zm_stereo = stereoMenu->addAction("&Zalman Monitor 3D");
980 pe_stereo = stereoMenu->addAction("&Parallel Eye Side by Side Stereo");
981 xe_stereo = stereoMenu->addAction("&Crossed Eye Side by Side Stereo");
982 an_stereo = stereoMenu->addAction("&Anaglyph Stereo red left blue right(testing)");
983 //hw_stereo = stereoMenu->addAction("&Hardware Stereo (testing)");
984
985
986 //printf("line %d\n",__LINE__);
987 //hw_stereo->setEnabled(chgl->context()->format().stereo());
988
989
990 //printf("line %d\n",__LINE__);
991 no_stereo = stereoMenu->addAction("Stereo &Mode off");
992 //connect(zm_stereo,SIGNAL(triggered()),chgl,SLOT(zalman()));
993 connect(pe_stereo,SIGNAL(triggered()),chgl,SLOT(parallel()));
994 connect(xe_stereo,SIGNAL(triggered()),chgl,SLOT(crosseye()));
995 connect(an_stereo,SIGNAL(triggered()),chgl,SLOT(anaglyphRedCyan()));
996 //connect(hw_stereo,SIGNAL(triggered()),chgl,SLOT(hardwareStereo()));
997 connect(no_stereo,SIGNAL(triggered()),chgl,SLOT(nostereo()));
998 stereoGroup = new QActionGroup(this);
999 //stereoGroup->addAction(zm_stereo);
1000 stereoGroup->addAction(pe_stereo);
1001 stereoGroup->addAction(xe_stereo);
1002 stereoGroup->addAction(an_stereo);
1003 //stereoGroup->addAction(hw_stereo);
1004 stereoGroup->addAction(no_stereo);
1005 //zm_stereo->setCheckable(true);
1006 pe_stereo->setCheckable(true);
1007 xe_stereo->setCheckable(true);
1008 an_stereo->setCheckable(true);
1009 //hw_stereo->setCheckable(true);
1010 no_stereo->setCheckable(true);
1011 no_stereo->setChecked(true);
1012 viewMenu->insertMenu(actionEP,stereoMenu);
1013 viewMenu->insertSeparator(actionEP);
1014 */
1015 moveMenu = new QMenu("Move Menu");
1016 moveMenu->addAction(tr("Zoom in") ,this,SLOT(zoomin ()), QKeySequence(Qt::ALT | Qt::Key_PageUp) );
1017 moveMenu->addAction(tr("Zoom out") ,this,SLOT(zoomout()), QKeySequence(Qt::ALT | Qt::Key_PageDown));
1018 moveMenu->addAction(tr("Rotate left") ,this,SLOT(rotl ()), QKeySequence(Qt::ALT | Qt::Key_Left) );
1019 moveMenu->addAction(tr("Rotate right") ,this,SLOT(rotr ()), QKeySequence(Qt::ALT | Qt::Key_Right) );
1020 moveMenu->addAction(tr("Rotate upwards") ,this,SLOT(rotu ()), QKeySequence(Qt::ALT | Qt::Key_Up) );
1021 moveMenu->addAction(tr("Rotate downwards") ,this,SLOT(rotd ()), QKeySequence(Qt::ALT | Qt::Key_Down) );
1022 moveMenu->addAction(sma);
1023 moveMenu->addAction("test test 1 2",this, SLOT(testOGL()),QKeySequence(Qt::META|Qt::SHIFT|Qt::Key_A) );
1024
1025
1026
1027 //printf("line %d\n",__LINE__);
1028 moveMenu->addAction("Zoom out", chgl, SLOT(zoomOut()), QKeySequence(Qt::ALT | Qt::CTRL | Qt::Key_Z));
1029 moveMenu->addAction("View along z direction",chgl,SLOT(along001()));
1030 viewMenu->insertMenu(actionEP,moveMenu);
1031
1032
1033 //printf("line %d\n",__LINE__);
1034 QIcon icke=QIcon(theIconPath+"ideal.svg");
1035 chgl->hideBeLo=viewMenu->addAction(icke,"Toggle BEDE and LONE objects (IDEAL)",chgl,SLOT(update()));
1036 chgl->hideBeLo->setCheckable(true);
1037 chgl->hideBeLo->setChecked(true);
1038 chgl->hideBeLo->setVisible(false);
1039 belocube = viewMenu->addAction("Compute and visualize BODD in direct space (IDEAL)" ,this,SLOT(beloWriteCube()));
1040 belocube->setVisible(false);
1041 belocube->setObjectName("BeLoCube");
1042 belocube->setShortcut(Qt::CTRL|Qt::Key_I);
1043 a=dialogMenu->addAction("HFIX only on suitable atoms", this, SLOT(toggleHFSAO(bool)));
1044 a->setCheckable(true);
1045 a->setChecked(mole.HFixSuitableAtomsOnly);
1046
1047 //printf("line %d\n",__LINE__);
1048 dialogMenu->addAction("Style BEDE and LONE objects (IDEAL)",this,SLOT(configBeLos()));
1049 chgl->shortLabels=viewMenu->addAction("Short Labels",chgl,SLOT(makeLabels()));
1050 chgl->shortLabels->setCheckable(true);
1051 chgl->shortLabels->setChecked(true);
1052 chgl->shortLabels->setShortcut(Qt::SHIFT | Qt::ALT | Qt::Key_L);
1053
1054 vito->addAction(astdlg);
1055 a=togAtom =viewMenu->addAction(QIcon(theIconPath+"atoms.svg"),
1056 tr("Toggle Atoms"), chgl, SLOT(setAtoms(bool)), QKeySequence("Alt+A"));
1057 a->setCheckable(true);
1058 a->setChecked(true);
1059 vito->addAction(a);
1060 a=chgl->tubes = vito->addAction(QIcon(theIconPath+"tubes.svg"),"Tubes",chgl,SLOT(update()));
1061 a=chgl->ballStick = vito->addAction(QIcon(theIconPath+"ballstick.svg"),"Ball-Stick",chgl,SLOT(update()));
1062 tubeGroup = new QActionGroup(this);
1063 tubeGroup->addAction(chgl->tubes);
1064 tubeGroup->addAction(chgl->ballStick);
1065 chgl->ballStick->setCheckable(true);
1066 chgl->ballStick->setChecked(true);
1067 connect(chgl->ballStick, SIGNAL(triggered()), chgl, SLOT(makeLegendAtoms()));
1068
1069 chgl->tubes->setCheckable(true);
1070 chgl->tubes->setChecked(false);
1071 connect(chgl->tubes, SIGNAL(triggered()), chgl, SLOT(makeLegendAtoms()));
1072
1073 //printf("line %d\n",__LINE__);
1074 {
1075 QIcon icke=QIcon(theIconPath+"adp.svg");
1076 //icke.addFile(theIconPath+"adp23.svg");
1077 a=chgl->adp =viewMenu->addAction(icke, tr("Toggle ADPs"), chgl, SLOT(update()), QKeySequence("Alt+E"));
1078 connect(chgl->adp, SIGNAL(triggered()), chgl, SLOT(makeLegendAtoms()));
1079 }
1080 a->setCheckable(true);
1081 a->setChecked(true);
1082 vito->addAction(a);
1083 a=togBond =viewMenu->addAction(QIcon(theIconPath+"bonds.svg"),
1084 tr("Toggle Bonds"), chgl, SLOT(setBonds(bool)), QKeySequence("Alt+B"));
1085 a->setCheckable(true);
1086 a->setChecked(true);
1087 vito->addAction(a);
1088 a=togLabel=viewMenu->addAction(QIcon(theIconPath+"labels.svg"),
1089 tr("Toggle Labels"),chgl,SLOT(setLabels(bool)),QKeySequence("Alt+L"));
1090 a->setCheckable(true);
1091 a->setChecked(true);
1092 vito->addAction(a);
1093
1094 //printf("line %d\n",__LINE__);
1095 /*
1096 a=viewMenu->addAction(QIcon(theIconPath+"laplus.svg"),
1097 tr("Increase label fontsize"),chgl,SLOT(incFontSize()),
1098 QKeySequence("Alt++"));
1099 a=viewMenu->addAction(QIcon(theIconPath+"laminus.svg"),
1100 tr("Decrease label fontsize"),chgl,SLOT(decFontSize()),
1101 QKeySequence("Alt+-"));*/
1102
1103 //printf("line %d\n", __LINE__);
1104 a=chgl->togUnit =viewMenu->addAction(QIcon(theIconPath+"unitcell.svg"),
1105 tr("Toggle Unit Cell"),chgl,SLOT(update()),QKeySequence("Alt+C"));
1106 a->setCheckable(true);
1107 a->setChecked(false);
1108 vito->addAction(a);
1109 //printf("line %d %p\n", __LINE__,viewMenu,chgl->h_bonds);
1110 a=chgl->h_bonds=viewMenu->addAction(QIcon(theIconPath+"hbrs.svg"),
1111 tr("Toggle H-bonds"),chgl,SLOT(update()),QKeySequence("Alt+H"));
1112 a->setCheckable(true);
1113 a->setChecked(true);
1114 vito->addAction(a);
1115 //printf("line %d %p %d\n", __LINE__, chgl->h_bonds, chgl->h_bonds->isVisible());
1116 a=chgl->atomLegend=viewMenu->addAction(QIcon(theIconPath+"legend.svg"),
1117 tr("Toggle Atom Legend"),chgl,SLOT(update()), QKeySequence("Alt+K"));
1118 a->setCheckable(true);
1119 a->setChecked(true);
1120 vito->addAction(a);
1121
1122 //printf("line %d\n",__LINE__);
1123 fxle= new FourXle(&mole, chgl, vito);
1124
1125 //printf("line %d\n",__LINE__);
1126 fxle->mapcontrol=dialogMenu->addAction(QIcon(theIconPath+"mapcontrol.svg"),tr("Open Map Control"), fxle, SLOT(openMapControl()));
1127 vito->addAction(fxle->mapcontrol);
1128 fxle->mapcontrol->setVisible(false);
1129 connect(chgl,SIGNAL(destroyed()),fxle ,SLOT(killFourXleFirst()));//maybe tidy up before die
1130 connect(fxle,SIGNAL(reloadRes()),this ,SLOT(loadAFile()));
1131 connect(fxle->jnkButton,SIGNAL(pressed()),this,SLOT(jnk()));
1132 fxle->keepiso = dialogMenu->addAction("Keep Map Iso Values Fixed", fxle, SLOT(keepIsoValues(bool )));
1133 fxle->keepiso->setCheckable(true);
1134 fxle->keepiso->setChecked(fxle->keepIso->isChecked());//diffent CaSe !
1135 /*a=viewMenu->addAction(tr("Toggle MSAA"),chgl,SLOT(setMSAA(bool)),QKeySequence("F4"));
1136 a->setCheckable(true);
1137 a->setChecked(true);*/
1138 a=equivHighlighting=viewMenu->addAction("Highlight Symmetry Equivalents",this,SLOT(toggleEQHighlighting(bool)));
1139 equivHighlighting->setCheckable(true);
1140 equivHighlighting->setChecked(true);
1141 a=togBackGr=viewMenu->addAction(tr("Toggle Background Gradient"), chgl, SLOT(setBGGradient(bool)), QKeySequence("F6"));
1142 a->setCheckable(true);
1143 a->setChecked(true);
1144 viewMenu->addAction(dock->toggleViewAction());
1145 viewMenu->addAction(shxEditorDock->toggleViewAction());
1146 //viewMenu->addAction(chgl->wireButt);
1147 viewMenu->addAction(chgl->rainbowPlot);
1148 /*=togDepthCueing=viewMenu->addAction(tr("toggle DepthCueing (mist)"),chgl,SLOT(setDepthCueing(bool)), QKeySequence(Qt::ALT | Qt::Key_M));//=togDepthCueing
1149 a->setCheckable(true);
1150 a->setChecked(false);*/
1151 //printf("line %d\n",__LINE__);
1152 viewMenu->addSeparator();
1153 ydleStart=viewMenu->addAction("Start rotation", this, SLOT(idleRotStart()), QKeySequence(Qt::ALT | Qt::Key_Y));
1154 ydleStop=viewMenu->addAction("Stop rotation", this, SLOT(idleRotStop()), QKeySequence(Qt::CTRL | Qt::ALT | Qt::Key_Space));
1155 ydleStop->setVisible(false);
1156
1157 QAction *moviMaker = viewMenu->addAction("Create a Rotation Movie", this,SLOT(makeRotMovi()));
1158 moviMaker->setShortcut(Qt::CTRL | Qt::Key_M);
1159
1160 viewMenu->addSeparator();
1161 viewMenu->addAction("Redraw Structure", this, SLOT(effuenf()), QKeySequence("F5"));
1162 viewMenu->addAction("Reload Structure From Current File", this,SLOT(loadAFile()), QKeySequence("Ctrl+F5"));
1163 {
1164 QAction *a=
1165 viewMenu->addAction("Create Voronoi Polyeders of Asymmetric Unit",this,SLOT(makeVoro()));
1166 a->setData(-1);
1167 }
1168 {
1169 QAction *a=clearVoro=
1170 viewMenu->addAction("Remove Voronoi Polyeder(s) ",this,SLOT(clearVoros()));
1171 a->setData(-1);
1172 clearVoro->setVisible(false);
1173 }
1174 //viewMenu->addAction("hide me!",this, SLOT(hide()),QKeySequence("F12"));
1175 //viewMenu->addAction("show must go on!",this, SLOT(show()),QKeySequence("F10"));
1176
1177 if (!QString(PROGRAM_NAME).compare("shelXle"))//olny in standalone shelXle
1178 viewMenu->addAction("Fullscreen Mode", this, SLOT(toggleFullScreen()), QKeySequence("F11"));
1179
1180 }
1181 {
1182 QAction *a;
1183 QToolBar *tb=bottomToolBar= new QToolBar("Atom Selection Tools",this);
1184 tb->setObjectName("AtomTB");
1185 tb->setMovable(false);
1186 tb->setAllowedAreas(Qt::BottomToolBarArea|Qt::TopToolBarArea);
1187 tb->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
1188 QMenu *m= new QMenu("Configure selection toolbar");
1189 a=m->addAction("Text Only",this,SLOT(configureBottomToolbar()));
1190 a->setData(Qt::ToolButtonTextOnly);
1191 a=m->addAction("Icon Only",this,SLOT(configureBottomToolbar()));
1192 a->setData(Qt::ToolButtonIconOnly);
1193 a=m->addAction("Text Beside Icon",this,SLOT(configureBottomToolbar()));
1194 a->setData(Qt::ToolButtonTextBesideIcon);
1195 a=m->addAction("Text Under Icon",this,SLOT(configureBottomToolbar()));
1196 a->setData(Qt::ToolButtonTextUnderIcon);
1197 m->addSeparator();
1198 a=m->addAction("Place on Top",this,SLOT(configureBottomToolbar()));
1199 a->setData(static_cast<int>(Qt::TopToolBarArea) + 32);
1200 a=m->addAction("Place on Bottom",this,SLOT(configureBottomToolbar()));
1201 a->setData(static_cast<int>(Qt::BottomToolBarArea) + 32);
1202 useNativeDlg=dialogMenu->addAction("Use Native Dialog for File Open/Save",this,SLOT(fileNative()));
1203 useNativeDlg->setCheckable(true);
1204 useNativeDlg->setChecked(true);
1205
1206 darkTheme=dialogMenu->addAction("Use Dark Colors Theme",this,SLOT(darkEdit()));
1207 darkTheme->setCheckable(true);
1208 darkTheme->setChecked(false);
1209 if (QString(PROGRAM_NAME).compare("shelXle")){
1210 darkTheme->setVisible(false);
1211 }
1212
1213 a=dialogMenu->addAction(QIcon(theIconPath+"configure-toolbars.svg"),"Configure Selection Toolbar");
1214 a->setToolTip("Configure Selection Toolbar icon/text style");
1215 a->setMenu(m);
1216 chgl->toggleDockWidgets= a = tb->addAction(QIcon(theIconPath+"hidedockwdg.svg"), "Hide Text Windows",this,SLOT(toggDocWid(bool)));
1217 a->setCheckable(true);
1218 a->setChecked(false);
1219 a->setVisible(false);
1220 chgl->toggleOrthoView = a = tb->addAction(QIcon(theIconPath+"ortho.svg"), "Ortho-projection",this,SLOT(toggleOrtho(bool)));
1221 a->setCheckable(true);
1222 a->setChecked(false);
1223 a->setToolTip("toggle Orthographic Projection / Central Perspective Projection");
1224 chgl->grow=a=tb->addAction(QIcon(theIconPath+"grow.svg"),"GROW ",this,SLOT(grow()));
1225 a->setShortcut(Qt::ALT | Qt::Key_G);
1226 packMenu->addAction(a);
1227 a->setToolTip("Complete the Molecule(s)");
1228 a->setVisible(false);
1229 chgl->fuse=a=tb->addAction(QIcon(theIconPath+"fuse.svg"),"FUSE ",this,SLOT(fuse()));
1230 a->setShortcut(Qt::ALT | Qt::Key_F);
1231 packMenu->addAction(a);
1232 a->setVisible(false);
1233 a->setToolTip("Show the Asymmetric Unit Only");
1234 recalcSDM=a=packMenu->addAction(QIcon(theIconPath+"grow.svg"),"Recalculate Distance Matrices",this,SLOT(sdm()));
1235 recalcSDM->setShortcut(Qt::CTRL | Qt::Key_R);
1236 QToolBar *sptb=new QToolBar();
1237 sptb->addAction(recalcSDM);
1238 renamUpdateAct=sptb->addAction("Update RESIdue Class ComboBox",this,SLOT(renamUpdate(bool)));
1239 renamUpdateAct->setCheckable(true);
1240 renamUpdateAct->setChecked(false);
1241 chgl->pickRadSpin=new QDoubleSpinBox(sptb);
1242 chgl->pickRadSpin->setMinimum(5.0);
1243 chgl->pickRadSpin->setMaximum(50.0);
1244 chgl->pickRadSpin->setDecimals(0);
1245 chgl->pickRadSpin->setValue(chgl->pickRad());
1246 chgl->pickRadSpin->setPrefix("pick radius");
1247 chgl->pickRadSpin->setSuffix("px");
1248 connect(chgl->pickRadSpin,SIGNAL(valueChanged(double)),chgl,SLOT(setPickRad(double)));
1249 sptb->addWidget(chgl->pickRadSpin);
1250 rnla->addWidget(sptb);
1251 a=packMenu->addAction("Symmetry Manager",this,SLOT(symmetryManager()));
1252 a->setShortcut(Qt::ALT | Qt::SHIFT | Qt::Key_M);
1253 tb->addAction(enterRenameMode);
1254 enterRenameMode->setIcon(QIcon(theIconPath+"rename.svg"));
1255 enterRenameMode->setVisible(false);
1256 tb->addAction(showQPeakLegend);
1257 showQPeakLegend->setVisible(false);
1258 //printf("line %d\n",__LINE__);
1259 a=tb->addAction(QIcon(theIconPath+"qbond.svg"),"Q-Peak-Bonds",chgl,SLOT(update()));
1260 a->setCheckable(true);
1261 a->setChecked(true);
1262 a->setVisible(false);
1263 chgl->qPeakBonds=a;
1264 sinaAct->setVisible(false);
1265 chgl->addBond=a=tb->addAction(QIcon(theIconPath+"bind.svg"),"Bind Selected Atoms",editor,SLOT(insertBind()));
1266 a->setVisible(false);
1267 chgl->killBond=a=tb->addAction(QIcon(theIconPath+"free.svg"),"Free Selected Atoms",editor,SLOT(insertFree()));
1268 a->setVisible(false);
1269 chgl->clearSelection=a=tb->addAction(QIcon(theIconPath+"deselect.svg"),"Deselect",chgl,SLOT(disSelection()));
1270 a->setVisible(false);
1271 chgl->centroid=a=tb->addAction(QIcon(theIconPath+"centroid.svg"), "Create Centroid", this , SLOT(createCentroid()));
1272 a->setVisible(false);
1273 chgl->cntrPlot = a = tb->addAction(QIcon(theIconPath+"cont.svg"),"Create Contour Plot",this, SLOT(contourPlot()));
1274 a->setVisible(false);
1275 chgl->nocntrPlot = a = tb->addAction(QIcon(theIconPath+"nocont.svg"),"Remove Contour Plot",this, SLOT(nocontourPlot()));
1276 a->setVisible(false);
1277 chgl->centerSelection=a=tb->addAction(QIcon(theIconPath+"center.svg"),"Center Selected Atoms",chgl,SLOT(homeXY()));
1278 a->setCheckable(true);
1279 a->setChecked(false);
1280 a->setVisible(false);
1281 chgl->invSelection=a=tb->addAction(QIcon(theIconPath+"invsel.svg"),"Invert Selection",chgl,SLOT(invertSelection()));
1282 a->setVisible(false);
1283 chgl->hideNotSelection=a=tb->addAction(QIcon(theIconPath+"hide.svg"),"Hide Other Atoms",chgl,SLOT(hideNonSelected()));
1284 a->setVisible(false);
1285 a=chgl->hideHydrogen=tb->addAction(QIcon(theIconPath+"hideh.svg"),"Hide Hydrogen Atoms",chgl,SLOT(hideHydrogens()));
1286 a->setVisible(false);
1287 chgl->unhide=a=tb->addAction(QIcon(theIconPath+"show.svg"),"Show All Hidden",chgl,SLOT(showHidden()));
1288 connect(a,SIGNAL(triggered()),qpv,SLOT(unhide()));
1289 a->setVisible(false);
1290 chgl->invhide=a=tb->addAction(QIcon(theIconPath+"invshow.svg"),"Toggle Visibility ",chgl,SLOT(invertHidden()));
1291 a->setVisible(false);
1292 chgl->shpm1=a=tb->addAction(QIcon(theIconPath+"part-1.svg"),"Hide PART -N Ghost",chgl,SLOT(hidePartMinusOne(bool )));
1293 a->setCheckable(true);
1294 a->setChecked(false);
1295 a->setVisible(false);
1296 a->setToolTip("Hide PART -N symmetry equivalent as ghost Atoms");
1297 //printf("line %d\n",__LINE__);
1298
1299 chgl->highlightParts=a=tb->addAction(QIcon(theIconPath+"parts.svg"),"Highlight PARTs",chgl,SLOT(update()));
1300 a->setCheckable(true);
1301 a->setChecked(false);
1302 a->setVisible(false);
1303 a=chgl->delSelAt = tb->addAction(QIcon(theIconPath+"killselected.svg"),"Delete Selected Atoms",this,SLOT(deleteSelectedAtoms()));
1304 a->setData(-1);
1305 a->setShortcut(Qt::CTRL|Qt::Key_Delete);
1306 a->setVisible(false);
1307 addToolBarBreak();
1308 addToolBar(Qt::TopToolBarArea,tb);
1309 }
1310 {
1311 QAction *a;
1312 a=packMenu->addAction("Pack cell",this,SLOT(fillCell()));
1313 a->setShortcut(Qt::ALT | Qt::SHIFT | Qt::Key_U);
1314 a=packMenu->addAction("Expand all contacts",this,SLOT(expandAll()));
1315 a->setShortcut(Qt::ALT | Qt::SHIFT | Qt::Key_X);
1316 //a=packMenu->addAction("Complete asymmetric unit" ,this,SLOT(grow_plus()));
1317 a=packMenu->addAction("Complete" ,this,SLOT(complete()));
1318 a->setShortcut(Qt::ALT | Qt::SHIFT | Qt::Key_C);
1319 a=packMenu->addAction("Pack inside given limits",this,SLOT(packInLimits()));
1320 a->setShortcut(Qt::ALT | Qt::SHIFT | Qt::Key_I);
1321 }
1322 menuBar()->addMenu(fileMenu);
1323 menuBar()->addMenu(editMenu);
1324 menuBar()->addMenu(dialogMenu);
1325 menuBar()->addMenu(viewMenu);
1326 menuBar()->addMenu(packMenu);
1327 menuBar()->addMenu(runMenu);
1328 menuBar()->addMenu(extraMenu);
1329 fcvsfoAct=fcoMenu->addAction("Fc vs Fo",this,SLOT(foversusfc()));
1330 fcvsfoAct->setDisabled(true);
1331 calcAct=fcoMenu->addAction("Crystallographic Calculator",this,SLOT(calculator()));
1332 calcAct->setEnabled(true);
1333 fcoMenu->addAction("Fractal Dimension Analysis (Henn-Meindl-plot)",this,SLOT(jnk()));
1334 fcoMenu->addAction("Plot Atomic Scattering Factors SFAC ", editor, SLOT(plotSFAC()));
1335 dsrAct = fcoMenu->addAction("DSR Plugin",this,SLOT(create_DSRGui()));
1336 dsrAct->setEnabled(true);
1337 dsrAct->setShortcut(Qt::ALT | Qt::Key_D);
1338 menuBar()->addMenu(fcoMenu);
1339 //printf("line %d\n",__LINE__);
1340
1341
1342 {
1343 helpMenu = new QMenu(tr("Help"), this);
1344 menuBar()->addMenu(helpMenu);
1345 helpMenu->addAction("Help ", this, SLOT(linkHelp()));
1346 helpMenu->addAction(QWhatsThis::createAction(this));
1347 helpMenu->addAction(tr("About"), this, SLOT(aboutXLE()));
1348 helpMenu->addAction(tr("About &Qt"), qApp, SLOT(aboutQt()));
1349 helpMenu->addAction("Check for New Versions Now",this,SLOT(checkForUpdates()));
1350 helpMenu->addAction("Show Key Bindings", this, SLOT(hereAreMyKeys()));
1351 }
1352
1353 chgl->rCenter = new QToolButton();
1354 chgl->rCenter->setText("Reset Rotation Center");
1355 connect(chgl->rCenter,SIGNAL(clicked()), chgl,SLOT( rotCenter()));
1356 chgl->rCenter->hide();
1357
1358 chgl->invertMouseZoom = new QToolButton(this);
1359 chgl->invertMouseZoom->setIcon(QIcon(theIconPath+"invzoom.svg"));
1360 chgl->invertMouseZoom->setCheckable(true);
1361 chgl->invertMouseZoom->setChecked(false);
1362 chgl->invertMouseZoom->setText("Invert Mouse Zoom");
1363 chgl->invertMouseZoom->setToolTip("invert mouse zoom (right mouse click and drag up or down");
1364
1365 //*
1366 quickReLoadButton = new QToolButton(this);
1367 QIcon qrlic =QIcon();
1368 qrlic.addFile(theIconPath+"quick-re-load.png",QSize(), QIcon::Normal, QIcon::Off );
1369 qrlic.addFile(theIconPath+"quick-re-load_on.png",QSize(), QIcon::Normal, QIcon::On );
1370 quickReLoadButton->setIcon(qrlic);
1371 quickReLoadButton->setCheckable(true);
1372 //Too many problems with this feature 11.03.2021
1373 quickReLoadButton->setChecked(false);
1374 quickReLoadButton->hide();
1375 quickReLoadButton->setText("Enable QuickReLoad");
1376 quickReLoadButton->setToolTip("QuickReLoad updates the structure instead of fresh reloading it");
1377 //*/
1378 homeMe = new QToolButton(this);
1379 homeMe->setIcon(QIcon(theIconPath+"home.svg"));
1380 homeMe->setText("home");
1381 homeMe->setToolTip("move molecules home");
1382 connect(homeMe,SIGNAL(clicked()),chgl,SLOT(homeXY()));
1383 qGrowPeak = new QCheckBox("grow Q-peaks");
1384 connect(qGrowPeak,SIGNAL(toggled(bool)),this,SLOT(growQPeaks(bool)));
1385 search4duplicates = new QCheckBox("search for duplicates");
1386 search4duplicates->setChecked(true);
1387 connect(search4duplicates,SIGNAL(toggled(bool)),this,SLOT(duplicates()));
1388 //printf("line %d\n",__LINE__);
1389
1390 sLabel = new QLabel;
1391 sLabel->setFrameStyle(QFrame::Panel );
1392 sLabel->setLineWidth(2);
1393 sLabel->setText(QString("%1").arg(PROGRAM_NAME));
1394 zoomIn = new QToolButton (this);
1395 zoomIn-> setIcon(QIcon(theIconPath+"zoom-in.svg"));
1396 zoomIn->setText("Zoom +");
1397 zoomIn->setToolTip("Zoom +");
1398 zoomIn->setAutoRepeat(true);
1399 zoomIn->setAutoRepeatDelay(150);
1400 zoomIn->setAutoRepeatInterval(3);
1401 zoomOut = new QToolButton(this);
1402 zoomOut->setIcon(QIcon(theIconPath+"zoom-out.svg"));
1403 zoomOut->setText("Zoom -");
1404 zoomOut->setToolTip("Zoom -");
1405 zoomOut->setAutoRepeat(true);
1406 zoomOut->setAutoRepeatDelay(150);
1407 zoomOut->setAutoRepeatInterval(3);
1408 connect(zoomIn,SIGNAL(pressed ()),this,SLOT(zoomin()));
1409 connect(zoomOut,SIGNAL(pressed ()),this,SLOT(zoomout()));
1410 //connect(chgl,SIGNAL(no_hw_st()),no_stereo,SLOT(toggle()));
1411 fvused = new QLabel("");
1412
1413 QCheckBox *autoupdate = new QCheckBox("?FPS?");
1414 autoupdate->setChecked(false);
1415 connect(autoupdate, &QCheckBox::stateChanged, chgl, &PlayOpenGL::toggleAutoUpdate);
1416
1417 lodsp = new QSpinBox();
1418 lodsp->setPrefix("LOD = ");
1419 lodsp->setRange(2, 8);
1420 lodsp->setValue(chgl->mol->LOD);
1421 #if (QT_VERSION >= 0x050f10)
1422 connect(lodsp, &QSpinBox::valueChanged, chgl, &PlayOpenGL::setLOD);
1423 #else
1424 connect(lodsp, SIGNAL(valueChanged(int)), chgl, SLOT(setLOD(int)));
1425 #endif
1426
1427 statusBar();
1428 statusBar()->addPermanentWidget(fvused);
1429 statusBar()->addPermanentWidget(autoupdate);
1430 statusBar()->addPermanentWidget(lodsp);
1431 //statusBar()->addPermanentWidget(chgl->pickRadSpin);
1432 statusBar()->addPermanentWidget(chgl->rCenter);
1433 statusBar()->addPermanentWidget(chgl->enviButt);
1434 statusBar()->addPermanentWidget(chgl->enviSelect);
1435 statusBar()->addPermanentWidget(qGrowPeak);
1436 statusBar()->addPermanentWidget(search4duplicates);
1437 statusBar()->addPermanentWidget(zoomIn);
1438 statusBar()->addPermanentWidget(zoomOut);
1439 statusBar()->addPermanentWidget(homeMe);
1440 statusBar()->addPermanentWidget(chgl->invertMouseZoom);
1441 statusBar()->addPermanentWidget(quickReLoadButton);
1442 statusBar()->addPermanentWidget(fxle->keepIso);
1443 statusBar()->addPermanentWidget(fxle->doMaps);
1444 statusBar()->addPermanentWidget(fxle->ownfcf6);
1445 QCheckBox *hideToolBars = new QCheckBox("Hide Tool Bars");
1446 hideToolBars->setChecked(false);
1447 connect(hideToolBars,SIGNAL(toggled(bool)),this,SLOT(hideToolz(bool)));
1448 statusBar()->addPermanentWidget(hideToolBars);
1449 statusBar()->addPermanentWidget(sLabel);
1450 connect(fxle,SIGNAL(bigmessage(const QString&)),this,SLOT(infoKanalNews(const QString&)));
1451 shxEditorDock->hide();
1452 printf("now settings\n");
1453 ////////////////////////////// SETTINGS /////////////////////////////////////////////////////////////////////////
1454
1455 mole.loadSettings();
1456 einstellung->beginGroup("Window");
1457 useNativeDlg->setChecked(einstellung->value("nativeDialogs",true).toBool());
1458 chgl->invertMouseZoom->setChecked( einstellung->value("InvertMouseZoom").toBool());
1459 //Too many issues with this feature 11.03.2021
1460 //quickReLoadButton->setChecked( einstellung->value("QuickReLoad",true).toBool());
1461 //connect(quickReLoadButton, SIGNAL(toggled(bool)), this, SLOT(loadAFile()));
1462 bool bbb=true;
1463 chgl->SDM_Limit=einstellung->value("SDM-LIMIT", 350).toInt();
1464 if (einstellung->contains("HighlightEquivalents")){
1465 bool bb;
1466 equivHighlighting->setChecked(bb=einstellung->value("HighlightEquivalents").toBool());
1467 mole.highlightEquivalents=bb;
1468 }
1469 //printf("line %d\n",__LINE__);
1470 if (einstellung->contains("ADPs"))
1471 chgl->adp->setChecked(bbb=einstellung->value("ADPs").toBool());
1472 if (einstellung->contains("Tubes"))
1473 chgl->tubes->setChecked(bbb=einstellung->value("Tubes").toBool());
1474 if (einstellung->contains("Legend"))
1475 chgl->atomLegend->setChecked(einstellung->value("Legend").toBool());
1476 if (einstellung->contains("ShowLabels"))
1477 togLabel->setChecked(bbb=einstellung->value("ShowLabels").toBool());
1478 chgl->setLabels(togLabel->isChecked());
1479
1480 //printf("line %d\n",__LINE__);
1481 if (einstellung->contains("ShortLabels"))
1482 chgl->shortLabels->setChecked(bbb=einstellung->value("ShortLabels").toBool());
1483 if (einstellung->contains("BackGroundGradient"))
1484 togBackGr->setChecked(bbb=einstellung->value("BackGroundGradient").toBool());
1485 chgl->setBGGradient(togBackGr->isChecked());
1486 /*
1487 if (einstellung->contains("WireModelOnRotate"))
1488 chgl->wireButt->setChecked(einstellung->value("WireModelOnRotate").toBool());
1489 */
1490 shelxlPath="shelxl";
1491 if (einstellung->contains("SHELXL-PATH"))
1492 shelxlPath=einstellung->value("SHELXL-PATH").toString();
1493 shelxlArgs="";
1494 if (einstellung->contains("SHELXL-OPTION"))
1495 shelxlArgs=einstellung->value("SHELXL-OPTION").toString();
1496 useMyBArray = false; // If true, ShelXle does not override b-array value
1497 if (einstellung->contains("SHELXL-BARRAY")) {
1498 useMyBArray=einstellung->value("SHELXL-BARRAY").toBool();
1499 }
1500 einstellung->endGroup();
1501
1502 //printf("line %d\n",__LINE__);
1503 einstellung->beginGroup("Files");
1504 dirName = einstellung->value("lastFile").toString();
1505
1506 QStringList files = einstellung->value("recentFileList").toStringList();
1507 foreach (QWidget *widget, QApplication::topLevelWidgets()) {
1508 Window *mainWin = qobject_cast<Window *>(widget);
1509 if (mainWin)
1510 mainWin->updateRecentFileActions();
1511 }
1512
1513 einstellung->endGroup();
1514 einstellung->beginGroup("Colors");
1515 chgl->backGroundColor=einstellung->value("BackGroundColor",QColor("lightskyblue")).value<QColor>();
1516 chgl->labelColor=einstellung->value("LabelColor").value<QColor>();
1517 chgl->labelBGColor = einstellung->value("LabelBGColor", QColor(0,0,0,0)).value<QColor>();
1518 chgl->focusedLabelBGColor = einstellung->value("focusedLabelBGColor", QColor(0,0,0,10)).value<QColor>();
1519 chgl->focusedLabelColor = einstellung->value("focusedLabelColor", QColor(255,255,0,255)).value<QColor>();
1520 chgl->selectedLabelBGColor = einstellung->value("selectedLabelBGColor", QColor(0,0,0,51)).value<QColor>();
1521 chgl->selectedLabelColor = einstellung->value("selectedLabelColor", QColor(135, 206, 235 ,255)).value<QColor>();
1522 /*printf("alphas %x %x %x %x %x %X",
1523 chgl->labelBGColor.alpha(),
1524 chgl->focusedLabelBGColor.alpha(),
1525 chgl->selectedLabelBGColor.alpha(),
1526 chgl->selectedLabelColor.alpha(),
1527 chgl->focusedLabelColor.alpha(),
1528 QColor(0u).alpha());*/
1529 if (QString(PROGRAM_NAME).compare("shelXle")==0){
1530 darkTheme->setChecked(einstellung->value("darkTheme","false").toBool());
1531 }
1532 darkEdit();
1533 einstellung->endGroup();
1534 int ignore=QMessageBox::Yes;
1535 einstellung->beginGroup("Updates");
1536 if (einstellung->contains("IgnoreUpdates"))
1537 ignore=einstellung->value("IgnoreUpdates").toInt();
1538 einstellung->endGroup();
1539 net = new QNetworkAccessManager(this);
1540 if (ignore!=QMessageBox::No){
1541 connect(net, SIGNAL(finished(QNetworkReply*)), this, SLOT(replyFinished(QNetworkReply*)));
1542 reply = net->get(QNetworkRequest(QUrl("http://shelxle.org/shelx/revision.php")));
1543 }
1544 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1545
1546
1547 extraProgramNames.clear();
1548 extraProgramPaths.clear();
1549 extraArguments.clear();
1550 extraExtensions.clear();
1551 extraResIns.clear();
1552 extraOpenFileDialogBefore.clear();
1553 extraIconOverlay.clear();
1554 extraOverlayPointSize.clear();
1555 einstellung->beginGroup("Extra");
1556 int siz=0;
1557 siz=einstellung->beginReadArray("ProgramNames");
1558 for (int i = 0; i < siz; i++) {
1559 einstellung->setArrayIndex(i);
1560 extraProgramNames.append(einstellung->value("Name","").toString());
1561 }
1562 einstellung->endArray();
1563 einstellung->endGroup();
1564
1565 einstellung->beginGroup("Extra");
1566 einstellung->beginReadArray("ProgramPaths");
1567 for (int i = 0; i < siz; i++) {
1568 einstellung->setArrayIndex(i);
1569 extraProgramPaths.append(einstellung->value("Path","").toString());
1570 }
1571 einstellung->endArray();
1572 einstellung->endGroup();
1573
1574 einstellung->beginGroup("Extra");
1575 einstellung->beginReadArray("ProgramArgs");
1576 for (int i = 0; i < siz; i++) {
1577 einstellung->setArrayIndex(i);
1578 extraArguments.append((Qt::CheckState) einstellung->value("Arg").toInt());
1579 }
1580 einstellung->endArray();
1581 einstellung->endGroup();
1582
1583 einstellung->beginGroup("Extra");
1584 einstellung->beginReadArray("ProgramExtensions");
1585 for (int i = 0; i < siz; i++) {
1586 einstellung->setArrayIndex(i);
1587 extraExtensions.append((Qt::CheckState)einstellung->value("Ext",0).toInt());
1588 }
1589 einstellung->endArray();
1590 einstellung->endGroup();
1591
1592 einstellung->beginGroup("Extra");
1593 einstellung->beginReadArray("ProgramResIns");
1594 for (int i = 0; i < siz; i++) {
1595 einstellung->setArrayIndex(i);
1596 extraResIns.append((Qt::CheckState)einstellung->value("Res2Ins",0).toInt());
1597 }
1598 einstellung->endArray();
1599 einstellung->endGroup();
1600
1601
1602 einstellung->beginGroup("Extra");
1603 einstellung->beginReadArray("FileDialog");
1604 for (int i = 0; i < siz; i++) {
1605 einstellung->setArrayIndex(i);
1606 extraOpenFileDialogBefore.append((Qt::CheckState)einstellung->value("fd",0).toInt());
1607 }
1608 einstellung->endArray();
1609 einstellung->endGroup();
1610
1611
1612 einstellung->beginGroup("Extra");
1613 einstellung->beginReadArray("IconOverlay");
1614 for (int i = 0; i < siz; i++) {
1615 einstellung->setArrayIndex(i);
1616 extraIconOverlay.append((Qt::CheckState)einstellung->value("icov",2).toInt());
1617 }
1618 einstellung->endArray();
1619 einstellung->endGroup();
1620
1621 einstellung->beginGroup("Extra");
1622 einstellung->beginReadArray("OverlayPointSize");
1623 for (int i = 0; i < siz; i++) {
1624 einstellung->setArrayIndex(i);
1625 extraOverlayPointSize.append(einstellung->value("icov",36).toInt());
1626 }
1627 einstellung->endArray();
1628 einstellung->endGroup();
1629
1630 einstellung->beginGroup("Extra");
1631 einstellung->beginReadArray("AltExtraIconPaths");
1632 for (int i = 0; i < siz; i++) {
1633 einstellung->setArrayIndex(i);
1634 altExtraIconPaths.append(einstellung->value("altIcon","").toString());
1635 }
1636 einstellung->endArray();
1637 einstellung->endGroup();
1638
1639 einstellung->beginGroup("Extra");
1640 einstellung->beginReadArray("ProgramDetached");
1641 for (int i = 0; i < siz; i++) {
1642 einstellung->setArrayIndex(i);
1643 extraDetach.append((Qt::CheckState)einstellung->value("Detach",0).toInt());
1644 }
1645 einstellung->endArray();
1646 einstellung->endGroup();
1647
1648 einstellung->beginGroup("Extra");
1649 einstellung->beginReadArray("AlternativeExtensions");
1650 for (int i = 0; i < siz; i++) {
1651 einstellung->setArrayIndex(i);
1652 extraExt2.append(einstellung->value("ext","").toString());
1653 }
1654 einstellung->endArray();
1655 einstellung->endGroup();
1656
1657 einstellung->beginGroup("Extra");
1658 einstellung->beginReadArray("CommandLineOptions");
1659 for (int i = 0; i < siz; i++) {
1660 einstellung->setArrayIndex(i);
1661 extraOptions.append(einstellung->value("opt","").toString());
1662 }
1663 einstellung->endArray();
1664 einstellung->endGroup();
1665
1666
1667 einstellung->beginGroup("Extra");
1668 einstellung->beginReadArray("AbsolutePathRequired");
1669 for (int i = 0; i < siz; i++) {
1670 einstellung->setArrayIndex(i);
1671 extraAbsolutePath.append(static_cast<Qt::CheckState>(einstellung->value("absolute",0).toInt()));
1672 }
1673 einstellung->endArray();
1674 einstellung->endGroup();
1675
1676 /*
1677 einstellung->beginGroup("SaveHint");
1678 if (einstellung->contains("ShowRenameHint"))
1679 hintL->setVisible(einstellung->value("ShowRenameHint").toBool());
1680 einstellung->endGroup();
1681 */
1682 hintL->hide();
1683 {
1684 extraMenu->addAction("add or remove external programs",this,SLOT(extraSettings()));
1685 }
1686 if (extraProgramNames.size()) extraMenu->addSeparator();
1687 QFileIconProvider *epic = new QFileIconProvider();
1688 extraTB= new QToolBar("External Program Tool Bar",this);
1689 extraTB->setObjectName("ExtraTB");
1690 extraTB->setToolButtonStyle(Qt::ToolButtonIconOnly);
1691 for (int i=0; i<extraProgramNames.size(); i++){
1692 QAction *a;
1693 QString icopa=extraProgramPaths.at(i);
1694 QIcon ico = epic->icon(QFileInfo(icopa));
1695 //qDebug()<<ico.availableSizes()<<ico.actualSize(QSize(32,32));
1696 QPixmap fmap = ico.pixmap(32,32);
1697 if (QFile::exists(altExtraIconPaths.at(i))) fmap=QIcon(altExtraIconPaths.at(i)).pixmap(64,64);
1698 if (extraIconOverlay.at(i)==Qt::Checked){
1699 QPainter *paint = new QPainter(&fmap);
1700 paint->setPen(QPen(QColor("#FFFFFF")));
1701 QFont ifont=chgl->myFont;
1702 ifont.setPixelSize(qMax(extraOverlayPointSize.at(i)*fmap.height()/64,2));
1703 paint->setFont(ifont);
1704 paint->drawText(1,fmap.height()-5,extraProgramNames.at(i));
1705 paint->setPen(QPen(QColor("#000000")));
1706 paint->drawText(0,fmap.height()-4,extraProgramNames.at(i));
1707 paint->end();
1708 }
1709 extraIcon=QIcon(fmap);
1710 a=extraMenu->addAction(extraIcon,QString("run %1 !").arg(extraProgramNames.at(i)),this,SLOT(runExtra()));
1711 a->setData(i);
1712 extraTB->addAction(a);
1713 }
1714 delete epic;
1715 addToolBar(extraTB);
1716 extraOutput = new QDialog(this);
1717 lt = new QVBoxLayout();
1718 extraOutPut = new QTextEdit();
1719 QFont mospfo(FONTFAM);
1720 extraOutPut->setFont(mospfo);
1721 #if (QT_VERSION >=0x050000)
1722 extraOutput->setMinimumWidth(
1723 QFontMetrics(extraOutPut->font())
1724 .horizontalAdvance("###########################################################################################"));
1725 #else
1726 extraOutput->setMinimumWidth(
1727 QFontMetrics(extraOutPut->font())
1728 .width("###########################################################################################"));
1729 #endif
1730 extraOutPut->setLineWrapMode(QTextEdit::NoWrap);
1731 lt->addWidget(extraOutPut);
1732 extraOutput->setLayout(lt);
1733
1734 #if defined (Q_OS_MAC)
1735 //printf("%d\n",__LINE__);
1736 setCentralWidget(container);
1737 #else
1738 setCentralWidget(chgl);
1739 #endif
1740 //chgl->setMSAA(true);
1741 // chgl->update();
1742 //printf("%d\n",__LINE__);
1743 einstellung->beginGroup("Window");
1744 bool EditorHasOwnToolBar = einstellung->value("EditorHasOwnToolBar",false).toBool();
1745 if (EditorHasOwnToolBar) shxMW->addToolBar(editToolBar);
1746 else addToolBar(editToolBar);
1747 adoptAct->setChecked(EditorHasOwnToolBar);
1748 QByteArray ba,ba_state = einstellung->value("state").toByteArray();
1749 bool ba_state_ok = false;
1750 if (!ba_state.isEmpty()) ba_state_ok = restoreState(ba_state);
1751 printf("ba_state_ok ? %d \n",ba_state_ok);
1752 QByteArray estate = einstellung->value("EditorState").toByteArray();
1753 if (!estate.isEmpty()) {
1754 printf("<< %s %d\n",editor->font().family().toStdString().c_str(),editor->font().pointSize());
1755 shxMW->restoreState(estate);
1756 printf(">> %s %d\n",editor->font().family().toStdString().c_str(),editor->font().pointSize());
1757 printf("state: %d\n", estate.size());
1758 //qDebug()<<estate;
1759 }
1760 ba=einstellung->value("geometry").toByteArray();
1761 //qDebug()<<ba.toHex()<<"##"<<ba_state.toHex();
1762 bool geook=false;
1763 if (!ba.isEmpty()) geook=restoreGeometry(ba);
1764 else {
1765 QSize size ;
1766 size=QSize(640,480);
1767 ediSize=QSize(640,480);
1768 ediPos=QPoint(0,0);
1769 if ((size.height())<45||(size.width()<108)) size=QSize(640,480);
1770 QPoint pos;
1771 pos=QPoint(1,1);
1772 move(pos);
1773 if(size.isNull())
1774 resize(640, 480);
1775 else
1776 resize(size);
1777 }
1778 if (!geook){
1779 printf("Geometry in ini was not ok?\n");
1780 QSize size ;
1781 #if (QT_VERSION >=0x050000)
1782 size=QSize(screen->geometry().width()-2,screen->geometry().height()-2);
1783 #else
1784 size=QSize(QApplication::desktop()->screenGeometry().width()-2,QApplication::desktop()->screenGeometry().height()-2);
1785 #endif
1786 ediSize=QSize(640,480);
1787 ediPos=QPoint(0,0);
1788 if ((size.height())<45||(size.width()<108)) size=QSize(640,480);
1789 QPoint pos;
1790 pos=QPoint(1,1);
1791 move(pos);
1792 if(size.isNull())
1793 resize(640, 480);
1794 else
1795 resize(size);
1796 }
1797 einstellung->endGroup();
1798 //printf("%d\n",__LINE__);
1799
1800 einstellung->beginGroup("Fonts");
1801 if (einstellung->contains("LabelFont")){
1802 chgl->myFont = einstellung->value("LabelFont").value<QFont>();
1803 chgl->myFont.setPointSize(einstellung->value("LabelFontSize", 24).toInt());
1804 }
1805 if (einstellung->contains("EditorFont")){
1806 QFont fnt;
1807 int id = QFontDatabase::addApplicationFont(theIconPath+"SourceCodePro-Regular.ttf");
1808 QString family = QFontDatabase::applicationFontFamilies(id).at(0);
1809 fnt = QFont(family);
1810 fnt = einstellung->value("EditorFont").value<QFont>();
1811 //editor->setFont(fnt);
1812 //QFontInfo finfo(fnt);
1813 /*if (!fnt.exactMatch()){
1814 printf("Font family; Point size; Pixel size; Style hint; Font weight; Font style; "
1815 "Underline; Strike out; Fixed pitch; Always 0; Capitalization; Letter spacing; "
1816 "Word spacing; Stretch; Style strategy; Font style (omitted when unavailable)\n");
1817 printf("Font: %s\nFont: %s\n", fnt.toString().toStdString().c_str(), editor->font().toString().toStdString().c_str());
1818 //qDebug()<<fnt.substitutions();
1819 int id = QFontDatabase::addApplicationFont(theIconPath+"SourceCodePro-Regular.ttf");
1820 QString family = QFontDatabase::applicationFontFamilies(id).at(0);
1821 fnt = QFont(family);
1822 printf("Font: %s\nFont: %s\n", fnt.toString().toStdString().c_str(), editor->font().toString().toStdString().c_str());
1823
1824 }else printf("font fits\n"); */
1825 int fosi = einstellung->value("EditorFontSize", 10).toInt();
1826 fnt.setPointSize(fosi);
1827 //#if (QT_VERSION >= 0x040700)
1828 // fnt.setStyleStrategy(QFont::ForceIntegerMetrics);//not a member anymore
1829 //#endif
1830 editor->setFont(fnt);
1831 printf("Font: %s\nFont: %s\n", fnt.toString().toStdString().c_str(), editor->font().toString().toStdString().c_str());
1832 xlPutor->setFont(fnt);
1833 printf("Font from settings %s %d\n", fnt.family().toStdString().c_str(),fnt.pointSize());
1834 }
1835 einstellung->endGroup();
1836
1837
1838 einstellung->beginGroup("ToolBar");
1839 if (einstellung->contains("SelectionToolBarStyle"))
1840 bottomToolBar->setToolButtonStyle((Qt::ToolButtonStyle) einstellung->value("SelectionToolBarStyle").toInt());
1841 einstellung->endGroup();
1842 einstellung->beginGroup("DoNotAskFileSave");
1843 if (einstellung->contains("DoNotAnnoyMe"))
1844 doNotAnnoyMe=einstellung->value("DoNotAnnoyMe",false).toBool();
1845 einstellung->endGroup();
1846 einstellung->beginGroup("Sorting");
1847 if (einstellung->contains("SortingOption")){
1848 editor->sortierWeise = einstellung->value("SortingOption").toInt();
1849 }
1850 einstellung->endGroup();
1851 //printf("%d\n",__LINE__);
1852
1853 {
1854 sortGroup = new QActionGroup(this);
1855 sortMenu = new QMenu("Change sort order",this);
1856 QAction *a = sortMenu->addAction("label number > atomic number > label suffix");
1857 sortGroup->addAction(a);
1858 a->setCheckable(true);
1859 if (editor->sortierWeise==1)a->setChecked(true);
1860 a->setData(1);
1861 a = sortMenu->addAction("atomic number > label number > label suffix");
1862 sortGroup->addAction(a);
1863 a->setCheckable(true);
1864 if (editor->sortierWeise==2)a->setChecked(true);
1865 a->setData(2);
1866 a = sortMenu->addAction("SFAC number > label number > label suffix");
1867 sortGroup->addAction(a);
1868 a->setCheckable(true);
1869 if (editor->sortierWeise==3)a->setChecked(true);
1870 a->setData(3);
1871 a = sortMenu->addAction("label suffix > atomic number > label number");
1872 sortGroup->addAction(a);
1873 a->setCheckable(true);
1874 if (editor->sortierWeise==4)a->setChecked(true);
1875 a->setData(4);
1876 a = sortMenu->addAction("fragment> atomic number > label number > label suffix");
1877 sortGroup->addAction(a);
1878 a->setCheckable(true);
1879 if (editor->sortierWeise==5)a->setChecked(true);
1880 a->setData(5);
1881
1882
1883 a = sortMenu->addAction("U equivalent");
1884 sortGroup->addAction(a);
1885 a->setCheckable(true);
1886 if (editor->sortierWeise==6)a->setChecked(true);
1887 a->setData(6);
1888 connect(sortGroup,SIGNAL(triggered(QAction*)), editor,SLOT(changeSortierWeise(QAction*)));
1889 runMenu->insertMenu(soact,sortMenu);
1890 }
1891 einstellung->beginGroup("Labeling");
1892 if (einstellung->contains("AutoUnused")){
1893 rufModeBox->setChecked(einstellung->value("AutoUnused").toBool());
1894 }
1895 einstellung->endGroup();
1896 tbiconSize=32;
1897 einstellung->beginGroup("ToolBarIcons");
1898 if (einstellung->contains("ToolBarIconSize")){
1899 tbiconSize=einstellung->value("ToolBarIconSize").toInt();
1900 }
1901 einstellung->endGroup();
1902 tbiconSize=qMin(tbiconSize,96);
1903 tbiconSize=qMax(tbiconSize,16);
1904 fito->setIconSize(QSize(tbiconSize,tbiconSize));
1905 editToolBar->setIconSize(QSize(tbiconSize,tbiconSize));
1906 refineToolBar->setIconSize(QSize(tbiconSize,tbiconSize));
1907 vito->setIconSize(QSize(tbiconSize,tbiconSize));
1908 extraTB->setIconSize(QSize(tbiconSize,tbiconSize));
1909 bottomToolBar->setIconSize(QSize(tbiconSize,tbiconSize));
1910 chgl->invertMouseZoom->setIconSize(QSize(tbiconSize,tbiconSize));
1911 quickReLoadButton->setIconSize(QSize(tbiconSize,tbiconSize));
1912 homeMe->setIconSize(QSize(tbiconSize,tbiconSize));
1913 zoomIn->setIconSize(QSize(tbiconSize,tbiconSize));
1914 zoomOut->setIconSize(QSize(tbiconSize,tbiconSize));
1915 ///
1916 {
1917 scalDlg = new QDialog(this);
1918 scalDlg->setWindowTitle("Change screen-shot scalefactor");
1919 scalla = new QGridLayout();
1920 scalwla = new QLabel("Width: ");
1921 scalhla = new QLabel("Height: ");
1922 scalsla = new QLabel("Scalefactor: ");
1923 widthBox = new QSpinBox();
1924 heightBox = new QSpinBox();
1925 scalefBox = new QDoubleSpinBox();
1926 widthBox->setMinimum(32);
1927 widthBox->setMaximum(10000);
1928 widthBox->setSuffix(" pixels");
1929 widthBox->setObjectName("widthBox");
1930 heightBox->setMinimum(32);
1931 heightBox->setMaximum(10000);
1932 heightBox->setSuffix(" pixels");
1933 heightBox->setObjectName("heightBox");
1934 scalefBox->setMinimum(1);
1935 scalefBox->setMaximum(400.0);
1936 scalefBox->setSuffix(" %");
1937 scalefBox->setValue(scalePic*100.0);
1938 scalefBox->setObjectName("scalefBox");
1939 header = new QLabel("<h3>Change screen-shot scalefactor</h3>");
1940 scalla->addWidget(header ,0,0,1,3);
1941 scalla->addWidget(scalwla ,1,0);
1942 scalla->addWidget(widthBox ,1,1);
1943 scalla->addWidget(scalhla ,2,0);
1944 scalla->addWidget(heightBox,2,1);
1945 scalla->addWidget(scalsla ,3,0);
1946 scalla->addWidget(scalefBox,3,1);
1947 scalDlg->setLayout(scalla);
1948 scalDlg->hide();
1949 connect(widthBox,SIGNAL(valueChanged(int)),this,SLOT(updateScaleDlg()));
1950 connect(heightBox,SIGNAL(valueChanged(int)),this,SLOT(updateScaleDlg()));
1951 connect(scalefBox,SIGNAL(valueChanged(double)),this,SLOT(updateScaleDlg()));
1952 }
1953 /////////////
1954 toggDocWid(true);
1955 raise();
1956 double vang=0;
1957
1958 #if (QT_VERSION >= 0x040600)
1959 dirName = (QProcessEnvironment::systemEnvironment ().value("PWD",dirName));
1960 #else
1961 {
1962 QStringList env = QProcess::systemEnvironment();
1963 int da = env.indexOf(QRegularExpression("^PWD=.*$"));
1964 if (da>-1) {
1965 dirName = QString(env.at(da)).remove(0,4);
1966 }
1967 }
1968 #endif
1969 QString ffna="";
1970 startFused=false;
1971 int argc=QCoreApplication::arguments().size();
1972 if (argc>1){
1973 for (int i=1;i<argc;i++){
1974 if ((QCoreApplication::arguments().at(i)=="-fcf6")) fxle->MYFCF=true;
1975 if ((QCoreApplication::arguments().at(i).endsWith(".ins",Qt::CaseInsensitive)) ||
1976 (QCoreApplication::arguments().at(i).endsWith(".res",Qt::CaseInsensitive)))
1977 ffna=QCoreApplication::arguments().at(i);
1978 if ((QCoreApplication::arguments().at(i)=="-fused")) startFused=true;
1979 if ((QCoreApplication::arguments().at(i)=="-HKLMAX")) fxle->HKLMX = QCoreApplication::arguments().at(i+1).toInt();
1980 if ((QCoreApplication::arguments().at(i)=="-viewangle")) vang = QCoreApplication::arguments().at(i+1).toDouble();
1981 if ((QCoreApplication::arguments().at(i)=="-voxel")) fxle->voxelstr = QCoreApplication::arguments().at(i+1);
1982 if ((QCoreApplication::arguments().at(i)=="-shaderInfo")) shaderInfo=true;
1983 //if ((QCoreApplication::arguments().at(i)=="-wt")) { chgl->dratpause = QCoreApplication::arguments().at(i+1).toInt();}
1984 }
1985 }
1986
1987 //printf("%d\n",__LINE__);
1988 //chgl->update();
1989 //if (vang>0.0) chgl->setViewAngle(vang);
1990
1991 einstellung->beginGroup("ViewSettings");
1992 if (einstellung->contains("OrthographicProjection")) {
1993 bool b=einstellung->value("OrthographicProjection").toBool();
1994 chgl->toggleOrthoView->setChecked(b);
1995 chgl->toggleOrtho(b);
1996 //toggleOrtho(b);
1997 }
1998 einstellung->endGroup();
1999 //printf("%d\n",__LINE__);
2000
2001 qPeakDock->setVisible(true);
2002 shxEditorDock->hide();
2003 shxOutputDock->hide();
2004 if (!ffna.isEmpty()) {
2005 dirName=ffna;
2006 printf("I will load this: %s.\n",ffna.toStdString().c_str());
2007 //connect(chgl, SIGNAL(initialized()), this, SLOT(loadAFile()));
2008 connect(chgl, SIGNAL(initialized()), this, SLOT(delayedLoad()));
2009 }
2010 printf("Window constructor finished.\n");
2011 #include "WhatsThisAndWhere.h"
2012 lastDirName="";
2013 //printf("%d\n",__LINE__);
2014
2015 }
2016
2017 Window::~Window() {
2018 //printf("close?? this %p calcmenu %p dsr %p sortmenu%p hidwillpse %p fxle%p chgl%p\n", this,calcmenu,dsr,sortMenu,hidwillpse,fxle,chgl);
2019 if (fxle!=NULL) delete fxle;
2020 //printf("OK!%d\n",__LINE__);
2021 if (calcmenu!=NULL) {
2022 calcmenu->close();
2023 delete calcmenu;//only delete it if it has been created. (seg fault)
2024 }
2025 if (dsr!=NULL) {
2026 dsr->close();
2027 delete dsr;
2028 }
2029 //printf("OK!%d\n",__LINE__);
2030 }
2031
2032 int Window::Version(){
2033 return Revision;
2034 }
2035
2036 void Window::hereAreMyKeys(){
2037 actionInfo.clear();
2038 actionInfo.append("<table>");
2039 QWidgetList wl = QApplication::allWidgets();
2040 QStringList shorts;
2041 for (int i=0; i<wl.size(); i++){
2042 QList<QAction *> acs = wl.at(i)->actions();
2043 for (int j=0; j<acs.size(); j++){
2044 QString st=acs.at(j)->shortcut().toString();
2045 QIcon ic=acs.at(j)->icon();
2046 if (!st.isEmpty()){
2047 QString kb=acs.at(j)->shortcut().toString().replace(QRegularExpression("\\+"),"]&nbsp;+&nbsp;[");
2048 kb=kb.replace("+&nbsp;[]&nbsp;+&nbsp;[","+&nbsp;[+");
2049 #if defined (Q_OS_MAC)
2050 kb=kb.replace("Ctrl","&#8984;");//clover CMD
2051 kb=kb.replace("Meta","&#8963;");//Ctrl
2052 kb=kb.replace("Alt","&#8997;");//Opt
2053 kb=kb.replace("Shift","&#8679;");//shift/
2054 #endif
2055 QString ac=acs.at(j)->text();
2056 int und=ac.indexOf('&');
2057 if (und!=-1) {
2058 ac=ac.insert(und+2,"</u>");
2059 ac=ac.replace('&',"<u>");
2060 }
2061 ac[0]=ac[0].toUpper();
2062 ac=ac.replace(' ',"&nbsp;");
2063 shorts.append(QString("<td><b>[%2]</b></td><td>%1</td>").arg(ac).arg(kb));
2064 }
2065 }
2066 }
2067 shorts.sort();
2068 shorts.removeDuplicates();
2069 for (int i=0; i<shorts.size();i++){
2070 if ((i%2)==0) actionInfo.append(QString("<tr>%1\n").arg(shorts.at(i)));
2071 else actionInfo.append(QString("%1</tr>\n").arg(shorts.at(i)));
2072 }
2073 actionInfo.append("</table><br>Try Whats This on empty menu parts for more.");
2074 QMessageBox::information(this, "ShelXle Key Bindings", actionInfo);
2075 }
2076
2077 void Window::fileNative(){
2078 einstellung->beginGroup("Window");
2079 einstellung->setValue("nativeDialogs",useNativeDlg->isChecked());
2080 einstellung->endGroup();
2081 }
2082
2083 void Window::darkEdit(){
2084
2085 bool b=darkTheme->isChecked();
2086 bool classic=false;
2087 if (QString(PROGRAM_NAME).compare("shelXle")){
2088 //this is BrukerShelXle so we do not use any syle sheets
2089 b=false;
2090 classic=true;
2091 editor->highlighter->loadHighlightPatterns(inspatternfile);
2092 xlPutor->highlighter->loadHighlightPatterns(lstpatternfile);
2093 qpv->dark=b;
2094 return;
2095 }
2096 maybeSave();
2097 editor->dark=xlPutor->dark=b;
2098 qpv->dark=b;
2099 if (b){
2100 editor->highlighter->loadHighlightPatterns(inspatternfile_dark);
2101 xlPutor->highlighter->loadHighlightPatterns(lstpatternfile_dark);
2102 QFile f(":dark/dstyle.qss");
2103
2104 if (!f.exists()) {
2105 printf("Unable to set stylesheet, file not found\n");
2106 }
2107 else {
2108 f.open(QFile::ReadOnly | QFile::Text);
2109 QTextStream ts(&f);
2110 QString stle=ts.readAll();
2111 if (!classic){
2112 qApp->setStyleSheet(stle);
2113 //printf("darkstyle dark!\n");
2114 }
2115
2116 }
2117 QPalette p = editor->palette();
2118 p.setColor(QPalette::Base,QColor(0xff1e1e1eu));
2119 p.setColor(QPalette::WindowText,QColor(0xffc8c8c8u));
2120 p.setColor(QPalette::Text,QColor(0xffc8c8c8u));
2121 editor->setPalette (p );
2122 p = xlPutor->palette();
2123 p.setColor(QPalette::Base,QColor(0xff1e1e1eu));
2124 p.setColor(QPalette::WindowText,QColor(0xffc8c8c8u));
2125 p.setColor(QPalette::Text,QColor(0xffc8c8c8u));
2126 xlPutor->setPalette (p );
2127 xlPutor->setStyleSheet("QPlainTextEdit {\nbackground-color: #19232D;\ncolor: #E0E1E3;\nborder-radius: 4px;\nborder: 1px solid #455364;\n}");
2128 }else{
2129 editor->highlighter->loadHighlightPatterns(inspatternfile);
2130 xlPutor->highlighter->loadHighlightPatterns(lstpatternfile);
2131 QFile f(":light/lstyle.qss");
2132
2133 if (!f.exists()) {
2134 printf("Unable to set stylesheet, file not found\n");
2135 }
2136 else {
2137 f.open(QFile::ReadOnly | QFile::Text);
2138 QTextStream ts(&f);
2139 QString stle=ts.readAll();
2140 if (!classic){
2141 qApp->setStyleSheet(stle);
2142 //printf("darkstyle light!\n");
2143 }
2144
2145 }
2146 QPalette p = xlPutor->palette();
2147 p.setColor(QPalette::WindowText,QColor(0xff000000u));
2148 p.setColor(QPalette::Text,QColor(0xff000000u));
2149 p.setColor(QPalette::Base,QColor(0xffffffffu));
2150 editor->setPalette (p );
2151 p.setColor(QPalette::Base,QColor(0xffffffe6u));
2152 xlPutor->setStyleSheet("QPlainTextEdit {\nbackground-color: #FFFFE6;\ncolor: #19232D;\nborder-radius: 4px;\nborder: 1px solid #C9CDD0;\n}");
2153 xlPutor->setPalette (p );
2154 }
2155 einstellung->beginGroup("Colors");
2156 einstellung->setValue("darkTheme",darkTheme->isChecked());
2157 einstellung->endGroup();
2158 if (editor->isVisible()){
2159 printf("reload file!\n");
2160 loadAFile();
2161 }
2162 einstellung->beginGroup("Fonts");
2163 if (einstellung->contains("EditorFont")){
2164 QFont fnt;
2165 int id = QFontDatabase::addApplicationFont(theIconPath+"SourceCodePro-Regular.ttf");
2166 QString family = QFontDatabase::applicationFontFamilies(id).at(0);
2167 fnt = QFont(family);
2168 fnt = einstellung->value("EditorFont").value<QFont>();
2169 /*QFontInfo finfo(fnt);
2170 if (!finfo.exactMatch()){
2171 int id = QFontDatabase::addApplicationFont(theIconPath+"SourceCodePro-Regular.ttf");
2172 QString family = QFontDatabase::applicationFontFamilies(id).at(0);
2173 fnt = QFont(family);
2174
2175 }*/
2176 int fosi = einstellung->value("EditorFontSize", 10).toInt();
2177 fnt.setPointSize(fosi);
2178 printf("Dark? Font from settings %s %d\n", fnt.family().toStdString().c_str(),fnt.pointSize());
2179 // #if (QT_VERSION >= 0x040700)
2180 // fnt.setStyleStrategy(QFont::ForceIntegerMetrics);
2181 // #endif
2182 editor->setFont(fnt);
2183 xlPutor->setFont(fnt);
2184 }
2185 einstellung->endGroup();
2186 update();
2187 }
2188
2189 bool Window::doWeHaveHKLF5here(QStringList &hk5s){
2190 QString dn=dirName.section('/',0,-2);
2191 QStringList filter;
2192 filter.append("*.hkl");
2193 QStringList files;
2194 files = QDir(dn).entryList(filter,QDir::Files,QDir::Time|QDir::Reversed);
2195 int cread=-1,bn=0;//chars read
2196 //*
2197 //Joergs suggestion
2198 char buffer[260*2];
2199 memset(buffer, '\0', sizeof(buffer));
2200 char *cline=buffer, *pline=buffer+260, *temp;
2201 char batchstr[10];
2202 memset(batchstr, '\0', sizeof(batchstr));
2203 for (int i=0; i<files.size();i++){
2204 int bnmax=0,bnmin=0;//,nb=0;//nl=0,
2205 bool is_hklf5=false;
2206 QFile hkl(QString("%1/%2").arg(dn).arg(files.at(i)));
2207 hkl.open(QIODevice::Text|QIODevice::ReadOnly);
2208 int no=-1;
2209 do{
2210 cread = hkl.readLine(cline,sizeof(buffer)/2);
2211 if (0==memcmp(cline," 0 0 0",12)) break;
2212 if (cread>28) {
2213 //nb++;
2214 //strncpy
2215 memcpy(batchstr,cline+28,4);
2216 batchstr[4]='\0';
2217 bn=atoi(batchstr);
2218 bnmax=fmax(bn,bnmax);
2219 bnmin=fmin(bn,bnmin);
2220 }
2221 if ((no != i) && (bnmin < 0) && (0 == memcmp(cline+12, pline+12, 16)) ) {//memcmp(cline+12, pline+12, 16))//strncmp(cline+12, pline+12,16)
2222 is_hklf5=true;
2223 //printf("|%s|%s|################\n%s",cline+12, pline+12,cline);
2224 no=i;
2225 hk5s.append(files.at(i));
2226 }
2227 temp = pline; pline = cline; cline = temp;
2228 }while ((!is_hklf5)&&(cread>0));
2229 //Joergs suggestion
2230 // */
2231 /*
2232 char line[260],batchpart[120],isigpart[120],asig[120];
2233 for (int j=0; j< 120;j++) {batchpart[j]='\0';isigpart[j]='\0';asig[j]='\0';}
2234 //int cread=-1,bn=0;//chars read
2235 for (int i=0; i<files.size();i++){
2236 int bnmax=0,bnmin=0,nl=0,nb=0;
2237 bool is_hklf5=false;
2238 QFile hkl(QString("%1/%2").arg(dn).arg(files.at(i)));
2239 hkl.open(QIODevice::Text|QIODevice::ReadOnly);
2240 int no=-1;
2241 do{
2242 for (int j=0; j< 120;j++) {batchpart[j]='\0';isigpart[j]='\0';}
2243 cread = hkl.readLine(line,sizeof(line));
2244 if (0==strncmp(line," 0 0 0",12)) break;
2245 //printf("[%d]%s\n",cread,line);
2246 nl++;
2247 if (cread>12) {
2248 for (int j=12,k=0; j< 28;j++) isigpart[k++]=line[j];
2249 }
2250 if (cread>28) {
2251 int maxbatch=fmin(cread,32);
2252 for (int j=28,k=0; j< maxbatch;j++) batchpart[k++]=line[j];
2253 nb++;
2254 //if (cread>33) printf("%d\n%s\n\ %s\n",cread,line,batchpart);
2255 bn=atoi(batchpart);
2256 bnmax=fmax(bn,bnmax);
2257 bnmin=fmin(bn,bnmin);
2258 }
2259 if ((no!=i)&&(0==strncmp(isigpart,asig,16))&&(bnmin<0)) {
2260 is_hklf5=true;
2261 no=i;
2262 hk5s.append(files.at(i));
2263 //printf("HKLF5 ?? %d %d i=%d bn=%d\n", hk5s.size(), hklf5files.size(), i, bn);
2264 }
2265 for (int j=0; j< 16;j++) asig[j]=isigpart[j];
2266 }while (cread>0);
2267 //*/
2268 /*printf("%s %d lines read bn max %d bn min %d (%d). Think this%s a HKLF5\n",
2269 files.at(i).toStdString().c_str(),
2270 nl,
2271 bnmax,
2272 bnmin,
2273 nb,
2274 (is_hklf5)?"":" not");// */
2275 }
2276 return !hk5s.isEmpty();
2277 }
2278
2279 void Window::connectEdior(){
2280 //printf("\n\n\nconnectEdior()-->\n");
2281 //editor->dumpObjectInfo ();
2282 bool disok=false;
2283 disok=editor->disconnect(SIGNAL(saveMe(bool,bool)),this,SLOT(fileSave(bool,bool)));
2284 //printf("%d %s\n",__LINE__,(disok)?"ok":"no");
2285 disok=editor->disconnect(SIGNAL(updateLabel()),this,SLOT(updateLabel()));
2286 //printf("%d %s\n",__LINE__,(disok)?"ok":"no");
2287 disok=editor->disconnect(SIGNAL(textChanged ()),this,SLOT(spellCheck()));
2288 //printf("%d %s\n",__LINE__,(disok)?"ok":"no");
2289 disok=editor->disconnect(SIGNAL(cursorPositionChanged ()),this,SLOT(updateLC()));
2290 //printf("%d %s\n",__LINE__,(disok)?"ok":"no");
2291 disok=editor->disconnect(SIGNAL(findInStructure(const QString&)),this,SLOT(findInStructure(const QString &)));
2292 //printf("%d %s\n",__LINE__,(disok)?"ok":"no");
2293 disok=editor->disconnect(SIGNAL(openIncludeFile(const QString&)),this,SLOT(openIncludeFile(const QString &)));
2294 //printf("%d %s\n",__LINE__,(disok)?"ok":"no");
2295 disok=editor->disconnect(SIGNAL(electInStructure(const QString&)),this,SLOT(selectInStructure(const QString &)));
2296 //printf("%d %s\n",__LINE__,(disok)?"ok":"no");
2297 disok=editor->disconnect(SIGNAL(textChanged()),this,SLOT(updateSelectResi()));
2298 //printf("%d %s\n",__LINE__,(disok)?"ok":"no");
2299 disok=editor->disconnect(SIGNAL(cursorPositionChanged()),this,SLOT(resiSelectorCheck()));
2300 //printf("%d %s\n",__LINE__,(disok)?"ok":"no");
2301 disok=editor->disconnect( SIGNAL(copyAvailable(bool)), actionCut, SLOT(setEnabled(bool)));
2302 //printf("%d %s\n",__LINE__,(disok)?"ok":"no");
2303 disok=editor->disconnect( SIGNAL(copyAvailable(bool)), actionCopy, SLOT(setEnabled(bool)));
2304 //printf("%d %s\n",__LINE__,(disok)?"ok":"no");
2305
2306 //printf("<--connectEdior()-->\n");
2307 //editor->dumpObjectInfo ();
2308 //actionUndo->disconnect();
2309 //actionRedo->disconnect();
2310 //actionCut->disconnect();
2311 //actionCopy->disconnect();
2312 //actionPaste->disconnect();
2313 connect(editor,SIGNAL(saveMe(bool,bool)),this,SLOT(fileSave(bool,bool)));
2314 connect(editor,SIGNAL(updateLabel()),this,SLOT(updateLabel()));
2315 connect(editor,SIGNAL(textChanged ()),this,SLOT(spellCheck()));
2316 connect(editor,SIGNAL(cursorPositionChanged ()),this,SLOT(updateLC()));
2317 connect(editor,SIGNAL(findInStructure(const QString&)),this,SLOT(findInStructure(const QString &)));
2318 connect(editor,SIGNAL(openIncludeFile(const QString&)),this,SLOT(openIncludeFile(const QString &)));
2319 connect(editor,SIGNAL(electInStructure(const QString&)),this,SLOT(selectInStructure(const QString &)));
2320 connect(editor,SIGNAL(textChanged()),this,SLOT(updateSelectResi()));
2321 connect(editor,SIGNAL(cursorPositionChanged()),this,SLOT(resiSelectorCheck()));
2322
2323 connect(editor->document(), SIGNAL(modificationChanged(bool)),
2324 actionSave, SLOT(setEnabled(bool)));
2325 connect(editor->document(), SIGNAL(modificationChanged(bool)),
2326 actionHFix, SLOT(setDisabled(bool)));
2327 connect(editor->document(), SIGNAL(modificationChanged(bool)),
2328 this, SLOT(setWindowModified(bool)));
2329 connect(editor->document(), SIGNAL(undoAvailable(bool)),
2330 actionUndo, SLOT(setEnabled(bool)));
2331 connect(editor->document(), SIGNAL(undoCommandAdded ()),
2332 this, SLOT(wasRename()));
2333 connect(editor->document(), SIGNAL(undoCommandAdded()),this,SLOT(wasDelete()));
2334 connect(editor->document(), SIGNAL(redoAvailable(bool)),
2335 actionRedo, SLOT(setEnabled(bool)));
2336 connect(actionUndo, SIGNAL(triggered()), editor, SLOT(undo()));
2337 connect(actionUndo,SIGNAL(triggered()),this,SLOT(undoRename()));
2338 connect(actionRedo, SIGNAL(triggered()), editor, SLOT(redo()));
2339 connect(actionRedo, SIGNAL(triggered()),this, SLOT(redoRename()));
2340 connect(actionCut, SIGNAL(triggered()), editor, SLOT(mcut()));
2341 connect(actionCopy, SIGNAL(triggered()), editor, SLOT(copy()));
2342 connect(actionPaste, SIGNAL(triggered()), editor, SLOT(mpaste()));
2343 connect(editor, SIGNAL(copyAvailable(bool)), actionCut, SLOT(setEnabled(bool)));
2344 connect(editor, SIGNAL(copyAvailable(bool)), actionCopy, SLOT(setEnabled(bool)));
2345 connect(editor,SIGNAL(deleteSelected()),this,SLOT(deleteSelectedAtoms()));
2346 //editor->dumpObjectInfo ();
2347 //printf("<--connectEdior()\n");
2348 }
2349
2350 void Window::updateTwinTest(){
2351 //printf("\n\nUPDATE TWIN TEST\n");
2352 Matrix M[6];
2353 M[0] =Matrix ( 0, 1, 0, 1, 0, 0, 0, 0, -1);
2354 M[1] =Matrix ( 0, -1, 0, -1, 0, 0, 0, 0, -1);
2355 M[2] =Matrix (-1, 0, 0, 0, -1, 0, 0, 0, 1);
2356 M[3] =Matrix ( 1, 0, 0, 0, -1, 0, 0, 0, -1);
2357 M[4] =Matrix (-1, 0, 0, 0, -1, 0, 0, 0, -1);
2358 M[5] =Matrix ( 1, 0, 0, 0, 1, 0, 0, 0, 1);
2359 QString dn=dirName.section('/',0,-2);
2360 QString wd=QString("%1/twintest/").arg(dn);
2361 bool didsomething=false;
2362 for (int m=0; m<6; m++){
2363 if (twinRedundant.at(m)) continue;
2364 if (twinDone.at(m)) continue;
2365 didsomething=true;
2366 //QString insnam=QString("%1test%2.ins").arg(wd).arg(m);
2367 //QString insnambase=QString("test%1").arg(m);
2368
2369 QString resnam=QString("%1test%2.res").arg(wd).arg(m);
2370 QFile res(resnam);
2371 if (res.open(QIODevice::ReadOnly|QIODevice::Text)){
2372 //printf("resname=%s\n",resnam.toStdString().c_str());
2373 QString inhalt=res.readAll();
2374 res.close();
2375 if (inhalt.isEmpty()) continue;
2376 QStringList basfs=inhalt.section("\nBASF ",1).section("\n",0,0).trimmed().split(" ",skipEmptyParts);
2377 bool maybe=true;
2378 if (!basfs.isEmpty()) {
2379 double basf=basfs.at(0).toDouble();
2380 //printf("BASF %f\n",basf);
2381 maybe=((basf>0.04)&&(basf<0.96));
2382 }
2383 inhalt = inhalt.section("\nHKLF ",1);
2384
2385 QStringList sl2 = inhalt.section("REM wR2 =",1).section("\n",0,0).trimmed().split(",",skipEmptyParts);
2386 //REM R1 = 0.0150 for 6927 Fo > 4sig(Fo) and 0.0160 for all 7220 data
2387 QStringList sl = inhalt.section("REM R1 =",1).section("\n",0,0).trimmed().split(" ",skipEmptyParts);
2388 if (sl.size()<11)continue;
2389 if (sl2.size()<1) maybe=maybe&&(sl.at(0).toDouble()*100.0<=(rvalue2beat+0.075));
2390 else maybe=maybe&&(sl2.at(0).toDouble()*100.0<=(wr2value2beat+0.075));
2391 /*printf("m=%d R1 %5.2f %d all %5.2f %d %s (%f)\n",
2392 m,
2393 sl.at(0).toDouble()*100.0,
2394 sl.at(2).toInt(),
2395 sl.at(7).toDouble()*100.0,
2396 sl.at(10).toInt(),
2397 (maybe)?"probably a twin":"not realy likely a suitabe twin law",
2398 rvalue2beat
2399 );*/
2400 QString Label= QString("TWIN %1 %2 %3 %4 %5 %6 %7 %8 %9 %10")
2401 .arg(M[m].m11).arg(M[m].m21).arg(M[m].m31)
2402 .arg(M[m].m12).arg(M[m].m22).arg(M[m].m32)
2403 .arg(M[m].m13).arg(M[m].m23).arg(M[m].m33)
2404 .arg((m==5)?"= no twin law for comparison":"");
2405 QGroupBox *gpx2 = new QGroupBox(Label,twinDlg);
2406
2407 gpx2->setAlignment(Qt::AlignRight);
2408 gpx2->setCheckable(true);
2409 gpx2->setChecked(maybe);
2410
2411 QVBoxLayout *v = new QVBoxLayout(gpx2);
2412 QHBoxLayout *hbl1 = new QHBoxLayout();
2413 double basfv=basfs.at(0).toDouble();
2414 QLabel *R1lab = new QLabel(QString("R1=%1\nafter applying\ntwin law").arg(sl.at(0).toDouble()*100.0,0,'f',2),twinDlg);
2415 R1lab->setStyleSheet(QString("QLabel { background-color : %1; color : white; }").arg(hw->rwert_farbverlauf(sl.at(0).toDouble()*300.0).name()));
2416 if (sl2.size()>0){
2417 QLabel *wR2lab = new QLabel(QString("wR2=%1\nafter applying\ntwin law").arg(sl2.at(0).toDouble()*100.0,0,'f',2),twinDlg);
2418 wR2lab->setStyleSheet(QString("QLabel { background-color : %1; color : white; }").arg(hw->rwert_farbverlauf(sl2.at(0).toDouble()*300.0).name()));
2419 QLabel *beatlab = new QLabel(QString("curent \nR1 =%1\nwR2= %2").arg(rvalue2beat,0,'f',2).arg(wr2value2beat,0,'f',2),twinDlg);
2420 beatlab->setStyleSheet(QString("QLabel { background-color : qlineargradient(x1: 0, y1: 0, x2: 1, y2: 0, stop: 0 %1, stop: 1 %2); color : white; }")
2421 .arg(hw->rwert_farbverlauf(rvalue2beat*3.0).name())
2422 .arg(hw->rwert_farbverlauf(wr2value2beat*3.0).name()));
2423
2424 QLabel *BASFlab = new QLabel(QString("BASF = %1").arg(basfv,0,'f',4),twinDlg);
2425 BASFlab->setStyleSheet(QString("QLabel { background-color : %1; color : white; }").arg(((basfv>0.04)&&(basfv<0.96))?"#009933":"#990033"));
2426 hbl1->addWidget(beatlab);
2427 hbl1->addWidget(R1lab);
2428 hbl1->addWidget(wR2lab);
2429 hbl1->addWidget(BASFlab);
2430 }else{// old xl versions do not rem the wR2 value
2431 QLabel *beatlab = new QLabel(QString("curent \nR1 =%1").arg(rvalue2beat,0,'f',2),twinDlg);
2432 beatlab->setStyleSheet(QString("QLabel { background-color : %1; white; }")
2433 .arg(hw->rwert_farbverlauf(rvalue2beat*3.0).name())
2434 );
2435
2436 QLabel *BASFlab = new QLabel(QString("BASF = %1").arg(basfv,0,'f',4),twinDlg);
2437 BASFlab->setStyleSheet(QString("QLabel { background-color : %1; color : white; }").arg(((basfv>0.04)&&(basfv<0.96))?"#009933":"#990033"));
2438 hbl1->addWidget(beatlab);
2439 hbl1->addWidget(R1lab);
2440 hbl1->addWidget(BASFlab);
2441 }
2442 //if (maybe){
2443 QAction *tryThisTwin = new QAction("insert this twin \nlaw in res file",twinDlg);
2444 tryThisTwin->setEnabled(maybe);
2445 tryThisTwin->setData(QString("%1\nBASF %2\n").arg(Label).arg(basfv,0,'f',4));
2446 connect(tryThisTwin,SIGNAL(triggered()),this,SLOT(insertTwin()));
2447 connect(tryThisTwin,SIGNAL(triggered()),twinDlg,SLOT(reject()));
2448 QToolButton *button =new QToolButton(twinDlg);
2449 button->setDefaultAction(tryThisTwin);
2450 connect(gpx2,SIGNAL(toggled(bool)),button,SLOT(setEnabled(bool)));
2451 if (m==5) {
2452 gpx2->setChecked(false);
2453 gpx2->setCheckable(false);
2454 button->setEnabled(false);
2455 }
2456 //button->setEnabled(maybe);
2457 hbl1->addWidget(button);
2458 //}
2459 v->addLayout(hbl1);
2460
2461 twinvbl->addWidget(gpx2);
2462
2463 twinDone[m]=true;
2464 twingpx->adjustSize();
2465 }
2466 }// */
2467 if (didsomething){
2468 twinDlg->update();
2469 twinDlg->show();
2470 }else {twinpatlab->hide();}
2471 }
2472
2473 void Window::testMerohedral(){
2474 Matrix M[6];
2475 M[0] =Matrix ( 0, 1, 0, 1, 0, 0, 0, 0, -1);
2476 M[1] =Matrix ( 0, -1, 0, -1, 0, 0, 0, 0, -1);
2477 M[2] =Matrix (-1, 0, 0, 0, -1, 0, 0, 0, 1);
2478 M[3] =Matrix ( 1, 0, 0, 0, -1, 0, 0, 0, -1);
2479 M[4] =Matrix (-1, 0, 0, 0, -1, 0, 0, 0, -1);
2480 M[5] =Matrix ( 1, 0, 0, 0, 1, 0, 0, 0, 1);
2481 twinRedundant.clear();
2482 twinDone.clear();
2483 for (int i=0; i<mole.cell.symmops.size(); i++){
2484 for (int m=0; m<6;m++){
2485 twinRedundant.append(false);
2486 twinDone.append(false);
2487 if ((m==4)&&(mole.cell.centeric)) twinRedundant[m]=true;
2488 Matrix tm=M[m]*mole.cell.symmops.at(i);
2489
2490 if (m!=5) for (int n=0; n<m; n++){
2491 if ((i>0)&&(m!=n)&&(tm==M[n])) {printf("Matrix %d %d %d is redundant\n",m,i,n);
2492 twinRedundant[m]=true;
2493 printf("\nX%9.3f %9.3f %9.3f\nX%9.3f %9.3f %9.3f\nX%9.3f %9.3f %9.3f\n\n"
2494 ,tm.m11
2495 ,tm.m21
2496 ,tm.m31
2497 ,tm.m12
2498 ,tm.m22
2499 ,tm.m32
2500 ,tm.m13
2501 ,tm.m23
2502 ,tm.m33
2503 );
2504 }
2505 }
2506 }
2507 }
2508
2509 QFile res(dirName);
2510 res.open(QIODevice::ReadOnly|QIODevice::Text);
2511 QString inhalt=res.readAll();
2512 res.close();
2513 inhalt = inhalt.section("\nHKLF ",1);
2514 //REM wR2 = 0.176801, GooF = S = 1.14341, Restrained GooF = 1.14341 for all data
2515 QStringList sl2 = inhalt.section("REM wR2 =",1).section("\n",0,0).trimmed().split(",",skipEmptyParts);
2516 //REM R1 = 0.0150 for 6927 Fo > 4sig(Fo) and 0.0160 for all 7220 data
2517 QStringList sl = inhalt.section("REM R1 =",1).section("\n",0,0).trimmed().split(" ",skipEmptyParts);
2518 rvalue2beat=99.0;
2519 wr2value2beat=99.0;
2520 if (sl.size()>10) rvalue2beat=sl.at(0).toDouble()*100.0;
2521 if (sl2.size()>1) wr2value2beat=sl2.at(0).toDouble()*100.0;
2522 QString dn=dirName.section('/',0,-2);
2523 QString hkl=dirName;
2524 hkl=hkl.replace(resorins,".hkl");
2525 QString wd=QString("%1/twintest/").arg(dn);
2526 QDir work=QDir(wd);
2527 if (!work.exists()) work.mkdir(wd);
2528 else{
2529 QStringList filter;
2530 filter << QString("*.*");
2531 QStringList files;
2532 files=work.entryList(filter,QDir::Files);
2533 for (int i=0; i<files.size(); i++){
2534 printf("remove %s ok=%d\n",files.at(i).toStdString().c_str(),
2535 work.remove(files.at(i)));
2536 }
2537 }
2538 //shelxl->setWorkingDirectory(wd);
2539 //qDebug()<<shelxlPath;
2540 for (int m=0; m<6; m++){
2541 if (twinRedundant.at(m)) continue;
2542 QString insnam=QString("%1test%2.ins").arg(wd).arg(m);
2543 QFile::copy(dirName,insnam);
2544 //printf("COPY %s to %s.\n",dirName.toStdString().c_str(),insnam.toStdString().c_str());
2545 QFile::copy(hkl,QString("%1test%2.hkl").arg(wd).arg(m));
2546 }
2547 if (twinDlg) {
2548 twinDlg->hide();
2549 delete twinDlg;
2550 }
2551 twinDlg = new QDialog(this);
2552
2553 twingpx =new QGroupBox("Possible twin laws for this structure:",twinDlg);
2554 twinvbl = new QVBoxLayout();
2555 QDialogButtonBox *bb = new QDialogButtonBox(QDialogButtonBox::Cancel,Qt::Horizontal,twinDlg);
2556 connect(bb, SIGNAL(rejected()), twinDlg, SLOT(reject()));
2557 twingpx->setLayout(twinvbl);
2558 QVBoxLayout *la = new QVBoxLayout();
2559 QScrollArea *qsa = new QScrollArea(twinDlg);
2560 twingpx->setMinimumSize(590,650);
2561 qsa->setWidget(twingpx);
2562 qsa->setMinimumSize(600,660);
2563 la->addWidget(qsa);
2564 la->addWidget(bb);
2565 twinDlg->setLayout(la);
2566 twinvbl->addWidget(twinpatlab = new QLabel("...please wait until some twin laws are checked..."));
2567 updateTwinTest();
2568 //QList<QCheckBox *> alleboxen;
2569 //QSignalMapper *map = new QSignalMapper(this);
2570
2571
2572
2573
2574
2575
2576 for (int m=0; m<6; m++){
2577 if (twinRedundant.at(m)) continue;
2578 QString insnam=QString("%1test%2.ins").arg(wd).arg(m);
2579 QString insnambase=QString("test%1").arg(m);
2580 QProcess *shelxl0 = new QProcess(this);
2581 shelxl0->setWorkingDirectory(wd);
2582 QFile f(insnam);
2583 f.open(QIODevice::ReadOnly|QIODevice::Text);
2584 QString all = f.readAll();
2585 f.close();
2586 all=all.replace(QRegularExpression("\nACTA[^\n]*\n", QRegularExpression::CaseInsensitiveOption),"\n");//no acta!
2587 all=all.replace(QRegularExpression("\nTWIN[^\n]*\n", QRegularExpression::CaseInsensitiveOption),"\n");//no TWIN!
2588 all=all.replace(QRegularExpression("\nBASF[^\n]*\n", QRegularExpression::CaseInsensitiveOption),"\n");//no basf!
2589 all=all.replace(QRegularExpression("\nAFIX[^\n]*\n", QRegularExpression::CaseInsensitiveOption),"\n");//no afix!
2590 all=all.replace(QRegularExpression("\nL.S.[^\n]*\n", QRegularExpression::CaseInsensitiveOption),"\n");//no L.S.!
2591
2592 int unitpos=all.indexOf("UNIT",0,Qt::CaseInsensitive);
2593 int afterunitpos=all.indexOf("\n",unitpos);
2594 all=all.insert(afterunitpos+1,QString("TWIN %1 %2 %3 %4 %5 %6 %7 %8 %9 2\nBASF 0.41\nL.S. 10\nAFIX 6\n")
2595 .arg(M[m].m11).arg(M[m].m21).arg(M[m].m31)
2596 .arg(M[m].m12).arg(M[m].m22).arg(M[m].m32)
2597 .arg(M[m].m13).arg(M[m].m23).arg(M[m].m33));
2598 f.open(QIODevice::WriteOnly|QIODevice::Text);
2599 f.write(all.toLatin1());
2600 f.close();
2601 QStringList al;
2602 al.append(insnambase);
2603 connect(shelxl0,SIGNAL(finished(int,QProcess::ExitStatus)),this,SLOT(updateTwinTest()));
2604 connect(shelxl0,SIGNAL(error(QProcess::ProcessError)),this,SLOT(updateTwinTest()));
2605 shelxl0->start(shelxlPath,al);
2606 //shelxl0->waitForFinished();
2607 //fprintf(stderr,"\n!![%s]\n",shelxl0->readAllStandardOutput().data());
2608 //fprintf(stderr,"\n!![%s]\n",shelxl0->readAllStandardError().data());
2609
2610 }
2611 QTimer::singleShot(5000,twinpatlab,SLOT(hide()));
2612
2613 }
2614 void Window::insertTwin(){
2615 QAction *action = qobject_cast<QAction *>(sender());
2616 QString insertthis;
2617 if (action)
2618 insertthis=action->data().toString();
2619 else return;
2620 QTextDocument *document = editor->document();
2621 QTextCursor cursor = editor->textCursor();
2622 cursor.beginEditBlock();
2623 editor->replace->setText("");
2624 editor->searchLE->setText("^TWIN");
2625 editor->wholeLine->setChecked(true);
2626 editor->replaceAll();
2627 editor->searchLE->setText("^BASF");
2628 editor->replaceAll();
2629 editor->replace->setText("");
2630 editor->searchLE->setText("");
2631 editor->wholeLine->setChecked(false);
2632 cursor.movePosition(QTextCursor::Start);
2633 cursor = document->find(unitinst,cursor);
2634 cursor.movePosition(QTextCursor::StartOfLine,QTextCursor::MoveAnchor);
2635 cursor.movePosition(QTextCursor::Down,QTextCursor::MoveAnchor);
2636 cursor.insertText(insertthis);
2637 cursor.endEditBlock();
2638
2639 }
2640 void Window::idleRotStart(){
2641 if ((ydleStart!=NULL)&&(ydleStop!=NULL)){
2642 ydleStart->setVisible(false);
2643 ydleStop->setVisible(true);
2644 ydleStart->setEnabled(false);
2645 ydleStop->setEnabled(true);
2646 }
2647 chgl->idl = new QTimer(this);
2648 chgl->idl_end = new QTimer(this);
2649 connect(chgl->idl, SIGNAL(timeout()), chgl, SLOT(rotateIdle( )));
2650 connect(this,SIGNAL(movedByUser()), this, SLOT(idleRotStop()));
2651 if (chgl!=NULL) connect(chgl,SIGNAL(movedByUser()), this, SLOT(idleRotStop()));//we have a signal in chgl as well
2652 chgl->idl->start(5);
2653 chgl->idl_end->singleShot(36000,this,SLOT(idleRotStop()));//stop this after ca 10 rotations 360/0.5 * 5 *10
2654 // printf("start rotation %d\n",chgl->idl->timerId());
2655 }
2656
2657 void Window::idleRotStop(){
2658 if ((ydleStart!=NULL)&&(ydleStop!=NULL)){
2659 ydleStart->setVisible(true);
2660 ydleStop->setVisible(false);
2661 ydleStart->setEnabled(true);
2662 ydleStop->setEnabled(false);
2663 }
2664 disconnect(this,SIGNAL(movedByUser()),this, SLOT(idleRotStop()));
2665 if (chgl!=NULL) {
2666 disconnect(chgl,SIGNAL(movedByUser()), this, SLOT(idleRotStop()));//we have a signal in chgl as well
2667 if (chgl->idl==NULL) return;
2668 }
2669 chgl->idl->stop();
2670 chgl->idl->disconnect();
2671 chgl->idl->deleteLater();
2672 // printf("stop rotation\n");
2673 }
2674
2675 void Window::setMonoQ(bool vis){
2676 mole.monoQrom=!vis;
2677
2678 chgl->update();
2679 }
2680
2681 void Window::foversusfc(){
2682
2683 QString fcfname = dirName;
2684 fcfname.replace(resorins,".fcf");
2685 FcVsFo *d = new FcVsFo(fcfname,mole.cell.a, mole.cell.b, mole.cell.c, mole.cell.al, mole.cell.be, mole.cell.ga, mole.cell.wave);
2686 connect(d,SIGNAL(weg(const QString &)), editor,SLOT(omitsome(const QString &)));
2687 d->exec();
2688 delete d;
2689 }
2690
2691 void Window::toggleHFSAO(bool on){
2692 mole.HFixSuitableAtomsOnly=on;
2693 einstellung->beginGroup("HFIX");
2694 //HFixSuitableAtomsOnly=
2695 einstellung->setValue("HFixSuitableAtomsOnly0",on);
2696 einstellung->endGroup();
2697 }
2698
2699 void Window::togOMIT(bool b){
2700 QGroupBox *gpx = findChild<QGroupBox *>("worstReflectionsGPX");
2701 if (gpx!=nullptr){
2702 QList<QCheckBox *> ck = gpx->findChildren<QCheckBox *>();
2703 for (int i=0; i<ck.size();i++){
2704 ck[i]->setChecked(b);
2705 }
2706 update();
2707 //printf("toggled %d boxes...\n",ck.size());
2708 }else{
2709 printf("cant't find worstReflectionsGPX");
2710 }
2711 }
2712
2713 void Window::selOmitG5(){
2714 QGroupBox *gpx = findChild<QGroupBox *>("worstReflectionsGPX");
2715 if (gpx!=nullptr){
2716 QList<QCheckBox *> ck = gpx->findChildren<QCheckBox *>();
2717 for (int i=0; i<ck.size();i++){
2718 ck[i]->setChecked(false);
2719 QString s=ck[i]->text();
2720 QStringList num = s.split(" ",skipEmptyParts);
2721 if ((num.size()==8)&&(num.at(5).toDouble()>5.0)){
2722 ck[i]->setChecked(true);
2723 }
2724 }
2725 update();
2726 }else{
2727 printf("cant't find worstReflectionsGPX");
2728 }
2729 }
2730
2731 void Window::selOmitG10(){
2732 QGroupBox *gpx = findChild<QGroupBox *>("worstReflectionsGPX");
2733 if (gpx!=nullptr){
2734 QList<QCheckBox *> ck = gpx->findChildren<QCheckBox *>();
2735 for (int i=0; i<ck.size();i++){
2736 ck[i]->setChecked(false);
2737 QString s=ck[i]->text();
2738 QStringList num = s.split(" ",skipEmptyParts);
2739 if ((num.size()==8)&&(num.at(5).toDouble()>10.0)){
2740 ck[i]->setChecked(true);
2741 }
2742 }
2743 update();
2744 }else{
2745 printf("cant't find worstReflectionsGPX");
2746 }
2747 }
2748
2749 void Window::omitRfl(){
2750 QGroupBox *gpx = findChild<QGroupBox *>("worstReflectionsGPX");
2751 if (gpx!=nullptr){
2752 QList<QCheckBox *> ck = gpx->findChildren<QCheckBox *>();
2753 QString omitstring;
2754 for (int i=0; i<ck.size();i++){
2755 if (ck[i]->isChecked()){
2756 QString s=ck[i]->text();
2757 QStringList num = s.split(" ",skipEmptyParts);
2758 omitstring.append(QString("OMIT %1 %2 %3\n").arg(num.at(0)).arg(num.at(1)).arg(num.at(2)));
2759 }
2760 }
2761 editor->omitsome(omitstring);
2762 }else{
2763 printf("cant't find worstReflectionsGPX");
2764 }
2765 }
2766
2767 void Window::worstReflections(){
2768 QString listName=dirName;
2769 listName.replace(punktins,".lst");
2770 listName.replace(punktres,".lst");
2771 QFile lstf(listName);
2772 if (lstf.open(QIODevice::ReadOnly|QIODevice::Text)){
2773 QDialog *mdr = new QDialog(this);
2774 QScrollArea *qsa = new QScrollArea(mdr);
2775 //mdr->set
2776 QGroupBox *gpx = new QGroupBox("Check Refelextions to omit.",mdr);
2777 gpx->setObjectName("worstReflectionsGPX");
2778 QVBoxLayout *lt = new QVBoxLayout(gpx);
2779 QVBoxLayout *la = new QVBoxLayout();
2780 QFont font;
2781 font.setFamily("Droid Sans Mono");
2782 la->addWidget(new QLabel("Most Disagreeable Reflections (* if suppressed or used for Rfree).\n\
2783 Error/esd is calculated as sqrt(wD^2/<wD^2>) where w is given by the weight\n\
2784 formula, D = Fo^2-Fc^2 and <> refers to the average over all reflections.",mdr));
2785 QCheckBox *allx;
2786 lt->addWidget(allx = new QCheckBox(QString(" h k l Fo^2 Fc^2 Error/esd Fc/Fc(max) Resolution(A)")));
2787 connect(allx,SIGNAL(toggled(bool)),this, SLOT(togOMIT(bool)));
2788 allx->setFont(font);
2789 QStringList liste=QString(lstf.readAll()).split('\n');
2790 int moststart=liste.indexOf(" h k l Fo^2 Fc^2 Error/esd Fc/Fc(max) Resolution(A)");
2791 if (moststart>0)for (int i=moststart+2; i<liste.size();i++){
2792 QStringList num=liste.at(i).split(" ",skipEmptyParts);
2793 if (num.size()==8){
2794 QCheckBox *bx;
2795 lt->addWidget(bx = new QCheckBox(QString("%1%2%3 %4 %5 %6 %7 %8")
2796 .arg(num.at(0).toInt(),4)
2797 .arg(num.at(1).toInt(),4)
2798 .arg(num.at(2).toInt(),4)
2799 .arg(num.at(3).toDouble(),10,'f',3)
2800 .arg(num.at(4).toDouble(),10,'f',3)
2801 .arg(num.at(5).toDouble(),10,'f',3)
2802 .arg(num.at(6).toDouble(),10,'f',3)
2803 .arg(num.at(7).toDouble(),10,'f',3)));
2804 bx->setFont(font);
2805 /*
2806 printf("%4d%4d%4d %10.3f %10.3f %10.3f %10.3f %10.3f\n"
2807 ,num.at(0).toInt()
2808 ,num.at(1).toInt()
2809 ,num.at(2).toInt()
2810 ,num.at(3).toDouble()
2811 ,num.at(4).toDouble()
2812 ,num.at(5).toDouble()
2813 ,num.at(6).toDouble()
2814 ,num.at(7).toDouble());*/
2815 }else break;
2816 }
2817 //printf("Most Disagreeable Reflections %d %d\n", moststart,static_cast<int>(liste.size()));
2818 gpx->setLayout(lt);
2819 qsa->setWidget(gpx);
2820 la->addWidget(qsa);
2821 QDialogButtonBox *bb = new QDialogButtonBox(QDialogButtonBox::Cancel,Qt::Horizontal,mdr);
2822 QPushButton *omit = bb->addButton("OMIT selected Refelections",QDialogButtonBox::AcceptRole);
2823 QPushButton *g5 = bb->addButton("select Refelections Error/esd > 5",QDialogButtonBox::ApplyRole);
2824 QPushButton *g10 = bb->addButton("select Refelections Error/esd > 10",QDialogButtonBox::ApplyRole);
2825 connect(omit,SIGNAL(clicked()),this,SLOT(omitRfl()));
2826 connect(g10,SIGNAL(clicked()),this,SLOT(selOmitG10()));
2827 connect(g5,SIGNAL(clicked()),this,SLOT(selOmitG5()));
2828 connect(bb, SIGNAL(accepted()), mdr, SLOT(accept()));
2829 connect(bb, SIGNAL(rejected()), mdr, SLOT(reject()));
2830 la->addWidget(bb);
2831 mdr->setLayout(la);
2832 mdr->exec();
2833 mdr->deleteLater();
2834 }
2835 }
2836
2837 void Window::delayedLoad(){
2838 printf("...load in 150ms\n");
2839 tim = new QTimer(this);
2840 tim->setSingleShot(true);
2841 connect(tim,SIGNAL(timeout()),this,SLOT(loadAFile()));
2842 tim->start(150);
2843 }
2844
2845 void Window::loadAFile(){
2846 /*
2847 einstellung->beginGroup("Window");
2848 einstellung->setValue("QuickReLoad",quickReLoadButton->isChecked());
2849 einstellung->endGroup();
2850 */
2851
2852 printf("...load now\n");
2853
2854 loadFile(dirName);
2855 }
2856
2857 void Window::openSaveHistory(){
2858 if ((dirName.isEmpty())||(!QFile::exists(dirName))) return;
2859 SaveHistoryWidget *shw = new SaveHistoryWidget(dirName,(QString(PROGRAM_NAME).compare("shelXle")==0)?darkTheme->isChecked():false);
2860 if (QDialog::Accepted==shw->exec()) {
2861 if ((quickReLoadButton->isChecked())) sdm();
2862 loadFile(dirName);
2863 if ((quickReLoadButton->isChecked())) sdm();
2864 }
2865 delete shw;
2866 }
2867
2868 void Window::adoptEditToolBar(bool b){
2869 if (b) shxMW->addToolBar(editToolBar);
2870 else addToolBar(editToolBar);
2871 einstellung->beginGroup("Window");
2872 einstellung->setValue("EditorHasOwnToolBar",b);
2873 einstellung->endGroup();
2874 update();
2875 }
2876
2877 void Window::toggleEQHighlighting(bool b){
2878 mole.highlightEquivalents = b;
2879 chgl->update();
2880 }
2881
2882 void Window::toggleOrtho(bool ov){
2883
2884
2885 //printf("toggleOrtho %d\n",__LINE__);
2886 chgl->toggleOrtho(ov);
2887 chgl->update();
2888 /*if ((ov)&&(togDepthCueing->isChecked())){
2889 togDepthCueing->setChecked(false);
2890 chgl->setDepthCueing(false);
2891 //printf("toggleOrtho %d\n",__LINE__);
2892 }
2893 togDepthCueing->setDisabled(ov);*/
2894 //chgl->setViewAngle((ov)?0.1:29.0);
2895 einstellung->beginGroup("ViewSettings");
2896 einstellung->setValue("OrthographicProjection",ov);
2897 einstellung->endGroup();
2898 }
2899
2900 int Window::getFvarCntr(int fvar){
2901 return fvarCntr.value(fvar);
2902 }
2903
2904 void Window::growQPeaks(bool qpg){
2905 mole.growQPeak=qpg;
2906
2907 bool growYes=chgl->fuse->isVisible ();
2908 chgl->mol->fuse();
2909 if (growYes) chgl->mol->grow();
2910
2911 loadMolInTest();
2912 chgl->update();
2913 }
2914
2915 void Window::spellCheck(){
2916 QString t=editor->toPlainText();
2917 if (t==altText) return;
2918 altText=t;
2919 QRegularExpression rx=QRegularExpression("\\s|_");
2920 QRegularExpression nch=QRegularExpression("[^\"\\-~#%&$'`§()+\\*\\./@\\[\\]^\\\\{}\\|<>A-Za-z0-9]+");
2921 QString s,s0;
2922 QString meld;
2923 editor->errorInLine.clear();
2924 bool cont=false;
2925 QStringList sl;
2926 for (int i= 0;i< editor->blocks.size(); i++){
2927 sl = editor->blocks.at(i).split(" ",skipEmptyParts);
2928 if (sl.isEmpty())continue;
2929 if ((cont)&&(editor->blocks.at(i).contains(QRegularExpression("^\\S+")))){
2930 editor->errorInLine.append(i-1);
2931 editor->errorInLine.append(i);
2932 meld+=QString("ERROR in line %1: Bad continuation line!<br>").arg(i);
2933 }
2934 cont=false;
2935 if (sl.isEmpty())continue;
2936 cont= (!(sl.at(0).contains(QRegularExpression("(^REM)|(^TITL)",QRegularExpression::CaseInsensitiveOption)))&&(editor->blocks.at(i).contains(QRegularExpression("=\\s*$"))));
2937 if((editor->blocks.at(i).size()>SX_LINE_LENGTH)&&(!editor->blocks.at(i).contains(QRegularExpression("^\\s+")))){
2938 editor->errorInLine.append(i);
2939 meld+=QString("ERROR in line %1: Line is too long for SHELXL!<br>").arg(i+1);
2940 }
2941 if (editor->blocks.at(i).startsWith(" ")) continue;
2942 if (isacommand(sl.at(0))==-1){
2943 s0=sl.at(0).section(rx,0,0);
2944 if (s0.size()>4) {
2945 meld+=QString("ERROR in line %1: Atom label too long %2!<br>").arg(i+1).arg(sl.at(0));
2946 editor->errorInLine.append(i);
2947 }
2948 if (sl.at(0).contains(nch)) {
2949 meld+=QString("ERROR in line %1: Not allowed characters in atom label %2!<br>").arg(i+1).arg(sl.at(0));
2950 editor->errorInLine.append(i);
2951 }
2952 bool bb=true;
2953 if (sl.size()>1) {
2954 s=sl.at(1);
2955 int ii = s.toInt(&bb);
2956 if ((sl.size()>3)&&((ii<1)||(!bb))) {
2957 meld+=QString("ERROR in line %1: Scatering-factor number is missing or out of range!<br>").arg(i+1);
2958 editor->errorInLine.append(i);
2959 }
2960 }
2961 }
2962 }
2963 FehlerTeufel= !meld.isEmpty();
2964 if (FehlerTeufel) infoKanalNews("<font color=red size=+1>"+meld+"</font>");
2965 else infoKanalNews("");
2966 spellCheckact->setVisible(FehlerTeufel);
2967 spellCheckact2->setVisible(FehlerTeufel);
2968 editor->update();
2969 }
2970
2971 void Window::exportCoordinates(){
2972 QString exportName = dirName;
2973 exportName.replace(resorins,"_EXPORTED.res");
2974 QString fn=QFileDialog::getSaveFileName(this, tr("Export all visible atoms"), exportName, tr("SHELX-files (*.res *.ins)"));
2975 if (fn.isEmpty()) return;
2976 QFile f(fn);
2977 QString body;
2978 body.append(QString("TITL %1\nCELL %2 %3 %4 %5 %6 %7 %8\n%9\n")
2979 .arg(title)
2980 .arg(mole.cell.wave )
2981 .arg(mole.cell.a )
2982 .arg(mole.cell.b )
2983 .arg(mole.cell.c )
2984 .arg(mole.cell.al )
2985 .arg(mole.cell.be )
2986 .arg(mole.cell.ga )
2987 .arg(mole.cell.Z )
2988 );
2989 body.append(QString("LATT -1\n"));
2990 for (int i=1; i<mole.cell.symmops.size();i++){
2991 body.append(QString("SYMM %1\n").arg(mole.symmcode2human(i)));
2992 }
2993 body.append(QString("SFAC "));
2994 for (int i=0; i<editor->sfac.size(); i++){
2995 body.append(QString("%1 ").arg(mole.pse(editor->sfac.at(i))));
2996 }
2997 body.append("\n");
2998 body.append(editor->unitNeu);
2999 body.append(
3000 "\n\nREM ######################################################\n"
3001 "REM This file exported by ShelXle is for information or \n"
3002 "REM visualiztion purposes only. You may run into trouble \n"
3003 "REM if you try to refine it against data.\n"
3004 "REM DISABLE_REFINE\n"
3005 "REM ######################################################\n\n");
3006 body.append("FVAR 1.00 ");
3007 for (int i=0; i<fvar.size();i++){
3008 body.append(QString("%1 ").arg(fvar.at(i)));
3009 }
3010 body.append("\n\n");
3011 int part=0,resi=0;
3012 chgl->rehide();
3013 for (int i=0; i< mole.showatoms.size(); i++){
3014 if (mole.showatoms.at(i).hidden) continue;
3015 if ((mole.nopm1)&&(mole.showatoms.at(i).symmGroup)&&(mole.showatoms.at(i).part<-0)) continue; // ignore hidden parts (-1)
3016 if ((mole.showatoms.at(i).an!=-42)&&(mole.showatoms.at(i).resiNr!=resi))
3017 body.append(QString("RESI %1 %2\n").arg(mole.showatoms.at(i).resiNr).arg(mole.showatoms.at(i).ResiClass));
3018 if ((mole.showatoms.at(i).an!=-42)&&(mole.showatoms.at(i).part!=part))
3019 body.append(QString("PART %1\n").arg(mole.showatoms.at(i).part));
3020 if (mole.showatoms.at(i).an==-1)
3021 body.append(QString("%1 %2 %3 %4 %5 %6 %7 %8\n")
3022 .arg(mole.showatoms.at(i).Label.section('_',0,0).section(QString::fromUtf8("»"),0,0),-5)
3023 .arg(qMax(1,editor->sfac.indexOf(mole.showatoms.at(i).an)+1))
3024 .arg(mole.showatoms.at(i).frac.x,10,'f',6)
3025 .arg(mole.showatoms.at(i).frac.y,10,'f',6)
3026 .arg(mole.showatoms.at(i).frac.z,10,'f',6)
3027 .arg(mole.showatoms.at(i).sof_org,9,'f',5)
3028 .arg(mole.showatoms.at(i).uf.m33,9,'f',5)
3029 .arg(mole.showatoms.at(i).peakHeight,9,'f',2)
3030 );
3031 else if (mole.showatoms.at(i).an==-42){
3032 Matrix uf = mole.b2u(mole.showatoms.at(i).uf);
3033 body.append(QString("%1 %2 %3 %4 %5 %6 %7 %8 =\n %9 %10 %11 %12\n")
3034 .arg(mole.showatoms.at(i).Label.section('_',0,0).section(QString::fromUtf8("»"),0,0),-5)
3035 .arg(2)
3036 .arg(mole.showatoms.at(i).frac.x,10,'f',6)
3037 .arg(mole.showatoms.at(i).frac.y,10,'f',6)
3038 .arg(mole.showatoms.at(i).frac.z,10,'f',6)
3039 .arg(mole.showatoms.at(i).sof_org,9,'f',5)
3040 .arg(uf.m11,9,'f',5)
3041 .arg(uf.m22,9,'f',5)
3042 .arg(uf.m33,9,'f',5)
3043 .arg(uf.m23,9,'f',5)
3044 .arg(uf.m13,9,'f',5)
3045 .arg(uf.m12,9,'f',5)
3046 );
3047 }
3048 else {if (mole.showatoms.at(i).isIso){
3049 body.append(QString("%1 %2 %3 %4 %5 %6 %7!x\n")
3050 .arg(mole.showatoms.at(i).Label.section('_',0,0).section(QString::fromUtf8("»"),0,0),-5)
3051 .arg(qMax(1,editor->sfac.indexOf(mole.showatoms.at(i).an)+1))
3052 .arg(mole.showatoms.at(i).frac.x,10,'f',6)
3053 .arg(mole.showatoms.at(i).frac.y,10,'f',6)
3054 .arg(mole.showatoms.at(i).frac.z,10,'f',6)
3055 .arg(mole.showatoms.at(i).sof_org,9,'f',5)
3056 .arg(mole.showatoms.at(i).ufiso_org)
3057 );
3058 }else{
3059 body.append(QString("%1 %2 %3 %4 %5 %6 %7 %8 =\n %9 %10 %11 %12\n")
3060 .arg(mole.showatoms.at(i).Label.section('_',0,0).section(QString::fromUtf8("»"),0,0),-5)
3061 .arg(qMax(1,editor->sfac.indexOf(mole.showatoms.at(i).an)+1))
3062 .arg(mole.showatoms.at(i).frac.x,10,'f',6)
3063 .arg(mole.showatoms.at(i).frac.y,10,'f',6)
3064 .arg(mole.showatoms.at(i).frac.z,10,'f',6)
3065 .arg(mole.showatoms.at(i).sof_org,9,'f',5)
3066 .arg(mole.showatoms.at(i).uf.m11,9,'f',5)
3067 .arg(mole.showatoms.at(i).uf.m22,9,'f',5)
3068 .arg(mole.showatoms.at(i).uf.m33,9,'f',5)
3069 .arg(mole.showatoms.at(i).uf.m23,9,'f',5)
3070 .arg(mole.showatoms.at(i).uf.m13,9,'f',5)
3071 .arg(mole.showatoms.at(i).uf.m12,9,'f',5)
3072 );
3073 }}
3074 part=mole.showatoms.at(i).part;
3075 resi=mole.showatoms.at(i).resiNr;
3076 }
3077
3078 body.append("\n\n");
3079 QString eqi=mole.symmcode2human(mole.usedSymmetry);
3080 eqi.replace("&raquo;","EQIV $");
3081 eqi.replace(":","");
3082 eqi.replace("<b>","");
3083 eqi.replace("</b>","");
3084 eqi.replace("<br>","\n");
3085 body.append(eqi);
3086 body.append("\n\n");
3087 for (int i =0; i<mole.showbonds.size();i++){
3088 if (mole.showbonds.at(i).ato1->hidden) continue;
3089 if (mole.showbonds.at(i).ato2->hidden) continue;
3090 if ((mole.nopm1)&&(mole.showbonds.at(i).ato1->symmGroup)&&(mole.showbonds.at(i).ato1->part<0))continue; //
3091 if ((mole.nopm1)&&(mole.showbonds.at(i).ato2->symmGroup)&&(mole.showbonds.at(i).ato2->part<0))continue; // ignore hidden parts (-1)
3092 QString s1="",s2="",s3="";
3093 s1=mole.showbonds.at(i).ato1->Label;
3094 s2=mole.showbonds.at(i).ato2->Label;
3095 s1=s1.section(QString::fromUtf8("»"),0,0);
3096 s2=s2.section(QString::fromUtf8("»"),0,0);
3097 if ((mole.showbonds.at(i).ato2->symmGroup)||(mole.showbonds.at(i).ato1->symmGroup))
3098 s3.append(QString("_$%1").arg(qMax(mole.showbonds.at(i).ato1->symmGroup,mole.showbonds.at(i).ato2->symmGroup)));
3099 body.append(QString("BIND%3 %1 %2\n")
3100 .arg(s1)
3101 .arg(s2)
3102 .arg(s3));
3103 }
3104 body.append("\nHKLF 0 !don't refine this\nEND\n");
3105 bool success = f.open(QIODevice::WriteOnly|QIODevice::Text);
3106 if (success){
3107 f.write(body.toLatin1());
3108 f.close();
3109 }
3110 }
3111
3112 void Window::changeIconSize(){
3113 bool ok;
3114 int tbs=tbiconSize;
3115
3116 #if (QT_VERSION >= 0x040500)
3117 tbs=QInputDialog::getInt(this,"Change tool bar icon size...","Tool bar icon size:",tbiconSize,16,96,1,&ok);
3118 #else
3119 tbs=QInputDialog::getInteger(this,"Change tool bar icon size...","Tool bar icon size:",tbiconSize,16,32,1,&ok);
3120 #endif
3121 if (ok) tbiconSize=tbs;
3122 einstellung->beginGroup("ToolBarIcons");
3123 einstellung->setValue("ToolBarIconSize",tbiconSize);
3124 einstellung->endGroup();
3125 fito->setIconSize(QSize(tbiconSize,tbiconSize));
3126 editToolBar->setIconSize(QSize(tbiconSize,tbiconSize));
3127 refineToolBar->setIconSize(QSize(tbiconSize,tbiconSize));
3128 vito->setIconSize(QSize(tbiconSize,tbiconSize));
3129 extraTB->setIconSize(QSize(tbiconSize,tbiconSize));
3130 bottomToolBar->setIconSize(QSize(tbiconSize,tbiconSize));
3131 chgl->invertMouseZoom->setIconSize(QSize(tbiconSize,tbiconSize));
3132 homeMe->setIconSize(QSize(tbiconSize,tbiconSize));
3133 zoomIn->setIconSize(QSize(tbiconSize,tbiconSize));
3134 zoomOut->setIconSize(QSize(tbiconSize,tbiconSize));
3135 update();
3136 }
3137
3138 void Window::changeQPeakLimit(){
3139 bool ok;
3140 int limit=MaxNumberOfPeaks;
3141
3142 #if (QT_VERSION >= 0x040500)
3143 limit=QInputDialog::getInt(this,"Change maximum number of created Q-peaks","maximum number of created Q-peaks:",MaxNumberOfPeaks,1,600,1,&ok);
3144 #else
3145 limit=QInputDialog::getInteger(this,"Change maximum number of created Q-peaks","maximum number of created Q-peaks:",MaxNumberOfPeaks,1,600,1,&ok);
3146 #endif
3147 if (ok) MaxNumberOfPeaks=limit;
3148 actionQPeakLimit->setText(QString("change maximum number of created Q-peaks (%1)").arg(MaxNumberOfPeaks));
3149 update();
3150 }
3151
3152 void Window::jnk(){
3153 if (!fxle->doMaps->isChecked())fxle->doMaps->setChecked(true);
3154 fxle->maptrunc=fxle->mapSchnitt->currentIndex ();
3155 if ((fxle->rw!=fxle->weak->value())||(fxle->rr!=fxle->mapprec->value())){
3156 fxle->rr = fxle->mapprec->value();
3157 fxle->rw = fxle->weak->value();
3158 if (!fxle->loadFouAndPerform(fxle->fouName.toLocal8Bit(),false)){
3159 infoKanalNews(QString("<font color=red>Error while loading %1!</font><br>").arg(fxle->fouName));
3160 //printf("%d\n",__LINE__);
3161 fxle->killmaps();
3162 //printf("%d\n",__LINE__);
3163 }
3164 }
3165 chgl->lintrans = fxle->lineTrans->value();
3166 chgl->linwidth = fxle->lineWidth->value();
3167 fxle->map_radius = fxle->maprad->value();
3168 fxle->iso[0] = fxle->fomaps->value();
3169 fxle->iso[1] = -fxle->difmaps->value();
3170 fxle->jnk();
3171 }
3172
3173 void Window::deleteAllQ(){
3174
3175 if (editor->sfac.isEmpty()) return;
3176 bool isQ = false;
3177 for (int o = 0; o < mole.asymm.size();o++){
3178 if (mole.asymm.at(o).an == -1){
3179 isQ = true;
3180 break;
3181 }
3182 }
3183 if (!isQ) return;
3184 QTextCursor cursor = editor->textCursor();
3185 editor->wholeLine->setChecked(false);
3186 editor->replace->setText("");
3187 editor->searchLE->setText("^Q\\S+\\s+1\\s+\\S+\\s+\\S+\\s+\\S+\\s+\\S+\\s+\\S+\\s+\\S+\\s*");
3188 for (int i = mole.asymm.size()-1; i>=0; i-- ){
3189 if (mole.asymm.at(i).an==-1){
3190 QString s =
3191 QString("<font color=magenta>Deleted atom: %1 part:%2 residue:%3 %4 </font> Please save to update structure view.")
3192 .arg(mole.asymm.at(i).Label)
3193 .arg(mole.asymm.at(i).part)
3194 .arg(mole.asymm.at(i).resiNr)
3195 .arg(mole.asymm.at(i).ResiClass);
3196 infoKanalNews(s);
3197 deletedAtom.append(mole.asymm.at(i));
3198 mole.asymm.removeAt(i);
3199 }
3200 }
3201 editor->replaceAll();
3202 editor->searchLE->setText("");
3203
3204 mole.showatoms.clear();
3205 mole.showbonds.clear();
3206 chgl->mol->showatoms.clear();
3207 chgl->mol->showbonds.clear();
3208 chgl->mol->selectedatoms.clear();
3209
3210 for (int o=0; o<mole.asymm.size();o++)
3211 mole.showatoms.append(mole.asymm[o]);
3212 mole.packer(mole.sdmcompleter());
3213 mole.showbonds =
3214 mole.connecting(mole.showatoms);
3215 bool growYes=chgl->fuse->isVisible ();
3216 if (growYes) chgl->mol->grow();
3217 else chgl->mol->fuse();
3218 if ((chgl->rotze!=-1)&&(!chgl->enviPositions.isEmpty())){
3219 chgl->envi();
3220 }
3221 chgl->mol->selectedatoms.clear();
3222 chgl->showHidden();
3223
3224
3225 // printf("%d\n",__LINE__);
3226
3227 loadMolInTest();
3228 chgl->updateBondActions();
3229 chgl->update();
3230 update();
3231 chgl->update();
3232 }
3233
3234 void Window::sdm(){
3235 if (!(chgl->fuse->isVisible()||chgl->grow->isVisible ())){
3236 chgl->fuse->setVisible(true);
3237 chgl->grow->setVisible(false);
3238 }
3239 mole.showatoms.clear();
3240 mole.showbonds.clear();
3241 chgl->mol->showatoms.clear();
3242 chgl->mol->showbonds.clear();
3243 chgl->mol->selectedatoms.clear();
3244 for (int o=0; o<mole.asymm.size();o++)
3245 mole.showatoms.append(mole.asymm[o]);
3246 mole.packer(mole.sdmcompleter());
3247 mole.showbonds =
3248 mole.connecting(mole.showatoms);
3249
3250 chgl->mol->selectedatoms.clear();
3251
3252 bool growYes=chgl->fuse->isVisible ();
3253 chgl->mol->fuse();
3254 if (growYes) chgl->mol->grow();
3255
3256 // printf("%d\n",__LINE__);
3257 chgl->updateBondActions();
3258 infoKanalNews(mole.Fragments);
3259 chgl->update();
3260 update();
3261 chgl->update();
3262
3263 loadMolInTest();
3264 }
3265
3266 void Window::makeVoro(){
3267 int ind=-1;
3268 QAction *action = qobject_cast<QAction *>(sender());
3269 if (action!=NULL){
3270 ind=action->data().toInt();
3271 ind=qMax(ind,-1);
3272 ind=qMin(ind,mole.asymm.size()-1);
3273 }
3274 clearVoro->setVisible(true);
3275 /*if (tgl) tgl->ogl->voronoij(mole.asymm,ind);
3276 else mole.voronoij(mole.asymm,ind);*/
3277 chgl->voronoij(mole.asymm,ind);
3278 infoKanalNews(mole.voroMsg);
3279 chgl->update();
3280 }
3281
3282 void Window::clearVoros(){
3283 mole.vtriangles.clear();
3284 mole.vorobas=0;
3285 chgl->voroDestruct();
3286 clearVoro->setVisible(false);
3287 chgl->update();
3288 }
3289
3290 void Window::deleteAllH(){
3291 if (editor->sfac.isEmpty()) return;
3292 bool isH = false;
3293 for (int o = 0; o < mole.asymm.size(); o++){
3294 if (mole.asymm.at(o).an == 0){
3295 isH = true;
3296 break;
3297 }
3298 }
3299 if (!isH) return;
3300 /* maybeSave2();
3301 printf("deleteallh %d %d\n",mole.asymm.size(),chgl->mol->showatoms.size());*/
3302 chgl->mol->selectedatoms.clear();
3303 for (int o = 0; o < mole.asymm.size(); o++){
3304 if (mole.asymm.at(o).an == 0){
3305 chgl->mol->selectedatoms.append(chgl->mol->showatoms[o]);
3306 chgl->mol->selectedatoms.last().style=o;
3307 }
3308 }
3309 deleteSelectedAtoms();
3310 }
3311
3312 void Window::deleteSelectedAtoms(){
3313 if (chgl->mol->selectedatoms.isEmpty()){
3314 QAction *action = qobject_cast<QAction *>(sender());
3315 int index=-1;
3316 if (action)
3317 index=action->data().toInt();
3318 else index=-1;
3319 if (index>mole.asymm.size()) index=-1;
3320 if (index!=-1) {
3321 chgl->mol->selectedatoms.clear();
3322 chgl->mol->selectedatoms.append(chgl->mol->showatoms[index]);
3323 chgl->mol->selectedatoms.last().style=index;
3324 }
3325 }
3326 if (chgl->mol->selectedatoms.isEmpty()) return;
3327
3328 bool donotsymm=false;
3329 QTextCursor cursor = editor->textCursor();
3330 QTextDocument *document = editor->document();
3331 cursor.beginEditBlock();
3332 int ende=chgl->mol->selectedatoms.size();
3333 for (int i = 0; i < ende; i++ ){
3334 if (chgl->mol->selectedatoms.at(i).symmGroup) continue;
3335 if (chgl->mol->selectedatoms.at(i).Label.contains(QString::fromUtf8("»")))continue;
3336 if ((chgl->mol->selectedatoms.at(i).afix>0)&&(chgl->mol->selectedatoms.at(i).an>0)) continue;
3337 int wg=chgl->mol->selectedatoms.at(i).style;
3338 QString label = mole.asymm.at(wg).orginalLine.left(80).trimmed();
3339 cursor.movePosition(QTextCursor::Start);
3340 cursor = document->find(label,cursor);
3341 if (cursor.isNull()){
3342 cursor = editor->textCursor();
3343 cursor.movePosition(QTextCursor::Start);
3344 label.chop(10);
3345 cursor = document->find(label,cursor);
3346 if (cursor.isNull()) {
3347 cursor = editor->textCursor();
3348 printf("hab was nicht %d/%d %d [%s]\n",i,ende,static_cast<int>(chgl->mol->selectedatoms.size()),label.toStdString().c_str());
3349 continue;
3350 }
3351 }
3352 cursor.movePosition(QTextCursor::StartOfLine,QTextCursor::MoveAnchor);
3353 //printf("wg2160->%d %s\n",wg,label.toStdString().c_str());
3354 bool afx=false;
3355 if (editor->parenthesis.at(cursor.blockNumber())){
3356 afx=true;
3357 do {
3358 if (!cursor.block().text().contains("afix",Qt::CaseInsensitive)) wg--;
3359 cursor.movePosition(QTextCursor::Up,QTextCursor::MoveAnchor);
3360 }while(!cursor.block().text().contains("afix",Qt::CaseInsensitive));
3361 cursor.movePosition(QTextCursor::Down,QTextCursor::KeepAnchor);
3362 }
3363 //printf("wg2168->%d [%s] {%s}\n",wg,cursor.selectedText().toStdString().c_str(),cursor.block().text().toStdString().c_str());
3364 cursor.movePosition(QTextCursor::EndOfLine,QTextCursor::KeepAnchor);
3365 while (cursor.selectedText().endsWith("=")) {
3366 cursor.movePosition(QTextCursor::Down,QTextCursor::KeepAnchor);
3367 cursor.movePosition(QTextCursor::EndOfLine,QTextCursor::KeepAnchor);
3368 }
3369 int haa=1;
3370 if (afx)
3371 while (!cursor.block().text().contains("afix",Qt::CaseInsensitive)){
3372 cursor.movePosition(QTextCursor::Down,QTextCursor::KeepAnchor);
3373 cursor.movePosition(QTextCursor::EndOfLine,QTextCursor::KeepAnchor);
3374 if ((!cursor.block().text().contains("afix",Qt::CaseInsensitive))&&(wg+haa)<chgl->mol->showatoms.size()){
3375 chgl->mol->selectedatoms.append(chgl->mol->showatoms.at(wg+haa));
3376 chgl->mol->selectedatoms.last().style=wg+haa;
3377 haa++;
3378 }
3379 /* printf("wg+ =%d %d/%d %d\n",wg+haa,cursor.blockNumber()+2,(editor->parenthesis.size()),editor->blockCount());
3380 printf("[[%s]]\n", cursor.selectedText().toStdString().c_str());
3381 printf("%d %d!\n",editor->parenthesis.at(cursor.blockNumber()+1),editor->parenthesis.at(cursor.blockNumber()+2));
3382 */
3383 }
3384 //printf("wg2191->[%s]\n",cursor.selectedText().toStdString().c_str());
3385 cursor.deleteChar();
3386 cursor.deleteChar();
3387 editor->updateAfix();
3388 }
3389
3390 for (int i = chgl->mol->selectedatoms.size()-1; i>=0; i-- ){
3391 if (chgl->mol->selectedatoms.at(i).Label.contains(QString::fromUtf8("»"))){donotsymm=true;continue;}
3392 if (chgl->mol->selectedatoms.at(i).symmGroup){donotsymm=true;continue;}
3393 QString s =
3394 QString("<font color=magenta>Deleted atom: %1 part:%2 residue:%3 %4 </font> Please save to update structure view.")
3395 .arg(chgl->mol->selectedatoms.at(i).Label)
3396 .arg(chgl->mol->selectedatoms.at(i).part)
3397 .arg(chgl->mol->selectedatoms.at(i).resiNr)
3398 .arg(chgl->mol->selectedatoms.at(i).ResiClass);
3399 infoKanalNews(s);
3400 int wg=mole.asymm.indexOf(chgl->mol->selectedatoms.at(i));
3401 if (wg<0) continue;
3402 deletedAtom.append(mole.asymm.at(wg));
3403 mole.asymm.removeAt(wg);
3404 }
3405
3406 cursor.endEditBlock();
3407
3408 mole.showatoms.clear();
3409 mole.showbonds.clear();
3410 chgl->mol->showatoms.clear();
3411 chgl->mol->showbonds.clear();
3412 chgl->mol->selectedatoms.clear();
3413 for (int o=0; o<mole.asymm.size();o++)
3414 mole.showatoms.append(mole.asymm[o]);
3415 mole.packer(mole.sdmcompleter());
3416 mole.showbonds =
3417 mole.connecting(mole.showatoms);
3418
3419 chgl->setMolecule(&mole);
3420 loadMolInTest();
3421
3422
3423 chgl->mol->selectedatoms.clear();
3424
3425
3426 bool growYes=chgl->fuse->isVisible ();
3427 chgl->mol->fuse();
3428 if (growYes) chgl->mol->grow();
3429
3430 switch (duplicates()){
3431 case 1:infoKanalNews("<font color=orange >Some hydrogen atoms have identical names please check.</font>");break;
3432 case 2:infoKanalNews("<font color=red >Some non-hydrogen atoms have identical names. YOU HAVE TO CHECK BEFORE REFINING!</font>");break;
3433 case 3:infoKanalNews("<font color=red >Some atoms have identical names. YOU HAVE TO CHECK BEFORE REFINING!</font>");break;
3434 }
3435 if (donotsymm) QMessageBox::information(0,"information","Only unique atoms can be deleted!");
3436
3437 // printf("%d\n",__LINE__);
3438
3439 loadMolInTest();
3440 chgl->updateBondActions();
3441 chgl->update();
3442 update();
3443 chgl->update();
3444 /*
3445 }
3446 else {chgl->disSelection();}*/
3447 }
3448
3449 void Window::createCentroid(){
3450 if (chgl->mol->selectedatoms.isEmpty()) return;
3451
3452 QTextCursor cursor = editor->textCursor();
3453 QTextDocument *document = editor->document();
3454 cursor.beginEditBlock();
3455 int ctrcnt=1;
3456 for (int i=0; i<mole.asymm.size();i++){
3457 if ((mole.asymm.at(i).an==-66)&&(mole.asymm.at(i).Label.startsWith("Cnt",Qt::CaseInsensitive)))
3458 ctrcnt++;
3459 }
3460 int ende=chgl->mol->selectedatoms.size();
3461 V3 posc = V3(0,0,0), posf = V3(0,0,0);
3462 QString creatorS;
3463 for (int i = 0; i < ende; i++ ){
3464 posc+=chgl->mol->selectedatoms.at(i).pos;
3465 creatorS.append(chgl->mol->selectedatoms.at(i).Label+", ");
3466 if (creatorS.section('\n',-1).size()>50) creatorS.append("\nREM ");
3467 }
3468 posc*=1.0/ende;
3469 mole.kart2frac(posc,posf);
3470 MyAtom ctr ;
3471 ctr.an=-66;
3472 ctr.part=0;
3473 ctr.peakHeight=9999.99;
3474 ctr.resiNr=0;
3475 ctr.hidden=0;
3476 ctr.symmGroup=0;
3477 ctr.sg=0;
3478 ctr.scod=555;//the identity
3479 ctr.auidx=-1;
3480 ctr.uc.m12=ctr.uc.m23=ctr.uc.m13=0.0;
3481 ctr.uc.m21=ctr.uc.m32=ctr.uc.m31=0.0;
3482 ctr.uf.m12=ctr.uf.m23=ctr.uf.m13=0.0;
3483 ctr.uf.m21=ctr.uf.m32=ctr.uf.m31=0.0;
3484 ctr.pos=posc;
3485 ctr.frac=posf;
3486 if (!editor->sfac.contains(-66)){
3487 editor->sfac.append(-66);
3488 editor->unitNeu.append(" 0");
3489 cursor.movePosition(QTextCursor::Start);
3490 cursor = document->find(editor->unitAlt,cursor);
3491 if (cursor.isNull()) {
3492 cursor = editor->textCursor();
3493 cursor.endEditBlock ();
3494 printf("can't find unit\n");
3495 update();
3496 return;
3497 }
3498 cursor.movePosition(QTextCursor::StartOfLine,QTextCursor::MoveAnchor);
3499 cursor.movePosition(QTextCursor::EndOfLine,QTextCursor::KeepAnchor);
3500 cursor.deleteChar();
3501 cursor.insertText(editor->unitNeu);
3502
3503 cursor.movePosition(QTextCursor::Start);
3504 cursor = document->find(editor->unitNeu,cursor);
3505 cursor.clearSelection ();
3506 cursor.movePosition(QTextCursor::StartOfLine,QTextCursor::MoveAnchor);
3507 cursor.insertText("SFAC cnt 0 0 0 0 0 0 0 0 0 0 0 0 0 0.1 ! centroid dummy\n");
3508 }
3509 cursor.movePosition(QTextCursor::Start);
3510 cursor = document->find("HKLF",cursor);
3511 cursor.movePosition(QTextCursor::StartOfLine,QTextCursor::MoveAnchor);
3512 cursor.insertText(ctr.orginalLine=QString("Cnt%5 %1 %2 %3 %4 10.000 0.001 ! centroid\n")
3513 .arg(editor->sfac.indexOf(-66)+1)
3514 .arg(posf.x,10,'f',6)
3515 .arg(posf.y,10,'f',6)
3516 .arg(posf.z,10,'f',6)
3517 .arg(ctrcnt,0,36));
3518 cursor.insertText(QString("REM Cnt%1 was created from: %2\n").arg(ctrcnt,0,36).arg(creatorS));
3519
3520 for (int i = 0; i < ende; i++ ){
3521 cursor.insertText(QString("FREE Cnt%1 %2 ! this might be needed for AFIX\n").arg(ctrcnt,0,36).arg(chgl->mol->selectedatoms.at(i).Label.section('_',0,0).section(QString::fromUtf8("»"),0,0)));
3522 }
3523 ctr.orginalLine= QString("Cnt%5 %1 %2 %3 %4 10.000 0.001\n")
3524 .arg(editor->sfac.indexOf(-66)+1)
3525 .arg(posf.x,10,'f',6)
3526 .arg(posf.y,10,'f',6)
3527 .arg(posf.z,10,'f',6)
3528 .arg(ctrcnt,0,36);
3529 ctr.Label=QString("Cnt%1").arg(ctrcnt,0,36);
3530 cursor.endEditBlock ();
3531 editor->setTextCursor(cursor);
3532 editor->centerCursor () ;
3533 cursor.clearSelection ();
3534 editor->setTextCursor(cursor);
3535 editor->setFocus () ;
3536 mole.asymm.append(ctr);
3537
3538 mole.showatoms.clear();
3539 mole.showbonds.clear();
3540 chgl->mol->showatoms.clear();
3541 chgl->mol->showbonds.clear();
3542 chgl->mol->selectedatoms.clear();
3543 for (int o=0; o<mole.asymm.size();o++){
3544 mole.showatoms.append(mole.asymm[o]);
3545 }
3546 mole.sdmcompleter();
3547 mole.showbonds =
3548 mole.connecting(mole.showatoms);
3549 chgl->setMolecule(&mole);
3550 chgl->mol->selectedatoms.clear();
3551
3552 bool growYes=chgl->fuse->isVisible ();
3553 chgl->mol->fuse();
3554 if (growYes) chgl->mol->grow();
3555
3556 // printf("%d\n",__LINE__);
3557 loadMolInTest();
3558
3559 chgl->update();
3560 update();
3561 }
3562
3563 void Window::moveSymmMateSel(){
3564
3565 QString kep,nextli;
3566 QTextCursor cursor = editor->textCursor();
3567 QTextDocument *document = editor->document();
3568 cursor.beginEditBlock();
3569 for (int si=0; si<mole.selectedatoms.size();si++){
3570 QString source,target;
3571 source=mole.selectedatoms.at(si).Label;
3572 target=source.section(QString::fromUtf8("»"),0,0);
3573 MyAtom ato=mole.selectedatoms.at(si);
3574 ato.Label=target;
3575 ato.symmGroup=0;
3576 ato.sg=0;
3577 ato.scod=555;//the identity
3578 int that=mole.asymm.indexOf(ato);
3579 ato.auidx=that;
3580 if ((that>=mole.asymm.size())||(that<0)) return;
3581 QString susu=mole.asymm.at(that).orginalLine;
3582 cursor.movePosition(QTextCursor::Start);
3583 cursor = document->find(susu,cursor);
3584 if (mole.asymm.at(that).isIso){
3585 ato.ufiso_org = mole.asymm.at(that).ufiso_org;
3586 kep=QString("%1 %2 %3 %4 %5 %6 %7")
3587 .arg(ato.Label.section('_',0,0),-5)
3588 .arg(qMax(1,editor->sfac.indexOf(ato.an)+1))
3589 .arg(ato.frac.x,10,'f',6)
3590 .arg(ato.frac.y,10,'f',6)
3591 .arg(ato.frac.z,10,'f',6)
3592 .arg(mole.asymm.at(that).sof_org,9,'f',5)
3593 .arg(ato.ufiso_org)
3594 ;
3595 ato.uf.m11=ato.uc.m11=ato.uc.m22=ato.uc.m33= mole.asymm.at(that).uf.m11;
3596 ato.isIso=true;
3597 ato.uc.m12=ato.uc.m13=ato.uc.m23=ato.uc.m21=ato.uc.m31=ato.uc.m32=0;
3598 cursor.deleteChar();
3599 cursor.insertText(kep);
3600 cursor.setPosition(cursor.position(), QTextCursor::MoveAnchor);
3601 editor->wholeLine->setChecked(false);
3602 editor->replaceNext();
3603 }else{
3604 kep=QString("%1 %2 %3 %4 %5 %6 %7 %8 ")
3605 .arg(ato.Label.section('_',0,0),-5)
3606 .arg(qMax(1,editor->sfac.indexOf(ato.an)+1))
3607 .arg(ato.frac.x,10,'f',6)
3608 .arg(ato.frac.y,10,'f',6)
3609 .arg(ato.frac.z,10,'f',6)
3610 .arg(mole.asymm.at(that).sof_org,9,'f',5)
3611 .arg(ato.uf.m11,9,'f',5)
3612 .arg(ato.uf.m22,9,'f',5);
3613 ato.sof_org=mole.asymm.at(that).sof_org;
3614 cursor.deleteChar();
3615 cursor.insertText(kep);
3616 cursor.setPosition(cursor.position(), QTextCursor::MoveAnchor);
3617 cursor.movePosition(QTextCursor::Down);
3618 cursor.movePosition(QTextCursor::StartOfLine,QTextCursor::MoveAnchor);
3619 cursor.movePosition(QTextCursor::EndOfLine,QTextCursor::KeepAnchor);
3620 nextli=cursor.selectedText();
3621 cursor = document->find(nextli,cursor);
3622
3623 cursor.deleteChar();
3624 cursor.insertText(QString(" %1 %2 %3 %4")
3625 .arg(ato.uf.m33,9,'f',5)
3626 .arg(ato.uf.m23,9,'f',5)
3627 .arg(ato.uf.m13,9,'f',5)
3628 .arg(ato.uf.m12,9,'f',5));
3629 cursor.setPosition(cursor.position(), QTextCursor::MoveAnchor);
3630 }
3631 ato.orginalLine=kep.section("=",0,0);
3632 mole.asymm[that]=ato;
3633 }
3634
3635 cursor = editor->textCursor();
3636 cursor.endEditBlock();
3637
3638 mole.showatoms.clear();
3639 mole.showbonds.clear();
3640 chgl->mol->showatoms.clear();
3641 chgl->mol->showbonds.clear();
3642 chgl->mol->selectedatoms.clear();
3643 for (int o=0; o<mole.asymm.size();o++)
3644 mole.showatoms.append(mole.asymm[o]);
3645 mole.sdmcompleter();
3646 mole.showbonds =
3647 mole.connecting(mole.showatoms);
3648 chgl->setMolecule(&mole);
3649 chgl->mol->selectedatoms.clear();
3650
3651 bool growYes=chgl->fuse->isVisible ();
3652 chgl->mol->fuse();
3653 if (growYes) chgl->mol->grow();
3654 editor->searchLE->setText("");
3655 editor->hideSearch();
3656 loadMolInTest();
3657
3658 // printf("%d\n",__LINE__);
3659 chgl->update();
3660 update();
3661 }
3662
3663 void Window::moveSymmMate(){
3664 QAction *action = qobject_cast<QAction *>(sender());
3665 int index=0;
3666 if (action)
3667 index=action->data().toInt();
3668 else return;
3669 QString source,target;
3670 source=chgl->mol->showatoms.at(index).Label;
3671 target=source.section(QString::fromUtf8("»"),0,0);
3672 MyAtom ato=chgl->mol->showatoms.at(index);
3673 ato.Label=target;
3674 ato.symmGroup=0;
3675 ato.sg=0;
3676 ato.scod=555;//the identity
3677 int that=mole.asymm.indexOf(ato);
3678 ato.auidx=that;
3679 if ((that>=mole.asymm.size())||(that<0)) return;
3680 QString susu=mole.asymm.at(that).orginalLine;
3681 editor->searchLE->setText(susu);
3682 if (mole.asymm.at(that).isIso){
3683 ato.ufiso_org = mole.asymm.at(that).ufiso_org;
3684 editor->replace->setText(QString("%1 %2 %3 %4 %5 %6 %7")
3685 .arg(ato.Label.section('_',0,0),-5)
3686 .arg(qMax(1, editor->sfac.indexOf(ato.an)+1))
3687 .arg(ato.frac.x,10,'f',6)
3688 .arg(ato.frac.y,10,'f',6)
3689 .arg(ato.frac.z,10,'f',6)
3690 .arg(mole.asymm.at(that).sof_org,9,'f',5)
3691 .arg(ato.ufiso_org)
3692 );
3693 ato.uf.m11=ato.uc.m11=ato.uc.m22=ato.uc.m33= mole.asymm.at(that).uf.m11;
3694 ato.isIso=true;
3695 ato.uc.m12=ato.uc.m13=ato.uc.m23=ato.uc.m21=ato.uc.m31=ato.uc.m32=0;
3696 editor->wholeLine->setChecked(false);
3697 editor->replaceNext();
3698
3699 }else{
3700 QString kep=QString("%1 %2 %3 %4 %5 %6 %7 %8 ")
3701 .arg(ato.Label.section('_',0,0),-5)
3702 .arg(qMax(1,editor->sfac.indexOf(ato.an)+1))
3703 .arg(ato.frac.x,10,'f',6)
3704 .arg(ato.frac.y,10,'f',6)
3705 .arg(ato.frac.z,10,'f',6)
3706 .arg(mole.asymm.at(that).sof_org,9,'f',5)
3707 .arg(ato.uf.m11,9,'f',5)
3708 .arg(ato.uf.m22,9,'f',5);
3709
3710 editor->replace->setText(kep);
3711 editor->wholeLine->setChecked(false);
3712 editor->replaceNext();
3713 editor->searchLE->setText(editor->replace->text());
3714 editor->replace->setText("");
3715 editor->findNext();
3716 QTextCursor cursor = editor->textCursor();
3717 cursor.movePosition(QTextCursor::Down);
3718 cursor.movePosition(QTextCursor::StartOfLine,QTextCursor::MoveAnchor);
3719 cursor.movePosition(QTextCursor::EndOfLine,QTextCursor::KeepAnchor);
3720 editor->searchLE->setText(cursor.selectedText());
3721 editor->replace->setText(QString(" %1 %2 %3 %4")
3722 .arg(ato.uf.m33,9,'f',5)
3723 .arg(ato.uf.m23,9,'f',5)
3724 .arg(ato.uf.m13,9,'f',5)
3725 .arg(ato.uf.m12,9,'f',5)
3726 );
3727
3728 editor->replaceNext();
3729 editor->replace->setText(kep);
3730 }
3731 editor->searchLE->setText(editor->replace->text());
3732 editor->replace->setText("");
3733 editor->findNext();
3734 QTextCursor cursor = editor->textCursor();
3735 ato.orginalLine=cursor.selectedText().section("=",0,0);
3736 mole.asymm[that]=ato;
3737
3738
3739 mole.showatoms.clear();
3740 mole.showbonds.clear();
3741 chgl->mol->showatoms.clear();
3742 chgl->mol->showbonds.clear();
3743 chgl->mol->selectedatoms.clear();
3744 for (int o=0; o<mole.asymm.size();o++)
3745 mole.showatoms.append(mole.asymm[o]);
3746 mole.sdmcompleter();
3747 mole.showbonds =
3748 mole.connecting(mole.showatoms);
3749 chgl->setMolecule(&mole);
3750 chgl->mol->selectedatoms.clear();
3751
3752 bool growYes=chgl->fuse->isVisible ();
3753 chgl->mol->fuse();
3754 if (growYes) chgl->mol->grow();
3755 editor->searchLE->setText("");
3756 editor->hideSearch();
3757 loadMolInTest();
3758
3759 // printf("%d\n",__LINE__);
3760 chgl->update();
3761 update();
3762 }
3763
3764 void Window::copySymmMate(){
3765 QAction *action = qobject_cast<QAction *>(sender());
3766 int index=0;
3767 if (action)
3768 index=action->data().toInt();
3769 else return;
3770 QString source,target;
3771 source=chgl->mol->showatoms.at(index).Label;
3772 target=source.section(QString::fromUtf8("»"),0,0);
3773 MyAtom ato=chgl->mol->showatoms.at(index);
3774 ato.Label=target;
3775 ato.symmGroup=0;
3776 ato.sg=0;
3777 ato.scod=555;//the identity
3778 int that=mole.asymm.indexOf(ato);
3779 ato.auidx=that;
3780 if ((that>=mole.asymm.size())||(that<0)) return;
3781 QString susu=mole.asymm.at(that).orginalLine;
3782 QTextCursor cursor = editor->textCursor();
3783 cursor.movePosition(QTextCursor::Start);
3784 QTextDocument *document = editor->document();
3785 if (document->find(susu, cursor).isNull()) {
3786 QMessageBox::information(0,"information","The File is out of sync with the model. Please save and try again!");
3787 return;
3788 }
3789 cursor.beginEditBlock();
3790 cursor.movePosition(QTextCursor::Start);
3791 cursor = document->find("HKLF",cursor);
3792 cursor.movePosition(QTextCursor::StartOfLine,QTextCursor::MoveAnchor);
3793 cursor.movePosition(QTextCursor::Up,QTextCursor::KeepAnchor);
3794 if (editor->parenthesis.at(cursor.blockNumber())){
3795 cursor.select(QTextCursor::WordUnderCursor);
3796 if ((cursor.selectedText().contains("RESI",Qt::CaseInsensitive))||(cursor.selectedText().contains("PART",Qt::CaseInsensitive)))
3797 cursor.movePosition(QTextCursor::Up,QTextCursor::KeepAnchor);
3798 cursor.select(QTextCursor::WordUnderCursor);
3799 if ((cursor.selectedText().contains("RESI",Qt::CaseInsensitive))||(cursor.selectedText().contains("PART",Qt::CaseInsensitive)))
3800 cursor.movePosition(QTextCursor::Up,QTextCursor::KeepAnchor);
3801 cursor.movePosition(QTextCursor::Down,QTextCursor::MoveAnchor);
3802 cursor.clearSelection();
3803 cursor.insertText("AFIX 0 \n");
3804 }
3805 /////////////////////////////
3806 cursor.movePosition(QTextCursor::Start);
3807 cursor = document->find(susu, cursor);
3808 cursor.movePosition(QTextCursor::Down);
3809 cursor.movePosition(QTextCursor::StartOfLine);
3810 if (mole.asymm.at(that).Label.contains(numbers)) {
3811 int p=mole.asymm.at(that).an;
3812 labelPSE=mole.pse(p);
3813
3814 labelIndex=mole.asymm.at(that).Label.section(nonumbers,0,0,QString::SectionSkipEmpty).toInt();
3815 labelSuffix=mole.asymm.at(that).Label.section(numbers,1,1);
3816 labelSuffix.remove(vorneweg);
3817 }
3818 else{
3819 int p=mole.asymm.at(that).an;
3820 labelPSE=mole.pse(p);
3821 labelIndex=-1;
3822 labelSuffix=mole.asymm.at(that).Label;
3823 labelSuffix.remove(0,labelPSE.size());
3824 labelSuffix.remove(vorneweg);
3825 }
3826
3827 partSpin->setValue(mole.asymm.at(that).part);
3828 resiNrSpin->setValue(mole.asymm.at(that).resiNr);
3829 resiResiClass->setText(mole.asymm.at(that).ResiClass);
3830 pserbt[mole.asymm.at(that).an+1]->setChecked(true);
3831 renamUpdate(false);
3832 updateLabel();
3833 QString neues=nextLabel;
3834 if (mole.asymm.at(that).isIso){
3835 cursor.insertText(QString("%1 %2 %3 %4 %5 %6 %7 !copy\n")
3836 .arg(neues,-5)//1
3837 .arg(qMax(1,editor->sfac.indexOf(ato.an)+1))//2
3838 .arg(ato.frac.x,10,'f',6)//3
3839 .arg(ato.frac.y,10,'f',6)//4
3840 .arg(ato.frac.z,10,'f',6)//5
3841 .arg(mole.asymm.at(that).sof_org,9,'f',5)//6
3842 .arg(ato.uf.m33=mole.asymm.at(that).uf.m33,9,'f',5)//7
3843 );
3844
3845 }else{
3846 cursor.movePosition(QTextCursor::Down);
3847 cursor.movePosition(QTextCursor::StartOfLine);
3848 while(editor->parenthesis.at(cursor.blockNumber()+1)){
3849 cursor.movePosition(QTextCursor::Down);
3850 cursor.movePosition(QTextCursor::StartOfLine);
3851 }
3852 cursor.insertText(QString("%1 %2 %3 %4 %5 %6 %7 %8 =\n %9 %10 %11 %12 !copy\n")
3853 .arg(neues,-5)//1
3854 .arg(qMax(1,editor->sfac.indexOf(ato.an)+1))//2
3855 .arg(ato.frac.x,10,'f',6)//3
3856 .arg(ato.frac.y,10,'f',6)//4
3857 .arg(ato.frac.z,10,'f',6)//5
3858 .arg(mole.asymm.at(that).sof_org,9,'f',5)//6
3859 .arg(ato.uf.m11,9,'f',5)//7
3860 .arg(ato.uf.m22,9,'f',5)//8
3861 .arg(ato.uf.m33,9,'f',5)//9
3862 .arg(ato.uf.m23,9,'f',5)//10
3863 .arg(ato.uf.m13,9,'f',5)//11
3864 .arg(ato.uf.m12,9,'f',5)//12
3865 );
3866
3867 }
3868 QString nn=QString("%1_%3%4")
3869 .arg(nextLabel)
3870 .arg((resiNrSpin->value())?QString::number(resiNrSpin->value()):"")
3871 .arg((partSpin->value())?QString::number((partSpin->value()<0)?
3872 36+partSpin->value():
3873 partSpin->value()+9,36):"");
3874 ato.Label=nn;
3875 mole.asymm.append(ato);
3876 cursor.endEditBlock();
3877 renamUpdate(false);
3878 updateLabel();
3879
3880 mole.showatoms.clear();
3881 mole.showbonds.clear();
3882 chgl->mol->showatoms.clear();
3883 chgl->mol->showbonds.clear();
3884 chgl->mol->selectedatoms.clear();
3885 for (int o=0; o<mole.asymm.size();o++)
3886 mole.showatoms.append(mole.asymm[o]);
3887 mole.sdmcompleter();
3888 mole.showbonds =
3889 mole.connecting(mole.showatoms);
3890 chgl->setMolecule(&mole);
3891 chgl->mol->selectedatoms.clear();
3892
3893 bool growYes=chgl->fuse->isVisible ();
3894 chgl->mol->fuse();
3895 if (growYes) chgl->mol->grow();
3896 loadMolInTest();
3897
3898 // printf("%d\n",__LINE__);
3899 chgl->update();
3900 update();
3901 }
3902
3903 void Window::updateTieFreeVar(){
3904 int part = partSpin->value();
3905 if (!part) {
3906 tieOccL->hide();
3907 tieType->hide();
3908 tieType->setCurrentIndex(0);
3909 tieFVNrL->hide();
3910 tieFVNr->hide();
3911 tieUsedL->hide();
3912 tieFix->hide();
3913 update();
3914 return;
3915 }
3916 tieOccL->show();
3917 tieType->show();
3918
3919 if (tieType->itemData(tieType->currentIndex()).toInt()){
3920 tieFVNrL->show();
3921 tieFVNr->show();
3922 tieUsedL->hide();
3923 tieFix->hide();
3924 int j=tieFVNr->value();
3925 tieUsedL->setText(QString("fv(%1)=%3 [%2x used]")
3926 .arg(j)
3927 .arg(fvarCntr.value(j))
3928 .arg((fvar.size()>(j-1))?fvar.at(j-1):0.666) );
3929 tieFVNr->setMaximum(fvar.size()+1);
3930 if (j!=1) tieUsedL->show();
3931 else {
3932 tieFix->show();
3933 tieType->hide();
3934 }
3935 }else{
3936 tieFVNrL->hide();
3937 tieFVNr->hide();
3938 tieUsedL->hide();
3939 tieFix->hide();
3940 }
3941 update();
3942 }
3943
3944 void Window::clipboardDataChanged(){
3945 #ifndef QT_NO_CLIPBOARD
3946 actionPaste->setEnabled(!QApplication::clipboard()->text().isEmpty());
3947 #endif
3948 }
3949
3950 void Window::shxActUpdate(bool vis){
3951 bool v = shxOutputDock->isVisible();
3952 editToolBar->setVisible(vis|v);
3953 refineToolBar->setVisible(vis|v);
3954 actionSearch->setVisible(vis|v);
3955 actionNext->setVisible(vis|v);
3956 actionPrev->setVisible(vis|v);
3957 actionUndo->setVisible(vis);
3958 actionRedo->setVisible(vis);
3959 actionCut->setVisible(vis);
3960 actionCopy->setVisible(vis);
3961 actionPaste->setVisible(vis);
3962 actionEP->setVisible(vis|v);
3963 actionEM->setVisible(vis|v);
3964 }
3965
3966 void Window::shxOPTUpdate(bool vis){
3967
3968 bool v = shxEditorDock->isVisible();
3969
3970 xlPutor->hideSearch();
3971 editToolBar->setVisible(vis|v);
3972 refineToolBar->setVisible(vis|v);
3973 actionSearch->setVisible(vis|v);
3974 actionNext->setVisible(vis|v);
3975 actionPrev->setVisible(vis|v);
3976 actionEP->setVisible(vis|v);
3977 actionEM->setVisible(vis|v);
3978 update();
3979 }
3980
3981 void Window::renamUpdate(bool vis){
3982 /*QElapsedTimer tmr;
3983 int ran=rand();
3984 tmr.start();*/
3985 //printf("==>%lld %d\n",tmr.elapsed(), ran);
3986 enterRenameMode->setChecked(vis);
3987 enterRenameMode->setText((vis)?"Exit Rename Mode":"Rename Mode");
3988 renamUpdateAct->setChecked(false);
3989 updateTieFreeVar();
3990 labelSuffix = "";
3991 sufixBox->clearEditText();
3992 sufixBox->setCurrentIndex(1);
3993 psew->hide();
3994 willpse->show();
3995 QStringList RCL;//ResiClassList
3996 RCL.append("");
3997 QString curcls=resiResiClass->text();
3998 if (!curcls.isEmpty()) RCL.append(curcls);
3999 for (int i=0; i<mole.asymm.size(); i++){
4000 if (mole.asymm.at(i).an<0) continue;
4001 if (!RCL.contains(mole.asymm.at(i).ResiClass))RCL.append(mole.asymm.at(i).ResiClass);
4002 }
4003 //printf("%d\n",RCL.size());
4004 resiResiClassCB->clear();
4005 resiResiClassCB->addItems(RCL);
4006 if (!curcls.isEmpty()) resiResiClassCB->setCurrentIndex(resiResiClassCB->findText(curcls));
4007 renameRNchanged(resiNrSpin->value());
4008 resiResiClass->setText(curcls);
4009
4010 if (vis) {
4011 renamDock->show();
4012 renamDock->raise();
4013 if (dock->isVisible()) dock->hide();
4014 if (histDock->isVisible()) histDock->hide();
4015 //if (!renamDock->isVisible()) renamDock->show();
4016 machPlatz=true;
4017 //printf("renamDock->raise()\n");
4018 renamDock->raise();
4019 //renamDock->raise();
4020 editToolBar->setVisible(vis);
4021 refineToolBar->setVisible(vis);
4022 actionSearch->setVisible(vis);
4023 actionNext->setVisible(vis);
4024 actionPrev->setVisible(vis);
4025 actionUndo->setVisible(vis);
4026 actionRedo->setVisible(vis);
4027 actionCut->setVisible(vis);
4028 actionCopy->setVisible(vis);
4029 actionPaste->setVisible(vis);
4030 actionEP->setVisible(vis);
4031 actionEM->setVisible(vis);
4032 //printf(" . da\n");
4033
4034 }
4035 else if (enterRenameMode->text()=="Rename Mode"){
4036 if ((machPlatz)&&(!dock->isVisible())&&(!histDock->isVisible())) {
4037 //printf(" da %d\n",vis);
4038 dock->show();
4039 histDock->show();
4040 shxEditorDock->show();
4041 shxEditorDock->raise();
4042 machPlatz=false;
4043 }
4044 }
4045 if (strcmp(PROGRAM_NAME,"shelXle")){
4046 if ((vis)&&(height()>hhh)) {
4047 #if defined(linux)
4048 showMaximized ();
4049 showNormal ();
4050 #endif
4051 //printf("da\n");
4052 showMaximized ();
4053 }
4054 }
4055 //printf("rename update %lld %s\n",tmr.elapsed(),(vis)?"true":"false");
4056 /*
4057 if ((vis)&&(renamDock->isVisible())){chgl->updateLabelTextures();
4058 //printf("rename update textures %lld %d\n",tmr.elapsed(),ran);
4059 }*/
4060 }
4061
4062 void Window::addNewScatteringFactor(int oz, bool HisD){
4063 QString smbl=((oz==0) && HisD)?"D":chgl->mol->pse(oz);
4064 changeElemetofLabel(smbl);
4065 if (editor->sfacsmbl.contains(smbl)) {
4066 pserbt[oz+1]->setChecked(true);
4067 return;
4068 }
4069 editor->sfac.append(oz);
4070 editor->sfacsmbl.append(smbl);
4071 int an = ((oz==0) && HisD)?110:editor->sfac.last()+1;
4072
4073 pserbt[an]->show();
4074 pserbt[an]->setChecked(true);
4075 sfacBox->setFixedSize((editor->sfacsmbl.size()+1)*52,70);
4076
4077 QTextDocument *document = editor->document();
4078 QTextCursor cursor = editor->textCursor();
4079 cursor.beginEditBlock();
4080 cursor.movePosition(QTextCursor::End);
4081 cursor = document->find("sfac", cursor, QTextDocument::FindBackward);
4082 if (!cursor.isNull()){
4083 cursor.movePosition(QTextCursor::StartOfLine,QTextCursor::MoveAnchor);
4084 cursor.movePosition(QTextCursor::EndOfLine,QTextCursor::KeepAnchor);
4085 QString sf = cursor.selectedText().trimmed();
4086 if (sf.size()<77) sf.append(QString(" %1").arg(smbl));
4087 cursor.deleteChar();
4088 cursor.insertText(sf);
4089 }
4090 cursor.movePosition(QTextCursor::End);
4091 cursor = document->find("unit", cursor, QTextDocument::FindBackward);
4092 if (!cursor.isNull()){
4093 cursor.movePosition(QTextCursor::StartOfLine,QTextCursor::MoveAnchor);
4094 cursor.movePosition(QTextCursor::EndOfLine,QTextCursor::KeepAnchor);
4095 QString sf = cursor.selectedText().trimmed();
4096 if (sf.size()<77) sf.append(" 1");
4097 cursor.deleteChar();
4098 cursor.insertText(sf);
4099 }
4100 cursor.endEditBlock();
4101 }
4102
4103 void Window::setDefaultPath(){ //!<when the first recent file does not exists then open dialog starts here
4104 QString dfpa="";
4105 einstellung->beginGroup("Files");
4106 if (einstellung->contains("defaultPath"))
4107 dfpa= einstellung->value("defaultPath").toString();
4108 else
4109 dfpa= QDir::homePath();
4110 einstellung->endGroup();
4111 dfpa=QFileDialog::getOpenFileName(this,
4112 "set default file directory",
4113 dfpa,
4114 "SHELX-Files (*.res *.ins);;",
4115 nullptr);
4116 if (!dfpa.isEmpty()){
4117 einstellung->beginGroup("Files");
4118 einstellung->setValue("defaultPath",dfpa);
4119 einstellung->endGroup();
4120 }
4121 }
4122
4123 void Window::openFile(){
4124 QString location=dirName;
4125 if (!QFile::exists(dirName)) {
4126 einstellung->beginGroup("Files");
4127 if (einstellung->contains("defaultPath"))
4128 location = einstellung->value("defaultPath").toString();
4129 else
4130 location = QDir::homePath();
4131 einstellung->endGroup();
4132 }
4133
4134 QString fileName = QFileDialog::getOpenFileName(this, tr("Open shelX file "), location,
4135 "SHELX-Files (*.res *.ins);;",nullptr,(useNativeDlg->isChecked())?noneopt:QFileDialog::DontUseNativeDialog);
4136 if (!fileName.isEmpty()) {
4137
4138 loadFile(fileName);
4139 }
4140 update();
4141 }
4142
4143 void Window::setShelxlOptions(){
4144 QDialog *shxOptDLG = new QDialog(this);
4145 shxOptDLG->setWindowTitle("SHELXL runtime options");
4146 QGridLayout *lt = new QGridLayout(shxOptDLG);
4147 QLabel *PathL = new QLabel("Full path to executable",shxOptDLG);
4148 shxPath = new QLineEdit(shxOptDLG);
4149 QLabel *argumentsL = new QLabel("Commandline options",shxOptDLG);
4150 QCheckBox *barray = new QCheckBox(tr("I want to set the B-array size myself"));
4151 shxOptions = new QLineEdit(shxOptDLG);
4152 shxPath->setText(shelxlPath);
4153 shxOptions->setText(shelxlArgs);
4154 if (useMyBArray == true) {
4155 barray->setChecked(true);
4156 } else {
4157 barray->setChecked(false);
4158 }
4159 QPushButton *browsePath = new QPushButton("Browse",shxOptDLG);
4160 connect(browsePath,SIGNAL(pressed ()),this, SLOT(setShelxlPath()));
4161 QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel,Qt::Horizontal,shxOptDLG);
4162 connect(buttonBox, SIGNAL(accepted()), shxOptDLG, SLOT(accept()));
4163 connect(buttonBox, SIGNAL(rejected()), shxOptDLG, SLOT(reject()));
4164 lt->addWidget(PathL, 1, 0);
4165 lt->addWidget(shxPath, 1, 1);
4166 lt->addWidget(argumentsL, 2, 0);
4167 lt->addWidget(shxOptions, 2, 1);
4168 lt->addWidget(browsePath, 1, 2);
4169 lt->addWidget(barray, 3, 1, 1, 2);
4170 lt->addWidget(buttonBox, 8, 1, 1, 3);
4171 shxOptDLG->setLayout(lt);
4172 if (shxOptDLG->exec()==QDialog::Accepted) {
4173 shelxlArgs=shxOptions->text();
4174 shelxlPath=shxPath->text();
4175 einstellung->beginGroup("Window");
4176 einstellung->setValue("SHELXL-PATH", shelxlPath);
4177 einstellung->setValue("SHELXL-OPTION", shelxlArgs);
4178 einstellung->setValue("SHELXL-BARRAY", barray->isChecked());
4179 useMyBArray = barray->isChecked();
4180 einstellung->endGroup();
4181 }
4182 shxOptDLG->deleteLater ();
4183 delete shxPath;
4184 delete shxOptions;
4185 shxPath=shxOptions=NULL;
4186 }
4187
4188 void Window::extraSettings(){
4189 // printf("extraSettings()\n");
4190 QDialog *extDLG = new QDialog(this);
4191 extDLG->setWindowTitle("External programs");
4192 QGridLayout *lt = new QGridLayout(extDLG);
4193 pgms = new QComboBox(extDLG);
4194 pgms->addItems(extraProgramNames);
4195 connect(pgms,SIGNAL(currentIndexChanged(int)), this, SLOT(updateExtraSettings(int)));
4196 QLabel *extraNameL = new QLabel("Name of external program for menu entry:",extDLG);
4197 extraName = new QLineEdit(extDLG);
4198 extraName->setMinimumSize(150,15);
4199 QLabel *extraPathL = new QLabel("Full path to executable",extDLG);
4200 extraPath = new QLineEdit(extDLG);
4201 QLabel *argumentsL = new QLabel("Commandline options",extDLG);
4202 extraArgumentsEdit = new QLineEdit(extDLG);
4203 QLabel *altExtL = new QLabel("Alternative file Extension",extDLG);
4204 extraAltExtEdit = new QLineEdit(extDLG);
4205 QPushButton *browsePath = new QPushButton("Browse",extDLG);
4206 extraFakeButton = new QToolButton(extDLG);
4207 extraFakeButton->setIconSize(QSize(tbiconSize,tbiconSize));
4208 connect(browsePath,SIGNAL(pressed ()),this, SLOT(setExtraPath()));
4209 connect(extraFakeButton,SIGNAL(pressed()),this,SLOT(brwsIcon()));
4210 useArgument = new QCheckBox("Give file name as argument",extDLG);
4211 omitExtension = new QCheckBox("Omit '*.res' extension in argument",extDLG);
4212 absolutePath = new QCheckBox("Use absolute path in argument",extDLG);
4213 copyResIns = new QCheckBox("Copy .res file to ins file before execution",extDLG);
4214 openFileDialogBefore = new QCheckBox("Open file dialog before execution",extDLG);
4215 iconOverlay = new QCheckBox("Text overlay",extDLG);
4216 iovlPointSize = new QSpinBox(extDLG);
4217 iovlPointSize->setRange(4,96);
4218 iovlPointSize->setValue(36);
4219 iovlPointSize->setPrefix("PointSize ");
4220 connect(iconOverlay,SIGNAL(stateChanged(int)),this,SLOT(updateExtraIcon()));
4221 connect(iovlPointSize,SIGNAL(valueChanged(int)),this,SLOT(updateExtraIcon()));
4222 detach = new QCheckBox("start detached",extDLG);
4223 detach->setChecked(true);
4224 QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::No| QDialogButtonBox::Ok | QDialogButtonBox::Apply | QDialogButtonBox::Cancel,Qt::Horizontal,extDLG);
4225 QPushButton *ok = buttonBox->button(QDialogButtonBox::Ok);
4226 ok->setText("Add program");
4227 QPushButton *no =buttonBox->button(QDialogButtonBox::No);
4228 no->setText("Remove program");
4229 connect(buttonBox, SIGNAL(clicked(QAbstractButton*)),this,SLOT(removeExtra(QAbstractButton*)));
4230 connect(buttonBox, SIGNAL(accepted()), extDLG, SLOT(accept()));
4231 connect(buttonBox, SIGNAL(rejected()), extDLG, SLOT(reject()));
4232 lt->addWidget(pgms,0,0);
4233 lt->addWidget(extraNameL,1,0);
4234 lt->addWidget(extraName, 1,1);
4235 lt->addWidget(extraPathL,2,0);
4236 lt->addWidget(extraPath, 2,1);
4237 lt->addWidget(browsePath,2,2);
4238 lt->addWidget(extraFakeButton,0,1);
4239 lt->addWidget(iconOverlay,0,2);
4240 lt->addWidget(iovlPointSize,0,3);
4241 lt->addWidget(argumentsL,4,0);
4242 lt->addWidget(extraArgumentsEdit,4,1);
4243 lt->addWidget(altExtL,5,0);
4244 lt->addWidget(extraAltExtEdit,5,1);
4245 lt->addWidget(useArgument, 1, 9);
4246 lt->addWidget(absolutePath, 2, 9);
4247 lt->addWidget(omitExtension, 3, 9);
4248 lt->addWidget(detach, 4, 9);
4249 lt->addWidget(copyResIns, 5, 9);
4250 lt->addWidget(openFileDialogBefore, 6, 9);
4251 lt->addWidget(buttonBox,14,0,1,11);
4252 extDLG->setLayout(lt);
4253 altExtraIconPath="";
4254 //printf("extraSettings()\n");
4255 updateExtraSettings(0);
4256
4257 while (extraOptions.size()>extraProgramNames.size()){extraOptions.removeLast();}
4258 while (extraAbsolutePath.size()>extraProgramNames.size()){extraAbsolutePath.removeLast();}
4259 while (extraExt2.size()>extraProgramNames.size()){extraExt2.removeLast();}
4260
4261 if (extDLG->exec()==QDialog::Accepted) {
4262 int wegmuss=extraProgramNames.indexOf(extraName->text());
4263 if (wegmuss!=-1) {
4264 extraProgramNames.removeAt(wegmuss);
4265 extraProgramPaths.removeAt(wegmuss);
4266 extraArguments.removeAt(wegmuss);
4267 extraExtensions.removeAt(wegmuss);
4268 if (wegmuss<extraResIns.size()) extraResIns.removeAt(wegmuss);
4269 if (wegmuss<extraOpenFileDialogBefore.size()) extraOpenFileDialogBefore.removeAt(wegmuss);
4270 if (wegmuss<extraIconOverlay.size()) extraIconOverlay.removeAt(wegmuss);
4271 if (wegmuss<extraOverlayPointSize.size()) extraOverlayPointSize.removeAt(wegmuss);
4272 if (wegmuss<altExtraIconPaths.size()) altExtraIconPaths.removeAt(wegmuss);
4273 extraDetach.removeAt(wegmuss);
4274 extraOptions.removeAt(wegmuss);
4275 if (wegmuss<extraAbsolutePath.size())extraAbsolutePath.removeAt(wegmuss);
4276 extraExt2.removeAt(wegmuss);
4277 }
4278 altExtraIconPaths.append(altExtraIconPath);
4279 extraProgramNames.append(extraName->text().trimmed());
4280 extraProgramPaths.append(extraPath->text().trimmed());
4281 extraArguments.append(useArgument->checkState());
4282 extraOptions.append(extraArgumentsEdit->text().trimmed());
4283 extraExt2.append(extraAltExtEdit->text().trimmed());
4284 extraExtensions.append(omitExtension->checkState());
4285 extraAbsolutePath.append(absolutePath->checkState());
4286 extraResIns.append(copyResIns->checkState());
4287 extraOpenFileDialogBefore.append(openFileDialogBefore->checkState());
4288 extraIconOverlay.append(iconOverlay->checkState());
4289 extraOverlayPointSize.append(iovlPointSize->value());
4290 extraDetach.append(detach->checkState());
4291 einstellung->beginGroup("Extra");
4292 einstellung->beginWriteArray("ProgramNames",extraProgramNames.size());
4293 for (int i = 0; i < extraProgramNames.size(); i++) {
4294 einstellung->setArrayIndex(i);
4295 einstellung->setValue("Name", extraProgramNames.at(i));
4296 }
4297 einstellung->endArray();
4298 einstellung->endGroup();
4299
4300 einstellung->beginGroup("Extra");
4301 einstellung->beginWriteArray("ProgramPaths",extraProgramPaths.size());
4302 for (int i = 0; i < extraProgramPaths.size(); i++) {
4303 einstellung->setArrayIndex(i);
4304 einstellung->setValue("Path", extraProgramPaths.at(i));
4305 }
4306 einstellung->endArray();
4307 einstellung->endGroup();
4308
4309 einstellung->beginGroup("Extra");
4310 einstellung->beginWriteArray("AlternativeExtensions",extraExt2.size());
4311 for (int i = 0; i < extraExt2.size(); i++) {
4312 einstellung->setArrayIndex(i);
4313 einstellung->setValue("ext", extraExt2.at(i));
4314 }
4315 einstellung->endArray();
4316 einstellung->endGroup();
4317
4318 einstellung->beginGroup("Extra");
4319 einstellung->beginWriteArray("CommandLineOptions",extraOptions.size());
4320 for (int i = 0; i < extraOptions.size(); i++) {
4321 einstellung->setArrayIndex(i);
4322 einstellung->setValue("opt", extraOptions.at(i));
4323 }
4324 einstellung->endArray();
4325 einstellung->endGroup();
4326
4327 einstellung->beginGroup("Extra");
4328 einstellung->beginWriteArray("AbsolutePathRequired",extraAbsolutePath.size());
4329 for (int i = 0; i < extraAbsolutePath.size(); i++) {
4330 einstellung->setArrayIndex(i);
4331 einstellung->setValue("absolute", extraAbsolutePath.at(i));
4332 }
4333 einstellung->endArray();
4334 einstellung->endGroup();
4335
4336 einstellung->beginGroup("Extra");
4337 einstellung->beginWriteArray("ProgramArgs",extraArguments.size());
4338 for (int i = 0; i < extraArguments.size(); i++) {
4339 einstellung->setArrayIndex(i);
4340 einstellung->setValue("Arg", extraArguments.at(i));
4341 }
4342 einstellung->endArray();
4343 einstellung->endGroup();
4344
4345 einstellung->beginGroup("Extra");
4346 einstellung->beginWriteArray("ProgramExtensions",extraExtensions.size());
4347 for (int i = 0; i < extraExtensions.size(); i++) {
4348 einstellung->setArrayIndex(i);
4349 einstellung->setValue("Ext", extraExtensions.at(i));
4350 }
4351 einstellung->endArray();
4352 einstellung->endGroup();
4353
4354 einstellung->beginGroup("Extra");
4355 einstellung->beginWriteArray("ProgramResIns",extraResIns.size());
4356 for (int i = 0; i < extraResIns.size(); i++) {
4357 einstellung->setArrayIndex(i);
4358 einstellung->setValue("Res2Ins", extraResIns.at(i));
4359 }
4360 einstellung->endArray();
4361 einstellung->endGroup();
4362
4363 einstellung->beginGroup("Extra");
4364 einstellung->beginWriteArray("FileDialog",extraOpenFileDialogBefore.size());
4365 for (int i = 0; i < extraOpenFileDialogBefore.size(); i++) {
4366 einstellung->setArrayIndex(i);
4367 einstellung->setValue("fd", extraOpenFileDialogBefore.at(i));
4368 }
4369 einstellung->endArray();
4370 einstellung->endGroup();
4371
4372 einstellung->beginGroup("Extra");
4373 einstellung->beginWriteArray("IconOverlay",extraIconOverlay.size());
4374 for (int i = 0; i < extraIconOverlay.size(); i++) {
4375 einstellung->setArrayIndex(i);
4376 einstellung->setValue("icov", extraIconOverlay.at(i));
4377 }
4378 einstellung->endArray();
4379 einstellung->endGroup();
4380
4381 einstellung->beginGroup("Extra");
4382 einstellung->beginWriteArray("OverlayPointSize",extraOverlayPointSize.size());
4383 for (int i = 0; i < extraOverlayPointSize.size(); i++) {
4384 einstellung->setArrayIndex(i);
4385 einstellung->setValue("icov", extraOverlayPointSize.at(i));
4386 }
4387 einstellung->endArray();
4388 einstellung->endGroup();
4389
4390 einstellung->beginGroup("Extra");
4391 einstellung->beginWriteArray("AltExtraIconPaths",altExtraIconPaths.size());
4392 for (int i = 0; i < altExtraIconPaths.size(); i++) {
4393 einstellung->setArrayIndex(i);
4394 einstellung->setValue("altIcon", altExtraIconPaths.at(i));
4395 }
4396 einstellung->endArray();
4397 einstellung->endGroup();
4398
4399 einstellung->beginGroup("Extra");
4400 einstellung->beginWriteArray("ProgramDetached",extraDetach.size());
4401 for (int i = 0; i < extraDetach.size(); i++) {
4402 einstellung->setArrayIndex(i);
4403 einstellung->setValue("Detach", extraDetach.at(i));
4404 }
4405 einstellung->endArray();
4406 einstellung->endGroup();
4407 extraMenu->clear();
4408 extraTB->clear();
4409 extraMenu->addAction("add/remove external program",this,SLOT(extraSettings()));
4410 QFileIconProvider *p = new QFileIconProvider();
4411 if (extraProgramNames.size()) extraMenu->addSeparator();
4412 for (int i=0; i<extraProgramNames.size(); i++){
4413 QAction *a;
4414 QString icopa=extraProgramPaths.at(i);
4415 QFileIconProvider *epic = new QFileIconProvider();
4416 QIcon ico = epic->icon(QFileInfo(icopa));
4417 //qDebug()<<ico.availableSizes()<<ico.actualSize(QSize(32,32));
4418 QPixmap fmap = ico.pixmap(32,32);
4419 if (QFile::exists(altExtraIconPaths.at(i))) fmap=QIcon(altExtraIconPaths.at(i)).pixmap(64,64);
4420 delete epic;
4421
4422 if (extraIconOverlay.at(i)==Qt::Checked){
4423 QPainter *paint = new QPainter(&fmap);
4424 paint->setPen(QPen(QColor("#FFFFFF")));
4425 QFont ifont=chgl->myFont;
4426 ifont.setPixelSize(qMax(extraOverlayPointSize.at(i)*fmap.height()/64,2));
4427 paint->setFont(ifont);
4428 paint->drawText(1,fmap.height()-5,extraProgramNames.at(i));
4429 paint->setPen(QPen(QColor("#000000")));
4430 paint->drawText(0,fmap.height()-4,extraProgramNames.at(i));
4431 paint->end();
4432 }
4433 extraIcon=QIcon(fmap);
4434 a=extraMenu->addAction(extraIcon,QString("run %1 !").arg(extraProgramNames.at(i)),this,SLOT(runExtra()));
4435 a->setData(i);
4436 extraTB->addAction(a);
4437 }
4438 //printf("extraSettings()\n");
4439 delete p;
4440
4441 }
4442 extDLG->deleteLater ();
4443 if (strcmp(PROGRAM_NAME,"shelXle")){
4444 QMessageBox::information(0,"information","Restart of APEX is required to make your changes to external programs active. ",QMessageBox::Ok);
4445
4446 }
4447 // printf("extraSettings()\n");
4448 }
4449
4450 void Window::extraSettingsLast(){
4451 QDialog *extDLG = new QDialog(this);
4452 extDLG->setWindowTitle("External programs");
4453 QGridLayout *lt = new QGridLayout(extDLG);
4454 pgms = new QComboBox(extDLG);
4455 pgms->addItems(extraProgramNames);
4456 connect(pgms,SIGNAL(currentIndexChanged(int)), this, SLOT(updateExtraSettings(int)));
4457 QLabel *extraNameL = new QLabel("Name of external program for menu entry:",extDLG);
4458 extraName = new QLineEdit(extDLG);
4459 extraName->setMinimumSize(150,15);
4460 QLabel *extraPathL = new QLabel("Full path to executable",extDLG);
4461 extraPath = new QLineEdit(extDLG);
4462 QLabel *argumentsL = new QLabel("Commandline options",extDLG);
4463 extraArgumentsEdit = new QLineEdit(extDLG);
4464 QLabel *altExtL = new QLabel("Alternative file Extension",extDLG);
4465 extraAltExtEdit = new QLineEdit(extDLG);
4466 QPushButton *browsePath = new QPushButton("Browse",extDLG);
4467 extraFakeButton = new QToolButton(extDLG);
4468 extraFakeButton->setIconSize(QSize(tbiconSize,tbiconSize));
4469 connect(browsePath,SIGNAL(pressed ()),this, SLOT(setExtraPath()));
4470 connect(extraFakeButton,SIGNAL(pressed()),this,SLOT(brwsIcon()));
4471 useArgument = new QCheckBox("Give file name as argument",extDLG);
4472 omitExtension = new QCheckBox("Omit '*.res' extension in argument",extDLG);
4473 absolutePath = new QCheckBox("Use absolute path in argument",extDLG);
4474 copyResIns = new QCheckBox("Copy .res file to ins file before execution",extDLG);
4475 openFileDialogBefore = new QCheckBox("Open file dialog before execution",extDLG);
4476 iconOverlay = new QCheckBox("Text overlay",extDLG);
4477 iovlPointSize = new QSpinBox(extDLG);
4478 iovlPointSize->setRange(4,96);
4479 iovlPointSize->setValue(36);
4480 iovlPointSize->setPrefix("PointSize ");
4481 connect(iconOverlay,SIGNAL(stateChanged(int)),this,SLOT(updateExtraIcon()));
4482 connect(iovlPointSize,SIGNAL(valueChanged(int)),this,SLOT(updateExtraIcon()));
4483 detach = new QCheckBox("start detached",extDLG);
4484 detach->setChecked(true);
4485 QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::No| QDialogButtonBox::Ok | QDialogButtonBox::Cancel,Qt::Horizontal,extDLG);
4486 QPushButton *ok = buttonBox->button(QDialogButtonBox::Ok);
4487 ok->setText("Add program");
4488 QPushButton *no =buttonBox->button(QDialogButtonBox::No);
4489 no->setText("Remove program");
4490 connect(buttonBox, SIGNAL(clicked(QAbstractButton*)),this,SLOT(removeExtra(QAbstractButton*)));
4491 connect(buttonBox, SIGNAL(accepted()), extDLG, SLOT(accept()));
4492 connect(buttonBox, SIGNAL(rejected()), extDLG, SLOT(reject()));
4493 lt->addWidget(pgms,0,0);
4494 lt->addWidget(extraNameL,1,0);
4495 lt->addWidget(extraName, 1,1);
4496 lt->addWidget(extraPathL,2,0);
4497 lt->addWidget(extraPath, 2,1);
4498 lt->addWidget(browsePath,2,2);
4499 lt->addWidget(extraFakeButton,0,1);
4500 lt->addWidget(iconOverlay,0,2);
4501 lt->addWidget(iovlPointSize,0,3);
4502 lt->addWidget(argumentsL,4,0);
4503 lt->addWidget(extraArgumentsEdit,4,1);
4504 lt->addWidget(altExtL,5,0);
4505 lt->addWidget(extraAltExtEdit,5,1);
4506 lt->addWidget(useArgument, 1, 9);
4507 lt->addWidget(absolutePath, 2, 9);
4508 lt->addWidget(omitExtension, 3, 9);
4509 lt->addWidget(detach, 4, 9);
4510 lt->addWidget(copyResIns, 5, 9);
4511 lt->addWidget(openFileDialogBefore, 6, 9);
4512 lt->addWidget(buttonBox,14,0,1,11);
4513 extDLG->setLayout(lt);
4514 altExtraIconPath="";
4515 pgms->setCurrentIndex(extraProgramNames.size()-1);
4516 updateExtraSettings(extraProgramNames.size()-1);
4517
4518 while (extraOptions.size()>extraProgramNames.size()){extraOptions.removeLast();}
4519 while (extraExt2.size()>extraProgramNames.size()){extraExt2.removeLast();}
4520
4521 if (extDLG->exec()==QDialog::Accepted) {
4522 int wegmuss=extraProgramNames.indexOf(extraName->text());
4523 if (wegmuss!=-1) {
4524 extraProgramNames.removeAt(wegmuss);
4525 extraProgramPaths.removeAt(wegmuss);
4526 extraArguments.removeAt(wegmuss);
4527 extraExtensions.removeAt(wegmuss);
4528 if (wegmuss<extraAbsolutePath.size())extraAbsolutePath.removeAt(wegmuss);
4529 if (wegmuss<extraResIns.size()) extraResIns.removeAt(wegmuss);
4530 if (wegmuss<extraOpenFileDialogBefore.size()) extraOpenFileDialogBefore.removeAt(wegmuss);
4531 if (wegmuss<extraIconOverlay.size()) extraIconOverlay.removeAt(wegmuss);
4532 if (wegmuss<extraOverlayPointSize.size()) extraOverlayPointSize.removeAt(wegmuss);
4533 if (wegmuss<altExtraIconPaths.size()) altExtraIconPaths.removeAt(wegmuss);
4534 extraDetach.removeAt(wegmuss);
4535 extraOptions.removeAt(wegmuss);
4536 extraExt2.removeAt(wegmuss);
4537 }
4538 altExtraIconPaths.append(altExtraIconPath);
4539 extraProgramNames.append(extraName->text().trimmed());
4540 extraProgramPaths.append(extraPath->text().trimmed());
4541 extraArguments.append(useArgument->checkState());
4542 extraOptions.append(extraArgumentsEdit->text().trimmed());
4543 extraExt2.append(extraAltExtEdit->text().trimmed());
4544 extraExtensions.append(omitExtension->checkState());
4545 extraAbsolutePath.append(absolutePath->checkState());
4546 extraResIns.append(copyResIns->checkState());
4547 extraOpenFileDialogBefore.append(openFileDialogBefore->checkState());
4548 extraIconOverlay.append(iconOverlay->checkState());
4549 extraOverlayPointSize.append(iovlPointSize->value());
4550 extraDetach.append(detach->checkState());
4551 einstellung->beginGroup("Extra");
4552 einstellung->beginWriteArray("ProgramNames",extraProgramNames.size());
4553 for (int i = 0; i < extraProgramNames.size(); i++) {
4554 einstellung->setArrayIndex(i);
4555 einstellung->setValue("Name", extraProgramNames.at(i));
4556 }
4557 einstellung->endArray();
4558 einstellung->endGroup();
4559
4560 einstellung->beginGroup("Extra");
4561 einstellung->beginWriteArray("ProgramPaths",extraProgramPaths.size());
4562 for (int i = 0; i < extraProgramPaths.size(); i++) {
4563 einstellung->setArrayIndex(i);
4564 einstellung->setValue("Path", extraProgramPaths.at(i));
4565 }
4566 einstellung->endArray();
4567 einstellung->endGroup();
4568
4569 einstellung->beginGroup("Extra");
4570 einstellung->beginWriteArray("AlternativeExtensions",extraExt2.size());
4571 for (int i = 0; i < extraExt2.size(); i++) {
4572 einstellung->setArrayIndex(i);
4573 einstellung->setValue("ext", extraExt2.at(i));
4574 }
4575 einstellung->endArray();
4576 einstellung->endGroup();
4577
4578 einstellung->beginGroup("Extra");
4579 einstellung->beginWriteArray("CommandLineOptions",extraOptions.size());
4580 for (int i = 0; i < extraOptions.size(); i++) {
4581 einstellung->setArrayIndex(i);
4582 einstellung->setValue("opt", extraOptions.at(i));
4583 }
4584 einstellung->endArray();
4585 einstellung->endGroup();
4586
4587 einstellung->beginGroup("Extra");
4588 einstellung->beginWriteArray("AbsolutePathRequired",extraAbsolutePath.size());
4589 for (int i = 0; i < extraAbsolutePath.size(); i++) {
4590 einstellung->setArrayIndex(i);
4591 einstellung->setValue("absolute", extraAbsolutePath.at(i));
4592 }
4593 einstellung->endArray();
4594 einstellung->endGroup();
4595
4596 einstellung->beginGroup("Extra");
4597 einstellung->beginWriteArray("ProgramArgs",extraArguments.size());
4598 for (int i = 0; i < extraArguments.size(); i++) {
4599 einstellung->setArrayIndex(i);
4600 einstellung->setValue("Arg", extraArguments.at(i));
4601 }
4602 einstellung->endArray();
4603 einstellung->endGroup();
4604
4605 einstellung->beginGroup("Extra");
4606 einstellung->beginWriteArray("ProgramExtensions",extraExtensions.size());
4607 for (int i = 0; i < extraExtensions.size(); i++) {
4608 einstellung->setArrayIndex(i);
4609 einstellung->setValue("Ext", extraExtensions.at(i));
4610 }
4611 einstellung->endArray();
4612 einstellung->endGroup();
4613
4614 einstellung->beginGroup("Extra");
4615 einstellung->beginWriteArray("ProgramResIns",extraResIns.size());
4616 for (int i = 0; i < extraResIns.size(); i++) {
4617 einstellung->setArrayIndex(i);
4618 einstellung->setValue("Res2Ins", extraResIns.at(i));
4619 }
4620 einstellung->endArray();
4621 einstellung->endGroup();
4622
4623 einstellung->beginGroup("Extra");
4624 einstellung->beginWriteArray("FileDialog",extraOpenFileDialogBefore.size());
4625 for (int i = 0; i < extraOpenFileDialogBefore.size(); i++) {
4626 einstellung->setArrayIndex(i);
4627 einstellung->setValue("fd", extraOpenFileDialogBefore.at(i));
4628 }
4629 einstellung->endArray();
4630 einstellung->endGroup();
4631
4632 einstellung->beginGroup("Extra");
4633 einstellung->beginWriteArray("IconOverlay",extraIconOverlay.size());
4634 for (int i = 0; i < extraIconOverlay.size(); i++) {
4635 einstellung->setArrayIndex(i);
4636 einstellung->setValue("icov", extraIconOverlay.at(i));
4637 }
4638 einstellung->endArray();
4639 einstellung->endGroup();
4640
4641 einstellung->beginGroup("Extra");
4642 einstellung->beginWriteArray("OverlayPointSize",extraOverlayPointSize.size());
4643 for (int i = 0; i < extraOverlayPointSize.size(); i++) {
4644 einstellung->setArrayIndex(i);
4645 einstellung->setValue("icov", extraOverlayPointSize.at(i));
4646 }
4647 einstellung->endArray();
4648 einstellung->endGroup();
4649
4650 einstellung->beginGroup("Extra");
4651 einstellung->beginWriteArray("AltExtraIconPaths",altExtraIconPaths.size());
4652 for (int i = 0; i < altExtraIconPaths.size(); i++) {
4653 einstellung->setArrayIndex(i);
4654 einstellung->setValue("altIcon", altExtraIconPaths.at(i));
4655 }
4656 einstellung->endArray();
4657 einstellung->endGroup();
4658
4659 einstellung->beginGroup("Extra");
4660 einstellung->beginWriteArray("ProgramDetached",extraDetach.size());
4661 for (int i = 0; i < extraDetach.size(); i++) {
4662 einstellung->setArrayIndex(i);
4663 einstellung->setValue("Detach", extraDetach.at(i));
4664 }
4665 einstellung->endArray();
4666 einstellung->endGroup();
4667 extraMenu->clear();
4668 extraTB->clear();
4669 extraMenu->addAction("add/remove external program",this,SLOT(extraSettings()));
4670 QFileIconProvider *p = new QFileIconProvider();
4671 if (extraProgramNames.size()) extraMenu->addSeparator();
4672 for (int i=0; i<extraProgramNames.size(); i++){
4673 QAction *a;
4674 QString icopa=extraProgramPaths.at(i);
4675 QFileIconProvider *epic = new QFileIconProvider();
4676 QIcon ico = epic->icon(QFileInfo(icopa));
4677 //qDebug()<<ico.availableSizes()<<ico.actualSize(QSize(32,32));
4678 QPixmap fmap = ico.pixmap(32,32);
4679 if (QFile::exists(altExtraIconPaths.at(i))) fmap=QIcon(altExtraIconPaths.at(i)).pixmap(64,64);
4680 delete epic;
4681
4682 if (extraIconOverlay.at(i)==Qt::Checked){
4683 QPainter *paint = new QPainter(&fmap);
4684 paint->setPen(QPen(QColor("#FFFFFF")));
4685 QFont ifont=chgl->myFont;
4686 ifont.setPixelSize(qMax(extraOverlayPointSize.at(i)*fmap.height()/64,2));
4687 paint->setFont(ifont);
4688 paint->drawText(1,fmap.height()-5,extraProgramNames.at(i));
4689 paint->setPen(QPen(QColor("#000000")));
4690 paint->drawText(0,fmap.height()-4,extraProgramNames.at(i));
4691 paint->end();
4692 }
4693 extraIcon=QIcon(fmap);
4694 a=extraMenu->addAction(extraIcon,QString("run %1 !").arg(extraProgramNames.at(i)),this,SLOT(runExtra()));
4695 a->setData(i);
4696 extraTB->addAction(a);
4697 }
4698 delete p;
4699
4700 }
4701 // printf("extraSettingsLast()\n");
4702 extDLG->deleteLater ();
4703 if (strcmp(PROGRAM_NAME,"shelXle")){
4704 QMessageBox::information(0,"information","Restart of APEX is required to make your changes to external programs active. ",QMessageBox::Ok);
4705
4706 }
4707 // printf("extraSettingsLast()\n");
4708 }
4709 void Window::removeExtra(QAbstractButton *button){
4710 if (button->text()=="Remove program") {
4711 int wegmuss=extraProgramNames.indexOf(extraName->text());
4712 if (wegmuss!=-1) {
4713 extraProgramNames.removeAt(wegmuss);
4714 extraProgramPaths.removeAt(wegmuss);
4715 extraArguments.removeAt(wegmuss);
4716 extraExtensions.removeAt(wegmuss);
4717 if (wegmuss<extraAbsolutePath.size())extraAbsolutePath.removeAt(wegmuss);
4718 if (wegmuss<extraResIns.size()) extraResIns.removeAt(wegmuss);
4719 if (wegmuss<extraOpenFileDialogBefore.size()) extraOpenFileDialogBefore.removeAt(wegmuss);
4720 if (wegmuss<extraIconOverlay.size()) extraIconOverlay.removeAt(wegmuss);
4721 if (wegmuss<extraOverlayPointSize.size()) extraOverlayPointSize.removeAt(wegmuss);
4722 if (wegmuss<altExtraIconPaths.size()) altExtraIconPaths.removeAt(wegmuss);
4723 extraOptions.removeAt(wegmuss);
4724 extraExt2.removeAt(wegmuss);
4725 extraDetach.removeAt(wegmuss);
4726 }
4727 while (extraOptions.size()>extraProgramNames.size()){extraOptions.removeLast();}
4728 while (extraExt2.size()>extraProgramNames.size()){extraExt2.removeLast();}
4729 einstellung->beginGroup("Extra");
4730 einstellung->beginWriteArray("ProgramNames",extraProgramNames.size());
4731 for (int i = 0; i < extraProgramNames.size(); i++) {
4732 einstellung->setArrayIndex(i);
4733 einstellung->setValue("Name", extraProgramNames.at(i));
4734 }
4735 einstellung->endArray();
4736 einstellung->endGroup();
4737
4738 einstellung->beginGroup("Extra");
4739 einstellung->beginWriteArray("ProgramPaths",extraProgramPaths.size());
4740 for (int i = 0; i < extraProgramPaths.size(); i++) {
4741 einstellung->setArrayIndex(i);
4742 einstellung->setValue("Path", extraProgramPaths.at(i));
4743 }
4744 einstellung->endArray();
4745 einstellung->endGroup();
4746
4747
4748 einstellung->beginGroup("Extra");
4749 einstellung->beginWriteArray("ProgramArgs",extraArguments.size());
4750 for (int i = 0; i < extraArguments.size(); i++) {
4751 einstellung->setArrayIndex(i);
4752 einstellung->setValue("Arg", extraArguments.at(i));
4753 }
4754 einstellung->endArray();
4755 einstellung->endGroup();
4756
4757 einstellung->beginGroup("Extra");
4758 einstellung->beginWriteArray("ProgramExtensions",extraExtensions.size());
4759 for (int i = 0; i < extraExtensions.size(); i++) {
4760 einstellung->setArrayIndex(i);
4761 einstellung->setValue("Ext", extraExtensions.at(i));
4762 }
4763 einstellung->endArray();
4764 einstellung->endGroup();
4765
4766 einstellung->beginGroup("Extra");
4767 einstellung->beginWriteArray("ProgramResIns",extraResIns.size());
4768 for (int i = 0; i < extraResIns.size(); i++) {
4769 einstellung->setArrayIndex(i);
4770 einstellung->setValue("Res2Ins", extraResIns.at(i));
4771 }
4772 einstellung->endArray();
4773 einstellung->endGroup();
4774
4775 einstellung->beginGroup("Extra");
4776 einstellung->beginWriteArray("FileDialog",extraOpenFileDialogBefore.size());
4777 for (int i = 0; i < extraOpenFileDialogBefore.size(); i++) {
4778 einstellung->setArrayIndex(i);
4779 einstellung->setValue("fd", extraOpenFileDialogBefore.at(i));
4780 }
4781 einstellung->endArray();
4782 einstellung->endGroup();
4783
4784
4785 einstellung->beginGroup("Extra");
4786 einstellung->beginWriteArray("IconOverlay",extraIconOverlay.size());
4787 for (int i = 0; i < extraIconOverlay.size(); i++) {
4788 einstellung->setArrayIndex(i);
4789 einstellung->setValue("icov", extraIconOverlay.at(i));
4790 }
4791 einstellung->endArray();
4792 einstellung->endGroup();
4793
4794 einstellung->beginGroup("Extra");
4795 einstellung->beginWriteArray("OverlayPointSize",extraOverlayPointSize.size());
4796 for (int i = 0; i < extraOverlayPointSize.size(); i++) {
4797 einstellung->setArrayIndex(i);
4798 einstellung->setValue("icov", extraOverlayPointSize.at(i));
4799 }
4800 einstellung->endArray();
4801 einstellung->endGroup();
4802
4803 einstellung->beginGroup("Extra");
4804 einstellung->beginWriteArray("AltExtraIconPaths",altExtraIconPaths.size());
4805 for (int i = 0; i < altExtraIconPaths.size(); i++) {
4806 einstellung->setArrayIndex(i);
4807 einstellung->setValue("altIcon", altExtraIconPaths.at(i));
4808 }
4809 einstellung->endArray();
4810 einstellung->endGroup();
4811
4812 einstellung->beginGroup("Extra");
4813 einstellung->beginWriteArray("ProgramDetached",extraDetach.size());
4814 for (int i = 0; i < extraDetach.size(); i++) {
4815 einstellung->setArrayIndex(i);
4816 einstellung->setValue("Detach", extraDetach.at(i));
4817 }
4818 einstellung->endArray();
4819 einstellung->endGroup();
4820 extraMenu->clear();
4821
4822 extraMenu->addAction("add external program",this,SLOT(extraSettings()));
4823 extraTB->clear();
4824 QFileIconProvider *epic = new QFileIconProvider();
4825 if (extraProgramNames.size()) extraMenu->addSeparator();
4826 for (int i=0; i<extraProgramNames.size(); i++){
4827 QAction *a;
4828 QString icopa=extraProgramPaths.at(i);
4829 QIcon ico = epic->icon(QFileInfo(icopa));
4830 //qDebug()<<ico.availableSizes()<<ico.actualSize(QSize(32,32));
4831 QPixmap fmap = ico.pixmap(32,32);
4832 if (QFile::exists(altExtraIconPaths.at(i))) fmap=QIcon(altExtraIconPaths.at(i)).pixmap(64,64);
4833 if (extraIconOverlay.at(i)==Qt::Checked){
4834 QPainter *paint = new QPainter(&fmap);
4835 paint->setPen(QPen(QColor("#FFFFFF")));
4836 QFont ifont=chgl->myFont;
4837 ifont.setPixelSize(qMax(extraOverlayPointSize.at(i)*fmap.height()/64,2));
4838 paint->setFont(ifont);
4839 paint->drawText(1,fmap.height()-5,extraProgramNames.at(i));
4840 paint->setPen(QPen(QColor("#000000")));
4841 paint->drawText(0,fmap.height()-4,extraProgramNames.at(i));
4842 paint->end();
4843 }
4844 extraIcon=QIcon(fmap);
4845 a=extraMenu->addAction(extraIcon,QString("run %1 !").arg(extraProgramNames.at(i)),this,SLOT(runExtra()));
4846 a->setData(i);
4847 extraTB->addAction(a);
4848 }
4849 delete epic;
4850
4851 }
4852 else if (button->text()=="Apply"){
4853
4854 int wegmuss = pgms->currentIndex();
4855 if ((wegmuss < 0)||(wegmuss >= extraProgramNames.size())) return;
4856 printf("changing extra programm %d\n", wegmuss);
4857 altExtraIconPaths[wegmuss] = altExtraIconPath;
4858 extraProgramNames[wegmuss] = extraName->text().trimmed();
4859 extraProgramPaths[wegmuss] = extraPath->text().trimmed();
4860 extraArguments[wegmuss] = useArgument->checkState();
4861 extraOptions[wegmuss] = extraArgumentsEdit->text().trimmed();
4862 extraExt2[wegmuss] = extraAltExtEdit->text().trimmed();
4863 extraExtensions[wegmuss] = omitExtension->checkState();
4864 extraAbsolutePath[wegmuss] = absolutePath->checkState();
4865 extraResIns[wegmuss] = copyResIns->checkState();
4866 extraOpenFileDialogBefore[wegmuss] = openFileDialogBefore->checkState();
4867 extraIconOverlay[wegmuss] = iconOverlay->checkState();
4868 extraOverlayPointSize[wegmuss] = iovlPointSize->value();
4869 extraDetach[wegmuss] = detach->checkState();
4870
4871 einstellung->beginGroup("Extra");
4872 einstellung->beginWriteArray("ProgramNames",extraProgramNames.size());
4873 for (int i = 0; i < extraProgramNames.size(); i++) {
4874 einstellung->setArrayIndex(i);
4875 einstellung->setValue("Name", extraProgramNames.at(i));
4876 }
4877 einstellung->endArray();
4878 einstellung->endGroup();
4879
4880 einstellung->beginGroup("Extra");
4881 einstellung->beginWriteArray("ProgramPaths",extraProgramPaths.size());
4882 for (int i = 0; i < extraProgramPaths.size(); i++) {
4883 einstellung->setArrayIndex(i);
4884 einstellung->setValue("Path", extraProgramPaths.at(i));
4885 }
4886 einstellung->endArray();
4887 einstellung->endGroup();
4888
4889 einstellung->beginGroup("Extra");
4890 einstellung->beginWriteArray("AlternativeExtensions",extraExt2.size());
4891 for (int i = 0; i < extraExt2.size(); i++) {
4892 einstellung->setArrayIndex(i);
4893 einstellung->setValue("ext", extraExt2.at(i));
4894 }
4895 einstellung->endArray();
4896 einstellung->endGroup();
4897
4898 einstellung->beginGroup("Extra");
4899 einstellung->beginWriteArray("CommandLineOptions",extraOptions.size());
4900 for (int i = 0; i < extraOptions.size(); i++) {
4901 einstellung->setArrayIndex(i);
4902 einstellung->setValue("opt", extraOptions.at(i));
4903 }
4904 einstellung->endArray();
4905 einstellung->endGroup();
4906
4907 einstellung->beginGroup("Extra");
4908 einstellung->beginWriteArray("AbsolutePathRequired",extraAbsolutePath.size());
4909 for (int i = 0; i < extraAbsolutePath.size(); i++) {
4910 einstellung->setArrayIndex(i);
4911 einstellung->setValue("absolute", extraAbsolutePath.at(i));
4912 }
4913 einstellung->endArray();
4914 einstellung->endGroup();
4915
4916 einstellung->beginGroup("Extra");
4917 einstellung->beginWriteArray("ProgramArgs",extraArguments.size());
4918 for (int i = 0; i < extraArguments.size(); i++) {
4919 einstellung->setArrayIndex(i);
4920 einstellung->setValue("Arg", extraArguments.at(i));
4921 }
4922 einstellung->endArray();
4923 einstellung->endGroup();
4924
4925 einstellung->beginGroup("Extra");
4926 einstellung->beginWriteArray("ProgramExtensions",extraExtensions.size());
4927 for (int i = 0; i < extraExtensions.size(); i++) {
4928 einstellung->setArrayIndex(i);
4929 einstellung->setValue("Ext", extraExtensions.at(i));
4930 }
4931 einstellung->endArray();
4932 einstellung->endGroup();
4933
4934 einstellung->beginGroup("Extra");
4935 einstellung->beginWriteArray("ProgramResIns",extraResIns.size());
4936 for (int i = 0; i < extraResIns.size(); i++) {
4937 einstellung->setArrayIndex(i);
4938 einstellung->setValue("Res2Ins", extraResIns.at(i));
4939 }
4940 einstellung->endArray();
4941 einstellung->endGroup();
4942
4943 einstellung->beginGroup("Extra");
4944 einstellung->beginWriteArray("FileDialog",extraOpenFileDialogBefore.size());
4945 for (int i = 0; i < extraOpenFileDialogBefore.size(); i++) {
4946 einstellung->setArrayIndex(i);
4947 einstellung->setValue("fd", extraOpenFileDialogBefore.at(i));
4948 }
4949 einstellung->endArray();
4950 einstellung->endGroup();
4951
4952 einstellung->beginGroup("Extra");
4953 einstellung->beginWriteArray("IconOverlay",extraIconOverlay.size());
4954 for (int i = 0; i < extraIconOverlay.size(); i++) {
4955 einstellung->setArrayIndex(i);
4956 einstellung->setValue("icov", extraIconOverlay.at(i));
4957 }
4958 einstellung->endArray();
4959 einstellung->endGroup();
4960
4961 einstellung->beginGroup("Extra");
4962 einstellung->beginWriteArray("OverlayPointSize",extraOverlayPointSize.size());
4963 for (int i = 0; i < extraOverlayPointSize.size(); i++) {
4964 einstellung->setArrayIndex(i);
4965 einstellung->setValue("icov", extraOverlayPointSize.at(i));
4966 }
4967 einstellung->endArray();
4968 einstellung->endGroup();
4969
4970 einstellung->beginGroup("Extra");
4971 einstellung->beginWriteArray("AltExtraIconPaths",altExtraIconPaths.size());
4972 for (int i = 0; i < altExtraIconPaths.size(); i++) {
4973 einstellung->setArrayIndex(i);
4974 einstellung->setValue("altIcon", altExtraIconPaths.at(i));
4975 }
4976 einstellung->endArray();
4977 einstellung->endGroup();
4978
4979 einstellung->beginGroup("Extra");
4980 einstellung->beginWriteArray("ProgramDetached",extraDetach.size());
4981 for (int i = 0; i < extraDetach.size(); i++) {
4982 einstellung->setArrayIndex(i);
4983 einstellung->setValue("Detach", extraDetach.at(i));
4984 }
4985 einstellung->endArray();
4986 einstellung->endGroup();
4987 extraMenu->clear();
4988 extraTB->clear();
4989 extraMenu->addAction("add/remove external program",this,SLOT(extraSettings()));
4990 //QFileIconProvider *p = new QFileIconProvider();
4991 if (extraProgramNames.size()) extraMenu->addSeparator();
4992 for (int i=0; i<extraProgramNames.size(); i++){
4993 QAction *a;
4994 QString icopa=extraProgramPaths.at(i);
4995 QFileIconProvider *epic = new QFileIconProvider();
4996 QIcon ico = epic->icon(QFileInfo(icopa));
4997 //qDebug()<<ico.availableSizes()<<ico.actualSize(QSize(32,32));
4998 QPixmap fmap = ico.pixmap(32,32);
4999 if (QFile::exists(altExtraIconPaths.at(i))) fmap=QIcon(altExtraIconPaths.at(i)).pixmap(64,64);
5000 delete epic;
5001
5002 if (extraIconOverlay.at(i)==Qt::Checked){
5003 QPainter *paint = new QPainter(&fmap);
5004 paint->setPen(QPen(QColor("#FFFFFF")));
5005 QFont ifont=chgl->myFont;
5006 ifont.setPixelSize(qMax(extraOverlayPointSize.at(i)*fmap.height()/64,2));
5007 paint->setFont(ifont);
5008 paint->drawText(1,fmap.height()-5,extraProgramNames.at(i));
5009 paint->setPen(QPen(QColor("#000000")));
5010 paint->drawText(0,fmap.height()-4,extraProgramNames.at(i));
5011 paint->end();
5012 }
5013 extraIcon=QIcon(fmap);
5014 a=extraMenu->addAction(extraIcon,QString("run %1 !").arg(extraProgramNames.at(i)),this,SLOT(runExtra()));
5015 a->setData(i);
5016 extraTB->addAction(a);
5017 }
5018 pgms->removeItem(wegmuss);
5019 pgms->insertItem(wegmuss,extraName->text().trimmed());
5020 pgms->setCurrentIndex(wegmuss);
5021 }
5022 }
5023
5024 void Window::updateExtraSettings(){
5025 updateExtraSettings(0);
5026 }
5027
5028 void Window::updateExtraSettings(int index){
5029 if ((index<0)||(index>=extraProgramNames.size())) return;
5030 extraName->setText(extraProgramNames.at(index));
5031 extraPath->setText(extraProgramPaths.at(index));
5032 altExtraIconPath=(index<altExtraIconPaths.size())?altExtraIconPaths.at(index):"";
5033 extraArgumentsEdit->setText(extraOptions.at(index));
5034 extraAltExtEdit->setText(extraExt2.at(index));
5035 QFileIconProvider *epic = new QFileIconProvider();
5036 QString icopa=extraProgramPaths.at(index);
5037 QIcon ico = epic->icon(QFileInfo(icopa));
5038 //qDebug()<<index<<ico.availableSizes()<<ico.actualSize(QSize(32,32));
5039 QPixmap fmap = ico.pixmap(32,32);
5040 if (QFile::exists(altExtraIconPaths.at(index))) fmap=QIcon(altExtraIconPaths.at(index)).pixmap(64,64);
5041 if (extraIconOverlay.at(index)==Qt::Checked){
5042 QPainter *paint = new QPainter(&fmap);
5043 paint->setPen(QPen(QColor("#FFFFFF")));
5044 QFont ifont=chgl->myFont;
5045 ifont.setPixelSize(qMax(iovlPointSize->value()*fmap.height()/64,2));
5046 paint->setFont(ifont);
5047 paint->drawText(1,fmap.height()-5,extraProgramNames.at(index));
5048 paint->setPen(QPen(QColor("#000000")));
5049 paint->drawText(0,fmap.height()-4,extraProgramNames.at(index));
5050 paint->end();
5051 }
5052 extraIcon=QIcon(fmap);
5053 extraFakeButton->setIcon(extraIcon);
5054 delete epic;
5055 useArgument->setCheckState(extraArguments.at(index));
5056 absolutePath->setCheckState(extraAbsolutePath.at(index));
5057 omitExtension->setCheckState(extraExtensions.at(index));
5058 if (index<extraResIns.size()) copyResIns->setCheckState(extraResIns.at(index));
5059 if (index<extraOpenFileDialogBefore.size()) openFileDialogBefore->setCheckState(extraOpenFileDialogBefore.at(index));
5060 if (index<extraIconOverlay.size()) iconOverlay->setCheckState(extraIconOverlay.at(index));
5061 if (index<extraOverlayPointSize.size()) iovlPointSize->setValue(extraOverlayPointSize.at(index));
5062 detach->setCheckState(extraDetach.at(index));
5063 update();
5064 }
5065
5066 void Window::updateExtraIcon(){
5067 QPixmap fmap;
5068 if (altExtraIconPath.isEmpty()){
5069 QFileIconProvider *epic = new QFileIconProvider();
5070 QIcon ico = epic->icon(QFileInfo(extraPath->text()));
5071 //qDebug()<<ico.availableSizes()<<ico.actualSize(QSize(32,32));
5072 fmap = ico.pixmap(32,32);
5073 delete epic;
5074 }
5075 else{
5076 fmap = QIcon(altExtraIconPath).pixmap(64,64);
5077
5078 }
5079 if (iconOverlay->isChecked()){
5080 QPainter *paint = new QPainter(&fmap);
5081 paint->setPen(QPen(QColor("#FFFFFF")));
5082 QFont ifont=chgl->myFont;
5083 ifont.setPixelSize(qMax(iovlPointSize->value()*fmap.height()/64,2));
5084 paint->setFont(ifont);
5085 paint->drawText(1, fmap.height()-5,extraName->text());
5086 paint->setPen(QPen(QColor("#000000")));
5087 paint->drawText(0, fmap.height()-4,extraName->text());
5088 paint->end();
5089 }
5090 extraIcon=QIcon(fmap);
5091 extraFakeButton->setIcon(extraIcon);
5092
5093 }
5094
5095 void Window::setExtraPath(){
5096 QString s =
5097 QFileDialog::getOpenFileName(this, "Path to external program executable", extraPath->text(), QString(),nullptr,(useNativeDlg->isChecked())?noneopt:QFileDialog::DontUseNativeDialog);
5098 if (!s.isEmpty()){
5099 extraPath->setText(s);
5100 updateExtraIcon();;
5101 }
5102 }
5103
5104 void Window::brwsIcon(){
5105 QString path="";
5106 #if defined (Q_WS_X11)
5107 path="/usr/share/pixmaps/";
5108 #endif
5109 QString *filter=NULL,s=
5110 QFileDialog::getOpenFileName(this,QString("Select icon source"),//caption
5111 path, "Icon files (*.xpm *.png *.ico *.svg);;",filter, (useNativeDlg->isChecked())?noneopt:QFileDialog::DontUseNativeDialog);
5112 if (QFile::exists(s)) altExtraIconPath=s;
5113 updateExtraIcon();
5114 }
5115
5116 void Window::runExtra(){
5117 QAction *action = qobject_cast<QAction *>(sender());
5118 int index=0;
5119 if (action){
5120 index=action->data().toInt();
5121 } else {
5122 return;
5123 }
5124 if ((index<0)||(index>=extraProgramNames.size())) return;
5125 extraOutput->hide();
5126 delete extraOutput;
5127 extraIndex = index;
5128 extraOutput = new QDialog(this);
5129 lt = new QVBoxLayout();
5130 extraOutPut = new QTextEdit();
5131 QFont mospfo(FONTFAM);
5132 extraOutPut->setFont(mospfo);
5133 #if (QT_VERSION >=0x050000)
5134 extraOutput->setMinimumWidth(
5135 QFontMetrics(extraOutPut->font())
5136 .horizontalAdvance("#########################################################################################################################################"));
5137 #else
5138 extraOutput->setMinimumWidth(
5139 QFontMetrics(extraOutPut->font())
5140 .width("###########################################################################################"));
5141 #endif
5142 extraOutPut->setLineWrapMode(QTextEdit::NoWrap);
5143 lt->addWidget(extraOutPut);
5144 extraOutput->setLayout(lt);
5145 extraOutput->setWindowTitle(QString("Running %1 ...").arg(extraProgramNames.at(index)));
5146 extraOutPut->clear();
5147 QString path,name;
5148 path=extraProgramPaths.at(index);
5149 #if defined (Q_WS_MAC)
5150 if ((QFileInfo(path).isDir())&&(path.endsWith(".app",Qt::CaseInsensitive))){
5151 path.append("/Contents/MacOS/");
5152 path.append(QDir(path).entryList(QDir::Executable|QDir::Files).first());
5153 }
5154 #endif
5155 QString dn=dirName.section('/',0,-2),
5156 argument=dirName.section('/',-1);
5157 if (extraOpenFileDialogBefore.at(index)==Qt::Checked){
5158 QString oMyDir=
5159 QFileDialog::getOpenFileName(this,QString("Open a file for %1").arg(extraProgramNames.at(index)),//caption
5160 dn,QString(),nullptr,(useNativeDlg->isChecked())?noneopt:QFileDialog::DontUseNativeDialog);
5161 dn=oMyDir.section('/',0,-2);
5162 argument=oMyDir.section('/',-1);
5163 }
5164 if (extraExtensions.at(index)==Qt::Checked) argument.remove(QRegularExpression(".res$|.ins$|.p4p$|.cif$",QRegularExpression::CaseInsensitiveOption));
5165 if (extraResIns.at(index)==Qt::Checked) {
5166 //##@##bruce will es
5167 //
5168 //printf("bruce will es\n");
5169 if (maybeSave2()){
5170 QString dn=dirName.section('/',0,-2),
5171 argument=dirName.section('/',-1);
5172 argument.remove(resorins);
5173 if (dirName.contains(punktres)){
5174 QString insname =dirName;
5175 insname.replace(punktres,".ins");
5176
5177 QString fcfname = dirName;
5178 fcfname.replace(punktres,".fcf");
5179 QString fcfname2 = dirName;
5180 fcfname2.replace(punktres,".2fcf");
5181 if ((QFileInfo(dirName).lastModified()>=QFileInfo(insname).lastModified())){
5182 QDir work=QDir(QString("%1/%2saves/").arg(dn).arg(PROGRAM_NAME));
5183 QStringList filter;
5184 filter << QString("%1_*_.ins").arg(argument);
5185 QStringList resfs;
5186 resfs=work.entryList(filter,QDir::Files,QDir::Time|QDir::Reversed);
5187 int vers=0;
5188 if (resfs.isEmpty()) vers=1;
5189 else {
5190 bool ok=true;
5191 for (int i = 0; i < resfs.size(); i++)
5192 vers = qMax(resfs.at(i).section("_",-2,-2).toInt(&ok,36),vers);
5193 vers++;
5194 }
5195 if (!work.exists ( QString("%1/%2saves/").arg(dn).arg(PROGRAM_NAME))) work.mkdir (QString("%1/%2saves/").arg(dn).arg(PROGRAM_NAME));
5196 QFile::copy(insname,QString("%1/%4saves/%2_%3_.ins").arg(dn).arg(argument).arg(vers,2,36,QLatin1Char('0')).arg(PROGRAM_NAME));
5197 QFile::remove(insname);
5198 QFile::copy(dirName,insname);
5199
5200 QFile::copy(fcfname2,QString("%1/%4saves/%2_%3_.fcf").arg(dn).arg(argument).arg(vers,2,36,QLatin1Char('0')).arg(PROGRAM_NAME));
5201 QFile::remove(fcfname2);
5202 QFile::copy(fcfname,fcfname2);
5203 }
5204 else {
5205 int but=QMessageBox::information(0,"information",
5206 QString("<h3>The <b>ins</b>truction file is newer than the <b>res</b>ult file you are working on!</h3> %1 %2 <br> %3 <br> %4<br>Maybe you edited it outside of this program.\
5207 <br> Now the your computer clock says: %5<br>%6 %7 (negative numbers here probably indicate asynchronous clocks on network file systems.)<br><hr><b> Click on 'Ignore' to copy your current .res to .ins file and refine.</b>")
5208 .arg(insname)
5209 .arg(dirName)
5210 .arg(QFileInfo(insname).lastModified().toString(Qt::TextDate))
5211 .arg(QFileInfo(dirName).lastModified().toString(Qt::TextDate))
5212 .arg(QDateTime::currentDateTime().toString(Qt::TextDate))
5213 #if (QT_VERSION >= 0x040700)
5214 .arg(QFileInfo(insname).lastModified().msecsTo(QDateTime::currentDateTime()))
5215 .arg(QFileInfo(dirName).lastModified().msecsTo(QDateTime::currentDateTime()))
5216 #else
5217 .arg(QFileInfo(insname).lastModified().secsTo(QDateTime::currentDateTime()))
5218 .arg(QFileInfo(dirName).lastModified().secsTo(QDateTime::currentDateTime()))
5219
5220 #endif
5221 ,QMessageBox::Ignore|QMessageBox::Ok);
5222 if (but==QMessageBox::Ignore){
5223 QDir work=QDir(QString("%1/%2saves/").arg(dn).arg(PROGRAM_NAME));
5224 QStringList filter;
5225 filter << QString("%1_*_.ins").arg(argument);
5226 QStringList resfs;
5227 resfs=work.entryList(filter,QDir::Files,QDir::Time|QDir::Reversed);
5228 int vers=0;
5229 if (resfs.isEmpty()) vers=1;
5230 else {
5231 bool ok=true;
5232 for (int i = 0; i < resfs.size(); i++)
5233 vers = qMax(resfs.at(i).section("_",-2,-2).toInt(&ok,36),vers);
5234 vers++;
5235 }
5236 if (!work.exists ( QString("%1/%2saves/").arg(dn).arg(PROGRAM_NAME))) work.mkdir (QString("%1/%2saves/").arg(dn).arg(PROGRAM_NAME));
5237 QFile::copy(insname,QString("%1/%4saves/%2_%3_.ins").arg(dn).arg(argument).arg(vers,2,36,QLatin1Char('0')).arg(PROGRAM_NAME));
5238 QFile::remove(insname);
5239 QFile::copy(dirName,insname);
5240
5241 QFile::copy(fcfname2,QString("%1/%4saves/%2_%3_.fcf").arg(dn).arg(argument).arg(vers,2,36,QLatin1Char('0')).arg(PROGRAM_NAME));
5242 QFile::remove(fcfname2);
5243 QFile::copy(fcfname,fcfname2);
5244 }else{
5245 shxOutputDock->hide();
5246 infotainmentDock->hide();
5247 refineButtonBox->hide();
5248 pro7->hide();
5249 refineButtonBox2->hide();
5250 stoppRefinement->hide();
5251 stoppRefinement2->hide();
5252 finishRefinement->hide();
5253 finishRefinement2->hide();
5254 shxEditorDock->show();
5255 dock->show();
5256 histDock->show();
5257 return;
5258 }
5259 }
5260 }else{
5261 QDir work=QDir(QString("%1/%2saves/").arg(dn).arg(PROGRAM_NAME));
5262 QStringList filter;
5263 filter << QString("%1_*_.ins").arg(argument);
5264 QStringList resfs;
5265 resfs=work.entryList(filter,QDir::Files,QDir::Time|QDir::Reversed);
5266 int vers=0;
5267 if (resfs.isEmpty()) vers=1;
5268 else {
5269 bool ok=true;
5270 for (int i = 0; i < resfs.size(); i++)
5271 vers = qMax(resfs.at(i).section("_",-2,-2).toInt(&ok,36),vers);
5272 vers++;
5273 }
5274 if (!work.exists ( QString("%1/%2saves/").arg(dn).arg(PROGRAM_NAME))) work.mkdir (QString("%1/%2saves/").arg(dn).arg(PROGRAM_NAME));
5275 QFile::copy(dirName,QString("%1/%4saves/%2_%3_.ins").arg(dn).arg(argument).arg(vers,2,36,QLatin1Char('0')).arg(PROGRAM_NAME));
5276
5277 }
5278 }
5279 /// bruce will es
5280 }
5281 if ((extraExt2.size()>index)&&(!extraExt2.at(index).isEmpty())){
5282 argument.remove(resorins);
5283 argument.append(extraExt2.at(index));
5284 }
5285 extraProc = new QProcess(this);
5286 QStringList al;
5287 if ((extraOptions.size()>index)&&(!extraOptions.at(index).isEmpty())) al.append(extraOptions.at(index));
5288 if (extraArguments.at(index)==Qt::Checked){
5289 if (extraAbsolutePath.at(index)==Qt::Checked) al.append(dirName); else al.append(argument);
5290 }
5291 extraProc->setWorkingDirectory(dn); // updateXLput()
5292 connect(extraProc,SIGNAL(readyReadStandardOutput ()),this,SLOT(updateExtraOutput()));
5293 connect(extraProc,SIGNAL(finished(int,QProcess::ExitStatus)),this,SLOT(updateExtraOutput()));
5294 connect(extraProc,SIGNAL(error(QProcess::ProcessError)),this,SLOT(updateExtraOutput()));
5295 #if (QT_VERSION >= 0x040600)
5296 QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
5297 extraProc->setProcessEnvironment(env);//Thanks to Dr. Pavlo Solntsev!!
5298 #else
5299 QStringList env = QProcess::systemEnvironment();
5300 extraProc->setEnvironment(env);
5301 #endif
5302 QString dummyargument=al.join(" ");
5303 al=dummyargument.split(" ");
5304 if (extraDetach.at(index)) {
5305
5306 #if (QT_VERSION >= 0x050700)
5307 #if defined Q_WS_WIN || defined Q_OS_WIN
5308 extraProc->setProgram(path);
5309 extraProc->setArguments(al);
5310 extraProc->setWorkingDirectory(dn);
5311 extraProc->setCreateProcessArgumentsModifier([] (QProcess::CreateProcessArguments *args) {args->flags &= ~CREATE_NO_WINDOW;});
5312 extraProc->startDetached();
5313 /*
5314 //https://bugreports.qt.io/browse/QTBUG-57687?focusedCommentId=354550&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-354550
5315 QProcess p;
5316 p.setProgram("cmd.exe");
5317 p.setArguments({"/k", "echo", "Hello from Qt!"});
5318 p.setCreateProcessArgumentsModifier([] (QProcess::CreateProcessArguments *args) {
5319 args->flags &= ~CREATE_NO_WINDOW;
5320 });
5321 p.startDetached();
5322 */
5323 #else
5324 extraProc->startDetached(path,al,dn);
5325 #endif
5326 #else
5327 extraProc->startDetached(path,al,dn);
5328 #endif
5329
5330 }
5331 else {
5332 extraProc->start(path,al);
5333 extraOutPut->setText(QString("|--- Running %1 %2 in %3 ---|\n").arg(path).arg(al.join(" ")).arg(dn));
5334 extraOutput->show();
5335 }
5336 }
5337
5338 void Window::updateExtraOutput(){
5339 #if (QT_VERSION >= 0x050300)
5340 if (extraProc->processId()) {
5341 #else
5342 if (extraProc->pid()) {
5343 #endif
5344 extraOutPut->setReadOnly(false);
5345 QString s=extraOutPut->toPlainText();
5346 s.append(extraProc->readAllStandardOutput());
5347 s.append(extraProc->readAllStandardError());
5348 extraOutPut->setPlainText(s);
5349 extraOutPut->moveCursor(QTextCursor::End);
5350 extraOutPut->ensureCursorVisible ();
5351 extraOutPut->setReadOnly(true);
5352 extraProc->write("\n"); // this is sent to fake a 'pause' waiting for any key so that the script continues
5353 }else{
5354 extraOutPut->setReadOnly(false);
5355 QString s=extraOutPut->toPlainText();
5356 s.append(extraProc->readAllStandardOutput());
5357 s.append(extraProc->readAllStandardError());
5358 if (s.isEmpty()) {
5359 s.append("|---Program is not running!---|\n");
5360 extraIndex = -1;
5361 }
5362 else{
5363 if ((s.endsWith(" ---|\n"))&&(extraIndex>-1)){
5364 einstellung->beginGroup("Extra");
5365 einstellung->beginWriteArray("ProgramDetached",extraDetach.size());
5366 einstellung->setArrayIndex(extraIndex);
5367 einstellung->setValue("Detach", Qt::Checked);
5368 extraDetach[extraIndex] = Qt::Checked;
5369 einstellung->endArray();
5370 einstellung->endGroup();
5371 printf("There was no output. I will start this program detached in future. I hope that is Ok.\n");
5372
5373 }
5374 if ((extraIndex == -21)&&(QFile::exists(pngName))){
5375 //here should be a png output file of povray be loaded
5376 QLabel *preview = new QLabel("");
5377 int eh = extraOutput->height(), ew = extraOutput->width();
5378 preview->setPixmap(QPixmap(pngName));
5379 if (qsaPNG==nullptr) qsaPNG = new QScrollArea(extraOutput);
5380 qsaPNG->setWidget(preview);
5381 lt->addWidget(qsaPNG);
5382 QString s=extraOutPut->toPlainText();
5383 s.append("\n|---Program is finished.---|\n");
5384 extraOutput->resize(ew,2*eh);
5385 }else{
5386 s.append("\n|---Program is finished.---|\n");
5387 QString dn=dirName.section('/',0,-2), argument=dirName.section('/',-1);
5388 argument.remove(QRegularExpression(".res$|.ins$|.cif$",QRegularExpression::CaseInsensitiveOption));
5389 QDir work=QDir(QString("%1/").arg(dn));
5390 QStringList filter;
5391 filter << QString("%1*.res").arg(argument)<< QString("%1*.ins").arg(argument);;
5392 QStringList resfs;
5393 resfs=work.entryList(filter,QDir::Files,QDir::Time|QDir::Reversed);
5394
5395 QList<QToolButton *> oldbuts = extraOutput->findChildren<QToolButton *>("resloadbutton");
5396 //printf("old buttons %d\n",oldbuts.size());
5397 for (int i=oldbuts.size()-1; i>=0; i--) {
5398 oldbuts[i]->setVisible(false);
5399 oldbuts[i]->deleteLater();
5400 }
5401 QHBoxLayout *hbl=new QHBoxLayout();
5402 QToolButton *tbb0=new QToolButton();
5403 QAction *ac0=new QAction(QString("cancel"),this);
5404 connect(ac0,SIGNAL(triggered()),extraOutput,SLOT(reject()));
5405 tbb0->setDefaultAction(ac0);
5406 tbb0->setObjectName("resloadbutton");
5407 for (int i=0; i<resfs.size(); i++){
5408 QAction *ac=new QAction(QString("load %1").arg(resfs.at(i)),this);
5409 ac->setData(QString("%1/%2").arg(dn).arg(resfs.at(i)));
5410
5411 connect(ac,SIGNAL(triggered()),this,SLOT(loadThisFile()));
5412 QToolButton *tbb=new QToolButton();
5413 tbb->setDefaultAction(ac);
5414 tbb->setObjectName("resloadbutton");
5415 hbl->addWidget(tbb);
5416 }
5417 hbl->addWidget(tbb0);
5418 lt->addLayout(hbl);
5419 }//-21
5420 extraIndex = -1;
5421 }
5422 extraOutPut->setPlainText(s);
5423 extraOutPut->moveCursor(QTextCursor::End);
5424 extraOutPut->ensureCursorVisible ();
5425 extraOutPut->setReadOnly(true);
5426 }
5427 }
5428
5429 void Window::loadThisFile(){
5430 extraOutput->hide();
5431 QAction *action = qobject_cast<QAction *>(sender());
5432 QString name="";
5433 if (action)
5434 name=action->data().toString();
5435 else return;
5436 if (name.isEmpty()) return;
5437
5438
5439 loadFile(name);
5440 }
5441
5442 void Window::configureBottomToolbar(){
5443 QAction *action = qobject_cast<QAction *>(sender());
5444 int index=0;
5445 if (action)
5446 index=action->data().toInt();
5447 else return;
5448 if ((index>=0)&&(index<5)) bottomToolBar->setToolButtonStyle((Qt::ToolButtonStyle) index);
5449 if (index>32) {
5450 index-=32;
5451 addToolBarBreak();
5452 addToolBar((Qt::ToolBarArea) index,bottomToolBar);
5453 }
5454 einstellung->beginGroup("ToolBar");
5455 einstellung->setValue("SelectionToolBarStyle",bottomToolBar->toolButtonStyle());
5456 einstellung->endGroup();
5457
5458 }
5459
5460 void Window::grossRC(const QString &text){
5461 QString s=text.toUpper ();
5462 resiResiClass->setText(s);
5463 update();
5464 }
5465
5466 void Window::defineBarray() {
5467 //! This method adjusts the value for the B array in SHELXL according to the number of atoms.
5468 //! The calculation is not rocket science, but should work in every case.
5469 int barray;
5470 if (useMyBArray) {
5471 return; // the user wants to have his own value;
5472 }
5473 barray = mole.asymm.size() * 9; // Can fail with very large molecules.
5474 if (barray > 3000) { // B array == 3000 is defult
5475 shelxlArgs = shelxlArgs.simplified();
5476 if (!shelxlArgs.contains("-b")) {
5477 shelxlArgs += QString(" -b%1").arg(barray);
5478 } else {
5479 shelxlArgs.replace(QRegularExpression("\\s{0,2}\\-b\\s{0,1}\\d{0,8}"), QString(" -b%1").arg(barray));
5480 }
5481 }
5482 }
5483
5484 void Window::runShelXL(){
5485 QAction *action = qobject_cast<QAction *>(sender());
5486 if (action){
5487 if (action->data().toInt()==1) {editor->insertAnis(); if (!fileSave(true,false)) return;}
5488 if (action->data().toInt()==2) {editor->insertActa(); if (!fileSave(true,false)) return;}
5489 if (action->data().toInt()==3) {editor->insertEXTI(); if (!fileSave(true,false)) return;}
5490 if (action->data().toInt()==4) {editor->insertCONF(); if (!fileSave(true,false)) return;}
5491 }
5492 if (maybeSave2()){
5493 if (mole.qbeforehkl) deleteAllQ();
5494 // printf("runXL line %d",__LINE__);
5495 editor->insertList6();
5496 xlPutor->clear();
5497
5498 xlPutor->ListFile=false;
5499 //xlPutor->highlighter->loadHighlightPatterns(lstpatternfile);
5500 shxOutputDock->show();
5501 stoppRefinement->show();
5502 finishRefinement->show();
5503 finishRefinement->setFocus();
5504 QObject::disconnect(stoppRefinement, 0, this, 0);
5505 if (infotainmentDock->isVisible())finishRefinement2->setFocus();
5506 stoppRefinement2->show();
5507 finishRefinement2->show();
5508 QObject::disconnect(stoppRefinement2, 0, this, 0);
5509 refineButtonBox->hide();
5510 pro7->hide();
5511 loadRes->show();
5512 refineButtonBox2->hide();
5513 loadRes2->show();
5514 shxEditorDock->hide();
5515 dock->hide();
5516 histDock->hide();
5517 renamDock->hide();
5518 QString dn=dirName.section('/',0,-2),
5519 argument=dirName.section('/',-1);
5520 argument.remove(resorins);
5521 if (dirName.contains(punktres)){
5522 QString insname =dirName;
5523 insname.replace(punktres,".ins");
5524
5525 QString fcfname = dirName;
5526 fcfname.replace(punktres,".fcf");
5527 QString fcfname2 = dirName;
5528 fcfname2.replace(punktres,".2fcf");
5529 // qDebug()<<QFileInfo(insname).lastModified().toString(Qt::TextDate)<<QFileInfo(dirName).lastModified().toString(Qt::TextDate)<<(QFileInfo(dirName).lastModified()>=QFileInfo(insname).lastModified());
5530 if (//(0)&&
5531 (QFileInfo(dirName).lastModified()>=QFileInfo(insname).lastModified())){
5532 QDir work=QDir(QString("%1/%2saves/").arg(dn).arg(PROGRAM_NAME));
5533 QStringList filter;
5534 filter << QString("%1_*_.ins").arg(argument);
5535 QStringList resfs;
5536 resfs=work.entryList(filter,QDir::Files,QDir::Time|QDir::Reversed);
5537 int vers=0;
5538 if (resfs.isEmpty()) vers=1;
5539 else {
5540 bool ok=true;
5541 for (int i = 0; i < resfs.size(); i++)
5542 vers = qMax(resfs.at(i).section("_",-2,-2).toInt(&ok,36),vers);
5543 vers++;
5544 }
5545 if (!work.exists ( QString("%1/%2saves/").arg(dn).arg(PROGRAM_NAME))) work.mkdir (QString("%1/%2saves/").arg(dn).arg(PROGRAM_NAME));
5546 QFile::copy(insname,QString("%1/%4saves/%2_%3_.ins").arg(dn).arg(argument).arg(vers,2,36,QLatin1Char('0')).arg(PROGRAM_NAME));
5547 QFile::remove(insname);
5548 QFile::copy(dirName,insname);
5549
5550 QFile::copy(fcfname2,QString("%1/%4saves/%2_%3_.fcf").arg(dn).arg(argument).arg(vers,2,36,QLatin1Char('0')).arg(PROGRAM_NAME));
5551 QFile::remove(fcfname2);
5552 QFile::copy(fcfname,fcfname2);
5553 }
5554 else {
5555 int but=QMessageBox::information(0,"information",
5556 QString("<h3>The <b>ins</b>truction file is newer than the <b>res</b>ult file you are working on!</h3> %1 %2 <br> %3 <br> %4<br>Maybe you edited it outside of this program.\
5557 <br> Now the your computer clock says: %5<br>%6 %7 (negative numbers here probably indicate asynchronous clocks on network file systems.)<br><hr><b> Click on 'Ignore' to copy your current .res to .ins file and refine.</b>")
5558 .arg(insname)
5559 .arg(dirName)
5560 .arg(QFileInfo(insname).lastModified().toString(Qt::TextDate))
5561 .arg(QFileInfo(dirName).lastModified().toString(Qt::TextDate))
5562 .arg(QDateTime::currentDateTime().toString(Qt::TextDate))
5563 #if (QT_VERSION >= 0x040700)
5564 .arg(QFileInfo(insname).lastModified().msecsTo(QDateTime::currentDateTime()))
5565 .arg(QFileInfo(dirName).lastModified().msecsTo(QDateTime::currentDateTime()))
5566 #else
5567 .arg(QFileInfo(insname).lastModified().secsTo(QDateTime::currentDateTime()))
5568 .arg(QFileInfo(dirName).lastModified().secsTo(QDateTime::currentDateTime()))
5569
5570 #endif
5571 ,QMessageBox::Ignore|QMessageBox::Ok);
5572 if (but==QMessageBox::Ignore){
5573 QDir work=QDir(QString("%1/%2saves/").arg(dn).arg(PROGRAM_NAME));
5574 QStringList filter;
5575 filter << QString("%1_*_.ins").arg(argument);
5576 QStringList resfs;
5577 resfs=work.entryList(filter,QDir::Files,QDir::Time|QDir::Reversed);
5578 int vers=0;
5579 if (resfs.isEmpty()) vers=1;
5580 else {
5581 bool ok=true;
5582 for (int i = 0; i < resfs.size(); i++)
5583 vers = qMax(resfs.at(i).section("_",-2,-2).toInt(&ok,36),vers);
5584 vers++;
5585 }
5586 if (!work.exists ( QString("%1/%2saves/").arg(dn).arg(PROGRAM_NAME))) work.mkdir (QString("%1/%2saves/").arg(dn).arg(PROGRAM_NAME));
5587 QFile::copy(insname,QString("%1/%4saves/%2_%3_.ins").arg(dn).arg(argument).arg(vers,2,36,QLatin1Char('0')).arg(PROGRAM_NAME));
5588 QFile::remove(insname);
5589 QFile::copy(dirName,insname);
5590
5591 QFile::copy(fcfname2,QString("%1/%4saves/%2_%3_.fcf").arg(dn).arg(argument).arg(vers,2,36,QLatin1Char('0')).arg(PROGRAM_NAME));
5592 QFile::remove(fcfname2);
5593 QFile::copy(fcfname,fcfname2);
5594 }else{
5595 shxOutputDock->hide();
5596 infotainmentDock->hide();
5597 refineButtonBox->hide();
5598 pro7->hide();
5599 refineButtonBox2->hide();
5600 finishRefinement->hide();
5601 finishRefinement2->hide();
5602 stoppRefinement->hide();
5603 stoppRefinement2->hide();
5604 shxEditorDock->show();
5605 dock->show();
5606 histDock->show();
5607 return;
5608 }
5609 }
5610 }else{
5611 QDir work=QDir(QString("%1/%2saves/").arg(dn).arg(PROGRAM_NAME));
5612 QStringList filter;
5613 filter << QString("%1_*_.ins").arg(argument);
5614 QStringList resfs;
5615 resfs=work.entryList(filter,QDir::Files,QDir::Time|QDir::Reversed);
5616 int vers=0;
5617 if (resfs.isEmpty()) vers=1;
5618 else {
5619 bool ok=true;
5620 for (int i = 0; i < resfs.size(); i++)
5621 vers = qMax(resfs.at(i).section("_",-2,-2).toInt(&ok,36),vers);
5622 vers++;
5623 }
5624 if (!work.exists ( QString("%1/%2saves/").arg(dn).arg(PROGRAM_NAME))) work.mkdir (QString("%1/%2saves/").arg(dn).arg(PROGRAM_NAME));
5625 QFile::copy(dirName,QString("%1/%4saves/%2_%3_.ins").arg(dn).arg(argument).arg(vers,2,36,QLatin1Char('0')).arg(PROGRAM_NAME));
5626
5627 }
5628 //printf("runXL!123\n");
5629
5630 shxOutputDock->setWindowTitle(QString("SHELXL OUTPUT: %1").arg(argument));
5631 shxOutputDock->show();
5632 shxOutputDock->raise();
5633 shelxl = new QProcess(this);
5634
5635 QStringList al;
5636 al.append(argument);
5637
5638 defineBarray();
5639 finishRefinement->setFocus();
5640 vis_settings->beginGroup("infotaiment");
5641 bool lastvis = vis_settings->value("info_as_default").toBool();
5642 vis_settings->endGroup();
5643 if (lastvis) {
5644 raiseTaff();
5645 finishRefinement2->setFocus();
5646 }
5647 al+=shelxlArgs.split(' ',skipEmptyParts);
5648 shelxl->setWorkingDirectory(dn); // updateXLput()
5649 if (focusSet) connect(shelxl,SIGNAL(finished(int,QProcess::ExitStatus)),loadRes ,SLOT(setFocus()));
5650 if ((lastvis)&&(focusSet)) connect(shelxl,SIGNAL(finished(int,QProcess::ExitStatus)),loadRes2 ,SLOT(setFocus()));
5651
5652 #if (QT_VERSION >= 0x060400)
5653 connect(shelxl,&QProcess::readyReadStandardOutput,this,&Window::updateXLput);
5654 connect(shelxl,&QProcess::finished, refineButtonBox, &QGroupBox::show);
5655 connect(shelxl,&QProcess::finished, refineButtonBox2, &QGroupBox::show);
5656 connect(shelxl,&QProcess::finished, stoppRefinement, &QPushButton::hide);
5657 connect(shelxl,&QProcess::finished, finishRefinement, &QPushButton::hide);
5658 connect(shelxl,&QProcess::finished, finishRefinement2, &QPushButton::hide);
5659 connect(shelxl,&QProcess::finished, stoppRefinement2, &QPushButton::hide);
5660 connect(shelxl,&QProcess::finished, this, &Window::updateXLput);
5661 connect(shelxl,&QProcess::finished, this, &Window::displayDisagreeableRestraints);
5662 connect(shelxl,&QProcess::errorOccurred,this,&Window::updateXLput);
5663 #else
5664 connect(shelxl,SIGNAL(readyReadStandardOutput ()),this,SLOT(updateXLput()));
5665 connect(shelxl,SIGNAL(finished(int,QProcess::ExitStatus)),refineButtonBox ,SLOT(show()));
5666 connect(shelxl,SIGNAL(finished(int,QProcess::ExitStatus)),refineButtonBox2 ,SLOT(show()));
5667 connect(shelxl,SIGNAL(finished(int,QProcess::ExitStatus)),stoppRefinement ,SLOT(hide()));
5668 connect(shelxl,SIGNAL(finished(int,QProcess::ExitStatus)),finishRefinement ,SLOT(hide()));
5669 connect(shelxl,SIGNAL(finished(int,QProcess::ExitStatus)),finishRefinement2 ,SLOT(hide()));
5670 connect(shelxl,SIGNAL(finished(int,QProcess::ExitStatus)),stoppRefinement2 ,SLOT(hide()));
5671 connect(shelxl,SIGNAL(finished(int,QProcess::ExitStatus)),this,SLOT(updateXLput()));
5672 connect(shelxl,SIGNAL(finished(int,QProcess::ExitStatus)),this,SLOT(displayDisagreeableRestraints()));
5673 connect(shelxl,SIGNAL(error(QProcess::ProcessError)),this,SLOT(updateXLput()));
5674 //printf("QT??? %X\n",QT_VERSION);
5675 #endif
5676
5677 connect(finishRefinement,SIGNAL(clicked()),this,SLOT(finXL()));
5678 connect(finishRefinement2,SIGNAL(clicked()),this,SLOT(finXL()));
5679 #if defined Q_WS_WIN || defined Q_OS_WIN
5680 connect(stoppRefinement,SIGNAL(clicked()),shelxl,SLOT(kill()));
5681 connect(stoppRefinement2,SIGNAL(clicked()),shelxl,SLOT(kill()));
5682 #else
5683 connect(stoppRefinement,SIGNAL(clicked()),shelxl,SLOT(terminate()));
5684 connect(stoppRefinement2,SIGNAL(clicked()),shelxl,SLOT(terminate()));
5685 #endif
5686 connect(stoppRefinement,SIGNAL(clicked()),loadRes,SLOT(hide()));
5687 connect(stoppRefinement2,SIGNAL(clicked()),loadRes2,SLOT(hide()));
5688 shelxl->start(shelxlPath,al);
5689 //printf("runXL!123 123\n");
5690 pro7->show();
5691 }
5692 }
5693
5694 void Window::displayResiduals(XLOutputParser &lfo, QString s) {
5695 //! Draws the residuals of the refinement as a table
5696 //qDebug()<<s;
5697 RGraph lsdata;
5698 lsdata.cycle = 0;
5699 restr_table->clear();
5700 foreach (QString line, s.split(QRegularExpression("\n|\r\n|\r"))) {
5701 resid_label->setText(lfo.residualsTextDisplay(line, ls_cycls));
5702 }
5703 }
5704
5705 void Window::displayDisagreeableRestraints() {
5706 //! Displays the list of disagreeable restraints in the restr_table widget
5707 //! This has to be started ofter SHELXL is finished! (via signal)
5708 QFileInfo lfi(dirName);
5709 QString restrtext = "There is no SHELXL list file available for this structure. Please refine to get output here.";
5710 QString lfpath;
5711 lfpath = lfi.absoluteFilePath().replace(".res", ".lst");
5712 if (QFile(lfpath).exists()) {
5713 ListFileHandler lf(lfpath);
5714 restrtext = lf.restraintsTable();
5715 }
5716 restr_table->setText(restrtext);
5717 }
5718
5719 void Window::updateXLput(){
5720 XLOutputParser xlo;
5721 QString warn = "** NO running Process maybe the 'shelxl' is not in PATH or is spelled differently **\n\n"
5722 "** Please give a correct path to an existing executable of shelxl. **\n\n"
5723 "** Check SHELXL -> 'Specify SHELXL runtime options' **";
5724 if (infotainmentDock->isVisible())finishRefinement2->setFocus(); else finishRefinement->setFocus();
5725 #if (QT_VERSION >= 0x050300)
5726 if (shelxl->processId()&&shelxl->isOpen()) {
5727 #else
5728 if (shelxl->pid()&&shelxl->isOpen()) {
5729 #endif
5730 // printf("updateXLput()\n");
5731 xlPutor->setReadOnly(false);
5732 QString s=xlPutor->toPlainText();
5733 s.append(shelxl->readAllStandardOutput());
5734 s.append(shelxl->readAllStandardError());
5735 //qDebug()<<__LINE__<<s;
5736 displayResiduals(xlo, s);
5737 if (shelxl->state()==QProcess::NotRunning) {
5738 s.append(warn);
5739 resid_label->append("<b>" + warn.replace("\n", "<br>") + "</b>");
5740 refineButtonBox->show();
5741 stoppRefinement->hide();
5742 finishRefinement->hide();
5743 finishRefinement2->hide();
5744 refineButtonBox2->show();
5745 stoppRefinement2->hide();
5746 }
5747 xlPutor->setPlainText(s);
5748 falschAtom=-1;
5749 xlPutor->setReadOnly(true);
5750 loadRes->setEnabled((s.contains("for all data")));
5751 loadRes2->setEnabled((s.contains("for all data")));
5752 if ((focusSet)&&(!s.contains("for all data"))) withdraw->setFocus();
5753 if (s.contains(" ** ")) {
5754 QString Fehl=s.section("**",1,1).simplified();
5755 Fehl=Fehl.remove("UNSUITABLE AFIX HYDROGENS FOLLOW ");
5756 Fehl=Fehl.remove("BAD Ueq DEPENDENCE FOR ");
5757 Fehl=Fehl.remove("BAD AFIX FOR ");
5758 Fehl=Fehl.remove("BAD AFIX CONNECTIVITY: ");
5759 Fehl=Fehl.remove("NO PIVOT ATOM FOR RIGID GROUP CONTAINING ");
5760 Fehl=Fehl.simplified();
5761 Fehl=Fehl.section(' ',0,0);
5762 if ((Fehl.size()<5)||Fehl.contains('_')){
5763 chgl->mol->selectedatoms.clear();
5764 for (int i=0; i<chgl->mol->showatoms.size(); i++){
5765 if (!Fehl.compare(chgl->mol->showatoms.at(i).Label,Qt::CaseInsensitive)){
5766 chgl->mol->selectedatoms.append(chgl->mol->showatoms[i]);
5767 chgl->mol->selectedatoms.last().style=i;
5768 }
5769 }
5770 if (!chgl->mol->selectedatoms.isEmpty()) {
5771 chgl->centerSelection->setChecked(true);
5772 chgl->updateBondActions();
5773 chgl->update();
5774 update();
5775 chgl->update();
5776 falschAtom=chgl->mol->selectedatoms.last().style;
5777 jumpToAtom(chgl->mol->selectedatoms.last().style);
5778
5779 }
5780 }
5781 }
5782 }else{
5783 xlPutor->setReadOnly(false);
5784 QString s=xlPutor->toPlainText();
5785 if (shelxl->isOpen()) {
5786 s.append(shelxl->readAllStandardOutput());
5787 s.append(shelxl->readAllStandardError());
5788 }
5789 //qDebug()<<__LINE__<<s;
5790 if (s.isEmpty()){
5791 s.append(warn);
5792 resid_label->append("<b>" + warn.replace("\n", "<br>") + "</b>");
5793 }
5794 xlPutor->setPlainText(s);
5795 xlPutor->setReadOnly(true);
5796 if (!s.contains("WGHT")){
5797 loadRes->setEnabled((s.contains("for all data")));
5798 loadRes2->setEnabled((s.contains("for all data")));
5799 refineButtonBox->show();
5800 stoppRefinement->hide();
5801 finishRefinement->hide();
5802 finishRefinement2->hide();
5803 refineButtonBox2->show();
5804 stoppRefinement2->hide();
5805 }
5806 if (!s.contains("Total elapsed")) {
5807 // SHELXL executed but didn't finish:
5808 resid_label->append("<b>SHELXL was terminated!</b>");
5809 }
5810 }
5811
5812 QTextCursor tc = xlPutor->textCursor();
5813 tc.movePosition(QTextCursor::End, QTextCursor::MoveAnchor);
5814 xlPutor->setTextCursor(tc);
5815 xlPutor->ensureCursorVisible();
5816 update();
5817 if (infotainmentDock->isVisible())finishRefinement2->setFocus(); else finishRefinement->setFocus();
5818 }
5819
5820 void Window::loadrefres(){
5821 dirName.replace(punktins,".res");
5822 shxOutputDock->hide();
5823 infotainmentDock->hide();
5824
5825 refineButtonBox->hide();
5826 refineButtonBox2->hide();
5827 shxEditorDock->show();
5828 shxEditorDock->raise();
5829
5830 loadFile(dirName);
5831 }
5832
5833 void Window::replyFinished(QNetworkReply* antwort){
5834 QSettings *einstellung =new QSettings( QSettings::IniFormat, QSettings::UserScope ,PROGRAM_NAME,mole.mynewnameis );
5835 int ignore=0;
5836 einstellung->beginGroup("Updates");
5837 if (einstellung->contains("IgnoreUpdates"))
5838 ignore=einstellung->value("IgnoreUpdates").toInt();
5839 einstellung->endGroup();
5840 QString a=antwort->readAll();
5841 latestRev=a;
5842 bool ok;
5843 int lat=a.toInt(&ok,10);
5844 if (ok&&lat&&(0==(ignore&QMessageBox::No))){
5845 if ((lat-7)>Revision) {
5846 int later=
5847 QMessageBox::information(
5848 0,"information",QString(
5849 "<h3>This is revision: <font color=#aa66cc>%1"
5850 "</font><br> The latest available version is revision: <font color=#aa66cc> %2</font> "
5851 "New versions can be downloaded here: "
5852 "<a href=\"http://shelxle.org/shelx/index.php\">"
5853 "http://shelxle.org/shelx/index.php</a></h3>"
5854 "<h4>Please contact the author"
5855 " <a href=\"mailto:[email protected]\">[email protected]</a> if you find any bugs.<br> Thank you!</h4>"
5856 "<h3>Do you want to be reminded later?</h3>").arg(Revision).arg(lat)
5857 ,QMessageBox::Yes|QMessageBox::No,QMessageBox::Yes);
5858
5859 einstellung->beginGroup("Updates");
5860 einstellung->setValue("IgnoreUpdates",later);
5861 einstellung->endGroup();
5862 }
5863 }else{
5864 latestRev="<font color=red> network unavailable, check failed.</font>";
5865 }
5866 antwort->close();
5867 antwort->deleteLater();
5868 disconnect(net,SIGNAL(finished(QNetworkReply*)),0,0);
5869 delete einstellung;
5870 }
5871
5872 void Window::checkForUpdates(){
5873 //disconnect(net,SIGNAL(finished(QNetworkReply*)),0,0);
5874 connect(net, SIGNAL(finished(QNetworkReply*)), this, SLOT(isUpToDate(QNetworkReply*)));
5875 reply = net->get(QNetworkRequest(QUrl("http://shelxle.org/shelx/revision.php")));
5876 }
5877
5878 void Window::isUpToDate(QNetworkReply* antwort){
5879 QSettings *einstellung =new QSettings( QSettings::IniFormat, QSettings::UserScope ,PROGRAM_NAME,mole.mynewnameis);
5880 //int ignore=0;
5881 einstellung->beginGroup("Updates");
5882 if (einstellung->contains("IgnoreUpdates"))
5883 // ignore=
5884 einstellung->value("IgnoreUpdates").toInt();
5885 einstellung->endGroup();
5886 QString a=antwort->readAll();
5887 latestRev=a;
5888 bool ok;
5889 int lat=a.toInt(&ok,10);
5890 if (ok&&lat){
5891 int later=
5892 QMessageBox::information(
5893 0,"information",QString(
5894 "<h3>This is revision: <font color=#aa66cc>%1"
5895 "</font><br> The latest available version is revision: <font color=#aa66cc> %2</font> "
5896 "<h3>%3</h3>"
5897 "New versions can be downloaded here: "
5898 "<a href=\"http://shelxle.org/shelx/index.php\">"
5899 "http://shelxle.org/shelx/index.php</a></h3>"
5900 "<h4>Please contact the author"
5901 " <a href=\"mailto:[email protected]\">[email protected]</a> if you find any bugs.<br> Thank you!</h4>"
5902 "<h3>Do you want to be reminded for new versions at startup?</h3>").arg(Revision).arg(lat).arg(((lat-3)>Revision)?"You should probably update ShelXle.":"Your ShelXle is rather up to date.")
5903 ,QMessageBox::Yes|QMessageBox::No,QMessageBox::Yes);
5904
5905 einstellung->beginGroup("Updates");
5906 einstellung->setValue("IgnoreUpdates",later);
5907 einstellung->endGroup();
5908 }else{
5909 latestRev="<font color=red> network unavailable, check failed.</font>";
5910 QMessageBox::information( 0,"information",latestRev);
5911 }
5912 antwort->close();
5913 antwort->deleteLater();
5914
5915 disconnect(net,SIGNAL(finished(QNetworkReply*)),0,0);
5916
5917 }
5918
5919 void Window::changeLabelFont(){
5920 bool ok;
5921 QFont font = QFontDialog::getFont(&ok, chgl->myFont, this,"Change Label Font");
5922 if (ok) {
5923 //font.setStyleStrategy(QFont::OpenGLCompatible);
5924 chgl->myFont=font;
5925 einstellung->beginGroup("Fonts");
5926 einstellung->setValue("LabelFont",chgl->myFont);
5927 einstellung->setValue("LabelFontSize", chgl->myFont.pointSize());
5928 einstellung->endGroup();
5929 //chgl->updateLabelTextures();
5930 chgl->update();
5931 }
5932 }
5933
5934 void Window::changeEditorFont(){
5935 bool ok;
5936 QFont font = QFontDialog::getFont(&ok, editor->font(), this,"Change Editor Font");
5937 if (ok) {
5938 font.setFixedPitch(true);
5939 einstellung->beginGroup("Fonts");
5940 einstellung->setValue("EditorFont",font);
5941 einstellung->setValue("EditorFontSize",font.pointSize());
5942 einstellung->endGroup();
5943 editor->setFont(font);
5944 xlPutor->setFont(font);
5945 }
5946 }
5947
5948 void Window::withdrawres(){
5949 if (dirName.contains(punktres)){
5950 QString insname =dirName;
5951 insname.replace(punktres,".ins");
5952 QString fcfname = dirName;
5953 fcfname.replace(punktres,".fcf");
5954 QString fcfname2 = dirName;
5955 fcfname2.replace(punktres,".2fcf");
5956 QFile::remove(dirName);
5957 QFile::copy(insname,dirName);
5958 QFile::remove(fcfname);
5959 QFile::copy(fcfname2,fcfname);
5960 editor->document()->setModified(false);
5961 loadFile(dirName);
5962 }
5963 shxOutputDock->hide();
5964 infotainmentDock->hide();
5965 refineButtonBox->hide();
5966 shxEditorDock->show();
5967 if (falschAtom!=-1){
5968 // qDebug()<<"tata"<<falschAtom;
5969 chgl->mol->selectedatoms.clear();
5970 chgl->mol->selectedatoms.append(chgl->mol->showatoms[falschAtom]);
5971 chgl->mol->selectedatoms.last().style=falschAtom;
5972 chgl->centerSelection->setChecked(true);
5973 chgl->updateBondActions();
5974 chgl->update();
5975 update();
5976 chgl->update();
5977 jumpToAtom(falschAtom);
5978
5979 }
5980 }
5981
5982 void Window::loadLst(){
5983 xlPutor->clear();
5984 pro7->hide();
5985 QString listName=dirName;
5986 listName.replace(punktins,".lst");
5987 listName.replace(punktres,".lst");
5988 QFile lstf(listName);
5989 int wl=0;
5990 //xlPutor->highlighter->setDocument(0);
5991 if (lstf.open(QIODevice::ReadOnly|QIODevice::Text)){
5992 QElapsedTimer stech;
5993 stech.start();
5994 xlPutor->setReadOnly(false);
5995 xlPutor->ListFile=true;
5996 //xlPutor->highlighter->setDocument(0);
5997 // xlPutor->highlighter->setOutputStyle();
5998 shxOutputDock->setWindowTitle(QString("LIST FILE: %1").arg(listName.section('/', -1)));
5999 // shxOutputDock->setWhatsThis("<h1>.lst file viewer</h1> The .lst file contains useful information about the refinement of your structure.");
6000 printf("1 %d ms\n", stech.elapsed());
6001 QString testS=QString(lstf.readAll().replace('\0','~'));
6002 printf("2 %d ms\n", stech.elapsed());
6003 xlPutor->setPlainText(testS);
6004 printf("3 %d ms\n", stech.elapsed());
6005 wl=testS.count("\n");
6006 lstf.close();
6007 shxOutputDock->show();
6008 shxOutputDock->lower();
6009 einstellung->beginGroup("Cursor");
6010 if (einstellung->contains("ListFilePos")){
6011 xlPutor->setReadOnly(false);
6012 int mipo= qMin(wl,einstellung->value("ListFilePos",0).toInt());
6013 // printf("mipo %d\n",mipo);
6014 QTextCursor c=xlPutor->textCursor();
6015 // qDebug()<<c.isNull();
6016 c.movePosition(QTextCursor::Start);
6017 c.movePosition(QTextCursor::Down,QTextCursor::MoveAnchor,mipo);
6018 if (!c.isNull()) xlPutor->setTextCursor(c);
6019 xlPutor->centerCursor();
6020 xlPutor->setReadOnly(true);
6021 printf("%s read and ready after %d ms\n",listName.toStdString().c_str(),stech.elapsed());
6022 }
6023 einstellung->endGroup();
6024 xlPutor->setReadOnly(true);
6025 // shxOutputDock->raise();
6026 }else {
6027 shxOutputDock->lower();
6028 shxOutputDock->hide();
6029 }
6030
6031 update();
6032 }
6033
6034 void Window::loadFile(QString fileName, bool fromloadref){
6035 //! Loads the shelxfile, sets the last cursor position in editor, saves "last file" entry in config,
6036 //! checks if file is valid in terms of UNIT, HKLF and END instructions, loads list file, runs the editor.
6037 mole.vtriangles.clear();
6038 mole.vorobas=0;
6039 //chgl->setLabelSize(24);
6040 QDir directory(fileName);
6041 QString dn=directory.canonicalPath();
6042 if ((editor->toPlainText().length()>79)){//(dn!=dirName)&&
6043 QTextCursor c=editor->textCursor();
6044 if (!c.isNull()){
6045 myHash[dirName]=c.position();
6046 einstellung->beginGroup("Cursor");
6047 einstellung->setValue("lastCursorHash", myHash );
6048 einstellung->setValue("ListFilePos",xlPutor->midCursorpos);
6049 einstellung->endGroup();
6050 }
6051 }
6052 dirName=dn;
6053 if (dn!=lastDirName){// do this only is we have a different file name
6054 hklf5files.clear();
6055 //QTime rzeit;
6056 //rzeit.start();
6057 switch2HKLF5->setVisible(doWeHaveHKLF5here(hklf5files));
6058 //printf("doWeHaveHKLF5here() took %d ms.\n", rzeit.elapsed()); // rzeit.restart();
6059 }
6060 switch2HKLF4->setVisible(false);
6061 einstellung->beginGroup("Files");
6062 einstellung->setValue("lastFile", dirName );
6063 einstellung->endGroup();
6064 fileName = dirName;
6065 lastDirName = dirName;
6066 if (fileName.isEmpty()) return;
6067 bool gut=false;
6068 QFile test;
6069 // alltest will contain the shelxfile that is displayed:
6070 QString alltest;
6071 test.setFileName(fileName);
6072 if (test.exists()&&test.size()){
6073 test.open(QIODevice::ReadOnly|QIODevice::Text);
6074 alltest=test.readAll().replace('\0','~');// title can be empty. Fortran then has a string with many \0 this would leed to end of string in Rfactor REMARK section as the title is there
6075
6076 gut = ((alltest.contains("UNIT",Qt::CaseInsensitive))&&(alltest.contains("HKLF",Qt::CaseInsensitive)||alltest.contains("END",Qt::CaseInsensitive)));
6077 test.close();
6078 }
6079 if (!gut){
6080 fileName.replace(QRegularExpression("res$",QRegularExpression::CaseInsensitiveOption),"ins");
6081 test.setFileName(fileName);
6082 if (test.exists()&&test.size()){
6083 test.open(QIODevice::ReadOnly|QIODevice::Text);
6084 alltest=test.readAll();
6085 gut = ((alltest.contains("UNIT",Qt::CaseInsensitive))&&(alltest.contains("HKLF",Qt::CaseInsensitive)||alltest.contains("END",Qt::CaseInsensitive)));
6086 test.close();
6087 if (gut ) dirName=fileName;
6088 }
6089 }
6090 if (!gut) {
6091 QMessageBox::information(this, "information", QString("Can't open %1").arg(fileName));
6092 test.open(QIODevice::ReadOnly|QIODevice::Text);
6093 alltest=test.readAll();
6094 test.close();
6095 return;
6096 }
6097
6098 packMenu->setEnabled(true);
6099
6100 int qtmajor=(QT_VERSION&0xff0000)>>16;
6101 if ((Revision%666)==0) {
6102 setWindowTitle(QString("%1 - A Qt GUI for sHELLxl (Rev: %2): %3[*] ")
6103 .arg(PROGRAM_NAME)
6104 .arg(Revision)
6105 .arg(fileName.section("/",-1)));
6106 } else {
6107 setWindowTitle(QString("%1 - A Qt GUI for SHELXL (Rev: %2)(%4bit)(Qt%5): %3[*] ")
6108 .arg(PROGRAM_NAME)
6109 .arg(Revision)
6110 .arg(fileName.section("/",-1))
6111 .arg(BitWidth)
6112 .arg(qtmajor)
6113 );
6114 }
6115 notRefine = alltest.contains("DISABLE_REFINE");// this has to be here to work correctly
6116 if (alltest.contains("OVERRIDEF000")) {
6117 double str = alltest.section("OVERRIDEF000",1,-1).section('\n',0,0).simplified().toDouble();
6118 fxle->overridef000=(float)str;
6119 //qDebug()<<str<<"hier"<<alltest.section("OVERRIDEF000",1,-1).section('\n',0,0).simplified();
6120 }
6121 runMenu->setDisabled(notRefine);
6122 packMenu->setDisabled(notRefine);
6123 refineToolBar->setDisabled(notRefine);
6124 refineToolBar->setVisible(!notRefine);
6125 alltest.replace(QRegularExpression("=\\s*[\\r\\n]+\\s{1,}"),"=");
6126 alltest.replace(QRegularExpression("REM[^\\n]*\n"),"\n");
6127 alltest.replace(QRegularExpression("![^\\n]*\n"),"\n");
6128 while (alltest.contains(QRegularExpression("[\\n^]\\++[^\\n]*\n"))) {
6129 QString incl=alltest.section(QRegularExpression("[\\n^]\\++"),1,1,QString::SectionSkipEmpty);
6130 incl=incl.section('\n',0,0);
6131 QString pre=dirName.section('/',0,-2);
6132 // qDebug()<<pre+"/"+incl<<QFileInfo(pre+"/"+incl).exists()<<dirName;
6133 if (QFileInfo(pre+"/"+incl).exists()) {
6134 QFile include(pre+"/"+incl);
6135 QString inst;
6136 if (include.open(QIODevice::ReadOnly|QIODevice::Text)) inst=include.readAll();
6137 alltest.replace("++" + incl, inst);
6138 alltest.replace("+" + incl, inst);
6139 } else {
6140 alltest.remove("++" + incl);
6141 alltest.remove("+" + incl);
6142 }
6143 }
6144 loadLst();
6145 //printf("after loadLst()\n");
6146 load_sheldrick(fileName, alltest);
6147 //printf("after load_sheldrick()\n");
6148 shx_editor(fileName);
6149 //printf("after shx_editor()\n");
6150 if (!fileName.contains("helXlesaves")){//do not remember files loaded from a saves folder ... lets see if this is a good idea :-P
6151 einstellung->beginGroup("Files");
6152 einstellung->setValue("lastFile", fileName );
6153 QStringList files = einstellung->value("recentFileList").toStringList();
6154 files.removeAll(fileName); //alle identischen "fileName" aus der Liste entfernen
6155 files.prepend(fileName); // und dann vorne anfuegen...
6156 while (files.size() > MaxRecentFiles) {
6157 files.removeLast() ;//hinten abschneiden was laenger als MaxRecentFiles ist
6158 }
6159 einstellung->setValue("recentFileList", files);
6160 foreach (QWidget *widget, QApplication::topLevelWidgets()) {
6161 Window *mainWin = qobject_cast<Window *>(widget);
6162 if (mainWin)
6163 mainWin->updateRecentFileActions();
6164 }
6165 einstellung->endGroup();
6166 }
6167 hw->setPath(fileName, dock->width());
6168 if (hw->gooddata.size()) histDock->show();
6169 //chgl->updateLabelTextures();
6170 emit fileLoaded();
6171 if ((chgl->toggleOrthoView->isChecked())&&(chgl->viewAngle>3.0)) {
6172 toggleOrtho(true);
6173 chgl->update();
6174 // qDebug()<<chgl->viewAngle;
6175 }
6176 chgl->update();
6177
6178 loadMolInTest(fromloadref);
6179 printf("loadFile\n");
6180 }
6181
6182 void Window::openRecentFile() {
6183 QAction *action = qobject_cast<QAction *>(sender());
6184 if (action)
6185 loadFile(action->data().toString());
6186 }
6187
6188 void Window::setMaxWGHTCycls(){
6189 bool ok;
6190 int i = QInputDialog::getInt(this,
6191 "limit",
6192 "number of maximum cycles in WGHT refinement" ,
6193 wght_max_cycls, -1, 100000, 1, &ok);
6194 if (ok){
6195 wght_max_cycls = i;
6196 wghtRefineAct->setText(QString("Try to refine until WGHT converges (max %1 runs)").arg(wght_max_cycls));
6197 }
6198
6199 }
6200
6201 void Window::setSDMLimit(){
6202 bool ok;
6203 int i = QInputDialog::getInt(this,"limit",
6204 "number of atoms in asymmetric unit to skip automatic distance calculation on loading" , chgl->SDM_Limit, 100, 10000, 1, &ok);
6205 if (ok)
6206 chgl->SDM_Limit=i;
6207
6208 }
6209
6210 void Window::closeEvent(QCloseEvent *event) {
6211 //printf("Close Event\n");
6212 chgl->clearEnvi();
6213 //printf("Close Event survived clearEnvi\n");
6214 if (isFullScreen ())showNormal();
6215 if (maybeSave()){
6216 einstellung->beginGroup("Window");
6217 einstellung->setValue("geometry", saveGeometry());
6218 einstellung->setValue("state", saveState());
6219 /*
6220 int kinder=0;
6221 const QObjectList smwk = shxMW->children();
6222 for (int chi=0; chi<smwk.size(); chi++){
6223 kinder+=smwk.at(chi)->children().size();
6224 }
6225 printf("editor dock has %d children\n",kinder);
6226 */
6227 einstellung->setValue("EditorState",shxMW->saveState());
6228 einstellung->setValue("InvertMouseZoom",(chgl->invertMouseZoom->isChecked()));
6229 einstellung->setValue("SDM-LIMIT", chgl->SDM_Limit);
6230 einstellung->setValue("Calculate-Maps",fxle->doMaps->isChecked());
6231 einstellung->setValue("KeepMapIsoValues",fxle->keepIso->isChecked());
6232 einstellung->setValue("Fo-Map",chgl->foact->isChecked());
6233 einstellung->setValue("Fc-Fo-Map",chgl->fofcact->isChecked());
6234 einstellung->setValue("Map-truncation-type",fxle->mapSchnitt->currentIndex());
6235 einstellung->setValue("Map-Line-Transparency",chgl->lintrans);
6236 einstellung->setValue("Map-Line-Width", chgl->linwidth);
6237 einstellung->setValue("Map-Resolution",fxle->rr);
6238 einstellung->setValue("Map-Weight",fxle->rw);
6239 einstellung->setValue("Map-Lighting",chgl->lighting->isChecked());
6240 einstellung->setValue("Nice-Transparency",chgl->niceTrans->isChecked());
6241 einstellung->setValue("Solid-Map",chgl->fillMap->isChecked());
6242 einstellung->setValue("HighlightEquivalents",mole.highlightEquivalents);
6243 einstellung->setValue("ADPs",chgl->adp->isChecked());
6244 einstellung->setValue("Tubes",chgl->tubes->isChecked());
6245 einstellung->setValue("Legend",chgl->atomLegend->isChecked());
6246 einstellung->setValue("ShowLabels",togLabel->isChecked());
6247 einstellung->setValue("ShortLabels",chgl->shortLabels->isChecked());
6248 einstellung->setValue("BackGroundGradient",togBackGr->isChecked());
6249 einstellung->setValue("SHELXL-PATH",shelxlPath);
6250 einstellung->setValue("LevelOfDetail",mole.LOD);
6251 //einstellung->setValue("Use_GLSL_Shaders",mole.useShaders);
6252 //einstellung->setValue("WireModelOnRotate",chgl->wireButt->isChecked());
6253 einstellung->endGroup();
6254 einstellung->beginGroup("Colors");
6255 einstellung->setValue("LabelColor",chgl->labelColor);
6256 einstellung->setValue("BackGroundColor",chgl->backGroundColor);
6257 einstellung->endGroup();
6258 einstellung->beginGroup("Files");
6259 einstellung->setValue("lastFile", dirName );
6260 einstellung->endGroup();
6261 einstellung->beginGroup("Fonts");
6262 printf("Storing Font to Settings %s %d\n", editor->font().family().toStdString().c_str(), editor->font().pointSize());
6263 einstellung->setValue("EditorFont", editor->font());
6264 einstellung->setValue("EditorFontSize", editor->font().pointSize());
6265 einstellung->setValue("LabelFont",chgl->myFont);
6266 einstellung->setValue("LabelFontSize", chgl->myFont.pointSize());
6267 einstellung->endGroup();
6268 einstellung->beginGroup("ToolBarIcons");
6269 einstellung->setValue("ToolBarIconSize",tbiconSize);
6270 einstellung->endGroup();
6271 QTextCursor c=editor->textCursor();
6272 if (!c.isNull()){
6273 myHash[dirName]=c.position();
6274 einstellung->beginGroup("Cursor");
6275 einstellung->setValue("lastCursorHash", myHash );
6276 einstellung->endGroup();
6277 }
6278 //printf("Close Event survived Einstellungen.\n");
6279 delete einstellung;
6280 //printf("deleting\n");
6281 // printf("%d\n",__LINE__);
6282 editor->clear();
6283 mole.asymm.clear();
6284 // printf("%d\n",__LINE__);
6285 mole.sdm.clear();
6286 // printf("%d\n",__LINE__);
6287 mole.showatoms.clear();
6288 // printf("%d\n",__LINE__);
6289 mole.showbonds.clear();
6290 // printf("%d\n",__LINE__);
6291 mole.cell.symmops.clear();
6292 // printf("%d\n",__LINE__);
6293 mole.cell.trans.clear();
6294 // printf("%d\n",__LINE__);
6295 mole.selectedatoms.clear();
6296 // printf("%d\n",__LINE__);
6297 editor->sfac.clear();
6298 editor->sfacsmbl.clear();
6299 // printf("%d\n",__LINE__);
6300 fvar.clear();
6301 // printf("%d\n",__LINE__);
6302 fvarCntr.clear();
6303 // printf("%d\n",__LINE__);
6304 mole.transEQIV.clear();
6305 // printf("%d\n",__LINE__);
6306 mole.symmopsEQIV.clear();
6307 // printf("%d\n",__LINE__);
6308 mole.labelEQIV.clear();
6309 // printf("%d\n",__LINE__);
6310 mole.freeatoms.clear();
6311 // printf("%d\n",__LINE__);
6312 mole.bindatoms.clear();
6313 // printf("%d\n",__LINE__);
6314 // disconnect(this);
6315 // printf("%d\n",__LINE__);
6316 // disconnect(editor);
6317 // printf("%d %p\n", __LINE__, chgl);
6318 // disconnect(chgl);
6319
6320 // printf("%d\n",__LINE__);
6321 mole.asymm.clear();
6322 // printf("%d\n",__LINE__);
6323 mole.sdm.clear();
6324 // printf("%d\n",__LINE__);
6325 mole.showbonds.clear();
6326 // printf("%d\n",__LINE__);
6327 mole.showatoms.clear();
6328 // printf("%d\n",__LINE__);
6329 mole.selectedatoms.clear();
6330 // printf("%d\n",__LINE__);
6331
6332 mole.envi_sdm.clear();
6333 // printf("%d\n",__LINE__);
6334 mole.contact.clear();
6335 // printf("%d\n",__LINE__);
6336 mole.symmopsEQIV.clear();
6337 // printf("%d\n",__LINE__);
6338 mole.labelEQIV.clear();
6339 // printf("%d\n",__LINE__);
6340 mole.transEQIV.clear();
6341 // printf("%d\n",__LINE__);
6342 mole.freeatoms.clear();
6343 // printf("%d\n",__LINE__);
6344 mole.bindatoms.clear();
6345 // printf("%d\n",__LINE__);
6346 for (int i=0; i<mole.knoepfe.size();i++) mole.knoepfe[i].neighbors.clear();
6347 mole.knoepfe.clear();
6348 // printf("%d\n",__LINE__);
6349 mole.cell.symmops.clear();
6350 // printf("%d\n",__LINE__);
6351 mole.cell.trans.clear();
6352 // printf("%d\n",__LINE__);
6353 // printf("Close Event survived!! Good bye! Ade! Ciao!\n");
6354 event->accept();
6355 }
6356 else{
6357 event->ignore();
6358 // printf("Close Event survived and Ignored\n");
6359 }
6360 }
6361
6362 void Window::changeScalefactor(){
6363 widthBox->disconnect();
6364 heightBox->disconnect();
6365 scalefBox->disconnect();
6366 widthBox->setValue(int(chgl->width()*scalePic+0.5));
6367 heightBox->setValue(int(chgl->height()*scalePic+0.5));
6368 scalefBox->setValue(scalePic*100.0);
6369 connect(widthBox,SIGNAL(valueChanged(int)),this,SLOT(updateScaleDlg()));
6370 connect(heightBox,SIGNAL(valueChanged(int)),this,SLOT(updateScaleDlg()));
6371 connect(scalefBox,SIGNAL(valueChanged(double)),this,SLOT(updateScaleDlg()));
6372 scalDlg->exec();
6373 }
6374
6375 void Window::updateScaleDlg(){
6376 QObject *o = qobject_cast<QObject *>(sender());
6377 if (o) {
6378 QString name = o->objectName();
6379 widthBox->disconnect();
6380 heightBox->disconnect();
6381 scalefBox->disconnect();
6382 if (name=="scalefBox"){
6383 scalePic=scalefBox->value()*0.01;
6384 widthBox->setValue(int(chgl->width()*scalePic+0.5));
6385 heightBox->setValue(int(chgl->height()*scalePic+0.5));
6386 } else if (name=="widthBox"){
6387 scalePic= (double (widthBox->value() -0.5) / chgl->width()) ;
6388 heightBox->setValue(int(chgl->height()*scalePic+0.5));
6389 scalefBox->setValue(scalePic*100.0);
6390 } else if (name=="heightBox"){
6391 scalePic= (double (heightBox->value() -0.5) / chgl->height()) ;
6392 widthBox->setValue(int(chgl->width()*scalePic+0.5));
6393 scalefBox->setValue(scalePic*100.0);
6394 }
6395 scalDlg->update();
6396
6397 connect(widthBox,SIGNAL(valueChanged(int)),this,SLOT(updateScaleDlg()));
6398 connect(heightBox,SIGNAL(valueChanged(int)),this,SLOT(updateScaleDlg()));
6399 connect(scalefBox,SIGNAL(valueChanged(double)),this,SLOT(updateScaleDlg()));
6400 }
6401 }
6402
6403 void Window::updateSelectResi(){
6404 QStringList l = editor->document()->toPlainText().split('\n');
6405 if (editor->resiFinder == NULL) return;
6406 editor->resiFinder->clear();
6407 editor->resiFinder->addItem("<Select residues>",-1);
6408 for (int i=0; i<l.size();i++){
6409 if ((l.at(i).startsWith("RESI",Qt::CaseInsensitive))&&(!l.at(i).contains(QRegularExpression(" 0\\b"))))
6410 editor->resiFinder->addItem(l.at(i).trimmed(),i);
6411 // if (l.at(i).startsWith("MOLE",Qt::CaseInsensitive))
6412 // resiFinder->addItem(l.at(i).trimmed(),i);
6413 }
6414 int mi=1,ma=-1;
6415 for (int i=0;i<editor->parenthesis2.size();i++){
6416 mi=qMin(editor->parenthesis2.at(i),mi);
6417 ma=qMax(editor->parenthesis2.at(i),ma);
6418 }
6419 spinSelectPart->setMinimum(mi);
6420 spinSelectPart->setMaximum(ma);
6421 }
6422
6423 void Window::selectParts(){
6424 int pt=spinSelectPart->value();
6425 bool b=inculdePartNull->isChecked();
6426 chgl->mol->selectedatoms.clear();
6427 int hidden=0;
6428 if (selectPart->isChecked()){
6429 for (int i=0; i<chgl->mol->showatoms.size();i++){
6430 hidden+=chgl->mol->showatoms.at(i).hidden;
6431 if (chgl->mol->showatoms.at(i).part==pt){
6432 chgl->mol->selectedatoms.append(chgl->mol->showatoms[i]);
6433 chgl->mol->selectedatoms.last().style=i;
6434 }
6435 if ((pt!=0)&&(chgl->mol->showatoms.at(i).part==0)&&b){
6436 chgl->mol->selectedatoms.append(chgl->mol->showatoms[i]);
6437 chgl->mol->selectedatoms.last().style=i;
6438 }
6439 }
6440 }
6441 if (hidden) chgl->hideNonSelected();
6442 chgl->updateBondActions();
6443 chgl->update();
6444 update();
6445 chgl->update();
6446 }
6447
6448 void Window::resiSelectorCheck(){
6449 QTextCursor tc = editor->textCursor();
6450 int l,c=0,rnr=-1;
6451 l=tc.blockNumber();
6452 while ((c<editor->resiFinder->count())&&(l>=(rnr=editor->resiFinder->itemData(c).toInt()))) {c++;}
6453 if (c) editor->resiFinder->setCurrentIndex(c-1);
6454 update();
6455 }
6456
6457 void Window::fuse(){
6458 printf("f\n");
6459 chgl->disSelection();
6460 chgl->mol->fuse();
6461 infoKanalNews(chgl->mol->HumanSymmetry);
6462
6463 chgl->setMolecule(&mole);
6464 chgl->fuse->setVisible(false);
6465 chgl->grow->setVisible(true);
6466 loadMolInTest();
6467
6468 chgl->update();
6469 update();
6470 chgl->update();
6471 }
6472
6473 void Window::uniq(){
6474 if (mole.asymm.isEmpty()) return;
6475
6476 chgl->disSelection();
6477 if ((mole.maxmols()==0)||(quickReLoadButton->isChecked())) sdm();
6478 chgl->mol->uniqueInCell();
6479 infoKanalNews(chgl->mol->HumanSymmetry);
6480 QTextDocument *document = editor->document();
6481 QTextCursor cursor = editor->textCursor();
6482 cursor.beginEditBlock ();
6483
6484 for (int i=0; i<mole.asymm.size();i++){
6485 cursor.movePosition(QTextCursor::Start);
6486 QString label=mole.asymm.at(i).orginalLine.left(80).trimmed();
6487 cursor = document->find(label ,cursor);
6488
6489 if (cursor.isNull()){
6490 cursor = editor->textCursor();
6491 cursor.movePosition(QTextCursor::Start);
6492 label.chop(10);
6493 cursor = document->find(label,cursor);
6494 if (cursor.isNull()) {
6495 cursor = editor->textCursor();
6496 }
6497 }
6498 QString vorherig,neues;
6499 cursor.movePosition(QTextCursor::StartOfLine,QTextCursor::MoveAnchor);
6500 cursor.movePosition(QTextCursor::EndOfLine,QTextCursor::KeepAnchor);
6501 while (cursor.selectedText().endsWith("=")) {
6502 cursor.movePosition(QTextCursor::Down,QTextCursor::KeepAnchor);
6503 cursor.movePosition(QTextCursor::EndOfLine,QTextCursor::KeepAnchor);
6504 }
6505 neues = vorherig= cursor.selectedText();
6506 QStringList sl = vorherig.split(leer);
6507 sl.removeOne("=");
6508 if (sl.size()>=7)
6509 neues=QString("%1 %2 %3 %4 %5 %6 %7 ")
6510 .arg(mole.asymm.at(i).Label.section('_',0,0),-4)
6511 .arg(qMax(1,editor->sfac.indexOf(mole.asymm.at(i).an)+1))
6512 .arg(mole.asymm.at(i).frac.x,10,'f',6)
6513 .arg(mole.asymm.at(i).frac.y,10,'f',6)
6514 .arg(mole.asymm.at(i).frac.z,10,'f',6)
6515 .arg(mole.asymm.at(i).sof_org,9,'f',5)
6516 .arg((mole.asymm.at(i).isIso)?mole.asymm.at(i).ufiso_org:QString("%1").arg(mole.asymm.at(i).uf.m11,9,'f',5));
6517 if (mole.asymm.at(i).an<0) {
6518 neues.append(QString("%1 ")
6519 .arg(mole.asymm.at(i).peakHeight,9,'f',2));
6520 } else
6521 if (!mole.asymm.at(i).isIso){
6522 neues.append(QString("%1 =\n %2 %3 %4 %5")
6523 .arg(mole.asymm.at(i).uf.m22,9,'f',5)
6524 .arg(mole.asymm.at(i).uf.m33,9,'f',5)
6525 .arg(mole.asymm.at(i).uf.m23,9,'f',5)
6526 .arg(mole.asymm.at(i).uf.m13,9,'f',5)
6527 .arg(mole.asymm.at(i).uf.m12,9,'f',5));
6528 }
6529 cursor.deleteChar();
6530 cursor.insertText(neues);
6531 mole.asymm[i].orginalLine=neues.section("=",0,0);
6532
6533 }//i
6534 cursor.endEditBlock ();
6535
6536 grow();
6537
6538 // printf("%d\n",__LINE__);
6539 }
6540
6541 void Window::grow(){
6542 printf("g\n");
6543 chgl->disSelection();
6544 chgl->mol->grow();
6545 infoKanalNews(chgl->mol->HumanSymmetry);
6546
6547 chgl->setMolecule(&mole);
6548 chgl->fuse->setVisible(true);
6549 chgl->grow->setVisible(false);
6550 loadMolInTest();
6551
6552 chgl->update();
6553 update();
6554 chgl->update();
6555 }
6556
6557 void Window::expandAll(){
6558 chgl->disSelection();
6559 chgl->mol->expandAll();
6560 infoKanalNews(chgl->mol->HumanSymmetry);
6561
6562 chgl->setMolecule(&mole);
6563 chgl->fuse->setVisible(true);
6564 chgl->grow->setVisible(false);
6565 loadMolInTest();
6566
6567 chgl->update();
6568 }
6569
6570 void Window::fillCell(){
6571 chgl->disSelection();
6572 chgl->mol->fillCell();
6573 infoKanalNews(chgl->mol->HumanSymmetry);
6574
6575 chgl->setMolecule(&mole);
6576 chgl->fuse->setVisible(true);
6577 chgl->grow->setVisible(false);
6578 loadMolInTest();
6579
6580 chgl->update();
6581 }
6582
6583 void Window::packInLimits(){
6584 QDialog *boxpack= new QDialog(this);
6585 QDoubleSpinBox
6586 *aminlim,*amaxlim,
6587 *bminlim,*bmaxlim,
6588 *cminlim,*cmaxlim;
6589 aminlim = new QDoubleSpinBox(boxpack);
6590 amaxlim = new QDoubleSpinBox(boxpack);
6591 bminlim = new QDoubleSpinBox(boxpack);
6592 bmaxlim = new QDoubleSpinBox(boxpack);
6593 cminlim = new QDoubleSpinBox(boxpack);
6594 cmaxlim = new QDoubleSpinBox(boxpack);
6595 aminlim->setMinimum(-10.0);
6596 amaxlim->setMinimum(0.0);
6597 bminlim->setMinimum(-10.0);
6598 bmaxlim->setMinimum(0.0);
6599 cminlim->setMinimum(-10.0);
6600 cmaxlim->setMinimum(0.0);
6601 aminlim->setMaximum(1.0);
6602 amaxlim->setMaximum(10.0);
6603 bminlim->setMaximum(1.0);
6604 bmaxlim->setMaximum(10.0);
6605 cminlim->setMaximum(1.0);
6606 cmaxlim->setMaximum(10.0);
6607 aminlim->setValue(0.0);
6608 amaxlim->setValue(1.0);
6609 bminlim->setValue(0.0);
6610 bmaxlim->setValue(1.0);
6611 cminlim->setValue(0.0);
6612 cmaxlim->setValue(1.0);
6613 QDialogButtonBox *buttonBox = new QDialogButtonBox( QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
6614 connect(buttonBox, SIGNAL(rejected()), boxpack, SLOT(reject()));
6615 connect(buttonBox, SIGNAL(accepted()), boxpack, SLOT(accept()));
6616 QGridLayout *g = new QGridLayout(boxpack);
6617 g->addWidget(new QLabel("pack range along a "),0,0);
6618 g->addWidget(aminlim,1,0);
6619 g->addWidget(amaxlim,2,0);
6620 g->addWidget(new QLabel("pack range along b "),0,1);
6621 g->addWidget(bminlim,1,1);
6622 g->addWidget(bmaxlim,2,1);
6623 g->addWidget(new QLabel("pack range along c "),0,2);
6624 g->addWidget(cminlim,1,2);
6625 g->addWidget(cmaxlim,2,2);
6626 g->addWidget(buttonBox,10,0,1,3);
6627 if (QDialog::Accepted==boxpack->exec()){
6628 chgl->disSelection();
6629 chgl->mol->showatoms.clear();
6630 chgl->mol->packInLimits(aminlim->value(),amaxlim->value(),bminlim->value(),bmaxlim->value(),cminlim->value(),cmaxlim->value());
6631 chgl->setMolecule(&mole);
6632 chgl->fuse->setVisible(true);
6633 chgl->grow->setVisible(false);
6634 loadMolInTest();
6635
6636 chgl->update();
6637 }
6638
6639 }
6640
6641 void Window::grow_plus(){
6642 printf("grow_plus?\n");
6643 chgl->disSelection();
6644 chgl->mol->grow_plus();
6645 infoKanalNews(chgl->mol->HumanSymmetry);
6646 loadMolInTest();
6647 chgl->setMolecule(&mole);
6648 chgl->fuse->setVisible(true);
6649 chgl->grow->setVisible(false);
6650
6651 chgl->update();
6652 }
6653
6654 void Window::complete(){
6655 printf("Complete?\n");
6656 chgl->disSelection();
6657 chgl->mol->complete();
6658 infoKanalNews(chgl->mol->HumanSymmetry);
6659 loadMolInTest();
6660 chgl->setMolecule(&mole);
6661 chgl->fuse->setVisible(true);
6662 chgl->grow->setVisible(false);
6663
6664 chgl->update();
6665 }
6666 struct Dtocom{//distance to center of mass
6667 int idx;
6668 double d;
6669 };
6670
6671 inline bool operator < (const Dtocom &d1, const Dtocom &d2) {return (d1.d<d2.d);};
6672
6673 void Window::inheritLabels(){
6674 return;
6675 /*
6676 QList <int> imapperA,imapperB, istfalsch,istsuper;
6677
6678 QAction *action = qobject_cast<QAction *>(sender());
6679 QList<int> index;
6680 if (action){
6681 //printf("inher it\n");
6682 index = chgl->lastClicked();
6683 }
6684 else return;
6685 if (index.size()<2) return;
6686 // *
6687 CEnvironment molecule[2];
6688 QList<Dtocom> dc[2];
6689 int nn=0, ne=0;
6690 //printf("asymmetric unit size: %d\n",mole.asymm.size());
6691 //printf("%d(%d) %d(%d)\n",mole.asymm.at(index.at(0)).molindex,index.at(0),mole.asymm.at(index.at(1)).molindex,index.at(1));
6692 //qDebug()<<index;
6693 V3 middle[2];
6694 middle[0]=V3(0.,0.,0.);
6695 middle[1]=V3(0.,0.,0.);
6696 // QList<SdmItem> sdms[2];
6697 Matrix amat[2];
6698 amat[0]=Matrix(1.,0.,0., 0.,1.,0., 0.,0.,1.);
6699 amat[1]=Matrix(1.,0.,0., 0.,1.,0., 0.,0.,1.);
6700 for (int j =0; j < mole.showatoms.size(); j++){
6701 mole.showatoms[j].hidden=1;
6702 if ((mole.asymm.at(index.at(0)).molindex == mole.showatoms.at(j).molindex)||
6703 (mole.asymm.at(index.at(1)).molindex == mole.showatoms.at(j).molindex)){
6704 mole.showatoms[j].hidden=0;
6705 }
6706 }
6707 for (int i =0; i < 2; i++){
6708 for (int j =0; j < mole.asymm.size(); j++){
6709 if (mole.asymm.at(index.at(i)).molindex == mole.asymm.at(j).molindex) {
6710 molecule[i].append(mole.asymm[j]);
6711 molecule[i].last().scod = j;
6712 molecule[i].last().sg = i;
6713 middle[i]+=mole.asymm.at(j).pos;
6714 }
6715 }
6716 middle[i]*=1.0/molecule[i].size();
6717 //sdms[i] = mole.computeSDM(molecule[i]);
6718 for (int j = 0; j < molecule[i].size(); j++){
6719 Dtocom cc;
6720 cc.idx=j;
6721 cc.d=Distance(molecule[i].at(j).pos, middle[i]);
6722 dc[i].append(cc);
6723 }
6724 #if (QT_VERSION >= 0x050000)
6725 std::sort(dc[i].begin(),dc[i].end());
6726 #else
6727 qSort(dc[i].begin(),dc[i].end());
6728 #endif
6729
6730 for (int n0=0; n0<dc[i].size(); n0++){
6731 printf("distance to center of mass %s %f\n",molecule[i][dc[i].at(n0).idx].Label.toStdString().c_str(),sqrt(dc[i].at(n0).d));
6732 }
6733
6734 nn=0;
6735 ne=dc[i].size();
6736 V3 a1,a2,a3;
6737 do{
6738 a1=Normalize(middle[i]-molecule[i].at(dc[i].at((nn+1)%ne).idx).pos);//a1=(A-B)/|A-B|
6739 a2=Normalize(middle[i]-molecule[i].at(dc[i].at((nn)%ne).idx).pos);//a2=(A-C)/|A-B|
6740 a3=Normalize(a1%a2);//a3=(a1 x a2)/(a1 x a2)
6741 a2=a3%a1;//a2 = a3 x a1
6742 printf("Determinant of fit matrix%d %g %f %f %d %d %d\n",i, a1*(a2%a3), sqrt(dc[i].at(nn%ne).d), sqrt(dc[i].at((nn+1)%ne).d) ,nn%ne,(nn+1)%ne,ne);
6743 nn++;
6744 } while((a1*(a2%a3))<0.9);
6745 amat[i]=(i==0)?transponse(Matrix(a1,a2,a3)):Matrix(a1,a2,a3);
6746
6747
6748 }
6749
6750 if (molecule[0].size()!=molecule[1].size()) {
6751 QMessageBox::information(0,"information",QString("The Number of atoms in the two molecules is not the same. This program can not help here, sorry! %1 %2")
6752 .arg(molecule[0].size()).arg(molecule[1].size()));
6753 return;
6754 }
6755
6756 for (int j = 0; j < molecule[0].size(); j++){
6757 //molecule[0][j].pos+=-1.0*middle[0];
6758 molecule[0][j].style=0;
6759 molecule[0][j].frac=(((molecule[0][j].pos-(1.0*middle[0]))*amat[1])*amat[0])+middle[1];
6760 printf("#%-5d %f %f %f %s\n %f %f %f %s\n",j
6761 ,molecule[0][j].frac.x, molecule[0][j].frac.y, molecule[0][j].frac.z, molecule[0][j].Label.toStdString().c_str()
6762 ,molecule[1][j].pos.x, molecule[1][j].pos.y, molecule[1][j].pos.z, molecule[1][j].Label.toStdString().c_str()
6763 );// * /
6764 }
6765 double dmd=0.0,dmdmin=1e37;
6766 int ia1min=0,ia2min=0;
6767
6768 //middle[0]=middle[1];
6769 for (int n0=0; n0<dc[0].size(); n0++){
6770 printf("I. distance to center of mass %s %f\n",molecule[0][dc[0].at(n0).idx].Label.toStdString().c_str()
6771 ,sqrt(Distance(molecule[0][dc[0].at(n0).idx].frac,middle[0])));
6772 printf("II. distance to center of mass %s %f\n",molecule[1][dc[1].at(n0).idx].Label.toStdString().c_str()
6773 ,sqrt(Distance(molecule[1][dc[1].at(n0).idx].pos,middle[1])));
6774 }
6775 for (int ia1=0; ia1<ne; ia1++){
6776 for (int ia2=0; ia2<ne; ia2++){
6777 if (ia1==ia2) continue;
6778 V3 a1,a2,a3;
6779 a1=Normalize(middle[0]-molecule[0].at(dc[0].at(ia1).idx).pos);//a1=(A-B)/|A-B|
6780 a2=Normalize(middle[0]-molecule[0].at(dc[0].at(ia2).idx).pos);//a2=(A-C)/|A-B|
6781 a3=Normalize(a1%a2);//a3=(a1 x a2)/(a1 x a2)
6782 a2=a3%a1;//a2 = a3 x a1
6783 printf("_Determinant of fit matrix0 %g %f %f %d %d %d\n", a1*(a2%a3), sqrt(dc[0].at(ia1).d), sqrt(dc[0].at(ia2).d), ia1, ia2,ne);
6784
6785 amat[0]=transponse(Matrix(a1,a2,a3));
6786 for (int j = 0; j < molecule[0].size(); j++){
6787 //molecule[0][j].pos+=-1.0*middle[0];
6788 molecule[0][j].style=0;
6789 molecule[0][j].frac=(((molecule[0][j].pos-(1.0*middle[0]))*amat[1])*amat[0])+middle[1];
6790 //printf("#%-5d %f %f %f %s\n %f %f %f %s\n",j
6791 // ,molecule[0][j].pos.x,molecule[0][j].pos.y,molecule[0][j].pos.z,molecule[0][j].Label.toStdString().c_str()
6792 // ,molecule[1][j].pos.x,molecule[1][j].pos.y,molecule[1][j].pos.z,molecule[1][j].Label.toStdString().c_str()
6793 // );
6794 }
6795 //mole.selectedatoms.append(xd);
6796 dmd=0.0;
6797 for (int i = 0; i < molecule[1].size(); i++){
6798 double dm = 1.0e35;
6799 int k=0;
6800 for (int j = 0; j < molecule[0].size(); j++){
6801 if (molecule[0][j].style!=0) continue;
6802 double d = Distance(molecule[0].at(i).frac, molecule[1].at(j).pos);
6803 if (d<dm){
6804 k=j;
6805 dm=d;
6806 }
6807 }
6808 molecule[0][k].style=1;
6809 dmd+=dm;
6810 }
6811 dmd/=molecule[0].size();
6812 if (dmd<dmdmin){
6813 dmdmin=dmd;
6814 ia1min=ia1;
6815 ia2min=ia2;
6816 }
6817 //printf("##### %f #### %f\n",dmd,dmdmin);
6818
6819 }
6820 }
6821 {
6822 V3 a1,a2,a3;
6823 a1=Normalize(middle[0]-molecule[0].at(dc[0].at(ia1min).idx).pos);//a1=(A-B)/|A-B|
6824 a2=Normalize(middle[0]-molecule[0].at(dc[0].at(ia2min).idx).pos);//a2=(A-C)/|A-B|
6825 a3=Normalize(a1%a2);//a3=(a1 x a2)/(a1 x a2)
6826 a2=a3%a1;//a2 = a3 x a1
6827 printf("_Determinant of fit final matrix0 %g %f %f %d %d %d\n", a1*(a2%a3), sqrt(dc[0].at(ia1min).d), sqrt(dc[0].at(ia2min).d), ia1min, ia2min,ne);
6828
6829 amat[0]=transponse(Matrix(a1,a2,a3));
6830
6831 for (int j = 0; j < molecule[0].size(); j++){
6832 //molecule[0][j].pos+=-1.0*middle[0];
6833 molecule[0][j].style=0;
6834 molecule[0][j].pos=(((molecule[0][j].pos-(1.0*middle[0]))*amat[1])*amat[0])+middle[1];
6835 printf("#%-5d %f %f %f %s\n %f %f %f %s\n",j
6836 ,molecule[0][j].pos.x,molecule[0][j].pos.y,molecule[0][j].pos.z,molecule[0][j].Label.toStdString().c_str()
6837 ,molecule[1][j].pos.x,molecule[1][j].pos.y,molecule[1][j].pos.z,molecule[1][j].Label.toStdString().c_str()
6838 );// * /
6839 }
6840 dmd=0.0;
6841 for (int i = 0; i < molecule[1].size(); i++){
6842 double dm = 100.0;
6843 int k=0;
6844 for (int j = 0; j < molecule[0].size(); j++){
6845 if (molecule[0][j].style!=0) continue;
6846 double d = Distance(molecule[0].at(i).pos, molecule[1].at(j).pos);
6847 if (d<dm){
6848 k=j;
6849 dm=d;
6850 }
6851 }
6852 molecule[0][k].style=1;
6853 printf("%s -> %s %f %f %f\n"
6854 ,molecule[0][i].Label.toStdString().c_str()
6855 ,molecule[1][k].Label.toStdString().c_str()
6856 ,sqrt(dm)
6857 ,sqrt(Distance(molecule[0].at(i).pos, middle[0]))
6858 ,sqrt(Distance(molecule[1].at(k).pos, middle[1]))
6859 );
6860 dmd+=dm;
6861 imapperA.append(molecule[1][k].scod);
6862 imapperB.append(molecule[0][i].scod);
6863 }
6864 dmd/=molecule[0].size();
6865 //printf("##### %f ####\n",dmd);
6866 }
6867
6868 chgl->setRotationCenter(middle[1]);
6869 mole.fitatoms.clear();
6870 MyAtom m;
6871 m.an=-42;
6872 m.pos=middle[1];
6873 m.Label="com";
6874
6875 m.part=0;
6876 m.resiNr=0;
6877 m.hidden=0;
6878 m.symmGroup=0;
6879 m.sg=0;
6880 m.scod=555;//the identity
6881 m.sof=0;
6882 m.sof_org=0;
6883 m.screenX=0;
6884 m.screenY=0;
6885 m.afix=0;
6886 mole.fitatoms.append(molecule[1]);
6887 mole.fitatoms.append(molecule[0]);
6888 mole.fitatoms.append(m);
6889
6890 // printf("%d\n",mole.fitatoms.size());
6891 Connection abond,bbond;
6892 abond = mole.connecting(molecule[1],true);
6893 mole.fitbonds = mole.connecting(molecule[0],true);
6894 mole.fitbonds.append(abond);
6895
6896 // chgl->pairing(imapperA,imapperB);
6897
6898 chgl->update();
6899
6900
6901
6902 DragDropAtomsDialog *ddad = new DragDropAtomsDialog(chgl, mole, imapperA, &imapperB,this);
6903 connect(ddad,SIGNAL(pairs(const QString&)),chgl,SLOT(selectPair(const QString&)));
6904 ddad->resiFinder=editor->resiFinder;
6905 //ddad->show();
6906
6907 molecule[0].clear();
6908 molecule[1].clear();
6909 imapperA.clear();
6910 imapperB.clear();
6911 mole.fitatoms.clear();
6912 mole.fitbonds.clear();
6913 mole.showbonds.clear();
6914 mole.showbonds=mole.connecting(mole.showatoms);
6915 chgl->rotCenter();
6916 chgl->rCenter->hide();
6917 chgl->showHidden();
6918 //sdms[0].clear();
6919 //sdms[1].clear();
6920 delete ddad;
6921 // */
6922 }
6923
6924 void Window::obj(){
6925 mole.exportOBJ(dirName,mole.showatoms,mole.showbonds);
6926 }
6927
6928 void Window::sina(){//anis rueckrwaerts
6929 if (mole.asymm.isEmpty()) return;
6930 if (chgl->mol->selectedatoms.isEmpty()) {
6931 QAction *action = qobject_cast<QAction *>(sender());
6932 int index=-1;
6933 if (action)
6934 index=action->data().toInt();
6935 else index=-1;
6936 if (index>mole.asymm.size()) index=-1;
6937 if (index!=-1) {
6938 chgl->mol->selectedatoms.clear();
6939 chgl->mol->selectedatoms.append(chgl->mol->showatoms[index]);
6940 chgl->mol->selectedatoms.last().style=index;
6941 }
6942 }
6943 QTextDocument *document = editor->document();
6944 QTextCursor cursor = editor->textCursor();
6945 if (chgl->mol->selectedatoms.isEmpty()){
6946 double uEQ;
6947 cursor.beginEditBlock();
6948 for (int i=0; i<mole.asymm.size(); i++){
6949 if (!mole.asymm.at(i).isIso){
6950 uEQ=0.05;//mole.ueq(mole.asymm.at(i).uf);
6951 mole.asymm[i].uf.m11=
6952 mole.asymm[i].uf.m22=
6953 mole.asymm[i].uf.m33=
6954 mole.asymm[i].uc.m11=
6955 mole.asymm[i].uc.m22=
6956 mole.asymm[i].uc.m33=uEQ;
6957 mole.asymm[i].isIso=true;
6958 mole.asymm[i].uf.m12 = mole.asymm[i].uf.m21 = uEQ * mole.cell.cosrg;
6959 mole.asymm[i].uf.m13 = mole.asymm[i].uf.m31 = uEQ * mole.cell.cosrb;
6960 mole.asymm[i].uf.m23 = mole.asymm[i].uf.m32 = uEQ * mole.cell.cosra;
6961 mole.asymm[i].uc.m21=
6962 mole.asymm[i].uc.m12=
6963 mole.asymm[i].uc.m13=
6964 mole.asymm[i].uc.m31=
6965 mole.asymm[i].uc.m32=
6966 mole.asymm[i].uc.m23=0.0;
6967 QString label = mole.asymm.at(i).orginalLine.left(80).trimmed();
6968 cursor.movePosition(QTextCursor::Start);
6969 cursor = document->find(label,cursor);
6970 if (cursor.isNull()){
6971 cursor = editor->textCursor();
6972 cursor.movePosition(QTextCursor::Start);
6973 label.chop(10);
6974 cursor = document->find(label,cursor);
6975 if (cursor.isNull()) {
6976 cursor = editor->textCursor();
6977 printf("hab was nicht %d %s\n",i,label.toStdString().c_str());
6978 continue;
6979 }
6980 }
6981 cursor.movePosition(QTextCursor::StartOfLine,QTextCursor::MoveAnchor);
6982 cursor.movePosition(QTextCursor::EndOfLine,QTextCursor::KeepAnchor);
6983 while (cursor.selectedText().endsWith("=")) {
6984 cursor.movePosition(QTextCursor::Down,QTextCursor::KeepAnchor);
6985 cursor.movePosition(QTextCursor::EndOfLine,QTextCursor::KeepAnchor);
6986 }
6987 cursor.deleteChar();
6988 mole.asymm[i].orginalLine=
6989 QString("%1 %2 %3 %4 %5 %6 %7")
6990 .arg(mole.asymm.at(i).Label.section('_',0,0),-4)
6991 .arg(qMax(1,editor->sfac.indexOf(mole.asymm.at(i).an)+1))
6992 .arg(mole.asymm.at(i).frac.x,9,'f',5)
6993 .arg(mole.asymm.at(i).frac.y,9,'f',5)
6994 .arg(mole.asymm.at(i).frac.z,9,'f',5)
6995 .arg(mole.asymm.at(i).sof_org,9,'f',5)
6996 .arg(mole.asymm.at(i).uf.m11,9,'f',5);
6997 cursor.insertText(mole.asymm[i].orginalLine);
6998 QString s =
6999 QString("<font color=blue>Isotropyfied atom: %1 part:%2 residue:%3 %4 </font> Please save to update structure view.")
7000 .arg(mole.asymm.at(i).Label)
7001 .arg(mole.asymm.at(i).part)
7002 .arg(mole.asymm.at(i).resiNr)
7003 .arg(mole.asymm.at(i).ResiClass);
7004 infoKanalNews(s);
7005 }
7006 }
7007 cursor.endEditBlock();
7008 mole.showatoms.clear();
7009 mole.showbonds.clear();
7010 chgl->mol->showatoms.clear();
7011 chgl->mol->showbonds.clear();
7012 chgl->mol->selectedatoms.clear();
7013 for (int o=0; o<mole.asymm.size();o++)
7014 mole.showatoms.append(mole.asymm[o]);
7015 mole.showbonds =
7016 mole.connecting(mole.showatoms);
7017 chgl->mol->selectedatoms.clear();
7018
7019 bool growYes=chgl->fuse->isVisible ();
7020 chgl->mol->fuse();
7021 if (growYes) chgl->mol->grow();
7022
7023
7024 // printf("%d\n",__LINE__);
7025
7026 loadMolInTest();
7027 chgl->updateBondActions();
7028 chgl->update();
7029 update();
7030 chgl->update();
7031 }
7032 else
7033 {
7034 double uEQ;
7035 cursor.beginEditBlock();
7036 for (int j=0; j<mole.selectedatoms.size(); j++){
7037 int i=mole.selectedatoms.at(j).style;
7038 if ((i>=mole.asymm.size())||(i<0)) continue;
7039 if (!mole.asymm.at(i).isIso){
7040 uEQ=0.05;//mole.ueq(mole.asymm.at(i).uf);
7041 mole.asymm[i].uf.m11=
7042 mole.asymm[i].uf.m22=
7043 mole.asymm[i].uf.m33=
7044 mole.asymm[i].uc.m11=
7045 mole.asymm[i].uc.m22=
7046 mole.asymm[i].uc.m33=uEQ;
7047 mole.asymm[i].isIso=true;
7048 mole.asymm[i].uf.m12 = mole.asymm[i].uf.m21 = uEQ * mole.cell.cosrg;
7049 mole.asymm[i].uf.m13 = mole.asymm[i].uf.m31 = uEQ * mole.cell.cosrb;
7050 mole.asymm[i].uf.m23 = mole.asymm[i].uf.m32 = uEQ * mole.cell.cosra;
7051 mole.asymm[i].uc.m21=
7052 mole.asymm[i].uc.m12=
7053 mole.asymm[i].uc.m13=
7054 mole.asymm[i].uc.m31=
7055 mole.asymm[i].uc.m32=
7056 mole.asymm[i].uc.m23=0.0;
7057 QString label = mole.asymm.at(i).orginalLine.left(80).trimmed();
7058 cursor.movePosition(QTextCursor::Start);
7059 cursor = document->find(label,cursor);
7060 if (cursor.isNull()){
7061 cursor = editor->textCursor();
7062 cursor.movePosition(QTextCursor::Start);
7063 label.chop(10);
7064 cursor = document->find(label,cursor);
7065 if (cursor.isNull()) {
7066 cursor = editor->textCursor();
7067 printf("hab was nicht %d %s\n",i,label.toStdString().c_str());
7068 continue;
7069 }
7070 }
7071 cursor.movePosition(QTextCursor::StartOfLine,QTextCursor::MoveAnchor);
7072 cursor.movePosition(QTextCursor::EndOfLine,QTextCursor::KeepAnchor);
7073 while (cursor.selectedText().endsWith("=")) {
7074 cursor.movePosition(QTextCursor::Down,QTextCursor::KeepAnchor);
7075 cursor.movePosition(QTextCursor::EndOfLine,QTextCursor::KeepAnchor);
7076 }
7077 cursor.deleteChar();
7078 mole.asymm[i].orginalLine=
7079 QString("%1 %2 %3 %4 %5 %6 %7")
7080 .arg(mole.asymm.at(i).Label.section('_',0,0),-4)
7081 .arg(qMax(1,editor->sfac.indexOf(mole.asymm.at(i).an)+1))
7082 .arg(mole.asymm.at(i).frac.x,9,'f',5)
7083 .arg(mole.asymm.at(i).frac.y,9,'f',5)
7084 .arg(mole.asymm.at(i).frac.z,9,'f',5)
7085 .arg(mole.asymm.at(i).sof_org,9,'f',5)
7086 .arg(mole.asymm.at(i).uf.m11,9,'f',5);
7087 cursor.insertText(mole.asymm[i].orginalLine);
7088 QString s =
7089 QString("<font color=blue>Isotropyfied atom: %1 part:%2 residue:%3 %4 </font> Please save to update structure view.")
7090 .arg(mole.asymm.at(i).Label)
7091 .arg(mole.asymm.at(i).part)
7092 .arg(mole.asymm.at(i).resiNr)
7093 .arg(mole.asymm.at(i).ResiClass);
7094 infoKanalNews(s);
7095 }
7096 }
7097 cursor.endEditBlock();
7098 mole.showatoms.clear();
7099 mole.showbonds.clear();
7100 chgl->mol->showatoms.clear();
7101 chgl->mol->showbonds.clear();
7102 chgl->mol->selectedatoms.clear();
7103 for (int o=0; o<mole.asymm.size();o++)
7104 mole.showatoms.append(mole.asymm[o]);
7105 mole.sdmcompleter();
7106 mole.showbonds =
7107 mole.connecting(mole.showatoms);
7108 chgl->mol->selectedatoms.clear();
7109
7110 bool growYes=chgl->fuse->isVisible ();
7111 chgl->mol->fuse();
7112 if (growYes) chgl->mol->grow();
7113
7114
7115 // printf("%d\n",__LINE__);
7116
7117 loadMolInTest();
7118 chgl->updateBondActions();
7119 chgl->update();
7120 update();
7121 chgl->update();
7122
7123 }
7124 }
7125
7126 void Window::autoHFix(){
7127 if (mole.asymm.isEmpty()) return;
7128 int warmal=mole.asymm.size();
7129 int warmalAtome=0;
7130 for (int i=0; i<mole.asymm.size();i++) if (mole.asymm.at(i).an>=0)warmalAtome++;
7131 QStringList alab;
7132 for (int i =0; i<mole.asymm.size(); i++){
7133 alab.append(mole.asymm.at(i).Label);
7134 }
7135 QString nn;
7136 chgl->disSelection();
7137 chgl->mol->grow();
7138
7139 MyAtom htest,qtest;
7140
7141 double xh[8]={
7142 0.98,//1
7143 0.97,//2
7144 0.96,//3
7145 0.93,//4
7146 1.10,//15 B
7147 0.82,//8 O
7148 0.93,//9
7149 0.93// 16
7150 };
7151
7152 if (editor->sfac.indexOf(0)==-1)addNewScatteringFactor(0,false);
7153 htest.an=0;
7154 htest.part=0;
7155 htest.resiNr=0;
7156 htest.hidden=0;
7157 htest.symmGroup=0;
7158 htest.sg=0;
7159 htest.scod=555;//the identity
7160 htest.auidx=-1;
7161 htest.uc.m12=htest.uc.m23=htest.uc.m13=0.0;
7162 htest.uc.m21=htest.uc.m32=htest.uc.m31=0.0;
7163 htest.uf.m12=htest.uf.m23=htest.uf.m13=0.0;
7164 htest.uf.m21=htest.uf.m32=htest.uf.m31=0.0;
7165 qtest=htest;
7166 qtest.an=-1;
7167 QTextDocument *document = editor->document();
7168 QTextCursor cursor = editor->textCursor();
7169 cursor.beginEditBlock ();
7170 QMap<int,int> keinDonor;
7171 QMap<int,int> istDonor;
7172 for (int j=0;j<mole.contact.size();j++){
7173 double ch1,ch2;
7174 if (mole.knoepfe.at(mole.contact.at(j).a1).neighbors.size()==0) keinDonor[mole.contact.at(j).a1]++;
7175 if (mole.knoepfe.at(mole.contact.at(j).a2).neighbors.size()==0) keinDonor[mole.contact.at(j).a2]++;
7176 if ((mole.asymm.at(mole.contact.at(j).a1).an==7)&&(mole.knoepfe.at(mole.contact.at(j).a1).neighbors.size()>1)) keinDonor[mole.contact.at(j).a1]++;
7177 if ((mole.asymm.at(mole.contact.at(j).a2).an==7)&&(mole.knoepfe.at(mole.contact.at(j).a2).neighbors.size()>1)) keinDonor[mole.contact.at(j).a2]++;
7178 if ((mole.contact.at(j).covalent)){//
7179 ch1=ch2=0;
7180
7181 for (int k=0; k<mole.knoepfe.at(mole.contact.at(j).a1).neighbors.size(); k++){
7182 ch1 += sqrt(Distance(mole.asymm.at(mole.contact.at(j).a1).pos,
7183 mole.showatoms.at(mole.knoepfe.at(mole.contact.at(j).a1).neighbors.at(k)).pos))-
7184 ((mole.Kovalenz_Radien[mole.asymm.at(mole.contact.at(j).a1).an]+
7185 mole.Kovalenz_Radien[mole.showatoms.at(mole.knoepfe.at(mole.contact.at(j).a1).neighbors.at(k)).an])*0.0095);
7186
7187 }
7188 if (mole.knoepfe.at(mole.contact.at(j).a1).neighbors.size())
7189 ch1*=1.0/mole.knoepfe.at(mole.contact.at(j).a1).neighbors.size();
7190
7191 for (int k=0; k<mole.knoepfe.at(mole.contact.at(j).a2).neighbors.size(); k++){
7192 ch2 += sqrt(Distance(mole.asymm.at(mole.contact.at(j).a2).pos,
7193 mole.showatoms.at(mole.knoepfe.at(mole.contact.at(j).a2).neighbors.at(k)).pos))-
7194 ((mole.Kovalenz_Radien[mole.asymm.at(mole.contact.at(j).a2).an]+
7195 mole.Kovalenz_Radien[mole.showatoms.at(mole.knoepfe.at(mole.contact.at(j).a2).neighbors.at(k)).an])*0.0095);
7196 }
7197 if (mole.knoepfe.at(mole.contact.at(j).a2).neighbors.size())
7198 ch2*=1.0/mole.knoepfe.at(mole.contact.at(j).a2).neighbors.size();
7199 /*printf("%s %s %d %d %g %g\n"
7200 ,mole.asymm.at(mole.contact.at(j).a1).Label.toStdString().c_str()
7201 ,mole.asymm.at(mole.contact.at(j).a2).Label.toStdString().c_str(),
7202 ((ch1-0.01)>ch2),((ch2-0.01)>ch1),ch1,ch2
7203 );*/
7204 if (ch1<-0.2 ) keinDonor[mole.contact.at(j).a1]++;
7205 if (ch2<-0.2 ) keinDonor[mole.contact.at(j).a2]++;
7206 if ((ch1-0.01)>ch2) istDonor[mole.contact.at(j).a1]++;
7207 if ((ch2-0.01)>ch1) istDonor[mole.contact.at(j).a2]++;
7208 }
7209 }
7210 for (int i =0; i<mole.asymm.size(); i++){
7211 if ((mole.asymm.at(i).an==5)||(mole.asymm.at(i).an==6)){
7212 double nh= (mole.asymm.at(i).an==6) ? 0.07 : 0;
7213 if (mole.is2Dissordered4H(mole.asymm.at(i))) continue;
7214 double plan=1.0;
7215 if (mole.knoepfe.at(i).neighbors.size()==1) {
7216 if ((mole.asymm.at(i).an==6)&&(!istDonor.contains(i))) {
7217 printf("%s is probably no donor \n",mole.asymm.at(i).Label.toStdString().c_str());
7218 continue;
7219 }
7220 V3 v=V3(0,0,0),w=V3(0,0,0),u=V3(0,0,0) ,a=V3(0,0,0);//,b=V3(0,0,0),c=V3(0,0,0);
7221 a = mole.showatoms.at(mole.knoepfe.at(i).neighbors.at(0)).pos - mole.asymm.at(i).pos;
7222 //printf("A = %s-%s %g %g %g\n",mole.showatoms.at(mole.knoepfe.at(i).neighbors.at(0)).Label.toStdString().c_str(),mole.asymm.at(i).Label.toStdString().c_str(),a.x,a.y,a.z);
7223 double chi = sqrt(Norm(a))-((mole.Kovalenz_Radien[mole.showatoms.at(mole.knoepfe.at(i).neighbors.at(0)).an]+mole.Kovalenz_Radien[mole.asymm.at(i).an])/100.0);
7224 if (chi>-0.09) {//afix 137 127
7225 int j,k,l;
7226 a=Normalize(a);
7227 double jx,kx,lx,mx,my,mz;
7228 double val[24],merg[8],wink=0,t=0,mt=0;
7229 for (int z=0; z<8;z++) merg[z]=0;
7230 if (fxle->n5){
7231 for (int z=0; z<24; z++){
7232 if ((a==V3(0,0,-1))||(a==V3(0,0,1))) {
7233 w=Normalize(V3(1,1,1)%a);
7234 } else {
7235 w=Normalize(V3(0,0,1)%a);
7236 }
7237 //printf("w= %g %g %g\n",w.x,w.y,w.z);
7238 u=Normalize(w%a);
7239 v=(-(xh[2]-nh)*0.33333*a)+ mole.asymm.at(i).pos+(xh[2]-nh)*0.942809041582*(sin(wink)*u+cos(wink)*w);
7240 qtest.pos=v;
7241 mole.kart2frac(v,v);
7242 int zplu=0;
7243 do {
7244 jx=((zplu+v.x)*fxle->n1+0.5);
7245 zplu++;
7246 }while (jx<0);
7247 zplu=0;
7248 do {
7249 kx=((zplu+v.y)*fxle->n2+0.5);
7250 zplu++;
7251 }while (kx<0);
7252 zplu=0;
7253 do {
7254 lx=((zplu+v.z)*fxle->n3+0.5);
7255 zplu++;
7256 }while (lx<0);
7257 mx=jx-floor(jx);
7258 my=kx-floor(kx);
7259 mz=lx-floor(lx);
7260 j=((int)jx)%fxle->n1;//
7261 k=((int)kx)%fxle->n2;//
7262 l=((int)lx)%fxle->n3;//
7263 merg[z%8]+=val[z]=(
7264 (1-mx)*fxle->datfo_fc[(j+fxle->n1*(k+l*fxle->n2))%fxle->n5]+
7265 mx*fxle->datfo_fc[((j+1)+fxle->n1*(k+l*fxle->n2))%fxle->n5]+
7266 (1-my)*fxle->datfo_fc[(j+fxle->n1*(k+l*fxle->n2))%fxle->n5]+
7267 my*fxle->datfo_fc[(j+fxle->n1*((k+1)+l*fxle->n2))%fxle->n5]+
7268 (1-mz)*fxle->datfo_fc[(j+fxle->n1*(k+l*fxle->n2))%fxle->n5]+
7269 mz*fxle->datfo_fc[(j+fxle->n1*(k+(l+1)*fxle->n2))%fxle->n5])/3.0;
7270 qtest.peakHeight=val[z];
7271 qtest.frac=v;
7272 qtest.Label=QString("Q%1#").arg(z,-2);
7273 mole.pmin=qMin(mole.pmin, qtest.peakHeight);
7274 mole.pmax=qMax(mole.pmax, qtest.peakHeight);
7275 qpv->cutoff=0;//mole.pmin;
7276 qpv->setMin(mole.pmin);
7277 qpv->setMax(mole.pmax);
7278 mole.asymm.append(qtest);
7279 wink+=0.261799387799;
7280 }
7281 for (int z=0; z<8;z++) {
7282 t =merg[(z+8)%8] ;
7283 double x = t - merg[(z+9)%8];
7284 double u = t - merg[(z+7)%8];
7285 if (fmin(x,u)<0) continue;
7286 double p=0.5*(u-x)/(u+x);
7287 t=t+0.25*(p*(u-x));
7288 mt=(mt>t)?mt:t;
7289 if (t<mt)continue;
7290 wink=((double) z + p )*0.261799387799;
7291 }
7292 } else {
7293 int zzz=0;
7294 int z=mole.knoepfe.at(mole.knoepfe.at(i).neighbors.at(0)).neighbors.at(zzz++);
7295 while ((z==i)&&(zzz<mole.knoepfe.at(mole.knoepfe.at(i).neighbors.at(0)).neighbors.size())) {
7296 z=mole.knoepfe.at(mole.knoepfe.at(i).neighbors.at(0)).neighbors.at(zzz++);
7297 }
7298 if ((a==V3(0,0,-1))||(a==V3(0,0,1))) {
7299 w=Normalize(V3(1,1,1)%a);
7300 } else {
7301 w=Normalize(V3(0,0,1)%a);
7302 }
7303 u=Normalize(w%a);
7304 v=(-(xh[2]-nh)*0.33333*a)+ mole.asymm.at(i).pos+(xh[2]-nh)*0.942809041582*(sin(wink)*u+cos(wink)*w);
7305 // if z == i then dieder() returns nan, because A in dieder gets (0,0,0)
7306 V3 increm = V3(0.0, 0.0, 0.0);
7307 if ( z == i ) {
7308 increm = V3(0.00001, 0.00001, 0.00001);
7309 }
7310 wink=mole.dieder(mole.showatoms.at(mole.knoepfe.at(i).neighbors.at(0)).pos+increm-mole.asymm.at(z).pos,
7311 mole.asymm.at(i).pos-mole.showatoms.at(mole.knoepfe.at(i).neighbors.at(0)).pos,
7312 v-mole.asymm.at(i).pos)/180.0*M_PI;
7313 }
7314 v=(-(xh[2]-nh)*0.33333*a)+ mole.asymm.at(i).pos+(xh[2]-nh)*0.942809041582*(sin(wink)*u+cos(wink)*w);
7315 htest.Label=mole.asymm.at(i).Label.section('_',0,0);
7316 htest.part=mole.asymm.at(i).part;
7317 htest.resiNr=mole.asymm.at(i).resiNr;
7318 htest.Label.replace(0,1,'H');
7319 QString baslab=htest.Label;
7320 int hindex=1;
7321 QString nnn=htest.Label;
7322 do {
7323 htest.Label=baslab;
7324 if (hindex) nnn=htest.Label.left(3).append(QString::number(hindex+9,36));
7325 if (nnn.size()>4) nnn=htest.Label.left(2).append(QString::number(hindex+9,36));
7326 if (htest.resiNr)
7327 nn=QString("%1_%2")//for shelxl same names in different parts are no problem but for platon so this should fix it.
7328 .arg(nnn)
7329 .arg((htest.resiNr)?QString::number(htest.resiNr):"");
7330 else nn=nnn;
7331 // qDebug()<<nn<<nnn<<(alab.contains(nn,Qt::CaseInsensitive));
7332 hindex++;
7333 }while(alab.contains(nn,Qt::CaseInsensitive));
7334 htest.Label=nnn;
7335 alab.append(nn);
7336 double uIso = mole.ueq(mole.asymm.at(i).uf)*1.5;
7337 htest.uf.m11 = htest.uf.m22 = htest.uf.m33 = uIso;
7338 htest.uf.m23 = uIso * mole.cell.cosra;
7339 htest.uf.m13 = uIso * mole.cell.cosrb;
7340 htest.uf.m12 = uIso * mole.cell.cosrg;
7341 htest.isIso=true;
7342 htest.ufiso_org=QString("-1.5");
7343 mole.Uf2Uo(htest.uf,htest.uc);
7344 htest.pos=v;
7345 mole.kart2frac(htest.pos,htest.frac);
7346 htest.orginalLine=QString("%1 %2 %3 %4 %5 %6 %7")
7347 .arg(htest.Label)
7348 .arg(qMax(1,editor->sfac.indexOf(0)+1))
7349 .arg(htest.frac.x,9,'f',5)
7350 .arg(htest.frac.y,9,'f',5)
7351 .arg(htest.frac.z,9,'f',5)
7352 .arg(mole.asymm.at(i).sof_org)
7353 .arg("-1.5");
7354 mole.asymm.append(htest);
7355 wink+=2.09439510239;
7356 v=(-(xh[2]-nh)*0.33333*a)+ mole.asymm.at(i).pos+(xh[2]-nh)*0.942809041582*(sin(wink)*u+cos(wink)*w);
7357 do {
7358 htest.Label=baslab;
7359 if (hindex) nnn=htest.Label.left(3).append(QString::number(hindex+9,36));
7360 if (nnn.size()>4) nnn=htest.Label.left(2).append(QString::number(hindex+9,36));
7361 if (htest.resiNr)
7362 nn=QString("%1_%2")//for shelxl same names in different parts are no problem but for platon so this should fix it.
7363 .arg(nnn)
7364 .arg((htest.resiNr)?QString::number(htest.resiNr):"");
7365 else nn=nnn;
7366 // qDebug()<<nn<<nnn<<(alab.contains(nn,Qt::CaseInsensitive));
7367 hindex++;
7368 }while(alab.contains(nn,Qt::CaseInsensitive));
7369 htest.Label=nnn;
7370 alab.append(nn);
7371 htest.pos=v;
7372 mole.kart2frac(htest.pos,htest.frac);
7373 htest.orginalLine=QString("%1 %2 %3 %4 %5 %6 %7")
7374 .arg(htest.Label)
7375 .arg(qMax(1,editor->sfac.indexOf(0)+1))
7376 .arg(htest.frac.x,9,'f',5)
7377 .arg(htest.frac.y,9,'f',5)
7378 .arg(htest.frac.z,9,'f',5)
7379 .arg(mole.asymm.at(i).sof_org)
7380 .arg("-1.5");
7381 mole.asymm.append(htest);
7382 wink+=2.09439510239;
7383 v=(-(xh[2]-nh)*0.33333*a)+ mole.asymm.at(i).pos+(xh[2]-nh)*0.942809041582*(sin(wink)*u+cos(wink)*w);
7384 do {
7385 htest.Label=baslab;
7386 if (hindex) nnn=htest.Label.left(3).append(QString::number(hindex+9,36));
7387 if (nnn.size()>4) nnn=htest.Label.left(2).append(QString::number(hindex+9,36));
7388 if (htest.resiNr)
7389 nn=QString("%1_%2")//for shelxl same names in different parts are no problem but for platon so this should fix it.
7390 .arg(nnn)
7391 .arg((htest.resiNr)?QString::number(htest.resiNr):"");
7392 else nn=nnn;
7393 // qDebug()<<nn<<nnn<<(alab.contains(nn,Qt::CaseInsensitive));
7394 hindex++;
7395 }while(alab.contains(nn,Qt::CaseInsensitive));
7396 htest.Label=nnn;
7397 alab.append(nn);
7398 htest.pos=v;
7399 mole.kart2frac(htest.pos,htest.frac);
7400 htest.orginalLine=QString("%1 %2 %3 %4 %5 %6 %7")
7401 .arg(htest.Label)
7402 .arg(qMax(1,editor->sfac.indexOf(0)+1))
7403 .arg(htest.frac.x,9,'f',5)
7404 .arg(htest.frac.y,9,'f',5)
7405 .arg(htest.frac.z,9,'f',5)
7406 .arg(mole.asymm.at(i).sof_org)
7407 .arg("-1.5");
7408 mole.asymm.append(htest);
7409 QString label = mole.showatoms.at(i).orginalLine.left(80).trimmed();
7410 // int afixfuenf=(mole.showatoms.at(i).afix/10)?(mole.showatoms.at(i).afix/10)*10+5:0;
7411 cursor.movePosition(QTextCursor::Start);
7412 cursor = document->find(label,cursor);
7413 if (cursor.isNull()){
7414 cursor = editor->textCursor();
7415 cursor.movePosition(QTextCursor::Start);
7416 label.chop(10);
7417 cursor = document->find(label,cursor);
7418 if (cursor.isNull()) {
7419 cursor = editor->textCursor();
7420 }
7421 }
7422 cursor.movePosition(QTextCursor::StartOfLine,QTextCursor::MoveAnchor);
7423 cursor.movePosition(QTextCursor::EndOfLine,QTextCursor::KeepAnchor);
7424 while (cursor.selectedText().endsWith("=")) {
7425 cursor.movePosition(QTextCursor::Down,QTextCursor::KeepAnchor);
7426 cursor.movePosition(QTextCursor::EndOfLine,QTextCursor::KeepAnchor);
7427 }
7428 cursor.clearSelection();
7429 cursor.movePosition(QTextCursor::Down);
7430 cursor.insertText(QString("AFIX 137\n%1\n%2\n%3\nAFIX %4\n")
7431 .arg(mole.asymm.at(mole.asymm.size()-3).orginalLine)
7432 .arg(mole.asymm.at(mole.asymm.size()-2).orginalLine)
7433 .arg(mole.asymm.at(mole.asymm.size()-1).orginalLine)
7434 .arg(mole.afix5(i))
7435 );
7436 }else if (chi> -0.27){//afix 93
7437 int j,k,l;
7438 a=Normalize(a);
7439 double jx,kx,lx,mx,my,mz;
7440 double val[24],merg[12],wink=0,t=0,mt=0;
7441 if (fxle->n5){
7442 for (int z=0; z<12;z++) merg[z]=0;
7443 for (int z=0; z<24; z++){
7444 wink=z*0.261799387799;
7445 w=Normalize(V3(0,0,1)%a);
7446 u=Normalize(w%a);
7447 v=(-(xh[6]-nh)*0.33333*a)+ mole.asymm.at(i).pos+(xh[6]-nh)*0.942809041582*(sin(wink)*u+cos(wink)*w);
7448 qtest.pos=v;
7449 mole.kart2frac(v,v);
7450 jx=(v.x>0)?(v.x*fxle->n1+0.5):((1.0+v.x)*fxle->n1+0.5);
7451 kx=(v.y>0)?(v.y*fxle->n2+0.5):((1.0+v.y)*fxle->n2+0.5);
7452 lx=(v.z>0)?(v.z*fxle->n3+0.5):((1.0+v.z)*fxle->n3+0.5);
7453 mx=jx-floor(jx);
7454 my=kx-floor(kx);
7455 mz=lx-floor(lx);
7456 j=((int)jx)%fxle->n1;//
7457 k=((int)kx)%fxle->n2;//
7458 l=((int)lx)%fxle->n3;//
7459 merg[z%12]+=val[z]=(
7460 (1-mx)*fxle->datfo_fc[(j+fxle->n1*(k+l*fxle->n2))%fxle->n5]+
7461 mx*fxle->datfo_fc[((j+1)+fxle->n1*(k+l*fxle->n2))%fxle->n5]+
7462 (1-my)*fxle->datfo_fc[(j+fxle->n1*(k+l*fxle->n2))%fxle->n5]+
7463 my*fxle->datfo_fc[(j+fxle->n1*((k+1)+l*fxle->n2))%fxle->n5]+
7464 (1-mz)*fxle->datfo_fc[(j+fxle->n1*(k+l*fxle->n2))%fxle->n5]+
7465 mz*fxle->datfo_fc[(j+fxle->n1*(k+(l+1)*fxle->n2))%fxle->n5])/3.0;
7466 qtest.peakHeight=val[z];
7467 qtest.frac=v;
7468 qtest.Label=QString("Q%1").arg(z+100);
7469 mole.pmin=qMin(mole.pmin, qtest.peakHeight);
7470 mole.pmax=qMax(mole.pmax, qtest.peakHeight);
7471 qpv->cutoff=0;//mole.pmin;
7472 qpv->setMin(mole.pmin);
7473 qpv->setMax(mole.pmax);
7474 mole.asymm.append(qtest);
7475 }
7476 for (int z=0; z<12;z++) {
7477 t =merg[(z+12)%12] ;
7478 double x = t - merg[(z+13)%12];
7479 double u = t - merg[(z+11)%12];
7480 if (fmin(x,u)<0) continue;
7481 double p=0.5*(u-x)/(u+x);
7482 t=t+0.25*(p*(u-x));
7483 mt=(mt>t)?mt:t;
7484 if (t<mt)continue;
7485 wink=((double) z + p )*0.261799387799;
7486
7487 /////////////////
7488 }
7489 }else{
7490 int zzz=0;
7491 int z=mole.knoepfe.at(mole.knoepfe.at(i).neighbors.at(0)).neighbors.at(zzz++);
7492 while ((z==i)&&(zzz<mole.knoepfe.at(mole.knoepfe.at(i).neighbors.at(0)).neighbors.size()))
7493 z=mole.knoepfe.at(mole.knoepfe.at(i).neighbors.at(0)).neighbors.at(zzz++);
7494 w=Normalize(V3(0,0,1)%a);
7495 u=Normalize(w%a);
7496 v=(-(xh[2]-nh)*0.33333*a)+ mole.asymm.at(i).pos+(xh[2]-nh)*0.942809041582*(sin(wink)*u+cos(wink)*w);
7497 // if z == i then dieder() returns nan, because A in dieder gets (0,0,0)
7498 V3 increm = V3(0.0, 0.0, 0.0);
7499 if ( z == i ) {
7500 increm = V3(0.00001, 0.00001, 0.00001);
7501 }
7502 wink=mole.dieder(mole.showatoms.at(mole.knoepfe.at(i).neighbors.at(0)).pos+increm-mole.asymm.at(z).pos,
7503 mole.asymm.at(i).pos-mole.showatoms.at(mole.knoepfe.at(i).neighbors.at(0)).pos,
7504 v-mole.asymm.at(i).pos)/180.0*M_PI;
7505
7506 }
7507
7508 v=(-(xh[6]-nh)*0.5*a)+ mole.asymm.at(i).pos+(xh[6]-nh)*0.866025403784*(sin(wink)*u+cos(wink)*w);
7509 htest.Label=mole.asymm.at(i).Label.section('_',0,0);
7510 htest.part=mole.asymm.at(i).part;
7511 htest.resiNr=mole.asymm.at(i).resiNr;
7512 htest.Label.replace(0,1,'H');
7513 int hindex=1;
7514 QString nnn=htest.Label;
7515 QString baslab=htest.Label;
7516 do {
7517 htest.Label=baslab;
7518 if (hindex) nnn=htest.Label.left(3).append(QString::number(hindex+9,36));
7519 if (nnn.size()>4) nnn=htest.Label.left(2).append(QString::number(hindex+9,36));
7520 if (htest.resiNr)
7521 nn=QString("%1_%2")//for shelxl same names in different parts are no problem but for platon so this should fix it.
7522 .arg(nnn)
7523 .arg((htest.resiNr)?QString::number(htest.resiNr):"");
7524 else nn=nnn;
7525 // qDebug()<<nn<<nnn<<(alab.contains(nn,Qt::CaseInsensitive));
7526 hindex++;
7527 }while(alab.contains(nn,Qt::CaseInsensitive));
7528 htest.Label=nnn;
7529 alab.append(nn);
7530 htest.isIso=true;
7531 htest.ufiso_org=QString("-1.2");
7532 double uIso = mole.ueq(mole.asymm.at(i).uf)*1.2;
7533 htest.uf.m11 = htest.uf.m22 = htest.uf.m33 = uIso;
7534 htest.uf.m23 = uIso * mole.cell.cosra;
7535 htest.uf.m13 = uIso * mole.cell.cosrb;
7536 htest.uf.m12 = uIso * mole.cell.cosrg;
7537 mole.Uf2Uo(htest.uf,htest.uc);
7538 htest.pos=v;
7539 mole.kart2frac(htest.pos,htest.frac);
7540 htest.orginalLine=QString("%1 %2 %3 %4 %5 %6 %7")
7541 .arg(htest.Label)
7542 .arg(qMax(1,editor->sfac.indexOf(0)+1))
7543 .arg(htest.frac.x,9,'f',5)
7544 .arg(htest.frac.y,9,'f',5)
7545 .arg(htest.frac.z,9,'f',5)
7546 .arg(mole.asymm.at(i).sof_org)
7547 .arg("-1.2");
7548 mole.asymm.append(htest);
7549 wink+=3.14159265359;
7550 v=(-(xh[6]-nh)*0.5*a)+ mole.asymm.at(i).pos+(xh[6]-nh)*0.866025403784*(sin(wink)*u+cos(wink)*w);
7551 do {
7552 htest.Label=baslab;
7553 if (hindex) nnn=htest.Label.left(3).append(QString::number(hindex+9,36));
7554 if (nnn.size()>4) nnn=htest.Label.left(2).append(QString::number(hindex+9,36));
7555 if (htest.resiNr)
7556 nn=QString("%1_%2")//for shelxl same names in different parts are no problem but for platon so this should fix it.
7557 .arg(nnn)
7558 .arg((htest.resiNr)?QString::number(htest.resiNr):"");
7559 else nn=nnn;
7560 // qDebug()<<nn<<nnn<<(alab.contains(nn,Qt::CaseInsensitive));
7561 hindex++;
7562 }while(alab.contains(nn,Qt::CaseInsensitive));
7563 htest.Label=nnn;
7564 alab.append(nn);
7565 htest.pos=v;
7566 mole.kart2frac(htest.pos,htest.frac);
7567 htest.orginalLine=QString("%1 %2 %3 %4 %5 %6 %7")
7568 .arg(htest.Label)
7569 .arg(qMax(1,editor->sfac.indexOf(0)+1))
7570 .arg(htest.frac.x,9,'f',5)
7571 .arg(htest.frac.y,9,'f',5)
7572 .arg(htest.frac.z,9,'f',5)
7573 .arg(mole.asymm.at(i).sof_org)
7574 .arg("-1.2");
7575 mole.asymm.append(htest);
7576
7577 QString label = mole.showatoms.at(i).orginalLine.left(80).trimmed();
7578 // int afixfuenf=(mole.showatoms.at(i).afix/10)?(mole.showatoms.at(i).afix/10)*10+5:0;
7579 cursor.movePosition(QTextCursor::Start);
7580 cursor = document->find(label,cursor);
7581 if (cursor.isNull()){
7582 cursor = editor->textCursor();
7583 cursor.movePosition(QTextCursor::Start);
7584 label.chop(10);
7585 cursor = document->find(label,cursor);
7586 if (cursor.isNull()) {
7587 cursor = editor->textCursor();
7588 }
7589 }
7590 cursor.movePosition(QTextCursor::StartOfLine,QTextCursor::MoveAnchor);
7591 cursor.movePosition(QTextCursor::EndOfLine,QTextCursor::KeepAnchor);
7592 while (cursor.selectedText().endsWith("=")) {
7593 cursor.movePosition(QTextCursor::Down,QTextCursor::KeepAnchor);
7594 cursor.movePosition(QTextCursor::EndOfLine,QTextCursor::KeepAnchor);
7595 }
7596 cursor.clearSelection();
7597 cursor.movePosition(QTextCursor::Down);
7598 cursor.insertText(QString("AFIX 93\n%1\n%2\nAFIX %3\n")
7599 .arg(mole.asymm.at(mole.asymm.size()-2).orginalLine)
7600 .arg(mole.asymm.at(mole.asymm.size()-1).orginalLine)
7601 .arg(mole.afix5(i))
7602 );
7603 }else{//afix 163
7604 if (mole.asymm.at(i).an==5){
7605 a = Normalize(mole.showatoms.at(mole.knoepfe.at(i).neighbors.at(0)).pos - mole.asymm.at(i).pos);
7606 v=(-(xh[7]-nh)*a)+ mole.asymm.at(i).pos;
7607 htest.Label=mole.asymm.at(i).Label.section('_',0,0);
7608 htest.part=mole.asymm.at(i).part;
7609 htest.resiNr=mole.asymm.at(i).resiNr;
7610 htest.Label.replace(0,1,'H');
7611 int hindex=0;
7612 QString nnn=htest.Label;
7613 do {
7614 if (hindex) nnn=htest.Label.left(3).append(QString::number(hindex+9,36));
7615 if (nnn.size()>4) nnn=htest.Label.left(2).append(QString::number(hindex+9,36));
7616 if (htest.resiNr)
7617 nn=QString("%1_%2")//for shelxl same names in different parts are no problem but for platon so this should fix it.
7618 .arg(nnn)
7619 .arg((htest.resiNr)?QString::number(htest.resiNr):"");
7620 else nn=nnn;
7621 // qDebug()<<nn<<nnn<<(alab.contains(nn,Qt::CaseInsensitive));
7622 hindex++;
7623 }while(alab.contains(nn,Qt::CaseInsensitive));
7624 htest.Label=nnn;
7625 alab.append(nn);
7626 htest.isIso=true;
7627 htest.ufiso_org=QString("-1.2");
7628 double uIso = mole.ueq(mole.asymm.at(i).uf)*1.2;
7629 htest.uf.m11 = htest.uf.m22 = htest.uf.m33 = uIso;
7630 htest.uf.m23 = uIso * mole.cell.cosra;
7631 htest.uf.m13 = uIso * mole.cell.cosrb;
7632 htest.uf.m12 = uIso * mole.cell.cosrg;
7633 mole.Uf2Uo(htest.uf,htest.uc);
7634 htest.pos=v;
7635 mole.kart2frac(htest.pos,htest.frac);
7636 htest.orginalLine=QString("%1 %2 %3 %4 %5 %6 %7")
7637 .arg(htest.Label)
7638 .arg(qMax(1,editor->sfac.indexOf(0)+1))
7639 .arg(htest.frac.x,9,'f',5)
7640 .arg(htest.frac.y,9,'f',5)
7641 .arg(htest.frac.z,9,'f',5)
7642 .arg(mole.asymm.at(i).sof_org)
7643 .arg("-1.2");
7644 mole.asymm.append(htest);
7645
7646 QString label = mole.showatoms.at(i).orginalLine.left(80).trimmed();
7647 // int afixfuenf=(mole.showatoms.at(i).afix/10)?(mole.showatoms.at(i).afix/10)*10+5:0;
7648 cursor.movePosition(QTextCursor::Start);
7649 cursor = document->find(label,cursor);
7650 if (cursor.isNull()){
7651 cursor = editor->textCursor();
7652 cursor.movePosition(QTextCursor::Start);
7653 label.chop(10);
7654 cursor = document->find(label,cursor);
7655 if (cursor.isNull()) {
7656 cursor = editor->textCursor();
7657 }
7658 }
7659 cursor.movePosition(QTextCursor::StartOfLine,QTextCursor::MoveAnchor);
7660 cursor.movePosition(QTextCursor::EndOfLine,QTextCursor::KeepAnchor);
7661 while (cursor.selectedText().endsWith("=")) {
7662 cursor.movePosition(QTextCursor::Down,QTextCursor::KeepAnchor);
7663 cursor.movePosition(QTextCursor::EndOfLine,QTextCursor::KeepAnchor);
7664 }
7665 cursor.clearSelection();
7666 cursor.movePosition(QTextCursor::Down);
7667 cursor.insertText(QString("AFIX 163\n%1\nAFIX %2\n")
7668 .arg(mole.asymm.at(mole.asymm.size()-1).orginalLine)
7669 .arg(mole.afix5(i))
7670 );
7671 }
7672 }
7673 }
7674 if (mole.knoepfe.at(i).neighbors.size()==2){//afix 43 oder 23
7675 if ((mole.asymm.at(i).an==6)&&(!istDonor.contains(i))) {
7676 printf("%s is probably no donor \n",mole.asymm.at(i).Label.toStdString().c_str());
7677 continue;
7678 }
7679 double angle=0;
7680 V3 v=V3(0,0,0),w=V3(0,0,0),u=V3(0,0,0) ,a=V3(0,0,0),b=V3(0,0,0),c=V3(0,0,0);
7681 a = mole.showatoms.at(mole.knoepfe.at(i).neighbors.at(0) ).pos - mole.asymm.at(i).pos;
7682 b = mole.showatoms.at(mole.knoepfe.at(i).neighbors.at(1) ).pos - mole.asymm.at(i).pos;
7683 double chi1 = sqrt(Norm(a))-
7684 ((mole.Kovalenz_Radien[mole.showatoms.at(mole.knoepfe.at(i).neighbors.at(0)).an]+
7685 mole.Kovalenz_Radien[mole.asymm.at(i).an])/100.0);
7686 double chi2 = sqrt(Norm(b))-
7687 ((mole.Kovalenz_Radien[mole.showatoms.at(mole.knoepfe.at(i).neighbors.at(1)).an]+
7688 mole.Kovalenz_Radien[mole.asymm.at(i).an])/100.0);
7689 a = c = Normalize(a) ;
7690 c = c+ (b= Normalize(b));
7691 angle=mole.winkel(a,b);
7692 c = Normalize(c);
7693 double andi=(mole.showatoms.at(mole.knoepfe.at(i).neighbors.at(1)).an+mole.showatoms.at(mole.knoepfe.at(i).neighbors.at(0)).an)/2.0-5.0;
7694 andi= (andi)?0.8:1.0;
7695 if (angle<160) {
7696 if ((andi*(chi1+chi2))<-0.13) {//43
7697 c = (-(xh[3]-nh) * c)+mole.asymm.at(i).pos;
7698 htest.Label=mole.asymm.at(i).Label.section('_',0,0);
7699 htest.part=mole.asymm.at(i).part;
7700 htest.resiNr=mole.asymm.at(i).resiNr;
7701 htest.Label.replace(0,1,'H');
7702 int hindex=0;
7703 QString nnn=htest.Label;
7704 do {
7705 if (hindex) nnn=htest.Label.left(3).append(QString::number(hindex+9,36));
7706 if (nnn.size()>4) nnn=htest.Label.left(2).append(QString::number(hindex+9,36));
7707 if (htest.resiNr)
7708 nn=QString("%1_%2")//for shelxl same names in different parts are no problem but for platon so this should fix it.
7709 .arg(nnn)
7710 .arg((htest.resiNr)?QString::number(htest.resiNr):"");
7711 else nn=nnn;
7712 // qDebug()<<nn<<nnn<<(alab.contains(nn,Qt::CaseInsensitive));
7713 hindex++;
7714 }while(alab.contains(nn,Qt::CaseInsensitive));
7715 htest.Label=nnn;
7716 alab.append(nn);
7717 htest.isIso=true;
7718 htest.ufiso_org=QString("-1.2");
7719 double uIso = mole.ueq(mole.asymm.at(i).uf)*1.2;
7720 htest.uf.m11 = htest.uf.m22 = htest.uf.m33 = uIso;
7721 htest.uf.m23 = uIso * mole.cell.cosra;
7722 htest.uf.m13 = uIso * mole.cell.cosrb;
7723 htest.uf.m12 = uIso * mole.cell.cosrg;
7724 mole.Uf2Uo(htest.uf,htest.uc);
7725 htest.pos=c;
7726 mole.kart2frac(htest.pos,htest.frac);
7727 htest.orginalLine=QString("%1 %2 %3 %4 %5 %6 %7")
7728 .arg(htest.Label)
7729 .arg(qMax(1,editor->sfac.indexOf(0)+1))
7730 .arg(htest.frac.x,9,'f',5)
7731 .arg(htest.frac.y,9,'f',5)
7732 .arg(htest.frac.z,9,'f',5)
7733 .arg(mole.asymm.at(i).sof_org)
7734 .arg("-1.2");
7735 mole.asymm.append(htest);
7736 QString label = mole.showatoms.at(i).orginalLine.left(80).trimmed();
7737 // int afixfuenf=(mole.showatoms.at(i).afix/10)?(mole.showatoms.at(i).afix/10)*10+5:0;
7738 cursor.movePosition(QTextCursor::Start);
7739 cursor = document->find(label,cursor);
7740 if (cursor.isNull()){
7741 cursor = editor->textCursor();
7742 cursor.movePosition(QTextCursor::Start);
7743 label.chop(10);
7744 cursor = document->find(label,cursor);
7745 if (cursor.isNull()) {
7746 cursor = editor->textCursor();
7747 }
7748 }
7749 cursor.movePosition(QTextCursor::StartOfLine,QTextCursor::MoveAnchor);
7750 cursor.movePosition(QTextCursor::EndOfLine,QTextCursor::KeepAnchor);
7751 while (cursor.selectedText().endsWith("=")) {
7752 cursor.movePosition(QTextCursor::Down,QTextCursor::KeepAnchor);
7753 cursor.movePosition(QTextCursor::EndOfLine,QTextCursor::KeepAnchor);
7754 }
7755 cursor.clearSelection();
7756 cursor.movePosition(QTextCursor::Down);
7757 cursor.insertText(QString("AFIX 43\n%1\nAFIX %2\n")
7758 .arg(mole.asymm.at(mole.asymm.size()-1).orginalLine)
7759 .arg(mole.afix5(i)));
7760 }
7761 else{//23
7762 w = Normalize(a);
7763 u = Normalize(b);
7764 double si=1.0376-0.0346*Norm(w-u); //=1.91063323625-((acos(u*w)-1.91063323625)/5.0);//-1.91063323625 = 109.47 grad ; 3.7 empirischer Wert
7765 c = (-cos(si)*(xh[1]-nh) * c);
7766 v = sin(si) *(xh[1]-nh) * Normalize(c%a);
7767 a = mole.asymm.at(i).pos + c + v;
7768 b = mole.asymm.at(i).pos + c - v;
7769 c = c + mole.asymm.at(i).pos;
7770
7771 htest.Label=mole.asymm.at(i).Label.section('_',0,0);
7772 htest.part=mole.asymm.at(i).part;
7773 htest.resiNr=mole.asymm.at(i).resiNr;
7774 htest.Label.replace(0,1,'H');
7775 int hindex=1;
7776 QString nnn=htest.Label;
7777 QString ann=htest.Label;
7778 do {
7779 if (hindex) nnn=htest.Label.left(3).append(QString::number(hindex+9,36));
7780 if (nnn.size()>4) nnn=htest.Label.left(2).append(QString::number(hindex+9,36));
7781 if (htest.resiNr)
7782 nn=QString("%1_%2")//for shelxl same names in different parts are no problem but for platon so this should fix it.
7783 .arg(nnn)
7784 .arg((htest.resiNr)?QString::number(htest.resiNr):"");
7785 else nn=nnn;
7786 // qDebug()<<nn<<nnn<<(alab.contains(nn,Qt::CaseInsensitive));
7787 hindex++;
7788 }while(alab.contains(nn,Qt::CaseInsensitive));
7789 htest.Label=nnn;
7790 alab.append(nn);
7791 htest.isIso=true;
7792 htest.ufiso_org=QString("-1.2");
7793 double uIso = mole.ueq(mole.asymm.at(i).uf)*1.2;
7794 htest.uf.m11 = htest.uf.m22 = htest.uf.m33 = uIso;
7795 htest.uf.m23 = uIso * mole.cell.cosra;
7796 htest.uf.m13 = uIso * mole.cell.cosrb;
7797 htest.uf.m12 = uIso * mole.cell.cosrg;
7798 mole.Uf2Uo(htest.uf,htest.uc);
7799 htest.pos=a;
7800 mole.kart2frac(htest.pos,htest.frac);
7801 htest.orginalLine=QString("%1 %2 %3 %4 %5 %6 %7")
7802 .arg(htest.Label)
7803 .arg(qMax(1,editor->sfac.indexOf(0)+1))
7804 .arg(htest.frac.x,9,'f',5)
7805 .arg(htest.frac.y,9,'f',5)
7806 .arg(htest.frac.z,9,'f',5)
7807 .arg(mole.asymm.at(i).sof_org)
7808 .arg("-1.2");
7809 mole.asymm.append(htest);
7810 //printf("AB problem: htest%s nnn%s ann%s\n",htest.Label.toStdString().c_str(),nnn.toStdString().c_str(),ann.toStdString().c_str());
7811 do {
7812 if (hindex) nnn=ann.left(3).append(QString::number(hindex+9,36));
7813 if (nnn.size()>4) nnn=ann.left(2).append(QString::number(hindex+9,36));
7814 if (htest.resiNr)
7815 nn=QString("%1_%2")//for shelxl same names in different parts are no problem but for platon so this should fix it.
7816 .arg(nnn)
7817 .arg((htest.resiNr)?QString::number(htest.resiNr):"");
7818 else nn=nnn;
7819 // qDebug()<<nn<<nnn<<(alab.contains(nn,Qt::CaseInsensitive));
7820 hindex++;
7821 }while(alab.contains(nn,Qt::CaseInsensitive));
7822 htest.Label=nnn;
7823 alab.append(nn);
7824 //printf("AB problems: htest%s nnn%s nn%s\n",htest.Label.toStdString().c_str(),nnn.toStdString().c_str(),nn.toStdString().c_str());
7825 htest.pos=b;
7826 mole.kart2frac(htest.pos,htest.frac);
7827 htest.orginalLine=QString("%1 %2 %3 %4 %5 %6 %7")
7828 .arg(htest.Label)
7829 .arg(qMax(1,editor->sfac.indexOf(0)+1))
7830 .arg(htest.frac.x,9,'f',5)
7831 .arg(htest.frac.y,9,'f',5)
7832 .arg(htest.frac.z,9,'f',5)
7833 .arg(mole.asymm.at(i).sof_org)
7834 .arg("-1.2");
7835 mole.asymm.append(htest);
7836 QString label = mole.showatoms.at(i).orginalLine.left(80).trimmed();
7837 // int afixfuenf=(mole.showatoms.at(i).afix/10)?(mole.showatoms.at(i).afix/10)*10+5:0;
7838 cursor.movePosition(QTextCursor::Start);
7839 cursor = document->find(label,cursor);
7840 if (cursor.isNull()){
7841 cursor = editor->textCursor();
7842 cursor.movePosition(QTextCursor::Start);
7843 label.chop(10);
7844 cursor = document->find(label,cursor);
7845 if (cursor.isNull()) {
7846 cursor = editor->textCursor();
7847 }
7848 }
7849 cursor.movePosition(QTextCursor::StartOfLine,QTextCursor::MoveAnchor);
7850 cursor.movePosition(QTextCursor::EndOfLine,QTextCursor::KeepAnchor);
7851 while (cursor.selectedText().endsWith("=")) {
7852 cursor.movePosition(QTextCursor::Down,QTextCursor::KeepAnchor);
7853 cursor.movePosition(QTextCursor::EndOfLine,QTextCursor::KeepAnchor);
7854 }
7855 cursor.clearSelection();
7856 cursor.movePosition(QTextCursor::Down);
7857 cursor.insertText(QString("AFIX 23\n%1\n%2\nAFIX %3\n")
7858 .arg(mole.asymm.at(mole.asymm.size()-2).orginalLine)
7859 .arg(mole.asymm.at(mole.asymm.size()-1).orginalLine)
7860 .arg(mole.afix5(i)));
7861
7862 }
7863 }
7864 }
7865
7866 if (mole.knoepfe.at(i).neighbors.size()==3) {
7867 if ((mole.asymm.at(i).an==6)&&(!istDonor.contains(i))) continue;
7868 V3 v,w=V3(0,0,0),u ,a,b,c=V3(0,0,0);
7869 double ch1=0;
7870 for (int k=0; k<3; k++){
7871 a = Normalize(mole.showatoms.at(mole.knoepfe.at(i).neighbors.at(k) ).pos - mole.asymm.at(i).pos);
7872 b = Normalize(mole.showatoms.at(mole.knoepfe.at(i).neighbors.at((k+1)%3)).pos - mole.asymm.at(i).pos);
7873 c = c + a;
7874 v = Normalize(a%b);
7875 if (k) {plan*=fabs(w*v);//1 for perfect flat
7876 }
7877 w = v;
7878 ch1 += sqrt(Distance(mole.asymm.at(i).pos,
7879 mole.showatoms.at(mole.knoepfe.at(i).neighbors.at(k)).pos))-
7880 ((mole.Kovalenz_Radien[mole.asymm.at(i).an]+
7881 mole.Kovalenz_Radien[mole.showatoms.at(mole.knoepfe.at(i).neighbors.at(k)).an])*0.01);
7882
7883 }
7884 c = Normalize(c);
7885 ch1*=1.0/3;
7886 if ((plan<0.8)&&(ch1>-0.09)){// not flat and not to short bonds
7887 c *=-(xh[0]-nh);
7888 htest.Label=mole.asymm.at(i).Label.section('_',0,0);
7889 htest.part=mole.asymm.at(i).part;
7890 htest.resiNr=mole.asymm.at(i).resiNr;
7891 htest.Label.replace(0,1,'H');
7892 int hindex=0;
7893 QString nnn=htest.Label;
7894 do {
7895 if (hindex) nnn=htest.Label.left(3).append(QString::number(hindex+9,36));
7896 if (nnn.size()>4) nnn=htest.Label.left(2).append(QString::number(hindex+9,36));
7897 if (htest.resiNr)
7898 nn=QString("%1_%2")//for shelxl same names in different parts are no problem but for platon so this should fix it.
7899 .arg(nnn)
7900 .arg((htest.resiNr)?QString::number(htest.resiNr):"");
7901 else nn=nnn;
7902 // qDebug()<<nn<<nnn<<(alab.contains(nn,Qt::CaseInsensitive));
7903 hindex++;
7904 }while(alab.contains(nn,Qt::CaseInsensitive));
7905 htest.Label=nnn;
7906 alab.append(nn);
7907 htest.isIso=true;
7908 htest.ufiso_org=QString("-1.2");
7909 double uIso = mole.ueq(mole.asymm.at(i).uf)*1.2;
7910 htest.uf.m11 = htest.uf.m22 = htest.uf.m33 = uIso;
7911 htest.uf.m23 = uIso * mole.cell.cosra;
7912 htest.uf.m13 = uIso * mole.cell.cosrb;
7913 htest.uf.m12 = uIso * mole.cell.cosrg;
7914 mole.Uf2Uo(htest.uf,htest.uc);
7915 htest.pos = mole.asymm.at(i).pos + c;
7916 mole.kart2frac(htest.pos,htest.frac);
7917 QString label = mole.showatoms.at(i).orginalLine.left(80).trimmed();
7918 // int afixfuenf=(mole.showatoms.at(i).afix/10)?(mole.showatoms.at(i).afix/10)*10+5:0;
7919 cursor.movePosition(QTextCursor::Start);
7920 cursor = document->find(label,cursor);
7921 if (cursor.isNull()){
7922 cursor = editor->textCursor();
7923 cursor.movePosition(QTextCursor::Start);
7924 label.chop(10);
7925 cursor = document->find(label,cursor);
7926 if (cursor.isNull()) {
7927 cursor = editor->textCursor();
7928 }
7929 }
7930 cursor.movePosition(QTextCursor::StartOfLine,QTextCursor::MoveAnchor);
7931 cursor.movePosition(QTextCursor::EndOfLine,QTextCursor::KeepAnchor);
7932 while (cursor.selectedText().endsWith("=")) {
7933 cursor.movePosition(QTextCursor::Down,QTextCursor::KeepAnchor);
7934 cursor.movePosition(QTextCursor::EndOfLine,QTextCursor::KeepAnchor);
7935 }
7936 cursor.clearSelection();
7937 cursor.movePosition(QTextCursor::Down);
7938 htest.orginalLine=QString("%1 %2 %3 %4 %5 %6 %7")
7939 .arg(htest.Label)
7940 .arg(qMax(1,editor->sfac.indexOf(0)+1))
7941 .arg(htest.frac.x,9,'f',5)
7942 .arg(htest.frac.y,9,'f',5)
7943 .arg(htest.frac.z,9,'f',5)
7944 .arg(mole.asymm.at(i).sof_org)
7945 .arg("-1.2");
7946 cursor.insertText(QString("AFIX 13\n%1\nAFIX %2\n").arg(htest.orginalLine).arg(mole.afix5(i)));
7947 mole.asymm.append(htest);
7948 }
7949 }
7950 }
7951 if (((mole.asymm.at(i).an==4)||(mole.asymm.at(i).an==5))&&((mole.knoepfe.at(i).neighbors.size()==4)||(mole.knoepfe.at(i).neighbors.size()==5))){//boron with 4 or 5 neighbors AFIX 153
7952 //qDebug()<<mole.knoepfe.at(i).neighbors.size()<<mole.asymm.at(i).Label;
7953 V3 vsum = V3(0.,0.,0.);
7954 int nbs=mole.knoepfe.at(i).neighbors.size();
7955 int nbr=0;
7956 for (int k=0; k<mole.knoepfe.at(i).neighbors.size();k++){
7957 if (abs(mole.showatoms.at(mole.knoepfe.at(i).neighbors.at(k)).an-5)<2){
7958 nbr++;
7959 vsum+=(mole.showatoms.at(mole.knoepfe.at(i).neighbors.at(k) ).pos - mole.asymm.at(i).pos);
7960 }
7961 }
7962 //printf("153 test length = %f %d==%d %s\n",Norm(vsum), nbs, nbr, mole.asymm.at(i).Label.toStdString().c_str());
7963 if ((nbs==nbr)&&(Norm(vsum)>10)){
7964 vsum=Normalize(vsum);
7965 vsum*=-1.0*xh[4];
7966 htest.Label=mole.asymm.at(i).Label.section('_',0,0);
7967 htest.part=mole.asymm.at(i).part;
7968 htest.resiNr=mole.asymm.at(i).resiNr;
7969 htest.Label.replace(0,1,'H');
7970 int hindex=0;
7971 QString nnn=htest.Label;
7972 do {
7973 if (hindex) nnn=htest.Label.left(3).append(QString::number(hindex+9,36));
7974 if (nnn.size()>4) nnn=htest.Label.left(2).append(QString::number(hindex+9,36));
7975 if (htest.resiNr)
7976 nn=QString("%1_%2")//for shelxl same names in different parts are no problem but for platon so this should fix it.
7977 .arg(nnn)
7978 .arg((htest.resiNr)?QString::number(htest.resiNr):"");
7979 else nn=nnn;
7980 // qDebug()<<nn<<nnn<<(alab.contains(nn,Qt::CaseInsensitive));
7981 hindex++;
7982 }while(alab.contains(nn,Qt::CaseInsensitive));
7983 htest.Label=nnn;
7984 alab.append(nn);
7985 htest.isIso=true;
7986 htest.ufiso_org=QString("-1.2");
7987 double uIso = mole.ueq(mole.asymm.at(i).uf)*1.2;
7988 htest.uf.m11 = htest.uf.m22 = htest.uf.m33 = uIso;
7989 htest.uf.m23 = uIso * mole.cell.cosra;
7990 htest.uf.m13 = uIso * mole.cell.cosrb;
7991 htest.uf.m12 = uIso * mole.cell.cosrg;
7992 mole.Uf2Uo(htest.uf,htest.uc);
7993 htest.pos = mole.asymm.at(i).pos + vsum;
7994 mole.kart2frac(htest.pos,htest.frac);
7995 QString label = mole.showatoms.at(i).orginalLine.left(80).trimmed();
7996 // int afixfuenf=(mole.showatoms.at(i).afix/10)?(mole.showatoms.at(i).afix/10)*10+5:0;
7997 cursor.movePosition(QTextCursor::Start);
7998 cursor = document->find(label,cursor);
7999 if (cursor.isNull()){
8000 cursor = editor->textCursor();
8001 cursor.movePosition(QTextCursor::Start);
8002 label.chop(10);
8003 cursor = document->find(label,cursor);
8004 if (cursor.isNull()) {
8005 cursor = editor->textCursor();
8006 }
8007 }
8008 cursor.movePosition(QTextCursor::StartOfLine,QTextCursor::MoveAnchor);
8009 cursor.movePosition(QTextCursor::EndOfLine,QTextCursor::KeepAnchor);
8010 while (cursor.selectedText().endsWith("=")) {
8011 cursor.movePosition(QTextCursor::Down,QTextCursor::KeepAnchor);
8012 cursor.movePosition(QTextCursor::EndOfLine,QTextCursor::KeepAnchor);
8013 }
8014 cursor.clearSelection();
8015 cursor.movePosition(QTextCursor::Down);
8016 htest.orginalLine=QString("%1 %2 %3 %4 %5 %6 %7")
8017 .arg(htest.Label)
8018 .arg(qMax(1,editor->sfac.indexOf(0)+1))
8019 .arg(htest.frac.x,9,'f',5)
8020 .arg(htest.frac.y,9,'f',5)
8021 .arg(htest.frac.z,9,'f',5)
8022 .arg(mole.asymm.at(i).sof_org)
8023 .arg("-1.2");
8024 cursor.insertText(QString("AFIX 153\n%1\nAFIX %2\n").arg(htest.orginalLine).arg(mole.afix5(i)));
8025 mole.asymm.append(htest);
8026 }
8027 }
8028 }
8029 for (int j=0;j<mole.contact.size();j++){
8030 /* printf("??LINE %d %s %s\n",__LINE__,
8031 mole.asymm.at(mole.contact.at(j).a1).Label.toStdString().c_str(),
8032 mole.asymm.at(mole.contact.at(j).a2).Label.toStdString().c_str());*/
8033 if ((istDonor.contains(mole.contact.at(j).a1)||(!keinDonor.contains(mole.contact.at(j).a1)))
8034 &&(mole.asymm.at(mole.contact.at(j).a1).an==7)) {
8035 if (keinDonor.contains(mole.contact.at(j).a1)) continue;
8036 if (fxle->n5) {
8037 htest = findOH(mole.cell.symmops.at(mole.contact.at(j).sn) * mole.asymm.at(mole.contact.at(j).a1).frac
8038 + mole.cell.trans.at(mole.contact.at(j).sn) - mole.contact.at(j).floorD,
8039 mole.asymm.at(mole.contact.at(j).a2).frac,
8040 mole.contact.at(j).a1,alab);
8041
8042 /*printf("LINE %d %s %s\n",__LINE__,
8043 mole.asymm.at(mole.contact.at(j).a1).Label.toStdString().c_str(),
8044 mole.asymm.at(mole.contact.at(j).a2).Label.toStdString().c_str());*/
8045
8046 if (Distance(htest.pos,V3(0,0,0))<0.001){
8047 htest = findOH(mole.asymm.at(mole.contact.at(j).a1).frac,
8048 mole.cell.symmops.at(mole.contact.at(j).sn) * mole.asymm.at(mole.contact.at(j).a2).frac
8049 + mole.cell.trans.at(mole.contact.at(j).sn) ,
8050 mole.contact.at(j).a1,alab);
8051 /* printf("LINE %d %s %s\n",__LINE__,
8052 mole.asymm.at(mole.contact.at(j).a1).Label.toStdString().c_str(),
8053 mole.asymm.at(mole.contact.at(j).a2).Label.toStdString().c_str());*/
8054 // if (Distance(htest.pos,V3(0,0,0))<0.001){ keinDonor[mole.contact.at(j).a2]++; }
8055 } else {
8056 keinDonor[mole.contact.at(j).a1]++;
8057 // qDebug()<<"done"<<mole.asymm.at(mole.contact.at(j).a2).Label;
8058 }
8059 if (Distance(htest.pos,V3(0,0,0))){
8060 htest.orginalLine=QString("%1 %2 %3 %4 %5 %6 %7")
8061 .arg(htest.Label)
8062 .arg(qMax(1,editor->sfac.indexOf(0)+1))
8063 .arg(htest.frac.x,9,'f',5)
8064 .arg(htest.frac.y,9,'f',5)
8065 .arg(htest.frac.z,9,'f',5)
8066 .arg(mole.asymm.at(mole.contact.at(j).a1).sof_org)
8067 .arg("-1.5");
8068 mole.asymm.append(htest);
8069 QString label = mole.showatoms.at(mole.contact.at(j).a1).orginalLine.left(80).trimmed();
8070 // int afixfuenf=(mole.showatoms.at(mole.contact.at(j).a1).afix/10)?(mole.showatoms.at(mole.contact.at(j).a1).afix/10)*10+5:0;
8071 cursor.movePosition(QTextCursor::Start);
8072 cursor = document->find(label,cursor);
8073 if (cursor.isNull()){
8074 cursor = editor->textCursor();
8075 cursor.movePosition(QTextCursor::Start);
8076 label.chop(10);
8077 cursor = document->find(label,cursor);
8078 if (cursor.isNull()) {
8079 cursor = editor->textCursor();
8080 }
8081 }
8082 cursor.movePosition(QTextCursor::StartOfLine,QTextCursor::MoveAnchor);
8083 cursor.movePosition(QTextCursor::EndOfLine,QTextCursor::KeepAnchor);
8084 while (cursor.selectedText().endsWith("=")) {
8085 cursor.movePosition(QTextCursor::Down,QTextCursor::KeepAnchor);
8086 cursor.movePosition(QTextCursor::EndOfLine,QTextCursor::KeepAnchor);
8087 }
8088 cursor.clearSelection();
8089 cursor.movePosition(QTextCursor::Down);
8090 cursor.insertText(QString("AFIX 148\n%1\nAFIX %2\n")
8091 .arg(mole.asymm.last().orginalLine)
8092 .arg(mole.afix5(mole.contact.at(j).a1))
8093 );
8094 }//Dist
8095 }//fxle->n5
8096 }// is O is in list of donors and not in list of no donors
8097
8098 }// all contacts
8099 cursor.endEditBlock();
8100 if (gehtMichAn.size()) gehtMichAn.takeLast();
8101 if (mole.asymm.size()!=warmal){
8102 gehtMichAn.append(mole.asymm.size()-warmal+2);
8103 }
8104
8105 int jetztAtome=0;
8106 for (int i=0; i<mole.asymm.size();i++) if (mole.asymm.at(i).an>=0)jetztAtome++;
8107 actionHFix->setDisabled(true);
8108 fuse();
8109 QString info=QString("<font color=\"green\"><b>%1</b> Hydrogen atoms added. <h2>Please SAVE NOW!</h2></font>").arg(jetztAtome-warmalAtome);
8110 infoKanalNews(info);
8111
8112 switch (duplicates()){
8113 case 1:infoKanalNews("<font color=orange >Some hydrogen atoms have identical names please check.</font>");break;
8114 case 2:infoKanalNews("<font color=red >Some non-hydrogen atoms have identical names. YOU HAVE TO CHECK BEFORE REFINING!</font>");break;
8115 case 3:infoKanalNews("<font color=red >Some atoms have identical names. YOU HAVE TO CHECK BEFORE REFINING!</font>");break;
8116 }
8117 chgl->update();
8118 }
8119
8120 MyAtom Window::findOH(V3 donor, V3 acceptor,int dindex,QStringList alab){
8121 CEnvironment peaks;
8122 QString nn;
8123 peaks.clear();
8124 double minGoofy=100000.0,g=0;
8125 int minG=0;
8126 V3 mdz=(0.5*fxle->dx)+(0.5*fxle->dy)+(0.5*fxle->dz);
8127 V3 df=donor;
8128 V3 af=acceptor;
8129 if (mole.fl(af.x-df.x, af.y-df.y,af.z-df.z)>3.3){
8130 V3 floors;
8131 floors = af-df+ V3(0.5,0.5,0.5);
8132 floors = V3(floor(floors.x),floor(floors.y),floor(floors.z));
8133 af+=-1.0*floors;
8134 }
8135 double ad=mole.fl(af.x-df.x, af.y-df.y,af.z-df.z);
8136 MyAtom htest;
8137 htest.an=0;
8138 htest.part=0;
8139 htest.resiNr=0;
8140 htest.hidden=0;
8141 htest.Label=mole.asymm.at(dindex).Label.section('_',0,0);
8142 htest.part=mole.asymm.at(dindex).part;
8143 htest.resiNr=mole.asymm.at(dindex).resiNr;
8144 htest.Label.replace(0,1,'H');
8145 int hindex=0;
8146 QString nnn=htest.Label;
8147 do {
8148 if (hindex) nnn=htest.Label.left(3).append(QString::number(hindex+9,36));
8149 if (nnn.size()>4) nnn=htest.Label.left(2).append(QString::number(hindex+9,36));
8150 if (htest.resiNr)
8151 nn=QString("%1_%2")//for shelxl same names in different parts are no problem but for platon so this should fix it.
8152 .arg(nnn)
8153 .arg((htest.resiNr)?QString::number(htest.resiNr):"");
8154 else nn=nnn;
8155 // qDebug()<<nn<<nnn<<(alab.contains(nn,Qt::CaseInsensitive));
8156 hindex++;
8157 }while(alab.contains(nn,Qt::CaseInsensitive));
8158 htest.Label=nnn;
8159 alab.append(nn);
8160 htest.symmGroup=0;
8161 htest.sg=0;
8162 htest.scod=555;//the identity
8163 htest.auidx=-1;
8164 htest.frac=V3(0,0,0);
8165 htest.pos=V3(0,0,0);
8166 htest.isIso=true;
8167 htest.ufiso_org=QString("-1.5");
8168 double uIso = mole.ueq(mole.asymm.at(dindex).uf)*1.5;
8169 htest.uf.m11 = htest.uf.m22 = htest.uf.m33 = uIso;
8170 htest.uf.m23 = uIso * mole.cell.cosra;
8171 htest.uf.m13 = uIso * mole.cell.cosrb;
8172 htest.uf.m12 = uIso * mole.cell.cosrg;
8173 mole.Uf2Uo(htest.uf,htest.uc);
8174 if (fxle->n5==0) return htest;
8175 double x,y,z,u,v,w,p,q,r,t;
8176 for (int k=0;k<fxle->n3;k++){
8177 for (int j=0;j<fxle->n2;j++){
8178 for (int i=0;i<fxle->n1;i++){
8179 V3 o= (i*fxle->dx+j*fxle->dy+k*fxle->dz) + mdz;
8180 mole.kart2frac(o,o);
8181 V3 floors;
8182 floors = o-df+ V3(0.5,0.5,0.5);
8183 floors = V3(floor(floors.x),floor(floors.y),floor(floors.z));
8184 o+=-1.0*floors;
8185 double ha,hd;
8186 hd=mole.fl(df.x-o.x, df.y-o.y,df.z-o.z);
8187 ha=mole.fl(af.x-o.x, af.y-o.y,af.z-o.z);
8188 if (1.2<hd) continue;//donor H must be smaller 1.2 A
8189 if (2.6<ha) continue;//donor H must be smaller 2.6 A
8190 if (hd<0.6) continue;//donor H must be greater 0.6 A
8191 if (((ha*ha+hd*hd-ad*ad)/(2*hd*ha))>-0.57)continue; //angle greater 125deg ok!
8192 t = fxle->datfo_fc[i+ fxle->n1*(j+k*fxle->n2)];
8193 x = t - fxle->datfo_fc[((i+1)%fxle->n1) + fxle->n1*(j+k*fxle->n2)];
8194 y = t - fxle->datfo_fc[i+ fxle->n1*(((j+1)%fxle->n2)+k*fxle->n2)];
8195 z = t - fxle->datfo_fc[i+ fxle->n1*(j+((k+1)%fxle->n3)*fxle->n2)];
8196 u = t - fxle->datfo_fc[((i+fxle->n1-1)%fxle->n1)+ fxle->n1*(j+k*fxle->n2)];
8197 v = t - fxle->datfo_fc[i+ fxle->n1*(((j+fxle->n2-1)%fxle->n2)+k*fxle->n2)];
8198 w = t - fxle->datfo_fc[i+ fxle->n1*(j+((k+fxle->n2-1)%fxle->n3)*fxle->n2)];
8199 if (fmin(x,fmin(y,fmin(z,fmin(u,fmin(v,w)))))<0) continue;//if this is not a maximum then skip
8200 p=0.5*(u-x)/(u+x);
8201 q=0.5*(v-y)/(v+y);
8202 r=0.5*(w-z)/(w+z);
8203 t=t+0.25*(p*(u-x)+q*(v-y)+r*(w-z));
8204 if (t<fabs(fxle->iso[1])*1.2) continue;// if this is below the green iso surface then skip
8205 htest.peakHeight=t;
8206 htest.frac.x = ((double) i + p +0.5)/fxle->n1;
8207 htest.frac.y = ((double) j + q +0.5)/fxle->n2;
8208 htest.frac.z = ((double) k + r +0.5)/fxle->n3;
8209 hd=mole.fl(df.x-htest.frac.x, df.y-htest.frac.y,df.z-htest.frac.z);
8210 ha=mole.fl(af.x-htest.frac.x, af.y-htest.frac.y,af.z-htest.frac.z);
8211 if (hd<0.6) continue;//to close to donor
8212 g=(ha+hd)/htest.peakHeight;
8213 minG=(g<minGoofy)?peaks.size():minG;
8214 minGoofy=(g<minGoofy)?g:minGoofy;
8215 mole.frac2kart( htest.frac, htest.pos);
8216 peaks.append(htest);
8217 }
8218 }
8219 }
8220 if (peaks.isEmpty()) {
8221 htest.frac=htest.pos=V3(0,0,0);
8222 return htest;
8223 }
8224 V3 D,floorD,prime,nf,dp;
8225 double min=1000,dk=0;
8226 for (int nn=0;nn<mole.cell.symmops.size(); nn++){
8227 prime=mole.cell.symmops.at(nn) * peaks.at(minG).frac + mole.cell.trans.at(nn);
8228 D=prime - mole.asymm.at(dindex).frac + V3(0.5,0.5,0.5) ;
8229 floorD=V3(floor(D.x),floor(D.y),floor(D.z));
8230 dp=D - floorD - V3(0.5,0.5,0.5);
8231 dk=mole.fl(dp.x,dp.y,dp.z);
8232 if (dk<min){
8233 min=dk;
8234 nf=prime-floorD;
8235 }
8236 }
8237 peaks[minG].frac=nf;
8238 mole.frac2kart(peaks[minG].frac,peaks[minG].pos);
8239 return peaks[minG];
8240 }
8241
8242 void Window::invert(){
8243 if (mole.asymm.isEmpty()) return;
8244 //inverting structure
8245 QList<V3> moves;
8246 moves.append(V3(1,1,1));//most of the space groups
8247 moves.append(V3(1,0.5,1));//I41, I41md, I41cd
8248 moves.append(V3(1,0.5,0.25));//I4122, I-42d
8249 moves.append(V3(0.25,0.25,1));//Fdd2
8250 moves.append(V3(0.25,0.25,0.25));//F4132
8251 int enantio=0;
8252 QString kep,nextli;
8253 QTextDocument *document = editor->document();
8254 QTextCursor cursor = editor->textCursor();
8255 cursor.beginEditBlock ();
8256 if ((!mole.cell.centered)&&(!mole.cell.centeric)){
8257 for (int i=0; i<mole.cell.trans.size(); i++){
8258 V3 t = V3(1,1,1) - mole.cell.trans.at(i);
8259 t.x=fmod(t.x,1);
8260 t.y=fmod(t.y,1);
8261 t.z=fmod(t.z,1);
8262 if (!(t==mole.cell.trans.at(i))) {
8263 enantio++;
8264 mole.cell.trans[i]=t;
8265 }
8266
8267 }
8268 }
8269 if (enantio){
8270
8271 editor->replace->setText("REM SYMM ");
8272 editor->searchLE->setText("^SYMM ");
8273 editor->replaceAll();
8274 cursor.movePosition(QTextCursor::Start,QTextCursor::MoveAnchor);
8275 cursor = document->find("REM SYMM",cursor);
8276 cursor.movePosition(QTextCursor::StartOfLine,QTextCursor::MoveAnchor);
8277 for (int i=1; i<mole.cell.symmops.size(); i++){
8278 cursor.insertText(QString("SYMM %1\n").arg(mole.symmcode2human(i)));
8279 }
8280
8281 cursor.insertText("REM enantiomorph space group. SYMM cards changed!\n");
8282 editor->searchLE->setText("");
8283 editor->replace->setText("");
8284 }
8285 //qDebug("test %d\n",enantio);
8286 V3 testP=V3(0.3234,0.2234,0.1234);
8287 QList<V3> tps,ips;
8288 Matrix inv(-1.0,0.0,0.0, 0.0,-1.0,0.0, 0.0,0.0,-1.0);
8289 for (int n=0;n<mole.cell.symmops.size(); n++){
8290 V3 pt=mole.cell.symmops.at(n) * testP + mole.cell.trans.at(n);
8291 ips.append(pt);
8292 }
8293 int kkk=0,jjj=0,mo=0;
8294 if (mole.cell.centered) do{
8295 kkk=jjj=0;
8296 tps.clear();
8297 for (int z=0; z<ips.size();z++){
8298 V3 pt=inv*ips.at(z)+moves.at(mo);
8299 tps.append(pt);
8300 }
8301 double dk;
8302 V3 prime,dp,D,floorD;
8303 for (int i=0; i<tps.size();i++){
8304 for (int j=0; j<tps.size();j++){
8305 for (int n=0;n<mole.cell.symmops.size(); n++){
8306 prime=mole.cell.symmops.at(n) * tps.at(i) + mole.cell.trans.at(n);
8307 D=prime - tps.at(j)+ V3(0.5,0.5,0.5) ;
8308 floorD=V3(floor(D.x),floor(D.y),floor(D.z));
8309 dp=D - floorD - V3(0.5,0.5,0.5);
8310 dk=mole.fl(dp.x,dp.y,dp.z);
8311 if (dk<0.1) kkk++;
8312 }
8313 }
8314 }
8315 for (int i=0; i<ips.size();i++){
8316 for (int j=0; j<ips.size();j++){
8317 for (int n=0;n<mole.cell.symmops.size(); n++){
8318 prime=mole.cell.symmops.at(n) * ips.at(i) + mole.cell.trans.at(n);
8319 D=prime - ips.at(j)+ V3(0.5,0.5,0.5) ;
8320 floorD=V3(floor(D.x),floor(D.y),floor(D.z));
8321 dp=D - floorD - V3(0.5,0.5,0.5);
8322 dk=mole.fl(dp.x,dp.y,dp.z);
8323 if (dk<0.1) jjj++;
8324 }
8325 }
8326 }
8327 mo++;
8328 }while (kkk-jjj);
8329 if (mo) mo--;
8330 //printf("Move : %g %g %g\n",moves.at(mo).x,moves.at(mo).y,moves.at(mo).z);
8331 for (int i = 0; i < mole.asymm.size(); i++){
8332 V3 f = inv * mole.asymm.at(i).frac + moves.at(mo);
8333 mole.asymm[i].frac=f;
8334 mole.frac2kart(mole.asymm.at(i).frac,mole.asymm[i].pos);
8335
8336 if (mole.asymm.at(i).an==-1) continue;
8337 QString source,target;
8338 source=mole.asymm.at(i).Label;
8339 target=source.section(QString::fromUtf8("»"),0,0);
8340 MyAtom ato=mole.asymm.at(i);
8341 ato.Label=target;
8342 ato.symmGroup=0;
8343 ato.sg=0;
8344 ato.scod=555;//the identity
8345 ato.auidx=-1;
8346 int that=mole.asymm.indexOf(ato);
8347 if ((that>=mole.asymm.size())||(that<0)) return;
8348 QString susu=mole.asymm.at(that).orginalLine;
8349 cursor.movePosition(QTextCursor::Start);
8350 cursor = document->find(susu,cursor);
8351 if (mole.asymm.at(that).isIso){
8352 ato.ufiso_org=mole.asymm.at(that).ufiso_org;
8353 kep=QString("%1 %2 %3 %4 %5 %6 %7")
8354 .arg(ato.Label.section('_',0,0),-5)
8355 .arg(qMax(1,editor->sfac.indexOf(ato.an)+1))
8356 .arg(ato.frac.x,10,'f',6)
8357 .arg(ato.frac.y,10,'f',6)
8358 .arg(ato.frac.z,10,'f',6)
8359 .arg(mole.asymm.at(that).sof_org,9,'f',5)
8360 .arg(ato.ufiso_org)
8361 ;
8362 cursor.deleteChar();
8363 cursor.insertText(kep);
8364 cursor.setPosition(cursor.position(), QTextCursor::MoveAnchor);
8365 ato.sof_org=mole.asymm.at(that).sof_org;
8366 // printf("debug:iso sof==%g atom#%d mole.asymm.at(that).afixParent %d \n",mole.asymm.at(that).sof_org,that,mole.asymm.at(that).afixParent);
8367 ato.uf= mole.asymm.at(that).uf;
8368 ato.uc= mole.asymm.at(that).uc;
8369 ato.isIso=true;
8370 editor->wholeLine->setChecked(false);
8371 editor->replaceNext();
8372 }else{
8373 kep=QString("%1 %2 %3 %4 %5 %6 %7 %8 ")
8374 .arg(ato.Label.section('_',0,0),-5)
8375 .arg(qMax(1,editor->sfac.indexOf(ato.an)+1))
8376 .arg(ato.frac.x,10,'f',6)
8377 .arg(ato.frac.y,10,'f',6)
8378 .arg(ato.frac.z,10,'f',6)
8379 .arg(mole.asymm.at(that).sof_org,9,'f',5)
8380 .arg(ato.uf.m11,9,'f',5)
8381 .arg(ato.uf.m22,9,'f',5);
8382 // printf("debug:anis sof==%g atom#%d\n",mole.asymm.at(that).sof_org,that);
8383 ato.sof_org=mole.asymm.at(that).sof_org;
8384 cursor.deleteChar();
8385 cursor.insertText(kep);
8386 cursor.setPosition(cursor.position(), QTextCursor::MoveAnchor);
8387 cursor.movePosition(QTextCursor::Down);
8388 cursor.movePosition(QTextCursor::StartOfLine,QTextCursor::MoveAnchor);
8389 cursor.movePosition(QTextCursor::EndOfLine,QTextCursor::KeepAnchor);
8390 nextli=cursor.selectedText();
8391 cursor = document->find(nextli,cursor);
8392
8393 cursor.deleteChar();
8394 cursor.insertText(QString(" %1 %2 %3 %4")
8395 .arg(ato.uf.m33,9,'f',5)
8396 .arg(ato.uf.m23,9,'f',5)
8397 .arg(ato.uf.m13,9,'f',5)
8398 .arg(ato.uf.m12,9,'f',5));
8399 cursor.setPosition(cursor.position(), QTextCursor::MoveAnchor);
8400 }
8401 ato.orginalLine=kep.section("=",0,0);
8402 mole.asymm[that]=ato;
8403 }
8404
8405 cursor = editor->textCursor();
8406 cursor.endEditBlock();
8407
8408 mole.showatoms.clear();
8409 mole.showbonds.clear();
8410 chgl->mol->showatoms.clear();
8411 chgl->mol->showbonds.clear();
8412 chgl->mol->selectedatoms.clear();
8413 for (int o=0; o<mole.asymm.size();o++)
8414 mole.showatoms.append(mole.asymm[o]);
8415 mole.sdmcompleter();
8416 mole.showbonds =
8417 mole.connecting(mole.showatoms);
8418 chgl->setMolecule(&mole);
8419 loadMolInTest();
8420
8421 chgl->mol->selectedatoms.clear();
8422
8423 bool growYes=chgl->fuse->isVisible ();
8424 chgl->mol->fuse();
8425 if (growYes) chgl->mol->grow();
8426 editor->searchLE->setText("");
8427 editor->hideSearch();
8428
8429 // printf("%d\n",__LINE__);
8430
8431 loadMolInTest();
8432 chgl->update();
8433 update();
8434
8435 }
8436
8437 void Window::addDissorderedMethyl(){//127
8438 QAction *action = qobject_cast<QAction *>(sender());
8439 int i=0;
8440 if (action)
8441 i=action->data().toInt();
8442 else return;
8443 if (i>mole.asymm.size()) return;
8444 int warmalAtome=0;
8445 for (int i=0; i<mole.asymm.size();i++) if (mole.asymm.at(i).an>=0)warmalAtome++;
8446
8447 chgl->disSelection();
8448 MyAtom htest,qtest;
8449 QStringList alab;
8450 for (int i =0; i<mole.asymm.size(); i++){
8451 alab.append(mole.asymm.at(i).Label);
8452 }
8453 QString nn;
8454 if (editor->sfac.indexOf(0)==-1)addNewScatteringFactor(0,false);
8455 htest.an=0;
8456 htest.part=0;
8457 htest.resiNr=0;
8458 htest.hidden=0;
8459 htest.symmGroup=0;
8460 htest.sg=0;
8461 htest.scod=555;//the identity
8462 htest.auidx=-1;
8463 htest.isIso=true;
8464 htest.uc.m11=htest.uc.m22=htest.uc.m33=0.05;
8465 htest.uc.m12=htest.uc.m23=htest.uc.m13=0.0;
8466 htest.uc.m21=htest.uc.m32=htest.uc.m31=0.0;
8467 htest.uf.m12=htest.uf.m23=htest.uf.m13=0.0;
8468 htest.uf.m21=htest.uf.m32=htest.uf.m31=0.0;
8469 qtest=htest;
8470 qtest.an=-1;
8471 QTextDocument *document = editor->document();
8472 QTextCursor cursor = editor->textCursor();
8473 cursor.beginEditBlock ();
8474 // !!!Neue Freie Variable anlegen!!!
8475 cursor.movePosition(QTextCursor::End);
8476 cursor = document->find("FVAR",cursor,QTextDocument::FindBackward);
8477 cursor.movePosition(QTextCursor::StartOfLine,QTextCursor::MoveAnchor);
8478 cursor.movePosition(QTextCursor::EndOfLine,QTextCursor::KeepAnchor);
8479 while (cursor.selectedText().endsWith("=")) {
8480 cursor.movePosition(QTextCursor::Down,QTextCursor::KeepAnchor);
8481 cursor.movePosition(QTextCursor::EndOfLine,QTextCursor::KeepAnchor);
8482 }
8483 QString fvstr = cursor.selectedText().trimmed();
8484 fvstr.append(" 0.666 ");
8485 fvar.append(0.667);
8486 cursor.deleteChar();
8487 cursor.insertText(fvstr);
8488 updateTieFreeVar();
8489 int frei=fvar.size();
8490 // !!!!
8491 double xh[8]={
8492 0.98,//1
8493 0.97,//2
8494 0.96,//3
8495 0.93,//4
8496 1.10,//15 B
8497 0.82,//8 O
8498 0.93,//9
8499 0.93// 16
8500 };
8501 V3 v=V3(0,0,0),w=V3(0,0,0),u=V3(0,0,0) ,a=V3(0,0,0);//,b=V3(0,0,0),c=V3(0,0,0);
8502 a = mole.showatoms.at(mole.knoepfe.at(i).neighbors.at(0)).pos - mole.asymm.at(i).pos;
8503 int ji,ki,li;
8504 a=Normalize(a);
8505 double jx,kx,lx,mx,my,mz;
8506 double val[24],merg[4],wink=0,t=0,mt=0;
8507 for (int z=0; z<4;z++) merg[z]=0;
8508 if (fxle->n5){
8509 for (int z=0; z<24; z++){
8510 w=Normalize(V3(0,0,1)%a);
8511 u=Normalize(w%a);
8512 v=(-(xh[2])*0.33333*a)+ mole.asymm.at(i).pos+(xh[2])*0.942809041582*(sin(wink)*u+cos(wink)*w);
8513 qtest.pos=v;
8514 mole.kart2frac(v,v);
8515 int zplu=0;
8516 do {
8517 jx=((zplu+v.x)*fxle->n1+0.5);
8518 zplu++;
8519 }while (jx<0);
8520 zplu=0;
8521 do {
8522 kx=((zplu+v.y)*fxle->n2+0.5);
8523 zplu++;
8524 }while (kx<0);
8525 zplu=0;
8526 do {
8527 lx=((zplu+v.z)*fxle->n3+0.5);
8528 zplu++;
8529 }while (lx<0);
8530 mx=jx-floor(jx);
8531 my=kx-floor(kx);
8532 mz=lx-floor(lx);
8533 ji=((int)jx)%fxle->n1;//
8534 ki=((int)kx)%fxle->n2;//
8535 li=((int)lx)%fxle->n3;//
8536 merg[z%4]+=val[z]=(
8537 (1-mx)*fxle->datfo_fc[(ji+fxle->n1*(ki+li*fxle->n2))%fxle->n5]+
8538 mx*fxle->datfo_fc[((ji+1)+fxle->n1*(ki+li*fxle->n2))%fxle->n5]+
8539 (1-my)*fxle->datfo_fc[(ji+fxle->n1*(ki+li*fxle->n2))%fxle->n5]+
8540 my*fxle->datfo_fc[(ji+fxle->n1*((ki+1)+li*fxle->n2))%fxle->n5]+
8541 (1-mz)*fxle->datfo_fc[(ji+fxle->n1*(ki+li*fxle->n2))%fxle->n5]+
8542 mz*fxle->datfo_fc[(ji+fxle->n1*(ki+(li+1)*fxle->n2))%fxle->n5])/3.0;
8543 qtest.peakHeight=val[z];
8544 qtest.frac=v;
8545 qtest.Label=QString("Q%1").arg(z,-3);
8546 mole.pmin=qMin(mole.pmin, qtest.peakHeight);
8547 mole.pmax=qMax(mole.pmax, qtest.peakHeight);
8548 qpv->cutoff=0;//mole.pmin;
8549 qpv->setMin(mole.pmin);
8550 qpv->setMax(mole.pmax);
8551 mole.asymm.append(qtest);
8552 wink+=0.261799387799;
8553 }
8554 for (int z=0; z<4;z++) {
8555 t =merg[(z+4)%4] ;
8556 double x = t - merg[(z+5)%4];
8557 double u = t - merg[(z+3)%4];
8558 if (fmin(x,u)<0) continue;
8559 double p=0.5*(u-x)/(u+x);
8560 t=t+0.25*(p*(u-x));
8561 mt=(mt>t)?mt:t;
8562 if (t<mt)continue;
8563 wink=((double) z + p )*0.261799387799;
8564 }
8565 }else{
8566 int zzz=0;
8567 int z=mole.knoepfe.at(mole.knoepfe.at(i).neighbors.at(0)).neighbors.at(zzz++);
8568 while ((z==i)&&(zzz<mole.knoepfe.at(mole.knoepfe.at(i).neighbors.at(0)).neighbors.size())) {
8569 z=mole.knoepfe.at(mole.knoepfe.at(i).neighbors.at(0)).neighbors.at(zzz++);
8570 }
8571 w=Normalize(V3(0,0,1)%a);
8572 u=Normalize(w%a);
8573 v=(-(xh[2])*0.33333*a)+ mole.asymm.at(i).pos+(xh[2])*0.942809041582*(sin(wink)*u+cos(wink)*w);
8574 // if z == i then dieder() returns nan, because A in dieder gets (0,0,0)
8575 V3 increm = V3(0.0, 0.0, 0.0);
8576 if ( z == i ) {
8577 increm = V3(0.00001, 0.00001, 0.00001);
8578 }
8579 wink=mole.dieder(mole.showatoms.at(mole.knoepfe.at(i).neighbors.at(0)).pos+increm-mole.asymm.at(z).pos,
8580 mole.asymm.at(i).pos-mole.showatoms.at(mole.knoepfe.at(i).neighbors.at(0)).pos,
8581 v-mole.asymm.at(i).pos)/180.0*M_PI;
8582 }
8583 v=(-(xh[2])*0.33333*a)+ mole.asymm.at(i).pos+(xh[2])*0.942809041582*(sin(wink)*u+cos(wink)*w);
8584 htest.Label=mole.asymm.at(i).Label.section('_',0,0);
8585 htest.Label.replace(0,1,'H');
8586 int hindex=1;
8587 QString nnn=htest.Label;
8588 QString ann=htest.Label;
8589 do {
8590 if (hindex) nnn=ann.left(3).append(QString::number(hindex+9,36));
8591 if (nnn.size()>4) nnn=ann.left(2).append(QString::number(hindex+9,36));
8592 if (htest.resiNr)
8593 nn=QString("%1_%2")//for shelxl same names in different parts are no problem but for platon so this should fix it.
8594 .arg(nnn)
8595 .arg((htest.resiNr)?QString::number(htest.resiNr):"");
8596 else nn=nnn;
8597 // qDebug()<<nn<<nnn<<(alab.contains(nn,Qt::CaseInsensitive));
8598 hindex++;
8599 }while(alab.contains(nn,Qt::CaseInsensitive));
8600 htest.Label=nnn;
8601 alab.append(nn);
8602
8603 htest.part=mole.asymm.at(i).part;
8604 htest.resiNr=mole.asymm.at(i).resiNr;
8605 htest.isIso=true;
8606 htest.ufiso_org=QString("-1.5");
8607 double uIso = mole.ueq(mole.asymm.at(i).uf)*1.5;
8608 htest.uf.m11 = htest.uf.m22 = htest.uf.m33 = uIso;
8609 htest.uf.m23 = uIso * mole.cell.cosra;
8610 htest.uf.m13 = uIso * mole.cell.cosrb;
8611 htest.uf.m12 = uIso * mole.cell.cosrg;
8612 mole.Uf2Uo(htest.uf,htest.uc);
8613 htest.pos=v;
8614 mole.kart2frac(htest.pos,htest.frac);
8615 htest.orginalLine=QString("%1 %2 %3 %4 %5 %6 %7")
8616 .arg(htest.Label)
8617 .arg(qMax(1,editor->sfac.indexOf(0)+1))
8618 .arg(htest.frac.x,9,'f',5)
8619 .arg(htest.frac.y,9,'f',5)
8620 .arg(htest.frac.z,9,'f',5)
8621 .arg(mole.asymm.at(i).sof+10*frei)
8622 .arg("-1.5");
8623 mole.asymm.append(htest);
8624 wink+=1.04719755119;
8625 v=(-(xh[2])*0.33333*a)+ mole.asymm.at(i).pos+(xh[2])*0.942809041582*(sin(wink)*u+cos(wink)*w);
8626 hindex+=2;
8627 do {
8628 if (hindex) nnn=ann.left(3).append(QString::number(hindex+9,36));
8629 if (nnn.size()>4) nnn=ann.left(2).append(QString::number(hindex+9,36));
8630 if (htest.resiNr)
8631 nn=QString("%1_%2")//for shelxl same names in different parts are no problem but for platon so this should fix it.
8632 .arg(nnn)
8633 .arg((htest.resiNr)?QString::number(htest.resiNr):"");
8634 else nn=nnn;
8635 // qDebug()<<nn<<nnn<<(alab.contains(nn,Qt::CaseInsensitive));
8636 hindex++;
8637 }while(alab.contains(nn,Qt::CaseInsensitive));
8638 hindex-=3;
8639 htest.Label=nnn;
8640 alab.append(nn);
8641 htest.pos=v;
8642 mole.kart2frac(htest.pos,htest.frac);
8643 htest.orginalLine=QString("%1 %2 %3 %4 %5 %6 %7")
8644 .arg(htest.Label)
8645 .arg(qMax(1,editor->sfac.indexOf(0)+1))
8646 .arg(htest.frac.x,9,'f',5)
8647 .arg(htest.frac.y,9,'f',5)
8648 .arg(htest.frac.z,9,'f',5)
8649 .arg(-1*(mole.asymm.at(i).sof+10*frei))
8650 .arg("-1.5");
8651 mole.asymm.append(htest);
8652 wink+=1.04719755119;
8653 v=(-(xh[2])*0.33333*a)+ mole.asymm.at(i).pos+(xh[2])*0.942809041582*(sin(wink)*u+cos(wink)*w);
8654 do {
8655 if (hindex) nnn=ann.left(3).append(QString::number(hindex+9,36));
8656 if (nnn.size()>4) nnn=ann.left(2).append(QString::number(hindex+9,36));
8657 if (htest.resiNr)
8658 nn=QString("%1_%2")//for shelxl same names in different parts are no problem but for platon so this should fix it.
8659 .arg(nnn)
8660 .arg((htest.resiNr)?QString::number(htest.resiNr):"");
8661 else nn=nnn;
8662 // qDebug()<<nn<<nnn<<(alab.contains(nn,Qt::CaseInsensitive));
8663 hindex++;
8664 }while(alab.contains(nn,Qt::CaseInsensitive));
8665 htest.Label=nnn;
8666 hindex+=2;
8667 alab.append(nn);
8668 htest.pos=v;
8669 mole.kart2frac(htest.pos,htest.frac);
8670 htest.orginalLine=QString("%1 %2 %3 %4 %5 %6 %7")
8671 .arg(htest.Label)
8672 .arg(qMax(1,editor->sfac.indexOf(0)+1))
8673 .arg(htest.frac.x,9,'f',5)
8674 .arg(htest.frac.y,9,'f',5)
8675 .arg(htest.frac.z,9,'f',5)
8676 .arg(mole.asymm.at(i).sof+10*frei)
8677 .arg("-1.5");
8678 mole.asymm.append(htest);
8679 wink+=1.04719755119;
8680 v=(-(xh[2])*0.33333*a)+ mole.asymm.at(i).pos+(xh[2])*0.942809041582*(sin(wink)*u+cos(wink)*w);
8681 do {
8682 if (hindex) nnn=ann.left(3).append(QString::number(hindex+9,36));
8683 if (nnn.size()>4) nnn=ann.left(2).append(QString::number(hindex+9,36));
8684 if (htest.resiNr)
8685 nn=QString("%1_%2")//for shelxl same names in different parts are no problem but for platon so this should fix it.
8686 .arg(nnn)
8687 .arg((htest.resiNr)?QString::number(htest.resiNr):"");
8688 else nn=nnn;
8689 // qDebug()<<nn<<nnn<<(alab.contains(nn,Qt::CaseInsensitive));
8690 hindex++;
8691 }while(alab.contains(nn,Qt::CaseInsensitive));
8692 htest.Label=nnn;
8693 alab.append(nn);
8694 htest.pos=v;
8695 hindex-=3;
8696 mole.kart2frac(htest.pos,htest.frac);
8697 htest.orginalLine=QString("%1 %2 %3 %4 %5 %6 %7")
8698 .arg(htest.Label)
8699 .arg(qMax(1,editor->sfac.indexOf(0)+1))
8700 .arg(htest.frac.x,9,'f',5)
8701 .arg(htest.frac.y,9,'f',5)
8702 .arg(htest.frac.z,9,'f',5)
8703 .arg(-1*(mole.asymm.at(i).sof+10*frei))
8704 .arg("-1.5");
8705 mole.asymm.append(htest);
8706 wink+=1.04719755119;
8707 v=(-(xh[2])*0.33333*a)+ mole.asymm.at(i).pos+(xh[2])*0.942809041582*(sin(wink)*u+cos(wink)*w);
8708 do {
8709 if (hindex) nnn=ann.left(3).append(QString::number(hindex+9,36));
8710 if (nnn.size()>4) nnn=ann.left(2).append(QString::number(hindex+9,36));
8711 if (htest.resiNr)
8712 nn=QString("%1_%2")//for shelxl same names in different parts are no problem but for platon so this should fix it.
8713 .arg(nnn)
8714 .arg((htest.resiNr)?QString::number(htest.resiNr):"");
8715 else nn=nnn;
8716 // qDebug()<<nn<<nnn<<(alab.contains(nn,Qt::CaseInsensitive));
8717 hindex++;
8718 }while(alab.contains(nn,Qt::CaseInsensitive));
8719 htest.Label=nnn;
8720 alab.append(nn);
8721 htest.pos=v;
8722 hindex+=2;
8723 mole.kart2frac(htest.pos,htest.frac);
8724 htest.orginalLine=QString("%1 %2 %3 %4 %5 %6 %7")
8725 .arg(htest.Label)
8726 .arg(qMax(1,editor->sfac.indexOf(0)+1))
8727 .arg(htest.frac.x,9,'f',5)
8728 .arg(htest.frac.y,9,'f',5)
8729 .arg(htest.frac.z,9,'f',5)
8730 .arg(mole.asymm.at(i).sof+10*frei)
8731 .arg("-1.5");
8732 mole.asymm.append(htest);
8733 wink+=1.04719755119;
8734 v=(-(xh[2])*0.33333*a)+ mole.asymm.at(i).pos+(xh[2])*0.942809041582*(sin(wink)*u+cos(wink)*w);
8735 do {
8736 if (hindex) nnn=ann.left(3).append(QString::number(hindex+9,36));
8737 if (nnn.size()>4) nnn=ann.left(2).append(QString::number(hindex+9,36));
8738 if (htest.resiNr)
8739 nn=QString("%1_%2")//for shelxl same names in different parts are no problem but for platon so this should fix it.
8740 .arg(nnn)
8741 .arg((htest.resiNr)?QString::number(htest.resiNr):"");
8742 else nn=nnn;
8743 // qDebug()<<nn<<nnn<<(alab.contains(nn,Qt::CaseInsensitive));
8744 hindex++;
8745 }while(alab.contains(nn,Qt::CaseInsensitive));
8746 htest.Label=nnn;
8747 alab.append(nn);
8748 htest.pos=v;
8749 mole.kart2frac(htest.pos,htest.frac);
8750 htest.orginalLine=QString("%1 %2 %3 %4 %5 %6 %7")
8751 .arg(htest.Label)
8752 .arg(qMax(1,editor->sfac.indexOf(0)+1))
8753 .arg(htest.frac.x,9,'f',5)
8754 .arg(htest.frac.y,9,'f',5)
8755 .arg(htest.frac.z,9,'f',5)
8756 .arg(-1*(mole.asymm.at(i).sof+10*frei))
8757 .arg("-1.5");
8758 mole.asymm.append(htest);
8759 QString label = mole.showatoms.at(i).orginalLine.left(80).trimmed();
8760 // int afixfuenf=(mole.showatoms.at(i).afix/10)?(mole.showatoms.at(i).afix/10)*10+5:0;
8761 cursor.movePosition(QTextCursor::Start);
8762 cursor = document->find(label,cursor);
8763 if (cursor.isNull()){
8764 cursor = editor->textCursor();
8765 cursor.movePosition(QTextCursor::Start);
8766 label.chop(10);
8767 cursor = document->find(label,cursor);
8768 if (cursor.isNull()) {
8769 cursor = editor->textCursor();
8770 }
8771 }
8772 cursor.movePosition(QTextCursor::StartOfLine,QTextCursor::MoveAnchor);
8773 cursor.movePosition(QTextCursor::EndOfLine,QTextCursor::KeepAnchor);
8774 while (cursor.selectedText().endsWith("=")) {
8775 cursor.movePosition(QTextCursor::Down,QTextCursor::KeepAnchor);
8776 cursor.movePosition(QTextCursor::EndOfLine,QTextCursor::KeepAnchor);
8777 }
8778 cursor.clearSelection();
8779 cursor.movePosition(QTextCursor::Down);
8780 cursor.insertText(QString("AFIX 127\n%1\n%2\n%3\n%5\n%6\n%7\nAFIX %4\n")
8781 .arg(mole.asymm.at(mole.asymm.size()-6).orginalLine)
8782 .arg(mole.asymm.at(mole.asymm.size()-4).orginalLine)
8783 .arg(mole.asymm.at(mole.asymm.size()-2).orginalLine)
8784 .arg(mole.afix5(i))
8785 .arg(mole.asymm.at(mole.asymm.size()-5).orginalLine)//-
8786 .arg(mole.asymm.at(mole.asymm.size()-3).orginalLine)//-
8787 .arg(mole.asymm.at(mole.asymm.size()-1).orginalLine)//-
8788 );
8789
8790 cursor.endEditBlock();
8791 int jetztAtome=0;
8792 for (int i=0; i<mole.asymm.size();i++) if (mole.asymm.at(i).an>=0)jetztAtome++;
8793 actionHFix->setDisabled(true);
8794 fuse();
8795 QString info=QString("<font color=\"green\"><b>%1</b> Hydrogen atoms added. <b>Please SAVE before GROW!</font>").arg(jetztAtome-warmalAtome);
8796 infoKanalNews(info);
8797 }
8798
8799 void Window::addH43(){//43
8800 QAction *action = qobject_cast<QAction *>(sender());
8801 int i=0;
8802 if (action)
8803 i=action->data().toInt();
8804 else return;
8805 if (i>mole.asymm.size()) return;
8806 if (mole.knoepfe.at(i).neighbors.size()!=2)return;//we need 2 non h neighbors
8807 int warmalAtome=0;
8808 for (int j=0; j<mole.asymm.size();j++) if (mole.asymm.at(j).an>=0)warmalAtome++;
8809 QStringList alab;
8810 for (int i =0; i<mole.asymm.size(); i++){
8811 alab.append(mole.asymm.at(i).Label);
8812 }
8813 QString nn;
8814 double nh= (mole.asymm.at(i).an==6) ? 0.07 : 0;
8815
8816 chgl->disSelection();
8817 MyAtom htest,qtest;
8818 if (editor->sfac.indexOf(0)==-1)addNewScatteringFactor(0,false);
8819 htest.an=0;
8820 htest.part=0;
8821 htest.resiNr=0;
8822 htest.hidden=0;
8823 htest.symmGroup=0;
8824 htest.sg=0;
8825 htest.scod=555;//the identity
8826 htest.auidx=-1;
8827 htest.isIso=true;
8828 htest.uc.m11=htest.uc.m22=htest.uc.m33=0.05;
8829 htest.uc.m12=htest.uc.m23=htest.uc.m13=0.0;
8830 htest.uc.m21=htest.uc.m32=htest.uc.m31=0.0;
8831 htest.uf.m12=htest.uf.m23=htest.uf.m13=0.0;
8832 htest.uf.m21=htest.uf.m32=htest.uf.m31=0.0;
8833 qtest=htest;
8834 qtest.an=-1;
8835 QTextDocument *document = editor->document();
8836 QTextCursor cursor = editor->textCursor();
8837 cursor.beginEditBlock ();
8838 double xh[8]={
8839 0.98,//1
8840 0.97,//2
8841 0.96,//3
8842 0.93,//4
8843 1.10,//15 B
8844 0.82,//8 O
8845 0.93,//9
8846 0.93// 16
8847 };
8848
8849 double angle=0;
8850 V3 a=V3(0,0,0),b=V3(0,0,0),c=V3(0,0,0);
8851 a = mole.showatoms.at(mole.knoepfe.at(i).neighbors.at(0) ).pos - mole.asymm.at(i).pos;
8852 b = mole.showatoms.at(mole.knoepfe.at(i).neighbors.at(1) ).pos - mole.asymm.at(i).pos;
8853 a = c = Normalize(a) ;
8854 c = c+ (b= Normalize(b));
8855 angle=mole.winkel(a,b);
8856 c = Normalize(c);
8857 if (angle<160) {
8858 c = (-(xh[3]-nh) * c)+mole.asymm.at(i).pos;
8859 htest.Label=mole.asymm.at(i).Label.section('_',0,0);
8860 htest.part=mole.asymm.at(i).part;
8861 htest.resiNr=mole.asymm.at(i).resiNr;
8862 htest.Label.replace(0,1,'H');
8863 int hindex=0;
8864 QString nnn=htest.Label;
8865 do {
8866 if (hindex) nnn=htest.Label.left(3).append(QString::number(hindex+9,36));
8867 if (nnn.size()>4) nnn=htest.Label.left(2).append(QString::number(hindex+9,36));
8868 if (htest.resiNr)
8869 nn=QString("%1_%2")//for shelxl same names in different parts are no problem but for platon so this should fix it.
8870 .arg(nnn)
8871 .arg((htest.resiNr)?QString::number(htest.resiNr):"");
8872 else nn=nnn;
8873 // qDebug()<<nn<<nnn<<(alab.contains(nn,Qt::CaseInsensitive));
8874 hindex++;
8875 }while(alab.contains(nn,Qt::CaseInsensitive));
8876 htest.Label=nnn;
8877 alab.append(nn);
8878 htest.isIso=true;
8879 htest.ufiso_org=QString("-1.2");
8880 double uIso = mole.ueq(mole.asymm.at(i).uf)*1.2;
8881 htest.uf.m11 = htest.uf.m22 = htest.uf.m33 = uIso;
8882 htest.uf.m23 = uIso * mole.cell.cosra;
8883 htest.uf.m13 = uIso * mole.cell.cosrb;
8884 htest.uf.m12 = uIso * mole.cell.cosrg;
8885 mole.Uf2Uo(htest.uf,htest.uc);
8886 htest.pos=c;
8887 mole.kart2frac(htest.pos,htest.frac);
8888 htest.orginalLine=QString("%1 %2 %3 %4 %5 %6 %7")
8889 .arg(htest.Label)
8890 .arg(qMax(1,editor->sfac.indexOf(0)+1))
8891 .arg(htest.frac.x,9,'f',5)
8892 .arg(htest.frac.y,9,'f',5)
8893 .arg(htest.frac.z,9,'f',5)
8894 .arg(mole.asymm.at(i).sof_org)
8895 .arg("-1.2");
8896 mole.asymm.append(htest);
8897 QString label = mole.showatoms.at(i).orginalLine.left(80).trimmed();
8898 // int afixfuenf=(mole.showatoms.at(i).afix/10)?(mole.showatoms.at(i).afix/10)*10+5:0;
8899 cursor.movePosition(QTextCursor::Start);
8900 cursor = document->find(label,cursor);
8901 if (cursor.isNull()){
8902 cursor = editor->textCursor();
8903 cursor.movePosition(QTextCursor::Start);
8904 label.chop(10);
8905 cursor = document->find(label,cursor);
8906 if (cursor.isNull()) {
8907 cursor = editor->textCursor();
8908 }
8909 }
8910 cursor.movePosition(QTextCursor::StartOfLine,QTextCursor::MoveAnchor);
8911 cursor.movePosition(QTextCursor::EndOfLine,QTextCursor::KeepAnchor);
8912 while (cursor.selectedText().endsWith("=")) {
8913 cursor.movePosition(QTextCursor::Down,QTextCursor::KeepAnchor);
8914 cursor.movePosition(QTextCursor::EndOfLine,QTextCursor::KeepAnchor);
8915 }
8916 cursor.clearSelection();
8917 cursor.movePosition(QTextCursor::Down);
8918 cursor.insertText(QString("AFIX 43\n%1\nAFIX %2\n")
8919 .arg(mole.asymm.at(mole.asymm.size()-1).orginalLine)
8920 .arg(mole.afix5(i)));
8921 }//angle
8922 cursor.endEditBlock();
8923 int jetztAtome=0;
8924 for (int i=0; i<mole.asymm.size();i++) if (mole.asymm.at(i).an>=0)jetztAtome++;
8925 actionHFix->setDisabled(true);
8926 fuse();
8927 QString info=QString("<font color=\"green\"><b>%1</b> Hydrogen atoms added. <b>Please SAVE before GROW!</font>").arg(jetztAtome-warmalAtome);
8928 infoKanalNews(info);
8929 }//43
8930
8931 void Window::addH23(){//23
8932 QAction *action = qobject_cast<QAction *>(sender());
8933 int i=0;
8934 if (action)
8935 i=action->data().toInt();
8936 else return;
8937 if (i>mole.asymm.size()) return;
8938 if (mole.knoepfe.at(i).neighbors.size()!=2)return;//we need 2 non h neighbors
8939 int warmalAtome=0;
8940 for (int j=0; j<mole.asymm.size();j++) if (mole.asymm.at(j).an>=0)warmalAtome++;
8941 QStringList alab;
8942 for (int i =0; i<mole.asymm.size(); i++){
8943 alab.append(mole.asymm.at(i).Label);
8944 }
8945 QString nn;
8946 double nh= (mole.asymm.at(i).an==6) ? 0.07 : 0;
8947
8948 chgl->disSelection();
8949 MyAtom htest,qtest;
8950 if (editor->sfac.indexOf(0)==-1)addNewScatteringFactor(0,false);
8951 htest.an=0;
8952 htest.part=0;
8953 htest.resiNr=0;
8954 htest.hidden=0;
8955 htest.symmGroup=0;
8956 htest.sg=0;
8957 htest.scod=555;//the identity
8958 htest.auidx=-1;
8959 htest.isIso=true;
8960 htest.uc.m11=htest.uc.m22=htest.uc.m33=0.05;
8961 htest.uc.m12=htest.uc.m23=htest.uc.m13=0.0;
8962 htest.uc.m21=htest.uc.m32=htest.uc.m31=0.0;
8963 htest.uf.m12=htest.uf.m23=htest.uf.m13=0.0;
8964 htest.uf.m21=htest.uf.m32=htest.uf.m31=0.0;
8965 qtest=htest;
8966 qtest.an=-1;
8967 QTextDocument *document = editor->document();
8968 QTextCursor cursor = editor->textCursor();
8969 cursor.beginEditBlock ();
8970 double xh[8]={
8971 0.98,//1
8972 0.97,//2
8973 0.96,//3
8974 0.93,//4
8975 1.10,//15 B
8976 0.82,//8 O
8977 0.93,//9
8978 0.93// 16
8979 };
8980 V3 v=V3(0,0,0),w=V3(0,0,0),u=V3(0,0,0) ,a=V3(0,0,0),b=V3(0,0,0),c=V3(0,0,0);
8981 a = mole.showatoms.at(mole.knoepfe.at(i).neighbors.at(0) ).pos - mole.asymm.at(i).pos;
8982 b = mole.showatoms.at(mole.knoepfe.at(i).neighbors.at(1) ).pos - mole.asymm.at(i).pos;
8983 a = c = Normalize(a) ;
8984 c = c+ (b= Normalize(b));
8985 double angle=mole.winkel(a,b);
8986 c = Normalize(c);
8987 if (angle<160) {
8988
8989 w = Normalize(a);
8990 u = Normalize(b);
8991 double si=1.0376-0.0346*Norm(w-u); //=1.91063323625-((acos(u*w)-1.91063323625)/5.0);//-1.91063323625 = 109.47 grad ; 3.7 empirischer Wert
8992 c = (-cos(si)*(xh[1]-nh) * c);
8993 v = sin(si) *(xh[1]-nh) * Normalize(c%a);
8994 a = mole.asymm.at(i).pos + c + v;
8995 b = mole.asymm.at(i).pos + c - v;
8996 c = c + mole.asymm.at(i).pos;
8997
8998 htest.Label=mole.asymm.at(i).Label.section('_',0,0);
8999 htest.part=mole.asymm.at(i).part;
9000 htest.resiNr=mole.asymm.at(i).resiNr;
9001 htest.Label.replace(0,1,'H');
9002 int hindex=1;
9003 QString nnn=htest.Label;
9004 QString ann=htest.Label;
9005 do {
9006 if (hindex) nnn=htest.Label.left(3).append(QString::number(hindex+9,36));
9007 if (nnn.size()>4) nnn=htest.Label.left(2).append(QString::number(hindex+9,36));
9008 if (htest.resiNr)
9009 nn=QString("%1_%2")//for shelxl same names in different parts are no problem but for platon so this should fix it.
9010 .arg(nnn)
9011 .arg((htest.resiNr)?QString::number(htest.resiNr):"");
9012 else nn=nnn;
9013 // qDebug()<<nn<<nnn<<(alab.contains(nn,Qt::CaseInsensitive));
9014 hindex++;
9015 }while(alab.contains(nn,Qt::CaseInsensitive));
9016 htest.Label=nnn;
9017 alab.append(nn);
9018 htest.isIso=true;
9019 htest.ufiso_org=QString("-1.2");
9020 double uIso = mole.ueq(mole.asymm.at(i).uf)*1.2;
9021 htest.uf.m11 = htest.uf.m22 = htest.uf.m33 = uIso;
9022 htest.uf.m23 = uIso * mole.cell.cosra;
9023 htest.uf.m13 = uIso * mole.cell.cosrb;
9024 htest.uf.m12 = uIso * mole.cell.cosrg;
9025 mole.Uf2Uo(htest.uf,htest.uc);
9026 htest.pos=a;
9027 mole.kart2frac(htest.pos,htest.frac);
9028 htest.orginalLine=QString("%1 %2 %3 %4 %5 %6 %7")
9029 .arg(htest.Label)
9030 .arg(qMax(1,editor->sfac.indexOf(0)+1))
9031 .arg(htest.frac.x,9,'f',5)
9032 .arg(htest.frac.y,9,'f',5)
9033 .arg(htest.frac.z,9,'f',5)
9034 .arg(mole.asymm.at(i).sof_org)
9035 .arg("-1.2");
9036 mole.asymm.append(htest);
9037 nnn=ann;//pevent HnAB labels
9038 do {
9039 if (hindex) nnn=ann.left(3).append(QString::number(hindex+9,36));
9040 if (nnn.size()>4) nnn=ann.left(2).append(QString::number(hindex+9,36));
9041 if (htest.resiNr)
9042 nn=QString("%1_%2")//for shelxl same names in different parts are no problem but for platon so this should fix it.
9043 .arg(nnn)
9044 .arg((htest.resiNr)?QString::number(htest.resiNr):"");
9045 else nn=nnn;
9046 // qDebug()<<nn<<nnn<<(alab.contains(nn,Qt::CaseInsensitive));
9047 hindex++;
9048 }while(alab.contains(nn,Qt::CaseInsensitive));
9049 htest.Label=nnn;
9050 alab.append(nn);
9051 htest.pos=b;
9052 mole.kart2frac(htest.pos,htest.frac);
9053 htest.orginalLine=QString("%1 %2 %3 %4 %5 %6 %7")
9054 .arg(htest.Label)
9055 .arg(qMax(1,editor->sfac.indexOf(0)+1))
9056 .arg(htest.frac.x,9,'f',5)
9057 .arg(htest.frac.y,9,'f',5)
9058 .arg(htest.frac.z,9,'f',5)
9059 .arg(mole.asymm.at(i).sof_org)
9060 .arg("-1.2");
9061 mole.asymm.append(htest);
9062 QString label = mole.showatoms.at(i).orginalLine.left(80).trimmed();
9063 // int afixfuenf=(mole.showatoms.at(i).afix/10)?(mole.showatoms.at(i).afix/10)*10+5:0;
9064 cursor.movePosition(QTextCursor::Start);
9065 cursor = document->find(label,cursor);
9066 if (cursor.isNull()){
9067 cursor = editor->textCursor();
9068 cursor.movePosition(QTextCursor::Start);
9069 label.chop(10);
9070 cursor = document->find(label,cursor);
9071 if (cursor.isNull()) {
9072 cursor = editor->textCursor();
9073 }
9074 }
9075 cursor.movePosition(QTextCursor::StartOfLine,QTextCursor::MoveAnchor);
9076 cursor.movePosition(QTextCursor::EndOfLine,QTextCursor::KeepAnchor);
9077 while (cursor.selectedText().endsWith("=")) {
9078 cursor.movePosition(QTextCursor::Down,QTextCursor::KeepAnchor);
9079 cursor.movePosition(QTextCursor::EndOfLine,QTextCursor::KeepAnchor);
9080 }
9081 cursor.clearSelection();
9082 cursor.movePosition(QTextCursor::Down);
9083 cursor.insertText(QString("AFIX 23\n%1\n%2\nAFIX %3\n")
9084 .arg(mole.asymm.at(mole.asymm.size()-2).orginalLine)
9085 .arg(mole.asymm.at(mole.asymm.size()-1).orginalLine)
9086 .arg(mole.afix5(i)));
9087 }//angle
9088 cursor.endEditBlock();
9089 int jetztAtome=0;
9090 for (int i=0; i<mole.asymm.size();i++) if (mole.asymm.at(i).an>=0)jetztAtome++;
9091 actionHFix->setDisabled(true);
9092 fuse();
9093 QString info=QString("<font color=\"green\"><b>%1</b> Hydrogen atoms added. <b>Please SAVE before GROW!</font>").arg(jetztAtome-warmalAtome);
9094 infoKanalNews(info);
9095
9096 }//23
9097
9098 void Window::addH93(){
9099 QAction *action = qobject_cast<QAction *>(sender());
9100 int idx=0;
9101 if (action)
9102 idx=action->data().toInt();
9103 else return;
9104 if (idx>mole.asymm.size()) return;
9105 if (mole.knoepfe.at(idx).neighbors.size()!=1)return;//we need 1 non h neighbors
9106 int warmalAtome=0;
9107 for (int jj=0; jj<mole.asymm.size();jj++) if (mole.asymm.at(jj).an>=0)warmalAtome++;
9108 QStringList alab;
9109 for (int i =0; i<mole.asymm.size(); i++){
9110 alab.append(mole.asymm.at(i).Label);
9111 }
9112 QString nn;
9113 double nh= (mole.asymm.at(idx).an==6) ? 0.07 : 0;
9114
9115 chgl->disSelection();
9116 MyAtom htest,qtest;
9117 if (editor->sfac.indexOf(0)==-1)addNewScatteringFactor(0,false);
9118 htest.an=0;
9119 htest.part=0;
9120 htest.resiNr=0;
9121 htest.hidden=0;
9122 htest.symmGroup=0;
9123 htest.sg=0;
9124 htest.scod=555;//the identity
9125 htest.auidx=-1;
9126 htest.isIso=true;
9127 htest.uc.m11=htest.uc.m22=htest.uc.m33=0.05;
9128 htest.uc.m12=htest.uc.m23=htest.uc.m13=0.0;
9129 htest.uc.m21=htest.uc.m32=htest.uc.m31=0.0;
9130 htest.uf.m12=htest.uf.m23=htest.uf.m13=0.0;
9131 htest.uf.m21=htest.uf.m32=htest.uf.m31=0.0;
9132 qtest=htest;
9133 qtest.an=-1;
9134 QTextDocument *document = editor->document();
9135 QTextCursor cursor = editor->textCursor();
9136 cursor.beginEditBlock ();
9137 double xh[8]={
9138 0.98,//1
9139 0.97,//2
9140 0.96,//3
9141 0.93,//4
9142 1.10,//15 B
9143 0.82,//8 O
9144 0.93,//9
9145 0.93// 16
9146 };
9147 V3 v=V3(0,0,0),w=V3(0,0,0),u=V3(0,0,0),a=V3(0,0,0);//,b=V3(0,0,0),c=V3(0,0,0);
9148 a = mole.showatoms.at(mole.knoepfe.at(idx).neighbors.at(0)).pos - mole.asymm.at(idx).pos;
9149 int j,k,l;
9150 a=Normalize(a);
9151 double jx,kx,lx,mx,my,mz;
9152 double val[24],merg[12],wink=0,t=0,mt=0;
9153 if (fxle->n5){
9154 for (int z=0; z<12;z++) merg[z]=0;
9155 for (int z=0; z<24; z++){
9156 wink=z*0.261799387799;
9157 w=Normalize(V3(0,0,1)%a);
9158 u=Normalize(w%a);
9159 v=(-(xh[6]-nh)*0.33333*a)+ mole.asymm.at(idx).pos+(xh[6]-nh)*0.942809041582*(sin(wink)*u+cos(wink)*w);
9160 qtest.pos=v;
9161 mole.kart2frac(v,v);
9162 jx=(v.x>0)?(v.x*fxle->n1+0.5):((1.0+v.x)*fxle->n1+0.5);
9163 kx=(v.y>0)?(v.y*fxle->n2+0.5):((1.0+v.y)*fxle->n2+0.5);
9164 lx=(v.z>0)?(v.z*fxle->n3+0.5):((1.0+v.z)*fxle->n3+0.5);
9165 mx=jx-floor(jx);
9166 my=kx-floor(kx);
9167 mz=lx-floor(lx);
9168 j=((int)jx)%fxle->n1;//
9169 k=((int)kx)%fxle->n2;//
9170 l=((int)lx)%fxle->n3;//
9171 merg[z%12]+=val[z]=(
9172 (1-mx)*fxle->datfo_fc[(j+fxle->n1*(k+l*fxle->n2))%fxle->n5]+
9173 mx*fxle->datfo_fc[((j+1)+fxle->n1*(k+l*fxle->n2))%fxle->n5]+
9174 (1-my)*fxle->datfo_fc[(j+fxle->n1*(k+l*fxle->n2))%fxle->n5]+
9175 my*fxle->datfo_fc[(j+fxle->n1*((k+1)+l*fxle->n2))%fxle->n5]+
9176 (1-mz)*fxle->datfo_fc[(j+fxle->n1*(k+l*fxle->n2))%fxle->n5]+
9177 mz*fxle->datfo_fc[(j+fxle->n1*(k+(l+1)*fxle->n2))%fxle->n5])/3.0;
9178 qtest.peakHeight=val[z];
9179 qtest.frac=v;
9180 qtest.Label=QString("Q%1").arg(z+100);
9181 mole.pmin=qMin(mole.pmin, qtest.peakHeight);
9182 mole.pmax=qMax(mole.pmax, qtest.peakHeight);
9183 qpv->cutoff=0;//mole.pmin;
9184 qpv->setMin(mole.pmin);
9185 qpv->setMax(mole.pmax);
9186 mole.asymm.append(qtest);
9187 }
9188 for (int z=0; z<12;z++) {
9189 t =merg[(z+12)%12] ;
9190 double x = t - merg[(z+13)%12];
9191 double u = t - merg[(z+11)%12];
9192 if (fmin(x,u)<0) continue;
9193 double p=0.5*(u-x)/(u+x);
9194 t=t+0.25*(p*(u-x));
9195 mt=(mt>t)?mt:t;
9196 if (t<mt)continue;
9197 wink=((double) z + p )*0.261799387799;
9198
9199 /////////////////
9200 }
9201 }else{
9202 int zzz=0;
9203 int z=mole.knoepfe.at(mole.knoepfe.at(idx).neighbors.at(0)).neighbors.at(zzz++);
9204 while ((z==idx)&&(zzz<mole.knoepfe.at(mole.knoepfe.at(idx).neighbors.at(0)).neighbors.size()))
9205 z=mole.knoepfe.at(mole.knoepfe.at(idx).neighbors.at(0)).neighbors.at(zzz++);
9206 w=Normalize(V3(0,0,1)%a);
9207 u=Normalize(w%a);
9208 v=(-(xh[2]-nh)*0.33333*a)+ mole.asymm.at(idx).pos+(xh[2]-nh)*0.942809041582*(sin(wink)*u+cos(wink)*w);
9209 // if z == i then dieder() returns nan, because A in dieder gets (0,0,0)
9210 V3 increm = V3(0.0, 0.0, 0.0);
9211 if ( z == idx ) {
9212 increm = V3(0.00001, 0.00001, 0.00001);
9213 }
9214 wink=mole.dieder(mole.showatoms.at(mole.knoepfe.at(idx).neighbors.at(0)).pos+increm-mole.asymm.at(z).pos,
9215 mole.asymm.at(idx).pos-mole.showatoms.at(mole.knoepfe.at(idx).neighbors.at(0)).pos,
9216 v-mole.asymm.at(idx).pos)/180.0*M_PI;
9217
9218 }
9219
9220 v=(-(xh[6]-nh)*0.5*a)+ mole.asymm.at(idx).pos+(xh[6]-nh)*0.866025403784*(sin(wink)*u+cos(wink)*w);
9221 htest.Label=mole.asymm.at(idx).Label.section('_',0,0);
9222 htest.part=mole.asymm.at(idx).part;
9223 htest.resiNr=mole.asymm.at(idx).resiNr;
9224 htest.Label.replace(0,1,'H');
9225 int hindex=1;
9226 QString nnn=htest.Label;
9227 QString baslab=htest.Label;
9228 do {
9229 htest.Label=baslab;
9230 if (hindex) nnn=htest.Label.left(3).append(QString::number(hindex+9,36));
9231 if (nnn.size()>4) nnn=htest.Label.left(2).append(QString::number(hindex+9,36));
9232 if (htest.resiNr)
9233 nn=QString("%1_%2")//for shelxl same names in different parts are no problem but for platon so this should fix it.
9234 .arg(nnn)
9235 .arg((htest.resiNr)?QString::number(htest.resiNr):"");
9236 else nn=nnn;
9237 // qDebug()<<nn<<nnn<<(alab.contains(nn,Qt::CaseInsensitive));
9238 hindex++;
9239 }while(alab.contains(nn,Qt::CaseInsensitive));
9240 htest.Label=nnn;
9241 alab.append(nn);
9242 htest.isIso=true;
9243 htest.ufiso_org=QString("-1.2");
9244 double uIso = mole.ueq(mole.asymm.at(idx).uf)*1.2;
9245 htest.uf.m11 = htest.uf.m22 = htest.uf.m33 = uIso;
9246 htest.uf.m23 = uIso * mole.cell.cosra;
9247 htest.uf.m13 = uIso * mole.cell.cosrb;
9248 htest.uf.m12 = uIso * mole.cell.cosrg;
9249 mole.Uf2Uo(htest.uf,htest.uc);
9250 htest.pos=v;
9251 mole.kart2frac(htest.pos,htest.frac);
9252 htest.orginalLine=QString("%1 %2 %3 %4 %5 %6 %7")
9253 .arg(htest.Label)
9254 .arg(qMax(1,editor->sfac.indexOf(0)+1))
9255 .arg(htest.frac.x,9,'f',5)
9256 .arg(htest.frac.y,9,'f',5)
9257 .arg(htest.frac.z,9,'f',5)
9258 .arg(mole.asymm.at(idx).sof_org)
9259 .arg("-1.2");
9260 mole.asymm.append(htest);
9261 wink+=3.14159265359;
9262 v=(-(xh[6]-nh)*0.5*a)+ mole.asymm.at(idx).pos+(xh[6]-nh)*0.866025403784*(sin(wink)*u+cos(wink)*w);
9263 do {
9264 htest.Label=baslab;
9265 if (hindex) nnn=htest.Label.left(3).append(QString::number(hindex+9,36));
9266 if (nnn.size()>4) nnn=htest.Label.left(2).append(QString::number(hindex+9,36));
9267 if (htest.resiNr)
9268 nn=QString("%1_%2")//for shelxl same names in different parts are no problem but for platon so this should fix it.
9269 .arg(nnn)
9270 .arg((htest.resiNr)?QString::number(htest.resiNr):"");
9271 else nn=nnn;
9272 // qDebug()<<nn<<nnn<<(alab.contains(nn,Qt::CaseInsensitive));
9273 hindex++;
9274 }while(alab.contains(nn,Qt::CaseInsensitive));
9275 htest.Label=nnn;
9276 alab.append(nn);
9277 htest.pos=v;
9278 mole.kart2frac(htest.pos,htest.frac);
9279 htest.orginalLine=QString("%1 %2 %3 %4 %5 %6 %7")
9280 .arg(htest.Label)
9281 .arg(qMax(1,editor->sfac.indexOf(0)+1))
9282 .arg(htest.frac.x,9,'f',5)
9283 .arg(htest.frac.y,9,'f',5)
9284 .arg(htest.frac.z,9,'f',5)
9285 .arg(mole.asymm.at(idx).sof_org)
9286 .arg("-1.2");
9287 mole.asymm.append(htest);
9288
9289 QString label = mole.showatoms.at(idx).orginalLine.left(80).trimmed();
9290 // int afixfuenf=(mole.showatoms.at(i).afix/10)?(mole.showatoms.at(i).afix/10)*10+5:0;
9291 cursor.movePosition(QTextCursor::Start);
9292 cursor = document->find(label,cursor);
9293 if (cursor.isNull()){
9294 cursor = editor->textCursor();
9295 cursor.movePosition(QTextCursor::Start);
9296 label.chop(10);
9297 cursor = document->find(label,cursor);
9298 if (cursor.isNull()) {
9299 cursor = editor->textCursor();
9300 }
9301 }
9302 cursor.movePosition(QTextCursor::StartOfLine,QTextCursor::MoveAnchor);
9303 cursor.movePosition(QTextCursor::EndOfLine,QTextCursor::KeepAnchor);
9304 while (cursor.selectedText().endsWith("=")) {
9305 cursor.movePosition(QTextCursor::Down,QTextCursor::KeepAnchor);
9306 cursor.movePosition(QTextCursor::EndOfLine,QTextCursor::KeepAnchor);
9307 }
9308 cursor.clearSelection();
9309 cursor.movePosition(QTextCursor::Down);
9310 cursor.insertText(QString("AFIX 93\n%1\n%2\nAFIX %3\n")
9311 .arg(mole.asymm.at(mole.asymm.size()-2).orginalLine)
9312 .arg(mole.asymm.at(mole.asymm.size()-1).orginalLine)
9313 .arg(mole.afix5(idx))
9314 );
9315
9316
9317
9318 cursor.endEditBlock();
9319 int jetztAtome=0;
9320 for (int i=0; i<mole.asymm.size();i++) if (mole.asymm.at(i).an>=0)jetztAtome++;
9321 actionHFix->setDisabled(true);
9322 fuse();
9323 QString info=QString("<font color=\"green\"><b>%1</b> Hydrogen atoms added. <b>Please SAVE before GROW!</font>").arg(jetztAtome-warmalAtome);
9324 infoKanalNews(info);
9325 }//93
9326
9327 void Window::addH163(){
9328 QAction *action = qobject_cast<QAction *>(sender());
9329 int i=0;
9330 if (action)
9331 i=action->data().toInt();
9332 else return;
9333 if (i>mole.asymm.size()) return;
9334 if (mole.knoepfe.at(i).neighbors.size()!=1)return;//we need 1 non h neighbors
9335 int warmalAtome=0;
9336 for (int j=0; j<mole.asymm.size();j++) if (mole.asymm.at(j).an>=0)warmalAtome++;
9337 QStringList alab;
9338 for (int i =0; i<mole.asymm.size(); i++){
9339 alab.append(mole.asymm.at(i).Label);
9340 }
9341 QString nn;
9342 double nh= (mole.asymm.at(i).an==6) ? 0.07 : 0;
9343
9344 chgl->disSelection();
9345 MyAtom htest,qtest;
9346 if (editor->sfac.indexOf(0)==-1)addNewScatteringFactor(0,false);
9347 htest.an=0;
9348 htest.part=0;
9349 htest.resiNr=0;
9350 htest.hidden=0;
9351 htest.symmGroup=0;
9352 htest.sg=0;
9353 htest.scod=555;//the identity
9354 htest.auidx=-1;
9355 htest.isIso=true;
9356 htest.uc.m11=htest.uc.m22=htest.uc.m33=0.05;
9357 htest.uc.m12=htest.uc.m23=htest.uc.m13=0.0;
9358 htest.uc.m21=htest.uc.m32=htest.uc.m31=0.0;
9359 htest.uf.m12=htest.uf.m23=htest.uf.m13=0.0;
9360 htest.uf.m21=htest.uf.m32=htest.uf.m31=0.0;
9361 qtest=htest;
9362 qtest.an=-1;
9363 QTextDocument *document = editor->document();
9364 QTextCursor cursor = editor->textCursor();
9365 cursor.beginEditBlock ();
9366 double xh[8]={
9367 0.98,//1
9368 0.97,//2
9369 0.96,//3
9370 0.93,//4
9371 1.10,//15 B
9372 0.82,//8 O
9373 0.93,//9
9374 0.93// 16
9375 };
9376 V3 v=V3(0,0,0),a=V3(0,0,0);
9377 a = Normalize(mole.showatoms.at(mole.knoepfe.at(i).neighbors.at(0)).pos - mole.asymm.at(i).pos);
9378 v=(-(xh[7]-nh)*a)+ mole.asymm.at(i).pos;
9379 htest.Label=mole.asymm.at(i).Label.section('_',0,0);
9380 htest.part=mole.asymm.at(i).part;
9381 htest.resiNr=mole.asymm.at(i).resiNr;
9382 htest.Label.replace(0,1,'H');
9383 int hindex=0;
9384 QString nnn=htest.Label;
9385 do {
9386 if (hindex) nnn=htest.Label.left(3).append(QString::number(hindex+9,36));
9387 if (nnn.size()>4) nnn=htest.Label.left(2).append(QString::number(hindex+9,36));
9388 if (htest.resiNr)
9389 nn=QString("%1_%2")//for shelxl same names in different parts are no problem but for platon so this should fix it.
9390 .arg(nnn)
9391 .arg((htest.resiNr)?QString::number(htest.resiNr):"");
9392 else nn=nnn;
9393 // qDebug()<<nn<<nnn<<(alab.contains(nn,Qt::CaseInsensitive));
9394 hindex++;
9395 }while(alab.contains(nn,Qt::CaseInsensitive));
9396 htest.Label=nnn;
9397 alab.append(nn);
9398 htest.isIso=true;
9399 htest.ufiso_org=QString("-1.2");
9400 double uIso = mole.ueq(mole.asymm.at(i).uf)*1.2;
9401 htest.uf.m11 = htest.uf.m22 = htest.uf.m33 = uIso;
9402 htest.uf.m23 = uIso * mole.cell.cosra;
9403 htest.uf.m13 = uIso * mole.cell.cosrb;
9404 htest.uf.m12 = uIso * mole.cell.cosrg;
9405 mole.Uf2Uo(htest.uf,htest.uc);
9406 htest.pos=v;
9407 mole.kart2frac(htest.pos,htest.frac);
9408 htest.orginalLine=QString("%1 %2 %3 %4 %5 %6 %7")
9409 .arg(htest.Label)
9410 .arg(qMax(1,editor->sfac.indexOf(0)+1))
9411 .arg(htest.frac.x,9,'f',5)
9412 .arg(htest.frac.y,9,'f',5)
9413 .arg(htest.frac.z,9,'f',5)
9414 .arg(mole.asymm.at(i).sof_org)
9415 .arg("-1.2");
9416 mole.asymm.append(htest);
9417
9418 QString label = mole.showatoms.at(i).orginalLine.left(80).trimmed();
9419 // int afixfuenf=(mole.showatoms.at(i).afix/10)?(mole.showatoms.at(i).afix/10)*10+5:0;
9420 cursor.movePosition(QTextCursor::Start);
9421 cursor = document->find(label,cursor);
9422 if (cursor.isNull()){
9423 cursor = editor->textCursor();
9424 cursor.movePosition(QTextCursor::Start);
9425 label.chop(10);
9426 cursor = document->find(label,cursor);
9427 if (cursor.isNull()) {
9428 cursor = editor->textCursor();
9429 }
9430 }
9431 cursor.movePosition(QTextCursor::StartOfLine,QTextCursor::MoveAnchor);
9432 cursor.movePosition(QTextCursor::EndOfLine,QTextCursor::KeepAnchor);
9433 while (cursor.selectedText().endsWith("=")) {
9434 cursor.movePosition(QTextCursor::Down,QTextCursor::KeepAnchor);
9435 cursor.movePosition(QTextCursor::EndOfLine,QTextCursor::KeepAnchor);
9436 }
9437 cursor.clearSelection();
9438 cursor.movePosition(QTextCursor::Down);
9439 cursor.insertText(QString("AFIX 163\n%1\nAFIX %2\n")
9440 .arg(mole.asymm.at(mole.asymm.size()-1).orginalLine)
9441 .arg(mole.afix5(i))
9442 );
9443
9444
9445
9446 cursor.endEditBlock();
9447 int jetztAtome=0;
9448 for (int i=0; i<mole.asymm.size();i++) if (mole.asymm.at(i).an>=0)jetztAtome++;
9449 actionHFix->setDisabled(true);
9450 fuse();
9451 QString info=QString("<font color=\"green\"><b>%1</b> Hydrogen atoms added. <b>Please SAVE before GROW!</font>").arg(jetztAtome-warmalAtome);
9452 infoKanalNews(info);
9453
9454 }//163
9455
9456 void Window::addMethyl(){//137
9457 QAction *action = qobject_cast<QAction *>(sender());
9458 int i=0;
9459 if (action)
9460 i=action->data().toInt();
9461 else return;
9462 if (i>mole.asymm.size()) return;
9463 int warmalAtome=0;
9464 for (int j=0; j<mole.asymm.size();j++) if (mole.asymm.at(j).an>=0)warmalAtome++;
9465 double nh= (mole.asymm.at(i).an==6) ? 0.07 : 0;
9466 QStringList alab;
9467 for (int i =0; i<mole.asymm.size(); i++){
9468 alab.append(mole.asymm.at(i).Label);
9469 }
9470 QString nn;
9471 chgl->disSelection();
9472 MyAtom htest,qtest;
9473 if (editor->sfac.indexOf(0)==-1)addNewScatteringFactor(0,false);
9474 htest.an=0;
9475 htest.part=0;
9476 htest.resiNr=0;
9477 htest.hidden=0;
9478 htest.symmGroup=0;
9479 htest.sg=0;
9480 htest.scod=555;//the identity
9481 htest.auidx=-1;
9482 htest.isIso=true;
9483 htest.uc.m11=htest.uc.m22=htest.uc.m33=0.05;
9484 htest.uc.m12=htest.uc.m23=htest.uc.m13=0.0;
9485 htest.uc.m21=htest.uc.m32=htest.uc.m31=0.0;
9486 htest.uf.m12=htest.uf.m23=htest.uf.m13=0.0;
9487 htest.uf.m21=htest.uf.m32=htest.uf.m31=0.0;
9488 qtest=htest;
9489 qtest.an=-1;
9490 QTextDocument *document = editor->document();
9491 QTextCursor cursor = editor->textCursor();
9492 cursor.beginEditBlock ();
9493 double xh[8]={
9494 0.98,//1
9495 0.97,//2
9496 0.96,//3
9497 0.93,//4
9498 1.10,//15 B
9499 0.82,//8 O
9500 0.93,//9
9501 0.93// 16
9502 };
9503 V3 v=V3(0,0,0),w=V3(0,0,0),u=V3(0,0,0) ,a=V3(0,0,0);//,b=V3(0,0,0),c=V3(0,0,0);
9504 a = mole.showatoms.at(mole.knoepfe.at(i).neighbors.at(0)).pos - mole.asymm.at(i).pos;
9505 int ji,ki,li;
9506 a=Normalize(a);
9507 double jx,kx,lx,mx,my,mz;
9508 double val[24],merg[8],wink=0,t=0,mt=0;
9509 for (int z=0; z<8;z++) merg[z]=0;
9510 if (fxle->n5){
9511 for (int z=0; z<24; z++){
9512 w=Normalize(V3(0,0,1)%a);
9513 u=Normalize(w%a);
9514 v=(-(xh[2]-nh)*0.33333*a)+ mole.asymm.at(i).pos+(xh[2]-nh)*0.942809041582*(sin(wink)*u+cos(wink)*w);
9515 qtest.pos=v;
9516 mole.kart2frac(v,v);
9517 int zplu=0;
9518 do {
9519 jx=((zplu+v.x)*fxle->n1+0.5);
9520 zplu++;
9521 }while (jx<0);
9522 zplu=0;
9523 do {
9524 kx=((zplu+v.y)*fxle->n2+0.5);
9525 zplu++;
9526 }while (kx<0);
9527 zplu=0;
9528 do {
9529 lx=((zplu+v.z)*fxle->n3+0.5);
9530 zplu++;
9531 }while (lx<0);
9532 mx=jx-floor(jx);
9533 my=kx-floor(kx);
9534 mz=lx-floor(lx);
9535 ji=((int)jx)%fxle->n1;//
9536 ki=((int)kx)%fxle->n2;//
9537 li=((int)lx)%fxle->n3;//
9538 merg[z%8]+=val[z]=(
9539 (1-mx)*fxle->datfo_fc[(ji+fxle->n1*(ki+li*fxle->n2))%fxle->n5]+
9540 mx*fxle->datfo_fc[((ji+1)+fxle->n1*(ki+li*fxle->n2))%fxle->n5]+
9541 (1-my)*fxle->datfo_fc[(ji+fxle->n1*(ki+li*fxle->n2))%fxle->n5]+
9542 my*fxle->datfo_fc[(ji+fxle->n1*((ki+1)+li*fxle->n2))%fxle->n5]+
9543 (1-mz)*fxle->datfo_fc[(ji+fxle->n1*(ki+li*fxle->n2))%fxle->n5]+
9544 mz*fxle->datfo_fc[(ji+fxle->n1*(ki+(li+1)*fxle->n2))%fxle->n5])/3.0;
9545 qtest.peakHeight=val[z];
9546 qtest.frac=v;
9547 qtest.Label=QString("Q%1").arg(z,-3);
9548 mole.pmin=qMin(mole.pmin, qtest.peakHeight);
9549 mole.pmax=qMax(mole.pmax, qtest.peakHeight);
9550 qpv->cutoff=0;//mole.pmin;
9551 qpv->setMin(mole.pmin);
9552 qpv->setMax(mole.pmax);
9553 mole.asymm.append(qtest);
9554 wink+=0.261799387799;
9555 }
9556 for (int z=0; z<8;z++) {
9557 t =merg[(z+8)%8] ;
9558 double x = t - merg[(z+9)%8];
9559 double u = t - merg[(z+7)%8];
9560 if (fmin(x,u)<0) continue;
9561 double p=0.5*(u-x)/(u+x);
9562 t=t+0.25*(p*(u-x));
9563 mt=(mt>t)?mt:t;
9564 if (t<mt)continue;
9565 wink=((double) z + p )*0.261799387799;
9566 }
9567 }else{
9568 int zzz=0;
9569 int z=mole.knoepfe.at(mole.knoepfe.at(i).neighbors.at(0)).neighbors.at(zzz++);
9570 while ((z==i)&&(zzz<mole.knoepfe.at(mole.knoepfe.at(i).neighbors.at(0)).neighbors.size())) {
9571 z=mole.knoepfe.at(mole.knoepfe.at(i).neighbors.at(0)).neighbors.at(zzz++);
9572 }
9573 w=Normalize(V3(0,0,1)%a);
9574 u=Normalize(w%a);
9575 v=(-(xh[2]-nh)*0.33333*a)+ mole.asymm.at(i).pos+(xh[2]-nh)*0.942809041582*(sin(wink)*u+cos(wink)*w);
9576 // if z == i then dieder() returns nan, because A in dieder gets (0,0,0)
9577 V3 increm = V3(0.0, 0.0, 0.0);
9578 if ( z == i ) {
9579 increm = V3(0.00001, 0.00001, 0.00001);
9580 }
9581 wink=mole.dieder(mole.showatoms.at(mole.knoepfe.at(i).neighbors.at(0)).pos+increm-mole.asymm.at(z).pos,
9582 mole.asymm.at(i).pos-mole.showatoms.at(mole.knoepfe.at(i).neighbors.at(0)).pos,
9583 v-mole.asymm.at(i).pos)/180.0*M_PI;
9584 }
9585 v=(-(xh[2]-nh)*0.33333*a)+ mole.asymm.at(i).pos+(xh[2]-nh)*0.942809041582*(sin(wink)*u+cos(wink)*w);
9586 htest.Label=mole.asymm.at(i).Label.section('_',0,0);
9587 htest.part=mole.asymm.at(i).part;
9588 htest.resiNr=mole.asymm.at(i).resiNr;
9589 htest.Label.replace(0,1,'H');
9590 int hindex=1;
9591 QString nnn=htest.Label;
9592 QString ann=htest.Label;
9593 do {
9594 if (hindex) nnn=ann.left(3).append(QString::number(hindex+9,36));
9595 if (nnn.size()>4) nnn=ann.left(2).append(QString::number(hindex+9,36));
9596 if (htest.resiNr)
9597 nn=QString("%1_%2")//for shelxl same names in different parts are no problem but for platon so this should fix it.
9598 .arg(nnn)
9599 .arg((htest.resiNr)?QString::number(htest.resiNr):"");
9600 else nn=nnn;
9601 // qDebug()<<nn<<nnn<<(alab.contains(nn,Qt::CaseInsensitive));
9602 hindex++;
9603 }while(alab.contains(nn,Qt::CaseInsensitive));
9604 htest.Label=nnn;
9605 alab.append(nn);
9606
9607 htest.isIso=true;
9608 htest.ufiso_org=QString("-1.5");
9609 double uIso = mole.ueq(mole.asymm.at(i).uf)*1.5;
9610 htest.uf.m11 = htest.uf.m22 = htest.uf.m33 = uIso;
9611 htest.uf.m23 = uIso * mole.cell.cosra;
9612 htest.uf.m13 = uIso * mole.cell.cosrb;
9613 htest.uf.m12 = uIso * mole.cell.cosrg;
9614 mole.Uf2Uo(htest.uf,htest.uc);
9615 htest.pos=v;
9616 mole.kart2frac(htest.pos,htest.frac);
9617 htest.orginalLine=QString("%1 %2 %3 %4 %5 %6 %7")
9618 .arg(htest.Label)
9619 .arg(qMax(1,editor->sfac.indexOf(0)+1))
9620 .arg(htest.frac.x,9,'f',5)
9621 .arg(htest.frac.y,9,'f',5)
9622 .arg(htest.frac.z,9,'f',5)
9623 .arg(mole.asymm.at(i).sof_org)
9624 .arg("-1.5");
9625 mole.asymm.append(htest);
9626 wink+=2.09439510239;
9627 v=(-(xh[2]-nh)*0.33333*a)+ mole.asymm.at(i).pos+(xh[2]-nh)*0.942809041582*(sin(wink)*u+cos(wink)*w);
9628 do {
9629 if (hindex) nnn=ann.left(3).append(QString::number(hindex+9,36));
9630 if (nnn.size()>4) nnn=ann.left(2).append(QString::number(hindex+9,36));
9631 if (htest.resiNr)
9632 nn=QString("%1_%2")//for shelxl same names in different parts are no problem but for platon so this should fix it.
9633 .arg(nnn)
9634 .arg((htest.resiNr)?QString::number(htest.resiNr):"");
9635 else nn=nnn;
9636 // qDebug()<<nn<<nnn<<(alab.contains(nn,Qt::CaseInsensitive));
9637 hindex++;
9638 }while(alab.contains(nn,Qt::CaseInsensitive));
9639 htest.Label=nnn;
9640 alab.append(nn);
9641 htest.pos=v;
9642 mole.kart2frac(htest.pos,htest.frac);
9643 htest.orginalLine=QString("%1 %2 %3 %4 %5 %6 %7")
9644 .arg(htest.Label)
9645 .arg(qMax(1,editor->sfac.indexOf(0)+1))
9646 .arg(htest.frac.x,9,'f',5)
9647 .arg(htest.frac.y,9,'f',5)
9648 .arg(htest.frac.z,9,'f',5)
9649 .arg(mole.asymm.at(i).sof_org)
9650 .arg("-1.5");
9651 mole.asymm.append(htest);
9652 wink+=2.09439510239;
9653 v=(-(xh[2]-nh)*0.33333*a)+ mole.asymm.at(i).pos+(xh[2]-nh)*0.942809041582*(sin(wink)*u+cos(wink)*w);
9654 do {
9655 if (hindex) nnn=ann.left(3).append(QString::number(hindex+9,36));
9656 if (nnn.size()>4) nnn=ann.left(2).append(QString::number(hindex+9,36));
9657 if (htest.resiNr)
9658 nn=QString("%1_%2")//for shelxl same names in different parts are no problem but for platon so this should fix it.
9659 .arg(nnn)
9660 .arg((htest.resiNr)?QString::number(htest.resiNr):"");
9661 else nn=nnn;
9662 // qDebug()<<nn<<nnn<<(alab.contains(nn,Qt::CaseInsensitive));
9663 hindex++;
9664 }while(alab.contains(nn,Qt::CaseInsensitive));
9665 htest.Label=nnn;
9666 alab.append(nn);
9667 htest.pos=v;
9668 mole.kart2frac(htest.pos,htest.frac);
9669 htest.orginalLine=QString("%1 %2 %3 %4 %5 %6 %7")
9670 .arg(htest.Label)
9671 .arg(qMax(1,editor->sfac.indexOf(0)+1))
9672 .arg(htest.frac.x,9,'f',5)
9673 .arg(htest.frac.y,9,'f',5)
9674 .arg(htest.frac.z,9,'f',5)
9675 .arg(mole.asymm.at(i).sof_org)
9676 .arg("-1.5");
9677 mole.asymm.append(htest);
9678 QString label = mole.showatoms.at(i).orginalLine.left(80).trimmed();
9679 // int afixfuenf=(mole.showatoms.at(i).afix/10)?(mole.showatoms.at(i).afix/10)*10+5:0;
9680 cursor.movePosition(QTextCursor::Start);
9681 cursor = document->find(label,cursor);
9682 if (cursor.isNull()){
9683 cursor = editor->textCursor();
9684 cursor.movePosition(QTextCursor::Start);
9685 label.chop(10);
9686 cursor = document->find(label,cursor);
9687 if (cursor.isNull()) {
9688 cursor = editor->textCursor();
9689 }
9690 }
9691 cursor.movePosition(QTextCursor::StartOfLine,QTextCursor::MoveAnchor);
9692 cursor.movePosition(QTextCursor::EndOfLine,QTextCursor::KeepAnchor);
9693 while (cursor.selectedText().endsWith("=")) {
9694 cursor.movePosition(QTextCursor::Down,QTextCursor::KeepAnchor);
9695 cursor.movePosition(QTextCursor::EndOfLine,QTextCursor::KeepAnchor);
9696 }
9697 cursor.clearSelection();
9698 cursor.movePosition(QTextCursor::Down);
9699 cursor.insertText(QString("AFIX 137\n%1\n%2\n%3\nAFIX %4\n")
9700 .arg(mole.asymm.at(mole.asymm.size()-3).orginalLine)
9701 .arg(mole.asymm.at(mole.asymm.size()-2).orginalLine)
9702 .arg(mole.asymm.at(mole.asymm.size()-1).orginalLine)
9703 .arg(mole.afix5(i))
9704 );
9705
9706 cursor.endEditBlock();
9707 int jetztAtome=0;
9708 for (int i=0; i<mole.asymm.size();i++) if (mole.asymm.at(i).an>=0)jetztAtome++;
9709 actionHFix->setDisabled(true);
9710 fuse();
9711 QString info=QString("<font color=\"green\"><b>%1</b> Hydrogen atoms added. <b>Please SAVE before GROW!</font>").arg(jetztAtome-warmalAtome);
9712 infoKanalNews(info);
9713 }
9714
9715
9716 void Window::addHydroxyl(){//148
9717 QAction *action = qobject_cast<QAction *>(sender());
9718 int idx=0;
9719 if (action)
9720 idx=action->data().toInt();
9721 else return;
9722 if (idx>mole.asymm.size()) return;
9723 int warmalAtome=0;
9724 for (int j=0; j<mole.asymm.size();j++) if (mole.asymm.at(j).an>=0)warmalAtome++;
9725
9726 QStringList alab;
9727 for (int i =0; i<mole.asymm.size(); i++){
9728 alab.append(mole.asymm.at(i).Label);
9729 }
9730 QString nn;
9731 chgl->disSelection();
9732 MyAtom htest,qtest;
9733 if (editor->sfac.indexOf(0)==-1)addNewScatteringFactor(0,false);
9734 htest.an=0;
9735 htest.part=0;
9736 htest.resiNr=0;
9737 htest.hidden=0;
9738 htest.symmGroup=0;
9739 htest.sg=0;
9740 htest.scod=555;//the identity
9741 htest.auidx=-1;
9742 htest.isIso=true;
9743 htest.uc.m11=htest.uc.m22=htest.uc.m33=0.05;
9744 htest.uc.m12=htest.uc.m23=htest.uc.m13=0.0;
9745 htest.uc.m21=htest.uc.m32=htest.uc.m31=0.0;
9746 htest.uf.m12=htest.uf.m23=htest.uf.m13=0.0;
9747 htest.uf.m21=htest.uf.m32=htest.uf.m31=0.0;
9748 qtest=htest;
9749 qtest.an=-1;
9750 QTextDocument *document = editor->document();
9751 QTextCursor cursor = editor->textCursor();
9752 cursor.beginEditBlock ();
9753 //printf("editblock begins\n");
9754 double xh[8]={
9755 0.98,//1
9756 0.97,//2
9757 0.96,//3
9758 0.93,//4
9759 1.10,//15 B
9760 0.82,//8 O
9761 0.93,//9
9762 0.93// 16
9763 };
9764 //qDebug()<<mole.showatoms.at(mole.knoepfe.at(idx).neighbors.at(0)).Label<<mole.asymm.at(idx).Label;
9765 V3 v=V3(0,0,0),w=V3(0,0,0),u=V3(0,0,0) ,a=V3(0,0,0);//,b=V3(0,0,0),c=V3(0,0,0);
9766 a = mole.showatoms.at(mole.knoepfe.at(idx).neighbors.at(0)).pos - mole.asymm.at(idx).pos;
9767 int ji,ki,li;
9768 a=Normalize(a);
9769 double jx,kx,lx,mx,my,mz;
9770 double val[24],wink=0,t=0,mt=0;
9771
9772 if (fxle->n5){
9773 for (int z=0; z<24; z++){
9774 w=Normalize(V3(0,0,1)%a);
9775 u=Normalize(w%a);
9776 v=(-(xh[5])*0.33333*a)+ mole.asymm.at(idx).pos+(xh[5])*0.942809041582*(sin(wink)*u+cos(wink)*w);
9777 qtest.pos=v;
9778 mole.kart2frac(v,v);
9779 int zplu=0;
9780 do {
9781 jx=((zplu+v.x)*fxle->n1+0.5);
9782 zplu++;
9783 }while (jx<0);
9784 zplu=0;
9785 do {
9786 kx=((zplu+v.y)*fxle->n2+0.5);
9787 zplu++;
9788 }while (kx<0);
9789 zplu=0;
9790 do {
9791 lx=((zplu+v.z)*fxle->n3+0.5);
9792 zplu++;
9793 }while (lx<0);
9794 mx=jx-floor(jx);
9795 my=kx-floor(kx);
9796 mz=lx-floor(lx);
9797 ji=((int)jx)%fxle->n1;//
9798 ki=((int)kx)%fxle->n2;//
9799 li=((int)lx)%fxle->n3;//
9800 val[z]=(
9801 (1-mx)*fxle->datfo_fc[(ji+fxle->n1*(ki+li*fxle->n2))%fxle->n5]+
9802 mx*fxle->datfo_fc[((ji+1)+fxle->n1*(ki+li*fxle->n2))%fxle->n5]+
9803 (1-my)*fxle->datfo_fc[(ji+fxle->n1*(ki+li*fxle->n2))%fxle->n5]+
9804 my*fxle->datfo_fc[(ji+fxle->n1*((ki+1)+li*fxle->n2))%fxle->n5]+
9805 (1-mz)*fxle->datfo_fc[(ji+fxle->n1*(ki+li*fxle->n2))%fxle->n5]+
9806 mz*fxle->datfo_fc[(ji+fxle->n1*(ki+(li+1)*fxle->n2))%fxle->n5])/3.0;
9807 qtest.peakHeight=val[z];
9808 qtest.frac=v;
9809 qtest.Label=QString("Q%1").arg(z,-3);
9810 mole.pmin=qMin(mole.pmin, qtest.peakHeight);
9811 mole.pmax=qMax(mole.pmax, qtest.peakHeight);
9812 qpv->cutoff=0;//mole.pmin;
9813 qpv->setMin(mole.pmin);
9814 qpv->setMax(mole.pmax);
9815 mole.asymm.append(qtest);
9816 wink+=0.261799387799;
9817 }
9818 for (int z=0; z<24;z++) {
9819 t =val[z%24] ;
9820 double x = t - val[(z+25)%24];
9821 double u = t - val[(z+23)%24];
9822 if (fmin(x,u)<0) continue;
9823 double p=0.5*(u-x)/(u+x);
9824 t=t+0.25*(p*(u-x));
9825 mt=(mt>t)?mt:t;
9826 if (t<mt)continue;
9827 wink=((double) z + p )*0.261799387799;
9828 }
9829 }else {qDebug()<<"Please enable Fourier maps!";cursor.endEditBlock(); return; }
9830 v=(-(xh[5])*0.33333*a)+ mole.asymm.at(idx).pos+(xh[5])*0.942809041582*(sin(wink)*u+cos(wink)*w);
9831 htest.Label=mole.asymm.at(idx).Label.section('_',0,0);
9832 htest.part=mole.asymm.at(idx).part;
9833 htest.resiNr=mole.asymm.at(idx).resiNr;
9834 htest.Label.replace(0,1,'H');
9835 int hindex=1;
9836 QString nnn=htest.Label;
9837 QString ann=htest.Label;
9838 do {
9839 if (hindex) nnn=ann.left(3).append(QString::number(hindex+9,36));
9840 if (nnn.size()>4) nnn=ann.left(2).append(QString::number(hindex+9,36));
9841 if (htest.resiNr)
9842 nn=QString("%1_%2")//for shelxl same names in different parts are no problem but for platon so this should fix it.
9843 .arg(nnn)
9844 .arg((htest.resiNr)?QString::number(htest.resiNr):"");
9845 else nn=nnn;
9846 // qDebug()<<nn<<nnn<<(alab.contains(nn,Qt::CaseInsensitive));
9847 hindex++;
9848 }while(alab.contains(nn,Qt::CaseInsensitive));
9849 htest.Label=nnn;
9850 alab.append(nn);
9851
9852 htest.isIso=true;
9853 htest.ufiso_org=QString("-1.5");
9854 double uIso = mole.ueq(mole.asymm.at(idx).uf)*1.5;
9855 htest.uf.m11 = htest.uf.m22 = htest.uf.m33 = uIso;
9856 htest.uf.m23 = uIso * mole.cell.cosra;
9857 htest.uf.m13 = uIso * mole.cell.cosrb;
9858 htest.uf.m12 = uIso * mole.cell.cosrg;
9859 mole.Uf2Uo(htest.uf,htest.uc);
9860 htest.pos=v;
9861 mole.kart2frac(htest.pos,htest.frac);
9862 htest.orginalLine=QString("%1 %2 %3 %4 %5 %6 %7")
9863 .arg(htest.Label)
9864 .arg(qMax(1,editor->sfac.indexOf(0)+1))
9865 .arg(htest.frac.x,9,'f',5)
9866 .arg(htest.frac.y,9,'f',5)
9867 .arg(htest.frac.z,9,'f',5)
9868 .arg(mole.asymm.at(idx).sof_org)
9869 .arg("-1.5");
9870 mole.asymm.append(htest);
9871 QString label = mole.showatoms.at(idx).orginalLine.left(80).trimmed();
9872 // int afixfuenf=(mole.showatoms.at(i).afix/10)?(mole.showatoms.at(i).afix/10)*10+5:0;
9873 cursor.movePosition(QTextCursor::Start);
9874 cursor = document->find(label,cursor);
9875 if (cursor.isNull()){
9876 cursor = editor->textCursor();
9877 cursor.movePosition(QTextCursor::Start);
9878 label.chop(10);
9879 cursor = document->find(label,cursor);
9880 if (cursor.isNull()) {
9881 cursor = editor->textCursor();
9882 }
9883 }
9884 cursor.movePosition(QTextCursor::StartOfLine,QTextCursor::MoveAnchor);
9885 cursor.movePosition(QTextCursor::EndOfLine,QTextCursor::KeepAnchor);
9886 while (cursor.selectedText().endsWith("=")) {
9887 cursor.movePosition(QTextCursor::Down,QTextCursor::KeepAnchor);
9888 cursor.movePosition(QTextCursor::EndOfLine,QTextCursor::KeepAnchor);
9889 }
9890 cursor.clearSelection();
9891 cursor.movePosition(QTextCursor::Down);
9892 cursor.insertText(QString("AFIX 148\n%1\nAFIX %2\n")
9893 .arg(mole.asymm.at(mole.asymm.size()-1).orginalLine)
9894 .arg(mole.afix5(idx))
9895 );
9896 //printf("%d cursor will end edit block\n",cursor.isNull());
9897 cursor.endEditBlock();
9898 int jetztAtome=0;
9899 for (int i=0; i<mole.asymm.size();i++) if (mole.asymm.at(i).an>=0)jetztAtome++;
9900 actionHFix->setDisabled(true);
9901 fuse();
9902 QString info=QString("<font color=\"green\"><b>%1</b> Hydrogen atoms added. <b>Please SAVE before GROW!</font>").arg(jetztAtome-warmalAtome);
9903 infoKanalNews(info);
9904 }
9905
9906
9907
9908
9909 void Window::addHnonplanarAminR2(){
9910 //<! there is no afix for R-NH2 for the nonplanar case
9911 //this trys to find similar to 23 the highest density in the terahedal cone
9912 QAction *action = qobject_cast<QAction *>(sender());
9913 int i=0;
9914 if (action)
9915 i=action->data().toInt();
9916 else return;
9917 if (i>mole.asymm.size()) return;
9918 if (mole.knoepfe.at(i).neighbors.size()!=2)return;//we need 2 non h neighbors
9919 int warmalAtome=0;
9920 for (int j=0; j<mole.asymm.size();j++) if (mole.asymm.at(j).an>=0)warmalAtome++;
9921 QStringList alab;
9922 for (int i =0; i<mole.asymm.size(); i++){
9923 alab.append(mole.asymm.at(i).Label);
9924 }
9925 QString nn;
9926 double dist=0.9;//nh= (mole.asymm.at(i).an==6) ? 0.07 : 0;
9927
9928 chgl->disSelection();
9929 MyAtom htest,qtest;
9930 if (editor->sfac.indexOf(0)==-1)addNewScatteringFactor(0,false);
9931 htest.an=0;
9932 htest.part=0;
9933 htest.resiNr=0;
9934 htest.hidden=0;
9935 htest.symmGroup=0;
9936 htest.sg=0;
9937 htest.scod=555;//the identity
9938 htest.auidx=-1;
9939 htest.isIso=true;
9940 htest.uc.m11=htest.uc.m22=htest.uc.m33=0.05;
9941 htest.uc.m12=htest.uc.m23=htest.uc.m13=0.0;
9942 htest.uc.m21=htest.uc.m32=htest.uc.m31=0.0;
9943 htest.uf.m12=htest.uf.m23=htest.uf.m13=0.0;
9944 htest.uf.m21=htest.uf.m32=htest.uf.m31=0.0;
9945 qtest=htest;
9946 qtest.an=-1;
9947 QTextDocument *document = editor->document();
9948 QTextCursor cursor = editor->textCursor();
9949 cursor.beginEditBlock ();
9950 V3 v=V3(0,0,0),w=V3(0,0,0),u=V3(0,0,0) ,a=V3(0,0,0),b=V3(0,0,0),c=V3(0,0,0);
9951 a = mole.showatoms.at(mole.knoepfe.at(i).neighbors.at(0) ).pos - mole.asymm.at(i).pos;
9952 b = mole.showatoms.at(mole.knoepfe.at(i).neighbors.at(1) ).pos - mole.asymm.at(i).pos;
9953 a = c = Normalize(a) ;
9954 c = c+ (b= Normalize(b));
9955 c = Normalize(c);
9956
9957 w = Normalize(a);
9958 u = Normalize(b);
9959 double si=1.0376-0.0346*Norm(w-u); //=1.91063323625-((acos(u*w)-1.91063323625)/5.0);//-1.91063323625 = 109.47 grad ; 3.7 empirischer Wert
9960 c = (-cos(si)*dist * c);
9961 v = sin(si) *dist * Normalize(c%a);
9962 a = mole.asymm.at(i).pos + c + v;
9963 b = mole.asymm.at(i).pos + c - v;
9964 // test if pos a or b has the higher residual density
9965 double densA=0.,densB=0.;
9966 if (fxle->n5){
9967 double jx,kx,lx,mx,my,mz;
9968 mole.kart2frac(a,v);
9969 int zplu=0,ji,ki,li;
9970 do {
9971 jx=((zplu+v.x)*fxle->n1+0.5);
9972 zplu++;
9973 }while (jx<0);
9974 zplu=0;
9975 do {
9976 kx=((zplu+v.y)*fxle->n2+0.5);
9977 zplu++;
9978 }while (kx<0);
9979 zplu=0;
9980 do {
9981 lx=((zplu+v.z)*fxle->n3+0.5);
9982 zplu++;
9983 }while (lx<0);
9984 mx=jx-floor(jx);
9985 my=kx-floor(kx);
9986 mz=lx-floor(lx);
9987 ji=((int)jx)%fxle->n1;//
9988 ki=((int)kx)%fxle->n2;//
9989 li=((int)lx)%fxle->n3;//
9990 densA=(
9991 (1-mx)*fxle->datfo_fc[(ji+fxle->n1*(ki+li*fxle->n2))%fxle->n5]+
9992 mx*fxle->datfo_fc[((ji+1)+fxle->n1*(ki+li*fxle->n2))%fxle->n5]+
9993 (1-my)*fxle->datfo_fc[(ji+fxle->n1*(ki+li*fxle->n2))%fxle->n5]+
9994 my*fxle->datfo_fc[(ji+fxle->n1*((ki+1)+li*fxle->n2))%fxle->n5]+
9995 (1-mz)*fxle->datfo_fc[(ji+fxle->n1*(ki+li*fxle->n2))%fxle->n5]+
9996 mz*fxle->datfo_fc[(ji+fxle->n1*(ki+(li+1)*fxle->n2))%fxle->n5]);
9997
9998 mole.kart2frac(b,v);
9999 zplu=0;
10000 do {
10001 jx=((zplu+v.x)*fxle->n1+0.5);
10002 zplu++;
10003 }while (jx<0);
10004 zplu=0;
10005 do {
10006 kx=((zplu+v.y)*fxle->n2+0.5);
10007 zplu++;
10008 }while (kx<0);
10009 zplu=0;
10010 do {
10011 lx=((zplu+v.z)*fxle->n3+0.5);
10012 zplu++;
10013 }while (lx<0);
10014 mx=jx-floor(jx);
10015 my=kx-floor(kx);
10016 mz=lx-floor(lx);
10017 ji=((int)jx)%fxle->n1;//
10018 ki=((int)kx)%fxle->n2;//
10019 li=((int)lx)%fxle->n3;//
10020 densB=(
10021 (1-mx)*fxle->datfo_fc[(ji+fxle->n1*(ki+li*fxle->n2))%fxle->n5]+
10022 mx*fxle->datfo_fc[((ji+1)+fxle->n1*(ki+li*fxle->n2))%fxle->n5]+
10023 (1-my)*fxle->datfo_fc[(ji+fxle->n1*(ki+li*fxle->n2))%fxle->n5]+
10024 my*fxle->datfo_fc[(ji+fxle->n1*((ki+1)+li*fxle->n2))%fxle->n5]+
10025 (1-mz)*fxle->datfo_fc[(ji+fxle->n1*(ki+li*fxle->n2))%fxle->n5]+
10026 mz*fxle->datfo_fc[(ji+fxle->n1*(ki+(li+1)*fxle->n2))%fxle->n5]);
10027 }//n5
10028 c = c + mole.asymm.at(i).pos;
10029
10030 htest.Label=mole.asymm.at(i).Label.section('_',0,0);
10031 htest.part=mole.asymm.at(i).part;
10032 htest.resiNr=mole.asymm.at(i).resiNr;
10033 htest.Label.replace(0,1,'H');
10034 int hindex=14;//N
10035 QString nnn=htest.Label;
10036 QString ann=nnn;
10037 if (densA>densB) {
10038 //HA
10039 do {
10040 if (hindex) nnn=ann.left(3).append(QString::number(hindex+9,36));
10041 if (nnn.size()>4) nnn=ann.left(2).append(QString::number(hindex+9,36));
10042 if (htest.resiNr)
10043 nn=QString("%1_%2")//for shelxl same names in different parts are no problem but for platon so this should fix it.
10044 .arg(nnn)
10045 .arg((htest.resiNr)?QString::number(htest.resiNr):"");
10046 else nn=nnn;
10047 hindex++;
10048 }while(alab.contains(nn,Qt::CaseInsensitive));
10049 htest.Label=nnn;
10050 alab.append(nn);
10051 htest.isIso=true;
10052 htest.ufiso_org=QString("-1.2");
10053 double uIso = mole.ueq(mole.asymm.at(i).uf)*1.2;
10054 htest.uf.m11 = htest.uf.m22 = htest.uf.m33 = uIso;
10055 htest.uf.m23 = uIso * mole.cell.cosra;
10056 htest.uf.m13 = uIso * mole.cell.cosrb;
10057 htest.uf.m12 = uIso * mole.cell.cosrg;
10058 mole.Uf2Uo(htest.uf,htest.uc);
10059 htest.pos=a;
10060 mole.kart2frac(htest.pos,htest.frac);
10061 htest.orginalLine=QString("%1 %2 %3 %4 %5 %6 %7")
10062 .arg(htest.Label)
10063 .arg(qMax(1,editor->sfac.indexOf(0)+1))
10064 .arg(htest.frac.x,9,'f',5)
10065 .arg(htest.frac.y,9,'f',5)
10066 .arg(htest.frac.z,9,'f',5)
10067 .arg(mole.asymm.at(i).sof_org)
10068 .arg("-1.2");
10069 mole.asymm.append(htest);
10070 } else {
10071 //HB
10072 do {
10073 if (hindex) nnn=ann.left(3).append(QString::number(hindex+9,36));
10074 if (nnn.size()>4) nnn=ann.left(2).append(QString::number(hindex+9,36));
10075 if (htest.resiNr)
10076 nn=QString("%1_%2")//for shelxl same names in different parts are no problem but for platon so this should fix it.
10077 .arg(nnn)
10078 .arg((htest.resiNr)?QString::number(htest.resiNr):"");
10079 else nn=nnn;
10080 hindex++;
10081 }while(alab.contains(nn,Qt::CaseInsensitive));
10082 htest.Label=nnn;
10083 alab.append(nn);
10084 htest.pos=b;
10085 mole.kart2frac(htest.pos,htest.frac);
10086 htest.orginalLine=QString("%1 %2 %3 %4 %5 %6 %7")
10087 .arg(htest.Label)
10088 .arg(qMax(1,editor->sfac.indexOf(0)+1))
10089 .arg(htest.frac.x,9,'f',5)
10090 .arg(htest.frac.y,9,'f',5)
10091 .arg(htest.frac.z,9,'f',5)
10092 .arg(mole.asymm.at(i).sof_org)
10093 .arg("-1.2");
10094 mole.asymm.append(htest);
10095 }
10096 QString label = mole.showatoms.at(i).orginalLine.left(80).trimmed();
10097 cursor.movePosition(QTextCursor::Start);
10098 cursor = document->find(label,cursor);
10099 if (cursor.isNull()){
10100 cursor = editor->textCursor();
10101 cursor.movePosition(QTextCursor::Start);
10102 label.chop(10);
10103 cursor = document->find(label,cursor);
10104 if (cursor.isNull()) {
10105 cursor = editor->textCursor();
10106 }
10107 }
10108 cursor.movePosition(QTextCursor::StartOfLine,QTextCursor::MoveAnchor);
10109 cursor.movePosition(QTextCursor::EndOfLine,QTextCursor::KeepAnchor);
10110 while (cursor.selectedText().endsWith("=")) {
10111 cursor.movePosition(QTextCursor::Down,QTextCursor::KeepAnchor);
10112 cursor.movePosition(QTextCursor::EndOfLine,QTextCursor::KeepAnchor);
10113 }
10114 cursor.clearSelection();
10115 cursor.movePosition(QTextCursor::Down);
10116 cursor.insertText(QString("REM HFIX R2N-H\n%1\n") .arg(mole.asymm.last().orginalLine));
10117 //now comes some DFIX/DANG/SADI stuff
10118 cursor.movePosition(QTextCursor::Start,QTextCursor::MoveAnchor);
10119 cursor = document->find(unitinst,cursor);
10120 cursor.movePosition(QTextCursor::StartOfLine,QTextCursor::MoveAnchor);
10121 cursor.movePosition(QTextCursor::Down,QTextCursor::MoveAnchor);
10122 QString rns="";
10123 if (mole.asymm.at(i).resiNr!=0) rns=QString("_%1").arg(mole.asymm.at(i).resiNr);
10124 QString buffer = QString("DFIX%1 %2 %3 %4\n")
10125 .arg(rns)
10126 .arg(dist,0,'f',2)
10127 .arg(mole.asymm.at(i).Label.section('_',0,0))
10128 .arg(mole.asymm.last().Label);
10129 cursor.insertText(buffer);
10130 for (int z = 0; z < mole.knoepfe.at(i).neighbors.size(); z++){
10131 buffer.clear();
10132 double einsdrei=sqrt(Distance(mole.asymm.last().pos,mole.showatoms.at(mole.knoepfe.at(i).neighbors.at(z)).pos));//showatoms because this might be not in asymmeric unit
10133 QString LL=mole.showatoms.at(mole.knoepfe.at(i).neighbors.at(z)).Label.section('_',0,0),dollarN="";
10134 if (mole.showatoms.at(mole.knoepfe.at(i).neighbors.at(z)).symmGroup>0){
10135 int eq = document->toPlainText().count("EQIV", Qt::CaseInsensitive)+1;
10136 dollarN=QString("$%1").arg(eq);
10137 buffer = QString("EQIV %1 %2\n").arg(dollarN).arg(mole.symmcode2human(mole.showatoms.at(mole.knoepfe.at(i).neighbors.at(z)).sg));
10138 dollarN.prepend('_');
10139 LL=LL.section(QString::fromUtf8("»"),0,0);
10140 }
10141 buffer += QString("DANG%1 %2 %3%4 %5\n")
10142 .arg(rns)
10143 .arg(einsdrei,0,'f',2)
10144 .arg(LL)
10145 .arg(dollarN)
10146 .arg(mole.asymm.last().Label);
10147 cursor.insertText(buffer);
10148
10149 }
10150 cursor.endEditBlock();
10151 int jetztAtome=0;
10152 for (int i=0; i<mole.asymm.size();i++) if (mole.asymm.at(i).an>=0)jetztAtome++;
10153 actionHFix->setDisabled(true);
10154 fuse();
10155 QString info=QString("<font color=\"green\"><b>%1</b> Hydrogen atoms added. <b>Please SAVE before GROW!</font>").arg(jetztAtome-warmalAtome);
10156 infoKanalNews(info);
10157 }
10158
10159 void Window::addHnonplanarAminR1(){
10160 //<! there is no afix for R-NH2 for the nonplanar case
10161 //this trys to find similar to 137 the highest density in the terahedal cone
10162 QAction *action = qobject_cast<QAction *>(sender());
10163 int i=0;
10164 if (action)
10165 i=action->data().toInt();
10166 else return;
10167 if (i>mole.asymm.size()) return;
10168 int warmalAtome=0;
10169 for (int j=0; j<mole.asymm.size();j++) if (mole.asymm.at(j).an>=0)warmalAtome++;
10170
10171 chgl->disSelection();
10172 MyAtom htest,qtest;
10173 if (editor->sfac.indexOf(0)==-1)addNewScatteringFactor(0,false);
10174 QStringList alab;
10175 for (int i =0; i<mole.asymm.size(); i++){
10176 alab.append(mole.asymm.at(i).Label);
10177 }
10178 QString nn;
10179 htest.an=0;
10180 htest.part=0;
10181 htest.resiNr=0;
10182 htest.hidden=0;
10183 htest.symmGroup=0;
10184 htest.sg=0;
10185 htest.scod=555;//the identity
10186 htest.auidx=-1;
10187 htest.isIso=true;
10188 htest.uc.m11=htest.uc.m22=htest.uc.m33=0.05;
10189 htest.uc.m12=htest.uc.m23=htest.uc.m13=0.0;
10190 htest.uc.m21=htest.uc.m32=htest.uc.m31=0.0;
10191 htest.uf.m12=htest.uf.m23=htest.uf.m13=0.0;
10192 htest.uf.m21=htest.uf.m32=htest.uf.m31=0.0;
10193 qtest=htest;
10194 qtest.an=-1;
10195 QTextDocument *document = editor->document();
10196 QTextCursor cursor = editor->textCursor();
10197 cursor.beginEditBlock ();
10198 V3 v=V3(0,0,0),w=V3(0,0,0),u=V3(0,0,0) ,a=V3(0,0,0);//,b=V3(0,0,0),c=V3(0,0,0);
10199 a = mole.showatoms.at(mole.knoepfe.at(i).neighbors.at(0)).pos - mole.asymm.at(i).pos;
10200 int ji, ki, li, main[24], fi=0,az=0,bz=0;
10201 a=Normalize(a);
10202 double jx,kx,lx,mx,my,mz,dist=0.89;
10203 bool andersrum=false;
10204 double val[24],wink=0,t=0,mt=0.0,mava[24];
10205 if (fxle->n5){
10206 for (int z=0; z<24; z++){
10207 main[z] = -1;
10208 mava[z] = 0.0;
10209 w=Normalize(V3(0,0,1)%a);
10210 u=Normalize(w%a);
10211 v=(-dist*0.33333*a)+ mole.asymm.at(i).pos+dist*0.942809041582*(sin(wink)*u+cos(wink)*w);
10212 qtest.pos=v;
10213 mole.kart2frac(v,v);
10214 int zplu=0;
10215 do {
10216 jx=((zplu+v.x)*fxle->n1+0.5);
10217 zplu++;
10218 }while (jx<0);
10219 zplu=0;
10220 do {
10221 kx=((zplu+v.y)*fxle->n2+0.5);
10222 zplu++;
10223 }while (kx<0);
10224 zplu=0;
10225 do {
10226 lx=((zplu+v.z)*fxle->n3+0.5);
10227 zplu++;
10228 }while (lx<0);
10229 mx=jx-floor(jx);
10230 my=kx-floor(kx);
10231 mz=lx-floor(lx);
10232 ji=((int)jx)%fxle->n1;//
10233 ki=((int)kx)%fxle->n2;//
10234 li=((int)lx)%fxle->n3;//
10235 val[z]=(
10236 (1-mx)*fxle->datfo_fc[(ji+fxle->n1*(ki+li*fxle->n2))%fxle->n5]+
10237 mx*fxle->datfo_fc[((ji+1)+fxle->n1*(ki+li*fxle->n2))%fxle->n5]+
10238 (1-my)*fxle->datfo_fc[(ji+fxle->n1*(ki+li*fxle->n2))%fxle->n5]+
10239 my*fxle->datfo_fc[(ji+fxle->n1*((ki+1)+li*fxle->n2))%fxle->n5]+
10240 (1-mz)*fxle->datfo_fc[(ji+fxle->n1*(ki+li*fxle->n2))%fxle->n5]+
10241 mz*fxle->datfo_fc[(ji+fxle->n1*(ki+(li+1)*fxle->n2))%fxle->n5]);
10242 qtest.peakHeight=val[z];
10243 qtest.frac=v;
10244 qtest.Label=QString("Q%1").arg(z,-3);
10245 mole.pmin=qMin(mole.pmin, qtest.peakHeight);
10246 mole.pmax=qMax(mole.pmax, qtest.peakHeight);
10247 qpv->cutoff=0;//mole.pmin;
10248 qpv->setMin(mole.pmin);
10249 qpv->setMax(mole.pmax);
10250 mole.asymm.append(qtest);
10251 wink+=0.261799387799;
10252 }
10253 for (int z=0; z<24;z++) {
10254 t = val[(z+24)%24] ;
10255 double x = t - val[(z+25)%24];
10256 double u = t - val[(z+23)%24];
10257 if (fmin(x,u)<0.0) continue;
10258 double p=0.5*(u-x)/(u+x);
10259 t=t+0.25*(p*(u-x));
10260 mt=(mt>t)?mt:t;
10261 main[fi]=z;
10262 mava[fi]=t;
10263 fi++;
10264 if (t<mt)continue;
10265 az=z;
10266 wink=((double) z + p )*0.261799387799;
10267 }
10268 double m2t=0.0;
10269 for (int z=0; z<fi; z++){
10270 //printf("%d#%f ",main[z],mava[z]);
10271 if (main[z] != az) if (m2t < mava[z]) {bz = main[z]; m2t = mava[z];}
10272 }
10273 //printf("\n");
10274 andersrum=((((bz-az)+36)%24)<12);//decide on which side is the other H
10275 //printf("2nd->%d andersrum %d %d %d\n", ((bz-az)+36)%24, andersrum,az,bz);
10276 }else{
10277 int zzz=0;
10278 int z=mole.knoepfe.at(mole.knoepfe.at(i).neighbors.at(0)).neighbors.at(zzz++);
10279 while ((z==i)&&(zzz<mole.knoepfe.at(mole.knoepfe.at(i).neighbors.at(0)).neighbors.size())) {
10280 z=mole.knoepfe.at(mole.knoepfe.at(i).neighbors.at(0)).neighbors.at(zzz++);
10281 }
10282 w=Normalize(V3(0,0,1)%a);
10283 u=Normalize(w%a);
10284 v=(-dist*0.33333*a)+ mole.asymm.at(i).pos+dist*0.942809041582*(sin(wink)*u+cos(wink)*w);
10285 V3 increm = V3(0.0, 0.0, 0.0);
10286 if ( z == i ) {
10287 increm = V3(0.00001, 0.00001, 0.00001);
10288 }
10289 wink=mole.dieder(mole.showatoms.at(mole.knoepfe.at(i).neighbors.at(0)).pos+increm-mole.asymm.at(z).pos,
10290 mole.asymm.at(i).pos-mole.showatoms.at(mole.knoepfe.at(i).neighbors.at(0)).pos,
10291 v-mole.asymm.at(i).pos)/180.0*M_PI;
10292 }
10293 v=(-dist*0.33333*a)+ mole.asymm.at(i).pos+dist*0.942809041582*(sin(wink)*u+cos(wink)*w);
10294 htest.Label=mole.asymm.at(i).Label.section('_',0,0);
10295 htest.part=mole.asymm.at(i).part;
10296 htest.resiNr=mole.asymm.at(i).resiNr;
10297 htest.Label.replace(0,1,'H');
10298 QString nnn=htest.Label;
10299 QString ann=nnn;
10300 int hindex=1;
10301 //HA
10302 do {
10303 if (hindex) nnn=ann.left(3).append(QString::number(hindex+9,36));
10304 if (nnn.size()>4) nnn=ann.left(2).append(QString::number(hindex+9,36));
10305 if (htest.resiNr)
10306 nn=QString("%1_%2")//for shelxl same names in different parts are no problem but for platon so this should fix it.
10307 .arg(nnn)
10308 .arg((htest.resiNr)?QString::number(htest.resiNr):"");
10309 else nn=nnn;
10310 hindex++;
10311 }while(alab.contains(nn,Qt::CaseInsensitive));
10312 htest.Label=nnn;
10313 htest.isIso=true;
10314 htest.ufiso_org=QString("-1.5");
10315 double uIso = mole.ueq(mole.asymm.at(i).uf)*1.5;
10316 htest.uf.m11 = htest.uf.m22 = htest.uf.m33 = uIso;
10317 htest.uf.m23 = uIso * mole.cell.cosra;
10318 htest.uf.m13 = uIso * mole.cell.cosrb;
10319 htest.uf.m12 = uIso * mole.cell.cosrg;
10320 mole.Uf2Uo(htest.uf,htest.uc);
10321 htest.pos=v;
10322 mole.kart2frac(htest.pos,htest.frac);
10323 htest.orginalLine=QString("%1 %2 %3 %4 %5 %6 %7")
10324 .arg(htest.Label)
10325 .arg(qMax(1,editor->sfac.indexOf(0)+1))
10326 .arg(htest.frac.x,9,'f',5)
10327 .arg(htest.frac.y,9,'f',5)
10328 .arg(htest.frac.z,9,'f',5)
10329 .arg(mole.asymm.at(i).sof_org)
10330 .arg("-1.5");
10331 mole.asymm.append(htest);
10332 wink+=2.09439510239;
10333 if (andersrum) wink+=2.09439510239;
10334 v=(-dist*0.33333*a)+ mole.asymm.at(i).pos+dist*0.942809041582*(sin(wink)*u+cos(wink)*w);
10335 //HB
10336 do {
10337 if (hindex) nnn=ann.left(3).append(QString::number(hindex+9,36));
10338 if (nnn.size()>4) nnn=ann.left(2).append(QString::number(hindex+9,36));
10339 if (htest.resiNr)
10340 nn=QString("%1_%2")//for shelxl same names in different parts are no problem but for platon so this should fix it.
10341 .arg(nnn)
10342 .arg((htest.resiNr)?QString::number(htest.resiNr):"");
10343 else nn=nnn;
10344 hindex++;
10345 }while(alab.contains(nn,Qt::CaseInsensitive));
10346 htest.Label=nnn;
10347 htest.pos=v;
10348 mole.kart2frac(htest.pos,htest.frac);
10349 htest.orginalLine=QString("%1 %2 %3 %4 %5 %6 %7")
10350 .arg(htest.Label)
10351 .arg(qMax(1,editor->sfac.indexOf(0)+1))
10352 .arg(htest.frac.x,9,'f',5)
10353 .arg(htest.frac.y,9,'f',5)
10354 .arg(htest.frac.z,9,'f',5)
10355 .arg(mole.asymm.at(i).sof_org)
10356 .arg("-1.5");
10357 mole.asymm.append(htest);
10358 QString label = mole.showatoms.at(i).orginalLine.left(80).trimmed();
10359 cursor.movePosition(QTextCursor::Start);
10360 cursor = document->find(label,cursor);
10361 if (cursor.isNull()){
10362 cursor = editor->textCursor();
10363 cursor.movePosition(QTextCursor::Start);
10364 label.chop(10);
10365 cursor = document->find(label,cursor);
10366 if (cursor.isNull()) {
10367 cursor = editor->textCursor();
10368 }
10369 }
10370 cursor.movePosition(QTextCursor::StartOfLine,QTextCursor::MoveAnchor);
10371 cursor.movePosition(QTextCursor::EndOfLine,QTextCursor::KeepAnchor);
10372 while (cursor.selectedText().endsWith("=")) {
10373 cursor.movePosition(QTextCursor::Down,QTextCursor::KeepAnchor);
10374 cursor.movePosition(QTextCursor::EndOfLine,QTextCursor::KeepAnchor);
10375 }
10376 cursor.clearSelection();
10377 cursor.movePosition(QTextCursor::Down);
10378 cursor.insertText(QString("REM R-NH2 (non planar) FIX \n%1\n%2\n")
10379 .arg(mole.asymm.at(mole.asymm.size()-2).orginalLine)
10380 .arg(mole.asymm.at(mole.asymm.size()-1).orginalLine)
10381 );
10382 //now comes some DFIX/DANG/SADI stuff
10383 //
10384 cursor.movePosition(QTextCursor::Start,QTextCursor::MoveAnchor);
10385 cursor = document->find(unitinst,cursor);
10386 cursor.movePosition(QTextCursor::StartOfLine,QTextCursor::MoveAnchor);
10387 cursor.movePosition(QTextCursor::Down,QTextCursor::MoveAnchor);
10388 //printf("Resinr %d %d\n",mole.asymm.at(i).resiNr,(mole.asymm.at(i).resiNr!=0) );
10389 QString rns="";
10390 if (mole.asymm.at(i).resiNr!=0) rns=QString("_%1").arg(mole.asymm.at(i).resiNr);
10391 QString buffer = QString("DFIX%1 %2 %3 %4\n")
10392 .arg(rns)
10393 .arg(dist,0,'f',2)
10394 .arg(mole.asymm.at(i).Label.section('_',0,0))
10395 .arg(mole.asymm.at(mole.asymm.size()-2).Label);
10396 cursor.insertText(buffer);
10397 buffer = QString("DFIX%1 %2 %3 %4\n")
10398 .arg(rns)
10399 .arg(dist,0,'f',2)
10400 .arg(mole.asymm.at(i).Label.section('_',0,0))
10401 .arg(mole.asymm.at(mole.asymm.size()-1).Label);
10402 cursor.insertText(buffer);
10403 buffer = QString("DANG%1 %2 %3 %4! 1,3 dist H..H\n")
10404 .arg(rns)
10405 .arg(1.5)
10406 .arg(mole.asymm.at(mole.asymm.size()-2).Label)
10407 .arg(mole.asymm.at(mole.asymm.size()-1).Label);
10408 cursor.insertText(buffer);
10409 int nnb=mole.knoepfe.at(i).neighbors.at(0);
10410 rns="";
10411 if (mole.asymm.at(nnb).resiNr!=0) rns=QString("_%1").arg(mole.asymm.at(nnb).resiNr);
10412
10413 buffer = QString("SADI%1 %2 %3 %4 %5\n")
10414 .arg(rns)
10415 .arg(mole.asymm.at(nnb).Label.section('_',0,0))
10416 .arg(mole.asymm.at(mole.asymm.size()-2).Label)
10417 .arg(mole.asymm.at(nnb).Label.section('_',0,0))
10418 .arg(mole.asymm.at(mole.asymm.size()-1).Label);
10419
10420 buffer = QString("DANG%1 %2 %3 %4 %3 %5!\n")
10421 .arg(rns)
10422 .arg(2.0)
10423 .arg(mole.asymm.at(nnb).Label.section('_',0,0))
10424 .arg(mole.asymm.at(mole.asymm.size()-2).Label)
10425 .arg(mole.asymm.at(mole.asymm.size()-1).Label);
10426
10427 cursor.insertText(buffer);
10428
10429 //
10430 cursor.endEditBlock();
10431 int jetztAtome=0;
10432 for (int i=0; i<mole.asymm.size();i++) if (mole.asymm.at(i).an>=0)jetztAtome++;
10433 actionHFix->setDisabled(true);
10434 fuse();
10435 QString info=QString("<font color=\"green\"><b>%1</b> Hydrogen atoms added. <b>Please SAVE before GROW!</font>").arg(jetztAtome-warmalAtome);
10436 infoKanalNews(info);
10437 }
10438
10439 bool peakcomp(MyAtom &a1,MyAtom &a2){
10440 return (a1.peakHeight>a2.peakHeight);
10441 }
10442
10443 void Window::addMoreQPeaks(){
10444 if (mole.asymm.isEmpty()) return;
10445 if (fxle->n5==0) return;
10446
10447 for (int i=mole.asymm.size()-1; i>=0; i--){
10448 if (mole.asymm.at(i).an<0) mole.asymm.removeAt(i);
10449 }
10450 MyAtom htest;
10451 htest.an=-1;
10452 htest.part=0;
10453 htest.resiNr=0;
10454 htest.hidden=0;
10455 htest.frac=V3(0,0,0);
10456 htest.pos=V3(0,0,0);
10457 htest.resiNr=0;
10458 htest.part=0;
10459 htest.style=1;
10460 htest.symmGroup=0;
10461 htest.sg=0;
10462 htest.scod=555;//the identity
10463 htest.auidx=-1;
10464 htest.uc.m12=htest.uc.m23=htest.uc.m13=0.0;
10465 htest.uc.m21=htest.uc.m32=htest.uc.m31=0.0;
10466 htest.uf.m12=htest.uf.m23=htest.uf.m13=0.0;
10467 htest.uf.m21=htest.uf.m32=htest.uf.m31=0.0;
10468 htest.uf.m11=0.05;
10469 htest.isIso=true;
10470 htest.uc.m11=htest.uc.m22=htest.uc.m33=htest.uf.m11;
10471 float x,y,z,u,v,w,p,q,r,t;
10472 int ipeak=0;
10473 mole.pmin=10000;
10474 mole.pmax=-10000;
10475 QList<MyAtom> peaks;
10476 for (int k=0;k<fxle->n3;k++){
10477 for (int j=0;j<fxle->n2;j++){
10478 for (int i=0;i<fxle->n1;i++){
10479 if (ipeak>MaxNumberOfPeaks) continue;
10480 t = fxle->datfo_fc[i+ fxle->n1*(j+k*fxle->n2)];
10481 x = t - fxle->datfo_fc[((i+1)%fxle->n1) + fxle->n1*(j+k*fxle->n2)];
10482 y = t - fxle->datfo_fc[i+ fxle->n1*(((j+1)%fxle->n2)+k*fxle->n2)];
10483 z = t - fxle->datfo_fc[i+ fxle->n1*(j+((k+1)%fxle->n3)*fxle->n2)];
10484 u = t - fxle->datfo_fc[((i+fxle->n1-1)%fxle->n1)+ fxle->n1*(j+k*fxle->n2)];
10485 v = t - fxle->datfo_fc[i+ fxle->n1*(((j+fxle->n2-1)%fxle->n2)+k*fxle->n2)];
10486 w = t - fxle->datfo_fc[i+ fxle->n1*(j+((k+fxle->n2-1)%fxle->n3)*fxle->n2)];
10487 if (fmin(x,fmin(y,fmin(z,fmin(u,fmin(v,w)))))<0) continue;
10488 p=0.5*(u-x)/(u+x);
10489 q=0.5*(v-y)/(v+y);
10490 r=0.5*(w-z)/(w+z);
10491 t=t+0.25*(p*(u-x)+q*(v-y)+r*(w-z));
10492 if (t<fabs(fxle->iso[1])*1.02) continue;
10493 htest.peakHeight=t;
10494 htest.frac.x = ((double) i + p +0.5)/fxle->n1;
10495 htest.frac.y = ((double) j + q +0.5)/fxle->n2;
10496 htest.frac.z = ((double) k + r +0.5)/fxle->n3;
10497 mole.frac2kart( htest.frac, htest.pos);
10498 if (!std_isfinite(htest.frac.x)||!std_isfinite(htest.frac.y)||!std_isfinite(htest.frac.z))continue;
10499 ipeak++;
10500 mole.pmin=qMin(mole.pmin, htest.peakHeight);
10501 mole.pmax=qMax(mole.pmax, htest.peakHeight);
10502 qpv->cutoff=0;//mole.pmin;
10503 qpv->setMin(mole.pmin);
10504 qpv->setMax(mole.pmax);
10505 htest.Label=QString("Q%1").arg(ipeak,3,36,QChar('0'));
10506 peaks.append(htest);
10507 }
10508 }
10509 }
10510 if (chgl->neutrons){
10511 for (int k=0;k<fxle->n3;k++){
10512 for (int j=0;j<fxle->n2;j++){
10513 for (int i=0;i<fxle->n1;i++){
10514 if (ipeak>MaxNumberOfPeaks) continue;
10515 t = fxle->datfo_fc[i+ fxle->n1*(j+k*fxle->n2)];
10516 x = t - fxle->datfo_fc[((i+1)%fxle->n1) + fxle->n1*(j+k*fxle->n2)];
10517 y = t - fxle->datfo_fc[i+ fxle->n1*(((j+1)%fxle->n2)+k*fxle->n2)];
10518 z = t - fxle->datfo_fc[i+ fxle->n1*(j+((k+1)%fxle->n3)*fxle->n2)];
10519 u = t - fxle->datfo_fc[((i+fxle->n1-1)%fxle->n1)+ fxle->n1*(j+k*fxle->n2)];
10520 v = t - fxle->datfo_fc[i+ fxle->n1*(((j+fxle->n2-1)%fxle->n2)+k*fxle->n2)];
10521 w = t - fxle->datfo_fc[i+ fxle->n1*(j+((k+fxle->n2-1)%fxle->n3)*fxle->n2)];
10522 if (fmax(x,fmax(y,fmax(z,fmax(u,fmax(v,w)))))>0) continue;
10523 p=0.5*(u-x)/(u+x);
10524 q=0.5*(v-y)/(v+y);
10525 r=0.5*(w-z)/(w+z);
10526 t=t+0.25*(p*(u-x)+q*(v-y)+r*(w-z));
10527 if (t>-fabs(fxle->iso[1])*1.02) continue;
10528 htest.peakHeight=t;
10529 htest.frac.x = ((double) i + p +0.5)/fxle->n1;
10530 htest.frac.y = ((double) j + q +0.5)/fxle->n2;
10531 htest.frac.z = ((double) k + r +0.5)/fxle->n3;
10532 mole.frac2kart( htest.frac, htest.pos);
10533 if (!std_isfinite(htest.frac.x)||!std_isfinite(htest.frac.y)||!std_isfinite(htest.frac.z))continue;
10534 ipeak++;
10535 mole.pmin=qMin(mole.pmin, htest.peakHeight);
10536 mole.pmax=qMax(mole.pmax, htest.peakHeight);
10537 qpv->cutoff=0;//mole.pmin;
10538 qpv->setMin(mole.pmin);
10539 qpv->setMax(mole.pmax);
10540 htest.Label=QString("Q%1").arg(ipeak,3,36,QChar('0'));
10541 peaks.append(htest);
10542 }
10543 }
10544 }
10545 }
10546
10547 #if (QT_VERSION >= 0x050000)
10548 std::sort(peaks.begin(),peaks.end(),peakcomp );
10549 #else
10550 qSort(peaks.begin(),peaks.end(),peakcomp );
10551 #endif
10552 mole.asymm+=peaks;
10553 mole.sdmcompleter();
10554 QList<MyAtom> duplicate;
10555 for (int i=0; i<mole.asymm.size(); i++){
10556 for (int j=i+1; j<mole.asymm.size(); j++){
10557 if ((mole.asymm.at(i).an>-1)||(mole.asymm.at(j).an>-1)) continue;
10558 if (Distance(mole.asymm.at(i).pos,mole.asymm.at(j).pos)<0.1) duplicate.append(mole.asymm.at(j));
10559 }
10560 }
10561 //printf("Duplicate size %d\n",duplicate.size());
10562 for (int i=0; i<duplicate.size();i++) {
10563 int rr=mole.asymm.indexOf(duplicate.at(i));
10564 if (rr<0) continue;
10565 mole.asymm.removeAt(rr);
10566 }
10567 QTextCursor cursor = editor->textCursor();
10568 cursor.beginEditBlock();
10569 editor->replace->setText("");
10570 editor->searchLE->setText("^Q\\S+\\s+1\\s+\\S+\\s+\\S+\\s+\\S+\\s+\\S+\\s+\\S+\\s+\\S+\\s*");
10571 editor->replaceAll();
10572 editor->searchLE->setText("");
10573 cursor.movePosition(QTextCursor::End);
10574 cursor.movePosition(QTextCursor::StartOfLine);
10575 ipeak=1;
10576 for (int i=0; i<mole.asymm.size(); i++){
10577 if (mole.asymm.at(i).an>-1) continue;
10578 mole.asymm[i].Label=QString("Q%1").arg(ipeak,3,36,QChar('0')).toUpper();
10579 ipeak++;
10580 mole.asymm[i].orginalLine=
10581 QString("%1 1 %2 %3 %4 %5 0.05 %6")
10582 .arg(mole.asymm.at(i).Label,-4)
10583 .arg(mole.asymm.at(i).frac.x,10,'f',6)
10584 .arg(mole.asymm.at(i).frac.y,10,'f',6)
10585 .arg(mole.asymm.at(i).frac.z,10,'f',6)
10586 .arg(mole.asymm[i].sof_org=(10+(1.0/mole.asymm.at(i).style)),9,'f',5)
10587 .arg(mole.asymm.at(i).peakHeight,9,'f',3)
10588 ;
10589 mole.asymm[i].sof=mole.asymm[i].sof_org-10;
10590
10591 cursor.insertText(mole.asymm[i].orginalLine);
10592 cursor.insertText("\n");
10593
10594 }
10595 cursor.endEditBlock();
10596
10597 mole.showatoms.clear();
10598 for (int i=0; i<mole.asymm.size(); i++){
10599 mole.showatoms.append(mole.asymm.at(i));
10600 }
10601 ////
10602 bool growYes=chgl->fuse->isVisible ();
10603 bool fuseYes=chgl->grow->isVisible ();
10604 chgl->fuse->setVisible(true);
10605 chgl->grow->setVisible(false);
10606 mole.sdmcompleter();
10607 mole.showbonds = mole.connecting(mole.showatoms);
10608
10609 chgl->mol->fuse();
10610 if (((!fuseYes)&&(growYes))||((!fuseYes)&&(!growYes))) chgl->mol->grow();
10611 else {
10612 chgl->fuse->setVisible(false);
10613 chgl->grow->setVisible(true);
10614 }
10615 infoKanalNews(mole.HumanSymmetry);
10616
10617 loadMolInTest();
10618 chgl->update();
10619 }
10620
10621 void Window::setShelxlPath(){
10622 QString s =
10623 QFileDialog::getOpenFileName(this, "Path to SHELXL executable", shelxlPath,QString(),nullptr,(useNativeDlg->isChecked())?noneopt:QFileDialog::DontUseNativeDialog);
10624 if (!s.isEmpty()){
10625 shelxlPath=s;
10626 einstellung->beginGroup("Window");
10627 einstellung->setValue("SHELXL-PATH",shelxlPath);
10628 einstellung->endGroup();
10629 if (shxPath!=NULL) shxPath->setText(shelxlPath);
10630 }
10631 }
10632
10633
10634 void Window::setFFMPEGEXE(){
10635 mole.ffmpegexe= QFileDialog::getOpenFileName(this,"path to ffmpeg.exe","ffmpeg.exe","",nullptr,(useNativeDlg->isChecked())?noneopt:QFileDialog::DontUseNativeDialog);
10636 if (ffmpegedt!=NULL) ffmpegedt->setText(mole.ffmpegexe);
10637 einstellung->beginGroup("Window");
10638 einstellung->setValue("FFMPEG.EXE",mole.ffmpegexe);
10639 einstellung->endGroup();
10640
10641 }
10642
10643 void Window::setMP4(){
10644 QString pth=dirName;
10645 pth.remove(resorins);
10646 QString s = QFileDialog::getSaveFileName(this,
10647 "save mp4 file",
10648 QString("%1.mp4").arg(pth),
10649 "Movie file (*.mp4)",nullptr,(useNativeDlg->isChecked())?noneopt:QFileDialog::DontUseNativeDialog);
10650 if (mp4file!=NULL) mp4file->setText(s);
10651 }
10652
10653 void Window::updateOutput(){
10654 #if (QT_VERSION >= 0x050300)
10655 if (runffmpeg->processId()) {
10656 #else
10657 if (runffmpeg->pid()) {
10658 #endif
10659 brs->show();
10660 QString s=brs->toPlainText();
10661 s.append(runffmpeg->readAllStandardOutput());
10662 s.append(runffmpeg->readAllStandardError());
10663 brs->setPlainText(s);
10664 }else{
10665 brs->show();
10666 QString s=brs->toPlainText();
10667 s.append(runffmpeg->readAllStandardOutput());
10668 s.append(runffmpeg->readAllStandardError());
10669 brs->setPlainText(s);
10670 QDir d=QDir::current();
10671
10672 QStringList clips;
10673 clips.append("molisoclip*");
10674 clips = d.entryList(clips);
10675 for (int i=0; i<clips.size();i++) QFile::remove(clips.at(i));
10676 QFile::remove("mcqwatermark.png");
10677 qint64 size = 0;
10678 QFile myFile(fffn);
10679 if (myFile.open(QIODevice::ReadOnly)){
10680 size = myFile.size(); //when file does open.
10681 myFile.close();
10682 }
10683 int kMGT=0;
10684 double siz=(double)size;
10685 while (siz>1024){
10686 siz/=1024;
10687 kMGT++;
10688 }
10689 QString byte="B";
10690 switch (kMGT){
10691 case 1: byte.prepend("k"); break;
10692 case 2: byte.prepend("M"); break;
10693 case 3: byte.prepend("G"); break;
10694 case 4: byte.prepend("T"); break;
10695 }
10696 QString fss=QString("%1 %2").arg(siz, 0, 'f', 2).arg(byte);
10697
10698 ffl->setText(QString("finished! %1 has %2").arg(fffn).arg(fss));
10699 bar->hide();
10700 closeFF->show();
10701 }
10702 }
10703
10704 void Window::makeRotMovi(){
10705 QDialog *tdlg = new QDialog(this);
10706 QGridLayout *l = new QGridLayout(tdlg);
10707 QDialogButtonBox *buttonBox = new QDialogButtonBox( QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
10708 connect(buttonBox, SIGNAL(accepted()), tdlg, SLOT(accept()));
10709 connect(buttonBox, SIGNAL(rejected()), tdlg, SLOT(reject()));
10710 ffmpegedt = new QLineEdit(mole.ffmpegexe);
10711 QPushButton *ffbrs = new QPushButton("Browse");
10712 connect(ffbrs,SIGNAL(pressed()),this,SLOT(setFFMPEGEXE()));
10713 QLabel *ffmpegtxt =new QLabel("Path to ffmpeg.exe <br>(You need ffmpeg.exe. You can get it from here <a href=\"https://ffmpeg.org/download.html\">https://ffmpeg.org/download.html</a> )");
10714 ffmpegtxt->setOpenExternalLinks(true);
10715 /* QRadioButton *hd720 = new QRadioButton("1280x720",tdlg);
10716 QRadioButton *hd1080 = new QRadioButton("1920x1080",tdlg);
10717 hd1080->setChecked(true);*/
10718 mp4file = new QLineEdit(QString("%1.mp4").arg(dirName));
10719 QPushButton *mp4brs = new QPushButton("Browse");
10720 connect(mp4brs,SIGNAL(pressed()),this,SLOT(setMP4()));
10721 QSpinBox *dura= new QSpinBox(tdlg);
10722 dura->setMinimum(5);
10723 dura->setMaximum(300);
10724 dura->setValue(10);
10725 dura->setSuffix("s");
10726 QSpinBox *fps= new QSpinBox(tdlg);
10727 fps->setMinimum(12);
10728 fps->setMaximum(60);
10729 fps->setValue(30);
10730
10731 l->addWidget(ffmpegtxt,0,0,1,20);
10732 l->addWidget(ffmpegedt,1,0,1,18);
10733 l->addWidget(ffbrs,1,19,1,1);
10734 //l->addWidget(hd720,2,0,1,5);
10735 // l->addWidget(hd1080,2,6,1,5);
10736 l->addWidget(new QLabel("Duration"),3,0,1,1);
10737 l->addWidget(dura,3,1,1,1);
10738 l->addWidget(new QLabel("Frames per second (FPS)"),4,0,1,1);
10739 l->addWidget(fps,4,1,1,1);
10740 l->addWidget(new QLabel("mp4 file name"),5,0,1,1);
10741 l->addWidget(mp4file,5,1,1,18);
10742 l->addWidget(mp4brs,5,19,1,1);
10743
10744 l->addWidget(buttonBox,20,0,1,20);
10745 if(tdlg->exec()==QDialog::Accepted) {
10746 if (mole.ffmpegexe.isEmpty()||mp4file->text().isEmpty()) return;
10747 QString fileName=mp4file->text();
10748 if (QFile::exists(fileName)) {
10749 QString n=fileName;
10750 QString re=QString("_%1_.mp4").arg(QDateTime::currentMSecsSinceEpoch (),0,36);
10751 n.replace(QRegularExpression(".mp4$"),re);
10752 QFile::rename(fileName,n);
10753 }
10754 int d,e;
10755 // bool hd=(hd720->isChecked()) ;
10756 int frameRate=fps->value();
10757 int frames = dura->value()*frameRate;
10758 d = chgl->width();
10759 e = chgl->height();
10760 //printf("%dx%d\n",d,e);
10761 //printf("!ungerade->%d %d\n",(d%2),d);
10762 if (d%2){
10763 chgl->setMinimumWidth(d+1);
10764 update();
10765 chgl->update();
10766 }
10767 int wi = 0;
10768 int hi = 0;
10769 d = chgl->width();
10770 e = chgl->height();
10771 wi=d;
10772 hi=e;
10773 // printf("%dx%d\n",d,e);
10774 //chgl->resize(wi,hi);
10775 //f = chgl->myFont.pointSize ();
10776 // h = chgl->MLegendFont.pointSize ();
10777 //printf("%p\n",chgl);
10778 QDialog *q =new QDialog(this);
10779 q->setWindowTitle("Wait! Movie file creation in progress");
10780 bar = new QProgressBar(q);
10781 bar->setMinimum(0);
10782 bar->setMaximum(frames);
10783 QGridLayout *g= new QGridLayout(q);
10784 g->addWidget(bar,0,0);
10785 ffl=new QLabel(QString("Please wait until movie is created!! %1 frames will be created and joined to a mp4 movie file.").arg(frames));
10786 g->addWidget(ffl,1,0);
10787 brs=new QTextBrowser(q);
10788 QTextCharFormat fmt;
10789 brs->setFontFamily(FONTFAM);
10790 QPalette p = brs->palette();
10791 p.setBrush(QPalette::Active,QPalette::Base,QColor("#242424"));
10792 brs->setPalette (p );
10793 fmt.setFontFamily(FONTFAM);
10794 fmt.setBackground(QColor("#242424"));
10795 fmt.setForeground(QColor("#DDDD00"));
10796 fmt.setFontWeight(50);
10797 brs->setCurrentCharFormat(fmt);
10798 brs->setWordWrapMode(QTextOption::WordWrap);
10799 brs->setPlainText("====================\n Output of ffmpeg: \n====================\n\n");
10800
10801 brs->hide();
10802 g->addWidget(brs,2,0);
10803 closeFF = new QPushButton("close", q);
10804 g->addWidget(closeFF,3,0);
10805 connect(closeFF,SIGNAL(released()),q,SLOT(close()));
10806 closeFF->hide();
10807
10808 q->show();
10809 //double stepssi= 1.0/frames;
10810 //QPixmap map;
10811 //printf("stepsize=%f frames %d\n",stepssi,frames);
10812 glReadBuffer(GL_FRONT);
10813 for (int i=0; i<frames; i++){
10814 ffl->setText(QString("Please wait until movie is created!! %1 of %2").arg(i).arg(frames));
10815 bar->setValue(i);
10816 char fname[255] ;
10817 // statusBar()->showMessage(tr("create pic #%1 of %2").arg(i+1).arg(frames) );
10818 sprintf(fname, "molisoclip%04d.png", i);
10819 //chgl->noWaitLabel=true;
10820 //chgl->paparazi=true;
10821 //glGetDoublev(GL_MODELVIEW_MATRIX,chgl->MM);
10822 /*
10823 map = chgl->renderPixmap(wi,hi);
10824 //chgl->paparazi=false;
10825 map.save(fname);*/
10826 QImage mapi=chgl->grabFramebuffer();
10827 int h = mapi.height();
10828 int w = mapi.width();
10829 mapi = mapi.scaled((w/2)*2,(h/2)*2);
10830 mapi.save(fname);
10831 chgl->rotY(18.0/(frames-1));
10832 //chgl->rotX(54.0/frames);
10833 //glRotated(360.0/frames,0.0,1.0,0.0);
10834 //glRotated(360/M_PI/frames,1.0,0.0,0.0);
10835 chgl->update();
10836 //printf("%d/%d\n",i,frames);
10837 q->update();
10838 q->repaint();
10839 }
10840 if (!fileName.isEmpty()) {
10841 QPixmap watermark = (chgl->dipc.name() == QString("#008080"))?QIcon(theIconPath+"IDEAL-text.png").pixmap(202, 76):
10842 QIcon(theIconPath+"shelxle-text.png").pixmap(235, 91);
10843 watermark.save("mcqwatermark.png");
10844 int wawi=watermark.width()+3;
10845 int wahi=watermark.height()+3;
10846 QStringList al;
10847 al <<"-r"<< QString("%1").arg(frameRate)<< "-f"<< "image2"<< "-s"<< QString("%1x%2").arg(wi).arg(hi)//QString("%1").arg((hd)?"1280x720":"1920x1080")
10848 <<"-start_number"<< "0"<< "-i"<< "molisoclip%04d.png"<<
10849 "-i"<< "mcqwatermark.png"<< "-filter_complex"<< QString("[0:v][1:v] overlay=%1:%2").arg(wi-wawi).arg(hi-wahi)<<
10850 "-vframes"<< QString("%1").arg(frames)<< "-codec:v"<< "libx264" <<"-crf" <<"25"<< "-pix_fmt"<< "yuv420p"<< fileName;
10851
10852 runffmpeg = new QProcess(this);
10853 QDir dn=QDir(QDir::current());
10854 runffmpeg->setWorkingDirectory(QDir::current().absolutePath()); // updateXLput()
10855 connect(runffmpeg,SIGNAL(readyReadStandardOutput ()),this,SLOT(updateOutput()));
10856 connect(runffmpeg,SIGNAL(finished(int,QProcess::ExitStatus)),this,SLOT(updateOutput()));
10857 connect(runffmpeg,SIGNAL(errorOccurred(QProcess::ProcessError)),this,SLOT(updateOutput()));
10858
10859 runffmpeg->start(mole.ffmpegexe,al);
10860 fffn=fileName;
10861 updateOutput();
10862
10863 }
10864 //chgl->myFont.setPointSize(f);
10865 //chgl->MLegendFont.setPointSize(h);
10866 //chgl->_win_width=d;
10867 //chgl->_win_height=e;
10868 //chgl->noWaitLabel=chgl->quickRot->isChecked();
10869 //q->close();
10870 // filmFred = new TMovieThread(frames,wi,hi,d,e,f,h,chgl,fileName,hd720->isChecked());
10871 //connect(filmFred,SIGNAL(finished ()),q,SLOT(close()));
10872 // filmFred->start();
10873 }
10874 }
10875
10876 void Window::savePovRay(){
10877 // printf("save p o v r a y\n");
10878 QString s1="",s2="",s3="";
10879 GLdouble mv[16];
10880 chgl->makeCurrent();
10881 //glGetDoublev(GL_MODELVIEW_MATRIX, mv);
10882 chgl->getMVmat(mv);
10883
10884 QString povName = dirName, iniName,incName;
10885 povName.replace(resorins,".pov");
10886 QString fn=QFileDialog::getSaveFileName(this, tr("Export POV-Ray scene"), povName, tr("POV-Ray files (*.pov)"));
10887 if (fn.isEmpty()) return;
10888 savePovInc(fn);
10889 povName=fn;
10890 iniName=fn;
10891 iniName.replace(punktpov,".ini");
10892 incName=fn;
10893 incName.replace(punktpov,".inc");
10894 pngName=fn;
10895 pngName.replace(punktpov,".png");
10896 QFile f(fn);
10897 QString headerPOV; // 1st part of PoV-Ray file
10898 QString visableAtoms; // used to save ellipsoids of _un-selected_ atoms in _visable_ part of pov-file
10899 QString hiddenAtoms; // used to save ellipsoids of _selected_ atoms in _hidden_ part of pov-file
10900 QString hydrogenAtoms; // used to save hydrogens data
10901 QString hiddenHAtoms; // used to save hydrogens data of _selected_ atoms in _hidden_ part of pov-file
10902 QString qpeaks; //Q peaks...
10903 QString unitCell;
10904 QString densityMaps; //Fo and Fo-Fc map or the IDEAL BODD map.
10905 QString labels;
10906 QString bondsPOV; // used for bonds in povray
10907 QString hidePOV;
10908 QString ringsPOV;
10909 QString voron;
10910 QString footerPOV;
10911 QString body;
10912 bool foundInSelected = false;
10913 GLdouble det=pow(mv[0]*mv[5]*mv[10] - mv[8]*mv[5]*mv[2] + mv[1]*mv[6]*mv[8] - mv[9]*mv[6]*mv[0] + mv[2]*mv[4]*mv[9] - mv[10]*mv[4]*mv[1], 1.0/3.0);
10914 mv[0]/=det; mv[1]/=det; mv[2]/=det; mv[4]/=det; mv[5]/=det; mv[6]/=det; mv[8]/=det; mv[9]/=det; mv[10]/=det;
10915 Matrix rm = Matrix(mv[0], mv[1], mv[2], mv[4], mv[5], mv[6], mv[8], mv[9], mv[10]);
10916 //for (int i=0; i<16; i++) printf("%10.5f i=%d%c",mv[i],i,((i % 4)==3)?'\n':' ');
10917 Matrix irm = inverse(rm);
10918 // POV-Ray Header
10919 headerPOV.append(QString("/*\n POV-Ray - 3.7 Scene Description File \n"));
10920 headerPOV.append(QString("Experimental POV-ray shelXLe-exporter by K.Radacki and C.B.Hubschle\n"));
10921 headerPOV.append(QString("This file is generated from: \n"));
10922 headerPOV.append(QString("%1 \n*/\n\n").arg(dirName));
10923 headerPOV.append(QString("#version 3.7;\n"));
10924 headerPOV.append(QString("global_settings{charset utf8}\n"));
10925 headerPOV.append(QString("#include \"transforms.inc\"\n"));
10926 headerPOV.append(QString("#include \"colors.inc\"\n"));
10927 headerPOV.append(QString("#include \"textures.inc\"\n"));
10928 //headerPOV.append(QString("#include \"metals.inc\"\n"));
10929 headerPOV.append(QString("#include \"shapes.inc\"\n"));
10930 headerPOV.append(QString("#include \"shapes2.inc\"\n"));
10931 headerPOV.append(QString("global_settings { assumed_gamma 1.2 ambient_light rgb < 1, 1, 1 > }\n"));
10932
10933 headerPOV.append(QString("#declare InvMat = transform {matrix \n<%1, %2, %3,\n %4, %5, %6,\n %7, %8, %9,\n 0.0, 0.0, 0.0>};\n")
10934 .arg(irm.m11,9,'g',6)
10935 .arg(irm.m12,9,'g',6)
10936 .arg(irm.m13,9,'g',6)
10937 .arg(irm.m21,9,'g',6)
10938 .arg(irm.m22,9,'g',6)
10939 .arg(irm.m23,9,'g',6)
10940 .arg(irm.m31,9,'g',6)
10941 .arg(irm.m32,9,'g',6)
10942 .arg(irm.m33,9,'g',6));
10943 headerPOV.append(QString("#declare EyeDir = vtransform(<0,0,1>,InvMat);//This is for the labels. It moves them closer to You. change it to move all label.s\n"));
10944 headerPOV.append(QString("#declare CameraDistance = %1;\n").arg((-mv[14]),0,'f',3));
10945 headerPOV.append(QString("#declare ViewAngle = %1;\n").arg(chgl->viewAngle,0,'f',3));
10946
10947 headerPOV.append(QString("#declare SCALE = %1/(image_width/image_height);// scale factor L=%2 dim=%3 %4 %5\n\n")
10948 .arg(chgl->getScaleing()/(.34*det*29.0/(chgl->viewAngle)))
10949 .arg(chgl->getScaleing())
10950 .arg(mole.dimension())
10951 .arg((.34*det*29.0/(chgl->viewAngle)))
10952 .arg(det));
10953
10954 headerPOV.append(QString("camera { perspective\n"));
10955 headerPOV.append(QString(" location < 0, 0 , CameraDistance >\n"));
10956 headerPOV.append(QString(" right < -image_width/image_height, 0, 0>\n"));
10957 headerPOV.append(QString(" look_at < 0, 0 , 0 >\n"));
10958 headerPOV.append(QString(" angle ViewAngle\n}\n\n"));//.arg(chgl->viewAngle,7,'f',1));
10959 headerPOV.append(QString("#declare DrawAromaticRings = true; // You need to place Centroids in the center of each ring for this.\n"));
10960 headerPOV.append(QString("#declare DrawRoundCorners = true;\n"));
10961 headerPOV.append(QString("#declare BW = false; // true = Black&White false = Color\n"));
10962 headerPOV.append(QString("#declare NoADP4Selected = true; // true = Visible false = Hidden\n"));
10963 headerPOV.append(QString("#declare Hiso = false; // true = Uiso false = r=Bond_Radius*1.3*Prob\n"));
10964 headerPOV.append(QString("#declare DrawHydrogens = true; // true = Visible false = Hidden\n"));
10965 headerPOV.append(QString("/* 'Hydrogens' here are all atoms with an isotropic ADP. Atoms with anisotropic ADP are considered to be non Hydrogen atoms.*/ \n"));
10966 //printf("sur vive %d %p \n",__LINE__,chgl->h_bonds);
10967 //printf("sur vive %d %p \n",__LINE__,chgl->togUnit);
10968 //printf("sur vive %d %p \n",__LINE__,chgl->atomLegend);
10969 //printf("sur vive %d %p \n",__LINE__,chgl->qPeakBonds);
10970 //printf("sur vive %d %d \n",__LINE__,chgl->mol->noQPeaksPlease);
10971 //printf("sur vive %d %p \n",__LINE__,chgl->qPeakBonds);
10972 headerPOV.append(QString("#declare DrawH_Bonds = %1; // true = Visible false = Hidden\n").arg(chgl->h_bonds->isChecked()?"true":"false"));
10973 headerPOV.append(QString("#declare DrawUnitCell = %1; // true = Visible false = Hidden\n").arg(chgl->togUnit->isChecked()?"true":"false"));
10974 headerPOV.append(QString("#declare CellWidth = 0.02; // line width of unit cell\n"));
10975 headerPOV.append(QString("#declare DrawLegend = %1; // true = Visible false = Hidden\n").arg(chgl->atomLegend->isChecked()?"true":"false"));
10976 headerPOV.append(QString("#declare DrawQPeaks = %1; // true = Visible false = Hidden\n").arg(chgl->mol->noQPeaksPlease?"false ":"true "));
10977 headerPOV.append(QString("#declare DrawQPeaksBonds = %1; // connecting lines between Q-peaks\n").arg(chgl->qPeakBonds->isChecked()?"true":"false"));
10978 headerPOV.append(QString("#declare BGGradient = %1; // Background Gradient as in ShelXle!\n\n").arg(togBackGr->isChecked()?"true":"false"));
10979 headerPOV.append(QString("#declare QPeakRad = %1; // icosahedron size\n").arg(chgl->mol->qPeakRad * 2.0));
10980 headerPOV.append(QString("#declare DrawMaps = %1;\n").arg((!chgl->fVertexes[0].isEmpty()||!chgl->fVertexes[1].isEmpty())?"true":"false"));
10981 headerPOV.append(QString("#declare DrawFo_Fc = %1;\n").arg(chgl->fofcact->isChecked()?"true":"false"));
10982 headerPOV.append(QString("#declare DrawFobserved = %1;\n").arg(chgl->foact->isChecked()?"true":"false"));
10983 headerPOV.append(QString("#declare DrawWireframeMaps = %1;\n").arg((!chgl->fillMap->isChecked())?"true":"false"));
10984 headerPOV.append(QString("#declare ForceWhiteBG = false;\n"));
10985 headerPOV.append(QString("#declare TransparentBG = true ;\n"));
10986
10987 headerPOV.append(QString("#declare UniColorBonds = %1;\n").arg((mole.bondColorStyle)?"true":"false"));
10988 headerPOV.append(QString("#declare NoShadows = true;\n"));
10989 headerPOV.append(QString("#declare DrawLabels = %1;\n").arg((togLabel->isChecked())?"true":"false"));
10990
10991 #if defined Q_WS_WIN || defined Q_OS_WIN
10992 headerPOV.append(QString("#declare atomfont = \"C:/Windows/Fonts/Arial.ttf\"//replace by any font path you like and works on your system\n"));//.arg(chgl->myFont.rawName()));
10993 #elif defined Q_WS_MAC || defined Q_OS_MAC
10994 headerPOV.append(QString("#declare atomfont = \"/System/Library/Fonts/Supplemental/Arial.ttf\"//replace by any font path you like and works on your system\n"));
10995 #else
10996 headerPOV.append(QString("#declare atomfont = \"/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf\"//replace by any font path you like and works on your system\n"));
10997 #endif
10998 headerPOV.append(QString("//ADP probability\n"
10999 "//#declare Prob = 0.76; // 10%\n"
11000 "//#declare Prob = 1.1932; // 30%\n"
11001 "//#declare Prob = 1.3672; // 40%\n"
11002 "#declare Prob = 1.5382; // 50%\n"
11003 "//#declare Prob = 1.7164; // 60%\n"
11004 "//#declare Prob = 1.9144; // 70%\n"
11005 "//#declare Prob = 2.5; // 90%\n"
11006 "\n"));
11007 headerPOV.append(QString("#declare CubeSize = 0.2; // cube size for NPD-atom\n"));
11008 headerPOV.append(QString("#declare Origin = < 0,0,0>; // declare origin \n\n"));
11009 headerPOV.append(QString("#include \"%1\"//<-This contains additional declarations.\n\n").arg(incName));
11010
11011 headerPOV.append(QString("#if (!TransparentBG)\n"));
11012 headerPOV.append(QString("#if (ForceWhiteBG)\n"));
11013 headerPOV.append(QString("background { color White}\n#else\n"));
11014 headerPOV.append(QString("#if (BW)\n background { color rgb< %1, %1, %1> }\n#else\n").arg(chgl->backGroundColor.valueF()));
11015 headerPOV.append(QString("background { color rgb<%1,%2,%3> }\n#end\n")
11016 .arg(chgl->backGroundColor.redF() ,9,'f',5)
11017 .arg(chgl->backGroundColor.greenF(),9,'f',5)
11018 .arg(chgl->backGroundColor.blueF() ,9,'f',5));
11019 headerPOV.append(QString("//Gradient Background\n"));
11020 headerPOV.append(QString("#if (BGGradient)\n"));
11021 headerPOV.append(QString("#declare dis=CameraDistance/tan(radians(ViewAngle/2));\n"));
11022 headerPOV.append(QString("mesh {\n"));
11023 headerPOV.append(QString("triangle{ <-image_width,-image_height,-dis>,< image_width,-image_height,-dis>,<-image_width, image_height,-dis> uv_vectors <0,0>, <0,0>, <0,1>}\n"));
11024 headerPOV.append(QString("triangle{<-image_width, image_height,-dis>,< image_width, image_height,-dis>,< image_width,-image_height,-dis> uv_vectors <0,1>, <0,1>, <0,0>}\n"));
11025 headerPOV.append(QString("texture {uv_mapping pigment {gradient <0,1,0>color_map {[0.0 color rgbt <1.0, 1.0, 1.0, 0.5>][1.0 color rgbt <0.3, 0.3, 0.3, 0.3>]}}finish { ambient 0.5 }}}\n"));
11026 headerPOV.append(QString("#end\n"));
11027 headerPOV.append(QString("#end //force white bg\n"));
11028 headerPOV.append(QString("#end //not transparent bg\n"));
11029 headerPOV.append(QString("light_source { < -100.0 , 100.0 , 100.0 > color rgb<1.0,1.0,1.0> parallel}\n"
11030 "//================================================================================================================================================\n"));
11031 headerPOV.append(QString("#if (DrawLegend)\n"));
11032 headerPOV.append(QString("#declare ww=tan(radians(ViewAngle/2))*CameraDistance;\n"));
11033 headerPOV.append(QString("#declare hh=ww/image_width*image_height;\n"));
11034 //headerPOV.append(QString("#debug \"HALLOHALLO\\n\"\n"));
11035 //headerPOV.append(QString("#debug concat(\"Value is:\",str(ww,0,6),\"\\n\")\n"));
11036 densityMaps.append(QString("\n//Density Maps \n#if (DrawMaps)\n#if (DrawFo_Fc)\n"));
11037 if (!chgl->fVertexes[0].isEmpty()){
11038 densityMaps.append(QString("#if (DrawWireframeMaps)\n"));
11039
11040 densityMaps.append(QString("union{\n"));
11041 for (int i=0; i<chgl->fVertexes[0].size();i+=9){
11042 if (Distance(
11043 V3( chgl->fVertexes[0].at(i+0), chgl->fVertexes[0].at(i+1), chgl->fVertexes[0].at(i+2)),
11044 V3( chgl->fVertexes[0].at(i+3), chgl->fVertexes[0].at(i+4), chgl->fVertexes[0].at(i+5)
11045 ))>0.0001)
11046 densityMaps.append(QString("cylinder{<%1,%2,%3>,<%4,%5,%6>,%7 texture{diffPosCol}}\n")
11047 .arg(chgl->fVertexes[0].at(i+0)-chgl->altemitte.x,10,'g',6)
11048 .arg(chgl->fVertexes[0].at(i+1)-chgl->altemitte.y,10,'g',6)
11049 .arg(chgl->fVertexes[0].at(i+2)-chgl->altemitte.z,10,'g',6)
11050 .arg(chgl->fVertexes[0].at(i+3)-chgl->altemitte.x,10,'g',6)
11051 .arg(chgl->fVertexes[0].at(i+4)-chgl->altemitte.y,10,'g',6)
11052 .arg(chgl->fVertexes[0].at(i+5)-chgl->altemitte.z,10,'g',6)
11053 .arg(chgl->linwidth*0.01));
11054 if (Distance(
11055 V3( chgl->fVertexes[0].at(i+3), chgl->fVertexes[0].at(i+4), chgl->fVertexes[0].at(i+5)),
11056 V3( chgl->fVertexes[0].at(i+6), chgl->fVertexes[0].at(i+7), chgl->fVertexes[0].at(i+8)
11057 ))>0.0001)
11058 densityMaps.append(QString("cylinder{<%1,%2,%3>,<%4,%5,%6>,%7 texture{diffPosCol}}\n")
11059 .arg(chgl->fVertexes[0].at(i+3)-chgl->altemitte.x,10,'g',6)
11060 .arg(chgl->fVertexes[0].at(i+4)-chgl->altemitte.y,10,'g',6)
11061 .arg(chgl->fVertexes[0].at(i+5)-chgl->altemitte.z,10,'g',6)
11062 .arg(chgl->fVertexes[0].at(i+6)-chgl->altemitte.x,10,'g',6)
11063 .arg(chgl->fVertexes[0].at(i+7)-chgl->altemitte.y,10,'g',6)
11064 .arg(chgl->fVertexes[0].at(i+8)-chgl->altemitte.z,10,'g',6)
11065 .arg(chgl->linwidth*0.01));
11066 if (Distance(
11067 V3( chgl->fVertexes[0].at(i+6), chgl->fVertexes[0].at(i+7), chgl->fVertexes[0].at(i+8)),
11068 V3( chgl->fVertexes[0].at(i+0), chgl->fVertexes[0].at(i+1), chgl->fVertexes[0].at(i+2)
11069 ))>0.0001)
11070 densityMaps.append(QString("cylinder{<%1,%2,%3>,<%4,%5,%6>,%7 texture{diffPosCol}}\n")
11071 .arg(chgl->fVertexes[0].at(i+6)-chgl->altemitte.x,10,'g',6)
11072 .arg(chgl->fVertexes[0].at(i+7)-chgl->altemitte.y,10,'g',6)
11073 .arg(chgl->fVertexes[0].at(i+8)-chgl->altemitte.z,10,'g',6)
11074 .arg(chgl->fVertexes[0].at(i+0)-chgl->altemitte.x,10,'g',6)
11075 .arg(chgl->fVertexes[0].at(i+1)-chgl->altemitte.y,10,'g',6)
11076 .arg(chgl->fVertexes[0].at(i+2)-chgl->altemitte.z,10,'g',6)
11077 .arg(chgl->linwidth*0.01));
11078 }
11079 densityMaps.append(QString("}"));
11080 densityMaps.append(QString("#else\n"));
11081 densityMaps.append(QString("mesh {\n"));
11082 for (int i=0; i<chgl->fVertexes[0].size();i+=9){
11083 densityMaps.append(QString("smooth_triangle{\n<%1,%2,%3>,<%10,%11,%12>,\n<%4,%5,%6>,<%13,%14,%15>,\n<%7,%8,%9>,<%16,%17,%19>\n}\n")
11084 .arg(chgl->fVertexes[0].at(i+0)-chgl->altemitte.x,10,'g',6)
11085 .arg(chgl->fVertexes[0].at(i+1)-chgl->altemitte.y,10,'g',6)
11086 .arg(chgl->fVertexes[0].at(i+2)-chgl->altemitte.z,10,'g',6)
11087 .arg(chgl->fVertexes[0].at(i+3)-chgl->altemitte.x,10,'g',6)
11088 .arg(chgl->fVertexes[0].at(i+4)-chgl->altemitte.y,10,'g',6)
11089 .arg(chgl->fVertexes[0].at(i+5)-chgl->altemitte.z,10,'g',6)
11090 .arg(chgl->fVertexes[0].at(i+6)-chgl->altemitte.x,10,'g',6)
11091 .arg(chgl->fVertexes[0].at(i+7)-chgl->altemitte.y,10,'g',6)
11092 .arg(chgl->fVertexes[0].at(i+8)-chgl->altemitte.z,10,'g',6)
11093 .arg(chgl->fNormals[0].at(i+0),10,'g',6)
11094 .arg(chgl->fNormals[0].at(i+1),10,'g',6)
11095 .arg(chgl->fNormals[0].at(i+2),10,'g',6)
11096 .arg(chgl->fNormals[0].at(i+3),10,'g',6)
11097 .arg(chgl->fNormals[0].at(i+4),10,'g',6)
11098 .arg(chgl->fNormals[0].at(i+5),10,'g',6)
11099 .arg(chgl->fNormals[0].at(i+6),10,'g',6)
11100 .arg(chgl->fNormals[0].at(i+7),10,'g',6)
11101 .arg(chgl->fNormals[0].at(i+8),10,'g',6)
11102 );
11103 }
11104 densityMaps.append(QString("texture {diffPosCol}\n}\n"));
11105 densityMaps.append(QString("#end\n"));
11106 }
11107 if (!chgl->fVertexes[1].isEmpty()){
11108
11109 densityMaps.append(QString("#if (DrawWireframeMaps)\n"));
11110
11111 densityMaps.append(QString("union{\n"));
11112 for (int i=0; i<chgl->fVertexes[1].size();i+=9){
11113 if (Distance(
11114 V3( chgl->fVertexes[1].at(i+0), chgl->fVertexes[1].at(i+1), chgl->fVertexes[1].at(i+2)),
11115 V3( chgl->fVertexes[1].at(i+3), chgl->fVertexes[1].at(i+4), chgl->fVertexes[1].at(i+5)
11116 ))>0.0001)
11117 densityMaps.append(QString("cylinder{<%1,%2,%3>,<%4,%5,%6>,%7 texture{diffMinCol}}\n")
11118 .arg(chgl->fVertexes[1].at(i+0)-chgl->altemitte.x,10,'g',6)
11119 .arg(chgl->fVertexes[1].at(i+1)-chgl->altemitte.y,10,'g',6)
11120 .arg(chgl->fVertexes[1].at(i+2)-chgl->altemitte.z,10,'g',6)
11121 .arg(chgl->fVertexes[1].at(i+3)-chgl->altemitte.x,10,'g',6)
11122 .arg(chgl->fVertexes[1].at(i+4)-chgl->altemitte.y,10,'g',6)
11123 .arg(chgl->fVertexes[1].at(i+5)-chgl->altemitte.z,10,'g',6)
11124 .arg(chgl->linwidth*0.01)
11125 );
11126 if (Distance(
11127 V3( chgl->fVertexes[1].at(i+3), chgl->fVertexes[1].at(i+4), chgl->fVertexes[1].at(i+5)),
11128 V3( chgl->fVertexes[1].at(i+6), chgl->fVertexes[1].at(i+7), chgl->fVertexes[1].at(i+8)
11129 ))>0.0001)
11130 densityMaps.append(QString("cylinder{<%1,%2,%3>,<%4,%5,%6>,%7 texture{diffMinCol}}\n")
11131 .arg(chgl->fVertexes[1].at(i+3)-chgl->altemitte.x,10,'g',6)
11132 .arg(chgl->fVertexes[1].at(i+4)-chgl->altemitte.y,10,'g',6)
11133 .arg(chgl->fVertexes[1].at(i+5)-chgl->altemitte.z,10,'g',6)
11134 .arg(chgl->fVertexes[1].at(i+6)-chgl->altemitte.x,10,'g',6)
11135 .arg(chgl->fVertexes[1].at(i+7)-chgl->altemitte.y,10,'g',6)
11136 .arg(chgl->fVertexes[1].at(i+8)-chgl->altemitte.z,10,'g',6)
11137 .arg(chgl->linwidth*0.01)
11138 );
11139 if (Distance(
11140 V3( chgl->fVertexes[1].at(i+6), chgl->fVertexes[1].at(i+7), chgl->fVertexes[1].at(i+8)),
11141 V3( chgl->fVertexes[1].at(i+0), chgl->fVertexes[1].at(i+1), chgl->fVertexes[1].at(i+2)
11142 ))>0.0001)
11143 densityMaps.append(QString("cylinder{<%1,%2,%3>,<%4,%5,%6>,%7 texture{diffMinCol}}\n")
11144 .arg(chgl->fVertexes[1].at(i+6)-chgl->altemitte.x,10,'g',6)
11145 .arg(chgl->fVertexes[1].at(i+7)-chgl->altemitte.y,10,'g',6)
11146 .arg(chgl->fVertexes[1].at(i+8)-chgl->altemitte.z,10,'g',6)
11147 .arg(chgl->fVertexes[1].at(i+0)-chgl->altemitte.x,10,'g',6)
11148 .arg(chgl->fVertexes[1].at(i+1)-chgl->altemitte.y,10,'g',6)
11149 .arg(chgl->fVertexes[1].at(i+2)-chgl->altemitte.z,10,'g',6)
11150 .arg(chgl->linwidth*0.01)
11151 );
11152 }
11153 densityMaps.append(QString("}"));
11154 densityMaps.append(QString("#else\n"));
11155 densityMaps.append(QString("mesh{\n"));
11156 for (int i=0; i<chgl->fVertexes[1].size();i+=9){
11157 densityMaps.append(QString("smooth_triangle{\n<%1,%2,%3>,<%10,%11,%12>,\n<%4,%5,%6>,<%13,%14,%15>,\n<%7,%8,%9>,<%16,%17,%19>\n}\n")
11158 .arg(chgl->fVertexes[1].at(i+0)-chgl->altemitte.x,10,'g',6)
11159 .arg(chgl->fVertexes[1].at(i+1)-chgl->altemitte.y,10,'g',6)
11160 .arg(chgl->fVertexes[1].at(i+2)-chgl->altemitte.z,10,'g',6)
11161 .arg(chgl->fVertexes[1].at(i+3)-chgl->altemitte.x,10,'g',6)
11162 .arg(chgl->fVertexes[1].at(i+4)-chgl->altemitte.y,10,'g',6)
11163 .arg(chgl->fVertexes[1].at(i+5)-chgl->altemitte.z,10,'g',6)
11164 .arg(chgl->fVertexes[1].at(i+6)-chgl->altemitte.x,10,'g',6)
11165 .arg(chgl->fVertexes[1].at(i+7)-chgl->altemitte.y,10,'g',6)
11166 .arg(chgl->fVertexes[1].at(i+8)-chgl->altemitte.z,10,'g',6)
11167 .arg(chgl->fNormals[1].at(i+0),10,'g',6)
11168 .arg(chgl->fNormals[1].at(i+1),10,'g',6)
11169 .arg(chgl->fNormals[1].at(i+2),10,'g',6)
11170 .arg(chgl->fNormals[1].at(i+3),10,'g',6)
11171 .arg(chgl->fNormals[1].at(i+4),10,'g',6)
11172 .arg(chgl->fNormals[1].at(i+5),10,'g',6)
11173 .arg(chgl->fNormals[1].at(i+6),10,'g',6)
11174 .arg(chgl->fNormals[1].at(i+7),10,'g',6)
11175 .arg(chgl->fNormals[1].at(i+8),10,'g',6)
11176 );
11177 }
11178 densityMaps.append(QString("texture {diffMinCol}\n}\n"));
11179 densityMaps.append(QString("#end\n"));
11180 }
11181 if (!chgl->fVertexes[2].isEmpty()){
11182 densityMaps.append(QString("#end\n\n#if (DrawFobserved)\n"));
11183 densityMaps.append(QString("#if (DrawWireframeMaps)\n"));
11184 densityMaps.append(QString("union{\n"));
11185 for (int i=0; i<chgl->fVertexes[2].size();i+=9){
11186 if (Distance(
11187 V3( chgl->fVertexes[2].at(i+0), chgl->fVertexes[2].at(i+1), chgl->fVertexes[2].at(i+2)),
11188 V3( chgl->fVertexes[2].at(i+3), chgl->fVertexes[2].at(i+4), chgl->fVertexes[2].at(i+5)
11189 ))>0.0001)
11190 densityMaps.append(QString("cylinder{<%1,%2,%3>,<%4,%5,%6>, %7 texture{FobsPosCol}}\n")
11191 .arg(chgl->fVertexes[2].at(i+0)-chgl->altemitte.x,10,'g',6)
11192 .arg(chgl->fVertexes[2].at(i+1)-chgl->altemitte.y,10,'g',6)
11193 .arg(chgl->fVertexes[2].at(i+2)-chgl->altemitte.z,10,'g',6)
11194 .arg(chgl->fVertexes[2].at(i+3)-chgl->altemitte.x,10,'g',6)
11195 .arg(chgl->fVertexes[2].at(i+4)-chgl->altemitte.y,10,'g',6)
11196 .arg(chgl->fVertexes[2].at(i+5)-chgl->altemitte.z,10,'g',6)
11197 .arg(chgl->linwidth*0.01)
11198 );
11199 if (Distance(
11200 V3( chgl->fVertexes[2].at(i+3), chgl->fVertexes[2].at(i+4), chgl->fVertexes[2].at(i+5)),
11201 V3( chgl->fVertexes[2].at(i+6), chgl->fVertexes[2].at(i+7), chgl->fVertexes[2].at(i+8)
11202 ))>0.0001)
11203 densityMaps.append(QString("cylinder{<%1,%2,%3>,<%4,%5,%6>, %7 texture{FobsPosCol}}\n")
11204 .arg(chgl->fVertexes[2].at(i+3)-chgl->altemitte.x,10,'g',6)
11205 .arg(chgl->fVertexes[2].at(i+4)-chgl->altemitte.y,10,'g',6)
11206 .arg(chgl->fVertexes[2].at(i+5)-chgl->altemitte.z,10,'g',6)
11207 .arg(chgl->fVertexes[2].at(i+6)-chgl->altemitte.x,10,'g',6)
11208 .arg(chgl->fVertexes[2].at(i+7)-chgl->altemitte.y,10,'g',6)
11209 .arg(chgl->fVertexes[2].at(i+8)-chgl->altemitte.z,10,'g',6)
11210 .arg(chgl->linwidth*0.01)
11211 );
11212 if (Distance(
11213 V3( chgl->fVertexes[2].at(i+6), chgl->fVertexes[2].at(i+7), chgl->fVertexes[2].at(i+8)),
11214 V3( chgl->fVertexes[2].at(i+0), chgl->fVertexes[2].at(i+1), chgl->fVertexes[2].at(i+2)
11215 ))>0.0001)
11216 densityMaps.append(QString("cylinder{<%1,%2,%3>,<%4,%5,%6>, %7 texture{FobsPosCol}}\n")
11217 .arg(chgl->fVertexes[2].at(i+6)-chgl->altemitte.x,10,'g',6)
11218 .arg(chgl->fVertexes[2].at(i+7)-chgl->altemitte.y,10,'g',6)
11219 .arg(chgl->fVertexes[2].at(i+8)-chgl->altemitte.z,10,'g',6)
11220 .arg(chgl->fVertexes[2].at(i+0)-chgl->altemitte.x,10,'g',6)
11221 .arg(chgl->fVertexes[2].at(i+1)-chgl->altemitte.y,10,'g',6)
11222 .arg(chgl->fVertexes[2].at(i+2)-chgl->altemitte.z,10,'g',6)
11223 .arg(chgl->linwidth*0.01)
11224 );
11225 }
11226 densityMaps.append(QString("}"));
11227 densityMaps.append(QString("#else\n"));
11228 densityMaps.append(QString("mesh{\n"));
11229 for (int i=0; i<chgl->fVertexes[2].size();i+=9){
11230 densityMaps.append(QString("smooth_triangle{\n<%1,%2,%3>,<%10,%11,%12>,\n<%4,%5,%6>,<%13,%14,%15>,\n<%7,%8,%9>,<%16,%17,%19>\n}\n")
11231 .arg(chgl->fVertexes[2].at(i+0)-chgl->altemitte.x,10,'g',6)
11232 .arg(chgl->fVertexes[2].at(i+1)-chgl->altemitte.y,10,'g',6)
11233 .arg(chgl->fVertexes[2].at(i+2)-chgl->altemitte.z,10,'g',6)
11234 .arg(chgl->fVertexes[2].at(i+3)-chgl->altemitte.x,10,'g',6)
11235 .arg(chgl->fVertexes[2].at(i+4)-chgl->altemitte.y,10,'g',6)
11236 .arg(chgl->fVertexes[2].at(i+5)-chgl->altemitte.z,10,'g',6)
11237 .arg(chgl->fVertexes[2].at(i+6)-chgl->altemitte.x,10,'g',6)
11238 .arg(chgl->fVertexes[2].at(i+7)-chgl->altemitte.y,10,'g',6)
11239 .arg(chgl->fVertexes[2].at(i+8)-chgl->altemitte.z,10,'g',6)
11240 .arg(chgl->fNormals[2].at(i+0),10,'g',6)
11241 .arg(chgl->fNormals[2].at(i+1),10,'g',6)
11242 .arg(chgl->fNormals[2].at(i+2),10,'g',6)
11243 .arg(chgl->fNormals[2].at(i+3),10,'g',6)
11244 .arg(chgl->fNormals[2].at(i+4),10,'g',6)
11245 .arg(chgl->fNormals[2].at(i+5),10,'g',6)
11246 .arg(chgl->fNormals[2].at(i+6),10,'g',6)
11247 .arg(chgl->fNormals[2].at(i+7),10,'g',6)
11248 .arg(chgl->fNormals[2].at(i+8),10,'g',6)
11249 );
11250 }
11251 densityMaps.append(QString("texture {FobsPosCol}\n}\n"));
11252 densityMaps.append(QString("#end\n"));
11253 }
11254 if (!chgl->fVertexes[3].isEmpty()){
11255 densityMaps.append(QString("#if (DrawWireframeMaps)\n"));
11256
11257 densityMaps.append(QString("union{\n"));
11258 for (int i=0; i<chgl->fVertexes[3].size();i+=9){
11259 if (Distance(
11260 V3( chgl->fVertexes[3].at(i+0), chgl->fVertexes[3].at(i+1), chgl->fVertexes[3].at(i+2)),
11261 V3( chgl->fVertexes[3].at(i+3), chgl->fVertexes[3].at(i+4), chgl->fVertexes[3].at(i+5)
11262 ))>0.0001)
11263 densityMaps.append(QString("cylinder{<%1,%2,%3>,<%4,%5,%6>, %7 texture{FobsMinCol}}\n")
11264 .arg(chgl->fVertexes[3].at(i+0)-chgl->altemitte.x,10,'g',6)
11265 .arg(chgl->fVertexes[3].at(i+1)-chgl->altemitte.y,10,'g',6)
11266 .arg(chgl->fVertexes[3].at(i+2)-chgl->altemitte.z,10,'g',6)
11267 .arg(chgl->fVertexes[3].at(i+3)-chgl->altemitte.x,10,'g',6)
11268 .arg(chgl->fVertexes[3].at(i+4)-chgl->altemitte.y,10,'g',6)
11269 .arg(chgl->fVertexes[3].at(i+5)-chgl->altemitte.z,10,'g',6)
11270 .arg(chgl->linwidth*0.01)
11271 );
11272 if (Distance(
11273 V3( chgl->fVertexes[3].at(i+3), chgl->fVertexes[3].at(i+4), chgl->fVertexes[3].at(i+5)),
11274 V3( chgl->fVertexes[3].at(i+6), chgl->fVertexes[3].at(i+7), chgl->fVertexes[3].at(i+8)
11275 ))>0.0001)
11276 densityMaps.append(QString("cylinder{<%1,%2,%3>,<%4,%5,%6>,%7 texture{FobsMinCol}}\n")
11277 .arg(chgl->fVertexes[3].at(i+3)-chgl->altemitte.x,10,'g',6)
11278 .arg(chgl->fVertexes[3].at(i+4)-chgl->altemitte.y,10,'g',6)
11279 .arg(chgl->fVertexes[3].at(i+5)-chgl->altemitte.z,10,'g',6)
11280 .arg(chgl->fVertexes[3].at(i+6)-chgl->altemitte.x,10,'g',6)
11281 .arg(chgl->fVertexes[3].at(i+7)-chgl->altemitte.y,10,'g',6)
11282 .arg(chgl->fVertexes[3].at(i+8)-chgl->altemitte.z,10,'g',6)
11283 .arg(chgl->linwidth*0.01)
11284 );
11285 if (Distance(
11286 V3( chgl->fVertexes[3].at(i+6), chgl->fVertexes[3].at(i+7), chgl->fVertexes[3].at(i+8)),
11287 V3( chgl->fVertexes[3].at(i+0), chgl->fVertexes[3].at(i+1), chgl->fVertexes[3].at(i+2)
11288 ))>0.0001)
11289 densityMaps.append(QString("cylinder{<%1,%2,%3>,<%4,%5,%6>,%7 texture{FobsMinCol}}\n")
11290 .arg(chgl->fVertexes[3].at(i+6)-chgl->altemitte.x,10,'g',6)
11291 .arg(chgl->fVertexes[3].at(i+7)-chgl->altemitte.y,10,'g',6)
11292 .arg(chgl->fVertexes[3].at(i+8)-chgl->altemitte.z,10,'g',6)
11293 .arg(chgl->fVertexes[3].at(i+0)-chgl->altemitte.x,10,'g',6)
11294 .arg(chgl->fVertexes[3].at(i+1)-chgl->altemitte.y,10,'g',6)
11295 .arg(chgl->fVertexes[3].at(i+2)-chgl->altemitte.z,10,'g',6)
11296 .arg(chgl->linwidth*0.01)
11297 );
11298 }
11299 densityMaps.append(QString("}"));
11300 densityMaps.append(QString("#else\n"));
11301 densityMaps.append(QString("mesh{\n"));
11302 for (int i=0; i<chgl->fVertexes[3].size();i+=9){
11303 densityMaps.append(QString("smooth_triangle{\n<%1,%2,%3>,<%10,%11,%12>,\n<%4,%5,%6>,<%13,%14,%15>,\n<%7,%8,%9>,<%16,%17,%19>\n}\n")
11304 .arg(chgl->fVertexes[3].at(i+0)-chgl->altemitte.x,10,'g',6)
11305 .arg(chgl->fVertexes[3].at(i+1)-chgl->altemitte.y,10,'g',6)
11306 .arg(chgl->fVertexes[3].at(i+2)-chgl->altemitte.z,10,'g',6)
11307 .arg(chgl->fVertexes[3].at(i+3)-chgl->altemitte.x,10,'g',6)
11308 .arg(chgl->fVertexes[3].at(i+4)-chgl->altemitte.y,10,'g',6)
11309 .arg(chgl->fVertexes[3].at(i+5)-chgl->altemitte.z,10,'g',6)
11310 .arg(chgl->fVertexes[3].at(i+6)-chgl->altemitte.x,10,'g',6)
11311 .arg(chgl->fVertexes[3].at(i+7)-chgl->altemitte.y,10,'g',6)
11312 .arg(chgl->fVertexes[3].at(i+8)-chgl->altemitte.z,10,'g',6)
11313 .arg(chgl->fNormals[3].at(i+0),10,'g',6)
11314 .arg(chgl->fNormals[3].at(i+1),10,'g',6)
11315 .arg(chgl->fNormals[3].at(i+2),10,'g',6)
11316 .arg(chgl->fNormals[3].at(i+3),10,'g',6)
11317 .arg(chgl->fNormals[3].at(i+4),10,'g',6)
11318 .arg(chgl->fNormals[3].at(i+5),10,'g',6)
11319 .arg(chgl->fNormals[3].at(i+6),10,'g',6)
11320 .arg(chgl->fNormals[3].at(i+7),10,'g',6)
11321 .arg(chgl->fNormals[3].at(i+8),10,'g',6)
11322 );
11323 }
11324 densityMaps.append(QString("texture {FobsMinCol}\n}\n"));
11325 densityMaps.append(QString("#end\n"));
11326 }
11327 densityMaps.append(QString("#end\n#end // maps\n\n"));
11328 if (!chgl->mol->vtriangles.isEmpty()){
11329 voron.append(QString("//voronoij polyherodron \n"));
11330
11331 for (int k=0; k<editor->sfac.size();k++){
11332 voron.append(QString("#declare _%1_%2_ = texture{pigment{color rgbt< %3, %4, %5, %6>}}\n")
11333 .arg(mole.pse(editor->sfac.at(k)))
11334 .arg("a")
11335
11336 .arg(mole.AtomColor[editor->sfac.at(k)].redF())
11337 .arg(mole.AtomColor[editor->sfac.at(k)].greenF())
11338 .arg(mole.AtomColor[editor->sfac.at(k)].blueF())
11339 .arg("0.97")
11340 );
11341 voron.append(QString("#declare _%1_%2_ = texture{pigment{color rgbt< %3, %4, %5, %6>}}\n")
11342 .arg(mole.pse(editor->sfac.at(k)))
11343 .arg("b")
11344 .arg(mole.AtomColor[editor->sfac.at(k)].redF())
11345 .arg(mole.AtomColor[editor->sfac.at(k)].greenF())
11346 .arg(mole.AtomColor[editor->sfac.at(k)].blueF())
11347 .arg("0.4")
11348 );
11349 }
11350 voron.append(QString("union{\n"));
11351 for (int ti=0; ti<mole.vtriangles.size(); ti++){
11352 voron.append(QString("cylinder {< %1, %2, %3 >,< %4, %5, %6>,0.01 texture{pigment{color rgbt< %7, %8, %9, 0.5>}}}\n")
11353 .arg(mole.vtriangles.at(ti).verts0.x-chgl->altemitte.x)
11354 .arg(mole.vtriangles.at(ti).verts0.y-chgl->altemitte.y)
11355 .arg(mole.vtriangles.at(ti).verts0.z-chgl->altemitte.z)
11356 .arg(mole.vtriangles.at(ti).verts1.x-chgl->altemitte.x)
11357 .arg(mole.vtriangles.at(ti).verts1.y-chgl->altemitte.y)
11358 .arg(mole.vtriangles.at(ti).verts1.z-chgl->altemitte.z)
11359 .arg(mole.AtomColor[mole.vtriangles.at(ti).acol].redF())
11360 .arg(mole.AtomColor[mole.vtriangles.at(ti).acol].greenF())
11361 .arg(mole.AtomColor[mole.vtriangles.at(ti).acol].blueF())
11362 );
11363 }
11364 voron.append(QString("}\nmesh{\n"));
11365 for (int ti=0; ti<mole.vtriangles.size(); ti++){
11366 voron.append(QString("triangle{< %1, %2, %3>,< %4, %5, %6>,< %7, %8, %9>\n")
11367 .arg(mole.vtriangles.at(ti).mid.x-chgl->altemitte.x)
11368 .arg(mole.vtriangles.at(ti).mid.y-chgl->altemitte.y)
11369 .arg(mole.vtriangles.at(ti).mid.z-chgl->altemitte.z)
11370 .arg(mole.vtriangles.at(ti).verts0.x-chgl->altemitte.x)
11371 .arg(mole.vtriangles.at(ti).verts0.y-chgl->altemitte.y)
11372 .arg(mole.vtriangles.at(ti).verts0.z-chgl->altemitte.z)
11373 .arg(mole.vtriangles.at(ti).verts1.x-chgl->altemitte.x)
11374 .arg(mole.vtriangles.at(ti).verts1.y-chgl->altemitte.y)
11375 .arg(mole.vtriangles.at(ti).verts1.z-chgl->altemitte.z)
11376 );
11377 voron.append(QString("texture { _%1_%2_ }}\n").arg(mole.pse(mole.vtriangles.at(ti).acol)).arg((mole.vtriangles.at(ti).intra)?"a":"b"));
11378 }
11379 voron.append(QString("} //voronoij\n"));
11380 }
11381 body.clear();
11382 for (int i=0,j=0; i<mole.legendAtoms.size();i++){
11383 if (mole.legendAtoms.at(i).hidden) continue;
11384 if (mole.legendAtoms.at(i).an<0){
11385 body.append(QString("#if (BW)\nqpeak(<-ww/1.025,-hh/1.25+%1*hh/18,0>,QPeakRad*4*ViewAngle/29.0,0.6,0.6,0.6,%1)\n"
11386 "#else\nqpeak(<-ww/1.025,-hh/1.08+%2*hh/18,0>,QPeakRad*4*ViewAngle/29.0,0.9,0.5,0.0,%1)\n#end\n")
11387 .arg(mole.legendAtoms.at(i).an)
11388 .arg(j)
11389 );//
11390 }else{
11391 if (chgl->mol->AtomStyle[mole.legendAtoms.at(i).an]&ATOM_STYLE_NOADP) {
11392 body.append(QString(" object{\n"));
11393 body.append(QString(" sphere{ Origin, 1 texture { finish { Shiny } pigment {color Color_%1 } } }\n").arg(mole.pse(mole.legendAtoms.at(i).an)));
11394 body.append(QString(" scale< H_Radius*Prob, H_Radius*Prob, H_Radius*Prob>*4*ViewAngle/29.0 \n"));
11395 }else{
11396 V3 ev=V3(0,0,0); // Eigen Vectors
11397 double *arr=mole.jacobi(mole.legendAtoms.at(i).uc,ev);
11398 if ((ev.x>0)&&(ev.y>0)&&(ev.z>0)){
11399 body.append(QString("#declare U11 = %1 ;\n").arg(sqrt(ev.x),10,'f',6));
11400 body.append(QString("#declare U22 = %1 ;\n").arg(sqrt(ev.y),10,'f',6));
11401 body.append(QString("#declare U33 = %1 ;\n").arg(sqrt(ev.z),10,'f',6));
11402 body.append(QString("object{\n union{\n"));
11403 body.append(QString(" sphere{Origin, 1 texture { finish { Shiny } pigment {color Color_%1 transmit %2} } }\n")
11404 .arg(mole.pse(mole.legendAtoms.at(i).an)).arg((chgl->mol->AtomStyle[mole.legendAtoms.at(i).an]&ATOM_STYLE_SOLID)?"0.0":"0.8"));
11405
11406 body.append(QString(" sphere{Origin, 1 scale<1,1,0.2> texture { finish { Shiny } pigment {color Color_%1 } } }\n").arg(mole.pse(mole.legendAtoms.at(i).an)));
11407 body.append(QString(" sphere{Origin, 1 scale<0.2,1,1> texture { finish { Shiny } pigment {color Color_%1 } } }\n").arg(mole.pse(mole.legendAtoms.at(i).an)));
11408 body.append(QString(" sphere{Origin, 1 scale<1,0.2,1> texture { finish { Shiny } pigment {color Color_%1 } } }\n").arg(mole.pse(mole.legendAtoms.at(i).an)));
11409 body.append(QString(" torus{ 1 .06 texture { finish { Shiny } pigment {color Equator_%1 } } }\n").arg(mole.pse(mole.legendAtoms.at(i).an)));
11410 body.append(QString(" torus{ 1 .06 rotate< 90,0,0> texture { finish { Shiny } pigment {color Equator_%1 } } }\n").arg(mole.pse(mole.legendAtoms.at(i).an)));
11411 body.append(QString(" torus{ 1 .06 rotate< 0,0,90> texture { finish { Shiny } pigment {color Equator_%1 } } }\n").arg(mole.pse(mole.legendAtoms.at(i).an)));
11412 body.append(QString(" scale< U11*Prob, U22*Prob, U33*Prob>*4*ViewAngle/29.0\n }\n"));
11413 body.append(QString(" Axis_Rotate_Trans( < %1 , %2 , %3 >, %4 ) \n")
11414 .arg(arr[1],10,'f',6)
11415 .arg(arr[2],10,'f',6)
11416 .arg(arr[3],10,'f',6)
11417 .arg(arr[0],10,'f',6));
11418 }
11419 }
11420 body.append(QString(" translate <-ww/1.025,-hh/1.08+%1*hh/18,0>\nno_shadow\n}\n\n").arg(j));
11421 }
11422 body.append(QString("llabel(\"%1\",<-ww/1.06,-hh/1.06+%2*hh/18,0>,Black,0.35*4*ViewAngle/29.0)\n").arg(mole.pse(mole.legendAtoms.at(i).an)).arg(j));
11423 j++;
11424 }
11425 headerPOV.append(body);
11426
11427 headerPOV.append(QString("#end //DrawLegend\n"));
11428 headerPOV.append(QString("// ====================================\n"));
11429 headerPOV.append(QString("// __Declarations of atoms coordinates \n"));
11430 for (int i=0; i< mole.showatoms.size(); i++){
11431 if (mole.showatoms.at(i).hidden) continue;
11432 if ((mole.nopm1)&&(mole.showatoms.at(i).symmGroup)&&(mole.showatoms.at(i).part<-0)) continue; // ignore hidden parts (-1)
11433 else {
11434 s1=QString("AtomPos%1").arg(i);
11435 headerPOV.append(QString("#declare %1 = < %2 , %3 , %4 >;//%5\n")
11436 .arg(s1)
11437 .arg(mole.showatoms.at(i).pos.x-chgl->altemitte.x,10,'f',6) //use the actual rotation center
11438 .arg(mole.showatoms.at(i).pos.y-chgl->altemitte.y,10,'f',6)
11439 .arg(mole.showatoms.at(i).pos.z-chgl->altemitte.z,10,'f',6)
11440 .arg(mole.showatoms.at(i).Label));
11441 }}
11442 headerPOV.append(QString("// ____________________________________ end of atom coordinates\n\n\n\n"));
11443
11444 headerPOV.append(QString("// ====================================\n"));
11445 headerPOV.append(QString("// __START union of objects\n"));
11446 headerPOV.append(QString("union {\n\n"));
11447
11448 headerPOV.append(QString("// ====================================\n"));
11449 headerPOV.append(QString("// Spheres for nicely overlapping bonds\n"));
11450 headerPOV.append(QString(" #if(DrawRoundCorners)\n"));
11451 body.clear(); // we will use body as temporary buffer for hydrogen atoms spheres
11452 body.append(QString("\n #if(DrawHydrogens)\n"));
11453
11454 for (int i=0; i< mole.showatoms.size(); i++){ // read Uij into matrix form
11455 if (mole.showatoms.at(i).an<0) continue;//only real atoms here
11456 if (mole.showatoms.at(i).hidden) continue;
11457 if ((mole.nopm1)&&(mole.showatoms.at(i).symmGroup)&&(mole.showatoms.at(i).part<-0)) continue; // ignore hidden parts (-1)
11458 s1=QString("AtomPos%1").arg(i);
11459 if (mole.showatoms.at(i).an==0)
11460 body.append(QString("sphere { %1 , HBond_Radius texture {Bond_Texture}}//%2\n").arg(s1)
11461 .arg(mole.showatoms.at(i).Label));
11462 else
11463 headerPOV.append(QString(" sphere { %1 , Bond_Radius texture {Bond_Texture}}//%2\n").arg(s1)
11464 .arg(mole.showatoms.at(i).Label));
11465 }
11466 headerPOV.append(body);
11467 headerPOV.append(QString(" #end // End of atomic spheres for hydrogens\n"));
11468 headerPOV.append(QString(" #end // End of atomic spheres\n"));
11469 headerPOV.append(QString("// ____________________________________ end of corners\n\n\n\n"));
11470
11471 headerPOV.append(QString("// ====================================\n"));
11472 headerPOV.append(QString("// __Declarations of atoms and their Uij\n\n"));
11473
11474 hiddenAtoms.append(QString("\n\n// ====================================\n"));
11475 hiddenAtoms.append(QString("// Put in this IF-END loop atoms that shouldn't be drawn.\n"));
11476 hiddenAtoms.append(QString("#if(!NoADP4Selected)\n"));
11477
11478 hydrogenAtoms.append(QString("\n\n// ====================================\n"));
11479 hydrogenAtoms.append(QString("// __Declarations of hydrogen atoms and their Uiso\n\n"));
11480 hydrogenAtoms.append(QString("#if(DrawHydrogens)\n"));
11481 hiddenHAtoms.append(QString("// __Declarations of hydrogen atoms and their Uiso\n"));
11482 hiddenHAtoms.append(QString("\n# if(DrawHydrogens)\n"));
11483
11484 for (int i=0; i< mole.showatoms.size(); i++){ // read Uij into matrix form
11485 if (mole.showatoms.at(i).an<0) continue;//only real atoms here
11486 if (mole.showatoms.at(i).hidden) continue;
11487 if ((mole.nopm1)&&(mole.showatoms.at(i).symmGroup)&&(mole.showatoms.at(i).part<-0)) continue; // ignore hidden parts (-1)
11488 if (mole.showatoms.at(i).isIso) {//Wow this is stupid all iso atoms are Hydrogens? If Hydrogens are anisotropic (neutrons, SHADE etc.) they are not Hydrogens????)
11489 s1=QString("AtomPos%1").arg(i);
11490 body.clear(); // we will use body as temporary buffer for hydrogen atoms
11491 body.append(QString(" #if (Hiso) #declare H_Radius = %1 ; #end\n").arg(sqrt(mole.showatoms.at(i).uf.m11),10,'f',6));
11492 body.append(QString(" object{\n"));
11493 if ((chgl->highlightParts->isChecked())&&(mole.showatoms.at(i).part!=0)){
11494 if ((mole.showatoms.at(i).part<0)&&(mole.showatoms.at(i).symmGroup))
11495 body.append(QString(" sphere{ Origin, 1 texture { finish { Shiny } pigment {color Color_%1 blue 1.0 transmit 0.7} } }\n").arg(mole.pse(mole.showatoms.at(i).an)));
11496 else
11497 body.append(QString(" sphere{ Origin, 1 texture { finish { Shiny } pigment {color ptcol%1 } } }\n")
11498 .arg((mole.showatoms.at(i).part>0)?QString("%1").arg(mole.showatoms.at(i).part):
11499 (mole.showatoms.at(i).part<-3)?"mX":QString("m%1").arg(-mole.showatoms.at(i).part))
11500 );
11501 } else{
11502 if ((mole.showatoms.at(i).part<0)&&(mole.showatoms.at(i).symmGroup))
11503 body.append(QString(" sphere{ Origin, 1 texture { finish { Shiny } pigment {color Color_%1 blue 1.0 transmit 0.7} } }\n").arg(mole.pse(mole.showatoms.at(i).an)));
11504 else
11505 body.append(QString(" sphere{ Origin, 1 texture { finish { Shiny } pigment {color Color_%1 } } }\n").arg(mole.pse(mole.showatoms.at(i).an)));
11506 }
11507 body.append(QString(" scale< H_Radius*Prob, H_Radius*Prob, H_Radius*Prob> \n"));
11508 body.append(QString(" translate %1//%2\n }\n\n").arg(s1)
11509 .arg(mole.showatoms.at(i).Label));
11510 foundInSelected=false;
11511 for (int j = 0; j <chgl->mol->selectedatoms.size();j++)if (chgl->mol->selectedatoms.at(j).style==i) {foundInSelected=true;break;}
11512 if (foundInSelected){hiddenHAtoms.append(body);}
11513 else {hydrogenAtoms.append(body);}
11514 } // end of Hs
11515 else {
11516 body.clear(); // we will use body as temporary buffer
11517 V3 ev=V3(0,0,0); // Eigen Vectors
11518 double *arr=mole.jacobi(mole.showatoms.at(i).uc,ev);
11519 if ((ev.x>0)&&(ev.y>0)&&(ev.z>0)){
11520
11521 body.append(QString("#declare U11 = %1 ;\n").arg(sqrt(ev.x),10,'f',6));
11522 body.append(QString("#declare U22 = %1 ;\n").arg(sqrt(ev.y),10,'f',6));
11523 body.append(QString("#declare U33 = %1 ;\n").arg(sqrt(ev.z),10,'f',6));
11524 body.append(QString("object{\n union{\n"));
11525 if ((chgl->highlightParts->isChecked())&&(mole.showatoms.at(i).part!=0)){
11526 if ((mole.showatoms.at(i).part<0)&&(mole.showatoms.at(i).symmGroup)){
11527 body.append(QString(" sphere{ Origin, 1.1 texture { finish { Shiny } pigment {color Color_%1 blue 1.0 transmit 0.7} } }\n")
11528 .arg(mole.pse(mole.showatoms.at(i).an)));
11529 }else{
11530 body.append(QString(" sphere{ Origin, 1.1 texture { finish { Shiny } pigment {color ptcol%1} } }\n")
11531 .arg((mole.showatoms.at(i).part>0)?QString("%1").arg(mole.showatoms.at(i).part):
11532 (mole.showatoms.at(i).part<-3)?"mX":QString("m%1").arg(-mole.showatoms.at(i).part))
11533 );
11534 }
11535 }
11536 if ((mole.showatoms.at(i).part<0)&&(mole.showatoms.at(i).symmGroup)){
11537 body.append(QString(" sphere{ Origin, 1 texture { finish { Shiny } pigment {color Color_%1 blue 1.0 transmit 0.7} } }\n")
11538 .arg(mole.pse(mole.showatoms.at(i).an))
11539 );
11540 body.append(QString(" sphere{Origin, 1 scale<1,1,0.2> texture { finish { Shiny } pigment {color Color_%1 blue 1.0 transmit 0.7} } }\n").arg(mole.pse(mole.showatoms.at(i).an)));
11541 body.append(QString(" sphere{Origin, 1 scale<0.2,1,1> texture { finish { Shiny } pigment {color Color_%1 blue 1.0 transmit 0.7} } }\n").arg(mole.pse(mole.showatoms.at(i).an)));
11542 body.append(QString(" sphere{Origin, 1 scale<1,0.2,1> texture { finish { Shiny } pigment {color Color_%1 blue 1.0 transmit 0.7} } }\n").arg(mole.pse(mole.showatoms.at(i).an)));
11543 body.append(QString(" torus{ 1 .06 texture { finish { Shiny } pigment {color Equator_%1 blue 1.0 transmit 0.7} } }\n").arg(mole.pse(mole.showatoms.at(i).an)));
11544 body.append(QString(" torus{ 1 .06 rotate< 90,0,0> texture { finish { Shiny } pigment {color Equator_%1 blue 1.0 transmit 0.7} } }\n").arg(mole.pse(mole.showatoms.at(i).an)));
11545 body.append(QString(" torus{ 1 .06 rotate< 0,0,90> texture { finish { Shiny } pigment {color Equator_%1 blue 1.0 transmit 0.7} } }\n").arg(mole.pse(mole.showatoms.at(i).an)));
11546
11547 }else{
11548 body.append(QString(" sphere{ Origin, 1 texture { finish { Shiny } pigment {color Color_%1 transmit %2} } }\n")
11549 .arg(mole.pse(mole.showatoms.at(i).an)).arg((chgl->mol->AtomStyle[mole.showatoms.at(i).an]&ATOM_STYLE_SOLID)?"0.0":"0.3"));
11550 body.append(QString(" sphere{Origin, 1 scale<1,1,0.2> texture { finish { Shiny } pigment {color Color_%1 } } }\n").arg(mole.pse(mole.showatoms.at(i).an)));
11551 body.append(QString(" sphere{Origin, 1 scale<0.2,1,1> texture { finish { Shiny } pigment {color Color_%1 } } }\n").arg(mole.pse(mole.showatoms.at(i).an)));
11552 body.append(QString(" sphere{Origin, 1 scale<1,0.2,1> texture { finish { Shiny } pigment {color Color_%1 } } }\n").arg(mole.pse(mole.showatoms.at(i).an)));
11553 body.append(QString(" torus{ 1 .06 texture { finish { Shiny } pigment {color Equator_%1 } } }\n").arg(mole.pse(mole.showatoms.at(i).an)));
11554 body.append(QString(" torus{ 1 .06 rotate< 90,0,0> texture { finish { Shiny } pigment {color Equator_%1 } } }\n").arg(mole.pse(mole.showatoms.at(i).an)));
11555 body.append(QString(" torus{ 1 .06 rotate< 0,0,90> texture { finish { Shiny } pigment {color Equator_%1 } } }\n").arg(mole.pse(mole.showatoms.at(i).an)));
11556 }
11557 body.append(QString(" scale< U11*Prob, U22*Prob, U33*Prob>\n }\n"));
11558 body.append(QString(" Axis_Rotate_Trans( < %1 , %2 , %3 >, %4 ) \n")
11559 .arg(arr[1],10,'f',6)
11560 .arg(arr[2],10,'f',6)
11561 .arg(arr[3],10,'f',6)
11562 .arg(arr[0],10,'f',6));
11563 }
11564 else {
11565 body.append(QString("object{\n union{\n"));
11566 body.append(QString("DrawCube(CubeSize,Color_%1,Equator_%1)}\n").arg(mole.pse(mole.showatoms.at(i).an)));
11567 }
11568 s1=QString("AtomPos%1").arg(i);
11569 body.append(QString(" translate %1//%2\n}\n\n").arg(s1)
11570 .arg(mole.showatoms.at(i).Label));
11571
11572 foundInSelected=false;
11573 for (int j = 0; j <chgl->mol->selectedatoms.size();j++)if (chgl->mol->selectedatoms.at(j).style==i) {foundInSelected=true;break;}
11574 if (foundInSelected){hiddenAtoms.append(body);}
11575 else {visableAtoms.append(body);}
11576 } // end of non-H
11577 } // end of lopp over all atoms for Uij computation
11578
11579 hydrogenAtoms.append(QString(" #end // closing hydrogen atoms loop\n"));
11580 hiddenHAtoms.append(QString(" #end // closing hidden hydrogen atoms loop\n"));
11581 hiddenAtoms.append(hiddenHAtoms);
11582 hiddenAtoms.append(QString("#end // ____________________________________ end of hidden atoms\n\n"));
11583
11584 hidePOV.append(QString("// ====================================\n"));
11585 hidePOV.append(QString("// Place in this IF-END loop atoms that shouldn't be drawn.\n"));
11586 hidePOV.append(QString("#if(NoADP4Selected)\n\n"));
11587 hidePOV.append(hiddenAtoms);
11588 hidePOV.append(QString("#end\n"));
11589 hidePOV.append(QString("// ____________________________________ end of hidden atoms\n\n\n\n"));
11590
11591 qpeaks.append(QString("// ====================================\n"));
11592 qpeaks.append(QString("// Q-Peaks show up here\n"));
11593 qpeaks.append(QString("#if (DrawQPeaks)\n"));
11594 for (int i=0; i< mole.showatoms.size(); i++){ // read Uij into matrix form
11595 if (mole.showatoms.at(i).an>=0) continue;//only non real atoms here
11596 if (mole.showatoms.at(i).hidden) continue;
11597 s1=QString("AtomPos%1").arg(i);
11598 QColor qcol=chgl->farbverlaufQC(chgl->mol->showatoms.at(i).peakHeight,chgl->mol->pmin,chgl->mol->pmax);
11599 if (mole.showatoms.at(i).an==-42){
11600 if (mole.beloColorByDefden) qcol=chgl->farbverlaufQC(chgl->mol->showatoms.at(i).sof,mole.lmin,mole.lmax);
11601 else qcol=mole.beloColor;
11602 }
11603 double grey=(chgl->mol->showatoms.at(i).peakHeight-chgl->mol->pmin)/(chgl->mol->pmax-chgl->mol->pmin);
11604 qpeaks.append(QString("#if (BW)//%7\nqpeak(%1,QPeakRad,%5,%5,%5,%6)\n#else\nqpeak(%1,QPeakRad,%2,%3,%4,%6)\n#end\n")
11605 .arg(s1)
11606 .arg(qcol.redF())
11607 .arg(qcol.greenF())
11608 .arg(qcol.blueF())
11609 .arg(grey,5,'f',4)
11610 .arg(mole.showatoms.at(i).an)
11611 .arg(mole.showatoms.at(i).Label)
11612 );//
11613 }
11614 qpeaks.append(QString("#if (DrawQPeaksBonds)\n"));
11615 for (int i=0; i<chgl->mol->lbonds.size();i++){
11616 if (mole.lbonds.at(i).ato1->hidden) continue;
11617 if (mole.lbonds.at(i).ato2->hidden) continue;
11618 s1=QString("AtomPos%1").arg(mole.lbonds.at(i).a1);
11619 s2=QString("AtomPos%1").arg(mole.lbonds.at(i).a2);
11620 qpeaks.append(QString("qbond(%1,%2)//%3==%4\n").arg(s1).arg(s2).arg(mole.lbonds.at(i).ato1->Label).arg(mole.lbonds.at(i).ato2->Label));
11621 }
11622 qpeaks.append(QString("#end\n"));
11623 qpeaks.append(QString("#end\n\n"));
11624 // BONDS
11625 bondsPOV.append(QString("\n\n"));
11626 bondsPOV.append(QString("// ====================================\n"));
11627 bondsPOV.append(QString("// __Bonds\n"));
11628
11629 body.clear(); // we will use body as temporary buffer for bonds to hydrogen atoms
11630 body.append(QString("\n#if(DrawHydrogens)\n"));
11631
11632 for (int i =0; i<mole.showbonds.size();i++){
11633 if (mole.showbonds.at(i).ato1->hidden) continue;
11634 if (mole.showbonds.at(i).ato2->hidden) continue;
11635 if ((mole.nopm1)&&(mole.showbonds.at(i).ato1->symmGroup)&&(mole.showbonds.at(i).ato1->part<0))continue; // ignore hidden parts (-1)
11636 if ((mole.nopm1)&&(mole.showbonds.at(i).ato2->symmGroup)&&(mole.showbonds.at(i).ato2->part<0))continue; // ignore hidden parts (-1)
11637 s1=QString("AtomPos%1").arg(mole.showbonds.at(i).a1);
11638 s2=QString("AtomPos%1").arg(mole.showbonds.at(i).a2);
11639 if ((chgl->mol->AtomStyle[chgl->mol->showbonds.at(i).ato1->an]&ATOM_STYLE_METAL)||(chgl->mol->AtomStyle[chgl->mol->showbonds.at(i).ato2->an]&ATOM_STYLE_METAL)){
11640 if ((mole.showbonds.at(i).ato1->an == 0)||(mole.showbonds.at(i).ato2->an == 0))
11641 body.append(QString(" DrawDashBond2( %1, %2, HBond_Radius,Dash_Length, Bond_Texture,Color_%3,Color_%4)//%5==%6\n").arg(s1).arg(s2)
11642 .arg(mole.pse(mole.showbonds.at(i).ato2->an))
11643 .arg(mole.pse(mole.showbonds.at(i).ato1->an)).arg(mole.showbonds.at(i).ato1->Label).arg(mole.showbonds.at(i).ato2->Label));
11644 else
11645 bondsPOV.append(QString("DrawDashBond2( %1, %2, Bond_Radius,Dash_Length, Bond_Texture,Color_%3,Color_%4)//%5==%6\n").arg(s1).arg(s2)
11646 .arg(mole.pse(mole.showbonds.at(i).ato2->an))
11647 .arg(mole.pse(mole.showbonds.at(i).ato1->an)).arg(mole.showbonds.at(i).ato1->Label).arg(mole.showbonds.at(i).ato2->Label));
11648 }else{
11649 if ((chgl->highlightParts->isChecked())&&(mole.showbonds.at(i).ato1->part!=0))
11650 bondsPOV.append(QString("DrawBond( %1, %2, Bond_Radius, Bond_Texture,ptcol%3,ptcol%4,%7)//%5==%6\n")
11651 .arg(s1)
11652 .arg(s2)
11653 .arg((mole.showbonds.at(i).ato1->part>0)?QString("%1").arg(mole.showbonds.at(i).ato1->part):
11654 (mole.showbonds.at(i).ato1->part<-3)?"mX":QString("m%1").arg(-mole.showbonds.at(i).ato1->part))
11655 .arg((mole.showbonds.at(i).ato2->part>0)?QString("%1").arg(mole.showbonds.at(i).ato2->part):
11656 (mole.showbonds.at(i).ato2->part<-3)?"mX":QString("m%1").arg(-mole.showbonds.at(i).ato2->part))
11657 .arg(mole.showbonds.at(i).ato1->Label).arg(mole.showbonds.at(i).ato2->Label)
11658 .arg((mole.showbonds.at(i).ato1->part<0)&&(mole.showbonds.at(i).ato1->symmGroup)));
11659
11660 else{
11661 if ((mole.showbonds.at(i).ato1->an == 0)||(mole.showbonds.at(i).ato2->an == 0))
11662 body.append(QString(" DrawBond( %1, %2, HBond_Radius, Bond_Texture,Color_%3,Color_%4,%7)//%5==%6\n").arg(s1).arg(s2).arg(mole.pse(mole.showbonds.at(i).ato1->an)).arg(mole.pse(mole.showbonds.at(i).ato2->an))
11663 .arg(mole.showbonds.at(i).ato1->Label).arg(mole.showbonds.at(i).ato2->Label)
11664 .arg((mole.showbonds.at(i).ato1->part<0)&&(mole.showbonds.at(i).ato1->symmGroup))
11665 );
11666 else
11667 bondsPOV.append(QString("DrawBond( %1, %2, Bond_Radius, Bond_Texture,Color_%3,Color_%4,%7)//%5==%6\n").arg(s1).arg(s2).arg(mole.pse(mole.showbonds.at(i).ato1->an)).arg(mole.pse(mole.showbonds.at(i).ato2->an))
11668 .arg(mole.showbonds.at(i).ato1->Label).arg(mole.showbonds.at(i).ato2->Label)
11669 .arg((mole.showbonds.at(i).ato1->part<0)&&(mole.showbonds.at(i).ato1->symmGroup)));
11670 }
11671 }
11672 }
11673 body.append(QString("\n#if(DrawH_Bonds)\n"));
11674 //qDebug()<<chgl->mol->theH_Bonds.size();
11675 for (int i =0; i<chgl->mol->theH_Bonds.size();i++){
11676 if (mole.theH_Bonds.at(i).ato1->hidden) continue;
11677 if (mole.theH_Bonds.at(i).ato2->hidden) continue;
11678 if ((mole.nopm1)&&(mole.theH_Bonds.at(i).ato1->symmGroup)&&(mole.theH_Bonds.at(i).ato1->part<0))continue; // ignore hidden parts (-1)
11679 if ((mole.nopm1)&&(mole.theH_Bonds.at(i).ato2->symmGroup)&&(mole.theH_Bonds.at(i).ato2->part<0))continue; // ignore hidden parts (-1)
11680 s1=QString("AtomPos%1").arg(mole.theH_Bonds.at(i).a1);
11681 s2=QString("AtomPos%1").arg(mole.theH_Bonds.at(i).a2);
11682 body.append(QString(" DrawDashBond( %1, %2, HBond_Radius, Dash_Length*0.5, HBond_Texture)\n").arg(s1).arg(s2));
11683
11684 }
11685 body.append(QString("#end // End of DrawH_Bonds\n"));
11686 body.append(QString("#end // End of bonds to hydrogen atoms\n"));
11687 bondsPOV.append(body);
11688 bondsPOV.append(QString("//------\n"));
11689
11690 bondsPOV.append(QString("\n//DrawDashBond( Ct02 , Hf1 , Dash_Radius, Dash_Length, texture { Bond_Texture } )\n"));
11691 bondsPOV.append(QString("// ____________________________________ end of bonds\n\n\n\n"));
11692
11693 ringsPOV.append(QString("// ====================================\n"));
11694 ringsPOV.append(QString("#if (DrawAromaticRings)\n"));
11695 ringsPOV.append(QString("/*\n"));
11696 ringsPOV.append(QString(" DrawRing - Example of usage\n"));
11697 ringsPOV.append(QString(" 1st declare new centroid; summation is over coordinates of all ring atoms\n"));
11698 ringsPOV.append(QString(" Divisor should be the same as count of atoms\n"));
11699 ringsPOV.append(QString(" The atoms C1 and N2, used in macro, should be neighbours in the ring.\n\n"));
11700 ringsPOV.append(QString(" #declare CtNew1=(C1+N2+C3+C4+N5)/5;\n"));
11701 ringsPOV.append(QString(" DrawRing(C1,N2,CtNew1)\n\n"));
11702 ringsPOV.append(QString("*/\n"));
11703
11704 // int nonMetal[10], countNonMetal;
11705 QList<int> nonMetals;
11706 for (int i=0; i< mole.showatoms.size(); i++){ // scan visble for Cnt
11707 if (mole.showatoms.at(i).hidden) continue;
11708 if ((mole.nopm1)&&(mole.showatoms.at(i).symmGroup)&&(mole.showatoms.at(i).part<-0)) continue; // ignore hidden parts (-1)
11709 if (mole.showatoms.at(i).an==-66) {//Cnt
11710 nonMetals.clear();
11711 for (int j=0; j< mole.showatoms.size(); j++){
11712 if ((i==j) || (mole.showatoms.at(j).an<1)) continue; // ignore Q, Cnt and H
11713 if (mole.AtomStyle[mole.showatoms.at(j).an]&ATOM_STYLE_METAL) continue;
11714 if ((mole.nopm1)&&(mole.showatoms.at(j).symmGroup)&&(mole.showatoms.at(j).part<-0)) continue; // ignore hidden parts (-1)
11715 double d = sqrt(Distance(mole.showatoms.at(i).pos,mole.showatoms.at(j).pos));
11716 double soll=(70+mole.Kovalenz_Radien[mole.showatoms.at(j).an])*0.012;
11717 if (d<soll) nonMetals.append(j);
11718 }
11719 if (nonMetals.size()>1) { for (int j=0; j<nonMetals.size(); j++){
11720 for (int k=j+1; k<nonMetals.size(); k++){
11721 double d = sqrt(Distance(mole.showatoms.at(nonMetals.at(j)).pos,mole.showatoms.at(nonMetals.at(k)).pos));
11722 double soll=(mole.Kovalenz_Radien[mole.showatoms.at(nonMetals.at(j)).an]+mole.Kovalenz_Radien[mole.showatoms.at(nonMetals.at(k)).an])*0.012;
11723 if (d<soll){
11724 s3=QString("AtomPos%1").arg(i);
11725 s2=QString("AtomPos%1").arg(nonMetals.at(j));
11726 s1=QString("AtomPos%1").arg(nonMetals.at(k));
11727 ringsPOV.append(QString(" DrawRing(%1,%2,%3)\n").arg(s1,10).arg(s2,10).arg(s3,10));
11728 goto endLoop;
11729 }
11730 }
11731 }}
11732 endLoop:;
11733 }
11734 }
11735 ringsPOV.append(QString("#end\n"));
11736 ringsPOV.append(QString("// ____________________________________ end of rings\n\n\n\n"));
11737 nonMetals.clear();
11738 labels.append("//Labels\n#if (DrawLabels)\n");
11739 for (int i=0; i<mole.showatoms.size(); i++){
11740 if (mole.showatoms.at(i).hidden) continue;
11741 if ((mole.nopm1)&&(mole.showatoms.at(i).symmGroup)&&(mole.showatoms.at(i).part<-0)) continue; // ignore hidden parts (-1)
11742 if (mole.showatoms.at(i).an<0) continue;
11743 s2=mole.showatoms.at(i).Label;
11744 if (chgl->shortLabels->isChecked()) {
11745 s2=s2.section("_",0,0);
11746 s2=s2.section(QString::fromUtf8("»"),0,0);
11747 }
11748 s2=s2.replace("\\","\\\\");
11749 s2=s2.replace("\"","\\\"");
11750 s1=QString("AtomPos%1").arg(i);
11751 labels.append(QString("label(\"%1\",%2,Black,0.35)\n").arg(s2).arg(s1));
11752 }
11753 labels.append("#end //DrawLabels\n\n");
11754
11755
11756 /*!draw a unit cell box
11757 *
11758 * */
11759 V3 uz0f,uz1f,uz2f,uz3f,uz4f,uz5f,uz6f,uz7f;
11760 V3 uz0k,uz1k,uz2k,uz3k,uz4k,uz5k,uz6k,uz7k;
11761 uz0f.x=0.0; uz0f.y=0.0; uz0f.z=0.0;
11762 uz1f.x=1.0; uz1f.y=0.0; uz1f.z=0.0;
11763 uz2f.x=0.0; uz2f.y=1.0; uz2f.z=0.0;
11764 uz3f.x=0.0; uz3f.y=0.0; uz3f.z=1.0;
11765 uz4f.x=1.0; uz4f.y=1.0; uz4f.z=0.0;
11766 uz5f.x=1.0; uz5f.y=0.0; uz5f.z=1.0;
11767 uz6f.x=0.0; uz6f.y=1.0; uz6f.z=1.0;
11768 uz7f.x=1.0; uz7f.y=1.0; uz7f.z=1.0;
11769 mole.frac2kart(uz0f,uz0k);
11770 mole.frac2kart(uz1f,uz1k);
11771 mole.frac2kart(uz2f,uz2k);
11772 mole.frac2kart(uz3f,uz3k);
11773 mole.frac2kart(uz4f,uz4k);
11774 mole.frac2kart(uz5f,uz5k);
11775 mole.frac2kart(uz6f,uz6k);
11776 mole.frac2kart(uz7f,uz7k);
11777 uz0k = uz0k - chgl->altemitte;
11778 uz1k = uz1k - chgl->altemitte;
11779 uz2k = uz2k - chgl->altemitte;
11780 uz3k = uz3k - chgl->altemitte;
11781 uz4k = uz4k - chgl->altemitte;
11782 uz5k = uz5k - chgl->altemitte;
11783 uz6k = uz6k - chgl->altemitte;
11784 uz7k = uz7k - chgl->altemitte;
11785 unitCell.append(QString("#if (DrawUnitCell)\n"));
11786 unitCell.append(QString("union{\n"));
11787 unitCell.append(QString("cylinder{<%1,%2,%3>,<%4,%5,%6>,CellWidth texture{pigment{color Red}}}\n")
11788 .arg(uz0k.x)
11789 .arg(uz0k.y)
11790 .arg(uz0k.z)
11791 .arg(uz1k.x)
11792 .arg(uz1k.y)
11793 .arg(uz1k.z));
11794 unitCell.append(QString("cylinder{<%1,%2,%3>,<%4,%5,%6>,CellWidth texture{pigment{color Green}}}\n")
11795 .arg(uz0k.x)
11796 .arg(uz0k.y)
11797 .arg(uz0k.z)
11798 .arg(uz2k.x)
11799 .arg(uz2k.y)
11800 .arg(uz2k.z));
11801 unitCell.append(QString("cylinder{<%1,%2,%3>,<%4,%5,%6>,CellWidth texture{pigment{color Blue}}}\n")
11802 .arg(uz0k.x)
11803 .arg(uz0k.y)
11804 .arg(uz0k.z)
11805 .arg(uz3k.x)
11806 .arg(uz3k.y)
11807 .arg(uz3k.z));
11808 unitCell.append(QString("cylinder{<%1,%2,%3>,<%4,%5,%6>,CellWidth texture{pigment{color LightSteelBlue}}}\n")
11809 .arg(uz4k.x)
11810 .arg(uz4k.y)
11811 .arg(uz4k.z)
11812 .arg(uz1k.x)
11813 .arg(uz1k.y)
11814 .arg(uz1k.z));
11815 unitCell.append(QString("cylinder{<%1,%2,%3>,<%4,%5,%6>,CellWidth texture{pigment{color LightSteelBlue}}}\n")
11816 .arg(uz5k.x)
11817 .arg(uz5k.y)
11818 .arg(uz5k.z)
11819 .arg(uz1k.x)
11820 .arg(uz1k.y)
11821 .arg(uz1k.z));
11822 unitCell.append(QString("cylinder{<%1,%2,%3>,<%4,%5,%6>,CellWidth texture{pigment{color LightSteelBlue}}}\n")
11823 .arg(uz2k.x)
11824 .arg(uz2k.y)
11825 .arg(uz2k.z)
11826 .arg(uz4k.x)
11827 .arg(uz4k.y)
11828 .arg(uz4k.z));
11829 unitCell.append(QString("cylinder{<%1,%2,%3>,<%4,%5,%6>,CellWidth texture{pigment{color LightSteelBlue}}}\n")
11830 .arg(uz2k.x)
11831 .arg(uz2k.y)
11832 .arg(uz2k.z)
11833 .arg(uz6k.x)
11834 .arg(uz6k.y)
11835 .arg(uz6k.z));
11836 unitCell.append(QString("cylinder{<%1,%2,%3>,<%4,%5,%6>,CellWidth texture{pigment{color LightSteelBlue}}}\n")
11837 .arg(uz3k.x)
11838 .arg(uz3k.y)
11839 .arg(uz3k.z)
11840 .arg(uz5k.x)
11841 .arg(uz5k.y)
11842 .arg(uz5k.z));
11843 unitCell.append(QString("cylinder{<%1,%2,%3>,<%4,%5,%6>,CellWidth texture{pigment{color LightSteelBlue}}}\n")
11844 .arg(uz3k.x)
11845 .arg(uz3k.y)
11846 .arg(uz3k.z)
11847 .arg(uz6k.x)
11848 .arg(uz6k.y)
11849 .arg(uz6k.z));
11850 unitCell.append(QString("cylinder{<%1,%2,%3>,<%4,%5,%6>,CellWidth texture{pigment{color LightSteelBlue}}}\n")
11851 .arg(uz4k.x)
11852 .arg(uz4k.y)
11853 .arg(uz4k.z)
11854 .arg(uz7k.x)
11855 .arg(uz7k.y)
11856 .arg(uz7k.z));
11857 unitCell.append(QString("cylinder{<%1,%2,%3>,<%4,%5,%6>,CellWidth texture{pigment{color LightSteelBlue}}}\n")
11858 .arg(uz5k.x)
11859 .arg(uz5k.y)
11860 .arg(uz5k.z)
11861 .arg(uz7k.x)
11862 .arg(uz7k.y)
11863 .arg(uz7k.z));
11864 unitCell.append(QString("cylinder{<%1,%2,%3>,<%4,%5,%6>,CellWidth texture{pigment{color LightSteelBlue}}}\n")
11865 .arg(uz6k.x)
11866 .arg(uz6k.y)
11867 .arg(uz6k.z)
11868 .arg(uz7k.x)
11869 .arg(uz7k.y)
11870 .arg(uz7k.z));
11871 unitCell.append(QString("}\n#end //DrawUnitCell\n\n"));
11872 footerPOV.append(QString("transform {\n"));
11873 footerPOV.append(QString("scale<3.5*ViewAngle/29,3.5*ViewAngle/29,3.5*ViewAngle/29>\n"));
11874 footerPOV.append(QString("scale<SCALE,SCALE,SCALE>\n"));
11875 footerPOV.append(QString(" matrix <\n"));
11876 footerPOV.append(QString(" %1, %2, %3, \n").arg(mv[0],9,'f',6).arg(mv[1],9,'f',6).arg(mv[2],9,'f',6));
11877 footerPOV.append(QString(" %1, %2, %3, \n").arg(mv[4],9,'f',6).arg(mv[5],9,'f',6).arg(mv[6],9,'f',6));
11878 footerPOV.append(QString(" %1, %2, %3, \n").arg(mv[8],9,'f',6).arg(mv[9],9,'f',6).arg(mv[10],9,'f',6));
11879 footerPOV.append(QString(" %1, %2, %3\n").arg(0.0,9,'f',6).arg(0.0,9,'f',6).arg(0.0,9,'f',6));
11880 footerPOV.append(QString(" >\n"));
11881 footerPOV.append(QString("// You can adapt geometry by applying \n"));
11882 footerPOV.append(QString("// translation and rotations (in deg).\n"));
11883 footerPOV.append(QString("// It's easier to use separate rotation for each axis.\n"));
11884 footerPOV.append(QString(" translate < %1, %2, 0.0000 >\n").arg(mv[12]/10,7,'f',4).arg(mv[13]/10,7,'f',4));
11885 footerPOV.append(QString(" rotate < 1.0000, 0.0000, 0.0000 > // Y\n"));
11886 footerPOV.append(QString(" rotate < 0.0000, 1.0000, 0.0000 > // |_______X\n"));
11887 footerPOV.append(QString(" rotate < 0.0000, 0.0000, 1.0000 > // /\n"));
11888 footerPOV.append(QString(" // Z\n"));
11889 footerPOV.append(QString(" }\n"));
11890 footerPOV.append(QString("#if (NoShadows)\nno_shadow\n#end\n} // __END union of objects\n\n"));
11891 printf("writing POV\n");
11892 bool success = f.open(QIODevice::WriteOnly|QIODevice::Text);
11893 if (success){
11894 f.write(headerPOV.toUtf8());
11895 f.write(visableAtoms.toUtf8());
11896 f.write(hydrogenAtoms.toUtf8());
11897 f.write(hiddenAtoms.toUtf8());
11898 f.write(qpeaks.toUtf8());
11899 f.write(bondsPOV.toUtf8());
11900 f.write(ringsPOV.toUtf8());
11901 f.write(unitCell.toUtf8());
11902 f.write(densityMaps.toUtf8());
11903 f.write(voron.toUtf8());
11904 f.write(labels.toUtf8());
11905 f.write(footerPOV.toUtf8());
11906 f.close();
11907 QFile ini(iniName);
11908 ini.open(QIODevice::WriteOnly|QIODevice::Text);
11909 body.clear();
11910 body.append(QString("Input_File_Name='%1';\nWidth=%2;\nHeight=%3;\nAntialias=on;\nAntialias_Threshold=0.3;\nOutput_File_Type=N;\nOutput_Alpha=on;\nOutput_File_Name='%4';\n\n")
11911 .arg(povName)
11912 .arg(int(chgl->width()*scalePic+0.5))
11913 .arg(int(chgl->height()*scalePic+0.5))
11914 .arg(pngName)
11915 );
11916 ini.write(body.toUtf8());
11917 ini.close();
11918 QString PovRayExe = QString();
11919 QSettings *povset = new QSettings( QSettings::IniFormat, QSettings::UserScope ,PROGRAM_NAME,mole.mynewnameis );
11920 povset->beginGroup("PovRay");
11921 PovRayExe = povset->value("PovRayExe","").toString();
11922 povset->endGroup();
11923 if ((PovRayExe.isEmpty())||(!QFileInfo(PovRayExe).isExecutable())) {
11924 PovRayExe.clear();
11925 }
11926 QString fn2;
11927 if (PovRayExe.isEmpty()){
11928 fn2=QFileDialog::getOpenFileName(this, tr("PovRay EXEcutable"), "povray","",nullptr,(useNativeDlg->isChecked())?noneopt:QFileDialog::DontUseNativeDialog );
11929 if (fn2.isEmpty()) return;
11930 }
11931 if ((!fn2.isEmpty())&&(QFileInfo(fn2).isExecutable())) {
11932 povset->beginGroup("PovRay");
11933 povset->setValue("PovRayExe", fn2);
11934 PovRayExe = fn2;
11935 povset->endGroup();
11936 }//executable
11937 //run povray
11938 QString dn=dirName.section('/',0,-2);
11939 #if defined Q_WS_WIN || defined Q_OS_WIN
11940 QStringList al=QString(QString("/EDIT*%1*/EDIT*%2*/RENDER*%2").arg(fn).arg(iniName)).split("*");//i think * should not be alowed in path names
11941 //qDebug()<<al;
11942 #else
11943 QStringList al=QString(QString("+I%1*%2").arg(fn).arg(iniName)).split("*");
11944
11945 #endif
11946 extraProc = new QProcess(this);
11947 #if (defined Q_WS_WIN || defined Q_OS_WIN)
11948 #if (QT_VERSION >= 0x050700)
11949 extraProc->setProgram(PovRayExe);
11950 extraProc->setArguments(al);
11951 extraProc->setWorkingDirectory(dn);
11952 extraProc->setCreateProcessArgumentsModifier([] (QProcess::CreateProcessArguments *args) {args->flags &= ~CREATE_NO_WINDOW;});
11953 extraProc->startDetached();
11954 #else
11955 extraProc->startDetached(PovRayExe,al,dn);
11956 #endif
11957 #else
11958 //not windows we need to parse the output of povray
11959 //qDebug()<<PovRayExe<<al<<dn;
11960 extraIndex = -21;
11961 extraProc->setWorkingDirectory(dn); // updateXLput()
11962 connect(extraProc,SIGNAL(readyReadStandardOutput ()),this,SLOT(updateExtraOutput()));
11963 connect(extraProc,SIGNAL(finished(int,QProcess::ExitStatus)),this,SLOT(updateExtraOutput()));
11964 connect(extraProc,SIGNAL(error(QProcess::ProcessError)),this,SLOT(updateExtraOutput()));
11965 #if (QT_VERSION >= 0x040600)
11966 QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
11967 extraProc->setProcessEnvironment(env);//Thanks to Dr. Pavlo Solntsev!!
11968 #else
11969 QStringList env = QProcess::systemEnvironment();
11970 extraProc->setEnvironment(env);
11971 #endif
11972 //extraProc->startDetached(,al,dn);
11973 extraProc->start(PovRayExe,al);
11974 extraOutPut->setReadOnly(false);
11975 extraOutPut->setText(QString("Running POVRAY ...\n"));
11976 extraOutput->show();
11977 updateExtraOutput();
11978 #endif
11979
11980 }//success
11981
11982 }
11983
11984 void Window::savePovInc(QString povName){
11985 // Generates additional incremenmt file with color and other parameters
11986
11987 // QString iniName = "atoms.inc";
11988 // QString fn=QFileDialog::getSaveFileName(this, tr("Export POV-Ray inc"), iniName, tr("POV-Ray inc (*.inc)"));
11989
11990 QString incName = povName.section('.',0,-2);
11991 incName.append(".inc");
11992
11993 //QString fn=QFileDialog::getSaveFileName(this, tr("Export POV-Ray inc"), iniName, tr("POV-Ray inc (*.inc)"));
11994 //if (fn.isEmpty()) return;
11995
11996 QFile f(incName);
11997 QString body;
11998 body.append("#declare Triacontaeder=\n"
11999 "object {\n"
12000 "#local A=1.0;\n"
12001 "#local B=0.0;\n"
12002 "#local C=(sqrt(5.0)+1.0)/2.0;//1.618034\n"
12003 "#local D=C-1.0;//0.618034\n"
12004 "mesh2 {\n"
12005 " vertex_vectors {\n"
12006 " 32,\n"
12007 "< B, -C, A>, \n"
12008 "<-A, B, C>,< A, B, C>,< B, D, C>,\n"
12009 "< B, -D, C>,< A, A, A>,< A, -A, A>,\n"
12010 "< C, B, D>,< C, B, -D>,< C, A, B>,\n"
12011 "< C, -A, B>,< -C, B, D>,< -C, A, B>,\n"
12012 "<-C, B, -D>,< -C, -A, B>,< A, A, -A>,\n"
12013 "< D, C, B>,< -A, A, A>,< -D, C, B>,\n"
12014 "<-A, A, -A>,< B, C, -A>,< B, C, A>,\n"
12015 "<-A, -A, -A>,< -D, -C, B>,< D, -C, B>,\n"
12016 "< A, -A, -A>,< B, -C, -A>,< B, D, -C>,\n"
12017 "< A, B, -C>,< -A, -A, A>,< B, -D, -C>,\n"
12018 "<-A, B, -C>\n"
12019 " }\n"
12020 " face_indices {\n"
12021 " 60,\n"
12022 " < 2, 3, 4>, < 2, 5, 3>, < 2, 4, 6>,\n"
12023 " < 2, 7, 5>, < 2, 6, 7>, < 7, 8, 9>,\n"
12024 " < 7, 10, 8>, < 11, 12, 13>, < 11, 13, 14>,\n"
12025 " < 9, 15, 16>, < 9, 8, 15>, < 3, 1, 4>,\n"
12026 " < 3, 17, 1>, < 18, 19, 12>, < 18, 20, 19>,\n"
12027 " < 12, 19, 13>, < 3, 21, 17>, < 14, 22, 23>,\n"
12028 " < 14, 13, 22>, < 24, 25, 10>, < 24, 26, 25>,\n"
12029 " < 10, 25, 8>, < 15, 27, 20>, < 15, 28, 27>,\n"
12030 " < 20, 27, 19>, < 1, 29, 4>, < 22, 30, 26>,\n"
12031 " < 22, 31, 30>, < 1, 17, 11>, < 26, 30, 25>,\n"
12032 " < 1, 11, 29>, < 25, 30, 28>, < 28, 30, 27>,\n"
12033 " < 27, 30, 31>, < 4, 0, 6>, < 5, 9, 16>,\n"
12034 " < 5, 16, 21>, < 21, 16, 18>, < 21, 18, 17>,\n"
12035 " < 29, 14, 23>, < 29, 23, 0>, < 0, 23, 24>,\n"
12036 " < 0, 24, 6>, < 16, 20, 18>, < 23, 26, 24>,\n"
12037 " < 16, 15, 20>, < 3, 5, 21>, < 23, 22, 26>,\n"
12038 " < 8, 28, 15>, < 8, 25, 28>, < 13, 19, 31>,\n"
12039 " < 13, 31, 22>, < 19, 27, 31>, < 4, 29, 0>,\n"
12040 " < 5, 7, 9>, < 17, 12, 11>, < 17, 18, 12>,\n"
12041 " < 29, 11, 14>, < 6, 10, 7>, < 6, 24, 10>\n"
12042 " }\n"
12043 "}//mesh\n"
12044 "};\n\n");
12045 body.append(QString("#macro DrawBond(at1,at2,rad,textur,t1,t2,ghost)\n"));
12046 body.append(QString("#if (ghost)\n"));
12047 body.append(QString("#local bc = (at1 + at2) * 0.5;\ncylinder {at1 bc rad texture { pigment{t1 blue 1.0 transmit 0.7} } }\ncylinder {at2 bc rad texture { pigment{t2 blue 1.0 transmit 0.7} } }\n"));
12048 body.append(QString("#else\n"));
12049 body.append(QString("#if (UniColorBonds)\n"));
12050 body.append(QString(" cylinder {at1 at2 rad texture { textur } }\n"));
12051 body.append(QString("#else\n"));
12052 body.append(QString("#local bc = (at1 + at2) * 0.5;\ncylinder {at1 bc rad texture { pigment{t1} } }\ncylinder {at2 bc rad texture { pigment{t2} } }\n"));
12053 body.append(QString("#end\n"));
12054 body.append(QString("#end\n"));
12055 body.append(QString("#end\n\n"));
12056 body.append(QString("#macro qbond(at1,at2)\n"));
12057 body.append(QString(" cylinder {at1 at2 0.005 texture { pigment{ color Color_Cnt} } }\n"));
12058 body.append(QString("##end\n\n"));
12059 body.append(QString("#macro qpeak(pos, r, cr, cg, cb, an)\n"));
12060 body.append(QString("object{\n"));
12061 body.append(QString("#local rf =1;\n"));
12062 body.append(QString("#switch (an)\n#case(-1)\nIcosahedron\nqpeakTexture(cr, cg, cb)\n#break\n#case(-42)\n"
12063 "Triacontaeder\nqpeakTexture(cr, cg, cb)\n#local rf =%1;\n"
12064 "#break\n#case(-66)\nDodecahedron\ntexture {pigment{ color Color_Cnt}}\n#local rf =1.25;\n\n#end\n").arg(0.5*mole.beloRad/mole.qPeakRad,0,'f',3));
12065 body.append(QString("scale <1, 1, 1> * r *rf \n"));
12066 body.append(QString("translate pos\n"));
12067 body.append(QString("}\n"));
12068 body.append(QString("#end\n\n"));
12069 body.append(QString("#macro DrawDashBond(at1,ct1,RadiusDash,LengthDash,TextureDash)\n"));
12070 body.append(QString(" #local L=VDist(at1,ct1);\n"));
12071 body.append(QString(" #local IL = L / LengthDash;\n"));
12072 body.append(QString(" #local strip = (ct1 - at1)/IL;\n"));
12073 body.append(QString(" #local i=0;\n"));
12074 body.append(QString(" #local tempXYZ=ct1;\n"));
12075 body.append(QString(" #while (i<IL )\n"));
12076 body.append(QString(" #local tempXYZ2=tempXYZ-strip;\n"));
12077 body.append(QString(" cylinder { tempXYZ tempXYZ2 RadiusDash texture { TextureDash } }\n"));
12078 body.append(QString(" #local tempXYZ=tempXYZ2-strip;\n"));
12079 body.append(QString(" #local i=i+2;\n"));
12080 body.append(QString(" #end\n"));
12081 body.append(QString("#end\n\n"));
12082
12083 body.append(QString("#macro DrawDashBond2(at1,ct1,RadiusDash,LengthDash,T0,T1,T2)\n"));
12084 body.append(QString(" #local L=VDist(at1,ct1);\n"));
12085 body.append(QString(" #local IL = L / LengthDash;\n"));
12086 body.append(QString(" #local strip = (ct1 - at1)/IL;\n"));
12087 body.append(QString(" #local i=0;\n"));
12088 body.append(QString(" #local tempXYZ=ct1;\n"));
12089 body.append(QString(" #while (i<IL )\n"));
12090 body.append(QString(" #local tempXYZ2=tempXYZ-strip;\n"));
12091 body.append(QString(" #if (UniColorBonds)\n"
12092 " cylinder { tempXYZ tempXYZ2 RadiusDash texture { T0 } }\n"
12093 " #else\n"
12094 " #if (i<IL/2)\n"
12095 " cylinder { tempXYZ tempXYZ2 RadiusDash texture { pigment{T1} } }\n"
12096 " #else\n"
12097 " cylinder { tempXYZ tempXYZ2 RadiusDash texture { pigment{T2} } }\n"
12098 " #end //IL/2\n"
12099 " #end //unicolor\n"));
12100 body.append(QString(" #local tempXYZ=tempXYZ2-strip;\n"));
12101 body.append(QString(" #local i=i+2;\n"));
12102 body.append(QString(" #end\n"));
12103 body.append(QString("#end\n\n"));
12104 body.append(QString("#macro DrawArrow(at1,at2,rad,textur)\n"));
12105 body.append(QString(" #local SpaceBeforeAt2 = 0.2; // arrow should end before ellipsoide\n"));
12106 body.append(QString(" #local ArrowConeLength = rad*4;\n"));
12107 body.append(QString(" #local ArrowConeRadius = rad*2;\n"));
12108 body.append(QString(" #local ArrowVector = (at2 - at1);\n"));
12109 body.append(QString(" #local ShaftMeetsHead = at2 - vnormalize (ArrowVector) * (ArrowConeLength+SpaceBeforeAt2);\n"));
12110 body.append(QString(" #local ArrowPoint = at2 - vnormalize (ArrowVector) * SpaceBeforeAt2;\n"));
12111 body.append(QString(" cylinder {at1 ShaftMeetsHead radiu texture { textur } }\n"));
12112 body.append(QString(" cone {ShaftMeetsHead, ArrowConeRadius, ArrowPoint, 0 texture { textur } }\n"));
12113 body.append(QString("#end\n\n"));
12114 body.append(QString("#macro DrawArrowC(at1,at2,rad,colou)\n"));
12115 body.append(QString(" #local SpaceBeforeAt2 = 0.2; // arrow should end before ellipsoide\n"));
12116 body.append(QString(" #local ArrowConeLength = rad*4;\n"));
12117 body.append(QString(" #local ArrowConeRadius = rad*2;\n"));
12118 body.append(QString(" #local ArrowVector = (at2 - at1);\n"));
12119 body.append(QString(" #local ShaftMeetsHead = at2 - vnormalize (ArrowVector) * (ArrowConeLength+SpaceBeforeAt2);\n"));
12120 body.append(QString(" #local ArrowPoint = at2 - vnormalize (ArrowVector) * SpaceBeforeAt2;\n"));
12121 body.append(QString(" cylinder {at1 ShaftMeetsHead rad texture { pigment {color colou} finish { Shiny } } }\n"));
12122 body.append(QString(" cone {ShaftMeetsHead, ArrowConeRadius, ArrowPoint, 0 texture { pigment {color colou} finish { Shiny } } }\n"));
12123 body.append(QString("#end\n\n"));
12124 body.append(QString("#macro DrawRing(at1,at2,Ct)\n"));
12125 body.append(QString("#declare w = vcross((at1-Ct),(at2-Ct));\n"));
12126 body.append(QString("#declare RadiusBig = vlength((at1+at2)/2 - Ct);\n"));
12127 body.append(QString("object {\n"));
12128 body.append(QString(" torus\n"));
12129 body.append(QString(" { RadiusBig*.75, Dash_Radius\n"));
12130 body.append(QString(" texture { Bond_Texture }\n"));
12131 body.append(QString(" }\n"));
12132 body.append(QString(" Reorient_Trans(<0, 1, 0>,w)\n"));
12133 body.append(QString(" translate Ct\n"));
12134 body.append(QString(" }\n"));
12135 body.append(QString("#end\n\n"));
12136 body.append(QString("#macro DrawCube(cL,colorCube,colorEdge)\n"));
12137 body.append(QString(" #local edgeR=cL/10;\n"));
12138 body.append(QString(" box{ <-cL,-cL,-cL>,<cL,cL,cL> texture { finish { Shiny } pigment {color colorCube } } }\n"));
12139 body.append(QString(" cylinder{ <-cL,-cL,-cL> < cL,-cL,-cL> edgeR texture { finish { Shiny } pigment {color colorEdge } } }\n"));
12140 body.append(QString(" cylinder{ <-cL,-cL,-cL> <-cL, cL,-cL> edgeR texture { finish { Shiny } pigment {color colorEdge } } }\n"));
12141 body.append(QString(" cylinder{ <-cL,-cL,-cL> <-cL,-cL, cL> edgeR texture { finish { Shiny } pigment {color colorEdge } } }\n"));
12142 body.append(QString(" cylinder{ < cL, cL, cL> < cL, cL,-cL> edgeR texture { finish { Shiny } pigment {color colorEdge } } }\n"));
12143 body.append(QString(" cylinder{ < cL, cL, cL> <-cL, cL, cL> edgeR texture { finish { Shiny } pigment {color colorEdge } } }\n"));
12144 body.append(QString(" cylinder{ < cL, cL, cL> < cL,-cL, cL> edgeR texture { finish { Shiny } pigment {color colorEdge } } }\n"));
12145 body.append(QString(" cylinder{ <-cL, cL, cL> <-cL, cL,-cL> edgeR texture { finish { Shiny } pigment {color colorEdge } } }\n"));
12146 body.append(QString(" cylinder{ <-cL, cL, cL> <-cL,-cL, cL> edgeR texture { finish { Shiny } pigment {color colorEdge } } }\n"));
12147 body.append(QString(" cylinder{ < cL,-cL, cL> < cL,-cL,-cL> edgeR texture { finish { Shiny } pigment {color colorEdge } } }\n"));
12148 body.append(QString(" cylinder{ < cL,-cL, cL> <-cL,-cL, cL> edgeR texture { finish { Shiny } pigment {color colorEdge } } }\n"));
12149 body.append(QString(" cylinder{ < cL, cL,-cL> < cL,-cL,-cL> edgeR texture { finish { Shiny } pigment {color colorEdge } } }\n"));
12150 body.append(QString(" cylinder{ < cL, cL,-cL> <-cL, cL,-cL> edgeR texture { finish { Shiny } pigment {color colorEdge } } }\n"));
12151 body.append(QString("#end\n\n"));
12152 body.append(QString("#declare Molekel_GrayLt = color red 0.70 green 0.70 blue 0.70;\n"));
12153 body.append(QString("#declare Molekel_Red = color red 0.70 green 0.00 blue 0.00;\n"));
12154 body.append(QString("#declare Molekel_Green = color red 0.00 green 0.40 blue 0.00;\n"));
12155 body.append(QString("#declare Molekel_Blue = color red 0.00 green 0.00 blue 0.60;\n"));
12156 body.append(QString("#declare Molekel_Yellow = color red 0.80 green 0.80 blue 0.00;\n"));
12157 body.append(QString("#declare Molekel_Violet = color red 0.60 green 0.00 blue 0.60;\n"));
12158 body.append(QString("#declare Molekel_GrayDk = color red 0.25 green 0.25 blue 0.25;\n"));
12159 body.append(QString("#declare Molekel_BrownDk = color red 0.30 green 0.20 blue 0.10;\n"));
12160 body.append(QString("#declare Molekel_BrownLt = color red 0.45 green 0.40 blue 0.25;\n"));
12161 body.append(QString("#declare Lightblue = color red 0.56 green 0.56 blue 1.00;\n"));
12162 body.append(QString("#declare DeepPink = color red 1.00 green 0.08 blue 0.58;\n\n"));
12163 body.append(QString("#macro qpeakTexture(r, g, b)\n"));
12164 body.append(QString(" texture{\n"));
12165 body.append(QString(" pigment{\n"));
12166 body.append(QString(" color <r, g, b>\n"));
12167 body.append(QString(" filter 0.25\n"));
12168 body.append(QString(" transmit 0.25}\n"));
12169 body.append(QString(" finish{\n"));
12170 body.append(QString(" specular 0.6\n"));
12171 body.append(QString(" phong 0.2\n"));
12172 body.append(QString(" phong_size 80}\n}\n"));
12173 body.append(QString(" interior_texture{\n"));
12174 body.append(QString(" pigment{\n"));
12175 body.append(QString(" color <r, g, b>\n"));
12176 body.append(QString(" filter 0.666\n"));
12177 body.append(QString(" transmit 0.475\n"));
12178 body.append(QString(" }\n"));
12179 body.append(QString(" finish{\n"));
12180 body.append(QString(" specular 0\n"));
12181 body.append(QString(" }\n"));
12182 body.append(QString(" }\n"));
12183 body.append(QString("#end\n\n"));
12184 body.append(QString("#if (BW)\n"));
12185 body.append(QString("#declare diffPosCol = texture{ pigment{ color rgbt<%1,%2,%3,%4>}finish { diffuse 1.0 ambient 0.5 specular 0.3 }};\n")
12186 .arg(0.8)
12187 .arg(0.8)
12188 .arg(0.8)
12189 .arg(1.0-chgl->lintrans));
12190 body.append(QString("#declare diffMinCol = texture{ pigment{ color rgbt<%1,%2,%3,%4>}finish { diffuse 1.0 ambient 0.5 specular 0.3 }};\n")
12191 .arg(0.2)
12192 .arg(0.2)
12193 .arg(0.2)
12194 .arg(1.0-chgl->lintrans));
12195 body.append(QString("#declare FobsPosCol = texture{ pigment{ color rgbt<%1,%2,%3,%4>}finish { diffuse 1.0 ambient 0.5 specular 0.3 }};\n")
12196 .arg(0.4)
12197 .arg(0.4)
12198 .arg(0.4)
12199 .arg(1.0-chgl->lintrans));
12200 body.append(QString("#declare FobsMinCol = texture{ pigment{ color rgbt<%1,%2,%3,%4>}finish { diffuse 1.0 ambient 0.5 specular 0.3 }};\n")
12201 .arg(0.6)
12202 .arg(0.6)
12203 .arg(0.6)
12204 .arg(1.0-chgl->lintrans));
12205 body.append(QString("#else\n"));
12206 body.append(QString("#declare diffPosCol = texture{ pigment{ color rgbt<%1,%2,%3,%4>}finish { diffuse 1.0 ambient 0.5 specular 0.3 }};\n")
12207 .arg(chgl->dipc.redF())
12208 .arg(chgl->dipc.greenF())
12209 .arg(chgl->dipc.blueF())
12210 .arg(1.0-chgl->lintrans));
12211 body.append(QString("#declare diffMinCol = texture{ pigment{ color rgbt<%1,%2,%3,%4>}finish { diffuse 1.0 ambient 0.5 specular 0.3 }};\n")
12212 .arg(chgl->dimc.redF())
12213 .arg(chgl->dimc.greenF())
12214 .arg(chgl->dimc.blueF())
12215 .arg(1.0-chgl->lintrans));
12216 body.append(QString("#declare FobsPosCol = texture{ pigment{ color rgbt<%1,%2,%3,%4>}finish { diffuse 1.0 ambient 0.5 specular 0.3 }};\n")
12217 .arg(chgl->fopc.redF())
12218 .arg(chgl->fopc.greenF())
12219 .arg(chgl->fopc.blueF())
12220 .arg(1.0-chgl->lintrans));
12221 body.append(QString("#declare FobsMinCol = texture{ pigment{ color rgbt<%1,%2,%3,%4>}finish { diffuse 1.0 ambient 0.5 specular 0.3 }};\n")
12222 .arg(chgl->fomc.redF())
12223 .arg(chgl->fomc.greenF())
12224 .arg(chgl->fomc.blueF())
12225 .arg(1.0-chgl->lintrans));
12226 body.append(QString("#end\n"));
12227 body.append(QString("#declare Bond_Texture = texture {\n"));
12228 body.append(QString("#if (BW)\npigment {color rgb<%1,%1,%1>}\n#else\n").arg(chgl->mol->bondColor.valueF()));
12229 body.append(QString("pigment {color rgb<%1, %2, %3>}\n#end\n").arg(chgl->mol->bondColor.redF()).arg(chgl->mol->bondColor.greenF()).arg(chgl->mol->bondColor.blueF()));
12230 body.append(QString("finish { diffuse 1.0 ambient 0.5 specular 1.0 } }\n\n"));
12231 body.append(QString("#declare HBond_Texture = texture {\n"));
12232 body.append(QString("pigment {\n#if (BW)\ncolor rgb<0.7, 0.7, 0.7>\n#else\ncolor rgb<1, 1, 0>\n#end\n}\n"));
12233 body.append(QString("finish { diffuse 1.0 ambient 0.5 specular 1.0 } }\n\n"));
12234 QColor pcolor;
12235
12236 body.append(QString("#declare Bond_Radius = %1;\n").arg(mole.bondStrength));
12237 body.append(QString("#declare H_Radius = Bond_Radius*1.3;\n"));
12238 body.append(QString("#declare Dash_Radius = 0.6 * Bond_Radius;\n"));
12239 body.append(QString("#declare Dash_Length = 0.14;\n"));
12240 body.append(QString("#declare HBond_Radius = 0.6 * Bond_Radius;\n\n"));
12241 body.append(QString("#macro label(lab,pos,col,scal)\n"));
12242 body.append(QString("text{ttf atomfont lab 0.01, 0.0 texture{pigment{color col}finish{ambient 1.0}}\n"));
12243 body.append(QString("scale scal\ntransform InvMat\ntranslate pos\ntranslate EyeDir\nno_shadow\n}\n#end\n\n"));
12244 body.append(QString("#macro llabel(lab,pos,col,scal)\n"));
12245 body.append(QString("text{ttf atomfont lab 0.01, 0.0 texture{pigment{color col}finish{ambient 1.0}}\n"));
12246 body.append(QString("scale scal\ntranslate pos\nno_shadow\n}\n#end\n\n"));
12247 body.append(QString("#if(BW) // _________________________________ set here colors for B&W modus\n"));
12248 //body.append(QString("#declare Color_Ct = color rgb<%1,%1,%1>;\n"));
12249 //body.append(QString("#declare Equator_Ct = color Gray05;\n"));
12250 for (int pt=1; pt<100; pt++){
12251
12252
12253 pcolor=PartColor::color(pt);
12254 pcolor.setAlpha(140);
12255 body.append(QString("#declare ptcol%1 = color rgbt<%2, %3, %4, %5>;\n")
12256 .arg(pt)
12257 .arg(pcolor.valueF())
12258 .arg(pcolor.valueF())
12259 .arg(pcolor.valueF())
12260 .arg(1.0-pcolor.alphaF())
12261 );
12262
12263 pcolor=PartColor::color(-pt);
12264 pcolor.setAlpha(140);
12265 body.append(QString("#declare ptcolm%5 = color rgbt<%1, %2, %3, %4>;\n")
12266 .arg(pcolor.valueF())
12267 .arg(pcolor.valueF())
12268 .arg(pcolor.valueF())
12269 .arg(1.0-pcolor.alphaF())
12270 .arg(pt));
12271 }
12272 pcolor=Qt::magenta;
12273 pcolor.setAlpha(140);
12274 body.append(QString("#declare ptcolmX = color rgbt<%1, %2, %3, %4>;\n")
12275 .arg(pcolor.valueF())
12276 .arg(pcolor.valueF())
12277 .arg(pcolor.valueF())
12278 .arg(1.0-pcolor.alphaF()));
12279 pcolor=QColor("fuchsia");
12280 pcolor.setAlpha(200);
12281 body.append(QString("#declare ptcol666 = color rgbt<%1, %2, %3, %4>;\n")
12282 .arg(pcolor.valueF())
12283 .arg(pcolor.valueF())
12284 .arg(pcolor.valueF())
12285 .arg(1.0-pcolor.alphaF())
12286 );
12287 for (int i=0; i<103; i++){
12288 body.append(QString("#declare Color_%2 = color rgb<%1,%1,%1>;\n").arg(chgl->mol->AtomColor[i].valueF()).arg(chgl->mol->pse(i)));
12289 body.append(QString("#declare Equator_%2 = color rgb<%1,%1,%1>;;\n").arg((chgl->mol->AtomStyle[i]&ATOM_STYLE_RINGS)
12290 ?((chgl->mol->AtomStyle[i]&ATOM_STYLE_WHITERING)? 0.95 : 0.05)
12291 :chgl->mol->AtomColor[i].valueF()).arg(chgl->mol->pse(i)));//ATOM_STYLE_WHITERING//ATOM_STYLE_RINGS
12292 }
12293 body.append(QString("#declare Color_Q = color rgbt<0.5,0.5,0.5,0.5>;\n"));
12294 body.append(QString("#declare Color_Cnt = color rgbt<0.2,0.2,0.2,0.5>;\n"));
12295 body.append(QString("#else // _________________________________ set here colors for Color modus\n"));
12296 for (int pt=1; pt<100; pt++){
12297
12298 pcolor=PartColor::color(pt);
12299 pcolor.setAlpha(140);
12300 body.append(QString("#declare ptcol%1 = color rgbt<%2, %3, %4, %5>;\n")
12301 .arg(pt)
12302 .arg(pcolor.redF())
12303 .arg(pcolor.greenF())
12304 .arg(pcolor.blueF())
12305 .arg(1.0-pcolor.alphaF())
12306 );
12307
12308 pcolor=PartColor::color(-pt);
12309 pcolor.setAlpha(140);
12310 body.append(QString("#declare ptcolm%5 = color rgbt<%1, %2, %3, %4>;\n")
12311 .arg(pcolor.redF())
12312 .arg(pcolor.greenF())
12313 .arg(pcolor.blueF())
12314 .arg(1.0-pcolor.alphaF())
12315 .arg(pt)
12316 );
12317 }
12318 pcolor=Qt::magenta;pcolor.setAlpha(140);
12319 body.append(QString("#declare ptcolmX = color rgbt<%1, %2, %3, %4>;\n")
12320 .arg(pcolor.redF())
12321 .arg(pcolor.greenF())
12322 .arg(pcolor.blueF())
12323 .arg(1.0-pcolor.alphaF())
12324 );
12325 pcolor=QColor("fuchsia");
12326 pcolor.setAlpha(200);
12327 body.append(QString("#declare ptcol666 = color rgbt<%1, %2, %3, %4>;\n")
12328 .arg(pcolor.redF())
12329 .arg(pcolor.greenF())
12330 .arg(pcolor.blueF())
12331 .arg(1.0-pcolor.alphaF())
12332 );
12333 for (int i=0; i<103; i++){
12334 body.append(QString("#declare Color_%1 = color rgb<%2,%3,%4>;\n").arg(chgl->mol->pse(i))
12335 .arg(chgl->mol->AtomColor[i].redF())
12336 .arg(chgl->mol->AtomColor[i].greenF())
12337 .arg(chgl->mol->AtomColor[i].blueF()));
12338 body.append(QString("#declare Equator_%2 = color rgb<%1,%1,%1>;;\n").arg((chgl->mol->AtomStyle[i]&ATOM_STYLE_RINGS)
12339 ?((chgl->mol->AtomStyle[i]&ATOM_STYLE_WHITERING)? 0.95 : 0.05)
12340 :chgl->mol->AtomColor[i].valueF()).arg(chgl->mol->pse(i)));//ATOM_STYLE_WHITERING//ATOM_STYLE_RINGS
12341 }
12342 body.append(QString("#declare Color_Q = color rgbt<1.0,0.5,0.0,0.5>;\n"));
12343 body.append(QString("#declare Color_Cnt = color Brown;\n"));
12344 //body.append(QString("#declare Color_Ct = color Gray95;\n"));
12345 //body.append(QString("#declare Equator_Ct = color Gray05;\n"));
12346 body.append(QString("#end // _________________________________ end of Color modus\n"));
12347
12348 bool success = f.open(QIODevice::WriteOnly|QIODevice::Text);
12349 if (success){
12350 f.write(body.toUtf8());
12351 f.close();
12352 }
12353 }
12354
12355 void Window::saveScene(){
12356 //glGetDoublev(GL_MODELVIEW_MATRIX,chgl->MM);
12357
12358 QList<QByteArray> supo = QImageWriter::supportedImageFormats ();
12359 QString formats;
12360 saveName = dirName;
12361 saveName.replace(dirName.size()-4,4,".png");
12362 QString selectedFilter="png-file (*.png)";
12363 for (int i=0; i<supo.size(); i++){
12364 if ((!QString(supo.at(i)).contains("ps",Qt::CaseInsensitive)) &&
12365 (!QString(supo.at(i)).contains(QRegularExpression("[A-Z]"))))
12366 formats+=QString("%1-file (*.%1)%2").arg(QString(supo.at(i))).arg(((i+1)<supo.size())?";;":"");
12367 }
12368 int
12369 a = int(chgl->width()*scalePic+0.5),
12370 b = int(chgl->height()*scalePic+0.5),
12371 c = int(chgl->myFont.pointSize ()*scalePic+0.5),
12372 //d = chgl->width(),
12373 //e = chgl->height(),
12374 f = chgl->myFont.pointSize ();
12375 QString fileName = QFileDialog::getSaveFileName(this,QString("Save a screen shot with %1 x %2 pixels").arg(a).arg(b), saveName,formats,&selectedFilter);
12376 if (!fileName.isEmpty()){
12377 QString endung=selectedFilter.section('*',1,1).section(')',0,0);
12378 if (!fileName.endsWith(endung)) fileName.append(endung);
12379 //chgl->noWaitLabel=true;
12380 chgl->exporting=true;
12381 chgl->myFont.setPointSize(c);
12382 mole.saveProg=mole.g_Program;
12383 QPixmap map;
12384
12385 //if (scalePic!=1.0) map= chgl->renderPixmap(a,b);
12386 if ((scalePic==1.0)||map.isNull ()){
12387 if (QOpenGLFramebufferObject::hasOpenGLFramebufferObjects()) {
12388 QImage mapi=chgl->grabFramebuffer();
12389 //printf("hasOpenGLFramebufferObjects\n");
12390 mapi.save(fileName);
12391 }else{
12392 #if (QT_VERSION >=0x050000)
12393 QPixmap pixmap = screen->grabWindow( chgl->winId() );
12394 #else
12395 QPixmap pixmap = QPixmap::grabWindow( chgl->winId() );
12396 #endif
12397 pixmap.save(fileName);
12398 }
12399 }else map.save(fileName);
12400 mole.g_Program=mole.saveProg;
12401 if(!separateLabelFile->isChecked()) {
12402 QPixmap fmap = QPixmap(fileName);
12403 QPainter *paint = new QPainter(&fmap);
12404 paint->setPen(QPen(chgl->labelColor));
12405 paint->setFont(chgl->myFont);
12406 for (int n=0; n<chgl->LabelZ.size(); n++){
12407 if ((!(mole.AtomStyle[chgl->LabelZ.at(n).an]&ATOM_STYLE_NOLABEL)))
12408 paint->drawText(chgl->LabelZ.at(n).x,chgl->LabelZ.at(n).y,chgl->LabelZ.at(n).l);
12409 }
12410 paint->end();
12411 fmap.save(fileName);
12412 }
12413 else{
12414 QPixmap fmap = QPixmap(a,b);
12415 fmap.fill(QColor(128,128,128,0));
12416 QPainter *paint = new QPainter(&fmap);
12417 paint->setPen(QPen(chgl->labelColor));
12418 paint->setFont(chgl->myFont);
12419 for (int n=0; n<chgl->LabelZ.size(); n++){
12420 if ((!(mole.AtomStyle[chgl->LabelZ.at(n).an]&ATOM_STYLE_NOLABEL)))
12421 paint->drawText(chgl->LabelZ.at(n).x,chgl->LabelZ.at(n).y,chgl->LabelZ.at(n).l);
12422 }
12423 paint->end();
12424 QString fn2=fileName;
12425 fn2.insert(fileName.lastIndexOf("."),"_labels");
12426 fmap.save(fn2);
12427 }
12428 saveName=fileName;
12429 chgl->exporting=false;
12430 }
12431 chgl->myFont.setPointSize(f);
12432 //chgl->ww=d;
12433 //chgl->wh=e;
12434 //chgl->noWaitLabel=false;
12435 }
12436
12437 void Window::infoKanalNews(const QString& s){
12438 QString alt = infoKanal->toHtml();
12439 // printf("\n\n\n%s\n\n\n",(const char *)alt.toLocal8Bit());
12440 alt.remove(QRegularExpression("ERROR [^!]*!"));
12441 alt.remove(QRegularExpression("<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:large; color:#ff0000;\"><br /></span></p>",
12442 QRegularExpression::CaseInsensitiveOption));//,QRegularExpression::FixedString
12443 alt.remove(QRegularExpression("<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-size:large; color:#ff0000;\"></span></p>"
12444 ,QRegularExpression::CaseInsensitiveOption));
12445 alt.append(s);
12446 infoKanal->setHtml(alt);
12447 QTextCursor c = infoKanal->textCursor();
12448 c.movePosition(QTextCursor::End);
12449 infoKanal->setTextCursor(c);
12450 infoKanal->ensureCursorVisible();
12451 if (chgl->toggleDockWidgets->isChecked()) return;
12452 if ( enterRenameMode->isChecked()) return;
12453 dock->show();
12454 dock->raise();
12455 }
12456
12457 void Window::shx_editor(QString filename){
12458 if (otherOpenFiles){
12459 editor->clear();
12460 editor->document()->disconnect();
12461 actionUndo->disconnect();
12462 actionRedo->disconnect();
12463 actionCut->disconnect();
12464 actionCopy->disconnect();
12465 actionPaste->disconnect();
12466 }
12467 altursize=0;
12468 QFile shxf(filename);
12469 if (shxf.open(QIODevice::ReadOnly|QIODevice::Text)){
12470 actionCut->setEnabled(false);
12471 actionCopy->setEnabled(false);
12472 QString s=shxf.readAll().replace('\0','~');
12473 QRegularExpression nonsp = QRegularExpression("[ \t]+\n");
12474 //printf("%d\n",__LINE__);
12475 s=s.replace(nonsp, " \n");// printf("remove non used spaces\n");
12476
12477 //printf("%d %d\n",__LINE__,s.size());
12478 editor->setPlainText(s);
12479 //printf("%d\n",__LINE__);
12480 actionSave->setEnabled(false);
12481 actionHFix->setDisabled(false);
12482 setWindowModified(editor->document()->isModified());
12483 editor->highlighter->setDocument(editor->document());
12484 //printf("%d\n",__LINE__);
12485 connectEdior();
12486 shxf.close();
12487 shxEditorDock->setWindowTitle(title);
12488 shxEditorDock->show();
12489 shxEditorDock->raise();
12490 actionSearch->setEnabled(true);
12491 actionNext->setEnabled(true);
12492 actionPrev->setEnabled(true);
12493 otherOpenFiles=true;
12494 editor->fv=fvar;
12495 QTextCursor c1=editor->textCursor();
12496 c1.movePosition(QTextCursor::End,QTextCursor::MoveAnchor);
12497 int maxPos=c1.position();
12498 c1.movePosition(QTextCursor::Start,QTextCursor::MoveAnchor);
12499 int pos1=0;
12500 einstellung->beginGroup("Cursor");
12501 if (einstellung->contains("lastCursorHash"))
12502 myHash=einstellung->value("lastCursorHash").toHash();
12503 //int uiui=0;
12504 QHash<QString,QVariant>::iterator i = myHash.begin();
12505 while ((i != myHash.end()) && (myHash.size()>20)) {
12506 i = myHash.erase(i);
12507 //printf("%d %d\n",i,myHash.size());
12508 }
12509 //qDebug()<<myHash;
12510 pos1=myHash.value(dirName).toInt();
12511 einstellung->endGroup();
12512 if ((myHash.contains(dirName))&&(pos1<=maxPos)&&(pos1>=0))
12513 c1.setPosition(pos1,QTextCursor::MoveAnchor);
12514 if (!c1.isNull()) editor->setTextCursor(c1);
12515 editor->centerCursor();
12516 if (focusSet) editor->setFocus(Qt::OtherFocusReason);
12517 if (!title.contains("!!Empty!!"))infoKanalNews(fvarinfo);
12518 }
12519 //printf("shx_edit\n");
12520 //printf("%d\n",__LINE__);
12521 if (title.contains("!!Empty!!")) infoKanalNews("<font size=+2 color=red>No atoms in file!</font>");
12522 }
12523
12524 bool Window::fileSave(bool spell, bool loadafter){
12525 if (spell) {
12526 spellCheck();
12527 }
12528 if (FehlerTeufel) {
12529 QMessageBox::warning(0,"Syntax-errors", "Syntax-errors were found in the file please correct them before saving! (Saving more frequently might reduce errors caused by this GUI)",QMessageBox::Ok,QMessageBox::Ok);
12530 return false;
12531 }
12532 QFile f(dirName);
12533
12534 if ((chgl->rotze!=-1)&&(chgl->rotze<mole.asymm.size())) {
12535 popel = mole.asymm.at(chgl->rotze).orginalLine.left(80).trimmed();
12536 //printf("rot center should stay %d\n", chgl->rotze);
12537 } else {
12538 popel = "";
12539 //printf("%d %d!\n", chgl->rotze, mole.asymm.size());
12540 chgl->rotze=-1;
12541 }
12542
12543 f.open(QIODevice::ReadOnly|QIODevice::Text);
12544 QString alterScheis=f.readAll();
12545 QFileInfo fi(f);
12546 f.close();
12547 QTextCursor c=editor->textCursor();
12548 if (!c.isNull()){
12549 myHash[dirName]=c.position();
12550 einstellung->beginGroup("Cursor");
12551 einstellung->setValue("lastCursorHash", myHash );
12552 einstellung->endGroup();
12553 }
12554 bool success = f.open(QIODevice::WriteOnly|QIODevice::Text);
12555 if (success){
12556 f.write(editor->toPlainText().toLatin1());
12557 f.close();
12558 QString dn=dirName.section('/',0,-2),
12559 argument=dirName.section('/',-1);
12560 QDir work=QDir(QString("%1/%2saves/").arg(dn).arg(PROGRAM_NAME));
12561 if (!work.exists ( QString("%1/%2saves/").arg(dn).arg(PROGRAM_NAME))) work.mkdir (QString("%1/%2saves/").arg(dn).arg(PROGRAM_NAME));
12562 QString saveHistName=QString("%1/%2saves/SAVEHIST").arg(dn).arg(PROGRAM_NAME);
12563 QFile sahi(saveHistName);
12564 sahi.open(QIODevice::Append|QIODevice::Text);
12565 sahi.write(QString("Entry|@|%1|@|%2|@|\n").arg(fi.lastModified().toString(Qt::ISODate)).arg(argument).toLatin1());
12566 sahi.write(alterScheis.toLatin1());
12567 sahi.close();
12568 editor->document()->setModified(false);
12569 if (loadafter) {
12570 loadFile(dirName);
12571 }
12572 }
12573 else
12574 infoKanalNews(QString("<font color=\"red\">%1 could not be opened for writing!</font>").arg(f.fileName()));
12575 return success;
12576 }
12577
12578 bool Window::fileSaveAs(){
12579 spellCheck();
12580 if (FehlerTeufel) {
12581 QMessageBox::warning(0,"Syntax-errors", "Syntax-errors were found in the file please correct them before saving! (Saving more frequently might reduce errors caused by this GUI)",QMessageBox::Ok,QMessageBox::Ok);
12582 return false;
12583 }
12584 QString fn=QFileDialog::getSaveFileName(this, tr("Save As ..."), dirName, tr("SHELX-files (*.res *.ins)"));
12585 if (fn.isEmpty()) return false;
12586 QFile f(fn);
12587 bool success = f.open(QIODevice::WriteOnly|QIODevice::Text);
12588 if (success){
12589 f.write(editor->toPlainText().toLatin1());
12590 f.close();
12591 editor->document()->setModified(false);
12592 loadFile(dirName=fn);
12593 }
12594 return success;
12595 }
12596
12597 void Window::fileSave4hklf5(){
12598 spellCheck();
12599 if (FehlerTeufel) {
12600 QMessageBox::warning(0,"Syntax-errors", "Syntax-errors were found in the file please correct them before saving! (Saving more frequently might reduce errors caused by this GUI)",QMessageBox::Ok,QMessageBox::Ok);
12601 return;
12602 }
12603 printf("fileSave4hklf5\n");
12604 makeItHKLF5();
12605 QAction *action = qobject_cast<QAction *>(sender());
12606 QString fn="";
12607 if (action)
12608 fn=action->data().toString();
12609 else return;
12610 if (fn.isEmpty()) return;
12611 QFile f(fn);
12612 bool success = f.open(QIODevice::WriteOnly|QIODevice::Text);
12613 if (success){
12614 f.write(editor->toPlainText().toLatin1());
12615 f.close();
12616 editor->document()->setModified(false);
12617 loadFile(dirName=fn);
12618 }
12619 }
12620
12621 void Window::unique(){
12622 if (mole.asymm.isEmpty()) return;
12623 mole.enviSDM(2.5);
12624 if (mole.maxmols()==0)sdm();
12625 QSet<int> molecules;
12626 QList<int> flags;
12627 for (int i=0; i<mole.asymm.size(); i++) if (molecules.contains(mole.asymm.at(i).molindex)){
12628 flags.append(-1);
12629 }else {
12630 molecules.insert(mole.asymm.at(i).molindex);
12631 flags.append(1);
12632 }
12633 int finished=1;
12634 do{
12635 finished=1;
12636 for (int i=0; i<mole.envi_sdm.size(); i++){
12637 if ((flags.at(mole.envi_sdm.at(i).a1)*flags.at(mole.envi_sdm.at(i).a2)==-1)&&
12638 ( mole.asymm.at(mole.envi_sdm.at(i).a1).molindex==mole.asymm.at(mole.envi_sdm.at(i).a2).molindex )) {
12639 if ((mole.asymm[mole.envi_sdm.at(i).a1].an<0)||(mole.asymm[mole.envi_sdm.at(i).a2].an<0))continue;
12640 if (flags.at(mole.envi_sdm.at(i).a1)==1)continue;
12641 if ((mole.envi_sdm.at(i).sn==0)&&(mole.envi_sdm.at(i).floorD==V3(0,0,0))) {
12642 flags[mole.envi_sdm.at(i).a1]=1;
12643 // flags[mole.envi_sdm.at(i).a2]=1;
12644 finished=0;
12645 break;
12646 }
12647 mole.asymm[mole.envi_sdm.at(i).a1].frac =
12648 mole.cell.symmops.at(mole.envi_sdm.at(i).sn) *
12649 mole.asymm[mole.envi_sdm.at(i).a1].frac +
12650 mole.cell.trans.at(mole.envi_sdm.at(i).sn) -
12651 mole.envi_sdm.at(i).floorD;
12652 flags[mole.envi_sdm.at(i).a1]=1;
12653 // flags[mole.envi_sdm.at(i).a2]=1;
12654 mole.frac2kart(mole.asymm[mole.envi_sdm.at(i).a1].frac, mole.asymm[mole.envi_sdm.at(i).a1].pos);
12655 finished=0;
12656
12657 mole.enviSDM(2.5);
12658 break;
12659 }
12660 }
12661 }while (!finished);
12662 mole.showatoms.clear();
12663 mole.showbonds.clear();
12664 chgl->mol->showatoms.clear();
12665 chgl->mol->showbonds.clear();
12666 chgl->mol->selectedatoms.clear();
12667 for (int o=0; o<mole.asymm.size();o++){
12668 mole.showatoms.append(mole.asymm[o]);
12669 }
12670 mole.sdmcompleter();
12671 mole.showbonds =
12672 mole.connecting(mole.showatoms);
12673 chgl->setMolecule(&mole);
12674 loadMolInTest();
12675
12676 chgl->mol->selectedatoms.clear();
12677
12678
12679 QTextDocument *document = editor->document();
12680 QTextCursor cursor = editor->textCursor();
12681 cursor.beginEditBlock ();
12682
12683 for (int i=0; i<mole.asymm.size();i++){
12684 cursor.movePosition(QTextCursor::Start);
12685 QString label=mole.asymm.at(i).orginalLine.left(80).trimmed();
12686 cursor = document->find(label ,cursor);
12687
12688 if (cursor.isNull()){
12689 cursor = editor->textCursor();
12690 cursor.movePosition(QTextCursor::Start);
12691 label.chop(10);
12692 cursor = document->find(label,cursor);
12693 if (cursor.isNull()) {
12694 cursor = editor->textCursor();
12695 }
12696 }
12697 QString vorherig,neues;
12698 cursor.movePosition(QTextCursor::StartOfLine,QTextCursor::MoveAnchor);
12699 cursor.movePosition(QTextCursor::EndOfLine,QTextCursor::KeepAnchor);
12700 while (cursor.selectedText().endsWith("=")) {
12701 cursor.movePosition(QTextCursor::Down,QTextCursor::KeepAnchor);
12702 cursor.movePosition(QTextCursor::EndOfLine,QTextCursor::KeepAnchor);
12703 }
12704 neues = vorherig= cursor.selectedText();
12705 QStringList sl = vorherig.split(leer);
12706 sl.removeOne("=");
12707 if (sl.size()>=7)
12708 neues=QString("%1 %2 %3 %4 %5 %6 %7 ")
12709 .arg(mole.asymm.at(i).Label.section('_',0,0),-4)
12710 .arg(qMax(1,editor->sfac.indexOf(mole.asymm.at(i).an)+1))
12711 .arg(mole.asymm.at(i).frac.x,10,'f',6)
12712 .arg(mole.asymm.at(i).frac.y,10,'f',6)
12713 .arg(mole.asymm.at(i).frac.z,10,'f',6)
12714 .arg(mole.asymm.at(i).sof_org,9,'f',5)
12715 .arg((mole.asymm.at(i).isIso)?mole.asymm.at(i).ufiso_org:QString("%1").arg(mole.asymm.at(i).uf.m11,9,'f',5));
12716 mole.asymm[i].orginalLine=neues;
12717 if (mole.asymm.at(i).an<0) {
12718 neues.append(QString("%1 ")
12719 .arg(mole.asymm.at(i).peakHeight,9,'f',2));
12720 } else
12721 if (!mole.asymm.at(i).isIso){
12722 neues.append(QString("%1 =\n %2 %3 %4 %5")
12723 .arg(mole.asymm.at(i).uf.m22,9,'f',5)
12724 .arg(mole.asymm.at(i).uf.m33,9,'f',5)
12725 .arg(mole.asymm.at(i).uf.m23,9,'f',5)
12726 .arg(mole.asymm.at(i).uf.m13,9,'f',5)
12727 .arg(mole.asymm.at(i).uf.m12,9,'f',5));
12728 }
12729 cursor.deleteChar();
12730 cursor.insertText(neues);
12731
12732 }//i
12733 cursor.endEditBlock ();
12734 molecules.clear();
12735 flags.clear();
12736 mole.envi_sdm.clear();
12737 bool growYes=chgl->fuse->isVisible ();
12738 chgl->mol->fuse();
12739 if (growYes) chgl->mol->grow();
12740
12741 loadMolInTest();
12742 // printf("%d\n",__LINE__);
12743
12744 }
12745
12746 void Window::editorIsVisible(bool vis){editor->uCanSeeMe=vis;}//isVisible is also true if widget is stacked behind an other
12747
12748 void Window::outputIsVisible(bool vis){xlPutor->uCanSeeMe=vis;}
12749
12750 void Window::hideToolz(bool b){
12751
12752 editToolBar->setVisible(!b);
12753 refineToolBar->setVisible(!b);
12754 bottomToolBar->setVisible(!b);
12755 fito->setVisible(!b);
12756 vito->setVisible(!b);
12757 update();
12758 }
12759
12760 void Window::updateLC(){
12761 QTextCursor tc = editor->textCursor();
12762 int l,c;
12763 l=tc.blockNumber()+1;
12764 c=tc.columnNumber()+1;
12765 lineColumn->setText(QString("Line: <b>%1</b> | Col: <b>%2</b>").arg(l,5).arg(c,5));
12766 editor->update();
12767 lineColumn->update();
12768 }
12769
12770 void Window::showEvent(QShowEvent *e){
12771 //printf("show?\n");
12772 if (QString(PROGRAM_NAME).compare("shelXle")){
12773 //printf("!Hide me now! %s\n%s\n%s\n",(isVisible())?"visible":"invisible",PROGRAM_NAME,"shelXle");
12774 e->accept();
12775 }
12776 }
12777
12778
12779 void Window::hideEvent(QHideEvent *){
12780 //printf("hide?\n");
12781 //printf("Hide me now! %s %s\n",(isVisible())?"visible":"invisible",PROGRAM_NAME);
12782 }
12783
12784 void Window::paintEvent(QPaintEvent * e){
12785 //static int ap=0;
12786 if (QString(PROGRAM_NAME).compare("shelXle")){
12787 //printf("may be no paint\n");
12788 setVisible(false);
12789 e->accept();
12790 hide();
12791 }
12792 /*if (chgl->stereo_mode==1){
12793 int p=geometry().y()+chgl->y();
12794 // chgl->minus=(p%2)?-1:1;
12795 chgl->minus=(p%2)?1:-1;
12796 if (p!=ap) chgl->update();
12797 ap=p;
12798 } // */
12799 //printf("paint\n");
12800 }
12801
12802
12803 void Window::closeSR(bool vis){
12804 //*
12805 if (vis) return;
12806 QDockWidget *splitDoc = findChild<QDockWidget*>("splitRotate");
12807 if (splitDoc != nullptr) {
12808 //printf("closeCR ?\n");
12809 mole.selectedatoms.clear();
12810 chgl->updateBondActions();
12811 chgl->changePivot1(-1);
12812 chgl->changePivot2(-1);
12813 chgl->pivot1cb->clear();
12814 chgl->pivot2cb->clear();
12815 //qDebug()<<splitDoc->children();
12816 QWidget *w = splitDoc->findChild<QWidget*>("splitRotateWidget");
12817 splitDoc->close();
12818 splitDoc->deleteLater();
12819 QObjectList ol=w->children();
12820 for (int i=0;i<ol.size();i++) {
12821 ol[i]->deleteLater();
12822 }
12823 //printf("now?\n");
12824 chgl->manualAx=nullptr;
12825 chgl->freeRot=nullptr;
12826 chgl->angle1=nullptr;
12827 chgl->angle2=nullptr;
12828 chgl->whyNotSplit->clear();
12829 chgl->whyNotSplit = nullptr;
12830 chgl->pivot2cb=nullptr;
12831 chgl->pivot1cb=nullptr;
12832 chgl->axx=nullptr;
12833 chgl->axy=nullptr;
12834 chgl->axz=nullptr;
12835 chgl->orgx=nullptr;
12836 chgl->orgy=nullptr;
12837 chgl->orgz=nullptr;
12838 //printf("closeCR !\n");
12839 }
12840 // */
12841
12842 }
12843
12844 void Window::splitRotate(){
12845 //*
12846 QDockWidget *splitDoc = findChild<QDockWidget*>("splitRotate");
12847 if (splitDoc == nullptr) {
12848 //if (chgl->canSplitRotate()) {chgl->updateBondActions(); chgl->splitRotate();}
12849 splitDoc = new QDockWidget("Split rotate molecule branch", this);
12850 QWidget *w = new QWidget(splitDoc);
12851 w->setObjectName("splitRotateWidget");
12852 splitDoc->setObjectName("splitRotate");
12853 splitDoc->setFeatures(QDockWidget::DockWidgetMovable|QDockWidget::DockWidgetFloatable|QDockWidget::DockWidgetClosable);
12854 QGridLayout *glo= new QGridLayout(w);
12855 chgl->whyNotSplit = new QLabel(w);
12856 chgl->angle1 = new QSpinBox(w);
12857 chgl->angle2 = new QSpinBox(w);
12858 chgl->angle1->setRange(0,360);
12859 chgl->angle2->setRange(0,360);
12860 chgl->angle1->setValue(30);
12861 chgl->angle2->setValue(0);
12862 chgl->angle1->setEnabled(chgl->canSplitRotate());
12863 chgl->angle2->setEnabled(chgl->canSplitRotate());
12864 QDial *ang1dial =new QDial(w);
12865 QDial *ang2dial =new QDial(w);
12866 ang1dial->setWrapping(true);
12867 ang2dial->setWrapping(true);
12868 ang1dial->setRange(0,360);
12869 ang2dial->setRange(0,360);
12870 ang1dial->setNotchesVisible(true);
12871 ang2dial->setNotchesVisible(true);
12872 ang1dial->setValue(30);
12873 ang2dial->setValue(0);
12874 ang1dial->setMinimumSize(110,110);
12875 ang2dial->setMinimumSize(110,110);
12876 ang1dial->setMaximumSize(110,110);
12877 ang2dial->setMaximumSize(110,110);
12878 ang1dial->setEnabled(chgl->canSplitRotate());
12879 ang2dial->setEnabled(chgl->canSplitRotate());
12880
12881 connect(ang1dial,SIGNAL(valueChanged(int)),chgl->angle1,SLOT(setValue(int)));
12882 connect(ang2dial,SIGNAL(valueChanged(int)),chgl->angle2,SLOT(setValue(int)));
12883
12884 connect(chgl->angle1,SIGNAL(valueChanged(int)),ang1dial,SLOT(setValue(int)));
12885 connect(chgl->angle2,SIGNAL(valueChanged(int)),ang2dial,SLOT(setValue(int)));
12886 connect(chgl,SIGNAL(splitable(bool)),chgl->angle1,SLOT(setEnabled(bool)));
12887 connect(chgl,SIGNAL(splitable(bool)),chgl->angle2,SLOT(setEnabled(bool)));
12888 connect(chgl,SIGNAL(splitable(bool)),ang1dial,SLOT(setEnabled(bool)));
12889 connect(chgl,SIGNAL(splitable(bool)),ang2dial,SLOT(setEnabled(bool)));
12890 connect(chgl,SIGNAL(splitable(bool)),this,SLOT(update()));
12891 connect(chgl->angle1,SIGNAL(valueChanged(int)),chgl,SLOT(splitRotate()));
12892 connect(chgl->angle2,SIGNAL(valueChanged(int)),chgl,SLOT(splitRotate()));
12893 connect(chgl,SIGNAL(splitable(bool)),chgl,SLOT(splitRotate()));
12894 chgl->pivot1cb = new QComboBox(w);
12895 chgl->pivot2cb = new QComboBox(w);
12896 for (int i=0; i<mole.asymm.size();i++){
12897 chgl->pivot1cb->insertItem(i,mole.asymm.at(i).Label);
12898 chgl->pivot2cb->insertItem(i,mole.asymm.at(i).Label);
12899 }
12900 connect(chgl,SIGNAL(pivot1Changed(int)),chgl->pivot1cb,SLOT(setCurrentIndex (int)));
12901 connect(chgl,SIGNAL(pivot2Changed(int)),chgl->pivot2cb,SLOT(setCurrentIndex (int)));
12902
12903 //connect(chgl,SIGNAL(splitable(bool)),pivot1,SLOT(setEnabled(bool)));
12904 //connect(chgl,SIGNAL(splitable(bool)),pivot2,SLOT(setEnabled(bool)));
12905 connect(chgl->pivot1cb,SIGNAL(currentIndexChanged(int)) ,chgl,SLOT(changePivot1(int)));
12906 connect(chgl->pivot2cb,SIGNAL(currentIndexChanged(int)) ,chgl,SLOT(changePivot2(int)));
12907
12908
12909 chgl->axx=new QDoubleSpinBox(w);
12910 chgl->axy=new QDoubleSpinBox(w);
12911 chgl->axz=new QDoubleSpinBox(w);
12912 chgl->orgx=new QDoubleSpinBox(w);
12913 chgl->orgy=new QDoubleSpinBox(w);
12914 chgl->orgz=new QDoubleSpinBox(w);
12915 chgl->manualAx= new QCheckBox("Rotate rotation axis [ALT]+[LeftMouse]",w);
12916 chgl->freeRot = new QCheckBox("Free move and rotate selected\natomes for part1\n[CTRL]+[ALT]+[LeftMouse] rotates and\n"
12917 "[CTRL]+[ALT]+[MiddleMouse] moves.",w);
12918
12919
12920 chgl->axx->setValue(1);
12921 chgl->axy->setValue(0);
12922 chgl->axz->setValue(0);
12923 chgl->axx->setRange(-1.0,1.0);
12924 chgl->axy->setRange(-1.0,1.0);
12925 chgl->axz->setRange(-1.0,1.0);
12926 chgl->axx->setSingleStep(0.01);
12927 chgl->axy->setSingleStep(0.01);
12928 chgl->axz->setSingleStep(0.01);
12929 chgl->axx->setDecimals(6);
12930 chgl->axy->setDecimals(6);
12931 chgl->axz->setDecimals(6);
12932 chgl->axx->setEnabled(false);
12933 chgl->axy->setEnabled(false);
12934 chgl->axz->setEnabled(false);
12935
12936
12937 chgl->orgx->setValue(0);
12938 chgl->orgy->setValue(0);
12939 chgl->orgz->setValue(0);
12940 chgl->orgx->setRange(-3*chgl->mol->cell.a,3*chgl->mol->cell.a);
12941 chgl->orgy->setRange(-3*chgl->mol->cell.b,3*chgl->mol->cell.b);
12942 chgl->orgz->setRange(-3*chgl->mol->cell.c,3*chgl->mol->cell.c);
12943 chgl->orgx->setSingleStep(0.01);
12944 chgl->orgy->setSingleStep(0.01);
12945 chgl->orgz->setSingleStep(0.01);
12946 chgl->orgx->setDecimals(6);
12947 chgl->orgy->setDecimals(6);
12948 chgl->orgz->setDecimals(6);
12949 chgl->orgx->setEnabled(false);
12950 chgl->orgy->setEnabled(false);
12951 chgl->orgz->setEnabled(false);
12952
12953
12954 sr_same = new QCheckBox("Use SAME restraint",w);
12955 sr_simu = new QCheckBox("Use SIMU restraint",w);
12956 sr_rigu = new QCheckBox("Use RIGU restraint",w);
12957 sr_alter_name = new QCheckBox("Alter names of 2nd part");//give alternataive name to 2nd part atoms
12958 sr_alter_name->setToolTip("This will add a ' to the atom names of the second part.");
12959 sr_ExyzAadp_ifclose = new QCheckBox("EXYZ and EADP for too close atoms"); // apply EXYZ and EADP if atoms are very close
12960
12961 sr_same->setChecked(true);
12962 sr_simu->setChecked(true);
12963 sr_rigu->setChecked(true);
12964 sr_alter_name->setChecked(false);
12965 sr_ExyzAadp_ifclose->setChecked(true);
12966
12967 connect(chgl->manualAx,SIGNAL(stateChanged(int)),chgl,SLOT(splitRotate()));
12968 connect(chgl->freeRot,SIGNAL(stateChanged(int)),chgl,SLOT(splitRotate()));
12969 connect(chgl->axx,SIGNAL(valueChanged(double)),chgl,SLOT(splitRotate()));
12970 connect(chgl->axy,SIGNAL(valueChanged(double)),chgl,SLOT(splitRotate()));
12971 connect(chgl->axz,SIGNAL(valueChanged(double)),chgl,SLOT(splitRotate()));
12972
12973 lpart= new QSpinBox(w);
12974 rpart= new QSpinBox(w);
12975 //printf("spinSelectPart->minimum()-2 = %d,spinSelectPart->maximum()+2 %d\n",spinSelectPart->minimum()-2,spinSelectPart->maximum()+2);
12976 lpart->setRange(spinSelectPart->minimum()-2,spinSelectPart->maximum()+2);
12977 rpart->setRange(spinSelectPart->minimum()-2,spinSelectPart->maximum()+2);
12978 lpart->setValue(spinSelectPart->maximum()+1);
12979 rpart->setValue(spinSelectPart->maximum()+2);
12980 QPushButton *split = new QPushButton("Split molecule now",w);
12981 connect(chgl, SIGNAL(splitable(bool)), split, SLOT(setEnabled(bool)));
12982 QPushButton *cancel=new QPushButton("Cancel",w);
12983 connect(cancel,SIGNAL(pressed ()),this,SLOT(notsplit()));
12984 connect(split,SIGNAL(pressed ()),this,SLOT(split()));
12985 glo->addWidget(chgl->whyNotSplit ,0,0,1,10,Qt::AlignBottom);
12986
12987 glo->addWidget(new QLabel("rotation angle of left branch",w) ,1,0,1,2,Qt::AlignRight|Qt::AlignBottom);
12988 glo->addWidget(new QLabel("rotation angle of right branch",w) ,1,2,1,2,Qt::AlignRight|Qt::AlignBottom);
12989
12990 glo->addWidget(chgl->angle1 ,2,0,1,1);
12991 glo->addWidget(ang1dial ,2,1,1,1);
12992 glo->addWidget(chgl->angle2 ,2,2,1,1);
12993 glo->addWidget(ang2dial ,2,3,1,1);
12994
12995 glo->addWidget(new QLabel("axis of rotation origin (pivot)",w),3,0,1,1);
12996 glo->addWidget(chgl->pivot1cb ,3,1,1,1);
12997 glo->addWidget(new QLabel("axis of rotation ",w) ,3,2,1,1);
12998 glo->addWidget(chgl->pivot2cb ,3,3,1,1);
12999
13000 glo->addWidget(chgl->manualAx, 4,0,1,1);
13001 glo->addWidget(chgl->axx, 4,1,1,1);
13002 glo->addWidget(chgl->axy, 4,2,1,1);
13003 glo->addWidget(chgl->axz, 4,3,1,1);
13004
13005 glo->addWidget(chgl->freeRot, 5,0,1,1);
13006 glo->addWidget(chgl->orgx, 5,1,1,1);
13007 glo->addWidget(chgl->orgy, 5,2,1,1);
13008 glo->addWidget(chgl->orgz, 5,3,1,1);
13009
13010 glo->addWidget(new QLabel("left PART",w), 7,0,1,1);
13011 glo->addWidget(lpart, 7,1,1,1);
13012 glo->addWidget(new QLabel("right PART",w), 7,2,1,1);
13013 glo->addWidget(rpart, 7,3,1,1);
13014
13015 glo->addWidget(sr_same, 8,0,1,1);
13016 glo->addWidget(sr_simu, 8,1,1,1);
13017 glo->addWidget(sr_rigu, 8,2,1,1);
13018 glo->addWidget(sr_alter_name, 9,0,1,1);
13019 glo->addWidget(sr_ExyzAadp_ifclose, 9,1,1,1);
13020
13021 glo->addWidget(cancel, 11,2,1,1);
13022 glo->addWidget(split, 11,3,1,1);
13023 //glo->addWidget(new QLabel("<h3>This feature is not final yet!!</h3> ",w),10,0,1,10);
13024 splitDoc->setWidget(w);
13025 if (!chgl->canSplitRotate()){
13026 chgl->whyNotSplit->setText("<h2>select some atoms (asymmetric unit only)</h2>");
13027 }
13028 if (!QString(PROGRAM_NAME).compare("shelXle")){
13029 tabifyDockWidget(shxEditorDock,splitDoc);
13030 //printf("%s %d\n",PROGRAM_NAME,QString(PROGRAM_NAME).compare("shelXle"));
13031 }
13032 else {
13033 splitDoc->setFloating(true);
13034 //printf("%s %d %d\n",PROGRAM_NAME,splitDoc->isFloating(),splitDoc->isVisible());
13035 }
13036 splitDoc->show();
13037 splitDoc->raise();
13038 connect(splitDoc,SIGNAL(visibilityChanged(bool)),this,SLOT(closeSR(bool)));
13039 if (chgl->canSplitRotate()) {chgl->updateBondActions(); chgl->splitRotate();}
13040 } else {
13041 chgl->pivot1cb->clear();
13042 chgl->pivot2cb->clear();
13043 for (int i=0; i<mole.asymm.size();i++){
13044 chgl->pivot1cb->insertItem(i,mole.asymm.at(i).Label);
13045 chgl->pivot2cb->insertItem(i,mole.asymm.at(i).Label);
13046 }
13047 splitDoc->show();
13048 splitDoc->raise();
13049 }
13050 //addDockWidget(dockWidgetArea(shxEditorDock),splitDoc);
13051 // */
13052 }
13053
13054
13055 void Window::split(){
13056 //printf("Spalter!\n");
13057 //*
13058 QDockWidget *splitDoc = findChild<QDockWidget*>("splitRotate");
13059
13060
13061 if (sr_alter_name->isChecked()){
13062 QStringList alab;
13063 QString alters("'\",#");
13064 for (int i = 0; i < mole.asymm.size(); i++){
13065 alab.append(mole.asymm.at(i).Label.section('_',0,0));
13066 }
13067 for (int i = 0; i<mole.splitRightAtoms.size(); i++){
13068 QString nlab = mole.splitRightAtoms.at(i).Label.section('_',0,0);
13069 if (nlab.size()>3) nlab=nlab.left(3);
13070 int j = 0;
13071 while (alab.contains(nlab+alters.at(j))) j++;
13072 mole.splitRightAtoms[i].Label = nlab+alters.at(j);
13073 }
13074 }
13075 QString constrain("");
13076 if (sr_ExyzAadp_ifclose->isChecked()){
13077 for (int i = 0; i < mole.splitLeftAtoms.size(); i++){
13078 for (int j = i; j < mole.splitRightAtoms.size(); j++){
13079 double d = Distance(mole.splitLeftAtoms.at(i).pos, mole.splitRightAtoms.at(j).pos);// this the squred length
13080 if (d<0.015) {
13081 if (sr_alter_name->isChecked())
13082 constrain.append(QString("%1 %2 ")
13083 .arg(mole.splitLeftAtoms.at(i).Label.section('_',0,0))
13084 .arg(mole.splitRightAtoms.at(j).Label.section('_',0,0)));
13085 else
13086 constrain.append(QString("%1^%3 %2^%4 ")
13087 .arg(mole.splitLeftAtoms.at(i).Label.section('_',0,0))
13088 .arg(mole.splitRightAtoms.at(j).Label.section('_',0,0))
13089 .arg(lpart->value()+9,0,36)//base36
13090 .arg(rpart->value()+9,0,36)//base36
13091 );
13092 }
13093 }
13094 }
13095 }
13096 QTextDocument *document = editor->document();
13097 QTextCursor cursor = editor->textCursor();
13098 cursor.beginEditBlock ();
13099 // !!!Neue Freie Variable anlegen!!!
13100 cursor.movePosition(QTextCursor::End);
13101 cursor = document->find(QRegularExpression("^FVAR"),cursor,QTextDocument::FindBackward);
13102 cursor.movePosition(QTextCursor::StartOfLine,QTextCursor::MoveAnchor);
13103 cursor.movePosition(QTextCursor::EndOfLine,QTextCursor::KeepAnchor);
13104 while (cursor.selectedText().endsWith("=")) {
13105 cursor.movePosition(QTextCursor::Down,QTextCursor::KeepAnchor);
13106 cursor.movePosition(QTextCursor::EndOfLine,QTextCursor::KeepAnchor);
13107 }
13108 QString fvstr = cursor.selectedText().trimmed();
13109 fvstr.append(" 0.666 ");
13110 fvar.append(0.667);
13111 cursor.deleteChar();
13112 cursor.insertText(fvstr);
13113 updateTieFreeVar();
13114 int fnj=fmax(fvar.size(),2);
13115 int hatafix=0;
13116 for (int i=0; i<mole.splitLeftAtoms.size(); i++){
13117 hatafix=fmax(hatafix,mole.splitLeftAtoms[i].afix);
13118 //the two parts should not differ on this featrure so it is enough to look for it in one branch
13119 }
13120 if (hatafix==0){// if there is a afix instrution then keep the order of atoms at it is.
13121 editor->sortAtoms( mole.splitLeftAtoms);
13122 editor->sortAtoms( mole.splitRightAtoms);
13123 }
13124 cursor.movePosition(QTextCursor::End);
13125 cursor = document->find(QRegularExpression("^HKLF"),cursor,QTextDocument::FindBackward);
13126 //cursor.movePosition(QTextCursor::Up,QTextCursor::KeepAnchor);
13127 //printf("LINE %d %d %d\n",__LINE__,mole.splitLeftAtoms.size(),mole.splitRightAtoms.size());
13128 cursor.movePosition(QTextCursor::StartOfLine,QTextCursor::KeepAnchor);
13129 cursor.clearSelection();
13130 QString stri;
13131 QString rigustr=QString("RIGU%1 ").arg((mole.splitLeftAtoms.first().resiNr!=0)?QString("_%1").arg(mole.splitLeftAtoms.first().resiNr):"");
13132 for (int i=0; i<mole.splitRightAtoms.size(); i++){
13133 rigustr.append(QString("%1 ").arg(mole.splitRightAtoms[i].Label.section('_',0,0)));
13134 }
13135 if (sr_alter_name->isChecked()) {
13136 for (int i=0; i<mole.splitLeftAtoms.size(); i++){
13137 rigustr.append(QString("%1 ").arg(mole.splitLeftAtoms[i].Label.section('_',0,0)));
13138 }
13139 }
13140 rigustr.append('\n');
13141 rigustr=DSRGui::textWrap(rigustr);
13142
13143
13144 QString simustr=QString("SIMU%1 0.01 0.08 0.25 ").arg((mole.splitLeftAtoms.first().resiNr!=0)?QString("_%1").arg(mole.splitLeftAtoms.first().resiNr):"");
13145 for (int i=0; i<mole.splitRightAtoms.size(); i++){
13146 simustr.append(QString("%1 ").arg(mole.splitRightAtoms[i].Label.section('_',0,0)));
13147 }
13148 if (sr_alter_name->isChecked()) {
13149 for (int i=0; i<mole.splitLeftAtoms.size(); i++){
13150 simustr.append(QString("%1 ").arg(mole.splitLeftAtoms[i].Label.section('_',0,0)));
13151 }
13152 }
13153 simustr.append('\n');
13154 simustr=DSRGui::textWrap(simustr);
13155 simustr.append("\n");
13156 rigustr.append("\n");
13157 QString equalstring("");
13158 if (!constrain.isEmpty()){
13159 equalstring.append(DSRGui::textWrap(QString("EXYZ %1").arg(constrain)));
13160 equalstring.append("\n");
13161 equalstring.append(DSRGui::textWrap(QString("EADP %1").arg(constrain)));
13162 equalstring.append("\n");
13163 }
13164 stri.append(QString("AFIX 0! Make sure that AFIX instructions before this line are closed.\n%3%1%2")
13165 .arg((sr_rigu->isChecked())?rigustr:"")
13166 .arg((sr_simu->isChecked())?simustr:"")
13167 .arg(equalstring));
13168 int aaf=0;
13169 if (mole.splitLeftAtoms.first().resiNr!=0)
13170 stri.append(QString("RESI %1 %2\n").arg(mole.splitLeftAtoms.first().resiNr).arg(mole.splitLeftAtoms.first().ResiClass));
13171 stri.append(QString("PART %1\n").arg(lpart->value()));
13172 //printf("LINE %d\n",__LINE__);
13173 for (int i=0; i<mole.splitLeftAtoms.size(); i++){
13174 //printf("i=%d\n",i);
13175 mole.splitLeftAtoms[i].isIso=true;
13176 double uEQ=mole.ueq(mole.splitLeftAtoms.at(i).uf);
13177 mole.splitLeftAtoms[i].uf.m11=
13178 mole.splitLeftAtoms[i].uf.m22=
13179 mole.splitLeftAtoms[i].uf.m33=
13180 mole.splitLeftAtoms[i].uc.m11=
13181 mole.splitLeftAtoms[i].uc.m22=
13182 mole.splitLeftAtoms[i].uc.m33=uEQ;
13183 mole.splitLeftAtoms[i].isIso=true;
13184 mole.splitLeftAtoms[i].uf.m12 = mole.splitLeftAtoms[i].uf.m21 = uEQ * mole.cell.cosrg;
13185 mole.splitLeftAtoms[i].uf.m13 = mole.splitLeftAtoms[i].uf.m31 = uEQ * mole.cell.cosrb;
13186 mole.splitLeftAtoms[i].uf.m23 = mole.splitLeftAtoms[i].uf.m32 = uEQ * mole.cell.cosra;
13187 mole.splitLeftAtoms[i].uc.m21=
13188 mole.splitLeftAtoms[i].uc.m12=
13189 mole.splitLeftAtoms[i].uc.m13=
13190 mole.splitLeftAtoms[i].uc.m31=
13191 mole.splitLeftAtoms[i].uc.m32=
13192 mole.splitLeftAtoms[i].uc.m23=0.0;
13193 mole.splitLeftAtoms[i].part=lpart->value();
13194 mole.kart2frac(mole.splitLeftAtoms.at(i).pos,mole.splitLeftAtoms[i].frac);
13195
13196 QString nsof=QString(" %1").arg(-1*(fabs(fmod(mole.splitLeftAtoms[i].sof_org,10))+(10*fnj)),7,'f',5);
13197 mole.splitLeftAtoms[i].orginalLine= QString("%5 %1 %2 %3 %4 %6 %7\n")
13198 .arg(editor->sfac.indexOf(mole.splitLeftAtoms[i].an)+1)
13199 .arg(mole.splitLeftAtoms[i].frac.x,10,'f',6)
13200 .arg(mole.splitLeftAtoms[i].frac.y,10,'f',6)
13201 .arg(mole.splitLeftAtoms[i].frac.z,10,'f',6)
13202 .arg(mole.splitLeftAtoms[i].Label.section('_',0,0),-5)
13203 .arg(nsof).arg(uEQ);
13204 stri.append(QString("%1%2").arg((aaf!=mole.splitLeftAtoms[i].afix)?QString("AFIX %1\n").arg(mole.splitLeftAtoms[i].afix):"")
13205 .arg(mole.splitLeftAtoms[i].orginalLine));
13206 aaf=mole.splitLeftAtoms[i].afix;
13207 mole.asymm.append(mole.splitLeftAtoms[i]);
13208 //printf("ok?\n");
13209 }
13210 if (aaf) stri.append("AFIX 0\n");
13211 aaf=0;
13212 QString same=QString("SAME%1 ").arg((mole.splitLeftAtoms.first().resiNr!=0)?QString("_%1").arg(mole.splitLeftAtoms.first().resiNr):"");
13213 for (int i=0; i<mole.splitLeftAtoms.size(); i++){
13214 same.append(QString("%1 ").arg(mole.splitLeftAtoms[i].Label.section('_',0,0)));
13215 }
13216 same.append('\n');
13217 if (sr_same->isChecked()) stri.append(DSRGui::textWrap(same));
13218
13219 stri.append(QString("PART %1\n").arg(rpart->value()));
13220 for (int i=0; i<mole.splitRightAtoms.size(); i++){
13221 mole.splitRightAtoms[i].isIso=true;
13222 double uEQ=mole.ueq(mole.splitRightAtoms.at(i).uf);
13223 mole.splitRightAtoms[i].uf.m11=
13224 mole.splitRightAtoms[i].uf.m22=
13225 mole.splitRightAtoms[i].uf.m33=
13226 mole.splitRightAtoms[i].uc.m11=
13227 mole.splitRightAtoms[i].uc.m22=
13228 mole.splitRightAtoms[i].uc.m33=uEQ;
13229 mole.splitRightAtoms[i].isIso=true;
13230 mole.splitRightAtoms[i].uf.m12 = mole.splitRightAtoms[i].uf.m21 = uEQ * mole.cell.cosrg;
13231 mole.splitRightAtoms[i].uf.m13 = mole.splitRightAtoms[i].uf.m31 = uEQ * mole.cell.cosrb;
13232 mole.splitRightAtoms[i].uf.m23 = mole.splitRightAtoms[i].uf.m32 = uEQ * mole.cell.cosra;
13233 mole.splitRightAtoms[i].uc.m21=
13234 mole.splitRightAtoms[i].uc.m12=
13235 mole.splitRightAtoms[i].uc.m13=
13236 mole.splitRightAtoms[i].uc.m31=
13237 mole.splitRightAtoms[i].uc.m32=
13238 mole.splitRightAtoms[i].uc.m23=0.0;
13239 mole.splitRightAtoms[i].part=rpart->value();
13240 QString nsof=QString(" %1").arg(1*(fabs(fmod(mole.splitRightAtoms[i].sof_org,10))+(10*fnj)),7,'f',5);
13241 mole.kart2frac(mole.splitRightAtoms.at(i).pos,mole.splitRightAtoms[i].frac);
13242 mole.splitRightAtoms[i].orginalLine= QString("%5 %1 %2 %3 %4 %6 %7\n")
13243 .arg(editor->sfac.indexOf(mole.splitRightAtoms[i].an)+1)
13244 .arg(mole.splitRightAtoms[i].frac.x,10,'f',6)
13245 .arg(mole.splitRightAtoms[i].frac.y,10,'f',6)
13246 .arg(mole.splitRightAtoms[i].frac.z,10,'f',6)
13247 .arg(mole.splitRightAtoms[i].Label.section('_',0,0),-5)
13248 .arg(nsof).arg(uEQ);
13249 stri.append(QString("%1%2").arg((aaf!=mole.splitRightAtoms[i].afix)?QString("AFIX %1").arg(mole.splitRightAtoms[i].afix):"")
13250 .arg(mole.splitRightAtoms[i].orginalLine));
13251
13252 aaf=mole.splitRightAtoms[i].afix;
13253
13254 //printf("%s !right\n",mole.splitRightAtoms[i].orginalLine.toStdString().c_str());
13255 mole.asymm.append(mole.splitRightAtoms[i]);
13256
13257 }
13258 if (aaf) stri.append("AFIX 0\n");
13259 //printf("!!\n%s!!",stri.toStdString().c_str());
13260 cursor.insertText(stri);
13261
13262 //printf("xx@\n");
13263 deleteSelectedAtoms();//remove existing full occupied atoms
13264 cursor.endEditBlock ();
13265 splitDoc->hide();// will deselect atoms
13266 shxEditorDock->raise();
13267 chgl->highlightParts->setVisible(true);
13268 chgl->highlightParts->setChecked(true);
13269 //*/
13270 }
13271
13272 void Window::notsplit(){
13273 //*
13274 QDockWidget *splitDoc = findChild<QDockWidget*>("splitRotate");
13275 splitDoc->hide();
13276 chgl->mol->selectedatoms.clear();
13277 chgl->updateBondActions();
13278 chgl->update();
13279 shxEditorDock->raise();
13280 // */
13281 }
13282
13283 void Window::styleDialog(){
13284 EacDlg *eac = new EacDlg(chgl->mol);
13285 double mi=mole.pmin;
13286 double ma=mole.pmax;
13287 eac->exec();
13288 mole.pmin=mi;
13289 mole.pmax=ma;
13290 chgl->shortLabels->setChecked(eac->areLabelsShort());
13291 lodsp->setValue(chgl->mol->LOD);
13292 chgl->myFont=eac->ogl->myFont;
13293 chgl->makeLabels();
13294 //chgl->setupTexture();
13295
13296 einstellung->beginGroup("Colors");
13297 chgl->backGroundColor=einstellung->value("BackGroundColor",QColor("lightskyblue")).value<QColor>();
13298 chgl->labelColor=einstellung->value("LabelColor").value<QColor>();
13299 chgl->labelBGColor = einstellung->value("LabelBGColor", QColor(0,0,0,0)).value<QColor>();
13300 chgl->focusedLabelBGColor = einstellung->value("focusedLabelBGColor", QColor(0,0,0,10)).value<QColor>();
13301 chgl->focusedLabelColor = einstellung->value("focusedLabelColor", QColor(255,255,0,255)).value<QColor>();
13302 chgl->selectedLabelBGColor = einstellung->value("selectedLabelBGColor", QColor(0,0,0,51)).value<QColor>();
13303 chgl->selectedLabelColor = einstellung->value("selectedLabelColor", QColor(135, 206, 235 ,255)).value<QColor>();
13304 einstellung->endGroup();
13305 mole.showbonds = mole.connecting(mole.showatoms);//das ist notwendig weil es in eac ebenfalls aufgerufen wird und dort lbonds ueberschreibt.
13306
13307 loadMolInTest();
13308 //chgl->setFocus(Qt::OtherFocusReason);
13309 chgl->show();
13310 chgl->raise();
13311 chgl->update();
13312 delete eac;
13313 }
13314
13315 void Window::effuenf(){
13316
13317 //chgl->setFocus(Qt::OtherFocusReason);
13318 chgl->show();
13319 chgl->raise();
13320 chgl->update();
13321 }
13322
13323 void Window::selectInStructure(const QString &info){
13324 chgl->mol->selectedatoms.clear();
13325 for (int i=0; i<chgl->mol->showatoms.size(); i++){
13326 if (chgl->mol->showatoms.at(i).orginalLine.size()<30) continue;
13327 if (info.contains(chgl->mol->showatoms.at(i).orginalLine,Qt::CaseInsensitive)){
13328 chgl->mol->selectedatoms.append(chgl->mol->showatoms[i]);
13329 chgl->mol->selectedatoms.last().style=i;
13330 }
13331 }
13332 chgl->updateBondActions();
13333 chgl->update();
13334 update();
13335 chgl->update();
13336 }
13337
13338 void Window::findInStructure(const QString &info){
13339 int index=-1;
13340 for (int i=0; i<chgl->mol->showatoms.size(); i++){
13341 if (chgl->mol->showatoms.at(i).orginalLine.contains(info,Qt::CaseInsensitive)) {index=i;break;}
13342 if (info.contains(chgl->mol->showatoms.at(i).orginalLine,Qt::CaseInsensitive)) {index=i;break;}
13343 }
13344 if (index!=-1){
13345 chgl->rotze=index;
13346 chgl->rCenter->show();
13347 chgl->mol->selectedatoms.clear();
13348 chgl->mol->selectedatoms.append(chgl->mol->showatoms[index]);
13349 chgl->mol->selectedatoms.last().style=index;
13350 chgl->updateBondActions();
13351 chgl->makeSelectedAtoms();
13352 chgl->update();
13353 update();
13354 chgl->update();
13355 }
13356 }
13357
13358 void Window::openIncludeFile(const QString &info){
13359 QString dn=dirName.section('/',0,-2);
13360 IncludeEditor *ie = new IncludeEditor(info,dn,this);
13361 ie->exec();
13362 }
13363
13364 void Window::jumpToAtom(int index){
13365 if ((chgl->inRenameMode)&&(enterRenameMode->isChecked())) {
13366 renameThisAtom(index);
13367 return;
13368 }
13369 if (chgl->inRenameMode) {
13370 printf("%d\n",__LINE__);
13371 renamUpdate(false);
13372 }
13373 QString label = mole.showatoms.at(index).orginalLine.left(80).trimmed();
13374 // qDebug()<<index<<mole.showatoms.at(index).Label<<label;
13375 QTextDocument *document = editor->document();
13376 QTextCursor cursor = editor->textCursor();
13377 cursor.movePosition(QTextCursor::Start);
13378 cursor = document->find(label,cursor);
13379 if (cursor.isNull()){
13380 cursor = editor->textCursor();
13381 cursor.movePosition(QTextCursor::Start);
13382 label.chop(10);
13383 cursor = document->find(label,cursor);
13384 if (cursor.isNull()) cursor = editor->textCursor();
13385 cursor.movePosition(QTextCursor::Start);
13386 label = mole.showatoms.at(index).orginalLine.left(80).simplified();
13387 cursor = document->find(label,cursor);
13388 if (cursor.isNull()) cursor = editor->textCursor();
13389 }
13390 cursor.movePosition(QTextCursor::StartOfLine);
13391 editor->setTextCursor(cursor);
13392 editor->doSetTextCursor(cursor,false);
13393 editor->centerCursor();
13394 cursor.clearSelection();
13395 editor->setTextCursor(cursor);
13396 editor->setFocus();
13397 //printf("W===========Jump 2 Atom!\n");
13398 if (chgl->toggleDockWidgets->isChecked()) return;
13399 shxEditorDock->show();
13400 }
13401
13402 void Window::rufmode(){
13403
13404 einstellung->beginGroup("Labeling");
13405 einstellung->setValue("AutoUnused",rufModeBox->isChecked());
13406 einstellung->endGroup();
13407 bool inuse=isLabelInUse();
13408 if ((inuse)&&(rufModeBox->isChecked())&&((labelIndex==-1)||(indexIncr->isChecked()))){
13409 if (sufixBox->currentIndex()<0) sufixBox->setCurrentIndex(0);
13410 while (isLabelInUse()){
13411 // qDebug()<<"zz"<<labelIndex;
13412 sufixBox->setCurrentIndex((sufixBox->count()>sufixBox->currentIndex()+1)?sufixBox->currentIndex()+1:sufixBox->currentIndex());
13413 updateLabel();
13414 }
13415 inuse=isLabelInUse();
13416 }else
13417 if ((rufModeBox->isChecked())){
13418 if (nowaste) labelIndex=1;
13419 while (isLabelInUse()) {
13420 labelIndex++;
13421 if (labelIndex>999) {
13422 labelIndex=00;
13423 sufixBox->setCurrentIndex((sufixBox->count()>sufixBox->currentIndex()+1)?sufixBox->currentIndex()+1:sufixBox->currentIndex());
13424 updateLabel();
13425 }
13426 }
13427 inuse=isLabelInUse();
13428 indexSpin->setValue(labelIndex);
13429 }
13430 updateLabel();
13431 }
13432
13433
13434 void Window::changeElemetofLabel(const QString &pse){
13435 labelPSE=pse;
13436 bool inuse=isLabelInUse();
13437 if ((inuse)&&(rufModeBox->isChecked())&&((labelIndex==-1)||(indexIncr->isChecked()))){
13438 if (sufixBox->currentIndex()<0) sufixBox->setCurrentIndex(0);
13439 while (isLabelInUse()){
13440 sufixBox->setCurrentIndex((sufixBox->count()>sufixBox->currentIndex()+1)?sufixBox->currentIndex()+1:sufixBox->currentIndex());
13441 updateLabel();
13442 }
13443 inuse=isLabelInUse();
13444 }else
13445 if ((rufModeBox->isChecked())){
13446 if (!nextLabel.contains("any"))labelIndex=1;
13447 while (isLabelInUse()) {
13448 labelIndex++;
13449 if (labelIndex>999) {
13450 labelIndex=00;
13451 sufixBox->setCurrentIndex((sufixBox->count()>sufixBox->currentIndex()+1)?sufixBox->currentIndex()+1:sufixBox->currentIndex());
13452 updateLabel();
13453 }
13454 }
13455 inuse=isLabelInUse();
13456 indexSpin->setValue(labelIndex);
13457 }
13458 if ((nextLabel.contains("any"))){
13459 QString altLabel="";
13460 for (int i=1; i<109; i++){
13461 if (pserbt[i]->isVisible()) {
13462 if (labelIndex<0) altLabel+=QString("%1%2").arg(pserbt[i]->text()).arg(labelSuffix);
13463 else altLabel+=QString("%1%2%3").arg(pserbt[i]->text()).arg(labelIndex).arg(labelSuffix);
13464 altLabel.append(", ");
13465 }
13466 }
13467 altLabel.remove(commaspace);
13468 int lakoma = altLabel.lastIndexOf(", ");
13469 if (lakoma>1) altLabel.replace(lakoma,2," or ");
13470 nextNameL->setText(QString("Next Label is:<br> <font size=\"+1\" color=\"%2\">%1</font>")
13471 .arg(altLabel)
13472 .arg("blue"));
13473 } else {
13474 nextNameL->setText(QString("Next Label is:<br> <font size=\"+1\" color=\"%2\">%1</font>%3")
13475 .arg(nextLabel)
13476 .arg((inuse)?"red":"green")
13477 .arg((inuse)?"<font size=\"-19\"><br>Label is already in use. You may change ResidueNr or Part.</font>":""));
13478 }
13479 update();
13480 }
13481
13482 void Window::changeIndexofLabel(int i){
13483 labelIndex=i;
13484 bool inuse=isLabelInUse();
13485 if ((inuse)&&(rufModeBox->isChecked())&&((labelIndex==-1)||(indexIncr->isChecked()))){
13486 if (sufixBox->currentIndex()<0) sufixBox->setCurrentIndex(0);
13487 while (isLabelInUse()){
13488 sufixBox->setCurrentIndex((sufixBox->count()>sufixBox->currentIndex()+1)?sufixBox->currentIndex()+1:sufixBox->currentIndex());
13489 updateLabel();
13490 }
13491 inuse=isLabelInUse();
13492 }else
13493 if ((rufModeBox->isChecked())){
13494 if (!nextLabel.contains("any"))labelIndex=1;
13495 while (isLabelInUse()) {
13496 labelIndex++;
13497 if (labelIndex>999) {
13498 labelIndex=00;
13499 sufixBox->setCurrentIndex((sufixBox->count()>sufixBox->currentIndex()+1)?sufixBox->currentIndex()+1:sufixBox->currentIndex());
13500 updateLabel();
13501 }
13502 }
13503 inuse=isLabelInUse();
13504 indexSpin->setValue(labelIndex);
13505 }
13506
13507
13508 if ((nextLabel.contains("any"))){
13509 QString altLabel="";
13510 for (int i=1; i<109; i++){
13511 if (pserbt[i]->isVisible()) {
13512 if (labelIndex<0) altLabel+=QString("%1%2").arg(pserbt[i]->text()).arg(labelSuffix);
13513 else altLabel+=QString("%1%2%3").arg(pserbt[i]->text()).arg(labelIndex).arg(labelSuffix);
13514 altLabel.append(", ");
13515 }
13516 }
13517 altLabel.remove(commaspace);
13518 int lakoma = altLabel.lastIndexOf(", ");
13519 if (lakoma>1) altLabel.replace(lakoma,2," or ");
13520 nextNameL->setText(QString("Next Label is:<br> <font size=\"+1\" color=\"%2\">%1</font>")
13521 .arg(altLabel)
13522 .arg("blue"));
13523 } else {
13524 nextNameL->setText(QString("Next Label is:<br> <font size=\"+1\" color=\"%2\">%1</font>%3")
13525 .arg(nextLabel)
13526 .arg((inuse)?"red":"green")
13527 .arg((inuse)?"<font size=\"-19\"><br>Label is already in use. You may change ResidueNr or Part.</font>":""));
13528 }
13529 update();
13530 }
13531
13532 void Window::changeSuffixofLabel(int i){
13533 QString fix = labelSuffix=sufixBox->itemText(i);
13534 bool inuse = isLabelInUse();
13535 if ((inuse)&&(rufModeBox->isChecked())&&((labelIndex==-1)||(indexIncr->isChecked()))){
13536 if (sufixBox->currentIndex()<0) sufixBox->setCurrentIndex(0);
13537 while (isLabelInUse()){
13538 sufixBox->setCurrentIndex((sufixBox->count()>sufixBox->currentIndex()+1)?sufixBox->currentIndex()+1:sufixBox->currentIndex());
13539 updateLabel();
13540 }
13541 inuse=isLabelInUse();
13542 }else if((inuse)&&(rufModeBox->isChecked())&&(labelIndex!=-1)){
13543 updateLabel();
13544 inuse=isLabelInUse();
13545 }
13546 if ((nextLabel.contains("any"))){
13547 QString altLabel="";
13548 for (int i=1; i<109; i++){
13549 if (pserbt[i]->isVisible()) {
13550 if (labelIndex<0) altLabel+=QString("%1%2").arg(pserbt[i]->text()).arg(labelSuffix);
13551 else altLabel+=QString("%1%2%3").arg(pserbt[i]->text()).arg(labelIndex).arg(labelSuffix);
13552 altLabel.append(", ");
13553 }
13554 }
13555 altLabel.remove(commaspace);
13556 int lakoma = altLabel.lastIndexOf(", ");
13557 if (lakoma>1) altLabel.replace(lakoma,2," or ");
13558 nextNameL->setText(QString("Next Label is:<br> <font size=\"+1\" color=\"%2\">%1</font>")
13559 .arg(altLabel)
13560 .arg("blue"));
13561 } else {
13562 nextNameL->setText(QString("Next Label is:<br> <font size=\"+1\" color=\"%2\">%1</font>%3")
13563 .arg(nextLabel)
13564 .arg((inuse)?"red":"green")
13565 .arg((inuse)?"<font size=\"-19\"><br>Label is already in use. You may change ResidueNr or Part.</font>":""));
13566 }
13567 update();
13568 }
13569
13570 void Window::updateLabel(){
13571 indexSpin->setValue(labelIndex);
13572 // if ((rufModeBox->isChecked())&&(!nextLabel.contains("any"))) labelIndex=1;
13573 bool inuse=isLabelInUse();
13574 if ((inuse)&&(rufModeBox->isChecked())){
13575 while (isLabelInUse()) {
13576 labelIndex++;
13577 if (labelIndex>999) {
13578 labelIndex=00;
13579 sufixBox->setCurrentIndex((sufixBox->count()>sufixBox->currentIndex()+1)?sufixBox->currentIndex()+1:sufixBox->currentIndex());
13580 updateLabel();
13581 }
13582 }
13583 inuse=isLabelInUse();
13584 indexSpin->setValue(labelIndex);
13585 }
13586 if ((nextLabel.contains("any"))){
13587 QString altLabel="";
13588 for (int i=1; i<109; i++){
13589 if (pserbt[i]->isVisible()) {
13590 if (labelIndex<0) altLabel+=QString("%1%2").arg(pserbt[i]->text()).arg(labelSuffix);
13591 else altLabel+=QString("%1%2%3").arg(pserbt[i]->text()).arg(labelIndex).arg(labelSuffix);
13592 altLabel.append(", ");
13593 }
13594 }
13595 altLabel.remove(commaspace);
13596 int lakoma = altLabel.lastIndexOf(", ");
13597 if (lakoma>1) altLabel.replace(lakoma,2," or ");
13598 nextNameL->setText(QString("Next Label is:<br> <font size=\"+1\" color=\"%2\">%1</font>")
13599 .arg(altLabel)
13600 .arg("blue"));
13601 } else {
13602 nextNameL->setText(QString("Next Label is:<br> <font size=\"+1\" color=\"%2\">%1</font>%3")
13603 .arg(nextLabel)
13604 .arg((inuse)?"red":"green")
13605 .arg((inuse)?"<font size=\"-19\"><br>Label is already in use. You may change ResidueNr or Part.</font>":""));
13606
13607 }
13608 //bool x=false;
13609
13610 for (int i=0; i<mole.asymm.size(); i++){
13611 if (mole.asymm.at(i).Label!=mole.showatoms.at(i).Label){
13612 //printf("!!%s %s\n",mole.asymm.at(i).Label.toStdString().c_str(),mole.showatoms.at(i).Label.toStdString().c_str());
13613 mole.showatoms[i].Label=mole.asymm.at(i).Label;
13614 // x=true;
13615 }
13616 }
13617 /* if (x){
13618 chgl->updateLabelTextures();
13619 //printf("update!!1elf\n");
13620 }*/
13621 update();
13622
13623
13624 }
13625
13626 int Window::duplicates(){
13627 int was=0;
13628 mole.duplicateAtoms.clear();
13629 if (search4duplicates->isChecked()){
13630 for (int i =0; i<mole.asymm.size(); i++){
13631 if (mole.asymm.at(i).an<0) continue;//Q peaks don't have to be uniq!
13632 for (int j =i+1; j<mole.asymm.size(); j++){
13633 if (mole.asymm.at(j).an<0) continue;//Q peaks don't have to be uniq!
13634 if ((mole.asymm.at(i).part==mole.asymm.at(j).part)&&
13635 (mole.asymm.at(i).resiNr==mole.asymm.at(j).resiNr)&&
13636 (mole.asymm.at(i).Label==mole.asymm.at(j).Label)){
13637 /* printf("i%d j %d p%d=%d rn%d=%d %s\n",i,j,
13638 mole.asymm.at(i).part,mole.asymm.at(j).part,
13639 mole.asymm.at(i).resiNr,mole.asymm.at(j).resiNr,
13640 mole.asymm.at(j).Label.toStdString().c_str());
13641 */ mole.duplicateAtoms.append(mole.asymm.at(i));
13642 mole.duplicateAtoms.last().part=666;
13643 mole.duplicateAtoms.last().style=i;
13644 mole.duplicateAtoms.append(mole.asymm.at(j));
13645 mole.duplicateAtoms.last().part=666;
13646 mole.duplicateAtoms.last().style=j;
13647 was|=(mole.asymm.at(i).an==0)?1:2;
13648
13649 }
13650 }
13651 }
13652 }
13653
13654 editor->highlighter->highlightDupl(mole.duplicateAtoms);
13655 chgl->makeSelectedAtoms();
13656 chgl->update();
13657 return was;
13658 }
13659
13660 bool Window::isLabelInUse(){
13661 QStringList alab;
13662 for (int i =0; i<mole.asymm.size(); i++){
13663 alab.append(mole.asymm.at(i).Label);
13664 }
13665 QString nn;
13666 //wenn rufMode dann labelIndex auf 1 setzen und hochzaehlen bis (alab.contains(nn,Qt::CaseInsensitive)) false
13667 // sollte (labelIndex<0) sein dann suffix auf A und hochzaehlen
13668 if (labelIndex<0) nextLabel=QString("%1%2").arg(labelPSE).arg(labelSuffix);
13669 else nextLabel=QString("%1%2%3").arg(labelPSE).arg(labelIndex).arg(labelSuffix);
13670 if (!nextLabel.startsWith("any")) nextLabel=nextLabel.left(4);
13671 if ((partSpin->value()!=0)||(resiNrSpin->value()!=0)){
13672 nn=QString("%1_%3%4")
13673 .arg(nextLabel)
13674 .arg((resiNrSpin->value())?QString::number(resiNrSpin->value()):"")
13675 .arg((partSpin->value())?QString::number((partSpin->value()<0)?
13676 36+partSpin->value():
13677 partSpin->value()+9,36):"");
13678
13679 }else
13680 nn=nextLabel;
13681 return (alab.contains(nn,Qt::CaseInsensitive));
13682 }
13683
13684 void Window::renameThisAtom(){
13685 //printf("renameThisAtom() (cast version)\n");
13686 QAction *action = qobject_cast<QAction *>(sender());
13687 int index=0;
13688 if (action)
13689 index=action->data().toInt();
13690 else return;
13691 if (index>mole.asymm.size()) return;
13692 if (mole.asymm.at(index).Label.contains(numbers)) {
13693 int p=mole.asymm.at(index).an;
13694 labelPSE=mole.pse(p);
13695
13696 labelIndex=mole.asymm.at(index).Label.section(nonumbers,0,0,QString::SectionSkipEmpty).toInt();
13697 labelSuffix=mole.asymm.at(index).Label.section(numbers,1,1);
13698 labelSuffix.remove(vorneweg);
13699 }
13700 else{
13701 int p=mole.asymm.at(index).an;
13702 labelPSE=mole.pse(p);
13703 labelIndex=-1;
13704 labelSuffix=mole.asymm.at(index).Label;
13705 labelSuffix.remove(0,labelPSE.size());
13706 labelSuffix.remove(vorneweg);
13707 }
13708
13709 partSpin->setValue(mole.asymm.at(index).part);
13710 resiNrSpin->setValue(mole.asymm.at(index).resiNr);
13711 resiResiClass->setText(mole.asymm.at(index).ResiClass);
13712 pserbt[mole.asymm.at(index).an+1]->setChecked(true);
13713
13714 printf("%d\n",__LINE__);
13715 renamUpdate(true);
13716 updateLabel();
13717
13718 }
13719
13720 void Window::rename2ThisAtom(int index){
13721 //printf("rename2ThisAtom\n");
13722 if (index>mole.asymm.size()) return;
13723 int p=mole.asymm.at(index).an;
13724 bool rmo= rufModeBox->isChecked(), iix=indexIncr->isChecked();
13725 rufModeBox->setChecked(false);
13726 sufixBox->setCurrentIndex(0);
13727 labelPSE=mole.pse(p);
13728 //sufixBox->setCurrentIndex(1);
13729 if (mole.asymm.at(index).Label.contains(numbers)) {
13730 labelIndex=mole.asymm.at(index).Label.section(nonumbers,0,0,QString::SectionSkipEmpty).toInt();
13731 labelSuffix=mole.asymm.at(index).Label.section(numbers,1,1);
13732 labelSuffix.remove(vorneweg);
13733 }
13734 else{
13735 labelIndex=-1;
13736 labelSuffix=mole.asymm.at(index).Label;
13737 labelSuffix.remove(0,labelPSE.size());
13738 labelSuffix.remove(vorneweg);
13739 }
13740 labelPSE="H";
13741 partSpin->setValue(mole.asymm.at(index).part);
13742 resiNrSpin->setValue(mole.asymm.at(index).resiNr);
13743 resiResiClass->setText(mole.asymm.at(index).ResiClass);
13744 pserbt[1]->setChecked(true);//H
13745 updateLabel();
13746 indexIncr->setChecked(true);
13747 rufModeBox->setChecked(true);
13748 printf("%d\n",__LINE__);
13749 renamUpdate(false);
13750 updateLabel();
13751 rufModeBox->setChecked(rmo);
13752 indexIncr->setChecked(iix);
13753 }
13754
13755
13756 void Window::renameRNchanged(int ii){
13757 QMap<int,QString> resNrClass;
13758 for (int i=0; i<editor->resiFinder->count(); i++){
13759 QString resil=editor->resiFinder->itemText(i).toUpper();
13760 resil.remove(QRegularExpression("^RESI"));//remove resi at the beginning resi could be also a (STUPID) resi class
13761 QString resinr=resil;
13762 resil.remove(QRegularExpression("\\b\\d+\\b"));//remove the number which separated (e.g. not like CCF3)
13763 resinr.remove(resil.trimmed());//the rest should be the number
13764 int rn=resinr.trimmed().toInt();
13765 resNrClass[rn]=resil.trimmed();
13766 }
13767
13768 if ((rufModeBox->isChecked())&&(!nextLabel.contains("any"))) labelIndex=1;
13769 if (!ii) {
13770 resiResiClass->setEnabled(false);
13771 resiResiClass->setText("");
13772 resiResiClassCB->setEnabled(false);
13773 }
13774 else {
13775 resiResiClassCB->setEnabled(!resNrClass.contains(ii));
13776 resiResiClass->setDisabled(resNrClass.contains(ii));
13777 resiResiClass->setText(resNrClass[ii]);
13778 }
13779 updateLabel();
13780
13781 }
13782
13783
13784 void Window::incResiNr(){
13785 int rnmax=-1;
13786 for (int i=0; i<editor->resiFinder->count(); i++){
13787 QString resil=editor->resiFinder->itemText(i).toUpper();
13788 resil.remove(QRegularExpression("^RESI"));//remove resi at the beginning resi could be also a (STUPID) resi class
13789 QString resinr=resil;
13790 resil.remove(QRegularExpression("\\b\\d+\\b"));//remove the number which separated (e.g. not like CCF3)
13791 resinr.remove(resil.trimmed());//the rest should be the number
13792 int rn=resinr.trimmed().toInt();
13793 rnmax=(rn>rnmax)?rn:rnmax;
13794 }
13795 int rnr = resiNrSpin->value()+1;
13796 rnr = (rnr>rnmax+1)?rnmax+1:rnr;
13797 resiNrSpin->setValue(rnr);
13798 updateLabel();
13799
13800 }
13801
13802 void Window::decResiNr(){
13803 int rnr = resiNrSpin->value()-1;
13804 rnr = (rnr<0)? 0: rnr;
13805 resiNrSpin->setValue(rnr);
13806 updateLabel();
13807
13808 }
13809
13810 void Window::redoRename(){
13811 if (gehtMichAn2.size()&&(0!=gehtMichAn2.takeLast())){//redoDeleteAtoms
13812 deletedAtom.clear();
13813 for (int i=0; i<restoredAtom.size();i++)deletedAtom.append(restoredAtom.at(i));
13814 for (int i=0; i<restoredAtom.size();i++){
13815 mole.asymm.removeAt(mole.asymm.indexOf(restoredAtom.at(i)));
13816 }
13817 restoredAtom.clear();
13818 chgl->disSelection();
13819 if (chgl->fuse->isVisible())chgl->mol->grow();
13820 else chgl->mol->fuse();
13821 loadMolInTest(true);
13822
13823 switch (duplicates()){
13824 case 1:infoKanalNews("<font color=orange >Some hydrogen atoms have identical names please check.</font>");break;
13825 case 2:infoKanalNews("<font color=red >Some non-hydrogen atoms have identical names. YOU HAVE TO CHECK BEFORE REFINING!</font>");break;
13826 case 3:infoKanalNews("<font color=red >Some atoms have identical names. YOU HAVE TO CHECK BEFORE REFINING!</font>");break;
13827 }
13828
13829 chgl->update();
13830 gehtMichAn.takeLast();
13831 return;
13832 }
13833 if (gehtMichAn.size()&&(0==gehtMichAn.takeLast()))return;
13834 MyAtom renamed;
13835 int renamindex;
13836 if (redoAtom.isEmpty()) return;
13837 renamindex = redoAtomIndex.takeLast();
13838 if (renamindex==-1){
13839 do {
13840 renamed = redoAtom.takeLast();
13841 undoAtom.append(renamed);
13842 mole.asymm.append(renamed);
13843 undoAtomIndex.append(renamindex);
13844 } while ((redoAtomIndex.size())&&(-1==(renamindex = redoAtomIndex.takeLast())));
13845 }else {
13846
13847 renamed = redoAtom.takeLast();
13848 undoAtom.append(mole.asymm[renamindex]);
13849 undoAtomIndex.append(renamindex);
13850
13851 mole.asymm[renamindex]=renamed;
13852 }
13853 updateLabel();
13854 chgl->disSelection();
13855 if (chgl->fuse->isVisible())chgl->mol->grow();
13856 else chgl->mol->fuse();
13857 loadMolInTest(true);
13858
13859 switch (duplicates()){
13860 case 1:infoKanalNews("<font color=orange >Some hydrogen atoms have identical names please check.</font>");break;
13861 case 2:infoKanalNews("<font color=red >Some non-hydrogen atoms have identical names. YOU HAVE TO CHECK BEFORE REFINING!</font>");break;
13862 case 3:infoKanalNews("<font color=red >Some atoms have identical names. YOU HAVE TO CHECK BEFORE REFINING!</font>");break;
13863 }
13864 chgl->update();
13865 }
13866
13867 void Window::wasDelete(){
13868 static int changeDel=0;
13869 if (changeDel!=(deletedAtom.size()+restoredAtom.size())) gehtMichAn2.append(1);
13870 else gehtMichAn2.append(0);
13871 changeDel=deletedAtom.size()+restoredAtom.size();
13872 }
13873
13874 void Window::wasRename(){
13875 if (altursize!=(redoAtom.size()+undoAtom.size()))gehtMichAn.append(1);
13876 else gehtMichAn.append(0);
13877 altursize=(redoAtom.size()+undoAtom.size());
13878 }
13879
13880 void Window::undoRename(){
13881 int angang=0;
13882 if (gehtMichAn2.size()&&(0!=(angang=gehtMichAn2.takeLast()))){//undoDeleteAtoms
13883 restoredAtom.clear();
13884 for (int i=0; i<deletedAtom.size();i++)restoredAtom.append(deletedAtom.at(i));
13885 for (int i=0; i<deletedAtom.size();i++){
13886 mole.asymm.append(deletedAtom.at(i));
13887 }
13888 deletedAtom.clear();
13889 chgl->disSelection();
13890 if (chgl->fuse->isVisible())chgl->mol->grow();
13891 else chgl->mol->fuse();
13892 loadMolInTest(true);
13893
13894 switch (duplicates()){
13895 case 1:infoKanalNews("<font color=orange >Some hydrogen atoms have identical names please check.</font>");break;
13896 case 2:infoKanalNews("<font color=red >Some non-hydrogen atoms have identical names. YOU HAVE TO CHECK BEFORE REFINING!</font>");break;
13897 case 3:infoKanalNews("<font color=red >Some atoms have identical names. YOU HAVE TO CHECK BEFORE REFINING!</font>");break;
13898 }
13899 chgl->update();
13900 gehtMichAn.takeLast();
13901 gehtMichAn2.append(1);
13902 return;
13903 }
13904 angang=0;
13905 if (gehtMichAn.size()&&(0==(angang=gehtMichAn.takeLast()))){
13906 return;
13907 }
13908 if (angang>1){
13909
13910 for (int i = 2; i<angang; i++ ){
13911 redoAtom.append(mole.asymm.takeLast());
13912 redoAtomIndex.append(-1);
13913
13914 }
13915
13916 updateLabel();
13917 chgl->disSelection();
13918 if (chgl->fuse->isVisible())chgl->mol->grow();
13919 else chgl->mol->fuse();
13920 loadMolInTest(true);
13921
13922 switch (duplicates()){
13923 case 1:infoKanalNews("<font color=orange >Some hydrogen atoms have identical names please check.</font>");break;
13924 case 2:infoKanalNews("<font color=red >Some non-hydrogen atoms have identical names. YOU HAVE TO CHECK BEFORE REFINING!</font>");break;
13925 case 3:infoKanalNews("<font color=red >Some atoms have identical names. YOU HAVE TO CHECK BEFORE REFINING!</font>");break;
13926 }
13927 chgl->update();
13928
13929 return;
13930 }
13931 MyAtom renamed;
13932 int renamindex;
13933 if (undoAtom.isEmpty()) return;
13934 renamed = undoAtom.takeLast();
13935 renamindex = undoAtomIndex.takeLast();
13936 if (renamindex<0)redoAtom.append(renamed);
13937 else redoAtom.append(mole.asymm[renamindex]);
13938 redoAtomIndex.append(renamindex);
13939
13940 mole.asymm[renamindex]=renamed;
13941 updateLabel();
13942 chgl->disSelection();
13943 if (chgl->fuse->isVisible())chgl->mol->grow();
13944 else chgl->mol->fuse();
13945 loadMolInTest(true);
13946
13947 switch (duplicates()){
13948 case 1:infoKanalNews("<font color=orange >Some hydrogen atoms have identical names please check.</font>");break;
13949 case 2:infoKanalNews("<font color=red >Some non-hydrogen atoms have identical names. YOU HAVE TO CHECK BEFORE REFINING!</font>");break;
13950 case 3:infoKanalNews("<font color=red >Some atoms have identical names. YOU HAVE TO CHECK BEFORE REFINING!</font>");break;
13951 }
13952 chgl->update();
13953 }
13954
13955
13956 void Window::renameThisAtom(int index){
13957 printf("renameThisAtom(index) \n");
13958 // QTime rzeit;
13959 // rzeit.start();
13960 // printf("renameThisAtom\n");
13961 if ((index<0)||index>=mole.asymm.size()){
13962 if ((index>=0)&&(mole.showatoms.at(index).Label.startsWith('Q'))){
13963 MyAtom ato(mole.showatoms.at(index));
13964 ato.Label=ato.Label.remove("'");
13965 ato.symmGroup=0;
13966 ato.sg=0;
13967 ato.scod=555;//the identity
13968 ato.auidx=index;
13969
13970 int nindex=mole.asymm.indexOf(ato);
13971 if (nindex!=-1 ){
13972 // mole.asymm.append(mole.asymm[nindex]);
13973 mole.asymm[nindex].frac=mole.showatoms.at(index).frac;
13974 mole.asymm[nindex].pos=mole.showatoms.at(index).pos;
13975 double uEQ=0.05;//mole.ueq(mole.asymm.at(i).uf);
13976 mole.asymm[nindex].uf.m11= mole.asymm[nindex].uc.m11= mole.asymm[nindex].uc.m22= mole.asymm[nindex].uc.m33=uEQ;
13977 mole.asymm[nindex].isIso=true;
13978 mole.asymm[nindex].uf.m33=uEQ;
13979 mole.asymm[nindex].uf.m12= mole.asymm[nindex].uf.m21= mole.asymm[nindex].uf.m13= mole.asymm[nindex].uf.m31=
13980 mole.asymm[nindex].uf.m23= mole.asymm[nindex].uf.m32= mole.asymm[nindex].uc.m21= mole.asymm[nindex].uc.m12=
13981 mole.asymm[nindex].uc.m13= mole.asymm[nindex].uc.m31= mole.asymm[nindex].uc.m32= mole.asymm[nindex].uc.m23=0.0;
13982 index=nindex;
13983 }else return;
13984 }
13985 else{
13986 QMessageBox::information(0,"information","The Atom you have clicked is not present in the file (yet) and can't be renamed by this program!<br>You can try 'move ... here' in the context menu of this atom. ");
13987 return;
13988 }
13989 }
13990
13991 // printf("PAUSE!\n");
13992 bool warnicht=false;
13993 static int previousHorse=-1;
13994 static int previousJokey=-1;
13995 CEnvironment respar;
13996 QString insertSuchString;
13997 for (int i=0; i<mole.asymm.size();i++){
13998 if (mole.asymm.at(i).resiNr!=resiNrSpin->value()) continue;
13999 if (mole.asymm.at(i).part!=partSpin->value()) continue;
14000 if (i!=index) respar.append(mole.asymm[i]);
14001 }
14002
14003 MyAtom testat=mole.asymm[index];
14004 testat.Label=nextLabel;
14005 testat.Label.replace("any",mole.pse((mole.asymm.at(index).an)<0?1:mole.asymm.at(index).an));
14006 testat.Label=testat.Label.left(4);
14007 testat.ResiClass = resiResiClass->text();
14008 testat.resiNr=resiNrSpin->value();
14009 testat.part=partSpin->value();
14010 // printf("testatom\n");
14011 testat.an=mole.getOZ(labelPSE);
14012 if (testat.an<0) {
14013 testat.an=5;
14014 }
14015 //respar.append(testat);
14016 // printf("AN: %d\n", testat.an);
14017 insertSuchString = editor->sortLabelList(respar,testat);
14018
14019 respar.clear();
14020
14021
14022 QString nlab = nextLabel ;
14023 //b= nlab.contains("any");
14024 //QString nsn = nlab.replace("any",mole.pse(mole.asymm.at(index).an));
14025 bool ridingH = false;
14026
14027 if (insertSuchString.startsWith('Q')) insertSuchString="HKLF";
14028 //printf("seek to: %s\n",insertSuchString.toStdString().c_str());
14029 if ((mole.getOZ(labelPSE)==0)&&(mole.asymm.at(index).an==-1)){
14030 int dahin2=-1;
14031 //double dd=0.0;
14032 for (int isd=0; isd<mole.sdm.size(); isd++){//sdm is sorted in that way that the smalest
14033 if (mole.sdm.at(isd).d>1.3) continue;
14034 if ((mole.sdm.at(isd).a1==index)&&(mole.asymm.at(mole.sdm.at(isd).a2).an>0)) {
14035 // dd=mole.sdm.at(isd).d;
14036 dahin2=mole.sdm.at(isd).a2;
14037 break;
14038 } //qDebug()<<isd<<'a'<<mole.asymm.at(mole.sdm.at(isd).a2).Label<<mole.sdm.at(isd).d;
14039 if ((mole.sdm.at(isd).a2==index)&&(mole.asymm.at(mole.sdm.at(isd).a1).an>0)) {
14040 // dd=mole.sdm.at(isd).d;
14041 dahin2=mole.sdm.at(isd).a1;
14042 break;
14043 } //qDebug()<<isd<<'b'<<mole.asymm.at(mole.sdm.at(isd).a1).Label<<mole.sdm.at(isd).d;
14044 }
14045 //qDebug()<<insertSuchString<<dahin2<<index<<dd<<mole.asymm.at(dahin2).orginalLine.left(80).trimmed();;a
14046 if (dahin2==-1)insertSuchString="HKLF";
14047 else{
14048 if (!enterRenameMode->isChecked()) {
14049 nowaste=false;
14050 rename2ThisAtom(dahin2);
14051 nowaste=true;
14052 }
14053 ridingH=true;
14054 //int orderer=0;
14055 if (previousHorse==dahin2){
14056 insertSuchString=mole.asymm.at(previousJokey).orginalLine.left(80).trimmed();
14057 //printf("second or later H here %d %d\n",previousJokey,dahin2);
14058 }else{
14059 insertSuchString=mole.asymm.at(dahin2).orginalLine.left(80).trimmed();
14060 }
14061 previousHorse=dahin2;
14062 previousJokey=index;
14063 // insertSuchString=mole.asymm.at(dahin2).orginalLine.left(80).trimmed();
14064 }
14065
14066 }
14067 //qDebug()<<"suche nach: "<<insertSuchString;
14068 QString label = mole.showatoms.at(index).orginalLine.left(80).trimmed();
14069 // printf("2 => %d ms\n", rzeit.elapsed()); rzeit.restart();
14070 QTextDocument *document = editor->document();
14071 QTextCursor cursor = editor->textCursor();
14072 cursor.beginEditBlock ();
14073 //insert missing afix 0 at end
14074 cursor.movePosition(QTextCursor::Start);
14075 cursor = document->find("HKLF",cursor);
14076 cursor.movePosition(QTextCursor::StartOfLine,QTextCursor::MoveAnchor);
14077 cursor.movePosition(QTextCursor::Up,QTextCursor::KeepAnchor);
14078 if (editor->parenthesis.at(cursor.blockNumber())){
14079 cursor.select(QTextCursor::WordUnderCursor);
14080 if ((cursor.selectedText().contains("RESI",Qt::CaseInsensitive))||(cursor.selectedText().contains("PART",Qt::CaseInsensitive)))
14081 cursor.movePosition(QTextCursor::Up,QTextCursor::KeepAnchor);
14082 cursor.select(QTextCursor::WordUnderCursor);
14083 if ((cursor.selectedText().contains("RESI",Qt::CaseInsensitive))||(cursor.selectedText().contains("PART",Qt::CaseInsensitive)))
14084 cursor.movePosition(QTextCursor::Up,QTextCursor::KeepAnchor);
14085 cursor.movePosition(QTextCursor::Down,QTextCursor::MoveAnchor);
14086 cursor.clearSelection();
14087 cursor.insertText("AFIX 0 ! chuebsch want to keep this here!!\nREM #####\n");
14088 editor->updateAfix();
14089 }
14090 //insert missing afix 0 at End!
14091
14092 cursor.movePosition(QTextCursor::Start);
14093 cursor = document->find(label,cursor);
14094 //printf("find{%s}\n",label.toStdString().c_str());
14095 if (cursor.isNull()){
14096 cursor = editor->textCursor();
14097 cursor.movePosition(QTextCursor::Start);
14098 label.chop(10);
14099 //printf("2find{%s}\n",label.toStdString().c_str());
14100 cursor = document->find(label,cursor);
14101 if (cursor.isNull()) {
14102 cursor = editor->textCursor();
14103 warnicht=true;
14104 printf("oje!\n");
14105 }
14106 }
14107 if (editor->parenthesis.at(cursor.blockNumber())){
14108 QMessageBox::information(0,"information",QString("ATOM %1 is in a AFIX construct and can't be renamed by this program!").arg(label.section(' ',0,0)));
14109 cursor.endEditBlock ();
14110 editor->setTextCursor(cursor);
14111 // printf("qpeakbug? %d\n",__LINE__);
14112
14113 // printf("%d\n",__LINE__);
14114 return;
14115 }
14116 if (warnicht) {
14117 QMessageBox::information(0,"information","The Atom you have clicked is not present in the file (yet) and can't be renamed by this program!");
14118 cursor.endEditBlock ();
14119 editor->setTextCursor(cursor);
14120
14121 // printf("%d\n",__LINE__);
14122 return;//hier muss eingefuegt werden: verhalten bei objecten die noch nicht in der datei stehen
14123 }
14124 QString vorherig,neues;
14125 cursor.movePosition(QTextCursor::StartOfLine,QTextCursor::MoveAnchor);
14126 cursor.movePosition(QTextCursor::EndOfLine,QTextCursor::KeepAnchor);
14127 QString otxt= cursor.selectedText();
14128 while (cursor.selectedText().endsWith("=")) {
14129 cursor.movePosition(QTextCursor::Down,QTextCursor::KeepAnchor);
14130 cursor.movePosition(QTextCursor::EndOfLine,QTextCursor::KeepAnchor);
14131 }
14132 while (editor->parenthesis.at(cursor.blockNumber()+1)){
14133 cursor.movePosition(QTextCursor::Down,QTextCursor::KeepAnchor);
14134 cursor.movePosition(QTextCursor::EndOfLine,QTextCursor::KeepAnchor);
14135 }
14136 neues = vorherig= cursor.selectedText();
14137 //qDebug()<<otxt<<neues;
14138 if (tieType->itemData(tieType->currentIndex()).toInt()){
14139 QString asof=neues.section(leer,5,5,QString::SectionSkipEmpty);
14140 asof.prepend(" ");
14141 int fnj=tieFVNr->value();
14142 QString nsof=(fnj!=1)?QString(" %1").arg(tieType->itemData(tieType->currentIndex()).toInt()*(fabs(fmod(mole.asymm.at(index).sof_org,10))+(10*fnj)),7,'f',5):
14143 QString(" %1").arg(fabs(fmod(mole.asymm.at(index).sof_org,10)*tieFix->value()+10),7,'f',5);
14144 ;
14145 // qDebug()<<asof<<nsof;
14146 neues.replace(asof,nsof);
14147 otxt.replace(asof,nsof);
14148 mole.asymm[index].sof_org=nsof.toDouble();
14149 }
14150 QString oldSfac=neues.section(leer,1,1,QString::SectionSkipEmpty);
14151 int ii=editor->sfacsmbl.indexOf(QRegularExpression(labelPSE,QRegularExpression::CaseInsensitiveOption));
14152 //printf("ii %d\n",ii);
14153 QString nl=QString("%1 ").arg(nextLabel,-4,' ');
14154 nl=nl.replace("any",mole.pse(editor->sfac.at(oldSfac.toInt()-1))).left(4);
14155 if (ii<0) {
14156 nl=nl.replace("any",mole.pse(editor->sfac.at(oldSfac.toInt()-1))).left(4);
14157 ii=oldSfac.toInt()-1;
14158 }
14159 else{
14160 neues.replace(QRegularExpression(QString("\\s%1\\s").arg(oldSfac)),QString(" %1 ").arg((ii+1)));
14161 otxt.replace(QRegularExpression(QString("\\s%1\\s").arg(oldSfac)),QString(" %1 ").arg((ii+1)));
14162 }
14163 nl=nl.left(4);
14164 neues.replace(0,4,nl);
14165 otxt.replace(0,4,nl);
14166 // printf("3 => %d ms\n", rzeit.elapsed()); rzeit.restart();
14167 undoAtom.append(mole.asymm[index]);
14168 undoAtomIndex.append(index);
14169 // printf("3' => %d ms\n", rzeit.elapsed()); rzeit.restart();
14170 QString ol=mole.asymm[index].Label.section('_',0,0);
14171 QString oldH=ol;
14172 oldH.replace(QRegularExpression(QString("^%1").arg(mole.pse(mole.asymm[index].an)),QRegularExpression::CaseInsensitiveOption),"H");
14173 mole.asymm[index].Label=nextLabel;
14174 mole.asymm[index].Label.replace("any",mole.pse(editor->sfac.at(oldSfac.toInt()-1)));
14175 mole.asymm[index].Label=mole.asymm[index].Label.left(4);
14176 if (mole.asymm[index].an<0) {
14177 otxt=neues=
14178 QString("%1 %2 %3 %4 %5 %6 %7 \n")
14179 .arg(mole.asymm[index].Label,-5)
14180 .arg(ii+1)
14181 .arg(mole.asymm.at(index).frac.x,9,'f',5)
14182 .arg(mole.asymm.at(index).frac.y,9,'f',5)
14183 .arg(mole.asymm.at(index).frac.z,9,'f',5)
14184 .arg(mole.asymm.at(index).sof_org,9,'f',5)
14185 .arg((ridingH)?"-1.5":"0.05");
14186 }
14187 mole.asymm[index].an=mole.getOZ(labelPSE);
14188 if (mole.asymm[index].an<0) {
14189 mole.asymm[index].an=editor->sfac.at(oldSfac.toInt()-1);
14190 }
14191 QString newH=mole.asymm[index].Label;
14192 newH.replace(QRegularExpression(QString("^%1").arg(mole.pse(mole.asymm.at(index).an)),QRegularExpression::CaseInsensitiveOption),"H");
14193 newH=newH.left(3);
14194 neues.replace(oldH,newH);
14195
14196 //printf("altes H='%s' neues H='%s' %s %s\n",oldH.toStdString().c_str(),newH.toStdString().c_str(),mole.asymm[index].Label.toStdString().c_str(),mole.pse(mole.asymm.at(index).an).toStdString().c_str());
14197 mole.asymm[index].orginalLine=otxt.left(80).section('=',0);
14198 // printf(":%s:\n",mole.asymm[index].orginalLine.toStdString().c_str());
14199 // qDebug()<<"aa"<<mole.asymm[index].orginalLine;
14200 mole.asymm[index].ResiClass = resiResiClass->text();
14201 mole.asymm[index].resiNr=resiNrSpin->value();
14202 mole.asymm[index].part=partSpin->value();
14203 cursor.deleteChar();
14204
14205 //cursor.deleteChar();//...this seems to cause errors but those emty lines are so ugly!
14206 //cursor.insertText(QString(" %1 has been renamed to %2. SHELXL ignores this line.").arg(ol).arg(mole.asymm[index].Label));
14207 QTextCursor wc = cursor;
14208 if ((partSpin->value()!=0)||(resiNrSpin->value()!=0)){
14209 mole.asymm[index].Label=QString("%1_%3%4")
14210 .arg(nextLabel)
14211 .arg((resiNrSpin->value())?QString::number(resiNrSpin->value()):"")
14212 .arg((partSpin->value())?QString::number((partSpin->value()<0)?
14213 36+partSpin->value():
14214 partSpin->value()+9,36):"");
14215 mole.asymm[index].Label.replace("any",mole.pse(editor->sfac.at(oldSfac.toInt()-1)));
14216
14217 }
14218 cursor = editor->textCursor();
14219 cursor.movePosition(QTextCursor::Start);
14220 editor->updateAfix();
14221 cursor = document->find(insertSuchString,cursor);
14222 if (cursor.isNull()){
14223 cursor = wc; //alte schreibposition setzen (wir haben atom nicht gefunden weil wir es gerade geloescht haben....
14224 cursor.movePosition(QTextCursor::Down);
14225 //printf("%s not found %d\n",insertSuchString.toStdString().c_str(),wc.position());
14226 }
14227 else if(insertSuchString!="HKLF"){
14228 cursor.movePosition(QTextCursor::StartOfLine,QTextCursor::MoveAnchor);
14229 cursor.movePosition(QTextCursor::EndOfLine,QTextCursor::KeepAnchor);
14230 while (cursor.selectedText().endsWith("=")) {
14231 cursor.movePosition(QTextCursor::Down,QTextCursor::KeepAnchor);
14232 cursor.movePosition(QTextCursor::EndOfLine,QTextCursor::KeepAnchor);
14233 }
14234 while (editor->parenthesis.at(cursor.blockNumber()+1)){
14235 cursor.movePosition(QTextCursor::Down,QTextCursor::KeepAnchor);
14236 cursor.movePosition(QTextCursor::EndOfLine,QTextCursor::KeepAnchor);
14237 }
14238 cursor.movePosition(QTextCursor::Down); //10.09.2020 do i need this really?=>yes
14239 //printf("%s found %d\n",insertSuchString.toStdString().c_str(),cursor.position());
14240 }
14241 cursor.clearSelection ();
14242 cursor.movePosition(QTextCursor::StartOfLine);
14243 if ((insertSuchString=="HKLF")&&(mole.asymm[index].resiNr)) cursor.insertText(QString("RESI %1 %2\n")
14244 .arg(mole.asymm[index].resiNr)
14245 .arg(mole.asymm[index].ResiClass));
14246 if ((insertSuchString=="HKLF")&&(mole.asymm[index].part)) cursor.insertText(QString("PART %1 \n")
14247 .arg(mole.asymm[index].part)
14248 // .arg((tieType->itemData(tieType->currentIndex()).toInt())?
14249 // QString::number((tieType->itemData(tieType->currentIndex()).toInt()*(10*tieFVNr->value()+1))):"")
14250 );
14251 cursor.insertText(neues);
14252 if (!neues.endsWith("\n")) cursor.insertText("\n");
14253 if ((insertSuchString=="HKLF")&&(mole.asymm[index].part)) cursor.insertText("PART 0\n");
14254 if ((insertSuchString=="HKLF")&&(mole.asymm[index].resiNr)) cursor.insertText("RESI 0\n");
14255 if ((tieType->itemData(tieType->currentIndex()).toInt())&&(mole.asymm[index].part)&&(fvar.size()<tieFVNr->value())){
14256 // !!!Neue Freie Variable anlegen!!!
14257 cursor.movePosition(QTextCursor::End);
14258 cursor = document->find("FVAR",cursor,QTextDocument::FindBackward);
14259 cursor.movePosition(QTextCursor::StartOfLine,QTextCursor::MoveAnchor);
14260 cursor.movePosition(QTextCursor::EndOfLine,QTextCursor::KeepAnchor);
14261 while (cursor.selectedText().endsWith("=")) {
14262 cursor.movePosition(QTextCursor::Down,QTextCursor::KeepAnchor);
14263 cursor.movePosition(QTextCursor::EndOfLine,QTextCursor::KeepAnchor);
14264 }
14265 QString fvstr = cursor.selectedText().trimmed();
14266 fvstr.append(" 0.666 ");
14267 fvar.append(0.667);
14268 cursor.deleteChar();
14269 fvstr = DSRGui::textWrap(fvstr, "\nFVAR ");
14270 cursor.insertText(fvstr);
14271 updateTieFreeVar();
14272 // !!!!
14273 }
14274 //qDebug()<<"redi";
14275 // printf("3! => %d ms\n", rzeit.elapsed()); rzeit.restart();
14276
14277
14278
14279 cursor.movePosition(QTextCursor::Start);
14280 int apo,po=cursor.position();
14281 apo=po;
14282 do {
14283 cursor.movePosition(QTextCursor::StartOfLine,QTextCursor::MoveAnchor);
14284 cursor.movePosition(QTextCursor::EndOfLine,QTextCursor::KeepAnchor);
14285 if (cursor.selectedText().isEmpty()) {
14286 cursor.deleteChar();
14287 }
14288 //cursor.deleteChar();
14289 cursor.setPosition(cursor.position(), QTextCursor::MoveAnchor);
14290 cursor.movePosition(QTextCursor::Down,QTextCursor::MoveAnchor);
14291 apo=po;
14292 po=cursor.position();
14293 }
14294 while (!cursor.isNull()&&(po!=apo));
14295
14296 // printf("3!a => %d ms\n", rzeit.elapsed()); rzeit.restart();
14297 cursor.endEditBlock ();
14298 // printf("3!b => %d ms\n", rzeit.elapsed()); rzeit.restart();
14299 if ((!indexIncr->isChecked())&&(labelIndex!=-1)) labelIndex++;
14300 else {
14301 if (sufixBox->currentIndex()<0) sufixBox->setCurrentIndex(0);
14302 sufixBox->setCurrentIndex((sufixBox->count()>sufixBox->currentIndex()+1)?sufixBox->currentIndex()+1:sufixBox->currentIndex());
14303 }
14304 updateLabel();
14305
14306 // printf("3!0 => %d ms\n", rzeit.elapsed()); rzeit.restart();
14307 chgl->disSelection();
14308 chgl->update();
14309 // printf("3!1 => %d ms\n", rzeit.elapsed()); rzeit.restart();
14310 // printf("Qpeak-Crash %d %d\n",__LINE__,mole.showatoms.size());
14311 if (chgl->fuse->isVisible())chgl->mol->grow();
14312 else chgl->mol->fuse();
14313 loadMolInTest(true);
14314 // printf("Qpeak-Crash %d %d\n",__LINE__,mole.showatoms.size());
14315
14316 // printf("3!2 => %d ms\n", rzeit.elapsed()); rzeit.restart();
14317 switch (duplicates()){
14318 case 1:infoKanalNews("<font color=orange >Some hydrogen atoms have identical names please check.</font>");break;
14319 case 2:infoKanalNews("<font color=red >Some non-hydrogen atoms have identical names. YOU HAVE TO CHECK BEFORE REFINING!</font>");break;
14320 case 3:infoKanalNews("<font color=red >Some atoms have identical names. YOU HAVE TO CHECK BEFORE REFINING!</font>");break;
14321 }
14322
14323 editor->setTextCursor(cursor);
14324 /*
14325 QFile dump("dkcrash.res");
14326 dump.open(QIODevice::WriteOnly|QIODevice::Text);
14327 dump.write( editor->toPlainText().toLatin1());
14328 dump.close();
14329 */
14330 //fileSave(false,true);
14331
14332 //chgl->setRotationCenter(index);
14333 // printf("4# => %d ms\n", rzeit.elapsed()); rzeit.restart();
14334
14335
14336
14337 //chgl->updateLabelTextures();
14338 // printf("%d\n",__LINE__);
14339
14340 // printf("NO PAUSE!\n");
14341 chgl->update();
14342 //printf("NO PAUSE!!\n");
14343 //sdm();
14344 // exportCoordinates();
14345 //printf("Qpeak-Crash %d \n",__LINE__);
14346 // printf("5 => %d ms\n", rzeit.elapsed()); rzeit.restart();
14347 }
14348
14349 void Window::changeResiPart(){
14350 if (chgl->mol->selectedatoms.isEmpty()) return;
14351
14352 CEnvironment todos = chgl->mol->selectedatoms;
14353 changeElemetofLabel("any");
14354 pserbt[0]->setChecked(true);
14355 int unusedpart=0;
14356 for (int i=0; i<mole.asymm.size();i++){
14357 unusedpart=qMax(mole.asymm.at(i).part,unusedpart);
14358 }
14359 unusedpart++;
14360 partSpin->setValue(unusedpart);
14361 tieType->setCurrentIndex(1);
14362 tieFVNr->setValue(fvar.size()+1);
14363 updateTieFreeVar();
14364 QDialog *groupReNaMo= new QDialog(this);
14365 groupReNaMo->setLayout(rnla);
14366 indexL->hide();
14367 indexSpin->hide();
14368 sufixL->hide();
14369 nextNameL->hide();
14370 sufixBox->hide();
14371 QString text=nliL->text();
14372 nliL->setText("Change RESI or PART of selected atoms.<br><> 0 value leaves current values unchaged.");
14373 rufModeBox->hide();
14374 indexIncr->hide();
14375 willpse->hide();
14376 qsa->hide();
14377 connect(buttonBoxRN, SIGNAL(accepted()), groupReNaMo, SLOT(accept()));
14378 connect(buttonBoxRN, SIGNAL(rejected()), groupReNaMo, SLOT(reject()));
14379 buttonBoxRN->show();
14380 int result=groupReNaMo->exec();
14381 renameBox->setLayout(rnla);
14382 nliL->setText(text);
14383 indexL->show();
14384 indexSpin->show();
14385 sufixL->show();
14386 sufixBox->show();
14387 nextNameL->show();
14388 rufModeBox->show();
14389 indexIncr->show();
14390 willpse->show();
14391 qsa->show();
14392 buttonBoxRN->hide();
14393 buttonBoxRN->disconnect();
14394 int rn= resiNrSpin->value();
14395 int pn= partSpin->value();
14396 if (result==QDialog::Accepted)
14397 for (int i=0; i<todos.size();i++){
14398 if (todos.at(i).symmGroup) continue;
14399 if (todos.at(i).Label.contains(QString::fromUtf8("»")))continue;
14400 if ((todos.at(i).an<0)) continue;
14401 if ((todos.at(i).afix>0)&&(todos.at(i).an==0)) continue;
14402
14403 int das=todos.at(i).style;
14404 // qDebug()<<"##==>>"<<i<<das<<todos.size()<<mole.asymm.at(das).Label;
14405
14406 labelIndex=mole.asymm.at(das).Label.section(nonumbers,0,0,QString::SectionSkipEmpty).toInt();
14407 labelSuffix=mole.asymm.at(das).Label.section(numbers,1,1);
14408 labelSuffix.remove(vorneweg);
14409 if (pn==0) partSpin->setValue(mole.asymm.at(das).part);
14410 if (rn==0){
14411 resiNrSpin->setValue(mole.asymm.at(das).resiNr);
14412 resiResiClass->setText(mole.asymm.at(das).ResiClass);
14413 }
14414 //printf("%d\n",__LINE__);
14415 renamUpdate(false);
14416 updateLabel();
14417 renameThisAtom(das);
14418 }
14419
14420 //printf("%d\n",__LINE__);
14421 chgl->update();
14422 }
14423
14424 bool Window::restraintsOrConstraints(){
14425 bool corr = (editor->toPlainText().contains("AFIX")) ;
14426 corr=(corr)||(editor->toPlainText().contains("BIND")) ;
14427 corr=(corr)||(editor->toPlainText().contains("CHIV")) ;
14428 corr=(corr)||(editor->toPlainText().contains("DANG")) ;
14429 corr=(corr)||(editor->toPlainText().contains("DFIX")) ;
14430 corr=(corr)||(editor->toPlainText().contains("EADP")) ;
14431 corr=(corr)||(editor->toPlainText().contains("EXYZ")) ;
14432 corr=(corr)||(editor->toPlainText().contains("FRAG")) ;
14433 corr=(corr)||(editor->toPlainText().contains("FEND")) ;
14434 corr=(corr)||(editor->toPlainText().contains("FREE")) ;
14435 corr=(corr)||(editor->toPlainText().contains("HFIX")) ;
14436 corr=(corr)||(editor->toPlainText().contains("MPLA")) ;
14437 corr=(corr)||(editor->toPlainText().contains("SADI")) ;
14438 corr=(corr)||(editor->toPlainText().contains("SAME")) ;
14439 corr=(corr)||(editor->toPlainText().contains("FLAT")) ;
14440 if (corr){
14441 QTextCursor cursor = editor->textCursor();
14442 cursor.setPosition(0);
14443 editor->setTextCursor(cursor);
14444 editor->searchLE->setText("(AFIX)|(BIND)|(CHIV)|(DANG)|(DFIX)|(EADP)|(EXYZ)|(FRAG)|(FEND)|(FREE)|(FLAT)|(HFIX)|(MPLA)|(SADI)|(SAME)");
14445 editor->wholeLine->setChecked(true);
14446 editor->findNext();
14447 editor->showSearch();
14448 }
14449 return corr;
14450 }
14451
14452 void Window::aula(){//!< Auto Labeling
14453
14454 if (mole.asymm.isEmpty())return;
14455 bool hasafix = (editor->toPlainText().contains("AFIX")) ;
14456 bool hasrest = restraintsOrConstraints();
14457 bool hash=false;
14458 bool useResis;
14459 for (int i=0;i<mole.asymm.size();i++){if (mole.asymm.at(i).an==0) {hash=true; break;}}
14460 QPushButton *okmitresi=nullptr,*okohneresi=nullptr;
14461 QMessageBox mb(QMessageBox::NoIcon,
14462 "Automatic Labeling",
14463 QString(
14464 "<img src=\""+theIconPath+"aula.svg\"><p><h3>AuLa <u>Au</u>tomatic <u>La</u>beling</h3> It will probably never give you satisfying results, but hopefully consitent ones."
14465 "<p>Please use this feature before adding Hydrogen atoms and %3restraints or constraints%4."
14466 "<p>%1 It will complain about any atom that is in a AFIX environment.%2"
14467 "<p>When finished it will sort and save the file automatically. Please be a little patient."
14468 "<p>First it searches for rings in each molecule or fragment. Rings may consist only of nonmetals. "
14469 "In each molecule it starts numbering in the ring that if most distant away from the molecules center of mass."
14470 "If possible, it annulate other rings to the first one. It then adds side chains and the side chains of these until no atoms are left in the molecule."
14471 "When there are no rings in the molecule it starts at the end of the chain that is most distant from molecules center of mass. "
14472 "Center of mass here means just the geometrical average position. %5")
14473 .arg((hasafix)?"<font color=red><b>":"")
14474 .arg((hasafix)?"</b></font>":"")
14475 .arg((hasrest)?"<font color=red><b>":"")
14476 .arg((hasrest)?"</b></font>":"")
14477 .arg((hasrest)?"<p><h3><font color=red> Please remove all Hydrogen atoms and constraints/restraints first and come back here later.</font></h3> "
14478 "You should not have any of these instructions in your file:<br> <b>AFIX BIND CHIV DANG DFIX EADP EXYZ FLAT FRAG FEND FREE HFIX MPLA SADI SAME</b> "
14479 :"<p><h3>Click on one of the AutoLabel buttons below to run the auto labeling procedure now. </h3>")
14480 ,
14481 (QMessageBox::Cancel ));
14482 if (hash){
14483 QPushButton *killh = mb.addButton("remove Hydrogen atoms now",QMessageBox::ActionRole);
14484 connect(killh,SIGNAL(clicked()),this,SLOT(deleteAllH()));
14485 }
14486 if (!hasrest){
14487 okmitresi = mb.addButton("AutoLabel with RESIdues",QMessageBox::AcceptRole);
14488 okohneresi= mb.addButton("AutoLabel without RESIdues",QMessageBox::AcceptRole);
14489 }
14490 mb.exec();
14491 bool ok=false;
14492 if (mb.clickedButton()==nullptr)return;
14493 if (mb.clickedButton()==okmitresi){useResis=true;ok=true;}
14494 if (mb.clickedButton()==okohneresi){useResis=false;ok=true;}
14495 if (!ok)return;
14496 sdm();
14497 AulaWorker *owl = new AulaWorker(this, useResis);
14498 connect(owl, SIGNAL(finished()), this, SLOT(sdm()));
14499 connect(owl, SIGNAL(finished()), owl, SLOT(finalize()));
14500 //connect(owl, SIGNAL(finished()), chgl, SLOT(updateLabelTextures()));
14501 connect(owl, SIGNAL(finished()), chgl, SLOT(update()));
14502 connect(owl, SIGNAL(message(const QString&)), this, SLOT(updateStatusBar(const QString&)));
14503 connect(owl, SIGNAL(message(const QString&)), this, SLOT(update()));
14504 connect(owl, SIGNAL(finished()), owl, SLOT(deleteLater()));
14505 QWhatsThis::showText(QPoint(pos().x() + width()/2,pos().y() + height()/2),"<H1>Auto Labeling in process please be patient!<br> You can follow progress below in the status bar.</H1>",this);
14506 maybeSave2();
14507 sdm();
14508 owl->start();
14509 }
14510
14511 void AulaWorker::aula(){
14512
14513 /*
14514 printf("TEST\n========Au=La=====================================================================\n");
14515 printf(
14516 " .-\"-~-\"-.\n"
14517 " /.-\"-.-\"-.\\\n"
14518 " ||((o|o))||\n"
14519 " )\\__/V\\__/(\n"
14520 " / ~ -...- ~ \\\n"
14521 " |\\` ~. ~ .~ `/|\n"
14522 " | `~ - ^ - ~` |\n"
14523 " | ; ' : . |\n"
14524 " \\ . : ' ; '/\n"
14525 " '. ; ' .'\n"
14526 " `uu---uu`\n");*/
14527 //printf("AuLa take %d ms. %d\n", rzeit.elapsed(),__LINE__); // rzeit.restart();
14528 inventNewLabels(chain);
14529 //printf("AuLa take %d ms. %d\n", rzeit.elapsed(),__LINE__); // rzeit.restart();
14530 possible=0;
14531 for (int i=0; i<_w->mole.asymm.size(); i++) if (_w->mole.asymm.at(i).an>=0) possible++;
14532 QFile res(_w->dirName);
14533 res.open(QIODevice::ReadOnly|QIODevice::Text);
14534 all = QString(res.readAll());
14535 res.close();
14536 //printf("AuLa take %d ms. %d\n", rzeit.elapsed(),__LINE__); // rzeit.restart();
14537 QStringList newlabels;
14538 int partmin=0;
14539 int partmax=0;
14540 for (int i=0; i<chain.size(); i++){
14541 int das = chain.at(i);
14542 partmin = qMin(partmin, _w->mole.asymm.at(das).part);
14543 partmax = qMax(partmax, _w->mole.asymm.at(das).part);
14544 QString old = _w->mole.asymm.at(das).Label;
14545 int j=1;
14546 int rn=(useResis)?_w->mole.asymm.at(das).molindex:0;
14547 QString nl=QString("%1%2_%3").arg(_w->mole.pse(_w->mole.asymm.at(das).an)).arg(j).arg(rn);
14548 while (newlabels.contains(nl)) nl=QString("%1%2_%3").arg(_w->mole.pse(_w->mole.asymm.at(das).an)).arg(++j).arg(rn);
14549 newlabels.append(nl);
14550 if (useResis){
14551 _w->mole.asymm[das].resiNr = rn;
14552 _w->mole.asymm[das].ResiClass = QString("M%1").arg(rn);
14553 }
14554 _w->mole.asymm[das].Label = nl.section('_',0,0);
14555 /*printf("%d#%d %s=>%s/%s j=%d an=%d PSE%s\n",i,
14556 das,
14557 old.toStdString().c_str(),
14558 nl.section('_',0,0).toStdString().c_str(),
14559 _w->mole.asymm.at(das).Label.toStdString().c_str(),
14560 j , _w->mole.asymm.at(das).an,
14561 _w->mole.asymm.at(das).orginalLine.toStdString().c_str()
14562 );*/
14563 }
14564 newlabels.clear();
14565 emit message("New labels created.");
14566 //printf("AuLa take %d ms. %d\n", rzeit.elapsed(),__LINE__); // rzeit.restart();
14567 int firstatom = all.indexOf(_w->mole.asymm.at(0).orginalLine);
14568 int firstpart = all.indexOf("\nPART",0,Qt::CaseInsensitive);
14569 int firstresi = all.indexOf("\nRESI",0,Qt::CaseInsensitive);
14570 int vonhier = firstatom;
14571 if (firstpart>-1) vonhier = qMin(vonhier,firstpart);
14572 if (firstresi>-1) vonhier = qMin(vonhier,firstresi);
14573
14574 int bisda =all.lastIndexOf("\nHKLF");
14575 //printf("%d ---- >%d\n", vonhier, bisda);
14576 //printf("AuLa take %d ms. %d\n", rzeit.elapsed(),__LINE__); // rzeit.restart();
14577 _w->editor->sortAtoms(_w->mole.asymm);
14578 //printf("AuLa take %d ms. %d\n", rzeit.elapsed(),__LINE__); // rzeit.restart();
14579 QString insert = "\n";
14580 int pr=0,pp=0;
14581 for (int i=0; i<_w->mole.asymm.size(); i++){
14582 int das = i;
14583 int _sfacnr = 1 + _w->editor->sfac.indexOf(_w->mole.asymm.at(das).an);
14584 if ((useResis)&&(pr!=_w->mole.asymm.at(das).molindex)) {
14585 insert+=QString("RESI %1 M%2\n").arg(_w->mole.asymm.at(das).molindex).arg(_w->mole.asymm.at(das).molindex);
14586 pr=_w->mole.asymm.at(das).molindex;
14587 }
14588 if (((partmin<0)||(partmax>0))&&(pp!=_w->mole.asymm.at(das).part)) {
14589 insert+=QString("PART %1\n").arg(_w->mole.asymm.at(das).part);
14590 pp=_w->mole.asymm.at(das).part;
14591 }
14592 if (_w->mole.asymm.at(das).isIso)
14593 insert+=QString("%1 %2 %3 %4 %5 %6 %7\n")
14594 .arg(_w->mole.asymm.at(das).Label,-4)
14595 .arg(_sfacnr)
14596 .arg(_w->mole.asymm.at(das).frac.x,10,'f',5)
14597 .arg(_w->mole.asymm.at(das).frac.y,10,'f',5)
14598 .arg(_w->mole.asymm.at(das).frac.z,10,'f',5)
14599 .arg(_w->mole.asymm.at(das).sof_org,10,'f',5)
14600 .arg(_w->mole.asymm.at(das).ufiso_org)
14601 ;
14602 else
14603 // 0.01902 0.00464 0.01485 -0.00203
14604 insert+=QString("%1 %2 %3 %4 %5 %6 %7 %8 =\n %9 %10 %11 %12\n")
14605 .arg(_w->mole.asymm.at(das).Label,-4)
14606 .arg(_sfacnr)
14607 .arg(_w->mole.asymm.at(das).frac.x,10,'f',5)
14608 .arg(_w->mole.asymm.at(das).frac.y,10,'f',5)
14609 .arg(_w->mole.asymm.at(das).frac.z,10,'f',5)
14610 .arg(_w->mole.asymm.at(das).sof_org,10,'f',5)
14611 .arg(_w->mole.asymm.at(das).uf.m11,10,'f',5)
14612 .arg(_w->mole.asymm.at(das).uf.m22,10,'f',5)
14613 .arg(_w->mole.asymm.at(das).uf.m33,10,'f',5)
14614 .arg(_w->mole.asymm.at(das).uf.m32,10,'f',5)
14615 .arg(_w->mole.asymm.at(das).uf.m31,10,'f',5)
14616 .arg(_w->mole.asymm.at(das).uf.m21,10,'f',5)
14617 ;
14618
14619 }
14620 all.replace(vonhier,bisda-vonhier,insert);
14621 emit message("...old labeld atoms replaced with new ones...");
14622 //printf("AuLa take %d ms. %d\n", rzeit.elapsed(),__LINE__); // rzeit.restart();
14623 //printf("%d %d %d\n",vonhier,bisda-vonhier,bisda);
14624 //printf("%s\n==================\n%s\n",insert.toStdString().c_str(),all.toStdString().c_str());
14625
14626 }
14627
14628 void AulaWorker::extendChain(QList<Ring> &rings,QList<int> &currentChain, QList<QList<int> > &neighbors,QSet<int> &nogo){
14629 int last=currentChain.last();
14630 for (int ri=0; ri<rings.size();ri++){
14631 if (rings.at(ri).done) continue;
14632 if (rings[ri].members.contains(last)){
14633 int bbv=currentChain.size();
14634 int strt=rings[ri].members.indexOf(last);
14635 for (int rri=0,rrj=0; rri<rings[ri].members.size(); rri++){
14636 rrj=(strt>=0)?(strt+rri)%rings[ri].members.size():rri;
14637 if (!currentChain.contains(rings[ri].members.at(rrj))) currentChain.append(rings[ri].members.at(rrj));
14638 }
14639 bbv-=currentChain.size();
14640 if (bbv) {
14641 rings[ri].done=true;
14642 }
14643 }
14644 }
14645 if (neighbors.at(last).size()==1) return;
14646 QList<int> c;
14647 int ic=-1;
14648 int manb=0;
14649 for (int i=0; i<neighbors.at(last).size(); i++){
14650 if (currentChain.contains(neighbors.at(last).at(i))) continue;
14651 if (nogo.contains(neighbors.at(last).at(i))) continue;
14652 int z=neighbors.at(neighbors.at(last).at(i)).size();
14653 if(z>manb){
14654 manb=z;
14655 ic=i;
14656 }
14657 }
14658 if (ic!=-1){
14659 c=currentChain;
14660 currentChain.append(neighbors.at(last).at(ic));
14661 extendChain(rings, currentChain, neighbors, nogo);
14662 }/*else{ // forking
14663 chains.append(c);
14664 int lc = chains.size() - 1;
14665 chains[lc].append(neighbors.at(last).at(i));
14666 extendChain(chains, chains[lc], neighbors, ng);
14667 ic++;
14668 ng.unite(chains[lc].toSet());
14669 }// */
14670 c.clear();
14671 }
14672
14673 void AulaWorker::inventNewLabels(QList<int> &result){
14674
14675 /*
14676 * Idea / draft:
14677 * for atoms in a molecule
14678 * find chain ends (E) neighbors 1
14679 * find chain atoms (C) neighbors 2
14680 * find nodes (N) neighbors >2
14681 * start at an E and append indexes to a QList chain
14682 * when a node N appears copy the list neighbors - 1 times (forking)
14683 * when no atoms left then compare number members in each chain
14684 * the longest chain wins
14685 * the longest part with carbons wins
14686 * the E with the greatest distance from center of mass wins
14687 * E-C-C-C-N-C-C-N-N-N-C-C-E
14688 * | | | |
14689 * C-C-C-C E E
14690 *
14691 * 1-2-3-4-5-g-h-a-b-c-d-e-f
14692 * | | | |
14693 * 6-7-8-9 i j
14694 */
14695 //return;
14696 QList<QList<int> > neighbors;
14697 QList<QList<int> > chains;
14698 QList<int> emptyChain;
14699 QSet<int> nogo;
14700 QList<int> molsizes;
14701 QList<bool> moleIsDone;
14702 QList<double> avan, di2com;// avarage atomic number, distance to center of mass
14703 QList<V3> centerOfMass;
14704 QList<int>cmax;//maximal chain length
14705 for (int i=0; i<_w->mole.asymm.size(); i++){
14706 if (_w->mole.asymm.at(i).an<0 )continue;
14707 neighbors.append(emptyChain);
14708 if (_w->mole.asymm.at(i).molindex < 0) printf("_w->mole.asymm.at(i).molindex = %d\n",_w->mole.asymm.at(i).molindex);
14709 if (_w->mole.asymm.at(i).molindex> molsizes.size()) {
14710 molsizes.append(0);
14711 cmax.append(0);
14712 moleIsDone.append(false);
14713 centerOfMass.append(V3(0.0,0.0,0.0));
14714 avan.append(999990.0);
14715 di2com.append(0.0);
14716 }
14717 molsizes[_w->mole.asymm.at(i).molindex-1]++;
14718 centerOfMass[_w->mole.asymm.at(i).molindex-1]+=_w->mole.asymm.at(i).pos;
14719 }
14720 for (int i=0; i<molsizes.size(); i++){
14721 centerOfMass[i]*=1.0/molsizes.at(i);
14722 }
14723 for (int i=0; i<_w->mole.sdm.size(); i++){
14724 if ((_w->mole.sdm.at(i).a1>=neighbors.size())||(_w->mole.sdm.at(i).a2>=neighbors.size())) continue;
14725 if (_w->mole.sdm.at(i).covalent) neighbors[_w->mole.sdm.at(i).a1].append(_w->mole.sdm.at(i).a2);
14726 }
14727 // find rings first
14728 QList<QList<int> > rings;
14729 QList<Tripel> tripels;
14730 Tripel t;//midcenter
14731 QList<Ring> ringe;
14732 QSet<int>nonMetals;
14733 emit message("find rings...");
14734 //B, C, N, O, F, Si, P, S, Cl, Ge, As, Se, Br, Sb, Te, I
14735 nonMetals<<4<<5<<6<<7<<8<<13<<14<<15<<16<<31<<32<<33<<34<<50<<51<<52;
14736 for (int i=0; i<neighbors.size();i++){
14737 if (!nonMetals.contains(_w->mole.asymm.at(i).an)) continue; //no rings with metals
14738 if (neighbors.at(i).size()>1)
14739 for (int j=0; j<neighbors.at(i).size();j++){
14740 for (int k=j+1; k<neighbors.at(i).size();k++){
14741 if (!nonMetals.contains(_w->mole.asymm.at(neighbors.at(i).at(j)).an)) continue; //no rings with metals
14742 if (!nonMetals.contains(_w->mole.asymm.at(neighbors.at(i).at(k)).an)) continue; //no rings with metals
14743 t.n[0]=i;
14744 t.n[1]=neighbors.at(i).at(j);
14745 t.n[2]=neighbors.at(i).at(k);
14746 double w = _w->mole.winkel(_w->mole.asymm.at(t.n[1]).pos - _w->mole.asymm.at(t.n[0]).pos,
14747 _w->mole.asymm.at(t.n[2]).pos - _w->mole.asymm.at(t.n[0]).pos) / 180.0 * M_PI;
14748 double scal = sin(w * 0.5) * sin(w * 0.5) / (sin(w) * sin(w));
14749 t.midcenter = _w->mole.asymm.at(t.n[0]).pos + scal * (_w->mole.asymm.at(t.n[1]).pos +
14750 _w->mole.asymm.at(t.n[2]).pos -(_w->mole.asymm.at(t.n[0]).pos * 2.0));
14751 tripels.append(t);
14752 }
14753 }
14754 }
14755 //printf("atoms%d tripel%d\n",neighbors.size(),tripels.size());
14756 const double RINGTEST=0.7;
14757 for (int i=0; i<tripels.size(); i++){
14758 /* print the midcenter as q peaks
14759 V3 f;
14760 kart2frac(tripels.at(i).midcenter,f);
14761 printf("Q%03d 1 %9.5f %9.5f %9.5f 11.0 0.05 %5.2f\n",i,f.x,f.y,f.z,i*0.01);
14762 */
14763 for (int j=0; j<i; j++){
14764 double dist=Distance(tripels.at(i).midcenter,tripels.at(j).midcenter);
14765 if (dist<RINGTEST){
14766 bool alreadyHaveIt=false;
14767 for (int k = 0; k < ringe.size(); k++){
14768 //printf("j%d i%d k%d\n",j,i,k);
14769 // if (ringe[k].isComplete()) continue;
14770 V3 r1=ringe[k].theCenter();
14771 double
14772 d1=Distance(tripels.at(i).midcenter,r1),
14773 d2=Distance(tripels.at(j).midcenter,r1);
14774 if ((d1<RINGTEST)||(d2<RINGTEST)){
14775 ringe[k].addTripel(tripels.at(i));
14776 ringe[k].addTripel(tripels.at(j));
14777 //printf(":: %d %f %f ::\n", k, d1, d2);
14778 alreadyHaveIt=true;
14779 // continue;
14780 }
14781 //else printf(":: %f %f ::\n",d1,d2);
14782 }
14783 if (!alreadyHaveIt){
14784 //printf("tic\n");
14785 ringe.append(Ring(tripels.at(i),tripels.at(j)));
14786 //ringe.last().printRing(this);
14787 }
14788 }//else {printf("DIST %g\n",dist);}
14789 //printf("j%d %d\n",j,i);
14790 }
14791 //printf("i%d \n",i);
14792 }
14793 //return;
14794 //printf("Rings %d\n",ringe.size());
14795 emit message(QString("found %1 rings.").arg(ringe.size()));
14796 // int fix=0;
14797 for (int ri=0; ri<ringe.size(); ri++){
14798 bool fertig = ringe[ri].isComplete();
14799 if ((!fertig)&&(ringe[ri].members.size()<7)) {
14800 //ringe[ri].printRing(this);
14801 int u=ringe[ri].members.size();
14802 for (int w=0; w<u; w++) {
14803 for (int v=0; v<tripels.size();v++){
14804 if (
14805 (ringe[ri].members.contains(tripels.at(v).n[0]))&&
14806 (ringe[ri].members.contains(tripels.at(v).n[1]))&&
14807 (ringe[ri].members.contains(tripels.at(v).n[2]))) {
14808 ringe[ri].addTripel(tripels.at(v));
14809 continue;
14810 }
14811 }
14812 }
14813 }
14814 //ringe[ri].printRing(this);
14815 fertig = ringe[ri].isComplete();
14816 ringe[ri].isItARealRing();
14817 fertig = ringe[ri].isComplete();
14818 //printf("%d %d %d\n",ringe[ri].t.size(),ringe[ri].members.size(),fertig);
14819 if (!fertig) {ringe.removeAt(ri);ri--;}
14820 }
14821 /*
14822 for (int ri=0; ri<ringe.size(); ri++){
14823 for (int rj=1; rj<ri; rj++){
14824 if (rj==ri)continue;
14825 if (Distance(ringe[ri].theCenter(),ringe[rj].theCenter())<0.2){ringe.removeAt(ri);ri--;break;}
14826 }
14827 }
14828 */
14829 //printf("Rings %d are real and complete.\n",ringe.size());
14830 emit message(QString("found %1 rings.").arg(ringe.size()));
14831 // return;
14832 for (int mi=0; mi<centerOfMass.size();mi++){
14833 //printf("Molecule#%d has %d atoms\n", mi, molsizes.at(mi));
14834 double away=-10.0;
14835 int itakethisring=0;
14836 for (int ri=0; ri<ringe.size(); ri++){
14837 if ((_w->mole.asymm.at(ringe.at(ri).members.at(0)).molindex-1)!=mi) continue;
14838 //bool fertig = ringe[ri].isComplete();
14839 // if (fertig) fix++;
14840 //ringe[ri].printRing(this);
14841 //printf("Ring #%d size = %d/%d is complete %d\n",ri,ringe.at(ri).t.size(),ringe.at(ri).members.size(),fertig);
14842 if (ringe.at(ri).members.size()==7){
14843 ringe[ri].debugRing(&_w->mole);
14844 ringe[ri].isItARealRing();
14845 }
14846 double d=Distance(centerOfMass[_w->mole.asymm.at(ringe.at(ri).members.at(0)).molindex-1],ringe[ri].theCenter());
14847 V3 dir = (_w->mole.asymm.at(ringe.at(ri).members.at(0)).pos -
14848 ringe[ri].theCenter())%(_w->mole.asymm.at(ringe.at(ri).members.at(1)).pos - ringe[ri].theCenter());
14849 V3 com2r = ringe[ri].theCenter()-centerOfMass[_w->mole.asymm.at(ringe.at(ri).members.at(0)).molindex-1];
14850 double test= dir*com2r;
14851 QList<int> rcpy=ringe[ri].members;
14852 if (test>0.0){//flip ring order
14853 ringe[ri].members.clear();
14854 for (int kk=rcpy.size()-1; kk>=0; kk--){
14855 ringe[ri].members.append(rcpy.at(kk));
14856 }
14857 dir = (_w->mole.asymm.at(ringe.at(ri).members.at(0)).pos -
14858 ringe[ri].theCenter())%(_w->mole.asymm.at(ringe.at(ri).members.at(1)).pos - ringe[ri].theCenter());
14859 test= dir*com2r;
14860 //printf("fliped ");
14861 }
14862 //ringe[ri].printRing(this);
14863 if (away<d){
14864 away=d;
14865 itakethisring=ri;
14866 }
14867 //printf("AWAYOFCOM %f %d test%g \n",d,ri,test);
14868 }
14869 //printf("Complete Rings %d\n",fix);
14870 //printf("Rings %d\n",ringe.size());
14871 emit message(QString("found %1 rings.").arg(ringe.size()));
14872 if ((!ringe.isEmpty())&&((_w->mole.asymm.at(ringe.at(itakethisring).members.at(0)).molindex-1)==mi)){
14873 //ringe[itakethisring].printRing(this);
14874 //printf("most far AWAY from COM %f %d\n",away,itakethisring);
14875 int starthere=0,mn=0;
14876 double away2=1000;
14877 for (int i=0; i<ringe[itakethisring].members.size(); i++){
14878 if ((neighbors.at(ringe[itakethisring].members.at(i)).size()>=mn)&&
14879 (Distance(_w->mole.asymm.at(ringe[itakethisring].members.at(i)).pos,centerOfMass[_w->mole.asymm.at(ringe.at(itakethisring).members.at(i)).molindex-1])<away2)){
14880 mn=neighbors.at(ringe[itakethisring].members.at(i)).size();
14881 away2=Distance(_w->mole.asymm.at(ringe[itakethisring].members.at(i)).pos,centerOfMass[_w->mole.asymm.at(ringe.at(itakethisring).members.at(i)).molindex-1]);
14882 starthere=i;
14883 }
14884 }
14885 chains.append(emptyChain);
14886 for (int i=0; i<ringe[itakethisring].members.size(); i++){
14887 chains.last().append(ringe[itakethisring].members.at(starthere%ringe[itakethisring].members.size()));
14888 starthere++;
14889 }
14890 ringe[itakethisring].done=true;
14891 //aneal ring
14892 for (int ci=0; ci<chains.last().size(); ci++){
14893 for (int ri=0; ri<ringe.size();ri++){
14894 if (ringe.at(ri).done) continue;
14895 if ((ringe[ri].members.contains(chains.last().at(ci)))&&(ringe[ri].members.contains(chains.last().at((ci+1)%chains.last().size())))){
14896 int bbv=chains.last().size();
14897 int ll=chains.last().last();
14898 int strt=ringe[ri].members.indexOf(ll);
14899 if (strt<0)strt = ringe[ri].members.indexOf(chains.last().at(ci));
14900 for (int rri=0,rrj=0; rri<ringe[ri].members.size(); rri++){
14901 rrj=(strt>=0)?(strt+rri)%ringe[ri].members.size():rri;
14902 if (!chains.last().contains(ringe[ri].members.at(rrj))) chains.last().append(ringe[ri].members.at(rrj));
14903 }
14904 bbv-=chains.last().size();
14905 if (bbv) ringe[ri].done=true;
14906 //printf("RING%d %d %d %d %d\n",ri,bbv,ci,chains.last().size(),ringe[ri].members.size());
14907 }
14908 }
14909 }
14910 do{
14911 int ce=chains.last().size();
14912 for (int cc=0; cc<ce; cc++){
14913 for (int nn=0; nn<neighbors.at(chains.last().at(cc)).size();nn++){
14914 if (!chains.last().contains(neighbors.at(chains.last().at(cc)).at(nn))) {
14915 chains.last().append(neighbors.at(chains.last().at(cc)).at(nn));
14916 //printf("ext %s\n",asymm.at(neighbors.at(chains.last().at(cc)).at(nn)).Label.toStdString().c_str());
14917 extendChain(ringe,chains.last(), neighbors,nogo);
14918 }
14919 }
14920 }
14921 }while(chains.last().size()<molsizes.at(mi));
14922 if (chains.last().size()==molsizes.at(mi))moleIsDone[mi]=true;
14923 }
14924 if ((!chains.isEmpty())&&(!result.contains(chains.last().last()))) {
14925 result.append(chains.last());
14926 }
14927 }//mi
14928
14929 /*
14930 for (int cs=0; cs<chains.size(); cs++){
14931 chains[cs].clear();
14932 }
14933 chains.clear();
14934 */
14935 //for(int i=0; i<result.size(); i++){printf("%s[%d]=",asymm.at(result.at(i)).Label.toStdString().c_str(),i+1);if(!(i%10))printf("\n");}printf("\n");
14936 //return;
14937 //
14938 //printf("Molecules with rings are done\n");
14939 emit message(QString("Molecules with rings are done."));
14940 for (int mi=0; mi<molsizes.size(); mi++){
14941 if (moleIsDone.at(mi)) continue;
14942 //printf("mol%d %d %d %d resultsize%d chains%d\n",mi,molsizes.at(mi),molsizes.size(),centerOfMass.size(),
14943 // result.size(),chains.size());
14944 int starthere=-1;
14945 double away=-10;
14946 for (int i=0; i<neighbors.size(); i++){
14947 if (_w->mole.asymm.at(i).an<0)continue;
14948 if ((_w->mole.asymm.at(i).molindex-1 == mi)&&(neighbors.at(i).size()==0)){
14949 result.append(i);//isolated atoms
14950 continue;
14951 }
14952 if ((_w->mole.asymm.at(i).molindex-1 == mi)&&(neighbors.at(i).size()==1)){//chain end
14953 //printf("%d %d %d %d %d\n",__LINE__,i,asymm.size(),neighbors.size());
14954 double d=Distance(_w->mole.asymm.at(i).pos,centerOfMass.at(mi));
14955 //printf("%d\n",__LINE__);
14956 if (d>away){
14957 away=d;
14958 starthere=i;
14959 }
14960 }
14961 // printf("%d\n",__LINE__);
14962 }
14963 //printf("%d\n",__LINE__);
14964 if (starthere<0) continue;
14965 //printf("start at %d if not done%d\n",starthere,!result.contains(starthere));
14966
14967 if (!result.contains(starthere)){
14968 chains.append(emptyChain);
14969 chains.last().append(starthere);
14970 extendChain(ringe,chains.last(),neighbors,nogo);
14971 }
14972 do{
14973 int ce=chains.last().size();
14974 for (int cc=0; cc<ce; cc++){
14975 for (int nn=0; nn<neighbors.at(chains.last().at(cc)).size();nn++){
14976 if (!chains.last().contains(neighbors.at(chains.last().at(cc)).at(nn))) {
14977 chains.last().append(neighbors.at(chains.last().at(cc)).at(nn));
14978 //printf("ext %s\n",asymm.at(neighbors.at(chains.last().at(cc)).at(nn)).Label.toStdString().c_str());
14979 extendChain(ringe,chains.last(), neighbors,nogo);
14980 }
14981 }
14982 }
14983 }while(chains.last().size()<molsizes.at(mi));
14984 if ((!chains.isEmpty())&&(!result.contains(chains.last().last()))) {
14985 result.append(chains.last());
14986 }
14987
14988 }
14989 for (int cs=0; cs<chains.size(); cs++){
14990 chains[cs].clear();
14991 }
14992 chains.clear();
14993 emit message("All chains are done!");
14994 }
14995
14996 void AulaWorker::finalize(){
14997 //printf("AuLa take %d ms. %d\n", rzeit.elapsed(),__LINE__); // rzeit.restart();
14998 _w->editor->setPlainText(all);
14999 all.clear();
15000 _w->fileSave();
15001 //printf("AuLa take %d ms. %d\n", rzeit.elapsed(),__LINE__); // rzeit.restart();
15002 //_w->editor->textCursor().beginEditBlock();
15003
15004 //printf("AuLa take %d ms. %d\n", rzeit.elapsed(),__LINE__); // rzeit.restart();
15005
15006 //_w->sdm();
15007 _w->chgl->update();
15008 //printf("AuLa take %d ms. %d\n", rzeit.elapsed(),__LINE__); // rzeit.restart();
15009 _w->fileSave();
15010
15011 //printf("AuLa took %d ms.\n", rzeit.elapsed()); // rzeit.restart();
15012 QWhatsThis::hideText();
15013 QMessageBox mb2(QMessageBox::Information,
15014 "Automatic Labeling",QString("<h4>Labeled %1 atoms out of %2 atoms in the asymmetic unit in %3 seconds </h4>")
15015 .arg(chain.size()).arg(possible).arg((rzeit.elapsed()/1000.0),0,'f',1));
15016 mb2.exec();
15017 }
15018
15019 void Window::changeSelectedElements(){
15020 QAction *action = qobject_cast<QAction *>(sender());
15021 int index=0;
15022 if (action)
15023 index=action->data().toInt();
15024 else return;
15025 if (index>editor->sfac.size()) return;
15026 //if ((chgl->ImeanThisAtom>mole.asymm.size())||(chgl->ImeanThisAtom<0)) return;
15027 QList<int> diese;
15028 for (int i=0; i<chgl->mol->selectedatoms.size(); i++){
15029 int das=(chgl->mol->selectedatoms.at(i).style>mole.asymm.size())?
15030 chgl->mol->showatoms.at(chgl->mol->selectedatoms.at(i).style).auidx:
15031 chgl->mol->selectedatoms.at(i).style;
15032 if (!diese.contains(das)) diese.append(das);
15033 printf("changeSelectedElements %s -> %s %d %d %d %d %s\n",
15034 chgl->mol->selectedatoms.at(i).Label.toStdString().c_str(),
15035 (chgl->mol->selectedatoms.at(i).style>mole.asymm.size())?
15036 chgl->mol->asymm.at(chgl->mol->showatoms.at(chgl->mol->selectedatoms.at(i).style).auidx).Label.toStdString().c_str():
15037 chgl->mol->asymm.at(chgl->mol->selectedatoms.at(i).style).Label.toStdString().c_str(),
15038
15039 i,
15040 chgl->mol->showatoms.at(chgl->mol->selectedatoms.at(i).style).auidx,
15041 chgl->mol->selectedatoms.at(i).style,
15042 index,
15043 mole.pse(editor->sfac.at(index)).toStdString().c_str() );
15044 }
15045 //return;
15046 mole.selectedatoms.clear();
15047 //////////////////
15048 sdm();
15049 rename_selected *owl = new rename_selected(this);
15050 owl->setChainAndNewAN(diese,editor->sfac.at(index));
15051 connect(owl, SIGNAL(finished()), this, SLOT(sdm()));
15052 connect(owl, SIGNAL(finished()), owl, SLOT(finalize()));
15053 //connect(owl, SIGNAL(finished()), chgl, SLOT(updateLabelTextures()));
15054 connect(owl, SIGNAL(finished()), chgl, SLOT(update()));
15055 connect(owl, SIGNAL(message(const QString&)), this, SLOT(updateStatusBar(const QString&)));
15056 connect(owl, SIGNAL(message(const QString&)), this, SLOT(update()));
15057 connect(owl, SIGNAL(finished()), owl, SLOT(deleteLater()));
15058 maybeSave2();
15059 QWhatsThis::showText(QPoint(pos().x() + width()/2,pos().y() + height()/2),"<H1>Auto Labeling in process please be patient!<br> You can follow progress below in the status bar.</H1>",this);
15060 sdm();
15061 owl->start();
15062 //////////////////
15063 /*
15064 bool alterMichi=rufModeBox->isChecked();
15065 for (int i=0; diese.size(); i++){
15066 int das=diese.at(i);
15067 rufModeBox->setChecked(true);
15068 // printf("new Element of %s is %s\n",mole.asymm.at(das).Label.toStdString().c_str(),mole.pse(editor->sfac.at(index)).toStdString().c_str());
15069 static QRegularExpression num=QRegularExpression("\\d+");
15070 if (mole.asymm.at(das).Label.contains(num)) {
15071 int p=editor->sfac.at(index);
15072 labelPSE=mole.pse(p);
15073
15074 labelIndex=mole.asymm.at(das).Label.section(nonumbers,0,0,QString::SectionSkipEmpty).toInt();
15075 labelSuffix=mole.asymm.at(das).Label.section(num,1,1);
15076 labelSuffix.remove(vorneweg);
15077 }
15078 else{
15079 int p=editor->sfac.at(index);
15080 labelPSE=mole.pse(p);
15081 labelIndex=-1;
15082 labelSuffix=mole.asymm.at(das).Label;
15083 labelSuffix.remove(0,labelPSE.size());
15084 labelSuffix.remove(vorneweg);
15085 }
15086
15087 partSpin->setValue(mole.asymm.at(das).part);
15088 resiNrSpin->setValue(mole.asymm.at(das).resiNr);
15089 resiResiClass->setText(mole.asymm.at(das).ResiClass);
15090 pserbt[editor->sfac.at(index)+1]->setChecked(true);
15091 printf("%d das %d\n",__LINE__,das);
15092 renamUpdate(false);
15093 updateLabel();
15094 renameThisAtom(das);
15095 printf("->i = %d/%d das = %d %d\n",i,diese.size(),das,alterMichi);
15096 }
15097 rufModeBox->setChecked(alterMichi);
15098 printf("done rename\n"); */
15099 }
15100
15101 void Window::changeElement(){
15102 QAction *action = qobject_cast<QAction *>(sender());
15103 int index=0;
15104 if (action)
15105 index=action->data().toInt();
15106 else return;
15107 if (index>editor->sfac.size()) return;
15108 if ((chgl->ImeanThisAtom>mole.asymm.size())||(chgl->ImeanThisAtom<0)) return;
15109 int das=chgl->ImeanThisAtom;
15110 bool alterMichi=rufModeBox->isChecked();
15111 rufModeBox->setChecked(true);
15112 // printf("new Element of %s is %s\n",mole.asymm.at(das).Label.toStdString().c_str(),mole.pse(editor->sfac.at(index)).toStdString().c_str());
15113 //static QRegularExpression num=QRegularExpression("\\d+");
15114 if (mole.asymm.at(das).Label.contains(numbers)) {
15115 int p=editor->sfac.at(index);
15116 labelPSE=mole.pse(p);
15117
15118 labelIndex=mole.asymm.at(das).Label.section(nonumbers,0,0,QString::SectionSkipEmpty).toInt();
15119 labelSuffix=mole.asymm.at(das).Label.section(numbers,1,1);
15120 labelSuffix.remove(vorneweg);
15121 }
15122 else{
15123 int p=editor->sfac.at(index);
15124 labelPSE=mole.pse(p);
15125 labelIndex=-1;
15126 labelSuffix=mole.asymm.at(das).Label;
15127 labelSuffix.remove(0,labelPSE.size());
15128 labelSuffix.remove(vorneweg);
15129 }
15130
15131 partSpin->setValue(mole.asymm.at(das).part);
15132 resiNrSpin->setValue(mole.asymm.at(das).resiNr);
15133 resiResiClass->setText(mole.asymm.at(das).ResiClass);
15134 pserbt[editor->sfac.at(index)+1]->setChecked(true);
15135 printf("%d\n",__LINE__);
15136 renamUpdate(false);
15137 updateLabel();
15138 renameThisAtom(das);
15139 rufModeBox->setChecked(alterMichi);
15140 }
15141
15142 void Window::zoomin(){
15143 chgl->zoom(0.1);
15144 chgl->update();
15145 }
15146
15147 void Window::zoomout(){
15148 chgl->zoom(-0.1);
15149 chgl->update();
15150 }
15151
15152 void Window::calculator() {
15153 if (!calcmenu) calcmenu = new Calculator(CurrentCellString,this);
15154 else calcmenu->show();
15155 connect(calcmenu,SIGNAL(currentCellrequest()),this,SLOT(setCalculatorsCurrentCell()) );
15156 }
15157
15158 void Window::setCalculatorsCurrentCell(){
15159 if (calcmenu){
15160 calcmenu->setHKLEdit(CurrentCellString);
15161 }
15162 }
15163
15164 void Window::create_DSRGui() {
15165 // Only starts DSRGui instance if not already started:
15166 if (dsr == nullptr) {
15167 dsr = new DSRGui(&mole, shelxlPath, this);
15168 connect(dsr, SIGNAL(closed()), this, SLOT(dsrClosed()) );
15169 QList<QAction *> acs = helpMenu->actions();
15170 bool oneisenough=true;
15171 for (int i = 0; i < acs.size(); ++i){
15172 if (acs.at(i)->text()=="About DSR Plugin") {oneisenough=false;break;}
15173 }
15174 if (oneisenough) helpMenu->addAction("About DSR Plugin", dsr, SLOT(aboutDSR()));
15175 }
15176 // Go out of rename mode.
15177 printf("%d\n",__LINE__);
15178 renamUpdate(false);
15179 if (!dsr->isActiveWindow()){
15180 dsr->raise();
15181 dsr->activateWindow();
15182 printf("%d\n",__LINE__);
15183 renamUpdate(false);
15184 }
15185 }
15186
15187 void Window::dsrClosed() {
15188 dsr = nullptr;
15189 }
15190
15191 void Window::insertDSRLine(QString dsrline, int position, QVector<int> previousLine){
15192 // Insert the DSR command line at the position below the FVAR line,
15193 // or if not present, the first atom.
15194 // If also a previous DSR line is present (previousLine > 0), the previous line will be deleted.
15195 foreach (int lineNum, previousLine) {
15196 if (lineNum > 0) {
15197 QTextCursor cursor = editor->textCursor();
15198 cursor.setPosition(0);
15199 cursor.movePosition(QTextCursor::Down, QTextCursor::MoveAnchor, lineNum);
15200 editor->setTextCursor(cursor);
15201 cursor.insertText("REM ");
15202 }
15203 }
15204 QTextCursor cursor = editor->textCursor();
15205 cursor.setPosition(0);
15206 cursor.movePosition(QTextCursor::Down, QTextCursor::MoveAnchor, position+1);
15207 editor->setTextCursor(cursor);
15208 cursor.insertText(dsrline);
15209 cursor.insertText("\n");
15210 fileSave(true, false);
15211 }
15212
15213 void Window::rotl(){
15214 emit movedByUser();
15215 chgl->rotY(0.1);
15216 chgl->update();
15217
15218 }
15219
15220 void Window::rotr(){
15221 emit movedByUser();
15222 chgl->rotY(-0.1);
15223 chgl->update();
15224 }
15225
15226 void Window::rotu(){
15227 emit movedByUser();
15228 chgl->rotX(0.1);
15229 chgl->update();
15230 }
15231
15232 void Window::rotd(){
15233 emit movedByUser();
15234 chgl->rotX(-0.1);
15235 chgl->update();
15236 }
15237
15238 void Window::updateStatusBar(const QString& s) {
15239 statusBar()->showMessage(s);
15240 emit pipeStatus(s);
15241 update();
15242
15243 }
15244
15245 int Window::getFvarNr(double v, const QList<double> fv){
15246 double av=qAbs(v);
15247 int m=0;
15248 while ((-10*m+av) > 5){m++;}
15249 if (m>1) m=qMin(m,fv.size());
15250 return m;
15251 }
15252
15253 double Window::getNumber(double v, const QList<double> fv,int idx,int &fixFlag){
15254 double av=qAbs(v),res=0.0,var=1.0;
15255 int m=0;
15256 while ((-10*m+av) > 5){m++;}
15257 if (m>1) m=qMin(m,fv.size());
15258 if (m>1) var=fv.at(m-1);
15259 if (!m) res=v;
15260 else if (v>0) res=(av-(10*m))*var;
15261 else res=(av-(10*m))*(1.0-var);
15262 fvarCntr[m]++;
15263 if (m>0) fixFlag|=1<<idx; else if (fixFlag&1<<idx) fixFlag-=1<<idx;
15264 //if (m==3) printf("Aidx: %d shift %d flag %d m%d fvarCntr=%d %f %f\n", idx,1<<idx,fixFlag,m,fvarCntr.value(m),v,res);
15265 return res;
15266 }
15267
15268 double Window::getNumber(double v, const QList<double> fv, double uiso){
15269 double av=qAbs(v),res=0.0,var=1.0;
15270 if ((v<-0.5)&& (v>-5.0)) return res = av * uiso ;
15271 int m=0;
15272 while ((-10*m+av) > 5){m++;}
15273 if (m>1) m=qMin(m,fv.size());
15274 if (m>1) var=fv.at(m-1);
15275 if (!m) return v;
15276 else if (v>=0) res=(av-(10*m))*var;
15277 else res=(av-(10*m))*(1.0-var);
15278 fvarCntr[m]++;
15279 //printf("Bidx: m%d fvarCntr=%d\n",m,fvarCntr.value(m));
15280 return res;
15281 }
15282
15283 int Window::isacommand(QString command){
15284 QStringList keywords;
15285 keywords <<
15286 "ACTA"<<//0
15287 "AFIX"<<//1
15288 "MPLA"<<//2
15289 "ANIS"<<//3
15290 "BASF"<<//4
15291 "BIND"<<//5
15292 "BLOC"<<//6
15293 "BOND"<<//7 AGS4 to MPLA
15294 "BUMP"<<//8
15295 "CELL"<<//9
15296 "CGLS"<<//10
15297 "CHIV"<<//11
15298 "CONF"<<//12
15299 "CONN"<<//13
15300 "DAMP"<<//14
15301 "DANG"<<//15
15302 "DEFS"<<//16
15303 "DELU"<<//17
15304 "DFIX"<<//18
15305 "DISP"<<//19
15306 "EADP"<<//20
15307 "EGEN"<<//21
15308 "END" <<//22
15309 "EQIV"<<//23
15310 "ESEL"<<//24
15311 "EXTI"<<//25
15312 "EXYZ"<<//26
15313 "FEND"<<//27
15314 "FLAT"<<//28
15315 "FMAP"<<//29
15316 "FRAG"<<//30
15317 "FREE"<<//31
15318 "FVAR"<<//32
15319 "GRID"<<//33
15320 "HFIX"<<//34
15321 "HKLF"<<//35
15322 "HOPE"<<//36
15323 "HTAB"<<//37
15324 "INIT"<<//38
15325 "ISOR"<<//39
15326 "LAST"<<//40
15327 "LATT"<<//41
15328 "LAUE"<<//42
15329 "LIST"<<//43
15330 "L.S."<<//44
15331 "MERG"<<//45
15332 "MOLE"<<//46
15333 "MORE"<<//47
15334 "MOVE"<<//48
15335 "NCSY"<<//49
15336 "OMIT"<<//50
15337 "PART"<<//51
15338 "PATT"<<//52
15339 "PHAN"<<//53
15340 "PHAS"<<//54
15341 "PLAN"<<//55
15342 "PSEE"<<//56
15343 "REM"<< //57
15344 "RESI"<<//58
15345 "RTAB"<<//59
15346 "SADI"<<//60
15347 "SAME"<<//61
15348 "SFAC"<<//62
15349 "SHEL"<<//63
15350 "SIMU"<<//64
15351 "SIZE"<<//65
15352 "SPEC"<<//66
15353 "SPIN"<<//67
15354 "STIR"<<//68
15355 "SUMP"<<//69
15356 "SWAT"<<//70
15357 "SYMM"<<//71
15358 "TEMP"<<//72
15359 "TEXP"<<//73
15360 "TIME"<<//74
15361 "TITL"<<//75
15362 "TREF"<<//76
15363 "TWIN"<<//77
15364 "UNIT"<<//78
15365 "VECT"<<//79
15366 "WPDB"<<//80
15367 "WGHT"<<//81
15368 "ZERR"<<//82
15369 "XNPD"<<//83
15370 "REST"<<//84
15371 "CHAN"<<//85
15372 "RIGU"<<//86
15373 "FLAP"<<//87
15374 "RNUM"<<//88
15375 "SOCC"<<//89
15376 "PRIG"<<//90
15377 "WIGL"<<//91
15378 "RANG"<<//92
15379 "TANG"<<//93
15380 "ADDA"<<//94
15381 "STAG"<<//95
15382 "ATOM"<<//96PDB dummy commands ...
15383 "HETA"<<//97
15384 "SCAL"<<//98
15385 "ABIN"<<//99
15386 "ANSC"<<//100
15387 "ANSR"<<//101
15388 "NOTR"<<//102
15389 "NEUT"<<//103
15390 "TWST"<<//104
15391 "BEDE"<<//105
15392 "LONE"//106<<
15393 ;//
15394 QString c=command;
15395 c=c.toUpper();
15396 c.remove(QRegularExpression("_\\S*"));
15397 if (c.startsWith("+")) return 666;//file inclusion
15398 return keywords.indexOf(c);
15399 }
15400
15401 void Window::clearStructure(){
15402 printf("clearStructure\n");
15403 chgl->showHidden();
15404 machPlatz=false;
15405 chgl->neutrons=false;
15406 infoKanal->clear();
15407 shxEditorDock->show();
15408 wghtAct->setEnabled(false);
15409 qPeakDock->hide();
15410
15411
15412 enterRenameMode->setVisible(true);
15413 chgl->qPeakBonds->setVisible(false);
15414 chgl->shpm1->setVisible(false);
15415 chgl->hideBeLo->setVisible(false);
15416 belocube->setVisible(false);
15417 mole.cell.symmops.clear();
15418 mole.cell.trans.clear();
15419 mole.asymm.clear();
15420 mole.sdm.clear();
15421 mole.showbonds.clear();
15422 mole.showatoms.clear();
15423 mole.selectedatoms.clear();
15424 mole.lbonds.clear();
15425
15426 mole.envi_sdm.clear();
15427 mole.contact.clear();
15428 mole.envi_sdm.clear();
15429 mole.contact.clear();
15430 mole.symmopsEQIV.clear();
15431 mole.labelEQIV.clear();
15432 mole.transEQIV.clear();
15433 mole.freeatoms.clear();
15434 mole.bindatoms.clear();
15435 for (int i=0; i<mole.knoepfe.size();i++) mole.knoepfe[i].neighbors.clear();
15436 mole.knoepfe.clear();
15437 mole.showbonds.clear();
15438 mole.selectedatoms.clear();
15439 //chgl->rotCenter();
15440 chgl->updateBondActions();
15441 mole.showatoms.clear();
15442 update();
15443 chgl->update();
15444
15445 }
15446
15447 bool Window::quickReLoad(QString fn, QString &content){
15448 //return false;
15449 // reasons for return false:
15450 // CELL differs +
15451 // filename differs +
15452 // LATT differs +
15453 // SYMM differs +
15454 // asymm.size is different -
15455 bool xit=(fn==oldFileName);
15456 oldFileName=fn;
15457 if (!xit) return false;
15458 // Disabled SkipEmptyParts because otherwise i is not in sync with the line number!
15459 QStringList lines = content.split(QRegularExpression("[\\r\\n]")); //,skipEmptyParts);
15460 {//cell
15461 int idx =lines.indexOf(QRegularExpression("^CELL.*$"));
15462 //printf("IDX %d\n",idx);
15463 double wave = lines.at(idx).section(leer,1,1).toDouble();
15464 double a = lines.at(idx).section(leer,2,2).toDouble();
15465 double b = lines.at(idx).section(leer,3,3).toDouble();
15466 double c = lines.at(idx).section(leer,4,4).toDouble();
15467 double al= lines.at(idx).section(leer,5,5).toDouble();
15468 double be = lines.at(idx).section(leer,6,6).toDouble();
15469 double ga = lines.at(idx).section(leer,7,7).toDouble();
15470 double diff=
15471 fabs(mole.cell.a-a)+
15472 fabs(mole.cell.b-b)+
15473 fabs(mole.cell.c-c)+
15474 fabs(mole.cell.al-al)+
15475 fabs(mole.cell.be-be)+
15476 fabs(mole.cell.ga-ga)+
15477 fabs(mole.cell.wave-wave);
15478 printf("cell differs %g\n",diff);
15479 if (diff>0.00001) {
15480 printf("cell differs too much!\n");
15481 lines.clear();
15482 return false;
15483 }
15484 }
15485 {//latt
15486 int idx =lines.indexOf(QRegularExpression("^LATT.*$"));
15487 //printf("IDX %d\n",idx);
15488 int thisLattice=lines.at(idx).section(leer,1,1).toInt();
15489 if (mole.latt!=thisLattice){
15490 lines.clear();
15491 return false;
15492 }
15493
15494 }
15495 int minp=1,maxp=0;
15496 bool qbeforehkl=false,hklf=false;
15497 mole.pmin=10000;
15498 mole.pmax=-10000;
15499 mole.lmin=10000;
15500 mole.lmax=-10000;
15501 qPeakDock->hide();
15502
15503 mole.symmopsEQIV.clear();
15504 mole.labelEQIV.clear();
15505 mole.transEQIV.clear();
15506 mole.freeatoms.clear();
15507 mole.bindatoms.clear();
15508 editor->sfac.clear();
15509 editor->sfacsmbl.clear();
15510 fvar.clear();
15511 firstAtomLine = 0;
15512 ls_cycls = 0;
15513 editor->fvMinLine = 0; // otherwise it does not recognize a moving fvar line
15514 MyAtom newAtom;
15515 newAtom.part=0;
15516 newAtom.resiNr=0;
15517 newAtom.hidden=0;
15518 newAtom.symmGroup=0;
15519 newAtom.sg=0;
15520 newAtom.scod=555;//the identity
15521 newAtom.sof=0;
15522 newAtom.sof_org=0;
15523 newAtom.screenX=0;
15524 newAtom.screenY=0;
15525 newAtom.afix=0;
15526 int part=0,afix=0;
15527 double part_fvar=11.0;
15528 double uiso=0.05;
15529 int qpeaks=0;
15530 int afixparent=0;
15531 Scatt s(&mole);
15532 //printf("after scatt\n");
15533 QStringList bedeRloneLY;
15534 CEnvironment quickAtoms;
15535 bool fragIgnore=false;
15536 for (int i=0; i<lines.size(); i++){
15537 if (lines.at(i).startsWith(" ")) continue;
15538 if (!lines.at(i).isEmpty()){
15539 newAtom.orginalLine=lines.at(i).section("=",0,0);
15540 lines[i].remove("=");
15541 int cmd=isacommand(lines.at(i).section(leer,0,0));
15542 //qDebug()<<cmd<<lines.at(i);
15543 QString resiSpez=lines.at(i).section(leer,0,0).section('_',1,1);
15544 if (cmd==30) fragIgnore=true;
15545 if (cmd==27) fragIgnore=false;
15546 if (!fragIgnore)
15547 switch (cmd) {
15548 case 1: //AFIX
15549 afix=lines.at(i).section(leer,1,1).toInt();
15550 // For later
15551 //afix_fvar = lines.at(i).section(leer,3,3).toInt();
15552 newAtom.afix=afix;
15553 break;
15554 case 5: {//bind
15555 if (!lines.at(i).section(leer,1,2).contains(buchstaben)){
15556 int pn01=0,pn02=0;
15557 bool ok1,ok2;
15558 pn01=lines.at(i).section(leer,1,1).toInt(&ok1);
15559 pn02=lines.at(i).section(leer,2,2).toInt(&ok2);
15560 if ((ok1)&&(ok2)) mole.bindPart[pn01]=pn02;
15561 if ((ok1)&&(ok2)) mole.bindPart[pn02]=pn01;
15562 }
15563 if (notRefine) break;
15564 MyBind aa;
15565 aa.Lab1=lines.at(i).section(leer,1,1).toUpper();
15566 aa.Lab2=lines.at(i).section(leer,2,2).toUpper();
15567 mole.bindatoms.append(aa);
15568 }
15569 break;
15570 case 9: { //CELL
15571 }
15572 break;
15573 case 10: { // L.S.
15574 ls_cycls = lines.at(i).section(leer, 1, 1).toInt();
15575 }
15576 break;
15577 case 19:{//DISP
15578 QStringList tok = lines.at(i).split(leer,skipEmptyParts);
15579 s.setDISP(tok);
15580 }
15581 break;
15582
15583 case 23:{ //EQIV
15584 mole.decodeSymmCardEQIV(lines.at(i));
15585 }
15586 break;
15587 case 25:{//EXTI
15588 mole.exti=lines.at(i).section(leer,1,1).toDouble();
15589 }
15590 break;
15591 case 31:{//free
15592 MyBind aa;
15593 aa.Lab1=lines.at(i).section(leer,1,1).toUpper();
15594 aa.Lab2=lines.at(i).section(leer,2,2).toUpper();
15595 mole.freeatoms.append(aa);
15596 }
15597 break;
15598 case 32:{ //FVAR
15599 editor->fvMinLine=i;
15600 QStringList tok = lines.at(i).split(leer,skipEmptyParts);
15601 for (int ifv=1; ifv<tok.size();ifv++){
15602 fvar.append(tok.at(ifv).toDouble());
15603 }
15604 if (!fvar.isEmpty()) {
15605 mole.osf=fvar.at(0);
15606 }
15607 }
15608 break;
15609 case 35: //HKLF
15610 {
15611 hklf=true;
15612 QStringList tok = lines.at(i).split(leer,skipEmptyParts);
15613 if (tok.size()>1){
15614 mole.hklf=tok.at(1).toInt();
15615 if (mole.hklf==5){
15616 switch2HKLF5->setVisible(false);
15617 switch2HKLF4->setVisible(true);
15618 }
15619 //printf("HKLF !! %d %d %d\n",mole.hklf,switch2HKLF4->isVisible(),switch2HKLF5->isVisible());
15620 }
15621 if (tok.size()>2)mole.hklScale=tok.at(2).toDouble();
15622 if (tok.size()>11){
15623 mole.hklMat.m11=tok.at(3).toDouble();
15624 mole.hklMat.m12=tok.at(4).toDouble();
15625 mole.hklMat.m13=tok.at(5).toDouble();
15626 mole.hklMat.m21=tok.at(6).toDouble();
15627 mole.hklMat.m22=tok.at(7).toDouble();
15628 mole.hklMat.m23=tok.at(8).toDouble();
15629 mole.hklMat.m31=tok.at(9).toDouble();
15630 mole.hklMat.m32=tok.at(10).toDouble();
15631 mole.hklMat.m33=tok.at(11).toDouble();
15632
15633 }
15634 if (tok.size()>12)mole.hklSigmaScale=tok.at(12).toDouble();
15635 /*printf("HKLF N=%d s:%g \n%g %g %g\n%g %g %g\n%g %g %g\nsm: %g \n",mole.hklf,mole.hklScale ,
15636 mole.hklMat.m11,mole.hklMat.m12,mole.hklMat.m13,
15637 mole.hklMat.m21,mole.hklMat.m22,mole.hklMat.m23,
15638 mole.hklMat.m31,mole.hklMat.m32,mole.hklMat.m33,
15639 mole.hklSigmaScale);
15640 // */
15641
15642 }
15643 break;
15644 case 41: { //LATT
15645 break;
15646 }
15647 case 44: { // CGLS
15648 ls_cycls = lines.at(i).section(leer, 1, 1).toInt();
15649 }
15650 break;
15651 case 50://OMIT
15652 {
15653 QStringList tok = lines.at(i).split(leer,skipEmptyParts);
15654 QRegularExpression num=QRegularExpression("$[A-Za-z]");
15655 if ((tok.size()==3)&&(!tok.at(1).contains(num))&&(!tok.at(2).contains(num))){
15656 //hklOmitSig,hklOmit2th,hklShellLow,hklShellHig
15657 mole.hklOmitSig=tok.at(1).toDouble();
15658 mole.hklOmit2th=tok.at(2).toDouble();
15659 mole.hklShellHig=0.5*mole.cell.wave/sin(mole.hklOmit2th/360.0*M_PI);
15660 }
15661 }
15662 break;
15663 case 51: { //PART n sof
15664 part = lines.at(i).section(leer,1,1).toInt();
15665 // part_fvar stores sof (and fvar) to decide during atom parsing
15666 part_fvar = lines.at(i).section(leer, 2, 2).toDouble();
15667 minp=(minp<part)?minp:part;
15668 maxp=(maxp>part)?maxp:part;
15669 }
15670 break;
15671 case 58: {//RESI
15672 if (lines.at(i).section(leer,1,1).indexOf(startnumbers)!=-1) {
15673 newAtom.resiNr=lines.at(i).section(leer,1,1).toInt();
15674 newAtom.ResiClass=lines.at(i).section(leer,2,2);
15675 } else {
15676 newAtom.resiNr=lines.at(i).section(leer,2,2).toInt();
15677 newAtom.ResiClass=lines.at(i).section(leer,1,1);
15678 }
15679 printf("%s %s %d\n",lines.at(i).section(leer,1,1).toStdString().c_str(),newAtom.ResiClass.toStdString().c_str(),newAtom.resiNr);
15680 break;
15681 }
15682 case 62: { //SFAC
15683 QStringList tok = lines.at(i).split(leer,skipEmptyParts);
15684 if ((tok.size()>4)&&(!tok.at(2).contains(buchstaben))) {
15685 s.setSCAT(tok);
15686 if ((tok.at(2).toDouble()==0)&&((tok.at(3).toDouble()==1))) {
15687 chgl->neutrons=true;
15688 }
15689 editor->sfac.append(mole.getOZ(tok.at(1)));
15690 editor->sfacsmbl.append(tok.at(1));
15691 if (editor->sfac.last()>-2) {
15692 if (tok.at(1)==QString("D")) {
15693 pserbt[110]->show();
15694 //printf("show D\n");
15695 }
15696 else pserbt[editor->sfac.last()+1]->show();
15697 }
15698 sfacBox->setFixedSize((editor->sfacsmbl.size()+1)*52,70);
15699 } else {
15700 for (int isf=1; isf<tok.size();isf++) {
15701 editor->sfac.append(mole.getOZ(tok.at(isf)));
15702 editor->sfacsmbl.append(tok.at(isf));
15703 if (tok.at(isf)==QString("D")) {
15704 pserbt[110]->show();
15705 //printf("show D\n");
15706 }
15707 else {
15708 pserbt[editor->sfac.last()+1]->show();
15709 //printf("!show %d %sw\n",editor->sfac.last(),tok.at(isf).toStdString().c_str());
15710 }
15711 sfacBox->setFixedSize((editor->sfacsmbl.size()+1)*52,70);
15712 }
15713 }
15714 }
15715 break;
15716 case 63:{//shel
15717 //hklOmitSig,hklOmit2th,hklShellLow,hklShellHig
15718 QStringList tok = lines.at(i).split(leer,skipEmptyParts);
15719 if (tok.size()>2){
15720 mole.hklShellLow=tok.at(1).toDouble();
15721 mole.hklShellHig=tok.at(2).toDouble();
15722 // qDebug()<<mole.hklShellLow<<mole.hklShellHig;
15723 }
15724 }break;
15725 case 69:{ //SUMP
15726 QStringList forml= lines.at(i).split(leer);
15727 int fvix=4;
15728 while (forml.size()>fvix){
15729 int m=forml.at(fvix).toInt();
15730 fvarCntr[m]++;
15731 //printf("SUMP m%d fvarCntr=%d\n", m,fvarCntr.value(m));
15732
15733 fvix+=2;
15734 }
15735 }
15736 break;
15737 case 70:{//SWAT g[0] U[2]
15738 mole.swat=0.0;
15739 mole.exti=2.0;
15740 QStringList tok = lines.at(i).split(leer,skipEmptyParts);
15741 if (tok.size()>1) mole.swat=tok.at(1).toDouble();
15742 if (tok.size()>2) mole.exti=tok.at(2).toDouble();
15743 }
15744 break;
15745
15746 case 71: {// SYMM
15747 if (mole.symmCard2Code(lines.at(i).section(" ",1,130)).isEmpty()){
15748 lines.clear();
15749 return false;
15750 }
15751 break;
15752 }
15753 case 75: {// TITL
15754 title = QString ("'%1'@ %2")
15755 .arg(lines.at(i).section(" ",1,30).simplified())
15756 .arg(fn.section('/', -1));
15757 mole.titl=lines.at(i).section(" ",1,-1).simplified();
15758 break;
15759 }
15760 case 78: {// UNIT
15761 editor->unitAlt = lines.at(i) ;
15762 break;
15763 }
15764 case 81: {// WGHT
15765 wghtAct->setEnabled(true);
15766 break;
15767 }
15768 case 82: {// ZERR
15769 mole.cell.Z= lines.at(i);
15770 break;
15771 }
15772 case 103: {// NEUT
15773 // qDebug()<<"Neutrons!";
15774
15775 chgl->neutrons=true;
15776 break;
15777 }
15778 case 105:// BEDE
15779 case 106:{// LONE
15780 bedeRloneLY.append(lines.at(i));
15781 chgl->hideBeLo->setVisible(true);
15782 belocube->setVisible(true);
15783 break;
15784 }
15785 case -1:{//an atom or an error!
15786 newAtom.isIso=false;
15787 newAtom.ufiso_org="";
15788 if (firstAtomLine == 0) {
15789 firstAtomLine = i;
15790 }
15791 if ((newAtom.afix>170)&&((newAtom.afix<180))) break;
15792 QStringList tok = lines.at(i).split(leer,skipEmptyParts);
15793 newAtom.part=part;
15794 if (newAtom.resiNr<0){
15795 newAtom.resiNr=0;
15796 newAtom.ResiClass="";
15797 }
15798 if (tok.size()==7){
15799 // We have an isotropic atom!
15800 if ((newAtom.part!=0)||(newAtom.resiNr!=0)){
15801 newAtom.Label=QString("%1_%3%4")
15802 .arg(tok.at(0))
15803 .arg((newAtom.resiNr)?QString::number(newAtom.resiNr):"")
15804 .arg((newAtom.part)?QString::number((newAtom.part<0)?
15805 36+newAtom.part:
15806 newAtom.part+9,36):"");
15807 } else {
15808 newAtom.Label=tok.at(0);
15809 }
15810 int fac=tok.at(1).toInt()-1;
15811 newAtom.fixFlag=0;
15812
15813 newAtom.an=((fac<0)||(fac>=editor->sfac.size()))?-2:editor->sfac.at(fac);
15814 newAtom.frac.x = getNumber(tok.at(2).toDouble(),fvar,0,newAtom.fixFlag);
15815 newAtom.frac.y = getNumber(tok.at(3).toDouble(),fvar,1,newAtom.fixFlag);
15816 newAtom.frac.z = getNumber(tok.at(4).toDouble(),fvar,2,newAtom.fixFlag);
15817 if (qAbs(part_fvar) > 11.0 ){
15818 // fvar is defined for entire part:
15819 newAtom.sof = getNumber(part_fvar, fvar, 3, newAtom.fixFlag);
15820 newAtom.sof_org = part_fvar;
15821 } else {
15822 // fvar is defined at each atom:
15823 newAtom.sof = getNumber(tok.at(5).toDouble(), fvar, 3, newAtom.fixFlag);
15824 newAtom.sof_org = tok.at(5).toDouble();
15825 }
15826 newAtom.isIso=true;
15827 double uIso = getNumber(tok.at(6).toDouble(),fvar,uiso);
15828 newAtom.uf.m11 = newAtom.uf.m22 = newAtom.uf.m33 = uIso;
15829 newAtom.uf.m32 = newAtom.uf.m23 = uIso * mole.cell.cosra;
15830 newAtom.uf.m31 = newAtom.uf.m13 = uIso * mole.cell.cosrb;
15831 newAtom.uf.m21 = newAtom.uf.m12 = uIso * mole.cell.cosrg;
15832 mole.Uf2Uo(newAtom.uf, newAtom.uc);
15833 newAtom.ufiso_org=tok.at(6);
15834 newAtom.peakHeight=-666;
15835 if (newAtom.an==-66) newAtom.peakHeight=9999.99;
15836 newAtom.afixParent=-1;
15837 if (newAtom.an>0) afixparent=quickAtoms.size();
15838 else newAtom.afixParent=afixparent;
15839 quickAtoms.append(newAtom);
15840 }
15841 if (tok.size()==8) {
15842 // We have a q-peak!
15843 newAtom.Label=tok.at(0);
15844 if (newAtom.Label.startsWith('Q',Qt::CaseInsensitive)) {
15845 newAtom.an=-1;
15846 newAtom.resiNr=-1;
15847 newAtom.ResiClass="Q-Peak";
15848 qpeaks++;
15849 if (!hklf) qbeforehkl=true;
15850 } else {
15851 int fac=tok.at(1).toInt()-1;
15852 newAtom.an=((fac<0)||(fac>=editor->sfac.size()))?-2:editor->sfac.at(fac);
15853 //isoat++;
15854 }
15855 newAtom.fixFlag=0;
15856 newAtom.frac.x = tok.at(2).toDouble();
15857 newAtom.frac.y = tok.at(3).toDouble();
15858 newAtom.frac.z = tok.at(4).toDouble();
15859 if (qAbs(part_fvar) > 11.0 ){
15860 // fvar is defined for entire part:
15861 newAtom.sof = getNumber(part_fvar, fvar, 3, newAtom.fixFlag);
15862 newAtom.sof_org = part_fvar;
15863 } else {
15864 // fvar is defined at each atom:
15865 newAtom.sof = getNumber(tok.at(5).toDouble(), fvar, 3, newAtom.fixFlag);
15866 newAtom.sof_org = tok.at(5).toDouble();
15867 }
15868 newAtom.isIso=true;
15869 double uIso = getNumber(tok.at(6).toDouble(),fvar,uiso);
15870 newAtom.uf.m11 = newAtom.uf.m22 = newAtom.uf.m33 = uIso;
15871 newAtom.uf.m32 = newAtom.uf.m23 = uIso * mole.cell.cosra;
15872 newAtom.uf.m31 = newAtom.uf.m13 = uIso * mole.cell.cosrb;
15873 newAtom.uf.m21 = newAtom.uf.m12 = uIso * mole.cell.cosrg;
15874 newAtom.ufiso_org=tok.at(6);
15875 newAtom.peakHeight=tok.at(7).toDouble();
15876 //printf("##%d %f\n",qpeaks,newAtom.peakHeight);
15877 if(newAtom.an==-1){
15878 mole.pmin=qMin(mole.pmin, newAtom.peakHeight);
15879 mole.pmax=qMax(mole.pmax, newAtom.peakHeight);
15880 }
15881 chgl->qPeakBonds->setVisible(true);
15882
15883 showQPeakLegend->setVisible(true);
15884 newAtom.afixParent=-1;
15885 quickAtoms.append(newAtom);
15886
15887 }
15888 if (tok.size()==12){
15889 // We have an ellipsoid atom!
15890 if ((newAtom.part!=0)||(newAtom.resiNr!=0)){
15891 newAtom.Label=QString("%1_%3%4")
15892 .arg(tok.at(0))
15893 .arg((newAtom.resiNr)?QString::number(newAtom.resiNr):"")
15894 .arg((newAtom.part)?QString::number((newAtom.part<0)?
15895 36+newAtom.part:
15896 newAtom.part+9,36):"");
15897 }else newAtom.Label=tok.at(0);
15898 int fac=tok.at(1).toInt()-1;
15899 newAtom.an=((fac<0)||(fac>=editor->sfac.size()))?-2:editor->sfac.at(fac);
15900 newAtom.frac.x = getNumber(tok.at(2).toDouble(),fvar,0,newAtom.fixFlag);
15901 newAtom.frac.y = getNumber(tok.at(3).toDouble(),fvar,1,newAtom.fixFlag);
15902 newAtom.frac.z = getNumber(tok.at(4).toDouble(),fvar,2,newAtom.fixFlag);
15903 if (qAbs(part_fvar) > 11.0 ){
15904 // fvar is defined for entire part:
15905 newAtom.sof = getNumber(part_fvar, fvar, 3, newAtom.fixFlag);
15906 newAtom.sof_org = part_fvar;
15907 } else {
15908 // fvar is defined at each atom:
15909 newAtom.sof = getNumber(tok.at(5).toDouble(), fvar, 3, newAtom.fixFlag);
15910 newAtom.sof_org = tok.at(5).toDouble();
15911 }
15912 newAtom.uf.m11 = getNumber(tok.at(6).toDouble(),fvar,4,newAtom.fixFlag);
15913 newAtom.uf.m22 = getNumber(tok.at(7).toDouble(),fvar,5,newAtom.fixFlag);
15914 newAtom.uf.m33 = getNumber(tok.at(8).toDouble(),fvar,6,newAtom.fixFlag);
15915 newAtom.uf.m32 = newAtom.uf.m23 = getNumber(tok.at(9).toDouble(),fvar,7,newAtom.fixFlag);
15916 newAtom.uf.m31 = newAtom.uf.m13 = getNumber(tok.at(10).toDouble(),fvar,8,newAtom.fixFlag);
15917 newAtom.uf.m21 = newAtom.uf.m12 = getNumber(tok.at(11).toDouble(),fvar,9,newAtom.fixFlag);
15918 newAtom.peakHeight=-666;
15919 uiso=mole.ueq(newAtom.uf);
15920 if (newAtom.an>0) afixparent=quickAtoms.size();
15921 newAtom.afixParent=-1;
15922 quickAtoms.append(newAtom);
15923 //adpat++;
15924 }
15925 }
15926 break;
15927 }
15928
15929
15930 }
15931
15932 }
15933 int lnrr=0;
15934 CEnvironment belo;
15935 //printf("belo: %d\n",bedeRloneLY.size());
15936 for (int bl=0; bl<bedeRloneLY.size(); bl++){
15937 int ignore=0;
15938 QStringList tok = bedeRloneLY.at(bl).split(leer,skipEmptyParts);
15939 //printf("belo: %s\n",tok.at(0).toStdString().c_str());
15940 if ((tok.at(0).endsWith("BEDE",Qt::CaseInsensitive))&&(tok.size()>6)){
15941 lnrr=belo.size();
15942 QString aton1=tok.at(1),aton2=tok.at(2);
15943 double rad = getNumber(tok.at(3).toDouble(),fvar,0,ignore);
15944 double a = getNumber(tok.at(4).toDouble(),fvar,0,ignore);
15945 double b1 = getNumber(tok.at(5).toDouble(),fvar,0,ignore);
15946 double b2 = getNumber(tok.at(6).toDouble(),fvar,0,ignore);
15947 newAtom.an=-42;
15948 newAtom.symmGroup=0;
15949 newAtom.sg=0;
15950 newAtom.scod=555;//the identity
15951 newAtom.auidx=-1;
15952 int an1=-1,an2=-2;
15953 for (int bl1=0; bl1<mole.asymm.size(); bl1++)
15954 for (int bl2=0; bl2<mole.asymm.size(); bl2++){
15955 if ((mole.asymm.at(bl1).an<0)||(mole.asymm.at(bl2).an<0)) continue;
15956 double soll=-1,d= sqrt(Distance(mole.asymm.at(bl1).pos,mole.asymm.at(bl2).pos));
15957 if ((mole.asymm.at(bl1).an==0)&&(mole.asymm.at(bl2).an==0)) continue;
15958 if ((mole.asymm.at(bl1).an>-1)&&(mole.asymm.at(bl2).an>-1)&&
15959 ((!mole.asymm.at(bl1).part)||(!mole.asymm.at(bl2).part)||(mole.asymm.at(bl1).part==mole.asymm.at(bl2).part)))
15960 soll=(mole.Kovalenz_Radien[mole.asymm.at(bl1).an]+ mole.Kovalenz_Radien[mole.asymm.at(bl2).an])*0.012;
15961 else
15962 soll=-1;
15963 if ((d>0.1)&&(d<soll)) {
15964 an1=-1;
15965 an2=-2;
15966 if (aton1[0]=='$') an1=mole.getOZ(aton1);
15967 if (aton2[0]=='$') an2=mole.getOZ(aton2);
15968 if (((an1>=0)&&(mole.asymm.at(bl1).an==an1))||(aton1==mole.asymm.at(bl1).Label.section('_',0,0)))
15969 if (((an2>=0)&&(mole.asymm.at(bl2).an==an2))||(aton2==mole.asymm.at(bl2).Label.section('_',0,0))){
15970 V3 pos = mole.asymm.at(bl1).pos+Normalize(mole.asymm.at(bl2).pos-mole.asymm.at(bl1).pos)*rad;
15971 newAtom.pos=pos;
15972 mole.kart2frac(pos,pos);
15973 newAtom.Label=QString("L%1").arg(++lnrr);
15974 newAtom.frac=pos;
15975 newAtom.peakHeight=b1;
15976 newAtom.sof=a;
15977 newAtom.auidx=-1;
15978 newAtom.uf=mole.u2b(mole.asymm.at(bl1).uf);//posible problem if U is not anisotrop
15979 belo.append(newAtom);
15980 pos=mole.asymm.at(bl1).frac;
15981 newAtom.Label=QString("L%1").arg(++lnrr);
15982 newAtom.frac=mole.asymm.at(bl1).frac;
15983 mole.frac2kart(newAtom.frac,newAtom.pos);
15984 newAtom.sof=-a;
15985 newAtom.peakHeight=b2;
15986 belo.append(newAtom);
15987
15988 mole.lmin=qMin(mole.lmin,-a);
15989 mole.lmax=qMax(mole.lmax, a);
15990
15991 }
15992 }
15993 }
15994
15995 }else
15996 if (tok.at(0).endsWith("LONE",Qt::CaseInsensitive)){
15997 belo.append(lonesome(bedeRloneLY.at(bl),belo.size()+1));
15998 }
15999 }
16000 if (!belo.isEmpty()) {
16001 for (int bl=0; bl<belo.size(); bl++){
16002 belo[bl].orginalLine=QString("%1 2 %2 %3 %4").arg(belo.at(bl).Label.section('_',0,0),-4)
16003 .arg(belo.at(bl).frac.x,10,'f',5)
16004 .arg(belo.at(bl).frac.y,10,'f',5)
16005 .arg(belo.at(bl).frac.z,10,'f',5);
16006 }
16007 quickAtoms.append(belo);
16008 }
16009 //printf("qck %d au %d\n",quickAtoms.size(),mole.asymm.size());
16010 for (int i=0;i<quickAtoms.size();i++){
16011 mole.Uf2Uo(quickAtoms.at(i).uf,quickAtoms[i].uc);
16012 mole.frac2kart(quickAtoms.at(i).frac,quickAtoms[i].pos);
16013 }
16014 if (quickAtoms.size()>mole.asymm.size()){
16015 int osiz=mole.asymm.size();
16016 for (int k=osiz;k<quickAtoms.size();k++){
16017 mole.showatoms.insert(k,quickAtoms[k]);
16018 }
16019 }
16020 //printf("qck %d au %d\n",quickAtoms.size(),mole.asymm.size());
16021 if (quickAtoms.size()<mole.asymm.size()){
16022 mole.asymm.clear();
16023 quickAtoms.clear();
16024 //printf("number of atoms differs too much!\n");
16025 lines.clear();
16026 return false;
16027 }
16028 mole.asymm.clear();
16029 for (int i=0; i<quickAtoms.size(); i++){
16030 mole.asymm.append(quickAtoms[i]);
16031 }
16032 //mole.asymm=quickAtoms;
16033 //printf("X-\n");
16034 for (int i=0; i<mole.showatoms.size(); i++){
16035 int idx=0;
16036 if ((mole.showatoms.at(i).auidx<0)||(mole.showatoms.at(i).auidx>quickAtoms.size())){
16037 idx=i;
16038 /* printf("AU:%s=%s %d=%d %f %f %f %f %f %f\n",mole.showatoms.at(i).Label.toStdString().c_str(),quickAtoms.at(idx).Label.toStdString().c_str(),
16039 mole.showatoms.at(i).scod,quickAtoms.at(i).scod,
16040 mole.showatoms.at(i).pos.x,mole.showatoms.at(i).pos.y,mole.showatoms.at(i).pos.z,
16041 quickAtoms.at(i).pos.x,quickAtoms.at(i).pos.y,quickAtoms.at(i).pos.z
16042 );*/
16043 }
16044 else idx=mole.showatoms.at(i).auidx;
16045 if (idx>=quickAtoms.size()) continue;
16046 //printf("quickAtoms %s %d %d %d %d %s\n",mole.showatoms.at(i).Label.toStdString().c_str(),i,idx,quickAtoms.size(),mole.showatoms.size(),quickAtoms.at(idx).Label.toStdString().c_str());
16047 V3 actpos = mole.applySymCode(quickAtoms.at(idx).frac,mole.showatoms.at(i).scod);
16048 //printf("#%-4d %d %d %d %d %g\n",i,mole.showatoms.at(i).symmGroup,mole.showatoms.at(i).sg,mole.showatoms.at(i).scod,mole.showatoms.at(i).hidden,Distance(actpos,mole.showatoms.at(i).frac));
16049 mole.showatoms[i].frac = actpos;
16050 mole.showatoms[i].isIso = quickAtoms.at(idx).isIso;
16051 if (mole.showatoms.at(i).scod==555){
16052 mole.showatoms[i].orginalLine = quickAtoms.at(idx).orginalLine;
16053 mole.showatoms[i].Label = quickAtoms.at(idx).Label;
16054 }
16055 //printf("tick %d scod%d %d %d\n",__LINE__,mole.showatoms.at(i).scod,i,idx);
16056 ///printf("%f %f\n",mole.showatoms[i].peakHeight , quickAtoms.at(idx).peakHeight);
16057 if (quickAtoms[idx].an>=0){
16058 mole.USymCode(quickAtoms[idx].uf,mole.showatoms.at(i).scod,mole.showatoms[i].uf);
16059 //printf("tick %d\n",__LINE__);
16060 mole.Uf2Uo(mole.showatoms[i].uf,mole.showatoms[i].uc);
16061 }
16062 mole.showatoms[i].peakHeight = quickAtoms.at(idx).peakHeight;
16063 //printf("tick %d\n",__LINE__);
16064 mole.showatoms[i].part = quickAtoms.at(idx).part;
16065 mole.showatoms[i].an = quickAtoms.at(idx).an;
16066 //printf("tick %d\n",__LINE__);
16067 mole.showatoms[i].resiNr= quickAtoms.at(idx).resiNr;
16068 //printf("tick %d\n",__LINE__);
16069 mole.showatoms[i].auidx = idx;
16070 //printf("tick %d\n",__LINE__);
16071 mole.showatoms[i].sof = quickAtoms.at(idx).sof;
16072 //printf("tick %d\n",__LINE__);
16073 mole.showatoms[i].sof_org = quickAtoms.at(idx).sof_org;
16074 //printf("tick %d\n",__LINE__);
16075 mole.showatoms[i].screenX = quickAtoms.at(idx).screenX;
16076 //printf("tick %d\n",__LINE__);
16077 mole.showatoms[i].screenY = quickAtoms.at(idx).screenY;
16078 //printf("tick %d\n",__LINE__);
16079 mole.showatoms[i].afix = quickAtoms.at(idx).afix;
16080 //printf("tick %d\n",__LINE__);
16081 mole.frac2kart(actpos,mole.showatoms[i].pos);
16082 //printf("tick %d\n",__LINE__);
16083 }
16084 //printf("x\n");
16085
16086 chgl->shpm1->setVisible(false);
16087 chgl->highlightParts->setVisible(false);
16088 if (minp<0) {
16089 chgl->shpm1->setVisible(true);
16090 chgl->highlightParts->setVisible(true);
16091 }
16092 if (maxp>0) chgl->highlightParts->setVisible(true);
16093 mole.qbeforehkl=qbeforehkl;
16094 actionUniq->setDisabled(mole.qbeforehkl);
16095 QString info;
16096 for (int ifv=0; ifv<fvar.size();ifv++){
16097 if (ifv==0) {
16098 info.append("OSF: ");
16099 info.append(QString("<font color=red>%1</font>").arg(fvar.at(ifv)));
16100 }
16101 else {
16102 info.append(QString("FVAR<font color=blue>%1</font>: ").arg(ifv+1));
16103 if (fvarCntr.value(ifv+1)<1)info.append(QString("<font color=red>%1</font>(Never Used!)").arg(fvar.at(ifv)));
16104 else info.append(QString("<font color=red>%1</font>(used %2 time%3.)").arg(fvar.at(ifv))
16105 .arg(fvarCntr.value(ifv+1)).arg((fvarCntr.value(ifv+1)>1)?"s":""));
16106 }
16107 if ((ifv+1)<fvar.size()) info.append(", ");
16108 info.append("<br>");
16109 }
16110 fvarinfo=QString("<b>Free variables:</b> %1").arg(info);
16111 qpv->setMin(mole.pmin);
16112 qpv->setMax(mole.pmax);
16113 //printf("%f %f\n",mole.pmin,mole.pmax);
16114
16115 qpv->update();
16116 for (int i=0; i<mole.showatoms.size(); i++){
16117 if (mole.showatoms.at(i).an!=-1) continue;
16118 if (mole.showatoms.at(i).peakHeight>mole.pmax) {printf("remove q %d %d %s %f %f max\n",i,mole.showatoms.at(i).an,mole.showatoms.at(i).Label.toStdString().c_str(),mole.showatoms.at(i).peakHeight,mole.pmax); mole.showatoms.removeAt(i); i--; i=(i<0)?0:i;}
16119 }
16120 for (int i=0; i<mole.showatoms.size(); i++){
16121 if (mole.showatoms.at(i).an!=-1) continue;
16122 if (mole.showatoms.at(i).peakHeight<mole.pmin) {printf("remove q %d %d %s %f %f min\n",i,mole.showatoms.at(i).an,mole.showatoms.at(i).Label.toStdString().c_str(),mole.showatoms.at(i).peakHeight,mole.pmin); mole.showatoms.removeAt(i); i--; i=(i<0)?0:i;}
16123 }
16124 updateStatusBar("finding bonds...");
16125 mole.showbonds.clear();
16126 mole.showbonds = mole.connecting(mole.showatoms);
16127 if (qpeaks) qPeakDock->show();
16128 //QTime zeit; zeit.start();
16129 //printf("MAPS?\n");
16130 fxle->resDir=QDir(fn);
16131 fxle->fouName=(fxle->MYFCF)?s.myfcf(fn):"";
16132 if (fxle->fouName.isEmpty()){
16133 fxle->fouName=fn;
16134 fxle->fouName.chop(4);
16135 fxle->fouName.append(".fcf");
16136 }
16137
16138 if ((fxle->doMaps->isChecked())&& (!fxle->loadFouAndPerform(fxle->fouName.toLocal8Bit()))) {
16139 if (fxle->doMaps->isChecked()) infoKanalNews(QString("<font color=red>Error while loading %1!</font><br>").arg(fxle->fouName));
16140
16141 //printf("%d\n",__LINE__);
16142 fxle->killmaps();
16143 //printf("%d\n",__LINE__);
16144 fxle->n1=fxle->n2=fxle->n3=fxle->n5=0;
16145 }
16146 if (fxle->doMaps->isChecked()){
16147 fxle->mapcontrol->setVisible(true);
16148 }
16149 fxle->doMaps->show();
16150 //printf("MAPS!\n");
16151 QString listName=fn;
16152 listName.replace(punktins,".lst");
16153 listName.replace(punktres,".lst");
16154 QFile lstf(listName);
16155 if (lstf.open(QIODevice::ReadOnly|QIODevice::Text)){
16156 QString liste=QString(lstf.readAll());
16157 while (liste.contains(QRegularExpression("\n\\s+REM"))) liste=liste.replace(QRegularExpression("\n\\s+REM[^\n]*\n",QRegularExpression::CaseInsensitiveOption),"\n");
16158 if (liste.contains("Flack x parameter =")){
16159 QString flackS=liste.section("Flack x parameter =",1).section('\n',0,0);
16160 double flackX=flackS.split(leer,skipEmptyParts).first().toDouble();
16161 double flackXesd=flackS.split(leer,skipEmptyParts).last().toDouble();
16162 infoKanalNews(QString("SHELXL-list file reports <b>Flack</b> x parameter:<b> %1 &plusmn; %2</b>").arg(flackX).arg(flackXesd));
16163 }
16164 //Flack x =
16165 if (liste.contains("Flack x =")) {
16166 QString flackS=liste.section("\n Flack x = ",1).section('\n',0,1);
16167 QString flackX = "";
16168 // prevent crash from empty flackS:
16169 if (flackS.split(leer,skipEmptyParts).length() > 0) {
16170 flackX=flackS.split(leer,skipEmptyParts).first();
16171 }
16172 QString parsonsZ=flackS.section('\n',1,1);
16173 if (parsonsZ.isEmpty() && !flackX.isEmpty()) {
16174 infoKanalNews(QString("SHELXL-list file reports <b>Flack</b> x parameter:<b> %1 </b>").arg(flackX));
16175 }
16176 if (!parsonsZ.isEmpty() && !flackX.isEmpty()) {
16177 parsonsZ=parsonsZ.split(leer,skipEmptyParts).first();
16178 infoKanalNews(QString("SHELXL-list file reports <br><b>Flack</b> x parameter:<b> %1 </b><br><b>Parsons</b> parameter:<b> %2</b>")
16179 .arg(flackX).arg(parsonsZ));
16180 }
16181 }
16182 lstf.close();
16183 }
16184 QMap<QString,double> unit;
16185 for (int i=0; i<mole.asymm.size(); i++){
16186 QStringList ol = mole.asymm.at(i).orginalLine.split(' ',skipEmptyParts,Qt::CaseInsensitive);
16187 QString smbl="!!";
16188 if (ol.size()>1) smbl=editor->sfacsmbl.at(ol.at(1).toInt());
16189 if (mole.asymm.at(i).an>=0) {
16190 unit[smbl]+= mole.asymm.at(i).sof * mole.cell.symmops.size();
16191 //printf("%s %f ;-)\n",smbl.toStdString().c_str(),unit.value(smbl));
16192 }
16193 }
16194 editor->unitNeu="UNIT";
16195 for (int i = 0; i < editor->sfacsmbl.size() ; i++){
16196 if (unit.value(editor->sfacsmbl.at(i))>9999)
16197 editor->unitNeu.append(QString(" %1").arg((int)unit.value(editor->sfacsmbl.at(i)))); else
16198 editor->unitNeu.append(QString(" %1").arg(unit.value(editor->sfacsmbl.at(i)),0,'g'));
16199 if (editor->unitNeu.split('\n').last().size()>76) editor->unitNeu.append("=\n ");
16200 }
16201 //printf("EX %d\n",__LINE__);
16202 //return false;
16203 return true;
16204 }
16205
16206 void Window::load_sheldrick(QString fileName, QString &inhalt){
16207 //! Parses the SHELX res/ins file into data structures.
16208 if (quickReLoadButton->isChecked())if (quickReLoad(fileName, inhalt)) return;// if quickreload works then here is nothing to do
16209 //printf("%d\n",__LINE__);
16210 fxle->killmaps();
16211 //printf("%d\n",__LINE__);
16212 fxle->n5=0;
16213 symmElementsAct->setChecked(false);
16214 symmElements(false);
16215 mole.newstructure();
16216 switch2HKLF4->setVisible(false);
16217 chgl->showHidden();
16218 machPlatz=false;
16219 chgl->neutrons=false;
16220 static QString maidenName="";
16221 infoKanal->clear();
16222 shxEditorDock->show();
16223 wghtAct->setEnabled(false);
16224 QString problem;
16225 qPeakDock->hide();
16226
16227 int minp=1,maxp=0;
16228 bool qbeforehkl=false,hklf=false;
16229 enterRenameMode->setVisible(true);
16230 chgl->qPeakBonds->setVisible(false);
16231 chgl->shpm1->setVisible(false);
16232 chgl->hideHydrogen->setVisible(false);
16233 chgl->hideBeLo->setVisible(false);
16234 belocube->setVisible(false);
16235 mole.cell.symmops.clear();
16236 mole.cell.trans.clear();
16237 mole.asymm.clear();
16238 mole.sdm.clear();
16239 mole.showbonds.clear();
16240 mole.showatoms.clear();
16241 mole.selectedatoms.clear();
16242
16243 mole.lbonds.clear();
16244 mole.envi_sdm.clear();
16245 mole.contact.clear();
16246 mole.envi_sdm.clear();
16247 mole.contact.clear();
16248 mole.symmopsEQIV.clear();
16249 mole.labelEQIV.clear();
16250 mole.transEQIV.clear();
16251 mole.freeatoms.clear();
16252 mole.bindatoms.clear();
16253 for (int i=0; i<mole.knoepfe.size();i++) mole.knoepfe[i].neighbors.clear();
16254 mole.knoepfe.clear();
16255 mole.showbonds.clear();
16256 mole.selectedatoms.clear();
16257 chgl->updateBondActions();
16258 mole.showatoms.clear();
16259 V3 nl(0,0,0);
16260 QStringList bedeRloneLY;
16261 mole.cell.trans.append(nl);
16262 mole.cell.symmops.append(Matrix(1,0,0, 0,1,0, 0,0,1));
16263 mole.pmin=10000;
16264 mole.pmax=-10000;
16265 mole.lmin=10000;
16266 mole.lmax=-10000;
16267 firstAtomLine = 0;
16268 ls_cycls = 0;
16269 editor->fvMinLine = 0; // otherwise it does not recognize a moving fvar line
16270 MyAtom newAtom;
16271 newAtom.part=0;
16272 newAtom.resiNr=0;
16273 newAtom.hidden=0;
16274 newAtom.symmGroup=0;
16275 newAtom.sg=0;
16276 newAtom.scod=555;//the identity
16277 newAtom.auidx=-1;
16278 newAtom.sof=0;
16279 newAtom.sof_org=0;
16280 newAtom.screenX=0;
16281 newAtom.screenY=0;
16282 newAtom.afix=0;
16283 //bool virg=true;
16284 if (maidenName!=fileName) {
16285 labelIndex=1;
16286 nextLabel="C1";
16287 labelPSE="C";
16288 pserbt[6]->setChecked(true);
16289 renamDock->hide();
16290 updateLabel();
16291 }else{
16292 //virg=false;
16293 }
16294 maidenName=fileName;
16295 int part=0,afix=0;
16296 double part_fvar=11.0;
16297 double uiso=0.05;
16298 int lattice=1;
16299 //int isoat=0,
16300 int adpat=0,qpeaks=0;
16301 int afixparent=0;
16302 mole.exti=-666.0;
16303 mole.swat=-666.0;
16304 editor->sfac.clear();
16305 editor->sfacsmbl.clear();
16306 fvar.clear();
16307 chgl->sfacMenu->clear();
16308 chgl->selSfacMenu->clear();
16309 MyAtom xda;
16310 xda.symmGroup=0;
16311 xda.sg=0;
16312 xda.scod=555;//the identity
16313 xda.auidx=-1;
16314 xda.hidden=0;
16315 xda.isIso=false;
16316 xda.part=0;
16317 xda.Label="H";
16318 xda.pos.x=-2.75;
16319 xda.pos.y=-6.8;
16320 xda.pos.z=0;
16321 xda.an=5;
16322 xda.peakHeight=0.02;
16323 xda.uc=Matrix(
16324 0.01773,-0.00303, 0.00266,
16325 -0.00303, 0.01456, 0.00172,
16326 0.00266, 0.00172, 0.01110);
16327 mole.legendAtoms.clear();
16328 //
16329 mole.osf=0.0;
16330 mole.hklScale=mole.hklSigmaScale=1.0;
16331 mole.hklMat=Matrix(1,0,0,0,1,0,0,0,1);
16332 mole.hklOmitSig=-2;
16333 mole.hklOmit2th=180.0;
16334 mole.hklShellLow=99999.0;
16335 mole.hklShellHig=0.0;
16336 fvarCntr.clear();
16337 mole.transEQIV.clear();
16338 mole.symmopsEQIV.clear();
16339 mole.labelEQIV.clear();
16340 mole.freeatoms.clear();
16341 mole.bindatoms.clear();
16342 mole.envi_sdm.clear();
16343 mole.bindPart.clear();
16344 Scatt s(&mole);
16345 editor->easf.clear();
16346 editor->easf = s.loadElectronScatteringFactors();
16347 editor->xasf.clear();
16348
16349 editor->xasf =s.loadXRayScatteringFactors();
16350 chgl->labs.clear();
16351 chgl->enviPositions.clear();
16352 for (int i=1; i<109; i++) pserbt[i]->hide();
16353 pserbt[110]->hide();
16354 if (notRefine) lattice=-1;
16355 // Disabled SkipEmptyParts because otherwise i is not in sync with the line number!
16356 QStringList lines = inhalt.split(QRegularExpression("[\\r\\n]")); //,skipEmptyParts);
16357 bool fragIgnore=false;
16358 for (int i=0; i<lines.size(); i++){
16359 if (lines.at(i).startsWith(" ")) continue;
16360 if (!lines.at(i).isEmpty()){
16361 newAtom.orginalLine=lines.at(i).section("=",0,0);
16362 lines[i].remove("=");
16363 int cmd=isacommand(lines.at(i).section(leer,0,0));
16364 //qDebug()<<cmd<<lines.at(i);
16365 QString resiSpez=lines.at(i).section(leer,0,0).section('_',1,1);
16366 if (cmd==30) fragIgnore=true;
16367 if (cmd==27) fragIgnore=false;
16368 if (!fragIgnore)
16369 switch (cmd) {
16370 case 1: //AFIX
16371 afix=lines.at(i).section(leer,1,1).toInt();
16372 // For later
16373 //afix_fvar = lines.at(i).section(leer,3,3).toInt();
16374 newAtom.afix=afix;
16375 break;
16376 case 5: {//bind
16377 if (!lines.at(i).section(leer,1,2).contains(buchstaben)){
16378 int pn01=0,pn02=0;
16379 bool ok1,ok2;
16380 pn01=lines.at(i).section(leer,1,1).toInt(&ok1);
16381 pn02=lines.at(i).section(leer,2,2).toInt(&ok2);
16382 if ((ok1)&&(ok2)) mole.bindPart[pn01]=pn02;
16383 if ((ok1)&&(ok2)) mole.bindPart[pn02]=pn01;
16384 }
16385 if (notRefine) break;
16386 MyBind aa;
16387 aa.Lab1=lines.at(i).section(leer,1,1).toUpper();
16388 aa.Lab2=lines.at(i).section(leer,2,2).toUpper();
16389 mole.bindatoms.append(aa);
16390 }
16391 break;
16392 case 9: { //CELL
16393 CurrentCellString=lines.at(i);
16394 mole.cell.wave = lines.at(i).section(leer,1,1).toDouble();
16395 mole.cell.a = lines.at(i).section(leer,2,2).toDouble();
16396 mole.cell.b = lines.at(i).section(leer,3,3).toDouble();
16397 mole.cell.c = lines.at(i).section(leer,4,4).toDouble();
16398 mole.cell.al= lines.at(i).section(leer,5,5).toDouble();
16399 mole.cell.be = lines.at(i).section(leer,6,6).toDouble();
16400 mole.cell.ga = lines.at(i).section(leer,7,7).toDouble();
16401 mole.cellSetup();
16402 }
16403 break;
16404 case 10: { // L.S.
16405 ls_cycls = lines.at(i).section(leer, 1, 1).toInt();
16406 }
16407 break;
16408 case 19:{//DISP
16409 QStringList tok = lines.at(i).split(leer,skipEmptyParts);
16410 s.setDISP(tok);
16411 }
16412 break;
16413
16414 case 23:{ //EQIV
16415 mole.decodeSymmCardEQIV(lines.at(i));
16416 }
16417 break;
16418 case 25:{//EXTI
16419 mole.exti=lines.at(i).section(leer,1,1).toDouble();
16420 }
16421 break;
16422 case 31:{//free
16423 MyBind aa;
16424 aa.Lab1=lines.at(i).section(leer,1,1).toUpper();
16425 aa.Lab2=lines.at(i).section(leer,2,2).toUpper();
16426 mole.freeatoms.append(aa);
16427 }
16428 break;
16429 case 32:{ //FVAR
16430 editor->fvMinLine=i;
16431 QStringList tok = lines.at(i).split(leer,skipEmptyParts);
16432 for (int ifv=1; ifv<tok.size();ifv++){
16433 fvar.append(tok.at(ifv).toDouble());
16434 }
16435 if (!fvar.isEmpty()) {
16436 mole.osf=fvar.at(0);
16437 }
16438 }
16439 break;
16440 case 35: //HKLF
16441 {
16442 hklf=true;
16443 newAtom.afix=afix=0;
16444 part=0;
16445 newAtom.resiNr=0;
16446 newAtom.ResiClass="";
16447 part_fvar=0.0;
16448
16449 QStringList tok = lines.at(i).split(leer,skipEmptyParts);
16450 if (tok.size()>1){
16451 mole.hklf=tok.at(1).toInt();
16452 if (mole.hklf==5){
16453 switch2HKLF5->setVisible(false);
16454 switch2HKLF4->setVisible(true);
16455 }
16456 //printf("HKLF !! %d %d %d\n",mole.hklf,switch2HKLF4->isVisible(),switch2HKLF5->isVisible());
16457 }
16458 if (tok.size()>2)mole.hklScale=tok.at(2).toDouble();
16459 if (tok.size()>11){
16460 mole.hklMat.m11=tok.at(3).toDouble();
16461 mole.hklMat.m12=tok.at(4).toDouble();
16462 mole.hklMat.m13=tok.at(5).toDouble();
16463 mole.hklMat.m21=tok.at(6).toDouble();
16464 mole.hklMat.m22=tok.at(7).toDouble();
16465 mole.hklMat.m23=tok.at(8).toDouble();
16466 mole.hklMat.m31=tok.at(9).toDouble();
16467 mole.hklMat.m32=tok.at(10).toDouble();
16468 mole.hklMat.m33=tok.at(11).toDouble();
16469
16470 }
16471 if (tok.size()>12)mole.hklSigmaScale=tok.at(12).toDouble();
16472 /* printf("HKLF N=%d s:%g \n%g %g %g\n%g %g %g\n%g %g %g\nsm: %g \n",mole.hklf,mole.hklScale ,
16473 mole.hklMat.m11,mole.hklMat.m12,mole.hklMat.m13,
16474 mole.hklMat.m21,mole.hklMat.m22,mole.hklMat.m23,
16475 mole.hklMat.m31,mole.hklMat.m32,mole.hklMat.m33,
16476 mole.hklSigmaScale);*/
16477
16478 }
16479 break;
16480 case 41: { //LATT
16481 lattice=lines.at(i).section(leer,1,1).toInt();
16482 break;
16483 }
16484 case 44: { // CGLS
16485 ls_cycls = lines.at(i).section(leer, 1, 1).toInt();
16486 }
16487 break;
16488 case 50://OMIT
16489 {
16490 QStringList tok = lines.at(i).split(leer,skipEmptyParts);
16491 QRegularExpression num=QRegularExpression("$[A-Za-z]");
16492 if ((tok.size()==3)&&(!tok.at(1).contains(num))&&(!tok.at(2).contains(num))){
16493 //hklOmitSig,hklOmit2th,hklShellLow,hklShellHig
16494 mole.hklOmitSig=tok.at(1).toDouble();
16495 mole.hklOmit2th=tok.at(2).toDouble();
16496 mole.hklShellHig=0.5*mole.cell.wave/sin(mole.hklOmit2th/360.0*M_PI);
16497 }
16498 }
16499 break;
16500 case 51: { //PART n sof
16501 part = lines.at(i).section(leer,1,1).toInt();
16502 // part_fvar stores sof (and fvar) to decide during atom parsing
16503 part_fvar = lines.at(i).section(leer, 2, 2).toDouble();
16504 minp=(minp<part)?minp:part;
16505 maxp=(maxp>part)?maxp:part;
16506 }
16507 break;
16508 case 58: {//RESI
16509 if (lines.at(i).section(leer,1,1).indexOf(startnumbers)!=-1) {
16510 newAtom.resiNr=lines.at(i).section(leer,1,1).toInt();
16511 newAtom.ResiClass=lines.at(i).section(leer,2,2);
16512 } else {
16513 newAtom.resiNr=lines.at(i).section(leer,2,2).toInt();
16514 newAtom.ResiClass=lines.at(i).section(leer,1,1);
16515 }
16516 //printf("RESI %s %s %d\n",lines.at(i).section(leer,1,1).toStdString().c_str(),newAtom.ResiClass.toStdString().c_str(),newAtom.resiNr);
16517 break;
16518 }
16519 case 62: { //SFAC
16520 QStringList tok = lines.at(i).split(leer,skipEmptyParts);
16521 if ((tok.size()>4)&&(!tok.at(2).contains(buchstaben))) {
16522 s.setSCAT(tok);
16523 if ((tok.at(2).toDouble()==0)&&((tok.at(3).toDouble()==1))) {
16524 chgl->neutrons=true;
16525 }
16526 editor->sfac.append(mole.getOZ(tok.at(1)));
16527 editor->sfacsmbl.append(tok.at(1));
16528 if (editor->sfac.last()>-2) {
16529 if (tok.at(1)==QString("D")) {
16530 pserbt[110]->show();
16531 //printf("show D\n");
16532 }
16533 else pserbt[editor->sfac.last()+1]->show();
16534 }
16535 sfacBox->setFixedSize((editor->sfacsmbl.size()+1)*52,70);
16536 } else {
16537 for (int isf=1; isf<tok.size();isf++) {
16538 editor->sfac.append(mole.getOZ(tok.at(isf)));
16539 editor->sfacsmbl.append(tok.at(isf));
16540 if (tok.at(isf)==QString("D")) {
16541 pserbt[110]->show();
16542 //printf("show D\n");
16543 }
16544 else {
16545 pserbt[editor->sfac.last()+1]->show();
16546 //printf("!show %d %sw\n",editor->sfac.last(),tok.at(isf).toStdString().c_str());
16547 }
16548 sfacBox->setFixedSize((editor->sfacsmbl.size()+1)*52,70);
16549 }
16550 }
16551 }
16552 break;
16553 case 63:{//shel
16554 //hklOmitSig,hklOmit2th,hklShellLow,hklShellHig
16555 QStringList tok = lines.at(i).split(leer,skipEmptyParts);
16556 if (tok.size()>2){
16557 mole.hklShellLow=tok.at(1).toDouble();
16558 mole.hklShellHig=tok.at(2).toDouble();
16559 // qDebug()<<mole.hklShellLow<<mole.hklShellHig;
16560 }
16561 }break;
16562 case 69:{ //SUMP
16563 QStringList forml= lines.at(i).split(leer);
16564 int fvix=4;
16565 while (forml.size()>fvix){
16566 int m=forml.at(fvix).toInt();
16567 fvarCntr[m]++;
16568 //printf("SUMP m%d fvarCntr=%d\n", m,fvarCntr.value(m));
16569 fvix+=2;
16570 }
16571 }
16572 break;
16573 case 70:{
16574 //SWAT g[0] U[2]
16575 mole.swat=0.0;
16576 mole.exti=2.0;
16577 QStringList tok = lines.at(i).split(leer,skipEmptyParts);
16578 if (tok.size()>1) mole.swat=tok.at(1).toDouble();
16579 if (tok.size()>2) mole.exti=tok.at(2).toDouble();
16580 }
16581 break;
16582
16583 case 71: {// SYMM
16584 mole.decodeSymmCard(lines.at(i).section(" ",1,130));
16585 break;
16586 }
16587 case 75: {// TITL
16588 title = QString ("'%1'@ %2")
16589 .arg(lines.at(i).section(" ",1,30).simplified())
16590 .arg(fileName.section('/', -1));
16591 mole.titl=lines.at(i).section(" ",1,-1).simplified();
16592 break;
16593 }
16594 case 78: {// UNIT
16595 editor->unitAlt = lines.at(i) ;
16596 mole.applyLatticeCentro(lattice);
16597
16598 break;
16599 }
16600 case 81: {// WGHT
16601 wghtAct->setEnabled(true);
16602 break;
16603 }
16604 case 82: {// ZERR
16605 mole.cell.Z= lines.at(i);
16606 break;
16607 }
16608 case 103: {// NEUT
16609 // qDebug()<<"Neutrons!";
16610
16611 chgl->neutrons=true;
16612 break;
16613 }
16614 case 105:// BEDE
16615 case 106:{// LONE
16616 bedeRloneLY.append(lines.at(i));
16617 chgl->hideBeLo->setVisible(true);
16618 belocube->setVisible(true);
16619 break;
16620 }
16621 case -1:{//an atom or an error!
16622 newAtom.isIso=false;
16623 newAtom.ufiso_org="";
16624 if (firstAtomLine == 0) {
16625 firstAtomLine = i;
16626 }
16627 if ((newAtom.afix>170)&&((newAtom.afix<180))) break;
16628 QStringList tok = lines.at(i).split(leer,skipEmptyParts);
16629 newAtom.part=part;
16630 if (newAtom.resiNr<0){
16631 newAtom.resiNr=0;
16632 newAtom.ResiClass="";
16633 }
16634 if (tok.size()==7){
16635 // We have an isotropic atom!
16636 if ((newAtom.part!=0)||(newAtom.resiNr!=0)){
16637 newAtom.Label=QString("%1_%3%4")
16638 .arg(tok.at(0))
16639 .arg((newAtom.resiNr)?QString::number(newAtom.resiNr):"")
16640 .arg((newAtom.part)?QString::number((newAtom.part<0)?
16641 36+newAtom.part:
16642 newAtom.part+9,36):"");
16643 } else {
16644 newAtom.Label=tok.at(0);
16645 }
16646 int fac=tok.at(1).toInt()-1;
16647 newAtom.fixFlag=0;
16648
16649 newAtom.an=((fac<0)||(fac>=editor->sfac.size()))?-2:editor->sfac.at(fac);
16650 newAtom.frac.x = getNumber(tok.at(2).toDouble(),fvar,0,newAtom.fixFlag);
16651 newAtom.frac.y = getNumber(tok.at(3).toDouble(),fvar,1,newAtom.fixFlag);
16652 newAtom.frac.z = getNumber(tok.at(4).toDouble(),fvar,2,newAtom.fixFlag);
16653 if (qAbs(part_fvar) > 11.0 ){
16654 // fvar is defined for entire part:
16655 //printf("7part with sof %f %s\n",part_fvar,newAtom.Label.toStdString().c_str());
16656 newAtom.sof = getNumber(part_fvar, fvar, 3, newAtom.fixFlag);
16657 newAtom.sof_org = part_fvar;
16658 } else {
16659 // fvar is defined at each atom:
16660 newAtom.sof = getNumber(tok.at(5).toDouble(), fvar, 3, newAtom.fixFlag);
16661 newAtom.sof_org = tok.at(5).toDouble();
16662 }
16663 newAtom.isIso=true;
16664 double uIso = getNumber(tok.at(6).toDouble(),fvar,uiso);
16665 newAtom.uf.m11 = newAtom.uf.m22 = newAtom.uf.m33 = uIso;
16666 newAtom.uf.m32 = newAtom.uf.m23 = uIso * mole.cell.cosra;
16667 newAtom.uf.m31 = newAtom.uf.m13 = uIso * mole.cell.cosrb;
16668 newAtom.uf.m21 = newAtom.uf.m12 = uIso * mole.cell.cosrg;
16669 mole.Uf2Uo(newAtom.uf, newAtom.uc);
16670 newAtom.ufiso_org=tok.at(6);
16671 /*printf("Uiso%g uiso%g %g %g %g\n",uIso,uiso,mole.cell.cosra,mole.cell.cosrb,mole.cell.cosrg);
16672 printf("%s org=%s iso=%d\n a%9.6f b%9.6f c%9.6f %9.6f %9.6f %9.6f\n d%9.6f e%9.6f f%9.6f %9.6f %9.6f %9.6f\n g%9.6f h%9.6f i%9.6f %9.6f %9.6f %9.6f\n\n",
16673 newAtom.Label.toStdString().c_str(),
16674 newAtom.ufiso_org.toStdString().c_str(),
16675 newAtom.isIso,
16676 newAtom.uf.m11,newAtom.uf.m12,newAtom.uf.m13, newAtom.uc.m11,newAtom.uc.m12,newAtom.uc.m13,
16677 newAtom.uf.m21,newAtom.uf.m22,newAtom.uf.m23, newAtom.uc.m21,newAtom.uc.m22,newAtom.uc.m23,
16678 newAtom.uf.m31,newAtom.uf.m32,newAtom.uf.m33, newAtom.uc.m31,newAtom.uc.m32,newAtom.uc.m33);*/
16679 //qDebug()<< newAtom.ufiso_org<< uIso<<newAtom.uc.m11<<newAtom.uc.m22<<newAtom.uc.m33<<newAtom.uc.m23<<newAtom.uc.m13<<newAtom.uc.m12;
16680 newAtom.peakHeight=-666;
16681 if (newAtom.an==-66) newAtom.peakHeight=9999.99;
16682 newAtom.afixParent=-1;
16683 if (newAtom.an>0) afixparent=mole.asymm.size();
16684 else newAtom.afixParent=afixparent;
16685 mole.asymm.append(newAtom);
16686 //isoat++;
16687 }
16688 if (tok.size()==8) {
16689 // We have a q-peak!
16690 newAtom.Label=tok.at(0);
16691 if (newAtom.Label.startsWith('Q',Qt::CaseInsensitive)) {
16692 newAtom.an=-1;
16693 newAtom.resiNr=-1;
16694 newAtom.ResiClass="Q-Peak";
16695 qpeaks++;
16696 } else {
16697 int fac=tok.at(1).toInt()-1;
16698 newAtom.an=((fac<0)||(fac>=editor->sfac.size()))?-2:editor->sfac.at(fac);
16699 //isoat++;
16700 }
16701 newAtom.fixFlag=0;
16702 newAtom.frac.x = tok.at(2).toDouble();
16703 newAtom.frac.y = tok.at(3).toDouble();
16704 newAtom.frac.z = tok.at(4).toDouble();
16705 if (qAbs(part_fvar) > 11.0 ){
16706 // fvar is defined for entire part:
16707 // printf("8part with sof %f %s\n",part_fvar,newAtom.Label.toStdString().c_str());
16708 newAtom.sof = getNumber(part_fvar, fvar, 3, newAtom.fixFlag);
16709 newAtom.sof_org = part_fvar;
16710 } else {
16711 // fvar is defined at each atom:
16712 newAtom.sof = getNumber(tok.at(5).toDouble(), fvar, 3, newAtom.fixFlag);
16713 newAtom.sof_org = tok.at(5).toDouble();
16714 }
16715 newAtom.isIso=true;
16716 double uIso = getNumber(tok.at(6).toDouble(),fvar,uiso);
16717 newAtom.uf.m11 = newAtom.uf.m22 = newAtom.uf.m33 = uIso;
16718 newAtom.uf.m32 = newAtom.uf.m23 = uIso * mole.cell.cosra;
16719 newAtom.uf.m31 = newAtom.uf.m13 = uIso * mole.cell.cosrb;
16720 newAtom.uf.m21 = newAtom.uf.m12 = uIso * mole.cell.cosrg;
16721 newAtom.ufiso_org=tok.at(6);
16722 //newAtom.uf.m11= getNumber(tok.at(6).toDouble(), fvar, uiso);
16723 //newAtom.isIso=true;
16724 //newAtom.uf.m33= tok.at(6).toDouble();
16725 newAtom.peakHeight=tok.at(7).toDouble();
16726 if (!hklf) qbeforehkl=true;
16727 if(newAtom.an==-1){
16728 mole.pmin=qMin(mole.pmin, newAtom.peakHeight);
16729 mole.pmax=qMax(mole.pmax, newAtom.peakHeight);
16730 }
16731 chgl->qPeakBonds->setVisible(true);
16732
16733 showQPeakLegend->setVisible(true);
16734 newAtom.afixParent=-1;
16735 mole.asymm.append(newAtom);
16736
16737 }
16738 if (tok.size()==12){
16739 // We have an ellipsoid atom!
16740 if ((newAtom.part!=0)||(newAtom.resiNr!=0)){
16741 newAtom.Label=QString("%1_%3%4")
16742 .arg(tok.at(0))
16743 .arg((newAtom.resiNr)?QString::number(newAtom.resiNr):"")
16744 .arg((newAtom.part)?QString::number((newAtom.part<0)?
16745 36+newAtom.part:
16746 newAtom.part+9,36):"");
16747 }else newAtom.Label=tok.at(0);
16748 int fac=tok.at(1).toInt()-1;
16749 newAtom.an=((fac<0)||(fac>=editor->sfac.size()))?-2:editor->sfac.at(fac);
16750 newAtom.frac.x = getNumber(tok.at(2).toDouble(),fvar,0,newAtom.fixFlag);
16751 newAtom.frac.y = getNumber(tok.at(3).toDouble(),fvar,1,newAtom.fixFlag);
16752 newAtom.frac.z = getNumber(tok.at(4).toDouble(),fvar,2,newAtom.fixFlag);
16753 if (qAbs(part_fvar) > 11.0 ){
16754 // fvar is defined for entire part:
16755 //printf(">11 part with sof %f %s\n",part_fvar,newAtom.Label.toStdString().c_str());
16756 newAtom.sof = getNumber(part_fvar, fvar, 3, newAtom.fixFlag);
16757 newAtom.sof_org = part_fvar;
16758 } else {
16759 // fvar is defined at each atom:
16760 newAtom.sof = getNumber(tok.at(5).toDouble(), fvar, 3, newAtom.fixFlag);
16761 newAtom.sof_org = tok.at(5).toDouble();
16762 }
16763 newAtom.uf.m11 = getNumber(tok.at(6).toDouble(),fvar,4,newAtom.fixFlag);
16764 newAtom.uf.m22 = getNumber(tok.at(7).toDouble(),fvar,5,newAtom.fixFlag);
16765 newAtom.uf.m33 = getNumber(tok.at(8).toDouble(),fvar,6,newAtom.fixFlag);
16766 newAtom.uf.m32 = newAtom.uf.m23 = getNumber(tok.at(9).toDouble(),fvar,7,newAtom.fixFlag);
16767 newAtom.uf.m31 = newAtom.uf.m13 = getNumber(tok.at(10).toDouble(),fvar,8,newAtom.fixFlag);
16768 newAtom.uf.m21 = newAtom.uf.m12 = getNumber(tok.at(11).toDouble(),fvar,9,newAtom.fixFlag);
16769 newAtom.peakHeight=-666;
16770 uiso=mole.ueq(newAtom.uf);
16771 if (newAtom.an>0) afixparent=mole.asymm.size();
16772 newAtom.afixParent=-1;
16773 mole.asymm.append(newAtom);
16774 adpat++;
16775 }
16776 }
16777 break;
16778 }
16779
16780
16781 }
16782
16783 }
16784 //printf("load sheldrick %d\n",__LINE__);
16785 mole.qboMax=1.67;
16786 if (minp<0) {
16787 chgl->shpm1->setVisible(true);
16788 chgl->highlightParts->setVisible(true);
16789 }
16790 if (maxp>0) chgl->highlightParts->setVisible(true);
16791 mole.qbeforehkl=qbeforehkl;
16792 actionUniq->setDisabled(mole.qbeforehkl);
16793 if (!popel.isEmpty()){
16794 for (int i=0;i<mole.asymm.size();i++){
16795 if (mole.asymm.at(i).orginalLine.contains(popel)){
16796 //printf("HATSCHI %d => %d! (%s)\n",chgl->rotze,i,popel.toStdString().c_str());
16797 chgl->rotze=i;
16798 }
16799 }
16800 }
16801 for (int i=0;i<mole.asymm.size();i++){
16802 mole.Uf2Uo(mole.asymm.at(i).uf,mole.asymm[i].uc);
16803 mole.frac2kart(mole.asymm.at(i).frac,mole.asymm[i].pos);
16804 mole.showatoms.append(mole.asymm.at(i));
16805 }
16806
16807 //printf("Average U equivalent (only positive definite counted): %f\n",mole.averageUeq());
16808 getMinMaxSintl(editor->smin,editor->smax);
16809 if (mole.asymm.size()){
16810 updateStatusBar("analysing structure...");
16811
16812 if ((!notRefine)&&(mole.asymm.size()<chgl->SDM_Limit)) mole.packer(mole.sdmcompleter());
16813 infoKanalNews(mole.Fragments);
16814 bool growYes=chgl->fuse->isVisible ();
16815 bool fuseYes=chgl->grow->isVisible ();
16816 chgl->fuse->setVisible(true);
16817 chgl->grow->setVisible(false);
16818 mole.loadSettings();
16819 updateStatusBar("finding bonds...");
16820
16821 mole.showbonds = mole.connecting(mole.showatoms);
16822 int lnrr=0;
16823 CEnvironment belo;
16824 //printf("belo: %d\n",bedeRloneLY.size());
16825 for (int bl=0; bl<bedeRloneLY.size(); bl++){
16826 int ignore=0;
16827 QStringList tok = bedeRloneLY.at(bl).split(leer,skipEmptyParts);
16828 if ((tok.at(0).endsWith("BEDE",Qt::CaseInsensitive))&&(tok.size()>6)){
16829 lnrr=belo.size();
16830 QString aton1=tok.at(1),aton2=tok.at(2);
16831 double rad = getNumber(tok.at(3).toDouble(),fvar,0,ignore);
16832 double a = getNumber(tok.at(4).toDouble(),fvar,0,ignore);
16833 double b1 = getNumber(tok.at(5).toDouble(),fvar,0,ignore);
16834 double b2 = getNumber(tok.at(6).toDouble(),fvar,0,ignore);
16835 newAtom.an=-42;
16836 newAtom.symmGroup=0;
16837 newAtom.sg=0;
16838 newAtom.scod=555;//the identity
16839 newAtom.auidx=-1;
16840 int an1=-1,an2=-2;
16841 for (int bl1=0; bl1<mole.asymm.size(); bl1++)
16842 for (int bl2=0; bl2<mole.asymm.size(); bl2++){
16843 if ((mole.asymm.at(bl1).an<0)||(mole.asymm.at(bl2).an<0)) continue;
16844 double soll=-1,d= sqrt(Distance(mole.asymm.at(bl1).pos,mole.asymm.at(bl2).pos));
16845 if ((mole.asymm.at(bl1).an==0)&&(mole.asymm.at(bl2).an==0)) continue;
16846 if ((mole.asymm.at(bl1).an>-1)&&(mole.asymm.at(bl2).an>-1)&&
16847 ((!mole.asymm.at(bl1).part)||(!mole.asymm.at(bl2).part)||(mole.asymm.at(bl1).part==mole.asymm.at(bl2).part)))
16848 soll=(mole.Kovalenz_Radien[mole.asymm.at(bl1).an]+ mole.Kovalenz_Radien[mole.asymm.at(bl2).an])*0.012;
16849 else
16850 soll=-1;
16851 if ((d>0.1)&&(d<soll)) {
16852 an1=-1;
16853 an2=-2;
16854 if (aton1[0]=='$') an1=mole.getOZ(aton1);
16855 if (aton2[0]=='$') an2=mole.getOZ(aton2);
16856 if (((an1>=0)&&(mole.asymm.at(bl1).an==an1))||(aton1==mole.asymm.at(bl1).Label))
16857 if (((an2>=0)&&(mole.asymm.at(bl2).an==an2))||(aton2==mole.asymm.at(bl2).Label)){
16858 V3 pos = mole.asymm.at(bl1).pos+Normalize(mole.asymm.at(bl2).pos-mole.asymm.at(bl1).pos)*rad;
16859 newAtom.pos=pos;
16860 mole.kart2frac(pos,pos);
16861 newAtom.Label=QString("L%1").arg(++lnrr);
16862 newAtom.frac=pos;
16863 newAtom.auidx=-1;
16864 newAtom.peakHeight=b1;
16865 newAtom.sof=a;
16866 newAtom.uf=mole.u2b(mole.asymm.at(bl1).uf);//possible problem if U is not anisotrop
16867 belo.append(newAtom);
16868 pos=mole.asymm.at(bl1).frac;
16869 newAtom.Label=QString("L%1").arg(++lnrr);
16870 newAtom.frac=mole.asymm.at(bl1).frac;
16871 mole.frac2kart(newAtom.frac,newAtom.pos);
16872 newAtom.sof=-a;
16873 newAtom.peakHeight=b2;
16874 belo.append(newAtom);
16875
16876 mole.lmin=qMin(mole.lmin,-a);
16877 mole.lmax=qMax(mole.lmax, a);
16878
16879 }
16880 }
16881 }
16882
16883 }else
16884 if (tok.at(0).endsWith("LONE",Qt::CaseInsensitive)){
16885 belo.append(lonesome(bedeRloneLY.at(bl),belo.size()+1));
16886 }
16887 }
16888 if (!belo.isEmpty()) {
16889 for (int bl=0; bl<belo.size(); bl++){
16890 belo[bl].orginalLine=QString("%1 2 %2 %3 %4").arg(belo.at(bl).Label.section('_',0,0),-4)
16891 .arg(belo.at(bl).frac.x,10,'f',5)
16892 .arg(belo.at(bl).frac.y,10,'f',5)
16893 .arg(belo.at(bl).frac.z,10,'f',5);
16894 }
16895 mole.asymm.append(belo);
16896 }
16897 QString info;
16898 for (int ifv=0; ifv<fvar.size();ifv++){
16899 if (ifv==0) {
16900 info.append("OSF: ");
16901 info.append(QString("<font color=red>%1</font>").arg(fvar.at(ifv)));
16902 }
16903 else {
16904 info.append(QString("FVAR<font color=blue>%1</font>: ").arg(ifv+1));
16905 if (fvarCntr.value(ifv+1)<1)info.append(QString("<font color=red>%1</font>(Never Used!)").arg(fvar.at(ifv)));
16906 else info.append(QString("<font color=red>%1</font>(used %2 time%3.)").arg(fvar.at(ifv))
16907 .arg(fvarCntr.value(ifv+1)).arg((fvarCntr.value(ifv+1)>1)?"s":""));
16908 }
16909 if ((ifv+1)<fvar.size()) info.append(", ");
16910 info.append("<br>");
16911 }
16912 fvarinfo=QString("<b>Free variables:</b> %1").arg(info);
16913
16914 chgl->setMolecule(&mole);
16915 chgl->mol->fuse();
16916 if ((!notRefine)&&(mole.asymm.size()<chgl->SDM_Limit)) {
16917 if (((!fuseYes)&&(growYes))||(((!fuseYes)&&(!growYes))&&(!startFused))) chgl->mol->grow();
16918 else {
16919 chgl->fuse->setVisible(false);
16920 chgl->grow->setVisible(true);
16921 }
16922 }
16923 else {
16924 //if ((mole.asymm.size()>chgl->SDM_Limit)&&(chgl->dratpause==80)) chgl->dratpause=300;
16925 chgl->fuse->setVisible(false);
16926 chgl->grow->setVisible(false);
16927
16928 }
16929
16930 infoKanalNews(mole.HumanSymmetry);
16931 //updateStatusBar("drawing display lists...");
16932
16933 chgl->rehide();
16934 updateStatusBar("");
16935 }
16936
16937 //printf("%d\n",__LINE__);
16938 chgl->update();
16939
16940
16941 urs=V3(0,0,0);int gt=0;
16942 for (int i=0; i<mole.showatoms.size();i++)
16943 if (mole.showatoms.at(i).an>-1) {urs+=mole.showatoms.at(i).frac;gt++;}
16944 urs*=1.0/gt;
16945 urs=V3(1,1,1)-1.0*urs;
16946 mole.frac2kart(urs,urs);
16947 mode=0;
16948 qpv->cutoff=0;//qMin(0.0,mole.pmin);
16949 qpv->setMin(mole.pmin);
16950 qpv->setMax(mole.pmax);
16951 if (qpeaks) qPeakDock->show();
16952
16953 //QTime zeit; zeit.start();
16954 //printf("MAPS?\n");
16955 fxle->resDir=QDir(fileName);
16956 fxle->fouName=(fxle->MYFCF)?s.myfcf(fileName):"";
16957 if (fxle->fouName.isEmpty()){
16958 fxle->fouName=fileName;
16959 fxle->fouName.chop(4);
16960 fxle->fouName.append(".fcf");
16961 }
16962
16963 if ((fxle->doMaps->isChecked())&& (!fxle->loadFouAndPerform(fxle->fouName.toLocal8Bit()))) {
16964 if (fxle->doMaps->isChecked()) infoKanalNews(QString("<font color=red>Error while loading %1!</font><br>").arg(fxle->fouName));
16965
16966 //printf("%d\n",__LINE__);
16967 fxle->killmaps();
16968 //printf("%d\n",__LINE__);
16969 fxle->n1=fxle->n2=fxle->n3=fxle->n5=0;
16970 }
16971 if (fxle->doMaps->isChecked()){
16972 fxle->mapcontrol->setVisible(true);
16973 }
16974 fxle->doMaps->show();
16975 //printf("MAPS!\n");
16976 /*
16977 QMap<int,double> unit;
16978 for (int i=0; i<mole.asymm.size(); i++){
16979 if (mole.asymm.at(i).an>=0) unit[mole.asymm.at(i).an]+= mole.asymm.at(i).sof * mole.cell.symmops.size();
16980 }
16981 editor->unitNeu="UNIT";
16982 for (int i = 0; i < editor->sfac.size() ; i++){
16983 if (unit.value(editor->sfac.at(i))>9999)
16984 editor->unitNeu.append(QString(" %1").arg((int)unit.value(editor->sfac.at(i)))); else
16985 editor->unitNeu.append(QString(" %1").arg(unit.value(editor->sfac.at(i)),0,'g'));
16986 if (editor->unitNeu.split('\n').last().size()>76) editor->unitNeu.append("=\n ");
16987 }*/
16988 QMap<QString,double> unit;
16989 for (int i=0; i<mole.asymm.size(); i++){
16990 if (mole.asymm.at(i).an<0) continue;
16991 QStringList ol = mole.asymm.at(i).orginalLine.split(' ', skipEmptyParts, Qt::CaseInsensitive);
16992 QString smbl="!!";
16993 if ((ol.size()>1)&&(ol.at(1).toInt()-1<editor->sfacsmbl.size())) smbl=editor->sfacsmbl.at(ol.at(1).toInt()-1);
16994 //printf("%d %d %d %s {%s}\n",__LINE__,ol.size(),editor->sfacsmbl.size(), mole.asymm.at(i).orginalLine.toStdString().c_str(), smbl.toStdString().c_str());
16995 //printf("%d\n",__LINE__);
16996 if (mole.asymm.at(i).an>=0) {
16997
16998 //printf("%d\n",__LINE__);
16999 unit[smbl]+= mole.asymm.at(i).sof * mole.cell.symmops.size();
17000 // printf("%d\n",__LINE__);
17001 /*
17002 printf("%s %d %f %f <> %f %f ;-)\n",
17003 smbl.toStdString().c_str(),i,
17004 unit.value(smbl), unit[smbl],
17005 mole.asymm.at(i).sof * mole.cell.symmops.size(),
17006 mole.asymm.at(i).sof);
17007 // */
17008 }
17009 //printf("%d\n",__LINE__);
17010 }
17011 editor->unitNeu="UNIT";
17012 for (int i = 0; i < editor->sfacsmbl.size() ; i++){
17013 if (unit.value(editor->sfacsmbl.at(i))>9999)
17014 editor->unitNeu.append(QString(" %1").arg((int)unit.value(editor->sfacsmbl.at(i)))); else
17015 editor->unitNeu.append(QString(" %1").arg(unit.value(editor->sfacsmbl.at(i)),0,'g'));
17016 if (editor->unitNeu.split('\n').last().size()>76) editor->unitNeu.append("=\n ");
17017 }
17018 //printf("%s\n",editor->unitNeu.toStdString().c_str());
17019 chgl->toggleDockWidgets->setVisible(true);
17020 astdlg->setDisabled(false);
17021 toggDocWid(false);
17022 sinaAct->setVisible(adpat!=0);
17023 if (!mole.asymm.size()) title.append("!!Empty!!");
17024
17025 refineAct->setVisible(!notRefine);
17026 refineAct->setEnabled(!notRefine);
17027
17028 refineActAnis->setVisible(!notRefine);
17029 refineActAnis->setEnabled(!notRefine);
17030
17031 refineActActa->setVisible(!notRefine);
17032 refineActActa->setEnabled(!notRefine);
17033
17034 refineActExti->setVisible(!notRefine);
17035 refineActExti->setEnabled(!notRefine);
17036
17037 refineActConf->setVisible(!notRefine);
17038 refineActConf->setEnabled(!notRefine);
17039 for (int k=0; k<editor->sfac.size();k++){
17040 xda.an = editor->sfac.at(k);
17041 xda.Label = mole.pse(editor->sfac.at(k));
17042 mole.legendAtoms.append(xda);
17043 if (editor->sfac.at(k)<0) continue;
17044 QAction *a = chgl->sfacMenu->addAction(mole.pse(editor->sfac.at(k)),this,SLOT(changeElement()));
17045 a->setData(k);
17046 a = chgl->selSfacMenu->addAction(mole.pse(editor->sfac.at(k)),this,SLOT(changeSelectedElements()));
17047 a->setData(k);
17048 }
17049 if (qpeaks){
17050 xda.an = -1;
17051 xda.Label = "Q";
17052 xda.peakHeight = mole.pmax-0.01;
17053 mole.legendAtoms.append(xda);
17054 xda.pos.y += 0.5;
17055 }
17056 if (chgl->hideBeLo->isVisible()){
17057 xda.an = -42;
17058 xda.Label = "BELO";
17059 xda.peakHeight = mole.lmax-0.01;
17060 mole.legendAtoms.append(xda);
17061 xda.pos.y += 0.5;
17062 }
17063 //printf("%d\n",__LINE__);
17064 //int td=0;
17065 if (!notRefine) switch (
17066 //td=
17067 duplicates()){
17068 case 1:infoKanalNews("<font color=orange >Some hydrogen atoms have identical names please check.</font>");break;
17069 case 2:infoKanalNews("<font color=red >Some non-hydrogen atoms have identical names. YOU HAVE TO CHECK BEFORE REFINING!</font>");break;
17070 case 3:infoKanalNews("<font color=red >Some atoms have identical names. YOU HAVE TO CHECK BEFORE REFINING!</font>");break;
17071 }
17072 QString listName=fileName;
17073 listName.replace(punktins,".lst");
17074 listName.replace(punktres,".lst");
17075 QFile lstf(listName);
17076 //printf("%d\n",__LINE__);
17077 if (lstf.open(QIODevice::ReadOnly|QIODevice::Text)){
17078 QString liste=QString(lstf.readAll());
17079 while (liste.contains(QRegularExpression("\n\\s+REM"))) {
17080 liste=liste.replace(QRegularExpression("\n\\s+REM[^\n]*\n",QRegularExpression::CaseInsensitiveOption),"\n");
17081 //printf("%d\n",__LINE__);
17082 }
17083 //printf("%d\n",__LINE__);
17084 if (liste.contains("Flack x parameter =")){
17085 QString flackS=liste.section("Flack x parameter =",1).section('\n',0,0);
17086 double flackX=flackS.split(leer,skipEmptyParts).first().toDouble();
17087 double flackXesd=flackS.split(leer,skipEmptyParts).last().toDouble();
17088 infoKanalNews(QString("SHELXL-list file reports <b>Flack</b> x parameter:<b> %1 &plusmn; %2</b>").arg(flackX).arg(flackXesd));
17089 }
17090 //Flack x =
17091 if (liste.contains("Flack x =")) {
17092 QString flackS=liste.section("\n Flack x = ",1).section('\n',0,1);
17093 QString flackX = "";
17094 // prevent crash from empty flackS:
17095 if (flackS.split(leer,skipEmptyParts).length() > 0) {
17096 flackX=flackS.split(leer,skipEmptyParts).first();
17097 }
17098 QString parsonsZ=flackS.section('\n',1,1);
17099 if (parsonsZ.isEmpty() && !flackX.isEmpty()) {
17100 infoKanalNews(QString("SHELXL-list file reports <b>Flack</b> x parameter:<b> %1 </b>").arg(flackX));
17101 }
17102 if (!parsonsZ.isEmpty() && !flackX.isEmpty()) {
17103 parsonsZ=parsonsZ.split(leer,skipEmptyParts).first();
17104 infoKanalNews(QString("SHELXL-list file reports <br><b>Flack</b> x parameter:<b> %1 </b><br><b>Parsons</b> parameter:<b> %2</b>")
17105 .arg(flackX).arg(parsonsZ));
17106 }
17107 }
17108 lstf.close();
17109 }
17110 QString fcfname = fileName;
17111 fcfname.replace(resorins,".fcf");
17112 fvused->setText(QString("%1 FVARs defined").arg(fvar.count()));
17113 fcvsfoAct->setEnabled(QFile::exists(fcfname));
17114 chgl->showHidden();
17115 editor->fitWidth();
17116
17117 //loadMolInTest();
17118 update();
17119 chgl->update();
17120 //return title;
17121 }//shelx
17122
17123
17124 #include "ideal_defden.h"
17125 void Window::beloWriteCube(){
17126 //printf("bWC belo?%d\n",fxle->isBelo);
17127 if (fxle->isBelo) return;
17128 fxle->isBelo=true;
17129 chgl->fofcact->setVisible(true);
17130 chgl->fofcact->setChecked(true);
17131 IdealDefdenGenerator *idealDefGen = new IdealDefdenGenerator(chgl, fxle, this);
17132 connect(idealDefGen, SIGNAL(finished()), fxle, SLOT(controlMap()));
17133 connect(idealDefGen, SIGNAL(message(const QString&)), this, SLOT(updateStatusBar(const QString&)));
17134 connect(idealDefGen, SIGNAL(finished()), idealDefGen, SLOT(deleteLater()));
17135 idealDefGen->start();
17136 chgl->update();
17137 }
17138
17139 void Window::configBeLos(){
17140 QColor c = mole.beloColor;
17141 QDialog *belodlg = new QDialog(this);
17142 QGridLayout *lo = new QGridLayout(belodlg);
17143 QDialogButtonBox *bb = new QDialogButtonBox(QDialogButtonBox::Ok|QDialogButtonBox::Cancel,Qt::Horizontal,belodlg);
17144 connect(bb, SIGNAL(accepted()), belodlg, SLOT(accept()));
17145 connect(bb, SIGNAL(rejected()), belodlg, SLOT(reject()));
17146 QDoubleSpinBox *beloRadSpin = new QDoubleSpinBox(belodlg);
17147 beloRadSpin->setMinimum(0.01);
17148 beloRadSpin->setMaximum(0.2);
17149 beloRadSpin->setValue(mole.beloRad);
17150 beloRadSpin->setSingleStep(0.01);
17151 QCheckBox *beloLabel = new QCheckBox("Show BEDE LONE Labels",belodlg);
17152 beloLabel->setChecked(mole.beloLabels);
17153 beloColorButton = new QPushButton("BEDE LONE objects color",belodlg);
17154 beloColorButton->setStyleSheet(QString(
17155 "QPushButton {"
17156 "border: 1px solid #000000;"
17157 "border-radius: 9px;"
17158 "color: %4;"
17159 "background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 %1, stop: 0.5 %3, stop: 1 %2);"
17160 "}"
17161 "QPushButton:hover {"
17162 "background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 %2, stop: 0.5 %1, stop: 1 %2);"
17163 "}"
17164 "QPushButton:flat {"
17165 " border: none; /* no border for a flat push button */"
17166 "}"
17167 )
17168 .arg(mole.beloColor.name())
17169 .arg(mole.beloColor.darker(200).name())
17170 .arg(mole.beloColor.lighter(200).name())
17171 .arg((mole.beloColor.value()<90)?"#ffffff":"#000000"));
17172 connect(beloColorButton, SIGNAL(pressed()), this, SLOT(colorButtonDialog()));
17173 QCheckBox *beloColorByDefdenBx = new QCheckBox("Use deformation density based color scheme",belodlg);
17174 beloColorByDefdenBx->setChecked(mole.beloColorByDefden);
17175 lo->addWidget(beloColorByDefdenBx,0,0,1,10);
17176 lo->addWidget(beloColorButton,1,0,1,10);
17177 lo->addWidget(new QLabel("BEDE LONE objects size:",belodlg),2,0,1,1);
17178 lo->addWidget(beloRadSpin,2,1,1,1);
17179 lo->addWidget(beloLabel,3,0,1,1);
17180 lo->addWidget(bb,10,0,1,10);
17181 if (belodlg->exec()==QDialog::Accepted){
17182 mole.beloRad=beloRadSpin->value();
17183 mole.beloColorByDefden = beloColorByDefdenBx->isChecked();
17184 mole.beloLabels = beloLabel->isChecked();
17185
17186 chgl->update();
17187 einstellung->beginGroup("IDEAL");
17188 einstellung->setValue("beloRad", mole.beloRad);
17189 einstellung->setValue("beloColor", mole.beloColor);
17190 einstellung->setValue("beloColorByDefden", mole.beloColorByDefden);
17191 einstellung->setValue("beloLabels", mole.beloLabels);
17192 einstellung->endGroup();
17193 }else{
17194 mole.beloColor=c;
17195 }
17196 belodlg->deleteLater();
17197
17198 }
17199
17200 void Window::colorButtonDialog(){
17201 QColor bgcolor;
17202 bgcolor=QColorDialog::getColor(mole.beloColor, this);
17203 if (bgcolor.isValid()) {
17204 beloColorButton->setStyleSheet(QString(
17205 "QPushButton {"
17206 "border: 1px solid #000000;"
17207 "border-radius: 9px;"
17208 "color: %4;"
17209 "background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 %1, stop: 0.5 %3, stop: 1 %2);"
17210 "}"
17211 "QPushButton:hover {"
17212 "background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 %2, stop: 0.5 %1, stop: 1 %2);"
17213 "}"
17214 "QPushButton:flat {"
17215 " border: none; /* no border for a flat push button */"
17216 "}"
17217 )
17218 .arg(bgcolor.name())
17219 .arg(bgcolor.darker(200).name())
17220 .arg(bgcolor.lighter(200).name())
17221 .arg((bgcolor.value()<90)?"#ffffff":"#000000"));
17222 mole.beloColor=bgcolor;
17223 }
17224 }
17225
17226 CEnvironment Window::lonesome(QString s, int stnum){
17227 const QRegularExpression num=QRegularExpression("^\\d+");
17228 const QRegularExpression alp=QRegularExpression("^[\\$A-Za-z]+");
17229 QStringList tok=s.split(leer,skipEmptyParts);
17230 int m=0,j=0,k=0,ll=stnum;;
17231 MyAtom horse;
17232 //static CEnvironment l;
17233 CEnvironment l;
17234 l.clear();
17235 MyAtom at;
17236 at.an=-42;
17237 at.auidx=-1;
17238 at.scod=555;
17239 int ignore=0;
17240 while (!tok.at(j).contains(num)) {j++;}
17241 m=tok.at(j).toInt();
17242 k=j;
17243 QString such;
17244 j=1;
17245 while ((!tok.at(j).contains(alp))) {j++;if (j>=tok.size()) break;}
17246 if (j==tok.size()) {
17247 qDebug()<<"oh-oh!";
17248 return l;//big problem
17249 }
17250 such=tok.at(j);
17251 //j=qMax(j,k)+1;
17252 j = k + 1;
17253 while (tok.at(j).contains(alp)) {j++;}
17254 double a = getNumber(tok.at(j).toDouble(),fvar,0,ignore);
17255 j++;
17256 while (tok.at(j).contains(alp)) {j++;}
17257 double b1 = getNumber(tok.at(j).toDouble(),fvar,0,ignore);
17258 j++;
17259 while (tok.at(j).contains(alp)) {j++;}
17260 double b2 = getNumber(tok.at(j).toDouble(),fvar,0,ignore);
17261 bool general=true;
17262 // qDebug()<<s<<such<<j<<tok.size()<<k<<'m'<<m<<'a'<<a<<"b1"<<b1<<"b2"<<b2;
17263
17264 for (int i=0; i<mole.asymm.size(); i++){
17265 if (such==mole.asymm.at(i).Label) {
17266 general=false;
17267 horse=mole.asymm[i];
17268 break;}
17269 }
17270 if (general){
17271
17272 QString such2=such;
17273 such2.remove('$');
17274 // qDebug()<<such<<such2;
17275 int an1= mole.getOZ(such2);
17276 int jjj=stnum;
17277 for (int recurs=0; recurs<mole.asymm.size();recurs++){
17278 if (mole.asymm.at(recurs).an==an1){
17279 QString s2=s;
17280 s2=s2.replace(such,mole.asymm.at(recurs).Label);
17281 // qDebug()<<l.size()<<s2;
17282 CEnvironment lrec;
17283 lrec=lonesome(s2, jjj);//recursion!
17284 jjj+=lrec.size();
17285 for (int dii=0; dii<lrec.size();dii++) {
17286 // qDebug()<<dii <<lrec.at(dii).Label;
17287 l.append(lrec[dii]);
17288 }
17289 // qDebug()<<l.size()<<jjj<<lrec.size();;
17290 }
17291 }
17292 // for (int dii=0; dii<l.size();dii++) { qDebug()<<"return "<<dii <<l.at(dii).Label; }
17293 return l;
17294
17295 }else{
17296 MyAtom n1=mole.asymm[0];
17297 MyAtom n2=mole.asymm[0];
17298 MyAtom n3=mole.asymm[0];
17299 switch (m) {
17300 case 1:{
17301 j=0;
17302 double d,soll=0;
17303 for (;j<mole.asymm.size();j++) {
17304 if (mole.asymm.at(j).an<0) continue;
17305 soll=(mole.Kovalenz_Radien[horse.an]+ mole.Kovalenz_Radien[mole.asymm.at(j).an])*0.012;
17306 d= sqrt(Distance(horse.pos,mole.asymm.at(j).pos));
17307 if ((d>0.1)&&(d<soll)){
17308 n1=mole.asymm[j];
17309 j++;
17310 break;
17311 }
17312 }
17313 for (;j<mole.asymm.size();j++) {
17314 if (mole.asymm.at(j).an<0) continue;
17315 soll=(mole.Kovalenz_Radien[horse.an]+ mole.Kovalenz_Radien[mole.asymm.at(j).an])*0.012;
17316 d= sqrt(Distance(horse.pos,mole.asymm.at(j).pos));
17317 if ((d>0.1)&&(d<soll)){
17318 n2=mole.asymm[j];
17319 j++;
17320 break;
17321 }
17322 }
17323 for (;j<mole.asymm.size();j++) {
17324 if (mole.asymm.at(j).an<0) continue;
17325 soll=(mole.Kovalenz_Radien[horse.an]+ mole.Kovalenz_Radien[mole.asymm.at(j).an])*0.012;
17326 d= sqrt(Distance(horse.pos,mole.asymm.at(j).pos));
17327 if ((d>0.1)&&(d<soll)){
17328 n3=mole.asymm[j];
17329 j++;
17330 break;
17331 }
17332 }
17333 V3 va= Normalize(n1.pos-horse.pos);
17334 V3 vb= Normalize(n2.pos-horse.pos);
17335 V3 vc= Normalize(n3.pos-horse.pos);
17336 V3 trisect=Normalize(va+vb+vc);
17337 double rad=tok.last().toDouble();
17338 if (rad<0) {
17339 rad=-rad;
17340 }
17341 at.pos=horse.pos-(trisect*rad);
17342 at.uf=mole.u2b(horse.uf);//possible problem if U is not anisotrop
17343 mole.kart2frac(at.pos,at.frac);
17344 at.peakHeight=b1;
17345 at.sof=a;
17346 at.auidx=-1;
17347 at.Label=QString("L%1").arg(ll++);
17348 l.append(at);
17349 at.pos=horse.pos;
17350 at.frac=horse.frac;
17351 at.peakHeight=b2;
17352 at.sof=-a*l.size();
17353 at.Label=QString("L%1").arg(ll++);
17354 l.append(at);
17355 //qDebug()<<n1.Label<<n2.Label;
17356 if (tok.size()>7) {
17357 QString s2=s;
17358 s2.remove(horse.Label);
17359 //qDebug()<<s2<<ll;
17360
17361 l.append(lonesome(s2,ll));
17362 }
17363 }
17364 break;
17365 case 2:{
17366 j=0;
17367 double d,soll=0;
17368 for (;j<mole.asymm.size();j++) {
17369 if (mole.asymm.at(j).an<0) continue;
17370 soll=(mole.Kovalenz_Radien[horse.an]+ mole.Kovalenz_Radien[mole.asymm.at(j).an])*0.012;
17371 d= sqrt(Distance(horse.pos,mole.asymm.at(j).pos));
17372 if ((d>0.1)&&(d<soll)){
17373 n1=mole.asymm[j];
17374 j++;
17375 break;
17376 }
17377 }
17378 for (;j<mole.asymm.size();j++) {
17379 if (mole.asymm.at(j).an<0) continue;
17380 soll=(mole.Kovalenz_Radien[horse.an]+ mole.Kovalenz_Radien[mole.asymm.at(j).an])*0.012;
17381 d= sqrt(Distance(horse.pos,mole.asymm.at(j).pos));
17382 if ((d>0.1)&&(d<soll)){
17383 n2=mole.asymm[j];
17384 j++;
17385 break;
17386 }
17387 }
17388 V3 va= Normalize(n1.pos-horse.pos);
17389 V3 vb= Normalize(n2.pos-horse.pos);
17390 V3 bisect=Normalize(va+vb);
17391 V3 ax=Normalize(vb%va);//LLLL
17392 double phi=tok.last().toDouble();
17393 double rad=tok.at(tok.size()-2).toDouble();
17394 //qDebug()<<phi<<rad;
17395 //qDebug()<<va.x<<va.y<<va.z;
17396 //qDebug()<<vb.x<<vb.y<<vb.z;
17397 phi*=M_PI/360.0;//we want /2 !
17398 V3 c=-cos(phi)*bisect;
17399 if (rad<0) {
17400 c=-1.0*c;
17401 rad=-rad;
17402 }
17403 V3 v=sin(phi)*ax;
17404 at.pos=horse.pos+(c+v)*rad;
17405 at.uf=mole.u2b(horse.uf);//possible problem if U is not anisotrop
17406 mole.kart2frac(at.pos,at.frac);
17407 at.peakHeight=b1;
17408 at.sof=a;
17409 at.auidx=-1;
17410 at.Label=QString("L%1").arg(ll++);
17411 l.append(at);
17412 at.pos=horse.pos+(c-v)*rad;
17413 mole.kart2frac(at.pos,at.frac);
17414 at.Label=QString("L%1").arg(ll++);
17415 l.append(at);
17416 at.pos=horse.pos;
17417 at.frac=horse.frac;
17418 at.peakHeight=b2;
17419 at.sof=-a*l.size();
17420 at.Label=QString("L%1").arg(ll++);
17421 l.append(at);
17422 //qDebug()<<n1.Label<<n2.Label;
17423 if (tok.size()>8) {
17424 QString s2=s;
17425 s2.remove(horse.Label);
17426 //qDebug()<<s2<<ll;
17427
17428 l.append(lonesome(s2,ll));
17429 }
17430 }
17431 break;
17432
17433 case 4:{
17434 j=0;
17435 double d,soll=0;
17436 for (;j<mole.asymm.size();j++) {
17437 if (mole.asymm.at(j).an<0) continue;
17438 soll=(mole.Kovalenz_Radien[horse.an]+ mole.Kovalenz_Radien[mole.asymm.at(j).an])*0.012;
17439 d= sqrt(Distance(horse.pos,mole.asymm.at(j).pos));
17440 if ((d>0.1)&&(d<soll)){
17441 n1=mole.asymm[j];
17442 j++;
17443 break;
17444 }
17445 }
17446 for (;j<mole.asymm.size();j++) {
17447 if (mole.asymm.at(j).an<0) continue;
17448 soll=(mole.Kovalenz_Radien[horse.an]+ mole.Kovalenz_Radien[mole.asymm.at(j).an])*0.012;
17449 d= sqrt(Distance(horse.pos,mole.asymm.at(j).pos));
17450 if ((d>0.1)&&(d<soll)){
17451 n2=mole.asymm[j];
17452 j++;
17453 break;
17454 }
17455 }
17456 V3 va= Normalize(n1.pos-horse.pos);
17457 V3 vb= Normalize(n2.pos-horse.pos);
17458 V3 bisect=Normalize(va+vb);
17459 //V3 ax=Normalize(vb%va);//LLLL
17460 double rad=tok.last().toDouble();
17461 at.pos=horse.pos-bisect*rad;
17462 at.uf=mole.u2b(horse.uf);//possible problem if U is not anisotrop
17463 mole.kart2frac(at.pos,at.frac);
17464 at.peakHeight=b1;
17465 at.sof=a;
17466 at.Label=QString("L%1").arg(ll++);
17467 l.append(at);
17468 at.pos=horse.pos;
17469 at.frac=horse.frac;
17470 at.peakHeight=b2;
17471 at.sof=-a;
17472 at.Label=QString("L%1").arg(ll++);
17473 l.append(at);
17474 //qDebug()<<n1.Label<<n2.Label;
17475 if (tok.size()>7) {
17476 QString s2=s;
17477 s2.remove(horse.Label);
17478 //qDebug()<<s2<<ll;
17479
17480 l.append(lonesome(s2,ll));
17481 }
17482 }
17483 break;
17484 case 6:{
17485 j=0;
17486 double d,soll=0;
17487 for (;j<mole.asymm.size();j++) {
17488 if (mole.asymm.at(j).an<0) continue;
17489 soll=(mole.Kovalenz_Radien[horse.an]+ mole.Kovalenz_Radien[mole.asymm.at(j).an])*0.012;
17490 d= sqrt(Distance(horse.pos,mole.asymm.at(j).pos));
17491 if ((d>0.1)&&(d<soll)){
17492 n1=mole.asymm[j];
17493 j++;
17494 break;
17495 }
17496 }
17497 for (;j<mole.asymm.size();j++) {
17498 if (mole.asymm.at(j).an<0) continue;
17499 soll=(mole.Kovalenz_Radien[horse.an]+ mole.Kovalenz_Radien[mole.asymm.at(j).an])*0.012;
17500 d= sqrt(Distance(horse.pos,mole.asymm.at(j).pos));
17501 if ((d>0.1)&&(d<soll)){
17502 n2=mole.asymm[j];
17503 j++;
17504 break;
17505 }
17506 }
17507 V3 va= Normalize(n1.pos-horse.pos);
17508 V3 vb= Normalize(n2.pos-horse.pos);
17509 V3 ax=Normalize(vb%va);//LLLL
17510 double rad=tok.last().toDouble();
17511 //qDebug()<<phi<<rad;
17512 //qDebug()<<va.x<<va.y<<va.z;
17513 //qDebug()<<vb.x<<vb.y<<vb.z;
17514 if (rad<0) {
17515 rad=-rad;
17516 }
17517 at.pos=horse.pos+(ax)*rad;
17518 at.uf=mole.u2b(horse.uf);//possible problem if U is not anisotrop
17519 mole.kart2frac(at.pos,at.frac);
17520 at.peakHeight=b1;
17521 at.sof=a;
17522 at.Label=QString("L%1").arg(ll++);
17523 l.append(at);
17524 at.pos=horse.pos-(ax)*rad;
17525 mole.kart2frac(at.pos,at.frac);
17526 at.Label=QString("L%1").arg(ll++);
17527 l.append(at);
17528 at.pos=horse.pos;
17529 at.frac=horse.frac;
17530 at.peakHeight=b2;
17531 at.sof=-a*l.size();
17532 at.Label=QString("L%1").arg(ll++);
17533 l.append(at);
17534 //qDebug()<<"m=6!"<<s<<n1.Label<<n2.Label<<at.Label;
17535 //qDebug()<<tok<<tok.size();
17536 if (tok.size()>7) {
17537 QString s2=s;
17538 s2.remove(horse.Label);
17539 //qDebug()<<s2<<ll;
17540
17541 l.append(lonesome(s2,ll));
17542 }
17543 }
17544 break;
17545 case 7:{
17546 j=0;
17547 double d,soll=0,d2;
17548 for (;j<mole.asymm.size();j++) {
17549 if (mole.asymm.at(j).an<0) continue;
17550 soll=(mole.Kovalenz_Radien[horse.an]+ mole.Kovalenz_Radien[mole.asymm.at(j).an])*0.012;
17551 d= sqrt(Distance(horse.pos,mole.asymm.at(j).pos));
17552 if ((d>0.1)&&(d<soll)){
17553 n1=mole.asymm[j];
17554 j++;
17555 break;
17556 }
17557 }
17558 for (j=0;j<mole.asymm.size();j++) {
17559 if (mole.asymm.at(j).an<0) continue;
17560 soll=(mole.Kovalenz_Radien[n1.an]+ mole.Kovalenz_Radien[mole.asymm.at(j).an])*0.012;
17561 d= sqrt(Distance(n1.pos,mole.asymm.at(j).pos));
17562 d2= sqrt(Distance(horse.pos,mole.asymm.at(j).pos));
17563 if ((d2>1.1)&&(d>0.1)&&(d<soll)){
17564 n2=mole.asymm[j];
17565 j++;
17566 break;
17567 }
17568 }
17569 V3 va= Normalize(n1.pos-horse.pos);
17570 V3 vb= Normalize(n2.pos-n1.pos);
17571 V3 ax=Normalize(vb%va);//LLLL
17572 double phi=tok.last().toDouble();
17573 double rad=tok.at(tok.size()-2).toDouble();
17574 //qDebug()<<phi<<rad;
17575 //qDebug()<<va.x<<va.y<<va.z;
17576 //qDebug()<<vb.x<<vb.y<<vb.z;
17577 phi*=M_PI/360.0;//we want /2 !
17578 V3 c=-cos(phi)*va;
17579 if (rad<0) {
17580 c=-1.0*c;
17581 rad=-rad;
17582 }
17583 V3 v=sin(phi)*ax;
17584 at.pos=horse.pos+(c+v)*rad;
17585 at.uf=mole.u2b(horse.uf);//possible problem if U is not anisotrop
17586 mole.kart2frac(at.pos,at.frac);
17587 at.peakHeight=b1;
17588 at.sof=a;
17589 at.Label=QString("L%1").arg(ll++);
17590 l.append(at);
17591 at.pos=horse.pos+(c-v)*rad;
17592 mole.kart2frac(at.pos,at.frac);
17593 at.Label=QString("L%1").arg(ll++);
17594 l.append(at);
17595 at.pos=horse.pos;
17596 at.frac=horse.frac;
17597 at.peakHeight=b2;
17598 at.sof=-a*l.size();
17599 at.Label=QString("L%1").arg(ll++);
17600 l.append(at);
17601 // qDebug()<<n1.Label<<n2.Label<<tok.size();
17602 if (tok.size()>8) {
17603 QString s2=s;
17604 s2.remove(horse.Label);
17605 //qDebug()<<s2<<ll;
17606
17607 l.append(lonesome(s2,ll));
17608 }
17609 }
17610 break;
17611 case 9:{
17612 j=0;
17613 double d,soll=0,d2;
17614 for (;j<mole.asymm.size();j++) {
17615 if (mole.asymm.at(j).an<0) continue;
17616 soll=(mole.Kovalenz_Radien[horse.an]+ mole.Kovalenz_Radien[mole.asymm.at(j).an])*0.012;
17617 d= sqrt(Distance(horse.pos,mole.asymm.at(j).pos));
17618 if ((d>0.1)&&(d<soll)){
17619 n1=mole.asymm[j];
17620 j++;
17621 break;
17622 }
17623 }
17624 for (j=0;j<mole.asymm.size();j++) {
17625 if (mole.asymm.at(j).an<0) continue;
17626 soll=(mole.Kovalenz_Radien[n1.an]+ mole.Kovalenz_Radien[mole.asymm.at(j).an])*0.012;
17627 d= sqrt(Distance(n1.pos,mole.asymm.at(j).pos));
17628 d2= sqrt(Distance(horse.pos,mole.asymm.at(j).pos));
17629 if ((d2>1.1)&&(d>0.1)&&(d<soll)){
17630 n2=mole.asymm[j];
17631 j++;
17632 break;
17633 }
17634 }
17635 V3 va= Normalize(n1.pos-horse.pos);
17636 V3 vb= Normalize(n2.pos-n1.pos);
17637 V3 ax1=Normalize(vb%va);//LLLL
17638 V3 ax=Normalize(va%ax1);//LLLL
17639 double phi=tok.last().toDouble();
17640 double rad=tok.at(tok.size()-2).toDouble();
17641 //qDebug()<<phi<<rad;
17642 //qDebug()<<va.x<<va.y<<va.z;
17643 //qDebug()<<vb.x<<vb.y<<vb.z;
17644 phi*=M_PI/360.0;//we want /2 !
17645 V3 c=-cos(phi)*va;
17646 if (rad<0) {
17647 c=-1.0*c;
17648 rad=-rad;
17649 }
17650 V3 v=sin(phi)*ax;
17651 at.pos=horse.pos+(c+v)*rad;
17652 at.uf=mole.u2b(horse.uf);//possible problem if U is not anisotrop
17653 mole.kart2frac(at.pos,at.frac);
17654 at.peakHeight=b1;
17655 at.sof=a;
17656 at.Label=QString("L%1").arg(ll++);
17657 l.append(at);
17658 at.pos=horse.pos+(c-v)*rad;
17659 mole.kart2frac(at.pos,at.frac);
17660 at.Label=QString("L%1").arg(ll++);
17661 l.append(at);
17662 at.pos=horse.pos;
17663 at.frac=horse.frac;
17664 at.peakHeight=b2;
17665 at.sof=-a*l.size();
17666 at.Label=QString("L%1").arg(ll++);
17667 l.append(at);
17668 //qDebug()<<n1.Label<<n2.Label<<tok.size();
17669 if (tok.size()>8) {
17670 QString s2=s;
17671 s2.remove(horse.Label);
17672 //qDebug()<<s2<<ll;
17673
17674 l.append(lonesome(s2,ll));
17675 }
17676 }
17677 break;
17678 default:
17679 fprintf(stderr,"%d das kann ich noch nicht! %s\n",m,such.toStdString().c_str());
17680 infoKanalNews(QString("<H1>%1 das kann ich noch nicht! %2</H1>").arg(m).arg(such));
17681 }
17682 }
17683 // qDebug()<<m<<such<<tok.size();
17684 return l;
17685 }
17686
17687 void Window::exportFMaps(){
17688 QString al;
17689 const double a0 = 0.52917720859;
17690 int ina=0;
17691 for (int i=0; i<mole.asymm.size();i++){
17692 if (mole.asymm[i].an<0) continue;
17693 ina++;
17694 }
17695 for (int i=0; i<mole.asymm.size();i++){
17696 if (mole.asymm[i].an<0) continue;
17697 mole.frac2kart(mole.asymm[i].frac,mole.asymm[i].pos);
17698 al.append(QString("\n%1%2%3%4%5").arg(mole.asymm[i].an+1,5).arg(mole.asymm[i].an+1.0,12,'f',6).arg(mole.asymm[i].pos.x/a0,12,'f',6).arg(mole.asymm[i].pos.y/a0,12,'f',6).arg(mole.asymm[i].pos.z/a0,12,'f',6));
17699 }
17700 fxle->exportMaps(ina, dirName.toStdString().c_str(), al.toStdString().c_str());
17701
17702 }
17703
17704 void Window::toggDocWid(bool weg){
17705 if (weg) {
17706 shxEditorDock->hide();
17707 shxOutputDock->hide();
17708 infotainmentDock->hide();
17709 dock->hide();
17710 renamDock->hide();
17711 histDock->hide();
17712 chgl->toggleDockWidgets->setText("Show Text Windows");
17713 }
17714 else{
17715 shxEditorDock->show();
17716 histDock->show();
17717 dock->show();
17718 chgl->toggleDockWidgets->setText("Hide Text Windows");
17719 }
17720 update();
17721 chgl->update();
17722 }
17723
17724 void Window::convergeWght(){
17725 /*! \brief Update WHGT scheme and refine in a loop until scheme has converged or a maximum of runs has exceeded.*/
17726 if (mole.asymm.isEmpty()) return;
17727 dirName.replace(punktins,".res");
17728 fileSave();
17729 finWasPressed=false;
17730 wght_cycls=0;
17731 xlPutor->clear();
17732 //xlPutor->highlighter->setOutputStyle();
17733 shxOutputDock->show();
17734 shxOutputDock->raise();
17735 //stoppRefinement->show();
17736 finishRefinement->show();
17737 loadRes->show();
17738 loadRes2->show();
17739 QObject::disconnect(stoppRefinement, 0, this, 0);
17740 QObject::disconnect(finishRefinement, 0, this, 0);
17741 refineButtonBox->hide();
17742 shxEditorDock->hide();
17743 dock->hide();
17744 histDock->hide();
17745 renamDock->hide();
17746 update();
17747 runXLWGHT();
17748 }
17749
17750 void Window::finXL(){
17751 QString finname =dirName;
17752 finname.replace(punktins,".res");
17753 finname.replace(punktres,".fin");
17754 QFile fin(finname);
17755 fin.open(QIODevice::WriteOnly|QIODevice::Text);
17756 fin.write("stopp",6);
17757 fin.close();
17758 finishRefinement->hide();
17759 finishRefinement2->hide();
17760 printf("FINISH!\n%s was written so shelxl should end soon.\n",finname.toStdString().c_str());
17761 finWasPressed=true;
17762 }
17763
17764 void Window::runXLWGHT() {
17765 update();
17766 QString dn=dirName.section('/',0,-2),
17767 argument=dirName.section('/',-1);
17768 argument.remove(resorins);
17769 QStringList al;
17770 al.append(argument);
17771 defineBarray();
17772 al+=shelxlArgs.split(' ',skipEmptyParts);
17773 shelxl = new QProcess(this);
17774 shelxl->setWorkingDirectory(dn); // updateXLput()
17775 // stoppRefinement->show();
17776 finishRefinement->show();
17777 finishRefinement->setFocus();
17778 refineButtonBox->hide();
17779 #if (QT_VERSION >= 0x060400)
17780 connect(shelxl,&QProcess::readyReadStandardOutput,this,&Window::updateXLput);
17781 connect(shelxl,&QProcess::finished, this, &Window::updateXLput);
17782 connect(shelxl,&QProcess::finished, this, &Window::runXLWGHT);
17783 connect(shelxl,&QProcess::errorOccurred,this,&Window::updateXLput);
17784 #else
17785
17786 connect(shelxl,SIGNAL(readyReadStandardOutput ()),this,SLOT(updateXLput()));
17787 connect(shelxl,SIGNAL(finished(int,QProcess::ExitStatus)),this,SLOT(updateXLput()));
17788 connect(shelxl,SIGNAL(finished(int,QProcess::ExitStatus)),this ,SLOT(runXLWGHT()));
17789 connect(shelxl,SIGNAL(error(QProcess::ProcessError)),this,SLOT(updateXLput()));
17790 #endif
17791
17792 connect(finishRefinement,SIGNAL(clicked()),this,SLOT(finXL()));;
17793 shxOutputDock->show();
17794 shxOutputDock->raise();
17795 QFile test;
17796 QStringList alltest;
17797 QString alls;
17798 test.setFileName(dirName);
17799 QStringList wghts;
17800 if (test.exists()&&test.size()){
17801 test.open(QIODevice::ReadOnly|QIODevice::Text);
17802 alls=test.readAll();
17803 alltest=alls.split('\n');
17804 wghts=alltest.filter(QRegularExpression("^WGHT.*$",QRegularExpression::CaseInsensitiveOption));
17805 if ((wghts.size()>1)&&(wght_cycls<qMax(1,wght_max_cycls))) alls.replace(wghts.at(0),wghts.at(1));
17806 else if (wghts.size()<2) {
17807 alls.replace(wghts.at(0),"WGHT 0.2!default");
17808 //printf("WGHT %s ==>>%d<==%d\n",wghts.at(0).toStdString().c_str(),wghts.size(),wght_cycls);
17809 }
17810 for (int i=0; i<wghts.size();i++) {
17811 wghts[i].remove(QRegularExpression("\\b0\\.[0]+\\b"));
17812 wghts[i].remove(QRegularExpression("\\B[0]+ "));
17813 wghts[i].remove(QRegularExpression("\\B[0]+$"));
17814 wghts[i] = wghts.at(i).simplified();
17815 }
17816 test.close();
17817 test.open(QIODevice::WriteOnly|QIODevice::Text);
17818 test.write(alls.toLatin1());
17819 test.close();
17820 }else{loadRes->setEnabled(false);}
17821 xlPutor->ListFile=false;
17822 QString s=xlPutor->toPlainText();
17823 /*I think this is good for nothing a job that has not ben started can't have output. Device not open on Qt5
17824 if ((s.isEmpty())&&(shelxl->isOpen())) {
17825 //qDebug()<<"what am I doing here?";
17826 s.append(shelxl->readAllStandardOutput());
17827 s.append(shelxl->readAllStandardError());
17828 }
17829 */
17830 bool same = ((wghts.size()>1)&&(wghts.at(0)==wghts.at(1)));
17831 double tol=0.0,difsum=0.0;
17832 if ((wghts.size()>1)&&(!same)) {
17833 difsum=0.0;
17834 tol=0.008;
17835 same = compareWGHTS(wghts.at(0), wghts.at(1),difsum,tol);
17836 }
17837 s.append(QString("############################\n%1\n%2\nConverged: %3\nafter %4 runs (tolerance %5 sum of differences %6).\n############################\n")
17838 .arg((wghts.size()>0)?wghts.at(0):"WGHT 0.2!default")
17839 .arg((wghts.size()>1)?wghts.at(1):"WGHT 0.2!default")
17840 .arg((same)?"Yes":"No")
17841 .arg(wght_cycls)
17842 .arg(tol)
17843 .arg(difsum)
17844 // .arg(wghts.at(0))
17845 // .arg(wghts.at(1))
17846 );
17847 xlPutor->setPlainText(s);
17848 QTextCursor tc = xlPutor->textCursor();
17849 tc.movePosition(QTextCursor::End, QTextCursor::MoveAnchor);
17850 xlPutor->setTextCursor(tc);
17851 xlPutor->ensureCursorVisible();
17852 update();
17853
17854 if (same) {
17855 stoppRefinement->hide();
17856 refineButtonBox->show();
17857 loadRes->setEnabled((s.contains("for all data"))||(s.contains("Converged: Yes")));
17858 stoppRefinement2->hide();
17859 finishRefinement2->hide();
17860 finishRefinement->hide();
17861 refineButtonBox2->show();
17862 loadRes2->setEnabled(loadRes->isEnabled());
17863 QTextCursor tc = xlPutor->textCursor();
17864 tc.movePosition(QTextCursor::End, QTextCursor::MoveAnchor);
17865 xlPutor->setTextCursor(tc);
17866 xlPutor->ensureCursorVisible();
17867 update();
17868 return;
17869 }
17870 bool endd = (wght_cycls>=wght_max_cycls);
17871 if ((wght_max_cycls<0)) endd = false;
17872 if ((!loadRes->isEnabled())||(endd)||finWasPressed) {
17873 stoppRefinement->hide();
17874 finishRefinement->hide();
17875 refineButtonBox->show();
17876 loadRes->setEnabled((s.contains("for all data")));
17877 stoppRefinement2->hide();
17878 finishRefinement2->hide();
17879 refineButtonBox2->show();
17880 loadRes2->setEnabled(loadRes->isEnabled());
17881 QTextCursor tc = xlPutor->textCursor();
17882 tc.movePosition(QTextCursor::End, QTextCursor::MoveAnchor);
17883 xlPutor->setTextCursor(tc);
17884 xlPutor->ensureCursorVisible();
17885 update();
17886 return;
17887 }
17888 if (dirName.contains(punktres)){
17889 QString insname =dirName;
17890 insname.replace(punktres,".ins");
17891
17892 QString fcfname = dirName;
17893 fcfname.replace(punktres,".fcf");
17894 QString fcfname2 = dirName;
17895 fcfname2.replace(punktres,".2fcf");
17896 if (QFileInfo(dirName).lastModified()>=QFileInfo(insname).lastModified()){
17897 QDir work=QDir(QString("%1/%2saves/").arg(dn).arg(PROGRAM_NAME));
17898 QStringList filter;
17899 filter << QString("%1_*_.ins").arg(argument);
17900 QStringList resfs;
17901 resfs=work.entryList(filter,QDir::Files,QDir::Time|QDir::Reversed);
17902 int vers=0;
17903 if (resfs.isEmpty()) vers=1;
17904 else {
17905 bool ok=true;
17906 for (int i = 0; i < resfs.size(); i++)
17907 vers = qMax(resfs.at(i).section("_",-2,-2).toInt(&ok,36),vers);
17908 vers++;
17909 }
17910 if (!work.exists ( QString("%1/%2saves/").arg(dn).arg(PROGRAM_NAME))) work.mkdir (QString("%1/%2saves/").arg(dn).arg(PROGRAM_NAME));
17911 QFile::copy(insname,QString("%1/%4saves/%2_%3_.ins").arg(dn).arg(argument).arg(vers,2,36,QLatin1Char('0')).arg(PROGRAM_NAME));
17912 QFile::remove(insname);
17913 QFile::copy(dirName,insname);
17914 QFile::copy(fcfname2,QString("%1/%4saves/%2_%3_.fcf").arg(dn).arg(argument).arg(vers,2,36,QLatin1Char('0')).arg(PROGRAM_NAME));
17915 QFile::remove(fcfname2);
17916 QFile::copy(fcfname,fcfname2);
17917 } else {
17918 QDir work=QDir(QString("%1/%2saves/").arg(dn).arg(PROGRAM_NAME));
17919 QStringList filter;
17920 filter << QString("%1_*_.ins").arg(argument);
17921 QStringList resfs;
17922 resfs=work.entryList(filter,QDir::Files,QDir::Time|QDir::Reversed);
17923 int vers=0;
17924 if (resfs.isEmpty()) vers=1;
17925 else {
17926 bool ok=true;
17927 for (int i = 0; i < resfs.size(); i++)
17928 vers = qMax(resfs.at(i).section("_",-2,-2).toInt(&ok,36),vers);
17929 vers++;
17930 }
17931 if (!work.exists ( QString("%1/%2saves/").arg(dn).arg(PROGRAM_NAME))) work.mkdir (QString("%1/%2saves/").arg(dn).arg(PROGRAM_NAME));
17932 QFile::copy(insname,QString("%1/%4saves/%2_%3_.ins").arg(dn).arg(argument).arg(vers,2,36,QLatin1Char('0')).arg(PROGRAM_NAME));
17933 QFile::remove(insname);
17934 QFile::copy(dirName,insname);
17935
17936 QFile::copy(fcfname2,QString("%1/%4saves/%2_%3_.fcf").arg(dn).arg(argument).arg(vers,2,36,QLatin1Char('0')).arg(PROGRAM_NAME));
17937 QFile::remove(fcfname2);
17938 QFile::copy(fcfname,fcfname2);
17939 }
17940 } else {
17941 QDir work=QDir(QString("%1/%2saves/").arg(dn).arg(PROGRAM_NAME));
17942 QStringList filter;
17943 filter << QString("%1_*_.ins").arg(argument);
17944 QStringList resfs;
17945 resfs=work.entryList(filter,QDir::Files,QDir::Time|QDir::Reversed);
17946 int vers=0;
17947 if (resfs.isEmpty()) vers=1;
17948 else {
17949 bool ok=true;
17950 for (int i = 0; i < resfs.size(); i++)
17951 vers = qMax(resfs.at(i).section("_",-2,-2).toInt(&ok,36),vers);
17952 vers++;
17953 }
17954 if (!work.exists ( QString("%1/%2saves/").arg(dn).arg(PROGRAM_NAME))) work.mkdir (QString("%1/%2saves/").arg(dn).arg(PROGRAM_NAME));
17955 QFile::copy(dirName,QString("%1/%4saves/%2_%3_.ins").arg(dn).arg(argument).arg(vers,2,36,QLatin1Char('0')).arg(PROGRAM_NAME));
17956 }
17957 shxOutputDock->setWindowTitle(QString("SHELXL OUTPUT: %1").arg(argument));
17958 shelxl->start(shelxlPath,al);
17959 wght_cycls++;
17960 }
17961
17962 bool Window::compareWGHTS(QString w1, QString w2, double &diff, double tolerance){
17963 QStringList Ws1, Ws2;
17964 QList<double> Wd1, Wd2;
17965 Ws1 = w1.split(leer);
17966 Ws2 = w2.split(leer);
17967 for (int i = 1; i < Ws1.size(); i++) Wd1.append(Ws1.at(i).toDouble());//0th element will be 'wght' so we don't need it for comarison
17968 for (int i = 1; i < Ws2.size(); i++) Wd2.append(Ws2.at(i).toDouble());
17969 bool same = true;
17970 if (Wd1.size() == Wd2.size()) {
17971 for (int i=0; i < Wd1.size(); i++){
17972 same = (same) && (fabs(Wd1.at(i) - Wd2.at(i)) < tolerance);
17973 diff+=fabs(Wd1.at(i) - Wd2.at(i));
17974 }
17975 }else return false;
17976 return same;
17977 }
17978
17979 void Window::togSop(bool b){
17980 QGroupBox *gpx= qobject_cast<QGroupBox *>(sender());
17981 int nn=gpx->objectName().section('=',1,1).toInt();
17982 if (b) chgl->mol->dontshowSop.removeOne(nn);
17983 else chgl->mol->dontshowSop.append(nn);
17984 chgl->update();
17985 }
17986
17987 void Window::togSel(bool b){
17988 QCheckBox *cbx= qobject_cast<QCheckBox *>(sender());
17989 int nn=cbx->objectName().section('=',1,1).toInt();
17990 if (b) chgl->mol->dontshowSel.removeOne(nn);
17991 else chgl->mol->dontshowSel.append(nn);
17992 chgl->update();
17993 }
17994
17995 void Window::changeInvRad(double r){
17996 chgl->InversionCenterRadius=r;
17997 update();
17998 chgl->update();
17999 }
18000
18001 void Window::changePlaneTransparence(double t){
18002 chgl->planeTransparence=t;
18003 update();
18004 chgl->update();
18005 }
18006
18007 void Window::changeglideVectorThickness(double t){
18008 chgl->glideVectorThickness=t;
18009 update();
18010 chgl->update();
18011 }
18012
18013 void Window::changeaxisThickness(double t){
18014 chgl->axisThickness=t;
18015 update();
18016 chgl->update();
18017 }
18018 void Window::changeplaneFrameThinkness(double t){
18019 chgl->planeFrameThinkness=t;
18020 update();
18021 chgl->update();
18022 }
18023
18024 void Window::sColorDLG(){
18025 QPushButton *but= qobject_cast<QPushButton *>(sender());
18026 QString style = but->styleSheet();// the styl contains the color we want to change here
18027 QString cn=but->objectName();
18028 int nn=cn.section('=',1,1).toInt();// which color we want to change
18029 QList<QPushButton*>bbs = findChildren<QPushButton*>(cn);
18030 int z=bbs.size();
18031 //printf("%d %d %p %p\n",nn,z,but,bbs[0]);
18032
18033 //qDebug()<<cn<<cn.section('=',1,1)<<nn;
18034 QColor c = QColor("#" + style.split(QRegularExpression("#|,")).at(7));
18035 c = QColorDialog::getColor(c, this);
18036 if (c.isValid()) {
18037 chgl->mol->symmColors[nn]=c;
18038 //*
18039 einstellung->beginGroup("SymmetryElements");
18040 einstellung->beginWriteArray("SymmetryElementColors",107);
18041 for (int i = 0; i < 18; ++i) {
18042 einstellung->setArrayIndex(i);
18043 einstellung->setValue("Color", chgl->mol->symmColors[i]);
18044 }
18045 einstellung->endArray();
18046 einstellung->endGroup();
18047 einstellung->sync();
18048 // */
18049 for (int i=0; i<z; i++) bbs[i]->setStyleSheet(QString(
18050 "QPushButton {"
18051 "border: 1px solid #00ff00;"
18052 "border-radius: 3px;"
18053 "color: %4;"
18054 "background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 %1, stop: 0.5 %3, stop: 1 %2);"
18055 "}"
18056 "QPushButton:hover {"
18057 "background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 %2, stop: 0.5 %1, stop: 1 %2);"
18058 "}"
18059 "QPushButton:pressed {"
18060 " border: none; /* no border for a flat push button */"
18061 "}"
18062 )
18063 .arg(c.name())
18064 .arg(c.darker(50).name())
18065 .arg(c.lighter(100).name())
18066 .arg((c.lightness()<130)?"#ffffff":"#000000"));
18067 }
18068 }
18069
18070 void Window::symmElements(bool b){
18071 if (!b){
18072 mole.axvecs.clear();
18073 mole.ptriangles.clear();
18074 mole.axcols.clear();
18075 mole.axoprs.clear();
18076 mole.dontshowSel.clear();
18077 mole.dontshowSop.clear();
18078 mole.invoprs.clear();
18079 mole.invvecs.clear();
18080 QDialog *seDlg_ = findChild<QDialog *>("symmElementsDialog");
18081 if (seDlg_!=nullptr) seDlg_->close();
18082 chgl->makeSymmetryElements();
18083 chgl->update();
18084 return;
18085 }
18086 if (mole.asymm.isEmpty()) return;
18087 QDialog *seDlg = new QDialog(this);
18088 seDlg->setObjectName("symmElementsDialog");
18089 seDlg->setMinimumWidth(450);
18090 seDlg->setAttribute(Qt::WA_DeleteOnClose);
18091 seDlg->setWindowTitle("Symmetry Elements");
18092 QGroupBox *gpx =new QGroupBox("Show symmetry elements",seDlg);
18093 gpx->setMinimumWidth(400);
18094 QVBoxLayout *vbl = new QVBoxLayout();
18095 QList<QCheckBox *> alleboxen;
18096 QStringList snn;
18097 snn<<"1" <<"2" <<"3" <<"4" <<"6"
18098 <<"-1" <<"m" <<"-3" <<"-4" <<"-6"
18099 <<"2_1"<<"3_x" <<"4_x" <<"6_x"
18100 <<"g" <<"-3_x"<<"-4_x"<<"-6_x";
18101 mole.findSymmElements();
18102 QGridLayout *hbl0 = new QGridLayout();
18103 for (int i=0,j=0; i<18; i++){
18104 if ((i>5)&&(j%5==0)) j++;
18105 //int colori=27+j;
18106 QColor c=chgl->mol->symmColors.at(i);//QColor::colorNames().at(colori);
18107 QPushButton *colbut = new QPushButton(snn.at(i),seDlg);
18108 colbut->setObjectName(QString("color=%1").arg(i));
18109 connect(colbut,SIGNAL(pressed()),this,SLOT(sColorDLG()));
18110 QCheckBox *fldchk = new QCheckBox(seDlg);
18111 fldchk->setObjectName(QString("Symmetry Element type=%1").arg(i));
18112 fldchk->setChecked(true);
18113 connect(fldchk,SIGNAL(toggled(bool)),this,SLOT(togSel(bool)));
18114 if (i==0)fldchk->setDisabled(true);
18115 colbut->setMinimumWidth(50);
18116 colbut->setStyleSheet(QString(
18117 "QPushButton {"
18118 "border: 1px solid #00ff00;"
18119 "border-radius: 3px;"
18120 "color: %4;"
18121 "background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 %1, stop: 0.5 %3, stop: 1 %2);"
18122 "}"
18123 "QPushButton:hover {"
18124 "background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 %2, stop: 0.5 %1, stop: 1 %2);"
18125 "}"
18126 "QPushButton:pressed {"
18127 " border: none; /* no border for a flat push button */"
18128 "}"
18129 )
18130 .arg(c.name())
18131 .arg(c.darker(50).name())
18132 .arg(c.lighter(100).name())
18133 .arg((c.lightness()<130)?"#ffffff":"#000000"));
18134 hbl0->addWidget(colbut,j/5,(j%5)*2+1,Qt::AlignLeft);
18135 hbl0->addWidget(fldchk,j/5,(j%5)*2,Qt::AlignRight);
18136 j++;
18137 }
18138 QDoubleSpinBox *invrad = new QDoubleSpinBox(this);
18139 invrad->setMinimum(0.02);
18140 invrad->setMaximum(0.5);
18141 invrad->setValue(chgl->InversionCenterRadius);
18142 invrad->setSingleStep(0.01);
18143 connect(invrad,SIGNAL(valueChanged(double)),this,SLOT(changeInvRad(double)));
18144 QDoubleSpinBox *planeTransparence = new QDoubleSpinBox(this);
18145 planeTransparence->setMinimum(0.01);
18146 planeTransparence->setMaximum(1.0);
18147 planeTransparence->setValue(chgl->planeTransparence);
18148 planeTransparence->setSingleStep(0.01);
18149 connect(planeTransparence,SIGNAL(valueChanged(double)),this,SLOT(changePlaneTransparence(double)));
18150
18151 QDoubleSpinBox *planeFrameThinkness = new QDoubleSpinBox(this);
18152 planeFrameThinkness->setMinimum(0.01);
18153 planeFrameThinkness->setMaximum(0.3);
18154 planeFrameThinkness->setValue(chgl->planeFrameThinkness);
18155 planeFrameThinkness->setSingleStep(0.01);
18156 connect(planeFrameThinkness,SIGNAL(valueChanged(double)),this,SLOT(changeplaneFrameThinkness(double)));
18157
18158 QDoubleSpinBox *axisThickness = new QDoubleSpinBox(this);
18159 axisThickness->setMinimum(0.01);
18160 axisThickness->setMaximum(0.3);
18161 axisThickness->setValue(chgl->axisThickness);
18162 axisThickness->setSingleStep(0.01);
18163 connect(axisThickness,SIGNAL(valueChanged(double)),this,SLOT(changeaxisThickness(double)));
18164
18165 QDoubleSpinBox *glideVectorThickness = new QDoubleSpinBox(this);
18166 glideVectorThickness->setMinimum(0.01);
18167 glideVectorThickness->setMaximum(0.3);
18168 glideVectorThickness->setValue(chgl->glideVectorThickness);
18169 glideVectorThickness->setSingleStep(0.01);
18170
18171 connect(glideVectorThickness,SIGNAL(valueChanged(double)),this,SLOT(changeglideVectorThickness(double)));
18172 hbl0->addWidget(new QLabel("Inversion center radius",this),6,0,1,3);
18173 hbl0->addWidget(invrad,6,3,1,2);
18174 hbl0->addWidget(new QLabel("Plane transparence",this),6,5,1,4);
18175 hbl0->addWidget(planeTransparence,6,8,1,2);
18176
18177 hbl0->addWidget(new QLabel("Plane Frame Thickness",this),7,0,1,3);
18178 hbl0->addWidget(planeFrameThinkness,7,3,1,2);
18179 hbl0->addWidget(new QLabel("Glide Vector Thickness",this),7,5,1,4);
18180 hbl0->addWidget(glideVectorThickness,7,8,1,2);
18181 hbl0->addWidget(new QLabel("Axis Thickness",this),8,0,1,3);
18182 hbl0->addWidget(axisThickness,8,3,1,2);
18183
18184 vbl->addLayout(hbl0);
18185 for (int n=0; n<mole.cell.symmops.size(); n++){
18186 int fold=0;
18187 V3 axis;
18188 QString sname=mole.nameSymmOp(mole.cell.symmops.at(n),fold,axis);
18189 V3 p = V3(0,0,0);
18190 QList<V3>pts;
18191 chgl->mol->specialPts(mole.cell.symmops.at(n),mole.cell.trans.at(n),pts);
18192 if (!pts.isEmpty()) p=pts.at(0);
18193 pts.clear();
18194 V3 pp = mole.cell.symmops.at(n) * p + mole.cell.trans.at(n);
18195 pp.x = pp.x - floor(pp.x+0.01);
18196 pp.y = pp.y - floor(pp.y+0.01);
18197 pp.z = pp.z - floor(pp.z+0.01);
18198 //V3 tfz=(pp-p);
18199 //printf("%g %g %g %g %g %g %g %g %g axis %g %g %g\n",pp.x,pp.y,pp.z, p.x,p.y,p.z, tfz.x,tfz.y,tfz.z, axis.x,axis.y,axis.z);
18200 double screwy = (fold==-2)?0.0:sqrt(Norm(pp-p));
18201 V3 screw = screwy * axis;
18202
18203 screw.x = screw.x - floor(screw.x+0.01);
18204 screw.y = screw.y - floor(screw.y+0.01);
18205 screw.z = screw.z - floor(screw.z+0.01);
18206 V3 glide= V3(0,0,0);
18207 if (fold==-2){
18208 glide = mole.cell.symmops.at(n) * mole.cell.trans.at(n);
18209 glide = (mole.cell.trans.at(n) + glide) * 0.5;
18210 }
18211 bool isTrans=(Norm(glide)>0.01)||(Norm(screw)>0.01);
18212 QString schraubstock=(isTrans)?QString("(%1,%2,%3)").arg(screw.x+glide.x).arg(screw.y+glide.y).arg(screw.z+glide.z):"";
18213 QString shname=chgl->mol->symmcode2human(n);
18214 QGroupBox *gpx2 = new QGroupBox(QString("#%1 '%2' %3 %4").arg(n+1).arg(shname).arg(sname).arg(schraubstock),seDlg);
18215 gpx2->setCheckable(true);
18216 gpx2->setChecked(true);
18217 if (fold==1){
18218 gpx2->setEnabled(false);
18219 }
18220 gpx2->setObjectName(QString("%1=%2").arg(shname).arg(n));
18221 gpx2->setMinimumWidth(380);
18222 connect(gpx2,SIGNAL(toggled(bool)),this,SLOT(togSop(bool)));
18223 //int colori=26+abs(fold);
18224 //colori+=(fold<0)?5:0;
18225 //colori+=(isTrans)?10:0;
18226 int colorj=abs(fold)-1;
18227 colorj+=(fold<0)?5:0;
18228 colorj+=(fold==6)?-1:0;
18229 colorj+=(fold==-6)?-1:0;
18230 colorj+=(isTrans)?9:0;
18231 colorj+=((isTrans)&&(fold<0))?-1:0;
18232 //printf("colori = %d fold = %d trans = %d\n",colorj,fold,isTrans);
18233 QColor c=chgl->mol->symmColors.at(colorj);//QColor::colorNames().at(colori);
18234 QPushButton *colbut = new QPushButton(shname, seDlg);
18235 colbut->setStyleSheet(QString(
18236 "QPushButton {"
18237 "border: 1px solid #00ff00;"
18238 "border-radius: 3px;"
18239 "color: %4;"
18240 "background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 %1, stop: 0.5 %3, stop: 1 %2);"
18241 "}"
18242 "QPushButton:hover {"
18243 "background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 %2, stop: 0.5 %1, stop: 1 %2);"
18244 "}"
18245 "QPushButton:pressed {"
18246 " border: none; /* no border for a flat push button */"
18247 "}"
18248 )
18249 .arg(c.name())
18250 .arg(c.darker(50).name())
18251 .arg(c.lighter(100).name())
18252 .arg((c.lightness()<130)?"#ffffff":"#000000"));
18253 colbut->setObjectName(QString("color=%1").arg(colorj));
18254 connect(colbut,SIGNAL(pressed()),this,SLOT(sColorDLG()));
18255 QHBoxLayout *hbl1 = new QHBoxLayout();
18256 hbl1->addWidget(colbut);
18257 gpx2->setLayout(hbl1);
18258 vbl->addWidget(gpx2);
18259 /*
18260 alleboxen.append(boxen);
18261 for (int j=0;j<boxen.size();j++){
18262 int idx=1<<j;
18263 boxen[j]->setChecked(mole.asymm.at(i).fixFlag&idx);
18264 map->setMapping(boxen[j],allIx++);
18265 connect(boxen[j], SIGNAL(stateChanged(int)), map, SLOT(map()));
18266 }
18267 */
18268 }
18269 //connect(map, SIGNAL(mapped(int)), this, SLOT(changeFixes(int)));
18270 gpx->setLayout(vbl);
18271 QVBoxLayout *la = new QVBoxLayout();
18272 QScrollArea *qsa = new QScrollArea(seDlg);
18273 qsa->setWidget(gpx);
18274 la->addWidget(qsa);
18275 seDlg->setLayout(la);
18276 seDlg->show();
18277 printf("SYMM SALA BUMM!\n %d %d %d\n", chgl->mol->axvecs.size(), chgl->mol->invvecs.size(), chgl->mol->ptriangles.size());
18278 chgl->makeSymmetryElements();
18279 chgl->update();
18280 }
18281
18282 void Window::fixIt(){
18283 if (mole.asymm.isEmpty()) return;
18284 QDialog *fixDlg = new QDialog(this);
18285 QGroupBox *gpx =new QGroupBox("Checked parameters will not be refined.",fixDlg);
18286 QVBoxLayout *vbl = new QVBoxLayout();
18287 QList<QCheckBox *> alleboxen;
18288 QSignalMapper *map = new QSignalMapper(this);
18289 int allIx=0;
18290 for (int i=0; i<mole.asymm.size(); i++){
18291 allIx=10*i;
18292 if (mole.asymm.at(i).an<0) continue;
18293 QGroupBox *gpx2 = new QGroupBox(mole.asymm.at(i).Label,fixDlg);
18294 QList<QCheckBox *> boxen;
18295 gpx2->setAlignment(Qt::AlignRight);
18296 QVBoxLayout *v = new QVBoxLayout(gpx2);
18297 QHBoxLayout *hbl1 = new QHBoxLayout();
18298 QCheckBox *Xlab = new QCheckBox(QString::number(mole.asymm.at(i).frac.x,'f',6).prepend("X: "),fixDlg);
18299 QCheckBox *Ylab = new QCheckBox(QString::number(mole.asymm.at(i).frac.y,'f',6).prepend("Y: "),fixDlg);
18300 QCheckBox *Zlab = new QCheckBox(QString::number(mole.asymm.at(i).frac.z,'f',6).prepend("Z: "),fixDlg);
18301 QCheckBox *Olab = new QCheckBox(QString::number(mole.asymm.at(i).sof,'f',6).prepend("site occupancy: "),fixDlg);
18302 hbl1->addWidget(Xlab);
18303 hbl1->addWidget(Ylab);
18304 hbl1->addWidget(Zlab);
18305 hbl1->addWidget(Olab);
18306 boxen.append(Xlab);
18307 boxen.append(Ylab);
18308 boxen.append(Zlab);
18309 boxen.append(Olab);
18310 v->addLayout(hbl1);
18311 if (!mole.asymm.at(i).isIso) {
18312 QHBoxLayout *hbl2 = new QHBoxLayout();
18313 QCheckBox *M11lab = new QCheckBox(QString::number(mole.asymm.at(i).uf.m11,'f',6).prepend("U11: "),fixDlg);
18314 QCheckBox *M22lab = new QCheckBox(QString::number(mole.asymm.at(i).uf.m22,'f',6).prepend("U22: "),fixDlg);
18315 QCheckBox *M33lab = new QCheckBox(QString::number(mole.asymm.at(i).uf.m33,'f',6).prepend("U33: "),fixDlg);
18316 QCheckBox *M23lab = new QCheckBox(QString::number(mole.asymm.at(i).uf.m23,'f',6).prepend("U23: "),fixDlg);
18317 QCheckBox *M13lab = new QCheckBox(QString::number(mole.asymm.at(i).uf.m13,'f',6).prepend("U13: "),fixDlg);
18318 QCheckBox *M12lab = new QCheckBox(QString::number(mole.asymm.at(i).uf.m12,'f',6).prepend("U12: "),fixDlg);
18319 hbl2->addWidget(M11lab);
18320 hbl2->addWidget(M22lab);
18321 hbl2->addWidget(M33lab);
18322 hbl2->addWidget(M23lab);
18323 hbl2->addWidget(M13lab);
18324 hbl2->addWidget(M12lab);
18325 boxen.append(M11lab);
18326 boxen.append(M22lab);
18327 boxen.append(M33lab);
18328 boxen.append(M23lab);
18329 boxen.append(M13lab);
18330 boxen.append(M12lab);
18331 v->addLayout(hbl2);
18332 }
18333 vbl->addWidget(gpx2);
18334 alleboxen.append(boxen);
18335 for (int j=0;j<boxen.size();j++){
18336 int idx=1<<j;
18337 boxen[j]->setChecked(mole.asymm.at(i).fixFlag&idx);
18338 map->setMapping(boxen[j],allIx++);
18339 connect(boxen[j], SIGNAL(stateChanged(int)), map, SLOT(map()));
18340 }
18341
18342
18343 }
18344 #if (QT_VERSION >= 0x050f00)
18345 //connect(map, SIGNAL(mappedInt(int)), this, SLOT(changeFixes(int)));
18346 connect(map, &QSignalMapper::mappedInt, this, &Window::changeFixes);
18347 //printf("QT_VERSION %x %s \n",QT_VERSION,(QT_VERSION >= 0x050f00)?"true":"false");
18348 #else
18349 connect(map, SIGNAL(mapped(int)), this, SLOT(changeFixes(int)));
18350 //printf("Why? QT_VERSION %x %s \n",QT_VERSION,(QT_VERSION >= 0x050f00)?"true":"false");
18351 #endif
18352 QDialogButtonBox *bb = new QDialogButtonBox(QDialogButtonBox::Ok|QDialogButtonBox::Cancel,Qt::Horizontal,fixDlg);
18353 connect(bb, SIGNAL(accepted()), fixDlg, SLOT(accept()));
18354 connect(bb, SIGNAL(rejected()), fixDlg, SLOT(reject()));
18355 gpx->setLayout(vbl);
18356 QVBoxLayout *la = new QVBoxLayout();
18357 QScrollArea *qsa = new QScrollArea(fixDlg);
18358 qsa->setWidget(gpx);
18359 la->addWidget(qsa);
18360 la->addWidget(bb);
18361 fixDlg->setLayout(la);
18362 fixDlg->exec();
18363 fixDlg->deleteLater();
18364
18365 }
18366
18367 void Window::changeFixes(int i){
18368 int da=i/10;
18369 int blub=i%10;
18370 int vor=-1;
18371 if (da<mole.asymm.size()){
18372
18373 vor=mole.asymm[da].fixFlag;
18374 if (vor&(1<<blub)) {
18375 mole.asymm[da].fixFlag-=1<<blub;
18376 } else {
18377 mole.asymm[da].fixFlag|=1<<blub;
18378 }
18379 jumpToAtom(da);
18380 QTextCursor c = editor->textCursor();
18381 c.movePosition(QTextCursor::EndOfLine,QTextCursor::KeepAnchor);
18382 if (c.selectedText().contains("=")) {
18383 c.movePosition(QTextCursor::Down,QTextCursor::KeepAnchor);
18384 c.movePosition(QTextCursor::EndOfLine,QTextCursor::KeepAnchor);
18385 }
18386 int end= (mole.asymm.at(da).isIso)?4:10;
18387 QString sn=c.selectedText();
18388 sn.remove(QRegularExpression(R"(^\S+\s+\d+\s+)"));
18389 sn.remove(QRegularExpression(R"([=]\S+\s)",QRegularExpression::MultilineOption|QRegularExpression::DotMatchesEverythingOption));
18390 QStringList snl=sn.split(QRegularExpression(R"(\s+)"));
18391 int egal=0;
18392 double w[10];
18393 int _m[10];
18394 for (int j=0; j<snl.size();j++){
18395 w[j]=getNumber(snl.at(j).toDouble(),fvar,j,egal);
18396 _m[j]=getFvarNr(snl.at(j).toDouble(),fvar);
18397 }
18398 for (int j=0; j<end; j++){
18399 int tst=1<<j;
18400 int pm=(tst&vor)?1:0;
18401 int m=(tst&mole.asymm.at(da).fixFlag)?1:0;
18402 /* free variables come here ... m*fvarNr*fvarType
18403 *
18404 * */
18405 if (pm&&m) w[j]=snl.at(j).toDouble();//if fix was there then keep fvar binding.
18406 else w[j]+=m*10;
18407 //printf("i%d %d %d %f tst %d %f vor%d fix%d %d %d\n",j ,m,_m[j],w[j],tst,snl.at(j).toDouble(),vor,mole.asymm.at(da).fixFlag,da,i);
18408 }
18409 QString neu=(end==10)?QString("%1 %2 %3 %4 %5 %6 %7 %8 =\n %9 %10 %11 %12")
18410 .arg(mole.asymm.at(da).Label.section('_',0,0),-4)
18411 .arg(qMax(1,editor->sfac.indexOf(mole.asymm.at(da).an)+1))
18412 .arg(w[0],11,'f',6)
18413 .arg(w[1],11,'f',6)
18414 .arg(w[2],11,'f',6)
18415 .arg(w[3],10,'f',5)
18416 .arg(w[4],10,'f',5)
18417 .arg(w[5],10,'f',5)
18418 .arg(w[6],10,'f',5)
18419 .arg(w[7],10,'f',5)
18420 .arg(w[8],10,'f',5)
18421 .arg(w[9],10,'f',5)
18422 :QString("%1 %2 %3 %4 %5 %6 %7")
18423 .arg(mole.asymm.at(da).Label.section('_',0,0),-4)
18424 .arg(qMax(1,editor->sfac.indexOf(mole.asymm.at(da).an)+1))
18425 .arg(w[0],11,'f',6)
18426 .arg(w[1],11,'f',6)
18427 .arg(w[2],11,'f',6)
18428 .arg(w[3],10,'f',5)
18429 .arg(w[4],10,'f',5);
18430 c.insertText(neu);
18431 mole.showatoms[da].orginalLine=mole.asymm[da].orginalLine=neu;
18432 mole.asymm[da].orginalLine.truncate(77);
18433 //qDebug()<<da<<mole.asymm.at(da).orginalLine;
18434 update();
18435
18436 }
18437
18438
18439 }
18440
18441 bool Window::maybeSave() {
18442 if (!editor->document()->isModified()) return true;
18443 QMessageBox::StandardButton ret;
18444 ret = QMessageBox::warning(this, tr("Application"),
18445 tr("The document has been modified.\n"
18446 "Do you want to save your changes?"),
18447 QMessageBox::Save | QMessageBox::Discard
18448 | QMessageBox::Cancel);
18449 if (ret == QMessageBox::Save){
18450 return fileSave();
18451 }
18452 else {if (ret == QMessageBox::Cancel)
18453 return false;
18454 }
18455 return true;
18456 }
18457
18458 bool Window::maybeSave2() {
18459 if (!editor->document()->isModified()) return true;
18460 if (doNotAnnoyMe) return fileSave();
18461 QMessageBox *box=new QMessageBox(QMessageBox::Question,tr("Application"),
18462 tr("The document has been modified.\n"
18463 "Do you want to save your changes?"),
18464 QMessageBox::Save | QMessageBox::Discard
18465 | QMessageBox::Cancel);
18466 QPushButton *ischkansonetabeida = box->addButton("Always!",QMessageBox::ActionRole);
18467 box->setDefaultButton(QMessageBox::Save);
18468 int ret;
18469 ret = box->exec();
18470
18471 if (box->clickedButton()==ischkansonetabeida){
18472 doNotAnnoyMe=true;
18473 einstellung->beginGroup("DoNotAskFileSave");
18474 einstellung->setValue("DoNotAnnoyMe",doNotAnnoyMe);
18475 einstellung->endGroup();
18476 return fileSave();
18477 }
18478 if (ret == QMessageBox::Save){
18479 return fileSave();
18480 }
18481 else {if (ret == QMessageBox::Cancel)
18482 return false;
18483 }
18484 return true;
18485 }
18486
18487 QString Window::strippedName(const QString &fullFileName) {
18488 return QFileInfo(fullFileName).fileName();
18489 }
18490
18491 void Window::updateRecentFileActions() {
18492 QSettings *einstellung =new QSettings( QSettings::IniFormat, QSettings::UserScope ,PROGRAM_NAME, mole.mynewnameis );
18493 einstellung->beginGroup("Files");
18494 QStringList files = einstellung->value("recentFileList").toStringList();
18495 int numRecentFiles = qMin(files.size(), (int)MaxRecentFiles);
18496
18497 for (int i = 0; i < numRecentFiles; ++i) {
18498 QString text = tr("&%1 %2").arg(i + 1).arg(strippedName(files[i]));
18499 recentFileActs[i]->setText(text);
18500 recentFileActs[i]->setData(files[i]);
18501 recentFileActs[i]->setStatusTip(files[i]);
18502 recentFileActs[i]->setVisible(true);
18503 }
18504 for (int j = numRecentFiles; j < MaxRecentFiles; ++j)
18505 recentFileActs[j]->setVisible(false);
18506 einstellung->endGroup();
18507 delete einstellung;
18508 }
18509
18510 void Window::linkHelp(){
18511 QMessageBox::about(this, tr("%1-Help").arg(PROGRAM_NAME),
18512 tr("<h1>%1-Help</h1><br> The offline help has ben removed. <a href=\"http://shelxle.org/shelx/help/\">Click here for Online Help.</a>\n"
18513 ).arg(PROGRAM_NAME));
18514 }
18515
18516 void Window::aboutXLE(){
18517 QString MEM;
18518 #if defined Q_WS_WIN || defined Q_OS_WIN
18519 MEMORYSTATUSEX memory_status;
18520
18521 ZeroMemory(&memory_status, sizeof(MEMORYSTATUSEX));
18522 memory_status.dwLength = sizeof(MEMORYSTATUSEX);
18523 if (GlobalMemoryStatusEx(&memory_status)) {
18524 double total = memory_status.ullTotalPhys;
18525 double avail = memory_status.ullAvailPhys;
18526 QString tu,au;
18527 int it=0,ia=0;
18528 while (total>1000.0){
18529 it++;
18530 total/=1024.0;
18531 }
18532 while (avail>1000.0){
18533 ia++;
18534 avail/=1024.0;
18535 }
18536 switch (it){
18537 case 0: tu="B"; break;
18538 case 1: tu="kB"; break;
18539 case 2: tu="MB"; break;
18540 case 3: tu="GB"; break;
18541 }
18542 switch (ia){
18543 case 0: au="B"; break;
18544 case 1: au="kB"; break;
18545 case 2: au="MB"; break;
18546 case 3: au="GB"; break;
18547 }
18548
18549
18550 MEM.append(QString("RAM: %1 %4 Available %2 %5 Memory load %3%\n").arg(total,0,'f',2).arg(avail,0,'f',2).arg(memory_status.dwMemoryLoad).arg(tu).arg(au));
18551 } else {
18552 MEM.append("Unknown RAM\n");
18553 }
18554 #endif
18555 QString openGLVersion=QString("OpenGL Version %1").arg((char *)glGetString(GL_VERSION));
18556 int glminor,glmajor;
18557 const char *verstring=(char*)glGetString(GL_VERSION);
18558 if ((verstring==nullptr)||(sscanf(verstring,"%d.%d",&glmajor,&glminor)!=2)) glminor=glmajor=0;
18559 QString GLSLVersion=(glmajor<2)?"Unsupported GLSL Version":QString("GLSL Version %1 (minimum 4.00)").arg((char*)glGetString(GL_SHADING_LANGUAGE_VERSION));
18560 //qDebug() << (QString(qgetenv("PATH")).split(QRegularExpression("[;:]")));
18561 QMessageBox::about(this, tr("About %1").arg(PROGRAM_NAME),
18562 QString("<p><b>%1</b>&nbsp;is&nbsp;a&nbsp;tool&nbsp;for&nbsp;<b>SHELX</b>&nbsp;small&nbsp;"\
18563 "molecule&nbsp;refinement.&nbsp;It&nbsp;combines&nbsp;an&nbsp;editor with simple syntax highlighting "\
18564 "with an OpenGL representation of the structure.</p> "\
18565 "<p><img src=\""+theIconPath+"cbh.png\" alt=\"Christian B. H&uuml;bschle\">"\
18566 "<img src=\""+theIconPath+"gms.png\" alt=\"George M. Sheldrick\"></p> "\
18567 "<p><b>%1</b> is written by <b>Christian B. H&uuml;bschle</b> "\
18568 " at the University of G&ouml;ttingen. "\
18569 "Some parts of the program are taken from Qt examples, others are from the "\
18570 "<b>SHELX</b> author <b>George M. Sheldrick</b> and/or his group Members</p> "\
18571 "<font color=darkgreen> Please cite: <br>C. B. H&uuml;bschle, G. M. Sheldrick and B. Dittrich<br>"
18572 "<em>'ShelXle:&nbsp;a&nbsp;Qt&nbsp;graphical&nbsp;user&nbsp;interface&nbsp;for&nbsp;SHELXL'</em><br>"
18573 "<em>J. Appl. Cryst.</em> (2011). <b>44</b>, 1281-1284 .</font><br>"
18574 "<a href=\"http://dx.doi.org/10.1107/S0021889811043202\">[&nbsp;doi:10.1107/S0021889811043202&nbsp;]</a>"
18575 "<p>Please visit the following web sites:<br>"
18576 "<a href=\"http://shelx.uni-goettingen.de\"><b>SHELX</b> site</a><p>"
18577 "<p><a href=\"http://shelxle.org/shelx/index.php\">"
18578 "Dowload new versions from here</a></p>"
18579 "<p>This is a %11 bit Version.</p> "
18580 "<p>This is Revision <b>%2</b>"
18581 //"last build was: <b>%3</b></p> "
18582 "<p>The latest Version available is '%6'"
18583 "<p>The Version of Qt used is %4. </p> "\
18584 "<p>%5<br>%8<br>%9 </p><p>The settings of this program are stored in: <b>%7</b><p>%10")
18585 .arg(PROGRAM_NAME)
18586 .arg(Revision)
18587 // .arg(datum)
18588 .arg(qVersion ())
18589 .arg(openGLVersion)
18590 .arg(latestRev)
18591 .arg(einstellung->fileName ())
18592 .arg(QString("Graphics card: %1") .arg((char *)glGetString(GL_RENDERER)))
18593 .arg(GLSLVersion)
18594 .arg(MEM)
18595 .arg(BitWidth)
18596 );
18597 }
18598
18599 void Window::hintLhide(){
18600 hintL->hide();
18601 einstellung->beginGroup("SaveHint");
18602 einstellung->setValue("ShowRenameHint",hintL->isVisible());
18603 einstellung->endGroup();
18604 }
18605
18606 void Window::symmetryManager(){
18607 prosaTimer.setSingleShot(true);
18608 QDialog *sman = new QDialog(this);
18609 sman->setWindowTitle("Symmetry Manager");
18610 QGridLayout *lt = new QGridLayout(sman);
18611 sman->setMinimumSize(400,300);
18612
18613 OrtepCodesbrowser=new QTextBrowser(sman);
18614 OrtepCodesbrowser->setOpenLinks(false);
18615 OrtepCodesbrowser->setLineWrapMode(QTextEdit::NoWrap);
18616 symmIntBx = new QSpinBox(sman);
18617 symmIntBx->setMinimum(1);
18618 symmIntBx->setMaximum(mole.cell.symmops.size());
18619
18620 symmXBx = new QSpinBox(sman);
18621 symmXBx->setMinimum(1);
18622 symmXBx->setMaximum(9);
18623 symmXBx->setValue(5);
18624
18625 symmYBx = new QSpinBox(sman);
18626 symmYBx->setMinimum(1);
18627 symmYBx->setMaximum(9);
18628 symmYBx->setValue(5);
18629
18630 symmZBx = new QSpinBox(sman);
18631 symmZBx->setMinimum(1);
18632 symmZBx->setMaximum(9);
18633 symmZBx->setValue(5);
18634
18635
18636 symmFrgBx = new QSpinBox(sman);
18637 symmFrgBx->setMinimum(1);
18638 symmFrgBx->setMaximum(mole.maxmols());
18639 symmFrgBx->setValue(1);
18640 prosaSymm = new QLineEdit();
18641 prosaSymm->setText("x,y,z");
18642 connect(prosaSymm,SIGNAL(textEdited(QString)),this,SLOT(updateSM4(QString)));
18643 connect(symmIntBx,SIGNAL(valueChanged(int)),this,SLOT(updateSM1()));
18644 connect(symmXBx,SIGNAL(valueChanged(int)),this,SLOT(updateSM1()));
18645 connect(symmYBx,SIGNAL(valueChanged(int)),this,SLOT(updateSM1()));
18646 connect(symmZBx,SIGNAL(valueChanged(int)),this,SLOT(updateSM1()));
18647 connect(symmFrgBx,SIGNAL(valueChanged(int)),this,SLOT(updateSM1()));
18648 QLabel *unter = new QLabel("_");
18649 QLabel *doppl = new QLabel(":");
18650 shortestDistanceLabel = new QLabel("<p>Shortest distace to asymmetric unit: 0.00 &Aring;</p>");
18651 QPushButton *addSymmOp=new QPushButton("add symmetry to list");
18652 connect(addSymmOp,SIGNAL(clicked()),this,SLOT(updateSM2()));
18653 QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
18654 connect(buttonBox, SIGNAL(accepted()), sman, SLOT(accept()));
18655 connect(buttonBox, SIGNAL(rejected()), sman, SLOT(reject()));
18656 connect(OrtepCodesbrowser,SIGNAL(anchorClicked( const QUrl &)), this ,SLOT(updateSM3(const QUrl &)));
18657 lt->addWidget(new QLabel("List of symmetry in use:"),0,0,1,12,Qt::AlignHCenter);
18658 // lt->addWidget(SymmetryCodesbrowser,1,0,1,5);
18659 lt->addWidget(OrtepCodesbrowser,1,0,1,12);
18660 lt->addWidget(new QLabel("symmetry operation"),2,0,1,5);
18661 lt->addWidget(new QLabel("sym No"),2,5,1,1);
18662 lt->addWidget(new QLabel("translation"),2,7,1,3,Qt::AlignHCenter);
18663 lt->addWidget(new QLabel("fragment"),2,11,1,1);
18664 lt->addWidget(prosaSymm,3,0,1,5);
18665 lt->addWidget(symmIntBx,3,5,1,1);
18666 lt->addWidget(unter,3,6,1,1);
18667 lt->addWidget(symmXBx,3,7,1,1);
18668 lt->addWidget(symmYBx,3,8,1,1);
18669 lt->addWidget(symmZBx,3,9,1,1);
18670 lt->addWidget(doppl,3,10,1,1);
18671 lt->addWidget(symmFrgBx,3,11,1,1);
18672 lt->addWidget(shortestDistanceLabel,4,0,1,9);
18673 lt->addWidget(addSymmOp,4,9,1,3);
18674 lt->addWidget(buttonBox,10,0,1,12);
18675 sman->setLayout(lt);
18676 QStringList oldsymm=mole.usedSymmetry;
18677 QString text="<table><tr><th>ID</th><th>symmetry op. </th><th style=\"background:#d4d4d4\">internal code</th><th></th><th></th><th>distance to asymmetric unit</th></tr>";;
18678 for (int i=0; i<mole.usedSymmetry.size(); i++)
18679 text.append(QString("<tr><th>$%6</th><td> %5 </td><th style=\"background:#d4d4d4\"> %1</th> <td><a href=\"%2\">remove</a> </td><td> <a href=\"%4\">edit</a></td><td> %3 &Aring;</td></tr>")
18680 .arg(mole.usedSymmetry.at(i))
18681 .arg(i)
18682 .arg(mole.shortestDistance(mole.usedSymmetry.at(i)),0,'f',2)
18683 .arg(-1-i)
18684 .arg(mole.symmcode2human(mole.usedSymmetry.at(i)))
18685 .arg(i+1));
18686 text.append("</table>");
18687 OrtepCodesbrowser->setHtml(text);
18688
18689 if (sman->exec()==QDialog::Accepted){
18690
18691 mole.showatoms.clear();
18692 mole.showbonds.clear();
18693 mole.showatoms+=mole.asymm;
18694 mole.packer(mole.usedSymmetry);
18695 mole.showbonds =
18696 mole.connecting(mole.showatoms);
18697 chgl->mol->selectedatoms.clear();
18698
18699 chgl->updateBondActions();
18700 loadMolInTest();
18701 }else{
18702 mole.usedSymmetry.clear();
18703 mole.usedSymmetry=oldsymm;
18704 oldsymm.clear();
18705
18706 mole.showatoms.clear();
18707
18708 mole.showatoms+=mole.asymm;
18709 mole.showbonds.clear();
18710 mole.packer(mole.usedSymmetry);
18711 mole.showbonds =
18712 mole.connecting(mole.showatoms);
18713 chgl->mol->selectedatoms.clear();
18714
18715 chgl->updateBondActions();
18716
18717 loadMolInTest();
18718 }
18719 ;
18720 delete buttonBox ;
18721
18722 text.clear();
18723 OrtepCodesbrowser->clear();
18724 delete OrtepCodesbrowser;
18725 delete symmIntBx;
18726 delete symmXBx;
18727 delete symmYBx;
18728 delete symmZBx;
18729 delete doppl;
18730 delete unter;
18731 delete symmFrgBx;
18732 delete shortestDistanceLabel;
18733 delete lt;
18734 delete sman;
18735
18736 chgl->update();
18737 update();
18738 chgl->update();
18739 }
18740
18741 void Window::updateSM1(){
18742 if (prosaTimer.isActive()) return;
18743 QString t=QString("%1_%2%3%4:%5")
18744 .arg(symmIntBx->value())
18745 .arg(symmXBx->value())
18746 .arg(symmYBx->value())
18747 .arg(symmZBx->value())
18748 .arg(symmFrgBx->value());
18749 shortestDistanceLabel->setText(QString("<p>Shortest distace to asymmetric unit: %1 &Aring;</p>").arg(
18750 mole.shortestDistance(t),0,'f',2));
18751 prosaSymm->setText(mole.symmcode2human(t));
18752 QPalette p = prosaSymm->palette();
18753 p.setBrush(QPalette::Active,QPalette::Base,Qt::white);
18754 prosaSymm->setPalette(p);
18755 }
18756
18757 void Window::updateSM2(){
18758 QString t=QString("%1_%2%3%4:%5,")
18759 .arg(symmIntBx->value())
18760 .arg(symmXBx->value())
18761 .arg(symmYBx->value())
18762 .arg(symmZBx->value())
18763 .arg(symmFrgBx->value());
18764 if (t.startsWith("1_555:1"))return;
18765 OrtepCodesbrowser->clear();
18766 if (!mole.usedSymmetry.contains(t)) mole.usedSymmetry.append(t);
18767 QString text="<table><tr><th>symmetry op. </th><th style=\"background:#d4d4d4\">internal code</th><th></th><th></th><th>distance to asymmetric unit</th></tr>";;
18768 for (int i=0; i<mole.usedSymmetry.size(); i++)
18769 text.append(QString("<tr><td>%5 </td><th style=\"background:#d4d4d4\"> %1</th> <td><a href=\"%2\">remove</a> </td><td> <a href=\"%4\">edit</a></td><td> %3 &Aring;</td></tr>")
18770 .arg(mole.usedSymmetry.at(i))
18771 .arg(i)
18772 .arg(mole.shortestDistance(mole.usedSymmetry.at(i)),0,'f',2)
18773 .arg(-1-i)
18774 .arg(mole.symmcode2human(mole.usedSymmetry.at(i))));
18775 text.append("</table>");
18776 OrtepCodesbrowser->setHtml(text);
18777
18778 }
18779
18780 void Window::updateSM3(const QUrl link){
18781 int index = link.toString().toInt();
18782 if (index<0) {
18783 index=-index-1;
18784 QString t = mole.usedSymmetry.at(index);
18785 int s,h,k,l,symmgroup;
18786 sscanf(t.toLatin1(),"%d_%1d%1d%1d:%d",&s,&h,&k,&l,&symmgroup);
18787 shortestDistanceLabel->setText(QString("<p>Shortest distace to asymmetric unit: %1 &Aring;</p>").arg(
18788 mole.shortestDistance(t),0,'f',2));
18789 prosaTimer.stop();
18790 symmIntBx->setValue(s);
18791 symmXBx->setValue(h);
18792 symmYBx->setValue(k);
18793 symmZBx->setValue(l);
18794 symmFrgBx->setValue(symmgroup);
18795 return;
18796 }
18797 if (mole.usedSymmetry.size()<=index) return;
18798 mole.usedSymmetry.removeAt(index);
18799 QString text="<table><tr><th>symmetry op. </th><th style=\"background:#d4d4d4\">internal code</th><th></th><th></th><th>distance to asymmetric unit</th></tr>";
18800 for (int i=0; i<mole.usedSymmetry.size(); i++)
18801 text.append(QString("<tr><td>%5 </td><th style=\"background:#d4d4d4\"> %1</th> <td><a href=\"%2\">remove</a> </td><td> <a href=\"%4\">edit</a></td><td> %3 &Aring;</td></tr>")
18802 .arg(mole.usedSymmetry.at(i))
18803 .arg(i)
18804 .arg(mole.shortestDistance(mole.usedSymmetry.at(i)),0,'f',2)
18805 .arg(-1-i)
18806 .arg(mole.symmcode2human(mole.usedSymmetry.at(i)))
18807 );
18808 text.append("</table>");
18809 OrtepCodesbrowser->setHtml(text);
18810
18811 }
18812
18813 void Window::updateSM4(QString symtxt){
18814 QString t = mole.symmCard2Code(symtxt);
18815 QPalette p = prosaSymm->palette();
18816
18817 p.setBrush(QPalette::Active,QPalette::Base,QColor(205,100,100));
18818 if (t.isEmpty()) {prosaSymm->setPalette(p);return;}
18819
18820 p.setBrush(QPalette::Active,QPalette::Base,Qt::white);
18821 int s,h,k,l,symmgroup;
18822 shortestDistanceLabel->setText(QString("<p>Shortest distace to asymmetric unit: %1 &Aring;</p>").arg(
18823 mole.shortestDistance(t),0,'f',2));
18824
18825 sscanf(t.toLatin1(),"%d_%1d%1d%1d:%d",&s,&h,&k,&l,&symmgroup);
18826 prosaTimer.start(80);
18827 symmIntBx->setValue(s);
18828 symmXBx->setValue(h);
18829 symmYBx->setValue(k);
18830 symmZBx->setValue(l);
18831 symmFrgBx->setValue(symmgroup);
18832 prosaSymm->setPalette(p);
18833 update();
18834 }
18835
18836 void Window::insertSADI(int selected){
18837 QString buffer = "SADI 0.02 ";
18838 if (selected>=mole.asymm.size()) return;
18839 QList<int> baerle;// only same sfac type and non H to prevent warnig in lst file. Experts can do what they want if they know what they do by hand
18840 for (int nb=1; nb<mole.knoepfe.at(selected).neighbors.size(); nb++){
18841 if ((mole.knoepfe.at(selected).neighbors.at(nb-1)>=mole.asymm.size())||(mole.knoepfe.at(selected).neighbors.at(nb)>=mole.asymm.size())) continue;
18842 if ((mole.asymm.at(mole.knoepfe.at(selected).neighbors.at(nb-1)).an>0)&&
18843 (mole.asymm.at(mole.knoepfe.at(selected).neighbors.at(nb-1)).an==mole.asymm.at(mole.knoepfe.at(selected).neighbors.at(nb)).an)){
18844 if (!baerle.contains(mole.knoepfe.at(selected).neighbors.at(nb-1))) baerle.append(mole.knoepfe.at(selected).neighbors.at(nb-1));
18845 if (!baerle.contains(mole.knoepfe.at(selected).neighbors.at(nb))) baerle.append(mole.knoepfe.at(selected).neighbors.at(nb));
18846 }
18847 }
18848 for (int n=0; n < baerle.size(); n++){
18849 MyAtom atom1 = mole.asymm.at(selected);
18850 QString resi1 = (atom1.resiNr > 0)?QString("_%1").arg(atom1.resiNr):"";
18851 MyAtom atom2 = mole.asymm.at(baerle.at(n));
18852 QString resi2 = (atom2.resiNr > 0)?QString("_%1").arg(atom2.resiNr):"";
18853 buffer += atom1.Label.section("_", 0, 0) + resi1 + " " + atom2.Label.section("_", 0, 0) + resi2 + " " ;
18854 }
18855 if (buffer.size()<12) {
18856 return;
18857 }
18858 QTextDocument *document = editor->document();
18859 QTextCursor cursor = editor->textCursor();
18860 cursor.movePosition(QTextCursor::Start,QTextCursor::MoveAnchor);
18861 cursor = document->find(unitinst,cursor);
18862 cursor.movePosition(QTextCursor::StartOfLine,QTextCursor::MoveAnchor);
18863 cursor.movePosition(QTextCursor::Down,QTextCursor::MoveAnchor);
18864 cursor.insertText(DSRGui::textWrap(buffer.simplified()) + "\n");
18865 mole.selectedatoms.clear();
18866 }
18867
18868 void Window::raiseTaff(){
18869 tabifyDockWidget(shxOutputDock, infotainmentDock);
18870 resid_label->clear();
18871 restr_table->clear();
18872 infotainmentDock->show();
18873 infotainmentDock->raise();
18874 vis_settings->beginGroup("infotaiment");
18875 vis_settings->setValue("info_as_default", true);
18876 vis_settings->endGroup();
18877 }
18878
18879 void Window::raiseTaz(){
18880 tabifyDockWidget(shxOutputDock, infotainmentDock);
18881 shxOutputDock->show();
18882 shxOutputDock->raise();
18883 vis_settings->beginGroup("infotaiment");
18884 vis_settings->setValue("info_as_default", false);
18885 vis_settings->endGroup();
18886 }
18887
18888 int Window::cifCheckSum(const QString &block){
18889 long long int sum=0;
18890 for (int i=0; i<block.size(); i++){
18891 if (static_cast<unsigned char>(block.at(i).toLatin1()) > ' '){
18892 sum+=block.at(i).toLatin1();
18893 }
18894 }
18895 sum %= 714025;
18896 sum *= 1366;
18897 sum += 150889;
18898 sum %= 714025;
18899 sum %= 100000;
18900
18901 /*
18902 def calc_checksum(input_str: str) -> int:
18903 """
18904 Calculates the shelx checksum of a cif file.
18905 The original algorithm was posted by Berthold Stöger on the Bruker Users Mailing list.
18906 """
18907 crc_sum = 0
18908 try:
18909 input_str = input_str.encode('cp1250', 'ignore')
18910 except Exception:
18911 input_str = input_str.encode('ascii', 'ignore')
18912 for char in input_str:
18913 # print(char)
18914 if char > 32: # ascii 32 is space character
18915 crc_sum += char
18916 crc_sum %= 714025
18917 crc_sum = crc_sum * 1366 + 150889
18918 crc_sum %= 714025
18919 crc_sum %= 100000
18920 return crc_sum
18921 */
18922 return static_cast<int>(sum);
18923 }
18924
18925
18926 void Window::shredCIF(){
18927 /*
18928 QSettings *shrcifset = new QSettings( QSettings::IniFormat, QSettings::UserScope ,PROGRAM_NAME,mole.mynewnameis );
18929 shrcifset->beginGroup("ShredCIF");
18930 shredCIFPath = shrcifset->value("ShredCIF-PATH","").toString();
18931 shrcifset->endGroup();
18932 //inspired by Daniels 'which' in DSRGUI
18933 QStringList foundInPath;
18934 foundInPath.clear();
18935 // qDebug()<<shredCIFPath.isEmpty()<<!QFileInfo(shredCIFPath).isExecutable()<<shredCIFPath;
18936 if ((shredCIFPath.isEmpty())||(!QFileInfo(shredCIFPath).isExecutable())) {
18937 QStringList execlist;
18938 QStringList pathList;
18939 pathList.clear();
18940 execlist.clear();
18941 pathList = QString(qgetenv("PATH")).split(QRegularExpression("[;:]"));
18942 // qDebug()<<pathList;
18943 foreach (QString path, pathList) {
18944 QString fullpath = path+"/shredcif";
18945 QFileInfo fi(fullpath);
18946 if (QFile::exists(fullpath) && (fi.isExecutable())){
18947 foundInPath.append(QDir::cleanPath(fullpath));
18948 }else {
18949 fi.setFile(fullpath+".exe");
18950 // qDebug()<<QDir::cleanPath(fullpath+".exe")<<QFile::exists(fullpath+".exe")<<(fi.isExecutable());
18951 if (QFile::exists(fullpath+".exe") && (fi.isExecutable())){
18952 foundInPath.append(QDir::cleanPath(fullpath+".exe"));
18953 }
18954 }
18955 }
18956
18957 if (foundInPath.isEmpty()){
18958 //file dialog
18959 QString shcf = QFileDialog::getOpenFileName(this, "Where is SHREDCIF? (http://shelx.uni-goettingen.de/download.php)",
18960 QString(),QString(),nullptr,(useNativeDlg->isChecked())?noneopt:QFileDialog::DontUseNativeDialog);
18961 //(QWidget *parent = nullptr, const QString &caption = QString(), const QString &dir = QString(), const QString &filter = QString(), QString *selectedFilter = nullptr, QFileDialog::Options options = Options())
18962 if (shcf.isEmpty()) return; // empty string means probably cancel
18963 if (QFileInfo(shcf).isExecutable()) shredCIFPath = shcf;
18964 }else {
18965 shredCIFPath = foundInPath.first();
18966 }
18967 shrcifset->beginGroup("ShredCIF");
18968 shrcifset->setValue("ShredCIF-PATH",shredCIFPath);
18969 shrcifset->endGroup();
18970 }
18971 // qDebug() << shredCIFPath;
18972 // */
18973
18974 QString cif2shred = QFileDialog::getOpenFileName(this, "Open a CIF to shred",dirName,"Crystallographic Information File (*.cif)"
18975 ,nullptr,(useNativeDlg->isChecked())?noneopt:QFileDialog::DontUseNativeDialog);
18976 if (cif2shred.isEmpty()) return;
18977 QString info;
18978 QString dn=cif2shred.section('/',0,-2), argument=cif2shred.section('/',-1);
18979 QFile ciffi(cif2shred);
18980 ciffi.open(QIODevice::ReadOnly|QIODevice::Text);
18981 QString strcif = QString(ciffi.readAll());
18982 ciffi.close();
18983 QRegularExpression data_= QRegularExpression("\\bdata_");
18984 QRegularExpression tblocksep = QRegularExpression("\n;\\s*\n");
18985 QRegularExpression tagexpr = QRegularExpression("^\\s*_\\S+");
18986 QRegularExpression incfcs = QRegularExpression("\nloop_\n_shelx_include_file_name\n_shelx_include_file\n_shelx_include_file_checksum\n");
18987 QStringList incfstr = strcif.split(incfcs, skipEmptyParts);
18988 //printf("incfstr size %d\n%s\n",incfstr.size(), incfstr.at(1).toStdString().c_str());
18989 if (incfstr.size()>1){
18990 QStringList incpart= incfstr.at(1).split("\n",keepEmptyParts);
18991 int textbl = 0;
18992 QString incbody;
18993 QString _shelx_include_file_name;
18994 for (int ip=0; ip<incpart.size(); ip++){
18995 if ((incpart.at(ip).startsWith("loop_"))||(incpart.at(ip).contains(tagexpr))) break;
18996 bool semicolon = incpart.at(ip).startsWith(";");
18997 textbl += (semicolon)?1:0;
18998 if ((!semicolon)&&((textbl%3)==0)) {
18999 _shelx_include_file_name = incpart.at(ip);
19000 }else if ((!semicolon)&&((textbl%3)==1)){
19001 incbody+=incpart.at(ip);
19002 incbody+="\n";
19003 }else if ((!semicolon)&&((textbl%3)==2)){
19004 int incsum = incpart.at(ip).toInt();
19005 int chksum = cifCheckSum(incbody);
19006 // printf("incsum %d = %d ok = %d\n ", incsum, chksum,(incsum==chksum));
19007 if (incsum==chksum){
19008 QString icfn=QString("%1/%2").arg(dn).arg(_shelx_include_file_name);
19009 // printf("%s\n",icfn.toStdString().c_str());
19010 QFile icf(icfn);
19011 bool canwrite = icf.open(QIODevice::WriteOnly|QIODevice::Text);
19012 icf.write(incbody.toLatin1());
19013 icf.close();
19014 info+= QString("<font color=green >Extracted %1 checksum was OK</font> File was %2successfully</font> written.<br>")
19015 .arg(icfn).arg(canwrite?"<font color=green >":"<font color=red >un");
19016 }
19017 textbl++;
19018 incbody.clear();
19019 }
19020
19021 }
19022 }
19023
19024 QStringList blcks = strcif.split(data_,skipEmptyParts);
19025 int done=0;
19026 QStringList resExportNameList;
19027 for (int bi = 0; bi < blcks.size(); bi++){
19028 //printf("blocks %d %s\n",blcks.size(),blcks.at(1).section("\n",0,0).toStdString().c_str());
19029 QString datablock = blcks.at(bi).section("\n",0,0).simplified();
19030 //printf("datablock %s %d %d\n", datablock.toStdString().c_str(), bi, blcks.size());
19031 QStringList textblocks = blcks.at(bi).split(tblocksep, skipEmptyParts);
19032 int xlsum = blcks.at(bi).section("_shelx_res_checksum",1,1).section("\n",0,0).toInt();
19033 int hklsum = blcks.at(bi).section("_shelx_hkl_checksum",1,1).section("\n",0,0).toInt();
19034
19035 //printf("textblocks %d\n", textblocks.size());
19036 QString hklExportName = QString("%1/%2_xle.hkl").arg(dn).arg(datablock);
19037 QString resExportName = QString("%1/%2_xle.res").arg(dn).arg(datablock);
19038 for (int j=0; j<textblocks.size();j++){
19039 int sum = cifCheckSum(textblocks.at(j));
19040 //printf("checksum %d size %d #%d res:%d hkl:%d data:%s\n",sum,textblocks.at(j).size(),j,xlsum,hklsum, datablock.toStdString().c_str());
19041 if (sum==xlsum){
19042 //printf("%s\n",resExportName.toStdString().c_str());
19043 QFile expresf(resExportName);
19044 bool canwrite = expresf.open(QIODevice::WriteOnly|QIODevice::Text);
19045 expresf.write(textblocks.at(j).toLatin1());
19046 expresf.close();
19047
19048 info+=QString("<font color=green >Extracted %1 checksum was OK</font> File was %2successfully</font> written.<br>")
19049 .arg(resExportName).arg(canwrite?"<font color=green >":"<font color=red >un");
19050 resExportNameList.append(resExportName);
19051 done++;
19052 }
19053 if (sum==hklsum){
19054 //printf("%s\n",hklExportName.toStdString().c_str());
19055 QFile exphklf(hklExportName);
19056 bool canwrite = exphklf.open(QIODevice::WriteOnly|QIODevice::Text);
19057 exphklf.write(textblocks.at(j).toLatin1());
19058 exphklf.close();
19059 info+=QString("<font color=green >Extracted %1 checksum was OK</font> File was %2successfully</font> written.<br>")
19060 .arg(hklExportName).arg(canwrite?"<font color=green >":"<font color=red >un");
19061 done++;
19062 }
19063 }
19064 }//bi
19065 einstellung->beginGroup("Files");
19066 //einstellung->setValue("lastFile", fileName );
19067 QStringList files = einstellung->value("recentFileList").toStringList();
19068 for (int i = 0; i < resExportNameList.size(); i++){
19069 files.removeAll(resExportNameList.at(i)); //alle identischen "fileName" aus der Liste entfernen
19070 files.prepend(resExportNameList.at(i)); // und dann vorne anfuegen...
19071 }
19072 while (files.size() > MaxRecentFiles) {
19073 files.removeLast() ;//hinten abschneiden was laenger als MaxRecentFiles ist
19074 }
19075 einstellung->setValue("recentFileList", files);
19076 foreach (QWidget *widget, QApplication::topLevelWidgets()) {
19077 Window *mainWin = qobject_cast<Window *>(widget);
19078 if (mainWin)
19079 mainWin->updateRecentFileActions();
19080 }
19081 einstellung->endGroup();
19082
19083 if (done>=2) {
19084 loadFile(resExportNameList.first());
19085 infoKanalNews(info);
19086 return;
19087 }
19088 //if done > 2 then let the user decide what file to load
19089 /*
19090 QProcess *shred = new QProcess(this);
19091 QStringList al;
19092 al.append(argument);
19093 shred->setWorkingDirectory(dn); // updateXLput()
19094 #if (QT_VERSION >= 0x040600)
19095 QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
19096 shred->setProcessEnvironment(env);//Thanks to Dr. Pavlo Solntsev!!
19097 #else
19098 QStringList env = QProcess::systemEnvironment();
19099 shred->setEnvironment(env);
19100 #endif
19101 shred->start(shredCIFPath,al);
19102 shred->waitForFinished(5000);
19103 QString op= shred->readAllStandardOutput();
19104 QMessageBox::information ( this, "shredcif output", "ShredCIF output:" + op );
19105 //qDebug()<<(!op.contains("checksum O.K."));
19106 if (!op.contains("checksum O.K.")) {qDebug()<<"No res file in cif file found!";return;}
19107 QStringList filter;
19108 filter << "*.res";
19109 QDir dir(dn);
19110 QStringList files = dir.entryList(filter,QDir::Files|QDir::Readable,QDir::Time|QDir::Reversed);
19111 //qDebug()<<files;
19112 QString fileName=files.last();
19113 if (fileName.isEmpty()) return;
19114 //qDebug()<<fileName;
19115 QString base = fileName;
19116 if (base.length()>4) base.chop(4);
19117 QString ase = fileName;//jul 2023 shredcif seam to eat the first letter of its output
19118 if (ase.length()>1) ase.remove(0,1);
19119 printf("shredcif outout:\n%s\n%s %d res files found.\n", op.toStdString().c_str(), ase.toStdString().c_str(), files.size());
19120 int extractedResFiles = 0;
19121 for (int i=0; i< files.size(); i++){
19122 QString nn= files.at(i);
19123 nn.remove(0,1);
19124 if (op.contains(nn)) {
19125 extractedResFiles++;
19126 printf("%s (%s)\n", nn.toStdString().c_str(),files.at(i).toStdString().c_str());
19127 }
19128 }
19129 printf("extractedResFiles %d\n",extractedResFiles);
19130
19131 //qDebug()<<base<<op.contains(base)<<op.contains(ase);
19132 if ((op.contains(base))||(op.contains(ase))) {
19133 printf("load file %s\n",(dn+"/"+fileName).toStdString().c_str());
19134 loadFile(dn+"/"+fileName);
19135 }
19136 */
19137 }
19138
19139 void Window::showSearch(){
19140 if (editor->uCanSeeMe) editor->showSearch();
19141 if (xlPutor->uCanSeeMe) xlPutor->showSearch();
19142 }
19143
19144 void Window::findNext(){
19145 if (editor->uCanSeeMe) editor->findNext();
19146 else if (xlPutor->uCanSeeMe) xlPutor->findNext();
19147 }
19148
19149 void Window::findPrev(){
19150 if (editor->uCanSeeMe) editor->findPrev();
19151 else if (xlPutor->uCanSeeMe) xlPutor->findPrev();
19152 }
19153
19154 void Window::brwsEPS(){
19155 QString selectedFilter;
19156 fxle->contEPSFile->setText(QFileDialog::getSaveFileName(this, tr("Save Contour-Encapsulated PostScript file "), "",
19157 "Encapsulated PostScript-Files (*.eps);;"
19158 ,&selectedFilter,(useNativeDlg->isChecked())?noneopt:QFileDialog::DontUseNativeDialog));
19159 if (!fxle->contEPSFile->text().endsWith(".eps",Qt::CaseInsensitive))
19160 fxle->contEPSFile->setText(fxle->contEPSFile->text()+".eps");
19161 }
19162
19163 void Window::nocontourPlot(){
19164 chgl->cont.clear();
19165 chgl->contval.clear();
19166 chgl->cntrPlot->setVisible(false);
19167 chgl->nocntrPlot->setVisible(false);
19168 chgl->rainbowPlot->setVisible(false);
19169 chgl->mol->selectedatoms.clear();
19170 chgl->contDestruct();
19171 chgl->updateBondActions();
19172 update();
19173 chgl->update();
19174 if (tgl){
19175 tgl->ogl->cont.clear();
19176 tgl->ogl->contval.clear();
19177 tgl->ogl->cntrPlot->setVisible(false);
19178 tgl->ogl->nocntrPlot->setVisible(false);
19179 tgl->ogl->rainbowPlot->setVisible(false);
19180 tgl->ogl->updateBondActions();
19181 tgl->ogl->update();
19182 }
19183 }
19184 void Window::contourPlot(){
19185 if (mole.showatoms.isEmpty()) return;
19186 chgl->cntrPlot->setVisible(false);
19187 chgl->nocntrPlot->setVisible(true);
19188
19189 QDialog *contDlg = new QDialog(this);
19190
19191 QLabel *contEPSFileL = new QLabel("Write Encapsulated Postscript file",contDlg);
19192 QPushButton *brwsEPS = new QPushButton("Browse",contDlg);
19193 connect(brwsEPS,SIGNAL(pressed()),this,SLOT(brwsEPS()));
19194 fxle->contEPSFile = new QLineEdit(contDlg);
19195 fxle->contEPSFile->setWhatsThis(
19196 "<h1>EPS file name</h1>"
19197 "If this field is not empty an encapsulated post script file is written to the given path");
19198 QLabel *planeAtomDefL = new QLabel("Define plane by:");
19199 int at1=0,at2=1,at3=2;
19200 if (chgl->mol->selectedatoms.size()>2){
19201 at1=chgl->mol->selectedatoms.at(0).style;
19202 at2=chgl->mol->selectedatoms.at(1).style;
19203 at3=chgl->mol->selectedatoms.at(2).style;
19204 }
19205 QLineEdit *planeAtomDef = new QLineEdit(QString("%1 %2 %3")
19206 .arg(mole.showatoms.at(at1).Label)
19207 .arg(mole.showatoms.at(at2).Label)
19208 .arg(mole.showatoms.at(at3).Label));
19209 planeAtomDef->setReadOnly(true);
19210 planeAtomDef->setEnabled(false);
19211 /*
19212 cubeGL->moliso->contMapFile->setReadOnly(true);
19213 cubeGL->moliso->contMapFile->setEnabled(false);
19214 */
19215 fxle->contourValueEdit = new QLineEdit(contDlg);
19216 fxle->contourValueEdit->setText("-1.0 0.0 1.0");
19217 QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
19218 connect(buttonBox, SIGNAL(accepted()), contDlg, SLOT(accept()));
19219 connect(buttonBox, SIGNAL(rejected()), contDlg, SLOT(reject()));
19220 QPushButton *edo = new QPushButton("uniform contours",contDlg);
19221 cStepBx = new QDoubleSpinBox(contDlg);
19222 cStepBx->setPrefix("Step size: ");
19223 cStepBx->setMinimum(0.001);
19224 cStepBx->setDecimals(3);
19225 cStepBx->setValue(0.1);
19226 cStepBx->setSingleStep(0.05);
19227 fxle->extendUnit = new QCheckBox("Extend over unit cell",contDlg);
19228 fxle->cScopeBx = new QDoubleSpinBox(contDlg);
19229 fxle->cScopeBx->setMinimum(0.0);
19230 fxle->cScopeBx->setDecimals(1);
19231 fxle->cScopeBx->setSingleStep(0.5);
19232 fxle->heightScale = new QDoubleSpinBox(contDlg);
19233 fxle->heightScale->setMinimum(0.0);
19234 fxle->heightScale->setDecimals(2);
19235 fxle->heightScale->setSingleStep(0.05);
19236 fxle->heightScale->setValue(0.0);
19237 fxle->heightScale->setPrefix("Height scale: ");
19238 QPushButton *eAIM = new QPushButton("+AIM contours",contDlg);
19239 eAIM->setWhatsThis(
19240 "<h1>Atoms In Molecules(AIM) contours</h1>"
19241 "This will add contours at <b>1 &times; 10<sup>n</sup>,2 &times; 10<sup>n</sup>,4 &times; 10<sup>n</sup>,6 &times; 10<sup>n</sup>and 8 &times; 10<sup>n</sup></b>. <b>n</b> ranges from -3 to 8.");
19242 connect(edo ,SIGNAL(released ()),this,SLOT(everyPointOne()));
19243 connect(eAIM,SIGNAL(released ()),this,SLOT(everyAIM()));
19244
19245 edo->setWhatsThis(
19246 "<h1>uniform contours</h1>"
19247 "This will add contours from -10 to 10 in steps with given step size.");
19248
19249 fxle->centerIsOn = new QComboBox(contDlg);
19250 fxle->centerIsOn ->addItem("first atom",0);
19251 fxle->centerIsOn ->addItem("second atom",1);
19252 fxle->centerIsOn ->addItem("third atom",2);
19253 fxle->centerIsOn ->addItem("center of 3 atoms",3);
19254 fxle->centerIsOn->setWhatsThis(
19255 "<h1>Center on</h1>"
19256 "When an EPS file is exported the center of the plot will be either on one of the selected atoms or the center of these three atoms."
19257 );
19258
19259 fxle->aspectRatios = new QComboBox(contDlg);
19260 fxle->aspectRatios->addItem("4:3",0);
19261 fxle->aspectRatios->addItem("16:9",1);
19262 fxle->aspectRatios->addItem("1:1",2);
19263 fxle->aspectRatios->setCurrentIndex(0);
19264
19265 fxle->sourceMap = new QComboBox(contDlg);
19266 fxle->sourceMap->addItem("Fo-Fc diffrence map",0);
19267 fxle->sourceMap->addItem("Fo map",1);
19268 fxle->sourceMap->setWhatsThis(
19269 "<h1>Source </h1>"
19270 "The contour plot can be based on the Diffrence Fourier Map (Fo-Fc Map) or the map of the observed structure factors with model phases (Fo map).");
19271
19272 QGridLayout *gl = new QGridLayout(contDlg);
19273 gl->addWidget(planeAtomDefL, 1, 0, 1, 1);
19274 gl->addWidget(planeAtomDef, 1, 1, 1, 1);
19275 gl->addWidget(new QLabel("Center on",contDlg), 1, 3, 1, 1);
19276 gl->addWidget(fxle->centerIsOn, 1, 4, 1, 1);
19277 gl->addWidget(new QLabel("Contour plot is based on:",contDlg), 2, 0, 1, 1);
19278 gl->addWidget(fxle->sourceMap,2,1,1,1);
19279 gl->addWidget(new QLabel("Contour values",contDlg), 3, 0, 1, 4);
19280 gl->addWidget(fxle->contourValueEdit, 4, 0, 1, 5);
19281 gl->addWidget(cStepBx ,5,0,1,1);
19282 gl->addWidget(edo,5,1,1,1);
19283 gl->addWidget(eAIM,5,2,1,1);
19284 gl->addWidget(fxle->heightScale,5,3,1,1);
19285 gl->addWidget(fxle->extendUnit,5,4,1,1);
19286 gl->addWidget(new QLabel("Scope (0 means now restriction)"),6,0,1,1);
19287 gl->addWidget(fxle->cScopeBx,6,1,1,1);
19288 gl->addWidget(new QLabel("Aspect ratio"),6,3,1,1);
19289 gl->addWidget(fxle->aspectRatios,6,4,1,1);
19290
19291 gl->addWidget(contEPSFileL, 7, 0, 1, 1);
19292 gl->addWidget(fxle->contEPSFile, 7, 1, 1, 3);
19293 gl->addWidget(brwsEPS, 7, 4, 1, 1);
19294 gl->addWidget(buttonBox, 10, 0, 1, 5);
19295
19296 if (contDlg->exec()==QDialog::Accepted){
19297 fxle->makePlane(chgl->cont,at1,at2,at3);
19298 chgl->mol->selectedatoms.clear();
19299 chgl->rainbowPlot->setVisible(true);
19300 /*showLeg->setChecked ( true );
19301 showLeg->setVisible(true);
19302 cubeGL->setLegend(true);*/
19303 chgl->update();
19304 }else{
19305 chgl->mol->selectedatoms.clear();
19306 chgl->updateBondActions();
19307 chgl->cntrPlot->setVisible(false);
19308 chgl->nocntrPlot->setVisible(false);
19309 chgl->rainbowPlot->setVisible(false);
19310 }
19311
19312 }
19313
19314 void Window::everyPointOne(){
19315 QString cfs;
19316 if (cStepBx->value()==0) return;
19317 double val=-100*cStepBx->value();
19318 double end=-val;
19319 while (val<end) {
19320 cfs.append(QString("%1 ").arg(val));
19321 val+=cStepBx->value();
19322 }
19323 fxle->contourValueEdit->setText(cfs);
19324 update();
19325 }
19326
19327 void Window::everyAIM(){
19328 double val=0.001;
19329 // double step=fabs(0.001)/5.0f;
19330 int i=-3;
19331 QString cfs;
19332 while (val<1e9) {
19333 cfs.append(QString("%1 ").arg(val));//1
19334 val+=1*pow(10.0,i);
19335 cfs.append(QString("%1 ").arg(val));//2
19336 val+=2*pow(10.0,i);
19337 cfs.append(QString("%1 ").arg(val));//4
19338 val+=2*pow(10.0,i);
19339 cfs.append(QString("%1 ").arg(val));//6
19340 val+=2*pow(10.0,i);
19341 cfs.append(QString("%1 ").arg(val));//8
19342 val+=2*pow(10.0,i);
19343
19344 i++;
19345 }
19346
19347 fxle->contourValueEdit->setText(cfs);
19348 update();
19349
19350 }
19351
19352 // K.R. start============================================================
19353 void Window::exportCC(){
19354
19355 #define GAUSS_FILES "gaussian (*.com | *.gjf)"
19356 #define XYZ_FILES "xyz (*.xyz)"
19357 #define TM_FILES "turbomole (*.coord)"
19358 #define XLE_FILES "ShelXle (*.shelxle)"
19359
19360 QString selectedFilter;
19361
19362 QString qmName = dirName;
19363 qmName.replace(resorins,"");
19364 QString fn=QFileDialog::getSaveFileName(this, "Export computational chemistry file", qmName,
19365 GAUSS_FILES ";;" XYZ_FILES ";;" TM_FILES ";;" XLE_FILES, &selectedFilter);
19366 if (fn.isEmpty())return;
19367 if (selectedFilter==GAUSS_FILES){
19368 QDialog *dlg = new ExportCCDlg(dirName,chgl->mol,fn);
19369 dlg->exec();
19370 }
19371 else{
19372 QString headerQM, bodyQM, footerQM, filenameQM;
19373 double a0= 1.0 / 0.5291772109;
19374 QFile f;
19375 f.setFileName(fn);
19376 QFileInfo fileInfo(f.fileName());
19377 filenameQM = fileInfo.baseName();
19378 // center of molecule
19379 V3 Vo=V3(0,0,0);
19380 int visCount=0;
19381 for (int i=0; i<mole.showatoms.size();i++) {
19382 if (mole.showatoms.at(i).an<0) continue; //ignore none atoms
19383 if ((mole.nopm1)&&(mole.showatoms.at(i).symmGroup)&&(mole.showatoms.at(i).part<-0)) continue; // ignore hidden parts (-1)
19384 if (mole.showatoms.at(i).hidden) continue;
19385 visCount++;
19386 Vo+=mole.showatoms.at(i).pos;
19387 }
19388 Vo*=1.0/visCount;
19389
19390
19391 // atoms themselves
19392 if (selectedFilter == XLE_FILES) {
19393 for (int i=0; i< mole.showatoms.size(); i++)
19394 bodyQM.append(mole.showatoms.at(i).toAtomString());
19395
19396 }else
19397 for (int i=0; i< mole.showatoms.size(); i++){
19398 if (mole.showatoms.at(i).an<0) continue; //ignore none atoms
19399 if ((mole.nopm1)&&(mole.showatoms.at(i).symmGroup)&&(mole.showatoms.at(i).part<-0)) continue; // ignore hidden parts (-1)
19400 if (mole.showatoms.at(i).hidden) continue;
19401 if (selectedFilter == XYZ_FILES) {
19402 bodyQM.append(QString("%1 %2 %3 %4\n")
19403 .arg(mole.pse(mole.showatoms.at(i).an),-2)
19404 .arg(mole.showatoms.at(i).pos.x-Vo.x,13,'f',10)
19405 .arg(mole.showatoms.at(i).pos.y-Vo.y,13,'f',10)
19406 .arg(mole.showatoms.at(i).pos.z-Vo.z,13,'f',10) );
19407 }
19408 else {
19409 bodyQM.append(QString(" %2 %3 %4 %1\n")
19410 .arg(mole.pse(mole.showatoms.at(i).an).toLower(),-4)
19411 .arg((mole.showatoms.at(i).pos.x-Vo.x)*a0,20,'f',14)
19412 .arg((mole.showatoms.at(i).pos.y-Vo.y)*a0,20,'f',14)
19413 .arg((mole.showatoms.at(i).pos.z-Vo.z)*a0,20,'f',14) );
19414 }
19415 }
19416
19417 if (selectedFilter == XYZ_FILES) {
19418 footerQM.append(QString("\n\n"));
19419 }
19420 else if (selectedFilter == XLE_FILES) {
19421 footerQM.append(QString("\n\n"));
19422 }
19423
19424 else {
19425 footerQM.append(QString("$end\n\n"));
19426 }
19427 if (selectedFilter == XYZ_FILES) { // ================= XYZ
19428 headerQM.append(QString("%1\n").arg(visCount));
19429 headerQM.append(QString("from %1\n").arg(dirName));
19430
19431 }
19432 else if (selectedFilter == XLE_FILES) {
19433 headerQM.append("@ShelXle file@\n");
19434 } else {
19435 headerQM.append(QString("$coord\n"));
19436 }
19437 bool success = f.open(QIODevice::WriteOnly|QIODevice::Text);
19438 if (success){
19439 f.write(QString("%1%2%3").arg(headerQM).arg(bodyQM).arg(footerQM).toLatin1());
19440 f.close();
19441 }
19442 }
19443 }
19444
19445 void Window::go2hklf5(){
19446 maybeSave();
19447 if ((hklf5files.isEmpty())||(chgl->mol->asymm.isEmpty())) return;
19448 QString dn=dirName.section('/',0,-2);
19449 QStringList ins5files,res5files;
19450 QString orthisres="";
19451 bool decisionRequired = false;
19452 for (int i=0; i< hklf5files.size();i++){
19453 QString hk5=hklf5files.at(i);
19454 //printf("=%d/%d %s\n",i,hklf5files.size(),hk5.toStdString().c_str());
19455 QString ins=hk5;
19456 QString res=hk5;
19457 res.replace(punkthkl,".res");
19458 ins.replace(punkthkl,".ins");
19459 res=QString("%1/%2").arg(dn).arg(res);
19460 ins=QString("%1/%2").arg(dn).arg(ins);
19461 if (QFile::exists(res)) {
19462 //printf("=%d/%d=>> A RES file already exists! %s\n",i,hklf5files.size(),res.toStdString().c_str());
19463 //loadFile(res);
19464 //return;
19465 decisionRequired = true;
19466 res5files.append(res);
19467 } else {
19468 res5files.append("!"+res);
19469 orthisres=res;
19470 }
19471 if (QFile::exists(ins)) {
19472 //printf("==>> A INS file already exists! %s\n",ins.toStdString().c_str());
19473 //loadFile(ins);
19474 //return;
19475 decisionRequired = true;
19476 ins5files.append(ins);
19477 }else ins5files.append("!"+ins);
19478 }
19479 if (decisionRequired){
19480 QDialog *dlg = new QDialog(this);
19481 dlg->setWindowTitle("Switch to HKLF 5 refinement");
19482 QGridLayout *gl = new QGridLayout(dlg);
19483 gl->addWidget(new QLabel("Switch to HKLF 5 refinement: Your decission is requred.",dlg),0,0,1,12);
19484 int column=0;
19485 for (int bi=0; bi< hklf5files.size(); bi++){
19486 if (!res5files.at(bi).isEmpty()){
19487 QAction *a = new QAction((res5files.at(bi).startsWith('!'))?
19488 QString("%1 does not exist yet")
19489 .arg(res5files.at(bi).section('/',-1)):
19490 QString("load %1 was modified %2")
19491 .arg(res5files.at(bi).section('/',-1))
19492 .arg(QFileInfo(res5files.at(bi)).lastModified().toString())
19493 ,dlg);
19494 //QString("%1/%2").arg(dn).arg(resfs.at(i))
19495 a->setDisabled(res5files.at(bi).startsWith('!'));
19496 a->setData(res5files.at(bi));
19497 connect(a,SIGNAL(triggered()),this,SLOT(loadThisFile()));
19498 connect(a,SIGNAL(triggered()),dlg,SLOT(accept()));
19499 QToolButton *tbb= new QToolButton(dlg);//17696
19500 tbb->setDefaultAction(a);
19501 gl->addWidget(tbb,1,column);
19502 }
19503
19504 if (!ins5files.at(bi).isEmpty()){
19505 QAction *a = new QAction((ins5files.at(bi).startsWith('!'))?
19506 QString("%1 does not exist yet")
19507 .arg(ins5files.at(bi).section('/',-1)):QString("load %1 was modified: %2")
19508 .arg(ins5files.at(bi).section('/',-1))
19509 .arg(QFileInfo(ins5files.at(bi)).lastModified().toString())
19510 ,dlg);
19511 //QString("%1/%2").arg(dn).arg(resfs.at(i))
19512 a->setDisabled(ins5files.at(bi).startsWith('!'));
19513 a->setData(ins5files.at(bi));
19514 connect(a,SIGNAL(triggered()),this,SLOT(loadThisFile()));
19515 connect(a,SIGNAL(triggered()),dlg,SLOT(accept()));
19516 QToolButton *tbb= new QToolButton(dlg);//17696
19517 tbb->setDefaultAction(a);
19518 gl->addWidget(tbb,2,column);
19519 }
19520
19521 if (!hklf5files.at(bi).isEmpty()){
19522 QAction *a = new QAction(QString("create res file from current file"),dlg);
19523 //QString("%1/%2").arg(dn).arg(resfs.at(i))
19524 QString hk5=hklf5files.at(bi);
19525 QString res=hk5;
19526 res=res.replace(punkthkl,".res");
19527 res=QString("%1/%2").arg(dn).arg(res);
19528 a->setData(res);
19529 connect(a,SIGNAL(triggered()),this,SLOT(fileSave4hklf5()));
19530 connect(a,SIGNAL(triggered()),dlg,SLOT(accept()));
19531 QToolButton *tbb= new QToolButton(dlg);//17696
19532 tbb->setDefaultAction(a);
19533 gl->addWidget(tbb,3,column);
19534 }
19535 column++;
19536 }
19537 dlg->exec();
19538 return;
19539
19540 }else{
19541 printf("go2hklf5()\n");
19542 QAction *action = qobject_cast<QAction *>(sender());
19543 action->setData(orthisres);
19544 //fileSave4hklf5();
19545 makeItHKLF5();
19546 }
19547 //printf("GOTO HKLF 5 =>> %d %d %d \n",hklf5files.size(),res5files.size(),ins5files.size());
19548 return;
19549 }
19550
19551 void Window::go2hklf4(){
19552 maybeSave();
19553 QString dn=dirName.section('/',0,-2);
19554 QString res4=dirName;
19555 res4.replace(QRegularExpression("_5.res$"),"_4.res");
19556 res4.replace(QRegularExpression("_5.ins$"),"_4.res");
19557 if (QFile::exists(res4)) {
19558 loadFile(res4);
19559 return;
19560 }else{
19561 QFile f(res4);
19562 bool success = f.open(QIODevice::WriteOnly|QIODevice::Text);
19563 if (success){
19564 jumpToAtom(0);
19565 QTextCursor cursor = editor->textCursor();
19566 editor->searchLE->setText("^BASF");
19567 editor->replace->setText("REM BASF");
19568 editor->wholeLine->setChecked(false);
19569 editor->replaceAll();
19570 editor->searchLE->setText("^HKLF");
19571 editor->replace->setText("HKLF 4");
19572 editor->wholeLine->setChecked(true);
19573 editor->replaceAll();
19574 f.write(editor->toPlainText().toLatin1());
19575 f.close();
19576 editor->document()->setModified(false);
19577 loadFile(res4);
19578 }
19579 }
19580 }
19581
19582 void Window::makeItHKLF5(){
19583
19584 QAction *action = qobject_cast<QAction *>(sender());
19585 QString hk5="";
19586 printf("%p %c\n", action,(action)?'y':'n');
19587 if (action)
19588 hk5=action->data().toString();
19589 else return;
19590 printf("%d %s\n", hk5.isEmpty(),action->objectName().toStdString().c_str());
19591 if (hk5.isEmpty()) return;
19592 QString res=hk5;
19593 res=res.replace(punkthkl,".res");
19594 QString dn=dirName.section('/',0,-2);
19595 QString basfs="BASF 0.51\n";
19596 QStringList filter;
19597 filter.append("*.abs");
19598 QStringList files;
19599 files = QDir(dn).entryList(filter,QDir::Files,QDir::Time|QDir::Reversed);
19600 for (int i=0; i<files.size();i++){
19601 QFile sad(QString("%1/%2").arg(dn).arg(files.at(i)));
19602 sad.open(QIODevice::Text|QIODevice::ReadOnly);
19603 QString sadstring=sad.readAll();
19604 if ((sadstring.contains(hk5))&&(sadstring.contains("Cycle N(1) Rint(1) N(all) Rint(all) Twin fractions"))){
19605 QString tail=sadstring.section("Cycle N(1) Rint(1) N(all) Rint(all) Twin fractions",-1);
19606 QStringList sadlines=tail.split('\n');
19607 for (int j=0; j<sadlines.size(); j++){
19608 QStringList tok=sadlines.at(j).split(leer,skipEmptyParts);
19609 if ((tok.size()>6)&&(tok.at(0).toInt()>0)&&(tok.at(6).toDouble()>0.0)){
19610 basfs.clear();
19611 basfs=QString("BASF");
19612 for (int ii=6; ii<tok.size();ii++) basfs.append(QString(" %1").arg(tok.at(ii).toDouble()));
19613 }
19614 }
19615 basfs.append('\n');
19616 }
19617 sad.close();
19618 }
19619 printf("%d", __LINE__);
19620 QFile f(res);
19621 bool success = f.open(QIODevice::WriteOnly|QIODevice::Text);
19622 if (success){
19623 jumpToAtom(0);
19624 QTextCursor cursor = editor->textCursor();
19625 cursor.insertText(basfs);
19626 editor->searchLE->setText("^HKLF");
19627 editor->replace->setText("HKLF 5");
19628 editor->wholeLine->setChecked(true);
19629 editor->replaceAll();
19630 f.write(editor->toPlainText().toLatin1());
19631 f.close();
19632 editor->document()->setModified(false);
19633 loadFile(res);
19634 }
19635 }
19636
19637 bool Window::canWeSqueeze(){
19638 #if defined Q_WS_WIN || defined Q_OS_WIN
19639 QString pwt;
19640 int v=0;
19641 #if (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0))
19642 pwt = QString(qEnvironmentVariable("PWTDIR"));
19643 if (pwt.isEmpty()) QString(qgetenv("PWTDIR"));
19644 v=1;
19645 #else
19646 pwt = QString(qgetenv("PWTDIR"));
19647 v=2;
19648 #endif
19649 printf("PWT (%s) %d %d\n",pwt.toStdString().c_str(),QFile::exists(QString("%1/%2").arg(pwt).arg("platon.exe")),v);
19650 if (pwt.isEmpty()) {
19651 QStringList foundInPath;
19652 foundInPath.clear();
19653 QStringList pathList;
19654 pathList.clear();
19655 //execlist.clear();
19656 pathList = QString(qgetenv("PATH")).split(QRegularExpression("[;:]"));
19657 // qDebug()<<pathList;
19658 foreach (QString path, pathList) {
19659 QString fullpath = path+"/platon";
19660 QFileInfo fi(fullpath);
19661 if (QFile::exists(fullpath) && (fi.isExecutable())){
19662 foundInPath.append(QDir::cleanPath(fullpath));
19663 }else {
19664 fi.setFile(fullpath+".exe");
19665 // qDebug()<<QDir::cleanPath(fullpath+".exe")<<QFile::exists(fullpath+".exe")<<(fi.isExecutable());
19666 if (QFile::exists(fullpath+".exe") && (fi.isExecutable())){
19667 foundInPath.append(QDir::cleanPath(fullpath+".exe"));
19668 }
19669 }
19670 }
19671 return (!foundInPath.isEmpty());
19672 }
19673 //qDebug()<<QString("%1/%2").arg(pwt).arg("platon.exe");
19674 return QFile::exists(QString("%1/%2").arg(pwt).arg("platon.exe"));
19675 #else
19676 return false;
19677 #endif
19678 }
19679
19680 void Window::runSqueeze(){
19681 if (!canWeSqueeze()) return;
19682 QString pwt;
19683 #if defined Q_WS_WIN || defined Q_OS_WIN
19684 #if (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0))
19685 pwt = QString(qEnvironmentVariable("PWTDIR"));
19686 #else
19687 pwt = QString(qgetenv("PWTDIR"));
19688 #endif
19689 #endif //win
19690 QString pwtplaton;
19691 if (pwt.isEmpty()) {
19692
19693 QStringList foundInPath;
19694 foundInPath.clear();
19695 QStringList pathList;
19696 pathList.clear();
19697 //execlist.clear();
19698 pathList = QString(qgetenv("PATH")).split(QRegularExpression("[;:]"));
19699 // qDebug()<<pathList;
19700 foreach (QString path, pathList) {
19701 QString fullpath = path+"/platon";
19702 QFileInfo fi(fullpath);
19703 if (QFile::exists(fullpath) && (fi.isExecutable())){
19704 foundInPath.append(QDir::cleanPath(fullpath));
19705 }else {
19706 fi.setFile(fullpath+".exe");
19707 // qDebug()<<QDir::cleanPath(fullpath+".exe")<<QFile::exists(fullpath+".exe")<<(fi.isExecutable());
19708 if (QFile::exists(fullpath+".exe") && (fi.isExecutable())){
19709 foundInPath.append(QDir::cleanPath(fullpath+".exe"));
19710 }
19711 }
19712 }
19713 if (foundInPath.isEmpty()) return;
19714 pwtplaton=foundInPath.first();
19715 }else{
19716 pwtplaton = QString("%1/%2").arg(pwt).arg("platon.exe");
19717 }
19718 if (!editor->toPlainText().contains("ACTA")) {
19719 qDebug()<<"We need to refine this first with ACTA and LIST 4 instructions";
19720 refineActActa->trigger();
19721 return;
19722 }
19723 pwtplaton = QString("%1/%2").arg(pwt).arg("platon.exe");
19724 QString dn=dirName.section('/',0,-2);
19725 QString cifName=dirName;
19726 cifName=cifName.replace(resorins, ".cif").section('/',-1,-1);
19727 QStringList al=QString(QString("%1*-q*").arg(cifName)).split("*");//i think * should not be alowed in path names
19728 //printf("al => {%s} {%s}\n",al.at(0).toStdString().c_str(),al.at(1).toStdString().c_str());
19729 extraProc = new QProcess(this);
19730 extraProc->setWorkingDirectory(dn); // updateXLput()
19731 connect(extraProc,SIGNAL(readyReadStandardOutput ()),this,SLOT(updateExtraOutput()));
19732 connect(extraProc,SIGNAL(finished(int,QProcess::ExitStatus)),this,SLOT(updateExtraOutput()));
19733 connect(extraProc,SIGNAL(error(QProcess::ProcessError)),this,SLOT(updateExtraOutput()));
19734 #if (defined Q_WS_WIN || defined Q_OS_WIN)
19735 #if (QT_VERSION >= 0x050700)
19736 extraProc->setProgram(pwtplaton);
19737 extraProc->setArguments(al);
19738 extraProc->setWorkingDirectory(dn);
19739 extraProc->setCreateProcessArgumentsModifier([] (QProcess::CreateProcessArguments *args) {args->flags &= ~CREATE_NO_WINDOW;});
19740 extraProc->start(pwtplaton,al);
19741 #else
19742 //extraProc->startDetached(pwtplaton,al,dn);
19743 extraProc->start(pwtplaton,al);
19744 #endif
19745 extraOutPut->setText(QString("|--- Running %1 %2 in %3 ---|\n").arg(pwtplaton).arg(al.join(" ")).arg(dn));
19746 extraOutput->show();
19747 #endif
19748 }
19749
19750 void Window::getMinMaxSintl(double &smin, double &smax){
19751 smin=1000.0;
19752 smax=0.0;
19753 QString hklf=dirName;
19754 hklf=hklf.replace(resorins,".hkl");
19755 QFile hkl(hklf);
19756 if (hkl.open(QFile::ReadOnly|QFile::Text)){
19757 QStringList lines = QString(hkl.readAll()).split('\n');
19758 for (int i=0; i<lines.size(); i++){
19759 QStringList tok = lines.at(i).split(' ', skipEmptyParts);
19760 if (tok.size()>3){
19761 V3 H=V3(tok.at(0).toInt(),tok.at(1).toInt(),tok.at(2).toInt());
19762 if (H==V3(0,0,0)) break;
19763 double stl=sqrt(H*mole.cell.Gi*H)/2.0;
19764 smin=qMin(smin, stl);
19765 smax=qMax(smax, stl);
19766 }
19767 }
19768 }
19769 hkl.close();
19770 //printf("%f %f\n",smin,smax);
19771 }
19772
19773
19774 void Window::loadMolInTest(bool fromloadref){
19775 printf("-->(chgl->isReady() %d\n",chgl->isReady());
19776 QElapsedTimer elti;
19777 elti.start();
19778 if ((tgl)&&(!chgl->mol->showatoms.isEmpty())){
19779 tgl->ogl->setMainWindow(this);
19780 tgl->ogl->shaderInfo = shaderInfo;
19781 tgl->ogl->sfacMenu = chgl->sfacMenu;
19782 tgl->ogl->makeBonds(chgl->mol->showatoms, chgl->mol->showbonds, chgl->mol->lbonds,chgl->mol->theH_Bonds);
19783 tgl->ogl->makeAtoms(chgl->mol->showatoms);
19784 tgl->ogl->makeUnitCell();
19785 if (fxle) {
19786 //printf("setOGL?\n");
19787 fxle->setOGL(tgl->ogl);
19788 tgl->ogl->rainbowPlot = chgl->rainbowPlot;
19789 }
19790 if (!chgl->fVertexes[0].isEmpty()||!chgl->fVertexes[1].isEmpty()){
19791 /*tgl->ogl->setMapsStuff(chgl->fVertexes, chgl->fNormals, &chgl->lintrans, &chgl->linwidth,
19792 &chgl->fopc, &chgl->fomc, &chgl->dipc, &chgl->dimc,
19793 chgl->lighting, chgl->niceTrans, chgl->fillMap, chgl->foact, chgl->fofcact
19794 ); // */
19795 tgl->ogl->setMapsStuff();
19796 fxle->connect(tgl->ogl,SIGNAL(inimibas()),fxle,SLOT(inimap()));
19797 fxle->connect(tgl->ogl,SIGNAL(neuemitte(V3)),fxle, SLOT(bewegt(V3)));
19798 fxle->connect(tgl->ogl,SIGNAL(diffscroll(int ,int )),fxle,SLOT(change_iso(int ,int )));
19799 connect(chgl,SIGNAL(rebuffer(QVector< QVector< float > > &,QVector< QVector< float > > &)),
19800 tgl->ogl,SLOT(makeMaps(QVector< QVector< float > > &,QVector< QVector< float > > &)));
19801 //ChGL::rebuffer()
19802 }
19803 }else if ((chgl->isReady())&&(!chgl->mol->showatoms.isEmpty())){
19804 //printf("not ogl\n");
19805 chgl->setMainWindow(this);
19806 chgl->shaderInfo = shaderInfo;
19807 //printf("Q? min %g max %g\n",chgl->mol->pmin,chgl->mol->pmax,chgl->qcutoff);
19808 if (!fromloadref) chgl->qcutoff=-10;
19809 //chgl->sfacMenu = chgl->sfacMenu;
19810 qint64 since=elti.elapsed();
19811 chgl->makeBonds(chgl->mol->showatoms, chgl->mol->showbonds, chgl->mol->lbonds,chgl->mol->theH_Bonds);
19812 qint64 then=elti.elapsed();
19813 printf("make bonds took %d ms\n",then-since);
19814 since=elti.elapsed();
19815 chgl->makeAtoms(chgl->mol->showatoms);
19816 then=elti.elapsed();
19817 printf("make atoms took %d ms\n",then-since);
19818 since=elti.elapsed();
19819 chgl->makeUnitCell();
19820 then=elti.elapsed();
19821 printf("make unit cell took %d ms\n",then-since);
19822 since=elti.elapsed();
19823 //if (fxle) {
19824 //printf("setOGL?\n");
19825 //fxle->setOGL(chgl);
19826 //chgl->rainbowPlot;
19827 //}
19828 chgl->updateSceenAtoms();
19829
19830 if (!chgl->fVertexes[0].isEmpty()||!chgl->fVertexes[1].isEmpty()){
19831 /*tgl->ogl->setMapsStuff(chgl->fVertexes, chgl->fNormals, &chgl->lintrans, &chgl->linwidth,
19832 &chgl->fopc, &chgl->fomc, &chgl->dipc, &chgl->dimc,
19833 chgl->lighting, chgl->niceTrans, chgl->fillMap, chgl->foact, chgl->fofcact
19834 ); // */
19835 chgl->setMapsStuff();
19836 fxle->connect(chgl,SIGNAL(inimibas()),fxle,SLOT(inimap()));
19837 fxle->connect(chgl,SIGNAL(neuemitte(V3)),fxle, SLOT(bewegt(V3)));
19838 fxle->connect(chgl,SIGNAL(diffscroll(int ,int )),fxle,SLOT(change_iso(int ,int )));
19839 connect(chgl,SIGNAL(rebuffer(QVector< QVector< float > > &,QVector< QVector< float > > &)),
19840 chgl,SLOT(makeMaps(QVector< QVector< float > > &,QVector< QVector< float > > &)));
19841
19842 //ChGL::rebuffer()
19843 }
19844 }
19845 printf("gl is ready %d %d %fseconds\n",chgl->isReady(), ((chgl->isReady())&&(!chgl->mol->showatoms.isEmpty())), elti.elapsed()/1000.0);
19846 }
19847
19848 void Window::testOGL(){
19849 QList<QAction*> acts;
19850 QList<QToolButton*> tbs0,tbs1;
19851 acts.append(viewMenu->findChildren<QAction*>());
19852 tbs0 = vito->findChildren<QToolButton *>();
19853 for (int i = 0; i < tbs0.size(); i++){
19854 QAction *a =tbs0.at(i)->defaultAction();
19855 if ((a != nullptr)
19856 &&(!a->text().isEmpty())
19857 &&(!acts.contains(a))
19858 ) acts.append(a);
19859 }
19860 tbs1 = bottomToolBar->findChildren<QToolButton *>();
19861 for (int i = 0; i < tbs1.size(); i++){
19862 QAction *a =tbs1.at(i)->defaultAction();
19863 if ((a != nullptr)
19864 &&(!a->text().isEmpty())
19865 &&(!acts.contains(a))
19866 ) acts.append(a);
19867 }
19868 tgl = new OpenGLTestWidget(chgl->mol, acts, this);
19869 tgl->show();
19870 connect(tgl->ogl, SIGNAL(initialized()), this, SLOT(loadMolInTest()));
19871 //loadMolInTest();
19872 }
19873 // */