Skip to content

Commit

Permalink
Fix error and simplify ranges operations
Browse files Browse the repository at this point in the history
  • Loading branch information
mlund committed Oct 29, 2024
1 parent b5ac8c2 commit 4331755
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/actions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ void AngularScan::Molecule::initialize(const Space::GroupVector& groups, int mol

faunus_logger->trace("{}: initizalizing group {}", NAME, index);

auto as_centered_position = [&](auto& particle) -> Point {
auto as_centered_position = [&](const auto& particle) -> Point {
return particle.pos - group.mass_center;
};
ref_positions = group | rv::transform(as_centered_position) | ranges::to_vector;
Expand All @@ -75,14 +75,17 @@ ParticleVector AngularScan::Molecule::getRotatedReference(const Space::GroupVect
auto particles = ParticleVector(group.begin(), group.end()); // copy particles from Space
auto positions =
ref_positions | rv::transform([&](const auto& pos) -> Point { return q * pos; });
std::copy(positions.begin(), positions.end(),
std::ranges::copy(positions,
(particles | rv::transform(&Particle::pos)).begin());
return particles;
}

void AngularScan::report(const Group& group1, const Group& group2, const Eigen::Quaterniond& q1,
const Eigen::Quaterniond& q2, Energy::NonbondedBase& nonbonded)
{
using ranges::views::concat;
using std::views::transform;

const auto energy = nonbonded.groupGroupEnergy(group1, group2);
if (energy >= max_energy) {
return;
Expand All @@ -98,8 +101,7 @@ void AngularScan::report(const Group& group1, const Group& group2, const Eigen::
*stream << format(q1) << format(q2)
<< fmt::format("{:8.4f} {:>10.3E}\n", group2.mass_center.z(), energy / 1.0_kJmol);
if (trajectory) {
auto positions = ranges::views::concat(group1, group2) |
std::views::transform(&Particle::pos);
auto positions = concat(group1, group2) | transform(&Particle::pos);
trajectory->writeNext({500, 500, 500}, positions.begin(), positions.end());
}
}
Expand All @@ -122,7 +124,7 @@ void AngularScan::operator()(Space& spc, Energy::Hamiltonian& hamiltonian)

#pragma omp parallel for
for (const auto& q1 : angles.quaternions_1) {
auto particles1 = molecules.second.getRotatedReference(spc.groups, q1);
auto particles1 = molecules.first.getRotatedReference(spc.groups, q1);
auto group1 = Group(0, particles1.begin(), particles1.end());
group1.updateMassCenter(spc.geometry.getBoundaryFunc(), {0, 0, 0});

Expand Down

0 comments on commit 4331755

Please sign in to comment.