Changeset 560bbe for src/molecule.cpp
- Timestamp:
- Feb 17, 2012, 3:24:18 PM (13 years ago)
- 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:
- cdaae6
- Parents:
- ac5c36
- git-author:
- Frederik Heber <heber@…> (01/06/12 16:49:11)
- git-committer:
- Frederik Heber <heber@…> (02/17/12 15:24:18)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/molecule.cpp
rac5c36 r560bbe 25 25 #include <gsl/gsl_inline.h> 26 26 #include <gsl/gsl_heapsort.h> 27 28 #include "molecule.hpp" 27 29 28 30 #include "Atom/atom.hpp" … … 32 34 #include "CodePatterns/Log.hpp" 33 35 #include "config.hpp" 36 #include "Descriptors/AtomIdDescriptor.hpp" 34 37 #include "Element/element.hpp" 35 38 #include "Element/periodentafel.hpp" … … 41 44 #include "LinearAlgebra/Vector.hpp" 42 45 #include "LinkedCell/linkedcell.hpp" 43 #include " molecule.hpp"46 #include "IdPool_impl.hpp" 44 47 #include "Tesselation/tesselation.hpp" 45 48 #include "World.hpp" … … 63 66 AtomCount(this,boost::bind(&molecule::doCountAtoms,this),"AtomCount"), 64 67 BondCount(this,boost::bind(&molecule::doCountBonds,this),"BondCount"), 68 atomIdPool(0, 20, 100), 65 69 last_atom(0) 66 70 { … … 103 107 cout << "Set name of molecule " << getId() << " to " << _name << endl; 104 108 strncpy(name,_name.c_str(),MAXSTRINGSIZE); 109 } 110 111 bool molecule::changeAtomNr(int oldNr, int newNr, atom* target){ 112 OBSERVE; 113 if(atomIdPool.reserveId(newNr)){ 114 if (oldNr != -1) // -1 is reserved and indicates no number 115 atomIdPool.releaseId(oldNr); 116 ASSERT (target, 117 "molecule::changeAtomNr() - given target is NULL, cannot set Nr or name."); 118 target->setNr(newNr); 119 setAtomName(target); 120 return true; 121 } else{ 122 return false; 123 } 105 124 } 106 125 … … 197 216 ++iter; 198 217 atomIds.erase( key->getId() ); 218 atomIdPool.releaseId(key->getNr()); 219 key->setNr(-1); 199 220 formula-=key->getType(); 200 221 key->removeFromMolecule(); … … 213 234 pair<atomIdSet::iterator,bool> res = atomIds.insert(key->getId()); 214 235 if (res.second) { // push atom if went well 236 key->setNr(atomIdPool.getNextId()); 237 setAtomName(key); 215 238 formula+=key->getType(); 216 239 return pair<iterator,bool>(iterator(res.first, FromIdToAtom()),res.second); … … 219 242 } 220 243 } 244 245 void molecule::setAtomName(atom *_atom) const 246 { 247 std::stringstream sstr; 248 sstr << _atom->getType()->getSymbol() << _atom->getNr()+1; 249 _atom->setName(sstr.str()); 250 } 251 221 252 222 253 bool molecule::containsAtom(atom* key){ … … 247 278 OBSERVE; 248 279 if (pointer != NULL) { 249 if (pointer->getType() != NULL) { 250 if (pointer->getType()->getAtomicNumber() != 1) 251 NoNonHydrogen++; 252 if(pointer->getName() == "Unknown"){ 253 stringstream sstr; 254 sstr << pointer->getType()->getSymbol() << pointer->getNr()+1; 255 pointer->setName(sstr.str()); 256 } 257 } 280 if (pointer->getType()->getAtomicNumber() != 1) 281 NoNonHydrogen++; 258 282 insert(pointer); 259 283 pointer->setMolecule(this); … … 1029 1053 { 1030 1054 int res = size(); 1031 int i = 0;1032 1055 NoNonHydrogen = 0; 1033 for (molecule::iterator iter = begin(); iter != end(); ++iter) {1034 (*iter)->setNr(i); // update number in molecule (for easier referencing in FragmentMolecule lateron)1056 // go through atoms and look for new ones 1057 for (molecule::const_iterator iter = begin(); iter != end(); ++iter) 1035 1058 if ((*iter)->getType()->getAtomicNumber() != 1) // count non-hydrogen atoms whilst at it 1036 1059 NoNonHydrogen++; 1037 stringstream sstr;1038 sstr << (*iter)->getType()->getSymbol() << (*iter)->getNr()+1;1039 (*iter)->setName(sstr.str());1040 LOG(3, "Naming atom nr. " << (*iter)->getNr() << " " << (*iter)->getName() << ".");1041 i++;1042 }1043 1060 return res; 1044 1061 }; … … 1106 1123 ActiveFlag = !ActiveFlag; 1107 1124 } 1125 1126 // construct idpool 1127 CONSTRUCT_IDPOOL(atomId_t, continuousId)
Note:
See TracChangeset
for help on using the changeset viewer.