Commit 0193e21a authored by Carl Poelking's avatar Carl Poelking
Browse files

Archiving: fixes.

parent b668b168
...@@ -159,7 +159,7 @@ void AtomicSpectrum::addQnlmNeighbour(Particle *nb, qnlm_t *nb_expansion) { ...@@ -159,7 +159,7 @@ void AtomicSpectrum::addQnlmNeighbour(Particle *nb, qnlm_t *nb_expansion) {
return; return;
} }
void AtomicSpectrum::mergeQnlm(AtomicSpectrum *other, double scale) { void AtomicSpectrum::mergeQnlm(AtomicSpectrum *other, double scale, bool gradients) {
// Function used to construct global spectrum as sum over atomic spectra. // Function used to construct global spectrum as sum over atomic spectra.
// The result is itself an "atomic" spectrum (as data fields are largely identical, // The result is itself an "atomic" spectrum (as data fields are largely identical,
// except for the fact that this summed spectrum does not have a well-defined center. // except for the fact that this summed spectrum does not have a well-defined center.
...@@ -186,6 +186,7 @@ void AtomicSpectrum::mergeQnlm(AtomicSpectrum *other, double scale) { ...@@ -186,6 +186,7 @@ void AtomicSpectrum::mergeQnlm(AtomicSpectrum *other, double scale) {
mit->second->add(*density, scale); mit->second->add(*density, scale);
} }
// Particle-ID-resolved gradients // Particle-ID-resolved gradients
if (gradients) {
map_pid_qnlm_t &map_pid_qnlm_other = other->getPidQnlmMap(); map_pid_qnlm_t &map_pid_qnlm_other = other->getPidQnlmMap();
for (auto it = map_pid_qnlm_other.begin(); it != map_pid_qnlm_other.end(); ++it) { for (auto it = map_pid_qnlm_other.begin(); it != map_pid_qnlm_other.end(); ++it) {
int pid = it->first; int pid = it->first;
...@@ -203,6 +204,7 @@ void AtomicSpectrum::mergeQnlm(AtomicSpectrum *other, double scale) { ...@@ -203,6 +204,7 @@ void AtomicSpectrum::mergeQnlm(AtomicSpectrum *other, double scale) {
// Add gradients ... // Add gradients ...
mit->second.second->addGradient(*density_grad); mit->second.second->addGradient(*density_grad);
} }
}
return; return;
} }
......
...@@ -59,7 +59,7 @@ public: ...@@ -59,7 +59,7 @@ public:
qnlm_t *getQnlmGeneric() { return _qnlm_generic; } qnlm_t *getQnlmGeneric() { return _qnlm_generic; }
map_qnlm_t &getQnlmMap() { return _map_qnlm; } map_qnlm_t &getQnlmMap() { return _map_qnlm; }
map_pid_qnlm_t &getPidQnlmMap() { return _map_pid_qnlm; } map_pid_qnlm_t &getPidQnlmMap() { return _map_pid_qnlm; }
void mergeQnlm(AtomicSpectrum *other, double scale); void mergeQnlm(AtomicSpectrum *other, double scale, bool gradients);
// XNKL METHODS // XNKL METHODS
void computePower(); void computePower();
void computePowerGradients(); void computePowerGradients();
......
#include "soap/cutoff.hpp" #include "soap/cutoff.hpp"
#include <boost/archive/binary_iarchive.hpp>
#include <boost/archive/binary_oarchive.hpp>
#include <boost/archive/text_iarchive.hpp>
#include <boost/archive/text_oarchive.hpp>
namespace soap { namespace soap {
...@@ -77,6 +81,7 @@ void CutoffFunctionFactory::registerAll(void) { ...@@ -77,6 +81,7 @@ void CutoffFunctionFactory::registerAll(void) {
CutoffFunctionOutlet().Register<CutoffFunctionHeaviside>("heaviside"); CutoffFunctionOutlet().Register<CutoffFunctionHeaviside>("heaviside");
} }
} }
BOOST_CLASS_EXPORT_IMPLEMENT(soap::CutoffFunctionHeaviside);
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
#include <string> #include <string>
#include <math.h> #include <math.h>
#include <vector> #include <vector>
#include <boost/serialization/base_object.hpp>
#include <boost/serialization/export.hpp>
#include "soap/base/exceptions.hpp" #include "soap/base/exceptions.hpp"
#include "soap/base/objectfactory.hpp" #include "soap/base/objectfactory.hpp"
...@@ -93,6 +95,9 @@ inline CutoffFunction *CutoffFunctionFactory::create(const std::string &key) { ...@@ -93,6 +95,9 @@ inline CutoffFunction *CutoffFunctionFactory::create(const std::string &key) {
} }
} }
} } /* CLOSE NAMESPACE */
BOOST_CLASS_EXPORT_KEY(soap::CutoffFunction);
BOOST_CLASS_EXPORT_KEY(soap::CutoffFunctionHeaviside);
#endif #endif
...@@ -96,6 +96,30 @@ bool Options::doExcludeTargetId(int pid) { ...@@ -96,6 +96,30 @@ bool Options::doExcludeTargetId(int pid) {
return (it == _exclude_target_id.end()) ? false : true; return (it == _exclude_target_id.end()) ? false : true;
} }
void Options::generateExclusionLists() {
if (!boost::python::len(_exclude_center_list)) {
for (auto it = _exclude_center.begin(); it != _exclude_center.end(); ++it) {
if (it->second) _exclude_center_list.append(it->first);
}
}
if (!boost::python::len(_exclude_target_list)) {
for (auto it = _exclude_target.begin(); it != _exclude_target.end(); ++it) {
if (it->second) _exclude_target_list.append(it->first);
}
}
if (!boost::python::len(_exclude_center_id_list)) {
for (auto it = _exclude_center_id.begin(); it != _exclude_center_id.end(); ++it) {
if (it->second) _exclude_center_id_list.append(it->first);
}
}
if (!boost::python::len(_exclude_target_id_list)) {
for (auto it = _exclude_target_id.begin(); it != _exclude_target_id.end(); ++it) {
if (it->second) _exclude_target_id_list.append(it->first);
}
}
return;
}
void Options::registerPython() { void Options::registerPython() {
using namespace boost::python; using namespace boost::python;
void (Options::*set_int)(std::string, int) = &Options::set; void (Options::*set_int)(std::string, int) = &Options::set;
......
...@@ -47,6 +47,9 @@ public: ...@@ -47,6 +47,9 @@ public:
boost::python::list getExcludeCenterIdList() { return _exclude_center_id_list; } boost::python::list getExcludeCenterIdList() { return _exclude_center_id_list; }
boost::python::list getExcludeTargetIdList() { return _exclude_target_id_list; } boost::python::list getExcludeTargetIdList() { return _exclude_target_id_list; }
// USED IN SERIALIZATION-LOAD: std::map TO boost::python::list
void generateExclusionLists();
// PYTHON // PYTHON
static void registerPython(); static void registerPython();
...@@ -57,13 +60,15 @@ public: ...@@ -57,13 +60,15 @@ public:
arch & _exclude_center; arch & _exclude_center;
arch & _exclude_target; arch & _exclude_target;
arch & _exclude_center_list; //arch & _exclude_center_list;
arch & _exclude_target_list; //arch & _exclude_target_list;
arch & _exclude_center_id; arch & _exclude_center_id;
arch & _exclude_target_id; arch & _exclude_target_id;
arch & _exclude_center_id_list; //arch & _exclude_center_id_list;
arch & _exclude_target_id_list; //arch & _exclude_target_id_list;
this->generateExclusionLists();
return; return;
} }
......
...@@ -129,13 +129,14 @@ AtomicSpectrum *Spectrum::computeGlobal() { ...@@ -129,13 +129,14 @@ AtomicSpectrum *Spectrum::computeGlobal() {
if (_global_atomic) throw soap::base::APIError("<Spectrum::computeGlobal> Already initialised."); if (_global_atomic) throw soap::base::APIError("<Spectrum::computeGlobal> Already initialised.");
_global_atomic = new AtomicSpectrum(_basis); _global_atomic = new AtomicSpectrum(_basis);
GLOG() << "Computing global spectrum ..." << std::endl; GLOG() << "Computing global spectrum ..." << std::endl;
bool gradients = _options->get<bool>("spectrum.gradients");
for (auto it = _atomspec_array.begin(); it != _atomspec_array.end(); ++it) { for (auto it = _atomspec_array.begin(); it != _atomspec_array.end(); ++it) {
GLOG() << " Adding center " << (*it)->getCenter()->getId() GLOG() << " Adding center " << (*it)->getCenter()->getId()
<< " (type " << (*it)->getCenter()->getType() << ")" << std::endl; << " (type " << (*it)->getCenter()->getType() << ")" << std::endl;
_global_atomic->mergeQnlm(*it, 0.5); // <- Scale factor 0.5 necessary in order not to overcount pairs _global_atomic->mergeQnlm(*it, 0.5, gradients); // <- Scale factor 0.5 necessary in order not to overcount pairs
} }
_global_atomic->computePower(); _global_atomic->computePower();
_global_atomic->computePowerGradients(); if (gradients) _global_atomic->computePowerGradients();
return _global_atomic; return _global_atomic;
} }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment