Scine::Swoose  2.1.0
This is the SCINE module Swoose.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Pages
QmmmCalculator.h
Go to the documentation of this file.
1 
8 #ifndef SWOOSE_QMMM_QMMMCALCULATOR_H
9 #define SWOOSE_QMMM_QMMMCALCULATOR_H
10 
12 #include <Core/Interfaces/EmbeddingCalculator.h>
13 #include <Utils/CalculatorBasics.h>
15 #include <algorithm>
16 
17 namespace Scine {
18 
19 namespace MolecularMechanics {
20 class MolecularMechanicsCalculator;
21 } // namespace MolecularMechanics
22 
23 namespace Qmmm {
24 
30 class QmmmCalculator : public Utils::CloneInterface<QmmmCalculator, Core::EmbeddingCalculator, Core::Calculator> {
31  public:
32  static constexpr const char* model = "QM-SFAM";
36  ~QmmmCalculator() override;
38  QmmmCalculator(const QmmmCalculator& rhs);
42  void setUnderlyingCalculators(std::vector<std::shared_ptr<Core::Calculator>> underlyingCalculators) override;
46  void addUnderlyingSettings() override;
50  std::vector<std::shared_ptr<Core::Calculator>> getUnderlyingCalculators() const override;
55  void setStructure(const Utils::AtomCollection& structure) override;
60  std::unique_ptr<Utils::AtomCollection> getStructure() const override;
65  void modifyPositions(Utils::PositionCollection newPositions) override;
69  const Utils::PositionCollection& getPositions() const override;
75  void setRequiredProperties(const Utils::PropertyList& requiredProperties) override;
83  Utils::PropertyList possibleProperties() const override;
92  const Utils::Results& calculate(std::string description) override;
97  std::string name() const override;
102  Utils::Settings& settings() override;
107  const Utils::Settings& settings() const override;
112  Utils::Results& results() override;
117  const Utils::Results& results() const override;
123  bool supportsMethodFamily(const std::string& methodFamily) const override;
128  std::shared_ptr<Core::State> getState() const final;
133  void loadState(std::shared_ptr<Core::State> /*state*/) final;
138  bool allowsPythonGILRelease() const override {
139  const auto underlyingCalculators = getUnderlyingCalculators();
140  return std::all_of(underlyingCalculators.begin(), underlyingCalculators.end(),
141  [](const auto& c) { return c->allowsPythonGILRelease(); });
142  };
147  std::shared_ptr<MolecularMechanics::MolecularMechanicsCalculator> getMolecularMechanicsCalculator();
152  std::shared_ptr<Core::Calculator> getQuantumMechanicsCalculator();
153 
154  private:
155  void setStructureImpl(const Utils::AtomCollection& structure);
156  void setUnderlyingCalculatorsImpl(std::vector<std::shared_ptr<Core::Calculator>> underlyingCalculators);
157  void addUnderlyingSettingsImpl();
158  void optimizeLinks();
159  void handleElectrostaticEmbedding();
160  void removeCalculatorSpecificSettings();
161  /*
162  * @brief Implementation of a calculation.
163  */
164  const Utils::Results& calculateImpl(std::string description);
165  /*
166  * @brief Implementation of a calculation where the QM calculation is not performed.
167  */
168  const Utils::Results& ignoreQmCalculateImpl(std::string description);
169  /*
170  * @brief Apply settings.
171  */
172  void applySettings();
173  /*
174  * @brief Apply settings to underlying calculators (QM and MM).
175  */
176  void applySettingsToUnderlyingCalculators();
177  /*
178  * @brief Eliminates those terms from the MM calculator which shall not be calculated at the MM level,
179  * but at the QM level instead.
180  * @param reducedEnergyCalculation Whether the current calculation is part of a
181  * reduced QM/MM energy evaluation. Default: It is not.
182  */
183  void prepareTermsForMmCalculator(bool reducedEnergyCalculation = false);
184  /*
185  * @brief Sets the current log of this calculator to the underlying QM and MM calculators.
186  */
187  void setLogForUnderlyingCalculators();
188  // The required properties.
189  Utils::PropertyList requiredProperties_;
190  // The settings.
191  std::unique_ptr<Utils::Settings> settings_;
192  // The results container.
193  Utils::Results results_;
194  // The structure of the full system
195  Utils::AtomCollection structure_;
196  // The structure of the QM region
197  Utils::AtomCollection qmRegion_;
198  // Vector containing the indices of the MM atoms close to the boundary (part of a cleft bond)
199  std::vector<int> mmBoundaryAtoms_;
200  // Vector containing the indices of the atoms in the QM region
201  std::vector<int> listOfQmAtoms_;
202  // QM calculator
203  std::shared_ptr<Core::Calculator> qmCalculator_;
204  // Flag for the case that the QM system spans the full system.
205  bool mmAtomsLeft_ = true;
206  /*
207  * Whether an additional MM calculation is performed to evaluate the QM/MM energy
208  * without any covalent and non-covalent contributions solely within the environment
209  */
210  bool calculateReducedQmMmEnergy_;
211  // MM calculator
212  std::shared_ptr<MolecularMechanics::MolecularMechanicsCalculator> mmCalculator_;
213  // Whether electrostatic embedding shall be used (otherwise just mechanical embedding)
214  bool electrostaticEmbedding_;
215  // Whether to not perform the QM calculation.
216  bool ignoreQm_;
217  // File to which the QM region is written in XYZ format
218  std::string qmRegionFile_;
219  // The scheme for how to redistribute the charges close to the QM-MM boundary
220  std::string chargeRedistributionScheme_;
221  // Name of the point charges file
222  static constexpr const char* pointChargesFilename_ = "environment_pointcharges.pc";
227  bool turbomoleIsQmCalculator_ = false;
228  /*
229  * The following boolean keeps track of whether the SCF convergence setting for the QM calculator was already set,
230  * because resetting it with every calculation (e.g., as part of an optimization) will result in a repeated
231  * warning with some calculators (e.g., ORCA). The reason is that some calculators reset this setting internally
232  * After calling setStructure(), this boolean will be reset to false again.
233  *
234  * Important note: This means that if one wants to reset the setting externally, setStructure() has to be recalled
235  * so that the setting is passed on to the QM calculator.
236  */
237  bool scfConvCriterionIsSet_ = false;
238  bool optimizeLinks_ = false;
239 };
240 
241 } // namespace Qmmm
242 } // namespace Scine
243 
244 #endif // SWOOSE_QMMM_QMMMCALCULATOR_H
bool supportsMethodFamily(const std::string &methodFamily) const override
Whether the calculator supports a method family.
Definition: QmmmCalculator.cpp:31
void setUnderlyingCalculators(std::vector< std::shared_ptr< Core::Calculator >> underlyingCalculators) override
Sets the underlying QM and MM calculators.
Definition: QmmmCalculator.cpp:55
Calculator implementing the QM/MM method.
Definition: QmmmCalculator.h:30
std::vector< std::shared_ptr< Core::Calculator > > getUnderlyingCalculators() const override
Gets the underlying QM and MM calculators.
Definition: QmmmCalculator.cpp:99
const Utils::PositionCollection & getPositions() const override
Getter for the coordinates of the underlying Utils::AtomCollection.
Definition: QmmmCalculator.cpp:391
std::shared_ptr< MolecularMechanics::MolecularMechanicsCalculator > getMolecularMechanicsCalculator()
Getter for the MM calculator.
Definition: QmmmCalculator.cpp:546
bool allowsPythonGILRelease() const override
Whether the calculator has no underlying Python code and can therefore release the global interpreter...
Definition: QmmmCalculator.h:138
void setStructure(const Utils::AtomCollection &structure) override
Changes the molecular structure to calculate.
Definition: QmmmCalculator.cpp:144
void loadState(std::shared_ptr< Core::State >) final
Implements Core::StateHandableObject::loadState().
Definition: QmmmCalculator.cpp:459
QmmmCalculator()
Constructor.
Definition: QmmmCalculator.cpp:35
Utils::Settings & settings() override
Accessor for the settings.
Definition: QmmmCalculator.cpp:447
Utils::PropertyList possibleProperties() const override
Returns the list of the possible properties to calculate.
Definition: QmmmCalculator.cpp:431
Utils::PropertyList getRequiredProperties() const override
Getter for the properties to calculate.
Definition: QmmmCalculator.cpp:427
~QmmmCalculator() override
Destructor.
Definition: QmmmCalculator.cpp:524
std::unique_ptr< Utils::AtomCollection > getStructure() const override
Gets the molecular structure as a const Utils::AtomCollection&amp;.
Definition: QmmmCalculator.cpp:375
std::shared_ptr< Core::Calculator > getQuantumMechanicsCalculator()
Getter for the QM calculator.
Definition: QmmmCalculator.cpp:550
std::string name() const override
Getter for the name of the Calculator.
Definition: QmmmCalculator.cpp:27
std::shared_ptr< Core::State > getState() const final
Implements Core::StateHandableObject::getState().
Definition: QmmmCalculator.cpp:463
const Utils::Results & calculate(std::string description) override
The main function running calculations.
Definition: QmmmCalculator.cpp:134
void setRequiredProperties(const Utils::PropertyList &requiredProperties) override
Sets the properties to calculate.
Definition: QmmmCalculator.cpp:395
Utils::Results & results() override
Accessor for the saved instance of Utils::Results.
Definition: QmmmCalculator.cpp:455
void modifyPositions(Utils::PositionCollection newPositions) override
Allows to modify the positions of the underlying Utils::AtomCollection.
Definition: QmmmCalculator.cpp:379
void addUnderlyingSettings() override
Sets the underlying QM and MM calculators.
Definition: QmmmCalculator.cpp:78