24#include <boost/lexical_cast.hpp>
47 processed_some_frames_(false) {}
55 std::cout <<
"begin to calculate distribution functions\n";
56 std::cout <<
"# of bonded interactions: " <<
bonded_.size() << std::endl;
57 std::cout <<
"# of non-bonded interactions: " <<
nonbonded_.size()
61 throw std::runtime_error(
62 "No interactions defined in options xml-file - nothing to be done");
73 Eigen::Matrix3d box = top->
getBox();
74 boxc_ = box.rowwise().sum() / 2.0;
76 std::cout <<
"Using center of box: " <<
boxc_ << std::endl;
84 std::string name = prop->get(
"name").value();
91 allbeads1.
Generate(*top, prop->get(
"type1").value());
92 allbeads2.
Generate(*top, prop->get(
"type2").value());
94 if (allbeads1.
size() == 0) {
95 throw std::runtime_error(
"Topology does not have beads of type \"" +
96 prop->get(
"type1").value() +
98 "This was specified in type1 of interaction \"" +
101 if (allbeads2.
size() == 0) {
102 throw std::runtime_error(
"Topology does not have beads of type \"" +
103 prop->get(
"type2").value() +
105 "This was specified in type2 of interaction \"" +
111 std::cout <<
"Volume correction on" << std::endl;
114 std::cout <<
"Volume correction off" << std::endl;
121 std::string name = p->
get(
"name").
value();
126 auto inter = std::make_unique<interaction_t>();
157 throw std::runtime_error(
158 "no frames were processed. Please check your input");
183 interaction_.second->average_.Clear();
187 group_.second->corr_.setZero();
194 Eigen::Vector3d boxc,
bool do_vol_corr)
196 subvol_rad_(subvol_rad),
198 do_vol_corr_(do_vol_corr) {}
208 double dr = (b1->
Pos() - boxc_).norm();
209 if (dist + dr > subvol_rad_) {
211 hist_->
Process(dist, 2.0 / SurfaceRatio(dist, dr));
225 return (1.0 + (subvol_rad_ * subvol_rad_ - r * r - dist * dist) /
232 for (
Property *prop : rdfcalculator_->nonbonded_) {
233 std::string name = prop->
get(
"name").
value();
241 rdfcalculator_->boxc_,
242 rdfcalculator_->subvol_rad_);
244 rdfcalculator_->boxc_,
245 rdfcalculator_->subvol_rad_);
247 cur_beadlist_1_count_ = (double)beads1.
size();
248 cur_beadlist_2_count_ = (double)beads2.
size();
252 cur_beadlist_2_count_ /= 2.0;
256 std::unique_ptr<NBList> nb;
258 bool gridsearch =
true;
260 if (rdfcalculator_->options_.exists(
"cg.nbsearch")) {
261 if (rdfcalculator_->options_.get(
"cg.nbsearch").as<std::string>() ==
264 }
else if (rdfcalculator_->options_.get(
"cg.nbsearch")
265 .as<std::string>() ==
"simple") {
268 throw std::runtime_error(
"cg.nbsearch invalid, can be grid or simple");
272 nb = std::make_unique<NBListGrid>();
274 nb = std::make_unique<NBList>();
280 current_hists_[i.
index_].Clear();
283 rdfcalculator_->subvol_rad_, rdfcalculator_->boxc_,
284 rdfcalculator_->do_vol_corr_);
289 nb->Generate(beads1);
291 nb->Generate(beads1, beads2);
302 for (
Property *prop : rdfcalculator_->bonded_) {
303 std::string name = prop->
get(
"name").
value();
308 current_hists_[i.
index_].Clear();
313 for (
auto ic : vec) {
314 double v = ic->EvaluateVar(*top);
315 current_hists_[i.
index_].Process(v);
322 std::map<std::string, std::unique_ptr<group_t>>::iterator iter;
325 return (
groups_[name] = std::make_unique<group_t>()).get();
327 return (*iter).second.get();
336 Table &t = interaction_.second->average_.data();
339 interaction_.second->norm_ /=
340 (interaction_.second->avg_beadlist_1_count_.getAvg() *
341 interaction_.second->avg_beadlist_2_count_.getAvg());
343 dist.
y().cwiseQuotient(dist.
x().cwiseAbs2());
345 dist.
Save((interaction_.first) + suffix +
".dist.new");
346 std::cout <<
"written " << (interaction_.first) + suffix +
".dist.new\n";
348 std::cout <<
"Avg. number of particles in subvol for "
349 << (interaction_.first) << std::endl;
350 std::cout <<
"beadlist 1: "
351 << interaction_.second->avg_beadlist_1_count_.getAvg()
353 std::cout <<
"beadlist 2: "
354 << interaction_.second->avg_beadlist_2_count_.getAvg()
358 std::cout <<
"Volume used for normalization: " <<
avg_vol_.
getAvg()
363 auto worker = std::make_unique<RDFCalculator::Worker>();
366 worker->rdfcalculator_ =
this;
370 worker->current_hists_[i->
index_].Initialize(
398 std::string(
"_") + boost::lexical_cast<std::string>(
nblock_);
virtual Eigen::Vector3d & Pos()
Index Generate(Topology &top, const std::string &select)
Select all beads of type "select".
Index GenerateInSphericalSubvolume(Topology &top, const std::string &select, Eigen::Vector3d ref, double radius)
Select all beads of type "select" withn a radius "radius" of reference vector "ref".
Worker, derived from Thread, does the work.
bool FoundPair(Bead *b1, Bead *, const Eigen::Vector3d &, const double dist)
double SurfaceRatio(double dist, double r)
IMCNBSearchHandler(HistogramNew *hist, double subvol_rad, Eigen::Vector3d boxc, bool do_vol_corr)
void DoNonbonded(Topology *top)
process non-bonded interactions for given frame
void DoBonded(Topology *top)
process bonded interactions for given frame
void EvalConfiguration(Topology *top, Topology *top_atom) override
evaluate current conformation
RDFCalculator * rdfcalculator_
std::vector< HistogramNew > current_hists_
std::unique_ptr< CsgApplication::Worker > ForkWorker()
std::vector< Property * > nonbonded_
list of non-bonded interactions
Average< double > avg_vol_
interaction_t * AddInteraction(Property *p)
create a new interaction entry based on given options
std::vector< Property * > bonded_
list of bonded interactions
void BeginEvaluate(Topology *top, Topology *top_atom)
begin coarse graining a trajectory
void EndEvaluate()
end coarse graining a trajectory
std::map< std::string, std::unique_ptr< interaction_t > > interactions_
std::map ineteractionm-name to interaction
void WriteDist(const std::string &suffix="")
Property options_
the options parsed from cg definition file
std::map< std::string, std::unique_ptr< group_t > > groups_
std::map group-name to group
bool processed_some_frames_
void LoadOptions(const std::string &file)
load cg definitions file
void MergeWorker(CsgApplication::Worker *worker_)
group_t * getGroup(const std::string &name)
get group by name, creates one if it doesn't exist
topology of the whole system
std::vector< Interaction * > InteractionsInGroup(const std::string &group)
const Eigen::Matrix3d & getBox() const
base class for all analysis tools
struct to store collected information for groups (e.g. crosscorrelations)
std::list< interaction_t * > interactions_
struct to store collected information for interactions
Average< double > avg_beadlist_2_count_
Average< double > avg_beadlist_1_count_