Ignore:
Timestamp:
Apr 17, 2013, 6:56:54 PM (12 years ago)
Author:
Frederik Heber <heber@…>
Branches:
Action_Thermostats, Add_AtomRandomPerturbation, Add_FitFragmentPartialChargesAction, Add_RotateAroundBondAction, Add_SelectAtomByNameAction, Added_ParseSaveFragmentResults, AddingActions_SaveParseParticleParameters, Adding_Graph_to_ChangeBondActions, Adding_MD_integration_tests, Adding_ParticleName_to_Atom, Adding_StructOpt_integration_tests, AtomFragments, Automaking_mpqc_open, AutomationFragmentation_failures, Candidate_v1.5.4, Candidate_v1.6.0, Candidate_v1.6.1, ChangeBugEmailaddress, ChangingTestPorts, ChemicalSpaceEvaluator, CombiningParticlePotentialParsing, Combining_Subpackages, Debian_Package_split, Debian_package_split_molecuildergui_only, Disabling_MemDebug, Docu_Python_wait, EmpiricalPotential_contain_HomologyGraph, EmpiricalPotential_contain_HomologyGraph_documentation, Enable_parallel_make_install, Enhance_userguide, Enhanced_StructuralOptimization, Enhanced_StructuralOptimization_continued, Example_ManyWaysToTranslateAtom, Exclude_Hydrogens_annealWithBondGraph, FitPartialCharges_GlobalError, Fix_BoundInBox_CenterInBox_MoleculeActions, Fix_ChargeSampling_PBC, Fix_ChronosMutex, Fix_FitPartialCharges, Fix_FitPotential_needs_atomicnumbers, Fix_ForceAnnealing, Fix_IndependentFragmentGrids, Fix_ParseParticles, Fix_ParseParticles_split_forward_backward_Actions, Fix_PopActions, Fix_QtFragmentList_sorted_selection, Fix_Restrictedkeyset_FragmentMolecule, Fix_StatusMsg, Fix_StepWorldTime_single_argument, Fix_Verbose_Codepatterns, Fix_fitting_potentials, Fixes, ForceAnnealing_goodresults, ForceAnnealing_oldresults, ForceAnnealing_tocheck, ForceAnnealing_with_BondGraph, ForceAnnealing_with_BondGraph_continued, ForceAnnealing_with_BondGraph_continued_betteresults, ForceAnnealing_with_BondGraph_contraction-expansion, FragmentAction_writes_AtomFragments, FragmentMolecule_checks_bonddegrees, GeometryObjects, Gui_Fixes, Gui_displays_atomic_force_velocity, ImplicitCharges, IndependentFragmentGrids, IndependentFragmentGrids_IndividualZeroInstances, IndependentFragmentGrids_IntegrationTest, IndependentFragmentGrids_Sole_NN_Calculation, JobMarket_RobustOnKillsSegFaults, JobMarket_StableWorkerPool, JobMarket_unresolvable_hostname_fix, MoreRobust_FragmentAutomation, ODR_violation_mpqc_open, PartialCharges_OrthogonalSummation, PdbParser_setsAtomName, PythonUI_with_named_parameters, QtGui_reactivate_TimeChanged_changes, Recreated_GuiChecks, Rewrite_FitPartialCharges, RotateToPrincipalAxisSystem_UndoRedo, SaturateAtoms_findBestMatching, SaturateAtoms_singleDegree, StoppableMakroAction, Subpackage_CodePatterns, Subpackage_JobMarket, Subpackage_LinearAlgebra, Subpackage_levmar, Subpackage_mpqc_open, Subpackage_vmg, Switchable_LogView, ThirdParty_MPQC_rebuilt_buildsystem, TrajectoryDependenant_MaxOrder, TremoloParser_IncreasedPrecision, TremoloParser_MultipleTimesteps, TremoloParser_setsAtomName, Ubuntu_1604_changes, stable
Children:
326000
Parents:
4b62d3
git-author:
Frederik Heber <heber@…> (03/19/13 11:04:34)
git-committer:
Frederik Heber <heber@…> (04/17/13 18:56:54)
Message:

Refactored CorrectBondDegree() and resetBondDegree() out of atom_bondedparticle.

  • both functions are for the moment placed in BondGraph but will eventually merge.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Graph/BondGraph.cpp

    r4b62d3 r378fc6b  
    224224  return true;
    225225}
     226
     227/** Corrects the bond degree by one at most if necessary.
     228 * \return number of corrections done
     229 */
     230int BondGraph::CorrectBondDegree(atom *_atom) const
     231{
     232  int NoBonds = 0;
     233  int OtherNoBonds = 0;
     234  int FalseBondDegree = 0;
     235  int CandidateDeltaNoBonds = -1;
     236  atom *OtherWalker = NULL;
     237  bond::ptr CandidateBond;
     238
     239  NoBonds = _atom->CountBonds();
     240  LOG(3, "Walker " << *_atom << ": " << (int)_atom->getType()->getNoValenceOrbitals() << " > " << NoBonds << "?");
     241  const int DeltaNoBonds = (int)(_atom->getType()->getNoValenceOrbitals()) - NoBonds;
     242  if (DeltaNoBonds > 0) { // we have a mismatch, check all bonding partners for mismatch
     243    const BondList& ListOfBonds = _atom->getListOfBonds();
     244    for (BondList::const_iterator Runner = ListOfBonds.begin(); Runner != ListOfBonds.end(); (++Runner)) {
     245      OtherWalker = (*Runner)->GetOtherAtom(_atom);
     246      OtherNoBonds = OtherWalker->CountBonds();
     247      const int OtherDeltaNoBonds = (int)(OtherWalker->getType()->getNoValenceOrbitals()) - OtherNoBonds;
     248      LOG(3, "OtherWalker " << *OtherWalker << ": " << (int)OtherWalker->getType()->getNoValenceOrbitals() << " > " << OtherNoBonds << "?");
     249      if (OtherDeltaNoBonds > 0) { // check if possible candidate
     250        const BondList& OtherListOfBonds = OtherWalker->getListOfBonds();
     251        if ((CandidateBond == NULL)
     252            || (ListOfBonds.size() > OtherListOfBonds.size()) // pick the one with fewer number of bonds first
     253            || ((CandidateDeltaNoBonds < 0) || (CandidateDeltaNoBonds > OtherDeltaNoBonds)) ) // pick the one closer to fulfilling its valence first
     254        {
     255          CandidateDeltaNoBonds = OtherDeltaNoBonds;
     256          CandidateBond = (*Runner);
     257          LOG(3, "New candidate is " << *CandidateBond << ".");
     258        }
     259      }
     260    }
     261    if ((CandidateBond != NULL)) {
     262      CandidateBond->setDegree(CandidateBond->getDegree()+1);
     263      LOG(2, "Increased bond degree for bond " << *CandidateBond << ".");
     264    } else {
     265      ELOG(2, "Could not find correct degree for atom " << *_atom << ".");
     266      FalseBondDegree++;
     267    }
     268  }
     269  return FalseBondDegree;
     270};
     271
     272/** Sets the weight of all connected bonds to one.
     273 */
     274void BondGraph::resetBondDegree(atom *_atom) const
     275{
     276  const BondList &ListOfBonds = _atom->getListOfBonds();
     277  for (BondList::const_iterator BondRunner = ListOfBonds.begin();
     278      BondRunner != ListOfBonds.end();
     279      ++BondRunner)
     280    (*BondRunner)->setDegree(1);
     281};
     282
Note: See TracChangeset for help on using the changeset viewer.