Changeset d1134d


Ignore:
Timestamp:
Jul 12, 2017, 7:10:32 PM (7 years ago)
Author:
Frederik Heber <frederik.heber@…>
Branches:
Action_Thermostats, Adding_Graph_to_ChangeBondActions, Adding_MD_integration_tests, Adding_StructOpt_integration_tests, AutomationFragmentation_failures, Candidate_v1.6.1, ChemicalSpaceEvaluator, Enhanced_StructuralOptimization, Enhanced_StructuralOptimization_continued, Exclude_Hydrogens_annealWithBondGraph, Fix_Verbose_Codepatterns, ForceAnnealing_with_BondGraph, ForceAnnealing_with_BondGraph_continued, ForceAnnealing_with_BondGraph_continued_betteresults, ForceAnnealing_with_BondGraph_contraction-expansion, Gui_displays_atomic_force_velocity, JobMarket_RobustOnKillsSegFaults, JobMarket_StableWorkerPool, PythonUI_with_named_parameters, Recreated_GuiChecks, StoppableMakroAction, TremoloParser_IncreasedPrecision
Children:
92d0e6
Parents:
4a6ef3
git-author:
Frederik Heber <frederik.heber@…> (05/18/17 19:10:25)
git-committer:
Frederik Heber <frederik.heber@…> (07/12/17 19:10:32)
Message:

FIX: rotate-around-bond now rotates only one side of mol's bond graph.

  • TESTS: Added regression test on almost complete circle where bond rotation only works because of the new functionality.
Files:
2 added
2 edited

Legend:

Unmodified
Added
Removed
  • src/Actions/MoleculeAction/RotateAroundBondAction.cpp

    r4a6ef3 rd1134d  
    4646#include "Graph/CyclicStructureAnalysis.hpp"
    4747#include "Graph/DepthFirstSearchAnalysis.hpp"
     48#include "Graph/BoostGraphCreator.hpp"
     49#include "Graph/BoostGraphHelpers.hpp"
     50#include "Graph/BreadthFirstSearchGatherer.hpp"
    4851
    4952#include "Atom/atom.hpp"
     
    7477}
    7578
     79static bool addEdgePredicate(
     80    const bond &_bond,
     81    const std::vector<atomId_t> &_atomids)
     82{
     83  ASSERT(_atomids.size() == (size_t)2,
     84      "addEdgePredicate() - atomids must contain exactly two ids.");
     85  // do not add selected edge
     86  return ((_bond.leftatom->getId() != _atomids[0])
     87      || (_bond.rightatom->getId() != _atomids[1]));
     88}
     89
    7690ActionState::ptr MoleculeRotateAroundBondAction::performCall()
    7791{
     
    109123  }
    110124
     125  // gather sorted ids
     126  std::vector<atomId_t> atomids(2);
     127  atomids[0] = atoms[0]->getId();
     128  atomids[1] = atoms[1]->getId();
     129  std::sort(atomids.begin(), atomids.end());
     130  LOG(1, "DEBUG: Selected nodes are " << atomids);
     131
     132  // get nodes on either side of selected bond via BFS discovery
     133  BoostGraphCreator BGcreator;
     134  BGcreator.createFromMolecule(*mol,
     135      boost::bind(addEdgePredicate, _1, boost::ref(atomids)));
     136  BreadthFirstSearchGatherer NodeGatherer(BGcreator);
     137  BoostGraphHelpers::Nodeset_t bondside_sets =
     138      NodeGatherer(params.bondside.get() ? atoms[0]->getId() : atoms[1]->getId());
     139  std::sort(bondside_sets.begin(), bondside_sets.end());
     140
    111141  // convert from degrees to radian
    112142  const double angle_radian = params.angle.get() * M_PI/180.;
     
    118148  Plane bondplane(NormalVector, OffsetVector);
    119149  Line RotationAxis(OffsetVector, NormalVector);
     150
    120151  // go through the molecule and rotate each atom relative two plane
    121152  for (molecule::iterator iter = mol->begin(); iter != mol->end(); ++iter) {
    122153    const Vector &position = (*iter)->getPosition();
    123154    const double signed_distance = bondplane.SignedDistance(position);
     155    // for each atom determine in which set of nodes it is and shift accordingly
     156    const atomId_t &atomid = (*iter)->getId();
    124157    LOG(3, "DEBUG: Inspecting atom " << **iter << " at " << position);
    125     if ((params.bondside.get() && (signed_distance > 0)) ||
    126         (!params.bondside.get() && (signed_distance < 0))) {
     158    if (std::binary_search(bondside_sets.begin(), bondside_sets.end(), atomid)) {
    127159      LOG(4, "DEBUG: Rotating atom " << **iter << " by " << angle_radian
    128160          << " rad around " << RotationAxis);
  • tests/regression/Molecules/RotateAroundBond/testsuite-molecules-rotate-around-bond.at

    r4a6ef3 rd1134d  
    8686
    8787AT_CLEANUP
     88
     89AT_SETUP([Molecules - Rotate around bond on almost complete cycle])
     90AT_KEYWORDS([molecules rotate-around-bond])
     91
     92file=benzene_90degree.pdb
     93AT_CHECK([/bin/cp -f ${abs_top_srcdir}/tests/regression/Molecules/RotateAroundBond/pre/benzene.pdb $file], 0)
     94AT_CHECK([chmod u+w $file], 0)
     95AT_CHECK([../../molecuilder -i $file --select-atom-by-order -1 -6 --remove-atom --select-atom-by-id 3 5 --rotate-around-bond 90.], 0, [stdout], [stderr])
     96AT_CHECK([diff -I '.*reated by molecuilder.*' $file ${abs_top_srcdir}/tests/regression/Molecules/RotateAroundBond/post/$file], 0, [ignore], [ignore])
     97
     98AT_CLEANUP
Note: See TracChangeset for help on using the changeset viewer.