You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
/// define the electronic structure model and all corresponding derived and interdependent parameters
/// keeps restart logic
/// keeps pointer to solver
/// may be simple (SCF) or complex (MP2)
class CalculationStrategy {
// where the calculation happens
path root
// for each directory one input file
ParameterManager pm;
// for each directory one solvers
std::shared_ptr<QCPropertyInterface> solver;
set_model();
set_keyval_in_parameters_block(parameters,key, val);
write_input();
run_calculation();
// set derived, interdependent parameters, i.e. parameters that are derived from parameter block
set_interdependent_parameters_mp2 {
double thresh=pm["cc2"].thresh();
pm["dft"].set_derived_parameter("k",5);
pm["dft"].set_derived_parameter("thresh",thresh*0.01,);
pm["dft"].set_derived_parameter("ncf",{"slater",2.0});
}
};
class SCFCalculationStrategy : public CalculationStrategy {
SCFCalculationStrategy() : (solver=SCF) {
}
};
class CISCalculationStrategy : public SCFCalculationStrategy {
CISCalculationStrategy() : (solver=CIS) {
}
};
/// model-agnostic base class to compute a property, creates file structure, runs independent calculations and gathers results
/// Each property has its own strategy derived from here
class PropertyStrategy {
CalculationManager calcmanager;
CalculationStrategy cs;
virtual PropertyStrategy(CalculationStrategy& cs) {}
// create directory structure and input files -- aka the dependency graph
setup() = 0
// run the calculation/ use solver
run() {
calcmanager.run_all()
}
// use solution from solver, write into json
recompute_results()
// read from json, no computation
get_results() = 0
};
// examples
class EnergyStrategy : public PropertyStrategy {};
class GradientStrategy : public PropertyStrategy {};
class HyperpolarizationStrategy : public PropertyStrategy {
// create subdirectories for the frequency responses
setup(CalculationStrategy& cs) {
// compute the reference
auto cs_scf=copy(cs).set_keyval_in_parameters_block("config","model","scf");
cs_scf.set_keyval_in_parameters_block("config","property","energy");
calcmanager.addStrategy(cs_scf, root);
// loop over all frequencies
cs_scf.set_keyval_in_parameters_block("config","property","frequency_response");
auto freq=ParameterManager.get_response_parameters["frequencies"]
for (auto& f : freq) {
cs_scf.set_keyval_in_parameters_block("response","frequency",f);
calcmanager.addStrategy(cs_scf, root+"/f"+f);
}
// compute the hyperpolarizability
filenames=make_filenames-from_frequencies
cs_scf.set_keyval_in_parameters_block("response","frequency_response_files", filenames);
cs_scf.set_keyval_in_parameters_block("config","property","hyperpolarizability");
calcmanager.addStrategy(cs_scf,root)
Tensor<double> hyper=...
}
get_property() {
}
};
class ExcitedStateStrategy : public PropertyStrategy {
setup(CalculationStrategy& cs) {
if (cs==SCF) {
calcmanager.addStrategy(CISCalculationStrategy(cs), root);
}
else if (cs==cc2) {
cs.set_keyval_in_parameters_block("cc2","model","lrcc2");
calcmanager.addStrategy(cs, root);
}
get_property() {
// e.g. for a finite difference calculation
calcmanager["calc1"].energy() - calcmanager["calc2"].energy();
}
};
/// wrapper around all calculations set up by PropertyStrategy,
CalculationManager {
std::vector<std::pair<CalculationStrategy,Path> calculation;
json output;
CalculationManager()
void addStrategy(CalculationStrategy, path>
void run_all()
json get_result()
};
std::shared_ptr<PropertyManager> create_property_manager(CalculationStrategy& cs, Configuration::property) {
if (property==energy) return EnergyManager(cs);
if (property==excitedstate) return ExcitedStateManager(cs)
..
}
main() {
ParameterManager pm(input, parser)
auto cs=CalculationStrategy(Configuration::model, pm)
auto ps=create_property_manager(cs, Configuration::property)
// from now on the configuration block in the input file is ignored
ps->setup();
ps->run();
ps->get_result();
}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
madqc
Layout
Beta Was this translation helpful? Give feedback.
All reactions