Debian Codegraph @

avogadro/qtplugins/forcefield/obmmenergy.h

raw
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
6 #ifndef AVOGADRO_QTPLUGINS_OBMMENERGY_H
7 #define AVOGADRO_QTPLUGINS_OBMMENERGY_H
8
9 #include <avogadro/calc/energycalculator.h>
10
11 #include <avogadro/core/avogadrocore.h>
12
13 #include <QtCore/QCoreApplication>
14 #include <QtCore/QProcess>
15 #include <QtCore/QString>
16 #include <QtCore/QTemporaryFile>
17
18 class QJsonObject;
19
20 namespace Avogadro {
21
22 namespace Io {
23 class FileFormat;
24 }
25
26 namespace QtPlugins {
27
28 class OBMMEnergy : public Avogadro::Calc::EnergyCalculator
29 {
30 Q_DECLARE_TR_FUNCTIONS(OBMMEnergy)
31
32 public:
33 /** Formats that may be written to the script's input. */
34 enum Format
35 {
36 NotUsed,
37 Cjson,
38 Cml,
39 Mdl, // sdf
40 Pdb,
41 Xyz
42 };
43
44 OBMMEnergy(const std::string& method = "");
45 ~OBMMEnergy() override;
46
47 std::string method() const { return m_identifier; }
48 void setupProcess();
49
50 Calc::EnergyCalculator* newInstance() const override;
51
52 std::string identifier() const override { return m_identifier; }
53 std::string name() const override { return m_name; }
54 std::string description() const override
55 {
56 return m_description.toStdString();
57 }
58
59 Core::Molecule::ElementMask elements() const override { return (m_elements); }
60
61 // This will check if the molecule is valid for this script
62 // and then start the external process
63 void setMolecule(Core::Molecule* mol) override;
64 // energy
65 Real value(const Eigen::VectorXd& x) override;
66 // gradient (which may be unsupported and fall back to numeric)
67 void gradient(const Eigen::VectorXd& x, Eigen::VectorXd& grad) override;
68
69 bool acceptsIons() const override { return true; }
70 // UFF can handle radicals
71 bool acceptsRadicals() const override;
72
73 /**
74 * @brief Synchronous use of the QProcess.
75 */
76 QByteArray writeAndRead(const QByteArray& input);
77
78 private:
79 Core::Molecule* m_molecule;
80 Io::FileFormat* m_inputFormat;
81 QProcess* m_process;
82 QString m_executable;
83
84 Core::Molecule::ElementMask m_elements;
85 std::string m_identifier;
86 std::string m_name;
87 QString m_description;
88
89 QTemporaryFile m_tempFile;
90 };
91
92 } // namespace QtPlugins
93 } // namespace Avogadro
94
95 #endif // AVOGADRO_QTPLUGINS_OBMMENERGY_H