Changeset 0cbad2


Ignore:
Timestamp:
Mar 1, 2011, 1:17:07 PM (14 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:
300220
Parents:
3738f0
git-author:
Frederik Heber <heber@…> (02/18/11 23:39:44)
git-committer:
Frederik Heber <heber@…> (03/01/11 13:17:07)
Message:

Moved molecule::CreateAdjacencyListFromDbondFile() over to BondGraph and made more flexible.

Files:
3 added
8 edited

Legend:

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

    r3738f0 r0cbad2  
    2020#include "CodePatterns/MemDebug.hpp"
    2121
     22#include "bondgraph.hpp"
    2223#include "CodePatterns/Log.hpp"
    2324#include "molecule.hpp"
     
    4546  if(World::getInstance().countSelectedMolecules() == 1) {
    4647    mol = World::getInstance().beginMoleculeSelection()->second;
    47     DoLog(0) && (Log() << Verbose(0) << "Parsing bonds from " << params.bondfile << "." << endl);
     48    LOG(0, "STATUS: Parsing bonds from " << params.bondfile
     49        << ", skipping " << params.skiplines << "lines"
     50        << ", adding " << params.id_offset << " to each id.");
    4851    ifstream input(params.bondfile.string().c_str());
    49     mol->CreateAdjacencyListFromDbondFile(&input);
     52    molecule::atomVector Set = mol->getAtomSet();
     53    World::getInstance().getBondGraph()->CreateAdjacencyListFromDbondFile(Set, &input, params.skiplines, params.id_offset);
    5054    input.close();
     55    mol->getBondCount();
    5156    return Action::success;
    5257  } else
  • src/Actions/MoleculeAction/BondFileAction.def

    r3738f0 r0cbad2  
    1212// ValueStorage by the token "Z" -> first column: int, Z, "Z"
    1313// "undefine" if no parameters are required, use (NODEFAULT) for each (undefined) default value
    14 #define paramtypes (boost::filesystem::path)
    15 #define paramtokens ("bond-file")
    16 #define paramdescriptions ("name of the bond file")
    17 #undef paramdefaults
    18 #define paramreferences (bondfile)
     14#define paramtypes (boost::filesystem::path)(int)(int)
     15#define paramtokens ("bond-file")("skiplines")("offset")
     16#define paramdescriptions ("name of the bond file")("number of header lines to skip")("offset to add to each id")
     17#define paramdefaults (NODEFAULT)("1")("0")
     18#define paramreferences (bondfile)(skiplines)(id_offset)
    1919
    2020#undef statetypes
  • src/bondgraph.cpp

    r3738f0 r0cbad2  
    206206    LOG(1, "I detected " << BondCount << " bonds in the molecule.");
    207207}
     208
  • src/bondgraph.hpp

    r3738f0 r0cbad2  
    3030#include "IPointCloud.hpp"
    3131#include "PointCloudAdaptor.hpp"
     32#include "WorldTime.hpp"
    3233
    3334/****************************************** forward declarations *****************************/
     
    151152      LOG(1, "REJECT: AtomCount is " << counter << ", thus no bonds, no connections.");
    152153    }
     154  }
     155
     156  /** Creates an adjacency list of the given \a Set of atoms.
     157   *
     158   * Note that the input stream is required to refer to the same number of
     159   * atoms also contained in \a Set.
     160   *
     161   * \param &Set container with atoms
     162   * \param *input input stream to parse
     163 * \param skiplines how many header lines to skip
     164 * \param id_offset is base id compared to World startin at 0
     165   */
     166  template <class container_type,
     167            class iterator_type,
     168            class const_iterator_type>
     169  void CreateAdjacencyListFromDbondFile(
     170      AtomSetMixin<container_type,iterator_type,const_iterator_type> &Set,
     171      ifstream *input,
     172      unsigned int skiplines,
     173      int id_offset) const
     174  {
     175    char line[MAXSTRINGSIZE];
     176
     177    // check input stream
     178    if (input->fail()) {
     179      ELOG(0, "Opening of bond file failed \n");
     180      return;
     181    };
     182    // skip headers
     183    unsigned int bondcount = 0;
     184    for (unsigned int i=0;i<skiplines;i++)
     185      input->getline(line,MAXSTRINGSIZE);
     186
     187    // create lookup map
     188    LOG(1, "STATUS: Creating lookup map.");
     189    std::map< unsigned int, atom *> AtomLookup;
     190    unsigned int counter = id_offset; // if ids do not start at 0
     191    for (iterator_type iter = Set.begin(); iter != Set.end(); ++iter) {
     192      AtomLookup.insert( make_pair( counter++, *iter) );
     193    }
     194    LOG(2, "INFO: There are " << counter << " atoms in the given set.");
     195
     196    LOG(1, "STATUS: Scanning file.");
     197    unsigned int atom1, atom2;
     198    unsigned int bondcounter = 0;
     199    while (!input->eof()) // Check whether we read everything already
     200    {
     201      input->getline(line,MAXSTRINGSIZE);
     202      stringstream zeile(line);
     203      if (zeile.str().empty())
     204        continue;
     205      zeile >> atom1;
     206      zeile >> atom2;
     207
     208      LOG(4, "INFO: Looking for atoms " << atom1 << " and " << atom2 << ".");
     209      if (atom2 < atom1) //Sort indices of atoms in order
     210        std::swap(atom1, atom2);
     211      ASSERT(atom2 < counter,
     212          "BondGraph::CreateAdjacencyListFromDbondFile() - ID "
     213          +toString(atom2)+" exceeds number of present atoms "+toString(counter)+".");
     214      ASSERT(AtomLookup.count(atom1),
     215          "BondGraph::CreateAdjacencyListFromDbondFile() - Could not find an atom with the ID given in dbond file");
     216      ASSERT(AtomLookup.count(atom2),
     217          "BondGraph::CreateAdjacencyListFromDbondFile() - Could not find an atom with the ID given in dbond file");
     218      atom * const Walker = AtomLookup[atom1];
     219      atom * const OtherWalker = AtomLookup[atom2];
     220
     221      LOG(3, "INFO: Creating bond between atoms " << atom1 << " and " << atom2 << ".");
     222      bond * const Binder = new bond(Walker, OtherWalker, 1, -1);
     223      Walker->RegisterBond(WorldTime::getTime(), Binder);
     224      OtherWalker->RegisterBond(WorldTime::getTime(), Binder);
     225      bondcounter++;
     226    }
     227    LOG(1, "STATUS: "<< bondcounter << " bonds have been parsed.");
    153228  }
    154229
  • src/molecule.hpp

    r3738f0 r0cbad2  
    210210
    211211  /// Initialising routines in fragmentation
    212   void CreateAdjacencyListFromDbondFile(ifstream *output);
     212  void CreateAdjacencyListFromDbondFile(ifstream *output,unsigned int skiplines,int id_offset);
    213213  void OutputBondsList() const;
    214214  void CyclicBondAnalysis() const;
  • src/molecule_graph.cpp

    r3738f0 r0cbad2  
    7272
    7373/************************************* Functions for class molecule *********************************/
    74 
    75 /** Creates an adjacency list of the molecule.
    76  * We obtain an outside file with the indices of atoms which are bondmembers.
    77  */
    78 void molecule::CreateAdjacencyListFromDbondFile(ifstream *input)
    79 {
    80   Info FunctionInfo(__func__);
    81   // 1 We will parse bonds out of the dbond file created by tremolo.
    82   int atom1, atom2;
    83   atom *Walker, *OtherWalker;
    84   char line[MAXSTRINGSIZE];
    85 
    86   if (input->fail()) {
    87     DoeLog(0) && (eLog() << Verbose(0) << "Opening of bond file failed \n");
    88     performCriticalExit();
    89   };
    90   doCountAtoms();
    91 
    92   // skip header
    93   input->getline(line,MAXSTRINGSIZE);
    94   DoLog(1) && (Log() << Verbose(1) << "Scanning file ... \n");
    95   while (!input->eof()) // Check whether we read everything already
    96   {
    97     input->getline(line,MAXSTRINGSIZE);
    98     stringstream zeile(line);
    99     zeile >> atom1;
    100     zeile >> atom2;
    101 
    102     DoLog(2) && (Log() << Verbose(2) << "Looking for atoms " << atom1 << " and " << atom2 << "." << endl);
    103     if (atom2 < atom1) //Sort indices of atoms in order
    104       std::swap(atom1, atom2);
    105     Walker = FindAtom(atom1);
    106     ASSERT(Walker,"Could not find an atom with the ID given in dbond file");
    107     OtherWalker = FindAtom(atom2);
    108     ASSERT(OtherWalker,"Could not find an atom with the ID given in dbond file");
    109     AddBond(Walker, OtherWalker); //Add the bond between the two atoms with respective indices.
    110   }
    111 }
    11274
    11375/** Checks for presence of bonds within atom list.
  • tests/regression/Molecules/BondFile/pre/test.dbond

    r3738f0 r0cbad2  
    1 m       n
    2 0       1
    3 0       3
    4 0       4
    5 0       5
    6 1       2
    7 1       6
    8 1       7
    9 2       8
    10 2       9
    11 2       10
     1m n
     20 1
     30 3
     40 4
     50 5
     61 2
     71 6
     81 7
     92 8
     102 9
     112 10
  • tests/regression/Molecules/BondFile/testsuite-molecules-bond-file.at

    r3738f0 r0cbad2  
    11### Bonds from file
    22
    3 AT_SETUP([Molecules - Bonds from file])
     3AT_SETUP([Molecules - Fragmentation bonds file])
    44AT_KEYWORDS([Molecules])
    55AT_CHECK([/bin/cp -f ${abs_top_srcdir}/${AUTOTEST_PATH}/Molecules/BondFile/pre/test.* .], 0)
    6 AT_CHECK([../../molecuilder -i test.conf  -v 4 --select-molecule-by-id 0 -A test.dbond], 0, [stdout], [stderr])
    7 AT_CHECK([fgrep "Looking for atoms 2 and 9." stdout], 0, [ignore], [ignore])
     6AT_CHECK([../../molecuilder -i test.conf -o pdb -v 4 --select-molecule-by-id 0 -A test.dbond --skiplines 1 --offset 0], 0, [stdout], [stderr])
     7AT_CHECK([file=test.pdb; diff -I '.*reated by molecuilder.*' $file ${abs_top_srcdir}/${AUTOTEST_PATH}/Molecules/BondFile/post/$file], 0, [ignore], [ignore])
    88AT_CLEANUP
     9
     10AT_SETUP([Molecules - TREMOLO dbond file])
     11AT_KEYWORDS([Molecules])
     12AT_CHECK([/bin/cp -f ${abs_top_srcdir}/${AUTOTEST_PATH}/Molecules/BondFile/pre/silica.* .], 0)
     13AT_CHECK([../../molecuilder -i silica.pov1.0000.pdb -v 4 --select-molecule-by-id 0 -A silica.dbond.0000 --skiplines 2 --offset 1], 0, [stdout], [stderr])
     14AT_CHECK([fgrep -c "CONECT 7153 6098 5949 5922" silica.pov1.0000.pdb], 0, [1
     15], [ignore])
     16AT_CLEANUP
Note: See TracChangeset for help on using the changeset viewer.