Debian Codegraph @

avogadro/qtplugins/scriptcharges/scriptchargemodel.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_SCRIPTCHARGEMODEL_H
7 #define AVOGADRO_QTPLUGINS_SCRIPTCHARGEMODEL_H
8
9 #include <avogadro/calc/chargemodel.h>
10
11 #include <avogadro/core/avogadrocore.h>
12
13 #include <QtCore/QString>
14 #include <QtCore/QVariantMap>
15
16 class QJsonObject;
17
18 namespace Avogadro {
19
20 namespace Io {
21 class FileFormat;
22 }
23
24 namespace QtGui {
25 class PythonScript;
26 }
27
28 namespace QtPlugins {
29
30 class ScriptChargeModel : public Avogadro::Calc::ChargeModel
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,
40 Pdb,
41 Sdf,
42 Xyz
43 };
44
45 ScriptChargeModel(const QString& scriptFileName = "");
46 ~ScriptChargeModel() override;
47
48 /**
49 * Configure the interpreter for package-based (pixi) execution.
50 */
51 void setPackageInfo(const QString& packageDir, const QString& command,
52 const QString& identifier);
53
54 /**
55 * Populate metadata fields from a QVariantMap (e.g. from pyproject.toml)
56 * instead of calling the script with --metadata.
57 */
58 void readMetaData(const QVariantMap& metadata);
59
60 QString scriptFilePath() const;
61
62 Format inputFormat() const { return m_inputFormat; }
63
64 bool isValid() const { return m_valid; }
65
66 ChargeModel* newInstance() const override;
67
68 std::string identifier() const override { return m_identifier; }
69
70 std::string name() const override { return m_name; }
71
72 Core::Molecule::ElementMask elements() const override { return m_elements; }
73
74 MatrixX partialCharges(Core::Molecule& mol) const override;
75 MatrixX partialCharges(const Core::Molecule& mol) const override;
76
77 double potential(Core::Molecule& mol, const Vector3& point) const override;
78
79 bool supportsCharges() const { return m_partialCharges; }
80
81 bool supportsElectrostatics() const { return m_electrostatics; }
82
83 Core::Array<double> potentials(
84 Core::Molecule& mol, const Core::Array<Vector3>& points) const override;
85
86 private:
87 static Format stringToFormat(const std::string& str);
88 static Io::FileFormat* createFileFormat(Format fmt);
89 void resetMetaData();
90 void readMetaData();
91 bool parseString(const QJsonObject& ob, const QString& key, std::string& str);
92 void processElementString(const QString& str);
93 bool parseElements(const QJsonObject& ob);
94 void copyMetaDataFrom(const ScriptChargeModel& other);
95
96 private:
97 QtGui::PythonScript* m_interpreter;
98 Format m_inputFormat;
99 Core::Molecule::ElementMask m_elements;
100 bool m_valid;
101 bool m_partialCharges;
102 bool m_electrostatics;
103 bool m_inputCjson;
104
105 std::string m_identifier;
106 std::string m_name;
107 std::string m_description;
108 QString m_formatString;
109 };
110
111 } // namespace QtPlugins
112 } // namespace Avogadro
113
114 #endif // AVOGADRO_QTPLUGINS_SCRIPTCHARGEMODEL_H