Changeset f33ef9 for src/Actions


Ignore:
Timestamp:
May 18, 2016, 10:02:54 PM (9 years ago)
Author:
Frederik Heber <heber@…>
Branches:
Action_Thermostats, Add_AtomRandomPerturbation, Add_FitFragmentPartialChargesAction, Add_RotateAroundBondAction, Add_SelectAtomByNameAction, Added_ParseSaveFragmentResults, Adding_Graph_to_ChangeBondActions, Adding_MD_integration_tests, Adding_ParticleName_to_Atom, Adding_StructOpt_integration_tests, 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_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, FragmentMolecule_checks_bonddegrees, GeometryObjects, Gui_Fixes, Gui_displays_atomic_force_velocity, IndependentFragmentGrids, IndependentFragmentGrids_IndividualZeroInstances, IndependentFragmentGrids_IntegrationTest, IndependentFragmentGrids_Sole_NN_Calculation, JobMarket_RobustOnKillsSegFaults, JobMarket_StableWorkerPool, JobMarket_unresolvable_hostname_fix, 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:
1ab6fc
Parents:
8eafd6
git-author:
Frederik Heber <heber@…> (03/10/16 13:06:47)
git-committer:
Frederik Heber <heber@…> (05/18/16 22:02:54)
Message:

FitPartialChargesAction checks whether AtomFragments has been loaded.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Actions/PotentialAction/FitPartialChargesAction.cpp

    r8eafd6 rf33ef9  
    395395}
    396396
     397bool isNotHydrogen(const atom * const _atom)
     398{
     399  return (_atom->getElementNo() != (atomicNumber_t) 1);
     400}
     401
    397402ActionState::ptr PotentialFitPartialChargesAction::performCall()
    398403{
    399404  // check for selected atoms
    400405  const World &world = const_cast<const World &>(World::getInstance());
    401   if (world.beginAtomSelection() == world.endAtomSelection()) {
     406  const std::vector<const atom *> selected_atoms = world.getSelectedAtoms();
     407  if (selected_atoms.empty()) {
    402408    STATUS("There are no atoms selected for fitting partial charges to.");
    403409    return Action::failure;
     
    407413  const AtomFragmentsMap &atomfragments = AtomFragmentsMap::getConstInstance();
    408414  if (!atomfragments.checkCompleteness()) {
    409     STATUS("AtomFragmentsMap failed internal consistency check, missing forcekeysets?");
     415    ELOG(0, "AtomFragmentsMap failed internal consistency check, missing forcekeysets?");
    410416    return Action::failure;
    411417  }
    412   std::set<KeySet> fragments =
    413       accumulateKeySetsForAtoms( atomfragments.getMap(), world.getSelectedAtoms());
     418  const std::set<KeySet> fragments =
     419      accumulateKeySetsForAtoms( atomfragments.getMap(), selected_atoms);
     420  const size_t NoNonHydrogens =
     421      std::count_if(selected_atoms.begin(), selected_atoms.end(), isNotHydrogen);
     422  if (fragments.size() < NoNonHydrogens) {
     423    ELOG(0, "Obtained fewer fragments than there are atoms, has AtomFragments been loaded?");
     424    return Action::failure;
     425  }
    414426
    415427  // reduce given fragments to homologous graphs to avoid multiple fittings
     
    430442  /// obtain average charge for each atom the fitted charges over all its fragments
    431443  detail::fitted_charges_t fitted_charges;
    432   for (World::AtomSelectionConstIterator atomiter = world.beginAtomSelection();
    433       atomiter != world.endAtomSelection(); ++atomiter) {
     444  for (std::vector<const atom *>::const_iterator atomiter = selected_atoms.begin();
     445      atomiter != selected_atoms.end(); ++atomiter) {
     446    const atomId_t walkerid = (*atomiter)->getId();
    434447    const double average_charge = fitAverageChargeToAtom(
    435         atomiter->second, atomfragments, keyset_graphs, fittedcharges_per_fragment);
     448        *atomiter, atomfragments, keyset_graphs, fittedcharges_per_fragment);
    436449
    437450    if (average_charge != 0.) {
    438       LOG(2, "DEBUG: For atom " << atomiter->first << " we have an average charge of "
     451      LOG(2, "DEBUG: For atom " << *atomiter << " we have an average charge of "
    439452          << average_charge);
    440453
    441       fitted_charges.insert( std::make_pair(atomiter->first, average_charge) );
     454      fitted_charges.insert( std::make_pair(walkerid, average_charge) );
    442455    }
    443456  }
     
    455468  detail::GraphIndices_t GraphIndices;
    456469  const AtomFragmentsMap::AtomFragmentsMap_t &atommap = atomfragments.getMap();
    457   for (World::AtomSelectionConstIterator atomiter = world.beginAtomSelection();
    458       atomiter != world.endAtomSelection(); ++atomiter) {
     470  for (std::vector<const atom *>::const_iterator atomiter = selected_atoms.begin();
     471      atomiter != selected_atoms.end(); ++atomiter) {
    459472    // use the non-hydrogen here
    460     const atomId_t walkerid = getNonHydrogenSurrogate(atomiter->second)->getId();
    461     if (walkerid != atomiter->first)
     473    const atomId_t walkerid = (*atomiter)->getId();
     474    const atomId_t surrogateid = getNonHydrogenSurrogate(*atomiter)->getId();
     475    if (surrogateid != walkerid)
    462476      continue;
    463477    const AtomFragmentsMap::AtomFragmentsMap_t::const_iterator keysetsiter =
    464         atommap.find(atomiter->first);
     478        atommap.find(walkerid);
    465479    ASSERT(keysetsiter != atommap.end(),
    466480        "PotentialFitPartialChargesAction::performCall() - we checked already that "
    467         +toString(walkerid)+" should be present!");
     481        +toString(surrogateid)+" should be present!");
    468482    const AtomFragmentsMap::keysets_t & keysets = keysetsiter->second;
    469483
     
    486500    }
    487501
    488     GraphIndices.insert( detail::GraphIndices_t::value_type(AtomsGraphIndices, atomiter->first) );
    489 
    490     LOG(2, "DEBUG: Atom #" << atomiter->first << "," << *atomiter->second
    491         << ". has graph indices " << AtomsGraphIndices);
     502    GraphIndices.insert( detail::GraphIndices_t::value_type(AtomsGraphIndices, walkerid) );
     503
     504    LOG(2, "DEBUG: Atom #" << walkerid << "," << *atomiter << ". has graph indices "
     505        << AtomsGraphIndices);
    492506  }
    493507  // then graphs from non-hydrogen bond partner for all hydrogens
    494   for (World::AtomSelectionConstIterator atomiter = world.beginAtomSelection();
    495       atomiter != world.endAtomSelection(); ++atomiter) {
     508  for (std::vector<const atom *>::const_iterator atomiter = selected_atoms.begin();
     509      atomiter != selected_atoms.end(); ++atomiter) {
    496510    // use the non-hydrogen here
    497     const atomId_t walkerid = getNonHydrogenSurrogate(atomiter->second)->getId();
    498     if (walkerid == atomiter->first)
     511    const atomId_t walkerid = (*atomiter)->getId();
     512    const atomId_t surrogateid = getNonHydrogenSurrogate((*atomiter))->getId();
     513    if (surrogateid == walkerid)
    499514      continue;
    500     detail::GraphIndices_t::right_const_iterator graphiter = GraphIndices.right.find(walkerid);
     515    detail::GraphIndices_t::right_const_iterator graphiter = GraphIndices.right.find(surrogateid);
    501516    ASSERT( graphiter != GraphIndices.right.end(),
    502         "PotentialFitPartialChargesAction::performCall() - atom #"+toString(walkerid)
     517        "PotentialFitPartialChargesAction::performCall() - atom #"+toString(surrogateid)
    503518        +" not contained in GraphIndices.");
    504519    const detail::AtomsGraphIndices_t &AtomsGraphIndices = graphiter->second;
    505     GraphIndices.insert( detail::GraphIndices_t::value_type(AtomsGraphIndices, atomiter->first) );
    506     LOG(2, "DEBUG: Hydrogen #" << atomiter->first << ", " << *atomiter->second
     520    GraphIndices.insert( detail::GraphIndices_t::value_type(AtomsGraphIndices, walkerid) );
     521    LOG(2, "DEBUG: Hydrogen #" << walkerid << ", " << *atomiter
    507522        << ", has graph indices " << AtomsGraphIndices);
    508523  }
     
    516531      GraphIndices,
    517532      atom_particlenames);
    518   for (World::AtomSelectionConstIterator atomiter = world.beginAtomSelection();
    519       atomiter != world.endAtomSelection(); ++atomiter) {
    520     const atom * const walker = atomiter->second;
     533  for (std::vector<const atom *>::const_iterator atomiter = selected_atoms.begin();
     534      atomiter != selected_atoms.end(); ++atomiter) {
     535    const atom * const walker = *atomiter;
     536    const atomId_t walkerid = walker->getId();
    521537    const detail::GraphIndices_t::right_const_iterator graphiter =
    522         GraphIndices.right.find(atomiter->first);
     538        GraphIndices.right.find(walkerid);
    523539    ASSERT( graphiter != GraphIndices.right.end(),
    524         "PotentialFitPartialChargesAction::performCall() - ");
     540        "PotentialFitPartialChargesAction::performCall() - cannot find "
     541        +toString(walkerid)+" in GraphIndices.");
    525542    const detail::AtomsGraphIndices_t &graphindex = graphiter->second;
    526543    const detail::AtomParticleNames_t::const_iterator particlesetiter =
    527544        atom_particlenames.find(graphindex);
    528545    ASSERT( particlesetiter != atom_particlenames.end(),
    529         "PotentialFitPartialChargesAction::performCall() - ");
     546        "PotentialFitPartialChargesAction::performCall() - cannot find "
     547        +toString(graphindex)+" in atom_particlenames.");
    530548    const std::map<atomicNumber_t, std::string>::const_iterator nameiter =
    531549        particlesetiter->second.find(walker->getElementNo());
    532550    ASSERT( nameiter != particlesetiter->second.end(),
    533551        "PotentialFitPartialChargesAction::performCall() - ");
    534     LOG(1, "INFO: atom " << *walker << " received the following particle " << nameiter->second);
     552    LOG(1, "INFO: atom " << *walker << " received the following particle "
     553        << nameiter->second);
    535554  }
    536555
Note: See TracChangeset for help on using the changeset viewer.