1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502
|
/*****************************************************************************
TRAVIS - Trajectory Analyzer and Visualizer
http://www.travis-analyzer.de/
Copyright (c) 2009-2020 Martin Brehm
2012-2020 Martin Thomas
2016-2020 Sascha Gehrke
Please cite: J. Chem. Phys. 2020, 152 (16), 164105. (DOI 10.1063/5.0005078 )
J. Chem. Inf. Model. 2011, 51 (8), 2007-2023. (DOI 10.1021/ci200217w )
This file was written by Martin Brehm and Martin Thomas.
---------------------------------------------------------------------------
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/
#ifndef MAINTOOLS_H
#define MAINTOOLS_H
// This must always be the first include directive
#include "config.h"
#include "travis.h"
#include "tools.h"
#include "database.h"
#include "statistics.h"
#include "element.h"
#include "base64.h"
bool OpenInputTrajectory();
bool CloseInputTrajectory();
bool InputTrajectoryEOF();
bool SeekInputTrajectory(int step);
void WriteRevisionInfo();
void CheckSourceVersion();
int bqbtool_main(int argc, const char *argv[]);
int cubetool_main( int argc, const char *argv[] );
class CAutoCorrelation : public CxObject
{
public:
CAutoCorrelation();
~CAutoCorrelation();
void Init(int input, int depth, bool fft);
void AutoCorrelate(CxDoubleArray *inp, CxDoubleArray *outp);
void AutoCorrelate(std::vector<double> &inp, std::vector<double> &outp);
void AutoCorrelateSqrt(CxDoubleArray *inp, CxDoubleArray *outp);
int m_iInput;
int m_iDepth;
int m_iFFTSize;
bool m_bFFT;
CFFT *m_pFFT;
CFFT *m_pFFT2;
};
class CCrossCorrelation : public CxObject
{
public:
CCrossCorrelation();
~CCrossCorrelation();
void Init(int input, int depth, bool fft);
void CrossCorrelate(CxDoubleArray *inp1, CxDoubleArray *inp2, CxDoubleArray *outp);
void CrossCorrelate(std::vector<double> &inp1, std::vector<double> &inp2, std::vector<double> &outp);
void CrossCorrelateSymmetric(CxDoubleArray *inp1, CxDoubleArray *inp2, CxDoubleArray *outp);
int m_iInput;
int m_iDepth;
int m_iFFTSize;
bool m_bFFT;
CFFT *m_pFFT;
CFFT *m_pFFT2;
CFFT *m_pFFTback;
};
class CAtomSort {
public:
double m_fPos[3];
double m_fColor[3];
double m_fRadius;
};
inline bool SORT_AtomSort_Z( const CAtomSort *a1, const CAtomSort *a2 ) {
return a1->m_fPos[2] > a2->m_fPos[2];
}
/*void AutoCorrelate(CxFloatArray *inp, CxFloatArray *outp, int depth);
void AutoCorrelate(CxFloatArray *inp, CxFloatArray *outp, int depth, CFFT *fft, CFFT *fft2);*/
CAnalysisGroup* AddAnalysisGroup(const char *name);
void AddAnalysis(CAnalysisGroup* g, const char *name, const char *abbrev);
void InitAnalyses();
void DumpAnalyses();
//void UniteNb();
bool ParseAtom(const char *s, int refmol, int &ty, int &rty, int &atom);
bool ParseRefSystem(int refmol, const char *s, int points);
CTimeStep* GetTimeStep(int i);
CTimeStep** GetTimeStepAddress(int i);
void CalcVelocities();
void CalcVolumetricDataTimeDev();
void CalcCurrentDensity();
void CalcForces();
/*double AtomMass(char *s);
int AtomOrd(char *s);
double AtomRadius(char *s);*/
CElement* FindElement(const char *s, bool quiet);
double GuessBoxSize();
void strtolower(char *s);
void SortAtoms();
void SortElementsLabel();
void SortElementsMass();
bool SetAnalysis(const char *s);
bool ParseFunctions(const char *s);
bool ParsePeriodic(const char *s);
void WriteHeader();
void CommandLineHelp();
bool ParseArgs(int argc, const char *argv[]);
void ParsePassiveArgs(int argc, const char *argv[]);
//void VariablesToDatabase();
//void DatabaseToVariables();
//void WriteDefaultSettings(const char *s);
void CreateDatabaseDefaults();
void LoadSettings();
void InitDatabase();
void RECURSION_BuildCDF(CObservation *o, int channel, int om, CxDoubleArray **data, double *result);
CVirtualAtom* AddVirtualAtom(int mol);
void RemoveAllElements();
void RemoveAllAtoms();
void RemoveAllAnalyses();
void RemoveAllMolecules();
void RemoveAllObservations();
void GetTravisPath();
void ReorderAtoms(int molecule);
void ReorderLikeInput();
void DoubleBoxHelper(unsigned char tpx, unsigned char tpy, unsigned char tpz);
unsigned long GraceColor(int z, double bleach);
void parseCoreCharges();
bool setupWannier();
void ParseDipole();
void parseMagneticDipole();
void DipolGrimme(const char *s);
inline CxDVector3 FoldVector(CxDVector3 v) {
int n;
if (g_bBoxNonOrtho) {
CxDVector3 w;
w = g_mBoxToOrtho * v;
n = PeriodicImage1D( w[0], -0.5, 0.5 );
if (n != 0)
w[0] -= n;
n = PeriodicImage1D( w[1], -0.5, 0.5 );
if (n != 0)
w[1] -= n;
n = PeriodicImage1D( w[2], -0.5, 0.5 );
if (n != 0)
w[2] -= n;
/* while (w[0] > 0.5)
w[0] -= 1.0;
while (w[0] <= -0.5)
w[0] += 1.0;
while (w[1] > 0.5)
w[1] -= 1.0;
while (w[1] <= -0.5)
w[1] += 1.0;
while (w[2] > 0.5)
w[2] -= 1.0;
while (w[2] <= -0.5)
w[2] += 1.0;*/
return g_mBoxFromOrtho * w;
} else {
if (g_bPeriodicX) {
n = PeriodicImage1D( v[0], -g_fBoxX/2.0, g_fBoxX/2.0 );
if (n != 0)
v[0] -= n*g_fBoxX;
}
if (g_bPeriodicY) {
n = PeriodicImage1D( v[1], -g_fBoxY/2.0, g_fBoxY/2.0 );
if (n != 0)
v[1] -= n*g_fBoxY;
}
if (g_bPeriodicZ) {
n = PeriodicImage1D( v[2], -g_fBoxZ/2.0, g_fBoxZ/2.0 );
if (n != 0)
v[2] -= n*g_fBoxZ;
}
/* if (g_bPeriodicX)
{
while (v[0] > g_fBoxX/2)
v[0] -= g_fBoxX;
while (v[0] <= -g_fBoxX/2)
v[0] += g_fBoxX;
}
if (g_bPeriodicY)
{
while (v[1] > g_fBoxY/2)
v[1] -= g_fBoxY;
while (v[1] <= -g_fBoxY/2)
v[1] += g_fBoxY;
}
if (g_bPeriodicZ)
{
while (v[2] > g_fBoxZ/2)
v[2] -= g_fBoxZ;
while (v[2] <= -g_fBoxZ/2)
v[2] += g_fBoxZ;
}*/
}
return v;
}
inline CxDVector3 FoldVectorPositive(CxDVector3 v) {
int n;
if (g_bBoxNonOrtho) {
CxDVector3 w;
w = g_mBoxToOrtho * v;
n = PeriodicImage1D( w[0], 0, 1.0 );
if (n != 0)
w[0] -= n;
n = PeriodicImage1D( w[1], 0, 1.0 );
if (n != 0)
w[1] -= n;
n = PeriodicImage1D( w[2], 0, 1.0 );
if (n != 0)
w[2] -= n;
/* while (w[0] >= 1.0)
w[0] -= 1.0;
while (w[0] < 0)
w[0] += 1.0;
while (w[1] >= 1.0)
w[1] -= 1.0;
while (w[1] < 0)
w[1] += 1.0;
while (w[2] >= 1.0)
w[2] -= 1.0;
while (w[2] < 0)
w[2] += 1.0;*/
return g_mBoxFromOrtho * w;
} else {
if (g_bPeriodicX) {
n = PeriodicImage1D( v[0], 0, g_fBoxX );
if (n != 0)
v[0] -= n*g_fBoxX;
}
if (g_bPeriodicY) {
n = PeriodicImage1D( v[1], 0, g_fBoxY );
if (n != 0)
v[1] -= n*g_fBoxY;
}
if (g_bPeriodicZ) {
n = PeriodicImage1D( v[2], 0, g_fBoxZ );
if (n != 0)
v[2] -= n*g_fBoxZ;
}
/* if (g_bPeriodicX)
{
while (v[0] >= g_fBoxX)
v[0] -= g_fBoxX;
while (v[0] < 0)
v[0] += g_fBoxX;
}
if (g_bPeriodicY)
{
while (v[1] >= g_fBoxY)
v[1] -= g_fBoxY;
while (v[1] < 0)
v[1] += g_fBoxY;
}
if (g_bPeriodicZ)
{
while (v[2] >= g_fBoxZ)
v[2] -= g_fBoxZ;
while (v[2] < 0)
v[2] += g_fBoxZ;
}*/
}
return v;
}
inline double FoldedLength(CxDVector3 v) {
int n;
if (g_bBoxNonOrtho) {
CxDVector3 w;
w = g_mBoxToOrtho * v;
n = PeriodicImage1D( w[0], -0.5, 0.5 );
if (n != 0)
w[0] -= n;
n = PeriodicImage1D( w[1], -0.5, 0.5 );
if (n != 0)
w[1] -= n;
n = PeriodicImage1D( w[2], -0.5, 0.5 );
if (n != 0)
w[2] -= n;
/* while (w[0] > 0.5)
w[0] -= 1.0;
while (w[0] <= -0.5)
w[0] += 1.0;
while (w[1] > 0.5)
w[1] -= 1.0;
while (w[1] <= -0.5)
w[1] += 1.0;
while (w[2] > 0.5)
w[2] -= 1.0;
while (w[2] <= -0.5)
w[2] += 1.0;*/
return (g_mBoxFromOrtho * w).GetLength();
} else {
if (g_bPeriodicX) {
n = PeriodicImage1D( v[0], -g_fBoxX/2.0, g_fBoxX/2.0 );
if (n != 0)
v[0] -= n*g_fBoxX;
}
if (g_bPeriodicY) {
n = PeriodicImage1D( v[1], -g_fBoxY/2.0, g_fBoxY/2.0 );
if (n != 0)
v[1] -= n*g_fBoxY;
}
if (g_bPeriodicZ) {
n = PeriodicImage1D( v[2], -g_fBoxZ/2.0, g_fBoxZ/2.0 );
if (n != 0)
v[2] -= n*g_fBoxZ;
}
/* if (g_bPeriodicX)
{
while (v[0] > g_fBoxX/2)
v[0] -= g_fBoxX;
while (v[0] <= -g_fBoxX/2)
v[0] += g_fBoxX;
}
if (g_bPeriodicY)
{
while (v[1] > g_fBoxY/2)
v[1] -= g_fBoxY;
while (v[1] <= -g_fBoxY/2)
v[1] += g_fBoxY;
}
if (g_bPeriodicZ)
{
while (v[2] > g_fBoxZ/2)
v[2] -= g_fBoxZ;
while (v[2] <= -g_fBoxZ/2)
v[2] += g_fBoxZ;
}*/
return v.GetLength();
}
}
/*inline CxDVector3 FoldVector1(CxDVector3 v)
{
while (v[0] >= 0.5)
v[0] -= 1.0;
while (v[0] < -0.5)
v[0] += 1.0;
while (v[1] >= 0.5)
v[1] -= 1.0;
while (v[1] < -0.5)
v[1] += 1.0;
while (v[2] >= 0.5)
v[2] -= 1.0;
while (v[2] < -0.5)
v[2] += 1.0;
return v;
}*/
inline double MeshRandom() {
if (g_bProcAddMeshJitter)
return ((rand()%20001)-10000)/2000000.0*g_fProcAddMeshJitter;
else
return 0;
}
void BuildAtomIndices();
bool DetermineTrajFormat();
void PrintSMode();
void PrintBMode();
void WriteCredits();
void WriteCredits_Long();
unsigned long CalcFFTSize(unsigned long i, bool silent);
//void FormatTime(unsigned long eta, char *buf);
void FormatTime(unsigned long eta, CxString *buf);
void RenderStructFormulas(int tries, bool allsm);
void RenderFormula(const char *s, int tries);
void InitGlobalVars();
void ParseVoronoiRadii();
void DumpNonOrthoCellData();
void ExtractXYZCellGeometry(const char *s);
void ExtractXYZCellGeometry3(const char *s);
void ParseCorrectWavenumber();
double CorrectWavenumber(double w);
const char* GetFileExtension(const char *s);
bool IsElementMetal(const char *s);
bool IsElementNobleGas(const char *s);
#endif
|