Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix anglescan when the two molecules are different #458

Merged
merged 4 commits into from
Oct 31, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions src/actions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ void AngularScan::Molecule::initialize(const Space::GroupVector& groups, int mol
if (group.isAtomic()) {
throw ConfigurationError("{}: group {} is not molecular", NAME, index);
}
auto as_centered_position = [&](auto& particle) -> Point {

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

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 @@ -72,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 @@ -95,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 @@ -119,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);
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Source of the problem!

auto group1 = Group(0, particles1.begin(), particles1.end());
group1.updateMassCenter(spc.geometry.getBoundaryFunc(), {0, 0, 0});

Expand Down
Loading