source: src/Graph/CheckAgainstAdjacencyFile.cpp@ 5605793

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
Last change on this file since 5605793 was 13a953, checked in by Frederik Heber <heber@…>, 14 years ago

Moved molecule::CheckAdjacencyAgainstFile() into functor in Graph/.

  • Note that this is currently not working because there is no correct mapping from indices in the adjacency file to the indices of the atoms (and without some fixed mean of aligning atoms, this will never be possible).
  • Property mode set to 100644
File size: 3.8 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2010 University of Bonn. All rights reserved.
5 * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
6 */
7
8/*
9 * CheckAgainstAdjacencyFile.cpp
10 *
11 * Created on: Mar 3, 2011
12 * Author: heber
13 */
14
15// include config.h
16#ifdef HAVE_CONFIG_H
17#include <config.h>
18#endif
19
20#include "CodePatterns/MemDebug.hpp"
21
22#include <iostream>
23
24#include "CheckAgainstAdjacencyFile.hpp"
25
26#include "atom.hpp"
27#include "Bond/bond.hpp"
28#include "CodePatterns/Assert.hpp"
29
30CheckAgainstAdjacencyFile::CheckAgainstAdjacencyFile() :
31 CurrentBonds(new int[MAXBONDS]),
32 status(true),
33 NonMatchNumber(0)
34{
35 for(int i=0;i<MAXBONDS;i++)
36 CurrentBonds[i] = 0;
37}
38
39CheckAgainstAdjacencyFile::~CheckAgainstAdjacencyFile()
40{
41 delete[](CurrentBonds);
42}
43
44void CheckAgainstAdjacencyFile::CompareBonds(const atom *&Walker, size_t &CurrentBondsOfAtom, int AtomNr, std::map<int, atom*> &ListOfAtoms)
45{
46 size_t j = 0;
47 int id = -1;
48
49 //Log() << Verbose(2) << "Walker is " << *Walker << ", bond partners: ";
50 const BondList& ListOfBonds = Walker->getListOfBonds();
51 if (CurrentBondsOfAtom == ListOfBonds.size()) {
52 for (BondList::const_iterator Runner = ListOfBonds.begin();
53 Runner != ListOfBonds.end();
54 ++Runner) {
55 id = (*Runner)->GetOtherAtom(Walker)->getNr();
56 j = 0;
57 for (; (j < CurrentBondsOfAtom) && (CurrentBonds[j++] != id);)
58 ; // check against all parsed bonds
59 if (CurrentBonds[j - 1] != id) { // no match ? Then mark in ListOfAtoms
60 ListOfAtoms[AtomNr] = NULL;
61 NonMatchNumber++;
62 status = false;
63 ELOG(2, id << " can not be found in list." << endl);
64 } else {
65 //Log() << Verbose(0) << "[" << id << "]\t";
66 }
67 }
68 //Log() << Verbose(0) << endl;
69 } else {
70 LOG(0, "STATUS: Number of bonds for Atom " << *Walker << " does not match, parsed " << CurrentBondsOfAtom << " against " << ListOfBonds.size() << ".");
71 status = false;
72 }
73}
74;
75
76/** Checks contents of adjacency file against bond structure in structure molecule.
77 * \param File file to parser
78 * \param ListOfAtoms map from int (index in file) to atom
79 * \return true - structure is equal, false - not equivalence
80 */
81bool CheckAgainstAdjacencyFile::operator()(std::ifstream &File, std::map<int, atom*> ListOfAtoms)
82{
83 LOG(0, "STATUS: Looking at bond structure stored in adjacency file and comparing to present one ... ");
84 if (File.fail()) {
85 LOG(1, "STATUS: Adjacency file not found." << endl);
86 return false;
87 }
88
89 char buffer[MAXSTRINGSIZE];
90 int tmp;
91 // Parse the file line by line and count the bonds
92 while (!File.eof()) {
93 File.getline(buffer, MAXSTRINGSIZE);
94 stringstream line;
95 line.str(buffer);
96 int AtomNr = -1;
97 line >> AtomNr;
98 size_t CurrentBondsOfAtom = -1; // we count one too far due to line end
99 // parse into structure
100 if (AtomNr >= 0) {
101 ASSERT(ListOfAtoms.count(AtomNr),
102 "CheckAgainstAdjacencyFile::operator() - index "
103 +toString(AtomNr)+" not present in ListOfAtoms.");
104 const atom *Walker = ListOfAtoms[AtomNr];
105 while (line >> ws >> tmp) {
106 LOG(3, "INFO: Recognized bond partner " << tmp);
107 CurrentBonds[++CurrentBondsOfAtom] = tmp;
108 ASSERT(CurrentBondsOfAtom < MAXBONDS,
109 "molecule::CheckAdjacencyFileAgainstMolecule() - encountered more bonds than allowed: "
110 +toString(CurrentBondsOfAtom)+" >= "+toString(int(MAXBONDS))+"!");
111 }
112 // compare against present bonds
113 CompareBonds(Walker, CurrentBondsOfAtom, AtomNr, ListOfAtoms);
114 } else {
115 if (AtomNr != -1)
116 ELOG(2, AtomNr << " is negative.");
117 }
118 }
119
120 if (status) { // if equal we parse the KeySetFile
121 LOG(0, "STATUS: Equal.");
122 } else
123 LOG(0, "STATUS: Not equal by " << NonMatchNumber << " atoms.");
124 return status;
125}
126;
Note: See TracBrowser for help on using the repository browser.