| 1 |
/****************************************************************************** |
| 2 |
This source file is part of the Avogadro project. |
| 3 |
This source code is released under the 3-Clause BSD License, (see "LICENSE"). |
| 4 |
******************************************************************************/ |
| 5 |
#include <avogadro/io/fileformatmanager.h> |
| 6 |
#include <avogadro/quantumio/gamessus.h> |
| 7 |
#include <avogadro/quantumio/gaussianfchk.h> |
| 8 |
#include <avogadro/quantumio/molden.h> |
| 9 |
#include <avogadro/quantumio/mopacaux.h> |
| 10 |
|
| 11 |
#include <avogadro/core/cube.h> |
| 12 |
#include <avogadro/core/gaussiansettools.h> |
| 13 |
#include <avogadro/core/molecule.h> |
| 14 |
#include <avogadro/core/version.h> |
| 15 |
|
| 16 |
#include <iostream> |
| 17 |
#include <sstream> |
| 18 |
#include <string> |
| 19 |
|
| 20 |
using Avogadro::Core::Cube; |
| 21 |
using Avogadro::Core::GaussianSetTools; |
| 22 |
using Avogadro::Core::Molecule; |
| 23 |
using Avogadro::Io::FileFormatManager; |
| 24 |
using std::cin; |
| 25 |
using std::cout; |
| 26 |
using std::endl; |
| 27 |
using std::ostringstream; |
| 28 |
using std::string; |
| 29 |
|
| 30 |
using Eigen::Vector3d; |
| 31 |
using Eigen::Vector3i; |
| 32 |
static const double BOHR_TO_ANGSTROM = 0.529177249; |
| 33 |
static const double ANGSTROM_TO_BOHR = 1.0 / BOHR_TO_ANGSTROM; |
| 34 |
|
| 35 |
void printHelp(); |
| 36 |
|
| 37 |
int main(int argc, char* argv[]) |
| 38 |
{ |
| 39 |
// Register our quantum file format. |
| 40 |
FileFormatManager& mgr = FileFormatManager::instance(); |
| 41 |
mgr.registerFormat(new Avogadro::QuantumIO::GAMESSUSOutput); |
| 42 |
mgr.registerFormat(new Avogadro::QuantumIO::GaussianFchk); |
| 43 |
mgr.registerFormat(new Avogadro::QuantumIO::MoldenFile); |
| 44 |
mgr.registerFormat(new Avogadro::QuantumIO::MopacAux); |
| 45 |
|
| 46 |
// Process the command line arguments, see what has been requested. |
| 47 |
string inFormat; |
| 48 |
int orbitalNumber = 0; |
| 49 |
string inFile; |
| 50 |
bool density = false; |
| 51 |
for (int i = 1; i < argc; ++i) { |
| 52 |
string current(argv[i]); |
| 53 |
if (current == "--help" || current == "-h") { |
| 54 |
printHelp(); |
| 55 |
return 0; |
| 56 |
} else if (current == "--version" || current == "-v") { |
| 57 |
cout << "Version: " << Avogadro::version() << endl; |
| 58 |
return 0; |
| 59 |
} else if (current == "-i" && i + 1 < argc) { |
| 60 |
inFormat = argv[++i]; |
| 61 |
cout << "input format " << inFormat << endl; |
| 62 |
} else if (current == "-orb" && i + 1 < argc) { |
| 63 |
orbitalNumber = atoi(argv[++i]); |
| 64 |
// cout << "plot orbital " << orbitalNumber << endl; |
| 65 |
} else if (current == "-dens" && i < argc) { |
| 66 |
density = true; |
| 67 |
} else if (inFile.empty()) { |
| 68 |
inFile = argv[i]; |
| 69 |
} |
| 70 |
} |
| 71 |
|
| 72 |
// Now read/write the molecule, if possible. Otherwise output errors. |
| 73 |
Molecule mol; |
| 74 |
if (!inFile.empty()) { |
| 75 |
if (!mgr.readFile(mol, inFile, inFormat)) { |
| 76 |
cout << "Failed to read " << inFile << " (" << inFormat << ")" << endl; |
| 77 |
return 1; |
| 78 |
} |
| 79 |
} else if (!inFormat.empty()) { |
| 80 |
ostringstream inFileString; |
| 81 |
string line; |
| 82 |
while (getline(cin, line)) |
| 83 |
inFileString << line; |
| 84 |
if (!inFileString.str().empty()) { |
| 85 |
if (!mgr.readString(mol, inFileString.str(), inFormat)) { |
| 86 |
cout << "Failed to read input stream: " << inFileString.str() << endl; |
| 87 |
return 1; |
| 88 |
} |
| 89 |
} |
| 90 |
} else { |
| 91 |
cout << "Error, no input file or stream supplied with format." << endl; |
| 92 |
} |
| 93 |
if ((orbitalNumber > 0) && density) { |
| 94 |
cout << "Error, choose either density or a single orbital, not both." |
| 95 |
<< endl; |
| 96 |
return 1; |
| 97 |
} |
| 98 |
|
| 99 |
// cube header |
| 100 |
cout << "Avogadro generated cube" << endl; |
| 101 |
if (orbitalNumber > 0) |
| 102 |
cout << "Orbital " << orbitalNumber << endl; |
| 103 |
else |
| 104 |
cout << "Electron Density" << endl; |
| 105 |
|
| 106 |
// set box dimensions in Bohr |
| 107 |
Vector3d min = Vector3d(-10.0, -10.0, -10.0); |
| 108 |
Vector3d max = Vector3d(10.0, 10.0, 10.0); |
| 109 |
Vector3i points = Vector3i(61, 61, 61); |
| 110 |
|
| 111 |
Cube* m_qube = new Cube; |
| 112 |
m_qube->setLimits(min * BOHR_TO_ANGSTROM, max * BOHR_TO_ANGSTROM, points); |
| 113 |
|
| 114 |
min = m_qube->position(0) * ANGSTROM_TO_BOHR; |
| 115 |
Vector3d spacing = m_qube->spacing() * ANGSTROM_TO_BOHR; |
| 116 |
int nat = mol.atomCount(); |
| 117 |
printf("%4d %11.6f %11.6f %11.6f\n", nat, min.x(), min.y(), min.z()); |
| 118 |
printf("%4d %11.6f %11.6f %11.6f\n", points.x(), spacing.x(), 0.0, 0.0); |
| 119 |
printf("%4d %11.6f %11.6f %11.6f\n", points.y(), 0.0, spacing.y(), .0); |
| 120 |
printf("%4d %11.6f %11.6f %11.6f\n", points.z(), 0.0, 0.0, spacing.z()); |
| 121 |
|
| 122 |
// atoms |
| 123 |
for (int iatom = 0; iatom < nat; iatom++) { |
| 124 |
printf("%4d %11.6f %11.6f %11.6f %11.6f\n", mol.atomicNumber(iatom), 0.0, |
| 125 |
mol.atomPosition3d(iatom).x() * ANGSTROM_TO_BOHR, |
| 126 |
mol.atomPosition3d(iatom).y() * ANGSTROM_TO_BOHR, |
| 127 |
mol.atomPosition3d(iatom).z() * ANGSTROM_TO_BOHR); |
| 128 |
} |
| 129 |
if (orbitalNumber > 0) |
| 130 |
cout << "1 " << orbitalNumber << endl; |
| 131 |
|
| 132 |
auto* m_tools = new GaussianSetTools(&mol); |
| 133 |
|
| 134 |
// print the qube values |
| 135 |
int linecount = 0; |
| 136 |
for (unsigned int i = 0; i < m_qube->data()->size(); i++) { |
| 137 |
if (i % points.z() == 0 && i > 0) { |
| 138 |
linecount = 0; |
| 139 |
printf("\n"); |
| 140 |
} |
| 141 |
double value = |
| 142 |
m_tools->calculateMolecularOrbital(m_qube->position(i), orbitalNumber); |
| 143 |
printf("%13.5E", value); |
| 144 |
// line wrapping |
| 145 |
linecount++; |
| 146 |
if (linecount % 6 == 0 && i > 0) |
| 147 |
printf("\n"); |
| 148 |
else |
| 149 |
printf(" "); |
| 150 |
} |
| 151 |
printf("\n"); |
| 152 |
|
| 153 |
return 0; |
| 154 |
} |
| 155 |
|
| 156 |
void printHelp() |
| 157 |
{ |
| 158 |
cout << "Usage: qube [-i <input-type>] <infilename> [-dens] [-orb <orbital " |
| 159 |
"number>] [-v / --version] \n" |
| 160 |
<< endl; |
| 161 |
} |