- Timestamp:
- Jul 3, 2017, 3:07:28 PM (7 years ago)
- Branches:
- ForceAnnealing_oldresults, IndependentFragmentGrids_IntegrationTest
- Children:
- ef8667
- Parents:
- 95b64f
- git-author:
- Frederik Heber <frederik.heber@…> (06/17/17 21:31:42)
- git-committer:
- Frederik Heber <frederik.heber@…> (07/03/17 15:07:28)
- Location:
- src/Parser
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/TremoloParser.cpp
r95b64f refc80e 143 143 molecule *newmol = World::getInstance().createMolecule(); 144 144 newmol->ActiveFlag = true; 145 usedFields_t usedFields_temp; 146 size_t timestep = 0; 147 atom *addedatom = NULL; 148 std::vector<atom *> addedatoms; 149 std::vector<atom *>::iterator atomiter = addedatoms.begin(); 145 150 while (file->good()) { 146 151 std::getline(*file, line, '\n'); 147 152 // we only parse in the first ATOMDATA line 148 if (usedFields_load.empty()) { 149 location = line.find("ATOMDATA", 0); 150 if (location != string::npos) { 151 parseAtomDataKeysLine(line, location + 8, usedFields_load); 153 location = line.find("ATOMDATA", 0); 154 if (location != string::npos) { 155 parseAtomDataKeysLine(line, location + 8, usedFields_temp); 156 if (usedFields_load.empty()) { 157 // first ATOMDATA: use this line 158 usedFields_load.insert(usedFields_load.end(), usedFields_temp.begin(), usedFields_temp.end()); 159 usedFields_temp.clear(); 160 LOG(3, "DEBUG: Local usedFields is: " << usedFields_load); 161 } else { 162 // following ATOMDATA: check against present 163 LOG(3, "DEBUG: Parsed check usedFields is: " << usedFields_temp); 164 if (usedFields_load != usedFields_temp) { 165 ELOG(1, "File contains multiple time steps with differing ATOMDATA line, parsing only first time step."); 166 break; 167 } else { 168 // update time step 169 ++timestep; 170 atomiter = addedatoms.begin(); 171 } 172 } 173 } else { 174 if (line.length() > 0 && line.at(0) != '#') { 175 if (timestep != 0) { 176 ASSERT( atomiter != addedatoms.end(), 177 "FormatParser< tremolo >::load() - timesteps contains more atoms than first one."); 178 addedatom = *atomiter++; 179 } 180 readAtomDataLine(line, newmol, timestep, addedatom); 181 if (timestep == 0) 182 addedatoms.push_back(addedatom); 152 183 } 153 184 } 154 if (line.length() > 0 && line.at(0) != '#') { 155 readAtomDataLine(line, newmol); 156 } 157 } 158 LOG(3, "DEBUG: Local usedFields is: " << usedFields_load); 185 } 186 ASSERT( addedatoms.size() == newmol->size(), 187 "FormatParser< tremolo >::load() - number of atoms in mol and addedatoms differ."); 159 188 160 189 // refresh atom::nr and atom::name … … 692 721 * \param line to parse as an atom 693 722 * \param *newmol molecule to add atom to 694 */ 695 void FormatParser< tremolo >::readAtomDataLine(const std::string &line, molecule *newmol) { 723 * \param _timestep time step to parse to 724 * \param _addedatom ref to added atom 725 */ 726 void FormatParser< tremolo >::readAtomDataLine( 727 const std::string &line, 728 molecule *newmol, 729 const size_t _timestep, 730 atom *&_addedatoms) 731 { 696 732 std::stringstream lineStream; 697 atom* newAtom = World::getInstance().createAtom(); 698 const atomId_t atomid = newAtom->getId(); 699 additionalAtomData[atomid] = TremoloAtomInfoContainer(); // fill with default values 733 atom* newAtom = NULL; 734 atomId_t atomid = -1; 735 if (_timestep == 0) { 736 newAtom = World::getInstance().createAtom(); 737 _addedatoms = newAtom; 738 atomid = newAtom->getId(); 739 additionalAtomData[atomid] = TremoloAtomInfoContainer(); // fill with default values 740 } else { 741 newAtom = _addedatoms; 742 atomid = newAtom->getId(); 743 } 700 744 TremoloAtomInfoContainer *atomInfo = &additionalAtomData[atomid]; 701 745 TremoloKey::atomDataKey currentField; … … 727 771 for (int i=0;i<NDIM;i++) { 728 772 ASSERT(tok_iter != tokens.end(), "FormatParser< tremolo >::readAtomDataLine() - no value for x["+toString(i)+"]!"); 729 LOG(4, "INFO: Parsing key " << keyName << " with next token " << word );730 newAtom->set (i, toDouble(word));773 LOG(4, "INFO: Parsing key " << keyName << " with next token " << word << " on step " << _timestep); 774 newAtom->setAtStep(i, _timestep, toDouble(word)); 731 775 tok_iter++; 732 776 } … … 736 780 for (int i=0;i<NDIM;i++) { 737 781 ASSERT(tok_iter != tokens.end(), "FormatParser< tremolo >::readAtomDataLine() - no value for u["+toString(i)+"]!"); 738 LOG(4, "INFO: Parsing key " << keyName << " with next token " << word );782 LOG(4, "INFO: Parsing key " << keyName << " with next token " << word << " on step " << _timestep); 739 783 tempVector[i] = toDouble(word); 740 784 tok_iter++; 741 785 } 742 newAtom->setAtomicVelocity (tempVector);786 newAtom->setAtomicVelocityAtStep(_timestep, tempVector); 743 787 break; 744 788 case TremoloKey::F : … … 746 790 for (int i=0;i<NDIM;i++) { 747 791 ASSERT(tok_iter != tokens.end(), "FormatParser< tremolo >::readAtomDataLine() - no value for F["+toString(i)+"]!"); 748 LOG(4, "INFO: Parsing key " << keyName << " with next token " << word );792 LOG(4, "INFO: Parsing key " << keyName << " with next token " << word << " on step " << _timestep); 749 793 tempVector[i] = toDouble(word); 750 794 tok_iter++; 751 795 } 752 newAtom->setAtomicForce (tempVector);796 newAtom->setAtomicForceAtStep(_timestep, tempVector); 753 797 break; 754 798 case TremoloKey::type : 755 799 { 756 800 ASSERT(tok_iter != tokens.end(), "FormatParser< tremolo >::readAtomDataLine() - no value for "+keyName+"!"); 757 LOG(4, "INFO: Parsing key " << keyName << " with next token " << word );801 LOG(4, "INFO: Parsing key " << keyName << " with next token " << word << " on step " << _timestep); 758 802 std::string elementname; 759 803 const element * elem = NULL; … … 787 831 case TremoloKey::Id : 788 832 ASSERT(tok_iter != tokens.end(), "FormatParser< tremolo >::readAtomDataLine() - no value for "+keyName+"!"); 789 LOG(4, "INFO: Parsing key " << keyName << " with next token " << word); 790 associateLocaltoGlobalId(toInt(word), atomid); 833 LOG(4, "INFO: Parsing key " << keyName << " with next token " << word << " on step " << _timestep); 834 if (_timestep == 0) { 835 associateLocaltoGlobalId(toInt(word), atomid); 836 } else { 837 // check association is the same 838 ASSERT( (atomId_t)getGlobalId(toInt(word)) == atomid, 839 "FormatParser< tremolo >::readAtomDataLine() - differing global id "+toString(atomid) 840 +" on timestep "+toString(_timestep)); 841 ASSERT( getLocalId(atomid) == toInt(word), 842 "FormatParser< tremolo >::readAtomDataLine() - differing local id "+toString(toInt(word)) 843 +" on timestep "+toString(_timestep)); 844 } 791 845 tok_iter++; 792 846 break; 793 847 case TremoloKey::neighbors : 794 848 for (int i=0;i<atoi(it->substr(it->find("=") + 1, 1).c_str());i++) { 795 ASSERT(tok_iter != tokens.end(), "FormatParser< tremolo >::readAtomDataLine() - no value for "+keyName+"!"); 796 LOG(4, "INFO: Parsing key " << keyName << " with next token " << word); 849 ASSERT(tok_iter != tokens.end(), 850 "FormatParser< tremolo >::readAtomDataLine() - no value for "+keyName+"!"); 851 if (_timestep == 0) 852 LOG(4, "INFO: Parsing key " << keyName << " with next token " << word << " on step " << _timestep); 797 853 lineStream << word << "\t"; 798 854 tok_iter++; 799 855 } 800 readNeighbors(&lineStream, 801 atoi(it->substr(it->find("=") + 1, 1).c_str()), atomid); 856 if (_timestep == 0) { 857 readNeighbors(&lineStream, 858 atoi(it->substr(it->find("=") + 1, 1).c_str()), atomid); 859 } 802 860 break; 803 861 case TremoloKey::charge : 804 862 ASSERT(tok_iter != tokens.end(), "FormatParser< tremolo >::readAtomDataLine() - no value for "+keyName+"!"); 805 LOG(4, "INFO: Parsing key " << keyName << " with next token " << word); 806 atomInfo->set(currentField, word); 807 newAtom->setCharge(boost::lexical_cast<double>(word)); 863 if (_timestep == 0) { 864 LOG(4, "INFO: Parsing key " << keyName << " with next token " << word << " on step " << _timestep); 865 atomInfo->set(currentField, word); 866 newAtom->setCharge(boost::lexical_cast<double>(word)); 867 } 808 868 tok_iter++; 809 869 break; 810 870 default : 811 871 ASSERT(tok_iter != tokens.end(), "FormatParser< tremolo >::readAtomDataLine() - no value for "+keyName+"!"); 812 LOG(4, "INFO: Parsing key " << keyName << " with next token " << word); 813 atomInfo->set(currentField, word); 872 if (_timestep == 0) { 873 LOG(4, "INFO: Parsing key " << keyName << " with next token " << word << " on step " << _timestep); 874 atomInfo->set(currentField, word); 875 } 814 876 tok_iter++; 815 877 break; -
src/Parser/TremoloParser.hpp
r95b64f refc80e 80 80 typedef std::vector<std::string> usedFields_t; 81 81 82 void readAtomDataLine(const std::string &line, molecule *newmol); 82 void readAtomDataLine( 83 const std::string &line, 84 molecule *newmol, 85 const size_t _timestep, 86 atom *&_addedatoms); 83 87 void parseAtomDataKeysLine(const std::string &line, const int offset, usedFields_t &fields); 84 88 static bool testParseAtomDataKeysLine(const std::string &line);
Note:
See TracChangeset
for help on using the changeset viewer.